| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
// phpcs Note: This file is only loaded if WP_DEBUG is enabled |
| 5 |
|
| 6 |
// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 7 |
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_dump, WordPress.PHP.DevelopmentFunctions.error_log_var_dump |
| 8 |
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace |
| 9 |
// phpcs:disable PublishPressStandards.Debug.DisallowDebugFunctions.FoundVarDumpFunction, |
| 10 |
|
| 11 |
add_action('admin_footer', 'presspermit_echo_usage_message', 50); |
| 12 |
|
| 13 |
function presspermit_usage_message($translate = true) |
| 14 |
{ |
| 15 |
if (function_exists('memory_get_usage')) { |
| 16 |
if ($translate) |
| 17 |
return sprintf(esc_html__('%1$s queries in %2$s seconds. %3$s MB used.', 'press-permit-core'), get_num_queries(), timer_stop(0, 2), round(memory_get_usage() / (1024 * 1024), 3), 'press-permit-core') . ' '; |
| 18 |
else |
| 19 |
return get_num_queries() . ' queries in ' . timer_stop(0, 2) . ' seconds. ' . round(memory_get_usage() / (1024 * 1024), 3) . ' MB used. '; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
function presspermit_echo_usage_message($translate = true) |
| 24 |
{ |
| 25 |
if (!defined('PUBLISHPRESS_REVISIONS_VERSION') && !defined('REVISIONARY_VERSION') && !defined('PRESSPERMIT_USAGE_MESSAGE_DONE') && !defined('AGP_NO_USAGE_MSG')) { // Revisionary outputs its own message |
| 26 |
echo '<p style="text-align:center">' . esc_html(presspermit_usage_message($translate)) . '</p>'; |
| 27 |
define('PRESSPERMIT_USAGE_MESSAGE_DONE', true); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function presspermit_editing_plugin() |
| 32 |
{ |
| 33 |
// avoid lockout in case of erroneous plugin edit via wp-admin |
| 34 |
global $pagenow; |
| 35 |
|
| 36 |
if (is_admin() && isset($pagenow) && ('plugin-editor.php' == $pagenow)) { |
| 37 |
require_once(PRESSPERMIT_ABSPATH . '/functions.php'); |
| 38 |
|
| 39 |
if (!PWP::is_REQUEST('action', ['activate', 'deactivate'])) { |
| 40 |
return true; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
if (!function_exists('pp_debug_echo')) { |
| 48 |
function pp_debug_echo($str) |
| 49 |
{ |
| 50 |
if (!constant('PRESSPERMIT_DEBUG')) |
| 51 |
return; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if (!function_exists('pp_errlog')) { |
| 56 |
function pp_errlog($msg, $line_break = true) |
| 57 |
{ |
| 58 |
if (!constant('PRESSPERMIT_DEBUG')) |
| 59 |
return; |
| 60 |
|
| 61 |
if (is_array($msg) || is_object($msg)) |
| 62 |
$msg = serialize($msg); |
| 63 |
|
| 64 |
$append = ($line_break) ? "\r\n" : ''; |
| 65 |
|
| 66 |
if (defined('PRESSPERMIT_DEBUG_LOGFILE')) |
| 67 |
error_log($msg . $append, 3, PRESSPERMIT_DEBUG_LOGFILE); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
if (!function_exists('pp_backtrace_dump')) { |
| 72 |
function pp_backtrace_dump($die = true) |
| 73 |
{ |
| 74 |
if (!constant('PRESSPERMIT_DEBUG')) |
| 75 |
return; |
| 76 |
|
| 77 |
$bt = debug_backtrace(); |
| 78 |
var_dump($bt); |
| 79 |
|
| 80 |
if ($die) |
| 81 |
die; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
if (!function_exists('_pp_memory_new_usage')) { |
| 87 |
function _pp_memory_new_usage() |
| 88 |
{ |
| 89 |
if (!constant('PRESSPERMIT_DEBUG') || !defined('PRESSPERMIT_MEMORY_LOG') || !PRESSPERMIT_MEMORY_LOG) |
| 90 |
return; |
| 91 |
|
| 92 |
static $last_mem_usage; |
| 93 |
|
| 94 |
if (!isset($last_mem_usage)) |
| 95 |
$last_mem_usage = 0; |
| 96 |
|
| 97 |
$current_mem_usage = memory_get_usage(true); |
| 98 |
$new_mem_usage = $current_mem_usage - $last_mem_usage; |
| 99 |
$last_mem_usage = $current_mem_usage; |
| 100 |
|
| 101 |
return $new_mem_usage; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
if (!function_exists('pp_log_mem_usage')) { |
| 106 |
function pp_log_mem_usage($label, $display_total = true) |
| 107 |
{ |
| 108 |
if (!constant('PRESSPERMIT_DEBUG') || !defined('PRESSPERMIT_MEMORY_LOG') || !PRESSPERMIT_MEMORY_LOG) |
| 109 |
return; |
| 110 |
|
| 111 |
$total = $display_total ? " (" . memory_get_usage(true) . ")" : ''; |
| 112 |
|
| 113 |
pp_errlog($label); |
| 114 |
pp_errlog(_pp_memory_new_usage() . $total); |
| 115 |
pp_errlog(''); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if (!function_exists('pp_dump')) { |
| 120 |
function pp_dump(&$var, $info = FALSE, $display_objects = true) |
| 121 |
{ |
| 122 |
var_dump($var); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
if (!function_exists('do_dump')) { |
| 127 |
function do_pp_dump(&$var, $display_objects = true, $var_name = NULL, $indent = NULL, $reference = NULL) |
| 128 |
{ |
| 129 |
var_dump($var); |
| 130 |
} |
| 131 |
} |
| 132 |
|