functions['pro-license']->get_license_key(); // Mask the license key $debug_info['license_key'] = preg_replace( '/([^-]+)-([^-]+)-([^-]+)-([^-]+)$/', '***-***-$3', $license_key ); } // Plugin version $debug_info['version'] = PERMALINK_MANAGER_VERSION; self::display_debug_data( $debug_info ); } return $query; } /** * Debug the redirect controlled by Permalink_Manager_Core_Functions::new_uri_redirect_and_404(); * * @param string $correct_permalink * @param string $redirect_type * @param mixed $queried_object * * @return string */ public function debug_redirect( $correct_permalink, $redirect_type, $queried_object ) { if ( isset( $_REQUEST['debug_redirect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here $debug_info['redirect_url'] = ( ! empty( $correct_permalink ) ) ? $correct_permalink : '-'; $debug_info['redirect_type'] = ( ! empty( $redirect_type ) ) ? $redirect_type : "-"; self::display_debug_data( $debug_info ); } return $correct_permalink; } /** * Debug wp_redirect() function used in 3rd party plugins * * @param string $url * @param string $status * * @return string */ public function debug_wp_redirect( $url, $status ) { if ( isset( $_GET['debug_wp_redirect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here $debug_info['url'] = $url; $debug_info['status'] = $status; $debug_info['backtrace'] = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 10 ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- Backtrace is a part of debug tools self::display_debug_data( $debug_info ); } return $url; } /** * Display the list of all custom fields assigned to specific post */ public static function debug_custom_fields() { global $pagenow; // phpcs:disable WordPress.Security.NonceVerification.Recommended -- No data is saved here if ( ! isset( $_GET['debug_custom_fields'] ) ) { return; } if ( $pagenow == 'post.php' && isset( $_GET['post'] ) ) { $post_id = intval( $_GET['post'] ); $custom_fields = get_post_meta( $post_id ); } if ( $pagenow == 'term.php' && isset( $_GET['tag_ID'] ) ) { $term_id = intval( $_GET['tag_ID'] ); $custom_fields = get_term_meta( $term_id ); } // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( isset ( $custom_fields ) ) { self::display_debug_data( $custom_fields ); } } /** * A helper function used to display the debug data in various functions * * @param mixed $debug_info */ public static function display_debug_data( $debug_info ) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- print_r() is a part of debug tool $debug_txt = print_r( $debug_info, true ); $debug_txt = sprintf( "
%s", esc_html( $debug_txt ) ); wp_die( wp_kses_post( $debug_txt ) ); } /** * Generate a CSV file from array * * @param array $array * @param string $filename */ public static function output_csv( $array, $filename = 'debug.csv', $delimiter = ',' ) { if ( count( $array ) == 0 ) { return null; } // Disable caching $now = gmdate( "D, d M Y H:i:s" ); header( "Expires: Tue, 03 Jul 2001 06:00:00 GMT" ); header( "Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate" ); header( "Last-Modified: {$now} GMT" ); // Force download header( "Content-Type: application/force-download" ); header( "Content-Type: application/octet-stream" ); header( "Content-Type: application/download" ); header( 'Content-Type: text/csv; charset=utf-8' ); // Disposition / encoding on response body header( "Content-Disposition: attachment;filename={$filename}" ); header( "Content-Transfer-Encoding: binary" ); $df = fopen( "php://output", 'w' ); // Use the same delimiter for headers and data fputcsv( $df, array_keys( reset( $array ) ), $delimiter ); foreach ( $array as $row ) { fputcsv( $df, $row, $delimiter ); } fclose( $df ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose die(); } }