PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / presenters / admin / meta-fields-presenter.php

meta-fields-presenter.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.3, at src/presenters/admin/meta-fields-presenter.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Presenters\Admin;
4
5 use WP_Post;
6 use WPSEO_Meta;
7 use Yoast\WP\SEO\Presenters\Abstract_Presenter;
8
9 /**
10 * Presenter class for meta fields in the post editor.
11 *
12 * Outputs the hidden fields for a particular field group and post.
13 */
14 class Meta_Fields_Presenter extends Abstract_Presenter {
15
16 /**
17 * The meta fields for which we are going to output hidden input.
18 *
19 * @var array
20 */
21 private $meta_fields;
22
23 /**
24 * The metabox post.
25 *
26 * @var WP_Post The metabox post.
27 */
28 private $post;
29
30 /**
31 * Meta_Fields_Presenter constructor.
32 *
33 * @param WP_Post $post The metabox post.
34 * @param string $field_group The key under which a group of fields is grouped.
35 * @param string $post_type The post type.
36 */
37 public function __construct( $post, $field_group, $post_type = 'post' ) {
38 $this->post = $post;
39 $this->meta_fields = WPSEO_Meta::get_meta_field_defs( $field_group, $post_type );
40 }
41
42 /**
43 * Presents the Meta Fields.
44 *
45 * @return string The styled Alert.
46 */
47 public function present() {
48 $output = '';
49
50 foreach ( $this->meta_fields as $key => $meta_field ) {
51 $form_key = \esc_attr( WPSEO_Meta::$form_prefix . $key );
52 $meta_value = WPSEO_Meta::get_value( $key, $this->post->ID );
53
54 $default = '';
55 if ( isset( $meta_field['default'] ) ) {
56 $default = \sprintf( ' data-default="%s"', \esc_attr( $meta_field['default'] ) );
57 }
58
59 $output .= '<input type="hidden" id="' . $form_key . '" name="' . $form_key . '" value="' . \esc_attr( $meta_value ) . '"' . $default . '/>' . "\n";
60 }
61
62 return $output;
63 }
64 }
65