Skip to content

Commit

Permalink
REST API: Terms: Allow sorting by term_order
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Nov 19, 2024
1 parent 70a8855 commit f421545
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
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;
}
}
30 changes: 30 additions & 0 deletions lib/compat/wordpress-6.8/rest-api.php
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 );
2 changes: 2 additions & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function gutenberg_is_experiment_enabled( $name ) {
// WordPress 6.8 compat.
require __DIR__ . '/compat/wordpress-6.8/block-comments.php';
require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php';
require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-terms-controller-6-8.php';
require __DIR__ . '/compat/wordpress-6.8/rest-api.php';

// Plugin specific code.
require_once __DIR__ . '/class-wp-rest-global-styles-controller-gutenberg.php';
Expand Down

0 comments on commit f421545

Please sign in to comment.