Making WordPress.org


Ignore:
Timestamp:
01/20/2016 09:49:51 PM (9 years ago)
Author:
iandunn
Message:

WordCamp Budgets: Centralize file uploads for all modules.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/payment-request.php

    r2331 r2342  
    387387     */
    388388    protected function render_files_input( $post, $label, $name, $description = '' ) {
    389         $files = get_posts( array(
    390             'post_parent'    => $post->ID,
    391             'post_type'      => 'attachment',
    392             'posts_per_page' => -1,
    393             'orderby'        => 'title',
    394             'order'          => 'ASC',
    395         ) );
    396 
    397         foreach ( $files as &$file ) {
    398             $file->filename = wp_basename( $file->guid );
    399             $file->url      = wp_get_attachment_url( $file->ID );
    400         }
     389        $files = WordCamp_Budgets::get_attached_files( $post );
     390
     391        wp_localize_script( 'wcb-attached-files', 'wcbAttachedFiles', $files ); // todo merge into wordcampBudgets var
    401392
    402393        require( dirname( __DIR__ ) . '/views/payment-request/input-files.php' );
     
    765756
    766757        // Attach existing files
    767         $this->attach_existing_files( $post_id, $_POST );
    768     }
    769 
     758        remove_action( 'save_post', array( $this, 'save_payment' ), 10 ); // avoid infinite recursion
     759        WordCamp_Budgets::attach_existing_files( $post_id, $_POST );
     760        add_action( 'save_post', array( $this, 'save_payment' ), 10, 2 );
     761    }
     762
     763    /**
     764     * Add log entries when the post status changes
     765     *
     766     * @param string  $new
     767     * @param string  $old
     768     * @param WP_Post $post
     769     */
    770770    public function transition_post_status( $new, $old, $post ) {
    771771        if ( $post->post_type != self::POST_TYPE )
     
    803803
    804804    /**
    805      * Attach unattached files to the payment request post
    806      *
    807      * Sometimes users will upload the files manually to the Media Library, instead of using the Add Files button,
    808      * and we need to attach them to the request so that they show up in the metabox.
    809      *
    810      * @param int   $post_id
    811      * @param array $request
    812      */
    813     protected function attach_existing_files( $post_id, $request ) {
    814         if ( empty( $request['wcp_existing_files_to_attach'] ) ) {
    815             return;
    816         }
    817 
    818         if ( ! $files = json_decode( $request['wcp_existing_files_to_attach'] ) ) {
    819             return;
    820         }
    821 
    822         remove_action( 'save_post', array( $this, 'save_payment' ), 10 ); // avoid infinite recursion
    823 
    824         foreach( $files as $file_id ) {
    825             wp_update_post( array(
    826                 'ID'          => $file_id,
    827                 'post_parent' => $post_id,
    828             ) );
    829         }
    830 
    831         add_action( 'save_post', array( $this, 'save_payment' ), 10, 2 );
    832     }
    833 
    834     /**
    835805     * Define columns for the Payment Requests screen.
    836806     *
Note: See TracChangeset for help on using the changeset viewer.