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