From ea969c917e92203e89f8bf91620b766ac18d8418 Mon Sep 17 00:00:00 2001 From: joerivanveen Date: Sat, 28 Oct 2023 20:06:57 +0200 Subject: [PATCH] fix: allow smooth taxonomy update --- faq-with-categories/faq-with-categories.php | 2 +- faq-with-categories/includes/ruigehond.php | 7 ++++--- faq-with-categories/includes/ruigehond010.php | 11 ++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/faq-with-categories/faq-with-categories.php b/faq-with-categories/faq-with-categories.php index 92ed837..9c25ae9 100644 --- a/faq-with-categories/faq-with-categories.php +++ b/faq-with-categories/faq-with-categories.php @@ -15,7 +15,7 @@ defined( 'ABSPATH' ) or die(); const RUIGEHOND010_VERSION = '1.2.0'; // This is plugin nr. 10 by ruige hond. It identifies with: ruigehond010. -if ( ! class_exists( 'ruigehond_0_4_0\ruigehond', false ) ) { +if ( ! class_exists( 'ruigehond_0_4_1\ruigehond', false ) ) { include_once( dirname( __FILE__ ) . '/includes/ruigehond.php' ); // base class } include_once( dirname( __FILE__ ) . '/includes/ruigehond010.php' ); diff --git a/faq-with-categories/includes/ruigehond.php b/faq-with-categories/includes/ruigehond.php index f14a98d..8f74a3a 100644 --- a/faq-with-categories/includes/ruigehond.php +++ b/faq-with-categories/includes/ruigehond.php @@ -27,7 +27,7 @@ function ruigehond_activation_error() { } } -namespace ruigehond_0_4_0 { +namespace ruigehond_0_4_1 { use stdClass; @@ -252,7 +252,7 @@ public function postExists( int $id ): bool { public function insertDb( string $table_name, array $values ): int { $rows_affected = $this->wpdb->insert( $table_name, $values ); if ( 1 === $rows_affected ) { - return $this->wpdb->insert_id; // var holds the last inserted id + return $this->wpdb->insert_id ?: PHP_INT_MAX; // var holds the last inserted id } else { return 0; } @@ -264,6 +264,7 @@ public function insertDb( string $table_name, array $values ): int { * @param array $where * * @return int 0 on failure, > 0 is the insert id, < 0 is the number of rows affected for update + * return value will be PHP_INT_MAX when insert succeeded, but there was no id column updated */ public function upsertDb( string $table_name, array $values, array $where ): int { $where_condition = 'WHERE 1 = 1'; @@ -403,4 +404,4 @@ public function __construct( $text, $data = null ) { // if data is null it means javascript doesn't have to send anything back } } -} // end of namespace ruigehond_0_4_0 +} // end of namespace ruigehond_0_4_1 diff --git a/faq-with-categories/includes/ruigehond010.php b/faq-with-categories/includes/ruigehond010.php index cb284ad..a9672dd 100644 --- a/faq-with-categories/includes/ruigehond010.php +++ b/faq-with-categories/includes/ruigehond010.php @@ -5,11 +5,11 @@ namespace ruigehond010; // TODO BUG if you put central faq short_code or any exclusive tag on multiple pages, the $on option keeps getting updated -use ruigehond_0_4_0; +use ruigehond_0_4_1; defined( 'ABSPATH' ) or die(); -class ruigehond010 extends ruigehond_0_4_0\ruigehond { +class ruigehond010 extends ruigehond_0_4_1\ruigehond { private $name, $database_version, $taxonomies, $slug, $choose_option, $choose_all, $search_faqs, $table_prefix, $more_button_text, $no_results_warning, $max, $max_ignore_elsewhere, $order_table, $header_tag, @@ -420,6 +420,7 @@ public function getHtmlForFrontend( $attributes = [], $content = null, $short_co } private function getTerms(): array { + // TODO have o.o sort the same for 1 as null if ( true === isset( $this->terms ) ) { return $this->terms; } // return cached value if available @@ -436,7 +437,7 @@ private function getTerms(): array { LEFT OUTER JOIN {$wp_prefix}term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = '$taxonomies' GROUP BY t.term_id, tt.parent, t.name, o.t, o.post_id, o.o - ORDER BY o.o, t.name;"; + ORDER BY tt.parent, COALESCE(o.o, 1), t.name;"; $rows = $this->wpdb->get_results( $sql, OBJECT ); $terms = array(); foreach ( $rows as $key => $row ) { @@ -518,7 +519,7 @@ private function getPosts( $exclusive = null, $term = null ): array { return $return_arr; } - public function handle_input( $args ): ruigehond_0_4_0\returnObject { + public function handle_input( $args ): ruigehond_0_4_1\returnObject { $returnObject = $this->getReturnObject(); $wp_prefix = $this->wpdb->prefix; if ( isset( $args['id'] ) ) { @@ -588,7 +589,7 @@ public function handle_input( $args ): ruigehond_0_4_0\returnObject { "$this->table_prefix$table_name", $update, array( $id_column => $id ) ); if ( 0 === $rows_affected ) { - $returnObject->add_message( __( 'Not updated', 'faq-with-categories' ) ); + $returnObject->add_message( __( 'Not updated', 'faq-with-categories' ), 'warn' ); } else { $returnObject->set_success( true ); $args['value'] = $this->wpdb->get_var(