Making WordPress.org


Ignore:
Timestamp:
01/20/2016 09:49:51 PM (11 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/wordcamp-budgets.php

    r2331 r2342  
    275275
    276276        /**
     277         * Get the files attached to a post
     278         *
     279         * @param WP_Post $post
     280         *
     281         * @return array
     282         */
     283        public static function get_attached_files( $post ) {
     284                $files = get_posts( array(
     285                        'post_parent'    => $post->ID,
     286                        'post_type'      => 'attachment',
     287                        'posts_per_page' => 100,
     288                        'orderby'        => 'title',
     289                        'order'          => 'ASC',
     290                ) );
     291
     292                foreach ( $files as &$file ) {
     293                        $file->filename = wp_basename( $file->guid );
     294                        $file->url      = wp_get_attachment_url( $file->ID );
     295                }
     296
     297                return $files;
     298        }
     299
     300        /**
     301         * Attach unattached files to the payment request post
     302         *
     303         * Sometimes users will upload the files manually to the Media Library, instead of using the Add Files button,
     304         * and we need to attach them to the request so that they show up in the metabox.
     305         *
     306         * NOTE: The calling function must remove any of its save_post callbacks before calling this, in order to
     307         * avoid infinite recursion
     308         *
     309         * @param int   $post_id
     310         * @param array $request
     311         */
     312        public static function attach_existing_files( $post_id, $request ) {
     313                if ( empty( $request['wcb_existing_files_to_attach'] ) ) {
     314                        return;
     315                }
     316
     317                if ( ! $files = json_decode( $request['wcb_existing_files_to_attach'] ) ) {
     318                        return;
     319                }
     320
     321                foreach( $files as $file_id ) {
     322                        wp_update_post( array(
     323                                'ID'          => $file_id,
     324                                'post_parent' => $post_id,
     325                        ) );
     326                }
     327        }
     328
     329        /**
    277330         * Insert an entry into a log for one of the custom post types
    278331         *
Note: See TracChangeset for help on using the changeset viewer.