Make WordPress Core

Ticket #43820: 43820.2.diff

File 43820.2.diff, 8.9 KB (added by audrasjb, 7 years ago)

Add "Mine" filter to both media library table view & grid view

  • src/wp-admin/includes/ajax-actions.php

    diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php
    index 4f30007..9e1b8c5 100644
    a b function wp_ajax_query_attachments() { 
    26272627                'paged',
    26282628                'post_mime_type',
    26292629                'post_parent',
     2630                'author',
    26302631                'post__in',
    26312632                'post__not_in',
    26322633                'year',
  • src/wp-admin/includes/class-wp-media-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php
    index 4b29ba6..f022cd3 100644
    a b class WP_Media_List_Table extends WP_List_Table { 
    130130                                _x( 'Trash', 'attachment filter' )
    131131                        );
    132132                }
     133
     134                $type_links['mine'] = sprintf(
     135                        '<option value="mine"%s>%s</option>',
     136                        selected( 'mine' === $filter, true, false ),
     137                        __( 'Mine' )
     138                );
     139
    133140                return $type_links;
    134141        }
    135142
  • src/wp-includes/js/media-models.js

    diff --git a/src/wp-includes/js/media-models.js b/src/wp-includes/js/media-models.js
    index 28caa15..bd194fc 100644
    a b Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ 
    11211121                // Only observe when a limited number of query args are set. There
    11221122                // are no filters for other properties, so observing will result in
    11231123                // false positives in those queries.
    1124                 allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ];
     1124                allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
    11251125                if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {
    11261126                        this.observe( wp.Uploader.queue );
    11271127                }
    Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ 
    12381238         * @readonly
    12391239         */
    12401240        propmap: {
    1241                 'search':    's',
    1242                 'type':      'post_mime_type',
    1243                 'perPage':   'posts_per_page',
    1244                 'menuOrder': 'menu_order',
    1245                 'uploadedTo': 'post_parent',
    1246                 'status':     'post_status',
    1247                 'include':    'post__in',
    1248                 'exclude':    'post__not_in'
     1241                'search':               's',
     1242                'type':                 'post_mime_type',
     1243                'perPage':              'posts_per_page',
     1244                'menuOrder':    'menu_order',
     1245                'uploadedTo':   'post_parent',
     1246                'status':               'post_status',
     1247                'include':              'post__in',
     1248                'exclude':              'post__not_in',
     1249                'author':               'author'
    12491250        },
    12501251        /**
    12511252         * Creates and returns an Attachments Query collection given the properties.
    Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ 
    12671268         * @param {Object} [props.menu_order]
    12681269         * @param {Object} [props.post_parent]
    12691270         * @param {Object} [props.post_status]
     1271         * @param {Object} [props.author]
    12701272         * @param {Object} [options]
    12711273         *
    12721274         * @returns {wp.media.model.Query} A new Attachments Query collection.
  • src/wp-includes/js/media-views.js

    diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js
    index 53f02cd..539fdc5 100644
    a b Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attac 
    72617261                        all: {
    72627262                                text:  text || l10n.allMediaItems,
    72637263                                props: {
    7264                                         uploadedTo: null,
    7265                                         orderby: 'date',
    7266                                         order:   'DESC'
     7264                                        uploadedTo:     null,
     7265                                        orderby:        'date',
     7266                                        order:          'DESC',
     7267                                        author:         null
    72677268                                },
    72687269                                priority: 10
    72697270                        },
    Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attac 
    72727273                                text:  l10n.uploadedToThisPost,
    72737274                                props: {
    72747275                                        uploadedTo: wp.media.view.settings.post.id,
    7275                                         orderby: 'menuOrder',
    7276                                         order:   'ASC'
     7276                                        orderby:        'menuOrder',
     7277                                        order:          'ASC',
     7278                                        author:         null
    72777279                                },
    72787280                                priority: 20
    72797281                        },
    Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attac 
    72827284                                text:  l10n.unattached,
    72837285                                props: {
    72847286                                        uploadedTo: 0,
    7285                                         orderby: 'menuOrder',
    7286                                         order:   'ASC'
     7287                                        orderby:        'menuOrder',
     7288                                        order:          'ASC',
     7289                                        author:         null
     7290                                },
     7291                                priority: 50
     7292                        },
     7293
     7294                        mine: {
     7295                                text:  l10n.mine,
     7296                                props: {
     7297                                        orderby:        'date',
     7298                                        order:          'DESC',
     7299                                        author:         parseInt( userSettings.uid )
    72877300                                },
    72887301                                priority: 50
    72897302                        }
    All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment 
    73207333                        filters[ key ] = {
    73217334                                text: text,
    73227335                                props: {
    7323                                         status:  null,
    7324                                         type:    key,
    7325                                         uploadedTo: null,
    7326                                         orderby: 'date',
    7327                                         order:   'DESC'
     7336                                        status:         null,
     7337                                        type:           key,
     7338                                        uploadedTo:     null,
     7339                                        orderby:        'date',
     7340                                        order:          'DESC',
     7341                                        author:         null
    73287342                                }
    73297343                        };
    73307344                });
    All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment 
    73327346                filters.all = {
    73337347                        text:  l10n.allMediaItems,
    73347348                        props: {
    7335                                 status:  null,
    7336                                 type:    null,
    7337                                 uploadedTo: null,
    7338                                 orderby: 'date',
    7339                                 order:   'DESC'
     7349                                status:         null,
     7350                                type:           null,
     7351                                uploadedTo:     null,
     7352                                orderby:        'date',
     7353                                order:          'DESC',
     7354                                author:         null
    73407355                        },
    73417356                        priority: 10
    73427357                };
    All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment 
    73457360                        filters.uploaded = {
    73467361                                text:  l10n.uploadedToThisPost,
    73477362                                props: {
    7348                                         status:  null,
    7349                                         type:    null,
    7350                                         uploadedTo: wp.media.view.settings.post.id,
    7351                                         orderby: 'menuOrder',
    7352                                         order:   'ASC'
     7363                                        status:         null,
     7364                                        type:           null,
     7365                                        uploadedTo:     wp.media.view.settings.post.id,
     7366                                        orderby:        'menuOrder',
     7367                                        order:          'ASC',
     7368                                        author:         null
    73537369                                },
    73547370                                priority: 20
    73557371                        };
    All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment 
    73587374                filters.unattached = {
    73597375                        text:  l10n.unattached,
    73607376                        props: {
    7361                                 status:     null,
    7362                                 uploadedTo: 0,
    7363                                 type:       null,
    7364                                 orderby:    'menuOrder',
    7365                                 order:      'ASC'
     7377                                status:         null,
     7378                                uploadedTo:     0,
     7379                                type:           null,
     7380                                orderby:        'menuOrder',
     7381                                order:          'ASC',
     7382                                author:         null
     7383                        },
     7384                        priority: 50
     7385                };
     7386
     7387                filters.mine = {
     7388                        text:  l10n.mine,
     7389                        props: {
     7390                                status:         null,
     7391                                type:           null,
     7392                                uploadedTo:     null,
     7393                                orderby:        'date',
     7394                                order:          'DESC',
     7395                                author:         parseInt( userSettings.uid )
    73667396                        },
    73677397                        priority: 50
    73687398                };
    All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment 
    73737403                        filters.trash = {
    73747404                                text:  l10n.trash,
    73757405                                props: {
    7376                                         uploadedTo: null,
    7377                                         status:     'trash',
    7378                                         type:       null,
    7379                                         orderby:    'date',
    7380                                         order:      'DESC'
     7406                                        uploadedTo:     null,
     7407                                        status:         'trash',
     7408                                        type:           null,
     7409                                        orderby:        'date',
     7410                                        order:          'DESC',
     7411                                        author:         null
    73817412                                },
    73827413                                priority: 50
    73837414                        };
  • src/wp-includes/js/media/models/query.js

    diff --git a/src/wp-includes/js/media/models/query.js b/src/wp-includes/js/media/models/query.js
    index 420e4bb..9debf2c 100644
    a b Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ 
    7171                // Only observe when a limited number of query args are set. There
    7272                // are no filters for other properties, so observing will result in
    7373                // false positives in those queries.
    74                 allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ];
     74                allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
    7575                if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {
    7676                        this.observe( wp.Uploader.queue );
    7777                }
    Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ 
    195195                'uploadedTo': 'post_parent',
    196196                'status':     'post_status',
    197197                'include':    'post__in',
    198                 'exclude':    'post__not_in'
     198                'exclude':    'post__not_in',
     199                'author':     'author'
    199200        },
    200201        /**
    201202         * Creates and returns an Attachments Query collection given the properties.
    Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ 
    217218         * @param {Object} [props.menu_order]
    218219         * @param {Object} [props.post_parent]
    219220         * @param {Object} [props.post_status]
     221         * @param {Object} [props.author]
    220222         * @param {Object} [options]
    221223         *
    222224         * @returns {wp.media.model.Query} A new Attachments Query collection.
  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index a52048f..38e861e 100644
    a b function wp_enqueue_media( $args = array() ) { 
    36573657                'noItemsFound'                => __( 'No items found.' ),
    36583658                'insertIntoPost'              => $post_type_object->labels->insert_into_item,
    36593659                'unattached'                  => __( 'Unattached' ),
     3660                'mine'                        => __( 'Mine' ),
    36603661                'trash'                       => _x( 'Trash', 'noun' ),
    36613662                'uploadedToThisPost'          => $post_type_object->labels->uploaded_to_this_item,
    36623663                'warnDelete'                  => __( "You are about to permanently delete this item from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ),