admin
2 months ago
compat
2 months ago
class-bwt-api-handler.php
4 months ago
class-bwt-connect.php
7 months ago
class-gsc-api-handler.php
4 months ago
class-gsc-connect.php
4 months ago
class-gsc-oauth-handler.php
7 months ago
class-secret.php
7 months ago
class-sitemap-core.php
7 months ago
class-sitemap-news.php
3 months ago
class-sitemap-plugin.php
3 months ago
class-sitemap.php
2 months ago
class-sitemaps-provider-custom.php
7 months ago
class-sitemaps-provider-external.php
7 months ago
class-sitemaps-provider-news.php
7 months ago
class-xmlsitemapfeed.php
3 months ago
functions-debugging.php
1 year ago
functions-pluggable.php
1 year ago
functions.php
3 months ago
translations.php
4 months ago
functions-debugging.php
101 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Debugging Functions |
| 4 | * |
| 5 | * @package XML Sitemap & Google News |
| 6 | * @since 5.4 |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Error messages for Nginx Helper Purge URLs |
| 11 | * |
| 12 | * @param array $urls Purged URLs. |
| 13 | */ |
| 14 | function xmlsf_debug_nginx_helper_purge_urls( $urls ) { |
| 15 | if ( ! WP_DEBUG_LOG ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | error_log( 'NGINX Helper purge urls array:' ); |
| 20 | error_log( print_r( $urls, true ) ); |
| 21 | } |
| 22 | |
| 23 | add_action( 'xmlsf_nginx_helper_purge_urls', 'xmlsf_debug_nginx_helper_purge_urls' ); |
| 24 | |
| 25 | /** |
| 26 | * Usage info for debugging |
| 27 | * |
| 28 | * @since 5.4 |
| 29 | * @return void |
| 30 | */ |
| 31 | function xmlsf_debug_usage() { |
| 32 | global $wpdb, $EZSQL_ERROR; |
| 33 | |
| 34 | $num = get_num_queries(); |
| 35 | $limit = ini_get( 'memory_limit' ); |
| 36 | |
| 37 | // Query errors. |
| 38 | $err = 'None encountered.'; |
| 39 | if ( is_array( $EZSQL_ERROR ) && count( $EZSQL_ERROR ) ) { |
| 40 | $err = ''; |
| 41 | $i = 1; |
| 42 | foreach ( $EZSQL_ERROR as $e ) { |
| 43 | $err .= PHP_EOL . $i . ': ' . implode( PHP_EOL, $e ) . PHP_EOL; |
| 44 | ++$i; |
| 45 | } |
| 46 | } |
| 47 | // Saved queries. |
| 48 | if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { |
| 49 | $saved = PHP_EOL . print_r( $wpdb->queries, true ); |
| 50 | } else { |
| 51 | $saved = 'Set SAVEQUERIES to show saved database queries here.'; |
| 52 | } |
| 53 | // Memory usage. |
| 54 | if ( function_exists( 'memory_get_peak_usage' ) ) { |
| 55 | $mem = round( memory_get_peak_usage() / 1024 / 1024, 2 ) . 'M'; |
| 56 | } else { |
| 57 | $mem = 'Not availabe.'; |
| 58 | } |
| 59 | // System load. |
| 60 | if ( function_exists( 'sys_getloadavg' ) ) { |
| 61 | $load = sys_getloadavg()[0]; |
| 62 | } else { |
| 63 | $load = 'Not available.'; |
| 64 | } |
| 65 | |
| 66 | echo '<!-- Queries executed: ' . esc_xml( $num ) . ' | Peak memory usage: ' . esc_xml( $mem ) . '| Memory limit: ' . esc_xml( $limit ) . ' -->' . PHP_EOL; |
| 67 | echo '<!-- Query errors: ' . esc_xml( $err ) . ' -->' . PHP_EOL; |
| 68 | echo '<!-- Queries: ' . $saved . ' -->' . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 69 | echo '<!-- Average system load during the last minute: ' . esc_xml( $load ) . ' -->' . PHP_EOL; |
| 70 | } |
| 71 | |
| 72 | add_action( |
| 73 | 'xmlsf_sitemap_loaded', |
| 74 | function () { |
| 75 | WP_DEBUG_LOG && add_action( 'shutdown', 'xmlsf_debug_usage' ); |
| 76 | } |
| 77 | ); |
| 78 | |
| 79 | add_action( |
| 80 | 'xmlsf_sitemap_news_loaded', |
| 81 | function () { |
| 82 | WP_DEBUG_LOG && add_action( 'shutdown', 'xmlsf_debug_usage' ); |
| 83 | } |
| 84 | ); |
| 85 | |
| 86 | add_action( |
| 87 | 'xmlsf_install', |
| 88 | function () { |
| 89 | // Kilroy was here. |
| 90 | WP_DEBUG_LOG && error_log( 'XML Sitemap Feeds version ' . XMLSF_VERSION . ' installed.' ); |
| 91 | } |
| 92 | ); |
| 93 | |
| 94 | add_action( |
| 95 | 'xmlsf_upgrade', |
| 96 | function ( $db_version ) { |
| 97 | // Kilroy was here. |
| 98 | WP_DEBUG_LOG && error_log( 'XML Sitemap Feeds upgraded from ' . $db_version . ' to ' . XMLSF_VERSION ); |
| 99 | } |
| 100 | ); |
| 101 |