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