{"id":696,"date":"2019-03-20T16:48:37","date_gmt":"2019-03-20T16:48:37","guid":{"rendered":"https:\/\/www.kolkataonweb.com\/code-bank\/?p=696"},"modified":"2019-03-14T12:59:25","modified_gmt":"2019-03-14T12:59:25","slug":"some-wordpress-tricks","status":"publish","type":"post","link":"https:\/\/www.kolkataonweb.com\/code-bank\/php\/some-wordpress-tricks\/","title":{"rendered":"Some WordPress Tricks"},"content":{"rendered":"<p>Redirect some or users to a particular URL after logging in<\/p>\n<pre class='wp-code-highlight prettyprint'>function login_redirect( $redirect_to, $request, $user ) \r\n{ \r\n   return ( is_array( $user-&gt;roles ) &amp;&amp; in_array( 'sln_staff', $user-&gt;roles ) ) ? \"https:\/\/mydevfactory.com\/~appfactory\/salonBooking\/wp-admin\/admin.php?page=salon\" : admin_url(); \/* here sln_staff is the admin group for which a redirect will happen after logging in *\/\r\n}\r\n\r\nadd_filter( 'login_redirect', 'login_redirect', 10, 3 );<\/pre>\n<p>&nbsp;<\/p>\n<p>Remove the Black Admin bar that appears on top of site when the user is logged in<\/p>\n<pre class='wp-code-highlight prettyprint'>function remove_admin_bar() \r\n{ \r\n   show_admin_bar(false);\r\n}\r\nadd_action('after_setup_theme', 'remove_admin_bar');<\/pre>\n<p>Remove the WordPress update notice on top of the Dashboard<\/p>\n<pre class='wp-code-highlight prettyprint'>function hide_update_notice_to_all_but_admin_users() \r\n{ \r\n   if (!current_user_can('update_core')) { \r\n     remove_action( 'admin_notices', 'update_nag', 3 ); \r\n   } \r\n   $user = wp_get_current_user(); \r\n   \/*echo ($user['roles'][0]); \r\n   if(in_array( 'sln_staff', $user-&gt;roles )) \r\n     echo \"SLN_STAFF\"; \r\n   else \r\n     echo \"WHOEVER\";*\/\r\n}\r\n\r\nadd_action( 'admin_head', 'hide_update_notice_to_all_but_admin_users', 1 );<\/pre>\n<p>&nbsp;<\/p>\n<p>Remove the Dashboard items using the Screen Options and then remove the Screen Options and Help tab<\/p>\n<pre class='wp-code-highlight prettyprint'>function remove_help_tabs($old_help, $screen_id, $screen)\r\n{ \r\n   $screen-&gt;remove_help_tabs(); \r\n   return $old_help;\r\n}\r\n\r\nadd_filter( 'contextual_help', 'remove_help_tabs', 999, 3 );\r\nadd_filter('screen_options_show_screen', '__return_false');<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redirect some or users to a particular URL after logging in function login_redirect( $redirect_to, $request, $user ) { return ( is_array( $user-&gt;roles ) &amp;&amp; in_array( &#8216;sln_staff&#8217;, $user-&gt;roles ) ) ? &#8220;https:\/\/mydevfactory.com\/~appfactory\/salonBooking\/wp-admin\/admin.php?page=salon&#8221; : admin_url(); \/* here sln_staff is the admin group for which a redirect will happen after logging in *\/ } add_filter( &#8216;login_redirect&#8217;, &#8216;login_redirect&#8217;, 10,&hellip; <a class=\"more-link\" href=\"https:\/\/www.kolkataonweb.com\/code-bank\/php\/some-wordpress-tricks\/\">Continue reading <span class=\"screen-reader-text\">Some WordPress Tricks<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-696","post","type-post","status-publish","format-standard","hentry","category-php","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/comments?post=696"}],"version-history":[{"count":1,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/696\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/696\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/media?parent=696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/categories?post=696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/tags?post=696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}