Plugins
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
|
||||
// phpcs:disable Yoast.NamingConventions.NamespaceName.Invalid
|
||||
namespace Yoast\WP\SEO\Integrations\Blocks;
|
||||
|
||||
use Yoast\WP\SEO\Conditionals\Schema_Blocks_Conditional;
|
||||
use Yoast\WP\SEO\Integrations\Integration_Interface;
|
||||
use Yoast\WP\SEO\Schema_Templates\Block_Patterns\Block_Pattern;
|
||||
use Yoast\WP\SEO\Schema_Templates\Block_Patterns\Block_Pattern_Categories;
|
||||
|
||||
/**
|
||||
* Registers the block patterns needed for the Premium Schema blocks.
|
||||
*/
|
||||
class Block_Patterns implements Integration_Interface {
|
||||
|
||||
/**
|
||||
* The block patterns to register.
|
||||
*
|
||||
* @var Block_Pattern[]
|
||||
*/
|
||||
protected $block_patterns = [];
|
||||
|
||||
/**
|
||||
* Block_Patterns integration constructor.
|
||||
*
|
||||
* @param Block_Pattern ...$block_patterns The block patterns to register.
|
||||
*/
|
||||
public function __construct( Block_Pattern ...$block_patterns ) {
|
||||
$this->block_patterns = $block_patterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the integration.
|
||||
*
|
||||
* This is the place to register hooks and filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_hooks() {
|
||||
\add_action( 'admin_init', [ $this, 'register_block_pattern_category' ] );
|
||||
\add_action( 'admin_init', [ $this, 'register_block_patterns' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of conditionals.
|
||||
*
|
||||
* @return array The conditionals.
|
||||
*/
|
||||
public static function get_conditionals() {
|
||||
return [ Schema_Blocks_Conditional::class ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the block patterns with WordPress.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_block_patterns() {
|
||||
foreach ( $this->block_patterns as $block_pattern ) {
|
||||
\register_block_pattern( $block_pattern->get_name(), $block_pattern->get_configuration() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the block pattern category with WordPress.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_block_pattern_category() {
|
||||
$category = [ 'label' => \__( 'Yoast Job Posting', 'wordpress-seo-premium' ) ];
|
||||
\register_block_pattern_category( Block_Pattern_Categories::YOAST_JOB_POSTING, $category );
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Premium\Integrations\Blocks;
|
||||
|
||||
use Yoast\WP\SEO\Integrations\Blocks\Dynamic_Block;
|
||||
|
||||
/**
|
||||
* Estimated_Reading_Time_Block class.
|
||||
*
|
||||
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
|
||||
*/
|
||||
class Estimated_Reading_Time_Block extends Dynamic_Block {
|
||||
|
||||
/**
|
||||
* The name of the block.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $block_name = 'estimated-reading-time';
|
||||
|
||||
/**
|
||||
* Holds the clock icon HTML.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $clock_icon = '<span class="yoast-reading-time__icon"><svg aria-hidden="true" focusable="false" data-icon="clock" width="20" height="20" fill="none" stroke="currentColor" style="display:inline-block;vertical-align:-0.1em" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg></span><span class="yoast-reading-time__spacer" style="display:inline-block;width:1em"></span>';
|
||||
|
||||
/**
|
||||
* The editor script for the block.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $script = 'wp-seo-premium-dynamic-blocks';
|
||||
|
||||
/**
|
||||
* Registers the block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_block() {
|
||||
\register_block_type(
|
||||
'yoast-seo/' . $this->block_name,
|
||||
[
|
||||
'editor_script' => $this->script,
|
||||
'render_callback' => [ $this, 'present' ],
|
||||
'attributes' => [
|
||||
'className' => [
|
||||
'default' => '',
|
||||
'type' => 'string',
|
||||
],
|
||||
'estimatedReadingTime' => [
|
||||
'type' => 'number',
|
||||
'default' => 0,
|
||||
],
|
||||
'descriptiveText' => [
|
||||
'type' => 'string',
|
||||
'default' => \__( 'Estimated reading time:', 'wordpress-seo-premium' ) . ' ',
|
||||
],
|
||||
'showDescriptiveText' => [
|
||||
'type' => 'boolean',
|
||||
'default' => true,
|
||||
],
|
||||
'showIcon' => [
|
||||
'type' => 'boolean',
|
||||
'default' => true,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Presents the block output.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $content The content.
|
||||
*
|
||||
* @return string The block output.
|
||||
*/
|
||||
public function present( $attributes, $content = '' ) {
|
||||
|
||||
$content = \preg_replace(
|
||||
'/<span class="yoast-reading-time__time-unit">.*<\/span>/',
|
||||
'<span class="yoast-reading-time__time-unit"> ' . \sprintf( \_n( 'minute', 'minutes', $attributes['estimatedReadingTime'], 'wordpress-seo-premium' ), $attributes['estimatedReadingTime'] ) . '</span>',
|
||||
$content,
|
||||
1
|
||||
);
|
||||
if ( $attributes['showIcon'] ) {
|
||||
// Replace 15.7 icon placeholder.
|
||||
$content = \preg_replace(
|
||||
'/ICON_PLACEHOLDER/',
|
||||
$this->clock_icon,
|
||||
$content,
|
||||
1
|
||||
);
|
||||
|
||||
// Replace the 15.8+ icon placeholder.
|
||||
return \preg_replace(
|
||||
'/<span class="yoast-reading-time__icon"><\/span>/',
|
||||
$this->clock_icon,
|
||||
$content,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
|
||||
// phpcs:disable Yoast.NamingConventions.NamespaceName.Invalid
|
||||
namespace Yoast\WP\SEO\Integrations\Blocks;
|
||||
|
||||
use Yoast\WP\SEO\Conditionals\Schema_Blocks_Conditional;
|
||||
use Yoast\WP\SEO\Integrations\Integration_Interface;
|
||||
|
||||
/**
|
||||
* Adds the block categories for the Jobs Posting block.
|
||||
*/
|
||||
class Job_Posting_Block implements Integration_Interface {
|
||||
|
||||
/**
|
||||
* Registers the hooks.
|
||||
*/
|
||||
public function register_hooks() {
|
||||
\add_filter( 'block_categories', [ $this, 'add_block_categories' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of conditionals.
|
||||
*
|
||||
* @return array The conditionals.
|
||||
*/
|
||||
public static function get_conditionals() {
|
||||
return [
|
||||
Schema_Blocks_Conditional::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Yoast block categories.
|
||||
*
|
||||
* @param array $categories The categories to filter.
|
||||
*
|
||||
* @return array The filtered categories.
|
||||
*/
|
||||
public function add_block_categories( $categories ) {
|
||||
$categories[] = [
|
||||
'slug' => 'yoast-required-job-blocks',
|
||||
'title' => \__( 'Required Job Posting Blocks', 'wordpress-seo-premium' ),
|
||||
];
|
||||
|
||||
$categories[] = [
|
||||
'slug' => 'yoast-recommended-job-blocks',
|
||||
'title' => \__( 'Recommended Job Posting Blocks', 'wordpress-seo-premium' ),
|
||||
];
|
||||
|
||||
return $categories;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Premium\Integrations\Blocks;
|
||||
|
||||
use Yoast\WP\SEO\Conditionals\No_Conditionals;
|
||||
use Yoast\WP\SEO\Integrations\Integration_Interface;
|
||||
|
||||
/**
|
||||
* Related content block class.
|
||||
*/
|
||||
class Related_Links_Block implements Integration_Interface {
|
||||
|
||||
use No_Conditionals;
|
||||
|
||||
/**
|
||||
* Initializes the integration.
|
||||
*
|
||||
* This is the place to register hooks and filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_hooks() {
|
||||
\register_block_type( 'yoast-seo/related-links', [ 'editor_script' => 'wp-seo-premium-blocks' ] );
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Integrations\Blocks;
|
||||
|
||||
use WPSEO_Admin_Asset_Manager;
|
||||
use Yoast\WP\SEO\Conditionals\Schema_Blocks_Conditional;
|
||||
use Yoast\WP\SEO\Integrations\Integration_Interface;
|
||||
|
||||
/**
|
||||
* Loads the Premium schema block templates into Gutenberg.
|
||||
*/
|
||||
class Schema_Blocks implements Integration_Interface {
|
||||
|
||||
/**
|
||||
* Represents the asset manager.
|
||||
*
|
||||
* @var WPSEO_Admin_Asset_Manager
|
||||
*/
|
||||
protected $asset_manager;
|
||||
|
||||
/**
|
||||
* Schema_Blocks constructor.
|
||||
*
|
||||
* @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
|
||||
*/
|
||||
public function __construct( WPSEO_Admin_Asset_Manager $asset_manager ) {
|
||||
$this->asset_manager = $asset_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of conditionals.
|
||||
*
|
||||
* @return array The conditionals.
|
||||
*/
|
||||
public static function get_conditionals() {
|
||||
return [
|
||||
Schema_Blocks_Conditional::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the integration.
|
||||
*
|
||||
* This is the place to register hooks and filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_hooks() {
|
||||
\add_filter( 'wpseo_load_schema_templates', [ $this, 'add_premium_templates' ] );
|
||||
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the Premium structured data blocks templates.
|
||||
*
|
||||
* @param array $templates The templates from Yoast SEO.
|
||||
*
|
||||
* @return array All the templates that should be loaded.
|
||||
*/
|
||||
public function add_premium_templates( $templates ) {
|
||||
$premium_schema_templates_path = \WPSEO_PREMIUM_PATH . 'src/schema-templates/';
|
||||
|
||||
$premium_templates = \glob( $premium_schema_templates_path . '*.php' );
|
||||
|
||||
return \array_merge( $templates, $premium_templates );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues the schema blocks css file.
|
||||
*/
|
||||
public function enqueue_assets() {
|
||||
\wp_enqueue_script( 'wp-seo-premium-schema-blocks' );
|
||||
$this->asset_manager->enqueue_style( 'premium-schema-blocks' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user