| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Conditionals\Admin; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\Conditional; |
| 6 |
|
| 7 |
/** |
| 8 |
* Conditional that is only when we want the Estimated Reading Time. |
| 9 |
*/ |
| 10 |
class Estimated_Reading_Time_Conditional implements Conditional { |
| 11 |
|
| 12 |
/** |
| 13 |
* The Post Conditional. |
| 14 |
* |
| 15 |
* @var Post_Conditional |
| 16 |
*/ |
| 17 |
protected $post_conditional; |
| 18 |
|
| 19 |
/** |
| 20 |
* Constructs the Estimated Reading Time Conditional. |
| 21 |
* |
| 22 |
* @param Post_Conditional $post_conditional The post conditional. |
| 23 |
*/ |
| 24 |
public function __construct( Post_Conditional $post_conditional ) { |
| 25 |
$this->post_conditional = $post_conditional; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Returns whether this conditional is met. |
| 30 |
* |
| 31 |
* @return bool Whether the conditional is met. |
| 32 |
*/ |
| 33 |
public function is_met() { |
| 34 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing -- Reason: Nonce verification should not be done in a conditional but rather in the classes using the conditional. |
| 35 |
// Check if we are in our Elementor ajax request (for saving). |
| 36 |
if ( \wp_doing_ajax() && isset( $_POST['action'] ) && \is_string( $_POST['action'] ) ) { |
| 37 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are only strictly comparing the variable. |
| 38 |
$post_action = \wp_unslash( $_POST['action'] ); |
| 39 |
if ( $post_action === 'wpseo_elementor_save' ) { |
| 40 |
return true; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
if ( ! $this->post_conditional->is_met() ) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
// We don't support Estimated Reading Time on the attachment post type. |
| 49 |
if ( isset( $_GET['post'] ) && \is_string( $_GET['post'] ) ) { |
| 50 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are casting to an integer. |
| 51 |
$post_id = (int) \wp_unslash( $_GET['post'] ); |
| 52 |
if ( $post_id !== 0 && \get_post_type( $post_id ) === 'attachment' ) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
return true; |
| 58 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
| 59 |
} |
| 60 |
} |
| 61 |
|