| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 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.3/wp-content/plugins/better-block-editor/Base/ |
Upload File : |
<?php
/**
* Base class for module which renders block with responsive settings.
*
* @package BetterBlockEditor
*/
namespace BetterBlockEditor\Base;
use BetterBlockEditor\Core\ResponsiveBlockUtils;
defined( 'ABSPATH' ) || exit;
abstract class ResponsiveBlockModuleBase extends ModuleBase {
/**
* Attributes of the block being processed.
*
* @var array
*/
protected $attributes = array();
/**
* Width at which the block should switch to responsive mode.
*
* @var int|null
*/
protected $switch_width = null;
protected const BLOCK_NAME = null;
public function setup_hooks() {
add_filter( 'render_block', array( $this, 'render_with_early_return' ), 20, 3 );
}
/**
* Render block with responsive settings.
*
* @param string $block_content Block content.
* @param array $block Block data (including name and attributes).
* @param WP_Block $wp_block_instance The WP_Block class instance.
*
* @return string Block content with applied responsive settings.
*/
public function render_with_early_return( $block_content, $block, $wp_block_instance ) {
// if there is no content
if ( $block_content === '' ) {
return $block_content;
}
// if there are no responsive settings
if ( ! ResponsiveBlockUtils::is_responsive( $block ) ) {
return $block_content;
}
// check block type if it's provided
$blockName = $block['blockName'] ?? null;
if ( static::BLOCK_NAME !== null && $blockName !== null && $blockName !== static::BLOCK_NAME ) {
return $block_content;
}
// Store some data for later use
$this->attributes = $block['attrs'] ?? array();
$this->switch_width = ResponsiveBlockUtils::get_switch_width( $this->attributes );
// if we can not get switch width
if ( null === $this->switch_width ) {
return $block_content;
}
if ( ! $this->need_to_apply_changes( $block_content, $block, $wp_block_instance ) ) {
return $block_content;
}
return $this->render( $block_content, $block, $wp_block_instance );
}
protected function get_responsive_setting( $name, $default = null ) {
return ResponsiveBlockUtils::get_setting( $this->attributes, $name, $default );
}
/**
* Check if we need to apply changes to the block content.
*
* @param string $block_content Block content.
* @param array $block Block data (including name and attributes).
* @param WP_Block $instance The block instance.
*
* @return bool True if changes are needed, false otherwise.
*/
abstract protected function need_to_apply_changes( $block_content, $block, $wp_block_instance );
/**
* Render the block content with responsive settings.
*
* @param string $block_content Block content.
* @param array $block Block data (including name and attributes).
* @param WP_Block $instance The block instance.
*
* @return string Rendered block content.
*/
abstract protected function render( $block_content, $block, $wp_block_instance );
}