Custom admin page: How to save changes specific to users

Then save the data in the usermeta table, linked to each user, by update_user_meta() and get_user_meta() functions. get_current_user_id() gives you the $user_id to pass. Choose a $meta_key that wion’t create conflict, preferrably with a unique prefix. Same rule as for keys for saving data in options table.

custom shortcode will not display the wrapped content

Because the shortcode must return a string. Avoid using the “echo” function in shortcode. Instead of doing that: function my_shortcode_function($content){ echo ‘<div class=”wrap”>’; echo ‘<div class=”col”>’.$content.'</div>’; echo ‘</div>’; } Do that: function my_shortcode_function($content){ $shortcode_return = ‘<div class=”wrap”>’; $shortcode_return .= ‘<div class=”col”>’.$content.'</div>’; $shortcode_return .= ‘</div>’; return $shortcode_return; } Or use object buffering: function my_shortcode_function($content){ ob_start(); ?> … Read more

Add htaccess rules with insert_with_markers at beginning of htaccess

Using insert_with_markers() function you can insert your rules only between WordPress comments e.i. # BEGIN WordPress and # END WordPress. So, you should use plain PHP to achieve your aim. Create your rules Read existing .htaccess and concatenate your and existing rules Write the file Here is a dirty example: <?php $str = “# BEGIN TEST\n# MY RULES\n# END TEST\n”; … Read more

Shortcode Inside Class Not Working

if you use any hooks, filters or shortcodes with class methods, you have three options. either declare it in the context of an instance, in which case, you can refer to the instance of the class. class myClass { function __construct() { add_shortcode(‘my_shortcode_name’, [ $this, ‘shortcode’ ]); } function shortcode() { //your code here //properties … Read more

wp_insert_post not working

I guess the reason is you have not added post title and added post id $my_post = array( ‘post_id’ => 1, ‘post_status’ => ‘pending’, ‘post_type’ => ‘post’ ); Ideally if should be $my_post = array( ‘post_title’ => wp_strip_all_tags( $_POST[‘post_title’] ), ‘post_content’ => $_POST[‘post_content’], ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array( 8,39 ), ‘post_type’ … Read more

Slide in Panel WordPress Post

The reason why your query fails is the following. You are finishing the loop before your cd-panel with <?php endwhile; wp_reset_postdata(); ?> which is correct. However, after that you are simply using <?php the_title(); ?>, <?php the_content(); ?> which is just a single template tag, and in your case, outputs the title of the first … Read more