← All changes
|
includes/shortcodes/class-charitable-campaigns-shortcode.php
+44
-20
1.7.0.1
→
1.8.13
View file →
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * Campaigns shortcode class. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Shortcodes/Campaigns |
| 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.0.0 |
| 10 | 10 | * @version 1.6.45 |
| 11 | 11 | */ |
| @@ -27,8 +27,9 @@ | ||
| 27 | 27 | /** |
| 28 | 28 | * Display the shortcode output. This is the callback method for the campaigns shortcode. |
| 29 | 29 | * |
| 30 | 30 | * @since 1.0.0 |
| 31 | + * @version 1.8.2 added 'description_limit' to the shortcode_atts and view_args filter. | |
| 31 | 32 | * |
| 32 | 33 | * @param array $atts The user-defined shortcode attributes. |
| 33 | 34 | * @return string |
| 34 | 35 | */ |
| @@ -33,24 +34,39 @@ | ||
| 33 | 34 | * @return string |
| 34 | 35 | */ |
| 35 | 36 | public static function display( $atts ) { |
| 36 | 37 | $default = array( |
| 37 | - 'id' => '', | |
| 38 | - 'orderby' => 'post_date', | |
| 39 | - 'order' => '', | |
| 40 | - 'number' => get_option( 'posts_per_page' ), | |
| 41 | - 'category' => '', | |
| 42 | - 'tag' => '', | |
| 43 | - 'creator' => '', | |
| 44 | - 'exclude' => '', | |
| 45 | - 'include_inactive' => false, | |
| 46 | - 'columns' => 2, | |
| 47 | - 'button' => 'donate', | |
| 48 | - 'responsive' => 1, | |
| 49 | - 'masonry' => 0, | |
| 38 | + 'id' => '', | |
| 39 | + 'parent_campaigns' => '', // only show child campaigns of the IDs provided. | |
| 40 | + 'orderby' => 'post_date', | |
| 41 | + 'order' => '', | |
| 42 | + 'number' => get_option( 'posts_per_page' ), | |
| 43 | + 'category' => '', | |
| 44 | + 'tag' => '', | |
| 45 | + 'creator' => '', | |
| 46 | + 'exclude' => '', | |
| 47 | + 'include_inactive' => false, | |
| 48 | + 'columns' => 2, | |
| 49 | + 'button' => 'donate', | |
| 50 | + 'responsive' => 1, | |
| 51 | + 'masonry' => 0, | |
| 52 | + 'description_limit' => 100, | |
| 53 | + 'shortcode' => 'campaigns', | |
| 50 | 54 | ); |
| 51 | 55 | |
| 52 | - $args = shortcode_atts( $default, $atts, 'campaigns' ); | |
| 56 | + $args = shortcode_atts( $default, $atts, 'campaigns' ); | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Modify the arguments passed to the campaigns shortcode. | |
| 60 | + * | |
| 61 | + * As an example, Ambassadors extension can add 'fundraiser_type' to the shortcode_atts which is used to filter campaigns by fundraiser type. | |
| 62 | + * | |
| 63 | + * @since 1.8.3 | |
| 64 | + * | |
| 65 | + * @param array $args The arguments passed to the shortcode. | |
| 66 | + */ | |
| 67 | + $args = apply_filters( 'charitable_campaigns_shortcode_atts', $args ); | |
| 68 | + | |
| 53 | 69 | $args['campaigns'] = self::get_campaigns( $args ); |
| 54 | 70 | |
| 55 | 71 | /** |
| 56 | 72 | * Replace the default template with your own. |
| @@ -80,9 +96,9 @@ | ||
| 80 | 96 | * |
| 81 | 97 | * @param array $view_args The arguments to pass. |
| 82 | 98 | * @param array $args All the parsed arguments. |
| 83 | 99 | */ |
| 84 | - $view_args = apply_filters( 'charitable_campaigns_shortcode_view_args', charitable_array_subset( $args, array( 'campaigns', 'columns', 'button', 'responsive', 'masonry' ) ), $args ); | |
| 100 | + $view_args = apply_filters( 'charitable_campaigns_shortcode_view_args', charitable_array_subset( $args, array( 'campaigns', 'columns', 'button', 'responsive', 'masonry', 'description_limit', 'shortcode' ) ), $args ); | |
| 85 | 101 | |
| 86 | 102 | $template->set_view_args( $view_args ); |
| 87 | 103 | |
| 88 | 104 | ob_start(); |
| @@ -104,8 +120,9 @@ | ||
| 104 | 120 | /** |
| 105 | 121 | * Return campaigns to display in the campaigns shortcode. |
| 106 | 122 | * |
| 107 | 123 | * @since 1.0.0 |
| 124 | + * @since 1.8.4.7 | |
| 108 | 125 | * |
| 109 | 126 | * @param array $args The query arguments to be used to retrieve campaigns. |
| 110 | 127 | * @return WP_Query |
| 111 | 128 | */ |
| @@ -118,8 +135,15 @@ | ||
| 118 | 135 | if ( ! empty( $args['id'] ) ) { |
| 119 | 136 | $query_args['post__in'] = explode( ',', $args['id'] ); |
| 120 | 137 | } |
| 121 | 138 | |
| 139 | + /* Only show child campaigns of the IDs provided, added in 1.8.4.7 */ | |
| 140 | + if ( ! empty( $args['parent_campaigns'] ) ) { | |
| 141 | + $query_args['post_parent__in'] = explode( ',', $args['parent_campaigns'] ); | |
| 142 | + } | |
| 143 | + | |
| 144 | + /* Parent IDs */ | |
| 145 | + | |
| 122 | 146 | /* Pagination */ |
| 123 | 147 | if ( ! empty( $args['paged'] ) ) { |
| 124 | 148 | $query_args['paged'] = $args['paged']; |
| 125 | 149 | } |
| @@ -125,9 +149,9 @@ | ||
| 125 | 149 | } |
| 126 | 150 | |
| 127 | 151 | /* Set category constraint */ |
| 128 | 152 | if ( ! empty( $args['category'] ) ) { |
| 129 | - $query_args['tax_query'] = array( | |
| 153 | + $query_args['tax_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query | |
| 130 | 154 | array( |
| 131 | 155 | 'taxonomy' => 'campaign_category', |
| 132 | 156 | 'field' => 'slug', |
| 133 | 157 | 'terms' => explode( ',', $args['category'] ), |
| @@ -137,9 +161,9 @@ | ||
| 137 | 161 | |
| 138 | 162 | /* Set tag constraint */ |
| 139 | 163 | if ( ! empty( $args['tag'] ) ) { |
| 140 | 164 | if ( ! array_key_exists( 'tax_query', $query_args ) ) { |
| 141 | - $query_args['tax_query'] = array(); | |
| 165 | + $query_args['tax_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query | |
| 142 | 166 | } |
| 143 | 167 | |
| 144 | 168 | $query_args['tax_query'][] = array( |
| 145 | 169 | 'taxonomy' => 'campaign_tag', |
| @@ -154,13 +178,13 @@ | ||
| 154 | 178 | } |
| 155 | 179 | |
| 156 | 180 | /* Only include active campaigns if flag is set */ |
| 157 | 181 | if ( ! $args['include_inactive'] ) { |
| 158 | - $query_args['meta_query'] = array( | |
| 182 | + $query_args['meta_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | |
| 159 | 183 | 'relation' => 'OR', |
| 160 | 184 | array( |
| 161 | 185 | 'key' => '_campaign_end_date', |
| 162 | - 'value' => date( 'Y-m-d H:i:s' ), | |
| 186 | + 'value' => date( 'Y-m-d H:i:s' ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 163 | 187 | 'compare' => '>=', |
| 164 | 188 | 'type' => 'datetime', |
| 165 | 189 | ), |
| 166 | 190 | array( |