| @@ -1,18 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Edit Flow utility functions. | |
| 4 | - * | |
| 5 | - * @package EditFlow | |
| 6 | - */ | |
| 7 | 2 | |
| 8 | -if ( ! function_exists( 'ef_draft_or_post_title' ) ) : | |
| 3 | +if( ! function_exists( 'ef_draft_or_post_title' ) ) : | |
| 9 | 4 | /** |
| 10 | 5 | * Copy of core's _draft_or_post_title without the filters |
| 11 | 6 | * |
| 12 | 7 | * The post title is fetched and if it is blank then a default string is |
| 13 | 8 | * returned. |
| 14 | - * | |
| 15 | 9 | * @param int $post_id The post id. If not supplied the global $post is used. |
| 16 | 10 | * @return string The post title if set |
| 17 | 11 | */ |
| 18 | 12 | function ef_draft_or_post_title( $post_id = 0 ) { |
| @@ -20,57 +14,50 @@ | ||
| 20 | 14 | return ! empty( $post->post_title ) ? $post->post_title : __( '(no title)', 'edit-flow' ); |
| 21 | 15 | } |
| 22 | 16 | endif; |
| 23 | 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 | + */ | |
| 24 | 35 | if ( ! function_exists( '_ef_wp_link_page' ) ) { |
| 25 | - /** | |
| 26 | - * Make post preview pagination work with custom post statuses. | |
| 27 | - * | |
| 28 | - * This function is necessary to make post preview pagination work with custom post statuses. | |
| 29 | - * | |
| 30 | - * @see _wp_link_page() | |
| 31 | - * @modified WordPress 4.9.2 | |
| 32 | - * | |
| 33 | - * Original Comments: | |
| 34 | - * | |
| 35 | - * Helper function for wp_link_pages() | |
| 36 | - * | |
| 37 | - * @since 3.1.0 | |
| 38 | - * @access private | |
| 39 | - * | |
| 40 | - * @global WP_Rewrite $wp_rewrite | |
| 41 | - * | |
| 42 | - * @param int $i Page number. | |
| 43 | - * @param array $custom_statuses Custom post statuses. | |
| 44 | - * @return string Link. | |
| 45 | - */ | |
| 46 | 36 | function _ef_wp_link_page( $i, $custom_statuses ) { |
| 47 | 37 | global $wp_rewrite; |
| 48 | - $post = get_post(); | |
| 38 | + $post = get_post(); | |
| 49 | 39 | $query_args = array(); |
| 50 | 40 | |
| 51 | 41 | if ( 1 == $i ) { |
| 52 | 42 | $url = get_permalink(); |
| 53 | - // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found | |
| 54 | 43 | } else { |
| 55 | - // Check for all custom post statuses, not just draft & pending. | |
| 56 | - if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array_merge( $custom_statuses, array( 'pending' ) ) ) ) { | |
| 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' ) ) ) ) | |
| 57 | 46 | $url = add_query_arg( 'page', $i, get_permalink() ); |
| 58 | - } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) { | |
| 59 | - $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); | |
| 60 | - } else { | |
| 61 | - $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' ); | |
| 62 | - } | |
| 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'); | |
| 63 | 51 | } |
| 64 | 52 | |
| 65 | 53 | if ( is_preview() ) { |
| 66 | - // Check for all custom post statuses, not just the draft. | |
| 67 | - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Nonce verified by WordPress is_preview() and preview_nonce validation. | |
| 68 | - if ( ( ! in_array( $post->post_status, $custom_statuses ) ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { | |
| 69 | - $query_args['preview_id'] = absint( wp_unslash( $_GET['preview_id'] ) ); | |
| 70 | - $query_args['preview_nonce'] = sanitize_text_field( wp_unslash( $_GET['preview_nonce'] ) ); | |
| 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'] ); | |
| 71 | 59 | } |
| 72 | - // phpcs:enable WordPress.Security.NonceVerification.Recommended | |
| 73 | 60 | |
| 74 | 61 | $url = get_preview_post_link( $post, $query_args, $url ); |
| 75 | 62 | } |
| 76 | 63 | |
| @@ -75,5 +62,5 @@ | ||
| 75 | 62 | } |
| 76 | 63 | |
| 77 | 64 | return '<a href="' . esc_url( $url ) . '">'; |
| 78 | 65 | } |
| 79 | -} | |
| 66 | +} | |