PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.5.3
Permalink Manager Lite v2.5.3
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 5 months ago permalink-manager-admin-functions.php 5 months ago permalink-manager-core-functions.php 5 months ago permalink-manager-debug.php 5 months ago permalink-manager-gutenberg.php 5 months ago permalink-manager-helper-functions.php 5 months ago permalink-manager-permastructures-functions.php 5 months ago permalink-manager-uri-functions-post.php 5 months ago permalink-manager-uri-functions.php 5 months ago
permalink-manager-debug.php
189 lines
1 <?php
2
3 /**
4 * Additional debug functions for "Permalink Manager Pro"
5 */
6 class Permalink_Manager_Debug_Functions {
7
8 public function __construct() {
9 add_action( 'init', array( $this, 'debug_data' ), 99 );
10 }
11
12 /**
13 * Map the debug functions to specific hooks
14 */
15 public function debug_data() {
16 global $permalink_manager_options;
17
18 if ( ! empty( $permalink_manager_options['general']['debug_mode'] ) || current_user_can( 'manage_options' ) ) {
19 add_filter( 'permalink_manager_filter_query', array( $this, 'debug_query' ), 9, 5 );
20 add_filter( 'permalink_manager_filter_redirect', array( $this, 'debug_redirect' ), 9, 3 );
21 add_filter( 'wp_redirect', array( $this, 'debug_wp_redirect' ), 9, 2 );
22
23 if ( current_user_can( 'manage_options' ) ) {
24 self::debug_custom_fields();
25 }
26 }
27 }
28
29 /**
30 * Debug the WordPress query filtered in the Permalink_Manager_Core_Functions::detect_post(); function
31 *
32 * @param array $query
33 * @param array $old_query
34 * @param array $uri_parts
35 * @param array $pm_query
36 * @param string $content_type
37 *
38 * @return array
39 */
40 public function debug_query( $query, $old_query = null, $uri_parts = null, $pm_query = null, $content_type = null ) {
41 global $permalink_manager;
42
43 if ( isset( $_REQUEST['debug_url'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here
44 $debug_info['uri_parts'] = $uri_parts;
45 $debug_info['old_query_vars'] = $old_query;
46 $debug_info['new_query_vars'] = $query;
47 $debug_info['pm_query'] = ( ! empty( $pm_query['id'] ) ) ? $pm_query['id'] : "-";
48 $debug_info['content_type'] = ( ! empty( $content_type ) ) ? $content_type : "-";
49
50 // License key info
51 if ( class_exists( 'Permalink_Manager_Pro_License' ) ) {
52 $license_key = $permalink_manager->functions['pro-license']->get_license_key();
53
54 // Mask the license key
55 $debug_info['license_key'] = preg_replace( '/([^-]+)-([^-]+)-([^-]+)-([^-]+)$/', '***-***-$3', $license_key );
56 }
57
58 // Plugin version
59 $debug_info['version'] = PERMALINK_MANAGER_VERSION;
60
61 self::display_debug_data( $debug_info );
62 }
63
64 return $query;
65 }
66
67 /**
68 * Debug the redirect controlled by Permalink_Manager_Core_Functions::new_uri_redirect_and_404();
69 *
70 * @param string $correct_permalink
71 * @param string $redirect_type
72 * @param mixed $queried_object
73 *
74 * @return string
75 */
76 public function debug_redirect( $correct_permalink, $redirect_type, $queried_object ) {
77 if ( isset( $_REQUEST['debug_redirect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here
78 $debug_info['redirect_url'] = ( ! empty( $correct_permalink ) ) ? $correct_permalink : '-';
79 $debug_info['redirect_type'] = ( ! empty( $redirect_type ) ) ? $redirect_type : "-";
80
81 self::display_debug_data( $debug_info );
82 }
83
84 return $correct_permalink;
85 }
86
87 /**
88 * Debug wp_redirect() function used in 3rd party plugins
89 *
90 * @param string $url
91 * @param string $status
92 *
93 * @return string
94 */
95 public function debug_wp_redirect( $url, $status ) {
96 if ( isset( $_GET['debug_wp_redirect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No data is saved here
97 $debug_info['url'] = $url;
98 $debug_info['status'] = $status;
99 $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
100
101 self::display_debug_data( $debug_info );
102 }
103
104 return $url;
105 }
106
107 /**
108 * Display the list of all custom fields assigned to specific post
109 */
110 public static function debug_custom_fields() {
111 global $pagenow;
112
113 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- No data is saved here
114 if ( ! isset( $_GET['debug_custom_fields'] ) ) {
115 return;
116 }
117
118 if ( $pagenow == 'post.php' && isset( $_GET['post'] ) ) {
119 $post_id = intval( $_GET['post'] );
120 $custom_fields = get_post_meta( $post_id );
121 }
122
123 if ( $pagenow == 'term.php' && isset( $_GET['tag_ID'] ) ) {
124 $term_id = intval( $_GET['tag_ID'] );
125
126 $custom_fields = get_term_meta( $term_id );
127 }
128 // phpcs:enable WordPress.Security.NonceVerification.Recommended
129
130 if ( isset ( $custom_fields ) ) {
131 self::display_debug_data( $custom_fields );
132 }
133 }
134
135 /**
136 * A helper function used to display the debug data in various functions
137 *
138 * @param mixed $debug_info
139 */
140 public static function display_debug_data( $debug_info ) {
141 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- print_r() is a part of debug tool
142 $debug_txt = print_r( $debug_info, true );
143 $debug_txt = sprintf( "<pre style=\"display:block;\">%s</pre>", esc_html( $debug_txt ) );
144
145 wp_die( wp_kses_post( $debug_txt ) );
146 }
147
148 /**
149 * Generate a CSV file from array
150 *
151 * @param array $array
152 * @param string $filename
153 */
154 public static function output_csv( $array, $filename = 'debug.csv', $delimiter = ',' ) {
155 if ( count( $array ) == 0 ) {
156 return null;
157 }
158
159 // Disable caching
160 $now = gmdate( "D, d M Y H:i:s" );
161 header( "Expires: Tue, 03 Jul 2001 06:00:00 GMT" );
162 header( "Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate" );
163 header( "Last-Modified: {$now} GMT" );
164
165 // Force download
166 header( "Content-Type: application/force-download" );
167 header( "Content-Type: application/octet-stream" );
168 header( "Content-Type: application/download" );
169 header( 'Content-Type: text/csv; charset=utf-8' );
170
171 // Disposition / encoding on response body
172 header( "Content-Disposition: attachment;filename={$filename}" );
173 header( "Content-Transfer-Encoding: binary" );
174
175 $df = fopen( "php://output", 'w' );
176
177 // Use the same delimiter for headers and data
178 fputcsv( $df, array_keys( reset( $array ) ), $delimiter );
179 foreach ( $array as $row ) {
180 fputcsv( $df, $row, $delimiter );
181 }
182
183 fclose( $df ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
184
185 die();
186 }
187
188 }
189