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 fix a Wordfence scan that doesn’t finish?
- Disable woocommerce cookies and delete cart data automatically
- className not populating in custom block
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Run plugins only on certain pages
- Add Plugin options as subpage to Theme options page
- changes to widget settings not showing up in individual pages pages until they’re updated [closed]
- Overide plugin files from child theme (/inc/ ) folder
- wp_generate_attachment_metadata is creating an empty array
- Show admin notice on incorrect value on form field
- custom payment gateway in woocommerce failed to connect to remote api server
- Display encrypted content on my website
- How to remove traces from widget during uninstallation
- Post category with counts been display like a menu
- Post custom Data value in The Events Calendar plugin [closed]
- Send reply with pre-prepared answers
- Best way to maintain and update 3rd-party WP plugin when developer is unresponsive?
- Save custom attributes of product in woocommerce
- Calling an attribute from a plugin shortcode
- Best place for short bio,image and button [closed]
- Use of Templates in a Plugin
- Why can’t I access my Intranet LDAPS with NADI?
- php page not found for plugin options menu
- External Domain on WordPress Multisite
- In the archive widget, how do I sort in between two years?
- Customization API for plugin development
- Fromcraft Plugin On click submit button [closed]
- add tabs in rdp-plugin/includes/settings.php and get settings saved
- creating a custom shop page display on archive woocommerce
- Enabling plugin failed because MySQL user do not have CREATE permissions
- Setup page on first login on multisite
- polylang + category/tag custom language link
- Anspress Customization: How to show logged in user votes on a single answer?
- Custom wordpress Theme and Plugin repository
- Automatic Updates Individual Plugins Not Working
- How do I make a child theme I made POST through a 3rd party plugin?
- wp_editor content in plugin options page
- How create Group Blogs based on user created Groups
- How to redirect users to their profile after they successfully edit their profile
- Custom table naming/access convention for multisite: $table_prefix vs base_prefix or other?
- Add ALT attribute to Pin It Button image to pass HTML5 validation
- date/time-picker and file upload (image) fields for custom fields (e.g. with more fields)
- Getting Theme element into plugins page editor in wp admin
- WordPress as web application base
- options creation for plugins
- Customize The Events Calendar to Include an Option to Expand for More Events Listings
- URL rewrite of independent plugin?
- Plugin for users to create their own ads like Google Adsence
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- How do I apply style to each category of a list?
- How to create an option page for this simple plugin
- Add category selection to custom post type (plugin)
- changing posts layout in ultimate member profile 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
- Login Customizer doesn’t change the background of the register form
- Inserting custom PHP script on homepage
- Creating Featured Content Boxes
- Integrating WP E-commerce plugin into custom theme
- Best practice for including plugin output in a template without using shortcode?
- Custom post types – remove default post supports through empty array?
- Basic gallery plugin suggestion [closed]
- Gathering and logging data from a plugin: how to do it without race conditions?
- Update a core option from plugin settings page
- WordPress error: Options page Setting_ not found in the allowed options list
- a weird attribute on every html tag
- How can I run a custom shortcode function on a live site and only run if the viewer is a specific machine?
- Can I use register_settings and unregister_setting once the settings page has loaded?
- Contact Form 7 – Form name blank [closed]
- update_option_{$option} not showing old value
- How do i get file_get_contents to work in wordpress
- Custom widget doesn’t save values from dropdown box
- Plugin Development – Functions or Hooks?
- Updating options into the wp database performance
- Can deactivating a plugin sometimes “reset” settings within that plugin?
- Allowed memory size exhausted problem
- Plugin function inside custom plugin
- WordPress as template engine
- How to change the wp_upload_dir() path in plugin
- Plugin getting Cannot modify header information errors
- How to add options to the plugin page?
- Saving widget options from class method
- How to prevent plugins from sniffing/stealing other plugins’ options?
- Add some fileds to the wp_posts table
- Customizing Titles on the Fly with Code
- Default plugin config to override wp_options?
- Disable plugin only for one post
- Free paypal cart solution [closed]
- Add filter on html tags,attributes on specific function in wordpress
- Which plugin can do horizontal scrolling of RSS feeds in WordPress [closed]
- When I try to de-activate any plugin it gives error “Warning: call_user_func_array() [function.call-user-func-array]”