BP_Group_Extension::get_screen_callback( string $context = '', string $type = 'screen' )

Get the appropriate screen callback for the specified context/type.


Description Description

BP Group Extensions have three special "screen contexts": create, admin, and edit. Each of these contexts has a corresponding _screen() and _screen_save() method, which allow group extension plugins to define different markup and logic for each context.

BP also supports fallback settings_screen() and settings_screen_save() methods, which can be used to define markup and logic that is shared between context. For each context, you may either provide context-specific methods, or you can let BP fall back on the shared settings_* callbacks.

For example, consider a BP_Group_Extension implementation that looks like this:

// … function create_screen( $group_id ) { … } function create_screen_save( $group_id ) { … } function settings_screen( $group_id ) { … } function settings_screen_save( $group_id ) { … } // …

BP_Group_Extension will use your create_ methods for the Create steps, and will use your generic settings_ methods for the Edit and Admin contexts. This schema allows plugin authors maximum flexibility without having to repeat themselves.

The get_screen_callback() method uses a ReflectionClass object to determine whether your extension has provided a given callback.


Top ↑

Parameters Parameters

$context

(string) (Optional) Screen context. 'create', 'edit', or 'admin'.

Default value: ''

$type

(string) (Optional) Screen type. 'screen' or 'screen_save'. Default: 'screen'.

Default value: 'screen'


Top ↑

Return Return

(callable) A callable function handle.


Source Source

File: bp-groups/classes/class-bp-group-extension.php

	public function get_screen_callback( $context = '', $type = 'screen' ) {
		$callback = '';

		// Try the context-specific callback first.
		$method  = $context . '_' . $type;
		$rmethod = $this->class_reflection->getMethod( $method );
		if ( isset( $rmethod->class ) && $this->class_name === $rmethod->class ) {
			$callback = array( $this, $method );
		}

		if ( empty( $callback ) ) {
			$fallback_method  = 'settings_' . $type;
			$rfallback_method = $this->class_reflection->getMethod( $fallback_method );
			if ( isset( $rfallback_method->class ) && $this->class_name === $rfallback_method->class ) {
				$callback = array( $this, $fallback_method );
			}
		}

		return $callback;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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