From 9a590d29569644eb9f83e4e3aa84b315f3247c5b Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 24 Feb 2020 11:59:17 -0700 Subject: [PATCH 1/6] feat: add term order field (resolves #294) --- includes/functions/metadata.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/includes/functions/metadata.php b/includes/functions/metadata.php index 144c439..c7284a9 100644 --- a/includes/functions/metadata.php +++ b/includes/functions/metadata.php @@ -362,9 +362,21 @@ function register_meta() { function resource_data_init() { $prefix = 'lc_resource_'; + $term_info = new_cmb2_box( + [ + 'id' => 'term_info', + 'title' => __( 'Tag Information', 'coop-library-framework' ), + 'object_types' => [ 'term' ], + 'taxonomies' => [ 'lc_goal', 'lc_topic' ], + 'context' => 'normal', + 'priority' => 'high', + 'show_names' => true, + ] + ); + $general_info = new_cmb2_box( [ - 'id' => '01_resource_data', + 'id' => '01_general_info', 'title' => __( 'General Information', 'coop-library-framework' ), 'object_types' => [ 'lc_resource' ], 'context' => 'normal', @@ -428,6 +440,17 @@ function resource_data_init() { ] ); + $term_info->add_field( + [ + 'name' => __( 'Order', 'coop-library-framework' ), + 'description' => __( 'The numeric order of this tag.', 'coop-library-framework' ), + 'id' => 'lc_term_order', + 'type' => 'text', + 'default' => 0, + 'sanitize_cb' => 'intval', + ] + ); + $general_info->add_field( [ 'name' => __( 'Favorites', 'coop-library-framework' ), From c0d9f0c07833787a4578d732478501414f879b8f Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 24 Feb 2020 14:12:44 -0700 Subject: [PATCH 2/6] fix: use WP Term Order (no need to reinvent the wheel) --- includes/functions/core.php | 1 + includes/functions/metadata.php | 23 ----------------------- wp-dependencies.json | 7 +++++++ 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/includes/functions/core.php b/includes/functions/core.php index bef176c..3955594 100644 --- a/includes/functions/core.php +++ b/includes/functions/core.php @@ -47,6 +47,7 @@ function setup() { add_filter( 'pll_get_taxonomies', $n( 'add_topic_to_pll' ), 10, 2 ); add_filter( 'pll_get_taxonomies', $n( 'add_goal_to_pll' ), 10, 2 ); add_filter( 'pll_get_taxonomies', $n( 'add_format_to_pll' ), 10, 2 ); + add_filter( 'wp_fancy_term_order', '__return_false' ); do_action( 'coop_library_framework_loaded' ); } diff --git a/includes/functions/metadata.php b/includes/functions/metadata.php index c7284a9..c3eca8a 100644 --- a/includes/functions/metadata.php +++ b/includes/functions/metadata.php @@ -362,18 +362,6 @@ function register_meta() { function resource_data_init() { $prefix = 'lc_resource_'; - $term_info = new_cmb2_box( - [ - 'id' => 'term_info', - 'title' => __( 'Tag Information', 'coop-library-framework' ), - 'object_types' => [ 'term' ], - 'taxonomies' => [ 'lc_goal', 'lc_topic' ], - 'context' => 'normal', - 'priority' => 'high', - 'show_names' => true, - ] - ); - $general_info = new_cmb2_box( [ 'id' => '01_general_info', @@ -440,17 +428,6 @@ function resource_data_init() { ] ); - $term_info->add_field( - [ - 'name' => __( 'Order', 'coop-library-framework' ), - 'description' => __( 'The numeric order of this tag.', 'coop-library-framework' ), - 'id' => 'lc_term_order', - 'type' => 'text', - 'default' => 0, - 'sanitize_cb' => 'intval', - ] - ); - $general_info->add_field( [ 'name' => __( 'Favorites', 'coop-library-framework' ), diff --git a/wp-dependencies.json b/wp-dependencies.json index da16899..98f3afb 100644 --- a/wp-dependencies.json +++ b/wp-dependencies.json @@ -33,5 +33,12 @@ "slug": "theme-translation-for-polylang/polylang-theme-translation.php", "uri": "https://wordpress.org/plugins/theme-translation-for-polylang/", "optional": false + }, + { + "name": "WP Term Order", + "host": "wordpress", + "slug": "wp-term-order/wp-term-order.php", + "uri": "https://wordpress.org/plugins/wp-term-order/", + "optional": false } ] From daf54d7a46da5b4010feed7229600fd4779c1fb4 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 24 Feb 2020 15:13:31 -0700 Subject: [PATCH 3/6] fix: patch term order bug --- includes/functions/core.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/includes/functions/core.php b/includes/functions/core.php index 3955594..b4b33c8 100644 --- a/includes/functions/core.php +++ b/includes/functions/core.php @@ -47,8 +47,13 @@ function setup() { add_filter( 'pll_get_taxonomies', $n( 'add_topic_to_pll' ), 10, 2 ); add_filter( 'pll_get_taxonomies', $n( 'add_goal_to_pll' ), 10, 2 ); add_filter( 'pll_get_taxonomies', $n( 'add_format_to_pll' ), 10, 2 ); + + // Disable inaccessible sortable JavaScript for term order. add_filter( 'wp_fancy_term_order', '__return_false' ); + // Fix for https://github.com/stuttter/wp-term-order/issues/11. + add_filter( 'get_terms_orderby', $n( 'get_terms_orderby' ), 9, 2 ); + do_action( 'coop_library_framework_loaded' ); } @@ -776,3 +781,26 @@ function supports_block_editor( $use_block_editor, $post_type ) { return $use_block_editor; } + +/** + * Force `orderby` to `tt.order` if not explicitly set to something else. + * + * @param string $orderby The `orderby` value. + * @param array $args Arguments. + * @return string $orderby The (possible modified) `orderby` value. + */ +function get_terms_orderby( $orderby = 'name', $args = array() ) { + + // Do not override if being manually controlled + if ( ! empty( $_GET['orderby'] ) && ! empty( $_GET['taxonomy'] ) ) { // @codingStandardsIgnoreLine + return $orderby; + } + + if ( empty( $args['orderby'] ) || empty( $orderby ) || ( 'order' === $args['orderby'] ) ) { + $orderby = 'tt.order'; + } elseif ( 't.name' === $orderby ) { + $orderby = 'tt.order, t.name'; + } + + return $orderby; +} From 3a443e4d9d42ae42021187908f752289e9b3b9dc Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 24 Feb 2020 16:02:21 -0700 Subject: [PATCH 4/6] fix: increase priority for get_terms_orderby --- includes/functions/core.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/functions/core.php b/includes/functions/core.php index b4b33c8..fbee4fd 100644 --- a/includes/functions/core.php +++ b/includes/functions/core.php @@ -52,7 +52,7 @@ function setup() { add_filter( 'wp_fancy_term_order', '__return_false' ); // Fix for https://github.com/stuttter/wp-term-order/issues/11. - add_filter( 'get_terms_orderby', $n( 'get_terms_orderby' ), 9, 2 ); + add_filter( 'get_terms_orderby', $n( 'get_terms_orderby' ), 11, 2 ); do_action( 'coop_library_framework_loaded' ); } @@ -790,15 +790,13 @@ function supports_block_editor( $use_block_editor, $post_type ) { * @return string $orderby The (possible modified) `orderby` value. */ function get_terms_orderby( $orderby = 'name', $args = array() ) { - - // Do not override if being manually controlled if ( ! empty( $_GET['orderby'] ) && ! empty( $_GET['taxonomy'] ) ) { // @codingStandardsIgnoreLine return $orderby; } - if ( empty( $args['orderby'] ) || empty( $orderby ) || ( 'order' === $args['orderby'] ) ) { - $orderby = 'tt.order'; - } elseif ( 't.name' === $orderby ) { + if ( empty( $args['orderby'] ) || empty( $orderby ) || in_array( $orderby, array( 'name', 't.name' ), true ) ) { + $orderby = 'tt.name, tt.order'; + } elseif ( 'order' === $args['orderby'] ) { $orderby = 'tt.order, t.name'; } From 19c55954bd842bd26ecb45803de3702a3b906023 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 24 Feb 2020 16:09:47 -0700 Subject: [PATCH 5/6] fix: default to numeric order followed by name --- includes/functions/core.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/functions/core.php b/includes/functions/core.php index fbee4fd..c4fb8ec 100644 --- a/includes/functions/core.php +++ b/includes/functions/core.php @@ -794,9 +794,7 @@ function get_terms_orderby( $orderby = 'name', $args = array() ) { return $orderby; } - if ( empty( $args['orderby'] ) || empty( $orderby ) || in_array( $orderby, array( 'name', 't.name' ), true ) ) { - $orderby = 'tt.name, tt.order'; - } elseif ( 'order' === $args['orderby'] ) { + if ( empty( $args['orderby'] ) || empty( $orderby ) || 'order' === $args['orderby'] ) { $orderby = 'tt.order, t.name'; } From 079b0d1ad21a50b0fcbfdd768e97c9408c8ad784 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 25 Feb 2020 11:55:28 -0700 Subject: [PATCH 6/6] fix: use fork --- includes/functions/core.php | 22 ---------------------- wp-dependencies.json | 4 ++-- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/includes/functions/core.php b/includes/functions/core.php index c4fb8ec..2ea9261 100644 --- a/includes/functions/core.php +++ b/includes/functions/core.php @@ -51,9 +51,6 @@ function setup() { // Disable inaccessible sortable JavaScript for term order. add_filter( 'wp_fancy_term_order', '__return_false' ); - // Fix for https://github.com/stuttter/wp-term-order/issues/11. - add_filter( 'get_terms_orderby', $n( 'get_terms_orderby' ), 11, 2 ); - do_action( 'coop_library_framework_loaded' ); } @@ -781,22 +778,3 @@ function supports_block_editor( $use_block_editor, $post_type ) { return $use_block_editor; } - -/** - * Force `orderby` to `tt.order` if not explicitly set to something else. - * - * @param string $orderby The `orderby` value. - * @param array $args Arguments. - * @return string $orderby The (possible modified) `orderby` value. - */ -function get_terms_orderby( $orderby = 'name', $args = array() ) { - if ( ! empty( $_GET['orderby'] ) && ! empty( $_GET['taxonomy'] ) ) { // @codingStandardsIgnoreLine - return $orderby; - } - - if ( empty( $args['orderby'] ) || empty( $orderby ) || 'order' === $args['orderby'] ) { - $orderby = 'tt.order, t.name'; - } - - return $orderby; -} diff --git a/wp-dependencies.json b/wp-dependencies.json index 98f3afb..2889d45 100644 --- a/wp-dependencies.json +++ b/wp-dependencies.json @@ -36,9 +36,9 @@ }, { "name": "WP Term Order", - "host": "wordpress", + "host": "github", "slug": "wp-term-order/wp-term-order.php", - "uri": "https://wordpress.org/plugins/wp-term-order/", + "uri": "platform-coop-toolkit/wp-term-order", "optional": false } ]