Making WordPress.org


Ignore:
Timestamp:
07/28/2018 12:46:28 AM (7 years ago)
Author:
coreymckrill
Message:

WordCamp Reports: Add WordCamp Details report

This is the first iteration of a report that allows WPCS staff to download a
spreadsheet of WordCamps and related data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-wordcamp-status.php

    r6662 r7516  
    77defined( 'WPINC' ) || die();
    88
     9use Exception;
     10use WordCamp\Reports;
     11use function WordCamp\Reports\Validation\validate_wordcamp_status;
    912use WordCamp_Loader;
    10 use WordCamp\Reports;
    1113
    1214/**
     
    101103        // Report-specific options.
    102104        $options = wp_parse_args( $options, array(
    103             'status_subset' => array(),
     105            'status_subset' => [],
    104106        ) );
    105107
    106108        parent::__construct( $start_date, $end_date, $options );
    107109
    108         if ( 'any' === $status ) {
    109             $status = '';
    110         }
    111 
    112         if ( $status && $this->validate_status_input( $status ) ) {
    113             $this->status = $status;
    114         }
    115     }
    116 
    117     /**
    118      * Validate the given status ID string.
    119      *
    120      * @param string $status The status ID to filter for in the report.
    121      *
    122      * @return bool True if the status ID is valid. Otherwise false.
    123      */
    124     protected function validate_status_input( $status ) {
    125         if ( is_array( $this->options['status_subset'] ) && ! empty( $this->options['status_subset'] ) ) {
    126             if ( ! in_array( $status, $this->options['status_subset'], true ) ) {
    127                 $this->error->add( 'invalid_status', 'Please enter a valid status ID.' );
    128 
    129                 return false;
    130             }
    131 
    132             return true;
    133         }
    134 
    135         if ( ! in_array( $status, array_keys( WordCamp_Loader::get_post_statuses() ), true ) ) {
    136             $this->error->add( 'invalid_status', 'Please enter a valid status ID.' );
    137 
    138             return false;
    139         }
    140 
    141         return true;
     110        if ( $status && 'any' !== $status ) {
     111            try {
     112                $this->status = validate_wordcamp_status( $status, $options );
     113            } catch ( Exception $e ) {
     114                $this->error->add(
     115                    self::$slug . '-status-error',
     116                    $e->getMessage()
     117                );
     118            }
     119        }
    142120    }
    143121
Note: See TracChangeset for help on using the changeset viewer.