Making WordPress.org

Ticket #4857: 4857.2.diff

File 4857.2.diff, 2.7 KB (added by dingo_d, 5 years ago)

Fixed the screen ID and the admin notice

  • wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    diff --git wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php
    index e5796871c..946446aa5 100644
    function wporg_themes_get_current_url( $path_only = false ) { 
    12971297
    12981298        return $link;
    12991299}
     1300
     1301/**
     1302 * Add suspend bulk action
     1303 */
     1304add_action( 'current_screen', 'wporg_themes_bulk_hooks' );
     1305
     1306/**
     1307 * Hooks to current_screen hook, so that we have the WP_Screen defined
     1308 */
     1309function wporg_themes_bulk_hooks() {
     1310        add_filter( 'bulk_actions-edit-repopackage', 'wporg_themes_add_bulk_suspend_option' );
     1311        add_filter( 'handle_bulk_actions-edit-repopackage', 'wporg_themes_suspend_bulk_action_handler', 10, 3 );
     1312        add_action( 'admin_notices', 'wporg_themes_suspend_bulk_action_admin_notice' );
     1313}
     1314
     1315/**
     1316 * Add a new bulk action
     1317 *
     1318 * Add the suspend themes action
     1319 *
     1320 * @param  array $bulk_actions Array of bulk actions.
     1321 * @return array               Updated array of bulk actions.
     1322 */
     1323function wporg_themes_add_bulk_suspend_option( $bulk_actions ) {
     1324        $bulk_actions['suspend_themes'] = __( 'Suspend themes', 'wporg-themes' );
     1325
     1326        return $bulk_actions;
     1327}
     1328
     1329/**
     1330 * Add the action handler for the suspend themes action
     1331 *
     1332 * @param  string $redirect_to The redirect URL.
     1333 * @param  string $doaction    The action being taken.
     1334 * @param  array  $post_ids    The post IDs to take the action on.
     1335 * @return string              Redirection URL after the action.
     1336 */
     1337function wporg_themes_suspend_bulk_action_handler( $redirect_to, $doaction, $post_ids ) {
     1338        if ( $doaction !== 'suspend_themes' ) {
     1339                return $redirect_to;
     1340        }
     1341
     1342        foreach ( $post_ids as $post_id ) {
     1343                wp_update_post(
     1344                        array(
     1345                                'ID'          => $post_id,
     1346                                'post_status' => 'suspended',
     1347                        )
     1348                );
     1349        }
     1350
     1351        $redirect_to = add_query_arg( 'bulk_suspend_themes', count( $post_ids ), $redirect_to );
     1352
     1353        return $redirect_to;
     1354}
     1355
     1356/**
     1357 * The admin notice after the suspend themes action happened.
     1358 */
     1359function wporg_themes_suspend_bulk_action_admin_notice() {
     1360        if ( ! empty( $_REQUEST['bulk_suspend_themes'] ) ) {
     1361                $suspended_themes_count = intval( $_REQUEST['bulk_suspend_themes'] );
     1362
     1363                printf( '<div id="message" class="updated notice is-dismissible"><p>' .
     1364                        _n( '%s theme is suspended.',
     1365                                '%s theme are suspended.',
     1366                                $suspended_themes_count,
     1367                                'wporg-themes'
     1368                        ) . '</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">' . __(' Dismiss this notice.', 'wporg-themes' ) . '</span></button></div>',
     1369                        $suspended_themes_count );
     1370        }
     1371}