Created
October 9, 2012 17:00
-
-
Save anonymous/3860049 to your computer and use it in GitHub Desktop.
Testing wp_update_post and post_status transitions
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
<?php | |
if($_GET) | |
test_content_date_edit(); | |
function test_content_date_edit() { | |
$newpostdata = array( | |
'post_title' => 'test_post', | |
'post_content' => 'test_content' ); | |
/** | |
* These are the only bits being altered for the tests. | |
* $post_id is only used when editing | |
*/ | |
$operation = 'edit'; | |
$post_date = strtotime( "yesterday" ); | |
$post_id = 40; | |
/* | |
* Simply check if the desired post is past/current or future, to decide | |
* the new post_status | |
*/ | |
if ( $post_date < strtotime( "tomorrow" ) ) { | |
$status = 'publish'; | |
$newpostdata['post_status'] = $status; | |
$newpostdata['post_date'] = date( 'Y-m-d H:i:s', $post_date ); | |
$msg .= 'publish'; | |
} elseif ( $post_date > strtotime( 'today' ) ) { | |
$status = 'future'; | |
$newpostdata['post_status'] = $status; | |
$newpostdata['post_date'] = date( 'Y-m-d H:i:s', $post_date ); | |
$msg .= 'future'; | |
} | |
/* | |
* Test if we're including or editing and apply $post_id when needed. | |
*/ | |
if ( 'include' == $operation ) { | |
$err = wp_insert_post($newpostdata, true); | |
$msg .= ' include'; | |
} elseif ( 'edit' == $operation ) { | |
$newpostdata['ID'] = $post_id; | |
$err = wp_update_post( $newpostdata ); | |
$msg .= ' edit'; | |
} | |
$msg = array('postid' => $err, 'resp' => $msg); | |
var_dump($msg); | |
return $msg; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment