PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.5.4
Permalink Manager Lite v2.5.4
2.5.4 2.5.3.4 2.2.18 2.2.19.2 2.2.19.3 2.2.19.3.1 2.2.2 2.2.20 2.2.20.1 2.2.20.3 2.2.4 2.2.5 2.2.6 2.2.7.2 2.2.7.3 2.2.7.5 2.2.7.6 2.2.8.4 2.2.8.5 2.2.8.6 2.2.8.7 2.2.8.9 2.2.9.1 2.2.9.2 2.2.9.2.1 2.2.9.3 2.2.9.4 2.2.9.6 2.2.9.7 2.2.9.9 2.3.0 2.3.1.1 2.4.0 2.4.1 2.4.1.2 2.4.1.3 2.4.1.4 2.4.1.5 2.4.1.6 2.4.2 2.4.2.1 2.4.3 2.4.3.1 2.4.3.2 2.4.3.3 2.4.3.4 2.4.4 2.4.4.1 2.4.4.2 2.4.4.3 2.5.0 2.5.1 2.5.1.1 2.5.1.2 2.5.1.3 2.5.1.4 2.5.2 2.5.2.1 2.5.2.2 2.5.2.3 2.5.2.4 2.5.3 2.5.3.1 2.5.3.2 2.5.3.3 trunk 0.2 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.4.8 0.4.9 0.5.3 0.5.4 1.0.0 1.0.1 1.0.4 1.1.0 1.1.1 1.1.2 1.11.6.3 2.0.0 2.0.3 2.0.4 2.0.4.3 2.0.5.1 2.0.5.2 2.0.5.3 2.0.5.3.1 2.0.5.4 2.0.5.4a 2.0.5.5 2.0.5.6 2.0.5.6.1 2.0.5.7 2.0.5.9a 2.0.6.2.1 2.0.6.2a 2.0.6.3 2.1.0 2.1.1 2.1.2.4 2.2.0 2.2.1.1 2.2.1.2 2.2.11 2.2.12 2.2.13.1 2.2.14 2.2.15.1 2.2.16 2.2.17
permalink-manager / includes / core / permalink-manager-debug.php
permalink-manager / includes / core Last commit date
permalink-manager-actions.php 2 days ago permalink-manager-admin-functions.php 2 days ago permalink-manager-core-functions.php 2 days ago permalink-manager-debug.php 2 days ago permalink-manager-gutenberg.php 2 days ago permalink-manager-helper-functions.php 2 days ago permalink-manager-permastructures-functions.php 2 days ago permalink-manager-uri-functions-post.php 2 days ago permalink-manager-uri-functions.php 2 days ago
permalink-manager-debug.php
203 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Additional debug functions for "Permalink Manager Pro"
9 */
10 class Permalink_Manager_Debug_Functions {
11
12 public function __construct() {
13 add_action( 'init', array( $this, 'debug_data' ), 99 );
14 }
15
16 /**
17 * Map the debug functions to specific hooks
18 */
19 public function debug_data() {
20 global $permalink_manager_options;
21
22 if ( ! empty( $permalink_manager_options['general']['debug_mode'] ) || current_user_can( 'manage_options' ) ) {
23 add_filter( 'permalink_manager_filter_query', array( $this, 'debug_query' ), 9, 5 );
24 add_filter( 'permalink_manager_filter_redirect', array( $this, 'debug_redirect' ), 9, 3 );
25 add_filter( 'wp_redirect', array( $this, 'debug_wp_redirect' ), 9, 2 );
26
27 if ( current_user_can( 'manage_options' ) ) {
28 self::debug_custom_fields();
29 }
30 }
31 }
32
33 /**
34 * Debug the WordPress query filtered in the Permalink_Manager_Core_Functions::detect_post(); function
35 *
36 * @param array $query
37 * @param array $old_query
38 * @param array $uri_parts
39 * @param array $pm_query
40 * @param string $content_type
41 *
42 * @return array
43 */
44 public function debug_query( $query, $old_query = null, $uri_parts = null, $pm_query = null, $content_type = null ) {
45 global $permalink_manager;
46
47 if ( isset( $_REQUEST['debug_url'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here
48 $debug_info['uri_parts'] = $uri_parts;
49 $debug_info['old_query_vars'] = $old_query;
50 $debug_info['new_query_vars'] = $query;
51 $debug_info['pm_query'] = ( ! empty( $pm_query['id'] ) ) ? $pm_query['id'] : "-";
52 $debug_info['content_type'] = ( ! empty( $content_type ) ) ? $content_type : "-";
53
54 // License key info
55 if ( class_exists( 'Permalink_Manager_Pro_License' ) ) {
56 $license_key = $permalink_manager->functions['pro-license']->get_license_key();
57
58 // Mask the license key
59 $debug_info['license_key'] = preg_replace( '/([^-]+)-([^-]+)-([^-]+)-([^-]+)$/', '***-***-$3', $license_key );
60 }
61
62 // Plugin version
63 $debug_info['version'] = PERMALINK_MANAGER_VERSION;
64
65 self::display_debug_data( $debug_info );
66 }
67
68 return $query;
69 }
70
71 /**
72 * Debug the redirect controlled by Permalink_Manager_Core_Functions::new_uri_redirect_and_404();
73 *
74 * @param string $correct_permalink
75 * @param string $redirect_type
76 * @param mixed $queried_object
77 *
78 * @return string
79 */
80 public function debug_redirect( $correct_permalink, $redirect_type, $queried_object ) {
81 if ( isset( $_REQUEST['debug_redirect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here
82 $debug_info['redirect_url'] = ( ! empty( $correct_permalink ) ) ? $correct_permalink : '-';
83 $debug_info['redirect_type'] = ( ! empty( $redirect_type ) ) ? $redirect_type : "-";
84
85 self::display_debug_data( $debug_info );
86 }
87
88 return $correct_permalink;
89 }
90
91 /**
92 * Debug wp_redirect() function used in 3rd party plugins
93 *
94 * @param string $url
95 * @param string $status
96 *
97 * @return string
98 */
99 public function debug_wp_redirect( $url, $status ) {
100 if ( isset( $_GET['debug_wp_redirect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here
101 $debug_info['url'] = $url;
102 $debug_info['status'] = $status;
103 $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
104
105 self::display_debug_data( $debug_info );
106 }
107
108 return $url;
109 }
110
111 /**
112 * Display the list of all custom fields assigned to specific post
113 */
114 public static function debug_custom_fields() {
115 global $pagenow;
116
117 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- No data is saved here
118 if ( ! isset( $_GET['debug_custom_fields'] ) ) {
119 return;
120 }
121
122 if ( $pagenow == 'post.php' && isset( $_GET['post'] ) ) {
123 $post_id = intval( $_GET['post'] );
124 $custom_fields = get_post_meta( $post_id );
125 }
126
127 if ( $pagenow == 'term.php' && isset( $_GET['tag_ID'] ) ) {
128 $term_id = intval( $_GET['tag_ID'] );
129
130 $custom_fields = get_term_meta( $term_id );
131 }
132 // phpcs:enable WordPress.Security.NonceVerification.Recommended
133
134 if ( isset ( $custom_fields ) ) {
135 self::display_debug_data( $custom_fields );
136 }
137 }
138
139 /**
140 * A helper function used to prepare the debug data
141 *
142 * @param mixed $debug_info
143 */
144 public static function prepare_debug_data( $debug_info, $wrap_in_pre = false ) {
145 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- print_r() is a part of debug tool
146 $debug_txt = print_r( $debug_info, true );
147
148 return ( $wrap_in_pre ) ? sprintf( '<pre style="display:block;">%s</pre>', esc_html( $debug_txt ) ) : ( $debug_txt );
149 }
150
151 /**
152 * A helper function used to display the debug data in various functions
153 *
154 * @param mixed $debug_info
155 */
156 public static function display_debug_data( $debug_info ) {
157 $debug_txt = self::prepare_debug_data( $debug_info, true );
158
159 wp_die( wp_kses_post( $debug_txt ) );
160 }
161
162 /**
163 * Generate a CSV file from array
164 *
165 * @param array $array
166 * @param string $filename
167 */
168 public static function output_csv( $array, $filename = 'debug.csv', $delimiter = ',' ) {
169 if ( count( $array ) == 0 ) {
170 return null;
171 }
172
173 // Disable caching
174 $now = gmdate( "D, d M Y H:i:s" );
175 header( "Expires: Tue, 03 Jul 2001 06:00:00 GMT" );
176 header( "Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate" );
177 header( "Last-Modified: {$now} GMT" );
178
179 // Force download
180 header( "Content-Type: application/force-download" );
181 header( "Content-Type: application/octet-stream" );
182 header( "Content-Type: application/download" );
183 header( 'Content-Type: text/csv; charset=utf-8' );
184
185 // Disposition / encoding on response body
186 header( "Content-Disposition: attachment;filename={$filename}" );
187 header( "Content-Transfer-Encoding: binary" );
188
189 $df = fopen( "php://output", 'w' );
190
191 // Use the same delimiter for headers and data
192 fputcsv( $df, array_keys( reset( $array ) ), $delimiter );
193 foreach ( $array as $row ) {
194 fputcsv( $df, $row, $delimiter );
195 }
196
197 fclose( $df ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
198
199 die();
200 }
201
202 }
203