Making WordPress.org

Ticket #5362: 5362-delist-actions.3.diff

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

Fix a bug in the .2 version where noindex could be overridden

  • 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'           => 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' );
    4857
     
    124133                $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' ) );
    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>';
    129145        }
     
    184200
    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}
    190206add_filter( 'admin_action_suspend', 'wporg_themes_suspend_theme' );
     
    227243         */
    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' );
    234250
    235251/**
     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' );
     344
     345/**
    236346 * Remove themes from wp-themes.com upon theme status moving to draft.
    237347 *
    238348 * @param WP_Post $post
     
    262372                add_settings_error( 'wporg_themes', 'reinstated', sprintf( $message, $reinstated ), 'updated' );
    263373        }
    264374
     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
    265388        // Display admin notices, if any.
    266389        settings_errors( 'wporg_themes' );
    267390}
  • class-themes-api.php

     
    446446                        $themes = get_posts( array(
    447447                                'name'      => $this->request->slug,
    448448                                'post_type' => 'repopackage',
     449                                'post_status' => 'publish,delist',
    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,delist';
     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 ( !$noindex && 'delist' === $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' );