Title: WP_MS_Themes_List_Table::prepare_items
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_MS_Themes_List_Table::prepare_items()

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#related)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#wp--skip-link--target)

Prepares the themes list for display.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#source)󠁿

    ```php
    public function prepare_items() {
    	global $status, $totals, $page, $orderby, $order, $s;

    	$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
    	$order   = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
    	$s       = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';

    	$themes = array(
    		/**
    		 * Filters the full array of WP_Theme objects to list in the Multisite
    		 * themes list table.
    		 *
    		 * @since 3.1.0
    		 *
    		 * @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
    		 */
    		'all'      => apply_filters( 'all_themes', wp_get_themes() ),
    		'search'   => array(),
    		'enabled'  => array(),
    		'disabled' => array(),
    		'upgrade'  => array(),
    		'broken'   => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
    	);

    	if ( $this->show_autoupdates ) {
    		$auto_updates = (array) get_site_option( 'auto_update_themes', array() );

    		$themes['auto-update-enabled']  = array();
    		$themes['auto-update-disabled'] = array();
    	}

    	if ( $this->is_site_themes ) {
    		$themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
    		$allowed_where   = 'site';
    	} else {
    		$themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
    		$allowed_where   = 'network';
    	}

    	$current      = get_site_transient( 'update_themes' );
    	$maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current;

    	foreach ( (array) $themes['all'] as $key => $theme ) {
    		if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
    			unset( $themes['all'][ $key ] );
    			continue;
    		}

    		if ( $maybe_update && isset( $current->response[ $key ] ) ) {
    			$themes['all'][ $key ]->update = true;
    			$themes['upgrade'][ $key ]     = $themes['all'][ $key ];
    		}

    		$filter                    = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
    		$themes[ $filter ][ $key ] = $themes['all'][ $key ];

    		$theme_data = array(
    			'update_supported' => $theme->update_supported ?? true,
    		);

    		// Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.
    		if ( isset( $current->response[ $key ] ) ) {
    			$theme_data = array_merge( (array) $current->response[ $key ], $theme_data );
    		} elseif ( isset( $current->no_update[ $key ] ) ) {
    			$theme_data = array_merge( (array) $current->no_update[ $key ], $theme_data );
    		} else {
    			$theme_data['update_supported'] = false;
    		}

    		$theme->update_supported = $theme_data['update_supported'];

    		/*
    		 * Create the expected payload for the auto_update_theme filter, this is the same data
    		 * as contained within $updates or $no_updates but used when the Theme is not known.
    		 */
    		$filter_payload = array(
    			'theme'        => $key,
    			'new_version'  => '',
    			'url'          => '',
    			'package'      => '',
    			'requires'     => '',
    			'requires_php' => '',
    		);

    		$filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );

    		$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload );

    		if ( ! is_null( $auto_update_forced ) ) {
    			$theme->auto_update_forced = $auto_update_forced;
    		}

    		if ( $this->show_autoupdates ) {
    			$enabled = in_array( $key, $auto_updates, true ) && $theme->update_supported;
    			if ( isset( $theme->auto_update_forced ) ) {
    				$enabled = (bool) $theme->auto_update_forced;
    			}

    			if ( $enabled ) {
    				$themes['auto-update-enabled'][ $key ] = $theme;
    			} else {
    				$themes['auto-update-disabled'][ $key ] = $theme;
    			}
    		}
    	}

    	if ( $s ) {
    		$status           = 'search';
    		$themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
    	}

    	$totals    = array();
    	$js_themes = array();
    	foreach ( $themes as $type => $list ) {
    		$totals[ $type ]    = count( $list );
    		$js_themes[ $type ] = array_keys( $list );
    	}

    	if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
    		$status = 'all';
    	}

    	$this->items = $themes[ $status ];
    	WP_Theme::sort_by_name( $this->items );

    	$this->has_items = ! empty( $themes['all'] );
    	$total_this_page = $totals[ $status ];

    	wp_localize_script(
    		'updates',
    		'_wpUpdatesItemCounts',
    		array(
    			'themes' => $js_themes,
    			'totals' => wp_get_update_data(),
    		)
    	);

    	if ( $orderby ) {
    		$orderby = ucfirst( $orderby );
    		$order   = strtoupper( $order );

    		if ( 'Name' === $orderby ) {
    			if ( 'ASC' === $order ) {
    				$this->items = array_reverse( $this->items );
    			}
    		} else {
    			uasort( $this->items, array( $this, '_order_callback' ) );
    		}
    	}

    	$start = ( $page - 1 ) * $themes_per_page;

    	if ( $total_this_page > $themes_per_page ) {
    		$this->items = array_slice( $this->items, $start, $themes_per_page, true );
    	}

    	$this->set_pagination_args(
    		array(
    			'total_items' => $total_this_page,
    			'per_page'    => $themes_per_page,
    		)
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/class-wp-ms-themes-list-table.php#L105)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/class-wp-ms-themes-list-table.php#L105-L267)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#hooks)󠁿

 [apply_filters( ‘all_themes’, WP_Theme[] $all )](https://developer.wordpress.org/reference/hooks/all_themes/)

Filters the full array of [WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/)
objects to list in the Multisite themes list table.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_is_auto_update_forced_for_item()](https://developer.wordpress.org/reference/functions/wp_is_auto_update_forced_for_item/)`wp-admin/includes/update.php` |

Checks whether auto-updates are forced for an item.

  | 
| [wp_get_themes()](https://developer.wordpress.org/reference/functions/wp_get_themes/)`wp-includes/theme.php` |

Returns an array of [WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/) objects based on the arguments.

  | 
| [WP_Theme::sort_by_name()](https://developer.wordpress.org/reference/classes/wp_theme/sort_by_name/)`wp-includes/class-wp-theme.php` |

Sorts themes by name.

  | 
| [wp_localize_script()](https://developer.wordpress.org/reference/functions/wp_localize_script/)`wp-includes/functions.wp-scripts.php` |

Localizes a script.

  | 
| [wp_get_update_data()](https://developer.wordpress.org/reference/functions/wp_get_update_data/)`wp-includes/update.php` |

Collects counts and UI strings for available updates.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [sanitize_text_field()](https://developer.wordpress.org/reference/functions/sanitize_text_field/)`wp-includes/formatting.php` |

Sanitizes a string from user input or from the database.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_site_transient()](https://developer.wordpress.org/reference/functions/get_site_transient/)`wp-includes/option.php` |

Retrieves the value of a site transient.

  | 
| [get_site_option()](https://developer.wordpress.org/reference/functions/get_site_option/)`wp-includes/option.php` |

Retrieve an option value for the current network based on name of option.

  |

[Show 5 more](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/prepare_items/?output_format=md#)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_ms_themes_list_table%2Fprepare_items%2F)
before being able to contribute a note or feedback.