Change default admin page for specific role(s)

In your theme’s functions.php: function hide_the_dashboard() { global $current_user; // is there a user ? if ( is_array( $current_user->roles ) ) { // substitute your role(s): if ( in_array( ‘custom_role’, $current_user->roles ) ) { // hide the dashboard: remove_menu_page( ‘index.php’ ); } } } add_action( ‘admin_menu’, ‘hide_the_dashboard’ ); function your_login_redirect( $redirect_to, $request, $user ) { … Read more

Load js/css files only on specific admin UI pages

The right hooks // Use both for scripts & styles *) wp_enqueue_scripts // (for the frontend) login_enqueue_scripts // (for the login screen) admin_enqueue_scripts // (for the admin dashboard) *) Read this article @wpdevel. Further reading in the Codex about the three hooks admin_menu network_admin_menu user_admin_menu On the admin_enqueue_scripts hook, you have an argument as well: … Read more

Prevent trash/delete action on specific post types

Here’s another approach using the map_meta_cap filter that’s applied within the map_meta_cap() function within the has_cap() method of the WP_User class (PHP 5.4+): add_filter( ‘map_meta_cap’, function ( $caps, $cap, $user_id, $args ) { // Nothing to do if( ‘delete_post’ !== $cap || empty( $args[0] ) ) return $caps; // Target the payment and transaction post … Read more

Admin settings update updating every time home page is hit?

A much better hook to use would the the update_option_{option_name} dynamic hook, which only runs after your specific option has been updated. So something like: add_action(‘update_option_woocommerce_email_send_time’, ‘send_time’) function update_send_time() { // Add code here to update cron job } The only problem you’ll get here is that scheduling the cron job for a time earlier … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)