PluginProbe
Parse.ly / 3.23.5
Parse.ly v3.23.5
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / Endpoints / class-metadata-endpoint.php

class-metadata-endpoint.php in Parse.ly 3.23.5, at src/Endpoints/class-metadata-endpoint.php

77 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Endpoints: Metadata endpoint abstract class
4 *
5 * @package Parsely
6 * @since 3.2.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\Endpoints;
12
13 use Parsely\Parsely;
14 use Parsely\UI\Metadata_Renderer;
15
16 /**
17 * Metadata endpoint classes are expected to implement the remaining functions
18 * of the class.
19 *
20 * @since 3.2.0
21 */
22 abstract class Metadata_Endpoint {
23 protected const FIELD_NAME = 'parsely';
24
25 /**
26 * Instance of Parsely class.
27 *
28 * @var Parsely
29 */
30 protected $parsely;
31
32 /**
33 * Constructor.
34 *
35 * @param Parsely $parsely Instance of Parsely class.
36 */
37 public function __construct( Parsely $parsely ) {
38 $this->parsely = $parsely;
39 }
40
41 /**
42 * Starts up the class and enqueues necessary actions.
43 *
44 * @since 3.2.0
45 */
46 abstract public function run(): void;
47
48 /**
49 * Registers the metadata fields on the appropriate resource types.
50 *
51 * @since 3.2.0
52 */
53 abstract public function register_meta(): void;
54
55 /**
56 * Returns the metadata in string format.
57 *
58 * @since 3.2.0
59 *
60 * @param string $meta_type `json_ld` or `repeated_metas`.
61 * @return string The metadata as HTML code.
62 */
63 public function get_rendered_meta( string $meta_type ): string {
64 $metadata_renderer = new Metadata_Renderer( $this->parsely );
65
66 ob_start();
67 $metadata_renderer->render_metadata( $meta_type );
68 $out = ob_get_clean();
69
70 if ( false === $out ) {
71 return '';
72 }
73
74 return trim( $out );
75 }
76 }
77