Posts

How To Add Custom Link In WordPress Admin Bar?

// Add Link In Admin Dashboard add_action( 'admin_bar_menu', 'custom_wp_toolbar_link', 10 ); function custom_wp_toolbar_link( $wp_admin_bar ) {     if( current_user_can( 'publish_posts' ) ){ // Set the permission level or capability here for which user tier can see the link.         $args = array(             'id' => 'james', // Set the ID of your custom link             'title' => 'James\' Link', // Set the title of your link             'href' => 'http://localhost/domhost/admin', // Define the destination of your link             'meta' => array(                 'target' => '_self', // Change to _blank for launching in a new window                 'class' => 'Visit Site', // Add a class to your link       ...

How To Change User of WordPress Post or Custom Post?

// Adds a meta box to the post editing screen function ca_custom_meta() { $args = array( 'public'   => true, ); $post_types = get_post_types( $args );     add_meta_box( 'authordiv', __('Author'), 'ca_meta_callback', $post_types, 'normal', 'high' ); } add_action( 'add_meta_boxes', 'ca_custom_meta' ); /**  * Outputs the content of the meta box  */ function ca_meta_callback( $post ) { global $user_ID; ?> <label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label> <?php wp_dropdown_users( array( 'name' => 'post_author_override', 'selected' => empty($post->ID) ? $user_ID : $post->post_author, 'include_selected' => true ) ); }

How To Allow Only Post Creator Can See His Own Post

// Current User Can Show His Own Post add_action('pre_get_posts', 'filter_posts_list'); function filter_posts_list($query) {     //$pagenow holds the name of the current page being viewed      global $pagenow;     //$current_user uses the get_currentuserinfo() method to get the currently logged in user's data      global $current_user;      get_currentuserinfo();             //Shouldn't happen for the admin, but for any role with the edit_posts capability and only on the posts list page, that is edit.php         if(!current_user_can('administrator') && current_user_can('edit_posts') && ('edit.php' == $pagenow))      {         //global $query's set() method for setting the author as the current user's id         $query->set('author', $current_user->ID); $screen = get_current_sc...

How To Remove WordPress Dashboard Menu Items From Different User Role

define( 'DISALLOW_FILE_EDIT', true); function remove_menus(){ if(current_user_can( 'Manager' )){   remove_menu_page( 'index.php' );                  //Dashboard   remove_menu_page( 'jetpack' );                    //Jetpack*   //remove_menu_page( 'edit.php' );                   //Posts   //remove_menu_page( 'upload.php' );                 //Media   //remove_menu_page( 'edit.php?post_type=page' );    //Pages   remove_menu_page( 'edit.php?post_type=acf-field-group' );    //ACF   /*remove_menu_page( 'edit-comments.php' );          //Comments   remove_menu_page( 'themes.php' );                 //Appearance   remove_menu_page( 'plugins.php' );  ...

How To Add And Remove Capacity of WordPress User

function add_theme_caps() {     $role = get_role( 'manager' );     // This only works, because it accesses the class instance.     // would allow the author to edit others' posts for current theme only     $role->add_cap( 'upload_files' );     $role->add_cap( 'edit_dashboard' );     $role->add_cap( 'switch_themes' );     $role->add_cap( 'edit_theme_options' );      $role->add_cap( 'edit_themes' );     $role->add_cap( 'install_themes' );     $role->add_cap( 'edit_plugins' );     $role->add_cap( 'activate_plugins' );     $role->add_cap( 'install_plugins' );     $role->add_cap( 'remove_users' );     $role->add_cap( 'add_users' );     $role->add_cap( 'activate_plugins' );     $role->add_cap( 'customize' );     $role->add_cap( 'manage_options' );   ...

How To Add Custom Role or User In WordPress?

add_role(     'manager',     __( 'Manager' ),     array(         'read'         => true,  // true allows this capability         'edit_posts'   => true,         'upload_files'   => true, 'level_10' => true,         //'delete_posts' => false, // Use false to explicitly deny     ) ); // Client User add_role(     'client',     __( 'Client' ),     array(         'read'         => true,  // true allows this capability 'edit_posts'   => true, 'upload_files'   => true, //'delete_posts' => false, // Use false to explicitly deny     ) );

How To Redirect In Same Page or Custom Page After Login In WordPress?

// Redirection in same page after login if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) { add_filter('login_redirect', 'my_login_redirect', 10, 3); function my_login_redirect() { $location = $_SERVER['HTTP_REFERER']; wp_safe_redirect($location); exit(); } } function my_login_redirect( $redirect_to, $request, $user ) {     $redirect_to = home_url() . '/home/';     return $redirect_to; } add_filter( 'login_redirect', 'my_login_redirect', 10, 3 ); // Redirection in same page after login