Last active
August 29, 2015 14:11
-
-
Save danielpataki/9148d10493cead437bc2 to your computer and use it in GitHub Desktop.
Figuring Out Hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'save_post', 'tweet_my_mood' ); | |
function tweet_my_mood( $post_id, $post ) { | |
echo get_post_meta( $post_id, 'mood', true ); | |
exit(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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