Questions tagged [hooks]

Method by which plugins and themes extend core WordPress functionality.

585 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
1answer
4k 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
801 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
460 views

Featured image upload finished hook

I'm looking for a way to hook into the process of uploading a featured image. Ideally I would want to be able to do some stuff right when the upload has finished, before the thumbnails are generated. ...
4
votes
3answers
1k views

new WP_Query() - what is the earliest valid hook?

Specifically, is it valid to run a new WP_Query() during the plugins_loaded action?
4
votes
2answers
503 views

Wordpress scheduled task is called but not executed

I created a plugin with a cron to update all posts of a certain type every 5 minutes. I installed WP Crontrol to check if the cron is registered correctly and everything seems to be okay. This is how ...
3
votes
1answer
51 views

How to remove “out of stock” variation options from size dropdown in woocommerce?

I'm using woocommerce to display products and their variations. I have a variation called 'Size' for all of the products. Some of the variations are out of stock, but these are still showing in the ...
3
votes
0answers
326 views

Admin Notification after save_post, when ajax saving in gutenberg

How can I display an admin notification? I want to do some actions on the save_post_post action and want to inform the admin about the success and details about the action after that. I tried so far:...
3
votes
1answer
167 views

Hide gutenberg option blocks

How to Hide/disable every feature on the New Post creator, Just the following area visible: Gutenberg Editor Publish button Tags Categories Even hiding the left sidebar and all menu options too.
3
votes
0answers
103 views

Hooking a callback into the code within a Gutenberg block

I want to run some JavaScript when a user uploads an image or images using the core/image block or core/gallery block. Ideally I would run my own code when the onSelectImage function is called (and ...
3
votes
0answers
47 views

How to find out what blocks are added by a plugin

I am creating a plugin, which adds a number of blocks defined by JS/PHP as per Gutenberg documentation. I want to display these block names on an admin page. Is there a hook or function I can use ...
3
votes
0answers
211 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
47 views

How can I add a fifth option to the alignment picker?

I'd like to have the following options in the image alignment picker: Left Right Center Full None Obviously four of those are there by default, but the "full" one doesn't currently exist. The idea ...
2
votes
1answer
37 views

how to create endpoint for downloading pdf files?

I would like the logged-in user to be able to download the PDF file, but not to see the real path to the file. Additionally, in this PDF file, I enter information about the user name and date of ...
2
votes
0answers
22 views

Hook all http requests

How do I hook all http requests in wordpress? More specifically I am interested in examining an http header in the request and then potentially modifying headers in the request so that other plugins ...
2
votes
1answer
326 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
2answers
459 views

Show only geolocated user country into Woocommerce checkout country fields

What I'm NOT trying to do: Remove or hide checkout (billing/shipping) country fields What I'm trying do to: Show only ONE country in checkout (billing/shipping) country fields, depending on ...
2
votes
0answers
100 views

Gutenberg disable the “block” tab in right sidebar

I'm working on a Gutenberg setup that allows only one classic block. I want to disable the "block" tab in right sidebar since no settings appear there anyway, but can't find a hook or way to achieve ...
2
votes
0answers
157 views

@wordpress/hooks use to add actions/filters within multiple plugin

I am trying to use @wordpress/hooks package in one of my react based plugin. I have added some hooks(filters/actions) and I need to hook into these from different plugin. I am able to add filter for ...
2
votes
0answers
184 views

When using the block.getSaveElement hook can you output different markup based on whether or not you are in the edit view or the live page view?

I am trying to extend the core/image block to add an option for a deferred image. I want to replace the src attribute of the image with an empty string and add the url as a data attribute to be loaded ...
2
votes
1answer
229 views

How to get all functions with priority '1' attached to hook 'wp_head'

How to get (loop through to disable unnecessary) all functions with priority '1' attached to hook 'wp_head' ('_wp_render_title_tag', 'wp_enqueue_scripts', 'noindex' etc.)? It is necessary to get it ...
2
votes
1answer
117 views

Hook into theme-switching later than `setup_theme`

I need to add a theme-switching logic to a site. Unfortunately, what I've tried already doesn't seem to work as required. The themes needs to switch based on whether the user is on the blog part of ...
2
votes
2answers
656 views

How To Change The Html of Products filtration sidebar in Woocommerce?

I have Used the function dynamic_sidebar('sidebarId') in the sidebar.php file. and all the functionality of the sidebar is Working succsessfully My Question is How To Change the Html of the sidebar ...
2
votes
1answer
313 views

Is there widely accepted phpDoc syntax for documenting which hook calls a function?

I keep all hooks in one file, and the functions are organized in their respective classes (different auto-loaded files). Looking for a standard way to document that a function's sole purpose is to be ...
2
votes
0answers
986 views

Hook (upgrader_process_complete) running moment

i want to use the upgrader_process_complete (documentation) to check if my plugin was updated (to run some scripts). My question is: when this action is triggered, WordPress is already running the ...
2
votes
0answers
97 views

Trigger Plugin database update after git pull

I have a couple of WordPress websites that I'm maintaining. The websites are on various git repositories (one for each site) with individual remotes. Currently when there is a plugin update ...
2
votes
1answer
90 views

Stuck in redirect loop after using wp_login action

I'm stuck in a WordPress redirect loop which happened after hooking into the wp_login action. The strange thing is that I've already removed the piece of code in question, cleared cookies and ...
2
votes
0answers
894 views

Add tab to profile.php wordpress plugin development

I already know how to add an extra field in user profile. But in my case I have A lot of field to add and It is good practice that your form is not too long. So I decided to implement tab panel in the ...
2
votes
0answers
442 views

Is it possible to delay execution of shortcode output callback?

I have a problem : shortcode output callback triggered too early. /* Defined in plugin constructor */ add_shortcode( 'foobar' , array($this,'pre_render_routine')); function ...
2
votes
1answer
792 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
0answers
145 views

wp.media add context

I have wp.media frame on my plugin to upload doc, docx file. I am filtering the uploaded file. If uploaded other than supported file, it will display this error I am filtering it at ...
2
votes
0answers
447 views

Hook before & after plugin / core update

I'm working on a maintenance plugin for my website and I want to enable it before plugin/core upgrade starts and disable it after plugin/upgrade ends. Any ideas ? Thanks! :) PS: all I know is I can ...
2
votes
0answers
2k views

How to set a custom path, for ajax image upload folder in admin?

I am coding my first Wordpress plugin that handles some data for a custom (shop-like) post type. It also has an image uploader within a metabox, where you simply drag in your images and it ...
2
votes
2answers
531 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
1answer
378 views

publish_post plugin hook doesn't always pass $post->post_content

I've written a simple plugin that grabs the contents of a post, as the post is published, and sends them to an external site for archiving. This generally works but when dealing with posts that haven'...
2
votes
1answer
1k views

Firing a function AFTER redirect

I am using a function that redirects the user to a custom page, rather than wp-login in the event of errors. In my case I am using the Http Referer function to send the user back to the same page ...
2
votes
1answer
1k views

WordPress Ajax callback function from plugin - OOP

Using PluginBoilerplate to write a plugin. I need to make an ajax call. I added to main plugin.php file, class to register scripts and handle ajax calls. if ( ! class_exists( 'PoorMansNameSpaceAJAX' ...
1
vote
0answers
22 views

Map a custom id to wordpress post id

I am new to Wordpress and wondering what the best way might be to go about doing this. We have a requirement to map our own id (known as friendly_id) to the Wordpress's post id. The idea is to import ...
1
vote
0answers
12 views

What is the filter or hook to add admin controls to posts on the front end?

What is the filter or hook that would allow me to add a custom control (an action link) for admins next to "Edit" on posts on the front end? I want to give admins the option of carrying out ...
1
vote
0answers
20 views

Is there a hook that fires when a row of wp_sitemeta table is updated?

I'm looking for something like the updated_options hook but instead of firing when a row from wp_options is updated, I want to perform some action when a row from wp_sitemeta is updated. Is there a ...
1
vote
0answers
25 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
159 views

woocommerce_package_rates not fired when wordpress woocommerce accessed as non ajax

I use woocommerce_package_rates hook on woocommerce so I could change the flat rate on checkout page, but the problem is when someone access the checkout page without js enabled, it will cause the ...
1
vote
0answers
20 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
1answer
585 views

Is there a better way to implement responsive images than what WordPress uses by default?

I am new to WordPress, and I started with my own custom theme. For responsive images in WordPress, I currently use custom html blocks in my theme with picture or img elements that use multiple ...
1
vote
0answers
9 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
1answer
18 views

wp_get_post_terms is difference obj model than the one in rest api response

I'm building a mobile app and using the rest API on WordPress to do that, I am customizing the /wp/v2/posts response by using the following code: add_filter('rest_prepare_post', '...
1
vote
0answers
26 views

Update a costume wp_usermeta key back to 0 every 24hours (time can be specified as needed)

I'm new around here but I will do my best to get the question out as clear as possible. I'm developing a website where users will be able to publish portfolio items from the front-end of the website. ...
1
vote
1answer
77 views

Send email with custom fields after new draft is saved or new post published

I have a custom post type immobile with some custom fields created with Toolset Types. I need to send and email with the title and a custom field when a new immobile is saved as a draft or it's ...
1
vote
0answers
100 views

Execute a ultimate member action when user role is updated

I want an Ultimate Member action to be performed when I assign a particular role to a user. A role "old_member" exists. If I assign this role to a user, the account should deactivate itself with the ...
1
vote
0answers
23 views

Send push when new post is published in a certain category

I'm trying to develop a plugin which send a push notification to an app users, when a new post is published on a certain category. I'm trying with the hook save_post, but when the hook is fired, the ...
1
vote
0answers
187 views

Viewing checkout page removes fees from mini cart

I customized the mini cart to show a breakdown of fees (discounts) to the customer. This works however if you visit the checkout page, which also uses ajax to load cart totals, when its done loading, ...

1
2 3 4 5
12