1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-22 20:56:55 +08:00
buddypress/tests/phpunit/assets/class-bptest-component.php
Mathieu Viet 3ca4e1da5b Improve BP_Component methods relative to setting BP Rewrites
So far `BP_Component::add_rewrite_tags()`, 
`BP_Component::add_rewrite_rules()` & `BP_Component::add_permastructs()` 
were just firing hooks. Thanks to the BP Rewrites plugin we were able to 
test how we can use them to actually enjoy the WP Rewrite API in 
BuddyPress. Compared to what was tested in this feature as plugin, some 
improvements has been brought so that it's easier to benefit from the BP 
Rewrites API for custom components (analyzing the included PHPUnit tests 
can give BP plugin authors a preview about how to process).

Introduce the `BP_Component::pre_query()` method to avoid superfluous Post 
queries when a BuddyPress page is displayed.

The `src/bp-core/bp-rewrites.php` file has also been inited, this is the 
place where all Core component rewrites function will be placed.

Props r-a-y, johnjamesjacoby, boonebgorges

See #4954



git-svn-id: https://buddypress.svn.wordpress.org/trunk@13422 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2023-02-15 10:23:05 +00:00

49 lines
984 B
PHP

<?php
// Testing Component Class.
class BPTest_Component extends BP_Component {
/**
* Globals to test.
*
* @var array
*/
public $globals = array();
// Start the `test` component setup process.
public function __construct( $args = array() ) {
$r = bp_parse_args(
$args,
array(
'id' => 'example',
'name' => 'Example Component',
'globals' => array(
'slug' => 'example',
),
)
);
$this->globals = $r['globals'];
parent::start(
$r['id'],
$r['name']
);
}
// Setup Test Globals.
public function setup_globals( $args = array() ) {
parent::setup_globals( $this->globals );
}
public function add_rewrite_tags( $rewrite_tags = array() ) {
parent::add_rewrite_tags( $rewrite_tags );
}
public function add_rewrite_rules( $rewrite_rules = array() ) {
parent::add_rewrite_rules( $rewrite_rules );
}
public function add_permastructs( $permastructs = array() ) {
parent::add_permastructs( $permastructs );
}
}