• Hi Matt,

    Useful plugin.

    I have created a custom set in functions.php and it is working perfectly. Problem is I need to have a second custom set on a different options page in the admin.

    What is the best way to load the custom set for a specific options page? I see get_options_page but not sure how to use it.

    Thanks.

Viewing 13 replies - 16 through 28 (of 28 total)
  • Thread Starter dbrabyn

    (@dbrabyn)

    At this point I think I am going to simply put together 2 select fields with the classes of the icons I need. My client won’t see the actual icons but so be it.

    This plugin is excellent and a real service to the ACF community. And your support Matt has been spectacular.

    Thanks again.

    Plugin Author Matt Keys

    (@mattkeys)

    Ok @dbrabyn sorry we couldn’t get it figured out. Thanks for your kind words.

    Hello,

    @mattkeys answer makes sense, if ACFFA_get_icons get called in acf/include_field_types, that means it’s basically called in the init hook at priority:5, even before acf/init. This is a very early hook, called before the current_screen and $plugin_page. This is why you don’t have access to all those information.

    You’ll have to rely on $pagenow and $_GET to check the actual page URL. Here is a code example that should now work:

    add_filter('ACFFA_get_icons', 'my_acf_options_page_icons');
    function my_acf_options_page_icons($results){
        
        // Get $pagenow
        global $pagenow;
        
        // Bail early if the URL is not: /wp-admin/admin.php?page=my-options-page
        if(!is_admin() || $pagenow !== 'admin.php' || acf_maybe_get_GET('page') !== 'my-options-page')
            return $results;
        
        // Do something...
        
        // Return
        return $results;
        
    }
    

    I know you probably already found a workaround, but I would like to find the solution, you know, for the science ??

    Regards.

    Thread Starter dbrabyn

    (@dbrabyn)

    @hwk-fr

    Tried it. No luck I’m afraid. No filtering happening.

    It checks against the page slug, right? Not the full screen ID.

    The site is running on FlyWheel’s Local. Does that change anything?

    Hello,

    It checks against the ACF Options Page with the menu slug: ‘my-options-page’. You need to update that part of the code with your Options Page slug, as described in the code comment.

    You’ll find it by clicking on it in the admin menu, and then in the URL. It should be something like: admin.php?page=xxx.

    What is yours?

    Regards.

    Thread Starter dbrabyn

    (@dbrabyn)

    That’s what I had understood.

    What is your Options Page url?

    I’ll install ACFFA and check it.

    Regards.

    Thread Starter dbrabyn

    (@dbrabyn)

    Okay, I’ll setup a similar Options Page and install the plugin.

    I just need to add an ACF FontAwesome field, and this field should only show specific icons (that I defined in the ACFFA_get_icons filter), on that specific Options Page, right?

    I’ll keep you updated here.

    Regards.

    PS: You can remove the actual domain name in your latest answer, just in case ??

    Thread Starter dbrabyn

    (@dbrabyn)

    Correct but ultimately I need to be able to have multiple such filtered custom sets on different options page (that said, I guess the ultimate would be to be able to have multiple sets on a same OP, i.e. target specific fields).

    Remove the domain name for security reasons even if it’s locally hosted?

    Hello,

    So, the ACF Font Awesome field make an ajax request everytime you open the select field. This is where ACFFA_get_icons hook is being called. Ajax requests are totally different from normal page requests and are completely isolated from the rest of the website. Common $pagenow, $plugin_page, $_GET or get_current_screen() checks will not work in there.

    In order to know which page is requesting the icons list (when opening the select field), we have to play with what the page send thru ajax. We got access to $_POST['field_key'] and $_POST['post_id'], which should help you to determine which field and which page is actually trying to list the icons.

    So here is a code example, for an Options Page with the native post id options (custom Options Page Post ID would help you organize and determine more easily which page is actually requesting the icons. But that’s optional. See acf_add_options_page() documentation). The code also check the field key which is listing the icons.

    add_filter('ACFFA_get_icons', 'my_acf_options_page_icons');
    function my_acf_options_page_icons($results){
        
        // Bail early if not an Ajax request
        if(!wp_doing_ajax())
            return $results;
        
        // Retrieve field key + Options Post ID
        $field_key = acf_maybe_get_POST('field_key');
        $post_id = acf_maybe_get_POST('post_id');
        
        // Check conditions
        if($field_key === 'field_5f60d66667cc1' && $post_id === 'options'){
        
            $results = array(
            
                'list' => array(
                
                    'fas' => array(
                        'fas fa-handshake'      => '<i class="fas">&#xf2b5</i> handshake',
                        'fas fa-birthday-cake'  => '<i class="fas">&#xf1fd</i> birthday-cake',
                    ),
            
                ),
            
                'details' => array(
                
                    'fas' => array(
                        'fas fa-handshake' => Array(
                            'hex' => '\f2b5',
                        ),
                        'fas fa-birthday-cake' => Array(
                            'hex' => '\f1fd',
                        )
                    ),
                )
        
            );
            
        }
        
        // Return
        return $results;
        
    }
    

    Video demo: https://i.imgur.com/3BELpnk.mp4

    You should now be able to do what you wanted to do.

    Regards.

    Plugin Author Matt Keys

    (@mattkeys)

    @hwk-fr, wow above and beyond.

    Thread Starter dbrabyn

    (@dbrabyn)

    @hwk-fr Fantastic. Worked perfectly. I’m all set.

Viewing 13 replies - 16 through 28 (of 28 total)
  • The topic ‘Multiple get_icons custom sets on same admin page’ is closed to new replies.