get_option( string $option, mixed $default = false )
Retrieves an option value based on an option name.
Contents
Description #Description
If the option does not exist, and a default value is not provided, boolean false is returned. This could be used to check whether you need to initialize an option during installation of a plugin, however that can be done better by using add_option() which will not overwrite existing options.
Not initializing an option and using boolean false
as a return value is a bad practice as it triggers an additional database query.
The type of the returned value can be different from the type that was passed when saving or updating the option. If the option value was serialized, then it will be unserialized when it is returned. In this case the type will be the same. For example, storing a non-scalar value like an array will return the same array.
In most cases non-string scalar and null values will be converted and returned as string equivalents.
Exceptions:
- When the option has not been saved in the database, the
$default
value is returned if provided. If not, booleanfalse
is returned. - When one of the Options API filters is used: ‘pre_option_{$option’}, ‘default_option_{$option’}, or ‘option_{$option’}, the returned value may not match the expected type.
- When the option has just been saved in the database, and get_option() is used right after, non-string scalar and null values are not converted to string equivalents and the original type is returned.
Examples:
When adding options like this: add_option( 'my_option_name', 'value' );
and then retrieving them with get_option( 'my_option_name' );
, the returned values will be:
false
returns string(0) ""
true
returns string(1) "1"
0
returns string(1) "0"
1
returns string(1) "1"
'0'
returns string(1) "0"
'1'
returns string(1) "1"
null
returns string(0) ""
When adding options with non-scalar values like add_option( 'my_array', array( false, 'str', null ) );
, the returned value will be identical to the original as it is serialized before saving it in the database:
array(3) { [0] => bool(false) [1] => string(3) "str" [2] => NULL }
Parameters #Parameters
- $option
-
(string) (Required) Name of the option to retrieve. Expected to not be SQL-escaped.
- $default
-
(mixed) (Optional) Default value to return if the option does not exist.
Default value: false
Return #Return
(mixed) Value of the option. A value of any type may be returned, including scalar (string, boolean, float, integer), null, array, object. Scalar and null values will be returned as strings as long as they originate from a database stored option value. If there is no option in the database, boolean false
is returned.
More Information #More Information
A concise list of commonly-used options is below, but a more complete one can be found at the Option Reference.
'admin_email'
– E-mail address of blog administrator.'blogname'
– Weblog title; set in General Options.'blogdescription'
– Tagline for your blog; set in General Options.'blog_charset'
– Character encoding for your blog; set in Reading Options.'date_format'
– Default date format; set in General Options.'default_category'
– Default post category; set in Writing Options.'home'
– The blog’s home web address; set in General Options.'siteurl'
– WordPress web address; set in General Options.
Warning: This is not the same asget_bloginfo( 'url' )
(which will return the homepage url), but asget_bloginfo( 'wpurl' )
.'template'
– The current theme’s name; set in Presentation.'start_of_week'
– Day of week calendar should start on; set in General Options.'upload_path'
– Default upload location; set in Miscellaneous Options.'users_can_register'
– Whether users can register; set in General Options.'posts_per_page'
– Maximum number of posts to show on a page; set in Reading Options.'posts_per_rss'
– Maximum number of most recent posts to show in the syndication feed; set in Reading Options.
There are many more options available, a lot of which depend on what plugins you have installed.
Source #Source
File: wp-includes/option.php
function get_option( $option, $default = false ) { global $wpdb; $option = trim( $option ); if ( empty( $option ) ) { return false; } /* * Until a proper _deprecated_option() function can be introduced, * redirect requests to deprecated keys to the new, correct ones. */ $deprecated_keys = array( 'blacklist_keys' => 'disallowed_keys', 'comment_whitelist' => 'comment_previously_approved', ); if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) { _deprecated_argument( __FUNCTION__, '5.5.0', sprintf( /* translators: 1: Deprecated option key, 2: New option key. */ __( 'The "%1$s" option key has been renamed to "%2$s".' ), $option, $deprecated_keys[ $option ] ) ); return get_option( $deprecated_keys[ $option ], $default ); } /** * Filters the value of an existing option before it is retrieved. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * Returning a truthy value from the filter will effectively short-circuit retrieval * and return the passed value instead. * * @since 1.5.0 * @since 4.4.0 The `$option` parameter was added. * @since 4.9.0 The `$default` parameter was added. * * @param mixed $pre_option The value to return instead of the option value. This differs * from `$default`, which is used as the fallback value in the event * the option doesn't exist elsewhere in get_option(). * Default false (to skip past the short-circuit). * @param string $option Option name. * @param mixed $default The fallback value to return if the option does not exist. * Default false. */ $pre = apply_filters( "pre_option_{$option}", false, $option, $default ); if ( false !== $pre ) { return $pre; } if ( defined( 'WP_SETUP_CONFIG' ) ) { return false; } // Distinguish between `false` as a default, and not passing one. $passed_default = func_num_args() > 1; if ( ! wp_installing() ) { // Prevent non-existent options from triggering multiple queries. $notoptions = wp_cache_get( 'notoptions', 'options' ); if ( isset( $notoptions[ $option ] ) ) { /** * Filters the default value for an option. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * @since 3.4.0 * @since 4.4.0 The `$option` parameter was added. * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. * * @param mixed $default The default value to return if the option does not exist * in the database. * @param string $option Option name. * @param bool $passed_default Was `get_option()` passed a default value? */ return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); } $alloptions = wp_load_alloptions(); if ( isset( $alloptions[ $option ] ) ) { $value = $alloptions[ $option ]; } else { $value = wp_cache_get( $option, 'options' ); if ( false === $value ) { $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); // Has to be get_row() instead of get_var() because of funkiness with 0, false, null values. if ( is_object( $row ) ) { $value = $row->option_value; wp_cache_add( $option, $value, 'options' ); } else { // Option does not exist, so we must cache its non-existence. if ( ! is_array( $notoptions ) ) { $notoptions = array(); } $notoptions[ $option ] = true; wp_cache_set( 'notoptions', $notoptions, 'options' ); /** This filter is documented in wp-includes/option.php */ return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); } } } } else { $suppress = $wpdb->suppress_errors(); $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); $wpdb->suppress_errors( $suppress ); if ( is_object( $row ) ) { $value = $row->option_value; } else { /** This filter is documented in wp-includes/option.php */ return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); } } // If home is not set, use siteurl. if ( 'home' === $option && '' === $value ) { return get_option( 'siteurl' ); } if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { $value = untrailingslashit( $value ); } /** * Filters the value of an existing option. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * @since 1.5.0 As 'option_' . $setting * @since 3.0.0 * @since 4.4.0 The `$option` parameter was added. * * @param mixed $value Value of the option. If stored serialized, it will be * unserialized prior to being returned. * @param string $option Option name. */ return apply_filters( "option_{$option}", maybe_unserialize( $value ), $option ); }
Expand full source code Collapse full source code View on Trac
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/load.php: wp_installing() |
Check or set whether WordPress is in “installation” mode. |
wp-includes/cache.php: wp_cache_get() |
Retrieves the cache contents from the cache by key and group. |
wp-includes/cache.php: wp_cache_add() |
Adds data to the cache, if the cache key doesn’t already exist. |
wp-includes/cache.php: wp_cache_set() |
Saves the data to the cache. |
wp-includes/l10n.php: __() |
Retrieve the translation of $text. |
wp-includes/formatting.php: untrailingslashit() |
Removes trailing forward slashes and backslashes if they exist. |
wp-includes/functions.php: _deprecated_argument() |
Mark a function argument as deprecated and inform when it has been used. |
wp-includes/functions.php: maybe_unserialize() |
Unserialize data only if it was serialized. |
wp-includes/plugin.php: apply_filters() |
Calls the callback functions that have been added to a filter hook. |
wp-includes/option.php: wp_load_alloptions() |
Loads and caches all autoloaded options, if available or all options. |
wp-includes/option.php: get_option() |
Retrieves an option value based on an option name. |
wp-includes/option.php: pre_option_{$option} |
Filters the value of an existing option before it is retrieved. |
wp-includes/option.php: default_option_{$option} |
Filters the default value for an option. |
wp-includes/option.php: option_{$option} |
Filters the value of an existing option. |
wp-includes/wp-db.php: wpdb::get_row() |
Retrieves one row from the database. |
wp-includes/wp-db.php: wpdb::prepare() |
Prepares a SQL query for safe execution. |
wp-includes/wp-db.php: wpdb::suppress_errors() |
Enables or disables suppressing of database errors. |
Used By #Used By
Used By | Description |
---|---|
wp-includes/block-editor.php: get_default_block_editor_settings() |
Returns the default block editor settings. |
wp-includes/blocks.php: build_query_vars_from_query_block() |
Helper function that constructs a WP_Query args array from a |
wp-admin/includes/plugin.php: deactivated_plugins_notice() |
Renders an admin notice when a plugin was deactivated during an update. |
wp-includes/robots-template.php: wp_robots_noindex() |
Adds noindex to the robots meta tag if required by the site configuration. |
wp-includes/robots-template.php: wp_robots_no_robots() |
Adds noindex to the robots meta tag. |
wp-includes/robots-template.php: wp_robots_max_image_preview_large() |
Adds ‘max-image-preview:large’ to the robots meta tag. |
wp-includes/https-detection.php: wp_is_site_url_using_https() |
Checks whether the current site’s URL where WordPress is stored is using HTTPS. |
wp-includes/https-detection.php: wp_is_https_supported() |
Checks whether HTTPS is supported for the server and domain. |
wp-includes/https-migration.php: wp_should_replace_insecure_home_url() |
Checks whether WordPress should replace old HTTP URLs to the site with their HTTPS counterpart. |
wp-includes/https-migration.php: wp_update_urls_to_https() |
Update the ‘home’ and ‘siteurl’ option to use the HTTPS variant of their URL. |
wp-includes/https-migration.php: wp_update_https_migration_required() |
Updates the ‘https_migration_required’ option if needed when the given URL has been updated from HTTP to HTTPS. |
wp-admin/includes/template.php: get_media_states() |
Retrieves an array of media states from an attachment. |
wp-includes/comment.php: _wp_batch_update_comment_type() |
Updates the comment type for a batch of comments. |
wp-includes/comment.php: wp_check_comment_disallowed_list() |
Checks if a comment contains disallowed characters or words. |
wp-includes/sitemaps/class-wp-sitemaps.php: WP_Sitemaps::sitemaps_enabled() |
Determines whether sitemaps are enabled or not. |
wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php: WP_Sitemaps_Posts::get_url_list() |
Gets a URL list for a post type sitemap. |
wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php: WP_Sitemaps_Posts::get_max_num_pages() |
Gets the max number of pages available for the object type. |
wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::send_plugin_theme_email() |
Sends an email upon the completion or failure of a plugin or theme background update. |
wp-includes/functions.php: wp_timezone_string() |
Retrieves the timezone from site settings as a string. |
wp-includes/media.php: wp_get_registered_image_subsizes() |
Returns a normalized list of all currently registered image sub-sizes. |
wp-admin/includes/template.php: get_post_states() |
Retrieves an array of post states from a post. |
wp-includes/class-wp-recovery-mode-key-service.php: WP_Recovery_Mode_Key_Service::get_keys() |
Gets the recovery key records. |
wp-includes/class-wp-recovery-mode-email-service.php: WP_Recovery_Mode_Email_Service::maybe_send_recovery_mode_email() |
Sends the recovery mode email if the rate limit has not been sent. |
wp-includes/class-wp-recovery-mode-email-service.php: WP_Recovery_Mode_Email_Service::send_recovery_mode_email() |
Sends the Recovery Mode email to the site admin email address. |
wp-includes/class-wp-recovery-mode-email-service.php: WP_Recovery_Mode_Email_Service::get_recovery_mode_email_address() |
Gets the email address to send the recovery mode link to. |
wp-includes/class-wp-query.php: WP_Query::is_privacy_policy() |
Is the query for the Privacy Policy page? |
wp-includes/class-wp-paused-extensions-storage.php: WP_Paused_Extensions_Storage::set() |
Records an extension error. |
wp-includes/class-wp-paused-extensions-storage.php: WP_Paused_Extensions_Storage::delete() |
Forgets a previously recorded extension error. |
wp-includes/class-wp-paused-extensions-storage.php: WP_Paused_Extensions_Storage::get_all() |
Gets the paused extensions with their errors. |
wp-includes/class-wp-paused-extensions-storage.php: WP_Paused_Extensions_Storage::delete_all() |
Remove all paused extensions. |
wp-admin/includes/class-wp-debug-data.php: WP_Debug_Data::debug_data() |
Static function for generating site debug data when required. |
wp-admin/includes/schema.php: populate_network_meta() |
Creates WordPress network meta and sets the default values. |
wp-includes/taxonomy.php: wp_check_term_meta_support_prefilter() |
Aborts calls to term meta if it is not supported. |
wp-includes/script-loader.php: wp_default_packages_vendor() |
Registers all the WordPress vendor scripts that are in the standardized |
wp-includes/script-loader.php: wp_default_packages_inline_scripts() |
Adds inline scripts required for the WordPress JavaScript packages. |
wp-includes/user.php: _wp_privacy_send_request_confirmation_notification() |
Notify the site administrator via email when a request is confirmed. |
wp-includes/user.php: _wp_privacy_send_erasure_fulfillment_notification() |
Notify the user when their erasure request is fulfilled. |
wp-includes/user.php: wp_send_user_request() |
Send a confirmation request email to confirm an action. |
wp-includes/link-template.php: get_the_privacy_policy_link() |
Returns the privacy policy link with formatting, when applicable. |
wp-includes/link-template.php: get_privacy_policy_url() |
Retrieves the URL to the privacy policy page. |
wp-admin/includes/class-wp-privacy-policy-content.php: WP_Privacy_Policy_Content::get_suggested_policy_text() |
Check for updated, added or removed privacy policy information from plugins. |
wp-admin/includes/class-wp-privacy-policy-content.php: WP_Privacy_Policy_Content::notice() |
Add a notice with a link to the guide when editing the privacy policy page. |
wp-admin/includes/class-wp-privacy-policy-content.php: WP_Privacy_Policy_Content::text_change_check() |
Quick check if any privacy info has changed. |
wp-admin/includes/class-wp-privacy-policy-content.php: WP_Privacy_Policy_Content::_policy_page_updated() |
Update the cached policy info when the policy page is updated. |
wp-admin/includes/privacy-tools.php: wp_privacy_send_personal_data_export_email() |
Send an email to the user with a link to the personal data export file |
wp-admin/includes/class-wp-privacy-requests-table.php: WP_Privacy_Requests_Table::get_timestamp_as_date() |
Convert timestamp for display. |
wp-includes/class-wp-roles.php: WP_Roles::get_roles_data() |
Gets the available roles data. |
wp-includes/nav-menu.php: _wp_menus_changed() |
Handle menu config after theme change. |
wp-includes/functions.php: wp_site_admin_email_change_notification() |
Send an email to the old site admin email address when the site admin email address changes. |
wp-includes/customize/class-wp-customize-date-time-control.php: WP_Customize_Date_Time_Control::content_template() |
Renders a JS template for the content of date time control. |
wp-includes/customize/class-wp-customize-date-time-control.php: WP_Customize_Date_Time_Control::get_timezone_info() |
Get timezone info. |
wp-admin/includes/file.php: wp_edit_theme_plugin_file() |
Attempts to edit a file for a theme or plugin. |
wp-includes/script-loader.php: wp_localize_community_events() |
Localizes community events data that needs to be passed to dashboard.js. |
wp-admin/includes/class-wp-community-events.php: WP_Community_Events::format_event_data_time() |
Adds formatted date and time items for each event in an API response. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::update_stashed_theme_mod_settings() |
Update stashed theme mod settings. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::import_theme_starter_content() |
Import theme starter content into the customized state. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::get_item_schema() |
Retrieves the user’s schema, conforming to JSON Schema. |
wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php: WP_REST_Settings_Controller::get_item() |
Retrieves the settings. |
wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php: WP_REST_Settings_Controller::update_item() |
Updates settings for the settings object. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_response() |
Prepares a single post output for response. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::get_items() |
Retrieves a collection of posts. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::get_item_schema() |
Retrieves the comment’s schema, conforming to JSON Schema. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item_permissions_check() |
Checks if a given request has access to create a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item() |
Creates a comment. |
wp-includes/class-wp-taxonomy.php: WP_Taxonomy::set_props() |
Sets taxonomy properties. |
wp-includes/class-wp-taxonomy.php: WP_Taxonomy::add_rewrite_rules() |
Adds the necessary rewrite rules for the taxonomy. |
wp-includes/script-loader.php: wp_localize_jquery_ui_datepicker() |
Localizes the jQuery UI datepicker. |
wp-includes/class-wp-post-type.php: WP_Post_Type::add_rewrite_rules() |
Adds the necessary rewrite rules for the post type. |
wp-includes/class-wp-post-type.php: WP_Post_Type::set_props() |
Sets post type properties. |
wp-includes/class-wp-site.php: WP_Site::get_details() |
Retrieves the details for this site. |
wp-includes/link-template.php: wp_get_canonical_url() |
Returns the canonical URL for a post. |
wp-includes/rest-api/class-wp-rest-request.php: WP_REST_Request::from_url() |
Retrieves a WP_REST_Request object from a full URL. |
wp-includes/functions.php: _wp_upload_dir() |
A non-filtered, non-cached version of wp_upload_dir() that doesn’t check the path. |
wp-admin/includes/class-wp-upgrader.php: WP_Upgrader::create_lock() |
Creates a lock using WordPress options. |
wp-includes/rest-api.php: get_rest_url() |
Retrieves the URL to a REST endpoint on a site. |
wp-includes/embed.php: _oembed_rest_pre_serve_request() |
Hooks into the REST API output to print XML instead of JSON. |
wp-includes/embed.php: get_post_embed_url() |
Retrieves the URL to embed a specific post in an iframe. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_pane_settings() |
Print JavaScript settings for parent window. |
wp-includes/class-wp-customize-setting.php: WP_Customize_Setting::get_root_value() |
Get the root value for a setting, especially for multidimensional ones. |
wp-includes/taxonomy.php: wp_term_is_shared() |
Determine whether a term is shared between multiple taxonomies. |
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::get_index() |
Retrieves the site index. |
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::serve_request() |
Handles serving a REST API request. |
wp-includes/comment.php: wp_handle_comment_submission() |
Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form. |
wp-includes/comment.php: wp_new_comment_notify_postauthor() |
Send a notification of a new comment to the post author. |
wp-includes/option.php: get_network_option() |
Retrieves a network’s option value based on the option name. |
wp-admin/includes/class-wp-screen.php: WP_Screen::render_meta_boxes_preferences() |
Render the meta boxes preferences. |
wp-admin/includes/ajax-actions.php: wp_ajax_delete_inactive_widgets() |
Ajax handler for removing inactive widgets. |
wp-includes/customize/class-wp-customize-nav-menu-setting.php: WP_Customize_Nav_Menu_Setting::update() |
Create/update the nav_menu term for this setting. |
wp-includes/customize/class-wp-customize-nav-menu-setting.php: WP_Customize_Nav_Menu_Setting::value() |
Get the instance data for a given widget setting. |
wp-includes/taxonomy.php: _wp_batch_split_terms() |
Splits a batch of shared taxonomy terms. |
wp-includes/general-template.php: get_language_attributes() |
Gets the language attributes for the ‘html’ tag. |
wp-includes/general-template.php: get_site_icon_url() |
Returns the Site Icon URL. |
wp-includes/formatting.php: format_for_editor() |
Formats text for the editor. |
wp-includes/comment.php: get_default_comment_status() |
Gets the default comment status for a post type. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::search_available_items_query() |
Performs post queries for available-item searching. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::customize_register() |
Add the customizer settings and controls. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::load_available_items_query() |
Performs the post_type and taxonomy queries for loading available menu items. |
wp-includes/rewrite.php: wp_resolve_numeric_slug_conflicts() |
Resolve numeric slugs that collide with date permalinks. |
wp-admin/includes/class-wp-ms-themes-list-table.php: WP_MS_Themes_List_Table::column_name() |
Handles the name column output. |
wp-admin/includes/class-wp-site-icon.php: WP_Site_Icon::delete_attachment_data() |
Deletes the Site Icon when the image file is deleted. |
wp-admin/includes/class-wp-site-icon.php: WP_Site_Icon::get_post_metadata() |
Adds custom image sizes when meta data for an image is requested, that happens to be used as Site Icon. |
wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::column_blogname() |
Handles the site name column output. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::unsanitized_post_values() |
Get dirty pre-sanitized setting values in the current customized state. |
wp-includes/taxonomy.php: wp_get_split_terms() |
Get data about terms that previously shared a single term_id, but have since been split. |
wp-includes/link-template.php: get_avatar_data() |
Retrieves default data about the avatar. |
wp-admin/includes/upgrade.php: wp_install_maybe_enable_pretty_permalinks() |
Maybe enable pretty permalinks on installation. |
wp-includes/user.php: retrieve_password() |
Handles sending a password retrieval email to a user. |
wp-trackback.php: trackback_response() |
Response to a trackback. |
wp-admin/includes/network.php: allow_subdomain_install() |
Allow subdomain installation |
wp-admin/includes/network.php: get_clean_basedomain() |
Get base domain of network. |
wp-admin/includes/network.php: network_step1() |
Prints step 1 for Network installation process. |
wp-admin/includes/network.php: network_step2() |
Prints step 2 for Network installation process. |
wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::send_email() |
Sends an email upon the completion or failure of a background core update. |
wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::upgrade() |
Upgrade a theme. |
wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::bulk_upgrade() |
Upgrade several themes at once. |
wp-admin/includes/class-plugin-upgrader.php: Plugin_Upgrader::bulk_upgrade() |
Bulk upgrade several plugins at once. |
wp-admin/includes/class-plugin-upgrader.php: Plugin_Upgrader::upgrade() |
Upgrade a plugin. |
wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::prepare_items() | |
wp-admin/includes/export.php: export_wp() |
Generates the WXR export file for download. |
wp-admin/includes/class-theme-installer-skin.php: Theme_Installer_Skin::after() |
Action to perform following a single theme install. |
wp-admin/includes/ms.php: upload_space_setting() |
Displays the site upload space quota setting form on the Edit Site Settings screen. |
wp-admin/includes/misc.php: update_option_new_admin_email() |
Send a confirmation request email when a change of site admin email address is attempted. |
wp-includes/user.php: send_confirmation_on_profile_email() |
Send a confirmation request email when a change of user email address is attempted. |
wp-admin/includes/ms.php: wpmu_delete_blog() |
Delete a site. |
wp-admin/includes/image-edit.php: wp_save_image() |
Saves image to post, along with enqueued changes in |
wp-admin/includes/misc.php: wp_check_locked_posts() |
Check lock status for posts displayed on the Posts screen |
wp-admin/includes/misc.php: wp_refresh_post_lock() |
Check lock status on the New/Edit Post screen and refresh the lock |
wp-admin/includes/misc.php: update_recently_edited() |
Update the “recently-edited” file for the plugin or theme editor. |
wp-admin/includes/dashboard.php: wp_welcome_panel() |
Displays a welcome panel to introduce users to WordPress. |
wp-admin/includes/dashboard.php: wp_dashboard_rss_output() |
Display generic dashboard RSS widget feed. |
wp-admin/includes/dashboard.php: wp_dashboard_cached_rss_widget() |
Checks to see if all of the feed url in $check_urls are cached. |
wp-admin/includes/dashboard.php: wp_dashboard_rss_control() |
The RSS dashboard widget control. |
wp-admin/includes/dashboard.php: wp_dashboard_right_now() |
Dashboard widget that displays some basic stats about the site. |
wp-admin/includes/dashboard.php: _wp_dashboard_recent_comments_row() |
Outputs a row for the Recent Comments widget. |
wp-admin/includes/upgrade.php: maybe_disable_link_manager() |
Disables the Link Manager on upgrade if, at the time of upgrade, no links exist in the DB. |
wp-admin/includes/upgrade.php: wp_install_defaults() |
Creates the initial content for a newly-installed site. |
wp-admin/includes/plugin.php: is_uninstallable_plugin() |
Whether the plugin can be uninstalled. |
wp-admin/includes/plugin.php: uninstall_plugin() |
Uninstall a single plugin. |
wp-admin/includes/plugin.php: is_plugin_active() |
Determines whether a plugin is active. |
wp-admin/includes/plugin.php: activate_plugin() |
Attempts activation of plugin in a “sandbox” and redirects on success. |
wp-admin/includes/plugin.php: deactivate_plugins() |
Deactivate a single plugin or multiple plugins. |
wp-admin/includes/plugin.php: validate_active_plugins() |
Validate active plugins |
wp-admin/includes/template.php: _wp_admin_html_begin() | |
wp-admin/includes/template.php: get_settings_errors() |
Fetch settings errors registered by add_settings_error(). |
wp-admin/includes/template.php: iframe_header() |
Generic Iframe header for use with Thickbox |
wp-admin/includes/class-wp-themes-list-table.php: WP_Themes_List_Table::prepare_items() | |
wp-admin/includes/media.php: wp_media_insert_url_form() |
Creates the form for external url |
wp-admin/includes/media.php: media_upload_max_image_resize() |
Displays the checkbox to scale images. |
wp-admin/includes/media.php: get_attachment_fields_to_edit() |
Retrieves the attachment fields to edit form fields. |
wp-admin/includes/media.php: media_upload_form() |
Outputs the legacy media upload form. |
wp-admin/includes/post.php: get_sample_permalink_html() |
Returns the HTML of the sample permalink slug editor. |
wp-admin/includes/post.php: _fix_attachment_links() |
Replace hrefs of attachment anchors with up-to-date permalinks. |
wp-admin/includes/post.php: wp_edit_posts_query() |
Run the wp query to fetch the posts for listing on the edit posts page |
wp-admin/includes/post.php: get_default_post_to_edit() |
Default post information to use when populating the “Write Post” form. |
wp-admin/includes/revision.php: wp_prepare_revisions_for_js() |
Prepare revisions for JavaScript. |
wp-admin/includes/meta-boxes.php: page_attributes_meta_box() |
Display page attributes form fields. |
wp-admin/includes/bookmark.php: wp_insert_link() |
Inserts a link into the database, or updates an existing link. |
wp-admin/includes/bookmark.php: wp_set_link_cats() |
Update link with the specified link categories. |
wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::__construct() |
Constructor. |
wp-admin/includes/nav-menu.php: wp_nav_menu_update_menu_items() |
Saves nav menu items |
wp-admin/includes/nav-menu.php: wp_nav_menu_item_post_type_meta_box() |
Displays a meta box for a post type menu item. |
wp-admin/includes/file.php: request_filesystem_credentials() |
Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem. |
wp-admin/includes/file.php: get_home_path() |
Gets the absolute filesystem path to the root of the WordPress installation. |
wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::__construct() |
Constructor. |
wp-admin/includes/options.php: options_reading_blog_charset() |
Render the site charset setting. |
wp-admin/includes/class-custom-background.php: Custom_Background::wp_set_background_image() | |
wp-admin/includes/class-custom-background.php: Custom_Background::handle_upload() |
Handle an Image upload for the background image. |
wp-includes/class-wp-roles.php: WP_Roles::remove_role() |
Remove role by name. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::register_controls() |
Register some default controls. |
wp-includes/capabilities.php: map_meta_cap() |
Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::setup_theme() |
Start preview and customize theme. |
wp-includes/cron.php: _get_cron_array() |
Retrieve cron info array option. |
wp-includes/category-template.php: wp_list_categories() |
Displays or retrieves the HTML list of categories. |
wp-includes/theme.php: check_theme_switched() |
Checks if a theme has been changed and runs ‘after_switch_theme’ hook on the next WP load. |
wp-includes/theme.php: set_theme_mod() |
Updates theme modification value for the current theme. |
wp-includes/theme.php: remove_theme_mod() |
Removes theme modification name from current theme list. |
wp-includes/theme.php: remove_theme_mods() |
Removes theme modifications option for current theme. |
wp-includes/theme.php: get_uploaded_header_images() |
Gets the header images uploaded for the current theme. |
wp-includes/theme.php: get_theme_root_uri() |
Retrieves URI for themes directory. |
wp-includes/theme.php: get_raw_theme_root() |
Gets the raw theme root relative to the content directory with no filters applied. |
wp-includes/theme.php: switch_theme() |
Switches the theme. |
wp-includes/theme.php: get_theme_mods() |
Retrieves all theme modifications. |
wp-includes/theme.php: get_template() |
Retrieves name of the current theme. |
wp-includes/theme.php: get_stylesheet() |
Retrieves name of the current stylesheet. |
wp-includes/l10n.php: get_locale() |
Retrieves the current locale. |
wp-includes/formatting.php: esc_textarea() |
Escaping for textarea values. |
wp-includes/formatting.php: sanitize_option() |
Sanitises various option values based on the nature of the option. |
wp-includes/deprecated.php: wp_htmledit_pre() |
Formats text for the HTML editor. |
wp-includes/deprecated.php: wp_richedit_pre() |
Formats text for the rich text editor. |
wp-includes/formatting.php: wp_trim_words() |
Trims text to a certain number of words. |
wp-includes/formatting.php: convert_smilies() |
Convert text equivalent of smilies to images. |
wp-includes/formatting.php: balanceTags() |
Balances tags if forced to, or if the ‘use_balanceTags’ option is set to true. |
wp-includes/pluggable.php: get_avatar() |
Retrieve the avatar |
wp-includes/formatting.php: wp_check_invalid_utf8() |
Checks for invalid UTF8 in a string. |
wp-includes/pluggable.php: wp_password_change_notification() |
Notify the blog admin of a user changing password, normally via email. |
wp-includes/pluggable.php: wp_new_user_notification() |
Email login credentials to a newly-registered user. |
wp-includes/pluggable.php: wp_notify_postauthor() |
Notify an author (and/or others) of a comment/trackback/pingback on a post. |
wp-includes/pluggable.php: wp_notify_moderator() |
Notifies the moderator of the site about a new comment that is awaiting approval. |
wp-includes/pluggable.php: wp_set_auth_cookie() |
Sets the authentication cookies based on user ID. |
wp-includes/deprecated.php: noindex() |
Displays a noindex meta tag if required by the blog configuration. |
wp-includes/deprecated.php: wp_no_robots() |
Display a noindex meta tag. |
wp-includes/general-template.php: get_the_modified_date() |
Retrieve the date on which the post was last modified. |
wp-includes/general-template.php: get_the_time() |
Retrieve the time at which the post was written. |
wp-includes/general-template.php: get_the_modified_time() |
Retrieve the time at which the post was last modified. |
wp-includes/general-template.php: wp_get_archives() |
Display archive links based on type and format. |
wp-includes/general-template.php: get_calendar() |
Display calendar with days that have posts as links. |
wp-includes/general-template.php: get_the_date() |
Retrieve the date on which the post was written. |
wp-includes/general-template.php: get_bloginfo() |
Retrieves information about the current site. |
wp-includes/general-template.php: wp_register() |
Display the Registration or Admin link. |
wp-includes/deprecated.php: get_boundary_post_rel_link() |
Get boundary post relational link. |
wp-includes/deprecated.php: get_parent_post_rel_link() |
Get parent post relational link. |
wp-includes/deprecated.php: get_current_theme() |
Retrieve current theme name. |
wp-includes/deprecated.php: make_url_footnote() |
Strip HTML and put links at the bottom of stripped content. |
wp-includes/deprecated.php: get_settings() |
Get value based on option. |
wp-includes/deprecated.php: get_links() |
Gets the links associated with category by ID. |
wp-includes/class-wp-theme.php: WP_Theme::get_allowed_on_site() |
Returns array of stylesheet names of themes allowed on the site. |
wp-includes/class-wp.php: WP::send_headers() |
Sends additional HTTP headers for caching, content type, etc. |
wp-includes/class-wp-query.php: WP_Query::is_front_page() |
Is the query for the front page of the site? |
wp-includes/class-wp-query.php: WP_Query::get_queried_object() |
Retrieves the currently queried object. |
wp-includes/class-wp-query.php: WP_Query::get_posts() |
Retrieves an array of posts based on query variables. |
wp-includes/class-wp-query.php: WP_Query::parse_query() |
Parse a query string and set query type booleans. |
wp-includes/load.php: wp_set_internal_encoding() |
Set internal encoding. |
wp-includes/load.php: wp_get_active_and_valid_plugins() |
Retrieve an array of active and valid plugin files. |
wp-includes/class-wp-http-proxy.php: WP_HTTP_Proxy::send_through_proxy() |
Determines whether the request should be sent through a proxy. |
wp-includes/class-http.php: WP_Http::block_request() |
Determines whether an HTTP API request to the given URL should be blocked. |
wp-includes/functions.php: wp_timezone_override_offset() |
gmt_offset modification for smart timezone handling. |
wp-includes/functions.php: wp_send_json() |
Send a JSON response back to an Ajax request. |
wp-includes/functions.php: smilies_init() |
Convert smiley code to the icon graphic file equivalent. |
wp-includes/functions.php: do_robots() |
Displays the default robots.txt file content. |
wp-includes/functions.php: get_weekstartend() |
Get the week start and end from the datetime or date string from MySQL. |
wp-includes/functions.php: current_time() |
Retrieves the current time based on specified type. |
wp-includes/widgets/class-wp-widget-rss.php: WP_Widget_RSS::widget() |
Outputs the content for the current RSS widget instance. |
wp-includes/widgets/class-wp-widget-recent-comments.php: WP_Widget_Recent_Comments::widget() |
Outputs the content for the current Recent Comments widget instance. |
wp-includes/widgets.php: wp_widget_rss_output() |
Display the RSS entries in a list. |
wp-includes/widgets.php: wp_widgets_init() |
Registers all of the default WordPress widgets on startup. |
wp-includes/taxonomy.php: _get_term_hierarchy() |
Retrieves children of taxonomy as Term IDs. |
wp-includes/taxonomy.php: wp_unique_term_slug() |
Will make slug unique, if it isn’t already. |
wp-includes/taxonomy.php: wp_delete_term() |
Removes a term from the database. |
wp-includes/default-constants.php: wp_cookie_constants() |
Defines cookie-related WordPress constants. |
wp-includes/default-constants.php: wp_ssl_constants() |
Defines SSL-related WordPress constants. |
wp-includes/taxonomy.php: create_initial_taxonomies() |
Creates the initial taxonomies. |
wp-includes/default-constants.php: wp_plugin_directory_constants() |
Defines plugin directory WordPress constants. |
wp-includes/link-template.php: wp_get_shortlink() |
Returns a shortlink for a post, page, attachment, or site. |
wp-includes/link-template.php: get_comments_pagenum_link() |
Retrieves the comments page number link. |
wp-includes/link-template.php: get_home_url() |
Retrieves the URL for a given site where the front end is accessible. |
wp-includes/link-template.php: get_site_url() |
Retrieves the URL for a given site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
wp-includes/link-template.php: get_adjacent_post_link() |
Retrieves the adjacent post link. |
wp-includes/link-template.php: get_adjacent_post_rel_link() |
Retrieves the adjacent post relational link. |
wp-includes/link-template.php: get_post_type_archive_link() |
Retrieves the permalink for a post type archive. |
wp-includes/link-template.php: get_post_type_archive_feed_link() |
Retrieves the permalink for a post type archive feed. |
wp-includes/link-template.php: get_term_feed_link() |
Retrieves the feed link for a term. |
wp-includes/link-template.php: get_post_comments_feed_link() |
Retrieves the permalink for the post comments feed. |
wp-includes/link-template.php: get_author_feed_link() |
Retrieves the feed link for a given author. |
wp-includes/link-template.php: get_permalink() |
Retrieves the full permalink for the current post or post ID. |
wp-includes/link-template.php: get_page_link() |
Retrieves the permalink for the current page or page ID. |
wp-includes/link-template.php: get_attachment_link() |
Retrieves the permalink for an attachment. |
wp-includes/class-wp-ajax-response.php: WP_Ajax_Response::send() |
Display XML formatted responses. |
wp-includes/update.php: wp_update_plugins() |
Checks for available updates to plugins based on the latest versions hosted on WordPress.org. |
wp-includes/update.php: wp_update_themes() |
Checks for available updates to themes based on the latest versions hosted on WordPress.org. |
wp-includes/http.php: wp_http_validate_url() |
Validate a URL for safe use in the HTTP API. |
wp-includes/admin-bar.php: wp_admin_bar_edit_menu() |
Provide an edit link for posts and terms. |
wp-includes/plugin.php: register_uninstall_hook() |
Sets the uninstallation hook for a plugin. |
wp-includes/feed.php: get_the_category_rss() |
Retrieve all of the post categories, formatted for use in feeds. |
wp-includes/feed.php: fetch_feed() |
Build SimplePie object based on RSS or Atom feed from URL. |
wp-includes/option.php: get_transient() |
Retrieves the value of a transient. |
wp-includes/option.php: set_transient() |
Sets/updates the value of a transient. |
wp-includes/option.php: update_option() |
Updates the value of an option that was already added. |
wp-includes/option.php: add_option() |
Adds a new option. |
wp-includes/option.php: get_option() |
Retrieves an option value based on an option name. |
wp-includes/option.php: form_option() |
Prints option value after sanitizing for forms. |
wp-includes/user.php: wp_update_user() |
Update a user in the database. |
wp-includes/user.php: register_new_user() |
Handles registering a new user. |
wp-includes/user.php: wp_insert_user() |
Insert a user into the database. |
wp-includes/user.php: get_blogs_of_user() |
Get the sites a user belongs to. |
wp-includes/bookmark-template.php: _walk_bookmarks() |
The formatted output of a list of bookmarks. |
wp-includes/nav-menu-template.php: _wp_menu_item_classes_by_context() |
Adds the class property classes for the current context, if applicable. |
wp-includes/class-walker-page.php: Walker_Page::start_el() |
Outputs the beginning of the current element in the tree. |
wp-includes/post-template.php: _wp_link_page() |
Helper function for wp_link_pages(). |
wp-includes/post-template.php: wp_list_pages() |
Retrieve or display a list of pages (or hierarchical post type items) in list (li) format. |
wp-includes/post-template.php: wp_page_menu() |
Displays or retrieves a list of pages with an optional home link. |
wp-includes/media.php: wp_enqueue_media() |
Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs. |
wp-includes/media.php: image_constrain_size_for_editor() |
Scale down the default size of an image. |
wp-includes/post.php: _publish_post_hook() |
Hook to schedule pings and enclosures when a post is published. |
wp-includes/post.php: wp_publish_post() |
Publish a post by transitioning the post status. |
wp-includes/post.php: wp_unique_post_slug() |
Computes a unique slug for the post, when given the desired slug and some post details. |
wp-includes/post.php: wp_set_post_categories() |
Set categories for a post. |
wp-includes/post.php: wp_insert_post() |
Insert or update a post. |
wp-includes/post.php: _reset_front_page_settings_for_post() |
Reset the page_on_front, show_on_front, and page_for_post settings when a linked page is deleted or trashed. |
wp-includes/post.php: is_sticky() |
Determines whether a post is sticky. |
wp-includes/post.php: stick_post() |
Make a post sticky. |
wp-includes/post.php: unstick_post() |
Un-stick a post. |
wp-includes/class-wp-rewrite.php: WP_Rewrite::init() |
Sets up the object’s properties. |
wp-includes/class-wp-rewrite.php: WP_Rewrite::set_category_base() |
Sets the category base for the category permalink. |
wp-includes/class-wp-rewrite.php: WP_Rewrite::set_tag_base() |
Sets the tag base for the tag permalink. |
wp-includes/class-wp-rewrite.php: WP_Rewrite::wp_rewrite_rules() |
Retrieves the rewrite rules. |
wp-includes/class-wp-rewrite.php: WP_Rewrite::generate_rewrite_rules() |
Generates rewrite rules from a permalink structure. |
wp-includes/rewrite.php: url_to_postid() |
Examine a URL and try to determine the post ID it represents. |
wp-includes/canonical.php: redirect_canonical() |
Redirects incoming links to the proper URL based on the site url. |
wp-includes/revision.php: _wp_upgrade_revisions_of_post() |
Upgrade the revisions author, add the current post as a revision and set the revisions version to 1 |
wp-includes/ms-functions.php: get_space_allowed() |
Returns the upload quota for the current blog. |
wp-includes/ms-functions.php: maybe_add_existing_user_to_blog() |
Add a new user to a blog by visiting /newbloguser/{key}/. |
wp-includes/ms-functions.php: wpmu_welcome_user_notification() |
Notify a user that their account activation has been successful. |
wp-includes/ms-functions.php: global_terms() |
Maintains a canonical list of terms by syncing terms created for each blog with the global terms table. |
wp-includes/ms-functions.php: newblog_notify_siteadmin() |
Notifies the network admin that a new site has been activated. |
wp-includes/ms-functions.php: wpmu_welcome_notification() |
Notifies the site administrator that their site activation was successful. |
wp-includes/ms-functions.php: wpmu_signup_blog_notification() |
Send a confirmation request email to a user when they sign up for a new site. The new site will not become active until the confirmation link is clicked. |
wp-includes/ms-functions.php: wpmu_signup_user_notification() |
Send a confirmation request email to a user when they sign up for a new user account (without signing up for a site at the same time). The user account will not become active until the confirmation link is clicked. |
wp-includes/ms-blogs.php: get_blog_option() |
Retrieve option value for a given blog id based on name of option. |
wp-includes/nav-menu.php: _wp_auto_add_pages_to_menu() |
Automatically add newly published page objects to menus with that as an option. |
wp-includes/ms-blogs.php: get_blog_details() |
Retrieve the details for a blog from the blogs table and blog options. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::pingback_ping() |
Retrieves a pingback and registers it. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_getOptions() |
Retrieve blog options value from list. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::blogger_getUsersBlogs() |
Retrieve blogs that user owns. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_newComment() |
Create new comment. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getUsersBlogs() |
Retrieve the blogs of the user. |
wp-includes/ms-default-constants.php: ms_cookie_constants() |
Defines Multisite cookie constants. |
wp-includes/class-wp-widget.php: WP_Widget::get_settings() |
Retrieves the settings for all instances of the widget class. |
wp-includes/widgets.php: is_dynamic_sidebar() |
Determines whether the dynamic sidebar is enabled and used by the theme. |
wp-includes/widgets.php: wp_get_sidebars_widgets() |
Retrieve full list of sidebars and their widget instance IDs. |
wp-includes/widgets.php: wp_convert_widget_settings() |
Converts the widget settings from single to multi-widget format. |
wp-includes/comment-template.php: get_post_reply_link() |
Retrieves HTML content for reply to post link. |
wp-includes/comment-template.php: wp_list_comments() |
Displays a list of comments. |
wp-includes/comment-template.php: comment_form() |
Outputs a complete commenting form for use within a template. |
wp-includes/comment-template.php: get_trackback_url() |
Retrieves the current post’s trackback URL. |
wp-includes/comment-template.php: get_comment_reply_link() |
Retrieves HTML content for reply to comment link. |
wp-includes/comment-template.php: comments_template() |
Loads the comment template specified in $file. |
wp-includes/comment-template.php: get_comment_link() |
Retrieves the link to a given comment. |
wp-includes/comment-template.php: get_comment_time() |
Retrieves the comment time of the current comment. |
wp-includes/comment-template.php: get_comment_date() |
Retrieves the comment date of the current comment. |
wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::preview_sidebars_widgets() |
When previewing, ensures the proper previewing widgets are used. |
wp-includes/comment.php: privacy_ping_filter() |
Check whether blog is public before returning sites. |
wp-includes/comment.php: trackback() |
Send a Trackback. |
wp-includes/comment.php: weblog_ping() |
Send a pingback. |
wp-includes/comment.php: _close_comments_for_old_posts() |
Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts. |
wp-includes/comment.php: _close_comments_for_old_post() |
Close comments on an old post. Hooked to comments_open and pings_open. |
wp-includes/comment.php: generic_ping() |
Sends pings to all of the ping site services. |
wp-includes/comment.php: get_comment_pages_count() |
Calculate the total number of comment pages. |
wp-includes/comment.php: get_page_of_comment() |
Calculate what page number a comment will appear on for comment paging. |
wp-includes/comment.php: check_comment() |
Check whether a comment passes internal checks to be allowed to add. |
Changelog #Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
User Contributed Notes #User Contributed Notes
You must log in before being able to contribute a note or feedback.
Handling of non-existing options
A quick tip that the output of
get_option()
is filterable:So you can change the output of
get_option()
at run time.Helpful for disabling specific plugins when required.
https://developer.wordpress.org/reference/hooks/option_option/
Show Blog Title
Displays your blog’s title in a
<h1>
tag.Show Character Set
Displays the character set your blog is using (ex: UTF-8)
Retrieve Administrator E-mail
Retrieve the e-mail of the blog administrator, storing it in a variable.
Check if option is set to avoid warnings.
Was getting Illegal Offset warnings when the checkbox was not selected on a plugin’s option page.
Adding isset() inside checked() sorted it all out.
Hope this helps somebody else out.
Just like we use
to incorporate the date format defined in Settings -> General,
We can also use
to incorporate the time format defined in Settings -> General.
for example
If you want to get a network-wide option, use the get_site_option function instead. https://developer.wordpress.org/reference/functions/get_site_option
There is a “long-hand” format for creating option settings-field parameter in one line that is harder to read/follow semantically, but provides a single string to a options setting instead of two strings for every option.
The above returns false, so technically there is no default to setup unless you require a value.
And there are just a bit less parameter parsing than
Alternatively (if default required):
And for a checkbox in a settings array, try:
This is helpful for assigning defaults values to multiple options:
Expand full source codeCollapse full source code
Usage as the following:
Displaying the option:
Simply way to check the option value set or not.
For Example, I have a plugin version 1.0 that is installed on the user site. The plugin version is set on the plugin activation. If I released a new plugin version 2.0 and need to check the installed plugin version and new apply changes on the new version update.
For it, you need to set default value in function:
So, if option value not set or avaiable than default value assigned to variable.
Sample code:
For use with images includes a default image in child theme folder named default.png and option when adding image using the customizer.
$image = get_option( 'genesis-customizer-image', sprintf( '%s/default.png', get_stylesheet_directory_uri() ) );
check options exists or not, use isset to check
if value exists then checked box appear, if there is no option then unchecked box appears