| | 136 | if ( current_user_can( 'suspend_theme', $post->ID ) && 'publish' == $post->post_status ) { |
| | 137 | $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' ) ); |
| | 138 | } |
| | 139 | elseif ( current_user_can( 'reinstate_theme', $post->ID ) && 'delist' == $post->post_status ) { |
| | 140 | $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' ) ); |
| | 141 | } |
| | 142 | |
| | 252 | * Action link to delist a theme. |
| | 253 | * |
| | 254 | * @param WP_Post $post |
| | 255 | * @return string URL |
| | 256 | */ |
| | 257 | function wporg_themes_get_delist_url( $post ) { |
| | 258 | 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}" ); |
| | 259 | } |
| | 260 | |
| | 261 | /** |
| | 262 | * Action link to relist a theme. |
| | 263 | * |
| | 264 | * @param WP_Post $post |
| | 265 | * @return string URL |
| | 266 | */ |
| | 267 | function wporg_themes_get_relist_url( $post ) { |
| | 268 | 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}" ); |
| | 269 | } |
| | 270 | |
| | 271 | /** |
| | 272 | * Delist a theme. |
| | 273 | */ |
| | 274 | function wporg_themes_delist_theme() { |
| | 275 | $post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : 0; |
| | 276 | |
| | 277 | if ( ! $post_id ) { |
| | 278 | wp_redirect( admin_url( 'edit.php' ) ); |
| | 279 | exit(); |
| | 280 | } |
| | 281 | |
| | 282 | check_admin_referer( 'delist-post_' . $post_id ); |
| | 283 | |
| | 284 | $post = get_post( $post_id ); |
| | 285 | |
| | 286 | if ( 'delist' == $post->post_status ) { |
| | 287 | wp_die( __( 'This item has already been delisted.', 'wporg-themes' ) ); |
| | 288 | } |
| | 289 | |
| | 290 | if ( ! get_post_type_object( $post->post_type ) ) { |
| | 291 | wp_die( __( 'Unknown post type.', 'wporg-themes' ) ); |
| | 292 | } |
| | 293 | |
| | 294 | if ( ! current_user_can( 'suspend_theme', $post_id ) || 'repopackage' != $post->post_type ) { |
| | 295 | wp_die( __( 'You are not allowed to delist this item.', 'wporg-themes' ) ); |
| | 296 | } |
| | 297 | |
| | 298 | wp_update_post( array( |
| | 299 | 'ID' => $post_id, |
| | 300 | 'post_status' => 'delist', |
| | 301 | ) ); |
| | 302 | |
| | 303 | wp_redirect( add_query_arg( 'delisted', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'reinstated', 'delisted', 'relisted' ), wp_get_referer() ) ) ); |
| | 304 | exit(); |
| | 305 | } |
| | 306 | add_filter( 'admin_action_delist', 'wporg_themes_delist_theme' ); |
| | 307 | |
| | 308 | /** |
| | 309 | * Reinstate a theme. |
| | 310 | */ |
| | 311 | function wporg_themes_relist_theme() { |
| | 312 | $post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : 0; |
| | 313 | |
| | 314 | if ( ! $post_id ) { |
| | 315 | wp_redirect( admin_url( 'edit.php' ) ); |
| | 316 | exit(); |
| | 317 | } |
| | 318 | |
| | 319 | check_admin_referer( 'relist-post_' . $post_id ); |
| | 320 | |
| | 321 | $post = get_post( $post_id ); |
| | 322 | |
| | 323 | if ( 'delist' != $post->post_status ) { |
| | 324 | wp_die( __( 'This item has already been relisted.', 'wporg-themes' ) ); |
| | 325 | } |
| | 326 | |
| | 327 | if ( ! get_post_type_object( $post->post_type ) ) { |
| | 328 | wp_die( __( 'Unknown post type.', 'wporg-themes' ) ); |
| | 329 | } |
| | 330 | |
| | 331 | if ( ! current_user_can( 'reinstate_theme', $post_id ) || 'repopackage' != $post->post_type ) { |
| | 332 | wp_die( __( 'You are not allowed to relist this item.', 'wporg-themes' ) ); |
| | 333 | } |
| | 334 | |
| | 335 | wp_update_post( array( |
| | 336 | 'ID' => $post_id, |
| | 337 | 'post_status' => 'publish', |
| | 338 | ) ); |
| | 339 | |
| | 340 | wp_redirect( add_query_arg( 'relisted', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'suspended', 'delisted', 'relisted' ), wp_get_referer() ) ) ); |
| | 341 | exit(); |
| | 342 | } |
| | 343 | add_filter( 'admin_action_relist', 'wporg_themes_relist_theme' ); |
| | 344 | |
| | 345 | /** |
| | 375 | elseif ( ! empty( $_GET['delisted'] ) ) { |
| | 376 | $delisted = absint( $_GET['delisted'] ); |
| | 377 | $message = _n( '%s theme delisted.', '%s themes delisted.', $delisted, 'wporg-themes' ); |
| | 378 | |
| | 379 | add_settings_error( 'wporg_themes', 'delisted', sprintf( $message, $delisted ) ); |
| | 380 | } |
| | 381 | elseif ( ! empty( $_GET['relisted'] ) ) { |
| | 382 | $relisted = absint( $_GET['relisted'] ); |
| | 383 | $message = _n( '%s theme relisted.', '%s themes relisted.', $relisted, 'wporg-themes' ); |
| | 384 | |
| | 385 | add_settings_error( 'wporg_themes', 'relisted', sprintf( $message, $relisted ), 'updated' ); |
| | 386 | } |
| | 387 | |