@@ -89,7 +89,7 @@ public function __construct( WP_Customize_Manager $manager ) {
8989 add_filter ( 'customize_snapshot_save ' , array ( $ this , 'transition_customize_draft ' ) );
9090 add_filter ( 'post_link ' , array ( $ this , 'post_link_draft ' ), 10 , 2 );
9191 add_filter ( 'post_type_link ' , array ( $ this , 'post_link_draft ' ), 10 , 2 );
92- add_filter ( 'page_link ' , array ( $ this , 'page_link_draft ' ), 10 , 2 );
92+ add_filter ( 'page_link ' , array ( $ this , 'post_link_draft ' ), 10 , 2 );
9393 add_action ( 'wp_ajax_customize-posts-add-new ' , array ( $ this , 'ajax_add_new_post ' ) );
9494
9595 $ this ->preview = new WP_Customize_Posts_Preview ( $ this );
@@ -702,57 +702,17 @@ public function transition_customize_draft( $data ) {
702702 *
703703 * @access public
704704 *
705- * @param string $permalink The post's permalink.
706- * @param WP_Post $post The post in question.
705+ * @param string $permalink The post's permalink.
706+ * @param int| WP_Post $post The post in question.
707707 * @return string
708708 */
709709 public function post_link_draft ( $ permalink , $ post ) {
710- if ( $ post instanceof WP_Post ) {
711- remove_filter ( 'post_link ' , array ( $ this , 'post_link_draft ' ), 10 );
712- remove_filter ( 'post_type_link ' , array ( $ this , 'post_link_draft ' ), 10 );
713- $ old_permalink = get_permalink ( $ post ->ID );
714- add_filter ( 'post_link ' , array ( $ this , 'post_link_draft ' ), 10 , 2 );
715- add_filter ( 'post_type_link ' , array ( $ this , 'post_link_draft ' ), 10 , 2 );
716-
717- $ post_status_match = in_array ( get_post_status ( $ post ->ID ), self ::$ draft_status , true );
718- $ post_slug_mismatch = get_option ( 'permalink_structure ' ) && basename ( $ old_permalink ) !== $ post ->post_name ;
719-
720- if ( $ post_status_match || $ post_slug_mismatch ) {
721- $ permalink = Edit_Post_Preview::get_preview_post_link ( $ post );
722- }
710+ if ( is_customize_preview () ) {
711+ $ permalink = Edit_Post_Preview::get_preview_post_link ( get_post ( $ post ) );
723712 }
724-
725713 return $ permalink ;
726714 }
727715
728- /**
729- * Filter the preview permalink for a page.
730- *
731- * @access public
732- *
733- * @param string $link The page's permalink.
734- * @param int $post_id The ID of the page.
735- * @return string
736- */
737- public function page_link_draft ( $ link , $ post_id ) {
738- $ post = get_post ( $ post_id );
739-
740- if ( $ post instanceof WP_Post ) {
741- remove_filter ( 'page_link ' , array ( $ this , 'page_link_draft ' ), 10 );
742- $ old_permalink = get_permalink ( $ post ->ID );
743- add_filter ( 'page_link ' , array ( $ this , 'page_link_draft ' ), 10 , 2 );
744-
745- $ post_status_match = in_array ( get_post_status ( $ post ->ID ), self ::$ draft_status , true );
746- $ post_slug_mismatch = get_option ( 'permalink_structure ' ) && basename ( $ old_permalink ) !== $ post ->post_name ;
747-
748- if ( $ post_status_match || $ post_slug_mismatch ) {
749- $ link = Edit_Post_Preview::get_preview_post_link ( $ post );
750- }
751- }
752-
753- return $ link ;
754- }
755-
756716 /**
757717 * Add a new `auto-draft` post.
758718 *
0 commit comments