← All changes
|
includes/abilities/content/class-update-term-seo.php
+31
-1
2.4.0
→
2.8.0
View file →
| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | namespace ThinkRank\Abilities\Content; |
| 11 | 11 | |
| 12 | 12 | use ThinkRank\Abilities\Ability_Base; |
| 13 | +use ThinkRank\SEO\Object_Redirect; | |
| 13 | 14 | use ThinkRank\SEO\Pattern_Resolver; |
| 14 | 15 | |
| 15 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | 17 | exit; // Exit if accessed directly. |
| @@ -50,8 +51,17 @@ | ||
| 50 | 51 | 'properties' => [ |
| 51 | 52 | 'title' => [ 'type' => 'string' ], |
| 52 | 53 | 'description' => [ 'type' => 'string' ], |
| 53 | 54 | 'canonical_url' => [ 'type' => 'string' ], |
| 55 | + 'redirect_url' => [ | |
| 56 | + 'type' => 'string', | |
| 57 | + 'description' => __( 'Send visitors from this term archive to this URL. Empty string removes the redirect. Requires ThinkRank Pro.', 'thinkrank' ), | |
| 58 | + ], | |
| 59 | + 'redirect_type' => [ | |
| 60 | + 'type' => 'integer', | |
| 61 | + 'enum' => Object_Redirect::TYPES, | |
| 62 | + 'description' => __( 'Redirect status code. Defaults to 301.', 'thinkrank' ), | |
| 63 | + ], | |
| 54 | 64 | 'focus_keyword' => [ 'type' => 'string' ], |
| 55 | 65 | 'robots_meta_enabled' => [ 'type' => 'boolean' ], |
| 56 | 66 | 'robots_meta' => [ 'type' => 'object' ], |
| 57 | 67 | 'advanced_robots_meta' => [ 'type' => 'object' ], |
| @@ -119,9 +129,29 @@ | ||
| 119 | 129 | } |
| 120 | 130 | |
| 121 | 131 | $touched = $this->save_term_meta( $term_id, $settings ); |
| 122 | 132 | |
| 123 | - if ( ! $touched ) { | |
| 133 | + // The redirect is not term meta — Pro's rules table holds it — so it is | |
| 134 | + // saved separately, and unlike the meta fields it can be refused. | |
| 135 | + $redirect_touched = array_key_exists( 'redirect_url', $settings ); | |
| 136 | + if ( $redirect_touched ) { | |
| 137 | + $redirect_result = Object_Redirect::save( | |
| 138 | + 'term', | |
| 139 | + $term_id, | |
| 140 | + (string) $settings['redirect_url'], | |
| 141 | + $settings['redirect_type'] ?? Object_Redirect::DEFAULT_TYPE | |
| 142 | + ); | |
| 143 | + | |
| 144 | + if ( is_wp_error( $redirect_result ) ) { | |
| 145 | + return new \WP_Error( | |
| 146 | + $redirect_result->get_error_code(), | |
| 147 | + $redirect_result->get_error_message(), | |
| 148 | + [ 'status' => 400 ] | |
| 149 | + ); | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + if ( ! $touched && ! $redirect_touched ) { | |
| 124 | 154 | return new \WP_Error( |
| 125 | 155 | 'thinkrank_no_valid_term_meta_keys', |
| 126 | 156 | __( 'No valid ThinkRank term SEO keys were provided.', 'thinkrank' ), |
| 127 | 157 | [ 'status' => 400 ] |