Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/integrat...
File: schema-blocks.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations;
[2] Fix | Delete
[3] Fix | Delete
use WPSEO_Admin_Asset_Manager;
[4] Fix | Delete
use WPSEO_Admin_Asset_Yoast_Components_L10n;
[5] Fix | Delete
use Yoast\WP\SEO\Conditionals\Schema_Blocks_Conditional;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Loads schema block templates into Gutenberg.
[10] Fix | Delete
*/
[11] Fix | Delete
class Schema_Blocks implements Integration_Interface {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* The registered templates.
[15] Fix | Delete
*
[16] Fix | Delete
* @var string[]
[17] Fix | Delete
*/
[18] Fix | Delete
protected $templates = [];
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Contains the asset manager.
[22] Fix | Delete
*
[23] Fix | Delete
* @var WPSEO_Admin_Asset_Manager
[24] Fix | Delete
*/
[25] Fix | Delete
protected $asset_manager;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Represents the schema blocks conditional.
[29] Fix | Delete
*
[30] Fix | Delete
* @var Schema_Blocks_Conditional
[31] Fix | Delete
*/
[32] Fix | Delete
protected $blocks_conditional;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Represents the short link helper.
[36] Fix | Delete
*
[37] Fix | Delete
* @var Short_Link_Helper
[38] Fix | Delete
*/
[39] Fix | Delete
protected $short_link_helper;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[43] Fix | Delete
*
[44] Fix | Delete
* @return array
[45] Fix | Delete
*/
[46] Fix | Delete
public static function get_conditionals() {
[47] Fix | Delete
return [
[48] Fix | Delete
Schema_Blocks_Conditional::class,
[49] Fix | Delete
];
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Schema_Blocks constructor.
[54] Fix | Delete
*
[55] Fix | Delete
* @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
[56] Fix | Delete
* @param Schema_Blocks_Conditional $blocks_conditional The schema blocks conditional.
[57] Fix | Delete
* @param Short_Link_Helper $short_link_helper The short link helper.
[58] Fix | Delete
*/
[59] Fix | Delete
public function __construct(
[60] Fix | Delete
WPSEO_Admin_Asset_Manager $asset_manager,
[61] Fix | Delete
Schema_Blocks_Conditional $blocks_conditional,
[62] Fix | Delete
Short_Link_Helper $short_link_helper
[63] Fix | Delete
) {
[64] Fix | Delete
$this->asset_manager = $asset_manager;
[65] Fix | Delete
$this->blocks_conditional = $blocks_conditional;
[66] Fix | Delete
$this->short_link_helper = $short_link_helper;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Initializes the integration.
[71] Fix | Delete
*
[72] Fix | Delete
* This is the place to register hooks and filters.
[73] Fix | Delete
*
[74] Fix | Delete
* @return void
[75] Fix | Delete
*/
[76] Fix | Delete
public function register_hooks() {
[77] Fix | Delete
\add_action( 'enqueue_block_editor_assets', [ $this, 'load' ] );
[78] Fix | Delete
\add_action( 'enqueue_block_editor_assets', [ $this, 'load_translations' ] );
[79] Fix | Delete
\add_action( 'admin_enqueue_scripts', [ $this, 'output' ] );
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Registers a schema template.
[84] Fix | Delete
*
[85] Fix | Delete
* @param string $template The template to be registered.
[86] Fix | Delete
* If starting with a / is assumed to be an absolute path.
[87] Fix | Delete
* If not starting with a / is assumed to be relative to WPSEO_PATH.
[88] Fix | Delete
*
[89] Fix | Delete
* @return void
[90] Fix | Delete
*/
[91] Fix | Delete
public function register_template( $template ) {
[92] Fix | Delete
if ( \substr( $template, 0, 1 ) !== '/' ) {
[93] Fix | Delete
$template = \WPSEO_PATH . '/' . $template;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$this->templates[] = $template;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Loads all schema block templates and the required JS library for them.
[101] Fix | Delete
*
[102] Fix | Delete
* @return void
[103] Fix | Delete
*/
[104] Fix | Delete
public function load() {
[105] Fix | Delete
$this->asset_manager->enqueue_script( 'schema-blocks' );
[106] Fix | Delete
$this->asset_manager->enqueue_style( 'schema-blocks' );
[107] Fix | Delete
[108] Fix | Delete
$this->asset_manager->localize_script(
[109] Fix | Delete
'schema-blocks',
[110] Fix | Delete
'yoastSchemaBlocks',
[111] Fix | Delete
[
[112] Fix | Delete
'requiredLink' => $this->short_link_helper->build( 'https://yoa.st/required-fields' ),
[113] Fix | Delete
'recommendedLink' => $this->short_link_helper->build( 'https://yoa.st/recommended-fields' ),
[114] Fix | Delete
]
[115] Fix | Delete
);
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Outputs the set templates.
[120] Fix | Delete
*/
[121] Fix | Delete
public function output() {
[122] Fix | Delete
if ( ! $this->asset_manager->is_script_enqueued( 'schema-blocks' ) ) {
[123] Fix | Delete
return;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
$templates = [];
[127] Fix | Delete
[128] Fix | Delete
// When the schema blocks feature flag is enabled, use the registered templates.
[129] Fix | Delete
if ( $this->blocks_conditional->is_met() ) {
[130] Fix | Delete
$templates = $this->templates;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Filter: 'wpseo_load_schema_templates' - Allow adding additional schema templates.
[135] Fix | Delete
*
[136] Fix | Delete
* @param array $templates The templates to filter.
[137] Fix | Delete
*/
[138] Fix | Delete
$templates = \apply_filters( 'wpseo_load_schema_templates', $templates );
[139] Fix | Delete
if ( ! \is_array( $templates ) || empty( $templates ) ) {
[140] Fix | Delete
return;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
foreach ( $templates as $template ) {
[144] Fix | Delete
if ( ! \file_exists( $template ) ) {
[145] Fix | Delete
continue;
[146] Fix | Delete
}
[147] Fix | Delete
// `.schema` and other suffixes become Schema (root) templates.
[148] Fix | Delete
$type = ( \substr( $template, -10 ) === '.block.php' ) ? 'block' : 'schema';
[149] Fix | Delete
echo '<script type="text/' . \esc_html( $type ) . '-template">';
[150] Fix | Delete
include $template;
[151] Fix | Delete
echo '</script>';
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Loads the translations and localizes the schema-blocks script file.
[157] Fix | Delete
*/
[158] Fix | Delete
public function load_translations() {
[159] Fix | Delete
$yoast_components_l10n = new WPSEO_Admin_Asset_Yoast_Components_L10n();
[160] Fix | Delete
$yoast_components_l10n->localize_script( 'schema-blocks' );
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function