dvadf
PK �MP\���g= g= class-wp-ms-users-list-table.phpnu �[��� <?php
/**
* List Table API: WP_MS_Users_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying users in a list table for the network admin.
*
* @since 3.1.0
*
* @see WP_List_Table
*/
class WP_MS_Users_List_Table extends WP_List_Table {
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'manage_network_users' );
}
/**
* @global string $mode List table view mode.
* @global string $usersearch
* @global string $role
*/
public function prepare_items() {
global $mode, $usersearch, $role;
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
set_user_setting( 'network_users_list_mode', $mode );
} else {
$mode = get_user_setting( 'network_users_list_mode', 'list' );
}
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
$users_per_page = $this->get_items_per_page( 'users_network_per_page' );
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
$paged = $this->get_pagenum();
$args = array(
'number' => $users_per_page,
'offset' => ( $paged - 1 ) * $users_per_page,
'search' => $usersearch,
'blog_id' => 0,
'fields' => 'all_with_meta',
);
if ( wp_is_large_network( 'users' ) ) {
$args['search'] = ltrim( $args['search'], '*' );
} elseif ( '' !== $args['search'] ) {
$args['search'] = trim( $args['search'], '*' );
$args['search'] = '*' . $args['search'] . '*';
}
if ( 'super' === $role ) {
$args['login__in'] = get_super_admins();
}
/*
* If the network is large and a search is not being performed,
* show only the latest users with no paging in order to avoid
* expensive count queries.
*/
if ( ! $usersearch && wp_is_large_network( 'users' ) ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$_GET['orderby'] = 'id';
$_REQUEST['orderby'] = 'id';
}
if ( ! isset( $_REQUEST['order'] ) ) {
$_GET['order'] = 'DESC';
$_REQUEST['order'] = 'DESC';
}
$args['count_total'] = false;
}
if ( isset( $_REQUEST['orderby'] ) ) {
$args['orderby'] = $_REQUEST['orderby'];
}
if ( isset( $_REQUEST['order'] ) ) {
$args['order'] = $_REQUEST['order'];
}
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
$args = apply_filters( 'users_list_table_query_args', $args );
// Query the user IDs for this page.
$wp_user_search = new WP_User_Query( $args );
$this->items = $wp_user_search->get_results();
$this->set_pagination_args(
array(
'total_items' => $wp_user_search->get_total(),
'per_page' => $users_per_page,
)
);
}
/**
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( current_user_can( 'delete_users' ) ) {
$actions['delete'] = __( 'Delete' );
}
$actions['spam'] = _x( 'Mark as spam', 'user' );
$actions['notspam'] = _x( 'Not spam', 'user' );
return $actions;
}
/**
*/
public function no_items() {
_e( 'No users found.' );
}
/**
* @global string $role
* @return array
*/
protected function get_views() {
global $role;
$total_users = get_user_count();
$super_admins = get_super_admins();
$total_admins = count( $super_admins );
$role_links = array();
$role_links['all'] = array(
'url' => network_admin_url( 'users.php' ),
'label' => sprintf(
/* translators: Number of users. */
_nx(
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
$total_users,
'users'
),
number_format_i18n( $total_users )
),
'current' => 'super' !== $role,
);
$role_links['super'] = array(
'url' => network_admin_url( 'users.php?role=super' ),
'label' => sprintf(
/* translators: Number of users. */
_n(
'Super Admin <span class="count">(%s)</span>',
'Super Admins <span class="count">(%s)</span>',
$total_admins
),
number_format_i18n( $total_admins )
),
'current' => 'super' === $role,
);
return $this->get_views_links( $role_links );
}
/**
* @global string $mode List table view mode.
*
* @param string $which
*/
protected function pagination( $which ) {
global $mode;
parent::pagination( $which );
if ( 'top' === $which ) {
$this->view_switcher( $mode );
}
}
/**
* @return string[] Array of column titles keyed by their column name.
*/
public function get_columns() {
$users_columns = array(
'cb' => '<input type="checkbox" />',
'username' => __( 'Username' ),
'name' => __( 'Name' ),
'email' => __( 'Email' ),
'registered' => _x( 'Registered', 'user' ),
'blogs' => __( 'Sites' ),
);
/**
* Filters the columns displayed in the Network Admin Users list table.
*
* @since MU (3.0.0)
*
* @param string[] $users_columns An array of user columns. Default 'cb', 'username',
* 'name', 'email', 'registered', 'blogs'.
*/
return apply_filters( 'wpmu_users_columns', $users_columns );
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'username' => array( 'login', false, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ),
'name' => array( 'name', false, __( 'Name' ), __( 'Table ordered by Name.' ) ),
'email' => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ),
'registered' => array( 'id', false, _x( 'Registered', 'user' ), __( 'Table ordered by User Registered Date.' ) ),
);
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$user` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param WP_User $item The current WP_User object.
*/
public function column_cb( $item ) {
// Restores the more descriptive, specific name for use within this method.
$user = $item;
if ( is_super_admin( $user->ID ) ) {
return;
}
?>
<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
<label for="blog_<?php echo $user->ID; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. %s: User login. */
printf( __( 'Select %s' ), $user->user_login );
?>
</span>
</label>
<?php
}
/**
* Handles the ID column output.
*
* @since 4.4.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_id( $user ) {
echo $user->ID;
}
/**
* Handles the username column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_username( $user ) {
$super_admins = get_super_admins();
$avatar = get_avatar( $user->user_email, 32 );
echo $avatar;
if ( current_user_can( 'edit_user', $user->ID ) ) {
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
$edit = "<a href=\"{$edit_link}\">{$user->user_login}</a>";
} else {
$edit = $user->user_login;
}
?>
<strong>
<?php
echo $edit;
if ( in_array( $user->user_login, $super_admins, true ) ) {
echo ' — ' . __( 'Super Admin' );
}
?>
</strong>
<?php
}
/**
* Handles the name column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_name( $user ) {
if ( $user->first_name && $user->last_name ) {
printf(
/* translators: 1: User's first name, 2: Last name. */
_x( '%1$s %2$s', 'Display name based on first name and last name' ),
$user->first_name,
$user->last_name
);
} elseif ( $user->first_name ) {
echo $user->first_name;
} elseif ( $user->last_name ) {
echo $user->last_name;
} else {
echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
_x( 'Unknown', 'name' ) .
'</span>';
}
}
/**
* Handles the email column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_email( $user ) {
echo "<a href='" . esc_url( "mailto:$user->user_email" ) . "'>$user->user_email</a>";
}
/**
* Handles the registered date column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param WP_User $user The current WP_User object.
*/
public function column_registered( $user ) {
global $mode;
if ( 'list' === $mode ) {
$date = __( 'Y/m/d' );
} else {
$date = __( 'Y/m/d g:i:s a' );
}
echo mysql2date( $date, $user->user_registered );
}
/**
* @since 4.3.0
*
* @param WP_User $user
* @param string $classes
* @param string $data
* @param string $primary
*/
protected function _column_blogs( $user, $classes, $data, $primary ) {
echo '<td class="', $classes, ' has-row-actions" ', $data, '>';
echo $this->column_blogs( $user );
echo $this->handle_row_actions( $user, 'blogs', $primary );
echo '</td>';
}
/**
* Handles the sites column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_blogs( $user ) {
$blogs = get_blogs_of_user( $user->ID, true );
if ( ! is_array( $blogs ) ) {
return;
}
foreach ( $blogs as $site ) {
if ( ! can_edit_network( $site->site_id ) ) {
continue;
}
$path = ( '/' === $site->path ) ? '' : $site->path;
$site_classes = array( 'site-' . $site->site_id );
/**
* Filters the span class for a site listing on the multisite user list table.
*
* @since 5.2.0
*
* @param string[] $site_classes Array of class names used within the span tag.
* Default "site-#" with the site's network ID.
* @param int $site_id Site ID.
* @param int $network_id Network ID.
* @param WP_User $user WP_User object.
*/
$site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $site->userblog_id, $site->site_id, $user );
if ( is_array( $site_classes ) && ! empty( $site_classes ) ) {
$site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) );
echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">';
} else {
echo '<span>';
}
echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . str_replace( '.' . get_network()->domain, '', $site->domain . $path ) . '</a>';
echo ' <small class="row-actions">';
$actions = array();
$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>';
$class = '';
if ( 1 === (int) $site->spam ) {
$class .= 'site-spammed ';
}
if ( 1 === (int) $site->mature ) {
$class .= 'site-mature ';
}
if ( 1 === (int) $site->deleted ) {
$class .= 'site-deleted ';
}
if ( 1 === (int) $site->archived ) {
$class .= 'site-archived ';
}
$actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $site->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
/**
* Filters the action links displayed next the sites a user belongs to
* in the Network Admin Users list table.
*
* @since 3.1.0
*
* @param string[] $actions An array of action links to be displayed. Default 'Edit', 'View'.
* @param int $userblog_id The site ID.
*/
$actions = apply_filters( 'ms_user_list_site_actions', $actions, $site->userblog_id );
$action_count = count( $actions );
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
$separator = ( $i < $action_count ) ? ' | ' : '';
echo "<span class='$action'>{$link}{$separator}</span>";
}
echo '</small></span><br />';
}
}
/**
* Handles the default column output.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$user` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param WP_User $item The current WP_User object.
* @param string $column_name The current column name.
*/
public function column_default( $item, $column_name ) {
// Restores the more descriptive, specific name for use within this method.
$user = $item;
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
$column_output = apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
/**
* Filters the display output of custom columns in the Network Users list table.
*
* @since 6.8.0
*
* @param string $output Custom column output. Default empty.
* @param string $column_name Name of the custom column.
* @param int $user_id ID of the currently-listed user.
*/
echo apply_filters( 'manage_users-network_custom_column', $column_output, $column_name, $user->ID );
}
/**
* Generates the list table rows.
*
* @since 3.1.0
*/
public function display_rows() {
foreach ( $this->items as $user ) {
$class = '';
$status_list = array(
'spam' => 'site-spammed',
'deleted' => 'site-deleted',
);
foreach ( $status_list as $status => $col ) {
if ( $user->$status ) {
$class .= " $col";
}
}
?>
<tr class="<?php echo trim( $class ); ?>">
<?php $this->single_row_columns( $user ); ?>
</tr>
<?php
}
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'username'.
*/
protected function get_default_primary_column_name() {
return 'username';
}
/**
* Generates and displays row action links.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$user` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param WP_User $item User being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row actions output for users in Multisite, or an empty string
* if the current column is not the primary column.
*/
protected function handle_row_actions( $item, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
// Restores the more descriptive, specific name for use within this method.
$user = $item;
$super_admins = get_super_admins();
$actions = array();
if ( current_user_can( 'edit_user', $user->ID ) ) {
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
}
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins, true ) ) {
$actions['delete'] = '<a href="' . esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
}
/**
* Filters the action links displayed under each user in the Network Admin Users list table.
*
* @since 3.2.0
*
* @param string[] $actions An array of action links to be displayed. Default 'Edit', 'Delete'.
* @param WP_User $user WP_User object.
*/
$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
return $this->row_actions( $actions );
}
}
PK �MP\���� � taxonomy.phpnu �[��� <?php
/**
* WordPress Taxonomy Administration API.
*
* @package WordPress
* @subpackage Administration
*/
//
// Category.
//
/**
* Checks whether a category exists.
*
* @since 2.0.0
*
* @see term_exists()
*
* @param int|string $cat_name Category name.
* @param int $category_parent Optional. ID of parent category.
* @return string|null Returns the category ID as a numeric string if the pairing exists, null if not.
*/
function category_exists( $cat_name, $category_parent = null ) {
$id = term_exists( $cat_name, 'category', $category_parent );
if ( is_array( $id ) ) {
$id = $id['term_id'];
}
return $id;
}
/**
* Gets category object for given ID and 'edit' filter context.
*
* @since 2.0.0
*
* @param int $id
* @return object
*/
function get_category_to_edit( $id ) {
$category = get_term( $id, 'category', OBJECT, 'edit' );
_make_cat_compat( $category );
return $category;
}
/**
* Adds a new category to the database if it does not already exist.
*
* @since 2.0.0
*
* @param int|string $cat_name Category name.
* @param int $category_parent Optional. ID of parent category.
* @return int|WP_Error
*/
function wp_create_category( $cat_name, $category_parent = 0 ) {
$id = category_exists( $cat_name, $category_parent );
if ( $id ) {
return $id;
}
return wp_insert_category(
array(
'cat_name' => $cat_name,
'category_parent' => $category_parent,
)
);
}
/**
* Creates categories for the given post.
*
* @since 2.0.0
*
* @param string[] $categories Array of category names to create.
* @param int $post_id Optional. The post ID. Default empty.
* @return int[] Array of IDs of categories assigned to the given post.
*/
function wp_create_categories( $categories, $post_id = 0 ) {
$cat_ids = array();
foreach ( $categories as $category ) {
$id = category_exists( $category );
if ( $id ) {
$cat_ids[] = $id;
} else {
$id = wp_create_category( $category );
if ( $id ) {
$cat_ids[] = $id;
}
}
}
if ( $post_id ) {
wp_set_post_categories( $post_id, $cat_ids );
}
return $cat_ids;
}
/**
* Updates an existing Category or creates a new Category.
*
* @since 2.0.0
* @since 2.5.0 $wp_error parameter was added.
* @since 3.0.0 The 'taxonomy' argument was added.
*
* @param array $catarr {
* Array of arguments for inserting a new category.
*
* @type int $cat_ID Category ID. A non-zero value updates an existing category.
* Default 0.
* @type string $taxonomy Taxonomy slug. Default 'category'.
* @type string $cat_name Category name. Default empty.
* @type string $category_description Category description. Default empty.
* @type string $category_nicename Category nice (display) name. Default empty.
* @type int|string $category_parent Category parent ID. Default empty.
* }
* @param bool $wp_error Optional. Default false.
* @return int|WP_Error The ID number of the new or updated Category on success. Zero or a WP_Error on failure,
* depending on param `$wp_error`.
*/
function wp_insert_category( $catarr, $wp_error = false ) {
$cat_defaults = array(
'cat_ID' => 0,
'taxonomy' => 'category',
'cat_name' => '',
'category_description' => '',
'category_nicename' => '',
'category_parent' => '',
);
$catarr = wp_parse_args( $catarr, $cat_defaults );
if ( '' === trim( $catarr['cat_name'] ) ) {
if ( ! $wp_error ) {
return 0;
} else {
return new WP_Error( 'cat_name', __( 'You did not enter a category name.' ) );
}
}
$catarr['cat_ID'] = (int) $catarr['cat_ID'];
// Are we updating or creating?
$update = ! empty( $catarr['cat_ID'] );
$name = $catarr['cat_name'];
$description = $catarr['category_description'];
$slug = $catarr['category_nicename'];
$parent = (int) $catarr['category_parent'];
if ( $parent < 0 ) {
$parent = 0;
}
if ( empty( $parent )
|| ! term_exists( $parent, $catarr['taxonomy'] )
|| ( $catarr['cat_ID'] && term_is_ancestor_of( $catarr['cat_ID'], $parent, $catarr['taxonomy'] ) ) ) {
$parent = 0;
}
$args = compact( 'name', 'slug', 'parent', 'description' );
if ( $update ) {
$catarr['cat_ID'] = wp_update_term( $catarr['cat_ID'], $catarr['taxonomy'], $args );
} else {
$catarr['cat_ID'] = wp_insert_term( $catarr['cat_name'], $catarr['taxonomy'], $args );
}
if ( is_wp_error( $catarr['cat_ID'] ) ) {
if ( $wp_error ) {
return $catarr['cat_ID'];
} else {
return 0;
}
}
return $catarr['cat_ID']['term_id'];
}
/**
* Aliases wp_insert_category() with minimal args.
*
* If you want to update only some fields of an existing category, call this
* function with only the new values set inside $catarr.
*
* @since 2.0.0
*
* @param array $catarr The 'cat_ID' value is required. All other keys are optional.
* @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
*/
function wp_update_category( $catarr ) {
$cat_id = (int) $catarr['cat_ID'];
if ( isset( $catarr['category_parent'] ) && ( $cat_id === (int) $catarr['category_parent'] ) ) {
return false;
}
// First, get all of the original fields.
$category = get_term( $cat_id, 'category', ARRAY_A );
_make_cat_compat( $category );
// Escape data pulled from DB.
$category = wp_slash( $category );
// Merge old and new fields with new fields overwriting old ones.
$catarr = array_merge( $category, $catarr );
return wp_insert_category( $catarr );
}
//
// Tags.
//
/**
* Checks whether a post tag with a given name exists.
*
* @since 2.3.0
*
* @param int|string $tag_name
* @return mixed Returns null if the term does not exist.
* Returns an array of the term ID and the term taxonomy ID if the pairing exists.
* Returns 0 if term ID 0 is passed to the function.
*/
function tag_exists( $tag_name ) {
return term_exists( $tag_name, 'post_tag' );
}
/**
* Adds a new tag to the database if it does not already exist.
*
* @since 2.3.0
*
* @param int|string $tag_name
* @return array|WP_Error
*/
function wp_create_tag( $tag_name ) {
return wp_create_term( $tag_name, 'post_tag' );
}
/**
* Gets comma-separated list of tags available to edit.
*
* @since 2.3.0
*
* @param int $post_id
* @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
* @return string|false|WP_Error
*/
function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
return get_terms_to_edit( $post_id, $taxonomy );
}
/**
* Gets comma-separated list of terms available to edit for the given post ID.
*
* @since 2.8.0
*
* @param int $post_id
* @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
* @return string|false|WP_Error
*/
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$post_id = (int) $post_id;
if ( ! $post_id ) {
return false;
}
$terms = get_object_term_cache( $post_id, $taxonomy );
if ( false === $terms ) {
$terms = wp_get_object_terms( $post_id, $taxonomy );
wp_cache_add( $post_id, wp_list_pluck( $terms, 'term_id' ), $taxonomy . '_relationships' );
}
if ( ! $terms ) {
return false;
}
if ( is_wp_error( $terms ) ) {
return $terms;
}
$term_names = array();
foreach ( $terms as $term ) {
$term_names[] = $term->name;
}
$terms_to_edit = esc_attr( implode( ',', $term_names ) );
/**
* Filters the comma-separated list of terms available to edit.
*
* @since 2.8.0
*
* @see get_terms_to_edit()
*
* @param string $terms_to_edit A comma-separated list of term names.
* @param string $taxonomy The taxonomy name for which to retrieve terms.
*/
$terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy );
return $terms_to_edit;
}
/**
* Adds a new term to the database if it does not already exist.
*
* @since 2.8.0
*
* @param string $tag_name The term name.
* @param string $taxonomy Optional. The taxonomy within which to create the term. Default 'post_tag'.
* @return array|WP_Error
*/
function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
$id = term_exists( $tag_name, $taxonomy );
if ( $id ) {
return $id;
}
return wp_insert_term( $tag_name, $taxonomy );
}
PK �MP\� �
import.phpnu �[��� <?php
/**
* WordPress Administration Importer API.
*
* @package WordPress
* @subpackage Administration
*/
/**
* Retrieves the list of importers.
*
* @since 2.0.0
*
* @global array $wp_importers
* @return array
*/
function get_importers() {
global $wp_importers;
if ( is_array( $wp_importers ) ) {
uasort( $wp_importers, '_usort_by_first_member' );
}
return $wp_importers;
}
/**
* Sorts a multidimensional array by first member of each top level member.
*
* Used by uasort() as a callback, should not be used directly.
*
* @since 2.9.0
* @access private
*
* @param array $a
* @param array $b
* @return int
*/
function _usort_by_first_member( $a, $b ) {
return strnatcasecmp( $a[0], $b[0] );
}
/**
* Registers importer for WordPress.
*
* @since 2.0.0
*
* @global array $wp_importers
*
* @param string $id Importer tag. Used to uniquely identify importer.
* @param string $name Importer name and title.
* @param string $description Importer description.
* @param callable $callback Callback to run.
* @return void|WP_Error Void on success. WP_Error when $callback is WP_Error.
*/
function register_importer( $id, $name, $description, $callback ) {
global $wp_importers;
if ( is_wp_error( $callback ) ) {
return $callback;
}
$wp_importers[ $id ] = array( $name, $description, $callback );
}
/**
* Cleanup importer.
*
* Removes attachment based on ID.
*
* @since 2.0.0
*
* @param string $id Importer ID.
*/
function wp_import_cleanup( $id ) {
wp_delete_attachment( $id );
}
/**
* Handles importer uploading and adds attachment.
*
* @since 2.0.0
*
* @return array Uploaded file's details on success, error message on failure.
*/
function wp_import_handle_upload() {
if ( ! isset( $_FILES['import'] ) ) {
return array(
'error' => sprintf(
/* translators: 1: php.ini, 2: post_max_size, 3: upload_max_filesize */
__( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your %1$s file or by %2$s being defined as smaller than %3$s in %1$s.' ),
'php.ini',
'post_max_size',
'upload_max_filesize'
),
);
}
$overrides = array(
'test_form' => false,
'test_type' => false,
);
$_FILES['import']['name'] .= '.txt';
$upload = wp_handle_upload( $_FILES['import'], $overrides );
if ( isset( $upload['error'] ) ) {
return $upload;
}
// Construct the attachment array.
$attachment = array(
'post_title' => wp_basename( $upload['file'] ),
'post_content' => $upload['url'],
'post_mime_type' => $upload['type'],
'guid' => $upload['url'],
'context' => 'import',
'post_status' => 'private',
);
// Save the data.
$id = wp_insert_attachment( $attachment, $upload['file'] );
/*
* Schedule a cleanup for one day from now in case of failed
* import or missing wp_import_cleanup() call.
*/
wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );
return array(
'file' => $upload['file'],
'id' => $id,
);
}
/**
* Returns a list from WordPress.org of popular importer plugins.
*
* @since 3.5.0
*
* @return array Importers with metadata for each.
*/
function wp_get_popular_importers() {
$locale = get_user_locale();
$cache_key = 'popular_importers_' . md5( $locale . wp_get_wp_version() );
$popular_importers = get_site_transient( $cache_key );
if ( ! $popular_importers ) {
$url = add_query_arg(
array(
'locale' => $locale,
'version' => wp_get_wp_version(),
),
'http://api.wordpress.org/core/importers/1.1/'
);
$options = array( 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ) );
if ( wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$response = wp_remote_get( $url, $options );
$popular_importers = json_decode( wp_remote_retrieve_body( $response ), true );
if ( is_array( $popular_importers ) ) {
set_site_transient( $cache_key, $popular_importers, 2 * DAY_IN_SECONDS );
} else {
$popular_importers = false;
}
}
if ( is_array( $popular_importers ) ) {
// If the data was received as translated, return it as-is.
if ( $popular_importers['translated'] ) {
return $popular_importers['importers'];
}
foreach ( $popular_importers['importers'] as &$importer ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
$importer['description'] = translate( $importer['description'] );
if ( 'WordPress' !== $importer['name'] ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
$importer['name'] = translate( $importer['name'] );
}
}
return $popular_importers['importers'];
}
return array(
// slug => name, description, plugin slug, and register_importer() slug.
'blogger' => array(
'name' => __( 'Blogger' ),
'description' => __( 'Import posts, comments, and users from a Blogger blog.' ),
'plugin-slug' => 'blogger-importer',
'importer-id' => 'blogger',
),
'wpcat2tag' => array(
'name' => __( 'Categories and Tags Converter' ),
'description' => __( 'Convert existing categories to tags or tags to categories, selectively.' ),
'plugin-slug' => 'wpcat2tag-importer',
'importer-id' => 'wp-cat2tag',
),
'livejournal' => array(
'name' => __( 'LiveJournal' ),
'description' => __( 'Import posts from LiveJournal using their API.' ),
'plugin-slug' => 'livejournal-importer',
'importer-id' => 'livejournal',
),
'movabletype' => array(
'name' => __( 'Movable Type and TypePad' ),
'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ),
'plugin-slug' => 'movabletype-importer',
'importer-id' => 'mt',
),
'rss' => array(
'name' => __( 'RSS' ),
'description' => __( 'Import posts from an RSS feed.' ),
'plugin-slug' => 'rss-importer',
'importer-id' => 'rss',
),
'tumblr' => array(
'name' => __( 'Tumblr' ),
'description' => __( 'Import posts & media from Tumblr using their API.' ),
'plugin-slug' => 'tumblr-importer',
'importer-id' => 'tumblr',
),
'wordpress' => array(
'name' => 'WordPress',
'description' => __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ),
'plugin-slug' => 'wordpress-importer',
'importer-id' => 'wordpress',
),
);
}
PK �MP\�`� class-wp-debug-data.phpnu �[��� <?php
/**
* Class for providing debug data based on a users WordPress environment.
*
* @package WordPress
* @subpackage Site_Health
* @since 5.2.0
*/
#[AllowDynamicProperties]
class WP_Debug_Data {
/**
* Calls all core functions to check for updates.
*
* @since 5.2.0
*/
public static function check_for_updates() {
wp_version_check();
wp_update_plugins();
wp_update_themes();
}
/**
* Static function for generating site debug data when required.
*
* @since 5.2.0
* @since 5.3.0 Added database charset, database collation,
* and timezone information.
* @since 5.5.0 Added pretty permalinks support information.
* @since 6.7.0 Modularized into separate theme-oriented methods.
*
* @throws ImagickException
*
* @return array The debug data for the site.
*/
public static function debug_data() {
/*
* Set up the array that holds all debug information.
*
* When iterating through the debug data, the ordering of the sections
* occurs in insertion-order of the assignments into this array.
*
* This is the single assignment of the sections before filtering. Null-entries will
* be automatically be removed.
*/
$info = array(
'wp-core' => self::get_wp_core(),
'wp-paths-sizes' => self::get_wp_paths_sizes(),
'wp-dropins' => self::get_wp_dropins(),
'wp-active-theme' => self::get_wp_active_theme(),
'wp-parent-theme' => self::get_wp_parent_theme(),
'wp-themes-inactive' => self::get_wp_themes_inactive(),
'wp-mu-plugins' => self::get_wp_mu_plugins(),
'wp-plugins-active' => self::get_wp_plugins_active(),
'wp-plugins-inactive' => self::get_wp_plugins_inactive(),
'wp-media' => self::get_wp_media(),
'wp-server' => self::get_wp_server(),
'wp-database' => self::get_wp_database(),
'wp-constants' => self::get_wp_constants(),
'wp-filesystem' => self::get_wp_filesystem(),
);
/*
* Remove null elements from the array. The individual methods are
* allowed to return `null`, which communicates that the category
* of debug data isn't relevant and shouldn't be passed through.
*/
$info = array_filter(
$info,
static function ( $section ) {
return isset( $section );
}
);
/**
* Filters the debug information shown on the Tools -> Site Health -> Info screen.
*
* Plugin or themes may wish to introduce their own debug information without creating
* additional admin pages. They can utilize this filter to introduce their own sections
* or add more data to existing sections.
*
* Array keys for sections added by core are all prefixed with `wp-`. Plugins and themes
* should use their own slug as a prefix, both for consistency as well as avoiding
* key collisions. Note that the array keys are used as labels for the copied data.
*
* All strings are expected to be plain text except `$description` that can contain
* inline HTML tags (see below).
*
* @since 5.2.0
*
* @param array $args {
* The debug information to be added to the core information page.
*
* This is an associative multi-dimensional array, up to three levels deep.
* The topmost array holds the sections, keyed by section ID.
*
* @type array ...$0 {
* Each section has a `$fields` associative array (see below), and each `$value` in `$fields`
* can be another associative array of name/value pairs when there is more structured data
* to display.
*
* @type string $label Required. The title for this section of the debug output.
* @type string $description Optional. A description for your information section which
* may contain basic HTML markup, inline tags only as it is
* outputted in a paragraph.
* @type bool $show_count Optional. If set to `true`, the amount of fields will be included
* in the title for this section. Default false.
* @type bool $private Optional. If set to `true`, the section and all associated fields
* will be excluded from the copied data. Default false.
* @type array $fields {
* Required. An associative array containing the fields to be displayed in the section,
* keyed by field ID.
*
* @type array ...$0 {
* An associative array containing the data to be displayed for the field.
*
* @type string $label Required. The label for this piece of information.
* @type mixed $value Required. The output that is displayed for this field.
* Text should be translated. Can be an associative array
* that is displayed as name/value pairs.
* Accepted types: `string|int|float|(string|int|float)[]`.
* @type string $debug Optional. The output that is used for this field when
* the user copies the data. It should be more concise and
* not translated. If not set, the content of `$value`
* is used. Note that the array keys are used as labels
* for the copied data.
* @type bool $private Optional. If set to `true`, the field will be excluded
* from the copied data, allowing you to show, for example,
* API keys here. Default false.
* }
* }
* }
* }
*/
$info = apply_filters( 'debug_information', $info );
return $info;
}
/**
* Gets the WordPress core section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_core(): array {
// Save few function calls.
$permalink_structure = get_option( 'permalink_structure' );
$is_ssl = is_ssl();
$users_can_register = get_option( 'users_can_register' );
$blog_public = get_option( 'blog_public' );
$default_comment_status = get_option( 'default_comment_status' );
$environment_type = wp_get_environment_type();
$core_version = wp_get_wp_version();
$core_updates = get_core_updates();
$core_update_needed = '';
if ( is_array( $core_updates ) ) {
foreach ( $core_updates as $core => $update ) {
if ( 'upgrade' === $update->response ) {
/* translators: %s: Latest WordPress version number. */
$core_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $update->version );
} else {
$core_update_needed = '';
}
}
}
$fields = array(
'version' => array(
'label' => __( 'Version' ),
'value' => $core_version . $core_update_needed,
'debug' => $core_version,
),
'site_language' => array(
'label' => __( 'Site Language' ),
'value' => get_locale(),
),
'user_language' => array(
'label' => __( 'User Language' ),
'value' => get_user_locale(),
),
'timezone' => array(
'label' => __( 'Timezone' ),
'value' => wp_timezone_string(),
),
'home_url' => array(
'label' => __( 'Home URL' ),
'value' => get_bloginfo( 'url' ),
'private' => true,
),
'site_url' => array(
'label' => __( 'Site URL' ),
'value' => get_bloginfo( 'wpurl' ),
'private' => true,
),
'permalink' => array(
'label' => __( 'Permalink structure' ),
'value' => $permalink_structure ? $permalink_structure : __( 'No permalink structure set' ),
'debug' => $permalink_structure,
),
'https_status' => array(
'label' => __( 'Is this site using HTTPS?' ),
'value' => $is_ssl ? __( 'Yes' ) : __( 'No' ),
'debug' => $is_ssl,
),
'multisite' => array(
'label' => __( 'Is this a multisite?' ),
'value' => is_multisite() ? __( 'Yes' ) : __( 'No' ),
'debug' => is_multisite(),
),
'user_registration' => array(
'label' => __( 'Can anyone register on this site?' ),
'value' => $users_can_register ? __( 'Yes' ) : __( 'No' ),
'debug' => $users_can_register,
),
'blog_public' => array(
'label' => __( 'Is this site discouraging search engines?' ),
'value' => $blog_public ? __( 'No' ) : __( 'Yes' ),
'debug' => $blog_public,
),
'default_comment_status' => array(
'label' => __( 'Default comment status' ),
'value' => 'open' === $default_comment_status ? _x( 'Open', 'comment status' ) : _x( 'Closed', 'comment status' ),
'debug' => $default_comment_status,
),
'environment_type' => array(
'label' => __( 'Environment type' ),
'value' => $environment_type,
'debug' => $environment_type,
),
);
// Conditionally add debug information for multisite setups.
if ( is_multisite() ) {
$site_id = get_current_blog_id();
$fields['site_id'] = array(
'label' => __( 'Site ID' ),
'value' => $site_id,
'debug' => $site_id,
);
$network_query = new WP_Network_Query();
$network_ids = $network_query->query(
array(
'fields' => 'ids',
'number' => 100,
'no_found_rows' => false,
)
);
$site_count = 0;
foreach ( $network_ids as $network_id ) {
$site_count += get_blog_count( $network_id );
}
$fields['site_count'] = array(
'label' => __( 'Site count' ),
'value' => $site_count,
);
$fields['network_count'] = array(
'label' => __( 'Network count' ),
'value' => $network_query->found_networks,
);
}
$fields['user_count'] = array(
'label' => __( 'User count' ),
'value' => get_user_count(),
);
// WordPress features requiring processing.
$wp_dotorg = wp_remote_get( 'https://wordpress.org', array( 'timeout' => 10 ) );
if ( ! is_wp_error( $wp_dotorg ) ) {
$fields['dotorg_communication'] = array(
'label' => __( 'Communication with WordPress.org' ),
'value' => __( 'WordPress.org is reachable' ),
'debug' => 'true',
);
} else {
$fields['dotorg_communication'] = array(
'label' => __( 'Communication with WordPress.org' ),
'value' => sprintf(
/* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
__( 'Unable to reach WordPress.org at %1$s: %2$s' ),
gethostbyname( 'wordpress.org' ),
$wp_dotorg->get_error_message()
),
'debug' => $wp_dotorg->get_error_message(),
);
}
return array(
'label' => __( 'WordPress' ),
'fields' => $fields,
);
}
/**
* Gets the WordPress drop-in section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_dropins(): array {
// Get a list of all drop-in replacements.
$dropins = get_dropins();
// Get drop-ins descriptions.
$dropin_descriptions = _get_dropins();
$fields = array();
foreach ( $dropins as $dropin_key => $dropin ) {
$fields[ sanitize_text_field( $dropin_key ) ] = array(
'label' => $dropin_key,
'value' => $dropin_descriptions[ $dropin_key ][0],
'debug' => 'true',
);
}
return array(
'label' => __( 'Drop-ins' ),
'show_count' => true,
'description' => sprintf(
/* translators: %s: wp-content directory name. */
__( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ),
'<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>'
),
'fields' => $fields,
);
}
/**
* Gets the WordPress server section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_server(): array {
// Populate the server debug fields.
if ( function_exists( 'php_uname' ) ) {
$server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
} else {
$server_architecture = 'unknown';
}
$php_version_debug = PHP_VERSION;
// Whether PHP supports 64-bit.
$php64bit = ( PHP_INT_SIZE * 8 === 64 );
$php_version = sprintf(
'%s %s',
$php_version_debug,
( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
);
if ( $php64bit ) {
$php_version_debug .= ' 64bit';
}
$fields = array();
$fields['server_architecture'] = array(
'label' => __( 'Server architecture' ),
'value' => ( 'unknown' !== $server_architecture ? $server_architecture : __( 'Unable to determine server architecture' ) ),
'debug' => $server_architecture,
);
$fields['httpd_software'] = array(
'label' => __( 'Web server' ),
'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ),
'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
);
$fields['php_version'] = array(
'label' => __( 'PHP version' ),
'value' => $php_version,
'debug' => $php_version_debug,
);
$fields['php_sapi'] = array(
'label' => __( 'PHP SAPI' ),
'value' => PHP_SAPI,
'debug' => PHP_SAPI,
);
// Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
if ( ! function_exists( 'ini_get' ) ) {
$fields['ini_get'] = array(
'label' => __( 'Server settings' ),
'value' => sprintf(
/* translators: %s: ini_get() */
__( 'Unable to determine some settings, as the %s function has been disabled.' ),
'ini_get()'
),
'debug' => 'ini_get() is disabled',
);
} else {
$fields['max_input_variables'] = array(
'label' => __( 'PHP max input variables' ),
'value' => ini_get( 'max_input_vars' ),
);
$fields['time_limit'] = array(
'label' => __( 'PHP time limit' ),
'value' => ini_get( 'max_execution_time' ),
);
if ( WP_Site_Health::get_instance()->php_memory_limit !== ini_get( 'memory_limit' ) ) {
$fields['memory_limit'] = array(
'label' => __( 'PHP memory limit' ),
'value' => WP_Site_Health::get_instance()->php_memory_limit,
);
$fields['admin_memory_limit'] = array(
'label' => __( 'PHP memory limit (only for admin screens)' ),
'value' => ini_get( 'memory_limit' ),
);
} else {
$fields['memory_limit'] = array(
'label' => __( 'PHP memory limit' ),
'value' => ini_get( 'memory_limit' ),
);
}
$fields['max_input_time'] = array(
'label' => __( 'Max input time' ),
'value' => ini_get( 'max_input_time' ),
);
$fields['upload_max_filesize'] = array(
'label' => __( 'Upload max filesize' ),
'value' => ini_get( 'upload_max_filesize' ),
);
$fields['php_post_max_size'] = array(
'label' => __( 'PHP post max size' ),
'value' => ini_get( 'post_max_size' ),
);
}
if ( function_exists( 'curl_version' ) ) {
$curl = curl_version();
$fields['curl_version'] = array(
'label' => __( 'cURL version' ),
'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
);
} else {
$fields['curl_version'] = array(
'label' => __( 'cURL version' ),
'value' => __( 'Not available' ),
'debug' => 'not available',
);
}
// SUHOSIN.
$suhosin_loaded = ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) );
$fields['suhosin'] = array(
'label' => __( 'Is SUHOSIN installed?' ),
'value' => ( $suhosin_loaded ? __( 'Yes' ) : __( 'No' ) ),
'debug' => $suhosin_loaded,
);
// Imagick.
$imagick_loaded = extension_loaded( 'imagick' );
$fields['imagick_availability'] = array(
'label' => __( 'Is the Imagick library available?' ),
'value' => ( $imagick_loaded ? __( 'Yes' ) : __( 'No' ) ),
'debug' => $imagick_loaded,
);
// Pretty permalinks.
$pretty_permalinks_supported = got_url_rewrite();
$fields['pretty_permalinks'] = array(
'label' => __( 'Are pretty permalinks supported?' ),
'value' => ( $pretty_permalinks_supported ? __( 'Yes' ) : __( 'No' ) ),
'debug' => $pretty_permalinks_supported,
);
// Check if a .htaccess file exists.
if ( is_file( ABSPATH . '.htaccess' ) ) {
// If the file exists, grab the content of it.
$htaccess_content = file_get_contents( ABSPATH . '.htaccess' );
// Filter away the core WordPress rules.
$filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
$filtered_htaccess_content = ! empty( $filtered_htaccess_content );
if ( $filtered_htaccess_content ) {
/* translators: %s: .htaccess */
$htaccess_rules_string = sprintf( __( 'Custom rules have been added to your %s file.' ), '.htaccess' );
} else {
/* translators: %s: .htaccess */
$htaccess_rules_string = sprintf( __( 'Your %s file contains only core WordPress features.' ), '.htaccess' );
}
$fields['htaccess_extra_rules'] = array(
'label' => __( '.htaccess rules' ),
'value' => $htaccess_rules_string,
'debug' => $filtered_htaccess_content,
);
}
// Check if a robots.txt file exists.
if ( is_file( ABSPATH . 'robots.txt' ) ) {
// If the file exists, turn debug info to true.
$robotstxt_debug = true;
/* translators: %s: robots.txt */
$robotstxt_string = sprintf( __( 'There is a static %s file in your installation folder. WordPress cannot dynamically serve one.' ), 'robots.txt' );
} elseif ( got_url_rewrite() ) {
// No robots.txt file available and rewrite rules in place, turn debug info to false.
$robotstxt_debug = false;
/* translators: %s: robots.txt */
$robotstxt_string = sprintf( __( 'Your site is using the dynamic %s file which is generated by WordPress.' ), 'robots.txt' );
} else {
// No robots.txt file, but without rewrite rules WP can't serve one.
$robotstxt_debug = true;
/* translators: %s: robots.txt */
$robotstxt_string = sprintf( __( 'WordPress cannot dynamically serve a %s file due to a lack of rewrite rule support' ), 'robots.txt' );
}
$fields['static_robotstxt_file'] = array(
'label' => __( 'robots.txt' ),
'value' => $robotstxt_string,
'debug' => $robotstxt_debug,
);
// Server time.
$date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
$fields['current'] = array(
'label' => __( 'Current time' ),
'value' => $date->format( DateTime::ATOM ),
);
$fields['utc-time'] = array(
'label' => __( 'Current UTC time' ),
'value' => $date->format( DateTime::RFC850 ),
);
$fields['server-time'] = array(
'label' => __( 'Current Server time' ),
'value' => wp_date( 'c', $_SERVER['REQUEST_TIME'] ),
);
return array(
'label' => __( 'Server' ),
'description' => __( 'The options shown below relate to your server setup. If changes are required, you may need your web host’s assistance.' ),
'fields' => $fields,
);
}
/**
* Gets the WordPress media section of the debug data.
*
* @since 6.7.0
*
* @throws ImagickException
* @return array
*/
private static function get_wp_media(): array {
// Spare few function calls.
$not_available = __( 'Not available' );
// Populate the media fields.
$fields['image_editor'] = array(
'label' => __( 'Active editor' ),
'value' => _wp_image_editor_choose(),
);
// Get ImageMagic information, if available.
if ( class_exists( 'Imagick' ) ) {
// Save the Imagick instance for later use.
$imagick = new Imagick();
$imagemagick_version = $imagick->getVersion();
} else {
$imagemagick_version = __( 'Not available' );
}
$fields['imagick_module_version'] = array(
'label' => __( 'ImageMagick version number' ),
'value' => ( is_array( $imagemagick_version ) ? $imagemagick_version['versionNumber'] : $imagemagick_version ),
);
$fields['imagemagick_version'] = array(
'label' => __( 'ImageMagick version string' ),
'value' => ( is_array( $imagemagick_version ) ? $imagemagick_version['versionString'] : $imagemagick_version ),
);
$imagick_version = phpversion( 'imagick' );
$fields['imagick_version'] = array(
'label' => __( 'Imagick version' ),
'value' => ( $imagick_version ) ? $imagick_version : __( 'Not available' ),
);
if ( ! function_exists( 'ini_get' ) ) {
$fields['ini_get'] = array(
'label' => __( 'File upload settings' ),
'value' => sprintf(
/* translators: %s: ini_get() */
__( 'Unable to determine some settings, as the %s function has been disabled.' ),
'ini_get()'
),
'debug' => 'ini_get() is disabled',
);
} else {
// Get the PHP ini directive values.
$file_uploads = ini_get( 'file_uploads' );
$post_max_size = ini_get( 'post_max_size' );
$upload_max_filesize = ini_get( 'upload_max_filesize' );
$max_file_uploads = ini_get( 'max_file_uploads' );
$effective = min( wp_convert_hr_to_bytes( $post_max_size ), wp_convert_hr_to_bytes( $upload_max_filesize ) );
// Add info in Media section.
$fields['file_uploads'] = array(
'label' => __( 'File uploads' ),
'value' => $file_uploads ? __( 'Enabled' ) : __( 'Disabled' ),
'debug' => $file_uploads,
);
$fields['post_max_size'] = array(
'label' => __( 'Max size of post data allowed' ),
'value' => $post_max_size,
);
$fields['upload_max_filesize'] = array(
'label' => __( 'Max size of an uploaded file' ),
'value' => $upload_max_filesize,
);
$fields['max_effective_size'] = array(
'label' => __( 'Max effective file size' ),
'value' => size_format( $effective ),
);
$fields['max_file_uploads'] = array(
'label' => __( 'Max simultaneous file uploads' ),
'value' => $max_file_uploads,
);
}
// If Imagick is used as our editor, provide some more information about its limitations.
if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) {
$limits = array(
'area' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : $not_available ),
'disk' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : $not_available ),
'file' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : $not_available ),
'map' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : $not_available ),
'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : $not_available ),
'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : $not_available ),
'time' => ( defined( 'imagick::RESOURCETYPE_TIME' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_TIME ) : $not_available ),
);
$limits_debug = array(
'imagick::RESOURCETYPE_AREA' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : 'not available' ),
'imagick::RESOURCETYPE_DISK' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : 'not available' ),
'imagick::RESOURCETYPE_FILE' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : 'not available' ),
'imagick::RESOURCETYPE_MAP' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : 'not available' ),
'imagick::RESOURCETYPE_MEMORY' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : 'not available' ),
'imagick::RESOURCETYPE_THREAD' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : 'not available' ),
'imagick::RESOURCETYPE_TIME' => ( defined( 'imagick::RESOURCETYPE_TIME' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_TIME ) : 'not available' ),
);
$fields['imagick_limits'] = array(
'label' => __( 'Imagick Resource Limits' ),
'value' => $limits,
'debug' => $limits_debug,
);
try {
$formats = Imagick::queryFormats( '*' );
} catch ( Exception $e ) {
$formats = array();
}
$fields['imagemagick_file_formats'] = array(
'label' => __( 'ImageMagick supported file formats' ),
'value' => ( empty( $formats ) ) ? __( 'Unable to determine' ) : implode( ', ', $formats ),
'debug' => ( empty( $formats ) ) ? 'Unable to determine' : implode( ', ', $formats ),
);
}
// Get the image format transforms.
$mappings = wp_get_image_editor_output_format( '', '' );
$formatted_mappings = array();
if ( ! empty( $mappings ) ) {
foreach ( $mappings as $format => $mime_type ) {
$formatted_mappings[] = sprintf( '%s → %s', $format, $mime_type );
}
$mappings_display = implode( ', ', $formatted_mappings );
} else {
$mappings_display = __( 'No format transforms defined' );
}
$fields['image_format_transforms'] = array(
'label' => __( 'Image format transforms' ),
'value' => $mappings_display,
'debug' => ( empty( $mappings ) ) ? 'No format transforms defined' : $mappings_display,
);
// Get GD information, if available.
if ( function_exists( 'gd_info' ) ) {
$gd = gd_info();
} else {
$gd = false;
}
$fields['gd_version'] = array(
'label' => __( 'GD version' ),
'value' => ( is_array( $gd ) ? $gd['GD Version'] : $not_available ),
'debug' => ( is_array( $gd ) ? $gd['GD Version'] : 'not available' ),
);
$gd_image_formats = array();
$gd_supported_formats = array(
'GIF Create' => 'GIF',
'JPEG' => 'JPEG',
'PNG' => 'PNG',
'WebP' => 'WebP',
'BMP' => 'BMP',
'AVIF' => 'AVIF',
'HEIF' => 'HEIF',
'TIFF' => 'TIFF',
'XPM' => 'XPM',
);
foreach ( $gd_supported_formats as $format_key => $format ) {
$index = $format_key . ' Support';
if ( isset( $gd[ $index ] ) && $gd[ $index ] ) {
array_push( $gd_image_formats, $format );
}
}
if ( ! empty( $gd_image_formats ) ) {
$fields['gd_formats'] = array(
'label' => __( 'GD supported file formats' ),
'value' => implode( ', ', $gd_image_formats ),
);
}
// Get Ghostscript information, if available.
if ( function_exists( 'exec' ) ) {
$gs = exec( 'gs --version' );
if ( empty( $gs ) ) {
$gs = $not_available;
$gs_debug = 'not available';
} else {
$gs_debug = $gs;
}
} else {
$gs = __( 'Unable to determine if Ghostscript is installed' );
$gs_debug = 'unknown';
}
$fields['ghostscript_version'] = array(
'label' => __( 'Ghostscript version' ),
'value' => $gs,
'debug' => $gs_debug,
);
return array(
'label' => __( 'Media Handling' ),
'fields' => $fields,
);
}
/**
* Gets the WordPress MU plugins section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_mu_plugins(): array {
// List must use plugins if there are any.
$mu_plugins = get_mu_plugins();
$fields = array();
foreach ( $mu_plugins as $plugin_path => $plugin ) {
$plugin_version = $plugin['Version'];
$plugin_author = $plugin['Author'];
$plugin_version_string = __( 'No version or author information is available.' );
$plugin_version_string_debug = 'author: (undefined), version: (undefined)';
if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
/* translators: 1: Plugin version number. 2: Plugin author name. */
$plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
$plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
} else {
if ( ! empty( $plugin_author ) ) {
/* translators: %s: Plugin author name. */
$plugin_version_string = sprintf( __( 'By %s' ), $plugin_author );
$plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
}
if ( ! empty( $plugin_version ) ) {
/* translators: %s: Plugin version number. */
$plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version );
$plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
}
}
$fields[ sanitize_text_field( $plugin['Name'] ) ] = array(
'label' => $plugin['Name'],
'value' => $plugin_version_string,
'debug' => $plugin_version_string_debug,
);
}
return array(
'label' => __( 'Must Use Plugins' ),
'show_count' => true,
'fields' => $fields,
);
}
/**
* Gets the WordPress paths and sizes section of the debug data.
*
* @since 6.7.0
*
* @return array|null Paths and sizes debug data for single sites,
* otherwise `null` for multi-site installs.
*/
private static function get_wp_paths_sizes(): ?array {
if ( is_multisite() ) {
return null;
}
$loading = __( 'Loading…' );
$fields = array(
'wordpress_path' => array(
'label' => __( 'WordPress directory location' ),
'value' => untrailingslashit( ABSPATH ),
),
'wordpress_size' => array(
'label' => __( 'WordPress directory size' ),
'value' => $loading,
'debug' => 'loading...',
),
'uploads_path' => array(
'label' => __( 'Uploads directory location' ),
'value' => wp_upload_dir()['basedir'],
),
'uploads_size' => array(
'label' => __( 'Uploads directory size' ),
'value' => $loading,
'debug' => 'loading...',
),
'themes_path' => array(
'label' => __( 'Themes directory location' ),
'value' => get_theme_root(),
),
'themes_size' => array(
'label' => __( 'Themes directory size' ),
'value' => $loading,
'debug' => 'loading...',
),
'plugins_path' => array(
'label' => __( 'Plugins directory location' ),
'value' => WP_PLUGIN_DIR,
),
'plugins_size' => array(
'label' => __( 'Plugins directory size' ),
'value' => $loading,
'debug' => 'loading...',
),
'fonts_path' => array(
'label' => __( 'Fonts directory location' ),
'value' => wp_get_font_dir()['basedir'],
),
'fonts_size' => array(
'label' => __( 'Fonts directory size' ),
'value' => $loading,
'debug' => 'loading...',
),
'database_size' => array(
'label' => __( 'Database size' ),
'value' => $loading,
'debug' => 'loading...',
),
'total_size' => array(
'label' => __( 'Total installation size' ),
'value' => $loading,
'debug' => 'loading...',
),
);
return array(
/* translators: Filesystem directory paths and storage sizes. */
'label' => __( 'Directories and Sizes' ),
'fields' => $fields,
);
}
/**
* Gets the WordPress active plugins section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_plugins_active(): array {
return array(
'label' => __( 'Active Plugins' ),
'show_count' => true,
'fields' => self::get_wp_plugins_raw_data()['wp-plugins-active'],
);
}
/**
* Gets the WordPress inactive plugins section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_plugins_inactive(): array {
return array(
'label' => __( 'Inactive Plugins' ),
'show_count' => true,
'fields' => self::get_wp_plugins_raw_data()['wp-plugins-inactive'],
);
}
/**
* Gets the raw plugin data for the WordPress active and inactive sections of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_plugins_raw_data(): array {
// List all available plugins.
$plugins = get_plugins();
$plugin_updates = get_plugin_updates();
$transient = get_site_transient( 'update_plugins' );
$auto_updates = array();
$fields = array(
'wp-plugins-active' => array(),
'wp-plugins-inactive' => array(),
);
$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );
if ( $auto_updates_enabled ) {
$auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
}
foreach ( $plugins as $plugin_path => $plugin ) {
$plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';
$plugin_version = $plugin['Version'];
$plugin_author = $plugin['Author'];
$plugin_version_string = __( 'No version or author information is available.' );
$plugin_version_string_debug = 'author: (undefined), version: (undefined)';
if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
/* translators: 1: Plugin version number. 2: Plugin author name. */
$plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
$plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
} else {
if ( ! empty( $plugin_author ) ) {
/* translators: %s: Plugin author name. */
$plugin_version_string = sprintf( __( 'By %s' ), $plugin_author );
$plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
}
if ( ! empty( $plugin_version ) ) {
/* translators: %s: Plugin version number. */
$plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version );
$plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
}
}
if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
/* translators: %s: Latest plugin version number. */
$plugin_version_string .= ' ' . sprintf( __( '(Latest version: %s)' ), $plugin_updates[ $plugin_path ]->update->new_version );
$plugin_version_string_debug .= sprintf( ' (latest version: %s)', $plugin_updates[ $plugin_path ]->update->new_version );
}
if ( $auto_updates_enabled ) {
if ( isset( $transient->response[ $plugin_path ] ) ) {
$item = $transient->response[ $plugin_path ];
} elseif ( isset( $transient->no_update[ $plugin_path ] ) ) {
$item = $transient->no_update[ $plugin_path ];
} else {
$item = array(
'id' => $plugin_path,
'slug' => '',
'plugin' => $plugin_path,
'new_version' => '',
'url' => '',
'package' => '',
'icons' => array(),
'banners' => array(),
'banners_rtl' => array(),
'tested' => '',
'requires_php' => '',
'compatibility' => new stdClass(),
);
$item = wp_parse_args( $plugin, $item );
}
$auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, (object) $item );
if ( ! is_null( $auto_update_forced ) ) {
$enabled = $auto_update_forced;
} else {
$enabled = in_array( $plugin_path, $auto_updates, true );
}
if ( $enabled ) {
$auto_updates_string = __( 'Auto-updates enabled' );
} else {
$auto_updates_string = __( 'Auto-updates disabled' );
}
/**
* Filters the text string of the auto-updates setting for each plugin in the Site Health debug data.
*
* @since 5.5.0
*
* @param string $auto_updates_string The string output for the auto-updates column.
* @param string $plugin_path The path to the plugin file.
* @param array $plugin An array of plugin data.
* @param bool $enabled Whether auto-updates are enabled for this item.
*/
$auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled );
$plugin_version_string .= ' | ' . $auto_updates_string;
$plugin_version_string_debug .= ', ' . $auto_updates_string;
}
$fields[ $plugin_part ][ sanitize_text_field( $plugin['Name'] ) ] = array(
'label' => $plugin['Name'],
'value' => $plugin_version_string,
'debug' => $plugin_version_string_debug,
);
}
return $fields;
}
/**
* Gets the WordPress active theme section of the debug data.
*
* @since 6.7.0
*
* @global array $_wp_theme_features
*
* @return array
*/
private static function get_wp_active_theme(): array {
global $_wp_theme_features;
// Populate the section for the currently active theme.
$theme_features = array();
if ( ! empty( $_wp_theme_features ) ) {
foreach ( $_wp_theme_features as $feature => $options ) {
$theme_features[] = $feature;
}
}
$active_theme = wp_get_theme();
$theme_updates = get_theme_updates();
$transient = get_site_transient( 'update_themes' );
$active_theme_version = $active_theme->version;
$active_theme_version_debug = $active_theme_version;
$auto_updates = array();
$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
if ( $auto_updates_enabled ) {
$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
}
if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
$theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];
/* translators: %s: Latest theme version number. */
$active_theme_version .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_update_new_version );
$active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
}
$active_theme_author_uri = $active_theme->display( 'AuthorURI' );
if ( $active_theme->parent_theme ) {
$active_theme_parent_theme = sprintf(
/* translators: 1: Theme name. 2: Theme slug. */
__( '%1$s (%2$s)' ),
$active_theme->parent_theme,
$active_theme->template
);
$active_theme_parent_theme_debug = sprintf(
'%s (%s)',
$active_theme->parent_theme,
$active_theme->template
);
} else {
$active_theme_parent_theme = __( 'None' );
$active_theme_parent_theme_debug = 'none';
}
$fields = array(
'name' => array(
'label' => __( 'Name' ),
'value' => sprintf(
/* translators: 1: Theme name. 2: Theme slug. */
__( '%1$s (%2$s)' ),
$active_theme->name,
$active_theme->stylesheet
),
),
'version' => array(
'label' => __( 'Version' ),
'value' => $active_theme_version,
'debug' => $active_theme_version_debug,
),
'author' => array(
'label' => __( 'Author' ),
'value' => wp_kses( $active_theme->author, array() ),
),
'author_website' => array(
'label' => __( 'Author website' ),
'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined' ) ),
'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
),
'parent_theme' => array(
'label' => __( 'Parent theme' ),
'value' => $active_theme_parent_theme,
'debug' => $active_theme_parent_theme_debug,
),
'theme_features' => array(
'label' => __( 'Theme features' ),
'value' => implode( ', ', $theme_features ),
),
'theme_path' => array(
'label' => __( 'Theme directory location' ),
'value' => get_stylesheet_directory(),
),
);
if ( $auto_updates_enabled ) {
if ( isset( $transient->response[ $active_theme->stylesheet ] ) ) {
$item = $transient->response[ $active_theme->stylesheet ];
} elseif ( isset( $transient->no_update[ $active_theme->stylesheet ] ) ) {
$item = $transient->no_update[ $active_theme->stylesheet ];
} else {
$item = array(
'theme' => $active_theme->stylesheet,
'new_version' => $active_theme->version,
'url' => '',
'package' => '',
'requires' => '',
'requires_php' => '',
);
}
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
if ( ! is_null( $auto_update_forced ) ) {
$enabled = $auto_update_forced;
} else {
$enabled = in_array( $active_theme->stylesheet, $auto_updates, true );
}
if ( $enabled ) {
$auto_updates_string = __( 'Enabled' );
} else {
$auto_updates_string = __( 'Disabled' );
}
/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled );
$fields['auto_update'] = array(
'label' => __( 'Auto-updates' ),
'value' => $auto_updates_string,
'debug' => $auto_updates_string,
);
}
return array(
'label' => __( 'Active Theme' ),
'fields' => $fields,
);
}
/**
* Gets the WordPress parent theme section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_parent_theme(): array {
$theme_updates = get_theme_updates();
$transient = get_site_transient( 'update_themes' );
$auto_updates = array();
$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
if ( $auto_updates_enabled ) {
$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
}
$active_theme = wp_get_theme();
$parent_theme = $active_theme->parent();
$fields = array();
if ( $parent_theme ) {
$parent_theme_version = $parent_theme->version;
$parent_theme_version_debug = $parent_theme_version;
if ( array_key_exists( $parent_theme->stylesheet, $theme_updates ) ) {
$parent_theme_update_new_version = $theme_updates[ $parent_theme->stylesheet ]->update['new_version'];
/* translators: %s: Latest theme version number. */
$parent_theme_version .= ' ' . sprintf( __( '(Latest version: %s)' ), $parent_theme_update_new_version );
$parent_theme_version_debug .= sprintf( ' (latest version: %s)', $parent_theme_update_new_version );
}
$parent_theme_author_uri = $parent_theme->display( 'AuthorURI' );
$fields = array(
'name' => array(
'label' => __( 'Name' ),
'value' => sprintf(
/* translators: 1: Theme name. 2: Theme slug. */
__( '%1$s (%2$s)' ),
$parent_theme->name,
$parent_theme->stylesheet
),
),
'version' => array(
'label' => __( 'Version' ),
'value' => $parent_theme_version,
'debug' => $parent_theme_version_debug,
),
'author' => array(
'label' => __( 'Author' ),
'value' => wp_kses( $parent_theme->author, array() ),
),
'author_website' => array(
'label' => __( 'Author website' ),
'value' => ( $parent_theme_author_uri ? $parent_theme_author_uri : __( 'Undefined' ) ),
'debug' => ( $parent_theme_author_uri ? $parent_theme_author_uri : '(undefined)' ),
),
'theme_path' => array(
'label' => __( 'Theme directory location' ),
'value' => get_template_directory(),
),
);
if ( $auto_updates_enabled ) {
if ( isset( $transient->response[ $parent_theme->stylesheet ] ) ) {
$item = $transient->response[ $parent_theme->stylesheet ];
} elseif ( isset( $transient->no_update[ $parent_theme->stylesheet ] ) ) {
$item = $transient->no_update[ $parent_theme->stylesheet ];
} else {
$item = array(
'theme' => $parent_theme->stylesheet,
'new_version' => $parent_theme->version,
'url' => '',
'package' => '',
'requires' => '',
'requires_php' => '',
);
}
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
if ( ! is_null( $auto_update_forced ) ) {
$enabled = $auto_update_forced;
} else {
$enabled = in_array( $parent_theme->stylesheet, $auto_updates, true );
}
if ( $enabled ) {
$parent_theme_auto_update_string = __( 'Enabled' );
} else {
$parent_theme_auto_update_string = __( 'Disabled' );
}
/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
$parent_theme_auto_update_string = apply_filters( 'theme_auto_update_debug_string', $parent_theme_auto_update_string, $parent_theme, $enabled );
$fields['auto_update'] = array(
'label' => __( 'Auto-update' ),
'value' => $parent_theme_auto_update_string,
'debug' => $parent_theme_auto_update_string,
);
}
}
return array(
'label' => __( 'Parent Theme' ),
'fields' => $fields,
);
}
/**
* Gets the WordPress inactive themes section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_themes_inactive(): array {
$active_theme = wp_get_theme();
$parent_theme = $active_theme->parent();
$theme_updates = get_theme_updates();
$transient = get_site_transient( 'update_themes' );
$auto_updates = array();
$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
if ( $auto_updates_enabled ) {
$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
}
// Populate a list of all themes available in the installation.
$all_themes = wp_get_themes();
$fields = array();
foreach ( $all_themes as $theme_slug => $theme ) {
// Exclude the currently active theme from the list of all themes.
if ( $active_theme->stylesheet === $theme_slug ) {
continue;
}
// Exclude the currently active parent theme from the list of all themes.
if ( ! empty( $parent_theme ) && $parent_theme->stylesheet === $theme_slug ) {
continue;
}
$theme_version = $theme->version;
$theme_author = $theme->author;
// Sanitize.
$theme_author = wp_kses( $theme_author, array() );
$theme_version_string = __( 'No version or author information is available.' );
$theme_version_string_debug = 'undefined';
if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
/* translators: 1: Theme version number. 2: Theme author name. */
$theme_version_string = sprintf( __( 'Version %1$s by %2$s' ), $theme_version, $theme_author );
$theme_version_string_debug = sprintf( 'version: %s, author: %s', $theme_version, $theme_author );
} else {
if ( ! empty( $theme_author ) ) {
/* translators: %s: Theme author name. */
$theme_version_string = sprintf( __( 'By %s' ), $theme_author );
$theme_version_string_debug = sprintf( 'author: %s, version: (undefined)', $theme_author );
}
if ( ! empty( $theme_version ) ) {
/* translators: %s: Theme version number. */
$theme_version_string = sprintf( __( 'Version %s' ), $theme_version );
$theme_version_string_debug = sprintf( 'author: (undefined), version: %s', $theme_version );
}
}
if ( array_key_exists( $theme_slug, $theme_updates ) ) {
/* translators: %s: Latest theme version number. */
$theme_version_string .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] );
$theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
}
if ( $auto_updates_enabled ) {
if ( isset( $transient->response[ $theme_slug ] ) ) {
$item = $transient->response[ $theme_slug ];
} elseif ( isset( $transient->no_update[ $theme_slug ] ) ) {
$item = $transient->no_update[ $theme_slug ];
} else {
$item = array(
'theme' => $theme_slug,
'new_version' => $theme->version,
'url' => '',
'package' => '',
'requires' => '',
'requires_php' => '',
);
}
$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
if ( ! is_null( $auto_update_forced ) ) {
$enabled = $auto_update_forced;
} else {
$enabled = in_array( $theme_slug, $auto_updates, true );
}
if ( $enabled ) {
$auto_updates_string = __( 'Auto-updates enabled' );
} else {
$auto_updates_string = __( 'Auto-updates disabled' );
}
/**
* Filters the text string of the auto-updates setting for each theme in the Site Health debug data.
*
* @since 5.5.0
*
* @param string $auto_updates_string The string output for the auto-updates column.
* @param WP_Theme $theme An object of theme data.
* @param bool $enabled Whether auto-updates are enabled for this item.
*/
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled );
$theme_version_string .= ' | ' . $auto_updates_string;
$theme_version_string_debug .= ', ' . $auto_updates_string;
}
$fields[ sanitize_text_field( $theme->name ) ] = array(
'label' => sprintf(
/* translators: 1: Theme name. 2: Theme slug. */
__( '%1$s (%2$s)' ),
$theme->name,
$theme_slug
),
'value' => $theme_version_string,
'debug' => $theme_version_string_debug,
);
}
return array(
'label' => __( 'Inactive Themes' ),
'show_count' => true,
'fields' => $fields,
);
}
/**
* Gets the WordPress constants section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_constants(): array {
// Check if WP_DEBUG_LOG is set.
$wp_debug_log_value = __( 'Disabled' );
if ( is_string( WP_DEBUG_LOG ) ) {
$wp_debug_log_value = WP_DEBUG_LOG;
} elseif ( WP_DEBUG_LOG ) {
$wp_debug_log_value = __( 'Enabled' );
}
// Check CONCATENATE_SCRIPTS.
if ( defined( 'CONCATENATE_SCRIPTS' ) ) {
$concatenate_scripts = CONCATENATE_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' );
$concatenate_scripts_debug = CONCATENATE_SCRIPTS ? 'true' : 'false';
} else {
$concatenate_scripts = __( 'Undefined' );
$concatenate_scripts_debug = 'undefined';
}
// Check COMPRESS_SCRIPTS.
if ( defined( 'COMPRESS_SCRIPTS' ) ) {
$compress_scripts = COMPRESS_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' );
$compress_scripts_debug = COMPRESS_SCRIPTS ? 'true' : 'false';
} else {
$compress_scripts = __( 'Undefined' );
$compress_scripts_debug = 'undefined';
}
// Check COMPRESS_CSS.
if ( defined( 'COMPRESS_CSS' ) ) {
$compress_css = COMPRESS_CSS ? __( 'Enabled' ) : __( 'Disabled' );
$compress_css_debug = COMPRESS_CSS ? 'true' : 'false';
} else {
$compress_css = __( 'Undefined' );
$compress_css_debug = 'undefined';
}
// Check WP_ENVIRONMENT_TYPE.
if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
$wp_environment_type = WP_ENVIRONMENT_TYPE ? WP_ENVIRONMENT_TYPE : __( 'Empty value' );
$wp_environment_type_debug = WP_ENVIRONMENT_TYPE;
} else {
$wp_environment_type = __( 'Undefined' );
$wp_environment_type_debug = 'undefined';
}
// Check DB_COLLATE.
if ( defined( 'DB_COLLATE' ) ) {
$db_collate = DB_COLLATE ? DB_COLLATE : __( 'Empty value' );
$db_collate_debug = DB_COLLATE;
} else {
$db_collate = __( 'Undefined' );
$db_collate_debug = 'undefined';
}
$fields = array(
'ABSPATH' => array(
'label' => 'ABSPATH',
'value' => ABSPATH,
'private' => true,
),
'WP_HOME' => array(
'label' => 'WP_HOME',
'value' => ( defined( 'WP_HOME' ) ? WP_HOME : __( 'Undefined' ) ),
'debug' => ( defined( 'WP_HOME' ) ? WP_HOME : 'undefined' ),
),
'WP_SITEURL' => array(
'label' => 'WP_SITEURL',
'value' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : __( 'Undefined' ) ),
'debug' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : 'undefined' ),
),
'WP_CONTENT_DIR' => array(
'label' => 'WP_CONTENT_DIR',
'value' => WP_CONTENT_DIR,
),
'WP_PLUGIN_DIR' => array(
'label' => 'WP_PLUGIN_DIR',
'value' => WP_PLUGIN_DIR,
),
'WP_MEMORY_LIMIT' => array(
'label' => 'WP_MEMORY_LIMIT',
'value' => WP_MEMORY_LIMIT,
),
'WP_MAX_MEMORY_LIMIT' => array(
'label' => 'WP_MAX_MEMORY_LIMIT',
'value' => WP_MAX_MEMORY_LIMIT,
),
'WP_DEBUG' => array(
'label' => 'WP_DEBUG',
'value' => WP_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ),
'debug' => WP_DEBUG,
),
'WP_DEBUG_DISPLAY' => array(
'label' => 'WP_DEBUG_DISPLAY',
'value' => WP_DEBUG_DISPLAY ? __( 'Enabled' ) : __( 'Disabled' ),
'debug' => WP_DEBUG_DISPLAY,
),
'WP_DEBUG_LOG' => array(
'label' => 'WP_DEBUG_LOG',
'value' => $wp_debug_log_value,
'debug' => WP_DEBUG_LOG,
),
'SCRIPT_DEBUG' => array(
'label' => 'SCRIPT_DEBUG',
'value' => SCRIPT_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ),
'debug' => SCRIPT_DEBUG,
),
'WP_CACHE' => array(
'label' => 'WP_CACHE',
'value' => WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ),
'debug' => WP_CACHE,
),
'CONCATENATE_SCRIPTS' => array(
'label' => 'CONCATENATE_SCRIPTS',
'value' => $concatenate_scripts,
'debug' => $concatenate_scripts_debug,
),
'COMPRESS_SCRIPTS' => array(
'label' => 'COMPRESS_SCRIPTS',
'value' => $compress_scripts,
'debug' => $compress_scripts_debug,
),
'COMPRESS_CSS' => array(
'label' => 'COMPRESS_CSS',
'value' => $compress_css,
'debug' => $compress_css_debug,
),
'WP_ENVIRONMENT_TYPE' => array(
'label' => 'WP_ENVIRONMENT_TYPE',
'value' => $wp_environment_type,
'debug' => $wp_environment_type_debug,
),
'WP_DEVELOPMENT_MODE' => array(
'label' => 'WP_DEVELOPMENT_MODE',
'value' => WP_DEVELOPMENT_MODE ? WP_DEVELOPMENT_MODE : __( 'Disabled' ),
'debug' => WP_DEVELOPMENT_MODE,
),
'DB_CHARSET' => array(
'label' => 'DB_CHARSET',
'value' => ( defined( 'DB_CHARSET' ) ? DB_CHARSET : __( 'Undefined' ) ),
'debug' => ( defined( 'DB_CHARSET' ) ? DB_CHARSET : 'undefined' ),
),
'DB_COLLATE' => array(
'label' => 'DB_COLLATE',
'value' => $db_collate,
'debug' => $db_collate_debug,
),
);
return array(
'label' => __( 'WordPress Constants' ),
'description' => __( 'These settings alter where and how parts of WordPress are loaded.' ),
'fields' => $fields,
);
}
/**
* Gets the WordPress database section of the debug data.
*
* @since 6.7.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return array
*/
private static function get_wp_database(): array {
global $wpdb;
// Populate the database debug fields.
if ( is_object( $wpdb->dbh ) ) {
// mysqli or PDO.
$extension = get_class( $wpdb->dbh );
} else {
// Unknown sql extension.
$extension = null;
}
$server = $wpdb->get_var( 'SELECT VERSION()' );
$client_version = $wpdb->dbh->client_info;
$fields = array(
'extension' => array(
'label' => __( 'Database Extension' ),
'value' => $extension,
),
'server_version' => array(
'label' => __( 'Server version' ),
'value' => $server,
),
'client_version' => array(
'label' => __( 'Client version' ),
'value' => $client_version,
),
'database_user' => array(
'label' => __( 'Database username' ),
'value' => $wpdb->dbuser,
'private' => true,
),
'database_host' => array(
'label' => __( 'Database host' ),
'value' => $wpdb->dbhost,
'private' => true,
),
'database_name' => array(
'label' => __( 'Database name' ),
'value' => $wpdb->dbname,
'private' => true,
),
'database_prefix' => array(
'label' => __( 'Table prefix' ),
'value' => $wpdb->prefix,
'private' => true,
),
'database_charset' => array(
'label' => __( 'Database charset' ),
'value' => $wpdb->charset,
'private' => true,
),
'database_collate' => array(
'label' => __( 'Database collation' ),
'value' => $wpdb->collate,
'private' => true,
),
'max_allowed_packet' => array(
'label' => __( 'Max allowed packet size' ),
'value' => self::get_mysql_var( 'max_allowed_packet' ),
),
'max_connections' => array(
'label' => __( 'Max connections number' ),
'value' => self::get_mysql_var( 'max_connections' ),
),
);
return array(
'label' => __( 'Database' ),
'fields' => $fields,
);
}
/**
* Gets the file system section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
private static function get_wp_filesystem(): array {
$upload_dir = wp_upload_dir();
$fonts_dir_exists = file_exists( wp_get_font_dir()['basedir'] );
$is_writable_abspath = wp_is_writable( ABSPATH );
$is_writable_wp_content_dir = wp_is_writable( WP_CONTENT_DIR );
$is_writable_upload_dir = wp_is_writable( $upload_dir['basedir'] );
$is_writable_wp_plugin_dir = wp_is_writable( WP_PLUGIN_DIR );
$is_writable_template_directory = wp_is_writable( get_theme_root( get_template() ) );
$is_writable_fonts_dir = $fonts_dir_exists ? wp_is_writable( wp_get_font_dir()['basedir'] ) : false;
$fields = array(
'wordpress' => array(
'label' => __( 'The main WordPress directory' ),
'value' => ( $is_writable_abspath ? __( 'Writable' ) : __( 'Not writable' ) ),
'debug' => ( $is_writable_abspath ? 'writable' : 'not writable' ),
),
'wp-content' => array(
'label' => __( 'The wp-content directory' ),
'value' => ( $is_writable_wp_content_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
'debug' => ( $is_writable_wp_content_dir ? 'writable' : 'not writable' ),
),
'uploads' => array(
'label' => __( 'The uploads directory' ),
'value' => ( $is_writable_upload_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
'debug' => ( $is_writable_upload_dir ? 'writable' : 'not writable' ),
),
'plugins' => array(
'label' => __( 'The plugins directory' ),
'value' => ( $is_writable_wp_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
'debug' => ( $is_writable_wp_plugin_dir ? 'writable' : 'not writable' ),
),
'themes' => array(
'label' => __( 'The themes directory' ),
'value' => ( $is_writable_template_directory ? __( 'Writable' ) : __( 'Not writable' ) ),
'debug' => ( $is_writable_template_directory ? 'writable' : 'not writable' ),
),
'fonts' => array(
'label' => __( 'The fonts directory' ),
'value' => $fonts_dir_exists
? ( $is_writable_fonts_dir ? __( 'Writable' ) : __( 'Not writable' ) )
: __( 'Does not exist' ),
'debug' => $fonts_dir_exists
? ( $is_writable_fonts_dir ? 'writable' : 'not writable' )
: 'does not exist',
),
);
// Add more filesystem checks.
if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
$is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );
$fields['mu-plugins'] = array(
'label' => __( 'The must use plugins directory' ),
'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
);
}
return array(
'label' => __( 'Filesystem Permissions' ),
'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ),
'fields' => $fields,
);
}
/**
* Returns the value of a MySQL system variable.
*
* @since 5.9.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $mysql_var Name of the MySQL system variable.
* @return string|null The variable value on success. Null if the variable does not exist.
*/
public static function get_mysql_var( $mysql_var ) {
global $wpdb;
$result = $wpdb->get_row(
$wpdb->prepare( 'SHOW VARIABLES LIKE %s', $mysql_var ),
ARRAY_A
);
if ( ! empty( $result ) && array_key_exists( 'Value', $result ) ) {
return $result['Value'];
}
return null;
}
/**
* Formats the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
*
* @since 5.2.0
*
* @param array $info_array Information gathered from the `WP_Debug_Data::debug_data()` function.
* @param string $data_type The data type to return, either 'info' or 'debug'.
* @return string The formatted data.
*/
public static function format( $info_array, $data_type ) {
$return = "`\n";
foreach ( $info_array as $section => $details ) {
// Skip this section if there are no fields, or the section has been declared as private.
if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
continue;
}
$section_label = 'debug' === $data_type ? $section : $details['label'];
$return .= sprintf(
"### %s%s ###\n\n",
$section_label,
( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
);
foreach ( $details['fields'] as $field_name => $field ) {
if ( isset( $field['private'] ) && true === $field['private'] ) {
continue;
}
if ( 'debug' === $data_type && isset( $field['debug'] ) ) {
$debug_data = $field['debug'];
} else {
$debug_data = $field['value'];
}
// Can be array, one level deep only.
if ( is_array( $debug_data ) ) {
$value = '';
foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
$value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
}
} elseif ( is_bool( $debug_data ) ) {
$value = $debug_data ? 'true' : 'false';
} elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
$value = 'undefined';
} else {
$value = $debug_data;
}
if ( 'debug' === $data_type ) {
$label = $field_name;
} else {
$label = $field['label'];
}
$return .= sprintf( "%s: %s\n", $label, $value );
}
$return .= "\n";
}
$return .= '`';
return $return;
}
/**
* Fetches the total size of all the database tables for the active database user.
*
* @since 5.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return int The size of the database, in bytes.
*/
public static function get_database_size() {
global $wpdb;
$size = 0;
$rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
if ( $wpdb->num_rows > 0 ) {
foreach ( $rows as $row ) {
$size += $row['Data_length'] + $row['Index_length'];
}
}
return (int) $size;
}
/**
* Fetches the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
* Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
*
* @since 5.2.0
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::get_directory_sizes()
* @see WP_REST_Site_Health_Controller::get_directory_sizes()
*
* @return array The sizes of the directories, also the database size and total installation size.
*/
public static function get_sizes() {
_deprecated_function( __METHOD__, '5.6.0', 'WP_REST_Site_Health_Controller::get_directory_sizes()' );
$size_db = self::get_database_size();
$upload_dir = wp_get_upload_dir();
/*
* We will be using the PHP max execution time to prevent the size calculations
* from causing a timeout. The default value is 30 seconds, and some
* hosts do not allow you to read configuration values.
*/
if ( function_exists( 'ini_get' ) ) {
$max_execution_time = ini_get( 'max_execution_time' );
}
/*
* The max_execution_time defaults to 0 when PHP runs from cli.
* We still want to limit it below.
*/
if ( empty( $max_execution_time ) ) {
$max_execution_time = 30; // 30 seconds.
}
if ( $max_execution_time > 20 ) {
/*
* If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
* edge-case timeouts that may happen after the size loop has finished running.
*/
$max_execution_time -= 2;
}
/*
* Go through the various installation directories and calculate their sizes.
* No trailing slashes.
*/
$paths = array(
'wordpress_size' => untrailingslashit( ABSPATH ),
'themes_size' => get_theme_root(),
'plugins_size' => WP_PLUGIN_DIR,
'uploads_size' => $upload_dir['basedir'],
'fonts_size' => wp_get_font_dir()['basedir'],
);
$exclude = $paths;
unset( $exclude['wordpress_size'] );
$exclude = array_values( $exclude );
$size_total = 0;
$all_sizes = array();
// Loop over all the directories we want to gather the sizes for.
foreach ( $paths as $name => $path ) {
$dir_size = null; // Default to timeout.
$results = array(
'path' => $path,
'raw' => 0,
);
// If the directory does not exist, skip checking it, as it will skew the other results.
if ( ! is_dir( $path ) ) {
$all_sizes[ $name ] = array(
'path' => $path,
'raw' => 0,
'size' => __( 'The directory does not exist.' ),
'debug' => 'directory not found',
);
continue;
}
if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
if ( 'wordpress_size' === $name ) {
$dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
} else {
$dir_size = recurse_dirsize( $path, null, $max_execution_time );
}
}
if ( false === $dir_size ) {
// Error reading.
$results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
$results['debug'] = 'not accessible';
// Stop total size calculation.
$size_total = null;
} elseif ( null === $dir_size ) {
// Timeout.
$results['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
$results['debug'] = 'timeout while calculating size';
// Stop total size calculation.
$size_total = null;
} else {
if ( null !== $size_total ) {
$size_total += $dir_size;
}
$results['raw'] = $dir_size;
$results['size'] = size_format( $dir_size, 2 );
$results['debug'] = $results['size'] . " ({$dir_size} bytes)";
}
$all_sizes[ $name ] = $results;
}
if ( $size_db > 0 ) {
$database_size = size_format( $size_db, 2 );
$all_sizes['database_size'] = array(
'raw' => $size_db,
'size' => $database_size,
'debug' => $database_size . " ({$size_db} bytes)",
);
} else {
$all_sizes['database_size'] = array(
'size' => __( 'Not available' ),
'debug' => 'not available',
);
}
if ( null !== $size_total && $size_db > 0 ) {
$total_size = $size_total + $size_db;
$total_size_mb = size_format( $total_size, 2 );
$all_sizes['total_size'] = array(
'raw' => $total_size,
'size' => $total_size_mb,
'debug' => $total_size_mb . " ({$total_size} bytes)",
);
} else {
$all_sizes['total_size'] = array(
'size' => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
'debug' => 'not available',
);
}
return $all_sizes;
}
}
PK �MP\���7� � list-table.phpnu �[��� <?php
/**
* Helper functions for displaying a list of items in an ajaxified HTML table.
*
* @package WordPress
* @subpackage List_Table
* @since 3.1.0
*/
/**
* Fetches an instance of a WP_List_Table class.
*
* @since 3.1.0
*
* @global string $hook_suffix
*
* @param string $class_name The type of the list table, which is the class name.
* @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
* @return WP_List_Table|false List table object on success, false if the class does not exist.
*/
function _get_list_table( $class_name, $args = array() ) {
$core_classes = array(
// Site Admin.
'WP_Posts_List_Table' => 'posts',
'WP_Media_List_Table' => 'media',
'WP_Terms_List_Table' => 'terms',
'WP_Users_List_Table' => 'users',
'WP_Comments_List_Table' => 'comments',
'WP_Post_Comments_List_Table' => array( 'comments', 'post-comments' ),
'WP_Links_List_Table' => 'links',
'WP_Plugin_Install_List_Table' => 'plugin-install',
'WP_Themes_List_Table' => 'themes',
'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
'WP_Plugins_List_Table' => 'plugins',
'WP_Application_Passwords_List_Table' => 'application-passwords',
// Network Admin.
'WP_MS_Sites_List_Table' => 'ms-sites',
'WP_MS_Users_List_Table' => 'ms-users',
'WP_MS_Themes_List_Table' => 'ms-themes',
// Privacy requests tables.
'WP_Privacy_Data_Export_Requests_List_Table' => 'privacy-data-export-requests',
'WP_Privacy_Data_Removal_Requests_List_Table' => 'privacy-data-removal-requests',
);
if ( isset( $core_classes[ $class_name ] ) ) {
foreach ( (array) $core_classes[ $class_name ] as $required ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php';
}
if ( isset( $args['screen'] ) ) {
$args['screen'] = convert_to_screen( $args['screen'] );
} elseif ( isset( $GLOBALS['hook_suffix'] ) ) {
$args['screen'] = get_current_screen();
} else {
$args['screen'] = null;
}
/**
* Filters the list table class to instantiate.
*
* @since 6.1.0
*
* @param string $class_name The list table class to use.
* @param array $args An array containing _get_list_table() arguments.
*/
$custom_class_name = apply_filters( 'wp_list_table_class_name', $class_name, $args );
if ( is_string( $custom_class_name ) && class_exists( $custom_class_name ) ) {
$class_name = $custom_class_name;
}
return new $class_name( $args );
}
return false;
}
/**
* Register column headers for a particular screen.
*
* @see get_column_headers(), print_column_headers(), get_hidden_columns()
*
* @since 2.7.0
*
* @param string $screen The handle for the screen to register column headers for. This is
* usually the hook name returned by the `add_*_page()` functions.
* @param string[] $columns An array of columns with column IDs as the keys and translated
* column names as the values.
*/
function register_column_headers( $screen, $columns ) {
new _WP_List_Table_Compat( $screen, $columns );
}
/**
* Prints column headers for a particular screen.
*
* @since 2.7.0
*
* @param string|WP_Screen $screen The screen hook name or screen object.
* @param bool $with_id Whether to set the ID attribute or not.
*/
function print_column_headers( $screen, $with_id = true ) {
$wp_list_table = new _WP_List_Table_Compat( $screen );
$wp_list_table->print_column_headers( $with_id );
}
PK �MP\M��uV uV class-wp-ms-sites-list-table.phpnu �[��� <?php
/**
* List Table API: WP_MS_Sites_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying sites in a list table for the network admin.
*
* @since 3.1.0
*
* @see WP_List_Table
*/
class WP_MS_Sites_List_Table extends WP_List_Table {
/**
* Site status list.
*
* @since 4.3.0
* @var array
*/
public $status_list;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
$this->status_list = array(
'archived' => array( 'site-archived', __( 'Archived' ) ),
'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
'deleted' => array( 'site-deleted', __( 'Flagged for Deletion' ) ),
'mature' => array( 'site-mature', __( 'Mature' ) ),
);
parent::__construct(
array(
'plural' => 'sites',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'manage_sites' );
}
/**
* Prepares the list of sites for display.
*
* @since 3.1.0
*
* @global string $mode List table view mode.
* @global string $s
* @global wpdb $wpdb WordPress database abstraction object.
*/
public function prepare_items() {
global $mode, $s, $wpdb;
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
set_user_setting( 'sites_list_mode', $mode );
} else {
$mode = get_user_setting( 'sites_list_mode', 'list' );
}
$per_page = $this->get_items_per_page( 'sites_network_per_page' );
$pagenum = $this->get_pagenum();
$s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
$wild = '';
if ( str_contains( $s, '*' ) ) {
$wild = '*';
$s = trim( $s, '*' );
}
/*
* If the network is large and a search is not being performed, show only
* the latest sites with no paging in order to avoid expensive count queries.
*/
if ( ! $s && wp_is_large_network() ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$_GET['orderby'] = '';
$_REQUEST['orderby'] = '';
}
if ( ! isset( $_REQUEST['order'] ) ) {
$_GET['order'] = 'DESC';
$_REQUEST['order'] = 'DESC';
}
}
$args = array(
'number' => (int) $per_page,
'offset' => (int) ( ( $pagenum - 1 ) * $per_page ),
'network_id' => get_current_network_id(),
);
if ( empty( $s ) ) {
// Nothing to do.
} elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s )
|| preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
|| preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
|| preg_match( '/^[0-9]{1,3}\.$/', $s )
) {
// IPv4 address.
$reg_blog_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s",
$wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' )
)
);
if ( $reg_blog_ids ) {
$args['site__in'] = $reg_blog_ids;
}
} elseif ( is_numeric( $s ) && empty( $wild ) ) {
$args['ID'] = $s;
} else {
$args['search'] = $s;
if ( ! is_subdomain_install() ) {
$args['search_columns'] = array( 'path' );
}
}
$order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
if ( 'registered' === $order_by ) {
// 'registered' is a valid field name.
} elseif ( 'lastupdated' === $order_by ) {
$order_by = 'last_updated';
} elseif ( 'blogname' === $order_by ) {
if ( is_subdomain_install() ) {
$order_by = 'domain';
} else {
$order_by = 'path';
}
} elseif ( 'blog_id' === $order_by ) {
$order_by = 'id';
} elseif ( ! $order_by ) {
$order_by = false;
}
$args['orderby'] = $order_by;
if ( $order_by ) {
$args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
}
if ( wp_is_large_network() ) {
$args['no_found_rows'] = true;
} else {
$args['no_found_rows'] = false;
}
// Take into account the role the user has selected.
$status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) {
$args[ $status ] = 1;
}
/**
* Filters the arguments for the site query in the sites list table.
*
* @since 4.6.0
*
* @param array $args An array of get_sites() arguments.
*/
$args = apply_filters( 'ms_sites_list_table_query_args', $args );
$_sites = get_sites( $args );
if ( is_array( $_sites ) ) {
update_site_cache( $_sites );
$this->items = array_slice( $_sites, 0, $per_page );
}
$total_sites = get_sites(
array_merge(
$args,
array(
'count' => true,
'offset' => 0,
'number' => 0,
)
)
);
$this->set_pagination_args(
array(
'total_items' => $total_sites,
'per_page' => $per_page,
)
);
}
/**
*/
public function no_items() {
_e( 'No sites found.' );
}
/**
* Gets links to filter sites by status.
*
* @since 5.3.0
*
* @return array
*/
protected function get_views() {
$counts = wp_count_sites();
$statuses = array(
/* translators: %s: Number of sites. */
'all' => _nx_noop(
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
'sites'
),
/* translators: %s: Number of sites. */
'public' => _n_noop(
'Public <span class="count">(%s)</span>',
'Public <span class="count">(%s)</span>'
),
/* translators: %s: Number of sites. */
'archived' => _n_noop(
'Archived <span class="count">(%s)</span>',
'Archived <span class="count">(%s)</span>'
),
/* translators: %s: Number of sites. */
'mature' => _n_noop(
'Mature <span class="count">(%s)</span>',
'Mature <span class="count">(%s)</span>'
),
/* translators: %s: Number of sites. */
'spam' => _nx_noop(
'Spam <span class="count">(%s)</span>',
'Spam <span class="count">(%s)</span>',
'sites'
),
/* translators: %s: Number of sites. */
'deleted' => _n_noop(
'Flagged for Deletion <span class="count">(%s)</span>',
'Flagged for Deletion <span class="count">(%s)</span>'
),
);
$view_links = array();
$requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
$url = 'sites.php';
foreach ( $statuses as $status => $label_count ) {
if ( (int) $counts[ $status ] > 0 ) {
$label = sprintf(
translate_nooped_plural( $label_count, $counts[ $status ] ),
number_format_i18n( $counts[ $status ] )
);
$full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url );
$view_links[ $status ] = array(
'url' => esc_url( $full_url ),
'label' => $label,
'current' => $requested_status === $status || ( '' === $requested_status && 'all' === $status ),
);
}
}
return $this->get_views_links( $view_links );
}
/**
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( current_user_can( 'delete_sites' ) ) {
$actions['delete'] = __( 'Delete' );
}
$actions['spam'] = _x( 'Mark as spam', 'site' );
$actions['notspam'] = _x( 'Not spam', 'site' );
return $actions;
}
/**
* @global string $mode List table view mode.
*
* @param string $which The location of the pagination nav markup: Either 'top' or 'bottom'.
*/
protected function pagination( $which ) {
global $mode;
parent::pagination( $which );
if ( 'top' === $which ) {
$this->view_switcher( $mode );
}
}
/**
* Displays extra controls between bulk actions and pagination.
*
* @since 5.3.0
*
* @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'.
*/
protected function extra_tablenav( $which ) {
?>
<div class="alignleft actions">
<?php
if ( 'top' === $which ) {
ob_start();
/**
* Fires before the Filter button on the MS sites list table.
*
* @since 5.3.0
*
* @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'.
*/
do_action( 'restrict_manage_sites', $which );
$output = ob_get_clean();
if ( ! empty( $output ) ) {
echo $output;
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'site-query-submit' ) );
}
}
?>
</div>
<?php
/**
* Fires immediately following the closing "actions" div in the tablenav for the
* MS sites list table.
*
* @since 5.3.0
*
* @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'.
*/
do_action( 'manage_sites_extra_tablenav', $which );
}
/**
* @return string[] Array of column titles keyed by their column name.
*/
public function get_columns() {
$sites_columns = array(
'cb' => '<input type="checkbox" />',
'blogname' => __( 'URL' ),
'lastupdated' => __( 'Last Updated' ),
'registered' => _x( 'Registered', 'site' ),
'users' => __( 'Users' ),
);
if ( has_filter( 'wpmublogsaction' ) ) {
$sites_columns['plugins'] = __( 'Actions' );
}
/**
* Filters the displayed site columns in Sites list table.
*
* @since MU (3.0.0)
*
* @param string[] $sites_columns An array of displayed site columns. Default 'cb',
* 'blogname', 'lastupdated', 'registered', 'users'.
*/
return apply_filters( 'wpmu_blogs_columns', $sites_columns );
}
/**
* @return array
*/
protected function get_sortable_columns() {
if ( is_subdomain_install() ) {
$blogname_abbr = __( 'Domain' );
$blogname_orderby_text = __( 'Table ordered by Site Domain Name.' );
} else {
$blogname_abbr = __( 'Path' );
$blogname_orderby_text = __( 'Table ordered by Site Path.' );
}
return array(
'blogname' => array( 'blogname', false, $blogname_abbr, $blogname_orderby_text ),
'lastupdated' => array( 'lastupdated', true, __( 'Last Updated' ), __( 'Table ordered by Last Updated.' ) ),
'registered' => array( 'blog_id', true, _x( 'Registered', 'site' ), __( 'Table ordered by Site Registered Date.' ), 'desc' ),
);
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param array $item Current site.
*/
public function column_cb( $item ) {
// Restores the more descriptive, specific name for use within this method.
$blog = $item;
if ( ! is_main_site( $blog['blog_id'] ) ) :
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
?>
<input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ); ?>" />
<label for="blog_<?php echo $blog['blog_id']; ?>">
<span class="screen-reader-text">
<?php
/* translators: %s: Site URL. */
printf( __( 'Select %s' ), $blogname );
?>
</span>
</label>
<?php
endif;
}
/**
* Handles the ID column output.
*
* @since 4.4.0
*
* @param array $blog Current site.
*/
public function column_id( $blog ) {
echo $blog['blog_id'];
}
/**
* Handles the site name column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param array $blog Current site.
*/
public function column_blogname( $blog ) {
global $mode;
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
?>
<strong>
<?php
printf(
'<a href="%1$s" class="edit">%2$s</a>',
esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ),
$blogname
);
$this->site_states( $blog );
?>
</strong>
<?php
if ( 'list' !== $mode ) {
switch_to_blog( $blog['blog_id'] );
echo '<p>';
printf(
/* translators: 1: Site title, 2: Site tagline. */
__( '%1$s – %2$s' ),
get_option( 'blogname' ),
'<em>' . get_option( 'blogdescription' ) . '</em>'
);
echo '</p>';
restore_current_blog();
}
}
/**
* Handles the lastupdated column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param array $blog Current site.
*/
public function column_lastupdated( $blog ) {
global $mode;
if ( 'list' === $mode ) {
$date = __( 'Y/m/d' );
} else {
$date = __( 'Y/m/d g:i:s a' );
}
if ( '0000-00-00 00:00:00' === $blog['last_updated'] ) {
_e( 'Never' );
} else {
echo mysql2date( $date, $blog['last_updated'] );
}
}
/**
* Handles the registered column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param array $blog Current site.
*/
public function column_registered( $blog ) {
global $mode;
if ( 'list' === $mode ) {
$date = __( 'Y/m/d' );
} else {
$date = __( 'Y/m/d g:i:s a' );
}
if ( '0000-00-00 00:00:00' === $blog['registered'] ) {
echo '—';
} else {
echo mysql2date( $date, $blog['registered'] );
}
}
/**
* Handles the users column output.
*
* @since 4.3.0
*
* @param array $blog Current site.
*/
public function column_users( $blog ) {
$user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
if ( ! $user_count ) {
$blog_users = new WP_User_Query(
array(
'blog_id' => $blog['blog_id'],
'fields' => 'ID',
'number' => 1,
'count_total' => true,
)
);
$user_count = $blog_users->get_total();
wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
}
printf(
'<a href="%1$s">%2$s</a>',
esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
number_format_i18n( $user_count )
);
}
/**
* Handles the plugins column output.
*
* @since 4.3.0
*
* @param array $blog Current site.
*/
public function column_plugins( $blog ) {
if ( has_filter( 'wpmublogsaction' ) ) {
/**
* Fires inside the auxiliary 'Actions' column of the Sites list table.
*
* By default this column is hidden unless something is hooked to the action.
*
* @since MU (3.0.0)
*
* @param int $blog_id The site ID.
*/
do_action( 'wpmublogsaction', $blog['blog_id'] );
}
}
/**
* Handles output for the default column.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param array $item Current site.
* @param string $column_name Current column name.
*/
public function column_default( $item, $column_name ) {
// Restores the more descriptive, specific name for use within this method.
$blog = $item;
/**
* Fires for each registered custom column in the Sites list table.
*
* @since 3.1.0
*
* @param string $column_name The name of the column to display.
* @param int $blog_id The site ID.
*/
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
}
/**
* Generates the list table rows.
*
* @since 3.1.0
*/
public function display_rows() {
foreach ( $this->items as $blog ) {
$blog = $blog->to_array();
$class = '';
reset( $this->status_list );
foreach ( $this->status_list as $status => $col ) {
if ( '1' === $blog[ $status ] ) {
$class = " class='{$col[0]}'";
}
}
echo "<tr{$class}>";
$this->single_row_columns( $blog );
echo '</tr>';
}
}
/**
* Determines whether to output comma-separated site states.
*
* @since 5.3.0
*
* @param array $site
*/
protected function site_states( $site ) {
$site_states = array();
// $site is still an array, so get the object.
$_site = WP_Site::get_instance( $site['blog_id'] );
if ( is_main_site( $_site->id ) ) {
$site_states['main'] = __( 'Main' );
}
reset( $this->status_list );
$site_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
foreach ( $this->status_list as $status => $col ) {
if ( '1' === $_site->{$status} && $site_status !== $status ) {
$site_states[ $col[0] ] = $col[1];
}
}
/**
* Filters the default site display states for items in the Sites list table.
*
* @since 5.3.0
*
* @param string[] $site_states An array of site states. Default 'Main',
* 'Archived', 'Mature', 'Spam', 'Flagged for Deletion'.
* @param WP_Site $site The current site object.
*/
$site_states = apply_filters( 'display_site_states', $site_states, $_site );
if ( ! empty( $site_states ) ) {
$state_count = count( $site_states );
$i = 0;
echo ' — ';
foreach ( $site_states as $state ) {
++$i;
$separator = ( $i < $state_count ) ? ', ' : '';
echo "<span class='post-state'>{$state}{$separator}</span>";
}
}
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'blogname'.
*/
protected function get_default_primary_column_name() {
return 'blogname';
}
/**
* Generates and displays row action links.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param array $item Site being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row actions output for sites in Multisite, or an empty string
* if the current column is not the primary column.
*/
protected function handle_row_actions( $item, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
// Restores the more descriptive, specific name for use within this method.
$blog = $item;
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
// Preordered.
$actions = array(
'edit' => '',
'backend' => '',
'activate' => '',
'deactivate' => '',
'archive' => '',
'unarchive' => '',
'spam' => '',
'unspam' => '',
'delete' => '',
'visit' => '',
);
$actions['edit'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ),
__( 'Edit' )
);
$actions['backend'] = sprintf(
'<a href="%1$s" class="edit">%2$s</a>',
esc_url( get_admin_url( $blog['blog_id'] ) ),
__( 'Dashboard' )
);
if ( ! is_main_site( $blog['blog_id'] ) ) {
if ( '1' === $blog['deleted'] ) {
$actions['activate'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url(
wp_nonce_url(
network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] ),
'activateblog_' . $blog['blog_id']
)
),
_x( 'Remove Deletion Flag', 'site' )
);
} else {
$actions['deactivate'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url(
wp_nonce_url(
network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] ),
'deactivateblog_' . $blog['blog_id']
)
),
__( 'Flag for Deletion' )
);
}
if ( '1' === $blog['archived'] ) {
$actions['unarchive'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url(
wp_nonce_url(
network_admin_url( 'sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] ),
'unarchiveblog_' . $blog['blog_id']
)
),
__( 'Unarchive' )
);
} else {
$actions['archive'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url(
wp_nonce_url(
network_admin_url( 'sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] ),
'archiveblog_' . $blog['blog_id']
)
),
_x( 'Archive', 'verb; site' )
);
}
if ( '1' === $blog['spam'] ) {
$actions['unspam'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url(
wp_nonce_url(
network_admin_url( 'sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] ),
'unspamblog_' . $blog['blog_id']
)
),
_x( 'Not Spam', 'site' )
);
} else {
$actions['spam'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url(
wp_nonce_url(
network_admin_url( 'sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] ),
'spamblog_' . $blog['blog_id']
)
),
_x( 'Spam', 'site' )
);
}
if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) {
$actions['delete'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url(
wp_nonce_url(
network_admin_url( 'sites.php?action=confirm&action2=deleteblog&id=' . $blog['blog_id'] ),
'deleteblog_' . $blog['blog_id']
)
),
__( 'Delete Permanently' )
);
}
}
$actions['visit'] = sprintf(
'<a href="%1$s" rel="bookmark">%2$s</a>',
esc_url( get_home_url( $blog['blog_id'], '/' ) ),
__( 'Visit' )
);
/**
* Filters the action links displayed for each site in the Sites list table.
*
* The 'Edit', 'Dashboard', 'Delete Permanently', and 'Visit' links are displayed by
* default for each site. The site's status determines whether to show the
* 'Remove Deletion Flag' or 'Flag for Deletion' link, 'Unarchive' or 'Archive' links, and
* 'Not Spam' or 'Spam' link for each site.
*
* @since 3.1.0
*
* @param string[] $actions An array of action links to be displayed.
* @param int $blog_id The site ID.
* @param string $blogname Site path, formatted depending on whether it is a sub-domain
* or subdirectory multisite installation.
*/
$actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
return $this->row_actions( $actions );
}
}
PK �MP\�$��% % - class-wp-application-passwords-list-table.phpnu �[��� <?php
/**
* List Table API: WP_Application_Passwords_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 5.6.0
*/
/**
* Class for displaying the list of application password items.
*
* @since 5.6.0
*
* @see WP_List_Table
*/
class WP_Application_Passwords_List_Table extends WP_List_Table {
/**
* Gets the list of columns.
*
* @since 5.6.0
*
* @return string[] Array of column titles keyed by their column name.
*/
public function get_columns() {
return array(
'name' => __( 'Name' ),
'created' => __( 'Created' ),
'last_used' => __( 'Last Used' ),
'last_ip' => __( 'Last IP' ),
'revoke' => __( 'Revoke' ),
);
}
/**
* Prepares the list of items for displaying.
*
* @since 5.6.0
*
* @global int $user_id User ID.
*/
public function prepare_items() {
global $user_id;
$this->items = array_reverse( WP_Application_Passwords::get_user_application_passwords( $user_id ) );
}
/**
* Handles the name column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_name( $item ) {
echo esc_html( $item['name'] );
}
/**
* Handles the created column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_created( $item ) {
if ( empty( $item['created'] ) ) {
echo '—';
} else {
echo date_i18n( __( 'F j, Y' ), $item['created'] );
}
}
/**
* Handles the last used column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_last_used( $item ) {
if ( empty( $item['last_used'] ) ) {
echo '—';
} else {
echo date_i18n( __( 'F j, Y' ), $item['last_used'] );
}
}
/**
* Handles the last ip column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_last_ip( $item ) {
if ( empty( $item['last_ip'] ) ) {
echo '—';
} else {
echo $item['last_ip'];
}
}
/**
* Handles the revoke column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_revoke( $item ) {
$name = 'revoke-application-password-' . $item['uuid'];
printf(
'<button type="button" name="%1$s" id="%1$s" class="button delete" aria-label="%2$s">%3$s</button>',
esc_attr( $name ),
/* translators: %s: the application password's given name. */
esc_attr( sprintf( __( 'Revoke "%s"' ), $item['name'] ) ),
__( 'Revoke' )
);
}
/**
* Generates content for a single row of the table
*
* @since 5.6.0
*
* @param array $item The current item.
* @param string $column_name The current column name.
*/
protected function column_default( $item, $column_name ) {
/**
* Fires for each custom column in the Application Passwords list table.
*
* Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter.
*
* @since 5.6.0
*
* @param string $column_name Name of the custom column.
* @param array $item The application password item.
*/
do_action( "manage_{$this->screen->id}_custom_column", $column_name, $item );
}
/**
* Generates custom table navigation to prevent conflicting nonces.
*
* @since 5.6.0
*
* @param string $which The location of the bulk actions: Either 'top' or 'bottom'.
*/
protected function display_tablenav( $which ) {
?>
<div class="tablenav <?php echo esc_attr( $which ); ?>">
<?php if ( 'bottom' === $which ) : ?>
<div class="alignright">
<button type="button" name="revoke-all-application-passwords" id="revoke-all-application-passwords" class="button delete"><?php _e( 'Revoke all application passwords' ); ?></button>
</div>
<?php endif; ?>
<div class="alignleft actions bulkactions">
<?php $this->bulk_actions( $which ); ?>
</div>
<?php
$this->extra_tablenav( $which );
$this->pagination( $which );
?>
<br class="clear" />
</div>
<?php
}
/**
* Generates content for a single row of the table.
*
* @since 5.6.0
*
* @param array $item The current item.
*/
public function single_row( $item ) {
echo '<tr data-uuid="' . esc_attr( $item['uuid'] ) . '">';
$this->single_row_columns( $item );
echo '</tr>';
}
/**
* Gets the name of the default primary column.
*
* @since 5.6.0
*
* @return string Name of the default primary column, in this case, 'name'.
*/
protected function get_default_primary_column_name() {
return 'name';
}
/**
* Prints the JavaScript template for the new row item.
*
* @since 5.6.0
*/
public function print_js_template_row() {
list( $columns, $hidden, , $primary ) = $this->get_column_info();
echo '<tr data-uuid="{{ data.uuid }}">';
foreach ( $columns as $column_name => $display_name ) {
$is_primary = $primary === $column_name;
$classes = "{$column_name} column-{$column_name}";
if ( $is_primary ) {
$classes .= ' has-row-actions column-primary';
}
if ( in_array( $column_name, $hidden, true ) ) {
$classes .= ' hidden';
}
printf( '<td class="%s" data-colname="%s">', esc_attr( $classes ), esc_attr( wp_strip_all_tags( $display_name ) ) );
switch ( $column_name ) {
case 'name':
echo '{{ data.name }}';
break;
case 'created':
// JSON encoding automatically doubles backslashes to ensure they don't get lost when printing the inline JS.
echo '<# print( wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ', data.created ) ) #>';
break;
case 'last_used':
echo '<# print( data.last_used !== null ? wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ", data.last_used ) : '—' ) #>";
break;
case 'last_ip':
echo "{{ data.last_ip || '—' }}";
break;
case 'revoke':
printf(
'<button type="button" class="button delete" aria-label="%1$s">%2$s</button>',
/* translators: %s: the application password's given name. */
esc_attr( sprintf( __( 'Revoke "%s"' ), '{{ data.name }}' ) ),
esc_html__( 'Revoke' )
);
break;
default:
/**
* Fires in the JavaScript row template for each custom column in the Application Passwords list table.
*
* Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter.
*
* @since 5.6.0
*
* @param string $column_name Name of the custom column.
*/
do_action( "manage_{$this->screen->id}_custom_column_js_template", $column_name );
break;
}
if ( $is_primary ) {
echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Show more details' ) .
'</span></button>';
}
echo '</td>';
}
echo '</tr>';
}
}
PK �MP\A��^2� 2� upgrade.phpnu �[��� <?php
/**
* WordPress Upgrade API
*
* Most of the functions are pluggable and can be overwritten.
*
* @package WordPress
* @subpackage Administration
*/
/** Include user installation customization script. */
if ( file_exists( WP_CONTENT_DIR . '/install.php' ) ) {
require WP_CONTENT_DIR . '/install.php';
}
/** WordPress Administration API */
require_once ABSPATH . 'wp-admin/includes/admin.php';
/** WordPress Schema API */
require_once ABSPATH . 'wp-admin/includes/schema.php';
if ( ! function_exists( 'wp_install' ) ) :
/**
* Installs the site.
*
* Runs the required functions to set up and populate the database,
* including primary admin user and initial options.
*
* @since 2.1.0
*
* @param string $blog_title Site title.
* @param string $user_name User's username.
* @param string $user_email User's email.
* @param bool $is_public Whether the site is public.
* @param string $deprecated Optional. Not used.
* @param string $user_password Optional. User's chosen password. Default empty (random password).
* @param string $language Optional. Language chosen. Default empty.
* @return array {
* Data for the newly installed site.
*
* @type string $url The URL of the site.
* @type int $user_id The ID of the site owner.
* @type string $password The password of the site owner, if their user account didn't already exist.
* @type string $password_message The explanatory message regarding the password.
* }
*/
function wp_install(
$blog_title,
$user_name,
$user_email,
$is_public,
$deprecated = '',
#[\SensitiveParameter]
$user_password = '',
$language = ''
) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.6.0' );
}
wp_check_mysql_version();
wp_cache_flush();
make_db_current_silent();
/*
* Ensure update checks are delayed after installation.
*
* This prevents users being presented with a maintenance mode screen
* immediately after installation.
*/
wp_unschedule_hook( 'wp_version_check' );
wp_unschedule_hook( 'wp_update_plugins' );
wp_unschedule_hook( 'wp_update_themes' );
wp_schedule_event( time() + HOUR_IN_SECONDS, 'twicedaily', 'wp_version_check' );
wp_schedule_event( time() + ( 1.5 * HOUR_IN_SECONDS ), 'twicedaily', 'wp_update_plugins' );
wp_schedule_event( time() + ( 2 * HOUR_IN_SECONDS ), 'twicedaily', 'wp_update_themes' );
populate_options();
populate_roles();
update_option( 'blogname', $blog_title );
update_option( 'admin_email', $user_email );
update_option( 'blog_public', $is_public );
// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
update_option( 'fresh_site', 1, false );
if ( $language ) {
update_option( 'WPLANG', $language );
}
$guessurl = wp_guess_url();
update_option( 'siteurl', $guessurl );
// If not a public site, don't ping.
if ( ! $is_public ) {
update_option( 'default_pingback_flag', 0 );
}
/*
* Create default user. If the user already exists, the user tables are
* being shared among sites. Just set the role in that case.
*/
$user_id = username_exists( $user_name );
$user_password = trim( $user_password );
$email_password = false;
$user_created = false;
if ( ! $user_id && empty( $user_password ) ) {
$user_password = wp_generate_password( 12, false );
$message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
$user_id = wp_create_user( $user_name, $user_password, $user_email );
update_user_meta( $user_id, 'default_password_nag', true );
$email_password = true;
$user_created = true;
} elseif ( ! $user_id ) {
// Password has been provided.
$message = '<em>' . __( 'Your chosen password.' ) . '</em>';
$user_id = wp_create_user( $user_name, $user_password, $user_email );
$user_created = true;
} else {
$message = __( 'User already exists. Password inherited.' );
}
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
if ( $user_created ) {
$user->user_url = $guessurl;
wp_update_user( $user );
}
wp_install_defaults( $user_id );
wp_install_maybe_enable_pretty_permalinks();
flush_rewrite_rules();
wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.' ) ) );
wp_cache_flush();
/**
* Fires after a site is fully installed.
*
* @since 3.9.0
*
* @param WP_User $user The site owner.
*/
do_action( 'wp_install', $user );
return array(
'url' => $guessurl,
'user_id' => $user_id,
'password' => $user_password,
'password_message' => $message,
);
}
endif;
if ( ! function_exists( 'wp_install_defaults' ) ) :
/**
* Creates the initial content for a newly-installed site.
*
* Adds the default "Uncategorized" category, the first post (with comment),
* first page, and default widgets for default theme for the current version.
*
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @global string $table_prefix The database table prefix.
*
* @param int $user_id User ID.
*/
function wp_install_defaults( $user_id ) {
global $wpdb, $wp_rewrite, $table_prefix;
// Default category.
$cat_name = __( 'Uncategorized' );
/* translators: Default category slug. */
$cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
$cat_id = 1;
$wpdb->insert(
$wpdb->terms,
array(
'term_id' => $cat_id,
'name' => $cat_name,
'slug' => $cat_slug,
'term_group' => 0,
)
);
$wpdb->insert(
$wpdb->term_taxonomy,
array(
'term_id' => $cat_id,
'taxonomy' => 'category',
'description' => '',
'parent' => 0,
'count' => 1,
)
);
$cat_tt_id = $wpdb->insert_id;
// First post.
$now = current_time( 'mysql' );
$now_gmt = current_time( 'mysql', true );
$first_post_guid = get_option( 'home' ) . '/?p=1';
if ( is_multisite() ) {
$first_post = get_site_option( 'first_post' );
if ( ! $first_post ) {
$first_post = "<!-- wp:paragraph -->\n<p>" .
/* translators: First post content. %s: Site link. */
__( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) .
"</p>\n<!-- /wp:paragraph -->";
}
$first_post = sprintf(
$first_post,
sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name )
);
// Back-compat for pre-4.4.
$first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
$first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
} else {
$first_post = "<!-- wp:paragraph -->\n<p>" .
/* translators: First post content. %s: Site link. */
__( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) .
"</p>\n<!-- /wp:paragraph -->";
}
$wpdb->insert(
$wpdb->posts,
array(
'post_author' => $user_id,
'post_date' => $now,
'post_date_gmt' => $now_gmt,
'post_content' => $first_post,
'post_excerpt' => '',
'post_title' => __( 'Hello world!' ),
/* translators: Default post slug. */
'post_name' => sanitize_title( _x( 'hello-world', 'Default post slug' ) ),
'post_modified' => $now,
'post_modified_gmt' => $now_gmt,
'guid' => $first_post_guid,
'comment_count' => 1,
'to_ping' => '',
'pinged' => '',
'post_content_filtered' => '',
)
);
if ( is_multisite() ) {
update_posts_count();
}
$wpdb->insert(
$wpdb->term_relationships,
array(
'term_taxonomy_id' => $cat_tt_id,
'object_id' => 1,
)
);
// Default comment.
if ( is_multisite() ) {
$first_comment_author = get_site_option( 'first_comment_author' );
$first_comment_email = get_site_option( 'first_comment_email' );
$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
$first_comment = get_site_option( 'first_comment' );
}
$first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' );
$first_comment_email = ! empty( $first_comment_email ) ? $first_comment_email : 'wapuu@wordpress.example';
$first_comment_url = ! empty( $first_comment_url ) ? $first_comment_url : esc_url( __( 'https://wordpress.org/' ) );
$first_comment = ! empty( $first_comment ) ? $first_comment : sprintf(
/* translators: %s: Gravatar URL. */
__(
'Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from <a href="%s">Gravatar</a>.'
),
/* translators: The localized Gravatar URL. */
esc_url( __( 'https://gravatar.com/' ) )
);
$wpdb->insert(
$wpdb->comments,
array(
'comment_post_ID' => 1,
'comment_author' => $first_comment_author,
'comment_author_email' => $first_comment_email,
'comment_author_url' => $first_comment_url,
'comment_date' => $now,
'comment_date_gmt' => $now_gmt,
'comment_content' => $first_comment,
'comment_type' => 'comment',
)
);
// First page.
if ( is_multisite() ) {
$first_page = get_site_option( 'first_page' );
}
if ( empty( $first_page ) ) {
$first_page = "<!-- wp:paragraph -->\n<p>";
/* translators: First page content. */
$first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" );
$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\">\n<!-- wp:paragraph -->\n<p>";
/* translators: First page content. */
$first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)" );
$first_page .= "</p>\n<!-- /wp:paragraph -->\n</blockquote>\n<!-- /wp:quote -->\n\n";
$first_page .= "<!-- wp:paragraph -->\n<p>";
/* translators: First page content. */
$first_page .= __( '...or something like this:' );
$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\">\n<!-- wp:paragraph -->\n<p>";
/* translators: First page content. */
$first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' );
$first_page .= "</p>\n<!-- /wp:paragraph -->\n</blockquote>\n<!-- /wp:quote -->\n\n";
$first_page .= "<!-- wp:paragraph -->\n<p>";
$first_page .= sprintf(
/* translators: First page content. %s: Site admin URL. */
__( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ),
admin_url()
);
$first_page .= "</p>\n<!-- /wp:paragraph -->";
}
$first_post_guid = get_option( 'home' ) . '/?page_id=2';
$wpdb->insert(
$wpdb->posts,
array(
'post_author' => $user_id,
'post_date' => $now,
'post_date_gmt' => $now_gmt,
'post_content' => $first_page,
'post_excerpt' => '',
'comment_status' => 'closed',
'post_title' => __( 'Sample Page' ),
/* translators: Default page slug. */
'post_name' => __( 'sample-page' ),
'post_modified' => $now,
'post_modified_gmt' => $now_gmt,
'guid' => $first_post_guid,
'post_type' => 'page',
'to_ping' => '',
'pinged' => '',
'post_content_filtered' => '',
)
);
$wpdb->insert(
$wpdb->postmeta,
array(
'post_id' => 2,
'meta_key' => '_wp_page_template',
'meta_value' => 'default',
)
);
// Privacy Policy page.
if ( is_multisite() ) {
// Disable by default unless the suggested content is provided.
$privacy_policy_content = get_site_option( 'default_privacy_policy_content' );
} else {
if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
}
$privacy_policy_content = WP_Privacy_Policy_Content::get_default_content();
}
if ( ! empty( $privacy_policy_content ) ) {
$privacy_policy_guid = get_option( 'home' ) . '/?page_id=3';
$wpdb->insert(
$wpdb->posts,
array(
'post_author' => $user_id,
'post_date' => $now,
'post_date_gmt' => $now_gmt,
'post_content' => $privacy_policy_content,
'post_excerpt' => '',
'comment_status' => 'closed',
'post_title' => __( 'Privacy Policy' ),
/* translators: Privacy Policy page slug. */
'post_name' => __( 'privacy-policy' ),
'post_modified' => $now,
'post_modified_gmt' => $now_gmt,
'guid' => $privacy_policy_guid,
'post_type' => 'page',
'post_status' => 'draft',
'to_ping' => '',
'pinged' => '',
'post_content_filtered' => '',
)
);
$wpdb->insert(
$wpdb->postmeta,
array(
'post_id' => 3,
'meta_key' => '_wp_page_template',
'meta_value' => 'default',
)
);
update_option( 'wp_page_for_privacy_policy', 3 );
}
// Set up default widgets for default theme.
update_option(
'widget_block',
array(
2 => array( 'content' => '<!-- wp:search /-->' ),
3 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Posts' ) . '</h2><!-- /wp:heading --><!-- wp:latest-posts /--></div><!-- /wp:group -->' ),
4 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Comments' ) . '</h2><!-- /wp:heading --><!-- wp:latest-comments {"displayAvatar":false,"displayDate":false,"displayExcerpt":false} /--></div><!-- /wp:group -->' ),
5 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Archives' ) . '</h2><!-- /wp:heading --><!-- wp:archives /--></div><!-- /wp:group -->' ),
6 => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Categories' ) . '</h2><!-- /wp:heading --><!-- wp:categories /--></div><!-- /wp:group -->' ),
'_multiwidget' => 1,
)
);
update_option(
'sidebars_widgets',
array(
'wp_inactive_widgets' => array(),
'sidebar-1' => array(
0 => 'block-2',
1 => 'block-3',
2 => 'block-4',
),
'sidebar-2' => array(
0 => 'block-5',
1 => 'block-6',
),
'array_version' => 3,
)
);
if ( ! is_multisite() ) {
update_user_meta( $user_id, 'show_welcome_panel', 1 );
} elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
update_user_meta( $user_id, 'show_welcome_panel', 2 );
}
if ( is_multisite() ) {
// Flush rules to pick up the new page.
$wp_rewrite->init();
$wp_rewrite->flush_rules();
$user = new WP_User( $user_id );
$wpdb->update( $wpdb->options, array( 'option_value' => $user->user_email ), array( 'option_name' => 'admin_email' ) );
// Remove all perms except for the login user.
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level' ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) );
/*
* Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
* TODO: Get previous_blog_id.
*/
if ( ! is_super_admin( $user_id ) && 1 !== $user_id ) {
$wpdb->delete(
$wpdb->usermeta,
array(
'user_id' => $user_id,
'meta_key' => $wpdb->base_prefix . '1_capabilities',
)
);
}
}
}
endif;
/**
* Maybe enable pretty permalinks on installation.
*
* If after enabling pretty permalinks don't work, fallback to query-string permalinks.
*
* @since 4.2.0
*
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
*
* @return bool Whether pretty permalinks are enabled. False otherwise.
*/
function wp_install_maybe_enable_pretty_permalinks() {
global $wp_rewrite;
// Bail if a permalink structure is already enabled.
if ( get_option( 'permalink_structure' ) ) {
return true;
}
/*
* The Permalink structures to attempt.
*
* The first is designed for mod_rewrite or nginx rewriting.
*
* The second is PATHINFO-based permalinks for web server configurations
* without a true rewrite module enabled.
*/
$permalink_structures = array(
'/%year%/%monthnum%/%day%/%postname%/',
'/index.php/%year%/%monthnum%/%day%/%postname%/',
);
foreach ( (array) $permalink_structures as $permalink_structure ) {
$wp_rewrite->set_permalink_structure( $permalink_structure );
/*
* Flush rules with the hard option to force refresh of the web-server's
* rewrite config file (e.g. .htaccess or web.config).
*/
$wp_rewrite->flush_rules( true );
$test_url = '';
// Test against a real WordPress post.
$first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
if ( $first_post ) {
$test_url = get_permalink( $first_post->ID );
}
/*
* Send a request to the site, and check whether
* the 'X-Pingback' header is returned as expected.
*
* Uses wp_remote_get() instead of wp_remote_head() because web servers
* can block head requests.
*/
$response = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
$x_pingback_header = wp_remote_retrieve_header( $response, 'X-Pingback' );
$pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;
if ( $pretty_permalinks ) {
return true;
}
}
/*
* If it makes it this far, pretty permalinks failed.
* Fallback to query-string permalinks.
*/
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules( true );
return false;
}
if ( ! function_exists( 'wp_new_blog_notification' ) ) :
/**
* Notifies the site admin that the installation of WordPress is complete.
*
* Sends an email to the new administrator that the installation is complete
* and provides them with a record of their login credentials.
*
* @since 2.1.0
*
* @param string $blog_title Site title.
* @param string $blog_url Site URL.
* @param int $user_id Administrator's user ID.
* @param string $password Administrator's password. Note that a placeholder message is
* usually passed instead of the actual password.
*/
function wp_new_blog_notification(
$blog_title,
$blog_url,
$user_id,
#[\SensitiveParameter]
$password
) {
$user = new WP_User( $user_id );
$email = $user->user_email;
$name = $user->user_login;
$login_url = wp_login_url();
$message = sprintf(
/* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL. */
__(
'Your new WordPress site has been successfully set up at:
%1$s
You can log in to the administrator account with the following information:
Username: %2$s
Password: %3$s
Log in here: %4$s
We hope you enjoy your new site. Thanks!
--The WordPress Team
https://wordpress.org/
'
),
$blog_url,
$name,
$password,
$login_url
);
$installed_email = array(
'to' => $email,
'subject' => __( 'New WordPress Site' ),
'message' => $message,
'headers' => '',
);
/**
* Filters the contents of the email sent to the site administrator when WordPress is installed.
*
* @since 5.6.0
*
* @param array $installed_email {
* Used to build wp_mail().
*
* @type string $to The email address of the recipient.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* @type string $headers Headers.
* }
* @param WP_User $user The site administrator user object.
* @param string $blog_title The site title.
* @param string $blog_url The site URL.
* @param string $password The site administrator's password. Note that a placeholder message
* is usually passed instead of the user's actual password.
*/
$installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password );
wp_mail(
$installed_email['to'],
$installed_email['subject'],
$installed_email['message'],
$installed_email['headers']
);
}
endif;
if ( ! function_exists( 'wp_upgrade' ) ) :
/**
* Runs WordPress Upgrade functions.
*
* Upgrades the database if needed during a site update.
*
* @since 2.1.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global int $wp_db_version The new database version.
*/
function wp_upgrade() {
global $wp_current_db_version, $wp_db_version;
$wp_current_db_version = (int) __get_option( 'db_version' );
// We are up to date. Nothing to do.
if ( $wp_db_version === $wp_current_db_version ) {
return;
}
if ( ! is_blog_installed() ) {
return;
}
wp_check_mysql_version();
wp_cache_flush();
pre_schema_upgrade();
make_db_current_silent();
upgrade_all();
if ( is_multisite() && is_main_site() ) {
upgrade_network();
}
wp_cache_flush();
if ( is_multisite() ) {
update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version );
update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() );
}
delete_transient( 'wp_core_block_css_files' );
/**
* Fires after a site is fully upgraded.
*
* @since 3.9.0
*
* @param int $wp_db_version The new $wp_db_version.
* @param int $wp_current_db_version The old (current) $wp_db_version.
*/
do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );
}
endif;
/**
* Functions to be called in installation and upgrade scripts.
*
* Contains conditional checks to determine which upgrade scripts to run,
* based on database version and WP version being updated-to.
*
* @ignore
* @since 1.0.1
*
* @global int $wp_current_db_version The old (current) database version.
* @global int $wp_db_version The new database version.
*/
function upgrade_all() {
global $wp_current_db_version, $wp_db_version;
$wp_current_db_version = (int) __get_option( 'db_version' );
// We are up to date. Nothing to do.
if ( $wp_db_version === $wp_current_db_version ) {
return;
}
// If the version is not set in the DB, try to guess the version.
if ( empty( $wp_current_db_version ) ) {
$wp_current_db_version = 0;
// If the template option exists, we have 1.5.
$template = __get_option( 'template' );
if ( ! empty( $template ) ) {
$wp_current_db_version = 2541;
}
}
if ( $wp_current_db_version < 6039 ) {
upgrade_230_options_table();
}
populate_options();
if ( $wp_current_db_version < 2541 ) {
upgrade_100();
upgrade_101();
upgrade_110();
upgrade_130();
}
if ( $wp_current_db_version < 3308 ) {
upgrade_160();
}
if ( $wp_current_db_version < 4772 ) {
upgrade_210();
}
if ( $wp_current_db_version < 4351 ) {
upgrade_old_slugs();
}
if ( $wp_current_db_version < 5539 ) {
upgrade_230();
}
if ( $wp_current_db_version < 6124 ) {
upgrade_230_old_tables();
}
if ( $wp_current_db_version < 7499 ) {
upgrade_250();
}
if ( $wp_current_db_version < 7935 ) {
upgrade_252();
}
if ( $wp_current_db_version < 8201 ) {
upgrade_260();
}
if ( $wp_current_db_version < 8989 ) {
upgrade_270();
}
if ( $wp_current_db_version < 10360 ) {
upgrade_280();
}
if ( $wp_current_db_version < 11958 ) {
upgrade_290();
}
if ( $wp_current_db_version < 15260 ) {
upgrade_300();
}
if ( $wp_current_db_version < 19389 ) {
upgrade_330();
}
if ( $wp_current_db_version < 20080 ) {
upgrade_340();
}
if ( $wp_current_db_version < 22422 ) {
upgrade_350();
}
if ( $wp_current_db_version < 25824 ) {
upgrade_370();
}
if ( $wp_current_db_version < 26148 ) {
upgrade_372();
}
if ( $wp_current_db_version < 26691 ) {
upgrade_380();
}
if ( $wp_current_db_version < 29630 ) {
upgrade_400();
}
if ( $wp_current_db_version < 33055 ) {
upgrade_430();
}
if ( $wp_current_db_version < 33056 ) {
upgrade_431();
}
if ( $wp_current_db_version < 35700 ) {
upgrade_440();
}
if ( $wp_current_db_version < 36686 ) {
upgrade_450();
}
if ( $wp_current_db_version < 37965 ) {
upgrade_460();
}
if ( $wp_current_db_version < 44719 ) {
upgrade_510();
}
if ( $wp_current_db_version < 45744 ) {
upgrade_530();
}
if ( $wp_current_db_version < 48575 ) {
upgrade_550();
}
if ( $wp_current_db_version < 49752 ) {
upgrade_560();
}
if ( $wp_current_db_version < 51917 ) {
upgrade_590();
}
if ( $wp_current_db_version < 53011 ) {
upgrade_600();
}
if ( $wp_current_db_version < 55853 ) {
upgrade_630();
}
if ( $wp_current_db_version < 56657 ) {
upgrade_640();
}
if ( $wp_current_db_version < 57155 ) {
upgrade_650();
}
if ( $wp_current_db_version < 58975 ) {
upgrade_670();
}
if ( $wp_current_db_version < 60421 ) {
upgrade_682();
}
maybe_disable_link_manager();
maybe_disable_automattic_widgets();
update_option( 'db_version', $wp_db_version );
update_option( 'db_upgraded', true );
}
/**
* Execute changes made in WordPress 1.0.
*
* @ignore
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_100() {
global $wpdb;
// Get the title and ID of every post, post_name to check if it already has a value.
$posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
if ( $posts ) {
foreach ( $posts as $post ) {
if ( '' === $post->post_name ) {
$newtitle = sanitize_title( $post->post_title );
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) );
}
}
}
$categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
foreach ( $categories as $category ) {
if ( '' === $category->category_nicename ) {
$newtitle = sanitize_title( $category->cat_name );
$wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) );
}
}
$sql = "UPDATE $wpdb->options
SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
WHERE option_name LIKE %s
AND option_value LIKE %s";
$wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
$done_ids = $wpdb->get_results( "SELECT DISTINCT post_id FROM $wpdb->post2cat" );
if ( $done_ids ) :
$done_posts = array();
foreach ( $done_ids as $done_id ) :
$done_posts[] = $done_id->post_id;
endforeach;
$catwhere = ' AND ID NOT IN (' . implode( ',', $done_posts ) . ')';
else :
$catwhere = '';
endif;
$allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
if ( $allposts ) :
foreach ( $allposts as $post ) {
// Check to see if it's already been imported.
$cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
if ( ! $cat && 0 !== (int) $post->post_category ) { // If there's no result.
$wpdb->insert(
$wpdb->post2cat,
array(
'post_id' => $post->ID,
'category_id' => $post->post_category,
)
);
}
}
endif;
}
/**
* Execute changes made in WordPress 1.0.1.
*
* @ignore
* @since 1.0.1
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_101() {
global $wpdb;
// Clean up indices, add a few.
add_clean_index( $wpdb->posts, 'post_name' );
add_clean_index( $wpdb->posts, 'post_status' );
add_clean_index( $wpdb->categories, 'category_nicename' );
add_clean_index( $wpdb->comments, 'comment_approved' );
add_clean_index( $wpdb->comments, 'comment_post_ID' );
add_clean_index( $wpdb->links, 'link_category' );
add_clean_index( $wpdb->links, 'link_visible' );
}
/**
* Execute changes made in WordPress 1.2.
*
* @ignore
* @since 1.2.0
* @since 6.8.0 User passwords are no longer hashed with md5.
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_110() {
global $wpdb;
// Set user_nicename.
$users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
foreach ( $users as $user ) {
if ( '' === $user->user_nicename ) {
$newname = sanitize_title( $user->user_nickname );
$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
}
}
// Get the GMT offset, we'll use that later on.
$all_options = get_alloptions_110();
$time_difference = $all_options->time_difference;
$server_time = time() + (int) gmdate( 'Z' );
$weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS;
$gmt_time = time();
$diff_gmt_server = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
$diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
$diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
$gmt_offset = -$diff_gmt_weblogger;
// Add a gmt_offset option, with value $gmt_offset.
add_option( 'gmt_offset', $gmt_offset );
/*
* Check if we already set the GMT fields. If we did, then
* MAX(post_date_gmt) can't be '0000-00-00 00:00:00'.
* <michel_v> I just slapped myself silly for not thinking about it earlier.
*/
$got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
if ( ! $got_gmt_fields ) {
// Add or subtract time to all dates, to get GMT dates.
$add_hours = (int) $diff_gmt_weblogger;
$add_minutes = (int) ( 60 * ( $diff_gmt_weblogger - $add_hours ) );
$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
$wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
$wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
$wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
$wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
}
}
/**
* Execute changes made in WordPress 1.5.
*
* @ignore
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_130() {
global $wpdb;
// Remove extraneous backslashes.
$posts = $wpdb->get_results( "SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts" );
if ( $posts ) {
foreach ( $posts as $post ) {
$post_content = addslashes( deslash( $post->post_content ) );
$post_title = addslashes( deslash( $post->post_title ) );
$post_excerpt = addslashes( deslash( $post->post_excerpt ) );
if ( empty( $post->guid ) ) {
$guid = get_permalink( $post->ID );
} else {
$guid = $post->guid;
}
$wpdb->update( $wpdb->posts, compact( 'post_title', 'post_content', 'post_excerpt', 'guid' ), array( 'ID' => $post->ID ) );
}
}
// Remove extraneous backslashes.
$comments = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments" );
if ( $comments ) {
foreach ( $comments as $comment ) {
$comment_content = deslash( $comment->comment_content );
$comment_author = deslash( $comment->comment_author );
$wpdb->update( $wpdb->comments, compact( 'comment_content', 'comment_author' ), array( 'comment_ID' => $comment->comment_ID ) );
}
}
// Remove extraneous backslashes.
$links = $wpdb->get_results( "SELECT link_id, link_name, link_description FROM $wpdb->links" );
if ( $links ) {
foreach ( $links as $link ) {
$link_name = deslash( $link->link_name );
$link_description = deslash( $link->link_description );
$wpdb->update( $wpdb->links, compact( 'link_name', 'link_description' ), array( 'link_id' => $link->link_id ) );
}
}
$active_plugins = __get_option( 'active_plugins' );
/*
* If plugins are not stored in an array, they're stored in the old
* newline separated format. Convert to new format.
*/
if ( ! is_array( $active_plugins ) ) {
$active_plugins = explode( "\n", trim( $active_plugins ) );
update_option( 'active_plugins', $active_plugins );
}
// Obsolete tables.
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );
// Update comments table to use comment_type.
$wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
$wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
// Some versions have multiple duplicate option_name rows with the same values.
$options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
foreach ( $options as $option ) {
if ( $option->dupes > 1 ) { // Could this be done in the query?
$limit = $option->dupes - 1;
$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
if ( $dupe_ids ) {
$dupe_ids = implode( ',', $dupe_ids );
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
}
}
}
make_site_theme();
}
/**
* Execute changes made in WordPress 2.0.
*
* @ignore
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_160() {
global $wpdb, $wp_current_db_version;
populate_roles_160();
$users = $wpdb->get_results( "SELECT * FROM $wpdb->users" );
foreach ( $users as $user ) :
if ( ! empty( $user->user_firstname ) ) {
update_user_meta( $user->ID, 'first_name', wp_slash( $user->user_firstname ) );
}
if ( ! empty( $user->user_lastname ) ) {
update_user_meta( $user->ID, 'last_name', wp_slash( $user->user_lastname ) );
}
if ( ! empty( $user->user_nickname ) ) {
update_user_meta( $user->ID, 'nickname', wp_slash( $user->user_nickname ) );
}
if ( ! empty( $user->user_level ) ) {
update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
}
if ( ! empty( $user->user_icq ) ) {
update_user_meta( $user->ID, 'icq', wp_slash( $user->user_icq ) );
}
if ( ! empty( $user->user_aim ) ) {
update_user_meta( $user->ID, 'aim', wp_slash( $user->user_aim ) );
}
if ( ! empty( $user->user_msn ) ) {
update_user_meta( $user->ID, 'msn', wp_slash( $user->user_msn ) );
}
if ( ! empty( $user->user_yim ) ) {
update_user_meta( $user->ID, 'yim', wp_slash( $user->user_icq ) );
}
if ( ! empty( $user->user_description ) ) {
update_user_meta( $user->ID, 'description', wp_slash( $user->user_description ) );
}
if ( isset( $user->user_idmode ) ) :
$idmode = $user->user_idmode;
if ( 'nickname' === $idmode ) {
$id = $user->user_nickname;
}
if ( 'login' === $idmode ) {
$id = $user->user_login;
}
if ( 'firstname' === $idmode ) {
$id = $user->user_firstname;
}
if ( 'lastname' === $idmode ) {
$id = $user->user_lastname;
}
if ( 'namefl' === $idmode ) {
$id = $user->user_firstname . ' ' . $user->user_lastname;
}
if ( 'namelf' === $idmode ) {
$id = $user->user_lastname . ' ' . $user->user_firstname;
}
if ( ! $idmode ) {
$id = $user->user_nickname;
}
$wpdb->update( $wpdb->users, array( 'display_name' => $id ), array( 'ID' => $user->ID ) );
endif;
// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
$caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities' );
if ( empty( $caps ) || defined( 'RESET_CAPS' ) ) {
$level = get_user_meta( $user->ID, $wpdb->prefix . 'user_level', true );
$role = translate_level_to_role( $level );
update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array( $role => true ) );
}
endforeach;
$old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );
$wpdb->hide_errors();
foreach ( $old_user_fields as $old ) {
$wpdb->query( "ALTER TABLE $wpdb->users DROP $old" );
}
$wpdb->show_errors();
// Populate comment_count field of posts table.
$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
if ( is_array( $comments ) ) {
foreach ( $comments as $comment ) {
$wpdb->update( $wpdb->posts, array( 'comment_count' => $comment->c ), array( 'ID' => $comment->comment_post_ID ) );
}
}
/*
* Some alpha versions used a post status of object instead of attachment
* and put the mime type in post_type instead of post_mime_type.
*/
if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
$objects = $wpdb->get_results( "SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'" );
foreach ( $objects as $object ) {
$wpdb->update(
$wpdb->posts,
array(
'post_status' => 'attachment',
'post_mime_type' => $object->post_type,
'post_type' => '',
),
array( 'ID' => $object->ID )
);
$meta = get_post_meta( $object->ID, 'imagedata', true );
if ( ! empty( $meta['file'] ) ) {
update_attached_file( $object->ID, $meta['file'] );
}
}
}
}
/**
* Execute changes made in WordPress 2.1.
*
* @ignore
* @since 2.1.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_210() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 3506 ) {
// Update status and type.
$posts = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" );
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
$status = $post->post_status;
$type = 'post';
if ( 'static' === $status ) {
$status = 'publish';
$type = 'page';
} elseif ( 'attachment' === $status ) {
$status = 'inherit';
$type = 'attachment';
}
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID ) );
}
}
}
if ( $wp_current_db_version < 3845 ) {
populate_roles_210();
}
if ( $wp_current_db_version < 3531 ) {
// Give future posts a post_status of future.
$now = gmdate( 'Y-m-d H:i:59' );
$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'" );
$posts = $wpdb->get_results( "SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'" );
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
wp_schedule_single_event( mysql2date( 'U', $post->post_date, false ), 'publish_future_post', array( $post->ID ) );
}
}
}
}
/**
* Execute changes made in WordPress 2.3.
*
* @ignore
* @since 2.3.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_230() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 5200 ) {
populate_roles_230();
}
// Convert categories to terms.
$tt_ids = array();
$have_tags = false;
$categories = $wpdb->get_results( "SELECT * FROM $wpdb->categories ORDER BY cat_ID" );
foreach ( $categories as $category ) {
$term_id = (int) $category->cat_ID;
$name = $category->cat_name;
$description = $category->category_description;
$slug = $category->category_nicename;
$parent = $category->category_parent;
$term_group = 0;
// Associate terms with the same slug in a term group and make slugs unique.
$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
if ( $exists ) {
$term_group = $exists[0]->term_group;
$id = $exists[0]->term_id;
$num = 2;
do {
$alt_slug = $slug . "-$num";
++$num;
$slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
} while ( $slug_check );
$slug = $alt_slug;
if ( empty( $term_group ) ) {
$term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group" ) + 1;
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id ) );
}
}
$wpdb->query(
$wpdb->prepare(
"INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES
(%d, %s, %s, %d)",
$term_id,
$name,
$slug,
$term_group
)
);
$count = 0;
if ( ! empty( $category->category_count ) ) {
$count = (int) $category->category_count;
$taxonomy = 'category';
$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
}
if ( ! empty( $category->link_count ) ) {
$count = (int) $category->link_count;
$taxonomy = 'link_category';
$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
}
if ( ! empty( $category->tag_count ) ) {
$have_tags = true;
$count = (int) $category->tag_count;
$taxonomy = 'post_tag';
$wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
}
if ( empty( $count ) ) {
$count = 0;
$taxonomy = 'category';
$wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
}
}
$select = 'post_id, category_id';
if ( $have_tags ) {
$select .= ', rel_type';
}
$posts = $wpdb->get_results( "SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id" );
foreach ( $posts as $post ) {
$post_id = (int) $post->post_id;
$term_id = (int) $post->category_id;
$taxonomy = 'category';
if ( ! empty( $post->rel_type ) && 'tag' === $post->rel_type ) {
$taxonomy = 'tag';
}
$tt_id = $tt_ids[ $term_id ][ $taxonomy ];
if ( empty( $tt_id ) ) {
continue;
}
$wpdb->insert(
$wpdb->term_relationships,
array(
'object_id' => $post_id,
'term_taxonomy_id' => $tt_id,
)
);
}
// < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
if ( $wp_current_db_version < 3570 ) {
/*
* Create link_category terms for link categories. Create a map of link
* category IDs to link_category terms.
*/
$link_cat_id_map = array();
$default_link_cat = 0;
$tt_ids = array();
$link_cats = $wpdb->get_results( 'SELECT cat_id, cat_name FROM ' . $wpdb->prefix . 'linkcategories' );
foreach ( $link_cats as $category ) {
$cat_id = (int) $category->cat_id;
$term_id = 0;
$name = wp_slash( $category->cat_name );
$slug = sanitize_title( $name );
$term_group = 0;
// Associate terms with the same slug in a term group and make slugs unique.
$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
if ( $exists ) {
$term_group = $exists[0]->term_group;
$term_id = $exists[0]->term_id;
}
if ( empty( $term_id ) ) {
$wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) );
$term_id = (int) $wpdb->insert_id;
}
$link_cat_id_map[ $cat_id ] = $term_id;
$default_link_cat = $term_id;
$wpdb->insert(
$wpdb->term_taxonomy,
array(
'term_id' => $term_id,
'taxonomy' => 'link_category',
'description' => '',
'parent' => 0,
'count' => 0,
)
);
$tt_ids[ $term_id ] = (int) $wpdb->insert_id;
}
// Associate links to categories.
$links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
if ( ! empty( $links ) ) {
foreach ( $links as $link ) {
if ( 0 === (int) $link->link_category ) {
continue;
}
if ( ! isset( $link_cat_id_map[ $link->link_category ] ) ) {
continue;
}
$term_id = $link_cat_id_map[ $link->link_category ];
$tt_id = $tt_ids[ $term_id ];
if ( empty( $tt_id ) ) {
continue;
}
$wpdb->insert(
$wpdb->term_relationships,
array(
'object_id' => $link->link_id,
'term_taxonomy_id' => $tt_id,
)
);
}
}
// Set default to the last category we grabbed during the upgrade loop.
update_option( 'default_link_category', $default_link_cat );
} else {
$links = $wpdb->get_results( "SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id" );
foreach ( $links as $link ) {
$link_id = (int) $link->link_id;
$term_id = (int) $link->category_id;
$taxonomy = 'link_category';
$tt_id = $tt_ids[ $term_id ][ $taxonomy ];
if ( empty( $tt_id ) ) {
continue;
}
$wpdb->insert(
$wpdb->term_relationships,
array(
'object_id' => $link_id,
'term_taxonomy_id' => $tt_id,
)
);
}
}
if ( $wp_current_db_version < 4772 ) {
// Obsolete linkcategories table.
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' );
}
// Recalculate all counts.
$terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" );
foreach ( (array) $terms as $term ) {
if ( 'post_tag' === $term->taxonomy || 'category' === $term->taxonomy ) {
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) );
} else {
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) );
}
$wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_taxonomy_id' => $term->term_taxonomy_id ) );
}
}
/**
* Remove old options from the database.
*
* @ignore
* @since 2.3.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_230_options_table() {
global $wpdb;
$old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
$wpdb->hide_errors();
foreach ( $old_options_fields as $old ) {
$wpdb->query( "ALTER TABLE $wpdb->options DROP $old" );
}
$wpdb->show_errors();
}
/**
* Remove old categories, link2cat, and post2cat database tables.
*
* @ignore
* @since 2.3.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_230_old_tables() {
global $wpdb;
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat' );
}
/**
* Upgrade old slugs made in version 2.2.
*
* @ignore
* @since 2.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_old_slugs() {
// Upgrade people who were using the Redirect Old Slugs plugin.
global $wpdb;
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'" );
}
/**
* Execute changes made in WordPress 2.5.0.
*
* @ignore
* @since 2.5.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_250() {
global $wp_current_db_version;
if ( $wp_current_db_version < 6689 ) {
populate_roles_250();
}
}
/**
* Execute changes made in WordPress 2.5.2.
*
* @ignore
* @since 2.5.2
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_252() {
global $wpdb;
$wpdb->query( "UPDATE $wpdb->users SET user_activation_key = ''" );
}
/**
* Execute changes made in WordPress 2.6.
*
* @ignore
* @since 2.6.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_260() {
global $wp_current_db_version;
if ( $wp_current_db_version < 8000 ) {
populate_roles_260();
}
}
/**
* Execute changes made in WordPress 2.7.
*
* @ignore
* @since 2.7.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_270() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 8980 ) {
populate_roles_270();
}
// Update post_date for unpublished posts with empty timestamp.
if ( $wp_current_db_version < 8921 ) {
$wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
}
}
/**
* Execute changes made in WordPress 2.8.
*
* @ignore
* @since 2.8.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_280() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 10360 ) {
populate_roles_280();
}
if ( is_multisite() ) {
$start = 0;
while ( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
foreach ( $rows as $row ) {
$value = maybe_unserialize( $row->option_value );
if ( $value === $row->option_value ) {
$value = stripslashes( $value );
}
if ( $value !== $row->option_value ) {
update_option( $row->option_name, $value );
}
}
$start += 20;
}
clean_blog_cache( get_current_blog_id() );
}
}
/**
* Execute changes made in WordPress 2.9.
*
* @ignore
* @since 2.9.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_290() {
global $wp_current_db_version;
if ( $wp_current_db_version < 11958 ) {
/*
* Previously, setting depth to 1 would redundantly disable threading,
* but now 2 is the minimum depth to avoid confusion.
*/
if ( 1 === (int) get_option( 'thread_comments_depth' ) ) {
update_option( 'thread_comments_depth', 2 );
update_option( 'thread_comments', 0 );
}
}
}
/**
* Execute changes made in WordPress 3.0.
*
* @ignore
* @since 3.0.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_300() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 15093 ) {
populate_roles_300();
}
if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) {
add_site_option( 'siteurl', '' );
}
// 3.0 screen options key name changes.
if ( wp_should_upgrade_global_tables() ) {
$sql = "DELETE FROM $wpdb->usermeta
WHERE meta_key LIKE %s
OR meta_key LIKE %s
OR meta_key LIKE %s
OR meta_key LIKE %s
OR meta_key LIKE %s
OR meta_key LIKE %s
OR meta_key = 'manageedittagscolumnshidden'
OR meta_key = 'managecategoriescolumnshidden'
OR meta_key = 'manageedit-tagscolumnshidden'
OR meta_key = 'manageeditcolumnshidden'
OR meta_key = 'categories_per_page'
OR meta_key = 'edit_tags_per_page'";
$prefix = $wpdb->esc_like( $wpdb->base_prefix );
$wpdb->query(
$wpdb->prepare(
$sql,
$prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'manage-' ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'meta-box-order' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'metaboxorder' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'screen_layout' ) . '%'
)
);
}
}
/**
* Execute changes made in WordPress 3.3.
*
* @ignore
* @since 3.3.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
* @global array $wp_registered_widgets
* @global array $sidebars_widgets
*/
function upgrade_330() {
global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) {
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" );
}
if ( $wp_current_db_version >= 11548 ) {
return;
}
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
$_sidebars_widgets = array();
if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) || empty( $sidebars_widgets ) ) {
$sidebars_widgets['array_version'] = 3;
} elseif ( ! isset( $sidebars_widgets['array_version'] ) ) {
$sidebars_widgets['array_version'] = 1;
}
switch ( $sidebars_widgets['array_version'] ) {
case 1:
foreach ( (array) $sidebars_widgets as $index => $sidebar ) {
if ( is_array( $sidebar ) ) {
foreach ( (array) $sidebar as $i => $name ) {
$id = strtolower( $name );
if ( isset( $wp_registered_widgets[ $id ] ) ) {
$_sidebars_widgets[ $index ][ $i ] = $id;
continue;
}
$id = sanitize_title( $name );
if ( isset( $wp_registered_widgets[ $id ] ) ) {
$_sidebars_widgets[ $index ][ $i ] = $id;
continue;
}
$found = false;
foreach ( $wp_registered_widgets as $widget_id => $widget ) {
if ( strtolower( $widget['name'] ) === strtolower( $name ) ) {
$_sidebars_widgets[ $index ][ $i ] = $widget['id'];
$found = true;
break;
} elseif ( sanitize_title( $widget['name'] ) === sanitize_title( $name ) ) {
$_sidebars_widgets[ $index ][ $i ] = $widget['id'];
$found = true;
break;
}
}
if ( $found ) {
continue;
}
unset( $_sidebars_widgets[ $index ][ $i ] );
}
}
}
$_sidebars_widgets['array_version'] = 2;
$sidebars_widgets = $_sidebars_widgets;
unset( $_sidebars_widgets );
// Intentional fall-through to upgrade to the next version.
case 2:
$sidebars_widgets = retrieve_widgets();
$sidebars_widgets['array_version'] = 3;
update_option( 'sidebars_widgets', $sidebars_widgets );
}
}
/**
* Execute changes made in WordPress 3.4.
*
* @ignore
* @since 3.4.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_340() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 19798 ) {
$wpdb->hide_errors();
$wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
$wpdb->show_errors();
}
if ( $wp_current_db_version < 19799 ) {
$wpdb->hide_errors();
$wpdb->query( "ALTER TABLE $wpdb->comments DROP INDEX comment_approved" );
$wpdb->show_errors();
}
if ( $wp_current_db_version < 20022 && wp_should_upgrade_global_tables() ) {
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" );
}
if ( $wp_current_db_version < 20080 ) {
if ( 'yes' === $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
$uninstall_plugins = get_option( 'uninstall_plugins' );
delete_option( 'uninstall_plugins' );
add_option( 'uninstall_plugins', $uninstall_plugins, null, false );
}
}
}
/**
* Execute changes made in WordPress 3.5.
*
* @ignore
* @since 3.5.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_350() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options().
}
if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) {
$meta_keys = array();
foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) {
if ( str_contains( $name, '-' ) ) {
$meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page';
}
}
if ( $meta_keys ) {
$meta_keys = implode( "', '", $meta_keys );
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" );
}
}
if ( $wp_current_db_version < 22422 ) {
$term = get_term_by( 'slug', 'post-format-standard', 'post_format' );
if ( $term ) {
wp_delete_term( $term->term_id, 'post_format' );
}
}
}
/**
* Execute changes made in WordPress 3.7.
*
* @ignore
* @since 3.7.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_370() {
global $wp_current_db_version;
if ( $wp_current_db_version < 25824 ) {
wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' );
}
}
/**
* Execute changes made in WordPress 3.7.2.
*
* @ignore
* @since 3.7.2
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_372() {
global $wp_current_db_version;
if ( $wp_current_db_version < 26148 ) {
wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
}
}
/**
* Execute changes made in WordPress 3.8.0.
*
* @ignore
* @since 3.8.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_380() {
global $wp_current_db_version;
if ( $wp_current_db_version < 26691 ) {
deactivate_plugins( array( 'mp6/mp6.php' ), true );
}
}
/**
* Execute changes made in WordPress 4.0.0.
*
* @ignore
* @since 4.0.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_400() {
global $wp_current_db_version;
if ( $wp_current_db_version < 29630 ) {
if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages(), true ) ) {
update_option( 'WPLANG', WPLANG );
} else {
update_option( 'WPLANG', '' );
}
}
}
}
/**
* Execute changes made in WordPress 4.2.0.
*
* @ignore
* @since 4.2.0
*/
function upgrade_420() {}
/**
* Executes changes made in WordPress 4.3.0.
*
* @ignore
* @since 4.3.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_430() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 32364 ) {
upgrade_430_fix_comments();
}
// Shared terms are split in a separate process.
if ( $wp_current_db_version < 32814 ) {
update_option( 'finished_splitting_shared_terms', 0 );
wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
}
if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
if ( is_multisite() ) {
$tables = $wpdb->tables( 'blog' );
} else {
$tables = $wpdb->tables( 'all' );
if ( ! wp_should_upgrade_global_tables() ) {
$global_tables = $wpdb->tables( 'global' );
$tables = array_diff_assoc( $tables, $global_tables );
}
}
foreach ( $tables as $table ) {
maybe_convert_table_to_utf8mb4( $table );
}
}
}
/**
* Executes comments changes made in WordPress 4.3.0.
*
* @ignore
* @since 4.3.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_430_fix_comments() {
global $wpdb;
$content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
if ( is_wp_error( $content_length ) ) {
return;
}
if ( false === $content_length ) {
$content_length = array(
'type' => 'byte',
'length' => 65535,
);
} elseif ( ! is_array( $content_length ) ) {
$length = (int) $content_length > 0 ? (int) $content_length : 65535;
$content_length = array(
'type' => 'byte',
'length' => $length,
);
}
if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
// Sites with malformed DB schemas are on their own.
return;
}
$allowed_length = (int) $content_length['length'] - 10;
$comments = $wpdb->get_results(
"SELECT `comment_ID` FROM `{$wpdb->comments}`
WHERE `comment_date_gmt` > '2015-04-26'
AND LENGTH( `comment_content` ) >= {$allowed_length}
AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )"
);
foreach ( $comments as $comment ) {
wp_delete_comment( $comment->comment_ID, true );
}
}
/**
* Executes changes made in WordPress 4.3.1.
*
* @ignore
* @since 4.3.1
*/
function upgrade_431() {
// Fix incorrect cron entries for term splitting.
$cron_array = _get_cron_array();
if ( isset( $cron_array['wp_batch_split_terms'] ) ) {
unset( $cron_array['wp_batch_split_terms'] );
_set_cron_array( $cron_array );
}
}
/**
* Executes changes made in WordPress 4.4.0.
*
* @ignore
* @since 4.4.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_440() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 34030 ) {
$wpdb->query( "ALTER TABLE {$wpdb->options} MODIFY option_name VARCHAR(191)" );
}
// Remove the unused 'add_users' role.
$roles = wp_roles();
foreach ( $roles->role_objects as $role ) {
if ( $role->has_cap( 'add_users' ) ) {
$role->remove_cap( 'add_users' );
}
}
}
/**
* Executes changes made in WordPress 4.5.0.
*
* @ignore
* @since 4.5.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_450() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 36180 ) {
wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
}
// Remove unused email confirmation options, moved to usermeta.
if ( $wp_current_db_version < 36679 && is_multisite() ) {
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^[0-9]+_new_email$'" );
}
// Remove unused user setting for wpLink.
delete_user_setting( 'wplink' );
}
/**
* Executes changes made in WordPress 4.6.0.
*
* @ignore
* @since 4.6.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_460() {
global $wp_current_db_version;
// Remove unused post meta.
if ( $wp_current_db_version < 37854 ) {
delete_post_meta_by_key( '_post_restored_from' );
}
// Remove plugins with callback as an array object/method as the uninstall hook, see #13786.
if ( $wp_current_db_version < 37965 ) {
$uninstall_plugins = get_option( 'uninstall_plugins', array() );
if ( ! empty( $uninstall_plugins ) ) {
foreach ( $uninstall_plugins as $basename => $callback ) {
if ( is_array( $callback ) && is_object( $callback[0] ) ) {
unset( $uninstall_plugins[ $basename ] );
}
}
update_option( 'uninstall_plugins', $uninstall_plugins );
}
}
}
/**
* Executes changes made in WordPress 5.0.0.
*
* @ignore
* @since 5.0.0
* @deprecated 5.1.0
*/
function upgrade_500() {
}
/**
* Executes changes made in WordPress 5.1.0.
*
* @ignore
* @since 5.1.0
*/
function upgrade_510() {
delete_site_option( 'upgrade_500_was_gutenberg_active' );
}
/**
* Executes changes made in WordPress 5.3.0.
*
* @ignore
* @since 5.3.0
*/
function upgrade_530() {
/*
* The `admin_email_lifespan` option may have been set by an admin that just logged in,
* saw the verification screen, clicked on a button there, and is now upgrading the db,
* or by populate_options() that is called earlier in upgrade_all().
* In the second case `admin_email_lifespan` should be reset so the verification screen
* is shown next time an admin logs in.
*/
if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) {
update_option( 'admin_email_lifespan', 0 );
}
}
/**
* Executes changes made in WordPress 5.5.0.
*
* @ignore
* @since 5.5.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_550() {
global $wp_current_db_version;
if ( $wp_current_db_version < 48121 ) {
$comment_previously_approved = get_option( 'comment_whitelist', '' );
update_option( 'comment_previously_approved', $comment_previously_approved );
delete_option( 'comment_whitelist' );
}
if ( $wp_current_db_version < 48575 ) {
// Use more clear and inclusive language.
$disallowed_list = get_option( 'blacklist_keys' );
/*
* This option key was briefly renamed `blocklist_keys`.
* Account for sites that have this key present when the original key does not exist.
*/
if ( false === $disallowed_list ) {
$disallowed_list = get_option( 'blocklist_keys' );
}
update_option( 'disallowed_keys', $disallowed_list );
delete_option( 'blacklist_keys' );
delete_option( 'blocklist_keys' );
}
if ( $wp_current_db_version < 48748 ) {
update_option( 'finished_updating_comment_type', 0 );
wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
}
}
/**
* Executes changes made in WordPress 5.6.0.
*
* @ignore
* @since 5.6.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_560() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 49572 ) {
/*
* Clean up the `post_category` column removed from schema in version 2.8.0.
* Its presence may conflict with `WP_Post::__get()`.
*/
$post_category_exists = $wpdb->get_var( "SHOW COLUMNS FROM $wpdb->posts LIKE 'post_category'" );
if ( ! is_null( $post_category_exists ) ) {
$wpdb->query( "ALTER TABLE $wpdb->posts DROP COLUMN `post_category`" );
}
/*
* When upgrading from WP < 5.6.0 set the core major auto-updates option to `unset` by default.
* This overrides the same option from populate_options() that is intended for new installs.
* See https://core.trac.wordpress.org/ticket/51742.
*/
update_option( 'auto_update_core_major', 'unset' );
}
if ( $wp_current_db_version < 49632 ) {
/*
* Regenerate the .htaccess file to add the `HTTP_AUTHORIZATION` rewrite rule.
* See https://core.trac.wordpress.org/ticket/51723.
*/
save_mod_rewrite_rules();
}
if ( $wp_current_db_version < 49735 ) {
delete_transient( 'dirsize_cache' );
}
if ( $wp_current_db_version < 49752 ) {
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT 1 FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT 1",
WP_Application_Passwords::USERMETA_KEY_APPLICATION_PASSWORDS
)
);
if ( ! empty( $results ) ) {
$network_id = get_main_network_id();
update_network_option( $network_id, WP_Application_Passwords::OPTION_KEY_IN_USE, 1 );
}
}
}
/**
* Executes changes made in WordPress 5.9.0.
*
* @ignore
* @since 5.9.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_590() {
global $wp_current_db_version;
if ( $wp_current_db_version < 51917 ) {
$crons = _get_cron_array();
if ( $crons && is_array( $crons ) ) {
// Remove errant `false` values, see #53950, #54906.
$crons = array_filter( $crons );
_set_cron_array( $crons );
}
}
}
/**
* Executes changes made in WordPress 6.0.0.
*
* @ignore
* @since 6.0.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_600() {
global $wp_current_db_version;
if ( $wp_current_db_version < 53011 ) {
wp_update_user_counts();
}
}
/**
* Executes changes made in WordPress 6.3.0.
*
* @ignore
* @since 6.3.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_630() {
global $wp_current_db_version;
if ( $wp_current_db_version < 55853 ) {
if ( ! is_multisite() ) {
// Replace non-autoload option can_compress_scripts with autoload option, see #55270
$can_compress_scripts = get_option( 'can_compress_scripts', false );
if ( false !== $can_compress_scripts ) {
delete_option( 'can_compress_scripts' );
add_option( 'can_compress_scripts', $can_compress_scripts, '', true );
}
}
}
}
/**
* Executes changes made in WordPress 6.4.0.
*
* @ignore
* @since 6.4.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_640() {
global $wp_current_db_version;
if ( $wp_current_db_version < 56657 ) {
// Enable attachment pages.
update_option( 'wp_attachment_pages_enabled', 1 );
// Remove the wp_https_detection cron. Https status is checked directly in an async Site Health check.
$scheduled = wp_get_scheduled_event( 'wp_https_detection' );
if ( $scheduled ) {
wp_clear_scheduled_hook( 'wp_https_detection' );
}
}
}
/**
* Executes changes made in WordPress 6.5.0.
*
* @ignore
* @since 6.5.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_650() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 57155 ) {
$stylesheet = get_stylesheet();
// Set autoload=no for all themes except the current one.
$theme_mods_options = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM $wpdb->options WHERE autoload = 'yes' AND option_name != %s AND option_name LIKE %s",
"theme_mods_$stylesheet",
$wpdb->esc_like( 'theme_mods_' ) . '%'
)
);
$autoload = array_fill_keys( $theme_mods_options, false );
wp_set_option_autoload_values( $autoload );
}
}
/**
* Executes changes made in WordPress 6.7.0.
*
* @ignore
* @since 6.7.0
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_670() {
global $wp_current_db_version;
if ( $wp_current_db_version < 58975 ) {
$options = array(
'recently_activated',
'_wp_suggested_policy_text_has_changed',
'dashboard_widget_options',
'ftp_credentials',
'adminhash',
'nav_menu_options',
'wp_force_deactivated_plugins',
'delete_blog_hash',
'allowedthemes',
'recovery_keys',
'https_detection_errors',
'fresh_site',
);
wp_set_options_autoload( $options, false );
}
}
/**
* Executes changes made in WordPress 6.8.2.
*
* @ignore
* @since 6.8.2
*
* @global int $wp_current_db_version The old (current) database version.
*/
function upgrade_682() {
global $wp_current_db_version;
if ( $wp_current_db_version < 60421 ) {
// Upgrade Ping-O-Matic and Twingly to use HTTPS.
$ping_sites_value = get_option( 'ping_sites' );
$ping_sites_value = explode( "\n", $ping_sites_value );
$ping_sites_value = array_map(
function ( $url ) {
$url = trim( $url );
$url = sanitize_url( $url );
if (
str_ends_with( trailingslashit( $url ), '://rpc.pingomatic.com/' )
|| str_ends_with( trailingslashit( $url ), '://rpc.twingly.com/' )
) {
$url = set_url_scheme( $url, 'https' );
}
return $url;
},
$ping_sites_value
);
$ping_sites_value = array_filter( $ping_sites_value );
$ping_sites_value = implode( "\n", $ping_sites_value );
update_option( 'ping_sites', $ping_sites_value );
}
}
/**
* Executes network-level upgrade routines.
*
* @since 3.0.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function upgrade_network() {
global $wp_current_db_version, $wpdb;
// Always clear expired transients.
delete_expired_transients( true );
// 2.8.0
if ( $wp_current_db_version < 11549 ) {
$wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' );
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
if ( $wpmu_sitewide_plugins ) {
if ( ! $active_sitewide_plugins ) {
$sitewide_plugins = (array) $wpmu_sitewide_plugins;
} else {
$sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins );
}
update_site_option( 'active_sitewide_plugins', $sitewide_plugins );
}
delete_site_option( 'wpmu_sitewide_plugins' );
delete_site_option( 'deactivated_sitewide_plugins' );
$start = 0;
while ( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) {
foreach ( $rows as $row ) {
$value = $row->meta_value;
if ( ! @unserialize( $value ) ) {
$value = stripslashes( $value );
}
if ( $value !== $row->meta_value ) {
update_site_option( $row->meta_key, $value );
}
}
$start += 20;
}
}
// 3.0.0
if ( $wp_current_db_version < 13576 ) {
update_site_option( 'global_terms_enabled', '1' );
}
// 3.3.0
if ( $wp_current_db_version < 19390 ) {
update_site_option( 'initial_db_version', $wp_current_db_version );
}
if ( $wp_current_db_version < 19470 ) {
if ( false === get_site_option( 'active_sitewide_plugins' ) ) {
update_site_option( 'active_sitewide_plugins', array() );
}
}
// 3.4.0
if ( $wp_current_db_version < 20148 ) {
// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
$allowedthemes = get_site_option( 'allowedthemes' );
$allowed_themes = get_site_option( 'allowed_themes' );
if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
$converted = array();
$themes = wp_get_themes();
foreach ( $themes as $stylesheet => $theme_data ) {
if ( isset( $allowed_themes[ $theme_data->get( 'Name' ) ] ) ) {
$converted[ $stylesheet ] = true;
}
}
update_site_option( 'allowedthemes', $converted );
delete_site_option( 'allowed_themes' );
}
}
// 3.5.0
if ( $wp_current_db_version < 21823 ) {
update_site_option( 'ms_files_rewriting', '1' );
}
// 3.5.2
if ( $wp_current_db_version < 24448 ) {
$illegal_names = get_site_option( 'illegal_names' );
if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) {
$illegal_name = reset( $illegal_names );
$illegal_names = explode( ' ', $illegal_name );
update_site_option( 'illegal_names', $illegal_names );
}
}
// 4.2.0
if ( $wp_current_db_version < 31351 && 'utf8mb4' === $wpdb->charset ) {
if ( wp_should_upgrade_global_tables() ) {
$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
$wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
$wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
$tables = $wpdb->tables( 'global' );
// sitecategories may not exist.
if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
unset( $tables['sitecategories'] );
}
foreach ( $tables as $table ) {
maybe_convert_table_to_utf8mb4( $table );
}
}
}
// 4.3.0
if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
if ( wp_should_upgrade_global_tables() ) {
$upgrade = false;
$indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
foreach ( $indexes as $index ) {
if ( 'domain_path' === $index->Key_name && 'domain' === $index->Column_name && '140' !== $index->Sub_part ) {
$upgrade = true;
break;
}
}
if ( $upgrade ) {
$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
}
$tables = $wpdb->tables( 'global' );
// sitecategories may not exist.
if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
unset( $tables['sitecategories'] );
}
foreach ( $tables as $table ) {
maybe_convert_table_to_utf8mb4( $table );
}
}
}
// 5.1.0
if ( $wp_current_db_version < 44467 ) {
$network_id = get_main_network_id();
delete_network_option( $network_id, 'site_meta_supported' );
is_site_meta_supported();
}
}
//
// General functions we use to actually do stuff.
//
/**
* Creates a table in the database, if it doesn't already exist.
*
* This method checks for an existing database table and creates a new one if it's not
* already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses
* to query all tables first and then run the SQL statement creating the table.
*
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $table_name Database table name.
* @param string $create_ddl SQL statement to create table.
* @return bool True on success or if the table already exists. False on failure.
*/
function maybe_create_table( $table_name, $create_ddl ) {
global $wpdb;
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
if ( $wpdb->get_var( $query ) === $table_name ) {
return true;
}
// Didn't find it, so try to create it.
$wpdb->query( $create_ddl );
// We cannot directly tell that whether this succeeded!
if ( $wpdb->get_var( $query ) === $table_name ) {
return true;
}
return false;
}
/**
* Drops a specified index from a table.
*
* @since 1.0.1
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $table Database table name.
* @param string $index Index name to drop.
* @return true True, when finished.
*/
function drop_index( $table, $index ) {
global $wpdb;
$wpdb->hide_errors();
$wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" );
// Now we need to take out all the extra ones we may have created.
for ( $i = 0; $i < 25; $i++ ) {
$wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" );
}
$wpdb->show_errors();
return true;
}
/**
* Adds an index to a specified table.
*
* @since 1.0.1
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $table Database table name.
* @param string $index Database table index column.
* @return true True, when done with execution.
*/
function add_clean_index( $table, $index ) {
global $wpdb;
drop_index( $table, $index );
$wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" );
return true;
}
/**
* Adds column to a database table, if it doesn't already exist.
*
* @since 1.3.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $table_name Database table name.
* @param string $column_name Table column name.
* @param string $create_ddl SQL statement to add column.
* @return bool True on success or if the column already exists. False on failure.
*/
function maybe_add_column( $table_name, $column_name, $create_ddl ) {
global $wpdb;
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
return true;
}
}
// Didn't find it, so try to create it.
$wpdb->query( $create_ddl );
// We cannot directly tell that whether this succeeded!
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
return true;
}
}
return false;
}
/**
* If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4.
*
* @since 4.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $table The table to convert.
* @return bool True if the table was converted, false if it wasn't.
*/
function maybe_convert_table_to_utf8mb4( $table ) {
global $wpdb;
$results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
if ( ! $results ) {
return false;
}
foreach ( $results as $column ) {
if ( $column->Collation ) {
list( $charset ) = explode( '_', $column->Collation );
$charset = strtolower( $charset );
if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
// Don't upgrade tables that have non-utf8 columns.
return false;
}
}
}
$table_details = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table'" );
if ( ! $table_details ) {
return false;
}
list( $table_charset ) = explode( '_', $table_details->Collation );
$table_charset = strtolower( $table_charset );
if ( 'utf8mb4' === $table_charset ) {
return true;
}
return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
}
/**
* Retrieve all options as it was for 1.2.
*
* @since 1.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return stdClass List of options.
*/
function get_alloptions_110() {
global $wpdb;
$all_options = new stdClass();
$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
if ( $options ) {
foreach ( $options as $option ) {
if ( 'siteurl' === $option->option_name || 'home' === $option->option_name || 'category_base' === $option->option_name ) {
$option->option_value = untrailingslashit( $option->option_value );
}
$all_options->{$option->option_name} = stripslashes( $option->option_value );
}
}
return $all_options;
}
/**
* Utility version of get_option that is private to installation/upgrade.
*
* @ignore
* @since 1.5.1
* @access private
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $setting Option name.
* @return mixed
*/
function __get_option( $setting ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
global $wpdb;
if ( 'home' === $setting && defined( 'WP_HOME' ) ) {
return untrailingslashit( WP_HOME );
}
if ( 'siteurl' === $setting && defined( 'WP_SITEURL' ) ) {
return untrailingslashit( WP_SITEURL );
}
$option = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) );
if ( 'home' === $setting && ! $option ) {
return __get_option( 'siteurl' );
}
if ( in_array( $setting, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
$option = untrailingslashit( $option );
}
return maybe_unserialize( $option );
}
/**
* Filters for content to remove unnecessary slashes.
*
* @since 1.5.0
*
* @param string $content The content to modify.
* @return string The de-slashed content.
*/
function deslash( $content ) {
// Note: \\\ inside a regex denotes a single backslash.
/*
* Replace one or more backslashes followed by a single quote with
* a single quote.
*/
$content = preg_replace( "/\\\+'/", "'", $content );
/*
* Replace one or more backslashes followed by a double quote with
* a double quote.
*/
$content = preg_replace( '/\\\+"/', '"', $content );
// Replace one or more backslashes with one backslash.
$content = preg_replace( '/\\\+/', '\\', $content );
return $content;
}
/**
* Modifies the database based on specified SQL statements.
*
* Useful for creating new tables and updating existing tables to a new structure.
*
* @since 1.5.0
* @since 6.1.0 Ignores display width for integer data types on MySQL 8.0.17 or later,
* to match MySQL behavior. Note: This does not affect MariaDB.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string[]|string $queries Optional. The query to run. Can be multiple queries
* in an array, or a string of queries separated by
* semicolons. Default empty string.
* @param bool $execute Optional. Whether or not to execute the query right away.
* Default true.
* @return string[] Strings containing the results of the various update queries.
*/
function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
global $wpdb;
if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) {
$queries = wp_get_db_schema( $queries );
}
// Separate individual queries into an array.
if ( ! is_array( $queries ) ) {
$queries = explode( ';', $queries );
$queries = array_filter( $queries );
}
/**
* Filters the dbDelta SQL queries.
*
* @since 3.3.0
*
* @param string[] $queries An array of dbDelta SQL queries.
*/
$queries = apply_filters( 'dbdelta_queries', $queries );
$cqueries = array(); // Creation queries.
$iqueries = array(); // Insertion queries.
$for_update = array();
// Create a tablename index for an array ($cqueries) of recognized query types.
foreach ( $queries as $qry ) {
if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
$table_name = trim( $matches[1], '`' );
$cqueries[ $table_name ] = $qry;
$for_update[ $table_name ] = 'Created table ' . $matches[1];
continue;
}
if ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) {
array_unshift( $cqueries, $qry );
continue;
}
if ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) {
$iqueries[] = $qry;
continue;
}
if ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
$iqueries[] = $qry;
continue;
}
}
/**
* Filters the dbDelta SQL queries for creating tables and/or databases.
*
* Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
*
* @since 3.3.0
*
* @param string[] $cqueries An array of dbDelta create SQL queries.
*/
$cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
/**
* Filters the dbDelta SQL queries for inserting or updating.
*
* Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
*
* @since 3.3.0
*
* @param string[] $iqueries An array of dbDelta insert or update SQL queries.
*/
$iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
$text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
$blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
$int_fields = array( 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint' );
$global_tables = $wpdb->tables( 'global' );
$db_version = $wpdb->db_version();
$db_server_info = $wpdb->db_server_info();
foreach ( $cqueries as $table => $qry ) {
// Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) {
unset( $cqueries[ $table ], $for_update[ $table ] );
continue;
}
// Fetch the table column structure from the database.
$suppress = $wpdb->suppress_errors();
$tablefields = $wpdb->get_results( "DESCRIBE {$table};" );
$wpdb->suppress_errors( $suppress );
if ( ! $tablefields ) {
continue;
}
// Clear the field and index arrays.
$cfields = array();
$indices = array();
$indices_without_subparts = array();
// Get all of the field names in the query from between the parentheses.
preg_match( '|\((.*)\)|ms', $qry, $match2 );
$qryline = trim( $match2[1] );
// Separate field lines into an array.
$flds = explode( "\n", $qryline );
// For every field line specified in the query.
foreach ( $flds as $fld ) {
$fld = trim( $fld, " \t\n\r\0\x0B," ); // Default trim characters, plus ','.
// Extract the field name.
preg_match( '|^([^ ]*)|', $fld, $fvals );
$fieldname = trim( $fvals[1], '`' );
$fieldname_lowercased = strtolower( $fieldname );
// Verify the found field name.
$validfield = true;
switch ( $fieldname_lowercased ) {
case '':
case 'primary':
case 'index':
case 'fulltext':
case 'unique':
case 'key':
case 'spatial':
$validfield = false;
/*
* Normalize the index definition.
*
* This is done so the definition can be compared against the result of a
* `SHOW INDEX FROM $table_name` query which returns the current table
* index information.
*/
// Extract type, name and columns from the definition.
preg_match(
'/^
(?P<index_type> # 1) Type of the index.
PRIMARY\s+KEY|(?:UNIQUE|FULLTEXT|SPATIAL)\s+(?:KEY|INDEX)|KEY|INDEX
)
\s+ # Followed by at least one white space character.
(?: # Name of the index. Optional if type is PRIMARY KEY.
`? # Name can be escaped with a backtick.
(?P<index_name> # 2) Name of the index.
(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+
)
`? # Name can be escaped with a backtick.
\s+ # Followed by at least one white space character.
)*
\( # Opening bracket for the columns.
(?P<index_columns>
.+? # 3) Column names, index prefixes, and orders.
)
\) # Closing bracket for the columns.
$/imx',
$fld,
$index_matches
);
// Uppercase the index type and normalize space characters.
$index_type = strtoupper( preg_replace( '/\s+/', ' ', trim( $index_matches['index_type'] ) ) );
// 'INDEX' is a synonym for 'KEY', standardize on 'KEY'.
$index_type = str_replace( 'INDEX', 'KEY', $index_type );
// Escape the index name with backticks. An index for a primary key has no name.
$index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`';
// Parse the columns. Multiple columns are separated by a comma.
$index_columns = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );
$index_columns_without_subparts = $index_columns;
// Normalize columns.
foreach ( $index_columns as $id => &$index_column ) {
// Extract column name and number of indexed characters (sub_part).
preg_match(
'/
`? # Name can be escaped with a backtick.
(?P<column_name> # 1) Name of the column.
(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+
)
`? # Name can be escaped with a backtick.
(?: # Optional sub part.
\s* # Optional white space character between name and opening bracket.
\( # Opening bracket for the sub part.
\s* # Optional white space character after opening bracket.
(?P<sub_part>
\d+ # 2) Number of indexed characters.
)
\s* # Optional white space character before closing bracket.
\) # Closing bracket for the sub part.
)?
/x',
$index_column,
$index_column_matches
);
// Escape the column name with backticks.
$index_column = '`' . $index_column_matches['column_name'] . '`';
// We don't need to add the subpart to $index_columns_without_subparts
$index_columns_without_subparts[ $id ] = $index_column;
// Append the optional sup part with the number of indexed characters.
if ( isset( $index_column_matches['sub_part'] ) ) {
$index_column .= '(' . $index_column_matches['sub_part'] . ')';
}
}
// Build the normalized index definition and add it to the list of indices.
$indices[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns ) . ')';
$indices_without_subparts[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns_without_subparts ) . ')';
// Destroy no longer needed variables.
unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns, $index_columns_without_subparts );
break;
}
// If it's a valid field, add it to the field array.
if ( $validfield ) {
$cfields[ $fieldname_lowercased ] = $fld;
}
}
// For every field in the table.
foreach ( $tablefields as $tablefield ) {
$tablefield_field_lowercased = strtolower( $tablefield->Field );
$tablefield_type_lowercased = strtolower( $tablefield->Type );
$tablefield_type_without_parentheses = preg_replace(
'/'
. '(.+)' // Field type, e.g. `int`.
. '\(\d*\)' // Display width.
. '(.*)' // Optional attributes, e.g. `unsigned`.
. '/',
'$1$2',
$tablefield_type_lowercased
);
// Get the type without attributes, e.g. `int`.
$tablefield_type_base = strtok( $tablefield_type_without_parentheses, ' ' );
// If the table field exists in the field array...
if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
// Get the field type from the query.
preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
$fieldtype = $matches[1];
$fieldtype_lowercased = strtolower( $fieldtype );
$fieldtype_without_parentheses = preg_replace(
'/'
. '(.+)' // Field type, e.g. `int`.
. '\(\d*\)' // Display width.
. '(.*)' // Optional attributes, e.g. `unsigned`.
. '/',
'$1$2',
$fieldtype_lowercased
);
// Get the type without attributes, e.g. `int`.
$fieldtype_base = strtok( $fieldtype_without_parentheses, ' ' );
// Is actual field type different from the field type in query?
if ( $tablefield->Type !== $fieldtype_lowercased ) {
$do_change = true;
if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
$do_change = false;
}
}
if ( in_array( $fieldtype_lowercased, $blob_fields, true ) && in_array( $tablefield_type_lowercased, $blob_fields, true ) ) {
if ( array_search( $fieldtype_lowercased, $blob_fields, true ) < array_search( $tablefield_type_lowercased, $blob_fields, true ) ) {
$do_change = false;
}
}
if ( in_array( $fieldtype_base, $int_fields, true ) && in_array( $tablefield_type_base, $int_fields, true )
&& $fieldtype_without_parentheses === $tablefield_type_without_parentheses
) {
/*
* MySQL 8.0.17 or later does not support display width for integer data types,
* so if display width is the only difference, it can be safely ignored.
* Note: This is specific to MySQL and does not affect MariaDB.
*/
if ( version_compare( $db_version, '8.0.17', '>=' )
&& ! str_contains( $db_server_info, 'MariaDB' )
) {
$do_change = false;
}
}
if ( $do_change ) {
// Add a query to change the column type.
$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
$for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
}
}
// Get the default value from the array.
if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
$default_value = $matches[1];
if ( $tablefield->Default !== $default_value ) {
// Add a query to change the column's default value
$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
$for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
}
}
// Remove the field from the array (so it's not added).
unset( $cfields[ $tablefield_field_lowercased ] );
} else {
// This field exists in the table, but not in the creation queries?
}
}
// For every remaining field specified for the table.
foreach ( $cfields as $fieldname => $fielddef ) {
// Push a query line into $cqueries that adds the field to that table.
$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
$for_update[ $table . '.' . $fieldname ] = 'Added column ' . $table . '.' . $fieldname;
}
// Index stuff goes here. Fetch the table index structure from the database.
$tableindices = $wpdb->get_results( "SHOW INDEX FROM {$table};" );
if ( $tableindices ) {
// Clear the index array.
$index_ary = array();
// For every index in the table.
foreach ( $tableindices as $tableindex ) {
$keyname = strtolower( $tableindex->Key_name );
// Add the index to the index data array.
$index_ary[ $keyname ]['columns'][] = array(
'fieldname' => $tableindex->Column_name,
'subpart' => $tableindex->Sub_part,
);
$index_ary[ $keyname ]['unique'] = ( '0' === (string) $tableindex->Non_unique ) ? true : false;
$index_ary[ $keyname ]['index_type'] = $tableindex->Index_type;
}
// For each actual index in the index array.
foreach ( $index_ary as $index_name => $index_data ) {
// Build a create string to compare to the query.
$index_string = '';
if ( 'primary' === $index_name ) {
$index_string .= 'PRIMARY ';
} elseif ( $index_data['unique'] ) {
$index_string .= 'UNIQUE ';
}
if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) {
$index_string .= 'FULLTEXT ';
}
if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) {
$index_string .= 'SPATIAL ';
}
$index_string .= 'KEY ';
if ( 'primary' !== $index_name ) {
$index_string .= '`' . $index_name . '`';
}
$index_columns = '';
// For each column in the index.
foreach ( $index_data['columns'] as $column_data ) {
if ( '' !== $index_columns ) {
$index_columns .= ',';
}
// Add the field to the column list string.
$index_columns .= '`' . $column_data['fieldname'] . '`';
}
// Add the column list to the index create string.
$index_string .= " ($index_columns)";
// Check if the index definition exists, ignoring subparts.
$aindex = array_search( $index_string, $indices_without_subparts, true );
if ( false !== $aindex ) {
// If the index already exists (even with different subparts), we don't need to create it.
unset( $indices_without_subparts[ $aindex ] );
unset( $indices[ $aindex ] );
}
}
}
// For every remaining index specified for the table.
foreach ( (array) $indices as $index ) {
// Push a query line into $cqueries that adds the index to that table.
$cqueries[] = "ALTER TABLE {$table} ADD $index";
$for_update[] = 'Added index ' . $table . ' ' . $index;
}
// Remove the original table creation query from processing.
unset( $cqueries[ $table ], $for_update[ $table ] );
}
$allqueries = array_merge( $cqueries, $iqueries );
if ( $execute ) {
foreach ( $allqueries as $query ) {
$wpdb->query( $query );
}
}
return $for_update;
}
/**
* Updates the database tables to a new schema.
*
* By default, updates all the tables to use the latest defined schema, but can also
* be used to update a specific set of tables in wp_get_db_schema().
*
* @since 1.5.0
*
* @uses dbDelta
*
* @param string $tables Optional. Which set of tables to update. Default is 'all'.
*/
function make_db_current( $tables = 'all' ) {
$alterations = dbDelta( $tables );
echo "<ol>\n";
foreach ( $alterations as $alteration ) {
echo "<li>$alteration</li>\n";
}
echo "</ol>\n";
}
/**
* Updates the database tables to a new schema, but without displaying results.
*
* By default, updates all the tables to use the latest defined schema, but can
* also be used to update a specific set of tables in wp_get_db_schema().
*
* @since 1.5.0
*
* @see make_db_current()
*
* @param string $tables Optional. Which set of tables to update. Default is 'all'.
*/
function make_db_current_silent( $tables = 'all' ) {
dbDelta( $tables );
}
/**
* Creates a site theme from an existing theme.
*
* {@internal Missing Long Description}}
*
* @since 1.5.0
*
* @param string $theme_name The name of the theme.
* @param string $template The directory name of the theme.
* @return bool
*/
function make_site_theme_from_oldschool( $theme_name, $template ) {
$home_path = get_home_path();
$site_dir = WP_CONTENT_DIR . "/themes/$template";
$default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
if ( ! file_exists( "$home_path/index.php" ) ) {
return false;
}
/*
* Copy files from the old locations to the site theme.
* TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
*/
$files = array(
'index.php' => 'index.php',
'wp-layout.css' => 'style.css',
'wp-comments.php' => 'comments.php',
'wp-comments-popup.php' => 'comments-popup.php',
);
foreach ( $files as $oldfile => $newfile ) {
if ( 'index.php' === $oldfile ) {
$oldpath = $home_path;
} else {
$oldpath = ABSPATH;
}
// Check to make sure it's not a new index.
if ( 'index.php' === $oldfile ) {
$index = implode( '', file( "$oldpath/$oldfile" ) );
if ( str_contains( $index, 'WP_USE_THEMES' ) ) {
if ( ! copy( "$default_dir/$oldfile", "$site_dir/$newfile" ) ) {
return false;
}
// Don't copy anything.
continue;
}
}
if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
return false;
}
chmod( "$site_dir/$newfile", 0777 );
// Update the blog header include in each file.
$lines = explode( "\n", implode( '', file( "$site_dir/$newfile" ) ) );
if ( $lines ) {
$f = fopen( "$site_dir/$newfile", 'w' );
foreach ( $lines as $line ) {
if ( preg_match( '/require.*wp-blog-header/', $line ) ) {
$line = '//' . $line;
}
// Update stylesheet references.
$line = str_replace(
"<?php echo __get_option('siteurl'); ?>/wp-layout.css",
"<?php bloginfo('stylesheet_url'); ?>",
$line
);
// Update comments template inclusion.
$line = str_replace(
"<?php include(ABSPATH . 'wp-comments.php'); ?>",
'<?php comments_template(); ?>',
$line
);
fwrite( $f, "{$line}\n" );
}
fclose( $f );
}
}
// Add a theme header.
$header = "/*\n" .
"Theme Name: $theme_name\n" .
'Theme URI: ' . __get_option( 'siteurl' ) . "\n" .
"Description: A theme automatically created by the update.\n" .
"Version: 1.0\n" .
"Author: Moi\n" .
"*/\n";
$stylelines = file_get_contents( "$site_dir/style.css" );
if ( $stylelines ) {
$f = fopen( "$site_dir/style.css", 'w' );
fwrite( $f, $header );
fwrite( $f, $stylelines );
fclose( $f );
}
return true;
}
/**
* Creates a site theme from the default theme.
*
* {@internal Missing Long Description}}
*
* @since 1.5.0
*
* @param string $theme_name The name of the theme.
* @param string $template The directory name of the theme.
* @return void|false
*/
function make_site_theme_from_default( $theme_name, $template ) {
$site_dir = WP_CONTENT_DIR . "/themes/$template";
$default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
/*
* Copy files from the default theme to the site theme.
* $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
*/
$theme_dir = @opendir( $default_dir );
if ( $theme_dir ) {
while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) {
if ( is_dir( "$default_dir/$theme_file" ) ) {
continue;
}
if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
return;
}
chmod( "$site_dir/$theme_file", 0777 );
}
closedir( $theme_dir );
}
// Rewrite the theme header.
$stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) );
if ( $stylelines ) {
$f = fopen( "$site_dir/style.css", 'w' );
$headers = array(
'Theme Name:' => $theme_name,
'Theme URI:' => __get_option( 'url' ),
'Description:' => 'Your theme.',
'Version:' => '1',
'Author:' => 'You',
);
foreach ( $stylelines as $line ) {
foreach ( $headers as $header => $value ) {
if ( str_contains( $line, $header ) ) {
$line = $header . ' ' . $value;
break;
}
}
fwrite( $f, $line . "\n" );
}
fclose( $f );
}
// Copy the images.
umask( 0 );
if ( ! mkdir( "$site_dir/images", 0777 ) ) {
return false;
}
$images_dir = @opendir( "$default_dir/images" );
if ( $images_dir ) {
while ( ( $image = readdir( $images_dir ) ) !== false ) {
if ( is_dir( "$default_dir/images/$image" ) ) {
continue;
}
if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
return;
}
chmod( "$site_dir/images/$image", 0777 );
}
closedir( $images_dir );
}
}
/**
* Creates a site theme.
*
* {@internal Missing Long Description}}
*
* @since 1.5.0
*
* @return string|false
*/
function make_site_theme() {
// Name the theme after the blog.
$theme_name = __get_option( 'blogname' );
$template = sanitize_title( $theme_name );
$site_dir = WP_CONTENT_DIR . "/themes/$template";
// If the theme already exists, nothing to do.
if ( is_dir( $site_dir ) ) {
return false;
}
// We must be able to write to the themes dir.
if ( ! is_writable( WP_CONTENT_DIR . '/themes' ) ) {
return false;
}
umask( 0 );
if ( ! mkdir( $site_dir, 0777 ) ) {
return false;
}
if ( file_exists( ABSPATH . 'wp-layout.css' ) ) {
if ( ! make_site_theme_from_oldschool( $theme_name, $template ) ) {
// TODO: rm -rf the site theme directory.
return false;
}
} else {
if ( ! make_site_theme_from_default( $theme_name, $template ) ) {
// TODO: rm -rf the site theme directory.
return false;
}
}
// Make the new site theme active.
$current_template = __get_option( 'template' );
if ( WP_DEFAULT_THEME === $current_template ) {
update_option( 'template', $template );
update_option( 'stylesheet', $template );
}
return $template;
}
/**
* Translate user level to user role name.
*
* @since 2.0.0
*
* @param int $level User level.
* @return string User role name.
*/
function translate_level_to_role( $level ) {
switch ( $level ) {
case 10:
case 9:
case 8:
return 'administrator';
case 7:
case 6:
case 5:
return 'editor';
case 4:
case 3:
case 2:
return 'author';
case 1:
return 'contributor';
case 0:
default:
return 'subscriber';
}
}
/**
* Checks the version of the installed MySQL binary.
*
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function wp_check_mysql_version() {
global $wpdb;
$result = $wpdb->check_database_version();
if ( is_wp_error( $result ) ) {
wp_die( $result );
}
}
/**
* Disables the Automattic widgets plugin, which was merged into core.
*
* @since 2.2.0
*/
function maybe_disable_automattic_widgets() {
$plugins = __get_option( 'active_plugins' );
foreach ( (array) $plugins as $plugin ) {
if ( 'widgets.php' === basename( $plugin ) ) {
array_splice( $plugins, array_search( $plugin, $plugins, true ), 1 );
update_option( 'active_plugins', $plugins );
break;
}
}
}
/**
* Disables the Link Manager on upgrade if, at the time of upgrade, no links exist in the DB.
*
* @since 3.5.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function maybe_disable_link_manager() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
update_option( 'link_manager_enabled', 0 );
}
}
/**
* Runs before the schema is upgraded.
*
* @since 2.9.0
*
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
*/
function pre_schema_upgrade() {
global $wp_current_db_version, $wpdb;
// Upgrade versions prior to 2.9.
if ( $wp_current_db_version < 11557 ) {
// Delete duplicate options. Keep the option with the highest option_id.
$wpdb->query( "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id" );
// Drop the old primary key and add the new.
$wpdb->query( "ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)" );
// Drop the old option_name index. dbDelta() doesn't do the drop.
$wpdb->query( "ALTER TABLE $wpdb->options DROP INDEX option_name" );
}
// Multisite schema upgrades.
if ( $wp_current_db_version < 60497 && is_multisite() && wp_should_upgrade_global_tables() ) {
// Upgrade versions prior to 3.7.
if ( $wp_current_db_version < 25179 ) {
// New primary key for signups.
$wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" );
}
if ( $wp_current_db_version < 25448 ) {
// Convert archived from enum to tinyint.
$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" );
$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" );
}
// Upgrade versions prior to 6.9
if ( $wp_current_db_version < 60497 ) {
// Convert ID columns from signed to unsigned
$wpdb->query( "ALTER TABLE $wpdb->blogs MODIFY blog_id bigint(20) unsigned NOT NULL auto_increment" );
$wpdb->query( "ALTER TABLE $wpdb->blogs MODIFY site_id bigint(20) unsigned NOT NULL default 0" );
$wpdb->query( "ALTER TABLE $wpdb->blogmeta MODIFY blog_id bigint(20) unsigned NOT NULL default 0" );
$wpdb->query( "ALTER TABLE $wpdb->registration_log MODIFY ID bigint(20) unsigned NOT NULL auto_increment" );
$wpdb->query( "ALTER TABLE $wpdb->registration_log MODIFY blog_id bigint(20) unsigned NOT NULL default 0" );
$wpdb->query( "ALTER TABLE $wpdb->site MODIFY id bigint(20) unsigned NOT NULL auto_increment" );
$wpdb->query( "ALTER TABLE $wpdb->sitemeta MODIFY meta_id bigint(20) unsigned NOT NULL auto_increment" );
$wpdb->query( "ALTER TABLE $wpdb->sitemeta MODIFY site_id bigint(20) unsigned NOT NULL default 0" );
$wpdb->query( "ALTER TABLE $wpdb->signups MODIFY signup_id bigint(20) unsigned NOT NULL auto_increment" );
}
}
// Upgrade versions prior to 4.2.
if ( $wp_current_db_version < 31351 ) {
if ( ! is_multisite() && wp_should_upgrade_global_tables() ) {
$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
}
$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
$wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
$wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
$wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
}
// Upgrade versions prior to 4.4.
if ( $wp_current_db_version < 34978 ) {
// If compatible termmeta table is found, use it, but enforce a proper index and update collation.
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->termmeta}'" ) && $wpdb->get_results( "SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'" ) ) {
$wpdb->query( "ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
maybe_convert_table_to_utf8mb4( $wpdb->termmeta );
}
}
}
/**
* Determine if global tables should be upgraded.
*
* This function performs a series of checks to ensure the environment allows
* for the safe upgrading of global WordPress database tables. It is necessary
* because global tables will commonly grow to millions of rows on large
* installations, and the ability to control their upgrade routines can be
* critical to the operation of large networks.
*
* In a future iteration, this function may use `wp_is_large_network()` to more-
* intelligently prevent global table upgrades. Until then, we make sure
* WordPress is on the main site of the main network, to avoid running queries
* more than once in multi-site or multi-network environments.
*
* @since 4.3.0
*
* @return bool Whether to run the upgrade routines on global tables.
*/
function wp_should_upgrade_global_tables() {
// Return false early if explicitly not upgrading.
if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
return false;
}
// Assume global tables should be upgraded.
$should_upgrade = true;
// Set to false if not on main network (does not matter if not multi-network).
if ( ! is_main_network() ) {
$should_upgrade = false;
}
// Set to false if not on main site of current network (does not matter if not multi-site).
if ( ! is_main_site() ) {
$should_upgrade = false;
}
/**
* Filters if upgrade routines should be run on global tables.
*
* @since 4.3.0
*
* @param bool $should_upgrade Whether to run the upgrade routines on global tables.
*/
return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );
}
PK �MP\��'b 'b &