| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Conditionals\Admin; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\Conditional; |
| 6 |
use Yoast\WP\SEO\Helpers\Input_Helper; |
| 7 |
|
| 8 |
/** |
| 9 |
* Conditional that is only when we want the Estimated Reading Time. |
| 10 |
*/ |
| 11 |
class Estimated_Reading_Time_Conditional implements Conditional { |
| 12 |
|
| 13 |
/** |
| 14 |
* The Post Conditional. |
| 15 |
* |
| 16 |
* @var Post_Conditional |
| 17 |
*/ |
| 18 |
protected $post_conditional; |
| 19 |
|
| 20 |
/** |
| 21 |
* The Input Helper. |
| 22 |
* |
| 23 |
* @var Input_Helper |
| 24 |
*/ |
| 25 |
protected $input_helper; |
| 26 |
|
| 27 |
/** |
| 28 |
* Constructs the Estimated Reading Time Conditional. |
| 29 |
* |
| 30 |
* @param Post_Conditional $post_conditional The post conditional. |
| 31 |
* @param Input_Helper $input_helper The input helper. |
| 32 |
*/ |
| 33 |
public function __construct( Post_Conditional $post_conditional, Input_Helper $input_helper ) { |
| 34 |
$this->post_conditional = $post_conditional; |
| 35 |
$this->input_helper = $input_helper; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Returns whether or not this conditional is met. |
| 40 |
* |
| 41 |
* @return bool Whether or not the conditional is met. |
| 42 |
*/ |
| 43 |
public function is_met() { |
| 44 |
// Check if we are in our Elementor ajax request (for saving). |
| 45 |
if ( \wp_doing_ajax() ) { |
| 46 |
$post_action = $this->input_helper->filter( \INPUT_POST, 'action', \FILTER_SANITIZE_STRING ); |
| 47 |
if ( $post_action === 'wpseo_elementor_save' ) { |
| 48 |
return true; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if ( ! $this->post_conditional->is_met() ) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
|
| 56 |
// We don't support Estimated Reading Time on the attachment post type. |
| 57 |
$post_id = (int) $this->input_helper->filter( \INPUT_GET, 'post', \FILTER_SANITIZE_NUMBER_INT ); |
| 58 |
if ( \get_post_type( $post_id ) === 'attachment' ) { |
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
return true; |
| 63 |
} |
| 64 |
} |
| 65 |
|