Hook for URL Request

Actually, my recommendation would be to do things a bit differently. You can add a custom rewrite endpoint to WordPress to handle these files specifically. For example, the URL http://site.com/download-xml/the_filename would automatically download the specified file as an attachment. First, you need to add a custom rewrite endpoint to set this up: function add_endpoint() { … Read more

Send data to 3rd party api with wp_remote_post on wp_login

The ‘body’ needs to be an array, not including the ‘json_encode($user)’ piece. $response = wp_remote_post( ‘myapp.com/endpoint’, array( ‘method’ => ‘POST’, ‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’), ‘body’ => $user ) ); I have this in my function since I also had issues with the body being an object: if (is_object($user) && !is_array($user)) $user = json_decode(json_encode($user), … Read more

Hook into wp_head(); in a plugin

Did you try this? function hook_header() { $example_position = get_theme_mod( ‘logo_placement’ ); if( $example_position != ” ) { switch ( $example_position ) { case ‘left’: // Do nothing. The theme already aligns the logo to the left break; case ‘right’: echo ‘<style type=”text/css”>’; echo ‘#main-header #logo{ float: right; }’; echo ‘</style>’; break; case ‘center’: echo … Read more

How can I send to multiple Contact Form 7 recipients based on form input? [closed]

No need to write any code, Contact form 7 has features of Additional Headers in the Mail section. In that you just need to write the email’s header inside the Additional headers textbox in Mail(Second Tab) section. Put this inside the Additional Headers textbox. Cc: [friend1-email], [friend2-email], [friend3-email], [friend4-email], [friend5-email] OR You can alter the … Read more

How to check if which hook triggered the call to a function?

I found the magic code you need. Use current_filter(). This function will return name of the current filter or action. add_action(‘my_test_hook_1′,’my_test_callback_function’); add_action(‘my_test_hook_2′,’my_test_callback_function’); add_action(‘my_test_hook_3′,’my_test_callback_function’); add_action(‘my_test_hook_4′,’my_test_callback_function’); function my_test_callback_function(){ $called_action_hook = current_filter(); // ***The magic code that will return the last called action echo “This function is called by action: ” . $called_action_hook ; } For reference: https://developer.wordpress.org/reference/functions/current_filter/

Are hooks called synchronously?

The do_action() and apply_filters() are both wrappers of the WP_Hook::apply_filters() method, that invokes the registered callbacks in sequential order (src). Here’s a simple test: Let’s define a callback wrapper: $callback_gen = function( $seconds ) { return function() use ( $seconds ) { sleep( $seconds ); printf( ‘%s finished’ . PHP_EOL, $seconds ); }; }; Next … Read more

Adding function directly vs using hook in function.php

Imagine 2 people are cooking food, and both are following a recipe, when both reach instruction 5. This instruction tells them what to do with some uncooked meat that may be dangerous to eat uncooked. In Alices‘s cookbook she sees: When the meat is safely cooked, eat the meat In Bobs‘s cookbook he sees: eat … Read more