-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REST API: Terms: Allow sorting by term_order
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
lib/compat/wordpress-6.8/class-gutenberg-rest-terms-controller-6-8.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* REST API: Gutenberg_REST_Terms_Controller_6_8 class | ||
* | ||
* @package gutenberg | ||
* @subpackage REST_API | ||
* @since 6.8.0 | ||
*/ | ||
class Gutenberg_REST_Terms_Controller_6_8 extends WP_REST_Terms_Controller { | ||
/** | ||
* Retrieves the query params for collections. | ||
* | ||
* @since 4.7.0 | ||
* @since 6.8.0 Added 'term_order' to the list of allowed orderby parameters. | ||
* | ||
* @return array Collection parameters. | ||
*/ | ||
public function get_collection_params() { | ||
$query_params = parent::get_collection_params(); | ||
|
||
$query_params['orderby']['enum'][] = 'term_order'; | ||
|
||
return $query_params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* PHP and WordPress configuration compatibility functions for the Gutenberg | ||
* editor plugin changes related to REST API. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
die( 'Silence is golden.' ); | ||
} | ||
|
||
/** | ||
* Overrides the default 'WP_REST_Terms_Controller' class for all taxonomies upon registration. | ||
* | ||
* @return array The updated taxonomy registration arguments. | ||
*/ | ||
function gutenberg_override_terms_controller_6_8( $args, $taxonomy ) { | ||
if ( empty( $args['show_in_rest'] ) ) { | ||
return $args; | ||
} | ||
|
||
if ( isset( $args['rest_controller_class'] ) && 'WP_REST_Terms_Controller' !== $args['rest_controller_class'] ) { | ||
return $args; | ||
} | ||
|
||
$args['rest_controller_class'] = Gutenberg_REST_Terms_Controller_6_8::class; | ||
return $args; | ||
} | ||
add_filter( 'register_taxonomy_args', 'gutenberg_override_terms_controller_6_8', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters