What is the proper way to get logged in user id in a plugin?

If you’re inside a plugin, WordPress is already loaded. You don’t need to load it yourself. Inside whatever function needs the user ID, you need to do two things: Globalize the user data variable Populate the user data variable Here’s some pseudocode: function some_function_that_needs_user_info() { global $current_user; get_currentuserinfo(); // Now reference $current_user->ID in your code. … Read more

add_filter doesn’t work

register_activation_hook and register_deactivation_hook refer to when the plugin is activated and deactivated, respectively, and only fire in those two instances. They’re to be used, for example, when you need to add a database table (and take it back down). You don’t need to remove your filters, either. Your plugin can just be shortened to: function … Read more

Wrap text around shortcode

Without seeing your show_sticky_posts, show_lastest_posts, show_lastest_missions,show_all_posts_from_categories i can guess that the shortcode content is always before the post content beacuse this functions are echoing/outputing the result and a shortcode should return content instead so you can try using output buffer of PHP like this: function show_posts_handler( $atts, $content=null, $code=”” ) { //code 4 displaying extract( … Read more

Using a multiple element in widget form

I would remove the jQuery save function that was added… and then… Try this for the form function: public function form( $instance ) { // Code for editing/adding title and adding IDs to the <select> object // … <?php printf ( ‘<select multiple=”multiple” name=”%s[]” id=”%s” class=”widefat” size=”15″ style=”margin-bottom:10px”>’, $this->get_field_name(‘ID_list’), $this->get_field_id(‘ID_list’) ); // Each individual option … Read more

Proper way to replace the_content only for pages created by custom plugin

You need to return the filtered content, try like this: add_filter(‘the_content’, ’emd_content’); function emd_content( $content ) { if ( is_page(‘Member Directory’) ) { include dirname( __FILE__ ) . ‘/content-members.php’; } elseif ( is_page(‘Contact Members’) ) { include dirname( __FILE__ ) . ‘/content-member-contact-form.php’; } else { return $content; } } But the better way is to … Read more

Create shortcode to echo javascript

First of all, it looks like you are trying to enqueue version 2.2.4 of jquery, under the condition that jquery has already been loaded. That doesn’t look good. Secondly, you can’t just echo a script in a shortcode. You must add it to another script using wp_add_inline_script. Like this: function wpse238227_custom_shortcode23() { wp_enqueue_script(‘script-typed’, ‘https://www.example.comwp-content/themes/mediso-v1-03/typed.js’, array(‘jquery’)); … Read more

How can I remove the WordPress-Version (?ver=5.x) from my plugin

Change the 4th parameter from false to null. wp_enqueue_script( ‘myID’, $url, array( ‘jquery’ ), null, true ); From the wp_enqueue_script() documentation: $ver (string|bool|null) (Optional) String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version … Read more