From 2c5da0bf09bed05cbde2a5c7f1f859310e15bca4 Mon Sep 17 00:00:00 2001 From: Fellan-91 Date: Thu, 25 Apr 2024 11:58:25 +0300 Subject: [PATCH] improved and simplified the sort code --- classes/class-admin.php | 4 +-- classes/class-get-portfolio.php | 43 +++++++-------------------------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/classes/class-admin.php b/classes/class-admin.php index fb0da54d..74a35a1a 100644 --- a/classes/class-admin.php +++ b/classes/class-admin.php @@ -1777,8 +1777,8 @@ public function register_controls() { 'title' => esc_html__( 'Item Title', 'visual-portfolio' ), 'description' => esc_html__( 'Item Description', 'visual-portfolio' ), 'image_title' => esc_html__( 'Image Title', 'visual-portfolio' ), - 'caption' => esc_html__( 'Image Caption', 'visual-portfolio' ), - 'alt' => esc_html__( 'Image Alt', 'visual-portfolio' ), + 'image_caption' => esc_html__( 'Image Caption', 'visual-portfolio' ), + 'image_alt' => esc_html__( 'Image Alt', 'visual-portfolio' ), 'image_description' => esc_html__( 'Image Description', 'visual-portfolio' ), 'date' => esc_html__( 'Image Uploaded', 'visual-portfolio' ), 'rand' => esc_html__( 'Random', 'visual-portfolio' ), diff --git a/classes/class-get-portfolio.php b/classes/class-get-portfolio.php index aca2d5e6..b8409930 100644 --- a/classes/class-get-portfolio.php +++ b/classes/class-get-portfolio.php @@ -1302,25 +1302,25 @@ public static function get_query_params( $options, $for_filter = false, $layout_ // title. if ( 'custom' !== $options['images_titles_source'] ) { - $images[ $k ]['title'] = isset( $img_meta[ $options['images_titles_source'] ] ) ? $img_meta[ $options['images_titles_source'] ] : ''; + $images[ $k ]['title'] = $img_meta[ $options['images_titles_source'] ] ?? ''; } // image title. - $images[ $k ]['image_title'] = isset( $img_meta['title'] ) ? $img_meta['title'] : ''; + $images[ $k ]['image_title'] = $img_meta['title'] ?? ''; // description. if ( 'custom' !== $options['images_descriptions_source'] ) { - $images[ $k ]['description'] = isset( $img_meta[ $options['images_descriptions_source'] ] ) ? $img_meta[ $options['images_descriptions_source'] ] : ''; + $images[ $k ]['description'] = $img_meta[ $options['images_descriptions_source'] ] ?? ''; } // image description. - $images[ $k ]['image_description'] = isset( $img_meta['description'] ) ? $img_meta['description'] : ''; + $images[ $k ]['image_description'] = $img_meta['description'] ?? ''; // image caption. - $images[ $k ]['image_caption'] = isset( $img_meta['caption'] ) ? $img_meta['caption'] : ''; + $images[ $k ]['image_caption'] = $img_meta['caption'] ?? ''; // image alt. - $images[ $k ]['image_alt'] = isset( $img_meta['alt'] ) ? $img_meta['alt'] : ''; + $images[ $k ]['image_alt'] = $img_meta['alt'] ?? ''; // add published date. $images[ $k ]['published_time'] = get_the_date( 'Y-m-d H:i:s', $attachment ); @@ -1364,39 +1364,14 @@ public static function get_query_params( $options, $for_filter = false, $layout_ case 'title': case 'description': case 'image_title': - case 'caption': - case 'alt': + case 'image_caption': + case 'image_alt': case 'image_description': $sort_tmp = array(); $new_images = array(); - $sort_by = 'date'; - - if ( 'title' === $custom_order ) { - $sort_by = 'title'; - } - - if ( 'description' === $custom_order ) { - $sort_by = 'description'; - } - - if ( 'image_title' === $custom_order ) { - $sort_by = 'image_title'; - } - - if ( 'caption' === $custom_order ) { - $sort_by = 'image_caption'; - } - - if ( 'alt' === $custom_order ) { - $sort_by = 'image_alt'; - } - - if ( 'image_description' === $custom_order ) { - $sort_by = 'image_description'; - } foreach ( $images as &$ma ) { - $sort_tmp[] = &$ma[ $sort_by ]; + $sort_tmp[] = &$ma[ $custom_order ]; } array_multisort( $sort_tmp, $images );