Making WordPress.org

Changeset 719


Ignore:
Timestamp:
06/20/2014 12:15:13 AM (11 years ago)
Author:
iandunn
Message:

Multi-Event Sponsors: Add helpers for retrieving sponsor names and excerpts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/multi-event-sponsors.php

    r718 r719  
    207207        return $addresses;
    208208    }
     209
     210    /**
     211     * Retrieve the names of the given sponsors in a sentence format.
     212     *
     213     * @param array $sponsors
     214     * @return string
     215     */
     216    public function get_sponsor_names( $sponsors ) {
     217        $names = wp_list_pluck( $sponsors, 'post_title' );
     218        $count = count( $names );
     219
     220        if ( 0 === $count ) {
     221            $names = '';
     222        } else if ( 1 === $count ) {
     223            $names = $names[0];
     224        } else {
     225            $names = implode( ', ', array_slice( $names, 0, $count - 1 ) ) . ' and ' . $names[ $count - 1 ];
     226        }
     227
     228        return $names;
     229    }
     230
     231
     232    /**
     233     * Get the excerpts for the given sponsors in HTML paragraphs.
     234     *
     235     * @param array $sponsors
     236     * @return string
     237     */
     238    public function get_sponsor_excerpts( $sponsors ) {
     239        $excerpts = wp_list_pluck( $sponsors, 'post_excerpt' );
     240
     241        foreach ( $excerpts as & $excerpt ) {
     242            $excerpt = '<p>' . $excerpt . '</p>';
     243        }
     244
     245        return implode( ' ', $excerpts );
     246    }
    209247} // end Multi_Event_Sponsors
Note: See TracChangeset for help on using the changeset viewer.