Tag Info

Hot answers tagged

32

@Arlen: As Keith S points out Adam Brown's List of Hooks is the defacto resource of hooks for WordPress. However, it's not perfect: It doesn't show the hooks in order of when they are called, It doesn't provide file name or line number where invoked, It doesn't provide a number of arguments passed, It's not a complete list because some hooks can be called ...


20

You should run the code after theme setup. function osu_twentyten_continue_reading_link() { return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>'; } function osu_twentyten_auto_excerpt_more( $more ) { return ' &hellip;' . ...


8

If you are building this for a single client, you should absolutely take advantage of mu-plugins. There are a lot of things in WordPress that you can't do in functions.php. Pluggable functions is one of them, but more obvious, a number of hooks (both actions and filters) fire before functions.php. In some cases, these hooks even fire before regular plugins, ...


6

Not really, no. You can override built-in PHP functions, but not user-defined functions. However, all this function does is define a meta box. Why not define your own? Once you've got your own meta box defined and added, you can call remove_meta_box to remove the standard one: remove_meta_box( 'add-POSTTYPENAME', 'nav-menus', 'side'); The meta box is ...


5

In the context of a once-off project, it is absolutely appropriate to drop must-use code into mu-plugins. If "having it all in once place" is a concern, just make a symlink in the theme dir to the mu-plugins drop-in, so it'll show up when searching the theme directory.


5

You're on the right track with creating the plugin. All your assumptions are correct. To avoid errors on activation you'll want to wrap the functions that you are redefining in function_exists blocks, as on activation those functions will already be defined: if ( ! function_exists( 'wp_hash_password' ) ) : function wp_hash_password( $password ) { ...


4

WordPress never makes any HTTP requests for gravatars, it just generates URLs to them. You don't really need to override function completely. You can filter get_avatar hook and return different URL if email matches user with custom avatar set.


4

Both the header and background image features setup some globals in order to work, unsetting those globals seems to have some effect, and at the least removes them from the administration side. add_action('after_setup_theme', 'remove_theme_features', 11 ); function remove_theme_features() { $GLOBALS['custom_background'] = 'kill_theme_features'; ...


4

There's actually a filter that you can use, see abstract-wc-email.php, line 214: return apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object ); you can put the following in your functions.php: add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2); ...


4

And there is another filter that will give you access to the $header variable which can allow you to BCC your emails so that you get a carbon copy of every email that goes to your clients on Woocommerce. This is just as easy as the code above except your clients will not see your email address. Just like the solution above you would add the following code: ...


4

Wrap your function in if( ! function_exists( 'wp_authenticate' ) ) to get rid of the error and successfully activate your plugin: if( ! function_exists( 'wp_authenticate' ) ){ function wp_authenticate(){} } This is necessary because in the context of activating a plugin, the function does already exist, only after it is activated will your plugin load ...


3

To prevent the comment deletion hook into before_delete_post, and filter the query for associated comments so the deletion routine cannot find and delete those. PHP 5.3 required: add_action( 'before_delete_post', function( $post_id ) { add_filter( 'query', function( $query ) use ( $post_id ) { $find = 'WHERE comment_parent = '; FALSE ...


3

There is no security risk in a pluggable function: If someone installs a plugin that lowers the security it is his/her own fault. On the other hand, you can override the functions to make nonces more unique or to change their format. In a custom function wp_verify_nonce() you could use an optional third parameter or change the time a nonce expires. ...


3

It depends entirely on a) what functions and template files you're talking about, and b) how those functions are defined, or template files are called, in the Parent Theme. If the Parent Theme uses get_template_part(), then you're golden. If the Parent Theme uses get_stylesheet_directory_uri() or STYLESHEETPATH, then you can override, with caveats. If the ...


2

You can use the show_option_all argument: <?php $args = array( 'show_option_all' => 'Categories' ); wp_dropdown_categories( $args ); ?> Function Reference/wp dropdown categories


2

Debug Bar Action Hooks plugin Displays a list of actions fired for the current request. Requires the debug bar plugin.


2

I suggest to check out Get the Image plugin. Basically it is single function that acts as flexible and configurable wrapper to mine posts for images via different methods (post meta fields, featured images, attached images, images in post body).


2

So the solution to the get_comments_pagenum_link() function is straightforward enough: add_filter('get_comments_pagenum_link' , 'new_get_comments_pagenum_link'); function new_get_comments_pagenum_link($content) { $content = str_ireplace('#comments' , '#other', $content); return $content; } Which filters the output of get_comments_pagenum_link() to ...


2

As noted in the trac ticket, you need to add that UI element in yourself. If you're still looking for it, I made a plugin to add custom post type sticky support, available here: http://www.superann.com/sticky-custom-post-types/


2

The Codex has an Action Reference and a Filter Reference. Adam Brown created a hook database that has all hooks in the source code, and adds the documentation from the wiki pages, version information and links to the source code. You can improve it by writing documentation in the Codex. Of course, some hooks are dynamic, depending on other data. Take the ...


2

Child theme is processed before parent theme. So your function is getting hooked earlier and fires before twentyten_setup(). Try: add_action( 'after_setup_theme', 'my_child_theme_setup', 11 ); Alternatively you can copy twentyten_setup() to your child theme and modify, since it is declared conditionally on ! function_exists( 'twentyten_setup' )


2

If the rest of your function works you just need to add a call to wp_safe_redirect and hook the whole thing into WordPress. I think that the first hook that will have a populated $wp_query is wp. So alter the last part of your function... if($max_page < $paged){ wp_safe_redirect(get_bloginof('url'),'301'); } And then add the following after ...


2

You can't do this: wp_redirect( get_permalink($pid)); after you've already sent content to the browser. Headers were already sent, and wp_redirect is attempting to send a header again. The first three lines of the template you pasted above are all sending content to the browser, when you close and open php. evidently your header.php file is doing the ...


1

When do Plugins load? Plugins are loaded right before the plugins_loaded hook. MU-Plugins (this is what every pluggable imho should be), are loaded even earlier, before the muplugins_loaded-hook. (Both are the first hooks for plugins and run much earlier than every hook accessible for themes). What exactly are Pluggables? "Pluggables" are called like ...


1

Functions, which aren't wrapped inside functions_exists() calls, are not meant to be pluggable. If you're searching for extensions, then use filters or hooks - in case there're some. As you can read in the phpDocBlock: Ensure that the welcome message is not empty. Currently unused. So this filter won't work. I'm no MU expert, but maybe you can make ...


1

The problem is that you're trying to load the code directly rather than with a WordPress hook. WordPress loads a bunch of code in a specific order (you can see the list of actions fired in a typical request in the Codex). By trying to fire your code directly, you're executing just before pluggable.php is loaded. And you should not try to include() this ...


1

Note: This is the merged version between my and @toscho answers. Explanation (by @toscho) Use add_meta_boxes_page as action hook. You can find the hook in wp-admin/edit-form-advanced.php and it displays as: do_action('add_meta_boxes_' . $post_type, $post); Solution(s) Try the following action, which is inside register_post_type() as well. function ...


1

You should not and do not need to write to pluggable.php (or any other core WordPress file). You can override a pluggable function simply by defining it in your plug-in's files (or for themes, functions.php). These get loaded before pluggable.php, and so the function definition given in your plug-in file is used in preference to that in pluggable.php. ...


1

remove_theme_support should do the trick. EDIT- It seems custom headers & custom backgrounds have their own functions for this: Custom Headers . I assume the same type of function should be for custom backgrounds, but I can't find it in the reference, searching for it in the files. EDIT 2 - The remove_custom_image_header function is available only ...


1

Here is the solution to my problem for anyone who is interested. Include this in your functions.php file require_once('custom/extract-post-thumbnail.php'); $extract_img = new extract_post_image(); add_filter( 'post_thumbnail_html', array(&$extract_img, 'get_post_image'),1,5 ); Create a new file and name it "extract-post-thumbnail.php", place ...



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