Created
December 4, 2025 23:11
-
-
Save seanlanglands/54c9d1e2ddc75c48249e0774596de705 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( | |
| 'plugins_loaded', function () { | |
| class QM_Output_RAW_EP_Query_Log extends QM_Output_Raw { | |
| /** | |
| * Collector instance. | |
| * | |
| * @var QM_Collector_HTTP Collector. | |
| */ | |
| protected $collector; | |
| /** | |
| * @return string | |
| */ | |
| public function name() { | |
| return __( 'EP Test', 'query-monitor' ); | |
| } | |
| /** | |
| * @return array<string, mixed> | |
| */ | |
| public function get_output() { | |
| $output = array(); | |
| $data = $this->collector->get_data(); | |
| if ( empty( $data['first_query_body'] ) ) { | |
| return $output; | |
| } | |
| $output['first_query_body'] = $data['first_query_body']; | |
| return $output; | |
| } | |
| } | |
| class QM_Collector_EP_Query_Log extends QM_Collector { | |
| /** | |
| * ID of the collector, used in the UI. | |
| * | |
| * @var string | |
| */ | |
| public $id = 'es_query_log'; | |
| public function name() { | |
| return 'ElasticPress Query Log'; | |
| } | |
| public function process() { | |
| if ( ! function_exists( 'ep_get_query_log' ) ) { | |
| $this->data['error'] = 'ElasticPress is not active or not available.'; | |
| return; | |
| } | |
| $ep_query_log = ep_get_query_log(); | |
| if ( ! empty( $ep_query_log[0]['args']['body'] ) ) { | |
| $decoded = json_decode( $ep_query_log[0]['args']['body'] ); | |
| $this->data['first_query_body'] = $decoded ?: '(Could not decode JSON)'; | |
| } else { | |
| $this->data['note'] = 'No query body found in first log entry.'; | |
| } | |
| } | |
| } | |
| add_filter( | |
| 'qm/collectors', function ( $collectors ) { | |
| $collectors['ep_query_log'] = new QM_Collector_EP_Query_Log(); | |
| return $collectors; | |
| }, 10, 2 ); | |
| add_filter( | |
| 'qm/outputter/raw', function ( array $output, QM_Collectors $collectors ) { | |
| $collector = QM_Collectors::get( 'es_query_log' ); | |
| if ( $collector ) { | |
| $output['es_query_log'] = new QM_Output_RAW_EP_Query_Log( $collector ); | |
| } | |
| return $output; | |
| }, 10, 2 ); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment