Articles of hooks

Pass info from functions.php to plugin

What is the best way to pass some information from functions.php to a plugin? I need to give a user the ability to pass a piece of data from their functions.php file to my plugin. (It can be any data, just something that I can check for; it can be a variable’s value, or even […]

WordPress Plugin Boilerplate – add_action hook in static “activate” function

I’m hoping someone can point me in the right direction here. I’m using the WordPress Plugin Boilerplate to develop a custom plugin. On install, the plugin will register a new post type (course), a new taxonomy (course-areas) and set up permalink structures for the new post type and taxonomy. I’ve added my code (to create […]

My add_action (wp_footer, 'method') is not calling?

In my themes functions.php file I have put: add_action(‘wp_footer’, ‘method’); function method() { echo “this is being called”; die(); } My wordpress footer.php file looks like this: <?php wp_footer(); ?> </body> </html> What could be the reason my add_action hook is not being called? I can provide additional code or information if needed. EDIT: Instead […]

How to intercept a 404 error

I’d like to intercept 404 errors and do some things before to show the 404 error page. How can intercept the 404 error?

Gravity Forms – Using a Form to Pre-populate A Gravity Form

I have a custom form (hardcoded, not a GF) on one page I’ve written myself: <form id=”tailor-select” method=”POST”> <ul> <li> <ul> <li> <input name=”input_9.1″ type=”checkbox” value=”Cover Design” id=”choice_2_9_1″ tabindex=”1″> <label for=”choice_2_9_1″ id=”label_2_9_1″>Cover Design</label> </li> <li> <input name=”input_9.2″ type=”checkbox” value=”Artwork Creation” id=”choice_2_9_2″ tabindex=”2″> <label for=”choice_2_9_2″ id=”label_2_9_2″>Artwork Creation/Redrawing/Relabelling <a rel=”#artwork” href=”javascript:void(0);”>read more ></a></label> </li> <li> <input name=”input_9.3″ […]

add_action for unknown custom post types

If the custom post type is known (e.g., ‘reference’) then the add_action is add_action( ‘publish_reference’ , ‘run_new_post_code’ ); Great. But what is the proper code for an unknown custom post type? I tried to add a text box so the custom_post_type could be added by the end-user. This is then called in $custom_post_type =. A […]

Adding dynamic section to WordPress

[Edit: I’ve added a more concrete example below] I need to convert a custom PHP site to WordPress. The site has 60,000+ media items along with a ton of metadata, all of which needs to carry over to the new site. The media data is accessed via a local API and I’ve already figured out […]

WooCommerce: Add Payment Gateway Field to Webhooks

I have created a custom Payment Gateway for a special EFT system we have setup. The Bank Account and Routing Number are supposed to get encrypted then sent to a Salesforce via the WooCommerce webhooks to be processed. Unfortunately, I cannot figure out how to add the Bank Number and Routing Number as line-items to […]

On WordPress 4.4, how to get the post id using the comment_post hook

Since WordPress 4.4, it seems like it is no longer possible to use get_the_ID() or the_ID() when hooking onto the comment_post action. How can I get the post_id when a new comment is saved?

Namespaced action and filter tags

I’m upgrading several of my plugins to use PHP namespaces, so that functions, classes, constants etc are all namespaced correctly. <?php namespace my\plugin; function init() { … } // Calls \my\plugin\init(); add_action(‘init’, __NAMESPACE__.’\init’); In several places my plugin calls do_action or apply_filters so that other plugins can modify its behaviour. If these are actions or […]