Making WordPress.org

Ticket #5362: 5362-delist-actions.diff

File 5362-delist-actions.diff, 7.7 KB (added by tellyworth, 4 years ago)

A lightly tested attempt

  • admin-edit.php

     
    4343                'exclude_from_search' => true,
    4444                'label_count'         => _n_noop( 'Suspended <span class="count">(%s)</span>', 'Suspended <span class="count">(%s)</span>', 'wporg-themes' ),
    4545        ) );
     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        ) );
    4654}
    4755add_action( 'init', 'wporg_themes_post_status' );
    4856
     
    124132                $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' ) );
    125133        }
    126134
     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
    127142        if ( ! empty( $links ) ) {
    128143                echo '<div class="misc-pub-section">' . implode( ' | ', $links ) . '</div>';
    129144        }
     
    184199
    185200        wporg_themes_remove_wpthemescom( $post->post_name );
    186201
    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() ) ) );
    188203        exit();
    189204}
    190205add_filter( 'admin_action_suspend', 'wporg_themes_suspend_theme' );
     
    227242         */
    228243        add_post_meta( $post_id, '_wporg_themes_reinstated', true );
    229244
    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() ) ) );
    231246        exit();
    232247}
    233248add_filter( 'admin_action_reinstate', 'wporg_themes_reinstate_theme' );
    234249
    235250/**
     251 * Action link to delist a theme.
     252 *
     253 * @param WP_Post $post
     254 * @return string URL
     255 */
     256function 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 */
     266function 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 */
     273function 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}
     305add_filter( 'admin_action_delist', 'wporg_themes_delist_theme' );
     306
     307/**
     308 * Reinstate a theme.
     309 */
     310function 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}
     342add_filter( 'admin_action_relist', 'wporg_themes_relist_theme' );
     343
     344/**
    236345 * Remove themes from wp-themes.com upon theme status moving to draft.
    237346 *
    238347 * @param WP_Post $post
  • class-themes-api.php

     
    446446                        $themes = get_posts( array(
    447447                                'name'      => $this->request->slug,
    448448                                'post_type' => 'repopackage',
     449                                'post_status' => 'publish,delisted',
    449450                        ) );
    450451
    451452                        if ( $themes ) {
  • class-wporg-themes-upload.php

     
    487487                         * Specify post stati so this query returns a result for draft themes, even
    488488                         * if the uploading user doesn't have have the permission to view drafts.
    489489                         */
    490                         'post_status'      => array( 'publish', 'pending', 'draft', 'future', 'trash', 'suspend' ),
     490                        'post_status'      => array( 'publish', 'pending', 'draft', 'future', 'trash', 'suspend', 'delist' ),
    491491                        'suppress_filters' => false,
    492492                ) );
    493493                $theme = current( $themes );
  • query-modifications.php

     
    3838                $query->query_vars['post_status'] = 'publish';
    3939        }
    4040
     41        if ( !empty( $query->query_vars['name'] ) ) {
     42                $query->query_vars['post_status'] = 'publish,delisted';
     43        }
     44
    4145        switch ( $query->query_vars['browse'] ) {
    4246                case 'new':
    4347                        $query->query_vars['orderby'] = 'post_date';
  • theme-directory.php

     
    11441144                                $noindex = true;
    11451145                        }
    11461146                }
     1147
     1148                if ( 'delisted' === $post->post_status ) {
     1149                        $noindex = 'nosnippet';
     1150                }
    11471151        }
    11481152
    11491153        if ( is_tag() ) {
     
    13331337add_filter( 'wporg_canonical_url', 'wporg_themes_canonical_url' );
    13341338
    13351339// Theme Directory doesn't support pagination.
    1336 add_filter( 'wporg_rel_next_pages', '__return_zero' );
    1337  No newline at end of file
     1340add_filter( 'wporg_rel_next_pages', '__return_zero' );