autoload = $autoload; $this->cron = $cron; } /** * Routes. */ public function register_routes(): void { $this->route( '/autoload', array( 'methods' => 'GET', 'callback' => array( $this, 'autoload' ), 'permission_callback' => array( $this, 'permission' ), ) ); $this->route( '/cron', array( 'methods' => 'GET', 'callback' => array( $this, 'cron' ), 'permission_callback' => array( $this, 'permission' ), ) ); } /** * Autoload view. */ public function autoload(): \WP_REST_Response { $r = $this->autoload->analyze( 15 ); $out = array(); foreach ( $r['owners'] as $key => $o ) { $out[] = array( 'key' => $key, 'name' => (string) ( $r['descriptors'][ $key ]['name'] ?? $key ), 'type' => (string) ( $r['descriptors'][ $key ]['type'] ?? 'unknown' ), 'kb' => round( $o['bytes'] / 1024, 1 ), 'count' => $o['count'], 'rows' => $o['rows'], ); } return new \WP_REST_Response( array( 'owners' => $out, 'unknown' => $r['unknown'], 'total_kb' => round( $r['total_bytes'] / 1024, 1 ), 'count' => $r['total_count'], ) ); } /** * Cron view. */ public function cron(): \WP_REST_Response { $r = $this->cron->analyze(); $out = array(); foreach ( $r['owners'] as $key => $o ) { $out[] = array( 'key' => $key, 'name' => (string) ( $r['descriptors'][ $key ]['name'] ?? $key ), 'type' => (string) ( $r['descriptors'][ $key ]['type'] ?? 'unknown' ), 'per_day' => $o['per_day'], 'events' => $o['events'], ); } return new \WP_REST_Response( array( 'owners' => $out, 'orphans' => $r['orphans'], 'total_per_day' => $r['total_per_day'], 'disabled' => defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON, ) ); } }