Hooks a function on to a specific action. Actions are (usually) triggered when the WordPress core calls do_action().
7
votes
2answers
934 views
Why do some hooks not work inside class context?
I'm pretty stumped on this one. I'm using add_action inside my plugin class to do certain things- add scripts & styles to the head, wp_ajax, etc. Here's the actions, in the __construct:
function ...
6
votes
2answers
708 views
Extract image from content and set it as the featured image
The problem:
I'm posting from the Wordpress iPhone app. When adding an image, the image shows up in the description itself, which I don't like.
What I'm trying to do:
Remove the image from the ...
5
votes
3answers
1k views
Conditional wp_enqueue_script on a page
For efficiency we are trying to hook some JS scripts only a certain page template of a theme that is to hold a form: page-with-form.php
On the theme functions.php we've defined a init_method as ...
5
votes
1answer
160 views
How to create an API for my plugin?
I have been developing plugins for WordPress. Most plugins I have developed with two three classes and not so huge like Buddypress, WooCommerce or etc.
I am planning to make two open source plugins ...
5
votes
3answers
1k views
How to know what functions are hooked to an action/filter?
Is there a way to know what functions are hooked to a particular hook? For example if I'd like to know what functions are hooked to the wp_head hook.
Thanks in advance.
4
votes
2answers
984 views
Does an activated plugin automatically mean its methods are available to other WP functions?
I made a WordPress plugin like this:
Class MY_CLASS {
//codes
}
Global $myclass;
$myclass = New MY_CLASS ();
After installed and activated the plugin, can I use this class in other plugins without ...
4
votes
5answers
484 views
Implementing advanced add_* function wrappers
add_action() and add_filter() are major functions. However in some scenarios add one more function and hook it somewhere approach gets bulky and inconvenient.
I had determined for myself several use ...
4
votes
1answer
492 views
How to override existing plugin action with new action
I'm using a plugin. It has an action like this.
add_action('publish_post', 'old_action');
function old_action($pid) {
"code goes here"
}
}
I'm writing a module for this plugin. So i need to ...
4
votes
2answers
3k views
When to use add_action('init') vs add_action('wp_enqueue_scripts')
In my theme's functions.php, I'm calling an add_action in order to gain a measure of control on where jquery is loaded (in the footer along with my theme's other scripts).
The problem I'm having is ...
4
votes
1answer
72 views
How Do I Load My Action Earlier Enough?
With add_action, I want to intercept as early as I can in my plugin and send a 304 Not Modified header per some rules. Does anyone know what the order is of events? When I view this page, it seems to ...
4
votes
1answer
169 views
Why, Where, and When to use reference pointers in filters/hooks?
Why, Where, and When to use reference pointers in filters/hooks? What are the potential cons of not using them when suggested or required? Just looking for a more detailed answer than the codex ...
4
votes
1answer
69 views
Getting the action's tag name within the action
There's a function attached to a set of actions, like this:
add_action('some_tag', 'the_function');
function the_function($maybe_some_vars){
// ...
}
Is it possible to find out the action name ...
3
votes
1answer
2k views
Difference between after_setup_theme and init action hooks?
What is the difference between the after_setup_theme and init action hooks? It seems they are both called right before any page in WordPress is loaded (even admin pages).
3
votes
2answers
592 views
Correct place to register and enqueue scripts
I'm queueing several scripts in my themes Functions.php:
if ( ! function_exists('b99_init_scripts') ) :
function b99_init_scripts(){
if ( !is_admin()){
...
3
votes
2answers
55 views
How to count number of functions attached to an action hook?
I have some actions like this
function simple_notification() {
echo '<div>This is a notification</div>';
}
add_action( 'site_notices', 'simple_notification' );
...
3
votes
2answers
77 views
How do I use add_action from a class method?
For some context, we're building an activation system for new users of an app using WordPress as a framework. We've got a plugin driving most of our interactions, where all of this code resides.
When ...
3
votes
1answer
1k views
When and Where to use wp_insert_post()
I'm building a function that creates a group of pages with a common parent ID.
If I run wp_insert_post() on a parent ID twice, does the function create the pages twice while altering the slugs? Or am ...
3
votes
1answer
298 views
Using action hooks inside of a shortcode
I am trying to create a modular plugin that includes action hooks for developers to add content before and after the main shortcode content. I'm having some trouble because anything I do in the ...
2
votes
4answers
2k views
add_action reference a class
Is it possible to reference a class instead of a function in 'add_action'? Can't seem to figure it out. Here is just a basic example of the function in question.
add_action( 'admin_init', 'MyClass' ...
2
votes
1answer
416 views
Create posts on user registration
How can I create let say 3 posts after the user finish the registration ?
The ideal outcome would be to create 3 posts using the user as the author of the posts and with some pre-defined values. ...
2
votes
2answers
1k views
Why is `add_meta_box` not working?
I'm trying to add some meta fields to a WPSC product using the following code:
/**
* data callback
*/
function abc_callback($object, $box)
{
echo 'callback executed!';
}
/**
* add custom ...
2
votes
1answer
2k views
pre get posts changing the query
i need to change the posts in taxonomy.php page. I have a meta_key which i want to compare to meta value. But currently my code is not returning anything. I am sure i am missing something. Please let ...
2
votes
2answers
499 views
add_action for saving a custom menu
Say you have custom menus enabled with your WP theme. Is there any action associated with saving a menu once you've arranged it accordingly? To further clarify: say you've arranged a menu with some ...
2
votes
2answers
941 views
add_action('wp_ajax_[action name]', myfunction) problem
I'm having the exact same problem described in this post: add_action('wp_ajax_[action name]', myfunction) problem
I set add_action('wp_ajax_my_function_call','my_ajax_function'). If I ...
2
votes
1answer
262 views
Trigger custom action when setting button pressed
This is my first wordpress plugin and I'm running a lot of trouble making it work, it almost work fine but I don't find a way to accomplish this specific thing.
Basically I've my custom setting page ...
2
votes
1answer
48 views
Is it possible to use object in add_action?
So is it possible to do something like this with add_action?
class class{}
$my_class = new class;
add_action('init', 'my_class');
2
votes
2answers
109 views
add_action in class and use it in theme
I'm programming a plugin in Wordpress and want to access some database functions with in my theme with the do_action feature. First I just included $fdb-> get_finaboo_footer(1); on my page for example ...
2
votes
2answers
202 views
Add new column to sites page
I'm trying to get info into my network sites page in a column. Below works great to grab the network site ID for each site.
How can I make it display the option_value for the item (blog_expire) in ...
2
votes
3answers
3k views
add_action with a class method is causing fatal errors
I wasn't sure if this was a PHP issue (suited for StackOverflow) or a WordPress issue (suited for StackExchange), however since my issue appears to be with the add_action() function, I have placed the ...
2
votes
2answers
543 views
Why can't I hook into save_posts after admin_init?
I'm trying to hook into the "save_post" action from an AJAX callback in my plugin, but it doesn't seem to work. In fact, hooking into "save_posts" only seems to work from a few key action execution ...
2
votes
1answer
43 views
Perform action on WPMU blog deletion
Hi guys :) I know there is the wpmu_new_blog action hook which enables us to perform an action when a new WPMU blog is created. Is there something similar to this which enables us to perform an action ...
2
votes
1answer
131 views
Do I need to call do_action in my plugin?
Do I need to call do_action function every time I add_action something?
2
votes
1answer
104 views
How to update feed only 2-3 times a week (for Feedburner email)?
So many of you know that Feedburner is a great (free) tool for sending out newsletters. The problem is that if you add content everyday, everyday emails will be sent out.
I'd like to control on ...
2
votes
1answer
143 views
Post IDs missing on delete_postmeta action hook
I'm using metadata in pages to store variables and do server side caching for dynamic generated PayPal buttons and other variables about the pages (page specific).
I'm trying to hook the page meta ...
2
votes
1answer
525 views
Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!
I'm trying to automatically create terms in a certain taxonomy when a certain custom post type is published. The newly created term must be the name of the post that was published.
Example: I have a ...
2
votes
5answers
233 views
How do I make a theme “plugin-ready”?
How do I revise a theme so that I can publish my event hooks and anyone can build a plugin to add new functionality easily to my theme?
2
votes
1answer
184 views
How to modify wp_ajax function?
I want to modify wp_ajax_find_posts function. It receives search string from find-posts form and delivers search results by ajax. Part of the function looks like this:
function wp_ajax_find_posts() {
...
1
vote
1answer
96 views
Stop loading “collaborators” users on add new post or page?
So our website has about 20k "collaborators" type of users and we'd like to stop loading all of them on the select box on the "add new post" or "add new page" PAGE. Maybe load only authors and above ...
1
vote
1answer
826 views
How can I automatically set a post slug based on the post title during post publish?
When you create a post in WP, if you don't specify a title rapidly, WP generates a default slug on autosave, based on the post ID. Then, when you add the title later, unless you modify the slug by ...
1
vote
2answers
178 views
do_action pass array argument as reference not copy
I have successive hooks to an action which are passed an associative array like: do_action($array)
I am trying to update the values in this array in the multiple add_action calls, however each ...
1
vote
1answer
512 views
add_action in functions.php, do_action in plugin?
I am trying to set an add_action function in my currently active WordPress theme functions.php file, for a defined do_action function within an activated WordPress plugin.
The add_action function in ...
1
vote
2answers
475 views
where is the documentation for add_action() parameters?
I am reading the source of a plugin (gallery to slideshow plugin) to make it behave like i want and it is using an action
add_action( 'the_posts', array( &$this, 'have_gallery' ), 10, 1 );
I ...
1
vote
1answer
32 views
How to select a page within admin?
How does one apply an action to one particular page within admin?
I've added a bunch of wysiwyg editors to one page ("Home") and now I don't need the main editor. But the function below - of course - ...
1
vote
1answer
233 views
Add something to beginning of content with add_action('the_content')?
I'm using add_action('the_content', 'myFunction', 10) to append data to the end of the content. How can I place content at the beginning of the content?
1
vote
2answers
450 views
How do I add a TinyMCE row that all users can see, instead of just admins?
Currently I have successfully added a row of shortcode buttons to the TinyMCE editor in WordPress. The problem is, only admins can see the row, and I need contributors and editors to see it too. I ...
1
vote
1answer
510 views
What is the very earliest action hook you can call?
After the solution to this question was to get a function to launch BEFORE the init action is fired by taking the sequence out of its function, it got me thinking, is there any earlier in the WP load ...
1
vote
1answer
320 views
Add title, post content, and category like add_post_meta and update_post_meta
How can I update/add a new title, post content, and category to a post with hard PHP code similar to add_post_meta(), update_post_meta()?
1
vote
1answer
2k views
register_taxonomy and register_post_type does not work
I have a problem using the register_post_type and register_taxonomy on my Wordpress. I created the code on my functions.php and it does not update my panel. Why?
//Categorias personalizadas
...
1
vote
2answers
29 views
Replace a word with a word in the URL string
I'm trying to replace a word on every page for example "Denver" with a word from a URL string, so I'll have like ?city=Atlanta in the URL. So I was thinking of using PHP's GET to just get the city ...
1
vote
2answers
222 views
My plugin class doesn't work! [closed]
Long story short; I'm writing a plugin in OOP. The constructor is run, but the callback of my add_action does not run. I just can't find out why.
I have added echo's on different spots to see what ...