Making WordPress.org

Changeset 1372


Ignore:
Timestamp:
03/04/2015 12:57:21 AM (11 years ago)
Author:
iandunn
Message:

WordCamp Post Types: Give preference to current page when deciding anchors.

This supports a new use case where the admin sets up a multiple pages that each contain [schedule], [speakers], and [sessions]. A camp might want to have page for each day that contained all of the information about what's going on that day, but not what's scheduled for other days.

In that situation, the anchor links in the schedule should point to the current page, rather than searching for the first page that contains the shortcodes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    r1371 r1372  
    734734     * Returns an anchor permalink for a Speaker or Session
    735735     *
    736      * If the speakers page is rendered with the [speakers] shortcode, it will
    737      * contain IDs that can be used as anchors. This function will attempt to find
    738      * a speakers page and link to the appropriate anchor.
    739      *
    740      * @param $post_id int The speaker/session's post ID.
     736     * Any page with the [speakers | sessions] shortcode will contain IDs that can be used as anchors.
     737     *
     738     * If the current page contains the corresponding shortcode, we'll assume the user wants to link there.
     739     * Otherwise, we'll attempt to find another page that contains the shortcode.
     740     *
     741     * @param $target_id int The speaker/session's post ID.
    741742     *
    742743     * @return string
    743744     */
    744     function get_wcpt_anchor_permalink( $post_id ) {
    745         $post = get_post( $post_id );
    746 
    747         if ( 'publish' != $post->post_status ) {
     745    function get_wcpt_anchor_permalink( $target_id ) {
     746        global $post;
     747        $anchor_target = get_post( $target_id );
     748
     749        if ( 'publish' != $anchor_target->post_status ) {
    748750            return '';
    749751        }
    750752
    751         switch( $post->post_type ) {
     753        switch( $anchor_target->post_type ) {
    752754            case 'wcb_speaker':
    753                 $permalink = $this->get_wcpt_permalink( 'speakers' );
    754                 $anchor_id = $post->post_name;
     755                $permalink = has_shortcode( $post->post_content, 'speakers' ) ? get_permalink( $post->id ) : $this->get_wcpt_permalink( 'speakers' );
     756                $anchor_id = $anchor_target->post_name;
    755757                break;
    756758
    757759            case 'wcb_session':
    758                 $permalink = $this->get_wcpt_permalink( 'sessions' );
    759                 $anchor_id = $post->ID;
     760                $permalink = has_shortcode( $post->post_content, 'sessions' ) ? get_permalink( $post->id ) : $this->get_wcpt_permalink( 'sessions' );
     761                $anchor_id = $anchor_target->ID;
    760762                break;
    761763
     
    772774            '%s#wcorg-%s-%s',
    773775            $permalink,
    774             str_replace( 'wcb_', '', $post->post_type ),
     776            str_replace( 'wcb_', '', $anchor_target->post_type ),
    775777            sanitize_html_class( $anchor_id )
    776778        );
     
    852854
    853855        if ( ! in_array( $attr['speaker_link'], array( 'anchor', 'wporg', 'permalink', 'none' ) ) )
    854             $attr['speaker_link'] = 'anchor';
     856            $attr['speaker_link'] = 'anchor';   // todo this is inconsistent with the values passed to shortcode_atts, and probably not needed if the default above is changed to 'anchor'
    855857
    856858        $attr['orderby'] = ( in_array( $attr['orderby'], array( 'date', 'title', 'rand' ) ) ) ? $attr['orderby'] : 'date';
Note: See TracChangeset for help on using the changeset viewer.