Created
November 5, 2012 16:53
-
-
Save micahwave/4018279 to your computer and use it in GitHub Desktop.
publish package slides
This file contains hidden or 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
/** | |
* Make slide post_status mirror the post status of the parent post | |
* | |
* Using $wpdb to update the values because I don't want to toggle all our other actions | |
*/ | |
function time_transition_package_status( $new_status, $old_status, $post ) { | |
global $wpdb; | |
// this is only for posts | |
if( $post->post_type != 'post' ) return; | |
// sometimes the format wont be set, we need to get it from $_POST | |
$format = isset( $_POST['time_post_format'] ) ? str_replace( 'time-post-format-', '', $_POST['time_post_format'] ) : time_get_post_format( $post->ID ); | |
// package == special | |
if( $format == 'special' ) { | |
// published packages | |
if( $old_status != 'publish' && $new_status == 'publish' ) { | |
// update all the slides to have a post_status of publish | |
$slides = time_get_slides( $post->ID ); | |
if( $slides ) { | |
$wpdb->query( | |
" | |
UPDATE $wpdb->posts | |
SET $wpdb->posts.post_status = 'publish' | |
WHERE $wpdb->posts.ID IN (".implode( ',', wp_list_pluck( $slides, 'ID' ) ).") | |
" | |
); | |
clean_post_cache( $post->ID ); | |
} | |
} else if( $old_status == 'publish' && $new_status != 'publish' ) { | |
// set all the slides to draft status | |
$slides = time_get_slides( $post->ID ); | |
if( $slides ) { | |
$wpdb->query( | |
" | |
UPDATE $wpdb->posts | |
SET $wpdb->posts.post_status = 'draft' | |
WHERE $wpdb->posts.ID IN (".implode( ',', wp_list_pluck( $slides, 'ID' ) ).") | |
" | |
); | |
clean_post_cache( $post->ID ); | |
} | |
} | |
} | |
} | |
add_action( 'transition_post_status', 'time_transition_package_status', 2, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment