Skip to content

Commit

Permalink
Merge pull request #1 from norcross/develop
Browse files Browse the repository at this point in the history
merging for release
  • Loading branch information
norcross authored Dec 2, 2024
2 parents 97266fe + c860d0f commit b22560b
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 336 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ All notable changes to this project will be documented in this file, according t

This project adheres to [Semantic Versioning](http://semver.org/).

##[0.0.0]
##[0.0.2]

* Initial public release.
207 changes: 0 additions & 207 deletions Gruntfile.js

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Quick Purge Debug for WordPress
Add ways to quickly purge the debug log file.
Adds an admin bar icon and CLI command for quickly purging the debug logfile.
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "norcross/quick-purge-debug",
"description": "Adds an admin bar icon and CLI command for quickly purging the debug logfile.",
"type": "wordpress-plugin",
"license": "MIT",
"authors":[
{
"name": "Andrew Norcross",
"email": "[email protected]",
"homepage": "https://github.com/norcross"
}
],
"require": {
"composer/installers": "^1 || ^2"
}
}
5 changes: 1 addition & 4 deletions includes/activate.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Our activation call
* Our activation call.
*
* @package QuickPurgeDebug
*/
Expand All @@ -20,8 +20,5 @@ function activate() {

// Include our action so that we may add to this later.
do_action( Core\HOOK_PREFIX . 'activate_process' );

// And flush our rewrite rules.
flush_rewrite_rules();
}
register_activation_hook( Core\FILE, __NAMESPACE__ . '\activate' );
56 changes: 43 additions & 13 deletions includes/admin/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
*/
function add_admin_bar_item( \WP_Admin_Bar $wp_admin_bar ) {

// Add the check to hide the empty.
$check_show = maybe_hide_admin_icon();

// Bail if we got a false.
if ( false === $check_show ) {
return;
}

// Get my purge file args.
$purge_args = fetch_admin_bar_args();

Expand All @@ -35,6 +43,28 @@ function add_admin_bar_item( \WP_Admin_Bar $wp_admin_bar ) {
}
}

/**
* Check to see if we should show the empty.
*
* @return boolean
*/
function maybe_hide_admin_icon() {

// First pass in our filter.
$hide_empty = apply_filters( Core\HOOK_PREFIX . 'hide_icon_when_empty', true );

// If we don't care, show it regardless.
if ( false === $hide_empty ) {
return true;
}

// Now get the file size.
$debug_size = Helpers\get_logfile_size();

// Now return the result.
return ! empty( $debug_size ) ? true : false;
}

/**
* Set all the args for the purge debug admin bar item.
*
Expand All @@ -43,31 +73,31 @@ function add_admin_bar_item( \WP_Admin_Bar $wp_admin_bar ) {
function fetch_admin_bar_args() {

// Get the actual purge link.
$adminbar_link = Helpers\get_logfile_purge_link();
$get_admin_bar_link = Helpers\get_logfile_purge_link();

// Bail if we don't have a link.
if ( empty( $adminbar_link ) ) {
if ( empty( $get_admin_bar_link ) ) {
return;
}

// Get the standard title, which is a trash can for us.
$fetch_titles = Helpers\get_admin_bar_titles();
$admin_bar_titles = Helpers\get_admin_bar_titles();

// Decide if a target blank.
$adminbar_blank = ! is_admin() ? '_blank' : '';
$maybe_link_target = ! is_admin() ? '_blank' : '';

// Now set up the args.
$adminbar_array = array(
$set_admin_bar_args = [
'id' => Core\ADMIN_BAR_ID,
'title' => $fetch_titles['title'],
'href' => esc_url( $adminbar_link ),
'title' => $admin_bar_titles['title'],
'href' => esc_url( $get_admin_bar_link ),
'position' => 0,
'meta' => array(
'title' => esc_attr( $fetch_titles['hover'] ),
'target' => $adminbar_blank,
),
);
'meta' => [
'title' => esc_attr( $admin_bar_titles['hover'] ),
'target' => $maybe_link_target,
],
];

// And return them, filtered.
return apply_filters( Core\HOOK_PREFIX . 'admin_bar_args', $adminbar_array );
return apply_filters( Core\HOOK_PREFIX . 'admin_bar_args', $set_admin_bar_args );
}
30 changes: 19 additions & 11 deletions includes/admin/notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,43 @@
*/
function admin_result_notices() {

// Make sure we have the completed flags.
if ( empty( $_GET['qpd-purge-complete'] ) || empty( $_GET['qpd-purge-result'] ) ) {
// Confirm this is one of our notices when done.
$confirm_isdone = filter_input( INPUT_GET, 'qpd-purge-complete', FILTER_SANITIZE_SPECIAL_CHARS );

// Make sure it is what we want.
if ( empty( $confirm_isdone ) || 'yes' !== $confirm_isdone ) {
return;
}

// Determine the message type.
$result = ! empty( $_GET['qpd-purge-result'] ) && 'success' === sanitize_text_field( $_GET['qpd-purge-result'] ) ? 'success' : 'error';
// Confirm this is one of our results when done.
$confirm_result = filter_input( INPUT_GET, 'qpd-purge-result', FILTER_SANITIZE_SPECIAL_CHARS );

// Make sure it is acceptable.
if ( empty( $confirm_result ) || ! in_array( $confirm_result, ['success', 'error'], true ) ) {
return;
}

// Handle the success first
if ( 'error' !== $result ) {
// Handle the success first.
if ( 'success' === $confirm_result ) {

// Go get my text to display.
$notice = Helpers\get_admin_notice_text( 'purge-success' );
$isdone_message = Helpers\get_admin_notice_text( 'purge-success' );

// And handle the display.
display_admin_notice_markup( $notice, $result );
display_admin_notice_markup( $isdone_message, $confirm_result );

// And be done.
return;
}

// Figure out my error code.
$error_code = ! empty( $_GET['qpd-purge-error'] ) ? $_GET['qpd-purge-error'] : 'unknown';
$confirm_error = filter_input( INPUT_GET, 'qpd-purge-error', FILTER_SANITIZE_SPECIAL_CHARS );

// Handle my error text retrieval.
$error_text = Helpers\get_admin_notice_text( $error_code );
$error_message = Helpers\get_admin_notice_text( $confirm_error );

// And handle the display.
display_admin_notice_markup( $error_text, 'error' );
display_admin_notice_markup( $error_message, 'error' );
}

/**
Expand Down
Loading

0 comments on commit b22560b

Please sign in to comment.