nce()->get_preview_manager(); $preview_manager->switch_to_preview_query(); $render_html = parent::render_element( $data ); $preview_manager->restore_current_query(); return $render_html; } public function get_wp_preview_url() { // Ajax request from editor. // PHPCS - the method is safe - just retrieving a value. if ( ! empty( $_POST['initial_document_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing return parent::get_wp_preview_url(); } $preview_id = (int) $this->get_settings( 'preview_id' ); $post_id = $this->get_main_id(); list( $preview_category, $preview_object_type ) = array_pad( explode( '/', $this->get_settings( 'preview_type' ) ), 2, '' ); $home_url = trailingslashit( home_url() ); switch ( $preview_category ) { case 'archive': switch ( $preview_object_type ) { case 'author': if ( empty( $preview_id ) ) { $preview_id = get_current_user_id(); } $preview_url = get_author_posts_url( $preview_id ); break; case 'date': $preview_url = add_query_arg( 'year', gmdate( 'Y' ), $home_url ); break; } break; case 'search': $preview_url = add_query_arg( 's', $this->get_settings( 'preview_search_term' ), $home_url ); break; case 'taxonomy': $term = get_term( $preview_id ); if ( $term && ! is_wp_error( $term ) ) { $preview_url = get_term_link( $preview_id ); } break; case 'page': switch ( $preview_object_type ) { case 'home': $preview_url = get_post_type_archive_link( 'post' ); break; case 'front': $preview_url = $home_url; break; case '404': $preview_url = add_query_arg( 'p', '-1', $home_url ); break; } break; case 'post_type_archive': $post_type = $preview_object_type; if ( post_type_exists( $post_type ) ) { $preview_url = get_post_type_archive_link( $post_type ); } break; case 'single': $post = get_post( $preview_id ); if ( $post ) { $preview_url = get_permalink( $post ); } break; } // End switch(). if ( empty( $preview_url ) ) { $preview_url = $this->get_permalink(); } $query_args = [ 'preview' => true, 'preview_nonce' => wp_create_nonce( 'post_preview_' . $post_id ), 'theme_template_id' => $post_id, ]; $preview_url = set_url_scheme( add_query_arg( $query_args, $preview_url ) ); /** * Document "WordPress preview" URL. * * Filters the WordPress preview URL. * * @since 2.0.0 * * @param string $preview_url Document preview URL. * @param Theme_Document $this An instance of the theme document. */ $preview_url = apply_filters( 'elementor/document/wp_preview_url', $preview_url, $this ); return $preview_url; } public function get_preview_as_query_args() { $preview_id = (int) $this->get_settings( 'preview_id' ); list( $preview_category, $preview_object_type ) = array_pad( explode( '/', $this->get_settings( 'preview_type' ) ), 2, '' ); switch ( $preview_category ) { case 'archive': switch ( $preview_object_type ) { case 'author': if ( empty( $preview_id ) ) { $preview_id = get_current_user_id(); } $query_args = [ 'author' => $preview_id, ]; break; case 'date': $query_args = [ 'year' => gmdate( 'Y' ), ]; break; case 'recent_posts': $query_args = [ 'post_type' => 'post', ]; break; } break; case 'search': $query_args = [ 's' => $this->get_settings( 'preview_search_term' ), ]; break; case 'taxonomy': $term = get_term( $preview_id ); if ( $term && ! is_wp_error( $term ) ) { $query_args = [ 'tax_query' => [ [ 'taxonomy' => $term->taxonomy, 'terms' => [ $preview_id ], 'field' => 'id', ], ], ]; } break; case 'page': switch ( $preview_object_type ) { case 'home': $query_args = []; break; case 'front': $query_args = [ 'p' => get_option( 'page_on_front' ), 'post_type' => 'page', ]; break; case '404': $query_args = [ 'p' => -1, ]; break; } break; case 'post_type_archive': $post_type = $preview_object_type; if ( post_type_exists( $post_type ) ) { $query_args = [ 'post_type' => $post_type, ]; } break; case 'single': $query_args = [ 'post_type' => $preview_object_type, 'p' => $preview_id, ]; break; } // End switch(). if ( empty( $query_args ) ) { $query_args = [ 'p' => $this->get_main_id(), 'post_type' => $this->get_main_post()->post_type, ]; } return $query_args; } public function after_preview_switch_to_query() { global $wp_query; if ( 'archive/recent_posts' === $this->get_settings( 'preview_type' ) ) { $wp_query->is_archive = true; } } public function get_location() { $value = self::get_property( 'location' ); if ( ! $value ) { $value = $this->get_main_meta( self::LOCATION_META_KEY ); } return $value; } public function get_initial_config() { $config = parent::get_initial_config(); $config['support_site_editor'] = static::get_property( 'support_site_editor' ); return $config; } }