Conditionally call add_action depending on post_type?

Using OOP PHP, add your initializer actions in the __construct and create appropriate methods for handling them. From your handler you can initialize any class variable (once) you want and reference it later without having to do any further checks. Here is an example: class my_plugin { private $post_type; private $isCustom = false; public function … Read more

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

The third parameter, $commentdata can be used to get the ID for the post that the comment was made on: function wpse211367_comment( $comment_ID, $comment_approved, $commentdata ) { // The id for the post that the comment is related to is available // in the $commentdata array: $comment_post_id = $commentdata[‘comment_post_ID’]; } add_action( ‘comment_post’, ‘wpse211367_comment’, 10, 3 … Read more

How to filter content post only on save

Look at ‘save_post’ and Post Status Transitions. save_post is an action triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. The data for the post is stored in $_POST, $_GET or the global $post_data, depending on how the post was … Read more

How can i trigger an action manually?

Use do_action, you can just: do_action( ‘my_action’); if your action has a callback function that need arguments say: function my_callback( $an_array ){ //use the array for something here var_dump($an_array); } add_action( ‘my_action’, ‘my_callback’ ); you can specify it in the do_action like this: do_action( ‘my_action’, array( ‘array_for_callback’) );

Add “Page Revised” column to Admin

Would need some prettifying, but basic code is following: add_filter(‘manage_pages_columns’, ‘add_revised_column’); add_action(‘manage_pages_custom_column’, ‘echo_revised_column’, 10, 2); function add_revised_column($columns) { $columns[‘revised’] = ‘Revised’; return $columns; } function echo_revised_column($column, $id) { if (‘revised’ == $column) echo get_post_field(‘post_modified’, $id); }