Merged in feature/MAW-855-import-code-into-aws (pull request #2)

code import from pantheon

* code import from pantheon
This commit is contained in:
Tony Volpe
2023-12-04 23:08:14 +00:00
parent 8c9b1312bc
commit 8f4b5efda6
4766 changed files with 185592 additions and 239967 deletions

View File

@@ -103,24 +103,6 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
$this->remove_colliding_redirect( $post, $post_before );
/**
* Filter: 'wpseo_premium_post_redirect_slug_change' - Check if a redirect should be created
* on post slug change.
*
* @deprecated 12.9.0. Use the {@see 'Yoast\WP\SEO\post_redirect_slug_change'} filter instead.
*
* @api bool Determines if a redirect should be created for this post slug change.
* @api int The ID of the post.
* @api WP_Post The current post object.
* @api WP_Post The previous post object.
*/
$create_redirect = apply_filters_deprecated(
'wpseo_premium_post_redirect_slug_change',
[ false, $post_id, $post, $post_before ],
'YoastSEO Premium 12.9.0',
'Yoast\WP\SEO\post_redirect_slug_change'
);
/**
* Filter: 'Yoast\WP\SEO\post_redirect_slug_change' - Check if a redirect should be created
* on post slug change.
@@ -134,7 +116,7 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
* @api WP_Post The current post object.
* @api WP_Post The previous post object.
*/
$create_redirect = apply_filters( 'Yoast\WP\SEO\post_redirect_slug_change', $create_redirect, $post_id, $post, $post_before );
$create_redirect = apply_filters( 'Yoast\WP\SEO\post_redirect_slug_change', false, $post_id, $post, $post_before );
if ( $create_redirect === true ) {
return true;
@@ -146,7 +128,7 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
}
// If the post URL wasn't public before, or isn't public now, don't even check if we have to redirect.
if ( ! $this->check_public_post_status( $post_before->ID ) || ! $this->check_public_post_status( $post->ID ) ) {
if ( ! $this->check_public_post_status( $post_before ) || ! $this->check_public_post_status( $post ) ) {
return false;
}
@@ -200,22 +182,6 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
// Check if the post type is enabled for redirects.
$post_type = get_post_type( $post );
/**
* Filter: 'wpseo_premium_redirect_post_type' - Check if a redirect should be created
* on post slug change for specified post type.
*
* @deprecated 12.9.0. Use the {@see 'Yoast\WP\SEO\redirect_post_type'} filter instead.
*
* @api bool Determines if a redirect should be created for this post type.
* @api string The post type that is being checked for.
*/
$post_type_accessible = apply_filters_deprecated(
'wpseo_premium_redirect_post_type',
[ WPSEO_Post_Type::is_post_type_accessible( $post_type ), $post_type ],
'YoastSEO Premium 12.9.0',
'Yoast\WP\SEO\redirect_post_type'
);
/**
* Filter: 'Yoast\WP\SEO\redirect_post_type' - Check if a redirect should be created
* on post slug change for specified post type.
@@ -227,7 +193,7 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
* @api bool Determines if a redirect should be created for this post type.
* @api string The post type that is being checked for.
*/
$post_type_accessible = apply_filters( 'Yoast\WP\SEO\redirect_post_type', $post_type_accessible, $post_type );
$post_type_accessible = apply_filters( 'Yoast\WP\SEO\redirect_post_type', WPSEO_Post_Type::is_post_type_accessible( $post_type ), $post_type );
if ( ! $post_type_accessible ) {
return false;
@@ -249,32 +215,24 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
/**
* Checks whether the given post is public or not.
*
* @param int $post_id The current post ID.
* @param int|WP_Post $post Post ID or post object.
*
* @return bool
*/
private function check_public_post_status( $post_id ) {
private function check_public_post_status( $post ) {
$public_post_statuses = [
'publish',
'static',
'private',
];
/**
* Filter: 'wpseo_public_post_statuses' - Allow changing the statuses that are expected
* to have caused a URL to be public.
*
* @deprecated 12.9.0. Use the {@see 'Yoast\WP\SEO\public_post_statuses'} filter instead.
*
* @api array $published_post_statuses The statuses that'll be treated as published.
* @param object $post The post object we're doing the published check for.
*/
$public_post_statuses = apply_filters_deprecated(
'wpseo_public_post_statuses',
[ $public_post_statuses, $post_id ],
'YoastSEO Premium 12.9.0',
'Yoast\WP\SEO\public_post_statuses'
);
// Need to set $post_id for backward compatibility with the filter, as $post can also be an object now.
if ( is_int( $post ) ) {
$post_id = $post;
}
else {
$post_id = $post->ID;
}
/**
* Filter: 'Yoast\WP\SEO\public_post_statuses' - Allow changing the statuses that are expected
@@ -289,7 +247,7 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
*/
$public_post_statuses = apply_filters( 'Yoast\WP\SEO\public_post_statuses', $public_post_statuses, $post_id );
return ( in_array( get_post_status( $post_id ), $public_post_statuses, true ) );
return ( in_array( get_post_status( $post ), $public_post_statuses, true ) );
}
/**
@@ -413,13 +371,12 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
// Message should only be shown if there isn't already a redirect.
$redirect = $this->get_redirect( $url );
if ( is_a( $redirect, 'WPSEO_Redirect' ) === $should_exist ) {
if ( $should_exist === false ) {
return $url;
}
if ( is_a( $redirect, 'WPSEO_Redirect' ) && $should_exist ) {
return $redirect;
}
if ( ! is_a( $redirect, 'WPSEO_Redirect' ) && ! $should_exist ) {
return $url;
}
}
}
return false;
@@ -433,21 +390,6 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
protected function get_included_automatic_redirection_post_types() {
$post_types = WPSEO_Post_Type::get_accessible_post_types();
/**
* Filter: 'wpseo_premium_include_automatic_redirection_post_types' - Post types to create
* automatic redirects for.
*
* @deprecated 12.9.0. Use the {@see 'Yoast\WP\SEO\automatic_redirection_post_types'} filter instead.
*
* @api array $included_post_types Array with the post type names to include to automatic redirection.
*/
$included_post_types = apply_filters_deprecated(
'wpseo_premium_include_automatic_redirection_post_types',
[ $post_types ],
'YoastSEO Premium 12.9.0',
'Yoast\WP\SEO\automatic_redirection_post_types'
);
/**
* Filter: 'Yoast\WP\SEO\automatic_redirection_post_types' - Post types to create
* automatic redirects for.
@@ -458,7 +400,7 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
*
* @api array $included_post_types Array with the post type names to include to automatic redirection.
*/
$included_post_types = apply_filters( 'Yoast\WP\SEO\automatic_redirection_post_types', $included_post_types );
$included_post_types = apply_filters( 'Yoast\WP\SEO\automatic_redirection_post_types', $post_types );
if ( ! is_array( $included_post_types ) ) {
$included_post_types = [];
@@ -584,25 +526,38 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
* @return bool True when the current page is nested pages.
*/
protected function is_nested_pages( $current_page ) {
return ( $current_page === 'admin.php' && filter_input( INPUT_GET, 'page' ) === 'nestedpages' );
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Reason: We are not controlling the request.
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are strictly comparing only.
return ( $current_page === 'admin.php' && isset( $_GET['page'] ) && is_string( $_GET['page'] ) && wp_unslash( $_GET['page'] ) === 'nestedpages' );
// phpcs:enable WordPress.Security.NonceVerification.Recommended.
}
/**
* Retrieves wpseo_old_post_url field from the post.
*
* @return mixed.
* @return mixed
*/
protected function get_post_old_post_url() {
return filter_input( INPUT_POST, 'wpseo_old_post_url' );
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Reason: Seems to be only used in tests.
if ( isset( $_POST['wpseo_old_post_url'] ) && is_string( $_POST['wpseo_old_post_url'] ) ) {
return sanitize_text_field( wp_unslash( $_POST['wpseo_old_post_url'] ) );
}
// phpcs:enable WordPress.Security.NonceVerification.Missing.
return false;
}
/**
* Retrieves action field from the post.
*
* @return mixed.
* @return mixed
*/
protected function get_post_action() {
return filter_input( INPUT_POST, 'action' );
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Reason: We are not controlling the request.
if ( isset( $_POST['action'] ) && is_string( $_POST['action'] ) ) {
return sanitize_text_field( wp_unslash( $_POST['action'] ) );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended.
return false;
}
/**