mirror of
https://gh.wpcy.net/https://github.com/buddypress/buddypress.git
synced 2026-06-01 06:04:04 +08:00
The shiny new BP_Group_Extension class boasts the following features: - The *_screen* methods (edit_screen(), edit_screen_save(), etc) now share identical requirements for markup and logic. You no longer need to provide a Submit button for edit_screen() but not for create_screen(); BuddyPress provides one for you in each context. (For backward compatibility, we verify that your edit_screen() method does not already have a Submit button before auto-adding our own.) Nonces are now created and checked automatically for all form contexts. And it is no longer necessary to check whether you are on the correct group creation or admin step before outputting your markup - BP_Group_Extension does it for you. - Introduces support for fallback methods settings_screen() and settings_screen_save(). When you define these methods in your extension, they will provide the markup and form-saving logic for your Create, Edit, and Admin panels. If you provide specific methods for a given context (say, edit_screen() and create_screen_save()), BP_Group_Extension detects it, and uses the more specific ones instead. This should make it much easier to write DRY code in your BP_Group_Extension classes, while maintaining maximum flexibility. - Configuration should now be set using a config array, which is then passed to parent::init() at the end of your class constructor. This technique more closely mirrors the way that BuddyPress and WordPress handle configuration elsewhere. BP_Group_Extension parses your config array to arbitrary depth, so that you only need to pass those values that you wish to change from the defaults. - Complete backward compatibility for legacy BP_Group_Extension plugins. - Improved organization, documentation, and unit tests. Props johnjamesjacoby for detailed feedback. See #4955 git-svn-id: https://buddypress.svn.wordpress.org/trunk@6997 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
148 lines
3.5 KiB
PHP
148 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* The following implementations of BP_Group_Extension act as dummy plugins
|
|
* for our unit tests
|
|
*/
|
|
|
|
class BPTest_Group_Extension_Parse_Legacy_Properties extends BP_Group_Extension {
|
|
function __construct() {
|
|
$class_name = get_class( $this );
|
|
$this->name = $class_name;
|
|
$this->slug = sanitize_title( $class_name );
|
|
$this->admin_name = $this->name . ' Edit';
|
|
$this->admin_slug = $this->slug . '-edit';
|
|
$this->create_name = $this->name . ' Create';
|
|
$this->create_slug = $this->slug . '-create';
|
|
$this->visibility = 'private';
|
|
$this->create_step_position = 58;
|
|
$this->nav_item_position = 63;
|
|
$this->admin_metabox_context = 'high';
|
|
$this->admin_metabox_priority = 'side';
|
|
$this->enable_create_step = false;
|
|
$this->enable_nav_item = true;
|
|
$this->enable_edit_item = false;
|
|
$this->enable_admin_item = true;
|
|
$this->nav_item_name = $this->name . ' Nav';
|
|
$this->display_hook = 'foo_hook';
|
|
$this->template_file = 'foo_template';
|
|
}
|
|
|
|
/**
|
|
* Provides access to protected method unneeded in BP
|
|
*/
|
|
function _parse_legacy_properties() {
|
|
return $this->parse_legacy_properties();
|
|
}
|
|
|
|
/**
|
|
* Provides access to protected property unneeded in BP
|
|
*/
|
|
function _get_legacy_properties_converted() {
|
|
return $this->legacy_properties_converted;
|
|
}
|
|
}
|
|
|
|
class BPTest_Group_Extension_Setup_Screens_Use_Global_Fallbacks extends BP_Group_Extension {
|
|
function __construct() {
|
|
$class_name = get_class( $this );
|
|
$this->slug = sanitize_title( $class_name );
|
|
$this->name = $class_name;
|
|
}
|
|
|
|
/**
|
|
* Provides access to protected method unneeded in BP
|
|
*/
|
|
function _get_default_screens() {
|
|
return $this->get_default_screens();
|
|
}
|
|
|
|
/**
|
|
* Provides access to protected method unneeded in BP
|
|
*/
|
|
function _setup_class_info() {
|
|
return $this->setup_class_info();
|
|
}
|
|
|
|
function settings_screen() {}
|
|
function settings_screen_save() {}
|
|
}
|
|
|
|
class BPTest_Group_Extension_Setup_Screens_Define_Edit_Screens_Locally extends BP_Group_Extension {
|
|
function __construct() {
|
|
$class_name = get_class( $this );
|
|
$this->slug = sanitize_title( $class_name );
|
|
$this->name = $class_name;
|
|
}
|
|
|
|
function edit_screen() {}
|
|
function edit_screen_save() {}
|
|
function settings_screen() {}
|
|
function settings_screen_save() {}
|
|
|
|
/**
|
|
* Provides access to protected method unneeded in BP
|
|
*/
|
|
function _get_default_screens() {
|
|
return $this->get_default_screens();
|
|
}
|
|
|
|
/**
|
|
* Provides access to protected method unneeded in BP
|
|
*/
|
|
function _setup_class_info() {
|
|
return $this->setup_class_info();
|
|
}
|
|
|
|
}
|
|
|
|
class BPTest_Group_Extension_Access_Root_Property extends BP_Group_Extension {
|
|
function __construct() {
|
|
$class_name = get_class( $this );
|
|
|
|
$args = array(
|
|
'slug' => sanitize_title( $class_name ),
|
|
'name' => $class_name,
|
|
'nav_item_position' => 39,
|
|
);
|
|
|
|
parent::init( $args );
|
|
}
|
|
}
|
|
|
|
class BPTest_Group_Extension_Access_Init_Property_Using_Legacy_Location extends BP_Group_Extension {
|
|
function __construct() {
|
|
$class_name = get_class( $this );
|
|
|
|
$args = array(
|
|
'slug' => sanitize_title( $class_name ),
|
|
'name' => $class_name,
|
|
'screens' => array(
|
|
'create' => array(
|
|
'position' => 18,
|
|
),
|
|
),
|
|
);
|
|
|
|
parent::init( $args );
|
|
}
|
|
}
|
|
|
|
class BPTest_Group_Extension_Get_Screen_Callback_Fallbacks extends BP_Group_Extension {
|
|
function __construct() {
|
|
$class_name = get_class( $this );
|
|
|
|
$args = array(
|
|
'slug' => sanitize_title( $class_name ),
|
|
'name' => $class_name,
|
|
);
|
|
|
|
parent::init( $args );
|
|
}
|
|
|
|
function settings_screen() {}
|
|
function settings_screen_save() {}
|
|
|
|
function edit_screen() {}
|
|
function edit_screen_save() {}
|
|
}
|