Skip to content

Commit

Permalink
Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Dec 11, 2024
2 parents 8fdc36b + 56b503f commit 94afe32
Show file tree
Hide file tree
Showing 24 changed files with 10,673 additions and 9,250 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
/.eslintrc export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.nvmrc export-ignore
/.npmrc export-ignore
/.stylelintrc export-ignore
/CHANGELOG.md export-ignore
/CODE_OF_CONDUCT.md export-ignore
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,38 @@ jobs:
name: Lint JS and CSS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: npm install
run: npm install

- name: eslint
run: npm run lint-js

- name: stylelint
run: npm run lint-css

phpcs:
name: PHPCS
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: composer install
run: composer install

- name: Set PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: :php-psr
tools: cs2pr
coverage: none

- name: PHPCS check
run: composer run lint
run: './vendor/bin/phpcs . -q --report=checkstyle --runtime-set testVersion 7.0- | cs2pr'

- name: PHP Compatibility Check
run: composer run check-php-compat
3 changes: 2 additions & 1 deletion .github/workflows/push-asset-readme-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
name: Deploy assets/readme to WP.org
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- name: WordPress.org plugin asset/readme update
uses: 10up/action-wordpress-plugin-asset-update@stable
env:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/push-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
name: Deploy plugin version to WP.org
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wordpress-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: WordPress version checker
uses: skaut/wordpress-version-checker@v1.2.0
uses: skaut/wordpress-version-checker@v2.2.2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ All notable changes to this project will be documented in this file, per [the Ke
### Security
-->

## [3.1.1] - 2024-12-11

### Added
- Display the number of queries in Query Monitor's tab title. Props [@felipeelia](https://github.com/felipeelia) and [@burhandodhy](https://github.com/burhandodhy) via [#105](https://github.com/10up/ElasticPress/pull/105).
- ElasticPress as a plugin dependency. Props [@jeffpaul](https://github.com/jeffpaul) via [#99](https://github.com/10up/ElasticPress/pull/99).

### Changed
- More modern versions of GitHub Actions, node, and node packages. Props [@felipeelia](https://github.com/felipeelia) via [#104](https://github.com/10up/ElasticPress/pull/104).

### Fixed
- Notices related to i18n calls. Props [@felipeelia](https://github.com/felipeelia) and [@archon810](https://github.com/archon810) via [#103](https://github.com/10up/ElasticPress/pull/103).
- Use new plugin name in the admin notice. Props [@burhandodhy](https://github.com/burhandodhy) via [#108](https://github.com/10up/ElasticPress/pull/108).

## [3.1.0] - 2023-09-20

### Added
Expand Down Expand Up @@ -96,6 +109,7 @@ This release drops the support for older versions of WordPress Core, ElasticPres
* Initial release

[Unreleased]: https://github.com/10up/debug-bar-elasticpress/compare/trunk...develop
[3.1.1]: https://github.com/10up/debug-bar-elasticpress/compare/3.1.0...3.1.1
[3.1.0]: https://github.com/10up/debug-bar-elasticpress/compare/3.0.0...3.1.0
[3.0.0]: https://github.com/10up/debug-bar-elasticpress/compare/2.1.1...3.0.0
[2.1.1]: https://github.com/10up/debug-bar-elasticpress/compare/2.1.0...2.1.1
Expand Down
3 changes: 2 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The following acknowledges the Maintainers for this repository, those who have C

The following individuals are responsible for curating the list of issues, responding to pull requests, and ensuring regular releases happen.

[Vasken Hauri (@brandwaffle)](https://github.com/brandwaffle).
[Thorsten Ott (@tott)](https://github.com/tott) and [Felipe Elia (@felipeelia)](https://github.com/felipeelia).

## Contributors

Expand All @@ -29,6 +29,7 @@ Thank you to all the people who have already contributed to this repository via
[Burhan Nasir (@burhandodhy)](https://github.com/burhandodhy),
[Nathaniel Taintor (@goldenapples)](https://github.com/goldenapples),
[Matt Gross (@mattonomics)](https://github.com/mattonomics),
[Artem Russakovskii (@archon810)](https://github.com/archon810),
and
[Christoph Bratschi (@cbratschi)](https://github.com/cbratschi).

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Debug Bar ElasticPress
# ElasticPress Debugging Add-On

> A WordPress plugin that adds a [Debug Bar](https://wordpress.org/plugins/debug-bar/) panel to examine ElasticPress queries.
> Adds an [ElasticPress](https://wordpress.org/plugins/elasticpress) panel to [Debug Bar](https://wordpress.org/plugins/debug-bar/) and/or [Query Monitor](https://wordpress.org/plugins/query-monitor/) plugins. Allows you to examine every ElasticPress query running on any given request.
[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Release Version](https://img.shields.io/github/tag/10up/debug-bar-elasticpress.svg?label=release)](https://github.com/10up/debug-bar-elasticpress/releases/latest) ![WordPress tested up to version](https://img.shields.io/wordpress/plugin/tested/debug-bar-elasticpress?label=WordPress) [![GPLv2 License](https://img.shields.io/github/license/10up/debug-bar-elasticpress.svg)](https://github.com/10up/debug-bar-elasticpress/blob/trunk/LICENSE.md)

## Requirements

* [ElasticPress](https://wordpress.org/plugins/elasticpress/) 4.4.0+
* [Debug Bar](https://wordpress.org/plugins/debug-bar/) 1.0+
* PHP 7.0+
* Optional: [Debug Bar](https://wordpress.org/plugins/debug-bar/) 1.0+ or [Query Monitor](https://wordpress.org/plugins/query-monitor/)

## Usage

After installing and activating, click the `Debug` button in the admin toolbar. Within the Debug Bar Panel, click the ElasticPress panel.
After installing and activating, click the `Debug` button or the Query Monitor Stats in the admin toolbar. Within Debug Bar/Query Monitor, click the ElasticPress panel.

Alternatively, go to ElasticPress > Query Log and set it to record ElasticPress queries.

## Issues

Expand Down
4 changes: 2 additions & 2 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
cursor: pointer;
display: inline-block;
font-size: 13px;
line-height: 2.15384615;
line-height: 2.1538;
min-height: 30px;
padding: 0 10px;
text-decoration: none;
Expand Down Expand Up @@ -92,7 +92,7 @@
display: inline-block;
font-family: inherit;
font-size: 13px;
line-height: 2.15384615 !important;
line-height: 2.1538 !important;
padding: 0 10px !important;
text-decoration: none !important;
text-shadow: none;
Expand Down
29 changes: 13 additions & 16 deletions classes/CommonPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,25 @@
* CommonPanel class.
*/
class CommonPanel {
/**
* Panel menu title
*
* @var string
*/
public $title = '';

/**
* Class constructor
*/
public function __construct() {
$this->title = esc_html__( 'ElasticPress', 'debug-bar-elasticpress' );
}

/**
* Return the panel title
*
* @return string
*/
public function get_title() : string {
return $this->title;
public function get_title(): string {
$queries_count = count( \ElasticPress\Elasticsearch::factory()->get_query_log() );

if ( $queries_count ) {
return sprintf(
/* translators: %d: number of queries */
esc_html__( 'ElasticPress (%d)', 'debug-bar-elasticpress' ),
$queries_count
);
}

return esc_html__( 'ElasticPress', 'debug-bar-elasticpress' );
}

/**
* Enqueue scripts for front end and admin
*/
Expand Down
Empty file modified classes/EP_Debug_Bar_ElasticPress.php
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions classes/QueryFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace DebugBarElasticPress;

use \ElasticPress\QueryLogger;
use ElasticPress\QueryLogger;

defined( 'ABSPATH' ) || exit;

Expand All @@ -24,7 +24,7 @@ class QueryFormatter extends QueryLogger {
* @param array $queries Queries to be displayed
* @return array
*/
public function format_queries_for_display( $queries ) : array {
public function format_queries_for_display( $queries ): array {
$formatted_queries = [];

$labels = [
Expand Down
34 changes: 19 additions & 15 deletions classes/QueryLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ public function action_admin_init() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK && isset( $_POST['ep_enable_logging'] ) ) {
check_admin_referer( 'ep-debug-options' );

update_site_option( 'ep_enable_logging', $this->sanitize_enable_logging( $_POST['ep_enable_logging'] ) );
update_site_option( 'ep_query_log_by_status', sanitize_text_field( $_POST['ep_query_log_by_status'] ) );
update_site_option( 'ep_enable_logging', $this->sanitize_enable_logging( $_POST['ep_enable_logging'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
if ( isset( $_POST['ep_query_log_by_status'] ) ) {
update_site_option( 'ep_query_log_by_status', sanitize_text_field( wp_unslash( $_POST['ep_query_log_by_status'] ) ) );
}
if ( ! empty( $_POST['ep_query_log_by_context'] ) ) {
update_site_option( 'ep_query_log_by_context', array_map( 'sanitize_text_field', $_POST['ep_query_log_by_context'] ) );
$ep_query_log_by_context = array_map( 'sanitize_text_field', wp_unslash( $_POST['ep_query_log_by_context'] ) );
update_site_option( 'ep_query_log_by_context', $ep_query_log_by_context );
} else {
update_site_option( 'ep_query_log_by_context', [] );
}
Expand Down Expand Up @@ -97,7 +100,10 @@ public function action_admin_init() {
* @since 1.3
*/
public function maybe_clear_log() {
if ( empty( $_GET['ep_clear_query_log'] ) || ! wp_verify_nonce( $_GET['ep_clear_query_log'], 'ep_clear_query_log' ) ) {
if (
empty( $_GET['ep_clear_query_log'] )
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['ep_clear_query_log'] ) ), 'ep_clear_query_log' )
) {
return;
}

Expand Down Expand Up @@ -323,7 +329,7 @@ public function screen_options() {

<?php
$queries = array_map(
function( $query ) {
function ( $query ) {
return $query['query'];
},
$log
Expand Down Expand Up @@ -386,7 +392,7 @@ public function json_decode_query_log( $value ) {
* @param string|null $type Type of request, used for debugging.
* @return array New request args
*/
public function maybe_add_request_type( array $args, string $path, array $query_args, $type ) : array {
public function maybe_add_request_type( array $args, string $path, array $query_args, $type ): array {
if ( ! empty( $args['ep_query_type'] ) ) {
return $args;
}
Expand All @@ -412,7 +418,7 @@ public function maybe_add_request_type( array $args, string $path, array $query_
* @param array $args Request args
* @return array
*/
public function maybe_add_request_context( array $args ) : array {
public function maybe_add_request_context( array $args ): array {
$args['ep_context'] = $this->get_current_context();

return $args;
Expand All @@ -424,7 +430,7 @@ public function maybe_add_request_context( array $args ) : array {
* @since 3.1.0
* @return string
*/
protected function get_current_context() : string {
protected function get_current_context(): string {
$context = 'public';

if ( is_admin() ) {
Expand Down Expand Up @@ -455,7 +461,7 @@ protected function get_current_context() : string {
* @param mixed $query_object Could be WP_Query, WP_User_Query, etc.
* @return array New request arguments
*/
public function maybe_add_request_query_type( array $request_args, string $path, string $index, string $type, array $query, array $query_args, $query_object ) : array {
public function maybe_add_request_query_type( array $request_args, string $path, string $index, string $type, array $query, array $query_args, $query_object ): array {
$request_args['ep_query_type'] = $this->determine_request_query_type( $request_args, $path, $index, $type, $query, $query_args, $query_object );
return $request_args;
}
Expand Down Expand Up @@ -488,7 +494,7 @@ public function admin_enqueue_scripts() {
* @param mixed $query_object Could be WP_Query, WP_User_Query, etc.
* @return string Request type
*/
protected function determine_request_query_type( array $request_args, string $path, string $index, string $type, array $query, array $query_args, $query_object ) : string {
protected function determine_request_query_type( array $request_args, string $path, string $index, string $type, array $query, array $query_args, $query_object ): string {
if ( $query_object instanceof \WP_Query && $query_object->is_main_query() ) {
return esc_html__( 'Main query', 'debug-bar-elasticpress' );
}
Expand Down Expand Up @@ -516,7 +522,7 @@ protected function determine_request_query_type( array $request_args, string $pa
* @since 3.1.0
* @return boolean
*/
protected function is_enabled() : bool {
protected function is_enabled(): bool {
$enabled = Utils\get_option( 'ep_enable_logging' );

return ! empty( $enabled );
Expand All @@ -542,7 +548,7 @@ protected function should_log_by_context() {
* @param string $type Query type
* @return boolean
*/
protected function should_log_by_status( array $query, $type ) : bool {
protected function should_log_by_status( array $query, $type ): bool {
$by_status = Utils\get_option( 'ep_query_log_by_status', 'failed' );

if ( 'all' === $by_status ) {
Expand Down Expand Up @@ -587,7 +593,7 @@ protected function should_log_by_status( array $query, $type ) : bool {
* @since 3.1.0
* @return integer
*/
protected function get_logging_storage_limit() : int {
protected function get_logging_storage_limit(): int {
/**
* Filter the log size limit
*
Expand Down Expand Up @@ -623,8 +629,6 @@ public function maybe_disable() {
* @return mixed
*/
public function sanitize_enable_logging( $value ) {
$value = sanitize_text_field( $_POST['ep_enable_logging'] );

if ( 'time_limit' === $value ) {
$value = wp_date( 'U', strtotime( '+5 minutes' ) );
} else {
Expand Down
2 changes: 1 addition & 1 deletion classes/QueryMonitorOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct( QueryMonitorCollector $collector ) {
*
* @return string
*/
public function name() : string {
public function name(): string {
return $this->common_panel->get_title();
}

Expand Down
6 changes: 3 additions & 3 deletions classes/QueryOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function render_query( $query, $type = '', $context = '' ) {
* @since 3.0.0
* @return string
*/
protected function get_copy_paste_report() : string {
protected function get_copy_paste_report(): string {
$output = sprintf(
"## %s ##\n\n",
__( 'Queries info', 'debug-bar-elasticpress' )
Expand Down Expand Up @@ -357,7 +357,7 @@ public function render_additional_buttons() {
* @since 3.1.0
* @return string
*/
public function get_explain_query_button() : string {
public function get_explain_query_button(): string {
if ( empty( $this->queries ) ) {
return '';
}
Expand All @@ -384,7 +384,7 @@ public function get_explain_query_button() : string {
* @since 3.1.0
* @return string
*/
public function get_retrieve_raw_document_button() : string {
public function get_retrieve_raw_document_button(): string {
if ( ! is_indexable_singular() ) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"license": ["GPL-2.0-only"],
"require-dev": {
"10up/phpcs-composer": "dev-master",
"10up/phpcs-composer": "^3.0.0",
"phpcompatibility/phpcompatibility-wp": "*"
},
"scripts": {
Expand Down
Loading

0 comments on commit 94afe32

Please sign in to comment.