Skip to content

Commit

Permalink
Unify checks + Nonce verification + CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Sep 5, 2023
1 parent 707f427 commit c09c28c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
24 changes: 13 additions & 11 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
}

.ep-queries-buttons-wrapper {
align-items: center;
clear: both;
display: flex;
gap: 10px;
padding: 1em 0;
}

Expand Down Expand Up @@ -76,12 +79,10 @@
* override QM's important rules
*/
#debug-menu-target-EP_Debug_Bar_ElasticPress .button,
#debug-menu-target-EP_Debug_Bar_ElasticPress a.button,
#debug-menu-target-EP_Debug_Bar_ElasticPress button.ep-copy-button.button.qm-button {
#debug-menu-target-EP_Debug_Bar_ElasticPress a.button {
background: #f6f7f7 !important;
border-color: #2271b1 !important;
border: 1px solid #2271b1 !important;
border-radius: 3px !important;
border-width: 1px;

/* Overriding some Debug Bar "important" rules */
color: #2271b1 !important;
Expand All @@ -95,16 +96,18 @@
text-shadow: none;
}

#debug-menu-target-EP_Debug_Bar_ElasticPress .button:hover {
#debug-menu-target-EP_Debug_Bar_ElasticPress .button:hover,
#query-monitor-main #qm-debug_bar_ep_debug_bar_elasticpress .button:hover {
background: #f0f0f1;
border-color: #0a4b78;
color: #0a4b78;
text-decoration: none;
color: #0a4b78 !important;
text-decoration: none !important;
}

#debug-menu-target-EP_Debug_Bar_ElasticPress .button:active {
background: #f6f7f7;
border-color: #8c8f94;
#debug-menu-target-EP_Debug_Bar_ElasticPress .button:active,
#query-monitor-main #qm-debug_bar_ep_debug_bar_elasticpress .button:hover {
background: #f6f7f7 !important;
border-color: #8c8f94 !important;
box-shadow: none;
}

Expand All @@ -119,7 +122,6 @@
background: #007cba !important;
border: 1px solid #007cba !important;
color: #fff !important;
margin-right: 5px !important;
}

#debug-menu-target-EP_Debug_Bar_ElasticPress a.button-primary:hover,
Expand Down
19 changes: 6 additions & 13 deletions classes/QueryOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function render_buttons() {
<a download="debug-bar-elasticpress-report.txt" href="data:text/plain;charset=utf-8,<?php echo rawurlencode( $copy_paste_output ); ?>" class="button button-primary" id="ep-download-requests-info">
<?php esc_html_e( 'Download Requests Info', 'debug-bar-elasticpress' ); ?>
</a>
<button class="ep-copy-button button qm-button" data-clipboard-text="<?php echo esc_attr( $copy_paste_output ); ?>">
<button class="ep-copy-button button bordered-button" data-clipboard-text="<?php echo esc_attr( $copy_paste_output ); ?>">
<?php esc_html_e( 'Copy Requests Info to Clipboard', 'debug-bar-elasticpress' ); ?>
</button>
<span class="ep-copy-button-wrapper__success" style="display: none;">
Expand Down Expand Up @@ -357,7 +357,7 @@ public function get_explain_query_button() : string {
);

return sprintf(
'<a href="%s" class="button button-primary" id="ep-explain-query">
'<a href="%s" class="ep-explain-query button bordered-button">
%s
</a>',
esc_url( $button_link ),
Expand All @@ -372,27 +372,20 @@ public function get_explain_query_button() : string {
* @return string
*/
public function get_retrieve_raw_document_button() : string {
if ( ! is_singular() ) {
return '';
}

$post_type = get_post_type();
$post_indexable = \ElasticPress\Indexables::factory()->get( 'post' );

$indexable_post_types = $post_indexable->get_indexable_post_types();
if ( ! in_array( $post_type, $indexable_post_types, true ) ) {
if ( ! is_indexable_singular() ) {
return '';
}

$button_link = add_query_arg(
[
'retrieve-raw-es-document' => '1',
'ep-retrieve-es-document' => '1',
'_wpnonce' => wp_create_nonce( 'ep-retrieve-es-document' ),
],
isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''
);

return sprintf(
'<a href="%s" class="button button-primary" id="ep-retrieve-raw-es-document">
'<a href="%s" class="ep-retrieve-es-document button bordered-button">
%s
</a>',
esc_url( $button_link ),
Expand Down
31 changes: 20 additions & 11 deletions debug-bar-elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,14 @@ function admin_notice_min_ep_version() {
}

/**
* Get document from Elasticsearch.
* Check if the current page is an indexable singular of an ES document or not.
*
* @since 3.1.0
*
* @return void
* @return boolean
*/
function retrieve_raw_document_from_es() {
if ( empty( $_GET['retrieve-raw-es-document'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}

function is_indexable_singular() {
if ( ! is_singular() ) {
return;
return false;
}

$id = get_the_ID();
Expand All @@ -177,9 +172,23 @@ function retrieve_raw_document_from_es() {
$post_indexable = \ElasticPress\Indexables::factory()->get( 'post' );
$indexable_post_types = $post_indexable->get_indexable_post_types();

if ( ! in_array( $post_type, $indexable_post_types, true ) ) {
return in_array( $post_type, $indexable_post_types, true );
}

/**
* Get document from Elasticsearch.
*
* @since 3.1.0
* @return void
*/
function retrieve_raw_document_from_es() {
if ( empty( $_GET['ep-retrieve-es-document'] ) || empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'ep-retrieve-es-document' ) ) {
return;
}

if ( ! is_indexable_singular() ) {
return;
}

$post_indexable->get( $id );
\ElasticPress\Indexables::factory()->get( 'post' )->get( get_the_ID() );
}

0 comments on commit c09c28c

Please sign in to comment.