Tag Info

Hot answers tagged

15

Yes, sort of. When the get_option call is made, WordPress runs a function called wp_load_alloptions, which either grabs a cached copy of all autoloaded options or loads all those options into the cache. Then wp_load_alloptions returns an array of all the autoloaded options. If your option is autoloaded (specified when you use the add_option function), it ...


9

We have to look a bit deeper here to get an answer to your question. So, bloginfo is a simple wrapper around get_bloginfo. <?php function bloginfo( $show='' ) { echo get_bloginfo( $show, 'display' ); } Notice the second argument display. Let's see what that does. <?php function get_bloginfo( $show = '', $filter = 'raw' ) { // snip snip, ...


7

Usually I remove the filter, then add it back on afterwards; function _my_custom_option( $option ) { remove_filter( 'pre_option_name', '_my_custom_option' ); // do what you like with $option add_filter( 'pre_option_name', '_my_custom_option' ); return $option; } add_filter( 'pre_option_name', '_my_custom_option' );


4

Widgets can be used multiple times. Your options will be passed to the widget directly and automatically, as part of the $instance variable. You should not be getting the options directly using get_option. The widget() function declaration in a WP_Widget derived class looks like this: function widget( $args, $instance ) The $instance variable will be ...


4

I didn't find much information about how the autoloaded values are used. There is no special case for autoloaded options, they are used in the same way as else regular options, but lets figure out what autoload column of the options table means. This column determines do we need to fetch an option at the initialization stage of a request or should we ...


4

No, this won't work: <?php echo get_option('notice_data[Message]'); ?> Because get_option pulls whole option value by option_name, it doesn't pull by pieces of the serialized array. What you are asking for is a key (option_name) called literally notice_data[Message]. Assuming you've saved the option as notice_data you aren't going to get a match, ...


4

Pull the add_action() outside of the function, and put the conditional inside the callback. Also, if you're printing a script directly, use wp_print_scripts instead of wp_head. You also have a syntax error. function testingone(){ if( get_option( 'MyOptionName' ) ) { ?> <script>var Script = GoesHere; </script> ...


4

The two functions output exactly the same thing. From the Codex entry for get_bloginfo(): 'name' - Returns the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. From source: case 'name': default: $output = get_option('blogname'); Neither get_bloginfo() nor bloginfo() do any sort ...


3

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 ...


3

Try turning your code around: function testingone() { if( FALSE !== get_option( 'MyOptionName' ) ) { echo( 'ok, this is in the head!' ); } } add_action( 'wp_head', 'testingone' ); As well, check in your theme's files (most likely header.php) to make sure that the wp_head() function is being called, and make sure that the MyOptionName ...


3

When in doubt, look at the source code. Digging in to get_option(), you'll see (abbreviated): $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 ...


3

The process of saving option conveniently offers filter for new value, with access to old value as well. We only need to combine both and give it to WP as value to save: add_filter( 'pre_update_option_recently_edited', 'increase_recently_edited_list', 10, 2 ); function increase_recently_edited_list( $newvalue, $oldvalue ) { return array_slice( ...


3

How plugins loading works WordPress has, as any other software, a specific order in which files get loaded. During loading WPs core files, there're specific points where you can either hook into do_action() or alter data during apply_filters() calls. Those functions always get called with a minimum of one argument: The name. Sometimes there're more ...


2

No, only the options that are specifically loaded with autoload set to true See http://codex.wordpress.org/Function_Reference/add_option So if it is an option that is needed on every page, when you add it to the db, set autoload=true. After that, just use get_option normally - wp will handle the cacheing etc.


2

WordPress load is complicated process and hard to grasp in full. The very basic overview would be like this. What you should do for starters - think in specifics. A lot of common tasks (adding scripts, using hooks, etc) are standardized technically or conventionally. So go by task - decide what you want to do and search (and ask if search fails you) what is ...


2

<?php $user_id = 9; $key = 'last_name'; $single = true; $user_last = get_user_meta( $user_id, $key, $single ); echo '<p>The '. $key . ' value for user id ' . $user_id . ' is: ' . $user_last . '</p>'; ?> More information here - http://codex.wordpress.org/Function_Reference/get_user_meta


2

Actually, there's not too much you can do. If an intruder has direct access to your site - where they can run get_option() or perform direct SQL queries - then you've already run into a problem. The safest bet here is to exercise your best judgement when installing new plugins. In other words, the best plan of action is prevention. Don't install plugins ...


2

Define an array of parameters to be injected into the script: $script_params = array( 'myWidth' => get_option('my_width') ); Localize the script via wp_localize_script: wp_localize_script( 'your-script-handle', 'scriptParams', $script_params ); scriptParams now is a js object you can access from within the script: alert( scriptParams.myWidth ); ...


2

If you're building something for public consumption (a plugin, a theme, etc) use admin-ajax.php like you should because that is the appropriate and accepted way to do things and gives your end users the power they need to change and modify things if they so choose. Beyond that, the best you MAY be able to do is use the SHORTINIT constant. Define it in a ...


1

To store Data use this Code : save the serialize values $title = 'Your Title Value'; $message = 'Your message HTML..'; $image = 'http://www.domain.com/yourimage.jpg'; $notice_data = array('title' => $title, 'message' => $message, 'image' => $image ); ...


1

get_option() returns a string, it doesn’t print anything. You have to use echo or print. But you should use home_url() instead, because this takes care of the proper scheme (http or https): echo esc_url( home_url() ); Or, in case of the log in URL: echo esc_url( wp_login_url() );


1

Two possible solutions here- Solution one is to not hardcode the modal markup into the template and instead use the wp_footer action to insert it, along with your data: function wpa_wp_footer(){ $someval = 'foo'; // get_option results echo '<div id="modalpopup"><div id="inside">' . $someval . '</div></div>'; } add_action( ...


1

You would still do this with AJAX, except that instead of firing on some event like a 'click', or 'hover', or submit, you would fire the Javascript function on jQuery(document).ready instead. That will execute immediately on page load. It doesn't let you execute the code before the page loads as your question states but you can't run Javascript before the ...


1

The shortest way is to load wp-load.php and abort the loading of the template engine (Note: You couldn't do that, if you'd be loading the header file, like you see it on many sites in the interweb). # No need for the template engine define( 'WP_USE_THEMES', false ); # Load WordPress Core // Assuming we're in a subdir: "~/wp-content/plugins/current_dir" ...


1

First of all, bloginfo will output value ;) If you want to get the value, you should use get_bloginfo. get_bloginfo takes one param from predefined set (You can find all possible values here: http://codex.wordpress.org/Function_Reference/bloginfo). Only part of these values are values of options (in such case bloginfo returns value of that option). ...


1

I found a solution!!! <li class="tweat"> <a href="<?php $globalOptions = get_option('global_options_arraykey'); echo $globalOptions['twitterid'];?>">Visit our twitter Account</a> </li> I got it from this site: Get Option for an Element in an array - WordPress-Hackers


1

If you just want to get rid of the \ characters in the string that's returned, you can use PHP's stripslashes(): $content = stripslashes( $content ); I'd recommend doing this on output rather than on input; WordPress adds the slashes as it sanitizes your data on insert, per update_option()'s Codex page, The $option (option name) value is escaped with ...


1

Here is how I do it, beware, post is extensive. /* Add Menus -----------------------------------------------------------------*/ add_action('admin_menu', 'ch_essentials_admin'); function ch_essentials_admin() { /* Base Menu */ add_menu_page( 'Essentials Theme', 'Essentials Theme', 'manage_options', 'ch-essentials-options', ...


1

Try if ( 'page' == get_option( 'show_on_front' ) ) {}. Edit but I've tried adding and replacing <?php endwhile; endif; elseif (is_home()): ?> with both of your code. Could you perhaps include your snippet with mine? I'm not sure why you would do that. I was specifically answering this question: But what if a page (instead of the 'blog') is ...


1

I'm guessing that you are using language tags around 'polish textdeutschland text' i.e. <!--:pl-->polish text<!--:--><!--:de-->deutschland text<!--:--> but that they got ignored when you posted your answer. I'm pretty sure what you need to be doing is using the __() (which returns the translation for use in php code) and _e() (echo's ...



Only top voted, non community-wiki answers of a minimum length are eligible