check_and_publish_future_post

函式
check_and_publish_future_post ( $post )
引數
  • (int|WP_Post) $post Post ID or post object.
    Required:
定義位置
相關方法
get_others_unpublished_postsblock_core_calendar_has_published_postswp_publish_post_publish_post_hookblock_core_calendar_update_has_published_posts
引入
2.5.0
棄用
-

check_and_publish_future_post: 這個函式檢查一個預定的文章是否應該被髮布,如果是,就釋出它。它被WordPress內部用來發布預定的文章。

釋出未來的文章,並確保文章ID具有未來的文章狀態。

由cron’publish_future_post’事件呼叫。這一保障措施可以防止cron釋出草稿等。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function check_and_publish_future_post( $post ) {
$post = get_post( $post );
if ( ! $post ) {
return;
}
if ( 'future' !== $post->post_status ) {
return;
}
$time = strtotime( $post->post_date_gmt . ' GMT' );
// Uh oh, someone jumped the gun!
if ( $time > time() ) {
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); // Clear anything else in the system.
wp_schedule_single_event( $time, 'publish_future_post', array( $post->ID ) );
return;
}
// wp_publish_post() returns no meaningful value.
wp_publish_post( $post->ID );
}
function check_and_publish_future_post( $post ) { $post = get_post( $post ); if ( ! $post ) { return; } if ( 'future' !== $post->post_status ) { return; } $time = strtotime( $post->post_date_gmt . ' GMT' ); // Uh oh, someone jumped the gun! if ( $time > time() ) { wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); // Clear anything else in the system. wp_schedule_single_event( $time, 'publish_future_post', array( $post->ID ) ); return; } // wp_publish_post() returns no meaningful value. wp_publish_post( $post->ID ); }
function check_and_publish_future_post( $post ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return;
	}

	if ( 'future' !== $post->post_status ) {
		return;
	}

	$time = strtotime( $post->post_date_gmt . ' GMT' );

	// Uh oh, someone jumped the gun!
	if ( $time > time() ) {
		wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); // Clear anything else in the system.
		wp_schedule_single_event( $time, 'publish_future_post', array( $post->ID ) );
		return;
	}

	// wp_publish_post() returns no meaningful value.
	wp_publish_post( $post->ID );
}

常見問題

FAQs
檢視更多 >