| Server IP : 38.190.208.107 / Your IP : 216.73.217.51 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.9/wp-content/themes/woodmart/inc/integrations/gutenberg/ |
Upload File : |
<?php
/**
* Gutenberg blocks class.
*
* @package woodmart
*/
namespace XTS\Gutenberg;
use XTS\Singleton;
/**
* Blocks modules.
*
* @package woodmart
*/
class Blocks extends Singleton {
/**
* Blocks config.
*
* @var array
*/
public $blocks = array();
/**
* Layout config.
*
* @var array
*/
public $layouts = array();
/**
* Register hooks and load base data.
*/
public function init() {
$this->load_blocks_from_config();
add_action( 'init', array( $this, 'register_block_types' ), 20 );
}
/**
* Get blocks config.
*
* @return array|mixed
*/
public function get_blocks() {
return $this->blocks;
}
/**
* Get block config by slug.
*
* @param string $slug Block slug.
*
* @return false|mixed
*/
public function get_block_config( $slug ) {
$config = false;
if ( isset( $this->blocks[ $slug ] ) ) {
$config = $this->blocks[ $slug ];
$config['type'] = 'blocks';
} elseif ( isset( $this->layouts[ $slug ] ) ) {
$config = $this->layouts[ $slug ];
$config['type'] = 'layouts';
}
return $config;
}
/**
* Load blocks from config file.
*
* @return mixed
*/
public function load_blocks_from_config() {
$this->blocks = require_once get_parent_theme_file_path( WOODMART_FRAMEWORK . '/integrations/gutenberg/configs/blocks.php' );
$this->layouts = require_once get_parent_theme_file_path( WOODMART_FRAMEWORK . '/integrations/gutenberg/configs/layouts.php' );
}
/**
* Register blocks.
*
* @return void
*/
public function register_block_types() {
$all_blocks = array(
'blocks' => $this->blocks,
'layouts' => $this->layouts,
);
foreach ( $all_blocks as $type => $blocks ) {
foreach ( $blocks as $slug => $block ) {
$block_name = $this->get_block_name( $slug );
if ( ! empty( $block['subfolder'] ) ) {
$block_name = $block['subfolder'] . '/' . $block_name;
}
if ( ! empty( $block['render_callback'] ) ) {
require_once get_parent_theme_file_path( WOODMART_FRAMEWORK . '/integrations/gutenberg/src/' . $type . '/' . $block_name . '/render.php' );
}
register_block_type( $this->get_block_folder_path( $block_name, $type ), $block );
}
}
}
/**
* Get folder path for block.
*
* @param string $name Block name.
* @param string $type Block type.
* @return string
*/
private function get_block_folder_path( $name, $type = 'blocks' ) {
return get_parent_theme_file_path( WOODMART_FRAMEWORK . '/integrations/gutenberg/build/' . $type . '/' . $name );
}
/**
* Get folder name based on the name of the block wd/section will generate section.
*
* @param string $slug Block slug.
* @return string
*/
private function get_block_name( $slug ) {
$name_parts = explode( '/', $slug );
return $name_parts[1];
}
}
Blocks::get_instance();