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

About Hooks and Filters

Seeing that you’ve referenced 3 Genesis Developers, i’d like to answer this question using 2 Genesis code snippets as well as 2 WordPress examples of action hooks and filters. Hooks Different template files in Genesis include hooks which simply enable you to execute PHP code in that position of the template. Here’s a visual guide … Read more

How to override WordPress registration and insert an auto-generated username?

One alternative is to modify the $_POST[‘user_login’] input value when submitting new registration form, that is before WP process the registration form. A good hook to achieve this is login_form_register that fires before processing and rendering registration form. login_init also works but need more work to make sure we are on register action. add_action(‘login_form_register’, ‘custom_user_login’); … 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

Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more

Am I using the right hook for removing quicktags on the admin TinyMCE?

After checking out the code, the best way to do this would be to use the wp_editor_settings filter in /wp-includes/class-wp-editor.php. When you call wp_editor() it internally makes a call to _WP_Editors::editor($content, $editor_id, $settings);. This function first passes the $settings array through parse_settings() which uses that filter. add_filter( ‘wp_editor_settings’, ‘remove_editor_quicktags’, 10, 2 ); function remove_editor_quicktags( $settings, … Read more

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