| @@ -12,5 +12,55 @@ | ||
| 12 | 12 | function ef_draft_or_post_title( $post_id = 0 ) { |
| 13 | 13 | $post = get_post( $post_id ); |
| 14 | 14 | return ! empty( $post->post_title ) ? $post->post_title : __( '(no title)', 'edit-flow' ); |
| 15 | 15 | } |
| 16 | -endif; | |
| 16 | +endif; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * This function is necessary to make post preview pagination work with custom post statuses | |
| 20 | + * @see _wp_link_page() | |
| 21 | + * @modified WordPress 4.9.2 | |
| 22 | + * | |
| 23 | + * Original Comments: | |
| 24 | + * | |
| 25 | + * Helper function for wp_link_pages() | |
| 26 | + * | |
| 27 | + * @since 3.1.0 | |
| 28 | + * @access private | |
| 29 | + * | |
| 30 | + * @global WP_Rewrite $wp_rewrite | |
| 31 | + * | |
| 32 | + * @param int $i Page number. | |
| 33 | + * @return string Link. | |
| 34 | + */ | |
| 35 | +if ( ! function_exists( '_ef_wp_link_page' ) ) { | |
| 36 | + function _ef_wp_link_page( $i, $custom_statuses ) { | |
| 37 | + global $wp_rewrite; | |
| 38 | + $post = get_post(); | |
| 39 | + $query_args = array(); | |
| 40 | + | |
| 41 | + if ( 1 == $i ) { | |
| 42 | + $url = get_permalink(); | |
| 43 | + } else { | |
| 44 | + // Check for all custom post statuses, not just draft & pending | |
| 45 | + if ( '' == get_option('permalink_structure') || in_array($post->post_status, array_merge( $custom_statuses, array( 'pending' ) ) ) ) | |
| 46 | + $url = add_query_arg( 'page', $i, get_permalink() ); | |
| 47 | + elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) | |
| 48 | + $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); | |
| 49 | + else | |
| 50 | + $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); | |
| 51 | + } | |
| 52 | + | |
| 53 | + if ( is_preview() ) { | |
| 54 | + | |
| 55 | + // Check for all custom post statuses, no just the draft | |
| 56 | + if ( ( ! in_array($post->post_status, $custom_statuses ) ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { | |
| 57 | + $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] ); | |
| 58 | + $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + $url = get_preview_post_link( $post, $query_args, $url ); | |
| 62 | + } | |
| 63 | + | |
| 64 | + return '<a href="' . esc_url( $url ) . '">'; | |
| 65 | + } | |
| 66 | +} | |