Questions tagged [actions]

A name for an event that is executed at specific points throughout the WordPress core.

274 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
1answer
339 views

Auto Load Plugin Hooks inside Must Use Plugin

I am creating a custom MU plugin to run on a multi-site network. I am working on a function that will dynamically include files containing additional action and filter hooks based on the active ...
4
votes
1answer
2k views

trigger save_post event programmatically

Is there a way to trigger the post saving or updating event in code? such as do_action('save_post', $post_id); The function here seems to imply that a WP_POST object needs to be passed in. Is there a ...
4
votes
1answer
36 views

Prevent Deletion of Blogs

I'm trying to prevent the deletion of blogs in a WordPress Multisite installation. There is already a plugin that does this, but it uses wp_die() as the solution, which in my scenario does not work. ...
3
votes
0answers
27 views

add_meta_boxes action with refresh on save

I've created a meta box using add_meta_boxes action and it works when I open any post to edit it. add_action('add_meta_boxes', function() { add_meta_box( ... ); }); When WP auto ...
3
votes
0answers
64 views

Make default new sites https (multisite)

Quick background case: If I use Softaculous to install WP in cPanel, I can specify which protocol I would like the site to be in... (so they have something that addresses this). However with my ...
3
votes
1answer
43 views

Is there a way to expose additional fields to the Bulk Action > Edit functionality?

I would like to know if it's possible (using the existing WordPress core development features) to hook into the existing WP Bulk Action > Edit functionality, in order to expose additional fields to ...
3
votes
1answer
389 views

Wordpress admin notice in plugin function

i have sample wordpress plugin class. Im hooking woocommerce woocommerce_saved_order_items and i want create a admin notice. Add action from __construct works, but when i want create a notice in hook ...
3
votes
1answer
155 views

Action hooks returning old category instead of new category

With some help I created a WP Action to send an email to the author of a post (custom post type) when the category has been changed. This works ok, except that the function is returning the previous ...
3
votes
0answers
69 views

How can I invoke an action after a CiviCRM triggering event?

If I want to have a certain action taken after a CiviCRM 'trigger', what is the best approach? I'm a Drupal developer used to using Drupal workflows on CiviCRM actions, and I am unfamiliar with ...
2
votes
0answers
37 views

Check Title Unique Or Not and If not error message and dont save

i am get tired from searching 2 days for what i wanna i have 'area' custom post type have Title and another field i wanna the title of area is unique if the user enter title 'area1' and this title ...
2
votes
1answer
138 views

Flush Rewrite Rules on init or rest_api_init?

if I'm using the REST API to create endpoints in my plugin, should I be flushing rewrite rules on init or in rest_api_init? I realize that it should be done on plugin activation/deactivation. However,...
2
votes
2answers
121 views

How can I enqueue a style only when a particular widget is active?

I have a plugin which requires a style sheet for the widget. I am trying to register the stylesheet when the widget is created, however the style sheet is not being queued and the styles ignored. The ...
2
votes
4answers
79 views

What is the Difference between directly call a function and call a function using add_action?

What is the difference between following two codes? (Directly call a function and call a function using add_action) function pp_submit__link_form(){ if(isset( $_POST['action']) && $...
2
votes
1answer
130 views

How to get all the predefined do_action() calls from an active theme

To hook my plugin content into anywhere, suppose I offered the theme developers to create their own hooks with a prefix (pre_) anywhere in their theme - the rest of the hook is unknown to me. So what ...
2
votes
1answer
789 views

Add custom buttons with custom actions in Edit Post screen in WordPress?

I am creating something for a client and I have a Class that I created with a Custom Post Type called 'PuSH Feeds' and when the user adds a new post and publishes it they can then click on one of two ...
2
votes
1answer
286 views

array of objects to do_action, callback gets singular object?

So I was passing an array of objects through an action today, no biggy, and things were working fine. Until I was iterating over one of the arguments to a callback and started getting errors. The only ...
2
votes
2answers
1k views

Using add_filter() in Widgets

Just have a query reference the add_filter() function. Can you use this function inside a WordPress widget class. Example I have a widget with dynamic created code that I want to pass to another ...
2
votes
0answers
98 views

How to load script-related styles automatically?

Scenario: It is common that a JS dependency is bundled with a style file to work properly (just think about your favorite slideshow jQuery plugin). AFAIK, in this situation, the script and style have ...
2
votes
2answers
447 views

add_action on inherit post status

I'm trying to use the add_action() hook to run a custom function, but am struggling with the post status. I originally tried using: add_action('pending_to_publish_portfolio', 'my_function'); (...
2
votes
0answers
76 views

Selectively applying action based on role

I've added an action to my functions.php file that forces a plugin (Content Scheduler) to act on posts, even when it wasn't explicitly enabled by the person writing the post. I've got that working, ...
1
vote
1answer
24 views

wp_set_object_terms not updating database without a die()

I have added custom taxonomy to media attachments. From the individual post page these are updating correctly, with some tweaks to get the column count updating correctly - and I can see these changes ...
1
vote
0answers
57 views

Save acf field data via acf/save_post before post is saved

I have 4 advanced custom fields and I would like to save each field value when it is changed on the post and not have to wait until the post is saved. I'm using acf/save_post action. Here is my code ...
1
vote
1answer
18 views

Are the hooks in the dashboard such as “load-$page_slug$” and “admin-head-$page_slug$” reliable and consistent throughout installs?

I've created a page using add_theme_page with the name of access_page. Whenever someone accesses that page, or rather, for that page, a few hooks are created, such as admin-head-access_page and load-...
1
vote
0answers
29 views

How to properly modify WP Vary or any existing headers?

I have a site that currently have a some part of the headers like: Vary: Accept-Encoding, Cookie I want to modify it to be: Vary: Accept-Language I tried the suggestions here using this code ...
1
vote
0answers
283 views

get_permalink() is not working after published

I created a plugin that, when updated, gets a link to a published record and sends it to the API. So I get the URL, but sometimes wordpress gives me such a link: site.com/?p=123, and should site.com/...
1
vote
0answers
29 views

Get Time Taken By Each Action Hook in Wordpress

I am developing a Plugin, and want to record Time taken by each Action Hook, I am able to get all the Hooks Triggered on a Page with the Action and Priority, but i am unable to get the Time taken by ...
1
vote
1answer
18 views

Is there way to run a code every time when any cron is run?

publish_post is an action triggered whenever a post is updated and its new status is "publish". Is there similar action which is trigger when cron is run including WordPress default crons? I am ...
1
vote
1answer
165 views

WP_Query ignoring tax_query when is_singular

I’m trying to set up some post permissions using taxonomies and I'm applying my rules in a pre_get_posts action. It’s working fine when multiple posts are found, but in class-wp-query.php near line ...
1
vote
0answers
26 views

Are functions in main plugin file called before function bound to register_activation_hook runs?

In my plugin, I am doing a minimum-supported PHP version compatibility check via a function bound to register_activation_hook and halting activation for those on PHP version less than the minimum ...
1
vote
0answers
24 views

Adding widgets to my plugin page instead of WordPress dashboard

So below is the action to add widget in the WordPress dashboard. How can i add widgets in my plugin's page? add_action('wp_dashboard_setup', 'csc412_dashboard_widgets'); function ...
1
vote
2answers
144 views

Is there an alternative to get_template_directory_uri()?

I need to know the templates directory uri at a point at which the function get_template_directory_uri() is not yet available. The function where I need the uri is triggered by the action ...
1
vote
0answers
60 views

Plugin developer automated documentation

I have published a plugin which provides a nice extensibility. Now, I want to provide my users an automated PHP Documentation which describes the API Functions, Filters and Actions like this page here:...
1
vote
1answer
30 views

Hook when editing user

I am trying to run a function. And that function I would like it to run when I open a user's form (in my wp-admin). Which Hook would be the one I should use ?? Ideally, you should run the function ...
1
vote
0answers
37 views

action theme mailchimp subscriber fields

I'm running the Action wordpress Theme. One of the widget that can be used to sign up users to a mailchimp list. The thing is, there are only 2 fields to fill in. Name and email. Now the list has ...
1
vote
2answers
96 views

Changing WordPress core without hacking core

In my situation, WordPress was using the wrong url in sortable column headers, filters and pagination in the admin dashboard. The only solution that worked involved modifying core files, specifically ...
1
vote
0answers
58 views

How to make an action run in the background?

In my web site which I am creating, I have some tasks which are quite heavy, etc. add_action('add_attachment', [$this, 'mediaAdd']); What mediaAdd does it grabs a file from the media libray and ...
1
vote
1answer
285 views

How to use do_action_ref_array?

I have a plugin which has this method in it that is supposed to have a hook for custom validation. I have two issues: I'm not sure how to call it (have posted my attempt below) It looks like the ...
1
vote
1answer
67 views

How to pass variables to custom filter from multiple functions

I am trying to pass a variable from a function (that renders a shortcode) to another which enqueues google fonts. I am using filters for that. Since the functions are hooked to add_shortcode, I guess ...
1
vote
2answers
1k views

admin_post hook not called

I have good experience in other CMS. but I'm very new in Wordpress. My goal is to intercept POST values in some of the form of a pre-existent site. Following documentation I've done the following ...
1
vote
1answer
87 views

How to filter content for specific content variable

I created a plugin that adds content from another post, and places this content next to the original content. I can say, that this content should appear at the bottom of the original post content. I ...
1
vote
1answer
83 views

Wait a result before enqueue

Supposing we have : class AwesomeClass{ private storedResult; private __construct(){ add_action( 'set_logged_in_cookie', array($this, 'a'),10,1); add_action('...
1
vote
0answers
24 views

Building a request processor for multi-page forms, etc using $_GET requests

Good day, What I'm trying to accomplish in a semi-elegant way today is building a multi-step form type thing. Essentially, I'm trying to rewrite the page based on a $_GET request. Like, say, it's /...
1
vote
2answers
136 views

schedule event in class oriented plugin

Actions usually support the following (if you are creating your plugin using a class based approach): add_action('admin_notices', array(&$this, 'emailNoticeGUI')); The wp_schedule_event does not ...
1
vote
1answer
351 views

Redux callback action

I'm very new with Redux. I don't know how to show and hide a textarea using switch (without saving). When my switch turns on, the text input displays and when it turns off, the input hides itself. I ...
1
vote
0answers
70 views

Comment search plugin

I want to develop a plugin which places a search input field above the first comment on the post pages, filters the comments below that post, and only shows the comments which include the string that ...
1
vote
1answer
510 views

How to trigger function on theme delete?

Tried to find an or some hook to fire a function when theme is being delited, but didn't find any hook.. May be someone can tell if there's a way to fire my function on themes delete event? I need ...
1
vote
0answers
384 views

load_plugin_textdomain doestn't work with add_action plugins_loaded

I am trying to load localization for my plugin. There is directory called languages in my plugin folder with .po and .mo files inside of it. I have the following code in the plugin main file: <?...
1
vote
1answer
3k views

Change meta tags programatically

Is there a way to change the meta tags not in the head but in a template file through code? I would like to change the meta tags <meta property="og:title" content="title" /> <meta ...
1
vote
0answers
1k views

Hooking action once but called twice

class GridModSidebars{ public function init(){ add_action('widgets_init', array($this, 'registerSidebars'),20); } public function registerSidebars(){ $args = array( 'name' =&...
1
vote
0answers
50 views

Multiple Loops Meta Data

I am now trying to figure out how to create the functions/ loops to pull my data from custom post types. I have two post types(keys): And I need to pull the data from both to run my functions. ...