initial
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles the accordion block.
|
||||
*
|
||||
* @package GenerateBlocks Pro
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
require_once 'class-accordion.php';
|
||||
require_once 'class-accordion-item.php';
|
||||
require_once 'class-accordion-toggle.php';
|
||||
require_once 'class-accordion-toggle-icon.php';
|
||||
require_once 'class-accordion-content.php';
|
||||
|
||||
add_filter( 'block_editor_settings_all', 'generateblocks_pro_accordion_block_editor_settings', 20 );
|
||||
/**
|
||||
* Add block editor settings for the navigation block.
|
||||
*
|
||||
* @param array $settings The block editor settings.
|
||||
*/
|
||||
function generateblocks_pro_accordion_block_editor_settings( $settings ) {
|
||||
$blocks_to_reset = [
|
||||
'.editor-styles-wrapper .wp-block-generateblocks-pro-accordion',
|
||||
'.editor-styles-wrapper .wp-block-generateblocks-pro-accordion-item',
|
||||
'.editor-styles-wrapper .wp-block-generateblocks-pro-accordion-toggle',
|
||||
'.editor-styles-wrapper .wp-block-generateblocks-pro-accordion-toggle-icon',
|
||||
'.editor-styles-wrapper .wp-block-generateblocks-pro-accordion-content',
|
||||
];
|
||||
$css = implode( ',', $blocks_to_reset ) . ' {max-width:unset;margin:0}';
|
||||
$settings['styles'][] = [ 'css' => $css ];
|
||||
|
||||
return $settings;
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles the Accordion block.
|
||||
*
|
||||
* @package GenerateBlocksPro
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Accordion block class.
|
||||
*/
|
||||
class GenerateBlocks_Block_Accordion_Content extends GenerateBlocks_Block {
|
||||
/**
|
||||
* Keep track of all blocks of this type on the page.
|
||||
*
|
||||
* @var array $block_ids The current block id.
|
||||
*/
|
||||
protected static $block_ids = [];
|
||||
|
||||
/**
|
||||
* Store our block name.
|
||||
*
|
||||
* @var string $block_name The block name.
|
||||
*/
|
||||
public static $block_name = 'generateblocks-pro/accordion-content';
|
||||
|
||||
/**
|
||||
* Render the Element block.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $block_content The block content.
|
||||
* @param array $block The block.
|
||||
*/
|
||||
public static function render_block( $attributes, $block_content, $block ) {
|
||||
// Add styles to this block if needed.
|
||||
$block_content = generateblocks_maybe_add_block_css(
|
||||
$block_content,
|
||||
[
|
||||
'class_name' => __CLASS__,
|
||||
'attributes' => $attributes,
|
||||
'block_ids' => self::$block_ids,
|
||||
]
|
||||
);
|
||||
|
||||
return $block_content;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles the Accordion block.
|
||||
*
|
||||
* @package GenerateBlocksPro
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Accordion block class.
|
||||
*/
|
||||
class GenerateBlocks_Block_Accordion_Item extends GenerateBlocks_Block {
|
||||
/**
|
||||
* Keep track of all blocks of this type on the page.
|
||||
*
|
||||
* @var array $block_ids The current block id.
|
||||
*/
|
||||
protected static $block_ids = [];
|
||||
|
||||
/**
|
||||
* Store our block name.
|
||||
*
|
||||
* @var string $block_name The block name.
|
||||
*/
|
||||
public static $block_name = 'generateblocks-pro/accordion-item';
|
||||
|
||||
/**
|
||||
* Render the Element block.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $block_content The block content.
|
||||
* @param array $block The block.
|
||||
*/
|
||||
public static function render_block( $attributes, $block_content, $block ) {
|
||||
// Add styles to this block if needed.
|
||||
$block_content = generateblocks_maybe_add_block_css(
|
||||
$block_content,
|
||||
[
|
||||
'class_name' => __CLASS__,
|
||||
'attributes' => $attributes,
|
||||
'block_ids' => self::$block_ids,
|
||||
]
|
||||
);
|
||||
|
||||
return $block_content;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles the Accordion block.
|
||||
*
|
||||
* @package GenerateBlocksPro
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Accordion block class.
|
||||
*/
|
||||
class GenerateBlocks_Block_Accordion_Toggle_Icon extends GenerateBlocks_Block {
|
||||
/**
|
||||
* Keep track of all blocks of this type on the page.
|
||||
*
|
||||
* @var array $block_ids The current block id.
|
||||
*/
|
||||
protected static $block_ids = [];
|
||||
|
||||
/**
|
||||
* Store our block name.
|
||||
*
|
||||
* @var string $block_name The block name.
|
||||
*/
|
||||
public static $block_name = 'generateblocks-pro/accordion-toggle-icon';
|
||||
|
||||
/**
|
||||
* Render the Element block.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $block_content The block content.
|
||||
* @param array $block The block.
|
||||
*/
|
||||
public static function render_block( $attributes, $block_content, $block ) {
|
||||
// Add styles to this block if needed.
|
||||
$block_content = generateblocks_maybe_add_block_css(
|
||||
$block_content,
|
||||
[
|
||||
'class_name' => __CLASS__,
|
||||
'attributes' => $attributes,
|
||||
'block_ids' => self::$block_ids,
|
||||
]
|
||||
);
|
||||
|
||||
return $block_content;
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles the Accordion block.
|
||||
*
|
||||
* @package GenerateBlocksPro
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Accordion block class.
|
||||
*/
|
||||
class GenerateBlocks_Block_Accordion_Toggle extends GenerateBlocks_Block {
|
||||
/**
|
||||
* Keep track of all blocks of this type on the page.
|
||||
*
|
||||
* @var array $block_ids The current block id.
|
||||
*/
|
||||
protected static $block_ids = [];
|
||||
|
||||
/**
|
||||
* Store our block name.
|
||||
*
|
||||
* @var string $block_name The block name.
|
||||
*/
|
||||
public static $block_name = 'generateblocks-pro/accordion-toggle';
|
||||
|
||||
/**
|
||||
* Render the Element block.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $block_content The block content.
|
||||
* @param array $block The block.
|
||||
*/
|
||||
public static function render_block( $attributes, $block_content, $block ) {
|
||||
// Add styles to this block if needed.
|
||||
$block_content = generateblocks_maybe_add_block_css(
|
||||
$block_content,
|
||||
[
|
||||
'class_name' => __CLASS__,
|
||||
'attributes' => $attributes,
|
||||
'block_ids' => self::$block_ids,
|
||||
]
|
||||
);
|
||||
|
||||
// Bail here if the HTML Tag Processor isn't available.
|
||||
if ( ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
$open_by_default = $block->context['generateblocks/accordion/openByDefault'] ?? false;
|
||||
$processor = new WP_HTML_Tag_Processor( $block_content );
|
||||
$tag_name = $attributes['tagName'] ?? 'div';
|
||||
$main_tag = $processor->next_tag( $tag_name );
|
||||
$updated_html = false;
|
||||
|
||||
if ( $processor && $main_tag ) {
|
||||
if ( $open_by_default ) {
|
||||
$processor->add_class( 'gb-block-is-current' );
|
||||
$updated_html = true;
|
||||
}
|
||||
|
||||
if ( 'div' === $tag_name ) {
|
||||
if ( ! $processor->get_attribute( 'tabindex' ) ) {
|
||||
$processor->set_attribute( 'tabindex', '0' );
|
||||
}
|
||||
|
||||
if ( ! $processor->get_attribute( 'role' ) ) {
|
||||
$processor->set_attribute( 'role', 'button' );
|
||||
}
|
||||
|
||||
$updated_html = true;
|
||||
}
|
||||
|
||||
if ( $updated_html ) {
|
||||
$block_content = $processor->get_updated_html();
|
||||
}
|
||||
}
|
||||
|
||||
return $block_content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles the Accordion block.
|
||||
*
|
||||
* @package GenerateBlocksPro
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Accordion block class.
|
||||
*/
|
||||
class GenerateBlocks_Block_Accordion extends GenerateBlocks_Block {
|
||||
/**
|
||||
* Keep track of all blocks of this type on the page.
|
||||
*
|
||||
* @var array $block_ids The current block id.
|
||||
*/
|
||||
protected static $block_ids = [];
|
||||
|
||||
/**
|
||||
* Store our block name.
|
||||
*
|
||||
* @var string $block_name The block name.
|
||||
*/
|
||||
public static $block_name = 'generateblocks-pro/accordion';
|
||||
|
||||
/**
|
||||
* Render the Element block.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $block_content The block content.
|
||||
* @param array $block The block.
|
||||
*/
|
||||
public static function render_block( $attributes, $block_content, $block ) {
|
||||
// Add styles to this block if needed.
|
||||
$block_content = generateblocks_maybe_add_block_css(
|
||||
$block_content,
|
||||
[
|
||||
'class_name' => __CLASS__,
|
||||
'attributes' => $attributes,
|
||||
'block_ids' => self::$block_ids,
|
||||
]
|
||||
);
|
||||
|
||||
if ( ! wp_style_is( 'generateblocks-accordion', 'enqueued' ) ) {
|
||||
self::enqueue_style();
|
||||
}
|
||||
|
||||
if ( ! wp_script_is( 'generateblocks-accordion', 'enqueued' ) ) {
|
||||
self::enqueue_assets();
|
||||
}
|
||||
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue block styles.
|
||||
*/
|
||||
private static function enqueue_style() {
|
||||
wp_enqueue_style(
|
||||
'generateblocks-accordion',
|
||||
GENERATEBLOCKS_PRO_DIR_URL . 'dist/accordion-style.css',
|
||||
[],
|
||||
GENERATEBLOCKS_PRO_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue block scripts.
|
||||
*/
|
||||
private static function enqueue_scripts() {
|
||||
wp_enqueue_script(
|
||||
'generateblocks-accordion',
|
||||
GENERATEBLOCKS_PRO_DIR_URL . 'dist/accordion.js',
|
||||
[],
|
||||
GENERATEBLOCKS_PRO_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue block assets.
|
||||
*/
|
||||
public static function enqueue_assets() {
|
||||
self::enqueue_scripts();
|
||||
self::enqueue_style();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user