| @@ -3,17 +3,50 @@ | ||
| 3 | 3 | * Displays the campaign description. |
| 4 | 4 | * |
| 5 | 5 | * Override this template by copying it to yourtheme/charitable/campaign/description.php |
| 6 | 6 | * |
| 7 | - * @author Studio 164a | |
| 7 | + * @author WP Charitable LLC | |
| 8 | + * @package Charitable/Templates/Campaign Page | |
| 8 | 9 | * @since 1.0.0 |
| 10 | + * @version 1.8.1.14 | |
| 11 | + * @version 1.8.3 | |
| 12 | + * @version 1.8.8.6 | |
| 13 | + * @version 1.8.12.1 Add charitable_campaign_description_limit filter. | |
| 9 | 14 | */ |
| 10 | 15 | |
| 11 | 16 | // Exit if accessed directly. |
| 12 | -if ( ! defined( 'ABSPATH' ) ) { exit; } | |
| 17 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 18 | + exit; | |
| 19 | +} | |
| 13 | 20 | |
| 14 | -$campaign = $view_args['campaign']; | |
| 21 | +// Prior the description output as $view_args['campaign']->description but since 1.7.0.4 as visual editor can add html. | |
| 22 | +$charitable_campaign = isset( $view_args['campaign'] ) ? $view_args['campaign'] : false; | |
| 23 | +$charitable_description = isset( $view_args['description'] ) ? $view_args['description'] : false; | |
| 24 | +$charitable_description_limit = isset( $view_args['view_args']['description_limit'] ) ? $view_args['view_args']['description_limit'] : 100; | |
| 15 | 25 | |
| 26 | +/** | |
| 27 | + * Filter the number of words the campaign description is trimmed to on the campaign page. | |
| 28 | + * | |
| 29 | + * @since 1.8.12.1 | |
| 30 | + * | |
| 31 | + * @param int $charitable_description_limit Number of words to keep. | |
| 32 | + * @param Charitable_Campaign|false $charitable_campaign The campaign object (may be false). | |
| 33 | + * @param array $view_args The template view arguments. | |
| 34 | + */ | |
| 35 | +$charitable_description_limit = (int) apply_filters( 'charitable_campaign_description_limit', $charitable_description_limit, $charitable_campaign, $view_args ); | |
| 36 | + | |
| 37 | +if ( $charitable_description === false ) { | |
| 38 | + $charitable_description = isset( $view_args['campaign'] ) && ! empty( $view_args['campaign']->description ) ? $view_args['campaign']->description : $charitable_description; | |
| 39 | + // If there still is no description, try to get it from the meta data (legacy). | |
| 40 | + if ( ( false === $charitable_description || '' === $charitable_description ) && false !== $charitable_campaign && is_object( $charitable_campaign ) && is_a( $charitable_campaign, 'Charitable_Campaign' ) ) { | |
| 41 | + $charitable_description = get_post_meta( $charitable_campaign->get_campaign_id(), '_campaign_description', true ); | |
| 42 | + if ( ( false === $charitable_description || '' === $charitable_description ) && isset( $charitable_campaign->post->post_content ) && ! empty( $charitable_campaign->post->post_content ) ) { | |
| 43 | + $charitable_description = $charitable_campaign->post->post_content; | |
| 44 | + } | |
| 45 | + } | |
| 46 | + $charitable_description = $charitable_description_limit > 0 ? wp_trim_words( $charitable_description, $charitable_description_limit, '...' ) : ''; | |
| 47 | +} | |
| 48 | + | |
| 16 | 49 | ?> |
| 17 | -<div class="campaign-description"> | |
| 18 | - <?php echo $campaign->description ?> | |
| 50 | +<div class="campaign-description"> | |
| 51 | + <?php echo apply_filters( 'charitable_campaign_description_template_content', $charitable_description, $charitable_campaign ); // phpcs:ignore ?> | |
| 19 | 52 | </div> |