Making WordPress.org

Changeset 10240


Ignore:
Timestamp:
09/08/2020 07:26:32 AM (6 years ago)
Author:
tellyworth
Message:

Theme directory: add a Delist status.

This temporarily hides a theme from search, while still making it available directly.

More testing and refinement is probably needed.

See #5362.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php

    r10134 r10240  
    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'           => false,
     51                'public'              => true,
     52                'exclude_from_search' => true,
     53                'label_count'         => _n_noop( 'Delisted <span class="count">(%s)</span>', 'Delisted <span class="count">(%s)</span>', 'wporg-themes' ),
     54        ) );
    4655}
    4756add_action( 'init', 'wporg_themes_post_status' );
    … …  
    125134        }
    126135
     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
    127143        if ( ! empty( $links ) ) {
    128144                echo '<div class="misc-pub-section">' . implode( ' | ', $links ) . '</div>';
    … …  
    185201        wporg_themes_remove_wpthemescom( $post->post_name );
    186202
    187         wp_redirect( add_query_arg( 'suspended', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'reinstated' ), wp_get_referer() ) ) );
     203        wp_redirect( add_query_arg( 'suspended', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'reinstated', 'delisted', 'relisted' ), wp_get_referer() ) ) );
    188204        exit();
    189205}
    … …  
    228244        add_post_meta( $post_id, '_wporg_themes_reinstated', true );
    229245
    230         wp_redirect( add_query_arg( 'reinstated', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'suspended' ), wp_get_referer() ) ) );
     246        wp_redirect( add_query_arg( 'reinstated', 1, remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids', 'suspended', 'delisted', 'relisted' ), wp_get_referer() ) ) );
    231247        exit();
    232248}
    233249add_filter( 'admin_action_reinstate', 'wporg_themes_reinstate_theme' );
     250
     251/**
     252 * Action link to delist a theme.
     253 *
     254 * @param WP_Post $post
     255 * @return string URL
     256 */
     257function 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 */
     267function 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 */
     274function 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}
     306add_filter( 'admin_action_delist', 'wporg_themes_delist_theme' );
     307
     308/**
     309 * Reinstate a theme.
     310 */
     311function 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}
     343add_filter( 'admin_action_relist', 'wporg_themes_relist_theme' );
    234344
    235345/**
    … …  
    261371
    262372                add_settings_error( 'wporg_themes', 'reinstated', sprintf( $message, $reinstated ), 'updated' );
     373        }
     374
     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' );
    263386        }
    264387
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-themes-api.php

    r10179 r10240  
    447447                                'name'      => $this->request->slug,
    448448                                'post_type' => 'repopackage',
     449                                'post_status' => 'publish,delist',
    449450                        ) );
    450451
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r10018 r10240  
    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                ) );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/query-modifications.php

    r10000 r10240  
    3737        if ( !isset( $query->query_vars['post_status'] ) ) {
    3838                $query->query_vars['post_status'] = 'publish';
     39        }
     40
     41        if ( !empty( $query->query_vars['name'] ) ) {
     42                $query->query_vars['post_status'] = 'publish,delist';
    3943        }
    4044
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r10177 r10240  
    11441144                                $noindex = true;
    11451145                        }
     1146                }
     1147
     1148                if ( !$noindex && 'delist' === $post->post_status ) {
     1149                        $noindex = 'nosnippet';
    11461150                }
    11471151        }
Note: See TracChangeset for help on using the changeset viewer.