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"></i> handshake',
'fas fa-birthday-cake' => '<i class="fas"></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.