diff --git a/includes/model/ListingForm.php b/includes/model/ListingForm.php index f3f71e6f67..5fc7cf6902 100644 --- a/includes/model/ListingForm.php +++ b/includes/model/ListingForm.php @@ -964,7 +964,11 @@ protected function set_directory() { if ( ! empty( $maybe_directory_id ) && ! is_numeric( $maybe_directory_id ) ) { $term = get_term_by( 'slug', $maybe_directory_id, ATBDP_TYPE ); - $maybe_directory_id = $term->term_id; + if ( $term && ! is_wp_error( $term ) ) { + $maybe_directory_id = $term->term_id; + } else { + $maybe_directory_id = 0; + } } $this->current_listing_type = (int) $maybe_directory_id; diff --git a/includes/model/SearchForm.php b/includes/model/SearchForm.php index 1fc780480e..ce6d259af7 100644 --- a/includes/model/SearchForm.php +++ b/includes/model/SearchForm.php @@ -1062,7 +1062,7 @@ public static function get_taxonomy_select_option_data( $id ) { $taxonomy = get_term( $id ); - if ( is_wp_error( $taxonomy ) ) { + if ( is_wp_error( $taxonomy ) || ! is_object( $taxonomy ) ) { return $item; } diff --git a/includes/modules/background-process/wp-background-process.php b/includes/modules/background-process/wp-background-process.php index 9219d74ac9..3d8f7d4c82 100644 --- a/includes/modules/background-process/wp-background-process.php +++ b/includes/modules/background-process/wp-background-process.php @@ -194,7 +194,12 @@ protected function is_queue_empty() { $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; - $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM %s WHERE %s LIKE %s", $table, $column, $key ) ); + $count = $wpdb->get_var( + $wpdb->prepare( + "SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", + $key + ) + ); return ( $count > 0 ) ? false : true; } @@ -267,19 +272,26 @@ protected function get_batch() { $query = $wpdb->get_row( $wpdb->prepare( - " - SELECT * - FROM %s - WHERE %s LIKE %s - ORDER BY %s ASC - LIMIT 1 - ", $table, $column, $key, $key_column - ) + "SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1", + $key + ) ); $batch = new stdClass(); - $batch->key = $query->$column; - $batch->data = maybe_unserialize( $query->$value_column ); + $batch->key = ''; + $batch->data = []; + + if ( ! is_object( $query ) ) { + return $batch; + } + + $batch->key = isset( $query->$column ) ? $query->$column : ''; + $batch->data = maybe_unserialize( $query->$value_column ?? [] ); + + if ( ! is_array( $batch->data ) ) { + $batch->data = []; + } + return $batch; } @@ -296,6 +308,10 @@ protected function handle() { do { $batch = $this->get_batch(); + if ( empty( $batch->key ) || empty( $batch->data ) || ! is_array( $batch->data ) ) { + break; + } + foreach ( $batch->data as $key => $value ) { $task = $this->task( $value );