Support

Account

Home Forums Add-ons Options Page Options Page 1.1.0 Issues

Solved

Options Page 1.1.0 Issues

  • Hey Elliot,

    Liking the updates to 1.1.0 for options pages, and already utilizing them : )

    I am running into some issues however, in implementing sub-pages under custom post type menus:

    • Get the following if I do not specify slug or capability:
      
      Notice: Undefined index: capability in /Users/ryanurban/Desktop/Git Repos/grable/content/plugins/acf-options-page/acf-options-page.php on line 251
      
      Notice: Undefined index: slug in /Users/ryanurban/Desktop/Git Repos/grable/content/plugins/acf-options-page/acf-options-page.php on line 251
      
    • The field groups that I am assigning to these pages are not being populated on the options pages.

    Finally here is how I’m implementing them:

    
    class TGF_Data_Architecture {
    
         /**
          *  Class constructor
          */
         public function __construct() {
              $this->hooks();
         }
    
         /**
          * Registers the filters and action
          */
         public function hooks() {
              add_action( 'init', array( $this, 'acf_archive_options_page' ) );
         }
    
         /**
          * ACF Archive Options Pages
          */
         public function acf_archive_options_page() {
    
              // Financial Reports Archive Options
    	  acf_add_options_sub_page( array(
    	       'slug' => 'financial-archive-page-content',
        	       'title' => 'Financial Archive Content',
        	       'parent' => 'edit.php?post_type=tgf-financials',
        	       'capability' => 'manage_options'
    	  ) );
    
    	  // Grants Archive Options
    	  acf_add_options_sub_page( array(
    	       'slug' => 'grants-archive-page-content',
        	       'title' => 'Grants Archive Content',
        	       'parent' => 'edit.php?post_type=tgf-grants',
        	       'capability' => 'manage_options'
    	  ) );
    
    	  // Areas of Focus Archive Options
    	  acf_add_options_sub_page( array(
    	       'slug' => 'areas-archive-page-content',
        	       'title' => 'Areas of Focus Archive Content',
                   'parent' => 'edit.php?post_type=tgf-focus-area',
        	       'capability' => 'manage_options'
    	  ) );
    
         }
    }
    

    Thanks for you time Elliot.

    • Elliot

    • July 17, 2013 at 2:48 pm

    Hi @fringewebdev

    Thanks for the detailed feedback, very useful.

    I’m a bit confused how this error is even occuring. You are specifying a slug, so why would you get an isset error…

    Are you able to debug the core code on line 251?

  • Hey Elliot, no problem!

    Sorry no, I specified the slug to get rid of the error 🙂

    Sure, tell me what to do, here is line 251:

    $child_page = add_submenu_page( $page['parent'], $page['title'], $page['title'], $page['capability'], $page['slug'], array($this, 'html'));

    And then of course the bigger problem is my fields not showing for these pages.

    Thanks Elliot.

  • Here’s the full function:


    function admin_menu()
    {
    // parent
    if( $this->settings['show_parent'] )
    {
    $parent_page = add_menu_page( $this->settings['title'], $this->settings['title'], $this->settings['capability'], $this->settings['slug'], array($this, 'html'));

    // actions
    add_action('load-' . $parent_page, array($this,'admin_load'));
    }

    // sub pages
    if( !empty( $this->settings['pages'] ) )
    {
    foreach( $this->settings['pages'] as $page )
    {
    $child_page = add_submenu_page( $page['parent'], $page['title'], $page['title'], $page['capability'], $page['slug'], array($this, 'html'));

    // actions
    add_action('load-' . $child_page, array($this,'admin_load'));
    }
    }

    }

    • Elliot

    • July 17, 2013 at 3:06 pm

    Hi @fringewebdev

    debugging means printing out the variables to determine what the function is doing right and what it is doing wrong.

    I would debug the $page variable.

  • Ah my apologies, here is what I get when I print_r on $page:

    
    Array ( [slug] => grants-archive-page-content [title] => Grants Archive Content [parent] => edit.php?post_type=tgf-grants [capability] => manage_options )
    

    And that’s with print_r right outside the foreach

  • Also don’t see any js errors or anything in console

  • Hey Elliot, been digging around some more. It seems as if when I don’t specify a slug, a slug isn’t being created for the page, and when I look at the sub-page url for the given page this is the link for it: ?page, and that is not the page title.

    It’s almost as if without a slug it isn’t going through your init() checks / settings.

    And then regarding fields not showing up on the options pages, it’s as if the sub-page isn’t full hooked into the various functions needed to implement the metaboxes or something. Tried debugging (eh eh), and got absolutely nothing. Just have the “No Custom field group….” flag.

    Hope this provides some insight. Let me know how else I can help.

    • Elliot

    • July 18, 2013 at 3:31 pm

    Hi @fringewebdev

    I wonder if the issue is that you are running this code in the init action.

    Can you please remove this action and run the functions in the root of the functions.php file (or constructor function)

  • Hmm when I try that (both), the sub-pages don’t even show up under the custom post types:

    
    // Financial Reports Archive Options
    acf_add_options_sub_page( array(
         'title' => 'Financial Archive Content',
         'parent' => 'edit.php?post_type=tgf-financials',
         'capability' => 'manage_options'
    ) );
    
    // Grants Archive Options
    acf_add_options_sub_page( array(
         'title' => 'Grants Archive Content',
         'parent' => 'edit.php?post_type=tgf-grants',
         'capability' => 'manage_options'
    ) );
    
  • So actually, I think it’s probably an issue somewhere in my core functionality plugin, as when I deactivated that and have the function in functions.php, the sub-page did work and showed the fields.

    So I need to figure out what is killing it. Ok, I believe you are blameless 🙂 I’ll report back with any findings if it could be a common gotcha for other people.

    Thanks for you excellent and responsive support as always, Elliot.

    Ryan

  • Alright you were correct Elliot, it didn’t like being fired on init, and the other part of the problem seemed to be my use of the following filter along with the acf_add_options_sub_page()

    add_filter( 'acf/options_page/settings', array( $this, 'acf_options_page_title' ) );

    Not sure if this filter is now deprecated with the 1.1.0 updates or not but they didn’t play well together. Ended up just using the acf_set_options_page_title() and acf_add_options_sub_page() tags, not in init, and everything then works fine.

    Thanks Elliot!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.