2019-10-25 23:34:46 +03:00
< ? php
/**
* Display pledge data in the archive & single view .
*/
namespace WordPressdotorg\Five_for_the_Future\Theme ;
2019-10-31 23:23:57 +02:00
use WordPressDotOrg\FiveForTheFuture\ { Contributor , PledgeMeta };
2019-10-25 23:34:46 +03:00
2019-10-31 23:23:57 +02:00
$pledge = get_post ();
2021-05-04 18:49:04 +03:00
$data = array ();
2019-10-25 23:34:46 +03:00
foreach ( PledgeMeta\get_pledge_meta_config () as $key => $config ) {
$data [ $key ] = get_post_meta ( get_the_ID (), PledgeMeta\META_PREFIX . $key , $config [ 'single' ] );
}
2021-04-30 22:55:55 +03:00
$contributors = Contributor\get_contributor_user_objects (
Contributor\get_pledge_contributors ( get_the_ID () )
);
2019-10-25 23:34:46 +03:00
2019-10-31 14:30:26 +02:00
$allowed_html = array_merge (
wp_kses_allowed_html ( 'data' ),
array (
'span' => array (
2019-11-23 20:24:37 +02:00
'class' => true ,
),
2019-10-31 14:30:26 +02:00
)
);
2019-11-23 20:24:37 +02:00
$more_text = sprintf (
__ ( '… <a href="%1$s">continue reading <span class="screen-reader-text">%2$s</span></a>' , 'wporg-5ftf' ),
2019-10-31 14:30:26 +02:00
esc_url ( get_permalink () ),
esc_html ( get_the_title () )
);
2019-10-25 23:34:46 +03:00
$content = apply_filters ( 'the_content' , $data [ 'org-description' ] );
2021-05-04 18:49:04 +03:00
$content = strip_tags ( $content ); // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags -- `we're the <strong>best</strong>` should keep "best" but remove the formatting.
2019-11-23 20:24:37 +02:00
$content = wp_trim_words ( $content , 55 , $more_text );
2019-10-25 23:34:46 +03:00
2019-10-31 23:23:57 +02:00
$total_hours = $pledge -> { PledgeMeta\META_PREFIX . 'pledge-total-hours' };
2019-10-25 23:34:46 +03:00
$contributor_title = sprintf (
esc_html (
2019-11-23 20:24:37 +02:00
_n ( '%1$s has pledged %2$d hour a week' , '%1$s has pledged %2$d hours a week' , $total_hours , 'wporg-5ftf' )
2019-10-25 23:34:46 +03:00
),
wp_kses_post ( get_the_title () ),
2019-10-31 23:23:57 +02:00
intval ( $total_hours )
2019-10-25 23:34:46 +03:00
);
?>
< article id = " post-<?php the_ID(); ?> " < ? php post_class (); ?> >
< div class = " entry-image " >
< ? php if ( has_post_thumbnail () ) : ?>
< div class = " entry-image__logo " >
2021-05-11 23:41:56 +03:00
< ? php the_post_thumbnail (); ?>
2019-10-25 23:34:46 +03:00
</ div >
< ? php else : ?>
< div class = " entry-image__placeholder " ></ div >
< ? php endif ; ?>
2019-10-28 19:38:49 +02:00
</ div ><!-- . entry - image -->
2019-10-25 23:34:46 +03:00
< header class = " entry-header " >
< ? php if ( is_singular () ) : ?>
< ? php the_title ( '<h1 class="entry-title">' , '</h1>' ); ?>
< ? php else : ?>
< ? php the_title ( '<h2 class="entry-title"><a href="' . esc_url ( get_permalink () ) . '" rel="bookmark">' , '</a></h2>' ); ?>
< ? php endif ; ?>
</ header ><!-- . entry - header -->
< div class = " entry-content " >
2019-11-01 03:33:16 +02:00
< p >
< ? php echo wp_kses ( $content , $allowed_html ); ?>
</ p >
2019-10-31 14:30:26 +02:00
2021-04-30 22:55:55 +03:00
< ? php /* phpcs:ignore -- escaped above */ ?>
< h3 >< ? php echo $contributor_title ?> </h3>
2019-10-25 23:34:46 +03:00
2021-04-30 22:55:55 +03:00
< ul class = " pledge-contributors " >
2019-10-25 23:34:46 +03:00
< ? php
2021-04-30 22:55:55 +03:00
foreach ( $contributors as $contrib_user ) {
printf (
'<li class="pledge-contributor__avatar">%s</li>' ,
get_avatar ( $contrib_user -> user_email , 40 , 'mystery' , $contrib_user -> display_name )
);
2019-10-25 23:34:46 +03:00
}
?>
2021-04-30 22:55:55 +03:00
</ ul ><!-- . pledge - contributors -->
2019-10-25 23:34:46 +03:00
</ div ><!-- . entry - content -->
</ article ><!-- #post-## -->