| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Conditionals\Third_Party; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\Conditional; |
| 6 |
|
| 7 |
/** |
| 8 |
* Conditional that is only met when on an Elementor edit page or when the current |
| 9 |
* request is an ajax request for saving our post meta data. |
| 10 |
*/ |
| 11 |
class Elementor_Edit_Conditional implements Conditional { |
| 12 |
|
| 13 |
/** |
| 14 |
* Returns whether this conditional is met. |
| 15 |
* |
| 16 |
* @return bool Whether the conditional is met. |
| 17 |
*/ |
| 18 |
public function is_met() { |
| 19 |
global $pagenow; |
| 20 |
|
| 21 |
// Editing a post/page in Elementor. |
| 22 |
if ( $pagenow === 'post.php' && $this->is_elementor_get_action() ) { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
// Request for us saving a post/page in Elementor (submits our form via AJAX). |
| 27 |
return \wp_doing_ajax() && $this->is_yoast_save_post_action(); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Checks if the current request' GET action is 'elementor'. |
| 32 |
* |
| 33 |
* @return bool True when the GET action is 'elementor'. |
| 34 |
*/ |
| 35 |
private function is_elementor_get_action(): bool { |
| 36 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. |
| 37 |
if ( ! isset( $_GET['action'] ) ) { |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. |
| 42 |
if ( ! \is_string( $_GET['action'] ) ) { |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, we are only strictly comparing. |
| 47 |
return \wp_unslash( $_GET['action'] ) === 'elementor'; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Checks if the current request' POST action is 'wpseo_elementor_save'. |
| 52 |
* |
| 53 |
* @return bool True when the POST action is 'wpseo_elementor_save'. |
| 54 |
*/ |
| 55 |
private function is_yoast_save_post_action(): bool { |
| 56 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information. |
| 57 |
if ( ! isset( $_POST['action'] ) ) { |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information. |
| 62 |
if ( ! \is_string( $_POST['action'] ) ) { |
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, we are only strictly comparing. |
| 67 |
return \wp_unslash( $_POST['action'] ) === 'wpseo_elementor_save'; |
| 68 |
} |
| 69 |
} |
| 70 |
|