| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin\Formatter |
| 6 |
*/ |
| 7 |
|
| 8 |
use Yoast\WP\SEO\Editors\Application\Seo\Post_Seo_Information_Repository; |
| 9 |
|
| 10 |
/** |
| 11 |
* This class provides data for the post metabox by return its values for localization. |
| 12 |
*/ |
| 13 |
class WPSEO_Post_Metabox_Formatter implements WPSEO_Metabox_Formatter_Interface { |
| 14 |
|
| 15 |
/** |
| 16 |
* Holds the WordPress Post. |
| 17 |
* |
| 18 |
* @var WP_Post |
| 19 |
*/ |
| 20 |
private $post; |
| 21 |
|
| 22 |
/** |
| 23 |
* The permalink to follow. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
private $permalink; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructor. |
| 31 |
* |
| 32 |
* @param WP_Post|array $post Post object. |
| 33 |
* @param array $options Title options to use. |
| 34 |
* @param string $structure The permalink to follow. |
| 35 |
*/ |
| 36 |
public function __construct( $post, array $options, $structure ) { |
| 37 |
$this->post = $post; |
| 38 |
$this->permalink = $structure; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Determines whether the social templates should be used. |
| 43 |
* |
| 44 |
* @deprecated 23.1 |
| 45 |
* @codeCoverageIgnore |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public function use_social_templates() { |
| 50 |
_deprecated_function( __METHOD__, 'Yoast SEO 23.1' ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Returns the translated values. |
| 55 |
* |
| 56 |
* @return array |
| 57 |
*/ |
| 58 |
public function get_values() { |
| 59 |
|
| 60 |
$values = [ |
| 61 |
'metaDescriptionDate' => '', |
| 62 |
]; |
| 63 |
|
| 64 |
if ( $this->post instanceof WP_Post ) { |
| 65 |
|
| 66 |
/** @var Post_Seo_Information_Repository $repo */ |
| 67 |
$repo = YoastSEO()->classes->get( Post_Seo_Information_Repository::class ); |
| 68 |
$repo->set_post( $this->post ); |
| 69 |
|
| 70 |
$values_to_set = [ |
| 71 |
'isInsightsEnabled' => $this->is_insights_enabled(), |
| 72 |
]; |
| 73 |
|
| 74 |
$values = ( $values_to_set + $values ); |
| 75 |
$values = ( $repo->get_seo_data() + $values ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Filter: 'wpseo_post_edit_values' - Allows changing the values Yoast SEO uses inside the post editor. |
| 80 |
* |
| 81 |
* @param array $values The key-value map Yoast SEO uses inside the post editor. |
| 82 |
* @param WP_Post $post The post opened in the editor. |
| 83 |
*/ |
| 84 |
return apply_filters( 'wpseo_post_edit_values', $values, $this->post ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Determines whether the insights feature is enabled for this post. |
| 89 |
* |
| 90 |
* @return bool |
| 91 |
*/ |
| 92 |
protected function is_insights_enabled() { |
| 93 |
return WPSEO_Options::get( 'enable_metabox_insights', false ); |
| 94 |
} |
| 95 |
} |
| 96 |
|