
WP-CLI v2 – 通过终端管理WordPress
_publish_post_hook ( $post_id )
_publish_post_hook。这个钩子在一个文章发布后被触发。它可以用来对文章进行操作,如发送通知邮件或更新相关内容。
当文章发布时,钩子会安排ping和包围。
使用XMLRPC_REQUEST和WP_IMPORTING常量。
function _publish_post_hook( $post_id ) { if ( defined( 'XMLRPC_REQUEST' ) ) { /** * Fires when _publish_post_hook() is called during an XML-RPC request. * * @since 2.1.0 * * @param int $post_id Post ID. */ do_action( 'xmlrpc_publish_post', $post_id ); } if ( defined( 'WP_IMPORTING' ) ) { return; } if ( get_option( 'default_pingback_flag' ) ) { add_post_meta( $post_id, '_pingme', '1', true ); } add_post_meta( $post_id, '_encloseme', '1', true ); $to_ping = get_to_ping( $post_id ); if ( ! empty( $to_ping ) ) { add_post_meta( $post_id, '_trackbackme', '1' ); } if ( ! wp_next_scheduled( 'do_pings' ) ) { wp_schedule_single_event( time(), 'do_pings' ); } }