What is the method to switch to specific page on entering theme customizer screen?

On entering the theme customizer, it defaults to the set home page, however I need to change the default to a page with ID 45.

The set home page uses a special template and is formatted by the elementor plugin so it is not expected to respond to the theme customizations. The page ID 45 uses the primary theme and is not set for public display, but solely for the purpose of previewing the changes.

I tried the following without success

add_action('customize_register', function($  mgr)  {   add_action('customize_controls_print_scripts', function()    {     echo '     <script>     wp.customize.previewer.previewUrl.set(wp.customize.settings.url + "?page_id=45");     </script>     ';   } } 

The console error states cannot read property of previewUrl but I am stumped on resolving the errors. I reviewed the customizer js api at https://developer.wordpress.org/themes/customize-api/the-customizer-javascript-api/ but just cannot determine the correct process.

Function range with numerical method

In[1]  FunctionRange[{{r^(1/2) Cos[t/2] + r^(1/3) Cos[t/3],             r^(1/2) Sin[t/2] + r^(1/3) Sin[t/3]},            0 <= r <= 1 && 0 <= t <= Pi/2}, {r, t}, {x, y}]  

Gives

Out[1]  0. <= x <= 2. && 0. <= y <= 1.20711 

with an error message :

enter image description here

FunctionRange: Unable to find the exact range. Returning bounds on the range computed using numeric optimization methods. 

Loos like mathematica attacked this problem algebraically at first, and failed, and tried numerical method. My question is : is it possible to attack this problem numerically from the beginning ?

My guess is

In[1]  FunctionRange[{{r^(1/2) Cos[t/2] + r^(1/3) Cos[t/3],             r^(1/2) Sin[t/2] + r^(1/3) Sin[t/3]},            0 <= r <= 1 && 0 <= t <= Pi/2}, {r, t}, {x, y}, Method -> blahblah] 

But I don’t know what blahblah is.

Efficient method to find patterns $\frac{a}{b}=k \frac{c}{d}$ in the set

I have a list of rules, the whole set is bigger, this is just a small part

rule1=MapIndexed[Subscript[A, First@#2]->#&,{0.017840140244041125`,0.03701275157916095`,0.051660116184981536`,0.08951663681268851`,0.11158027392659164`,0.11199090055895211`,0.11722479640123873`,0.12880796041375156`,0.13998629375261973`,0.14799408926444602`,0.1603406353916348`,0.1691630967698906`,0.17603820358593392`,0.17625123467649714`,0.19645343424258566`,0.21551707277352605`,0.2181102569613515`,0.23391774392335418`,0.2550771120859639`,0.268556465535236`,0.3048461639996855`,0.31092372219882125`,0.3127938111713915`,0.31392896827464023`,0.3409781586745735`,0.34596915956848695`,0.3529110816686192`,0.3616255919094322`,0.367472697175696`,0.3934402946502719`,0.4047693032887368`,0.4311153156718978`,0.4683757162129396`,0.46952099223657906`,0.5072262199843859`,0.5221019133548683`,0.5343944162249954`,0.547890105814087`,0.5599232760856494`,0.5668852126411741`,0.5798751142315612`,0.5934466012255624`,0.5974131205016744`,0.6095346242098095`,0.6435968663448772`,0.6590218413254265`,0.6941771182743655`,0.7420644764943874`,0.7438917323215621`,0.7969894568033051`,0.8000537128029253`,0.8374749504134635`,0.8407436273863764`,0.8616085956899902`,0.9112275732642781`,0.9275783068606626`,0.9389371022951489`,0.9437334963687791`,0.9593199516799973`,1}]; 

a, b, c, d are the four numbers in the set, and at most two are equal, satisfy the following relationship:
$ \frac{a}{b}=k \frac{c}{d}$
$ k$ is a rational number.
when $ k=1$ , The GroupBy based approach is fast enter image description here

GroupBy[#/#2 -> (#/#2 /. rule1) & @@@ Subsets[Keys@rule1, {2}],    Round[Last@#, 10^-10.] & -> First, Equal @@ # &] // DeleteCases[True] // AbsoluteTiming 

when $ k\neq 1$ , assume that $ k = 1/3$
It’s not easy to do with GroupBy, I thought of a way to use Gather, It’s much slower than the previous one enter image description here

Gather[#/#2 -> (#/#2 /. rule1) & @@@ Subsets[Keys@rule1, {2}],    Abs[#[[2]] #2[[2]] - 1/3] < 10^-10. &] // Select[Length@# > 1 &] // AbsoluteTiming 

I want to know if $ k\neq 1$ , is there a way to use Groupby instead of Gather, or other more efficient methods?
Thank you in advance.

Automatic Method for FindMinimum with constraints

What is the default method used by FindMinimum with constraints?

The documentation says-"Currently, the only method available for constrained optimization is the interior point algorithm"

But a random example gives different results for the Method->Automatic and Method->"InteriorPoints"

Reap[FindMinimum[{x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x,  4}, {y, 4}}, Method -> Automatic,StepMonitor :> Sow[{x^2 + y^2, x, y}]]]  Reap[FindMinimum[{x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x,      4}, {y, 4}}, Method -> "InteriorPoint",    StepMonitor :> Sow[{x^2 + y^2, x, y}]]] 

The above code yields the same final solution. But the steps taken are different for both, which suggests that the interior points is not used as the automatic one.

The same question has been asked here and here

So what is the exact method being used when Method->Automatic is specified?

How can I add a method to create files when in theme-editor.php


This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven’t tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that’s a solid option, I’d like to keep it all in the core file editor. It’s just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.

Method for playing an online text-based RPG that doesn’t require everyone to be online at once?

I am contemplating starting up a web-based text game for my D&D group to be played alongside our weekly sessions. The idea would be to play through events related to the main storyline, but not so involved that the outcomes would directly affect our current adventure.

I don’t want to require everyone to be online at once (or else this is just another session), so IRC and chatrooms are out. I am looking for a method that allows us to play at a slow pace but gives everyone a chance to respond to what the GM says before moving onward with the story or the combat.

The only idea that comes to mind is a forum-based game with heavy restrictions (e.g. each player must post a response or opt out of responding before the GM posts again). For combats I would post maps with the position of all the monsters and characters between each turn.

Does anyone have any experience running a game like this?

What’s the best way to run a web-based text RPG in such a way that not all players need to be online at the same time?

widget() method can’t access $instance variable WordPress

I followed a guide to create a WordPress plugin, which shows a youtube sub button on your page.

In the guide it works perfectly, but for some reason it doesn’t work for me.

This is my problem: When I var_dump($ instance) in widget() it prints out an empty array, but when I try to print_r($ instance) inside of my form() it prints out the correct information

Here is the widget file:

<?php  /**   * Adds Youtube_Subs widget.   */  class Youtube_Subs_Widget extends WP_Widget {    /**   * Register widget with WordPress.   */  function __construct() {    parent::__construct(      'youtubesubs_widget', // Base ID      esc_html__( 'YouTube Subs', 'mp_domain' ), // Name      array( 'description' => esc_html__( 'Widget to display YouTube subs', 'mp_domain' ), ) // Args    );  }    /**   * Front-end display of widget.   *   * @see WP_Widget::widget()   *   * @param array $  args     Widget arguments.   * @param array $  instance Saved values from database.   */  public function widget( $  args, $  instance ) {    echo $  args['before_widget']; // Whatever you want to display before widget (<div>, etc)    if ( ! empty( $  instance['title'] ) ) {      echo $  args['before_title'] . apply_filters( 'widget_title', $  instance['title'] ) . $  args['after_title'];    }     // Widget Content Output    var_dump($  instance);    // echo '<div class="g-ytsubscribe" data-channel="'.$  instance['channel'].'" data-layout="'.$  instance['layout'].'" data-count="'.$  instance['count'].'"></div>';      echo $  args['after_widget']; // Whatever you want to display after widget (</div>, etc)  }    /**   * Back-end widget form.   *   * @see WP_Widget::form()   *   * @param array $  instance Previously saved values from database.   */  public function form( $  instance ) {    $  title = (! empty( $  instance['title'] ) ? $  instance['title'] : esc_attr( 'YouTube Subs', 'mp_domain' ));      $  channel = (! empty( $  instance['channel'] ) ? $  instance['channel'] : esc_attr( 'techguyweb', 'mp_domain' ));      $  layout = (! empty( $  instance['layout'] ) ? $  instance['layout'] : esc_attr( 'default', 'mp_domain' ));      $  count = (! empty( $  instance['count'] ) ? $  instance['count'] : esc_attr( 'default', 'mp_domain' ));      ?>        <!-- TITLE -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'title' ) ); ?>">        <?php esc_attr_e( 'Title:', 'mp_domain' ); ?>      </label>         <input         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'title' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'title' ) ); ?>"         type="text"         value="<?php echo esc_attr( $  title ); ?>">    </p>      <!-- CHANNEL -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'channel' ) ); ?>">        <?php esc_attr_e( 'Channel:', 'mp_domain' ); ?>      </label>         <input         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'channel' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'channel' ) ); ?>"         type="text"         value="<?php echo esc_attr( $  channel ); ?>">    </p>      <!-- LAYOUT -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'layout' ) ); ?>">        <?php esc_attr_e( 'Layout:', 'mp_domain' ); ?>      </label>         <select         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'layout' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'layout' ) ); ?>">        <option value="default" <?php echo ($  layout == 'default') ? 'selected' : ''; ?>>          Default        </option>        <option value="full" <?php echo ($  layout == 'full') ? 'selected' : ''; ?>>          Full        </option>      </select>    </p>      <!-- COUNT -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'count' ) ); ?>">        <?php esc_attr_e( 'Count:', 'mp_domain' ); ?>      </label>         <select         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'count' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'count' ) ); ?>">        <option value="default" <?php echo ($  count == 'default') ? 'selected' : ''; ?>>          Default        </option>        <option value="hidden" <?php echo ($  count == 'hidden') ? 'selected' : ''; ?>>          Hidden        </option>      </select>    </p>    <?php       print_r($  instance);  }    /**   * Sanitize widget form values as they are saved.   *   * @see WP_Widget::update()   *   * @param array $  new_instance Values just sent to be saved.   * @param array $  old_instance Previously saved values from database.   *  * @return array Updated safe values to be saved.  */ public function update( $  new_instance, $  old_instance ) {   $  instance = $  old_instance;    $  instance['title'] = ( ! empty( $  new_instance['title'] ) ) ? strip_tags( $  new_instance['title'] ) : '';   $  instance['channel'] = ( ! empty( $  new_instance['channel'] ) ) ? strip_tags( $  new_instance['channel'] ) : '';   $  instance['layout'] = ( ! empty( $  new_instance['layout'] ) ) ? strip_tags( $  new_instance['layout'] ) : '';   $  instance['count'] = ( ! empty( $  new_instance['count'] ) ) ? strip_tags( $  new_instance['count'] ) :      '';         return $  instance;  } } 

I have this hooked up with my plugin file in where I register the widget:

 // Register Widget  function register_myplugin() {      register_widget('Youtube_Subs_Widget');  }   // Hook in function  add_action('widgets_init', 'register_myplugin'); 

I hope someone knows what is wrong and can help me correct my mistake, thanks in advance

Logging of method calls for recreation

Some games have the option to let you play offline and sync with a server once you have internet again. To prevent cheating and validate if it was an authentic play, usually some sort of log of all input actions is sent and validated afterwards on the server.

In my case I would be interested in a single MonoBehaviour and having all its method calls logged with the its parameters values. Giving this input, the game result output should be the same. (There is no random involved and no physics interaction)

  • One way would be just a writer at the start of each method that logs the timestamp, method name and paramter
  • Another would be maybe something like a multi delegate inbetween that calls both my method and a writer class
  • There is something else (some audit interface, annotation, etc)

What is the best way to achieve the logging? (No the actual format, just how to setup the framework to do the logging)