Changeset 1371
- Timestamp:
- 03/03/2015 11:51:49 PM (11 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types
- Files:
-
- 2 edited
-
inc/widgets.php (modified) (3 diffs)
-
wc-post-types.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/inc/widgets.php
r758 r1371 149 149 echo $widget_content; 150 150 151 $speakers_permalink = $wcpt_plugin->get_ speakers_permalink();151 $speakers_permalink = $wcpt_plugin->get_wcpt_permalink( 'speakers' ); 152 152 if ( ! empty( $speakers_permalink ) ) 153 153 printf( '<a class="wcpt-speakers-link" href="%s">%s</a>', esc_url( $speakers_permalink ), esc_html( __( 'View all speakers →', 'wordcamporg' ) ) ); … … 255 255 echo $widget_content; 256 256 257 $sessions_permalink = $wcpt_plugin->get_ sessions_permalink();257 $sessions_permalink = $wcpt_plugin->get_wcpt_permalink( 'sessions' ); 258 258 if ( ! empty( $sessions_permalink ) ) 259 259 printf( '<a class="wcpt-sessions-link" href="%s">%s</a>', esc_url( $sessions_permalink ), esc_html( __( 'View all sessions →', 'wordcamporg' ) ) ); … … 356 356 echo $widget_content; 357 357 358 $organizers_permalink = $wcpt_plugin->get_ organizers_permalink();358 $organizers_permalink = $wcpt_plugin->get_wcpt_permalink( 'organizers' ); 359 359 if ( ! empty( $organizers_permalink ) ) 360 360 printf( '<a class="wcpt-organizers-link" href="%s">%s</a>', esc_url( $organizers_permalink ), esc_html( __( 'Organizing team →', 'wordcamporg' ) ) ); -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php
r1340 r1371 8 8 9 9 class WordCamp_Post_Types_Plugin { 10 protected $wcpt_permalinks; 10 11 11 12 /** … … 13 14 */ 14 15 function __construct() { 16 $this->wcpt_permalinks = array(); 17 15 18 add_action( 'init', array( $this, 'register_post_types' ) ); 16 19 add_action( 'init', array( $this, 'register_taxonomies' ) ); … … 748 751 switch( $post->post_type ) { 749 752 case 'wcb_speaker': 750 $permalink = $this->get_ speakers_permalink();753 $permalink = $this->get_wcpt_permalink( 'speakers' ); 751 754 $anchor_id = $post->post_name; 752 755 break; 753 756 754 757 case 'wcb_session': 755 $permalink = $this->get_ sessions_permalink();758 $permalink = $this->get_wcpt_permalink( 'sessions' ); 756 759 $anchor_id = $post->ID; 757 760 break; … … 775 778 776 779 /** 777 * Returns the speakers page permalink778 * 779 * Fetches for a post or page with the [speakers ] shortcode and780 * Returns the page permalink for speakers, sessions or organizers 781 * 782 * Fetches for a post or page with the [speakers | sessions | organizers] shortcode and 780 783 * returns the permalink of whichever comes first. 781 */ 782 function get_speakers_permalink() { 783 // todo combine this, get_sessions_permalink, and get_organizers_permalink into a DRY function 784 785 if ( isset( $this->speakers_permalink ) ) 786 return $this->speakers_permalink; 787 788 $this->speakers_permalink = false; 789 790 $speakers_post = get_posts( array( 791 'post_type' => array( 'post', 'page' ), 792 'post_status' => 'publish', 793 's' => '[speakers', 784 * 785 * @param string $type 786 * 787 * @return false | string 788 */ 789 function get_wcpt_permalink( $type ) { 790 if ( ! in_array( $type, array( 'speakers', 'sessions', 'organizers' ) ) ) { 791 return false; 792 } 793 794 /* 795 * The [schedule] shortcode can call this for each session and speaker, so cache the result to avoid 796 * dozens of SQL queries. 797 */ 798 if ( isset( $this->wcpt_permalinks[ $type ] ) ) { 799 return $this->wcpt_permalinks[ $type ]; 800 } 801 802 $this->wcpt_permalinks[ $type ] = false; 803 804 $wcpt_post = get_posts( array( 805 'post_type' => array( 'post', 'page' ), 806 'post_status' => 'publish', 807 's' => '[' . $type, 794 808 'posts_per_page' => 1, 795 809 ) ); 796 810 797 if ( ! empty( $speakers_post ) ) 798 $this->speakers_permalink = get_permalink( $speakers_post[0] ); 799 800 return $this->speakers_permalink; 801 } 802 803 /** 804 * Returns the sessions page permalink 805 */ 806 function get_sessions_permalink() { 807 if ( isset( $this->sessions_permalink ) ) 808 return $this->sessions_permalink; 809 810 $this->sessions_permalink = false; 811 812 $sessions_post = get_posts( array( 813 'post_type' => array( 'post', 'page' ), 814 'post_status' => 'publish', 815 's' => '[sessions', 816 'posts_per_page' => 1, 817 ) ); 818 819 if ( ! empty( $sessions_post ) ) 820 $this->sessions_permalink = get_permalink( $sessions_post[0] ); 821 822 return $this->sessions_permalink; 823 } 824 825 /** 826 * Returns the organizers page permalink 827 */ 828 function get_organizers_permalink() { 829 if ( isset( $this->organizers_permalink ) ) 830 return $this->organizers_permalink; 831 832 $this->organizers_permalink = false; 833 834 $organizers_post = get_posts( array( 835 'post_type' => array( 'post', 'page' ), 836 'post_status' => 'publish', 837 's' => '[organizers', 838 'posts_per_page' => 1, 839 ) ); 840 841 if ( ! empty( $organizers_post ) ) 842 $this->organizers_permalink = get_permalink( $organizers_post[0] ); 843 844 return $this->organizers_permalink; 811 if ( ! empty( $wcpt_post ) ) { 812 $this->wcpt_permalinks[ $type ] = get_permalink( $wcpt_post[0] ); 813 } 814 815 return $this->wcpt_permalinks[ $type ]; 845 816 } 846 817
Note: See TracChangeset
for help on using the changeset viewer.