Skip to content

Refactor WP_Block_Type::render() logic.#4716

Closed
tfrommen wants to merge 4 commits intoWordPress:masterfrom
tfrommen:class-wp-block-type
Closed

Refactor WP_Block_Type::render() logic.#4716
tfrommen wants to merge 4 commits intoWordPress:masterfrom
tfrommen:class-wp-block-type

Conversation

@tfrommen
Copy link
Copy Markdown
Member

Description

In case of no render callback, the function always returned '' (empty string) for faulty (i.e., == false) $content. Firstly, the code for doing this was overly complicated, secondly, it didn't make sure there was actually a string being returned, and thirdly, in case of the string '0' there was also the empty string being returned.

The proposed code is straightforward, type-safe, and does not include the '0' error.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.

@noisysocks
Copy link
Copy Markdown
Member

This makes sense, and reads a lot nicer. Could we add tests for this logic?

@tfrommen
Copy link
Copy Markdown
Member Author

tfrommen commented Jan 29, 2018

@noisysocks - I just did. ...OK, not "just", but in the end, I did. 😉

@aduth
Copy link
Copy Markdown
Member

aduth commented Jan 30, 2018

The changes proposed here conflict with those proposed in #4591, namely the removal of $content argument from BlockType::render

@tfrommen
Copy link
Copy Markdown
Member Author

tfrommen commented Jan 30, 2018

Well, such things happen.

If you could add a (string) cast before the call_user_func() in #4591, I'm happy. :)

@tfrommen tfrommen closed this Jan 30, 2018
@aduth
Copy link
Copy Markdown
Member

aduth commented Jan 31, 2018

@tfrommen Good call, though #4591 has since been merged. I can plan to create a separate pull request.

@tfrommen tfrommen deleted the class-wp-block-type branch January 31, 2018 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants