I am using wp_video_shortcode_override filter in one of my plugins. I would like to make this as on option top user so its not active by default. I have set up following scenario. I need to call wpdb to get some options from my plugin. Is this the good achitecture?
add_action('init', 'foo_init_setup');
function foo_init_setup() {
global $wpdb;
$settings_table = $wpdb->prefix . "foo_settings";
$result = $wpdb->get_row("SELECT options FROM {$settings_table} WHERE id = '0'", ARRAY_A);
$settings = unserialize($result['options']);
$overide_video = (bool)($settings["overide_video"]);
if($overide_video)add_filter('wp_video_shortcode_override', 'foo_video_shortcode_override', 10, 2 );
}
function foo_video_shortcode_override( $html, $attr ) {
//something here
};
I am using wp_video_shortcode_override filter in one of my plugins. I would like to make this as on option top user so its not active by default. I have set up following scenario. I need to call wpdb to get some options from my plugin. Is this the good achitecture?
add_action('init', 'foo_init_setup');
function foo_init_setup() {
global $wpdb;
$settings_table = $wpdb->prefix . "foo_settings";
$result = $wpdb->get_row("SELECT options FROM {$settings_table} WHERE id = '0'", ARRAY_A);
$settings = unserialize($result['options']);
$overide_video = (bool)($settings["overide_video"]);
if($overide_video)add_filter('wp_video_shortcode_override', 'foo_video_shortcode_override', 10, 2 );
}
function foo_video_shortcode_override( $html, $attr ) {
//something here
};
Share
Improve this question
asked Aug 26, 2019 at 15:32
ToniqToniq
4476 silver badges15 bronze badges
1 Answer
Reset to default 1Yes, you can do this like that.
You can call foo_init_setup
on init
or on wp
hook and it will work just fine.
I would call it as late as possible, I guess. This way you won't affect loading time for requests that don't end with page rendering (for example when template_redirect
is used for redirecting).
PS. There is much bigger problem with your code, though. You create custom table and store only one row with serialized array containing options for your plugin.
It would be much nicer, if you used Options API.