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

Can I hook inside another hook?

When it comes to the oop way of doing things you need more than just the class, you also need to instantiate it as an object at some point if you want the action to fire. class myClass{ function __construct(){ add_action( ‘init’, array( $this, ‘someFun’ ) ); } function someFun(){ include( ‘my-script.php’ ); } } … Read more

__NAMESPACE__ with register_activation_hook

The reason that the plugin activation hook wasn’t working in the code provided in the question is that on plugin activation the plugins_loaded hook is never run. Since the register_activation_hook hook was hooked from plugins_loaded it was never run on activation. And since it’s never fired ever again, this way of hooking results in register_activation_hook … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)