Skip to content

Commit

Permalink
Bring over changes to demote get_reports() back to a magic method lev…
Browse files Browse the repository at this point in the history
…eraging get_items_sorted() from #6280.
  • Loading branch information
DrewAPicture committed Jan 9, 2018
1 parent 667b4da commit 17ad721
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions includes/admin/reporting/class-reports-registry.php
Expand Up @@ -22,6 +22,7 @@
*
* @method array get_report( string $report_id )
* @method void remove_report( string $report_id )
* @method array get_reports( string $sort )
*/
class Reports_Registry extends Registry implements Utils\Static_Registry {

Expand Down Expand Up @@ -69,15 +70,19 @@ public static function instance() {
*/
public function __call( $name, $arguments ) {

$report_id = isset( $arguments[0] ) ? $arguments[0] : '';
$report_id_or_sort = isset( $arguments[0] ) ? $arguments[0] : '';

switch( $name ) {
case 'get_report':
return parent::get_item( $report_id );
return parent::get_item( $report_id_or_sort );
break;

case 'remove_report':
parent::remove_item( $report_id );
parent::remove_item( $report_id_or_sort );
break;

case 'get_reports':
return $this->get_items_sorted( $report_id_or_sort );
break;
}
}
Expand Down Expand Up @@ -135,36 +140,4 @@ public function add_report( $report_id, $attributes ) {
}
}

/**
* Retrieves all registered reports with a given sorting scheme.
*
* @since 3.0
*
* @param string $sort Optional. How to sort the list of registered reports before retrieval.
* Accepts 'priority' or 'ID' (alphabetized by report ID), or empty (none).
* Default empty.
*/
public function get_reports( $sort = '' ) {
// If sorting, handle it before retrieval from the ArrayObject.
switch( $sort ) {
case 'ID':
parent::ksort();
break;

case 'priority':
parent::uasort( function( $a, $b ) {
if ( $a['priority'] == $b['priority'] ) {
return 0;
}

return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
} );
break;

default: break;
}

return parent::get_items();
}

}

0 comments on commit 17ad721

Please sign in to comment.