PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.5.1
Permalink Manager Lite v2.5.1
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-uri-editor-post.php
permalink-manager / includes / views Last commit date
permalink-manager-debug.php 1 year ago permalink-manager-permastructures.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-uri-editor-post.php
327 lines
1 <?php
2
3 /**
4 * Use WP_List_Table to display the "Bulk URI Editor" for post items
5 */
6 class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
7
8 public $displayed_post_types, $displayed_post_statuses;
9
10 public function __construct() {
11 global $permalink_manager_options, $active_subsection;
12
13 parent::__construct( array(
14 'singular' => 'slug',
15 'plural' => 'slugs'
16 ) );
17
18 $this->displayed_post_statuses = ( isset( $permalink_manager_options['screen-options']['post_statuses'] ) ) ? "'" . implode( "', '", $permalink_manager_options['screen-options']['post_statuses'] ) . "'" : "'no-post-status'";
19 $this->displayed_post_types = ( $active_subsection == 'all' ) ? "'" . implode( "', '", $permalink_manager_options['screen-options']['post_types'] ) . "'" : "'{$active_subsection}'";
20 }
21
22 /**
23 * Get the HTML output with the whole WP_List_Table
24 *
25 * @return string
26 */
27 public function display_admin_section() {
28 $output = "<form id=\"permalinks-post-types-table\" class=\"slugs-table\" method=\"post\">";
29 $output .= wp_nonce_field( 'permalink-manager', 'uri_editor' );
30 $output .= Permalink_Manager_UI_Elements::generate_option_field( 'pm_session_id', array( 'value' => uniqid(), 'type' => 'hidden' ) );
31
32 // Bypass
33 ob_start();
34
35 $this->prepare_items();
36 $this->display();
37 $output .= ob_get_contents();
38
39 ob_end_clean();
40
41 $output .= "</form>";
42
43 return $output;
44 }
45
46 /**
47 * Return an array of classes to be used in the HTML table
48 *
49 * @return array
50 */
51 function get_table_classes() {
52 return array( 'widefat', 'striped', $this->_args['plural'] );
53 }
54
55 /**
56 * Add columns to the table
57 *
58 * @return array
59 */
60 public function get_columns() {
61 return apply_filters( 'permalink_manager_uri_editor_columns', array(
62 'item_title' => __( 'Post title', 'permalink-manager' ),
63 'item_uri' => __( 'Custom permalink', 'permalink-manager' )
64 ) );
65 }
66
67 /**
68 * Define sortable columns
69 *
70 * @return array
71 */
72 public function get_sortable_columns() {
73 return array(
74 'item_title' => array( 'post_title', false )
75 );
76 }
77
78 /**
79 * Data inside the columns
80 *
81 * @param array $item
82 * @param string $column_name
83 *
84 * @return string
85 */
86 public function column_default( $item, $column_name ) {
87 global $permalink_manager_options;
88
89 if ( Permalink_Manager_Helper_Functions::is_front_page( $item['ID'] ) ) {
90 $uri = '';
91 $permalink = Permalink_Manager_Helper_Functions::get_permalink_base( $item['ID'] );
92 $is_front_page = true;
93 } else {
94 $is_draft = ( $item["post_status"] == 'draft' ) ? true : false;
95 $uri = Permalink_Manager_URI_Functions_Post::get_post_uri( $item['ID'], true, $is_draft );
96 $uri = ( ! empty( $permalink_manager_options['general']['decode_uris'] ) ) ? urldecode( $uri ) : $uri;
97 $permalink = get_permalink( $item['ID'] );
98 $is_front_page = false;
99 }
100
101 $field_args_base = array( 'type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => 'custom_uri', 'extra_atts' => "data-element-id=\"{$item['ID']}\"" );
102 $post_title = sanitize_text_field( $item['post_title'] );
103
104 $post_statuses_array = Permalink_Manager_Helper_Functions::get_post_statuses();
105 $post_statuses_array['inherit'] = __( 'Inherit (Attachment)', 'permalink-manager' );
106
107 $output = apply_filters( 'permalink_manager_uri_editor_column_content', '', $column_name, get_post( $item['ID'] ) );
108 if ( ! empty( $output ) ) {
109 return $output;
110 }
111
112 switch ( $column_name ) {
113 case 'item_uri':
114 // Get auto-update settings
115 $auto_update_val = get_post_meta( $item['ID'], "auto_update_uri", true );
116 $auto_update_uri = ( ! empty( $auto_update_val ) ) ? $auto_update_val : $permalink_manager_options["general"]["auto_update_uris"];
117
118 if ( $is_front_page ) {
119 $field_args_base['disabled'] = true;
120 $field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor is disabled because a custom permalink cannot be set for a front page.', 'permalink-manager' ) );
121 } else if ( Permalink_Manager_Helper_Functions::is_draft_excluded( (int) $item['ID'] ) ) {
122 $field_args_base['disabled'] = true;
123 $field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor disabled due to "Exclude drafts & pending posts" setting and the post status.', 'permalink-manager' ) );
124 } else if ( $auto_update_uri == 1 ) {
125 $field_args_base['readonly'] = true;
126 $field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'The above permalink will be automatically updated and is locked for editing.', 'permalink-manager' ) );
127 } else if ( $auto_update_uri == 2 ) {
128 $field_args_base['disabled'] = true;
129 $field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor disabled due to "Permalink update" setting.', 'permalink-manager' ) );
130 }
131
132 $output = '<div class="custom_uri_container">';
133 $output .= Permalink_Manager_UI_Elements::generate_option_field( "uri[{$item['ID']}]", $field_args_base );
134 $output .= "<span class=\"duplicated_uri_alert\"></span>";
135 $output .= sprintf( "<a class=\"small post_permalink\" href=\"%s\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> %s</a>", $permalink, urldecode( $permalink ) );
136 $output .= '</div>';
137
138 return $output;
139
140 case 'item_title':
141 $output = $post_title;
142 $output .= '<div class="extra-info small">';
143 $output .= sprintf( "<span><strong>%s:</strong> %s</span>", __( "Slug", "permalink-manager" ), urldecode( $item['post_name'] ) );
144 $output .= sprintf( " | <span><strong>%s:</strong> {$post_statuses_array[$item["post_status"]]}</span>", __( "Post status", "permalink-manager" ) );
145 $output .= apply_filters( 'permalink_manager_uri_editor_extra_info', '', $column_name, get_post( $item['ID'] ) );
146 $output .= '</div>';
147
148 $output .= '<div class="row-actions">';
149 $output .= sprintf( "<span class=\"edit\"><a href=\"%s\" title=\"%s\">%s</a> | </span>", get_edit_post_link( $item['ID'] ), __( 'Edit', 'permalink-manager' ), __( 'Edit', 'permalink-manager' ) );
150 $output .= '<span class="view"><a target="_blank" href="' . $permalink . '" title="' . __( 'View', 'permalink-manager' ) . ' ' . $post_title . '" rel="permalink">' . __( 'View', 'permalink-manager' ) . '</a> | </span>';
151 $output .= '<span class="id">#' . $item['ID'] . '</span>';
152 $output .= '</div>';
153
154 return $output;
155
156 default:
157 return $item[ $column_name ];
158 }
159 }
160
161 /**
162 * The button that allows to save updated slugs
163 */
164 function extra_tablenav( $which ) {
165 global $wpdb, $active_section, $active_subsection;
166
167 if ( $which == "top" ) {
168 $button_text = __( 'Save all the permalinks below', 'permalink-manager' );
169 $button_name = 'update_all_slugs[top]';
170 } else {
171 $button_text = __( 'Save all the permalinks above', 'permalink-manager' );
172 $button_name = 'update_all_slugs[bottom]';
173 }
174
175 $html = "<div class=\"alignleft actions\">";
176 $html .= get_submit_button( $button_text, 'primary alignleft', $button_name, false, array( 'id' => 'doaction', 'value' => 'update_all_slugs' ) );
177 $html .= "</div>";
178
179 if ( $which == "top" ) {
180 // Filter by date
181 $months = $wpdb->get_results( "SELECT DISTINCT month(post_date) AS m, year(post_date) AS y FROM {$wpdb->posts} WHERE post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types) ORDER BY post_date DESC", ARRAY_A );
182
183 if ( $months ) {
184 $choices = array( __( 'All dates', 'permalink-manager' ) );
185
186 foreach ( $months as $month ) {
187 $month_raw = sprintf( "%s-%s", $month['y'], $month['m'] );
188 $choices[ $month_raw ] = date_i18n( "F Y", strtotime( $month_raw ) );
189 }
190
191 $select_field = Permalink_Manager_UI_Elements::generate_option_field( 'month', array(
192 'type' => 'select',
193 'choices' => $choices,
194 'value' => ( isset( $_REQUEST['month'] ) ) ? esc_attr( $_REQUEST['month'] ) : ''
195 ) );
196
197 $html .= sprintf( '<div id=\"months-filter\" class="alignleft actions">%s</div>', $select_field );
198 }
199
200 $extra_fields = apply_filters( 'permalink_manager_uri_editor_extra_fields', '', 'posts' );
201
202 if ( $months || $extra_fields ) {
203 $html .= $extra_fields;
204
205 $html .= '<div class="alignleft">';
206 $html .= get_submit_button( __( "Filter", "permalink-manager" ), 'button', false, false, array( 'id' => 'filter-button', 'name' => 'filter-button' ) );
207 $html .= "</div>";
208 }
209
210 $html .= '<div class="alignright">';
211 $html .= $this->search_box( __( 'Search', 'permalink-manager' ), 'search-input' );
212 $html .= '</div>';
213 }
214
215 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
216 echo $html;
217 }
218
219 /**
220 * Display the search input field
221 *
222 * @return string
223 */
224 public function search_box( $text = '', $input_id = '' ) {
225 $search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_attr( $_REQUEST['s'] ) : "";
226
227 $output = "<p class=\"search-box\">";
228 $output .= "<label class=\"screen-reader-text\" for=\"{$input_id}\">{$text}:</label>";
229 $output .= Permalink_Manager_UI_Elements::generate_option_field( 's', array( 'value' => $search_query, 'type' => 'search' ) );
230 $output .= get_submit_button( $text, 'button', false, false, array( 'id' => 'search-submit', 'name' => 'search-submit' ) );
231 $output .= "</p>";
232
233 return $output;
234 }
235
236 /**
237 * Prepare the items for the table to process
238 */
239 public function prepare_items() {
240 global $wpdb;
241
242 $columns = $this->get_columns();
243 $hidden = $this->get_hidden_columns();
244 $sortable = $this->get_sortable_columns();
245 $current_page = $this->get_pagenum();
246
247 // SQL query parameters
248 $order = ( isset( $_REQUEST['order'] ) && in_array( $_REQUEST['order'], array( 'asc', 'desc' ) ) ) ? sanitize_sql_orderby( $_REQUEST['order'] ) : 'desc';
249 $orderby = ( isset( $_REQUEST['orderby'] ) ) ? sanitize_sql_orderby( $_REQUEST['orderby'] ) : 'ID';
250 $search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_sql( $_REQUEST['s'] ) : "";
251
252 // Extra filters
253 $extra_filters = $attachment_support = '';
254 if ( ! empty( $_GET['month'] ) ) {
255 $month = date( "n", strtotime( $_GET['month'] ) );
256 $year = date( "Y", strtotime( $_GET['month'] ) );
257
258 $extra_filters .= "AND month(post_date) = {$month} AND year(post_date) = {$year}";
259 }
260
261 // Support for attachments
262 if ( strpos( $this->displayed_post_types, 'attachment' ) !== false ) {
263 $attachment_support = " OR (post_type = 'attachment')";
264 }
265
266 // Grab posts from database
267 $sql_parts['start'] = "SELECT * FROM {$wpdb->posts} AS p ";
268 if ( $search_query ) {
269 $sql_parts['where'] = "WHERE (LOWER(post_title) LIKE LOWER('%{$search_query}%') ";
270
271 // Search in array with custom URIs
272 $found = Permalink_Manager_URI_Functions::find_uri( $search_query, false, 'posts' );
273 if ( $found ) {
274 $sql_parts['where'] .= sprintf( "OR ID IN (%s)", implode( ',', $found ) );
275 }
276 $sql_parts['where'] .= " ) AND ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} ";
277 } else {
278 $sql_parts['where'] = "WHERE ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} ";
279 }
280
281 // Do not display excluded posts in Bulk URI Editor
282 $excluded_posts = Permalink_Manager_Helper_Functions::get_excluded_post_ids();
283 if ( ! empty( $excluded_posts ) && is_array( $excluded_posts ) ) {
284 $sql_parts['where'] .= sprintf( "AND ID NOT IN ('%s') ", implode( "', '", $excluded_posts ) );
285 }
286
287 $sql_parts['end'] = "ORDER BY {$orderby} {$order}";
288
289 list( $all_items, $total_items, $per_page ) = Permalink_Manager_URI_Editor::prepare_sql_query( $sql_parts, $current_page, false );
290
291 $this->set_pagination_args( array(
292 'total_items' => $total_items,
293 'per_page' => $per_page
294 ) );
295
296 $this->_column_headers = array( $columns, $hidden, $sortable );
297 $this->items = $all_items;
298 }
299
300 /**
301 * Define hidden columns
302 *
303 * @return array
304 */
305 public function get_hidden_columns() {
306 return array();
307 }
308
309 /**
310 * Sort the data
311 *
312 * @param mixed $a
313 * @param mixed $b
314 *
315 * @return int
316 */
317 private function sort_data( $a, $b ) {
318 // Set defaults
319 $orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_sql_orderby( $_GET['orderby'] ) : 'post_title';
320 $order = ( ! empty( $_GET['order'] ) ) ? sanitize_sql_orderby( $_GET['order'] ) : 'asc';
321 $result = strnatcasecmp( $a[ $orderby ], $b[ $orderby ] );
322
323 return ( $order === 'asc' ) ? $result : - $result;
324 }
325
326 }
327