* Output the rel next/prev tags on a paginated single post. * * @return void */ private function adjacent_rel_links_single() { $num_pages = 1; $queried_object = get_queried_object(); if ( ! empty( $queried_object ) ) { $num_pages = substr_count( $queried_object->post_content, '' ) + 1; } if ( 1 === $num_pages ) { return; } $page = max( 1, (int) get_query_var( 'page' ) ); $url = get_permalink( get_queried_object_id() ); if ( $page > 1 ) { $this->adjacent_rel_link( 'prev', $url, $page - 1, 'page' ); } if ( $page < $num_pages ) { $this->adjacent_rel_link( 'next', $url, $page + 1, 'page' ); } } /** * Output the rel next/prev tags on archives. */ private function adjacent_rel_links_archive() { $url = Paper::get()->get_canonical( true, true ); if ( ! is_string( $url ) || '' === $url ) { return; } $paged = max( 1, (int) get_query_var( 'paged' ) ); if ( 2 === $paged ) { $this->adjacent_rel_link( 'prev', $url, $paged - 1 ); } if ( is_front_page() ) { $url = Router::get_base_url( '' ); } if ( $paged > 2 ) { $this->adjacent_rel_link( 'prev', $url, $paged - 1 ); } if ( $paged < $GLOBALS['wp_query']->max_num_pages ) { $this->adjacent_rel_link( 'next', $url, $paged + 1 ); } } /** * Build adjacent page link for archives. * * @param string $rel Prev or next. * @param string $url The current archive URL without page parameter. * @param string $page The page number added to the $url in the link tag. * @param string $query_arg The pagination query argument to use for the $url. */ private function adjacent_rel_link( $rel, $url, $page, $query_arg = 'paged' ) { global $wp_rewrite; if ( $page > 1 ) { $url = ! $wp_rewrite->using_permalinks() ? Security::add_query_arg_raw( $query_arg, $page, $url ) : user_trailingslashit( trailingslashit( $url ) . $this->get_pagination_base() . $page ); } /** * Change the link rel HTML output. * * @param string $link The `do_filter( "frontend/{$rel}_rel_link", '\n" ); if ( Str::is_non_empty( $link ) ) { $allowed_tags = [ 'link' => [ 'href' => [], 'rel' => [], ], ]; echo wp_kses( $link, $allowed_tags ); } } /** * Get pagination base. * * @return string The pagination base. */ private function get_pagination_base() { global $wp_rewrite; return ( ! is_singular() || Post::is_home_static_page() ) ? trailingslashit( $wp_rewrite->pagination_base ) : ''; } /** * Credits. * * @param boolean $closing Is closing credits needed. */ private function credits( $closing = false ) { /** * Disable credit in the HTML source. * * @param bool $remove */ if ( $this->do_filter( 'frontend/remove_credit_notice', false ) ) { return; } if ( false === $closing ) { if ( ! Helper::is_whitelabel() && ! defined( 'RANK_MATH_PRO_FILE' ) ) { echo "\n\n"; } elseif ( defined( 'RANK_MATH_PRO_FILE' ) ) { echo "\n\n"; } return; } if ( ! Helper::is_whitelabel() ) { echo '\n\n"; } } /** * Start the Output Buffer. * * @since 1.0.29 */ public function start_ob() { ob_start(); } /** * Use output buffering to force rewrite the title tag. */ public function rewrite_title() { global $wp_query; // Check if we're in the main query. $old_wp_query = null; if ( ! $wp_query->is_main_query() ) { $old_wp_query = $wp_query; wp_reset_query(); //phpcs:ignore -- This function is needed here to reset the query before running the head code. } $content = ob_get_clean(); $title = Paper::get()->get_title(); if ( empty( $title ) ) { echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- This is the output buffer, escaping is unnecessary. } // Find all title tags, remove them, and add the new one. $content = preg_replace( '//i', '', $content ); $content = str_replace( '', '' . "\n" . '' . esc_html( $title ) . '', $content ); if ( ! empty( $old_wp_query ) ) { $GLOBALS['wp_query'] = $old_wp_query; } echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- This is the output buffer, escaping is unnecessary. } }