Making WordPress.org


Ignore:
Timestamp:
04/18/2018 09:22:07 PM (6 years ago)
Author:
iandunn
Message:

WP15: Set new Tagregator posts to pending for manual approval.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wp15.wordpress.net/public_html/content/mu-plugins/miscellaneous.php

    r7079 r7130  
    1111namespace WP15\Miscellaneous;
    1212use DateTime;
     13use TGGRSourceFlickr, TGGRSourceGoogle, TGGRSourceInstagram, TGGRSourceTwitter;
    1314
    1415defined( 'WPINC' ) || die();
     
    1617add_filter( 'map_meta_cap',           __NAMESPACE__ . '\allow_css_editing',         10, 2 );
    1718add_filter( 'tggr_end_date',          __NAMESPACE__ . '\set_tagregator_cutoff_date'       );
     19add_filter( 'wp_insert_post_data',    __NAMESPACE__ . '\moderate_tagregator_posts'        );
    1820add_action( 'wp_enqueue_scripts',     __NAMESPACE__ . '\register_assets',            1    );
    1921add_action( 'admin_enqueue_scripts',  __NAMESPACE__ . '\register_assets',            1    );
     
    6163
    6264/**
     65 * Set new Tagregator posts to `pending`, so they can be manually approved before being displayed.
     66 *
     67 * The `#WP15` hashtag is shared with other, non-WordPress meanings, and sometimes has content that would be
     68 * inappropriate for an official WP site. So, we need to manually approve the posts before they're published.
     69 *
     70 * @param array $post_data
     71 *
     72 * @return array
     73 */
     74function moderate_tagregator_posts( $post_data ) {
     75    $tagregator_post_types = array();
     76    $moderator_actions     = array( 'edit', 'editpost', 'inline-save' );
     77    $modules               = array( 'TGGRSourceFlickr', 'TGGRSourceGoogle', 'TGGRSourceInstagram', 'TGGRSourceTwitter' );
     78
     79    foreach ( $modules as $module ) {
     80        if ( defined( "$module::POST_TYPE_SLUG" ) ) {
     81            array_push( $tagregator_post_types, $module::POST_TYPE_SLUG );
     82        }
     83    }
     84
     85    if ( 'publish' !== $post_data['post_status'] || ! in_array( $post_data['post_type'], $tagregator_post_types, true ) ) {
     86        return $post_data;
     87    }
     88
     89    if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $moderator_actions, true ) ) {
     90        return $post_data;
     91    }
     92
     93    $post_data['post_status'] = 'pending';
     94
     95    return $post_data;
     96}
     97
     98/**
    6399 * Register style and script assets for later enqueueing.
    64100 */
Note: See TracChangeset for help on using the changeset viewer.