Support

Account

Home Forums ACF PRO Only Show Options Page If Field Group Exists (Multisite)

Solving

Only Show Options Page If Field Group Exists (Multisite)

  • Hi all,

    I’ve got a multisite install where some of the newer sites are making use of an ACF options page, where the older sites are not. I’ve set up my options page fine, but is there a way to filter conditionally so that if field_group does not exist on that site, I can declare my acf_add_options_page FALSE? Thanks!

    if( (function_exists(‘acf_add_options_page’) )) {

    $option_page = acf_add_options_page(array(
    ‘parent_slug’ => ‘themes.php’,
    ‘page_title’ => ‘Setup Options’,
    ‘menu_title’ => ‘Setup Options’
    ));

    }

  • I’m not sure if this will work or not, it’s just a guess.

    If you register your options page on the acf/init hook you might be able to test to see if the field group exists.

    
    add_action('acf/init', 'register_my_options_page');
    function register_my_options_page() {
      // get the field group
      $group = acf_get_field_group('group_123456'); // field group key
      // here's the guess
      // I think $group will be empty if the group does not exist
      // you'll need to test this
      if ($group) {
        // add your options page here
      }
    }
    
  • Thank you John, I believe that did the trick! Ultimately ended with this code::

    add_action('acf/init', 'register_my_options_page');
    function register_my_options_page() {
      $group = acf_get_field_group('group_5be9f72567db1'); // field group key
      if (($group) && (function_exists('acf_add_options_page'))) {
        $option_page = acf_add_options_page(array(
    		'parent_slug' => 'themes.php',
    		'page_title' 	=> 'Setup Options',
    		'menu_title' 	=> 'Setup Options'
    	));
      }
    }

    Thank you again for your eyes on this one!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Only Show Options Page If Field Group Exists (Multisite)’ is closed to new replies.