Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/themify-.../classes
File: class-themify-builder-gutenberg.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Gutenberg compatibility for Themify Builder
[3] Fix | Delete
*
[4] Fix | Delete
* @package Themify
[5] Fix | Delete
* @since 3.5.4
[6] Fix | Delete
*/
[7] Fix | Delete
if (!class_exists('Themify_Builder_Gutenberg',false)) :
[8] Fix | Delete
[9] Fix | Delete
final class Themify_Builder_Gutenberg {
[10] Fix | Delete
[11] Fix | Delete
private const BLOCK_PATTERNS = '<!-- wp:themify-builder/canvas /-->';
[12] Fix | Delete
[13] Fix | Delete
public static function init():void {
[14] Fix | Delete
add_action('wp_loaded', array(__CLASS__, 'load'));
[15] Fix | Delete
add_theme_support('align-wide');
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
public static function load():void {
[19] Fix | Delete
/* add template for all post types that support the editor */
[20] Fix | Delete
$post_types = Themify_Builder::builder_post_types_support();
[21] Fix | Delete
foreach ($post_types as $type) {
[22] Fix | Delete
add_filter('rest_prepare_' . $type, array(__CLASS__, 'enable_block_existing_content'), 10, 3);
[23] Fix | Delete
$post_type_object = get_post_type_object($type);
[24] Fix | Delete
$post_type_object->template = array(
[25] Fix | Delete
array('themify-builder/canvas')
[26] Fix | Delete
);
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
add_action('rest_api_init', array(__CLASS__, 'register_builder_content_field'));
[30] Fix | Delete
if (is_admin()) {
[31] Fix | Delete
add_action('current_screen', array(__CLASS__, 'admin_init'));
[32] Fix | Delete
} else {
[33] Fix | Delete
self::register_block();
[34] Fix | Delete
}
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public static function admin_init():void {
[38] Fix | Delete
if (Themify_Builder_Model::is_gutenberg_editor() && function_exists('register_block_type')) {
[39] Fix | Delete
self::register_block();
[40] Fix | Delete
add_action('enqueue_block_editor_assets', array(__CLASS__, 'enqueue_editor_scripts'));
[41] Fix | Delete
add_filter('admin_body_class', array(__CLASS__, 'admin_body_class'));
[42] Fix | Delete
}
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
private static function register_block():void {
[46] Fix | Delete
wp_register_style(
[47] Fix | Delete
'builder-styles',
[48] Fix | Delete
THEMIFY_BUILDER_URI . '/css/themify-builder-style.css',
[49] Fix | Delete
null,
[50] Fix | Delete
THEMIFY_VERSION
[51] Fix | Delete
);
[52] Fix | Delete
[53] Fix | Delete
register_block_type('themify-builder/canvas', array(
[54] Fix | Delete
'render_callback' => array(__CLASS__, 'render_builder_block'),
[55] Fix | Delete
'editor_style' => 'themify-builder-style',
[56] Fix | Delete
'style' => 'themify-builder-style'
[57] Fix | Delete
));
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
public static function enqueue_editor_scripts():void {
[61] Fix | Delete
add_filter('themify_defer_js_exclude', array(__CLASS__, 'exclude_defer_script'));
[62] Fix | Delete
themify_enque_script('themify-builder-gutenberg-block', THEMIFY_BUILDER_URI . '/js/editor/backend/themify-builder-gutenberg.js', THEMIFY_VERSION, array('wp-blocks', 'wp-i18n', 'wp-element', 'backbone'));
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
public static function render_builder_block($attributes):string {
[66] Fix | Delete
return self::BLOCK_PATTERNS; // just return custom block tag, let builder the_content filter to render builder output
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
public static function exclude_defer_script(array $handles):array {
[70] Fix | Delete
return array_merge($handles, array('themify-builder-gutenberg-block'));
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Enable builder block on existing content data.
[75] Fix | Delete
*
[76] Fix | Delete
* @param object $data
[77] Fix | Delete
* @param object $post
[78] Fix | Delete
* @param object $context
[79] Fix | Delete
* @return object
[80] Fix | Delete
*/
[81] Fix | Delete
public static function enable_block_existing_content($data, $post, $context) {
[82] Fix | Delete
if ('edit' === $context['context'] && isset($data->data['content']['raw'])) {
[83] Fix | Delete
$content = &$data->data['content']['raw'];
[84] Fix | Delete
[85] Fix | Delete
$builder_placeholder = '<!-- wp:themify-builder/canvas --><!-- /wp:themify-builder/canvas -->';
[86] Fix | Delete
if ( Themify_Builder_Model::is_gutenberg_active() && self::has_builder_block( $content ) ) {
[87] Fix | Delete
$content = ThemifyBuilder_Data_Manager::update_static_content_string( '', $content ); // remove static content tag
[88] Fix | Delete
/* convert old Gutenberg placeholder */
[89] Fix | Delete
if ( str_contains( $content, self::BLOCK_PATTERNS ) ) {
[90] Fix | Delete
$content = str_replace( self::BLOCK_PATTERNS, $builder_placeholder, $content );
[91] Fix | Delete
}
[92] Fix | Delete
} elseif ( ThemifyBuilder_Data_Manager::has_static_content( $content ) ) {
[93] Fix | Delete
$content = ThemifyBuilder_Data_Manager::update_static_content_string( $builder_placeholder, $content );
[94] Fix | Delete
} else {
[95] Fix | Delete
$content .= "\n\n" . $builder_placeholder;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
$builder_data = ThemifyBuilder_Data_Manager::get_data( $post->ID );
[99] Fix | Delete
if ( ! empty( $builder_data ) ) {
[100] Fix | Delete
$plain_text = ThemifyBuilder_Data_Manager::_get_all_builder_text_content( $builder_data );
[101] Fix | Delete
$plain_text = ThemifyBuilder_Data_Manager::add_static_content_wrapper( $plain_text );
[102] Fix | Delete
$content = preg_replace_callback( '/(<!-- wp:themify-builder\/canvas -->)[\s\S]*?(<!-- \/wp:themify-builder\/canvas -->)/', function( $matches ) use( $plain_text ) {
[103] Fix | Delete
return $matches[1] . $plain_text . $matches[2];
[104] Fix | Delete
}, $content );
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
return $data;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Added body class
[113] Fix | Delete
*/
[114] Fix | Delete
public static function admin_body_class(?string $classes):string {
[115] Fix | Delete
$classes .= ' themify-gutenberg-editor';
[116] Fix | Delete
$screen=get_current_screen();
[117] Fix | Delete
if (!empty($screen) && Themify_Builder_Model::is_builder_disabled_for_post_type( $screen->post_type ) ) {
[118] Fix | Delete
$classes .= ' tb_editor_disabled';
[119] Fix | Delete
}
[120] Fix | Delete
return $classes;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Register builder content meta
[125] Fix | Delete
*
[126] Fix | Delete
* @access public
[127] Fix | Delete
* @return type
[128] Fix | Delete
*/
[129] Fix | Delete
public static function register_builder_content_field():void {
[130] Fix | Delete
$post_types = Themify_Builder::builder_post_types_support();
[131] Fix | Delete
foreach ($post_types as $type) {
[132] Fix | Delete
register_rest_field($type, 'builder_content', array(
[133] Fix | Delete
'get_callback' => array(__CLASS__, 'get_post_meta_builder'),
[134] Fix | Delete
'schema' => null
[135] Fix | Delete
)
[136] Fix | Delete
);
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Update builder block tag in the string.
[142] Fix | Delete
*/
[143] Fix | Delete
public static function replace_builder_block_tag(string $replace_string, string $content): string {
[144] Fix | Delete
if (self::has_builder_block($content)) {
[145] Fix | Delete
$content = str_replace(self::BLOCK_PATTERNS, $replace_string, $content);
[146] Fix | Delete
$content = ThemifyBuilder_Data_Manager::remove_empty_p($content);
[147] Fix | Delete
}
[148] Fix | Delete
return $content;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Check if content has builder block
[153] Fix | Delete
*/
[154] Fix | Delete
public static function has_builder_block(string $content):string {
[155] Fix | Delete
return has_block( 'themify-builder/canvas', $content );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Get builder content value.
[160] Fix | Delete
*
[161] Fix | Delete
* @access public
[162] Fix | Delete
* @param type $object
[163] Fix | Delete
*/
[164] Fix | Delete
public static function get_post_meta_builder($object):string {
[165] Fix | Delete
return ThemifyBuilder_Data_Manager::_get_all_builder_text_content(ThemifyBuilder_Data_Manager::get_data($object['id']));
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
Themify_Builder_Gutenberg::init();
[170] Fix | Delete
endif;
[171] Fix | Delete
[172] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function