Questions tagged [actions]

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

344 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
2answers
5k 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
976 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 ...
4
votes
1answer
44 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
256 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
89 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
2answers
368 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 ...
3
votes
1answer
328 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
1answer
1k 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 ...
3
votes
0answers
73 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
34 views

What is the best filter where to use register_block_type?

I'm using register_block_type to register my blocks. I'm not sure what is the best hook to use, between init and enqueue_block_editor_assets. I suppose that enqueue_block_editor_assets it is loaded ...
2
votes
1answer
1k views

Is there a Woocommerce hook that fires when applying a coupon but before checking if it's valid?

I want to add an item to the cart (that same item gets discounted with the coupon) upon using a coupon code (with a hook). E.g. when using the coupon code SAMPLECODE, a product is added to the cart ...
2
votes
1answer
204 views

WP action is not triggering a do_action() call within?

Okay, so I have a plugin on my site that triggers a do_action(). In a second plugin, my custom plugin, I hook into this action and end up calling a do_action() for another custom action of my own. ...
2
votes
0answers
69 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
846 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
1answer
460 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 ...
2
votes
4answers
160 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
904 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 ...
2
votes
1answer
420 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
0answers
116 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
599 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
77 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
111 views

Adding rewrite rule dynamically

I'm trying to dynamically add a rewrite rule that allows one to access any page under an alternate permalink structure of my choosing. So for example, if the alternate permalink structure includes the ...
1
vote
0answers
12 views

How to hook a custom user function to a wordpress core ajax action?

I need to call a 3rd party API when a permalink edit happens for a post.I found once an edit happens, it calls an ajax function with the core wp post action 'sample-permalink'. How to hook my custom ...
1
vote
1answer
46 views

Code run fast on a cronjob but slow with a do_action or ajax call

I am creating several posts from a csv, when I execute the code using a cronjob the operation lasts about 7 minutes, but if I use the code directly in a template, or make a call to do_action or ...
1
vote
1answer
155 views

Gutenberg - Dispatch action or setAttributes() on Post Save/Update action instead of onChange listener

I have a requirement to add up to 8 user selected custom colors to the list of default options when using the Colour Palette. I have registered a meta that saves custom colours. Problem: I want to ...
1
vote
0answers
109 views

Shortcodes — Using add_action, add_filter in the shortcode

A client wants the following: User clicks on a specific button which takes them to a partner's site. If this is their first time clicking the link, they need to accept terms and conditions. If they'...
1
vote
0answers
35 views

Prefixing plugin hooks (actions/filters) with a wrapper class or functions

I'm developing a rather extensive plugin which has a lot of hooks that are prefixed with the plugin namespace. I have created a wrapper class like the one below but because this plugin is geared ...
1
vote
0answers
26 views

How to remove action with slashes and arrows?

I have two actions like BSF_AIOSRS_Pro_Markup–>disable_astra_theme_schema and 'Yoast\WP\SEO\Integrations\Front_End\Redirects–>archive_redirect' on 'wp'. But I can't remove these both as usually ...
1
vote
0answers
135 views

Can the wordpress color palettes by changed through Javascript?

I'm building a setup for a client that allows them to use a number of colour swatches throughout their gutenberg blocks in a post. They define the colour swatches in the document inspector panel (post-...
1
vote
0answers
12 views

How can I get my Script to work on the Login page?

I am trying to disable the right click feature, on the login page, using the following code: <?php function disable_right_click() { ?> <script> jQuery(document).ready(function(){ ...
1
vote
0answers
42 views

How to redirect if a background request is still being executed

I am using the Woocommerce Waitlist plugin to allow users to subscribe to product waitlists. After subscribing to a waitlist I want to redirect the user to another page to complete a form. I am using ...
1
vote
1answer
240 views

Adding custom fields to bbpress reply form

Referring to post "adding-custom-fields-bbpress-topic-form" with link https://wp-dreams.com/articles/2013/06/adding-custom-fields-bbpress-topic-form/, I want to add custom fields to bbpress reply form ...
1
vote
0answers
82 views

remove_action returns false regardless of priority

I am writing my own plugin to customize a public plugin. My plugin is doing this customization by removing an action via remove_action() and adding it back with my customized code. The code below ...
1
vote
1answer
78 views

How to check current user before all actions and filters?

I am working on a plugin with 50+ actions and filters. All actions and filters only apply to users with a specific user meta (b2b). I want to check this user meta before everything How can I do this? ...
1
vote
0answers
550 views

Contact Fom 7 - how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?

Contact Fom 7 - how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control ? Using the 'Query Monitor' plugin I found that the HOOK which I need to ...
1
vote
0answers
70 views

Set a custom display_name on user_register?

I'm trying to force a specific "display_name" using data collected in a wpforms registration form. In the registration form, I've got a field for "last name in high-school" and a field for "nickname ...
1
vote
0answers
75 views

How do I use remove_action on an add_action that uses an array?

This is a messy question :) I'm running into a conflict between plugins and need to disable one (WP Bakery) on the front end of certain pages. I'm looking at multiple questions on how to disable a ...
1
vote
0answers
20 views

A method for ordering mixed dates in search result loop (theory only, no actual code)

My issue Hello, some time ago: I had the regular post and the custom evento post types; the evento post type had a ev_data_out custom field; the search result loop had to return a list of posts from ...
1
vote
0answers
257 views

Using Nested add_action()

I am new in WordPress.I am learning Plugin Development. Is it possible to use Nested add_action() like below ? add_action( 'admin_post_addAddress', 'add_new_address' ); function add_new_address(){ ...
1
vote
0answers
407 views

Trying to place a custom field after the total section in the checkout page in woocommerce

This code correctly works but does not place the custom field where I want it. In the add_action I would like to use woocommerce_review_order_after_order_total as the location attribute to place it on ...
1
vote
0answers
25 views

How do I add a custom screen for a custom post type to be called from custom post row action?

I have custom post type called messages where I will store emails and my request is very specific. New post cannot be created and user cannot do anything with it except delete it. I have already added ...
1
vote
1answer
589 views

Wordpress action admin_post for non-admin authenticated users - Form submission

I'm trying to submit form using: `admin_post` && `admin_post_nopriv` actions. This is a shortcode for users search: add_shortcode( 'search_users', 'search_users' ); function search_users( $...
1
vote
0answers
63 views

Unable to change footer using wp_footer action hook

I am learning Wordpress from a book and while learning about how to use action hooks the author gives the below code . I am assuming this would change the footer at the front end . <?php ...
1
vote
0answers
86 views

How to list all WC products by their attributes values?

I wanted to get some advice on how to list all my inventory attributes values. I have this simple code that will output the products as plain text, But instead of the_title(); I want a list of all ...
1
vote
1answer
174 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
468 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
69 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
794 views

Set global $wp_query/$post variable for dynamic page generation

This is a difficult one to describe, but I'll do my best... I'm trying to set up pages that can be shown based on a second (meta/ACF) slug, dependent on the language the user is using. Essentially, I ...
1
vote
0answers
69 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
1k 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
2 3 4 5
7