Tag Info

Hot answers tagged

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


6

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' );


6

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


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


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


3

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


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

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


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

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

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

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


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

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

Generally, you cannot access local variables in a function from outside the function, so this... function func() { $var = 2; } $var = 1; func(); echo $var; would result in "1". To make a global variable, you can do this to make $option available outside functions.php: function func() { global $option; $option = get_option( 'simple_options' ...


1

You should hook your function to the WordPress AJAX Api. function your_ajax_function() { // your Script here } add_action( 'wp_ajax_your_ajax_function', 'your_ajax_function' ); add_action( 'wp_ajax_nopriv_your_ajax_function', 'your_ajax_function' ); // Skip this line if you want the AJAX just for logged in users Now you can easily call your function ...


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

The function is update_recently_edited in wp-admin/includes/misc.php. unfortunately it is fixed at 5: function update_recently_edited( $file ) { $oldfiles = (array) get_option( 'recently_edited' ); if ( $oldfiles ) { $oldfiles = array_reverse( $oldfiles ); $oldfiles[] = $file; $oldfiles = array_reverse( $oldfiles ); ...


1

You may need to use one of the following configuration parameters: // Don't remove line breaks 'remove_linebreaks' => false; // Convert newline characters to BR tags 'convert_newlines_to_brs' => true; WordPress passes an $init argument array to TinyMCE that sets the opposite value for each of these parameters. I assume you can pass them directly ...


1

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


1

Use the Settings API. A look at my latest plugin may help you to understand how to register a save function for your fields. Most relevant excerpt: /** * Register custom settings for the fields. * * @see save_settings() * @see print_input_field() * @return void */ public function add_contact_fields() { register_setting( 'general', ...


1

Try this: <?php $options = get_option( 'schema_theme_options' ); $meta_desc = $options['metadescription']; ?> <?php if( ( is_home() || is_front_page() ) && '' !== $meta_desc ) : ?> <meta name="description" content="<?php echo $meta_desc; ?>"> <?php endif; ?> It's a bit neater and a bit more foolproof than the ...


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


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 think this should work if you are wrapping the condition around the arguments, and not the menu link itself: if(!is_user_logged_in()) { $args = array( 'exclude' => '100,110,145' ); } else { $args = array( 'exclude' => '100,145' ); } wp_list_pages( $args );


1

In some occasions the_content() will also return blank if a single post/page is viewed and the loop is not initiated. Meaning that you will have to use the code below to be able to see output from the_content. if ( have_posts() ) : while ( have_posts() ) : the_post(); the_content(); endwhile; endif;


1

Fixed my problem! I was finally able to find some info out there in the vast internet. Visit this site for info on fixing this odd issue. Over all using the remove_filter('the_content','wpautop'); did the trick. http://www.undermyhat.org/blog/2009/07/sudden-empty-blank-page-for-large-posts-with-wordpress/


1

Edit: Wow. I mistyped a bunch the first time around. Hopefully nobody read that. All corrected now. /edit I went code spelunking... :) Short version, the workaround would be this: <?php $front_page_id = get_option( 'page_on_front' ); $my_permalink = _get_page_link( $front_page_id ); ?> If you look into link-template.php in the WordPress ...



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