Changeset 7872
- Timestamp:
- 11/19/2018 08:54:21 PM (6 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-base.php
r7734 r7872 5 5 6 6 namespace WordCamp\Reports\Report; 7 use WP_Post;8 9 7 defined( 'WPINC' ) || die(); 8 9 use WP_Error, WP_Post, WP_REST_Response; 10 10 11 11 /** … … 115 115 ) ); 116 116 117 $this->error = new \WP_Error();117 $this->error = new WP_Error(); 118 118 } 119 119 … … 149 149 150 150 return $data; 151 } 152 153 /** 154 * Determine the data fields safelist based on the context of the report. 155 * 156 * @return array The list of fields that are safe to include. 157 */ 158 public function get_data_fields_safelist() { 159 $safelist = $this->public_data_fields; 160 161 if ( false === $this->options['public'] ) { 162 $safelist = array_merge( $safelist, $this->private_data_fields ); 163 } 164 165 return $safelist; 151 166 } 152 167 … … 218 233 * Merge two error objects into one, new error object. 219 234 * 220 * @param \WP_Error $error1 An error object.221 * @param \WP_Error $error2 An error object.222 * 223 * @return \WP_Error The combined errors of the two parameters.224 */ 225 protected function merge_errors( \WP_Error $error1, \WP_Error $error2 ) {235 * @param WP_Error $error1 An error object. 236 * @param WP_Error $error2 An error object. 237 * 238 * @return WP_Error The combined errors of the two parameters. 239 */ 240 protected function merge_errors( WP_Error $error1, WP_Error $error2 ) { 226 241 $codes = $error2->get_error_codes(); 227 242 … … 235 250 236 251 return $error1; 237 }238 239 /**240 * Validate a given WordCamp post ID.241 *242 * @param int $wordcamp_id The ID of a WordCamp post.243 *244 * @return bool True if the WordCamp ID is valid. Otherwise false.245 */246 protected function validate_wordcamp_id( $wordcamp_id ) {247 $wordcamp = get_post( $wordcamp_id );248 249 if ( ! $wordcamp instanceof WP_Post || WCPT_POST_TYPE_ID !== get_post_type( $wordcamp ) ) {250 $this->error->add( 'invalid_wordcamp_id', 'Please enter a valid WordCamp ID.' );251 252 return false;253 }254 255 $wordcamp_site_id = get_wordcamp_site_id( $wordcamp );256 257 if ( ! $wordcamp_site_id ) {258 $this->error->add( 'wordcamp_without_site', 'The specified WordCamp does not have a site yet.' );259 260 return false;261 }262 263 return true;264 252 } 265 253 … … 288 276 * @param array $additional_response_params Additional top-level parameters to add to the response. 289 277 * 290 * @return \WP_REST_Response278 * @return WP_REST_Response 291 279 */ 292 280 protected static function prepare_rest_response( $data, array $additional_response_params = array() ) { … … 298 286 $response_data['data'] = $data; 299 287 300 return new \WP_REST_Response( $response_data ); 301 } 302 303 /** 304 * Determine the data fields safelist based on the context of the report. 305 * 306 * @return array The list of fields that are safe to include. 307 */ 308 public function get_data_fields_safelist() { 309 $safelist = $this->public_data_fields; 310 311 if ( false === $this->options['public'] ) { 312 $safelist = array_merge( $safelist, $this->private_data_fields ); 313 } 314 315 return $safelist; 288 return new WP_REST_Response( $response_data ); 316 289 } 317 290 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-payment-activity.php
r7434 r7872 9 9 defined( 'WPINC' ) || die(); 10 10 11 use Exception; 11 12 use WordCamp\Reports; 12 13 use WordCamp\Utilities; 14 use function WordCamp\Reports\Validation\{validate_wordcamp_id}; 13 15 use WordCamp\Budgets_Dashboard\Reimbursement_Requests; 14 16 … … 122 124 $this->xrt = new Utilities\Currency_XRT_Client(); 123 125 124 if ( $wordcamp_id && $this->validate_wordcamp_id( $wordcamp_id ) ) { 125 $this->wordcamp_id = $wordcamp_id; 126 $this->wordcamp_site_id = get_wordcamp_site_id( get_post( $wordcamp_id ) ); 126 if ( $wordcamp_id ) { 127 try { 128 $valid = validate_wordcamp_id( $wordcamp_id ); 129 130 $this->wordcamp_id = $valid->post_id; 131 $this->wordcamp_site_id = $valid->site_id; 132 } catch( Exception $e ) { 133 $this->error->add( 134 self::$slug . '-wordcamp-id-error', 135 $e->getMessage() 136 ); 137 } 127 138 } 128 139 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-sponsor-invoices.php
r7434 r7872 9 9 defined( 'WPINC' ) || die(); 10 10 11 use Exception; 11 12 use WordCamp\Reports; 12 13 use WordCamp\Utilities; 14 use function WordCamp\Reports\Validation\{validate_wordcamp_id}; 13 15 use WordCamp\Budgets_Dashboard\Sponsor_Invoices as WCBD_Sponsor_Invoices; 14 16 … … 121 123 $this->xrt = new Utilities\Currency_XRT_Client(); 122 124 123 if ( $wordcamp_id && $this->validate_wordcamp_id( $wordcamp_id ) ) { 124 $this->wordcamp_id = $wordcamp_id; 125 $this->wordcamp_site_id = get_wordcamp_site_id( get_post( $wordcamp_id ) ); 125 if ( $wordcamp_id ) { 126 try { 127 $valid = validate_wordcamp_id( $wordcamp_id ); 128 129 $this->wordcamp_id = $valid->post_id; 130 $this->wordcamp_site_id = $valid->site_id; 131 } catch( Exception $e ) { 132 $this->error->add( 133 self::$slug . '-wordcamp-id-error', 134 $e->getMessage() 135 ); 136 } 126 137 } 127 138 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-sponsorship-grants.php
r7434 r7872 9 9 defined( 'WPINC' ) || die(); 10 10 11 use Exception; 11 12 use WordCamp\Reports; 12 13 use WordCamp\Reports\Report; 13 14 use WordCamp\Utilities; 15 use function WordCamp\Reports\Validation\{validate_wordcamp_id}; 14 16 15 17 /** … … 116 118 $this->xrt = new Utilities\Currency_XRT_Client(); 117 119 118 if ( $wordcamp_id && $this->validate_wordcamp_id( $wordcamp_id ) ) { 119 $this->wordcamp_id = $wordcamp_id; 120 $this->wordcamp_site_id = get_wordcamp_site_id( get_post( $wordcamp_id ) ); 120 if ( $wordcamp_id ) { 121 try { 122 $valid = validate_wordcamp_id( $wordcamp_id ); 123 124 $this->wordcamp_id = $valid->post_id; 125 $this->wordcamp_site_id = $valid->site_id; 126 } catch( Exception $e ) { 127 $this->error->add( 128 self::$slug . '-wordcamp-id-error', 129 $e->getMessage() 130 ); 131 } 121 132 } 122 133 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-ticket-revenue.php
r7434 r7872 9 9 defined( 'WPINC' ) || die(); 10 10 11 use Exception; 11 12 use WordCamp\Reports; 12 13 use WordCamp\Utilities; 14 use function WordCamp\Reports\Validation\{validate_wordcamp_id}; 13 15 14 16 /** … … 127 129 $this->xrt = new Utilities\Currency_XRT_Client(); 128 130 129 if ( $wordcamp_id && $this->validate_wordcamp_id( $wordcamp_id ) ) { 130 $this->wordcamp_id = $wordcamp_id; 131 $this->wordcamp_site_id = get_wordcamp_site_id( get_post( $wordcamp_id ) ); 131 if ( $wordcamp_id ) { 132 try { 133 $valid = validate_wordcamp_id( $wordcamp_id ); 134 135 $this->wordcamp_id = $valid->post_id; 136 $this->wordcamp_site_id = $valid->site_id; 137 } catch( Exception $e ) { 138 $this->error->add( 139 self::$slug . '-wordcamp-id-error', 140 $e->getMessage() 141 ); 142 } 132 143 } 133 144 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-wordcamp-payment-methods.php
r7465 r7872 9 9 defined( 'WPINC' ) || die(); 10 10 11 use Exception; 11 12 use WordCamp\Reports; 12 13 use WordCamp\Utilities; 14 use function WordCamp\Reports\Validation\{validate_wordcamp_id}; 13 15 14 16 /** … … 112 114 $this->xrt = new Utilities\Currency_XRT_Client(); 113 115 114 if ( $wordcamp_id && $this->validate_wordcamp_id( $wordcamp_id ) ) { 115 $this->wordcamp_id = $wordcamp_id; 116 $this->wordcamp_site_id = get_wordcamp_site_id( get_post( $wordcamp_id ) ); 116 if ( $wordcamp_id ) { 117 try { 118 $valid = validate_wordcamp_id( $wordcamp_id ); 119 120 $this->wordcamp_id = $valid->post_id; 121 $this->wordcamp_site_id = $valid->site_id; 122 } catch( Exception $e ) { 123 $this->error->add( 124 self::$slug . '-wordcamp-id-error', 125 $e->getMessage() 126 ); 127 } 117 128 } 118 129 }
Note: See TracChangeset
for help on using the changeset viewer.