get_referer() && isset( $_SERVER['REQUEST_URI'] ) && ( false !== strpos( $request_uri, 'wp-json' ) || false !== strpos( $request_uri, 'rest_route' ) ); } public function get_wp_link_page( $i ) { if ( ( ! is_singular() || is_front_page() ) && ! $this->is_rest_request() && ! $this->is_allow_to_use_custom_page_option() ) { return get_pagenum_link( $i ); } // Based on wp-includes/post-template.php:957 `_wp_link_page`. global $wp_rewrite; $post = get_post(); $query_args = []; $url = get_permalink(); if ( $this->is_rest_request() ) { $link_unescaped = wp_get_referer(); $post_id = url_to_postid( $link_unescaped ); if ( $post_id > 0 ) { $post = get_post( $post_id ); } $url = $this->get_base_url_for_rest_request( $post_id, $url ); } if ( $i > 1 ) { if ( '' === get_option( 'permalink_structure' ) || in_array( $post->post_status, [ 'draft', 'pending' ] ) ) { $url = add_query_arg( $this->get_wp_pagination_query_var(), $i, $url ); } elseif ( get_option( 'show_on_front' ) === 'page' && (int) get_option( 'page_on_front' ) === $post->ID ) { $url = trailingslashit( $url ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); } else { $url = trailingslashit( $url ) . user_trailingslashit( $i, 'single_paged' ); } } if ( $i > 1 && $this->is_allow_to_use_custom_page_option() ) { $url = $this->get_wp_link_page_url_for_custom_page_option( $url, $i, $post_id ?? 0 ); } if ( 1 === $i && $this->is_allow_to_use_custom_page_option() ) { $url = $this->get_base_url(); } if ( is_preview() ) { $url = $this->get_wp_link_page_url_for_preview( $post, $query_args, $url ); } if ( $this->is_rest_request() ) { $url = $this->get_wp_link_page_url_for_rest_request( $url, $link_unescaped ); } if ( ! $this->is_rest_request() && $this->current_url_contains_taxonomy_filter() && ! is_preview() ) { $url = $this->get_wp_link_page_url_for_normal_page_load( $url ); } return esc_url( apply_filters( 'elementor/posts/wp_link_page', $url ) ); } public function is_allow_to_use_custom_page_option() { return 'ajax' === $this->get_settings_for_display( 'pagination_load_type' ) || 'yes' === $this->get_settings_for_display( 'pagination_individual_handle' ); } protected function get_base_url_for_rest_request( $post_id, $url ) { if ( $post_id > 0 ) { return get_permalink( $post_id ); } global $wp_rewrite; if ( $wp_rewrite->using_permalinks() && ( $this->current_url_contains_taxonomy_filter() || $this->referer_contains_taxonomy_filter() ) ) { $url = $this->is_allow_to_use_custom_page_option() ? get_query_var( 'pagination_base_url' ) : get_query_var( 'pagination_base_url' ) . user_trailingslashit( "$wp_rewrite->pagination_base/", 'single_paged' ); } else { $url = remove_query_arg( 'p', $url ); } return $url; } protected function get_wp_link_page_url_for_preview( $post, $query_args, $url ) { if ( 'draft' === $post->post_status || ! isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { return $url; } $query_args['preview_id'] = Utils::_unstable_get_super_global_value( $_GET, 'preview_id' ); $query_args['preview_nonce'] = Utils::_unstable_get_super_global_value( $_GET, 'preview_nonce' ); if ( $this->is_rest_request() || ! $this->current_url_contains_taxonomy_filter() ) { return get_preview_post_link( $post, $query_args, $url ); } wp_parse_str( htmlspecialchars_decode( Utils::_unstable_get_super_global_value( $_SERVER, 'QUERY_STRING' ) ), $query_params ); foreach ( $query_params as $param_key => $param_value ) { if ( false !== strpos( $param_key, 'e-filter-' ) ) { $query_args[ $param_key ] = $param_value; } } return get_preview_post_link( $post, $query_args, $url ); } protected function get_wp_link_page_url_for_rest_request( $url, $link_unescaped ) { $url_components = wp_parse_url( $link_unescaped ); $query_args = []; if ( isset( $url_components['query'] ) ) { wp_parse_str( $url_components['query'], $query_args ); } $url = ! empty( $query_args ) ? $url . '&' . http_build_query( $query_args ) : $url; return $this->format_query_string_concatenation( $url ); } protected function get_wp_link_page_url_for_normal_page_load( $url ) { wp_parse_str( htmlspecialchars_decode( Utils::_unstable_get_super_global_value( $_SERVER, 'QUERY_STRING' ) ), $query_params ); $e_filters = ''; foreach ( $query_params as $param_key => $param_value ) { if ( false !== strpos( $param_key, 'e-filter' ) ) { $e_filters .= '&' . $param_key . '=' . $param_value; } } return $this->format_query_string_concatenation( $url . $e_filters ); } public function current_url_contains_taxonomy_filter() { return false !== strpos( Utils::_unstable_get_super_global_value( $_SERVER, 'QUERY_STRING' ), 'e-filter-' ); } public function referer_contains_taxonomy_filter() { return false !== strpos( Utils::_unstable_get_super_global_value( $_SERVER, 'HTTP_REFERER' ), 'e-filter-' ); } protected function format_query_string_concatenation( $input ) { if ( false === strpos( $input, '?' ) ) { // If "?" doesn't exist in the input URL, replace the first "&" with "?" $input = preg_replace( '/&/', '?', $input, 1 ); } return $input; } public function get_posts_nav_link( $page_limit = null ) { if ( ! $page_limit ) { $page_limit = $this->query->max_num_pages; } $return = []; $paged = $this->get_current_page(); $link_template = '%s'; $disabled_template = '%s'; if ( $paged > 1 ) { $next_page = intval( $paged ) - 1; if ( $next_page < 1 ) { $next_page = 1; } $return['prev'] = sprintf( $link_template, 'prev', $this->get_wp_link_page( $next_page ), $this->get_settings_for_display( 'pagination_prev_label' ) ); } else { $return['prev'] = sprintf( $disabled_template, 'prev', $this->get_settings_for_display( 'pagination_prev_label' ) ); } $next_page = intval( $paged ) + 1; if ( $next_page <= $page_limit ) { $return['next'] = sprintf( $link_template, 'next', $this->get_wp_link_page( $next_page ), $this->get_settings_for_display( 'pagination_next_label' ) ); } else { $return['next'] = sprintf( $disabled_template, 'next', $this->get_settings_for_display( 'pagination_next_label' ) ); } return $return; } protected function register_controls() { $this->start_controls_section( 'section_layout', [ 'label' => esc_html__( 'Layout', 'elementor-pro' ), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->end_controls_section(); } protected function get_pagination_type_options() { return [ '' => esc_html__( 'None', 'elementor-pro' ), 'numbers' => esc_html__( 'Numbers', 'elementor-pro' ), 'prev_next' => esc_html__( 'Previous/Next', 'elementor-pro' ), 'numbers_and_prev_next' => esc_html__( 'Numbers', 'elementor-pro' ) . ' + ' . esc_html__( 'Previous/Next', 'elementor-pro' ), self::LOAD_MORE_ON_CLICK => esc_html__( 'Load on Click', 'elementor-pro' ), self::LOAD_MORE_INFINITE_SCROLL => esc_html__( 'Infinite Scroll', 'elementor-pro' ), ]; } public function render_plain_content() {} /** * @param string $url * @param int $i * @param int $post_id * @return string */ private function get_wp_link_page_url_for_custom_page_option( $url, $i, $post_id ) { $base_raw_url = $this->is_rest_request() ? $this->get_base_url_for_rest_request( $post_id, $url ) : $this->get_base_url(); $pagination_key = 'e-page-' . $this->get_id(); if ( 'yes' === $this->get_settings_for_display( 'pagination_individual_handle' ) ) { $base_raw_url .= $this->get_pagination_query_vars_for_others_individually_paginated_widgets( $pagination_key ); } return $this->format_query_string_concatenation( $base_raw_url . '&' . $pagination_key . '=' . $i ); } private function get_pagination_query_vars_for_others_individually_paginated_widgets( string $pagination_key ): string { wp_parse_str( htmlspecialchars_decode( Utils::_unstable_get_super_global_value( $_SERVER, 'QUERY_STRING' ) ), $query_params ); $e_page = ''; foreach ( $query_params as $param_key => $param_value ) { if ( false !== strpos( $param_key, 'e-page' ) && $pagination_key !== $param_key ) { $e_page .= '&' . $param_key . '=' . $param_value; } } return $e_page; } /** * @return string */ private function get_wp_pagination_query_var() { if ( '' === get_option( 'permalink_structure' ) && $this->is_posts_page( $this->is_allow_to_use_custom_page_option() ) ) { return 'paged'; } return 'page'; } }