get_option [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Retrieve option value based on name of option.
If the option does not exist or does not have a value, then the return value will be false. This is useful to check whether you need to install an option and is commonly used during installation of plugin options and to test whether upgrading is required.
If the option was serialized then it will be unserialized when it is returned.
Source
<?php
function get_option( $option, $default = false ) {
global $wpdb;
// Allow plugins to short-circuit options.
$pre = apply_filters( 'pre_option_' . $option, false );
if ( false !== $pre )
return $pre;
$option = trim($option);
if ( empty($option) )
return false;
if ( defined( 'WP_SETUP_CONFIG' ) )
return false;
if ( ! defined( 'WP_INSTALLING' ) ) {
// prevent non-existent options from triggering multiple queries
$notoptions = wp_cache_get( 'notoptions', 'options' );
if ( isset( $notoptions[$option] ) )
return apply_filters( 'default_option_' . $option, $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
$notoptions[$option] = true;
wp_cache_set( 'notoptions', $notoptions, 'options' );
return apply_filters( 'default_option_' . $option, $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
return apply_filters( 'default_option_' . $option, $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') ) )
$value = untrailingslashit( $value );
return apply_filters( 'option_' . $option, maybe_unserialize( $value ) );
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- get_option - WordPress Codex
Description. A safe way of getting values for a named option from the options database table. If the desired option does not exist, or no value is associated with it, ...
codex.wordpress.org - WordPress › Support » get_bloginfo or get_option
It kind of doesn't matter as in most cases, get_bloginfo is just a wrapper for get_option , but in the case of get_option('wpurl'); nothing will be returned. Internally ...
wordpress.org - customization - How to use get_option() without any filter ...
get_option() is working correctly in any php WordPress file or template, but not in my AJAX... EDIT: In template: $.post('<?php echo get_bloginfo( 'template_url' ); ...
wordpress.stackexchange.com - Call to a member function get_option() on a non-object in views ...
PHP Fatal error: Call to a member function get_option() on a non-object in /var/ www/html/modules/views/includes/view.inc on line 1904, referer: ...
drupal.org
Kullanýcý Tartýþmalarý [ wordpress.org ]
- sandraqu on "if homepage, then get_option homepage"
- anthonycamilleri on "Fetching Values using Options API within TinyMCE Popup"
- vtxyzzy on "get_options"
- khris.sh on "get_options"
- teka34 on "get_option() error"
- chris.foxy on ""Call to undefined function get_option()" from another plugin script"
- Andrea_r on "Clone theme settings"
- expromo on "Clone theme settings"
- ethanhackett on "How to create radio button in options page?"
- deewilcox on "Problem calling Cufon option from theme-options.php"