Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Fix an issue where the block_field( 'className' ) doesn't output anything#353

Merged
lukecarbis merged 1 commit intodevelopfrom
fix/class-name
Jun 28, 2019
Merged

Fix an issue where the block_field( 'className' ) doesn't output anything#353
lukecarbis merged 1 commit intodevelopfrom
fix/class-name

Conversation

@kienstra
Copy link
Copy Markdown
Collaborator

@kienstra kienstra commented Jun 26, 2019

@RobStino found this issue, where block_field( 'className' ) has no output. Similarly, block_value( 'className' ) didn't return anything.

…hing

Rob found this issue.
Reinstate the handling of className before.
if ( 'autop' === $block_lab_config->fields[ $name ]->settings['new_lines'] ) {
$value = wpautop( $value );
if ( isset( $block_lab_config->fields[ $name ]->type ) ) {
switch ( $block_lab_config->fields[ $name ]->type ) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a previous version ,1.3.1, the switch statement in block_field() was wrapped in an isset() conditional:

// Cast block value as correct type.
if ( isset( $block_lab_config['fields'][ $name ]['type'] ) ) {
switch ( $block_lab_config['fields'][ $name ]['type'] ) {

This PR adds that isset() conditional back in, though maybe there was another reason for removing it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since className isn't in $block_lab_config['fields'], this caused an error before.

$value = wpautop( $value );
if ( isset( $block_lab_config->fields[ $name ]->type ) ) {
switch ( $block_lab_config->fields[ $name ]->type ) {
case 'string':
Copy link
Copy Markdown
Collaborator Author

@kienstra kienstra Jun 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff inside this switch block is whitespace-only, from indenting it inside the new conditional. You might want to check Hide whitespace changes

! isset( $block_lab_attributes ) ||
! is_array( $block_lab_attributes ) ||
! isset( $block_lab_config->fields[ $name ] )
( ! isset( $block_lab_config->fields[ $name ] ) && 'className' !== $name )
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

className isn't normally in $block_lab_config->fields

@kienstra
Copy link
Copy Markdown
Collaborator Author

kienstra commented Jun 26, 2019

Steps To Reproduce

Thanks to @RobStino for finding this.

  1. Create a new post, and add any Block Lab block
  2. In the the Inspector, under Advanced > Additional CSS Class(es), add a class like 'foo-class'
  3. In the template's PHP file, like block-test-class.php, use block_field( 'className' )
  4. Expected: it outputs the class, like 'foo-class'
  5. Actual: It doesn't output anything

@kienstra
Copy link
Copy Markdown
Collaborator Author

kienstra commented Jun 26, 2019

Request For Review

Hi @lukecarbis and @RobStino,
Hope you're having a great week. Could you please test this?

Though this looks to fix the issue for now, there might need to be more thought about block_field() eventually.

It has a lot of special handling for className that might be confusing, or allow future bugs.

Thanks!

@kienstra kienstra requested review from RobStino and lukecarbis June 26, 2019 17:25
@kienstra
Copy link
Copy Markdown
Collaborator Author

Also, I'm making it a priority to add more unit tests to the plugin. They might have prevented an issue like this.

Copy link
Copy Markdown
Member

@lukecarbis lukecarbis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested – everything here works great. :)

@lukecarbis lukecarbis merged commit a488465 into develop Jun 28, 2019
@lukecarbis lukecarbis deleted the fix/class-name branch June 28, 2019 02:19
lukecarbis added a commit to lukecarbis/block-lab that referenced this pull request Aug 18, 2019
Fix an issue where the block_field( 'className' ) doesn't output anything
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants