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:
@@ -102,6 +102,8 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* Set old URL when the quick edit is used for taxonomies.
|
||||
*/
|
||||
public function set_old_url_quick_edit() {
|
||||
check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
|
||||
|
||||
$permalink = $this->get_taxonomy_permalink();
|
||||
|
||||
if ( ! is_wp_error( $permalink ) ) {
|
||||
@@ -119,21 +121,6 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* @return bool
|
||||
*/
|
||||
public function detect_slug_change( $term_id, $tt_id, $taxonomy ) {
|
||||
/**
|
||||
* Filter: 'wpseo_premium_term_redirect_slug_change' - Check if a redirect should be created
|
||||
* on term slug change.
|
||||
*
|
||||
* @deprecated 12.9.0. Use the {@see 'Yoast\WP\SEO\term_redirect_slug_change'} filter instead.
|
||||
*
|
||||
* @api bool unsigned
|
||||
*/
|
||||
$create_redirect = apply_filters_deprecated(
|
||||
'wpseo_premium_term_redirect_slug_change',
|
||||
[ false ],
|
||||
'YoastSEO Premium 12.9.0',
|
||||
'Yoast\WP\SEO\term_redirect_slug_change'
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter: 'Yoast\WP\SEO\term_redirect_slug_change' - Check if a redirect should be created
|
||||
* on term slug change.
|
||||
@@ -144,7 +131,7 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
*
|
||||
* @api bool unsigned
|
||||
*/
|
||||
if ( apply_filters( 'Yoast\WP\SEO\term_redirect_slug_change', $create_redirect ) === true ) {
|
||||
if ( apply_filters( 'Yoast\WP\SEO\term_redirect_slug_change', false ) === true ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -184,18 +171,17 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
/**
|
||||
* Offer to create a redirect from the term that is about to get deleted.
|
||||
*
|
||||
* @param int $term_id The term id that will be deleted.
|
||||
* @param int $term_taxonomy_id The term taxonomy id that will be deleted.
|
||||
*/
|
||||
public function detect_term_delete( $term_id ) {
|
||||
$term = \get_term( $term_id );
|
||||
public function detect_term_delete( $term_taxonomy_id ) {
|
||||
$term = \get_term_by( 'term_taxonomy_id', (int) $term_taxonomy_id );
|
||||
|
||||
if ( ! $term || is_wp_error( $term ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->is_redirect_needed( $term ) ) {
|
||||
$url = $this->get_target_url( $term, $term->taxonomy );
|
||||
|
||||
$url = $this->get_target_url( $term, $term->taxonomy );
|
||||
if ( $this->is_redirect_needed( $term, $url ) ) {
|
||||
$this->set_delete_notification( $url );
|
||||
}
|
||||
}
|
||||
@@ -204,11 +190,14 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* Checks if a redirect is needed for the term with the given ID.
|
||||
*
|
||||
* @param WP_Term $term The term to check.
|
||||
* @param string $url The target url.
|
||||
*
|
||||
* @return bool If a redirect is needed.
|
||||
*/
|
||||
protected function is_redirect_needed( $term ) {
|
||||
return ! \is_nav_menu( $term->term_id ) && \is_taxonomy_viewable( $term->taxonomy );
|
||||
protected function is_redirect_needed( $term, $url ) {
|
||||
$redirect_manager = new WPSEO_Redirect_Manager( 'plain' );
|
||||
$redirect = $redirect_manager->get_redirect( $url );
|
||||
return ! $redirect || ( ! \is_nav_menu( $term->term_id ) && \is_taxonomy_viewable( $term->taxonomy ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +215,7 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to the term and returns it's path.
|
||||
* Gets the URL to the term and returns its path.
|
||||
*
|
||||
* @param string $tag The current tag name.
|
||||
* @param string $taxonomy The name of the current taxonomy.
|
||||
@@ -234,8 +223,16 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* @return string
|
||||
*/
|
||||
protected function get_target_url( $tag, $taxonomy ) {
|
||||
// Get the term link.
|
||||
$term_link = get_term_link( $tag, $taxonomy );
|
||||
|
||||
// Return early if the term link is not a string, i.e. a WP_Error Object.
|
||||
if ( ! is_string( $term_link ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Use the correct URL path.
|
||||
$url = wp_parse_url( get_term_link( $tag, $taxonomy ) );
|
||||
$url = wp_parse_url( $term_link );
|
||||
if ( is_array( $url ) && isset( $url['path'] ) ) {
|
||||
return $url['path'];
|
||||
}
|
||||
@@ -249,7 +246,13 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* @return string|WP_Error
|
||||
*/
|
||||
protected function get_taxonomy_permalink() {
|
||||
return get_term_link( get_term( filter_input( INPUT_POST, 'tax_ID' ), filter_input( INPUT_POST, 'taxonomy' ) ), filter_input( INPUT_POST, 'taxonomy' ) );
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Reason: We verify the nonce before coming here.
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We do sanitize by casting to int.
|
||||
$term_id = isset( $_POST['tax_ID'] ) ? (int) wp_unslash( $_POST['tax_ID'] ) : 0;
|
||||
$taxonomy = isset( $_POST['taxonomy'] ) ? sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) ) : null;
|
||||
// phpcs:enable
|
||||
|
||||
return get_term_link( get_term( $term_id, $taxonomy ), $taxonomy );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +261,10 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function get_old_url() {
|
||||
$wpseo_old_term_url = filter_input( INPUT_POST, 'wpseo_old_term_url' );
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Reason: This is used while hooked in an action thus we don't control the nonce creation.
|
||||
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: This data looks like it's being used only with WP functions later on.
|
||||
$wpseo_old_term_url = isset( $_POST['wpseo_old_term_url'] ) ? wp_unslash( $_POST['wpseo_old_term_url'] ) : null;
|
||||
// phpcs:enable
|
||||
|
||||
if ( empty( $wpseo_old_term_url ) ) {
|
||||
if ( ! empty( $this->old_url ) ) {
|
||||
@@ -324,7 +330,13 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* @return bool True when in an AJAX-request and the action is inline-save.
|
||||
*/
|
||||
protected function is_action_inline_save_tax() {
|
||||
return ( wp_doing_ajax() && filter_input( INPUT_POST, 'action' ) === 'inline-save-tax' );
|
||||
if ( ! wp_doing_ajax() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We don't control the nonce creation.
|
||||
$action = isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : null;
|
||||
return $action === 'inline-save-tax';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,6 +345,12 @@ class WPSEO_Term_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
|
||||
* @return bool True when in an AJAX-request and the action is delete-tag.
|
||||
*/
|
||||
protected function is_action_delete_tag() {
|
||||
return ( wp_doing_ajax() && filter_input( INPUT_POST, 'action' ) === 'delete-tag' );
|
||||
if ( ! wp_doing_ajax() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We don't control the nonce creation.
|
||||
$action = isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : null;
|
||||
return $action === 'delete-tag';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user