PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.4
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 / bulk-editor / infrastructure / updates / field-renderer.php

field-renderer.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.4, at src/bulk-editor/infrastructure/updates/field-renderer.php

45 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Bulk_Editor\Infrastructure\Updates;
5
6 use Yoast\WP\SEO\Bulk_Editor\Application\Updates\Field_Renderer_Interface;
7 use Yoast\WP\SEO\Helpers\Meta_Helper;
8
9 /**
10 * Renders a stored meta field to its display value, resolving replacement variables the same way
11 * the post editor does, so the bulk editor can re-score a field on the value users actually see.
12 */
13 class Field_Renderer implements Field_Renderer_Interface {
14
15 /**
16 * The meta helper.
17 *
18 * @var Meta_Helper
19 */
20 private $meta_helper;
21
22 /**
23 * The constructor.
24 *
25 * @param Meta_Helper $meta_helper The meta helper.
26 */
27 public function __construct( Meta_Helper $meta_helper ) {
28 $this->meta_helper = $meta_helper;
29 }
30
31 /**
32 * Renders the current value of a meta field for a post, with replacement variables resolved.
33 *
34 * @param int $post_id The ID of the post.
35 * @param string $meta_key The meta key (without prefix) to render.
36 *
37 * @return string The rendered value.
38 */
39 public function render( int $post_id, string $meta_key ): string {
40 $value = (string) $this->meta_helper->get_value( $meta_key, $post_id );
41
42 return (string) \wpseo_replace_vars( $value, \get_post( $post_id ) );
43 }
44 }
45