LLMS_Blocks_Reusable::mod_wp_block_query( arrays $args, WP_REST_Request $request )

Modify the rest request query used to list reusable blocks within the block editor

Description Description

Ensures that reusable blocks containing LifterLMS Form Fields can only be inserted/viewed in the context that we allow them to be used within.

  • When viewing a wp_block post, all reusable blocks should be displayed.
  • When viewing an llms_form post, only blocks that specify is_llms_field as ‘yes’ can be displayed.
  • When viewing any other post, any post with is_llms_field of ‘yes’ is excluded.

See also See also

Top ↑

Parameters Parameters


(arrays) (Required) WP_Query arguments.


(WP_REST_Request) (Required) Request object.

Top ↑

Return Return


Top ↑

Source Source

File: libraries/lifterlms-blocks/includes/class-llms-blocks-reusable.php

	public function mod_wp_block_query( $args, $request ) {

		$referer = $request->get_header( 'referer' );
		$screen  = empty( $referer ) ? false : $this->get_screen_from_referer( $referer );

		// We don't care about the screen or it's a reusable block screen.
		if ( empty( $screen ) || 'wp_block' === $screen ) {
			return $args;

		// Add a meta query if it doesn't already exist.
		if ( empty( $args['meta_query'] ) ) {
			$args['meta_query'] = array(
				'relation' => 'AND',

		// Forms should show only blocks with forms and everything else should exclude blocks with forms.
		$include_fields       = 'llms_form' === $screen;
		$args['meta_query'][] = $this->get_meta_query( $include_fields );

		return $args;


Top ↑

Changelog Changelog

Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.