Execute a plugin only on post pages

No, the plugin is loaded long before WordPress has figured out if it should display a single post. But you can restrict the code of the plugin to do something only then. Example: add_action( ‘template_redirect’, function() { if ( ! is_single() ) return; // initialize plugin code here. });

WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page

I’ll preface this by saying I think it’s a really bad idea, but you could circumvent the admin UI by hooking an action that happens after things are initialized, but before any output occurs: function my_admin_ui(){ if( isset( $_GET[‘page’] ) && ‘myPlugin-ui’ == $_GET[‘page’] ){ include( plugin_dir_path( __FILE__ ) . ‘views/myPlugin-ui.php’ ); exit; } } … Read more

Modify hard-coded conditionals for roles to custom roles

First, your check code works, and takes this pattern: if ( $current_user->data->wp_capabilities[‘hardcoded role name’] ) { $role=”hardcoded role name”; } So lets swap the hardcoded role string out for a variable called $role_name ( you could call it something else if you want ). The check for a role name is now: if ( $current_user->data->wp_capabilities[$role_name] … Read more

How to change commenter links to /user/user_id?

You can use the get_comment_author_link hook, which is part of the get_comment_author_link() template tag, like your question already suggests. Then you only have to get the according user_id, which can be done via the $comment global, and construct the link you want accordingly. Exemplary usage like shown below: add_filter( ‘get_comment_author_link’, ‘wpse144835_custom_comment_author_link’ ); function wpse144835_custom_comment_author_link( $link … Read more

Disable The Events Calendar plugin from loading its scripts

I was successfully able to disabled The Events Calendar plugin for users that are not logged in by using only filters (see below). The dequeue_tec_scripts function dequeues scripts loaded by the plugin. The restricted_access_template function, redirects the user to a custom template named ‘restricted_access.php’ or ‘404.php’ if the template file is not found. I haven’t … Read more

Read text defined under __()

You should look at gettext filter hook which is applied to the translated text by the internationalization functions (__(), _e(), etc.). eg: add_filter( ‘gettext’, ‘my_sanitizer’, 20, 3 ); /** * my_sanitizer * @param string $translated_text the translation * @param string $text the origial text from __() * @param string $domain text domain * @return string … Read more