Making WordPress.org

Changeset 6819


Ignore:
Timestamp:
03/01/2018 10:35:57 PM (8 years ago)
Author:
coreymckrill
Message:

WordCamp Central: Prevent access to incident report submission posts

This adds two filters that attempt to prevent access to the posts by non-
super admins. The first modifies queries that include feedback posts when the
current user can't manage the network. The second changes the capabilities
necessary to export content from the WordCamp Central site to include
managing the network.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-misc.php

    r6712 r6819  
    349349add_action( 'wp_enqueue_scripts',    'wcorg_register_scripts' );
    350350add_action( 'admin_enqueue_scripts', 'wcorg_register_scripts' );
     351
     352/**
     353 * Conditionally omit incident report submission feedback posts from post query results.
     354 *
     355 * @param WP_Query $wp_query
     356 */
     357function wcorg_central_omit_incident_reports( $wp_query ) {
     358    if ( ! $wp_query instanceof WP_Query ) {
     359        return $wp_query;
     360    }
     361
     362    $post_types = $wp_query->get( 'post_type' );
     363
     364    if ( BLOG_ID_CURRENT_SITE == get_current_blog_id()
     365         && in_array( 'feedback', (array) $post_types, true )
     366         && ! current_user_can( 'manage_network' ) // TODO add a subrole for this.
     367    ) {
     368        $meta_query = $wp_query->get( 'meta_query', array() );
     369
     370        $meta_query[] = array(
     371            'relation' => 'OR',
     372            array(
     373                'key'     => '_feedback_email',
     374                'value'   => 'report@wordcamp.org',
     375                'compare' => 'NOT LIKE',
     376            ),
     377            // This catches non-feedback posts, but may cause a performance issue.
     378            // See https://developer.wordpress.org/reference/classes/wp_query/#comment-2315
     379            array(
     380                'key'   => '_feedback_email',
     381                'value' => 'NOT EXISTS',
     382            ),
     383        );
     384
     385        $wp_query->set( 'meta_query', $meta_query );
     386    }
     387
     388    return $wp_query;
     389}
     390
     391add_filter( 'pre_get_posts', 'wcorg_central_omit_incident_reports' );
     392
     393/**
     394 * Modify the capabilities necessary for exporting content from WordCamp Central.
     395 *
     396 * This effectively makes it so that only super admins and trusted deputies can export.
     397 *
     398 * The intention is to prevent the export of incident report submission feedback posts, which don't seem to be filtered
     399 * out by `wcorg_central_omit_incident_reports` when exporting all content.
     400 *
     401 * @param array  $primitive_caps The original list of primitive caps mapped to the given meta cap.
     402 * @param string $meta_cap       The meta cap in question.
     403 */
     404function wcorg_central_modify_export_caps( $primitive_caps, $meta_cap ) {
     405    if ( BLOG_ID_CURRENT_SITE == get_current_blog_id() && 'export' === $meta_cap ) {
     406        return array_merge( (array) $primitive_caps, array( 'manage_network' ) ); // TODO add a subrole for this.
     407    }
     408
     409    return $primitive_caps;
     410}
     411
     412add_filter( 'map_meta_cap', 'wcorg_central_modify_export_caps', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.