| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters; |
| 4 |
|
| 5 |
use WPSEO_Utils; |
| 6 |
|
| 7 |
/** |
| 8 |
* Presenter class for the schema object. |
| 9 |
*/ |
| 10 |
class Schema_Presenter extends Abstract_Indexable_Presenter { |
| 11 |
|
| 12 |
/** |
| 13 |
* The tag key name. |
| 14 |
* |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
protected $key = 'schema'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Returns the schema output. |
| 21 |
* |
| 22 |
* @return string The schema tag. |
| 23 |
*/ |
| 24 |
public function present() { |
| 25 |
$deprecated_data = [ |
| 26 |
'_deprecated' => 'Please use the "wpseo_schema_*" filters to extend the Yoast SEO schema data - see the WPSEO_Schema class.', |
| 27 |
]; |
| 28 |
|
| 29 |
/** |
| 30 |
* Filter: 'wpseo_json_ld_output' - Allows disabling Yoast's schema output entirely. |
| 31 |
* |
| 32 |
* @api mixed If false or an empty array is returned, disable our output. |
| 33 |
*/ |
| 34 |
$return = \apply_filters( 'wpseo_json_ld_output', $deprecated_data, '' ); |
| 35 |
if ( $return === [] || $return === false ) { |
| 36 |
return ''; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Action: 'wpseo_json_ld' - Output Schema before the main schema from Yoast SEO is output. |
| 41 |
*/ |
| 42 |
\do_action( 'wpseo_json_ld' ); |
| 43 |
|
| 44 |
$schema = $this->get(); |
| 45 |
if ( \is_array( $schema ) ) { |
| 46 |
$output = WPSEO_Utils::format_json_encode( $schema ); |
| 47 |
$output = \str_replace( "\n", \PHP_EOL . "\t", $output ); |
| 48 |
return '<script type="application/ld+json" class="yoast-schema-graph">' . $output . '</script>'; |
| 49 |
} |
| 50 |
|
| 51 |
return ''; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Gets the raw value of a presentation. |
| 56 |
* |
| 57 |
* @return array The raw value. |
| 58 |
*/ |
| 59 |
public function get() { |
| 60 |
return $this->presentation->schema; |
| 61 |
} |
| 62 |
} |
| 63 |
|