query( 'jetpack.verifyFrameNonce', sanitize_key( $_GET['frame-nonce'] ) ); if ( $xml->isError() ) { return false; } return (bool) $xml->getResponse(); } /** * Conditionally add a hook on posts_results if this is the main query, a preview, and singular. * * @since 4.3.0 * * @param WP_Query $query * * @return WP_Query */ public function maybe_display_post( $query ) { if ( $query->is_main_query() && $query->is_preview() && $query->is_singular() ) { add_filter( 'posts_results', array( $this, 'set_post_to_publish' ), 10, 2 ); } return $query; } /** * Conditionally set the first post to 'publish' if the frame nonce is valid and there is a post. * * @since 4.3.0 * * @param array $posts * * @return array */ public function set_post_to_publish( $posts ) { remove_filter( 'posts_results', array( $this, 'set_post_to_publish' ), 10, 2 ); if ( empty( $posts ) || is_user_logged_in() || ! $this->is_frame_nonce_valid() ) { return $posts; } $posts[0]->post_status = 'publish'; // Disable comments and pings for this post. add_filter( 'comments_open', '__return_false' ); add_filter( 'pings_open', '__return_false' ); return $posts; } /** * Handle validation for autosave preview request * * @since 4.7.0 * */ public function handle_autosave_nonce_validation() { if ( ! $this->is_frame_nonce_valid() ) { wp_die( __( 'Sorry, you are not allowed to preview drafts.', 'jetpack' ) ); } add_filter( 'the_preview', '_set_preview' ); } } Jetpack_Frame_Nonce_Preview::get_instance();