Questions tagged [actions]
A name for an event that is executed at specific points throughout the WordPress core.
1,409
questions
0
votes
2
answers
36
views
How to stop execution of a function via add_action hook?
I have the following functions:
function test($post_id){
do_action('test_action',$post_id);
echo $post_id;
}
add_action('test_action',function($post_id){
if ( $post_id == 2 ) //Stop test function ...
1
vote
0
answers
78
views
add_action and do_action: multiple calls to same callback?
I have a setup similar to this:
function get_type_data($val) {
// Get the data from the DB where the ID is $val and return it.
}
add_action('my_hook', array($this, 'get_type_data'), 10, 1);
I ...
0
votes
1
answer
28
views
Ajax callback not work
My files is :
synergyservice.php
register_activation_hook( __FILE__, array( 'Synergy', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Synergy', 'plugin_deactivation' ) );
if ( ...
0
votes
0
answers
28
views
admin-ajax.php calls fail if referrer is sent with 500
calling admin-ajax.php via jquery ajax calls were failing from my site but postman calls to the same url were successfull.
After some looking at headers it seems that the referer being set is the ...
0
votes
1
answer
24
views
How to pass multiple parameter in add_action()
I have below code.
add_action( 'admin_init', [$this, 'settings_page_registration'] );
I would like to use enqueue_assets function name inside add_action().
Should I use like below ?
add_action( '...
0
votes
1
answer
25
views
Prevent posts with certain post_meta to be edited
So I am looking at adding some custom post_meta to posts and I want those posts to not be editable, which will be some content that I am pulling in.
Here is what I have:
I have solved the issues when ...
2
votes
1
answer
102
views
Find variables available at a given hook
I'm hoping for a simple way to tell/find/echo what the available arguments are available for use at a given hook.
For example —
function example_function($something){
//do stuff with $something
...
-1
votes
0
answers
14
views
how to limit search to post titles and contents by functions code?
Is there a way to limit search to post titles and contents?
I tried below code in the link and its working but its just for titles.
I would like to have function code for titles and contents.
how to ...
0
votes
0
answers
12
views
Displaying page content from plugin, inside exising empty WP page
Old php developer here, very.. very new to WP, so be kind.
I am building my first WP Plugin. I have this in the plugin central file (the one that is /plugins/my_plugin/my_plugin.php):
// Setup the ...
0
votes
1
answer
50
views
Update media library image shown in "attachment details" when using wp_insert_attachment to add item to the media library
I'm using the function wp_insert_attachment() to run on a form submission from GravityForms, take a file uploaded in the form, and add it to the WordPress Media Library.
Code in functions.php below, ...
0
votes
0
answers
14
views
Replace Data In Post & Update Meta Field Post Is Saved
I'm a bit lost & I'm wondering if someone can help.
I have a post that is being generated from a podcast feed. That feed contains an audio player using the <audio> tag. I wanted to remove ...
0
votes
1
answer
33
views
What is @Action in Wordpress?
I have found this code snippet on a plugin.
/** * @Action(name="workforce_content_loop_before", priority=10) */
public static function show_breadcrumb() {
echo do_shortcode( '[...
0
votes
1
answer
20
views
How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
I created a custom plugin and I need to schedule add_action using Crontrol Plugin, the Setup class is from different php class. But the schedule action cant read the Crontrol even if I execute ...
1
vote
1
answer
58
views
Should action callbacks start with a verb?
class Singleton {
public function __construct() {
// Case #1
add_action( 'woocommerce_before_shop_loop_item', [ $this, 'open_product_wrapper' ], 10 );
add_action( '...
0
votes
1
answer
20
views
Wordpress action - Pass arguments into action in an AJAX call?
My theme uses a custom action which expects two arguments. I am trying to call the function in an AJAX call but because I am not passing those arguments I end up getting a 500 error.
The action is ...
0
votes
0
answers
21
views
How to use wp_enqueue_script properly?
I'm trying to load mine scripts, but it doesn't work properly.
function theme_enqueue_assets() {
wp_enqueue_script('load_more', get_stylesheet_directory_uri() . '/assets/js/load_more.js', array('...
0
votes
1
answer
33
views
How to catch wordpress post ID when it's published
I am trying to either automatically a forum section when a post is published - like a discussion page. Normally, I wanted to make the users create the topic but I realized a forum category with many ...
0
votes
0
answers
22
views
How do I add an action using namespaces, and file separation? [duplicate]
I'm working on a plugin, and I'm trying to get to grips with namespaces and how they work with actions. In a separate file, I have a single function with a namespace declared at the top:
namespace ...
0
votes
0
answers
34
views
Hook from plugin doesn't fire up from external PHP script
I have this habit of installing a plugin with all my custom hooks, instead of writing a functions.php file with the same PHP code in it. That way I get the same functionality without the need of ...
0
votes
1
answer
33
views
Set Taxonomy based on post status
I am setting a taxonomy based on the post_status. It works as needed except I want to allow the taxonomy to be overridden if a particular taxonomy is selected.
Here is the code
function ...
1
vote
0
answers
14
views
Plugin with action 'save_post' needs to press publish twice on order to publish
I have an old plugin, which used to work fine (years ago). Now I have to press publish twice to publich the post.
The problem is in the blocks below. The used variables are declared above the code ...
0
votes
1
answer
21
views
How to find where an action is triggered? [closed]
As far as I understand about the action hook, add_action is used to add callback functions to an exsiting action hook, which means, to make lines like
add_action('some_action_hook',function(){ // some ...
0
votes
1
answer
17
views
What do I put in the form action attr on top of form wordpress
I created an html form, but have no clue, what I must put in the <form action = on top of the form. Does the user info go to the database, or to a file in wordpress. I am not sure what to put there....
0
votes
0
answers
40
views
Prevent other hooks from firing after wp_update_post() outside of editor
I'm working on a plugin that batch updates post content using a call to wp_update_post(). This all happens outside the editor window, in a batch processing script.
My problem is that ACF is firing ...
0
votes
0
answers
43
views
How to do admin ajax request in a plugin for rest api
This must be something very simple, but I cannot figure it out.
I'm working on a plugin, that extends a theme's functionality to rest api. Theme has an ajax action function that updates user profile. ...
0
votes
1
answer
27
views
Hook add_attachment error
I am trying to optimize my images when uploading to website. I trying to write plugin, that will use hook 'add_attachment' and after attachment uploaded do image converting.
add_action( '...
0
votes
1
answer
52
views
WordPress redirect redirecting too many times or not at all
I am new to WordPress. I am trying to simply redirect users to a login page if they go to the account page without being logged in.
I first tried adding this code to the functions.php code:
add_action(...
1
vote
1
answer
134
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 ...
0
votes
1
answer
37
views
Action / Hook when a new plugin is added
Is there an action hook when a new plugin is installed?
I want to hook into the moment when a new plugin was put into the /wp-content/plugins folder. So really just adding the plugin (either via ...
0
votes
2
answers
50
views
Can we change the hook firing sequence?
In admin, I need to fire the save_post action before firing the transition_post_status hook. But according to this, the transition_post_status fires first before the post is saved.
How can I reverse ...
0
votes
2
answers
32
views
changing genesis_before_while in new theme framework
I am moving a site from a Genesis theme to Colorlib theme. The genesis theme includes add_action( 'genesis_before_while', 'custom function' ); in a custom archive page, which loads restricted content ...
2
votes
1
answer
174
views
Define a function outside a class and call the function using action or filter hook
Hi Currently i am developing a sub plugin for my own main plugin. Please see the main plugin code below
<?php
class MyClass
{
function __construct()
{
function test1()
{
...
0
votes
0
answers
23
views
apply_filters() and call_user_func() to define and call a function outside a class
Hi Please see the following code of my class
class MyClass {
function __construct() {
$this->autoload_function();
}
function autoload_function(){
$my_array=...
0
votes
0
answers
93
views
Trying to update repeater field (ACF) dynamically with data from Contact Forms 7
I'm trying to feed a repeater field with the values submitted via a registration form (I'm using Contact Forms 7).
When debugging the array of values passed to the "add_row" function, ...
0
votes
0
answers
12
views
Wordpress Post Block Element not properly parsed with the_content filter
I made a small script which echoes the content of all Wordpress Posts on post_updated, deleted_post and trashed_post actions.
add_action('post_updated', 'echoAllPosts');
add_action('deleted_post', '...
0
votes
1
answer
27
views
current_user_can comma list vs OR (||) list
Can any help with this?
I like the comma separated version because it's smaller to write and easy on the eyes, lol, but I can't make it work.
//** WORKING - Works on the Checkout page
add_action( '...
0
votes
0
answers
21
views
Rewrite the search page to use an appended slug + parameter
I have two URLs that handle search
~/search/ = main search page
~/?s= = results page
What I want: to have one search page where the search parameter for the results page appends to the search page ...
0
votes
0
answers
17
views
Session management issues with WordPRess 404 Error page
I have tried to integrate wordpress into my existing website as the documentation archive using the existing login session. I have installed wordpress under /wp of the root app.
In my main app, I set ...
0
votes
1
answer
53
views
Call to undefined function is_home() or any conditional tags
Currently I am coding in my own custom plugin. For some reason I can't use conditional tags inside my function. For example
function check_home() {
if(is_home()) {
$my_val=1;
} else {
...
0
votes
1
answer
39
views
Override a function defined in wp-includes/comment-template.php
I need to override the function get_cancel_comment_reply_link or cancel_comment_reply_link that are defined in
wp-includes/comment-template.php
These functions are not listed in pluggable.php.
How ...
0
votes
0
answers
57
views
Using `set_transient()` when saving a custom post type
I've got multiple custom post types registered via a plugin and one of them is used as a precursor for multiple other queries. In an attempt to reduce queries throughout the site, I've attempted to ...
0
votes
1
answer
31
views
How to call do_action() to pass arguments to hooked functions that take different number of args?
Here is a simple example to explain my question. 3 functions are hooked into the myaction. Each take a different number of args and the args can be a number of an array of numbers. So args can also be ...
0
votes
0
answers
25
views
Using publish_{custom-post-type} hook for custom post type to update meta doesn't work
I am using publish_{custom-post-type} hook to update meta of the post that has just been published. The post-type is jobboard-post-jobs. Why isn't it working?
add_action('publish_jobboard-post-jobs', '...
2
votes
2
answers
152
views
Get updated post meta on save_post action?
I'm trying to save post id and keyword (Yoast Focus Keyword) to a custom table when post is created or updated via save_post action. It saves everything fine on Publish (first-time) but when I update ...
0
votes
0
answers
27
views
Fire action after enqueue script
I have a color switcher but its css files load before default css files.so, it doesn't work good.I want to fire it after enqueue script.after all css and js files on the website, I want to load my ...
0
votes
1
answer
39
views
Remove an action created by a Gravity Forms add-on
I'm using Gravity Forms User Registration add-on and need to remove the action that include the activate page.
In the add-on, the hook is called like this:
add_action( 'wp', array( $this, '...
0
votes
1
answer
45
views
How to pass a variable between filter/action functions?
In a function fired from filter wp_handle_upload_prefilter, how can I utilise a variable obtained from previously firing action edit_user_profile?
My aim: on user-edit.php, when user uploads a file (...
1
vote
1
answer
79
views
Is there a filter called 'network_admin_init'?
Is there a network equivalent to 'admin_init', or what do I have to do to add an action to network admin screens? I use 'admin_init' for an action on admin network screens, but the respective function ...
1
vote
0
answers
15
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 ...
0
votes
0
answers
21
views
Add metabox if there is at least one post available
So I am building a WordPress Dashboard widget which will showcase all posts & pages where a Gutenberg Block is active.
The below code does it's job and pulls in an array based on get_posts().
Here ...