Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpataki/9148d10493cead437bc2 to your computer and use it in GitHub Desktop.
Save danielpataki/9148d10493cead437bc2 to your computer and use it in GitHub Desktop.
Figuring Out Hooks
add_action( 'save_post', 'tweet_my_mood' );
function tweet_my_mood( $post_id, $post ) {
echo get_post_meta( $post_id, 'mood', true );
exit();
}
add_filter( 'post_class', 'my_post_class', 10, 3 );
function my_post_class( $classes , $class, $post_id ) {
$date = strtotime( get_post_field( 'post_date', $post_id ) );
if( $date < strtotime( '2010-01-01 00:00:00' ) ) {
$classes[] = 'old-post';
}
return $classes;
}
/**
* Filter the list of CSS classes for the current post.
*
* @since 2.7.0
*
* @param array $classes An array of post classes.
* @param string $class A comma-separated list of additional classes added to the post.
* @param int $post_id The post ID.
*/
$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
add_action( 'save_post', 'tweet_my_mood' );
function tweet_my_mood( $post_id, $post ) {
$mood = get_post_meta( $post_id, 'mood', true );
tweet_mood( $mood );
}
function wp_publish_post( $post ) {
global $wpdb;
if ( ! $post = get_post( $post ) )
return;
if ( 'publish' == $post->post_status )
return;
$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
clean_post_cache( $post->ID );
$old_status = $post->post_status;
$post->post_status = 'publish';
wp_transition_post_status( 'publish', $old_status, $post );
/** This action is documented in wp-includes/post.php */
do_action( 'edit_post', $post->ID, $post );
/** This action is documented in wp-includes/post.php */
do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
/** This action is documented in wp-includes/post.php */
do_action( 'save_post', $post->ID, $post, true );
/** This action is documented in wp-includes/post.php */
do_action( 'wp_insert_post', $post->ID, $post, true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment