Remove deprecations in PHP 8.1
-
Hi! We are seeing several deprecation warnings when running a WordPress site under PHP 8.1 with your plugin.
Here I’m attaching a patch to fix them.
diff --git a/src/css-optimize.php b/src/css-optimize.php index ece4b43281..2a7d6dcc14 100644 --- a/src/css-optimize.php +++ b/src/css-optimize.php @@ -140,7 +140,7 @@ if ( ! class_exists( 'Stackable_CSS_Optimize' ) ) { */ public function parse_blocks( $blocks, &$style_arr ) { foreach ( $blocks as $block ) { - if ( stripos( $block['blockName'], 'stackable/' ) !== false ) { + if ( stripos( $block['blockName'] ?? '', 'stackable/' ) !== false ) { $this->parse_block_style( $block, $style_arr ); } @@ -262,8 +262,8 @@ if ( ! class_exists( 'Stackable_CSS_Optimize' ) ) { } // Only do this to our blocks. - if ( ! empty( $block ) && is_array( $block ) && stripos( $block['blockName'], 'stackable/' ) === 0 ) { - if ( stripos( $block_content, '<style' ) !== false ) { + if ( ! empty( $block ) && is_array( $block ) && stripos( $block['blockName'] ?? '', 'stackable/' ) === 0 ) { + if ( stripos( $block_content ?? '', '<style' ) !== false ) { // We need the unique id for tracking. if ( is_array( $block['attrs'] ) && array_key_exists( 'uniqueId', $block['attrs'] ) ) { diff --git a/src/fonts.php b/src/fonts.php index 648e7e8ae9..6d7f93ef2e 100644 --- a/src/fonts.php +++ b/src/fonts.php @@ -39,7 +39,7 @@ if ( ! class_exists( 'Stackable_Google_Fonts' ) ) { } public function is_stackable_block( $block_name ) { - return strpos( $block_name, 'ugb/' ) === 0 || strpos( $block_name, 'stackable/' ) === 0; + return strpos( $block_name ?? '', 'ugb/' ) === 0 || strpos( $block_name ?? '', 'stackable/' ) === 0; } public static function register_font( $font_name ) { diff --git a/src/global-settings.php b/src/global-settings.php index a82b691db5..223e16de82 100644 --- a/src/global-settings.php +++ b/src/global-settings.php @@ -765,7 +765,7 @@ if ( ! class_exists( 'Stackable_Global_Settings' ) ) { } // Only do this for native blocks. - if ( stripos( $block['blockName'], 'core/' ) !== 0 ) { + if ( stripos( $block['blockName'] ?? '', 'core/' ) !== 0 ) { return $block_content; } diff --git a/src/init.php b/src/init.php index 3708e48155..5fe16281c9 100644 --- a/src/init.php +++ b/src/init.php @@ -192,7 +192,7 @@ if ( ! class_exists( 'Stackable_Init' ) ) { // frontend. if ( ! $this->is_main_script_loaded && ! is_admin() ) { if ( - stripos( $block['blockName'], 'stackable/' ) === 0 || + stripos( $block['blockName'] ?? '', 'stackable/' ) === 0 || stripos( $block_content, '<!-- wp:stackable/' ) !== false || stripos( $block_content, 'stk-highlight' ) !== false ) { @@ -203,8 +203,8 @@ if ( ! class_exists( 'Stackable_Init' ) ) { // Load our individual block script if they're used in the page. $stackable_block = ''; - if ( stripos( $block['blockName'], 'stackable/' ) === 0 ) { - if ( preg_match( '#stackable/([\w\d-]+)#', $block['blockName'], $matches ) ) { + if ( stripos( $block['blockName'] ?? '', 'stackable/' ) === 0 ) { + if ( preg_match( '#stackable/([\w\d-]+)#', $block['blockName'] ?? '', $matches ) ) { $stackable_block = $matches[1]; } } else if ( stripos( $block_content, '<!-- wp:stackable/' ) !== false ) { diff --git a/src/welcome/index.php b/src/welcome/index.php index 2435860121..4e4d3eed40 100644 --- a/src/welcome/index.php +++ b/src/welcome/index.php @@ -36,7 +36,7 @@ if ( ! class_exists( 'Stackable_Welcome_Screen' ) ) { // Our getting started page. add_submenu_page( - isset( $_GET['page'] ) && $_GET['page'] === 'stackable-getting-started' ? 'options-general.php' : null, // Parent slug. Only show when in the page. + isset( $_GET['page'] ) && $_GET['page'] === 'stackable-getting-started' ? 'options-general.php' : '', // Parent slug. Only show when in the page. __( 'Get Started', STACKABLE_I18N ), // Page title. '<span class="fs-submenu-item fs-sub"></span>' . __( 'Get Started', STACKABLE_I18N ), // Menu title. 'manage_options', // Capability. diff --git a/src/welcome/wizard.php b/src/welcome/wizard.php index fe53638e4e..b30a5608fc 100644 --- a/src/welcome/wizard.php +++ b/src/welcome/wizard.php @@ -20,7 +20,7 @@ if ( ! class_exists( 'Stackable_Onboarding_Wizard' ) ) { public function add_dashboard_page() { // Our wizard page. add_submenu_page( - isset( $_GET['page'] ) && $_GET['page'] === 'stackable-settings-wizard' ? 'options-general.php' : null, // Parent slug. Only show when in the page. + isset( $_GET['page'] ) && $_GET['page'] === 'stackable-settings-wizard' ? 'options-general.php' : '', // Parent slug. Only show when in the page. __( 'Wizard', STACKABLE_I18N ), // Page title. '<span class="fs-submenu-item fs-sub"></span>' . __( 'Wizard', STACKABLE_I18N ), // Menu title. 'manage_options', // Capability.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Remove deprecations in PHP 8.1’ is closed to new replies.