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/popup-ma.../classes/Admin
File: BlockEditor.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Admin BlockEditor
[2] Fix | Delete
*
[3] Fix | Delete
* @package PUM
[4] Fix | Delete
* @copyright Copyright (c) 2023, Code Atlantic LLC
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Class PUM_Admin_BlockEditor
[9] Fix | Delete
*
[10] Fix | Delete
* @since 1.10.0
[11] Fix | Delete
*/
[12] Fix | Delete
class PUM_Admin_BlockEditor {
[13] Fix | Delete
[14] Fix | Delete
public static $version = '1.0.0';
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Initialize
[18] Fix | Delete
*/
[19] Fix | Delete
public static function init() {
[20] Fix | Delete
// Bail early if the Block Playground is active and ahead of core.
[21] Fix | Delete
if ( defined( 'PUM_BLOCK_PLAYGROUND' ) && version_compare( PUM_BLOCK_PLAYGROUND, self::$version, '>' ) ) {
[22] Fix | Delete
return;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
// TODO Test if this is needed in core or not.
[26] Fix | Delete
add_action( 'enqueue_block_editor_assets', [ 'PUM_Site_Assets', 'register_styles' ] );
[27] Fix | Delete
add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'register_editor_assets' ] );
[28] Fix | Delete
[29] Fix | Delete
add_action( 'wp_loaded', [ __CLASS__, 'add_attributes_to_registered_blocks' ], 999 );
[30] Fix | Delete
[31] Fix | Delete
// Here for future use.
[32] Fix | Delete
// add_action( 'enqueue_block_assets', [ __CLASS__, 'register_block_assets' ] );
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Registers all block assets so that they can be enqueued through Gutenberg in
[37] Fix | Delete
* the corresponding context.
[38] Fix | Delete
*
[39] Fix | Delete
* Passes translations to JavaScript.
[40] Fix | Delete
*
[41] Fix | Delete
* @since 1.10.0
[42] Fix | Delete
*/
[43] Fix | Delete
public static function register_editor_assets( $hook ) {
[44] Fix | Delete
[45] Fix | Delete
$screen = get_current_screen();
[46] Fix | Delete
[47] Fix | Delete
$build_path = 'dist/block-editor/';
[48] Fix | Delete
[49] Fix | Delete
$script_path = $build_path . 'block-editor.js';
[50] Fix | Delete
$script_asset_path = $build_path . 'block-editor.asset.php';
[51] Fix | Delete
$script_asset = file_exists( Popup_Maker::$DIR . $script_asset_path ) ? require Popup_Maker::$DIR . $script_asset_path : [
[52] Fix | Delete
'dependencies' => [],
[53] Fix | Delete
'version' => Popup_Maker::$VER,
[54] Fix | Delete
];
[55] Fix | Delete
$script_url = plugins_url( $script_path, Popup_Maker::$FILE );
[56] Fix | Delete
$script_deps = $script_asset['dependencies'];
[57] Fix | Delete
[58] Fix | Delete
if ( 'widgets' !== $screen->id ) {
[59] Fix | Delete
$script_deps = array_merge( $script_deps, [ 'wp-edit-post' ] );
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
wp_enqueue_script( 'popup-maker-block-editor', $script_url, $script_deps, $script_asset['version'] );
[63] Fix | Delete
[64] Fix | Delete
wp_localize_script(
[65] Fix | Delete
'popup-maker-block-editor',
[66] Fix | Delete
'pum_block_editor_vars',
[67] Fix | Delete
[
[68] Fix | Delete
'popups' => pum_get_all_popups(),
[69] Fix | Delete
'popup_trigger_excluded_blocks' => apply_filters(
[70] Fix | Delete
'pum_block_editor_popup_trigger_excluded_blocks',
[71] Fix | Delete
[
[72] Fix | Delete
'core/nextpage',
[73] Fix | Delete
]
[74] Fix | Delete
),
[75] Fix | Delete
]
[76] Fix | Delete
);
[77] Fix | Delete
[78] Fix | Delete
$editor_styles_path = $build_path . 'block-editor-styles.css';
[79] Fix | Delete
$editor_styles_asset_path = $build_path . 'block-editor-styles.asset.php';
[80] Fix | Delete
$editor_styles_asset = file_exists( Popup_Maker::$DIR . $editor_styles_asset_path ) ? require Popup_Maker::$DIR . $editor_styles_asset_path : [
[81] Fix | Delete
'dependencies' => [],
[82] Fix | Delete
'version' => Popup_Maker::$VER,
[83] Fix | Delete
];
[84] Fix | Delete
wp_enqueue_style( 'popup-maker-block-editor', plugins_url( $editor_styles_path, Popup_Maker::$FILE ), [], $editor_styles_asset['version'] );
[85] Fix | Delete
[86] Fix | Delete
if ( function_exists( 'wp_set_script_translations' ) ) {
[87] Fix | Delete
/**
[88] Fix | Delete
* May be extended to wp_set_script_translations( 'my-handle', 'my-domain',
[89] Fix | Delete
* plugin_dir_path( MY_PLUGIN ) . 'languages' ) ). For details see
[90] Fix | Delete
* https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
[91] Fix | Delete
*/
[92] Fix | Delete
wp_set_script_translations( 'popup-maker-block-editor', 'popup-maker' );
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Register assets for individual block styles
[98] Fix | Delete
*/
[99] Fix | Delete
public static function register_block_assets() {
[100] Fix | Delete
$build_path = 'dist/block-editor/';
[101] Fix | Delete
$block_styles_path = $build_path . 'block-styles.css';
[102] Fix | Delete
$block_styles_asset_path = $build_path . 'block-styles.asset.php';
[103] Fix | Delete
$block_styles_asset = file_exists( Popup_Maker::$DIR . $block_styles_asset_path ) ? require Popup_Maker::$DIR . $block_styles_asset_path : [
[104] Fix | Delete
'dependencies' => [],
[105] Fix | Delete
'version' => Popup_Maker::$VER,
[106] Fix | Delete
];
[107] Fix | Delete
wp_enqueue_style( 'popup-maker-block-styles', plugins_url( $block_styles_path, Popup_Maker::$FILE ), [], $block_styles_asset['version'] );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* This is needed to resolve an issue with blocks that use the
[112] Fix | Delete
* ServerSideRender component. Registering the attributes only in js
[113] Fix | Delete
* can cause an error message to appear. Registering the attributes in
[114] Fix | Delete
* PHP as well, seems to resolve the issue. Ideally, this bug will be
[115] Fix | Delete
* fixed in the future.
[116] Fix | Delete
*
[117] Fix | Delete
* Reference: https://github.com/WordPress/gutenberg/issues/16850
[118] Fix | Delete
*
[119] Fix | Delete
* @since 1.16.0
[120] Fix | Delete
*/
[121] Fix | Delete
public static function add_attributes_to_registered_blocks() {
[122] Fix | Delete
global $wp_version;
[123] Fix | Delete
[124] Fix | Delete
if ( version_compare( $wp_version, '5.0' ) === -1 ) {
[125] Fix | Delete
return;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
[129] Fix | Delete
[130] Fix | Delete
foreach ( $registered_blocks as $block ) {
[131] Fix | Delete
$block->attributes['openPopupId'] = [
[132] Fix | Delete
'type' => 'string',
[133] Fix | Delete
'default' => '',
[134] Fix | Delete
];
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function