rebase on oct-10-2023
This commit is contained in:
@@ -2,11 +2,6 @@
|
||||
|
||||
namespace Yoast\WP\SEO\Helpers;
|
||||
|
||||
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
|
||||
use Yoast\WP\SEO\Helpers\Options_Helper;
|
||||
use Yoast\WP\SEO\Helpers\Url_Helper;
|
||||
use Yoast\WP\SEO\Helpers\Redirect_Helper;
|
||||
|
||||
/**
|
||||
* Class Crawl_Cleanup_Helper.
|
||||
*
|
||||
@@ -81,6 +76,16 @@ class Crawl_Cleanup_Helper {
|
||||
* @return array The list of the allowed extra vars.
|
||||
*/
|
||||
public function get_allowed_extravars() {
|
||||
$default_allowed_extravars = [
|
||||
'utm_source',
|
||||
'utm_medium',
|
||||
'utm_campaign',
|
||||
'utm_term',
|
||||
'utm_content',
|
||||
'gclid',
|
||||
'gtm_debug',
|
||||
];
|
||||
|
||||
/**
|
||||
* Filter: 'Yoast\WP\SEO\allowlist_permalink_vars' - Allows plugins to register their own variables not to clean.
|
||||
*
|
||||
@@ -88,7 +93,8 @@ class Crawl_Cleanup_Helper {
|
||||
*
|
||||
* @param array $allowed_extravars The list of the allowed vars (empty by default).
|
||||
*/
|
||||
$allowed_extravars = \apply_filters( 'Yoast\WP\SEO\allowlist_permalink_vars', [] );
|
||||
|
||||
$allowed_extravars = \apply_filters( 'Yoast\WP\SEO\allowlist_permalink_vars', $default_allowed_extravars );
|
||||
|
||||
$clean_permalinks_extra_variables = $this->options_helper->get( 'clean_permalinks_extra_variables' );
|
||||
|
||||
@@ -253,7 +259,7 @@ class Crawl_Cleanup_Helper {
|
||||
* Redirects clean permalink.
|
||||
*
|
||||
* @param string $proper_url The proper URL.
|
||||
* @return void.
|
||||
* @return void
|
||||
*/
|
||||
public function do_clean_redirect( $proper_url ) {
|
||||
$this->redirect_helper->set_header( 'Content-Type: redirect', true );
|
||||
|
||||
@@ -418,7 +418,7 @@ class Current_Page_Helper {
|
||||
$current_page = \wp_unslash( $_GET['page'] );
|
||||
return \strpos( $current_page, 'wpseo_' ) === 0;
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,7 +434,7 @@ class Current_Page_Helper {
|
||||
return \sanitize_text_field( \wp_unslash( $_GET['page'] ) );
|
||||
}
|
||||
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -297,8 +297,8 @@ class Image_Helper {
|
||||
/**
|
||||
* Find an attachment ID for a given URL.
|
||||
*
|
||||
* @param string $url The URL to find the attachment for.
|
||||
* @param bool $use_link_table Whether the SEO Links table will be used to retrieve the id.
|
||||
* @param string $url The URL to find the attachment for.
|
||||
* @param bool $use_link_table Whether the SEO Links table will be used to retrieve the id.
|
||||
*
|
||||
* @return int The found attachment ID, or 0 if none was found.
|
||||
*/
|
||||
@@ -308,7 +308,8 @@ class Image_Helper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ! $this->options_helper->get( 'disable-attachment' ) ) {
|
||||
/** The `wpseo_force_creating_and_using_attachment_indexables` filter is documented in indexable-link-builder.php */
|
||||
if ( ! $this->options_helper->get( 'disable-attachment' ) || \apply_filters( 'wpseo_force_creating_and_using_attachment_indexables', false ) ) {
|
||||
// Strip out the size part of an image URL.
|
||||
$url = \preg_replace( '/(.*)-\d+x\d+\.(jpeg|jpg|png|gif)$/', '$1.$2', $url );
|
||||
|
||||
|
||||
@@ -48,6 +48,13 @@ class Indexing_Helper {
|
||||
*/
|
||||
protected $indexing_actions;
|
||||
|
||||
/**
|
||||
* The indexation actions that can be done in the background.
|
||||
*
|
||||
* @var Indexation_Action_Interface[]|Limited_Indexing_Action_Interface[]
|
||||
*/
|
||||
protected $background_indexing_actions;
|
||||
|
||||
/**
|
||||
* The indexable repository.
|
||||
*
|
||||
@@ -100,6 +107,9 @@ class Indexing_Helper {
|
||||
$post_link_indexing_action,
|
||||
$term_link_indexing_action,
|
||||
];
|
||||
|
||||
// Coincidentally, the background indexing actions are the same with the Free indexing actions for now.
|
||||
$this->background_indexing_actions = $this->indexing_actions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,15 +317,20 @@ class Indexing_Helper {
|
||||
/**
|
||||
* Returns a limited number of unindexed objects.
|
||||
*
|
||||
* @param int $limit Limit the number of unindexed objects that are counted.
|
||||
* @param int $limit Limit the number of unindexed objects that are counted.
|
||||
* @param Indexation_Action_Interface[]|Limited_Indexing_Action_Interface[] $actions The actions whose counts will be calculated.
|
||||
*
|
||||
* @return int The total number of unindexed objects.
|
||||
*/
|
||||
public function get_limited_unindexed_count( $limit ) {
|
||||
public function get_limited_unindexed_count( $limit, $actions = [] ) {
|
||||
$unindexed_count = 0;
|
||||
|
||||
foreach ( $this->indexing_actions as $indexing_action ) {
|
||||
$unindexed_count += $indexing_action->get_limited_unindexed_count( $limit - $unindexed_count + 1 );
|
||||
if ( empty( $actions ) ) {
|
||||
$actions = $this->indexing_actions;
|
||||
}
|
||||
|
||||
foreach ( $actions as $action ) {
|
||||
$unindexed_count += $action->get_limited_unindexed_count( $limit - $unindexed_count + 1 );
|
||||
if ( $unindexed_count > $limit ) {
|
||||
return $unindexed_count;
|
||||
}
|
||||
@@ -332,7 +347,7 @@ class Indexing_Helper {
|
||||
* @return int The total number of unindexed objects.
|
||||
*/
|
||||
public function get_limited_filtered_unindexed_count( $limit ) {
|
||||
$unindexed_count = $this->get_limited_unindexed_count( $limit );
|
||||
$unindexed_count = $this->get_limited_unindexed_count( $limit, $this->indexing_actions );
|
||||
|
||||
if ( $unindexed_count > $limit ) {
|
||||
return $unindexed_count;
|
||||
@@ -348,4 +363,29 @@ class Indexing_Helper {
|
||||
*/
|
||||
return \apply_filters( 'wpseo_indexing_get_limited_unindexed_count', $unindexed_count, $limit );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of unindexed objects that can be indexed in the background and applies a filter for third party integrations.
|
||||
*
|
||||
* @param int $limit Limit the number of unindexed objects that are counted.
|
||||
*
|
||||
* @return int The total number of unindexed objects that can be indexed in the background.
|
||||
*/
|
||||
public function get_limited_filtered_unindexed_count_background( $limit ) {
|
||||
$unindexed_count = $this->get_limited_unindexed_count( $limit, $this->background_indexing_actions );
|
||||
|
||||
if ( $unindexed_count > $limit ) {
|
||||
return $unindexed_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter: 'wpseo_indexing_get_limited_unindexed_count_background' - Allow changing the amount of unindexed objects that can be indexed in the background,
|
||||
* and allow for a maximum number of items counted to improve performance.
|
||||
*
|
||||
* @param int $unindexed_count The amount of unindexed objects.
|
||||
* @param int|false $limit Limit the number of unindexed objects that need to be counted.
|
||||
* False if it doesn't need to be limited.
|
||||
*/
|
||||
return \apply_filters( 'wpseo_indexing_get_limited_unindexed_count_background', $unindexed_count, $limit );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,12 @@ class Pagination_Helper {
|
||||
public function get_paginated_url( $url, $page, $add_pagination_base = true, $pagination_query_name = 'page' ) {
|
||||
$wp_rewrite = $this->wp_rewrite_wrapper->get();
|
||||
|
||||
if ( $wp_rewrite->using_permalinks() ) {
|
||||
$key_query_loop = $this->get_key_query_loop();
|
||||
if ( $key_query_loop ) {
|
||||
$pagination_query_name = $key_query_loop;
|
||||
}
|
||||
|
||||
if ( $wp_rewrite->using_permalinks() && ! $key_query_loop ) {
|
||||
$url_parts = \wp_parse_url( $url );
|
||||
$has_url_params = \array_key_exists( 'query', $url_parts );
|
||||
|
||||
@@ -113,9 +118,18 @@ class Pagination_Helper {
|
||||
* @return int The current archive page.
|
||||
*/
|
||||
public function get_current_archive_page_number() {
|
||||
$wp_query = $this->wp_query_wrapper->get_main_query();
|
||||
$wp_query = $this->wp_query_wrapper->get_main_query();
|
||||
$page_number = (int) $wp_query->get( 'paged' );
|
||||
if ( $page_number > 1 ) {
|
||||
return $page_number;
|
||||
}
|
||||
|
||||
return (int) $wp_query->get( 'paged' );
|
||||
$query_loop_page_number = $this->get_page_number_from_query_loop();
|
||||
|
||||
if ( $query_loop_page_number ) {
|
||||
return $query_loop_page_number;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,6 +140,12 @@ class Pagination_Helper {
|
||||
public function get_current_post_page_number() {
|
||||
$wp_query = $this->wp_query_wrapper->get_main_query();
|
||||
|
||||
$query_loop_page_number = $this->get_page_number_from_query_loop();
|
||||
|
||||
if ( $query_loop_page_number ) {
|
||||
return $query_loop_page_number;
|
||||
}
|
||||
|
||||
return (int) $wp_query->get( 'page' );
|
||||
}
|
||||
|
||||
@@ -141,7 +161,47 @@ class Pagination_Helper {
|
||||
return $page_number;
|
||||
}
|
||||
|
||||
$query_loop_page_number = $this->get_page_number_from_query_loop();
|
||||
|
||||
if ( $query_loop_page_number ) {
|
||||
return $query_loop_page_number;
|
||||
}
|
||||
|
||||
// Get the page number for a page in a paginated post.
|
||||
return \get_query_var( 'page', 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key of the query loop.
|
||||
*
|
||||
* @return string The key of the query loop.
|
||||
*/
|
||||
public function get_key_query_loop() {
|
||||
$regex_pattern = '/^query-\d+-page$/';
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- not form data.
|
||||
foreach ( $_GET as $key => $value ) {
|
||||
if ( \preg_match( $regex_pattern, $key ) ) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page number from the query loop.
|
||||
*
|
||||
* @return string The page number from the query loop.
|
||||
*/
|
||||
public function get_page_number_from_query_loop() {
|
||||
$key_query_loop = $this->get_key_query_loop();
|
||||
|
||||
if ( $key_query_loop ) {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.NonceVerification.Recommended -- Validated in get_key_query_loop().
|
||||
$page_number = (int) $_GET[ $key_query_loop ];
|
||||
if ( $page_number > 1 ) {
|
||||
return $page_number;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,13 @@ class Product_Helper {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version.
|
||||
*
|
||||
* @return string The version.
|
||||
*/
|
||||
public function get_version() {
|
||||
return \WPSEO_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class Redirect_Helper {
|
||||
* @param string $header The header to set.
|
||||
*/
|
||||
public function set_header( $header ) {
|
||||
header( $header );
|
||||
\header( $header );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +57,6 @@ class Redirect_Helper {
|
||||
* @param string $header The header to remove.
|
||||
*/
|
||||
public function remove_header( $header ) {
|
||||
header_remove( $header );
|
||||
\header_remove( $header );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,11 @@ class Image_Helper {
|
||||
/**
|
||||
* Find an image based on its URL and generate a Schema object for it.
|
||||
*
|
||||
* @param string $schema_id The `@id` to use for the returned image.
|
||||
* @param string $url The image URL to base our object on.
|
||||
* @param string $caption An optional caption.
|
||||
* @param bool $add_hash Whether a hash will be added as a suffix in the @id.
|
||||
* @param bool $use_link_table Whether the SEO Links table will be used to retrieve the id.
|
||||
* @param string $schema_id The `@id` to use for the returned image.
|
||||
* @param string $url The image URL to base our object on.
|
||||
* @param string $caption An optional caption.
|
||||
* @param bool $add_hash Whether a hash will be added as a suffix in the @id.
|
||||
* @param bool $use_link_table Whether the SEO Links table will be used to retrieve the id.
|
||||
*
|
||||
* @return array Schema ImageObject array.
|
||||
*/
|
||||
|
||||
@@ -112,9 +112,9 @@ class Short_Link_Helper {
|
||||
];
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
|
||||
if ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ) {
|
||||
if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
|
||||
$admin_page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
|
||||
$admin_page = \sanitize_text_field( \wp_unslash( $_GET['page'] ) );
|
||||
if ( ! empty( $admin_page ) ) {
|
||||
$data['screen'] = $admin_page;
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ class Social_Profiles_Helper {
|
||||
return [ $twitter_setting ];
|
||||
}
|
||||
|
||||
/*** DEPRECATED METHODS ***/
|
||||
/* DEPRECATED METHODS */
|
||||
|
||||
/**
|
||||
* Gets the person social profile fields supported by us after WP filtering.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Yoast\WP\SEO\Helpers;
|
||||
|
||||
use WPSEO_Shortlinker;
|
||||
use Yoast\WP\SEO\Conditionals\Non_Multisite_Conditional;
|
||||
use Yoast\WP\SEO\Config\Wincher_Client;
|
||||
use Yoast\WP\SEO\Exceptions\OAuth\Authentication_Failed_Exception;
|
||||
@@ -82,9 +83,11 @@ class Wincher_Helper {
|
||||
*/
|
||||
public function get_admin_global_links() {
|
||||
return [
|
||||
'links.wincher.website' => \WPSEO_Shortlinker::get( 'https://yoa.st/wincher-popup' ),
|
||||
'links.wincher.pricing' => \WPSEO_Shortlinker::get( 'https://yoa.st/wincher-popup-pricing' ),
|
||||
'links.wincher.login' => 'https://app.wincher.com/login?utm_medium=plugin&utm_source=yoast&referer=yoast&partner=yoast',
|
||||
'links.wincher.about' => WPSEO_Shortlinker::get( 'https://yoa.st/dashboard-about-wincher' ),
|
||||
'links.wincher.pricing' => WPSEO_Shortlinker::get( 'https://yoa.st/wincher-popup-pricing' ),
|
||||
'links.wincher.website' => WPSEO_Shortlinker::get( 'https://yoa.st/wincher-popup' ),
|
||||
'links.wincher.upgrade' => WPSEO_Shortlinker::get( 'https://yoa.st/wincher-upgrade' ),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user