$envelope Envelope data. * @param WP_REST_Response $response Original response data. * @return array Envelope data. */ public function filter_rest_envelope_response( array $envelope, WP_REST_Response $response ) { if ( ! $this->should_dispatch() ) { return $envelope; } $data = array(); $this->before_output(); /** @var array $outputters */ $outputters = $this->get_outputters( 'raw' ); foreach ( $outputters as $id => $output ) { $data[ $id ] = $output->get_output(); } $this->after_output(); $envelope['qm'] = $data; return $envelope; } /** * @return void */ protected function before_output() { foreach ( (array) glob( $this->qm->plugin_path( 'output/raw/*.php' ) ) as $file ) { include_once $file; } } /** * @return bool */ public function is_active() { if ( ! self::user_can_view() ) { return false; } return true; } } /** * @param array $dispatchers * @param QM_Plugin $qm * @return array */ function register_qm_dispatcher_rest_envelope( array $dispatchers, QM_Plugin $qm ) { $dispatchers['rest_envelope'] = new QM_Dispatcher_REST_Envelope( $qm ); return $dispatchers; } add_filter( 'qm/dispatchers', 'register_qm_dispatcher_rest_envelope', 10, 2 );