Making WordPress.org

Changeset 7226


Ignore:
Timestamp:
05/24/2018 07:40:14 PM (6 years ago)
Author:
coreymckrill
Message:

WordCamp: Fix data export for wcb_organizer

In the case where there was no valid user account associated with the
given email address, the query for the Organizer post type was being
run with no meta query attached, so all Organizer posts were returned.
This fixes it so the query doesn't happen at all when there is no valid
user account.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/inc/privacy.php

    r7220 r7226  
    1010defined( 'WPINC' ) || die();
    1111
    12 use WP_Query, WP_User;
     12use WP_Query, WP_User, WP_Error;
    1313
    1414add_filter( 'wp_privacy_personal_data_exporters', __NAMESPACE__ . '\register_personal_data_exporters' );
     
    114114
    115115    $post_query = get_wc_posts( $post_type, $email_address, $page );
     116
     117    if ( is_wp_error( $post_query ) ) {
     118        return [
     119            'data' => [],
     120            'done' => true,
     121        ];
     122    }
    116123
    117124    foreach ( (array) $post_query->posts as $post ) {
     
    209216 * @param int    $page
    210217 *
    211  * @return WP_Query
     218 * @return WP_Query|WP_Error
    212219 */
    213220function get_wc_posts( $post_type, $email_address, $page ) {
     
    237244                $meta_query[] = [
    238245                    [
    239                         'key' => '_wcpt_user_id',
     246                        'key'   => '_wcpt_user_id',
    240247                        'value' => $user->ID,
     248                        'type'  => 'NUMERIC',
    241249                    ],
    242250                ];
     
    263271                $meta_query = [
    264272                    [
    265                         'key' => '_wcpt_user_id',
     273                        'key'   => '_wcpt_user_id',
    266274                        'value' => $user->ID,
     275                        'type'  => 'NUMERIC',
    267276                    ],
    268277                ];
    269278
    270279                $query_args['meta_query'] = $meta_query;
     280            } else {
     281                $query_args = [];
    271282            }
    272283            break;
    273284    }
    274285
     286    if ( empty( $query_args ) ) {
     287        return new WP_Error();
     288    }
     289
    275290    return new WP_Query( $query_args );
    276291}
Note: See TracChangeset for help on using the changeset viewer.