Ticket #5362: 5362-delist-actions.diff
File 5362-delist-actions.diff, 7.7 KB (added by , 4 years ago) |
---|
-
admin-edit.php
43 43 'exclude_from_search' => true, 44 44 'label_count' => _n_noop( 'Suspended <span class="count">(%s)</span>', 'Suspended <span class="count">(%s)</span>', 'wporg-themes' ), 45 45 ) ); 46 47 // Themes can be "delisted" to hide them from search, but allow them to be uploaded. 48 register_post_status( 'delist', array( 49 'label' => __( 'Delisted', 'wporg-themes' ), 50 'protected' => true, 51 'exclude_from_search' => true, 52 'label_count' => _n_noop( 'Delisted <span class="count">(%s)</span>', 'Delisted <span class="count">(%s)</span>', 'wporg-themes' ), 53 ) ); 46 54 } 47 55 add_action( 'init', 'wporg_themes_post_status' ); 48 56 … … 124 132 $links[] = sprintf( '<a class="submit-reinstate_theme" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Suspend this item', 'wporg-themes' ), esc_url( wporg_themes_get_reinstate_url( $post ) ), __( 'Reinstate', 'wporg-themes' ) ); 125 133 } 126 134 135 if ( current_user_can( 'suspend_theme', $post->ID ) && 'publish' == $post->post_status ) { 136 $links[] = sprintf( '<a class="submit-delist_theme submitdelete" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Delist this item', 'wporg-themes' ), esc_url( wporg_themes_get_delist_url( $post ) ), __( 'Delist', 'wporg-themes' ) ); 137 } 138 elseif ( current_user_can( 'reinstate_theme', $post->ID ) && 'delist' == $post->post_status ) { 139 $links[] = sprintf( '<a class="submit-relist_theme" title="%1$s" href="%2$s">%3$s</a>', esc_attr__( 'Relist this item', 'wporg-themes' ), esc_url( wporg_themes_get_relist_url( $post ) ), __( 'Relist', 'wporg-themes' ) ); 140 } 141 127 142 if ( ! empty( $links ) ) { 128 143 echo '<div class="misc-pub-section">' . implode( ' | ', $links ) . '</div>'; 129 144 } … … 184 199 185 200 wporg_themes_remove_wpthemescom( $post->post_name ); 186 201 187 wp_redirect( add_query_arg( 'suspended', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'reinstated' ), wp_get_referer() ) ) );202 wp_redirect( add_query_arg( 'suspended', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'reinstated', 'delist', 'relist' ), wp_get_referer() ) ) ); 188 203 exit(); 189 204 } 190 205 add_filter( 'admin_action_suspend', 'wporg_themes_suspend_theme' ); … … 227 242 */ 228 243 add_post_meta( $post_id, '_wporg_themes_reinstated', true ); 229 244 230 wp_redirect( add_query_arg( 'reinstated', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'suspended' ), wp_get_referer() ) ) );245 wp_redirect( add_query_arg( 'reinstated', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'suspended', 'delist', 'relist' ), wp_get_referer() ) ) ); 231 246 exit(); 232 247 } 233 248 add_filter( 'admin_action_reinstate', 'wporg_themes_reinstate_theme' ); 234 249 235 250 /** 251 * Action link to delist a theme. 252 * 253 * @param WP_Post $post 254 * @return string URL 255 */ 256 function wporg_themes_get_delist_url( $post ) { 257 return wp_nonce_url( add_query_arg( 'action', 'delist', admin_url( sprintf( get_post_type_object( $post->post_type )->_edit_link, $post->ID ) ) ), "delist-post_{$post->ID}" ); 258 } 259 260 /** 261 * Action link to relist a theme. 262 * 263 * @param WP_Post $post 264 * @return string URL 265 */ 266 function wporg_themes_get_relist_url( $post ) { 267 return wp_nonce_url( add_query_arg( 'action', 'relist', admin_url( sprintf( get_post_type_object( $post->post_type )->_edit_link, $post->ID ) ) ), "relist-post_{$post->ID}" ); 268 } 269 270 /** 271 * Delist a theme. 272 */ 273 function wporg_themes_delist_theme() { 274 $post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : 0; 275 276 if ( ! $post_id ) { 277 wp_redirect( admin_url( 'edit.php' ) ); 278 exit(); 279 } 280 281 check_admin_referer( 'delist-post_' . $post_id ); 282 283 $post = get_post( $post_id ); 284 285 if ( 'delist' == $post->post_status ) { 286 wp_die( __( 'This item has already been delisted.', 'wporg-themes' ) ); 287 } 288 289 if ( ! get_post_type_object( $post->post_type ) ) { 290 wp_die( __( 'Unknown post type.', 'wporg-themes' ) ); 291 } 292 293 if ( ! current_user_can( 'suspend_theme', $post_id ) || 'repopackage' != $post->post_type ) { 294 wp_die( __( 'You are not allowed to delist this item.', 'wporg-themes' ) ); 295 } 296 297 wp_update_post( array( 298 'ID' => $post_id, 299 'post_status' => 'delist', 300 ) ); 301 302 wp_redirect( add_query_arg( 'delisted', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'reinstated', 'delist', 'relist' ), wp_get_referer() ) ) ); 303 exit(); 304 } 305 add_filter( 'admin_action_delist', 'wporg_themes_delist_theme' ); 306 307 /** 308 * Reinstate a theme. 309 */ 310 function wporg_themes_relist_theme() { 311 $post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : 0; 312 313 if ( ! $post_id ) { 314 wp_redirect( admin_url( 'edit.php' ) ); 315 exit(); 316 } 317 318 check_admin_referer( 'relist-post_' . $post_id ); 319 320 $post = get_post( $post_id ); 321 322 if ( 'delist' != $post->post_status ) { 323 wp_die( __( 'This item has already been relisted.', 'wporg-themes' ) ); 324 } 325 326 if ( ! get_post_type_object( $post->post_type ) ) { 327 wp_die( __( 'Unknown post type.', 'wporg-themes' ) ); 328 } 329 330 if ( ! current_user_can( 'reinstate_theme', $post_id ) || 'repopackage' != $post->post_type ) { 331 wp_die( __( 'You are not allowed to relist this item.', 'wporg-themes' ) ); 332 } 333 334 wp_update_post( array( 335 'ID' => $post_id, 336 'post_status' => 'publish', 337 ) ); 338 339 wp_redirect( add_query_arg( 'relisted', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'suspended', 'delist', 'relist' ), wp_get_referer() ) ) ); 340 exit(); 341 } 342 add_filter( 'admin_action_relist', 'wporg_themes_relist_theme' ); 343 344 /** 236 345 * Remove themes from wp-themes.com upon theme status moving to draft. 237 346 * 238 347 * @param WP_Post $post -
class-themes-api.php
446 446 $themes = get_posts( array( 447 447 'name' => $this->request->slug, 448 448 'post_type' => 'repopackage', 449 'post_status' => 'publish,delisted', 449 450 ) ); 450 451 451 452 if ( $themes ) { -
class-wporg-themes-upload.php
487 487 * Specify post stati so this query returns a result for draft themes, even 488 488 * if the uploading user doesn't have have the permission to view drafts. 489 489 */ 490 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'trash', 'suspend' ),490 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'trash', 'suspend', 'delist' ), 491 491 'suppress_filters' => false, 492 492 ) ); 493 493 $theme = current( $themes ); -
query-modifications.php
38 38 $query->query_vars['post_status'] = 'publish'; 39 39 } 40 40 41 if ( !empty( $query->query_vars['name'] ) ) { 42 $query->query_vars['post_status'] = 'publish,delisted'; 43 } 44 41 45 switch ( $query->query_vars['browse'] ) { 42 46 case 'new': 43 47 $query->query_vars['orderby'] = 'post_date'; -
theme-directory.php
1144 1144 $noindex = true; 1145 1145 } 1146 1146 } 1147 1148 if ( 'delisted' === $post->post_status ) { 1149 $noindex = 'nosnippet'; 1150 } 1147 1151 } 1148 1152 1149 1153 if ( is_tag() ) { … … 1333 1337 add_filter( 'wporg_canonical_url', 'wporg_themes_canonical_url' ); 1334 1338 1335 1339 // Theme Directory doesn't support pagination. 1336 add_filter( 'wporg_rel_next_pages', '__return_zero' ); 1337 No newline at end of file 1340 add_filter( 'wporg_rel_next_pages', '__return_zero' );