Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix PHP warning
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux authored and tjcafferkey committed Jan 4, 2022
1 parent 012741e commit 987445e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/BlockTypes/LegacyTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class LegacyTemplate extends AbstractDynamicBlock {
*/
protected $api_version = '2';


/**
* Initialize this block.
*/
protected function initialize() {
parent::initialize();
add_filter( 'render_block', array( $this, 'get_markup_with_classes_by_attributes' ), 10, 2 );
}

/**
* Render method for the Legacy Template block. This method will determine which template to render.
*
Expand Down Expand Up @@ -66,7 +75,6 @@ protected function render( $attributes, $content ) {
* @return string Rendered block type output.
*/
protected function render_single_product() {
add_filter( 'render_block', array( $this, 'get_markup_with_classes_by_attributes' ), 10, 2 );
ob_start();

/**
Expand Down Expand Up @@ -102,7 +110,6 @@ protected function render_single_product() {
* @return string Rendered block type output.
*/
protected function render_archive_product() {
add_filter( 'render_block', array( $this, 'get_markup_with_classes_by_attributes' ), 10, 2 );
ob_start();

/**
Expand Down Expand Up @@ -199,6 +206,10 @@ public function get_markup_with_classes_by_attributes( string $content, array $b
$matches = array();
preg_match( $pattern, $content, $matches );

if ( ! isset( $matches[0] ) ) {
return $content;
}

return preg_replace( $pattern, $matches[0] . ' ' . $align_class['class'], $content, 1 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/StyleAttributesUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static function get_background_color_class_and_style( $attributes ) {
*/
public static function get_align_class_and_style( $attributes ) {

$align_attribute = $attributes['align'];
$align_attribute = isset( $attributes['align'] ) ? $attributes['align'] : null;

if ( ! $align_attribute ) {
return null;
Expand Down

0 comments on commit 987445e

Please sign in to comment.