BP_Group_Extension::get_screen_callback( string $context = '', string $type = 'screen' )
Get the appropriate screen callback for the specified context/type.
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.
Parameters
- $context
-
(Optional) Screen context. 'create', 'edit', or 'admin'.
Default value: ''
- $type
-
(Optional) Screen type. 'screen' or 'screen_save'. Default: 'screen'.
Default value: 'screen'
Return
(callable) A callable function handle.
Source
File: bp-groups/classes/class-bp-group-extension.php
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 | 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 ; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.8.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.