Hey, I’m attempting to register an options page from a custom plugin but for some reason the page won’t register. If I put the same code in my theme file, the options page registers fine. All the other functions in the plugin work fine. But for some reason this doesn’t:
if( function_exists(‘acf_add_options_page’) ) {
$page = acf_add_options_page(array(
‘page_title’ => ‘Theme General Settings’,
‘menu_title’ => ‘Theme Settings’,
‘menu_slug’ => ‘theme-general-settings’,
‘capability’ => ‘edit_posts’,
‘redirect’ => false
));
}
In fact, if I remove the “if function exists” wrapper, I get “Fatal error: Call to undefined function acf_add_options_page() “.
Any idea what’s going on? I’ve registered options like this dozens of times, but for some reason it’s not working today.
I figured it out. Plugins load in alphabetical order. My plugin had “45” in its name, so it was loading before ACF. I renamed it “Forty-five” and problem solved.
More info here: https://wordpress.org/support/topic/how-to-change-plugins-load-order?replies=11#post-1385859
I know that you marked this as a solution, but I wanted to post this for others that find it. You can’t be sure of the order that plugins are loaded unless you activate them in a specific order. Updating a plugin usually causes it to deactivate and reactivate, changing the order of the array mentioned in the link you gave.
It’s better to run a function on a WP hook, for example
add_action('init', 'my_init_function');
function my_init_function() {
if (function_exists('acf_add_options_page')) {
$page = acf_add_options_page(array(
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
}
the plugins_loaded
hook would also work in this case