Custom plugin: how do I call a PHP file if settings option is set to true?
I am making a custom plugin with various functions that do different things. I have created a settings page using the Settings API to save data to the options db. That works fine. Now I'm trying to turn on/off functions from the settings page, with the below example currently being set to true. If the form value on the settings page equals true, then the function should be called, otherwise it should not be called.
What would be the best approach for this? I'm thinking adding each function as a different php file, and then checking if the option is true and calling the file if necessary. I have added the function to a file called add_id_user_admin.php
, and currently attempting to call it like so:
add_action( 'init', 'switch_functions' ); // Tested and works
function switch_functions() { // Tested and works
if (get_option('new_option_name') == 'true') { // Tested and works
include '/wp-content/plugins/eri-webtools-plugin/includes/theme/functions/add_id_user_admin.php'; // Not working
}
}
Perhaps the file path is the problem, or I should be using a different method of calling the php file? Can't seem to get it to fire the function even though I know the get_option() equals true at the moment.
Topic plugin-options settings-api functions php plugin-development Wordpress
Category Web