Articles of hooks

Hook to get image filename when it is uploaded

I want to get the full local filename of an uploaded image so that I can copy it to a new directory and process it with my own image processing scripts. Which hooks/actions should I look into to achieve this? Thanks

Why doesn't wp_enqueue_script() work when including a JavaScript file with TEMPLATEPATH?

I am trying to use tips from here to add my JS file. I put the following in the functions.php of atahualpa theme I’ve got installed function lektor_init() { if (true) { wp_enqueue_script(‘lektor’,TEMPLATEPATH.’/js/synteza.js’); } } add_action(‘init’,’lektor_init’); TEMPLATEPATH has been already used before in there, so I just adapted it. But it doesn’t show up. What […]

Failed to invoke other hook from the init hook

Related to this question (Use wp init hook to call other hooks?) but not the same. Sometimes, I found that the hook will failed to run when I place inside the init hook, e.g. Not Work: add_action(‘init’,’my_init’); function my_init() { add_filter(‘locale’, … } Work: add_action(‘init’,’my_init’); add_filter(‘locale’, … Of course some hooks/filters will just work okay […]

When to use actions and when to use filters

I’m trying to understand where to use filters and where to use actions. Suppose I have a query in a plugin, which later add on modules might modify to change the results of the query, thus modifying the arguments. Would this be an ideal implementation of this concept, or should I be using actions here? […]

Using the 'draft_to_publish' hook (post status transition)

I am trying to use the draft_to_publish hook ( to run a function when a post that is a draft becomes published. This hook does not appear to be working: add_action(‘draft_to_publish’, ‘myFunction’); When I use this in my plug-in, myFunction is never fired. I have used/tested the function before. I know it is the hook, […]

Add action hook conditionally – only when home.php in use

I am trying to add action hook in functions.php only if the page is home.php but the following does not work if ( is_page_template(“home.php”) ) { // do stuff } To make sure that file being used is home.php I do this global $template; echo $template;

How to inject content after <body>

I would like to inject some elements directly after the <body> tag. Is that possible using only WordPress hooks?

Insert all post IDs in new database table

I have a plugin which creates a new database table. Upon activating the plugin is there a way to insert all my posts ids into that table? Right now I’m using an action hook to immediately insert the id of new posts I publish. function transfer_post_id($post_ID) { global $wpdb; if (!($wpdb->get_row(“SELECT post_id FROM $my_table WHERE […]

Execute function when post is published

I try to use this function i have created when a post is published for the first time. function a_new_post($post){ $post_id = $post->ID; if ( !get_post_meta( $post_id, ‘firstpublish’, $single = true ) ) { // …run code once update_post_meta( $post_id, ‘firstpublish’, true ); } } add_action( ‘draft_to_published’, ‘a_new_post’ ); I can’t see anything wrong with […]

Disable HTML (Text) Tab in Post Editor

I am attempting to disable the Text tab in the post editor but not having any luck. The first thing I want to do is set the Visual editor to be the default but this code does not work (it is being called from a MU plugin): apply_filters( ‘wp_default_editor’, ‘tinymce’ ); Next, I want to […]