Making WordPress.org

Changeset 235


Ignore:
Timestamp:
01/08/2014 07:16:11 PM (13 years ago)
Author:
iandunn
Message:

Post Types: Add 'link' option to sponsors shortcode.

This lets organizers enter a sponsor's website address and have the output of the sponsor shortcode contain a link to it.

File:
1 edited

Legend:

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

    r172 r235  
    2626                add_action( 'save_post', array( $this, 'save_post_session' ), 10, 2 );
    2727                add_action( 'save_post', array( $this, 'save_post_organizer' ), 10, 2);
     28                add_action( 'save_post', array( $this, 'save_post_sponsor' ), 10, 2);
    2829
    2930                add_filter( 'manage_wcb_speaker_posts_columns', array( $this, 'manage_post_types_columns' ) );
    … …  
    869870
    870871                $attr = shortcode_atts( array(
    871 
     872                        'link' => 'none'
    872873                ), $attr );
    873874
    … …  
    896897
    897898                                <?php while ( $sponsors->have_posts() ) : $sponsors->the_post(); ?>
     899                                <?php $website = get_post_meta( get_the_ID(), '_wcpt_sponsor_website', true ); ?>
     900                                       
    898901                                <div id="wcorg-sponsor-<?php the_ID(); ?>" class="wcorg-sponsor">
    899                                         <h3><?php the_title(); ?></h3>
     902                                        <?php if ( 'website' == $attr['link'] && $website ) : ?>
     903                                                <h3><a href="<?php echo esc_attr( esc_url( $website ) ); ?>"><?php the_title(); ?></a></h3>
     904                                        <?php else : ?>
     905                                                <h3><?php the_title(); ?></h3>
     906                                        <?php endif; ?>
     907                                       
    900908                                        <div class="wcorg-sponsor-description">
    901                                                 <?php the_post_thumbnail(); ?>
     909                                                <?php if ( 'website' == $attr['link'] && $website ) : ?>
     910                                                        <a href="<?php echo esc_attr( esc_url( $website ) ); ?>"><?php the_post_thumbnail(); ?></a>
     911                                                <?php else : ?>
     912                                                        <?php the_post_thumbnail(); ?>
     913                                                <?php endif; ?>
     914                                               
    902915                                                <?php the_content(); ?>
    903916                                        </div>
    … …  
    925938                add_meta_box( 'speakers-list', __( 'Speakers', $this->textdomain ), array( $this, 'metabox_speakers_list' ), 'wcb_session', 'side' );
    926939                add_meta_box( 'session-info', __( 'Session Info', $this->textdomain ), array( $this, 'metabox_session_info' ), 'wcb_session', 'side' );
     940                add_meta_box( 'sponsor-info', __( 'Sponsor Info', 'wordcampbase' ), array( $this, 'metabox_sponsor_info' ), 'wcb_sponsor', 'side' );
    927941        }
    928942
    … …  
    10651079
    10661080        /**
     1081         * Render the Sponsor Info metabox view
     1082         */
     1083        function metabox_sponsor_info( $sponsor ) {
     1084                $website = get_post_meta( $sponsor->ID, '_wcpt_sponsor_website', true );
     1085                wp_nonce_field( 'edit-sponsor-info', 'wcpt-meta-sponsor-info' );
     1086               
     1087                ?>
     1088               
     1089                <p>
     1090                        <label for="_wcpt_sponsor_websitee"><?php _e( 'Website:', 'wordcampbase' ); ?></label>
     1091                        <input type="text" class="widefat" id="_wcpt_sponsor_website" name="_wcpt_sponsor_website" value="<?php echo esc_attr( esc_url( $website ) ); ?>" />
     1092                </p>
     1093               
     1094                <?php
     1095        }
     1096
     1097        /**
    10671098         * Fired when a post is saved, makes sure additional metadata is also updated.
    10681099         */
    … …  
    11941225
    11951226        /**
     1227         * Save meta data for Sponsor posts
     1228         */
     1229        function save_post_sponsor( $post_id, $post ) {
     1230                if ( wp_is_post_revision( $post_id ) || $post->post_type != 'wcb_sponsor' || ! current_user_can( 'edit_post', $post_id ) ) {
     1231                        return;
     1232                }
     1233
     1234                if ( isset( $_POST['wcpt-meta-sponsor-info'] ) && wp_verify_nonce( $_POST['wcpt-meta-sponsor-info'], 'edit-sponsor-info' ) ) {
     1235                        $website = esc_url_raw( $_POST['_wcpt_sponsor_website'] );
     1236                       
     1237                        // TODO: maybe only allows links to home page, depending on outcome of http://make.wordpress.org/community/2013/12/31/irs-rules-for-corporate-sponsorship-of-wordcamp/
     1238
     1239                        if ( $website ) {
     1240                                update_post_meta( $post_id, '_wcpt_sponsor_website', $website );
     1241                        } else {
     1242                                delete_post_meta( $post_id, '_wcpt_sponsor_website' );
     1243                        }
     1244                }
     1245        }
     1246
     1247        /**
    11961248         * Registers the custom post types, runs during init.
    11971249         */
Note: See TracChangeset for help on using the changeset viewer.