Posts

Showing posts from April, 2018

Remove Add New Post Sub Menu From Custom Post

// Remove New Post function disable_new_posts() {       $global_settings = get_posts( 'post_type=domain_hosting' );     if ( count($global_settings) != 0 ) {       // Remove sidebar link       global $submenu;       unset($submenu['edit.php?post_type=domain_hosting'][10]);       // Hide Add new button with CSS       // * change post id to id of existing post on next line *       if ((isset($_GET['post_type']) && $_GET['post_type'] == 'domain_hosting') || $_GET['post'] == 273) {           echo '%MINIFYHTMLb8a8432e92a03a7d02f4061d76fed79384%';       }     } } add_action('admin_menu', 'disable_new_posts'); // Remove New Post // add_action( 'admin_init', 'my_remove_menu_pages' ); function my_remove_menu_pages() { global $user_ID; if ( current_user_can( 'client' ) ) { remove_menu_page( 'edit.ph...

How To Remove and Add Visit Site Menu From WordPress Admin Bar?

Using This Code, you can remove the 'Visit Site' Section admin bar drop down and add it to admin bar menu section // Add Visit Site in ID Section   -- Bonus add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {     if ( ! is_admin() ) {         return;     }     /** @var WP_Admin_Bar $wp_admin_bar */     $wp_admin_bar->remove_node( 'view-site' );     $wp_admin_bar->add_menu( array(         'id'    => 'view-site',         'title' => __( 'Visit Site' ),         'href'  => home_url( '/' ),     ) ); }, 31 ); // After `wp_admin_bar_site_menu()` at 30. // Another Way add_action( 'admin_bar_menu', 'make_parent_node', 999 ); function make_parent_node( $wp_admin_bar ) {     if ( ! is_admin() ) { return; }  // end function if not in admin back-end, credit @Rarst   ...

How To Remove Links and Menus From WordPress Admin Bar?

// Remove Admin Menu Visit Link function remove_admin_bar_links() {     global $wp_admin_bar;     $wp_admin_bar->remove_menu('view-site');        // Remove the view site link     $wp_admin_bar->remove_menu('site-name');        // Remove the site name menu     $wp_admin_bar->remove_menu('customize');        // Remove the site name menu     $wp_admin_bar->remove_menu('comments');        // Remove the site name menu     $wp_admin_bar->remove_menu('edit');        // Remove the site name menu     $wp_admin_bar->remove_menu('new-content');        // Remove the site name menu     $wp_admin_bar->remove_menu('appearance');        // Remove the site name menu     $wp_admin_bar->remove_menu('my-account');        // ...

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 

Change WordPress Dashboard Background

// Add Css JS On WordPress Dashboard function my_login_stylesheet() {     wp_enqueue_style( 'custom-login', get_stylesheet_directory_uri() . '/style-login.css' );     wp_enqueue_script( 'custom-login', get_stylesheet_directory_uri() . '/style-login.js' ); } add_action( 'login_enqueue_scripts', 'my_login_stylesheet' ); // Add CSS JS In WordPress Dashboard

How To Change WordPress Dashboard Login Logo

// Custom Logo in Dashboard function my_login_logo() { ?>     <style type="text/css">         #login h1 a, .login h1 a {             background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/logo.png); height:65px; width:320px; background-size: 160px 60px;; background-repeat: no-repeat;         }     </style> <?php } add_action( 'login_enqueue_scripts', 'my_login_logo' ); function my_login_logo_url() {     return home_url(); } add_filter( 'login_headerurl', 'my_login_logo_url' ); function my_login_logo_url_title() {     return 'Linux Pathshala Limited Dashboard'; } add_filter( 'login_headertitle', 'my_login_logo_url_title' ); // Custom Logo in Dashboard

Page Redirection To Targeted Page

Redirected one page to another page. //Contact Page Redirection function my_page_template_redirect() {     if( is_page( 'home' ) && ! is_user_logged_in() )     {         wp_redirect( home_url( '/wp-admin/' ) );         die;     } } add_action( 'template_redirect', 'my_page_template_redirect' ); //Contact Page Redirection

How To Register Custom Post In WordPress

Register a Custom Post In WordPress add_action( 'init', 'domain_hosting_entry' ); function domain_hosting_entry() { register_post_type( 'Domain_Hosting', array( 'labels' => array( 'name' => __( 'Domain Hosting Information', 'muhibul' ), 'all_items'     => __( 'All Domain Hosting Information', 'muhibul' ), 'singular_name' => __( 'Domain Hosting Item', 'muhibul' ), 'add_new'       => __( 'Add New Domain Hosting', 'muhibul' ), 'add_new_item'  => __( 'Add New Domain Hosting Item', 'muhibul' ) ), 'public' => true, 'publicly_queryable' => true, 'has_password' => true, 'menu_icon' => 'dashicons-megaphone', 'supports' => array('title', 'editor', 'thumbnail' ), 'menu_posi...