• room34

    (@room34)


    I already submitted this as a ticket to the original ACF team, but since it most likely affects SCF as well, it’s probably worth sharing here.

    I just discovered an issue with a setup I have where I don’t want users to be able to access the admin pages for the plugin’s Custom Post Types (e.g. the Field Groups, Post Types, Taxonomies and Option Pages editing screens —?I’m not sure offhand which of these are Pro-only).

    I’ve been using this code for ages:

    add_filter('acf/settings/show_admin', '__return_false');

    And while it does remove the links from the admin menu (as well as killing the Tools page), it does not actually prevent access to the editing screens for the plugin’s CPTs, if the user knows the URLs. This is because WordPress automatically creates those pages if?show_ui?is set to?true?in the?register_post_type()?function. The plugin’s existing code for the?acf/settings/show_admin?filter bails out before creating its own admin pages, but it doesn’t do anything to change the?show_uiproperty of the CPTs.

    I found that adding this extra bit of code does the trick:

    add_filter('register_post_type_args', function($args, $cpt) {
    switch ($cpt) {
    case 'acf-field-group':
    case 'acf-post-type':
    case 'acf-taxonomy':
    case 'acf-ui-options-page':
    $args['show_ui'] = false;
    break;
    }
    return $args;
    }, 10, 2);

    I went with?switch?because it worked best for my purposes but this could also be achieved with?in_array($cpt, array('acf-field-group', 'acf-post-type', 'acf-taxonomy', 'acf-ui-options-page')).

  • You must be logged in to reply to this topic.