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