Changeset 6846
- Timestamp:
- 03/08/2018 08:48:30 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php
r6832 r6846 18 18 add_action( 'transition_post_status', __NAMESPACE__ . '\ticket_sales_opened', 10, 3 ); 19 19 add_action( 'camptix_payment_result', __NAMESPACE__ . '\track_payment_results', 10, 3 ); 20 add_filter( 'camptix_shortcode_contents', __NAMESPACE__ . '\modify_shortcode_contents', 10, 2 ); 20 21 21 22 // Attendees … … 618 619 * Get a string for HTML email footers listing global sponsors. 619 620 * 621 * @param array $sponsor_args Args for filtering which sponsors to include. 622 * 620 623 * @return string 621 624 */ 622 function get_global_sponsors_string( ) {625 function get_global_sponsors_string( $sponsor_args = array() ) { 623 626 $sponsor_message_html = ''; 624 $sponsors = get_global_sponsors( );627 $sponsors = get_global_sponsors( $sponsor_args ); 625 628 $sponsor_count = count( $sponsors ); 626 629 627 630 if ( $sponsor_count > 0 ) { 628 631 $sponsors = wp_list_pluck( $sponsors, 'name' ); 632 633 $sponsors = array_map( function( $string ) { 634 return "<strong>$string</strong>"; 635 }, $sponsors ); 629 636 630 637 shuffle( $sponsors ); … … 656 663 } 657 664 658 $sponsor_message_html = sprintf( 659 /* translators: The first %s placeholder is a list of sponsor names. The second %s placeholder is a URL. */ 660 __( 'WordPress Global Community Sponsors help fund WordCamps and meetups around the world. Thank you to %s for <a href="%s">their support</a>!', 'wordcamporg' ), 665 $intro = __( 'WordPress Global Community Sponsors help fund WordCamps and meetups around the world.', 'wordcamporg' ); 666 667 $thank_you = sprintf( 668 /* translators: %1$s: list of sponsor names; %2$s: URL; */ 669 _n( 670 'Thank you to %1$s for <a href="%2$s">its support</a>!', 671 'Thank you to %1$s for <a href="%2$s">their support</a>!', 672 $sponsor_count, 673 'wordcamporg' 674 ), 661 675 $sponsors_string, 662 676 'https://central.wordcamp.org/global-community-sponsors/' 663 677 ); 678 679 if ( isset( $sponsor_args['region_id'], $sponsor_args['level_id'] ) ) { 680 $sponsor_level = get_sponsorship_level_name_from_id( $sponsor_args['level_id'] ); 681 $sponsor_region = get_sponsorship_region_description_from_id( $sponsor_args['region_id'] ); 682 683 if ( $sponsor_level && $sponsor_region ) { 684 $thank_you = sprintf( 685 /* translators: %1$s: sponsorship type; %2$s: list of sponsor names; %3$s: URL; %4$s: sponsorship region; */ 686 _n( 687 'Thank you to our %1$s sponsor %2$s for <a href="%3$s">its support</a> in %4$s!', 688 'Thank you to our %1$s sponsors %2$s for <a href="%3$s">their support</a> in %4$s!', 689 $sponsor_count, 690 'wordcamporg' 691 ), 692 $sponsor_level, 693 $sponsors_string, 694 'https://central.wordcamp.org/global-community-sponsors/', 695 $sponsor_region 696 ); 697 } 698 } 699 700 $sponsor_message_html = sprintf( '%s %s', $intro, $thank_you ); 664 701 } 665 702 … … 674 711 function get_donation_string() { 675 712 return sprintf( 713 /* translators: %s is a placeholder for a URL. */ 676 714 __( 'Do you love WordPress events? To support open source education and charity hackathons, please <a href="%s">donate to the WordPress Foundation</a>.', 'wordcamporg' ), 677 715 'https://wordpressfoundation.org/donate/' … … 682 720 * Get an array of Global Sponsor names and URLs. 683 721 * 722 * @param array $args Args for filtering which sponsors to include. 723 * 684 724 * @return array 685 725 */ 686 function get_global_sponsors() { 726 function get_global_sponsors( $args = array() ) { 727 $args = wp_parse_args( $args, array( 728 'region_id' => '', 729 'level_id' => '', 730 ) ); 731 687 732 $sponsors = array(); 688 733 … … 696 741 697 742 foreach ( $sponsor_posts as $sponsor_post ) { 743 $sponsorships = $sponsor_post->mes_regional_sponsorships; 744 745 if ( $args['region_id'] ) { 746 if ( ! isset( $sponsorships[ $args['region_id'] ] ) || empty( $sponsorships[ $args['region_id'] ] ) ) { 747 continue; 748 } 749 750 $sponsorships = array_intersect_key( $sponsorships, array( $args['region_id'] => '' ) ); 751 } 752 753 if ( $args['level_id'] ) { 754 $levels = array_map( 'absint', $sponsorships ); 755 756 if ( ! in_array( $args['level_id'], $levels, true ) ) { 757 continue; 758 } 759 } 760 698 761 $sponsors[] = array( 699 762 'name' => $sponsor_post->post_title, … … 705 768 706 769 return $sponsors; 770 } 771 772 /** 773 * Get a sponsorship region description. 774 * 775 * The two sponsorship regions currently in use are hard-coded so they can be translated. If a different region is 776 * specified, this function will attempt to retrieve a description string from the database (which won't be translated). 777 * 778 * @param int $region_id 779 * 780 * @return string 781 */ 782 function get_sponsorship_region_description_from_id( $region_id ) { 783 $region_id = absint( $region_id ); 784 $region_description = ''; 785 786 if ( $region_id ) { 787 // Make the two standard options translatable. 788 switch( $region_id ) { 789 case 558366 : // Eastern 790 $region_description = __( 'Europe, Africa, and Asia Pacific', 'wordcamporg' ); 791 break; 792 case 558365 : // Western 793 $region_description = __( 'North, Central, and South America', 'wordcamporg' ); 794 break; 795 } 796 797 if ( ! $region_description ) { 798 switch_to_blog( BLOG_ID_CURRENT_SITE ); 799 800 $region = get_term( $region_id, 'mes-regions' ); 801 802 if ( $region instanceof \WP_Term ) { 803 $region_description = $region->description; 804 } 805 806 restore_current_blog(); 807 } 808 } 809 810 return $region_description; 811 } 812 813 /** 814 * Get the name of a sponsorship level. 815 * 816 * @param int $level_id 817 * 818 * @return string 819 */ 820 function get_sponsorship_level_name_from_id( $level_id ) { 821 $level_id = absint( $level_id ); 822 $level_name = ''; 823 824 if ( $level_id ) { 825 switch_to_blog( BLOG_ID_CURRENT_SITE ); 826 827 $level_name = get_the_title( $level_id ); 828 829 restore_current_blog(); 830 } 831 832 return $level_name; 707 833 } 708 834 … … 758 884 return $message; 759 885 } 886 887 /** 888 * Modify the output of the `[camptix]` shortcode when certain conditions are met. 889 * 890 * @param string $shortcode_contents 891 * @param string $tix_action 892 * 893 * @return string 894 */ 895 function modify_shortcode_contents( $shortcode_contents, $tix_action ) { 896 switch ( $tix_action ) { 897 case 'access_tickets' : // Screen after purchase is complete. 898 $content_end = '</div><!-- #tix -->'; 899 900 $current_wordcamp = get_wordcamp_post(); 901 $region_id = isset( $current_wordcamp->meta['Multi-Event Sponsor Region'][0] ) ? $current_wordcamp->meta['Multi-Event Sponsor Region'][0] : ''; 902 903 $sponsors_string = get_global_sponsors_string( array( 904 'region_id' => $region_id, 905 'level_id' => 3040794, // Gold 906 ) ); 907 $donation_string = get_donation_string(); 908 909 if ( false !== strpos( $shortcode_contents, $content_end ) ) { 910 $shortcode_contents = str_replace( 911 $content_end, 912 wpautop( "$sponsors_string\n\n$donation_string" ) . $content_end, 913 $shortcode_contents 914 ); 915 } 916 break; 917 } 918 919 return $shortcode_contents; 920 }
Note: See TracChangeset
for help on using the changeset viewer.