admin管理员组文章数量:1415664
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.
本文标签: pluginsWhen to call addfilter
版权声明:本文标题:plugins - When to call add_filter 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745212174a2647953.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论