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)

Java stored procedure or user-defined function could not call Java method

After I created a Java external stored procedure in DB2 as in my previous question, the call

call user1.send_mail(    P_TO          => 'me@domain.com'   ,P_CC          => NULL   ,P_BCC         => NULL   ,P_FROM        => 'me@domain.com'   ,P_SUBJECT     => 'db2 java subject'   ,P_TEXT_MSG    => 'db2 java test'   ,P_HTML_MSG    => null   ,P_ATTACH_NAME => null   ,P_ATTACH_MIME => null   ,P_ATTACH_BLOB => null   ,P_SMTP_HOST   => 'domain.com'   ,P_SMTP_PORT   => 465   ,P_USER_NAME   => 'me@domain.com'   ,P_PASSWORD    => 'secret'); 

fails it due to the following error:

Java stored procedure or user-defined function "USER1.SEND_MAIL", specific name "SQL201208113215436" could not call Java method "send_mail", signature "(Ljava/lang/String".. SQLCODE=-4306, SQLSTATE=42724, DRIVER=3.68.61

I made sure that all parameters that have no default values receive non-NULL values. What else is necessary for this to work?

How do you render_callback for register_block_type to a method in another class?

I’m writing a new plugin, and one of the things it does is create a new dynamic block. I generally write my plugins based off of WPPB, which does things in an object-oriented way, and semantically separates admin functionality from public functionality.

I have the admin class successfully creating the edit side of the block. But for the "save" side, for a dynamic block, it makes semantic sense for the render function to be in the public class … but (I think) it needs to get registered in the admin class (actually, now that I’m writing this, is there any harm to calling register_block_type more than once?).

I’m thinking there’s more than one way to skin this cat, and I’m trying to figure out the "best", where "best" is making optimal use of both PHP OOP and WordPress builtin functionality, to maximize speed, minimize size, and provide clean, readable code.

Option 1: make sure the main plugin class instantiates the public class first, and then passes it to the admin class:

class My_Plugin {         $  my_public = new My_Public();         $  my_admin = new My_Admin($  my_public); }  class My_Admin {         public function __construct($  my_public) {                 $  this->my_public = $  my_public;         }          register_block_type( 'my-plugin/my-block',                     array(                         'editor_script' => 'my_editor_function',                         'render_callback' => array($  this->my_public, 'my_save_function')         ) ); }  class My_Public {         public function my_save_function() {                 //do stuff to render the public side of the block         } } 

Option 2: do something with WordPress Actions and Hooks:

class My_Admin {         register_block_type( 'my-plugin/my-block',                     array(                         'editor_script' => 'my-editor-function',                         'render_callback' => 'render_front_end')         ) );          public function render_front_end() {                 do_action('my_plugin_render_action');         } }  class My_Public {         public function my_save_function() {                 //do stuff to render the public side of the block         }         add_action('my_plugin_render_action', 'my_save_function', 10); } 

Or, hypothetically, Option 3: if there’s no problem calling the register function more than once:

class My_Admin {         register_block_type( 'my-plugin/my-block',                     array(                         'editor_script' => 'my-editor-function',         ) ); }  class My_Public {         register_block_type( 'my-plugin/my-block',                     array(                         'render_callback' => 'my_save_function'         ) );          public function my_save_function() {                 //do stuff to render the public side of the block         } } 

Is one of these preferable? Do all of these work? Is there a better way to do this?

No route was found matching the URL and request method. I don’t understand where the problem is

When I send parameters, I get this: No route was found matching the URL and request method.

/**   * Add json data on plugin.  *   * */ add_action('rest_api_init', 'register_api_hooks'); function register_api_hooks() {   register_rest_route(     'passwordless_register/v0', '/register/(?P<name>[a-zA-Z0-9-]+)/(?P<email>[a-zA-Z0-9-]+)/?aam-jwt=(?P<token>[a-zA-Z0-9-]+)',     array(       'methods'  => 'POST',       'callback' => 'wc_rest_user_endpoint_handler',     )   ); }  /**  * Register a new user  *  * @param  WP_REST_Request $  request Full details about the request.  * @return array $  args.  **/ function wc_rest_user_endpoint_handler($  request) {   $  request = new WP_REST_Request( 'POST', 'passwordless_register/v0/register/(?P<name>[a-zA-Z0-9-]+)/(?P<email>[a-zA-Z0-9-]+)/?aam-jwt=(?P<token>[a-zA-Z0-9-]+)' );   $  username = $  request['name'];   $  email = $  request['email'];   $  response = array();   $  error = new WP_Error();   if (empty($  username)) {     $  error->add(400, __("name field 'username' is required.", 'wp-rest-user'), array('status' => 400));     return $  error;   }   if (empty($  email)) {     $  error->add(401, __("Email field 'email' is required.", 'wp-rest-user'), array('status' => 400));     return $  error;   }   $  user_id = username_exists($  username);   if (!$  user_id && email_exists($  email) == false) {       $  password = wp_generate_password( 20, false );     $  user_id = wp_create_user($  username, $  password, $  email);     if (!is_wp_error($  user_id)) {       // Ger User Meta Data (Sensitive, Password included. DO NOT pass to front end.)       $  user = get_user_by('id', $  user_id);       // $  user->set_role($  role);       $  user->set_role('subscriber');       // WooCommerce specific code       if (class_exists('WooCommerce')) {         $  user->set_role('customer');       }       // Ger User Data (Non-Sensitive, Pass to front end.)       wp_nonce_field( 'wpa_passwordless_login_request', 'nonce', false );       $  unique_url = wpa_generate_url( $  email , $  nonce );       $  response['code'] = 200;       $  response['message'] = __("User '" . $  username . "' Registration was Successful", "wp-rest-user");       $  response['mail'] = __("Mail '" . $  email . "' Registration was Successful", "wp-rest-email");       $  response['password'] =  __("Pass '" . $  password . "' Registration was Successful", "wp-rest-pass");       $  response['url'] =  __("Link '" . $  unique_url . "' Registration was Successful", "wp-rest-url");     } else {       return $  user_id;     }   } else {     $  error->add(406, __("Email already exists, please try 'Reset Password'", 'wp-rest-user'), array('status' => 400));     return $  error;   }   return new WP_REST_Response($  response, 123);           } add_action( 'after_setup_theme', 'passwordless_register/v0' ); 

Choosing Constant for Last Step in Substitution METHOD $T(n)= 5T(n/4) + n^2$

I figured out a solution to a recurrence relation, but I’m not sure what the constant should be for the last step to hold.

$ T(n)= 5T(n/4) + n^2$

Guess: $ T(n) = O(n^2)$

Prove: $ T(n) \leq cn^2 $

Breakdown

$ T(n) \leq 5(c(n/4)^2) + n^2 $

$ = (5/16)cn^2 + n^2 $

$ \leq cn^2 $

For the last step to hold I’m not sure what the value of c should be because of the (5/16). My guess would be c >= 1 and I’m not sure if that would hold.