Please see screenshot. I would like to know how to hide

Hi,

Please see screenshot. I would like to know how to hide this red area from all of my users. For example, I want to force my users to add content via the /questions/ask approach rather than by the dashboard approach. Thus, hiding this section on the dashboard seems appropriate. In addition, the links in the red section correspond to:

/wp-admin/edit.php?post_type=question

/wp-admin/post-new.php?post_type=question

/wp-admin/edit.php?post_type=answer

Requirements:

I want to make sure that the red section disappears for my users.

I want to make sure that users can't access the 3 links above.

I want to make sure that users can still use the plugin to post content via /questions/ask etc

Thank you so much for your time and help.

[attachments are only viewable by logged-in members]

  • Sajid
    • DEV MAN’s Sidekick

    Hi @Peter

    Hope you are doing good today :slight_smile:

    Add following piece of code in fucntions.php file of your child theme or use mu-plugins.

    function wpmu_custom_admin_head() {
    if( !is_admin() || !is_super_admin() )
    echo '<style> #menu-posts-question {display: none !important;} </style>';
    }
    add_action( 'admin_head', 'wpmu_custom_admin_head' );

    This will hide menu items for you non admins and super admins from wp-admin area.

    Hope that helps :slight_smile:

    Cheers, Sajid

  • Peter
    • WPMU DEV Initiate

    Hi Sajid,

    Thanks! I think that solves requirement#1. However, how do i solve requirements #2 and #3?

    wp-admin/edit.php?post_type=question

    /wp-admin/post-new.php?post_type=question

    /wp-admin/edit.php?post_type=answer

    Requirements:

    1) I want to make sure that the red section disappears for my users.

    2) I want to make sure that users can’t access the 3 links above.

    3) I want to make sure that users can still use the plugin to post content via /questions/ask etc

  • Sajid
    • DEV MAN’s Sidekick

    Hi @Peter

    Hope you are doing good today :slight_smile:

    3) I want to make sure that users can still use the plugin to post content via /questions/ask etc

    I tested the code on my own site and users can still ask question from frontend via questions/ask. Is it not working for you ?

    2) I want to make sure that users can’t access the 3 links above.

    To restrict access via direct link add following code in functions.php file of your child theme or use mu-plugin.

    function wpmu_custom_qa_redirect() {
    if( ( !is_admin() || !is_super_admin() )
    and isset($_GET['post_type']) && ( $_GET['post_type'] == 'question' || $_GET['post_type'] == 'answer')
    ){
    wp_redirect( site_url('/questions/ask') );
    exit;

    }
    }
    add_action( 'admin_head', 'wpmu_custom_qa_redirect' );

    The above code will redirect non admins to /questions/ask.

    Hope that helps :slight_smile:

    Cheers, Sajid