PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.4.4.3
Permalink Manager Lite v2.4.4.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 / views / permalink-manager-tools.php
permalink-manager / includes / views Last commit date
permalink-manager-debug.php 1 year ago permalink-manager-permastructs.php 1 year ago permalink-manager-settings.php 1 year ago permalink-manager-tools.php 1 year ago permalink-manager-ui-elements.php 1 year ago permalink-manager-uri-editor-post.php 1 year ago permalink-manager-uri-editor.php 1 year ago
permalink-manager-tools.php
320 lines
1 <?php
2
3 /**
4 * Display the page where the slugs could be regenerated or replaced
5 */
6 class Permalink_Manager_Tools {
7
8 public function __construct() {
9 add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 1 );
10 }
11
12 /**
13 * Add a new section to the Permalink Manager UI
14 *
15 * @param array $admin_sections
16 *
17 * @return array
18 */
19 public function add_admin_section( $admin_sections ) {
20 $admin_sections['tools'] = array(
21 'name' => __( 'Tools', 'permalink-manager' ),
22 'subsections' => array(
23 'duplicates' => array(
24 'name' => __( 'Permalink Duplicates', 'permalink-manager' ),
25 'function' => array( 'class' => 'Permalink_Manager_Tools', 'method' => 'duplicates_output' )
26 ),
27 'find_and_replace' => array(
28 'name' => __( 'Find & Replace', 'permalink-manager' ),
29 'function' => array( 'class' => 'Permalink_Manager_Tools', 'method' => 'find_and_replace_output' )
30 ),
31 'regenerate_slugs' => array(
32 'name' => __( 'Regenerate/Reset', 'permalink-manager' ),
33 'function' => array( 'class' => 'Permalink_Manager_Tools', 'method' => 'regenerate_slugs_output' )
34 ),
35 'stop_words' => array(
36 'name' => __( 'Stop Words', 'permalink-manager' ),
37 'function' => array( 'class' => 'Permalink_Manager_UI_Elements', 'method' => 'pro_text' )
38 ),
39 'import' => array(
40 'name' => __( 'Custom Permalinks', 'permalink-manager' ),
41 'function' => array( 'class' => 'Permalink_Manager_UI_Elements', 'method' => 'pro_text' )
42 )
43 )
44 );
45
46 return $admin_sections;
47 }
48
49 /**
50 * Display a warning message before the user changes the permalinks mode to "Native slugs"
51 *
52 * @return string
53 */
54 public function display_instructions() {
55 return sprintf( '<p><strong>%s</strong>', __( 'A MySQL backup is highly recommended before using "<em>Native slugs</em>" mode!', 'permalink-manager' ) );
56 }
57
58 /**
59 * Display a list of all duplicated URIs and redirects
60 *
61 * @return string
62 */
63 public function duplicates_output() {
64 // Get the duplicates & another variables
65 $all_duplicates = Permalink_Manager_Admin_Functions::get_all_duplicates();
66
67 $button_url = add_query_arg( array(
68 'section' => 'tools',
69 'subsection' => 'duplicates',
70 'clear-permalink-manager-uris' => 1,
71 'permalink-manager-nonce' => wp_create_nonce( 'permalink-manager' )
72 ), Permalink_Manager_Admin_Functions::get_admin_url() );
73
74 $html = sprintf( "<h3>%s</h3>", __( "List of duplicated permalinks", "permalink-manager" ) );
75 $html .= wpautop( sprintf( "<a class=\"button button-primary\" href=\"%s\">%s</a>", $button_url, __( 'Fix custom permalinks & redirects', 'permalink-manager' ) ) );
76
77 if ( ! empty( $all_duplicates ) ) {
78 foreach ( $all_duplicates as $uri => $duplicates ) {
79 $html .= "<div class=\"permalink-manager postbox permalink-manager-duplicate-box\">";
80 $html .= sprintf( '<h4 class="heading"><a href="%1$s" target="_blank">%1$s <span class="dashicons dashicons-external"></span></a></h4>', Permalink_Manager_Core_Functions::control_trailing_slashes( home_url( $uri ) ) );
81 $html .= "<table>";
82
83 foreach ( $duplicates as $item_id ) {
84 $html .= "<tr>";
85
86 // Detect duplicate type
87 preg_match( "/(redirect-([\d]+)_)?(?:(tax-)?([\d]*))/", $item_id, $parts );
88
89 $is_extra_redirect = ( ! empty( $parts[1] ) ) ? true : false;
90 $duplicate_type = ( $is_extra_redirect ) ? __( 'Extra Redirect', 'permalink-manager' ) : __( 'Custom permalink', 'permalink-manager' );
91 $detected_id = $parts[4];
92 // $detected_index = $parts[2];
93 $detected_term = ( ! empty( $parts[3] ) ) ? true : false;
94 $remove_link = ( $is_extra_redirect ) ? sprintf( " <a href=\"%s\"><span class=\"dashicons dashicons-trash\"></span> %s</a>", admin_url( "tools.php?page=permalink-manager&section=tools&subsection=duplicates&remove-redirect={$item_id}" ), __( 'Remove Redirect', 'permalink-manager' ) ) : "";
95
96 // Get term
97 if ( $detected_term && ! empty( $detected_id ) ) {
98 $term = get_term( $detected_id );
99 if ( ! empty( $term->name ) ) {
100 $title = $term->name;
101 $edit_label = "<span class=\"dashicons dashicons-edit\"></span>" . __( "Edit term", "permalink-manager" );
102 $edit_link = get_edit_tag_link( $term->term_id, $term->taxonomy );
103 } else {
104 $title = __( "(Removed term)", "permalink-manager" );
105 $edit_label = "<span class=\"dashicons dashicons-trash\"></span>" . __( "Remove broken URI", "permalink-manager" );
106 $edit_link = admin_url( "tools.php?page=permalink-manager&section=tools&subsection=duplicates&remove-uri=tax-{$detected_id}" );
107 }
108 } // Get post
109 else if ( ! empty( $detected_id ) ) {
110 $post = get_post( $detected_id );
111 if ( ! empty( $post->post_title ) && post_type_exists( $post->post_type ) ) {
112 $title = $post->post_title;
113 $edit_label = "<span class=\"dashicons dashicons-edit\"></span>" . __( "Edit post", "permalink-manager" );
114 $edit_link = get_edit_post_link( $post->ID );
115 } else {
116 $title = __( "(Removed post)", "permalink-manager" );
117 $edit_label = "<span class=\"dashicons dashicons-trash\"></span>" . __( "Remove broken URI", "permalink-manager" );
118 $edit_link = admin_url( "tools.php?page=permalink-manager&section=tools&subsection=duplicates&remove-uri={$detected_id}" );
119 }
120 } else {
121 continue;
122 }
123
124 $html .= sprintf( '<td><a href="%1$s">%2$s</a>%3$s</td><td>%4$s</td><td class="actions"><a href="%1$s">%5$s</a>%6$s</td>', $edit_link, $title, " <small>#{$detected_id}</small>", $duplicate_type, $edit_label, $remove_link );
125 $html .= "</tr>";
126 }
127 $html .= "</table>";
128 $html .= "</div>";
129 }
130 } else {
131 $html .= sprintf( "<p class=\"alert notice-success notice\">%s</p>", __( 'Congratulations! No duplicated URIs or Redirects found!', 'permalink-manager' ) );
132 }
133
134 return $html;
135 }
136
137 /**
138 * Generate a form for "Tools -> Find & replace" tool
139 *
140 * @return string
141 */
142 public function find_and_replace_output() {
143 // Get all registered post types array & statuses
144 $all_post_statuses_array = Permalink_Manager_Helper_Functions::get_post_statuses();
145 $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
146 $all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array();
147
148 $fields = apply_filters( 'permalink_manager_tools_fields', array(
149 'old_string' => array(
150 'label' => __( 'Find ...', 'permalink-manager' ),
151 'type' => 'text',
152 'container' => 'row',
153 'input_class' => 'widefat'
154 ),
155 'new_string' => array(
156 'label' => __( 'Replace with ...', 'permalink-manager' ),
157 'type' => 'text',
158 'container' => 'row',
159 'input_class' => 'widefat'
160 ),
161 'mode' => array(
162 'label' => __( 'Mode', 'permalink-manager' ),
163 'type' => 'select',
164 'container' => 'row',
165 'choices' => array(
166 'custom_uris' => __( 'Custom permalinks', 'permalink-manager' ),
167 'slugs' => __( 'Native slugs', 'permalink-manager' )
168 ),
169 ),
170 'content_type' => array(
171 'label' => __( 'Select content type', 'permalink-manager' ),
172 'type' => 'select',
173 'disabled' => true,
174 'pro' => true,
175 'container' => 'row',
176 'default' => 'post_types',
177 'choices' => array(
178 'post_types' => __( 'Post types', 'permalink-manager' ),
179 'taxonomies' => __( 'Taxonomies', 'permalink-manager' )
180 ),
181 ),
182 'post_types' => array(
183 'label' => __( 'Select post types', 'permalink-manager' ),
184 'type' => 'checkbox',
185 'container' => 'row',
186 'default' => array( 'post', 'page' ),
187 'choices' => $all_post_types,
188 'select_all' => '',
189 'unselect_all' => '',
190 ),
191 'taxonomies' => array(
192 'label' => __( 'Select taxonomies', 'permalink-manager' ),
193 'type' => 'checkbox',
194 'container' => 'row',
195 'container_class' => 'hidden',
196 'default' => array( 'category', 'post_tag' ),
197 'choices' => $all_taxonomies,
198 'pro' => true,
199 'select_all' => '',
200 'unselect_all' => '',
201 ),
202 'post_statuses' => array(
203 'label' => __( 'Select post statuses', 'permalink-manager' ),
204 'type' => 'checkbox',
205 'container' => 'row',
206 'default' => array( 'publish' ),
207 'choices' => $all_post_statuses_array,
208 'select_all' => '',
209 'unselect_all' => '',
210 ),
211 'ids' => array(
212 'label' => __( 'Select IDs', 'permalink-manager' ),
213 'type' => 'text',
214 'container' => 'row',
215 //'disabled' => true,
216 'description' => __( 'To narrow the above filters you can type the post IDs (or ranges) here. E.g. <strong>1-8, 10, 25</strong>.', 'permalink-manager' ),
217 //'pro' => true,
218 'input_class' => 'widefat'
219 ),
220 'preview_mode' => array(
221 'label' => __( 'Preview mode', 'permalink-manager' ),
222 'type' => 'single_checkbox',
223 'container' => 'row',
224 'description' => __( 'Enable this option if you want to review the changes in "read mode" before saving them in the database.', 'permalink-manager' )
225 )
226 ), 'find_and_replace' );
227
228 $sidebar = '<h3>' . __( 'Important notices', 'permalink-manager' ) . '</h3>';
229 $sidebar .= self::display_instructions();
230
231 return Permalink_Manager_UI_Elements::get_the_form( $fields, 'columns-3', array( 'text' => __( 'Find and replace', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'find_and_replace' ), true, 'form-ajax' );
232 }
233
234 /**
235 * Generate a form for "Tools -> Regenerate/reset" tool
236 *
237 * @return string
238 */
239 public function regenerate_slugs_output() {
240 // Get all registered post types array & statuses
241 $all_post_statuses_array = Permalink_Manager_Helper_Functions::get_post_statuses();
242 $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
243 $all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array();
244
245 $fields = apply_filters( 'permalink_manager_tools_fields', array(
246 'mode' => array(
247 'label' => __( 'Mode', 'permalink-manager' ),
248 'type' => 'select',
249 'container' => 'row',
250 'choices' => array(
251 'custom_uris' => __( 'Regenerate custom permalinks', 'permalink-manager' ),
252 'slugs' => __( 'Regenerate native slugs', 'permalink-manager' ),
253 'native' => __( 'Use original URLs as custom permalinks', 'permalink-manager' )
254 ),
255 ),
256 'content_type' => array(
257 'label' => __( 'Select content type', 'permalink-manager' ),
258 'type' => 'select',
259 'disabled' => true,
260 'pro' => true,
261 'container' => 'row',
262 'default' => 'post_types',
263 'choices' => array(
264 'post_types' => __( 'Post types', 'permalink-manager' ),
265 'taxonomies' => __( 'Taxonomies', 'permalink-manager' )
266 ),
267 ),
268 'post_types' => array(
269 'label' => __( 'Select post types', 'permalink-manager' ),
270 'type' => 'checkbox',
271 'container' => 'row',
272 'default' => array( 'post', 'page' ),
273 'choices' => $all_post_types,
274 'select_all' => '',
275 'unselect_all' => '',
276 ),
277 'taxonomies' => array(
278 'label' => __( 'Select taxonomies', 'permalink-manager' ),
279 'type' => 'checkbox',
280 'container' => 'row',
281 'container_class' => 'hidden',
282 'default' => array( 'category', 'post_tag' ),
283 'choices' => $all_taxonomies,
284 'pro' => true,
285 'select_all' => '',
286 'unselect_all' => '',
287 ),
288 'post_statuses' => array(
289 'label' => __( 'Select post statuses', 'permalink-manager' ),
290 'type' => 'checkbox',
291 'container' => 'row',
292 'default' => array( 'publish' ),
293 'choices' => $all_post_statuses_array,
294 'select_all' => '',
295 'unselect_all' => '',
296 ),
297 'ids' => array(
298 'label' => __( 'Select IDs', 'permalink-manager' ),
299 'type' => 'text',
300 'container' => 'row',
301 //'disabled' => true,
302 'description' => __( 'To narrow the above filters you can type the post IDs (or ranges) here. E.g. <strong>1-8, 10, 25</strong>.', 'permalink-manager' ),
303 //'pro' => true,
304 'input_class' => 'widefat'
305 ),
306 'preview_mode' => array(
307 'label' => __( 'Preview mode', 'permalink-manager' ),
308 'type' => 'single_checkbox',
309 'container' => 'row',
310 'description' => __( 'Enable this option if you want to review the changes in "read mode" before saving them in the database.', 'permalink-manager' )
311 )
312 ), 'regenerate' );
313
314 $sidebar = '<h3>' . __( 'Important notices', 'permalink-manager' ) . '</h3>';
315 $sidebar .= self::display_instructions();
316
317 return Permalink_Manager_UI_Elements::get_the_form( $fields, 'columns-3', array( 'text' => __( 'Regenerate', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'regenerate' ), true, 'form-ajax' );
318 }
319 }
320