Both ways are almost equal, the first will be slightly faster, because the callback is called only if the check equals to TRUE
.
Note you cannot test an option like this, unless the option name is really 'my_option[option_1]'
. What you probably want is:
if ( $test = get_option('my_option') and 1 === $test['option_1'] )
add_action();
An extended example:
$my_options = get_option('my_option');
if ( 1 === $my_options['test_1'] )
add_action( 'init', 'my_init' );
if ( 1 === $my_options['test_2'] )
add_action( 'shutdown', 'my_shutdown' );
// clean up
unset( $my_options );
Related Posts:
- Add custom meta box on Post page
- clean wp_options table unused rows
- Redirect to another page using contact form 7? [closed]
- Change the style of h1, h2, only in post entry
- Changing the CSS with a plugin
- save short-code in my custom plugin settings problem missed something
- Echo custom admin field into a is_single()
- Manual Backup – How to save to Firefox or Chrome (instead of IE which brings up popup I can’t get rid of)
- How to implement a customizable free OpenID authentication?
- Difference between add_filter and apply_filters
- Creating Unique Post URLs for A/B Testing… Is this even possible?
- How to delete the Hello Dolly plugin automatically?
- How to enable edit button in the theme’s customize UI?
- How to tell if plugin has been network activated
- Delete Post With No Traffic?
- Automatically Creating Posts for Popular Forum Topics or Products [closed]
- Generate custom output for page/URL in a plugin
- What’s the recommended process for organising collaborative posting?
- How to list the Hooks and order of execution in current loading page? [duplicate]
- Updating post meta for custom post types
- Some Plugin Settings Are Kept After Removal and Reinstall of the Plugin
- While Using Static Pages, How Can I Get /blog into the URL of Each Post?
- Is there a plugin to display certain posts on certain pages? [closed]
- Get all options saved by another plugin
- REST-API: extend media-endpoint
- Is it ok to call get_option without hooks?
- Enable/Disable WP options programmatically
- How to make sexy bookmarks plugin work in WPMU
- register_post_status invisible but searchable
- I need some direction on how to have a sidebar based on meta rather than page
- Can’t create term for product attribute
- WordPress and WebRTC?
- Getting Post details when post is published
- Plugin Customization Lost During Plugin Upgates
- Set the active Navigation Menu from a plugin
- Serialize data for wp options
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- Custom Field Template seriously messed up in WP 3.1.1
- Plugin upgrade issue
- How to add a default value to get_option if it’s used as a variable?
- My plugin wants to update another plugin
- I have no idea “How change font for elements in widget?”
- What’s the best way to implement AJAX in WordPress?
- Display encrypted content on my website
- How to remove traces from widget during uninstallation
- Save custom attributes of product in woocommerce
- How do I make a child theme I made POST through a 3rd party plugin?
- Add category selection to custom post type (plugin)
- get_option error plugin development
- “No Add Button” for me to customize my WordPress with themes and pluggins
- Translation plugin to translate another plugins
- Contact Form 7 – Form name blank [closed]
- Add some fileds to the wp_posts table
- Customizing Titles on the Fly with Code
- Text change in Advanced Customs Fields [closed]
- Loop in elementor custom widget not working
- OceanWP settings are missing from Add New Post [closed]
- Historical customisations won’t go away [closed]
- .php file for woocommerce edit category? [closed]
- Plugin scheduled event not working
- How do you add a settings page to another menu?
- How to display an alert when deleting a plugin?
- unregister a sidebar widget
- Custom content plugin for front page in wordpress
- How to disable Wp-PageNavi at the top of the page
- 404 errors when updating options in admin dashboard
- Display WordPress comments before the plugins?
- Mobilepress fails to translate short codes
- How to make sure settings are not lost when plugin is updated?
- woocommerce remove coupon link does not work
- Getting infinite scrolling working on my custom template
- Display posts by alphabetical order
- Adding discount functionality to the cart
- Precheck fields when I add a new post
- Custom wp_list_tables redirect on specfic page
- Paid Membership Pro displaying a user name in PHP
- Optimized PHP & WordPress settings for speed/performance?
- Automatically check “Enable stock management at product level” to the existing products?
- The etiquette of forking a plugin and table tag
- Creating Nested custom fields
- Confusing problem with displaying message recipient metadata
- WordPress update plugin through Dashboard/Plugins displaying error
- Plugin does not create a custom table upon activation
- get_option returning old value for non-admin users
- Disable default posts (Posts,Pages,Comments and Media) in wp-admin
- Plugin program: JQuery not working in this plugin
- how to protect wordpress website
- admin panel save option with ajax
- homepage olderposts link showing page not found
- Get page type to display content
- How to fix vanilla comments extra iframe space
- Woocommerce quick checkout form [closed]
- How to add image for custom taxonomy
- Social network plugins for WordPress [closed]
- Why haven’t I see plugins using get_file_data to handle retrieving plugin version?
- Wrapping code in an if block
- How can I properly sanitize the update_option in WordPress?
- Create Custom Coupon Type
- Is website for online game guides doable in WordPress? [closed]
- Using ACF to allow user to add and edit multiple saved forms