Plugin or code to send out email to admin when a post is created

No need for plugin here are a few lines of code you can modify and paste in your themes functions.php file and you will get a new email whenever a post is published: add_action(‘publish_post’, ‘send_admin_email’); function send_admin_email($post_id){ $to = ‘[email protected]’; $subject=”mail subject here”; $message = “your message here ex: new post published at: “.get_permalink($post_id); wp_mail($to, … Read more

Do not allow the creation of an administrator remotely

Here is a short script that prevents unapproved admins from logging in. Of course it is possible to add multiple login names. add_filter( ‘authenticate’, ‘auth_signon’, 30, 3 ); function auth_signon( $user, $username, $password ) { if( strtoupper($username) !== ‘MYLOGINNAME’ && in_array( ‘administrator’, (array) $user->roles )){ wp_logout(); return new WP_Error( ‘broke’, __( $username . “, good … Read more

How can I catch WordPress custom settings page slug has already changed?

you can use the admin_init hook along with the add_query_arg() function to modify the redirection URL for handle the situation. Redirect users to the correct URL admin.php?page=management if they access the settings page with an unexpected slug. Modify the redirection URL after settings have been updated to include the current page slug management, ensuring that … Read more

Custom WP_List_Table displays blank rows

You’re getting the blank rows because your column headers are registered late. And you should register the headers (i.e. initialize the list table class instance) before admin notices are rendered on the page, i.e. before WordPress fires hooks like admin_notices. But your customer_list_page() function, which I believe, is a callback for either add_menu_page() or add_submenu_page(), … 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 set up a private custom post type that is accessible in the administrative dashboard?

For the frontend, you can use template_redirect action to identify the page, and perform redirects or adjust the request on the fly (untested): add_action( ‘template_redirect’, static function () { if ( ! is_singular( ‘cpt’ ) && ! is_post_type_archive( ‘cpt’ ) ) { return; } if ( current_user_can( ‘read_private_pages’ ) || current_user_can( ‘read_private_posts’ ) ) { … Read more

tech