Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for customizing block arguments #3782

Merged
merged 5 commits into from Nov 17, 2020
Merged

Conversation

renatho
Copy link
Contributor

@renatho renatho commented Nov 16, 2020

Changes proposed in this Pull Request

  • It removes the sensei_take_course_block_type_args filter in favor of the generic sensei_block_type_args.

Notice that this is for backwards compatibility, and after the WP 5.5 we should use the register_block_type_args. See this PR for more details.

Testing instructions

  • Create a course.
  • Add all Sensei blocks to the course.
  • Add the following filter, and make sure all the blocks render as a text "Filtered":
		add_filter( 'sensei_block_type_args', function( $args ) {
			$args[ 'render_callback' ] = function() { return 'Filtered'; };
			return $args;
		} );

New/Updated Hooks

sensei_block_type_args - For WordPress < 5.5, filters block arguments. For WordPress >= 5.5, use register_block_type_args instead.

@renatho renatho added this to the 3.6.0 milestone Nov 16, 2020
@renatho renatho requested a review from a team November 16, 2020 18:47
@renatho renatho self-assigned this Nov 16, 2020
Copy link
Member

@jom jom left a comment

Choose a reason for hiding this comment

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

Minor change then it is ready 👍

* @see includes/blocks/compat.php
*
* @param {array} $args The block arguments as defined by register_block_type.
* @param {string} $args Block name.
Copy link
Member

Choose a reason for hiding this comment

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

Param variable name needs to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops! Fixed here: cb156c1

@gikaragia
Copy link
Contributor

gikaragia commented Nov 17, 2020

Updated WCPC to use the new filte here

@renatho renatho merged commit 4eb7d84 into master Nov 17, 2020
@renatho renatho deleted the add/sensei-blocks-filter branch November 17, 2020 13:03
@donnapep donnapep added the Hooks This change adds or modifies one or more hooks. label Nov 17, 2020
@donnapep donnapep changed the title Add sensei blocks args filter Add filter for customizing block arguments Nov 17, 2020
* @param {array} $block_args The block arguments as defined by register_block_type.
* @param {string} $block_name Block name.
*/
$block_args = apply_filters( 'sensei_block_type_args', $block_args, $block_name );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this filter is showing up as an action in the hook docs. This is because filters need an @return attribute - 4f98ea0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed here: #3789

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hooks This change adds or modifies one or more hooks. [Type] Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants