Rest API Hook When Post Is Requested

My original answer was all wrong, so it’s been removed in it’s entirety. Neither the posts_selection nor wp hook are fired during the REST API request. The hook you need is rest_pre_echo_response. This hook passes three parameters: The response data to send to the client The server instance. The request used to generate the response. … Read more

How to debug removal of rewrite rule flushing?

To see if the option ‘rewrite_rules’ was reset – that’s what flush_rewrite_rules() does internally – hook into the option actions and log what happens. The following small plugin does that. It will tell you what code flushed the rewrite rules and how the rules looked before and after the flush. If no flush happened it … Read more

Can’t get ID of post that relates to the comment

comment_post hook pass to attached functions 3 parameters. The fourth parameter of add_action() indicates to how many parameters the attached function will be able to access. add_action( ‘comment_post’, ‘save_chbox_in_db’, 10, 3 ); function save_chbox_in_db( $comment_ID, $comment_approved, $commentdata ) { $post_id = (int)$commentdata[‘comment_post_ID’]; // // other code // }

Setcookie works on admin but not front end

Some things non-WordPress specific regarding cookies: set cookie fails if some output has been done in the page you can’t access to coockie value in the same request you set it (as @Milo pointed out in a comment to OP) Another general rule is better to use filter_input or filter_intput_array instead of direct accessing to … Read more

Hooks are not executing

The do_action is in the wrong place. It is calling it’s self. You have this: public function hook_name() { do_action(‘hook_name’); } Do this: do_action(‘hook_name’); public function hook_name() { do_action(‘other_hook_name’); }

Removing action added from constructor

If that class works as a singleton and has a getInstance() method (or similar) to retrieve the instance, you can remove the action pretty much the same way it was added: remove_action(‘wp_travel_engine_enquiry_form’, array( $instance, ‘wpte_enquiry_form’ )); Edit: I’ve looked into this some more, and you find the necessary information by looking into $wp_filters (global variable, … Read more

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