Changeset 13332 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
- Timestamp:
- 03/14/2024 03:26:56 AM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r13308 r13332 793 793 794 794 // For any invalid values passed to browse, set it to featured instead 795 if ( !empty ( $wp_query->query ['browse'] ) && 796 !in_array( $wp_query->query['browse'], array( 'featured', 'popular', 'beta', 'blocks', 'block', 'new', 'favorites', 'adopt-me', 'updated' ) ) ) { 797 $wp_query->query['browse'] = 'featured'; 795 if ( 796 ! empty ( $wp_query->query['browse'] ) && 797 ! in_array( $wp_query->query['browse'], array( 'featured', 'popular', 'beta', 'blocks', 'block', 'new', 'favorites', 'adopt-me', 'updated' ) ) 798 ) { 799 $wp_query->query['browse'] = 'featured'; 798 800 $wp_query->query_vars['browse'] = 'featured'; 799 801 } … … 802 804 switch ( $wp_query->get( 'browse' ) ) { 803 805 case 'beta': 804 $wp_query->query_vars['meta_key'] = 'last_updated'; 805 $wp_query->query_vars['orderby'] = 'meta_value'; 806 $wp_query->query_vars['order'] = 'DESC'; 806 $wp_query->query_vars['orderby'] ??= 'last_updated'; 807 807 808 808 // Limit the Beta tab to plugins updated within 12 months. … … 833 833 $wp_query->query_vars['post_name__in'] = get_user_meta( $favorites_user->ID, 'plugin_favorites', true ); 834 834 835 $wp_query->query_vars['orderby'] = 'post_title';836 $wp_query->query_vars['order'] = 'ASC';835 $wp_query->query_vars['orderby'] ??= 'post_title'; 836 $wp_query->query_vars['order'] ??= 'ASC'; 837 837 } 838 838 … … 843 843 844 844 case 'updated': 845 $wp_query->query_vars['orderby'] = 'post_modified';845 $wp_query->query_vars['orderby'] ??= 'last_updated'; 846 846 break; 847 847 848 848 case 'block': 849 849 case 'new': 850 $wp_query->query_vars['orderby'] = 'post_date';850 $wp_query->query_vars['orderby'] ??= 'post_date'; 851 851 break; 852 852 } … … 905 905 } 906 906 907 $wp_query->query_vars['orderby'] = 'post_title';908 $wp_query->query_vars['order'] = 'ASC';907 $wp_query->query_vars['orderby'] ??= 'post_title'; 908 $wp_query->query_vars['order'] ??= 'ASC'; 909 909 910 910 // Treat it as a taxonomy query now, not the author archive. … … 979 979 980 980 // By default, all archives are sorted by active installs 981 if ( $wp_query->is_archive() && empty( $wp_query->query_vars['orderby'] ) ) { 982 $wp_query->query_vars['orderby'] = 'meta_value_num'; 983 $wp_query->query_vars['meta_key'] = '_active_installs'; 981 if ( $wp_query->is_archive() && ! $wp_query->is_search() && empty( $wp_query->query_vars['orderby'] ) ) { 982 $wp_query->query_vars['orderby'] = 'active_installs'; 983 } 984 985 // Adjust the rules for other sorts. 986 // Support orderby={orderby}_{order} 987 if ( isset( $wp_query->query_vars['orderby'] ) && is_string( $wp_query->query_vars['orderby'] ) ) { 988 $orderby = $wp_query->query_vars['orderby']; 989 if ( str_ends_with( $orderby, '_desc' ) ) { 990 $wp_query->query_vars['order'] = 'DESC'; 991 $wp_query->query_vars['orderby'] = substr( $orderby, 0, -5 ); 992 } elseif ( str_ends_with( $orderby, '_asc' ) ) { 993 $wp_query->query_vars['order'] = 'ASC'; 994 $wp_query->query_vars['orderby'] = substr( $orderby, 0, -4 ); 995 } 996 } 997 998 // The custom sorts. 999 $orderby = $wp_query->query_vars['orderby'] ?? ''; 1000 $order = $wp_query->query_vars['order'] ?? 'DESC'; 1001 switch( $orderby ) { 1002 case 'rating': 1003 // TODO: Round out the rating to be based on half-stars. A 4.95 rating vs a 5.00 appears the same, but sorts differently. 1004 $wp_query->query_vars['meta_query']['rating'] ??= [ 1005 'key' => 'rating', 1006 'type' => 'DECIMAL(3,2)', 1007 'compare' => 'EXISTS', 1008 ]; 1009 $wp_query->query_vars['meta_query']['num_ratings'] ??= [ 1010 'key' => 'num_ratings', 1011 'type' => 'UNSIGNED', 1012 'compare' => '>', 1013 'value' => 0, 1014 ]; 1015 1016 // Should be a multisort, with an additional `num_ratings`. 1017 $wp_query->query_vars['orderby'] = array( 1018 'rating' => $order, 1019 'num_ratings' => $order, 1020 ); 1021 1022 break; 1023 1024 case 'num_ratings': 1025 case 'ratings': 1026 $wp_query->query_vars['meta_query']['num_ratings'] ??= [ 1027 'key' => 'num_ratings', 1028 'type' => 'UNSIGNED', 1029 'compare' => '>', 1030 'value' => 0, 1031 ]; 1032 1033 $wp_query->query_vars['orderby'] = 'num_ratings'; 1034 break; 1035 1036 case '_active_installs': 1037 case 'active_installs': 1038 $wp_query->query_vars['meta_query']['active_installs'] ??= [ 1039 'key' => '_active_installs', 1040 'type' => 'UNSIGNED', 1041 'compare' => 'EXISTS' 1042 ]; 1043 1044 $wp_query->query_vars['orderby'] = 'active_installs'; 1045 break; 1046 1047 case 'last_updated': 1048 $wp_query->query_vars['meta_query']['last_updated'] ??= [ 1049 'key' => 'last_updated', 1050 'type' => 'DATE', 1051 'compare' => 'EXISTS', 1052 ]; 1053 break; 1054 1055 case 'tested': 1056 $wp_query->query_vars['meta_query']['tested'] ??= [ 1057 'key' => 'tested', 1058 'type' => 'DECIMAL(2,1)', 1059 'compare' => 'EXISTS', 1060 ]; 1061 break; 1062 1063 case 'downloads': 1064 $wp_query->query_vars['meta_query']['downloads'] ??= [ 1065 'key' => 'downloads', 1066 'type' => 'UNSIGNED', 1067 'compare' => 'EXISTS', 1068 ]; 1069 $wp_query->query_vars['orderby'] = 'downloads'; 1070 break; 984 1071 } 985 1072 }
Note: See TracChangeset
for help on using the changeset viewer.