Function exclusion for a plugin

With the help of given line you should be able to check if the request is related to Ninja Tables. Also you can modify this if you have another condition to detect the plugin’s context. In this case we have used did_action(‘ninja_tables_loaded’) to checks if the action ninja_tables_loaded has been fired, which might be specific … Read more

Function extension

The issue arises because str_replace() is replacing partial matches (like “POA” inside “POA (+)”). To fix this and ensure only exact matches are replaced, we can switch to using regular expressions with preg_replace(). Here’s a refined version of your function: function auto_link_post_titles( $content, $post_id, $field ) { $excluded_ids = array(); $excluded_field_names = array(); if ( … Read more

How to sort a non-meta field in the User Admin Panel?

The WP_User_Query::parse_orderby() actually supports sorting by the number of posts, but because WP_User_Query::parse_orderby() limits by what users can be sorted, accomplishing a custom sort is a bit of a hack. Here’s the workaround I’ve created (semi-tested): add_filter( ‘manage_users_sortable_columns’, static function ( $columns ) { $columns[‘articles_count’] = array( ‘articles_count’, false, __( ‘Articles’ ), __( ‘Table ordered … Read more

How to build an expiring function in WordPress?

In this code we are getting the Publish Date using get_the_date() to retrieve the publish date of the current post. and then calculating the difference by comparing the publish date with the current date. After this we conditionally output the script. The condition is if the publish date is within the last 30 days, output … Read more

Hide ID for WordPress User Role Subscriber

You can use the body_class filter and the wp_get_current_user() function to add the current user’s role to the <body> element, and then hide your elements with that (untested): add_filter( ‘body_class’, static function ( $classes ) { $user = wp_get_current_user(); $roles = $user->roles; if ( ! is_array( $roles ) ) { $roles = array( ‘subscriber’ ); … Read more