Making WordPress.org


Ignore:
Timestamp:
07/09/2015 10:54:33 PM (10 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Insert live Multi-Event Sponsor data into new sites.

Previously it was hard-coded, because at the time we didn't have the Multi Event Sponsor post types on Central. Now that we do, we can pull live data to avoid it becoming out of date.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-new-site.php

    r1683 r1717  
    7272
    7373        if ( 'URL' == $key && 'wc-url' == $field_type && isset( $_POST[ $field_name ] ) ) {
     74            // todo use https instead of http
    7475            $url = strtolower( substr( $_POST[ $field_name ], 0, 4 ) ) == 'http' ? $_POST[ $field_name ] : 'http://' . $_POST[ $field_name ];
    7576            $url = set_url_scheme( esc_url_raw( $url ), 'https' );
     
    9192    protected function create_new_site( $wordcamp_id, $url ) {
    9293        if ( ! current_user_can( 'manage_sites' ) ) {
     94            return;
     95        }
     96
     97        // The sponsor region is required so we can import the relevant sponsors and levels
     98        if ( ! get_post_meta( $wordcamp_id, 'Multi-Event Sponsor Region', true ) ) {
    9399            return;
    94100        }
     
    208214     * Create stubs for commonly-used posts
    209215     *
    210      * @todo Create sponsorship levels based on new mes-sponsor-level taxonomy instead of hardcoding
    211      *
    212216     * @param WP_Post $wordcamp
    213217     * @param array   $meta
     
    215219     */
    216220    protected function create_post_stubs( $wordcamp, $meta, $lead_organizer ) {
     221        $assigned_sponsor_data = $this->get_assigned_sponsor_data( $wordcamp->ID );
     222        $this->create_sponsorship_levels( $assigned_sponsor_data['assigned_sponsors'] );
     223
    217224        // Get stub content
    218225        $stubs = array_merge(
    219226            $this->get_stub_posts( $wordcamp, $meta ),
    220227            $this->get_stub_pages( $wordcamp, $meta ),
    221             $this->get_stub_me_sponsors( $wordcamp, $meta ),
    222             $this->get_stub_me_sponsor_thank_yous( $wordcamp, $meta )
     228            $this->get_stub_me_sponsors( $assigned_sponsor_data ),
     229            $this->get_stub_me_sponsor_thank_yous( $assigned_sponsor_data )
    223230        );
    224 
    225         // Create sponsorship levels -- @todo pull these from Central instead of hardcoding
    226         $sponsor_level_ids['champion']   = wp_create_term( 'WordCamp Champion',   'wcb_sponsor_level' );
    227         $sponsor_level_ids['accomplice'] = wp_create_term( 'WordCamp Accomplice', 'wcb_sponsor_level' );
    228         $sponsor_level_ids['pillar']     = wp_create_term( 'WordCamp Pillar',     'wcb_sponsor_level' );
    229231
    230232        // Create actual posts from stubs
     
    266268
    267269                // Assign sponsorship level
    268                 if ( isset( $page['term'] ) ) {
    269                     wp_set_post_terms( $page_id, $sponsor_level_ids[ $page['term'] ], 'wcb_sponsor_level', true );
     270                if ( 'wcb_sponsor' == $page['type'] && isset( $page['term'] ) ) {
     271                    wp_set_object_terms( $page_id, $page['term'], 'wcb_sponsor_level', true );
    270272                }
    271273            }
     
    551553
    552554    /**
     555     * Create the sponsorship levels for the assigned Multi-Event Sponsors
     556     *
     557     * @param array $assigned_sponsors
     558     */
     559    protected function create_sponsorship_levels( $assigned_sponsors ) {
     560        foreach( $assigned_sponsors as $sponsorship_level_id ) {
     561            foreach ( $sponsorship_level_id as $sponsor ) {
     562                wp_create_term(
     563                    $sponsor->sponsorship_level->post_title,
     564                    'wcb_sponsor_level'
     565                );
     566            }
     567        }
     568    }
     569
     570    /**
    553571     * Get the content for sponsor stubs
    554572     *
    555573     * These are just the multi-event sponsors. Each camp will also have local sponsors, but they'll add those manually.
    556574     *
    557      * @todo - load these from the new Multi_Event_Sponsors post type instead of hardcoding.
    558      *
    559      * @param WP_Post $wordcamp
    560      * @param array   $meta
     575     * @param array   $assigned_sponsor_data
    561576     *
    562577     * @return array
    563578     */
    564     protected function get_stub_me_sponsors( $wordcamp, $meta ) {
    565         $me_sponsors = array(
    566             array(
    567                 'title'          => 'Code Poet',
    568                 'content'        => "<p>If you use WordPress to build things for other people, Code Poet wants to make your life easier. No matter whether you freelance on a solo basis, lead a small web shop, make plugins in a dark closet, or crack the whip at a large design firm, Code Poet’s aim is to become your go-to source of information and resources to help you expand your WordPress skills and know-how. To make you better at what you do. To make it easier to make your living and look great doing it.</p> <p>You’re part of a tribe of WordPress designers and developers over 10,000 strong, spanning the entire globe. <a href='http://codepoet.com'>codepoet.com</a> aims to bring the working knowledge and real world strategies of those people into one place, for you to tap into.</p>",
    569                 'status'         => 'publish',
    570                 'type'           => 'wcb_sponsor',
    571                 'featured_image' => 'http://central.wordcamp.org/files/2013/09/Code-Poet-2.png',
    572                 'term'           => 'champion'
    573             ),
    574 
    575             array(
    576                 'title'          => 'WPML',
    577                 'content'        => "<p>WPML turns WordPress websites multilingual. It works with caching, SEO and E-Commerce plugins, and allows the building of complete multilingual sites. WPML powers simple blogs as well as corporate and enterprise sites.</p> <p>WPML allows users to translate everything in the site, including content, menus, widgets and even theme and plugin texts. WPML powers over 400,000 commercial websites from all over the world.</p> <p>More information about going multilingual can be found at <a href='http://wpml.org'>WPML.org</a></p>",
    578                 'status'         => 'publish',
    579                 'type'           => 'wcb_sponsor',
    580                 'featured_image' => 'http://central.wordcamp.org/files/2013/09/wpml-web.png',
    581                 'term'           => 'accomplice'
    582             ),
    583 
    584             array(
    585                 'title'          => 'Bluehost',
    586                 'content'        => "<p><a href='http://bluehost.com'>Bluehost</a> has been a WordPress partner since 2005 and powers over one million WordPress sites. Their goal is to provide outstanding hosting services and customer support for the best possible price. Bluehost is also constantly innovating and upgrading their services and infrastructure at no additional cost to their customers. Join the millions of other website owners that have already chosen Bluehost and see how they can help you with your site.</p>",
    587                 'status'         => 'publish',
    588                 'type'           => 'wcb_sponsor',
    589                 'featured_image' => 'http://central.wordcamp.org/files/2013/09/bluehost-logo13.png',
    590                 'term'           => 'pillar'
    591             ),
    592 
    593             array(
    594                 'title'          => 'DreamHost',
    595                 'content'        => "<p>DreamHost is a global Web hosting and cloud services provider with over 350,000 customers and 1.2 million blogs, websites and apps hosted. The company offers a wide spectrum of Web hosting and cloud services including Shared Hosting, Virtual Private Servers (VPS), Dedicated Server Hosting, Domain Name Registration, the cloud storage service, DreamObjects, and the cloud computing service DreamCompute. More information can be found at <a href='http://dreamhost.com'>http://dreamhost.com</a>.</p>",
    596                 'status'         => 'publish',
    597                 'type'           => 'wcb_sponsor',
    598                 'featured_image' => 'http://central.wordcamp.org/files/2013/09/dreamhost_logo-cmyk-no_tag-2012.jpg',
    599                 'term'           => 'accomplice'
    600             ),
    601 
    602             array(
    603                 'title'          => 'Media Temple',
    604                 'content'        => "<p>From its inception in 1998, (mt) Media Temple has been on a mission to help people and businesses succeed online.</p> <p>Over 125,000 customers in 100 countries now rely on Media Temple’s tools for domain registration, web hosting, business applications, virtual servers, and other cloud services to power more than 1.5 million websites. With 200 dedicated, U.S.-based employees, Media Temple takes pride in our 24/7 customer support. Our customers range from everyday people to top bloggers, creative professionals, and small businesses, as well as large enterprises like Starbucks, Adidas, Samsung, and Toyota.</p> <p>More information can be found anytime on the web at <a href='http://mediatemple.com'>http://mediatemple.com</a> or on Twitter <a href='https://twitter.com/mediatemple'>@MediaTemple</a>.</p>",
    605                 'status'         => 'publish',
    606                 'type'           => 'wcb_sponsor',
    607                 'featured_image' => 'http://central.wordcamp.org/files/2013/12/mt-250x140-dk.png',
    608                 'term'           => 'pillar'
    609             ),
    610         );
     579    protected function get_stub_me_sponsors( $assigned_sponsor_data ) {
     580        $me_sponsors = array();
     581
     582        foreach ( $assigned_sponsor_data['assigned_sponsors'] as $sponsorship_level_id => $assigned_sponsors ) {
     583            foreach ( $assigned_sponsors as $assigned_sponsor ) {
     584                $me_sponsors[] = array(
     585                    'title'          => $assigned_sponsor->post_title,
     586                    'content'        => $assigned_sponsor->post_content,
     587                    'status'         => 'publish',
     588                    'type'           => 'wcb_sponsor',
     589                    'term'           => $assigned_sponsor->sponsorship_level->post_name,
     590                    'featured_image' => isset( $assigned_sponsor_data['featured_images'][ $assigned_sponsor->ID ] ) ? $assigned_sponsor_data['featured_images'][ $assigned_sponsor->ID ] : '',
     591                );
     592            }
     593        }
    611594
    612595        return $me_sponsors;
     
    627610        switch_to_blog( BLOG_ID_CURRENT_SITE ); // central.wordcamp.org
    628611
     612        $data['featured_images']    = array();
    629613        $data['assigned_sponsors']  = $multi_event_sponsors->get_wordcamp_me_sponsors( $wordcamp_id, 'sponsor_level' );
    630614        $data['sponsorship_levels'] = get_posts( array(
     
    632616            'numberposts' => -1
    633617        ) );
     618        // todo remove sponsorship levels item and refactor thank you stubs to use new posts in data['assigned_sponsors'][sponsor][sponsorship_level]
     619
     620        foreach( $data['assigned_sponsors'] as $sponsorship_level_id => $sponsors ) {
     621            foreach( $sponsors as $sponsor ) {
     622                if ( ! $attachment_id = get_post_thumbnail_id( $sponsor->ID ) ) {
     623                    continue;
     624                }
     625
     626                if ( ! $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ) ) {
     627                    continue;
     628                }
     629
     630                $data['featured_images'][ $sponsor->ID ] = $attachment[0];
     631            }
     632        }
    634633
    635634        restore_current_blog();
     
    644643     * post excerpts contain the blurb for each sponsor.
    645644     *
    646      * @param WP_Post $wordcamp
    647      * @param array   $meta
     645     * @param array   $assigned_sponsor_data
    648646     *
    649647     * @return array
    650648     */
    651     protected function get_stub_me_sponsor_thank_yous( $wordcamp, $meta ) {
     649    protected function get_stub_me_sponsor_thank_yous( $assigned_sponsor_data ) {
    652650        /** @var $multi_event_sponsors Multi_Event_Sponsors */
    653651        global $multi_event_sponsors;
    654652        $pages = array();
    655 
    656         $assigned_sponsor_data = $this->get_assigned_sponsor_data( $wordcamp->ID );
    657653
    658654        foreach ( $assigned_sponsor_data['sponsorship_levels'] as $sponsorship_level ) {
Note: See TracChangeset for help on using the changeset viewer.