← All changes
|
includes/shortcodes/class-charitable-donors-shortcode.php
+35
-2
1.7.0.9
→
1.8.13
View file →
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * Donors shortcode class. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Shortcodes/Donors |
| 6 | 6 | * @author David Bisset |
| 7 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 9 | * @since 1.5.0 |
| 10 | 10 | * @version 1.5.7 |
| 11 | 11 | */ |
| @@ -44,11 +44,43 @@ | ||
| 44 | 44 | 'show_location' => 0, |
| 45 | 45 | 'show_amount' => 1, |
| 46 | 46 | 'show_avatar' => 1, |
| 47 | 47 | 'hide_if_no_donors' => 0, |
| 48 | + 'campaign_categories' => '', | |
| 49 | + 'builder_preview' => false, // added in 1.8.0 | |
| 48 | 50 | ); |
| 49 | 51 | |
| 50 | - $args = shortcode_atts( $default, $atts, 'charitable_donors' ); | |
| 52 | + $args = shortcode_atts( $default, $atts, 'charitable_donors' ); | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * The order attribute is interpolated into the ORDER BY clause of the | |
| 56 | + * donor query, so restrict it to a valid sort direction before it is | |
| 57 | + * passed any further. | |
| 58 | + * | |
| 59 | + * @since 1.8.12.2 | |
| 60 | + */ | |
| 61 | + $args['order'] = charitable_validate_sort_direction( $args['order'] ); | |
| 62 | + | |
| 63 | + if ( '' !== $args['campaign_categories'] ) { | |
| 64 | + $campaign_categories = str_replace( ', ', ',', $args['campaign_categories'] ); | |
| 65 | + $campaign_categories = explode( ',', $args['campaign_categories'] ); | |
| 66 | + $cat_args = [ | |
| 67 | + 'post_type' => 'campaign', | |
| 68 | + 'posts_per_page' => -1, | |
| 69 | + 'fields' => 'ids', | |
| 70 | + 'tax_query' => [ | |
| 71 | + [ | |
| 72 | + 'taxonomy' => 'campaign_category', | |
| 73 | + 'field' => 'slug', | |
| 74 | + 'terms' => $campaign_categories, | |
| 75 | + ], | |
| 76 | + ], | |
| 77 | + ]; | |
| 78 | + $query = new WP_Query( $cat_args ); | |
| 79 | + if ( ! empty( $query->posts ) ) { | |
| 80 | + $args['campaign'] = $query->posts; | |
| 81 | + } | |
| 82 | + } | |
| 51 | 83 | $args['donors'] = self::get_donors( $args ); |
| 52 | 84 | |
| 53 | 85 | /** |
| 54 | 86 | * Replace the default template with your own. |
| @@ -97,8 +129,9 @@ | ||
| 97 | 129 | 'show_location', |
| 98 | 130 | 'show_amount', |
| 99 | 131 | 'show_avatar', |
| 100 | 132 | 'hide_if_no_donors', |
| 133 | + 'builder_preview' | |
| 101 | 134 | ) |
| 102 | 135 | ), |
| 103 | 136 | $args |
| 104 | 137 | ); |