Changeset 4316
- Timestamp:
- 11/01/2016 08:58:43 PM (8 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator/bootstrap.php
r3015 r4316 15 15 const REQUIRED_CAPABILITY = 'manage_options'; 16 16 17 require_once( __DIR__ . '/includes/common.php' ); 18 require_once( __DIR__ . '/includes/html-badges.php' ); 19 17 20 if ( is_admin() ) { 18 require_once( __DIR__ . '/includes/common.php' );19 21 require_once( __DIR__ . '/includes/indesign-badges.php' ); 20 22 } 21 22 require_once( __DIR__ . '/includes/html-badges.php' ); -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator/includes/common.php
r3015 r4316 6 6 defined( 'WPINC' ) or die(); 7 7 8 add_filter( 'camptix_menu_tools_tabs', __NAMESPACE__ . '\add_badges_tab' ); 9 add_action( 'camptix_menu_tools_badges', __NAMESPACE__ . '\render_badges_page' ); 10 add_action( 'admin_print_styles', __NAMESPACE__ . '\print_admin_styles' ); 8 if ( is_admin() ) { 9 add_filter( 'camptix_menu_tools_tabs', __NAMESPACE__ . '\add_badges_tab' ); 10 add_action( 'camptix_menu_tools_badges', __NAMESPACE__ . '\render_badges_page' ); 11 add_action( 'admin_print_styles', __NAMESPACE__ . '\print_admin_styles' ); 12 } 13 14 add_filter( 'get_post_metadata', __NAMESPACE__ . '\add_dynamic_post_meta', 10, 3 ); 11 15 12 16 /** … … 58 62 <?php 59 63 } 64 65 /** 66 * Get the attendees 67 * 68 * @return array 69 */ 70 function get_attendees() { 71 $attendees = get_posts( array( 72 'post_type' => 'tix_attendee', 73 'posts_per_page' => 12000, 74 'orderby' => 'title', 75 ) ); 76 77 return $attendees; 78 } 79 80 /** 81 * Add dynamically-generated "post meta" to `\WP_Post` objects 82 * 83 * This makes it possible to access dynamic data related to a post object by simply referencing `$post->foo`. 84 * That keeps the calling code much cleaner than if it were to have to do something like 85 * `$foo = some_custom_logic( get_post_meta( $post->ID, 'bar', true ) ); echo esc_html( $foo )`. 86 * 87 * @param mixed $value 88 * @param int $post_id 89 * @param string $meta_key 90 * 91 * @return mixed 92 * `null` to instruct `get_metadata()` to pull the value from the database 93 * Any non-null value will be returned as if it were pulled from the database 94 */ 95 function add_dynamic_post_meta( $value, $post_id, $meta_key ) { 96 /** @global \CampTix_Plugin $camptix */ 97 global $camptix; 98 99 $attendee = get_post( $post_id ); 100 101 if ( 'tix_attendee' != $attendee->post_type ) { 102 return $value; 103 } 104 105 switch ( $meta_key ) { 106 case 'avatar_url': 107 $value = get_avatar_url( $attendee->tix_email, array( 'size' => 600 ) ); 108 break; 109 110 case 'coupon': 111 if ( $attendee->tix_coupon_id ) { 112 $coupon = get_post( $attendee->tix_coupon_id ); 113 $value = $coupon->post_name; 114 } 115 break; 116 117 case 'css_classes': 118 $value = get_css_classes( $attendee ); 119 break; 120 121 case 'formatted_name': 122 $value = $camptix->format_name_string( 123 '<span class="first-name">%first%</span> 124 <span class="last-name">%last%</span>', 125 $attendee->tix_first_name, 126 $attendee->tix_last_name 127 ); 128 break; 129 130 case 'ticket': 131 $ticket = get_post( $attendee->tix_ticket_id ); 132 $value = $ticket->post_name; 133 break; 134 } 135 136 return $value; 137 } 138 139 /** 140 * Get the CSS classes for an attendee element 141 * 142 * @param \WP_Post $attendee 143 * 144 * @return string 145 */ 146 function get_css_classes( $attendee ) { 147 $classes = array( 148 'attendee-' . $attendee->post_name, 149 'ticket-' . $attendee->ticket 150 ); 151 152 if ( $attendee->coupon ) { 153 $classes[] = 'coupon-' . $attendee->coupon; 154 } 155 156 return implode( ' ', $classes ); 157 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator/includes/html-badges.php
r4315 r4316 12 12 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_previewer_scripts', 999 ); // after remove_all_previewer_styles() 13 13 add_filter( 'template_include', __NAMESPACE__ . '\use_badges_template' ); 14 add_filter( 'get_post_metadata', __NAMESPACE__ . '\add_dynamic_post_meta', 10, 3 );15 14 16 15 /** … … 215 214 ); 216 215 217 $attendees = get_posts( array( 218 'post_type' => 'tix_attendee', 219 'posts_per_page' => -1, 220 'orderby' => 'title', 221 ) ); 216 $attendees = Badge_Generator\get_attendees(); 222 217 223 218 require( dirname( __DIR__ ) . '/views/html-badges/template-badges.php' ); 224 }225 226 /**227 * Add dynamically-generated "post meta" to `\WP_Post` objects228 *229 * This makes it possible to access dynamic data related to a post object by simply referencing `$post->foo`.230 * That keeps the calling code much cleaner than if it were to have to do something like231 * `$foo = some_custom_logic( get_post_meta( $post->ID, 'bar', true ) ); echo esc_html( $foo )`.232 *233 * @param mixed $value234 * @param int $post_id235 * @param string $meta_key236 *237 * @return mixed238 * `null` to instruct `get_metadata()` to pull the value from the database239 * Any non-null value will be returned as if it were pulled from the database240 */241 function add_dynamic_post_meta( $value, $post_id, $meta_key ) {242 /** @global \CampTix_Plugin $camptix */243 global $camptix;244 245 $attendee = get_post( $post_id );246 247 if ( 'tix_attendee' != $attendee->post_type ) {248 return $value;249 }250 251 switch ( $meta_key ) {252 case 'avatar_url':253 $value = get_avatar_url( $attendee->tix_email, array( 'size' => 600 ) );254 break;255 256 case 'css_classes':257 $value = get_css_classes( $attendee );258 break;259 260 case 'formatted_name':261 $value = $camptix->format_name_string(262 '<span class="first-name">%first%</span>263 <span class="last-name">%last%</span>',264 $attendee->tix_first_name,265 $attendee->tix_last_name266 );267 break;268 }269 270 return $value;271 }272 273 /**274 * Get the CSS classes for an attendee element275 *276 * @param \WP_Post $attendee277 *278 * @return string279 */280 function get_css_classes( $attendee ) {281 // Name282 $classes = array( 'attendee-' . $attendee->post_name );283 284 // Ticket285 $ticket = get_post( $attendee->tix_ticket_id );286 $classes[] = 'ticket-' . $ticket->post_name;287 288 // Coupon289 if ( $attendee->tix_coupon_id ) {290 $coupon = get_post( $attendee->tix_coupon_id );291 $classes[] = 'coupon-' . $coupon->post_name;292 }293 294 return implode( ' ', $classes );295 219 } 296 220 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator/views/html-badges/template-badges.php
r4315 r4316 3 3 namespace CampTix\Badge_Generator\HTML; 4 4 defined( 'WPINC' ) or die(); 5 6 /** 7 * @global string $template 8 * @var array $attendees 9 * @var \WP_Post $attendee 10 */ 5 11 6 12 /* -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator/views/indesign-badges/page-indesign-badges.php
r3015 r4316 3 3 namespace CampTix\Badge_Generator\InDesign; 4 4 defined( 'WPINC' ) or die(); 5 6 /** 7 * @var string $html_customizer_url 8 */ 5 9 6 10 ?>
Note: See TracChangeset
for help on using the changeset viewer.