Making WordPress.org

Changeset 2962


Ignore:
Timestamp:
04/15/2016 01:50:06 PM (11 years ago)
Author:
kovshenin
Message:

WordCamp.org: Create a new site a bit later.

The wcpt_metabox_save action is a bit misleading because
it runs multiple times, so the multi-sponsor region is saved
after the WordCamp URL is saved, causing our "create site"
functionality to fail the first time.

This commit creates a new wcpt_metabox_save_done action which
is called when all metabox fields are saved. Moves the site
creation process to that new action.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt
Files:
3 edited

Legend:

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

    r2898 r2962  
    5959        function metabox () {
    6060                do_action( 'wcpt_metabox' );
    61         }
    62 
    63         /**
    64          * metabox_save ()
    65          *
    66          * Pass the metabox values before saving
    67          *
    68          * @param int $post_id
    69          * @return int
    70          */
    71         function metabox_save ( $post_id ) {
    72                 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    73                         return $post_id;
    74 
    75                 if ( !current_user_can( 'edit_post', $post_id ) )
    76                         return $post_id;
    77 
    78                 do_action( 'wcpt_metabox_save' );
    7961        }
    8062
    … …  
    189171}
    190172endif; // class_exists check
    191 
    192 ?>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php

    r2912 r2962  
    206206                        }
    207207                }
     208
     209                do_action( 'wcpt_metabox_save_done', $post_id );
    208210
    209211                $this->validate_and_add_note( $post_id );
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-new-site.php

    r2898 r2962  
    1212                add_action( 'wcpt_metabox_value', array( $this, 'render_site_url_field' ), 10, 3 );
    1313                add_action( 'wcpt_metabox_save',  array( $this, 'save_site_url_field' ), 10, 3 );
     14                add_action( 'wcpt_metabox_save_done', array( $this, 'maybe_create_new_site' ), 10, 1 );
    1415        }
    1516
    … …  
    7273
    7374                if ( 'URL' == $key && 'wc-url' == $field_type && isset( $_POST[ $field_name ] ) ) {
    74                         // todo use https instead of http
    7575                        $url = strtolower( substr( $_POST[ $field_name ], 0, 4 ) ) == 'http' ? $_POST[ $field_name ] : 'http://' . $_POST[ $field_name ];
    7676                        $url = set_url_scheme( esc_url_raw( $url ), 'https' );
    7777                        update_post_meta( $wordcamp_id, $key, esc_url( $url ) );
    78 
    79                         if ( isset( $_POST[ wcpt_key_to_str( 'create-site-in-network', 'wcpt_' ) ] ) && ! empty( $url ) ) {
    80                                 $this->create_new_site( $wordcamp_id, $url );
    81                         }
    82                 }
    83         }
    84 
    85 
    86         /**
    87          * Create a new site in the network
     78                }
     79        }
     80
     81
     82        /**
     83         * Maybe create a new site in the network
    8884         *
    8985         * @param int    $wordcamp_id
    90          * @param string $url
    91          */
    92         protected function create_new_site( $wordcamp_id, $url ) {
     86         */
     87        protected function maybe_create_new_site( $wordcamp_id ) {
    9388                if ( ! current_user_can( 'manage_sites' ) ) {
    9489                        return;
    … …  
    9792                // The sponsor region is required so we can import the relevant sponsors and levels
    9893                if ( ! get_post_meta( $wordcamp_id, 'Multi-Event Sponsor Region', true ) ) {
     94                        return;
     95                }
     96
     97                $url = get_post_meta( $wordcamp_id, 'URL', true );
     98                if ( ! isset( $_POST[ wcpt_key_to_str( 'create-site-in-network', 'wcpt_' ) ] ) || empty( $url ) ) {
    9999                        return;
    100100                }
    … …  
    372372                                'content' =>
    373373                                        '<p>' . __( "<em>Organizers note:</em> Upload photos to this page and they'll automagically appear in a slideshow!", 'wordcamporg' ) . '</p> ' .
    374                                     '<p>[slideshow]</p>',
     374                                        '<p>[slideshow]</p>',
    375375                                'status'  => 'draft',
    376376                                'type'    => 'page',
    … …  
    459459                        array(
    460460                                'title'   => __( 'Call for Sponsors', 'wordcamporg' ),
    461                                 'content' => 
     461                                'content' =>
    462462                                        '<p>' . __( '<em>Organizers note:</em> Make sure you update the "to" address and other fields before publishing this page!', 'wordcamporg' ) . '</p> ' .
    463463                                        '<p>' . __( 'Blurb with information for potential sponsors.', 'wordcamporg' ) . '</p> ' .
    … …  
    489489                        array(
    490490                                'title'   => __( 'Call for Speakers', 'wordcamporg' ),
    491                                 'content' => 
     491                                'content' =>
    492492                                        '<p>' . __( '<em>Organizers note:</em> Submissions to this form will automatically create draft posts for the Speaker and Session post types. Feel free to customize the form, but deleting or renaming the following fields will break the automation: Name, Email, WordPress.org Username, Your Bio, Session Title, Session Description.', 'wordcamporg' ) . '</p>' .
    493493                                        '<p>' . __( "If you'd like to propose multiple topics, please submit the form multiple times, once for each topic. [Other speaker instructions/info goes here.]", 'wordcamporg' ) . '</p>' .
    … …  
    524524                        array(
    525525                                'title'   => __( 'Call for Volunteers', 'wordcamporg' ),
    526                                 'content' => 
     526                                'content' =>
    527527                                        '<p>' . __( '<em>Organizers note:</em> Make sure you update the "to" address and other fields before publishing this page!', 'wordcamporg' ) . '</p> ' .
    528528                                        '<p>' . __( 'Blurb with information for potential volunteers.', 'wordcamporg' ) . '</p> ' .
Note: See TracChangeset for help on using the changeset viewer.