| 1 |
<?php |
| 2 |
/** |
| 3 |
* Metadata endpoint abstract class |
| 4 |
* |
| 5 |
* @package Parsely\Endpoints |
| 6 |
* @since 3.2.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace Parsely\Endpoints; |
| 12 |
|
| 13 |
use Parsely\Parsely; |
| 14 |
|
| 15 |
/** |
| 16 |
* Metadata endpoint classes are expected to implement the remaining functions of the class. |
| 17 |
* |
| 18 |
* @since 3.2.0 |
| 19 |
*/ |
| 20 |
abstract class Metadata_Endpoint { |
| 21 |
protected const FIELD_NAME = 'parsely'; |
| 22 |
|
| 23 |
/** |
| 24 |
* Instance of Parsely class. |
| 25 |
* |
| 26 |
* @var Parsely |
| 27 |
*/ |
| 28 |
protected $parsely; |
| 29 |
|
| 30 |
/** |
| 31 |
* Constructor. |
| 32 |
* |
| 33 |
* @param Parsely $parsely Instance of Parsely class. |
| 34 |
*/ |
| 35 |
public function __construct( Parsely $parsely ) { |
| 36 |
$this->parsely = $parsely; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Function to start up the class and enqueue necessary actions. |
| 41 |
* |
| 42 |
* @since 3.2.0 |
| 43 |
* |
| 44 |
* @return void |
| 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 |
* @return void |
| 54 |
*/ |
| 55 |
abstract public function register_meta(): void; |
| 56 |
|
| 57 |
/** |
| 58 |
* Get the metadata in string format. |
| 59 |
* |
| 60 |
* @since 3.2.0 |
| 61 |
* |
| 62 |
* @param string $meta_type `json_ld` or `repeated_metas`. |
| 63 |
* @return string The metadata as HTML code. |
| 64 |
*/ |
| 65 |
public function get_rendered_meta( string $meta_type ): string { |
| 66 |
ob_start(); |
| 67 |
$this->parsely->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 |
|