Update WP and plugins

This commit is contained in:
Oliver Davies 2019-04-16 20:56:22 +01:00
parent 10a4713229
commit 1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions

View file

@ -19,16 +19,16 @@ add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata'
add_action( 'media_upload_image', 'wp_media_upload_handler' );
add_action( 'media_upload_audio', 'wp_media_upload_handler' );
add_action( 'media_upload_video', 'wp_media_upload_handler' );
add_action( 'media_upload_file', 'wp_media_upload_handler' );
add_action( 'media_upload_file', 'wp_media_upload_handler' );
add_action( 'post-plupload-upload-ui', 'media_upload_flash_bypass' );
add_action( 'post-html-upload-ui', 'media_upload_html_bypass' );
add_action( 'post-html-upload-ui', 'media_upload_html_bypass' );
add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
add_filter( 'async_upload_file', 'get_media_item', 10, 2 );
add_filter( 'async_upload_file', 'get_media_item', 10, 2 );
add_filter( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 );
@ -38,12 +38,12 @@ add_filter( 'media_upload_library', 'media_upload_library' );
add_filter( 'media_upload_tabs', 'update_gallery_tab' );
// Misc hooks.
add_action( 'admin_init', 'wp_admin_headers' );
add_action( 'login_init', 'wp_admin_headers' );
add_action( 'admin_head', 'wp_admin_canonical_url' );
add_action( 'admin_init', 'wp_admin_headers' );
add_action( 'login_init', 'wp_admin_headers' );
add_action( 'admin_head', 'wp_admin_canonical_url' );
add_action( 'admin_head', 'wp_color_scheme_settings' );
add_action( 'admin_head', 'wp_site_icon' );
add_action( 'admin_head', '_ipad_meta' );
add_action( 'admin_head', 'wp_site_icon' );
add_action( 'admin_head', '_ipad_meta' );
// Privacy tools
add_action( 'admin_menu', '_wp_privacy_hook_requests_page' );
@ -55,20 +55,20 @@ if ( ! is_customize_preview() ) {
add_filter( 'admin_print_styles', 'wp_resource_hints', 1 );
}
add_action( 'admin_print_scripts-post.php', 'wp_page_reload_on_back_button_js' );
add_action( 'admin_print_scripts-post.php', 'wp_page_reload_on_back_button_js' );
add_action( 'admin_print_scripts-post-new.php', 'wp_page_reload_on_back_button_js' );
add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_page_on_front', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_admin_email', 'wp_site_admin_email_change_notification', 10, 3 );
add_action( 'update_option_admin_email', 'wp_site_admin_email_change_notification', 10, 3 );
add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 3 );
add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
add_filter( 'heartbeat_received', 'heartbeat_autosave', 500, 2 );
add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 3 );
add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
add_filter( 'heartbeat_received', 'heartbeat_autosave', 500, 2 );
add_filter( 'wp_refresh_nonces', 'wp_refresh_post_nonces', 10, 3 );
add_filter( 'wp_refresh_nonces', 'wp_refresh_heartbeat_nonces' );
@ -82,30 +82,24 @@ add_action( 'admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items' )
add_filter( 'whitelist_options', 'option_update_filter' );
// Plugin Install hooks.
add_action( 'install_plugins_featured', 'install_dashboard' );
add_action( 'install_plugins_upload', 'install_plugins_upload' );
add_action( 'install_plugins_search', 'display_plugins_table' );
add_action( 'install_plugins_popular', 'display_plugins_table' );
add_action( 'install_plugins_recommended', 'display_plugins_table' );
add_action( 'install_plugins_new', 'display_plugins_table' );
add_action( 'install_plugins_beta', 'display_plugins_table' );
add_action( 'install_plugins_favorites', 'display_plugins_table' );
add_action( 'install_plugins_featured', 'install_dashboard' );
add_action( 'install_plugins_upload', 'install_plugins_upload' );
add_action( 'install_plugins_search', 'display_plugins_table' );
add_action( 'install_plugins_popular', 'display_plugins_table' );
add_action( 'install_plugins_recommended', 'display_plugins_table' );
add_action( 'install_plugins_new', 'display_plugins_table' );
add_action( 'install_plugins_beta', 'display_plugins_table' );
add_action( 'install_plugins_favorites', 'display_plugins_table' );
add_action( 'install_plugins_pre_plugin-information', 'install_plugin_information' );
// Template hooks.
add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
// Theme hooks.
add_action( 'customize_controls_print_footer_scripts', 'customize_themes_print_templates' );
// Theme Install hooks.
// add_action('install_themes_dashboard', 'install_themes_dashboard');
// add_action('install_themes_upload', 'install_themes_upload', 10, 0);
// add_action('install_themes_search', 'display_themes');
// add_action('install_themes_featured', 'display_themes');
// add_action('install_themes_new', 'display_themes');
// add_action('install_themes_updated', 'display_themes');
add_action( 'install_themes_pre_theme-information', 'install_theme_information' );
// User hooks.
@ -122,7 +116,7 @@ add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
add_action( 'load-plugins.php', 'wp_plugin_update_rows', 20 ); // After wp_update_plugins() is called.
add_action( 'load-themes.php', 'wp_theme_update_rows', 20 ); // After wp_update_themes() is called.
add_action( 'admin_notices', 'update_nag', 3 );
add_action( 'admin_notices', 'update_nag', 3 );
add_action( 'admin_notices', 'maintenance_nag', 10 );
add_filter( 'update_footer', 'core_update_footer' );

View file

@ -7,7 +7,7 @@
* @since 2.3.0
*/
if ( ! defined('WP_ADMIN') ) {
if ( ! defined( 'WP_ADMIN' ) ) {
/*
* This file is being included from a file other than wp-admin/admin.php, so
* some setup was skipped. Make sure the admin message catalog is loaded since
@ -17,71 +17,71 @@ if ( ! defined('WP_ADMIN') ) {
}
/** WordPress Administration Hooks */
require_once(ABSPATH . 'wp-admin/includes/admin-filters.php');
require_once( ABSPATH . 'wp-admin/includes/admin-filters.php' );
/** WordPress Bookmark Administration API */
require_once(ABSPATH . 'wp-admin/includes/bookmark.php');
require_once( ABSPATH . 'wp-admin/includes/bookmark.php' );
/** WordPress Comment Administration API */
require_once(ABSPATH . 'wp-admin/includes/comment.php');
require_once( ABSPATH . 'wp-admin/includes/comment.php' );
/** WordPress Administration File API */
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once( ABSPATH . 'wp-admin/includes/file.php' );
/** WordPress Image Administration API */
require_once(ABSPATH . 'wp-admin/includes/image.php');
require_once( ABSPATH . 'wp-admin/includes/image.php' );
/** WordPress Media Administration API */
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once( ABSPATH . 'wp-admin/includes/media.php' );
/** WordPress Import Administration API */
require_once(ABSPATH . 'wp-admin/includes/import.php');
require_once( ABSPATH . 'wp-admin/includes/import.php' );
/** WordPress Misc Administration API */
require_once(ABSPATH . 'wp-admin/includes/misc.php');
require_once( ABSPATH . 'wp-admin/includes/misc.php' );
/** WordPress Options Administration API */
require_once(ABSPATH . 'wp-admin/includes/options.php');
require_once( ABSPATH . 'wp-admin/includes/options.php' );
/** WordPress Plugin Administration API */
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
/** WordPress Post Administration API */
require_once(ABSPATH . 'wp-admin/includes/post.php');
require_once( ABSPATH . 'wp-admin/includes/post.php' );
/** WordPress Administration Screen API */
require_once(ABSPATH . 'wp-admin/includes/class-wp-screen.php');
require_once(ABSPATH . 'wp-admin/includes/screen.php');
require_once( ABSPATH . 'wp-admin/includes/class-wp-screen.php' );
require_once( ABSPATH . 'wp-admin/includes/screen.php' );
/** WordPress Taxonomy Administration API */
require_once(ABSPATH . 'wp-admin/includes/taxonomy.php');
require_once( ABSPATH . 'wp-admin/includes/taxonomy.php' );
/** WordPress Template Administration API */
require_once(ABSPATH . 'wp-admin/includes/template.php');
require_once( ABSPATH . 'wp-admin/includes/template.php' );
/** WordPress List Table Administration API and base class */
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table-compat.php');
require_once(ABSPATH . 'wp-admin/includes/list-table.php');
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table-compat.php' );
require_once( ABSPATH . 'wp-admin/includes/list-table.php' );
/** WordPress Theme Administration API */
require_once(ABSPATH . 'wp-admin/includes/theme.php');
require_once( ABSPATH . 'wp-admin/includes/theme.php' );
/** WordPress User Administration API */
require_once(ABSPATH . 'wp-admin/includes/user.php');
require_once( ABSPATH . 'wp-admin/includes/user.php' );
/** WordPress Site Icon API */
require_once(ABSPATH . 'wp-admin/includes/class-wp-site-icon.php');
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-icon.php' );
/** WordPress Update Administration API */
require_once(ABSPATH . 'wp-admin/includes/update.php');
require_once( ABSPATH . 'wp-admin/includes/update.php' );
/** WordPress Deprecated Administration API */
require_once(ABSPATH . 'wp-admin/includes/deprecated.php');
require_once( ABSPATH . 'wp-admin/includes/deprecated.php' );
/** WordPress Multisite support API */
if ( is_multisite() ) {
require_once(ABSPATH . 'wp-admin/includes/ms-admin-filters.php');
require_once(ABSPATH . 'wp-admin/includes/ms.php');
require_once(ABSPATH . 'wp-admin/includes/ms-deprecated.php');
require_once( ABSPATH . 'wp-admin/includes/ms-admin-filters.php' );
require_once( ABSPATH . 'wp-admin/includes/ms.php' );
require_once( ABSPATH . 'wp-admin/includes/ms-deprecated.php' );
}

File diff suppressed because it is too large Load diff

View file

@ -34,15 +34,16 @@ function edit_link( $link_id = 0 ) {
);
}
$_POST['link_url'] = esc_html( $_POST['link_url'] );
$_POST['link_url'] = esc_url($_POST['link_url']);
$_POST['link_name'] = esc_html( $_POST['link_name'] );
$_POST['link_url'] = esc_html( $_POST['link_url'] );
$_POST['link_url'] = esc_url( $_POST['link_url'] );
$_POST['link_name'] = esc_html( $_POST['link_name'] );
$_POST['link_image'] = esc_html( $_POST['link_image'] );
$_POST['link_rss'] = esc_url($_POST['link_rss']);
if ( !isset($_POST['link_visible']) || 'N' != $_POST['link_visible'] )
$_POST['link_rss'] = esc_url( $_POST['link_rss'] );
if ( ! isset( $_POST['link_visible'] ) || 'N' != $_POST['link_visible'] ) {
$_POST['link_visible'] = 'Y';
}
if ( !empty( $link_id ) ) {
if ( ! empty( $link_id ) ) {
$_POST['link_id'] = $link_id;
return wp_update_link( $_POST );
} else {
@ -59,15 +60,17 @@ function edit_link( $link_id = 0 ) {
*/
function get_default_link_to_edit() {
$link = new stdClass;
if ( isset( $_GET['linkurl'] ) )
if ( isset( $_GET['linkurl'] ) ) {
$link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) );
else
} else {
$link->link_url = '';
}
if ( isset( $_GET['name'] ) )
if ( isset( $_GET['name'] ) ) {
$link->link_name = esc_attr( wp_unslash( $_GET['name'] ) );
else
} else {
$link->link_name = '';
}
$link->link_visible = 'Y';
@ -122,7 +125,7 @@ function wp_delete_link( $link_id ) {
* @return array The requested link's categories
*/
function wp_get_link_cats( $link_id = 0 ) {
$cats = wp_get_object_terms( $link_id, 'link_category', array('fields' => 'ids') );
$cats = wp_get_object_terms( $link_id, 'link_category', array( 'fields' => 'ids' ) );
return array_unique( $cats );
}
@ -152,10 +155,15 @@ function get_link_to_edit( $link ) {
function wp_insert_link( $linkdata, $wp_error = false ) {
global $wpdb;
$defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 );
$defaults = array(
'link_id' => 0,
'link_name' => '',
'link_url' => '',
'link_rating' => 0,
);
$args = wp_parse_args( $linkdata, $defaults );
$r = wp_unslash( sanitize_bookmark( $args, 'db' ) );
$r = wp_unslash( sanitize_bookmark( $args, 'db' ) );
$link_id = $r['link_id'];
$link_name = $r['link_name'];
@ -245,12 +253,13 @@ function wp_insert_link( $linkdata, $wp_error = false ) {
* @since 2.1.0
*
* @param int $link_id ID of the link to update.
* @param array $link_categories Array of link categories to add the link to.
* @param int[] $link_categories Array of link category IDs to add the link to.
*/
function wp_set_link_cats( $link_id = 0, $link_categories = array() ) {
// If $link_categories isn't already an array, make it one:
if ( !is_array( $link_categories ) || 0 == count( $link_categories ) )
if ( ! is_array( $link_categories ) || 0 == count( $link_categories ) ) {
$link_categories = array( get_option( 'default_link_category' ) );
}
$link_categories = array_map( 'intval', $link_categories );
$link_categories = array_unique( $link_categories );
@ -277,14 +286,14 @@ function wp_update_link( $linkdata ) {
$link = wp_slash( $link );
// Passed link category list overwrites existing category list if not empty.
if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] )
&& 0 != count( $linkdata['link_category'] ) )
if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) && 0 != count( $linkdata['link_category'] ) ) {
$link_cats = $linkdata['link_category'];
else
} else {
$link_cats = $link['link_category'];
}
// Merge old and new fields with new fields overwriting old ones.
$linkdata = array_merge( $link, $linkdata );
$linkdata = array_merge( $link, $linkdata );
$linkdata['link_category'] = $link_cats;
return wp_insert_link( $linkdata );
@ -300,8 +309,9 @@ function wp_update_link( $linkdata ) {
*/
function wp_link_manager_disabled_message() {
global $pagenow;
if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow )
if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow ) {
return;
}
add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
$really_can_manage_links = current_user_can( 'manage_links' );
@ -309,6 +319,7 @@ function wp_link_manager_disabled_message() {
if ( $really_can_manage_links && current_user_can( 'install_plugins' ) ) {
$link = network_admin_url( 'plugin-install.php?tab=search&s=Link+Manager' );
/* translators: %s: URL of link manager plugin */
wp_die( sprintf( __( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager</a> plugin.' ), $link ) );
}

View file

@ -50,7 +50,6 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
}
/**
*
* @return array
*/
public function get_upgrade_messages() {
@ -58,7 +57,6 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
}
/**
*
* @param string|array|WP_Error $data
*/
public function feedback( $data ) {
@ -69,30 +67,36 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
} else {
$string = $data;
}
if ( ! empty( $this->upgrader->strings[ $string ] ) )
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
$string = $this->upgrader->strings[ $string ];
}
if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( ! empty( $args ) )
if ( ! empty( $args ) ) {
$string = vsprintf( $string, $args );
}
}
$string = trim( $string );
// Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
$string = wp_kses( $string, array(
'a' => array(
'href' => true
),
'br' => true,
'em' => true,
'strong' => true,
) );
$string = wp_kses(
$string,
array(
'a' => array(
'href' => true,
),
'br' => true,
'em' => true,
'strong' => true,
)
);
if ( empty( $string ) )
if ( empty( $string ) ) {
return;
}
$this->messages[] = $string;
}
@ -107,7 +111,8 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
*/
public function footer() {
$output = ob_get_clean();
if ( ! empty( $output ) )
if ( ! empty( $output ) ) {
$this->feedback( $output );
}
}
}

View file

@ -16,27 +16,26 @@
* @see Bulk_Upgrader_Skin
*/
class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
public $plugin_info = array(); // Plugin_Upgrader::bulk_upgrade() will fill this in.
public function add_strings() {
parent::add_strings();
$this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
/* translators: 1: name of plugin being updated, 2: number of updating plugin, 3: total number of plugins being updated */
$this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)' );
}
/**
*
* @param string $title
*/
public function before($title = '') {
parent::before($this->plugin_info['Title']);
public function before( $title = '' ) {
parent::before( $this->plugin_info['Title'] );
}
/**
*
* @param string $title
*/
public function after($title = '') {
parent::after($this->plugin_info['Title']);
public function after( $title = '' ) {
parent::after( $this->plugin_info['Title'] );
$this->decrement_update_count( 'plugin' );
}
@ -44,24 +43,26 @@ class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
*/
public function bulk_footer() {
parent::bulk_footer();
$update_actions = array(
$update_actions = array(
'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>',
'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>',
);
if ( ! current_user_can( 'activate_plugins' ) )
if ( ! current_user_can( 'activate_plugins' ) ) {
unset( $update_actions['plugins_page'] );
}
/**
* Filters the list of action links available following bulk plugin updates.
*
* @since 3.0.0
*
* @param array $update_actions Array of plugin action links.
* @param array $plugin_info Array of information for the last-updated plugin.
* @param string[] $update_actions Array of plugin action links.
* @param array $plugin_info Array of information for the last-updated plugin.
*/
$update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
if ( ! empty($update_actions) )
$this->feedback(implode(' | ', (array)$update_actions));
if ( ! empty( $update_actions ) ) {
$this->feedback( implode( ' | ', (array) $update_actions ) );
}
}
}

View file

@ -16,27 +16,26 @@
* @see Bulk_Upgrader_Skin
*/
class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
public $theme_info = array(); // Theme_Upgrader::bulk_upgrade() will fill this in.
public function add_strings() {
parent::add_strings();
$this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
/* translators: 1: name of theme being updated, 2: number of updating themes, 3: total number of themes being updated */
$this->upgrader->strings['skin_before_update_header'] = __( 'Updating Theme %1$s (%2$d/%3$d)' );
}
/**
*
* @param string $title
*/
public function before($title = '') {
parent::before( $this->theme_info->display('Name') );
public function before( $title = '' ) {
parent::before( $this->theme_info->display( 'Name' ) );
}
/**
*
* @param string $title
*/
public function after($title = '') {
parent::after( $this->theme_info->display('Name') );
public function after( $title = '' ) {
parent::after( $this->theme_info->display( 'Name' ) );
$this->decrement_update_count( 'theme' );
}
@ -44,24 +43,26 @@ class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
*/
public function bulk_footer() {
parent::bulk_footer();
$update_actions = array(
'themes_page' => '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>',
'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
$update_actions = array(
'themes_page' => '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>',
'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>',
);
if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) {
unset( $update_actions['themes_page'] );
}
/**
* Filters the list of action links available following bulk theme updates.
*
* @since 3.0.0
*
* @param array $update_actions Array of theme action links.
* @param array $theme_info Array of information for the last-updated theme.
* @param string[] $update_actions Array of theme action links.
* @param WP_Theme $theme_info Theme object for the last-updated theme.
*/
$update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
if ( ! empty($update_actions) )
$this->feedback(implode(' | ', (array)$update_actions));
if ( ! empty( $update_actions ) ) {
$this->feedback( implode( ' | ', (array) $update_actions ) );
}
}
}

View file

@ -23,52 +23,56 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
public $error = false;
/**
*
* @param array $args
*/
public function __construct($args = array()) {
$defaults = array( 'url' => '', 'nonce' => '' );
$args = wp_parse_args($args, $defaults);
public function __construct( $args = array() ) {
$defaults = array(
'url' => '',
'nonce' => '',
);
$args = wp_parse_args( $args, $defaults );
parent::__construct($args);
parent::__construct( $args );
}
/**
*/
public function add_strings() {
$this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
$this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
/* translators: 1: Title of an update, 2: Error message */
$this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s');
/* translators: 1: Title of an update */
$this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
/* translators: 1: Title of an update */
$this->upgrader->strings['skin_update_successful'] = __( '%1$s updated successfully.' );
$this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
$this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' );
/* translators: %s: Title of an update */
$this->upgrader->strings['skin_update_failed'] = __( 'The update of %s failed.' );
/* translators: %s: Title of an update */
$this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' );
$this->upgrader->strings['skin_upgrade_end'] = __( 'All updates have been completed.' );
}
/**
*
* @param string $string
*/
public function feedback($string) {
if ( isset( $this->upgrader->strings[$string] ) )
$string = $this->upgrader->strings[$string];
public function feedback( $string ) {
if ( isset( $this->upgrader->strings[ $string ] ) ) {
$string = $this->upgrader->strings[ $string ];
}
if ( strpos($string, '%') !== false ) {
if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice($args, 1);
$args = array_splice( $args, 1 );
if ( $args ) {
$args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args );
$string = vsprintf($string, $args);
$args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args );
$string = vsprintf( $string, $args );
}
}
if ( empty($string) )
if ( empty( $string ) ) {
return;
if ( $this->in_loop )
}
if ( $this->in_loop ) {
echo "$string<br />\n";
else
} else {
echo "<p>$string</p>\n";
}
}
/**
@ -84,65 +88,64 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
}
/**
*
* @param string|WP_Error $error
*/
public function error($error) {
if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
$this->error = $this->upgrader->strings[$error];
public function error( $error ) {
if ( is_string( $error ) && isset( $this->upgrader->strings[ $error ] ) ) {
$this->error = $this->upgrader->strings[ $error ];
}
if ( is_wp_error($error) ) {
if ( is_wp_error( $error ) ) {
$messages = array();
foreach ( $error->get_error_messages() as $emessage ) {
if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) {
$messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
else
} else {
$messages[] = $emessage;
}
}
$this->error = implode(', ', $messages);
$this->error = implode( ', ', $messages );
}
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
}
/**
*/
public function bulk_header() {
$this->feedback('skin_upgrade_start');
$this->feedback( 'skin_upgrade_start' );
}
/**
*/
public function bulk_footer() {
$this->feedback('skin_upgrade_end');
$this->feedback( 'skin_upgrade_end' );
}
/**
*
* @param string $title
*/
public function before($title = '') {
public function before( $title = '' ) {
$this->in_loop = true;
printf( '<h2>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count );
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>';
// This progress messages div gets moved via JavaScript when clicking on "Show details.".
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>';
$this->flush_output();
}
/**
*
* @param string $title
*/
public function after($title = '') {
public function after( $title = '' ) {
echo '</p></div>';
if ( $this->error || ! $this->result ) {
if ( $this->error ) {
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
} else {
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>';
}
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>';
}
if ( $this->result && ! is_wp_error( $this->result ) ) {
if ( ! $this->error ) {
@ -152,7 +155,7 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
'</p></div>';
}
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
}
$this->reset();
@ -163,7 +166,7 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
*/
public function reset() {
$this->in_loop = false;
$this->error = false;
$this->error = false;
}
/**

View file

@ -26,15 +26,15 @@ class Core_Upgrader extends WP_Upgrader {
* @since 2.8.0
*/
public function upgrade_strings() {
$this->strings['up_to_date'] = __('WordPress is at the latest version.');
$this->strings['locked'] = __('Another update is currently in progress.');
$this->strings['no_package'] = __('Update package not available.');
$this->strings['up_to_date'] = __( 'WordPress is at the latest version.' );
$this->strings['locked'] = __( 'Another update is currently in progress.' );
$this->strings['no_package'] = __( 'Update package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __('Unpacking the update&#8230;');
$this->strings['copy_failed'] = __('Could not copy files.');
$this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' );
$this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' );
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' );
$this->strings['copy_failed'] = __( 'Could not copy files.' );
$this->strings['copy_failed_space'] = __( 'Could not copy files. You may have run out of disk space.' );
$this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' );
$this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' );
}
@ -43,7 +43,7 @@ class Core_Upgrader extends WP_Upgrader {
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global callable $_wp_filesystem_direct_method
*
* @param object $current Response object for whether WordPress is current.
@ -66,10 +66,10 @@ class Core_Upgrader extends WP_Upgrader {
$start_time = time();
$defaults = array(
'pre_check_md5' => true,
'attempt_rollback' => false,
'do_rollback' => false,
$defaults = array(
'pre_check_md5' => true,
'attempt_rollback' => false,
'do_rollback' => false,
'allow_relaxed_file_ownership' => false,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -78,21 +78,23 @@ class Core_Upgrader extends WP_Upgrader {
$this->upgrade_strings();
// Is an update available?
if ( !isset( $current->response ) || $current->response == 'latest' )
return new WP_Error('up_to_date', $this->strings['up_to_date']);
if ( ! isset( $current->response ) || $current->response == 'latest' ) {
return new WP_Error( 'up_to_date', $this->strings['up_to_date'] );
}
$res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] );
if ( ! $res || is_wp_error( $res ) ) {
return $res;
}
$wp_dir = trailingslashit($wp_filesystem->abspath());
$wp_dir = trailingslashit( $wp_filesystem->abspath() );
$partial = true;
if ( $parsed_args['do_rollback'] )
if ( $parsed_args['do_rollback'] ) {
$partial = false;
elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() )
} elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) {
$partial = false;
}
/*
* If partial update is returned from the API, use that, unless we're doing
@ -100,17 +102,18 @@ class Core_Upgrader extends WP_Upgrader {
* the new_bundled zip. Don't though if the constant is set to skip bundled items.
* If the API returns a no_content zip, go with it. Finally, default to the full zip.
*/
if ( $parsed_args['do_rollback'] && $current->packages->rollback )
if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
$to_download = 'rollback';
elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial )
} elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial ) {
$to_download = 'partial';
elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
&& ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
} elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
&& ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
$to_download = 'new_bundled';
elseif ( $current->packages->no_content )
} elseif ( $current->packages->no_content ) {
$to_download = 'no_content';
else
} else {
$to_download = 'full';
}
// Lock to prevent multiple Core Updates occurring
$lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS );
@ -131,12 +134,12 @@ class Core_Upgrader extends WP_Upgrader {
}
// Copy update-core.php from the new version into place.
if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
$wp_filesystem->delete($working_dir, true);
if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) {
$wp_filesystem->delete( $working_dir, true );
WP_Upgrader::release_lock( 'core_updater' );
return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' );
}
$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
$wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE );
require_once( ABSPATH . 'wp-admin/includes/update-core.php' );
@ -157,12 +160,13 @@ class Core_Upgrader extends WP_Upgrader {
* mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full.
* do_rollback allows for update_core() to trigger a rollback if needed.
*/
if ( false !== strpos( $error_code, 'do_rollback' ) )
if ( false !== strpos( $error_code, 'do_rollback' ) ) {
$try_rollback = true;
elseif ( false !== strpos( $error_code, '__copy_dir' ) )
} elseif ( false !== strpos( $error_code, '__copy_dir' ) ) {
$try_rollback = true;
elseif ( 'disk_full' === $error_code )
} elseif ( 'disk_full' === $error_code ) {
$try_rollback = true;
}
}
if ( $try_rollback ) {
@ -175,12 +179,26 @@ class Core_Upgrader extends WP_Upgrader {
$rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) );
$original_result = $result;
$result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 'update' => $original_result, 'rollback' => $rollback_result ) );
$result = new WP_Error(
'rollback_was_required',
$this->strings['rollback_was_required'],
(object) array(
'update' => $original_result,
'rollback' => $rollback_result,
)
);
}
}
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ) );
do_action(
'upgrader_process_complete',
$this,
array(
'action' => 'update',
'type' => 'core',
)
);
// Clear the current updates
delete_site_transient( 'update_core' );
@ -191,7 +209,7 @@ class Core_Upgrader extends WP_Upgrader {
'success' => true,
'fs_method' => $wp_filesystem->method,
'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ),
'fs_method_direct' => !empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',
'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',
'time_taken' => time() - $start_time,
'reported' => $wp_version,
'attempted' => $current->version,
@ -228,16 +246,14 @@ class Core_Upgrader extends WP_Upgrader {
*
* @since 3.7.0
*
* @static
*
* @param string $offered_ver The offered version, of the format x.y.z.
* @return bool True if we should update to the offered version, otherwise false.
*/
public static function should_update_to_version( $offered_ver ) {
include( ABSPATH . WPINC . '/version.php' ); // $wp_version; // x.y.z
$current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
$new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
$current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
$new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
$current_is_development_version = (bool) strpos( $wp_version, '-' );
// Defaults:
@ -255,34 +271,39 @@ class Core_Upgrader extends WP_Upgrader {
$upgrade_dev = $upgrade_minor = $upgrade_major = true;
} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
// Only minor updates for core
$upgrade_dev = $upgrade_major = false;
$upgrade_dev = $upgrade_major = false;
$upgrade_minor = true;
}
}
// 1: If we're already on that version, not much point in updating?
if ( $offered_ver == $wp_version )
if ( $offered_ver == $wp_version ) {
return false;
}
// 2: If we're running a newer version, that's a nope
if ( version_compare( $wp_version, $offered_ver, '>' ) )
if ( version_compare( $wp_version, $offered_ver, '>' ) ) {
return false;
}
$failure_data = get_site_option( 'auto_core_update_failed' );
if ( $failure_data ) {
// If this was a critical update failure, cannot update.
if ( ! empty( $failure_data['critical'] ) )
if ( ! empty( $failure_data['critical'] ) ) {
return false;
}
// Don't claim we can update on update-core.php if we have a non-critical failure logged.
if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) )
if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) {
return false;
}
// Cannot update if we're retrying the same A to B update that caused a non-critical failure.
// Some non-critical failures do allow retries, like download_failed.
// 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2.
if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] )
if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) {
return false;
}
}
// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2
@ -296,8 +317,9 @@ class Core_Upgrader extends WP_Upgrader {
* @param bool $upgrade_dev Whether to enable automatic updates for
* development versions.
*/
if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) )
if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) {
return false;
}
// Else fall through to minor + major branches below.
}
@ -346,15 +368,18 @@ class Core_Upgrader extends WP_Upgrader {
$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
if ( ! is_array( $checksums ) )
if ( ! is_array( $checksums ) ) {
return false;
}
foreach ( $checksums as $file => $checksum ) {
// Skip files which get updated
if ( 'wp-content' == substr( $file, 0, 10 ) )
if ( 'wp-content' == substr( $file, 0, 10 ) ) {
continue;
if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum )
}
if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
return false;
}
}
return true;

View file

@ -52,28 +52,33 @@ class File_Upload_Upgrader {
*/
public function __construct( $form, $urlholder ) {
if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
wp_die(__('Please select a file'));
if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) {
wp_die( __( 'Please select a file' ) );
}
//Handle a newly uploaded file, Else assume it's already been uploaded
if ( ! empty($_FILES) ) {
$overrides = array( 'test_form' => false, 'test_type' => false );
$file = wp_handle_upload( $_FILES[$form], $overrides );
if ( ! empty( $_FILES ) ) {
$overrides = array(
'test_form' => false,
'test_type' => false,
);
$file = wp_handle_upload( $_FILES[ $form ], $overrides );
if ( isset( $file['error'] ) )
if ( isset( $file['error'] ) ) {
wp_die( $file['error'] );
}
$this->filename = $_FILES[$form]['name'];
$this->package = $file['file'];
$this->filename = $_FILES[ $form ]['name'];
$this->package = $file['file'];
// Construct the object array
$object = array(
'post_title' => $this->filename,
'post_content' => $file['url'],
'post_title' => $this->filename,
'post_content' => $file['url'],
'post_mime_type' => $file['type'],
'guid' => $file['url'],
'context' => 'upgrader',
'post_status' => 'private'
'guid' => $file['url'],
'context' => 'upgrader',
'post_status' => 'private',
);
// Save the data.
@ -82,22 +87,24 @@ class File_Upload_Upgrader {
// Schedule a cleanup for 2 hours from now in case of failed installation.
wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) );
} elseif ( is_numeric( $_GET[$urlholder] ) ) {
} elseif ( is_numeric( $_GET[ $urlholder ] ) ) {
// Numeric Package = previously uploaded file, see above.
$this->id = (int) $_GET[$urlholder];
$this->id = (int) $_GET[ $urlholder ];
$attachment = get_post( $this->id );
if ( empty($attachment) )
wp_die(__('Please select a file'));
if ( empty( $attachment ) ) {
wp_die( __( 'Please select a file' ) );
}
$this->filename = $attachment->post_title;
$this->package = get_attached_file( $attachment->ID );
$this->package = get_attached_file( $attachment->ID );
} else {
// Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) {
wp_die( $uploads['error'] );
}
$this->filename = sanitize_file_name( $_GET[ $urlholder ] );
$this->package = $uploads['basedir'] . '/' . $this->filename;
$this->package = $uploads['basedir'] . '/' . $this->filename;
if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) {
wp_die( __( 'Please select a file' ) );
@ -113,11 +120,12 @@ class File_Upload_Upgrader {
* @return bool Whether the cleanup was successful.
*/
public function cleanup() {
if ( $this->id )
if ( $this->id ) {
wp_delete_attachment( $this->id );
elseif ( file_exists( $this->package ) )
} elseif ( file_exists( $this->package ) ) {
return @unlink( $this->package );
}
return true;
}

View file

@ -16,21 +16,25 @@
* @see WP_Upgrader_Skin
*/
class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
public $language_update = null;
public $done_header = false;
public $done_footer = false;
public $language_update = null;
public $done_header = false;
public $done_footer = false;
public $display_footer_actions = true;
/**
*
* @param array $args
*/
public function __construct( $args = array() ) {
$defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
$args = wp_parse_args( $args, $defaults );
$defaults = array(
'url' => '',
'nonce' => '',
'title' => __( 'Update Translations' ),
'skip_header_footer' => false,
);
$args = wp_parse_args( $args, $defaults );
if ( $args['skip_header_footer'] ) {
$this->done_header = true;
$this->done_footer = true;
$this->done_header = true;
$this->done_footer = true;
$this->display_footer_actions = false;
}
parent::__construct( $args );
@ -43,11 +47,11 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
echo '<div class="update-messages lp-show-latest">';
/* translators: 1: name of project, 2: language */
printf( '<h2>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h2>', $name, $this->language_update->language );
}
/**
*
* @param string|WP_Error $error
*/
public function error( $error ) {
@ -66,7 +70,7 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
*/
public function bulk_footer() {
$this->decrement_update_count( 'translation' );
$update_actions = array();
$update_actions = array();
$update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>';
/**
@ -74,11 +78,12 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
*
* @since 3.7.0
*
* @param array $update_actions Array of translations update links.
* @param string[] $update_actions Array of translations update links.
*/
$update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
if ( $update_actions && $this->display_footer_actions )
if ( $update_actions && $this->display_footer_actions ) {
$this->feedback( implode( ' | ', $update_actions ) );
}
}
}

View file

@ -41,7 +41,6 @@ class Language_Pack_Upgrader extends WP_Upgrader {
* Hooked to the {@see 'upgrader_process_complete'} action by default.
*
* @since 3.7.0
* @static
*
* @param false|WP_Upgrader $upgrader Optional. WP_Upgrader instance or false. If `$upgrader` is
* a Language_Pack_Upgrader instance, the method will bail to
@ -94,9 +93,11 @@ class Language_Pack_Upgrader extends WP_Upgrader {
if ( $upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin ) {
$skin = $upgrader->skin;
} else {
$skin = new Language_Pack_Upgrader_Skin( array(
'skip_header_footer' => true,
) );
$skin = new Language_Pack_Upgrader_Skin(
array(
'skip_header_footer' => true,
)
);
}
$lp_upgrader = new Language_Pack_Upgrader( $skin );
@ -110,13 +111,15 @@ class Language_Pack_Upgrader extends WP_Upgrader {
*/
public function upgrade_strings() {
$this->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while we update them as well.' );
$this->strings['up_to_date'] = __( 'The translations are up to date.' );
$this->strings['no_package'] = __( 'Update package not available.' );
$this->strings['up_to_date'] = __( 'The translations are up to date.' );
$this->strings['no_package'] = __( 'Update package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' );
$this->strings['process_failed'] = __( 'Translation update failed.' );
$this->strings['process_success'] = __( 'Translation updated successfully.' );
$this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' );
$this->strings['process_failed'] = __( 'Translation update failed.' );
$this->strings['process_success'] = __( 'Translation updated successfully.' );
$this->strings['remove_old'] = __( 'Removing the old version of the translation&#8230;' );
$this->strings['remove_old_failed'] = __( 'Could not remove the old translation.' );
}
/**
@ -148,22 +151,23 @@ class Language_Pack_Upgrader extends WP_Upgrader {
*
* @since 3.7.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param array $language_updates Optional. Language pack updates. Default empty array.
* @param array $args {
* Optional. Other arguments for upgrading multiple language packs. Default empty array
* @param object[] $language_updates Optional. Array of language packs to update. @see wp_get_translation_updates().
* Default empty array.
* @param array $args {
* Other arguments for upgrading multiple language packs. Default empty array.
*
* @type bool $clear_update_cache Whether to clear the update cache when done.
* Default true.
* }
* @return array|bool|WP_Error Will return an array of results, or true if there are no updates,
* false or WP_Error for initial errors.
* false or WP_Error for initial errors.
*/
public function bulk_upgrade( $language_updates = array(), $args = array() ) {
global $wp_filesystem;
$defaults = array(
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -171,8 +175,9 @@ class Language_Pack_Upgrader extends WP_Upgrader {
$this->init();
$this->upgrade_strings();
if ( ! $language_updates )
if ( ! $language_updates ) {
$language_updates = wp_get_translation_updates();
}
if ( empty( $language_updates ) ) {
$this->skin->header();
@ -183,8 +188,9 @@ class Language_Pack_Upgrader extends WP_Upgrader {
return true;
}
if ( 'upgrader_process_complete' == current_filter() )
if ( 'upgrader_process_complete' == current_filter() ) {
$this->skin->feedback( 'starting_upgrade' );
}
// Remove any existing upgrade filters from the plugin/theme upgraders #WP29425 & #WP29230
remove_all_filters( 'upgrader_pre_install' );
@ -205,7 +211,7 @@ class Language_Pack_Upgrader extends WP_Upgrader {
$results = array();
$this->update_count = count( $language_updates );
$this->update_count = count( $language_updates );
$this->update_current = 0;
/*
@ -213,9 +219,11 @@ class Language_Pack_Upgrader extends WP_Upgrader {
* as we then may need to create a /plugins or /themes directory inside of it.
*/
$remote_destination = $wp_filesystem->find_folder( WP_LANG_DIR );
if ( ! $wp_filesystem->exists( $remote_destination ) )
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) )
if ( ! $wp_filesystem->exists( $remote_destination ) ) {
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination );
}
}
$language_updates_results = array();
@ -224,24 +232,25 @@ class Language_Pack_Upgrader extends WP_Upgrader {
$this->skin->language_update = $language_update;
$destination = WP_LANG_DIR;
if ( 'plugin' == $language_update->type )
if ( 'plugin' == $language_update->type ) {
$destination .= '/plugins';
elseif ( 'theme' == $language_update->type )
} elseif ( 'theme' == $language_update->type ) {
$destination .= '/themes';
}
$this->update_current++;
$options = array(
'package' => $language_update->package,
'destination' => $destination,
'clear_destination' => false,
'package' => $language_update->package,
'destination' => $destination,
'clear_destination' => true,
'abort_if_destination_exists' => false, // We expect the destination to exist.
'clear_working' => true,
'is_multi' => true,
'hook_extra' => array(
'clear_working' => true,
'is_multi' => true,
'hook_extra' => array(
'language_update_type' => $language_update->type,
'language_update' => $language_update,
)
'language_update' => $language_update,
),
);
$result = $this->run( $options );
@ -268,12 +277,16 @@ class Language_Pack_Upgrader extends WP_Upgrader {
remove_action( 'upgrader_process_complete', 'wp_update_themes' );
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
do_action( 'upgrader_process_complete', $this, array(
'action' => 'update',
'type' => 'translation',
'bulk' => true,
'translations' => $language_updates_results
) );
do_action(
'upgrader_process_complete',
$this,
array(
'action' => 'update',
'type' => 'translation',
'bulk' => true,
'translations' => $language_updates_results,
)
);
// Re-add upgrade hooks.
add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
@ -311,8 +324,9 @@ class Language_Pack_Upgrader extends WP_Upgrader {
public function check_package( $source, $remote_source ) {
global $wp_filesystem;
if ( is_wp_error( $source ) )
if ( is_wp_error( $source ) ) {
return $source;
}
// Check that the folder contains a valid language.
$files = $wp_filesystem->dirlist( $remote_source );
@ -320,16 +334,20 @@ class Language_Pack_Upgrader extends WP_Upgrader {
// Check to see if a .po and .mo exist in the folder.
$po = $mo = false;
foreach ( (array) $files as $file => $filedata ) {
if ( '.po' == substr( $file, -3 ) )
if ( '.po' == substr( $file, -3 ) ) {
$po = true;
elseif ( '.mo' == substr( $file, -3 ) )
} elseif ( '.mo' == substr( $file, -3 ) ) {
$mo = true;
}
}
if ( ! $mo || ! $po ) {
return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'],
/* translators: 1: .po 2: .mo */
sprintf( __( 'The language pack is missing either the %1$s or %2$s files.' ),
return new WP_Error(
'incompatible_archive_pomo',
$this->strings['incompatible_archive'],
sprintf(
/* translators: 1: .po, 2: .mo */
__( 'The language pack is missing either the %1$s or %2$s files.' ),
'<code>.po</code>',
'<code>.mo</code>'
)
@ -354,17 +372,101 @@ class Language_Pack_Upgrader extends WP_Upgrader {
case 'theme':
$theme = wp_get_theme( $update->slug );
if ( $theme->exists() )
if ( $theme->exists() ) {
return $theme->Get( 'Name' );
}
break;
case 'plugin':
$plugin_data = get_plugins( '/' . $update->slug );
$plugin_data = reset( $plugin_data );
if ( $plugin_data )
if ( $plugin_data ) {
return $plugin_data['Name'];
}
break;
}
return '';
}
/**
* Clears existing translations where this item is going to be installed into.
*
* @since 5.1.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $remote_destination The location on the remote filesystem to be cleared.
* @return bool|WP_Error True upon success, WP_Error on failure.
*/
public function clear_destination( $remote_destination ) {
global $wp_filesystem;
$language_update = $this->skin->language_update;
$language_directory = WP_LANG_DIR . '/'; // Local path for use with glob().
if ( 'core' === $language_update->type ) {
$files = array(
$remote_destination . $language_update->language . '.po',
$remote_destination . $language_update->language . '.mo',
$remote_destination . 'admin-' . $language_update->language . '.po',
$remote_destination . 'admin-' . $language_update->language . '.mo',
$remote_destination . 'admin-network-' . $language_update->language . '.po',
$remote_destination . 'admin-network-' . $language_update->language . '.mo',
$remote_destination . 'continents-cities-' . $language_update->language . '.po',
$remote_destination . 'continents-cities-' . $language_update->language . '.mo',
);
$json_translation_files = glob( $language_directory . $language_update->language . '-*.json' );
if ( $json_translation_files ) {
foreach ( $json_translation_files as $json_translation_file ) {
$files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );
}
}
} else {
$files = array(
$remote_destination . $language_update->slug . '-' . $language_update->language . '.po',
$remote_destination . $language_update->slug . '-' . $language_update->language . '.mo',
);
$language_directory = $language_directory . $language_update->type . 's/';
$json_translation_files = glob( $language_directory . $language_update->slug . '-' . $language_update->language . '-*.json' );
if ( $json_translation_files ) {
foreach ( $json_translation_files as $json_translation_file ) {
$files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );
}
}
}
$files = array_filter( $files, array( $wp_filesystem, 'exists' ) );
// No files to delete.
if ( ! $files ) {
return true;
}
// Check all files are writable before attempting to clear the destination.
$unwritable_files = array();
// Check writability.
foreach ( $files as $file ) {
if ( ! $wp_filesystem->is_writable( $file ) ) {
// Attempt to alter permissions to allow writes and try again.
$wp_filesystem->chmod( $file, FS_CHMOD_FILE );
if ( ! $wp_filesystem->is_writable( $file ) ) {
$unwritable_files[] = $file;
}
}
}
if ( ! empty( $unwritable_files ) ) {
return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );
}
foreach ( $files as $file ) {
if ( ! $wp_filesystem->delete( $file ) ) {
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
}
}
return true;
}
}

View file

@ -20,24 +20,31 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
public $type;
/**
*
* @param array $args
*/
public function __construct($args = array()) {
$defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
$args = wp_parse_args($args, $defaults);
public function __construct( $args = array() ) {
$defaults = array(
'type' => 'web',
'url' => '',
'plugin' => '',
'nonce' => '',
'title' => '',
);
$args = wp_parse_args( $args, $defaults );
$this->type = $args['type'];
$this->api = isset($args['api']) ? $args['api'] : array();
$this->api = isset( $args['api'] ) ? $args['api'] : array();
parent::__construct($args);
parent::__construct( $args );
}
/**
*/
public function before() {
if ( !empty($this->api) )
$this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
if ( ! empty( $this->api ) ) {
/* translators: 1: name of API, 2: version of API */
$this->upgrader->strings['process_success'] = sprintf( __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' ), $this->api->name, $this->api->version );
}
}
/**
@ -47,11 +54,11 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
$install_actions = array();
$from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
$from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins';
if ( 'import' == $from ) {
$install_actions['activate_plugin'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin &amp; Run Importer' ) . '</a>';
} else if ( 'press-this' == $from ) {
} elseif ( 'press-this' == $from ) {
$install_actions['activate_plugin'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&amp;from=press-this&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin &amp; Return to Press This' ) . '</a>';
} else {
$install_actions['activate_plugin'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>';
@ -72,7 +79,7 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
$install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>';
}
if ( ! $this->result || is_wp_error($this->result) ) {
if ( ! $this->result || is_wp_error( $this->result ) ) {
unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
} elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) ) {
unset( $install_actions['activate_plugin'] );
@ -83,11 +90,11 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
*
* @since 2.7.0
*
* @param array $install_actions Array of plugin action links.
* @param object $api Object containing WordPress.org API plugin data. Empty
* for non-API installs, such as when a plugin is installed
* via upload.
* @param string $plugin_file Path to the plugin file.
* @param string[] $install_actions Array of plugin action links.
* @param object $api Object containing WordPress.org API plugin data. Empty
* for non-API installs, such as when a plugin is installed
* via upload.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
*/
$install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );

View file

@ -16,55 +16,61 @@
* @see WP_Upgrader_Skin
*/
class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
public $plugin = '';
public $plugin_active = false;
public $plugin = '';
public $plugin_active = false;
public $plugin_network_active = false;
/**
*
* @param array $args
*/
public function __construct( $args = array() ) {
$defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
$args = wp_parse_args($args, $defaults);
$defaults = array(
'url' => '',
'plugin' => '',
'nonce' => '',
'title' => __( 'Update Plugin' ),
);
$args = wp_parse_args( $args, $defaults );
$this->plugin = $args['plugin'];
$this->plugin_active = is_plugin_active( $this->plugin );
$this->plugin_active = is_plugin_active( $this->plugin );
$this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
parent::__construct($args);
parent::__construct( $args );
}
/**
*/
public function after() {
$this->plugin = $this->upgrader->plugin_info();
if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
if ( ! empty( $this->plugin ) && ! is_wp_error( $this->result ) && $this->plugin_active ) {
// Currently used only when JS is off for a single plugin update?
echo '<iframe title="' . esc_attr__( 'Update progress' ) . '" style="border:0;overflow:hidden" width="100%" height="170" src="' . wp_nonce_url( 'update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ) . '"></iframe>';
}
$this->decrement_update_count( 'plugin' );
$update_actions = array(
'activate_plugin' => '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>',
'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>'
$update_actions = array(
'activate_plugin' => '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>',
'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>',
);
if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) )
if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) {
unset( $update_actions['activate_plugin'] );
}
/**
* Filters the list of action links available following a single plugin update.
*
* @since 2.7.0
*
* @param array $update_actions Array of plugin action links.
* @param string $plugin Path to the plugin file.
* @param string[] $update_actions Array of plugin action links.
* @param string $plugin Path to the plugin file relative to the plugins directory.
*/
$update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
if ( ! empty($update_actions) )
$this->feedback(implode(' | ', (array)$update_actions));
if ( ! empty( $update_actions ) ) {
$this->feedback( implode( ' | ', (array) $update_actions ) );
}
}
}

View file

@ -44,16 +44,16 @@ class Plugin_Upgrader extends WP_Upgrader {
* @since 2.8.0
*/
public function upgrade_strings() {
$this->strings['up_to_date'] = __('The plugin is at the latest version.');
$this->strings['no_package'] = __('Update package not available.');
$this->strings['up_to_date'] = __( 'The plugin is at the latest version.' );
$this->strings['no_package'] = __( 'Update package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __('Unpacking the update&#8230;');
$this->strings['remove_old'] = __('Removing the old version of the plugin&#8230;');
$this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
$this->strings['process_failed'] = __('Plugin update failed.');
$this->strings['process_success'] = __('Plugin updated successfully.');
$this->strings['process_bulk_success'] = __('Plugins updated successfully.');
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' );
$this->strings['remove_old'] = __( 'Removing the old version of the plugin&#8230;' );
$this->strings['remove_old_failed'] = __( 'Could not remove the old plugin.' );
$this->strings['process_failed'] = __( 'Plugin update failed.' );
$this->strings['process_success'] = __( 'Plugin updated successfully.' );
$this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' );
}
/**
@ -62,14 +62,14 @@ class Plugin_Upgrader extends WP_Upgrader {
* @since 2.8.0
*/
public function install_strings() {
$this->strings['no_package'] = __('Installation package not available.');
$this->strings['no_package'] = __( 'Installation package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __('Unpacking the package&#8230;');
$this->strings['installing_package'] = __('Installing the plugin&#8230;');
$this->strings['no_files'] = __('The plugin contains no files.');
$this->strings['process_failed'] = __('Plugin installation failed.');
$this->strings['process_success'] = __('Plugin installed successfully.');
$this->strings['unpack_package'] = __( 'Unpacking the package&#8230;' );
$this->strings['installing_package'] = __( 'Installing the plugin&#8230;' );
$this->strings['no_files'] = __( 'The plugin contains no files.' );
$this->strings['process_failed'] = __( 'Plugin installation failed.' );
$this->strings['process_success'] = __( 'Plugin installed successfully.' );
}
/**
@ -89,7 +89,7 @@ class Plugin_Upgrader extends WP_Upgrader {
*/
public function install( $package, $args = array() ) {
$defaults = array(
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -97,28 +97,31 @@ class Plugin_Upgrader extends WP_Upgrader {
$this->init();
$this->install_strings();
add_filter('upgrader_source_selection', array($this, 'check_package') );
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_plugins() knows about the new plugin.
add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
}
$this->run( array(
'package' => $package,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => false, // Do not overwrite files.
'clear_working' => true,
'hook_extra' => array(
'type' => 'plugin',
'action' => 'install',
$this->run(
array(
'package' => $package,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => false, // Do not overwrite files.
'clear_working' => true,
'hook_extra' => array(
'type' => 'plugin',
'action' => 'install',
),
)
) );
);
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
remove_filter('upgrader_source_selection', array($this, 'check_package') );
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
if ( ! $this->result || is_wp_error($this->result) )
if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}
// Force refresh of plugin update information
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
@ -132,7 +135,7 @@ class Plugin_Upgrader extends WP_Upgrader {
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
*
* @param string $plugin The basename path to the main plugin file.
* @param string $plugin Path to the plugin file relative to the plugins directory.
* @param array $args {
* Optional. Other arguments for upgrading a plugin package. Default empty array.
*
@ -143,7 +146,7 @@ class Plugin_Upgrader extends WP_Upgrader {
*/
public function upgrade( $plugin, $args = array() ) {
$defaults = array(
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -152,10 +155,10 @@ class Plugin_Upgrader extends WP_Upgrader {
$this->upgrade_strings();
$current = get_site_transient( 'update_plugins' );
if ( !isset( $current->response[ $plugin ] ) ) {
if ( ! isset( $current->response[ $plugin ] ) ) {
$this->skin->before();
$this->skin->set_result(false);
$this->skin->error('up_to_date');
$this->skin->set_result( false );
$this->skin->error( 'up_to_date' );
$this->skin->after();
return false;
}
@ -163,33 +166,36 @@ class Plugin_Upgrader extends WP_Upgrader {
// Get the URL to the zip file
$r = $current->response[ $plugin ];
add_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'), 10, 2);
add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4);
add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
//'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_plugins() knows about the new plugin.
add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
}
$this->run( array(
'package' => $r->package,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => true,
'clear_working' => true,
'hook_extra' => array(
'plugin' => $plugin,
'type' => 'plugin',
'action' => 'update',
),
) );
$this->run(
array(
'package' => $r->package,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => true,
'clear_working' => true,
'hook_extra' => array(
'plugin' => $plugin,
'type' => 'plugin',
'action' => 'update',
),
)
);
// Cleanup our hooks, in case something else does a upgrade on this connection.
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'));
remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
if ( ! $this->result || is_wp_error($this->result) )
if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}
// Force refresh of plugin update information
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
@ -203,18 +209,17 @@ class Plugin_Upgrader extends WP_Upgrader {
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
*
* @param array $plugins Array of the basename paths of the plugins' main files.
* @param array $args {
* Optional. Other arguments for upgrading several plugins at once. Default empty array.
* @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
* @param array $args {
* Optional. Other arguments for upgrading several plugins at once.
*
* @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
* Default true.
* @type bool $clear_update_cache Whether to clear the plugin updates cache if successful. Default true.
* }
* @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
*/
public function bulk_upgrade( $plugins, $args = array() ) {
$defaults = array(
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -225,12 +230,12 @@ class Plugin_Upgrader extends WP_Upgrader {
$current = get_site_transient( 'update_plugins' );
add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4);
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
$this->skin->header();
// Connect to the Filesystem first.
$res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
if ( ! $res ) {
$this->skin->footer();
return false;
@ -245,70 +250,79 @@ class Plugin_Upgrader extends WP_Upgrader {
* @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
*/
$maintenance = ( is_multisite() && ! empty( $plugins ) );
foreach ( $plugins as $plugin )
$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin] ) );
if ( $maintenance )
$this->maintenance_mode(true);
foreach ( $plugins as $plugin ) {
$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );
}
if ( $maintenance ) {
$this->maintenance_mode( true );
}
$results = array();
$this->update_count = count($plugins);
$this->update_count = count( $plugins );
$this->update_current = 0;
foreach ( $plugins as $plugin ) {
$this->update_current++;
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );
if ( !isset( $current->response[ $plugin ] ) ) {
$this->skin->set_result('up_to_date');
if ( ! isset( $current->response[ $plugin ] ) ) {
$this->skin->set_result( 'up_to_date' );
$this->skin->before();
$this->skin->feedback('up_to_date');
$this->skin->feedback( 'up_to_date' );
$this->skin->after();
$results[$plugin] = true;
$results[ $plugin ] = true;
continue;
}
// Get the URL to the zip file.
$r = $current->response[ $plugin ];
$this->skin->plugin_active = is_plugin_active($plugin);
$this->skin->plugin_active = is_plugin_active( $plugin );
$result = $this->run( array(
'package' => $r->package,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => true,
'clear_working' => true,
'is_multi' => true,
'hook_extra' => array(
'plugin' => $plugin
$result = $this->run(
array(
'package' => $r->package,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => true,
'clear_working' => true,
'is_multi' => true,
'hook_extra' => array(
'plugin' => $plugin,
),
)
) );
);
$results[$plugin] = $this->result;
$results[ $plugin ] = $this->result;
// Prevent credentials auth screen from displaying multiple times
if ( false === $result )
if ( false === $result ) {
break;
}
} //end foreach $plugins
$this->maintenance_mode(false);
$this->maintenance_mode( false );
// Force refresh of plugin update information.
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
do_action( 'upgrader_process_complete', $this, array(
'action' => 'update',
'type' => 'plugin',
'bulk' => true,
'plugins' => $plugins,
) );
do_action(
'upgrader_process_complete',
$this,
array(
'action' => 'update',
'type' => 'plugin',
'bulk' => true,
'plugins' => $plugins,
)
);
$this->skin->bulk_footer();
$this->skin->footer();
// Cleanup our hooks, in case something else does a upgrade on this connection.
remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
return $results;
}
@ -321,25 +335,27 @@ class Plugin_Upgrader extends WP_Upgrader {
*
* @since 3.3.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $source The path to the downloaded package source.
* @return string|WP_Error The source as passed, or a WP_Error object
* if no plugins were found.
*/
public function check_package($source) {
public function check_package( $source ) {
global $wp_filesystem;
if ( is_wp_error($source) )
if ( is_wp_error( $source ) ) {
return $source;
}
$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation.
$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
return $source;
}
// Check the folder contains at least 1 valid plugin.
$plugins_found = false;
$files = glob( $working_directory . '*.php' );
$files = glob( $working_directory . '*.php' );
if ( $files ) {
foreach ( $files as $file ) {
$info = get_plugin_data( $file, false, false );
@ -350,8 +366,9 @@ class Plugin_Upgrader extends WP_Upgrader {
}
}
if ( ! $plugins_found )
if ( ! $plugins_found ) {
return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
}
return $source;
}
@ -366,16 +383,19 @@ class Plugin_Upgrader extends WP_Upgrader {
* @return string|false The full path to the main plugin file, or false.
*/
public function plugin_info() {
if ( ! is_array($this->result) )
if ( ! is_array( $this->result ) ) {
return false;
if ( empty($this->result['destination_name']) )
}
if ( empty( $this->result['destination_name'] ) ) {
return false;
}
$plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
if ( empty($plugin) )
$plugin = get_plugins( '/' . $this->result['destination_name'] ); //Ensure to pass with leading slash
if ( empty( $plugin ) ) {
return false;
}
$pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
$pluginfiles = array_keys( $plugin ); //Assume the requested plugin is the first in the list
return $this->result['destination_name'] . '/' . $pluginfiles[0];
}
@ -392,22 +412,25 @@ class Plugin_Upgrader extends WP_Upgrader {
* @param array $plugin Plugin package arguments.
* @return bool|WP_Error The passed in $return param or WP_Error.
*/
public function deactivate_plugin_before_upgrade($return, $plugin) {
public function deactivate_plugin_before_upgrade( $return, $plugin ) {
if ( is_wp_error($return) ) //Bypass.
if ( is_wp_error( $return ) ) { //Bypass.
return $return;
}
// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it
if ( wp_doing_cron() )
if ( wp_doing_cron() ) {
return $return;
}
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
if ( empty($plugin) )
return new WP_Error('bad_request', $this->strings['bad_request']);
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
if ( empty( $plugin ) ) {
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
}
if ( is_plugin_active($plugin) ) {
if ( is_plugin_active( $plugin ) ) {
//Deactivate the plugin silently, Prevent deactivation hooks from running.
deactivate_plugins($plugin, true);
deactivate_plugins( $plugin, true );
}
return $return;
@ -421,38 +444,43 @@ class Plugin_Upgrader extends WP_Upgrader {
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param bool|WP_Error $removed
* @param string $local_destination
* @param string $remote_destination
* @param array $plugin
* @return WP_Error|bool
*/
public function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
global $wp_filesystem;
if ( is_wp_error($removed) )
if ( is_wp_error( $removed ) ) {
return $removed; //Pass errors through.
}
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
if ( empty($plugin) )
return new WP_Error('bad_request', $this->strings['bad_request']);
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
if ( empty( $plugin ) ) {
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
}
$plugins_dir = $wp_filesystem->wp_plugins_dir();
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
$plugins_dir = $wp_filesystem->wp_plugins_dir();
$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );
if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If it's already vanished.
if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { //If it's already vanished.
return $removed;
}
// If plugin is in its own directory, recursively delete the directory.
if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that it's not the root plugin folder
$deleted = $wp_filesystem->delete($this_plugin_dir, true);
else
$deleted = $wp_filesystem->delete($plugins_dir . $plugin);
if ( strpos( $plugin, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder
$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
} else {
$deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
}
if ( ! $deleted )
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
if ( ! $deleted ) {
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
}
return true;
}

View file

@ -20,84 +20,105 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin {
public $type;
/**
*
* @param array $args
*/
public function __construct($args = array()) {
$defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
$args = wp_parse_args($args, $defaults);
public function __construct( $args = array() ) {
$defaults = array(
'type' => 'web',
'url' => '',
'theme' => '',
'nonce' => '',
'title' => '',
);
$args = wp_parse_args( $args, $defaults );
$this->type = $args['type'];
$this->api = isset($args['api']) ? $args['api'] : array();
$this->api = isset( $args['api'] ) ? $args['api'] : array();
parent::__construct($args);
parent::__construct( $args );
}
/**
*/
public function before() {
if ( !empty($this->api) )
$this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
if ( ! empty( $this->api ) ) {
$this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version );
}
}
/**
*/
public function after() {
if ( empty($this->upgrader->result['destination_name']) )
if ( empty( $this->upgrader->result['destination_name'] ) ) {
return;
}
$theme_info = $this->upgrader->theme_info();
if ( empty( $theme_info ) )
if ( empty( $theme_info ) ) {
return;
}
$name = $theme_info->display('Name');
$name = $theme_info->display( 'Name' );
$stylesheet = $this->upgrader->result['destination_name'];
$template = $theme_info->get_template();
$activate_link = add_query_arg( array(
'action' => 'activate',
'template' => urlencode( $template ),
'stylesheet' => urlencode( $stylesheet ),
), admin_url('themes.php') );
$activate_link = add_query_arg(
array(
'action' => 'activate',
'template' => urlencode( $template ),
'stylesheet' => urlencode( $stylesheet ),
),
admin_url( 'themes.php' )
);
$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
$install_actions = array();
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$customize_url = add_query_arg(
$customize_url = add_query_arg(
array(
'theme' => urlencode( $stylesheet ),
'theme' => urlencode( $stylesheet ),
'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ),
),
admin_url( 'customize.php' )
);
$install_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
$install_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">';
$install_actions['preview'] .= '<span aria-hidden="true">' . __( 'Live Preview' ) . '</span>';
/* translators: %s: theme name */
$install_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
}
$install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
$install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink">';
$install_actions['activate'] .= '<span aria-hidden="true">' . __( 'Activate' ) . '</span>';
/* translators: %s: theme name */
$install_actions['activate'] .= '<span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) {
$install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
}
if ( $this->type == 'web' )
if ( $this->type == 'web' ) {
$install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>';
elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
} elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) {
$install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
}
if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) {
unset( $install_actions['activate'], $install_actions['preview'] );
}
/**
* Filters the list of action links available following a single theme installation.
*
* @since 2.8.0
*
* @param array $install_actions Array of theme action links.
* @param string[] $install_actions Array of theme action links.
* @param object $api Object containing WordPress.org API theme data.
* @param string $stylesheet Theme directory name.
* @param WP_Theme $theme_info Theme object.
*/
$install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
if ( ! empty($install_actions) )
$this->feedback(implode(' | ', (array)$install_actions));
if ( ! empty( $install_actions ) ) {
$this->feedback( implode( ' | ', (array) $install_actions ) );
}
}
}

View file

@ -19,16 +19,20 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
public $theme = '';
/**
*
* @param array $args
*/
public function __construct($args = array()) {
$defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
$args = wp_parse_args($args, $defaults);
public function __construct( $args = array() ) {
$defaults = array(
'url' => '',
'theme' => '',
'nonce' => '',
'title' => __( 'Update Theme' ),
);
$args = wp_parse_args( $args, $defaults );
$this->theme = $args['theme'];
parent::__construct($args);
parent::__construct( $args );
}
/**
@ -38,37 +42,50 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
$update_actions = array();
if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
$name = $theme_info->display('Name');
$name = $theme_info->display( 'Name' );
$stylesheet = $this->upgrader->result['destination_name'];
$template = $theme_info->get_template();
$activate_link = add_query_arg( array(
'action' => 'activate',
'template' => urlencode( $template ),
'stylesheet' => urlencode( $stylesheet ),
), admin_url('themes.php') );
$activate_link = add_query_arg(
array(
'action' => 'activate',
'template' => urlencode( $template ),
'stylesheet' => urlencode( $stylesheet ),
),
admin_url( 'themes.php' )
);
$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
$customize_url = add_query_arg(
array(
'theme' => urlencode( $stylesheet ),
'theme' => urlencode( $stylesheet ),
'return' => urlencode( admin_url( 'themes.php' ) ),
),
admin_url( 'customize.php' )
);
if ( get_stylesheet() == $stylesheet ) {
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
$update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">';
$update_actions['preview'] .= '<span aria-hidden="true">' . __( 'Customize' ) . '</span>';
/* translators: %s: theme name */
$update_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
}
} elseif ( current_user_can( 'switch_themes' ) ) {
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
$update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">';
$update_actions['preview'] .= '<span aria-hidden="true">' . __( 'Live Preview' ) . '</span>';
/* translators: %s: theme name */
$update_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
}
$update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
$update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink">';
$update_actions['activate'] .= '<span aria-hidden="true">' . __( 'Activate' ) . '</span>';
/* translators: %s: theme name */
$update_actions['activate'] .= '<span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
}
if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) {
unset( $update_actions['preview'], $update_actions['activate'] );
}
}
$update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
@ -78,12 +95,13 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
*
* @since 2.8.0
*
* @param array $update_actions Array of theme action links.
* @param string $theme Theme directory name.
* @param string[] $update_actions Array of theme action links.
* @param string $theme Theme directory name.
*/
$update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
if ( ! empty($update_actions) )
$this->feedback(implode(' | ', (array)$update_actions));
if ( ! empty( $update_actions ) ) {
$this->feedback( implode( ' | ', (array) $update_actions ) );
}
}
}

View file

@ -43,15 +43,15 @@ class Theme_Upgrader extends WP_Upgrader {
* @since 2.8.0
*/
public function upgrade_strings() {
$this->strings['up_to_date'] = __('The theme is at the latest version.');
$this->strings['no_package'] = __('Update package not available.');
$this->strings['up_to_date'] = __( 'The theme is at the latest version.' );
$this->strings['no_package'] = __( 'Update package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __('Unpacking the update&#8230;');
$this->strings['remove_old'] = __('Removing the old version of the theme&#8230;');
$this->strings['remove_old_failed'] = __('Could not remove the old theme.');
$this->strings['process_failed'] = __('Theme update failed.');
$this->strings['process_success'] = __('Theme updated successfully.');
$this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' );
$this->strings['remove_old'] = __( 'Removing the old version of the theme&#8230;' );
$this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' );
$this->strings['process_failed'] = __( 'Theme update failed.' );
$this->strings['process_success'] = __( 'Theme updated successfully.' );
}
/**
@ -60,23 +60,23 @@ class Theme_Upgrader extends WP_Upgrader {
* @since 2.8.0
*/
public function install_strings() {
$this->strings['no_package'] = __('Installation package not available.');
$this->strings['no_package'] = __( 'Installation package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s&#8230;' ), '<span class="code">%s</span>' );
$this->strings['unpack_package'] = __('Unpacking the package&#8230;');
$this->strings['installing_package'] = __('Installing the theme&#8230;');
$this->strings['no_files'] = __('The theme contains no files.');
$this->strings['process_failed'] = __('Theme installation failed.');
$this->strings['process_success'] = __('Theme installed successfully.');
$this->strings['unpack_package'] = __( 'Unpacking the package&#8230;' );
$this->strings['installing_package'] = __( 'Installing the theme&#8230;' );
$this->strings['no_files'] = __( 'The theme contains no files.' );
$this->strings['process_failed'] = __( 'Theme installation failed.' );
$this->strings['process_success'] = __( 'Theme installed successfully.' );
/* translators: 1: theme name, 2: version */
$this->strings['process_success_specific'] = __('Successfully installed the theme <strong>%1$s %2$s</strong>.');
$this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed&#8230;');
$this->strings['process_success_specific'] = __( 'Successfully installed the theme <strong>%1$s %2$s</strong>.' );
$this->strings['parent_theme_search'] = __( 'This theme requires a parent theme. Checking if it is installed&#8230;' );
/* translators: 1: theme name, 2: version */
$this->strings['parent_theme_prepare_install'] = __('Preparing to install <strong>%1$s %2$s</strong>&#8230;');
$this->strings['parent_theme_prepare_install'] = __( 'Preparing to install <strong>%1$s %2$s</strong>&#8230;' );
/* translators: 1: theme name, 2: version */
$this->strings['parent_theme_currently_installed'] = __('The parent theme, <strong>%1$s %2$s</strong>, is currently installed.');
$this->strings['parent_theme_currently_installed'] = __( 'The parent theme, <strong>%1$s %2$s</strong>, is currently installed.' );
/* translators: 1: theme name, 2: version */
$this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, <strong>%1$s %2$s</strong>.');
$this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' );
/* translators: %s: theme name */
$this->strings['parent_theme_not_found'] = sprintf( __( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' );
}
@ -97,56 +97,69 @@ class Theme_Upgrader extends WP_Upgrader {
// Check to see if we need to install a parent theme
$theme_info = $this->theme_info();
if ( ! $theme_info->parent() )
if ( ! $theme_info->parent() ) {
return $install_result;
}
$this->skin->feedback( 'parent_theme_search' );
if ( ! $theme_info->parent()->errors() ) {
$this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display('Name'), $theme_info->parent()->display('Version') );
$this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) );
// We already have the theme, fall through.
return $install_result;
}
// We don't have the parent theme, let's install it.
$api = themes_api('theme_information', array('slug' => $theme_info->get('Template'), 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
$api = themes_api(
'theme_information',
array(
'slug' => $theme_info->get( 'Template' ),
'fields' => array(
'sections' => false,
'tags' => false,
),
)
); //Save on a bit of bandwidth.
if ( ! $api || is_wp_error($api) ) {
$this->skin->feedback( 'parent_theme_not_found', $theme_info->get('Template') );
if ( ! $api || is_wp_error( $api ) ) {
$this->skin->feedback( 'parent_theme_not_found', $theme_info->get( 'Template' ) );
// Don't show activate or preview actions after installation
add_filter('install_theme_complete_actions', array($this, 'hide_activate_preview_actions') );
add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) );
return $install_result;
}
// Backup required data we're going to override:
$child_api = $this->skin->api;
$child_api = $this->skin->api;
$child_success_message = $this->strings['process_success'];
// Override them
$this->skin->api = $api;
$this->skin->api = $api;
$this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version);
$this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version);
$this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version );
add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme.
add_filter( 'install_theme_complete_actions', '__return_false', 999 ); // Don't show any actions after installing the theme.
// Install the parent theme
$parent_result = $this->run( array(
'package' => $api->download_link,
'destination' => get_theme_root(),
'clear_destination' => false, //Do not overwrite files.
'clear_working' => true
) );
$parent_result = $this->run(
array(
'package' => $api->download_link,
'destination' => get_theme_root(),
'clear_destination' => false, //Do not overwrite files.
'clear_working' => true,
)
);
if ( is_wp_error($parent_result) )
add_filter('install_theme_complete_actions', array($this, 'hide_activate_preview_actions') );
if ( is_wp_error( $parent_result ) ) {
add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) );
}
// Start cleaning up after the parents installation
remove_filter('install_theme_complete_actions', '__return_false', 999);
remove_filter( 'install_theme_complete_actions', '__return_false', 999 );
// Reset child's result and data
$this->result = $child_result;
$this->skin->api = $child_api;
$this->result = $child_result;
$this->skin->api = $child_api;
$this->strings['process_success'] = $child_success_message;
return $install_result;
@ -165,7 +178,7 @@ class Theme_Upgrader extends WP_Upgrader {
* @return array
*/
public function hide_activate_preview_actions( $actions ) {
unset($actions['activate'], $actions['preview']);
unset( $actions['activate'], $actions['preview'] );
return $actions;
}
@ -187,7 +200,7 @@ class Theme_Upgrader extends WP_Upgrader {
*/
public function install( $package, $args = array() ) {
$defaults = array(
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -195,30 +208,33 @@ class Theme_Upgrader extends WP_Upgrader {
$this->init();
$this->install_strings();
add_filter('upgrader_source_selection', array($this, 'check_package') );
add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3);
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_themes() knows about the new theme.
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
}
$this->run( array(
'package' => $package,
'destination' => get_theme_root(),
'clear_destination' => false, //Do not overwrite files.
'clear_working' => true,
'hook_extra' => array(
'type' => 'theme',
'action' => 'install',
),
) );
$this->run(
array(
'package' => $package,
'destination' => get_theme_root(),
'clear_destination' => false, //Do not overwrite files.
'clear_working' => true,
'hook_extra' => array(
'type' => 'theme',
'action' => 'install',
),
)
);
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
remove_filter('upgrader_source_selection', array($this, 'check_package') );
remove_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'));
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) );
if ( ! $this->result || is_wp_error($this->result) )
if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}
// Refresh the Theme Update information
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
@ -243,7 +259,7 @@ class Theme_Upgrader extends WP_Upgrader {
*/
public function upgrade( $theme, $args = array() ) {
$defaults = array(
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -253,9 +269,9 @@ class Theme_Upgrader extends WP_Upgrader {
// Is an update available?
$current = get_site_transient( 'update_themes' );
if ( !isset( $current->response[ $theme ] ) ) {
if ( ! isset( $current->response[ $theme ] ) ) {
$this->skin->before();
$this->skin->set_result(false);
$this->skin->set_result( false );
$this->skin->error( 'up_to_date' );
$this->skin->after();
return false;
@ -263,33 +279,36 @@ class Theme_Upgrader extends WP_Upgrader {
$r = $current->response[ $theme ];
add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2);
add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2);
add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);
add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 );
add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 );
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_themes() knows about the new theme.
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
}
$this->run( array(
'package' => $r['package'],
'destination' => get_theme_root( $theme ),
'clear_destination' => true,
'clear_working' => true,
'hook_extra' => array(
'theme' => $theme,
'type' => 'theme',
'action' => 'update',
),
) );
$this->run(
array(
'package' => $r['package'],
'destination' => get_theme_root( $theme ),
'clear_destination' => true,
'clear_working' => true,
'hook_extra' => array(
'theme' => $theme,
'type' => 'theme',
'action' => 'update',
),
)
);
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
remove_filter('upgrader_pre_install', array($this, 'current_before'));
remove_filter('upgrader_post_install', array($this, 'current_after'));
remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) );
remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) );
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) );
if ( ! $this->result || is_wp_error($this->result) )
if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
@ -302,8 +321,8 @@ class Theme_Upgrader extends WP_Upgrader {
* @since 3.0.0
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
*
* @param array $themes The theme slugs.
* @param array $args {
* @param string[] $themes Array of the theme slugs.
* @param array $args {
* Optional. Other arguments for upgrading several themes at once. Default empty array.
*
* @type bool $clear_update_cache Whether to clear the update cache if successful.
@ -313,7 +332,7 @@ class Theme_Upgrader extends WP_Upgrader {
*/
public function bulk_upgrade( $themes, $args = array() ) {
$defaults = array(
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@ -324,14 +343,14 @@ class Theme_Upgrader extends WP_Upgrader {
$current = get_site_transient( 'update_themes' );
add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2);
add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2);
add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);
add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 );
add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 );
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 );
$this->skin->header();
// Connect to the Filesystem first.
$res = $this->fs_connect( array(WP_CONTENT_DIR) );
$res = $this->fs_connect( array( WP_CONTENT_DIR ) );
if ( ! $res ) {
$this->skin->footer();
return false;
@ -344,71 +363,80 @@ class Theme_Upgrader extends WP_Upgrader {
// - a theme with an update available is currently in use.
// @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
$maintenance = ( is_multisite() && ! empty( $themes ) );
foreach ( $themes as $theme )
foreach ( $themes as $theme ) {
$maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
if ( $maintenance )
$this->maintenance_mode(true);
}
if ( $maintenance ) {
$this->maintenance_mode( true );
}
$results = array();
$this->update_count = count($themes);
$this->update_count = count( $themes );
$this->update_current = 0;
foreach ( $themes as $theme ) {
$this->update_current++;
$this->skin->theme_info = $this->theme_info($theme);
$this->skin->theme_info = $this->theme_info( $theme );
if ( !isset( $current->response[ $theme ] ) ) {
$this->skin->set_result(true);
if ( ! isset( $current->response[ $theme ] ) ) {
$this->skin->set_result( true );
$this->skin->before();
$this->skin->feedback( 'up_to_date' );
$this->skin->after();
$results[$theme] = true;
$results[ $theme ] = true;
continue;
}
// Get the URL to the zip file
$r = $current->response[ $theme ];
$result = $this->run( array(
'package' => $r['package'],
'destination' => get_theme_root( $theme ),
'clear_destination' => true,
'clear_working' => true,
'is_multi' => true,
'hook_extra' => array(
'theme' => $theme
),
) );
$result = $this->run(
array(
'package' => $r['package'],
'destination' => get_theme_root( $theme ),
'clear_destination' => true,
'clear_working' => true,
'is_multi' => true,
'hook_extra' => array(
'theme' => $theme,
),
)
);
$results[$theme] = $this->result;
$results[ $theme ] = $this->result;
// Prevent credentials auth screen from displaying multiple times
if ( false === $result )
if ( false === $result ) {
break;
}
} //end foreach $plugins
$this->maintenance_mode(false);
$this->maintenance_mode( false );
// Refresh the Theme Update information
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
do_action( 'upgrader_process_complete', $this, array(
'action' => 'update',
'type' => 'theme',
'bulk' => true,
'themes' => $themes,
) );
do_action(
'upgrader_process_complete',
$this,
array(
'action' => 'update',
'type' => 'theme',
'bulk' => true,
'themes' => $themes,
)
);
$this->skin->bulk_footer();
$this->skin->footer();
// Cleanup our hooks, in case something else does a upgrade on this connection.
remove_filter('upgrader_pre_install', array($this, 'current_before'));
remove_filter('upgrader_post_install', array($this, 'current_after'));
remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) );
remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) );
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) );
return $results;
}
@ -422,7 +450,7 @@ class Theme_Upgrader extends WP_Upgrader {
*
* @since 3.3.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $source The full path to the package source.
* @return string|WP_Error The source or a WP_Error.
@ -430,30 +458,44 @@ class Theme_Upgrader extends WP_Upgrader {
public function check_package( $source ) {
global $wp_filesystem;
if ( is_wp_error($source) )
if ( is_wp_error( $source ) ) {
return $source;
}
// Check the folder contains a valid theme
$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation.
$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
return $source;
}
// A proper archive should have a style.css file in the single subdirectory
if ( ! file_exists( $working_directory . 'style.css' ) ) {
return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'],
/* translators: %s: style.css */
sprintf( __( 'The theme is missing the %s stylesheet.' ),
return new WP_Error(
'incompatible_archive_theme_no_style',
$this->strings['incompatible_archive'],
sprintf(
/* translators: %s: style.css */
__( 'The theme is missing the %s stylesheet.' ),
'<code>style.css</code>'
)
);
}
$info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
$info = get_file_data(
$working_directory . 'style.css',
array(
'Name' => 'Theme Name',
'Template' => 'Template',
)
);
if ( empty( $info['Name'] ) ) {
return new WP_Error( 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'],
/* translators: %s: style.css */
sprintf( __( 'The %s stylesheet doesn&#8217;t contain a valid theme header.' ),
return new WP_Error(
'incompatible_archive_theme_no_name',
$this->strings['incompatible_archive'],
sprintf(
/* translators: %s: style.css */
__( 'The %s stylesheet doesn&#8217;t contain a valid theme header.' ),
'<code>style.css</code>'
)
);
@ -461,9 +503,12 @@ class Theme_Upgrader extends WP_Upgrader {
// If it's not a child theme, it must have at least an index.php to be legit.
if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) {
return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'],
/* translators: %s: index.php */
sprintf( __( 'The theme is missing the %s file.' ),
return new WP_Error(
'incompatible_archive_theme_no_index',
$this->strings['incompatible_archive'],
sprintf(
/* translators: %s: index.php */
__( 'The theme is missing the %s file.' ),
'<code>index.php</code>'
)
);
@ -484,17 +529,20 @@ class Theme_Upgrader extends WP_Upgrader {
* @param array $theme
* @return bool|WP_Error
*/
public function current_before($return, $theme) {
if ( is_wp_error($return) )
public function current_before( $return, $theme ) {
if ( is_wp_error( $return ) ) {
return $return;
}
$theme = isset($theme['theme']) ? $theme['theme'] : '';
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
if ( $theme != get_stylesheet() ) //If not current
if ( $theme != get_stylesheet() ) { //If not current
return $return;
}
//Change to maintenance mode now.
if ( ! $this->bulk )
$this->maintenance_mode(true);
if ( ! $this->bulk ) {
$this->maintenance_mode( true );
}
return $return;
}
@ -511,14 +559,16 @@ class Theme_Upgrader extends WP_Upgrader {
* @param array $theme
* @return bool|WP_Error
*/
public function current_after($return, $theme) {
if ( is_wp_error($return) )
public function current_after( $return, $theme ) {
if ( is_wp_error( $return ) ) {
return $return;
}
$theme = isset($theme['theme']) ? $theme['theme'] : '';
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
if ( $theme != get_stylesheet() ) // If not current
if ( $theme != get_stylesheet() ) { // If not current
return $return;
}
// Ensure stylesheet name hasn't changed after the upgrade:
if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
@ -528,8 +578,9 @@ class Theme_Upgrader extends WP_Upgrader {
}
//Time to remove maintenance mode
if ( ! $this->bulk )
$this->maintenance_mode(false);
if ( ! $this->bulk ) {
$this->maintenance_mode( false );
}
return $return;
}
@ -552,17 +603,20 @@ class Theme_Upgrader extends WP_Upgrader {
public function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
global $wp_filesystem;
if ( is_wp_error( $removed ) )
if ( is_wp_error( $removed ) ) {
return $removed; // Pass errors through.
}
if ( ! isset( $theme['theme'] ) )
if ( ! isset( $theme['theme'] ) ) {
return $removed;
}
$theme = $theme['theme'];
$theme = $theme['theme'];
$themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) )
if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) {
return false;
}
}
return true;
@ -579,13 +633,14 @@ class Theme_Upgrader extends WP_Upgrader {
* @return WP_Theme|false The theme's info object, or false `$theme` is not supplied
* and the last result isn't set.
*/
public function theme_info($theme = null) {
public function theme_info( $theme = null ) {
if ( empty($theme) ) {
if ( !empty($this->result['destination_name']) )
if ( empty( $theme ) ) {
if ( ! empty( $this->result['destination_name'] ) ) {
$theme = $this->result['destination_name'];
else
} else {
return false;
}
}
return wp_get_theme( $theme );
}

View file

@ -18,7 +18,10 @@
*/
class Walker_Category_Checklist extends Walker {
public $tree_type = 'category';
public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
public $db_fields = array(
'parent' => 'parent',
'id' => 'term_id',
); //TODO: decouple this
/**
* Starts the list before the elements are added.
@ -32,7 +35,7 @@ class Walker_Category_Checklist extends Walker {
* @param array $args An array of arguments. @see wp_terms_checklist()
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$indent = str_repeat( "\t", $depth );
$output .= "$indent<ul class='children'>\n";
}
@ -48,7 +51,7 @@ class Walker_Category_Checklist extends Walker {
* @param array $args An array of arguments. @see wp_terms_checklist()
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$indent = str_repeat( "\t", $depth );
$output .= "$indent</ul>\n";
}
@ -79,13 +82,13 @@ class Walker_Category_Checklist extends Walker {
}
$args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
$class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
$class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
$args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
if ( ! empty( $args['list_only'] ) ) {
$aria_checked = 'false';
$inner_class = 'category';
$inner_class = 'category';
if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
$inner_class .= ' selected';
@ -100,7 +103,7 @@ class Walker_Category_Checklist extends Walker {
} else {
/** This filter is documented in wp-includes/category-template.php */
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';

View file

@ -15,7 +15,6 @@
*/
class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
/**
*
* @param array $fields
*/
public function __construct( $fields = false ) {
@ -36,7 +35,7 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
* @param array $args Not used.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class='children'>\n";
}
@ -52,7 +51,7 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
* @param array $args Not used.
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent</ul>";
}
@ -74,9 +73,9 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $_nav_menu_placeholder;
$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
$possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
$possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
@ -84,34 +83,37 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
$output .= '<label class="menu-item-title">';
$output .= '<input type="checkbox" class="menu-item-checkbox';
if ( ! empty( $item->front_or_home ) )
if ( ! empty( $item->front_or_home ) ) {
$output .= ' add-to-top';
}
$output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
$output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="' . esc_attr( $item->object_id ) . '" /> ';
if ( ! empty( $item->label ) ) {
$title = $item->label;
} elseif ( isset( $item->post_type ) ) {
/** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( 'the_title', $item->post_title, $item->ID );
if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title )
if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title ) {
/* translators: %s: front page title */
$title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $title );
}
}
$output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
$output .= '</label>';
$output .= '</label>';
// Menu item hidden fields
$output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />';
$output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />';
$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />';
$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
$output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="' . esc_attr( $item->object ) . '" />';
$output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="' . esc_attr( $item->menu_item_parent ) . '" />';
$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="' . esc_attr( $item->type ) . '" />';
$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="' . esc_attr( $item->title ) . '" />';
$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="' . esc_attr( $item->url ) . '" />';
$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="' . esc_attr( $item->target ) . '" />';
$output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="' . esc_attr( $item->attr_title ) . '" />';
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="' . esc_attr( implode( ' ', $item->classes ) ) . '" />';
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="' . esc_attr( $item->xfn ) . '" />';
}
} // Walker_Nav_Menu_Checklist

View file

@ -60,7 +60,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
ob_start();
$item_id = esc_attr( $item->ID );
$item_id = esc_attr( $item->ID );
$removed_args = array(
'action',
'customlink-tab',
@ -73,11 +73,12 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
$original_title = false;
if ( 'taxonomy' == $item->type ) {
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
if ( is_wp_error( $original_title ) )
if ( is_wp_error( $original_title ) ) {
$original_title = false;
}
} elseif ( 'post_type' == $item->type ) {
$original_object = get_post( $item->object_id );
$original_title = get_the_title( $original_object->ID );
$original_title = get_the_title( $original_object->ID );
} elseif ( 'post_type_archive' == $item->type ) {
$original_object = get_post_type_object( $item->object );
if ( $original_object ) {
@ -88,7 +89,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
$classes = array(
'menu-item menu-item-depth-' . $depth,
'menu-item-' . esc_attr( $item->object ),
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
);
$title = $item->title;
@ -100,52 +101,59 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
$classes[] = 'pending';
/* translators: %s: title of menu item in draft status */
$title = sprintf( __('%s (Pending)'), $item->title );
$title = sprintf( __( '%s (Pending)' ), $item->title );
}
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
$submenu_text = '';
if ( 0 == $depth )
if ( 0 == $depth ) {
$submenu_text = 'style="display: none;"';
}
?>
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>">
<div class="menu-item-bar">
<div class="menu-item-handle">
<span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
<span class="item-controls">
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
<span class="item-order hide-if-js">
<a href="<?php
<a href="
<?php
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'move-up-menu-item',
'action' => 'move-up-menu-item',
'menu-item' => $item_id,
),
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
),
'move-menu_item'
);
?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up' ) ?>">&#8593;</a>
?>
" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up' ); ?>">&#8593;</a>
|
<a href="<?php
<a href="
<?php
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'move-down-menu-item',
'action' => 'move-down-menu-item',
'menu-item' => $item_id,
),
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
),
'move-menu_item'
);
?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down' ) ?>">&#8595;</a>
?>
" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down' ); ?>">&#8595;</a>
</span>
<a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php
echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
?>" aria-label="<?php esc_attr_e( 'Edit menu item' ); ?>"><span class="screen-reader-text"><?php _e( 'Edit' ); ?></span></a>
<a class="item-edit" id="edit-<?php echo $item_id; ?>" href="
<?php
echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
?>
" aria-label="<?php esc_attr_e( 'Edit menu item' ); ?>"><span class="screen-reader-text"><?php _e( 'Edit' ); ?></span></a>
</span>
</div>
</div>
@ -180,7 +188,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
<p class="field-css-classes description description-thin">
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
<?php _e( 'CSS Classes (optional)' ); ?><br />
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $item->classes ) ); ?>" />
</label>
</p>
<p class="field-xfn description description-thin">
@ -193,7 +201,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
<?php _e( 'Description' ); ?><br />
<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
<span class="description"><?php _e( 'The description will be displayed in the menu if the current theme supports it.' ); ?></span>
</label>
</p>
@ -209,21 +217,38 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
<div class="menu-item-actions description-wide submitbox">
<?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
<p class="link-to-original">
<?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
<?php
/* translators: %s: original title */
printf( __( 'Original: %s' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' );
?>
</p>
<?php endif; ?>
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
echo wp_nonce_url(
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="
<?php
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'delete-menu-item',
'menu-item' => $item_id,
),
admin_url( 'nav-menus.php' )
),
'delete-menu_item_' . $item_id
);
?>
"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="
<?php
echo esc_url(
add_query_arg(
array(
'action' => 'delete-menu-item',
'menu-item' => $item_id,
'edit-menu-item' => $item_id,
'cancel' => time(),
),
admin_url( 'nav-menus.php' )
),
'delete-menu_item_' . $item_id
); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
)
);
?>
#menu-item-settings-<?php echo $item_id; ?>"><?php _e( 'Cancel' ); ?></a>
</div>
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />

View file

@ -61,8 +61,10 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
$messages = array();
foreach ( $this->errors->get_error_codes() as $error_code ) {
if ( $this->errors->get_error_data( $error_code ) && is_string( $this->errors->get_error_data( $error_code ) ) ) {
$messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $this->errors->get_error_data( $error_code ) ) );
$error_data = $this->errors->get_error_data( $error_code );
if ( $error_data && is_string( $error_data ) ) {
$messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $error_data ) );
} else {
$messages[] = $this->errors->get_error_message( $error_code );
}
@ -95,7 +97,7 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
// Count existing errors to generate an unique error code.
$errors_count = count( $this->errors->get_error_codes() );
$this->errors->add( 'unknown_upgrade_error_' . $errors_count + 1 , $string );
$this->errors->add( 'unknown_upgrade_error_' . $errors_count + 1, $string );
} elseif ( is_wp_error( $errors ) ) {
foreach ( $errors->get_error_codes() as $error_code ) {
$this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) );

View file

@ -29,11 +29,13 @@ class WP_Automatic_Updater {
*/
public function is_disabled() {
// Background updates are disabled if you don't want file changes.
if ( ! wp_is_file_mod_allowed( 'automatic_updater' ) )
if ( ! wp_is_file_mod_allowed( 'automatic_updater' ) ) {
return true;
}
if ( wp_installing() )
if ( wp_installing() ) {
return true;
}
// More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters.
$disabled = defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED;
@ -71,10 +73,11 @@ class WP_Automatic_Updater {
*/
public function is_vcs_checkout( $context ) {
$context_dirs = array( untrailingslashit( $context ) );
if ( $context !== ABSPATH )
if ( $context !== ABSPATH ) {
$context_dirs[] = untrailingslashit( ABSPATH );
}
$vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' );
$vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' );
$check_dirs = array();
foreach ( $context_dirs as $context_dir ) {
@ -83,10 +86,11 @@ class WP_Automatic_Updater {
$check_dirs[] = $context_dir;
// Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here.
if ( $context_dir == dirname( $context_dir ) )
if ( $context_dir == dirname( $context_dir ) ) {
break;
}
// Continue one level at a time.
// Continue one level at a time.
} while ( $context_dir = dirname( $context_dir ) );
}
@ -95,8 +99,9 @@ class WP_Automatic_Updater {
// Search all directories we've found for evidence of version control.
foreach ( $vcs_dirs as $vcs_dir ) {
foreach ( $check_dirs as $check_dir ) {
if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) )
if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) {
break 2;
}
}
}
@ -131,8 +136,9 @@ class WP_Automatic_Updater {
// Used to see if WP_Filesystem is set up to allow unattended updates.
$skin = new Automatic_Upgrader_Skin;
if ( $this->is_disabled() )
if ( $this->is_disabled() ) {
return false;
}
// Only relax the filesystem checks when the update doesn't include new files
$allow_relaxed_file_ownership = false;
@ -142,16 +148,18 @@ class WP_Automatic_Updater {
// If we can't do an auto core update, we may still be able to email the user.
if ( ! $skin->request_filesystem_credentials( false, $context, $allow_relaxed_file_ownership ) || $this->is_vcs_checkout( $context ) ) {
if ( 'core' == $type )
if ( 'core' == $type ) {
$this->send_core_update_notification_email( $item );
}
return false;
}
// Next up, is this an item we can update?
if ( 'core' == $type )
if ( 'core' == $type ) {
$update = Core_Upgrader::should_update_to_version( $item->current );
else
} else {
$update = ! empty( $item->autoupdate );
}
/**
* Filters whether to automatically update core, a plugin, a theme, or a language.
@ -163,7 +171,7 @@ class WP_Automatic_Updater {
* by default, while translations and minor and development versions for core
* are updated by default.
*
* See the {@see 'allow_dev_auto_core_updates', {@see 'allow_minor_auto_core_updates'},
* See the {@see 'allow_dev_auto_core_updates'}, {@see 'allow_minor_auto_core_updates'},
* and {@see 'allow_major_auto_core_updates'} filters for a more straightforward way to
* adjust core updates.
*
@ -175,8 +183,9 @@ class WP_Automatic_Updater {
$update = apply_filters( "auto_update_{$type}", $update, $item );
if ( ! $update ) {
if ( 'core' == $type )
if ( 'core' == $type ) {
$this->send_core_update_notification_email( $item );
}
return false;
}
@ -185,13 +194,15 @@ class WP_Automatic_Updater {
global $wpdb;
$php_compat = version_compare( phpversion(), $item->php_version, '>=' );
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
$mysql_compat = true;
else
} else {
$mysql_compat = version_compare( $wpdb->db_version(), $item->mysql_version, '>=' );
}
if ( ! $php_compat || ! $mysql_compat )
if ( ! $php_compat || ! $mysql_compat ) {
return false;
}
}
return true;
@ -208,8 +219,9 @@ class WP_Automatic_Updater {
$notified = get_site_option( 'auto_core_update_notified' );
// Don't notify if we've already notified the same email address of the same version.
if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current )
if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current ) {
return false;
}
// See if we need to notify users of a core update.
$notify = ! empty( $item->notify_email );
@ -233,8 +245,9 @@ class WP_Automatic_Updater {
* @param bool $notify Whether the site administrator is notified.
* @param object $item The update offer.
*/
if ( ! apply_filters( 'send_core_update_notification_email', $notify, $item ) )
if ( ! apply_filters( 'send_core_update_notification_email', $notify, $item ) ) {
return false;
}
$this->send_email( 'manual', $item );
return true;
@ -275,8 +288,9 @@ class WP_Automatic_Updater {
}
// Determine whether we can and should perform this update.
if ( ! $this->should_update( $type, $item, $context ) )
if ( ! $this->should_update( $type, $item, $context ) ) {
return false;
}
/**
* Fires immediately prior to an auto-update.
@ -293,24 +307,30 @@ class WP_Automatic_Updater {
$upgrader_item = $item;
switch ( $type ) {
case 'core':
/* translators: %s: WordPress version */
$skin->feedback( __( 'Updating to WordPress %s' ), $item->version );
/* translators: %s: WordPress version */
$item_name = sprintf( __( 'WordPress %s' ), $item->version );
break;
case 'theme':
$upgrader_item = $item->theme;
$theme = wp_get_theme( $upgrader_item );
$item_name = $theme->Get( 'Name' );
$theme = wp_get_theme( $upgrader_item );
$item_name = $theme->Get( 'Name' );
/* translators: %s: Theme name */
$skin->feedback( __( 'Updating theme: %s' ), $item_name );
break;
case 'plugin':
$upgrader_item = $item->plugin;
$plugin_data = get_plugin_data( $context . '/' . $upgrader_item );
$item_name = $plugin_data['Name'];
$plugin_data = get_plugin_data( $context . '/' . $upgrader_item );
$item_name = $plugin_data['Name'];
/* translators: %s: Plugin name */
$skin->feedback( __( 'Updating plugin: %s' ), $item_name );
break;
case 'translation':
$language_item_name = $upgrader->get_name_for_update( $item );
/* translators: %s: Name of language item */
$item_name = sprintf( __( 'Translations for %s' ), $language_item_name );
/* translators: 1: Name of language item, 2: Language */
$skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)&#8230;' ), $language_item_name, $item->language ) );
break;
}
@ -321,15 +341,18 @@ class WP_Automatic_Updater {
}
// Boom, This sites about to get a whole new splash of paint!
$upgrade_result = $upgrader->upgrade( $upgrader_item, array(
'clear_update_cache' => false,
// Always use partial builds if possible for core updates.
'pre_check_md5' => false,
// Only available for core updates.
'attempt_rollback' => true,
// Allow relaxed file ownership in some scenarios
'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
) );
$upgrade_result = $upgrader->upgrade(
$upgrader_item,
array(
'clear_update_cache' => false,
// Always use partial builds if possible for core updates.
'pre_check_md5' => false,
// Only available for core updates.
'attempt_rollback' => true,
// Allow relaxed file ownership in some scenarios
'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
)
);
// If the filesystem is unavailable, false is returned.
if ( false === $upgrade_result ) {
@ -354,7 +377,7 @@ class WP_Automatic_Updater {
'item' => $item,
'result' => $upgrade_result,
'name' => $item_name,
'messages' => $skin->get_upgrade_messages()
'messages' => $skin->get_upgrade_messages(),
);
return $upgrade_result;
@ -366,14 +389,17 @@ class WP_Automatic_Updater {
* @since 3.7.0
*/
public function run() {
if ( $this->is_disabled() )
if ( $this->is_disabled() ) {
return;
}
if ( ! is_main_network() || ! is_main_site() )
if ( ! is_main_network() || ! is_main_site() ) {
return;
}
if ( ! WP_Upgrader::create_lock( 'auto_updater' ) )
if ( ! WP_Upgrader::create_lock( 'auto_updater' ) ) {
return;
}
// Don't automatically run these thins, as we'll handle it ourselves
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
@ -384,7 +410,7 @@ class WP_Automatic_Updater {
// Next, Plugins
wp_update_plugins(); // Check for Plugin updates
$plugin_updates = get_site_transient( 'update_plugins' );
if ( $plugin_updates && !empty( $plugin_updates->response ) ) {
if ( $plugin_updates && ! empty( $plugin_updates->response ) ) {
foreach ( $plugin_updates->response as $plugin ) {
$this->update( 'plugin', $plugin );
}
@ -395,7 +421,7 @@ class WP_Automatic_Updater {
// Next, those themes we all love
wp_update_themes(); // Check for Theme updates
$theme_updates = get_site_transient( 'update_themes' );
if ( $theme_updates && !empty( $theme_updates->response ) ) {
if ( $theme_updates && ! empty( $theme_updates->response ) ) {
foreach ( $theme_updates->response as $theme ) {
$this->update( 'theme', (object) $theme );
}
@ -407,8 +433,9 @@ class WP_Automatic_Updater {
wp_version_check(); // Check for Core updates
$core_update = find_core_auto_update();
if ( $core_update )
if ( $core_update ) {
$this->update( 'core', $core_update );
}
// Clean up, and check for any pending translations
// (Core_Upgrader checks for core updates)
@ -456,11 +483,13 @@ class WP_Automatic_Updater {
* install is a development version.
* Return false to avoid the email.
*/
if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) )
if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) ) {
$this->send_debug_email();
}
if ( ! empty( $this->update_results['core'] ) )
if ( ! empty( $this->update_results['core'] ) ) {
$this->after_core_update( $this->update_results['core'][0] );
}
/**
* Fires after all automatic updates have run.
@ -503,7 +532,7 @@ class WP_Automatic_Updater {
$critical = true;
} elseif ( $error_code === 'rollback_was_required' && is_wp_error( $result->get_error_data()->rollback ) ) {
// A rollback is only critical if it failed too.
$critical = true;
$critical = true;
$rollback_result = $result->get_error_data()->rollback;
} elseif ( false !== strpos( $error_code, 'do_rollback' ) ) {
$critical = true;
@ -538,29 +567,34 @@ class WP_Automatic_Updater {
* In fact, let's schedule a special update for an hour from now. (It's possible
* the issue could actually be on WordPress.org's side.) If that one fails, then email.
*/
$send = true;
$transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro', 'locked' );
if ( in_array( $error_code, $transient_failures ) && ! get_site_option( 'auto_core_update_failed' ) ) {
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' );
$send = false;
}
$n = get_site_option( 'auto_core_update_notified' );
// Don't notify if we've already notified the same email address of the same version of the same notification type.
if ( $n && 'fail' == $n['type'] && $n['email'] == get_site_option( 'admin_email' ) && $n['version'] == $core_update->current )
$send = true;
$transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro', 'locked' );
if ( in_array( $error_code, $transient_failures ) && ! get_site_option( 'auto_core_update_failed' ) ) {
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' );
$send = false;
}
update_site_option( 'auto_core_update_failed', array(
'attempted' => $core_update->current,
'current' => $wp_version,
'error_code' => $error_code,
'error_data' => $result->get_error_data(),
'timestamp' => time(),
'retry' => in_array( $error_code, $transient_failures ),
) );
$n = get_site_option( 'auto_core_update_notified' );
// Don't notify if we've already notified the same email address of the same version of the same notification type.
if ( $n && 'fail' == $n['type'] && $n['email'] == get_site_option( 'admin_email' ) && $n['version'] == $core_update->current ) {
$send = false;
}
if ( $send )
update_site_option(
'auto_core_update_failed',
array(
'attempted' => $core_update->current,
'current' => $wp_version,
'error_code' => $error_code,
'error_data' => $result->get_error_data(),
'timestamp' => time(),
'retry' => in_array( $error_code, $transient_failures ),
)
);
if ( $send ) {
$this->send_email( 'fail', $core_update, $result );
}
}
/**
@ -573,17 +607,21 @@ class WP_Automatic_Updater {
* @param mixed $result Optional. The result for the core update. Can be WP_Error.
*/
protected function send_email( $type, $core_update, $result = null ) {
update_site_option( 'auto_core_update_notified', array(
'type' => $type,
'email' => get_site_option( 'admin_email' ),
'version' => $core_update->current,
'timestamp' => time(),
) );
update_site_option(
'auto_core_update_notified',
array(
'type' => $type,
'email' => get_site_option( 'admin_email' ),
'version' => $core_update->current,
'timestamp' => time(),
)
);
$next_user_core_update = get_preferred_from_update_core();
// If the update transient is empty, use the update we just performed
if ( ! $next_user_core_update )
if ( ! $next_user_core_update ) {
$next_user_core_update = $core_update;
}
$newer_version_available = ( 'upgrade' == $next_user_core_update->response && version_compare( $next_user_core_update->version, $core_update->version, '>' ) );
/**
@ -597,27 +635,28 @@ class WP_Automatic_Updater {
* @param object $core_update The update offer that was attempted.
* @param mixed $result The result for the core update. Can be WP_Error.
*/
if ( 'manual' !== $type && ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) )
if ( 'manual' !== $type && ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) ) {
return;
}
switch ( $type ) {
case 'success' : // We updated.
case 'success': // We updated.
/* translators: 1: Site name, 2: WordPress version number. */
$subject = __( '[%1$s] Your site has updated to WordPress %2$s' );
break;
case 'fail' : // We tried to update but couldn't.
case 'manual' : // We can't update (and made no attempt).
case 'fail': // We tried to update but couldn't.
case 'manual': // We can't update (and made no attempt).
/* translators: 1: Site name, 2: WordPress version number. */
$subject = __( '[%1$s] WordPress %2$s is available. Please update!' );
break;
case 'critical' : // We tried to update, started to copy files, then things went wrong.
case 'critical': // We tried to update, started to copy files, then things went wrong.
/* translators: 1: Site name. */
$subject = __( '[%1$s] URGENT: Your site may be down due to a failed update' );
break;
default :
default:
return;
}
@ -628,18 +667,22 @@ class WP_Automatic_Updater {
$body = '';
switch ( $type ) {
case 'success' :
case 'success':
/* translators: 1: Home URL, 2: WordPress version */
$body .= sprintf( __( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ), home_url(), $core_update->current );
$body .= "\n\n";
if ( ! $newer_version_available )
if ( ! $newer_version_available ) {
$body .= __( 'No further action is needed on your part.' ) . ' ';
}
// Can only reference the About screen if their update was successful.
list( $about_version ) = explode( '-', $core_update->current, 2 );
$body .= sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version );
/* translators: %s: WordPress core version */
$body .= sprintf( __( 'For more on version %s, see the About WordPress screen:' ), $about_version );
$body .= "\n" . admin_url( 'about.php' );
if ( $newer_version_available ) {
/* translators: %s: WordPress core latest version */
$body .= "\n\n" . sprintf( __( 'WordPress %s is also now available.' ), $next_user_core_update->current ) . ' ';
$body .= __( 'Updating is easy and only takes a few moments:' );
$body .= "\n" . network_admin_url( 'update-core.php' );
@ -647,26 +690,31 @@ class WP_Automatic_Updater {
break;
case 'fail' :
case 'manual' :
case 'fail':
case 'manual':
/* translators: 1: Home URL, 2: WordPress core latest version */
$body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $next_user_core_update->current );
$body .= "\n\n";
// Don't show this message if there is a newer version available.
// Potential for confusion, and also not useful for them to know at this point.
if ( 'fail' == $type && ! $newer_version_available )
if ( 'fail' == $type && ! $newer_version_available ) {
$body .= __( 'We tried but were unable to update your site automatically.' ) . ' ';
}
$body .= __( 'Updating is easy and only takes a few moments:' );
$body .= "\n" . network_admin_url( 'update-core.php' );
break;
case 'critical' :
if ( $newer_version_available )
case 'critical':
if ( $newer_version_available ) {
/* translators: 1: Home URL, 2: WordPress core latest version */
$body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update WordPress to version %2$s.' ), home_url(), $core_update->current );
else
} else {
/* translators: 1: Home URL, 2: Core update version */
$body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.' ), home_url(), $core_update->current );
}
$body .= "\n\n" . __( "This means your site may be offline or broken. Don't panic; this can be fixed." );
@ -678,7 +726,8 @@ class WP_Automatic_Updater {
$critical_support = 'critical' === $type && ! empty( $core_update->support_email );
if ( $critical_support ) {
// Support offer if available.
$body .= "\n\n" . sprintf( __( "The WordPress team is willing to help you. Forward this email to %s and the team will work with you to make sure your site is working." ), $core_update->support_email );
/* translators: %s: Support e-mail */
$body .= "\n\n" . sprintf( __( 'The WordPress team is willing to help you. Forward this email to %s and the team will work with you to make sure your site is working.' ), $core_update->support_email );
} else {
// Add a note about the support forums.
$body .= "\n\n" . __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' );
@ -691,7 +740,7 @@ class WP_Automatic_Updater {
}
if ( $critical_support ) {
$body .= " " . __( "If you reach out to us, we'll also ensure you'll never have this problem again." );
$body .= ' ' . __( "If you reach out to us, we'll also ensure you'll never have this problem again." );
}
// If things are successful and we're now on the latest, mention plugins and themes if any are out of date.
@ -704,34 +753,41 @@ class WP_Automatic_Updater {
if ( 'critical' == $type && is_wp_error( $result ) ) {
$body .= "\n***\n\n";
/* translators: %s: WordPress version */
$body .= sprintf( __( 'Your site was running version %s.' ), get_bloginfo( 'version' ) );
$body .= ' ' . __( 'We have some data that describes the error your site encountered.' );
$body .= ' ' . __( 'Your hosting company, support forum volunteers, or a friendly developer may be able to use this information to help you:' );
// If we had a rollback and we're still critical, then the rollback failed too.
// Loop through all errors (the main WP_Error, the update result, the rollback result) for code, data, etc.
if ( 'rollback_was_required' == $result->get_error_code() )
if ( 'rollback_was_required' == $result->get_error_code() ) {
$errors = array( $result, $result->get_error_data()->update, $result->get_error_data()->rollback );
else
} else {
$errors = array( $result );
}
foreach ( $errors as $error ) {
if ( ! is_wp_error( $error ) )
if ( ! is_wp_error( $error ) ) {
continue;
}
$error_code = $error->get_error_code();
$body .= "\n\n" . sprintf( __( "Error code: %s" ), $error_code );
if ( 'rollback_was_required' == $error_code )
/* translators: %s: Error code */
$body .= "\n\n" . sprintf( __( 'Error code: %s' ), $error_code );
if ( 'rollback_was_required' == $error_code ) {
continue;
if ( $error->get_error_message() )
}
if ( $error->get_error_message() ) {
$body .= "\n" . $error->get_error_message();
}
$error_data = $error->get_error_data();
if ( $error_data )
if ( $error_data ) {
$body .= "\n" . implode( ', ', (array) $error_data );
}
}
$body .= "\n";
}
$to = get_site_option( 'admin_email' );
$to = get_site_option( 'admin_email' );
$headers = '';
$email = compact( 'to', 'subject', 'body', 'headers' );
@ -767,20 +823,24 @@ class WP_Automatic_Updater {
*/
protected function send_debug_email() {
$update_count = 0;
foreach ( $this->update_results as $type => $updates )
foreach ( $this->update_results as $type => $updates ) {
$update_count += count( $updates );
}
$body = array();
$body = array();
$failures = 0;
/* translators: %s: Network home URL */
$body[] = sprintf( __( 'WordPress site: %s' ), network_home_url( '/' ) );
// Core
if ( isset( $this->update_results['core'] ) ) {
$result = $this->update_results['core'][0];
if ( $result->result && ! is_wp_error( $result->result ) ) {
/* translators: %s: WordPress core version */
$body[] = sprintf( __( 'SUCCESS: WordPress was successfully updated to %s' ), $result->name );
} else {
/* translators: %s: WordPress core version */
$body[] = sprintf( __( 'FAILED: WordPress failed to update to %s' ), $result->name );
$failures++;
}
@ -789,8 +849,9 @@ class WP_Automatic_Updater {
// Plugins, Themes, Translations
foreach ( array( 'plugin', 'theme', 'translation' ) as $type ) {
if ( ! isset( $this->update_results[ $type ] ) )
if ( ! isset( $this->update_results[ $type ] ) ) {
continue;
}
$success_items = wp_list_filter( $this->update_results[ $type ], array( 'result' => true ) );
if ( $success_items ) {
$messages = array(
@ -801,6 +862,7 @@ class WP_Automatic_Updater {
$body[] = $messages[ $type ];
foreach ( wp_list_pluck( $success_items, 'name' ) as $name ) {
/* translators: %s: name of plugin / theme / translations */
$body[] = ' * ' . sprintf( __( 'SUCCESS: %s' ), $name );
}
}
@ -815,6 +877,7 @@ class WP_Automatic_Updater {
$body[] = $messages[ $type ];
foreach ( $this->update_results[ $type ] as $item ) {
if ( ! $item->result || is_wp_error( $item->result ) ) {
/* translators: %s: name of plugin / theme / translations */
$body[] = ' * ' . sprintf( __( 'FAILED: %s' ), $item->name );
$failures++;
}
@ -825,8 +888,9 @@ class WP_Automatic_Updater {
$site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
if ( $failures ) {
$body[] = trim( __(
"BETA TESTING?
$body[] = trim(
__(
"BETA TESTING?
=============
This debugging email is sent when you are using a development version of WordPress.
@ -835,35 +899,46 @@ If you think these failures might be due to a bug in WordPress, could you report
* Open a thread in the support forums: https://wordpress.org/support/forum/alphabeta
* Or, if you're comfortable writing a bug report: https://core.trac.wordpress.org/
Thanks! -- The WordPress Team" ) );
Thanks! -- The WordPress Team"
)
);
$body[] = '';
/* translators: %s: site title */
$subject = sprintf( __( '[%s] There were failures during background updates' ), $site_title );
} else {
/* translators: %s: site title */
$subject = sprintf( __( '[%s] Background updates have finished' ), $site_title );
}
$body[] = trim( __(
'UPDATE LOG
==========' ) );
$body[] = trim(
__(
'UPDATE LOG
=========='
)
);
$body[] = '';
foreach ( array( 'core', 'plugin', 'theme', 'translation' ) as $type ) {
if ( ! isset( $this->update_results[ $type ] ) )
if ( ! isset( $this->update_results[ $type ] ) ) {
continue;
}
foreach ( $this->update_results[ $type ] as $update ) {
$body[] = $update->name;
$body[] = str_repeat( '-', strlen( $update->name ) );
foreach ( $update->messages as $message )
$body[] = " " . html_entity_decode( str_replace( '&#8230;', '...', $message ) );
foreach ( $update->messages as $message ) {
$body[] = ' ' . html_entity_decode( str_replace( '&#8230;', '...', $message ) );
}
if ( is_wp_error( $update->result ) ) {
$results = array( 'update' => $update->result );
// If we rolled back, we want to know an error that occurred then too.
if ( 'rollback_was_required' === $update->result->get_error_code() )
if ( 'rollback_was_required' === $update->result->get_error_code() ) {
$results = (array) $update->result->get_error_data();
}
foreach ( $results as $result_type => $result ) {
if ( ! is_wp_error( $result ) )
if ( ! is_wp_error( $result ) ) {
continue;
}
if ( 'rollback' === $result_type ) {
/* translators: 1: Error code, 2: Error message. */
@ -873,8 +948,9 @@ Thanks! -- The WordPress Team" ) );
$body[] = ' ' . sprintf( __( 'Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() );
}
if ( $result->get_error_data() )
if ( $result->get_error_data() ) {
$body[] = ' ' . implode( ', ', (array) $result->get_error_data() );
}
}
}
$body[] = '';
@ -885,7 +961,7 @@ Thanks! -- The WordPress Team" ) );
'to' => get_site_option( 'admin_email' ),
'subject' => $subject,
'body' => implode( "\n", $body ),
'headers' => ''
'headers' => '',
);
/**

View file

@ -45,17 +45,19 @@ class WP_Comments_List_Table extends WP_List_Table {
add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
}
parent::__construct( array(
'plural' => 'comments',
'singular' => 'comment',
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'plural' => 'comments',
'singular' => 'comment',
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
public function floated_admin_avatar( $name, $comment_ID ) {
$comment = get_comment( $comment_ID );
$avatar = get_avatar( $comment, 32, 'mystery' );
$avatar = get_avatar( $comment, 32, 'mystery' );
return "$avatar $name";
}
@ -63,11 +65,10 @@ class WP_Comments_List_Table extends WP_List_Table {
* @return bool
*/
public function ajax_user_can() {
return current_user_can('edit_posts');
return current_user_can( 'edit_posts' );
}
/**
*
* @global int $post_id
* @global string $comment_status
* @global string $search
@ -77,10 +78,11 @@ class WP_Comments_List_Table extends WP_List_Table {
global $post_id, $comment_status, $search, $comment_type;
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) )
if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ) ) ) {
$comment_status = 'all';
}
$comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
$comment_type = ! empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
@ -89,7 +91,7 @@ class WP_Comments_List_Table extends WP_List_Table {
$user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
$orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : '';
$order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
$order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
$comments_per_page = $this->get_per_page( $comment_status );
@ -97,8 +99,7 @@ class WP_Comments_List_Table extends WP_List_Table {
if ( isset( $_REQUEST['number'] ) ) {
$number = (int) $_REQUEST['number'];
}
else {
} else {
$number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
}
@ -115,29 +116,39 @@ class WP_Comments_List_Table extends WP_List_Table {
}
$status_map = array(
'mine' => '',
'moderated' => 'hold',
'approved' => 'approve',
'all' => '',
'approved' => 'approve',
'all' => '',
);
$args = array(
'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
'search' => $search,
'user_id' => $user_id,
'offset' => $start,
'number' => $number,
'post_id' => $post_id,
'type' => $comment_type,
'orderby' => $orderby,
'order' => $order,
'status' => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status,
'search' => $search,
'user_id' => $user_id,
'offset' => $start,
'number' => $number,
'post_id' => $post_id,
'type' => $comment_type,
'orderby' => $orderby,
'order' => $order,
'post_type' => $post_type,
);
/**
* Filters the arguments for the comment query in the comments list table.
*
* @since 5.1.0
*
* @param array $args An array of get_comments() arguments.
*/
$args = apply_filters( 'comments_list_table_query_args', $args );
$_comments = get_comments( $args );
if ( is_array( $_comments ) ) {
update_comment_cache( $_comments );
$this->items = array_slice( $_comments, 0, $comments_per_page );
$this->items = array_slice( $_comments, 0, $comments_per_page );
$this->extra_items = array_slice( $_comments, $comments_per_page );
$_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
@ -145,20 +156,26 @@ class WP_Comments_List_Table extends WP_List_Table {
$this->pending_count = get_pending_comments_num( $_comment_post_ids );
}
$total_comments = get_comments( array_merge( $args, array(
'count' => true,
'offset' => 0,
'number' => 0
) ) );
$total_comments = get_comments(
array_merge(
$args,
array(
'count' => true,
'offset' => 0,
'number' => 0,
)
)
);
$this->set_pagination_args( array(
'total_items' => $total_comments,
'per_page' => $comments_per_page,
) );
$this->set_pagination_args(
array(
'total_items' => $total_comments,
'per_page' => $comments_per_page,
)
);
}
/**
*
* @param string $comment_status
* @return int
*/
@ -176,7 +193,6 @@ class WP_Comments_List_Table extends WP_List_Table {
}
/**
*
* @global string $comment_status
*/
public function no_items() {
@ -190,7 +206,6 @@ class WP_Comments_List_Table extends WP_List_Table {
}
/**
*
* @global int $post_id
* @global string $comment_status
* @global string $comment_type
@ -203,12 +218,19 @@ class WP_Comments_List_Table extends WP_List_Table {
$stati = array(
/* translators: %s: all comments count */
'all' => _nx_noop(
'all' => _nx_noop(
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
'comments'
), // singular not used
/* translators: %s: current user's comments count */
'mine' => _nx_noop(
'Mine <span class="count">(%s)</span>',
'Mine <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: pending comments count */
'moderated' => _nx_noop(
'Pending <span class="count">(%s)</span>',
@ -217,33 +239,35 @@ class WP_Comments_List_Table extends WP_List_Table {
),
/* translators: %s: approved comments count */
'approved' => _nx_noop(
'approved' => _nx_noop(
'Approved <span class="count">(%s)</span>',
'Approved <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: spam comments count */
'spam' => _nx_noop(
'spam' => _nx_noop(
'Spam <span class="count">(%s)</span>',
'Spam <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: trashed comments count */
'trash' => _nx_noop(
'trash' => _nx_noop(
'Trash <span class="count">(%s)</span>',
'Trash <span class="count">(%s)</span>',
'comments'
)
),
);
if ( !EMPTY_TRASH_DAYS )
unset($stati['trash']);
if ( ! EMPTY_TRASH_DAYS ) {
unset( $stati['trash'] );
}
$link = admin_url( 'edit-comments.php' );
if ( !empty($comment_type) && 'all' != $comment_type )
if ( ! empty( $comment_type ) && 'all' != $comment_type ) {
$link = add_query_arg( 'comment_type', $comment_type, $link );
}
foreach ( $stati as $status => $label ) {
$current_link_attributes = '';
@ -252,11 +276,27 @@ class WP_Comments_List_Table extends WP_List_Table {
$current_link_attributes = ' class="current" aria-current="page"';
}
if ( !isset( $num_comments->$status ) )
if ( 'mine' === $status ) {
$current_user_id = get_current_user_id();
$num_comments->mine = get_comments(
array(
'post_id' => $post_id ? $post_id : 0,
'user_id' => $current_user_id,
'count' => true,
)
);
$link = add_query_arg( 'user_id', $current_user_id, $link );
} else {
$link = remove_query_arg( 'user_id', $link );
}
if ( ! isset( $num_comments->$status ) ) {
$num_comments->$status = 10;
}
$link = add_query_arg( 'comment_status', $status, $link );
if ( $post_id )
if ( $post_id ) {
$link = add_query_arg( 'p', absint( $post_id ), $link );
}
/*
// I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
if ( !empty( $_REQUEST['s'] ) )
@ -264,7 +304,8 @@ class WP_Comments_List_Table extends WP_List_Table {
*/
$status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf(
translate_nooped_plural( $label, $num_comments->$status ),
sprintf( '<span class="%s-count">%s</span>',
sprintf(
'<span class="%s-count">%s</span>',
( 'moderated' === $status ) ? 'pending' : $status,
number_format_i18n( $num_comments->$status )
)
@ -275,15 +316,15 @@ class WP_Comments_List_Table extends WP_List_Table {
* Filters the comment status links.
*
* @since 2.5.0
* @since 5.1.0 The 'Mine' link was added.
*
* @param array $status_links An array of fully-formed status links. Default 'All'.
* Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'.
* @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
* 'Pending', 'Approved', 'Spam', and 'Trash'.
*/
return apply_filters( 'comment_status_links', $status_links );
}
/**
*
* @global string $comment_status
*
* @return array
@ -292,12 +333,15 @@ class WP_Comments_List_Table extends WP_List_Table {
global $comment_status;
$actions = array();
if ( in_array( $comment_status, array( 'all', 'approved' ) ) )
if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) {
$actions['unapprove'] = __( 'Unapprove' );
if ( in_array( $comment_status, array( 'all', 'moderated' ) ) )
}
if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) {
$actions['approve'] = __( 'Approve' );
if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) )
}
if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) ) {
$actions['spam'] = _x( 'Mark as Spam', 'comment' );
}
if ( 'trash' === $comment_status ) {
$actions['untrash'] = __( 'Restore' );
@ -305,16 +349,16 @@ class WP_Comments_List_Table extends WP_List_Table {
$actions['unspam'] = _x( 'Not Spam', 'comment' );
}
if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS )
if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = __( 'Delete Permanently' );
else
} else {
$actions['trash'] = __( 'Move to Trash' );
}
return $actions;
}
/**
*
* @global string $comment_status
* @global string $comment_type
*
@ -327,32 +371,36 @@ class WP_Comments_List_Table extends WP_List_Table {
if ( ! isset( $has_items ) ) {
$has_items = $this->has_items();
}
?>
?>
<div class="alignleft actions">
<?php
<?php
if ( 'top' === $which ) {
?>
<label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label>
<select id="filter-by-comment-type" name="comment_type">
<option value=""><?php _e( 'All comment types' ); ?></option>
<?php
?>
<label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label>
<select id="filter-by-comment-type" name="comment_type">
<option value=""><?php _e( 'All comment types' ); ?></option>
<?php
/**
* Filters the comment types dropdown menu.
*
* @since 2.7.0
*
* @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
* @param string[] $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
*/
$comment_types = apply_filters( 'admin_comment_types_dropdown', array(
'comment' => __( 'Comments' ),
'pings' => __( 'Pings' ),
) );
$comment_types = apply_filters(
'admin_comment_types_dropdown',
array(
'comment' => __( 'Comments' ),
'pings' => __( 'Pings' ),
)
);
foreach ( $comment_types as $type => $label )
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
foreach ( $comment_types as $type => $label ) {
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
}
?>
</select>
<?php
</select>
<?php
/**
* Fires just before the Filter submit button for comment types.
*
@ -382,14 +430,14 @@ class WP_Comments_List_Table extends WP_List_Table {
* @return string|false
*/
public function current_action() {
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
return 'delete_all';
}
return parent::current_action();
}
/**
*
* @global int $post_id
*
* @return array
@ -399,10 +447,11 @@ class WP_Comments_List_Table extends WP_List_Table {
$columns = array();
if ( $this->checkbox )
if ( $this->checkbox ) {
$columns['cb'] = '<input type="checkbox" />';
}
$columns['author'] = __( 'Author' );
$columns['author'] = __( 'Author' );
$columns['comment'] = _x( 'Comment', 'column name' );
if ( ! $post_id ) {
@ -416,14 +465,13 @@ class WP_Comments_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
protected function get_sortable_columns() {
return array(
'author' => 'comment_author',
'response' => 'comment_post_ID',
'date' => 'comment_date'
'date' => 'comment_date',
);
}
@ -441,13 +489,13 @@ class WP_Comments_List_Table extends WP_List_Table {
/**
*/
public function display() {
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
$this->display_tablenav( 'top' );
$this->screen->render_screen_reader_content( 'heading_list' );
?>
?>
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<thead>
<tr>
@ -461,8 +509,14 @@ class WP_Comments_List_Table extends WP_List_Table {
<tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;">
<?php
/*
* Back up the items to restore after printing the extra items markup.
* The extra items may be empty, which will prevent the table nav from displaying later.
*/
$items = $this->items;
$this->items = $this->extra_items;
$this->display_rows_or_placeholder();
$this->items = $items;
?>
</tbody>
@ -473,7 +527,7 @@ class WP_Comments_List_Table extends WP_List_Table {
</tfoot>
</table>
<?php
<?php
$this->display_tablenav( 'bottom' );
}
@ -507,54 +561,58 @@ class WP_Comments_List_Table extends WP_List_Table {
unset( $GLOBALS['post'], $GLOBALS['comment'] );
}
/**
* Generate and display row actions links.
*
* @since 4.3.0
*
* @global string $comment_status Status for the current listed comments.
*
* @param WP_Comment $comment The comment object.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string|void Comment row actions output.
*/
protected function handle_row_actions( $comment, $column_name, $primary ) {
global $comment_status;
/**
* Generate and display row actions links.
*
* @since 4.3.0
*
* @global string $comment_status Status for the current listed comments.
*
* @param WP_Comment $comment The comment object.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string|void Comment row actions output.
*/
protected function handle_row_actions( $comment, $column_name, $primary ) {
global $comment_status;
if ( $primary !== $column_name ) {
return '';
}
if ( ! $this->user_can ) {
return;
if ( ! $this->user_can ) {
return;
}
$the_comment_status = wp_get_comment_status( $comment );
$out = '';
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
$url = "comment.php?c=$comment->comment_ID";
$approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
$approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
$unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
$spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
$unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
$trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
$untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
$delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
$spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
$unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
$trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
$untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
$delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
// Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
$actions = array(
'approve' => '', 'unapprove' => '',
'reply' => '',
'approve' => '',
'unapprove' => '',
'reply' => '',
'quickedit' => '',
'edit' => '',
'spam' => '', 'unspam' => '',
'trash' => '', 'untrash' => '', 'delete' => ''
'edit' => '',
'spam' => '',
'unspam' => '',
'trash' => '',
'untrash' => '',
'delete' => '',
);
// Not looking at all comments.
@ -565,7 +623,7 @@ class WP_Comments_List_Table extends WP_List_Table {
$actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved' class='vim-a vim-destructive' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
}
} else {
$actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
$actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
$actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
}
@ -579,16 +637,16 @@ class WP_Comments_List_Table extends WP_List_Table {
$actions['untrash'] = "<a href='$untrash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' class='vim-z vim-destructive' aria-label='" . esc_attr__( 'Restore this comment from the Trash' ) . "'>" . __( 'Restore' ) . '</a>';
}
if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || !EMPTY_TRASH_DAYS ) {
if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Delete this comment permanently' ) . "'>" . __( 'Delete Permanently' ) . '</a>';
} else {
$actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Move this comment to the Trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
}
if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) {
$actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>';
$actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>" . __( 'Edit' ) . '</a>';
$format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" aria-label="%s" href="#">%s</a>';
$format = '<button type="button" data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s button-link" aria-expanded="false" aria-label="%s">%s</button>';
$actions['quickedit'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline', esc_attr__( 'Quick edit this comment inline' ), __( 'Quick&nbsp;Edit' ) );
@ -598,20 +656,21 @@ class WP_Comments_List_Table extends WP_List_Table {
/** This filter is documented in wp-admin/includes/dashboard.php */
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$i = 0;
$i = 0;
$out .= '<div class="row-actions">';
foreach ( $actions as $action => $link ) {
++$i;
( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
// Reply and quickedit need a hide-if-no-js span when not added with ajax
if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() )
if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
$action .= ' hide-if-no-js';
elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) {
if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) )
} elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) {
if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
$action .= ' approve';
else
} else {
$action .= ' unapprove';
}
}
$out .= "<span class='$action'>$sep$link</span>";
@ -624,14 +683,14 @@ class WP_Comments_List_Table extends WP_List_Table {
}
/**
*
* @param WP_Comment $comment The comment object.
*/
public function column_cb( $comment ) {
if ( $this->user_can ) { ?>
if ( $this->user_can ) {
?>
<label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label>
<input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
<?php
<?php
}
}
@ -647,7 +706,7 @@ class WP_Comments_List_Table extends WP_List_Table {
$parent = get_comment( $comment->comment_parent );
if ( $parent ) {
$parent_link = esc_url( get_comment_link( $parent ) );
$name = get_comment_author( $parent );
$name = get_comment_author( $parent );
printf(
/* translators: %s: comment link */
__( 'In reply to %s.' ),
@ -657,23 +716,23 @@ class WP_Comments_List_Table extends WP_List_Table {
}
comment_text( $comment );
if ( $this->user_can ) { ?>
<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
<textarea class="comment" rows="1" cols="1"><?php
if ( $this->user_can ) {
/** This filter is documented in wp-admin/includes/comment.php */
echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) );
?></textarea>
<div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
<div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
<div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
$comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
?>
<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
<textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea>
<div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
<div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
<div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
</div>
<?php
<?php
}
}
/**
*
* @global string $comment_status
*
* @param WP_Comment $comment The comment object.
@ -688,7 +747,9 @@ class WP_Comments_List_Table extends WP_List_Table {
$author_url_display = wp_html_excerpt( $author_url_display, 49, '&hellip;' );
}
echo "<strong>"; comment_author( $comment ); echo '</strong><br />';
echo '<strong>';
comment_author( $comment );
echo '</strong><br />';
if ( ! empty( $author_url_display ) ) {
printf( '<a href="%s">%s</a><br />', esc_url( $author_url ), esc_html( $author_url_display ) );
}
@ -705,7 +766,13 @@ class WP_Comments_List_Table extends WP_List_Table {
$author_ip = get_comment_author_IP( $comment );
if ( $author_ip ) {
$author_ip_url = add_query_arg( array( 's' => $author_ip, 'mode' => 'detail' ), admin_url( 'edit-comments.php' ) );
$author_ip_url = add_query_arg(
array(
's' => $author_ip,
'mode' => 'detail',
),
admin_url( 'edit-comments.php' )
);
if ( 'spam' === $comment_status ) {
$author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
}
@ -715,19 +782,19 @@ class WP_Comments_List_Table extends WP_List_Table {
}
/**
*
* @param WP_Comment $comment The comment object.
*/
public function column_date( $comment ) {
/* translators: 1: comment date, 2: comment time */
$submitted = sprintf( __( '%1$s at %2$s' ),
$submitted = sprintf(
__( '%1$s at %2$s' ),
/* translators: comment date format. See https://secure.php.net/date */
get_comment_date( __( 'Y/m/d' ), $comment ),
get_comment_date( __( 'g:i a' ), $comment )
);
echo '<div class="submitted-on">';
if ( 'approved' === wp_get_comment_status( $comment ) && ! empty ( $comment->comment_post_ID ) ) {
if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
printf(
'<a href="%s">%s</a>',
esc_url( get_comment_link( $comment ) ),
@ -740,7 +807,6 @@ class WP_Comments_List_Table extends WP_List_Table {
}
/**
*
* @param WP_Comment $comment The comment object.
*/
public function column_response( $comment ) {
@ -750,15 +816,15 @@ class WP_Comments_List_Table extends WP_List_Table {
return;
}
if ( isset( $this->pending_count[$post->ID] ) ) {
$pending_comments = $this->pending_count[$post->ID];
if ( isset( $this->pending_count[ $post->ID ] ) ) {
$pending_comments = $this->pending_count[ $post->ID ];
} else {
$_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
$pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID];
$pending_comments = $this->pending_count[ $post->ID ] = $_pending_count_temp[ $post->ID ];
}
if ( current_user_can( 'edit_post', $post->ID ) ) {
$post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
$post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
$post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
} else {
$post_link = esc_html( get_the_title( $post->ID ) );
@ -778,7 +844,6 @@ class WP_Comments_List_Table extends WP_List_Table {
}
/**
*
* @param WP_Comment $comment The comment object.
* @param string $column_name The custom column's name.
*/

View file

@ -95,8 +95,8 @@ class WP_Community_Events {
// include an unmodified $wp_version
include( ABSPATH . WPINC . '/version.php' );
$api_url = 'http://api.wordpress.org/events/1.0/';
$request_args = $this->get_request_args( $location_search, $timezone );
$api_url = 'http://api.wordpress.org/events/1.0/';
$request_args = $this->get_request_args( $location_search, $timezone );
$request_args['user-agent'] = 'WordPress/' . $wp_version . '; ' . home_url( '/' );
if ( wp_http_supports( array( 'ssl' ) ) ) {
@ -203,7 +203,7 @@ class WP_Community_Events {
// Wrap the args in an array compatible with the second parameter of `wp_remote_get()`.
return array(
'body' => $args
'body' => $args,
);
}
@ -233,7 +233,7 @@ class WP_Community_Events {
* or false on failure.
*/
public static function get_unsafe_client_ip() {
$client_ip = $netmask = false;
$client_ip = false;
// In order of preference, with the best ones for this purpose first.
$address_headers = array(
@ -308,7 +308,7 @@ class WP_Community_Events {
if ( isset( $location['ip'] ) ) {
$key = 'community-events-' . md5( $location['ip'] );
} else if ( isset( $location['latitude'], $location['longitude'] ) ) {
} elseif ( isset( $location['latitude'], $location['longitude'] ) ) {
$key = 'community-events-' . md5( $location['latitude'] . $location['longitude'] );
}
@ -425,7 +425,7 @@ class WP_Community_Events {
$response_body['events'] = array_slice( $response_body['events'], 0, 3 );
$trimmed_event_types = wp_list_pluck( $response_body['events'], 'type' );
// Make sure the soonest upcoming WordCamps is pinned in the list.
// Make sure the soonest upcoming WordCamp is pinned in the list.
if ( ! in_array( 'wordcamp', $trimmed_event_types ) && $wordcamps ) {
array_pop( $response_body['events'] );
array_push( $response_body['events'], $wordcamps[0] );
@ -452,11 +452,13 @@ class WP_Community_Events {
return;
}
error_log( sprintf(
'%s: %s. Details: %s',
__METHOD__,
trim( $message, '.' ),
wp_json_encode( $details )
) );
error_log(
sprintf(
'%s: %s. Details: %s',
__METHOD__,
trim( $message, '.' ),
wp_json_encode( $details )
)
);
}
}

View file

@ -53,10 +53,11 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
public function abspath() {
$folder = $this->find_folder(ABSPATH);
$folder = $this->find_folder( ABSPATH );
// Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
if ( ! $folder && $this->is_dir( '/' . WPINC ) )
if ( ! $folder && $this->is_dir( '/' . WPINC ) ) {
$folder = '/';
}
return $folder;
}
@ -68,7 +69,7 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
public function wp_content_dir() {
return $this->find_folder(WP_CONTENT_DIR);
return $this->find_folder( WP_CONTENT_DIR );
}
/**
@ -79,7 +80,7 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
public function wp_plugins_dir() {
return $this->find_folder(WP_PLUGIN_DIR);
return $this->find_folder( WP_PLUGIN_DIR );
}
/**
@ -94,8 +95,9 @@ class WP_Filesystem_Base {
$theme_root = get_theme_root( $theme );
// Account for relative theme roots
if ( '/themes' == $theme_root || ! is_dir( $theme_root ) )
if ( '/themes' == $theme_root || ! is_dir( $theme_root ) ) {
$theme_root = WP_CONTENT_DIR . $theme_root;
}
return $this->find_folder( $theme_root );
}
@ -108,7 +110,7 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
public function wp_lang_dir() {
return $this->find_folder(WP_LANG_DIR);
return $this->find_folder( WP_LANG_DIR );
}
/**
@ -128,7 +130,7 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
public function find_base_dir( $base = '.', $echo = false ) {
_deprecated_function(__FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
_deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
$this->verbose = $echo;
return $this->abspath();
}
@ -149,7 +151,7 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
public function get_base_dir( $base = '.', $echo = false ) {
_deprecated_function(__FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
_deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
$this->verbose = $echo;
return $this->abspath();
}
@ -166,29 +168,33 @@ class WP_Filesystem_Base {
* @return string|false The location of the remote path, false on failure.
*/
public function find_folder( $folder ) {
if ( isset( $this->cache[ $folder ] ) )
if ( isset( $this->cache[ $folder ] ) ) {
return $this->cache[ $folder ];
}
if ( stripos($this->method, 'ftp') !== false ) {
if ( stripos( $this->method, 'ftp' ) !== false ) {
$constant_overrides = array(
'FTP_BASE' => ABSPATH,
'FTP_BASE' => ABSPATH,
'FTP_CONTENT_DIR' => WP_CONTENT_DIR,
'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR,
'FTP_LANG_DIR' => WP_LANG_DIR
'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR,
'FTP_LANG_DIR' => WP_LANG_DIR,
);
// Direct matches ( folder = CONSTANT/ )
foreach ( $constant_overrides as $constant => $dir ) {
if ( ! defined( $constant ) )
if ( ! defined( $constant ) ) {
continue;
if ( $folder === $dir )
}
if ( $folder === $dir ) {
return trailingslashit( constant( $constant ) );
}
}
// Prefix Matches ( folder = CONSTANT/subdir )
foreach ( $constant_overrides as $constant => $dir ) {
if ( ! defined( $constant ) )
if ( ! defined( $constant ) ) {
continue;
}
if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir
$potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );
$potential_folder = trailingslashit( $potential_folder );
@ -200,23 +206,25 @@ class WP_Filesystem_Base {
}
}
} elseif ( 'direct' == $this->method ) {
$folder = str_replace('\\', '/', $folder); // Windows path sanitisation
return trailingslashit($folder);
$folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation
return trailingslashit( $folder );
}
$folder = preg_replace('|^([a-z]{1}):|i', '', $folder); // Strip out windows drive letter if it's there.
$folder = str_replace('\\', '/', $folder); // Windows path sanitisation
$folder = preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out windows drive letter if it's there.
$folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation
if ( isset($this->cache[ $folder ] ) )
if ( isset( $this->cache[ $folder ] ) ) {
return $this->cache[ $folder ];
}
if ( $this->exists($folder) ) { // Folder exists at that absolute path.
$folder = trailingslashit($folder);
if ( $this->exists( $folder ) ) { // Folder exists at that absolute path.
$folder = trailingslashit( $folder );
$this->cache[ $folder ] = $folder;
return $folder;
}
if ( $return = $this->search_for_folder($folder) )
if ( $return = $this->search_for_folder( $folder ) ) {
$this->cache[ $folder ] = $return;
}
return $return;
}
@ -233,26 +241,28 @@ class WP_Filesystem_Base {
* @return string|false The location of the remote path, false to cease looping.
*/
public function search_for_folder( $folder, $base = '.', $loop = false ) {
if ( empty( $base ) || '.' == $base )
$base = trailingslashit($this->cwd());
if ( empty( $base ) || '.' == $base ) {
$base = trailingslashit( $this->cwd() );
}
$folder = untrailingslashit($folder);
$folder = untrailingslashit( $folder );
if ( $this->verbose ) {
/* translators: 1: folder to locate, 2: folder to start searching from */
printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "<br/>\n", $folder, $base );
}
$folder_parts = explode('/', $folder);
$folder_parts = explode( '/', $folder );
$folder_part_keys = array_keys( $folder_parts );
$last_index = array_pop( $folder_part_keys );
$last_path = $folder_parts[ $last_index ];
$last_index = array_pop( $folder_part_keys );
$last_path = $folder_parts[ $last_index ];
$files = $this->dirlist( $base );
foreach ( $folder_parts as $index => $key ) {
if ( $index == $last_index )
if ( $index == $last_index ) {
continue; // We want this to be caught by the next code block.
}
/*
* Working from /home/ to /user/ to /wordpress/ see if that file exists within
@ -261,10 +271,10 @@ class WP_Filesystem_Base {
* folder level, and see if that matches, and so on. If it reaches the end, and still
* cant find it, it'll return false for the entire function.
*/
if ( isset($files[ $key ]) ){
if ( isset( $files[ $key ] ) ) {
// Let's try that folder:
$newdir = trailingslashit(path_join($base, $key));
$newdir = trailingslashit( path_join( $base, $key ) );
if ( $this->verbose ) {
/* translators: %s: directory name */
printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir );
@ -272,25 +282,27 @@ class WP_Filesystem_Base {
// Only search for the remaining path tokens in the directory, not the full path again.
$newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) )
if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop ) ) {
return $ret;
}
}
}
// Only check this as a last resort, to prevent locating the incorrect install.
// All above procedures will fail quickly if this is the right branch to take.
if (isset( $files[ $last_path ] ) ) {
if ( isset( $files[ $last_path ] ) ) {
if ( $this->verbose ) {
/* translators: %s: directory name */
printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path );
printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path );
}
return trailingslashit($base . $last_path);
return trailingslashit( $base . $last_path );
}
// Prevent this function from looping again.
// No need to proceed if we've just searched in /
if ( $loop || '/' == $base )
if ( $loop || '/' == $base ) {
return false;
}
// As an extra last resort, Change back to / if the folder wasn't found.
// This comes into effect when the CWD is /home/user/ but WP is at /var/www/....
@ -310,45 +322,46 @@ class WP_Filesystem_Base {
* @param string $file String filename.
* @return string The *nix-style representation of permissions.
*/
public function gethchmod( $file ){
public function gethchmod( $file ) {
$perms = intval( $this->getchmod( $file ), 8 );
if (($perms & 0xC000) == 0xC000) // Socket
if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket
$info = 's';
elseif (($perms & 0xA000) == 0xA000) // Symbolic Link
} elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link
$info = 'l';
elseif (($perms & 0x8000) == 0x8000) // Regular
} elseif ( ( $perms & 0x8000 ) == 0x8000 ) { // Regular
$info = '-';
elseif (($perms & 0x6000) == 0x6000) // Block special
} elseif ( ( $perms & 0x6000 ) == 0x6000 ) { // Block special
$info = 'b';
elseif (($perms & 0x4000) == 0x4000) // Directory
} elseif ( ( $perms & 0x4000 ) == 0x4000 ) { // Directory
$info = 'd';
elseif (($perms & 0x2000) == 0x2000) // Character special
} elseif ( ( $perms & 0x2000 ) == 0x2000 ) { // Character special
$info = 'c';
elseif (($perms & 0x1000) == 0x1000) // FIFO pipe
} elseif ( ( $perms & 0x1000 ) == 0x1000 ) { // FIFO pipe
$info = 'p';
else // Unknown
} else { // Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
$info .= ( ( $perms & 0x0100 ) ? 'r' : '-' );
$info .= ( ( $perms & 0x0080 ) ? 'w' : '-' );
$info .= ( ( $perms & 0x0040 ) ?
( ( $perms & 0x0800 ) ? 's' : 'x' ) :
( ( $perms & 0x0800 ) ? 'S' : '-' ) );
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
$info .= ( ( $perms & 0x0020 ) ? 'r' : '-' );
$info .= ( ( $perms & 0x0010 ) ? 'w' : '-' );
$info .= ( ( $perms & 0x0008 ) ?
( ( $perms & 0x0400 ) ? 's' : 'x' ) :
( ( $perms & 0x0400 ) ? 'S' : '-' ) );
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
$info .= ( ( $perms & 0x0004 ) ? 'r' : '-' );
$info .= ( ( $perms & 0x0002 ) ? 'w' : '-' );
$info .= ( ( $perms & 0x0001 ) ?
( ( $perms & 0x0200 ) ? 't' : 'x' ) :
( ( $perms & 0x0200 ) ? 'T' : '-' ) );
return $info;
}
@ -368,7 +381,7 @@ class WP_Filesystem_Base {
*
* Converts '-rw-r--r--' to 0644
* From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
*
*
* @link https://secure.php.net/manual/en/function.chmod.php#49614
*
* @since 2.5.0
@ -378,20 +391,25 @@ class WP_Filesystem_Base {
*/
public function getnumchmodfromh( $mode ) {
$realmode = '';
$legal = array('', 'w', 'r', 'x', '-');
$attarray = preg_split('//', $mode);
$legal = array( '', 'w', 'r', 'x', '-' );
$attarray = preg_split( '//', $mode );
for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
if ($key = array_search($attarray[$i], $legal)) {
$realmode .= $legal[$key];
}
if ( $key = array_search( $attarray[ $i ], $legal ) ) {
$realmode .= $legal[ $key ];
}
}
$mode = str_pad($realmode, 10, '-', STR_PAD_LEFT);
$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
$mode = strtr($mode,$trans);
$mode = str_pad( $realmode, 10, '-', STR_PAD_LEFT );
$trans = array(
'-' => '0',
'r' => '4',
'w' => '2',
'x' => '1',
);
$mode = strtr( $mode, $trans );
$newmode = $mode[0];
$newmode = $mode[0];
$newmode .= $mode[1] + $mode[2] + $mode[3];
$newmode .= $mode[4] + $mode[5] + $mode[6];
$newmode .= $mode[7] + $mode[8] + $mode[9];
@ -539,7 +557,7 @@ class WP_Filesystem_Base {
*
* @since 2.5.0
* @abstract
*
*
* @param string $file Path to the file.
* @return string|bool Username of the user or false on error.
*/

View file

@ -18,10 +18,9 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* constructor
*
*
* @param mixed $arg ignored argument
*/
public function __construct($arg) {
public function __construct( $arg ) {
$this->method = 'direct';
$this->errors = new WP_Error();
}
@ -29,29 +28,26 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* Reads entire file into a string
*
*
* @param string $file Name of the file to read.
* @return string|bool The function returns the read data or false on failure.
*/
public function get_contents($file) {
return @file_get_contents($file);
public function get_contents( $file ) {
return @file_get_contents( $file );
}
/**
* Reads entire file into an array
*
*
* @param string $file Path to the file.
* @return array|bool the file contents in an array or false on failure.
*/
public function get_contents_array($file) {
return @file($file);
public function get_contents_array( $file ) {
return @file( $file );
}
/**
* Write a string to a file
*
*
* @param string $file Remote path to the file where to write the data.
* @param string $contents The data to write.
* @param int $mode Optional. The file permissions as octal number, usually 0644.
@ -60,8 +56,9 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
*/
public function put_contents( $file, $contents, $mode = false ) {
$fp = @fopen( $file, 'wb' );
if ( ! $fp )
if ( ! $fp ) {
return false;
}
mbstring_binary_safe_encoding();
@ -73,8 +70,9 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
fclose( $fp );
if ( $data_length !== $bytes_written )
if ( $data_length !== $bytes_written ) {
return false;
}
$this->chmod( $file, $mode );
@ -84,7 +82,6 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* Gets the current working directory
*
*
* @return string|bool the current working directory on success, or false on failure.
*/
public function cwd() {
@ -94,35 +91,37 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* Change directory
*
*
* @param string $dir The new current directory.
* @return bool Returns true on success or false on failure.
*/
public function chdir($dir) {
return @chdir($dir);
public function chdir( $dir ) {
return @chdir( $dir );
}
/**
* Changes file group
*
*
* @param string $file Path to the file.
* @param mixed $group A group name or number.
* @param bool $recursive Optional. If set True changes file group recursively. Default false.
* @return bool Returns true on success or false on failure.
*/
public function chgrp($file, $group, $recursive = false) {
if ( ! $this->exists($file) )
public function chgrp( $file, $group, $recursive = false ) {
if ( ! $this->exists( $file ) ) {
return false;
if ( ! $recursive )
return @chgrp($file, $group);
if ( ! $this->is_dir($file) )
return @chgrp($file, $group);
}
if ( ! $recursive ) {
return @chgrp( $file, $group );
}
if ( ! $this->is_dir( $file ) ) {
return @chgrp( $file, $group );
}
// Is a directory, and we want recursive
$file = trailingslashit($file);
$filelist = $this->dirlist($file);
foreach ($filelist as $filename)
$this->chgrp($file . $filename, $group, $recursive);
$file = trailingslashit( $file );
$filelist = $this->dirlist( $file );
foreach ( $filelist as $filename ) {
$this->chgrp( $file . $filename, $group, $recursive );
}
return true;
}
@ -130,30 +129,32 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* Changes filesystem permissions
*
*
* @param string $file Path to the file.
* @param int $mode Optional. The permissions as octal number, usually 0644 for files,
* 0755 for dirs. Default false.
* @param bool $recursive Optional. If set True changes file group recursively. Default false.
* @return bool Returns true on success or false on failure.
*/
public function chmod($file, $mode = false, $recursive = false) {
public function chmod( $file, $mode = false, $recursive = false ) {
if ( ! $mode ) {
if ( $this->is_file($file) )
if ( $this->is_file( $file ) ) {
$mode = FS_CHMOD_FILE;
elseif ( $this->is_dir($file) )
} elseif ( $this->is_dir( $file ) ) {
$mode = FS_CHMOD_DIR;
else
} else {
return false;
}
}
if ( ! $recursive || ! $this->is_dir($file) )
return @chmod($file, $mode);
if ( ! $recursive || ! $this->is_dir( $file ) ) {
return @chmod( $file, $mode );
}
// Is a directory, and we want recursive
$file = trailingslashit($file);
$filelist = $this->dirlist($file);
foreach ( (array)$filelist as $filename => $filemeta)
$this->chmod($file . $filename, $mode, $recursive);
$file = trailingslashit( $file );
$filelist = $this->dirlist( $file );
foreach ( (array) $filelist as $filename => $filemeta ) {
$this->chmod( $file . $filename, $mode, $recursive );
}
return true;
}
@ -161,24 +162,26 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* Changes file owner
*
*
* @param string $file Path to the file.
* @param mixed $owner A user name or number.
* @param bool $recursive Optional. If set True changes file owner recursively.
* Default false.
* @return bool Returns true on success or false on failure.
*/
public function chown($file, $owner, $recursive = false) {
if ( ! $this->exists($file) )
public function chown( $file, $owner, $recursive = false ) {
if ( ! $this->exists( $file ) ) {
return false;
if ( ! $recursive )
return @chown($file, $owner);
if ( ! $this->is_dir($file) )
return @chown($file, $owner);
}
if ( ! $recursive ) {
return @chown( $file, $owner );
}
if ( ! $this->is_dir( $file ) ) {
return @chown( $file, $owner );
}
// Is a directory, and we want recursive
$filelist = $this->dirlist($file);
foreach ($filelist as $filename) {
$this->chown($file . '/' . $filename, $owner, $recursive);
$filelist = $this->dirlist( $file );
foreach ( $filelist as $filename ) {
$this->chown( $file . '/' . $filename, $owner, $recursive );
}
return true;
}
@ -186,17 +189,18 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* Gets file owner
*
*
* @param string $file Path to the file.
* @return string|bool Username of the user or false on error.
*/
public function owner($file) {
$owneruid = @fileowner($file);
if ( ! $owneruid )
public function owner( $file ) {
$owneruid = @fileowner( $file );
if ( ! $owneruid ) {
return false;
if ( ! function_exists('posix_getpwuid') )
}
if ( ! function_exists( 'posix_getpwuid' ) ) {
return $owneruid;
$ownerarray = posix_getpwuid($owneruid);
}
$ownerarray = posix_getpwuid( $owneruid );
return $ownerarray['name'];
}
@ -205,64 +209,66 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
*
* FIXME does not handle errors in fileperms()
*
*
* @param string $file Path to the file.
* @return string Mode of the file (last 3 digits).
*/
public function getchmod($file) {
public function getchmod( $file ) {
return substr( decoct( @fileperms( $file ) ), -3 );
}
/**
*
* @param string $file
* @return string|false
*/
public function group($file) {
$gid = @filegroup($file);
if ( ! $gid )
public function group( $file ) {
$gid = @filegroup( $file );
if ( ! $gid ) {
return false;
if ( ! function_exists('posix_getgrgid') )
}
if ( ! function_exists( 'posix_getgrgid' ) ) {
return $gid;
$grouparray = posix_getgrgid($gid);
}
$grouparray = posix_getgrgid( $gid );
return $grouparray['name'];
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @param int $mode
* @return bool
*/
public function copy($source, $destination, $overwrite = false, $mode = false) {
if ( ! $overwrite && $this->exists($destination) )
public function copy( $source, $destination, $overwrite = false, $mode = false ) {
if ( ! $overwrite && $this->exists( $destination ) ) {
return false;
}
$rtval = copy($source, $destination);
if ( $mode )
$this->chmod($destination, $mode);
$rtval = copy( $source, $destination );
if ( $mode ) {
$this->chmod( $destination, $mode );
}
return $rtval;
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @return bool
*/
public function move($source, $destination, $overwrite = false) {
if ( ! $overwrite && $this->exists($destination) )
public function move( $source, $destination, $overwrite = false ) {
if ( ! $overwrite && $this->exists( $destination ) ) {
return false;
}
// Try using rename first. if that fails (for example, source is read only) try copy.
if ( @rename($source, $destination) )
if ( @rename( $source, $destination ) ) {
return true;
}
if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ) {
$this->delete($source);
if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) {
$this->delete( $source );
return true;
} else {
return false;
@ -270,220 +276,225 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
}
/**
*
* @param string $file
* @param bool $recursive
* @param string $type
* @return bool
*/
public function delete($file, $recursive = false, $type = false) {
if ( empty( $file ) ) // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
public function delete( $file, $recursive = false, $type = false ) {
if ( empty( $file ) ) { // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
return false;
}
$file = str_replace( '\\', '/', $file ); // for win32, occasional problems deleting files otherwise
if ( 'f' == $type || $this->is_file($file) )
return @unlink($file);
if ( ! $recursive && $this->is_dir($file) )
return @rmdir($file);
if ( 'f' == $type || $this->is_file( $file ) ) {
return @unlink( $file );
}
if ( ! $recursive && $this->is_dir( $file ) ) {
return @rmdir( $file );
}
// At this point it's a folder, and we're in recursive mode
$file = trailingslashit($file);
$filelist = $this->dirlist($file, true);
$file = trailingslashit( $file );
$filelist = $this->dirlist( $file, true );
$retval = true;
if ( is_array( $filelist ) ) {
foreach ( $filelist as $filename => $fileinfo ) {
if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) )
if ( ! $this->delete( $file . $filename, $recursive, $fileinfo['type'] ) ) {
$retval = false;
}
}
}
if ( file_exists($file) && ! @rmdir($file) )
if ( file_exists( $file ) && ! @rmdir( $file ) ) {
$retval = false;
}
return $retval;
}
/**
*
* @param string $file
* @return bool
*/
public function exists($file) {
return @file_exists($file);
public function exists( $file ) {
return @file_exists( $file );
}
/**
*
* @param string $file
* @return bool
*/
public function is_file($file) {
return @is_file($file);
public function is_file( $file ) {
return @is_file( $file );
}
/**
*
* @param string $path
* @return bool
*/
public function is_dir($path) {
return @is_dir($path);
public function is_dir( $path ) {
return @is_dir( $path );
}
/**
*
* @param string $file
* @return bool
*/
public function is_readable($file) {
return @is_readable($file);
public function is_readable( $file ) {
return @is_readable( $file );
}
/**
*
* @param string $file
* @return bool
*/
public function is_writable($file) {
return @is_writable($file);
public function is_writable( $file ) {
return @is_writable( $file );
}
/**
*
* @param string $file
* @return int
*/
public function atime($file) {
return @fileatime($file);
public function atime( $file ) {
return @fileatime( $file );
}
/**
*
* @param string $file
* @return int
*/
public function mtime($file) {
return @filemtime($file);
public function mtime( $file ) {
return @filemtime( $file );
}
/**
*
* @param string $file
* @return int
*/
public function size($file) {
return @filesize($file);
public function size( $file ) {
return @filesize( $file );
}
/**
*
* @param string $file
* @param int $time
* @param int $atime
* @return bool
*/
public function touch($file, $time = 0, $atime = 0) {
if ($time == 0)
public function touch( $file, $time = 0, $atime = 0 ) {
if ( $time == 0 ) {
$time = time();
if ($atime == 0)
}
if ( $atime == 0 ) {
$atime = time();
return @touch($file, $time, $atime);
}
return @touch( $file, $time, $atime );
}
/**
*
* @param string $path
* @param mixed $chmod
* @param mixed $chown
* @param mixed $chgrp
* @return bool
*/
public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
// Safe mode fails with a trailing slash under certain PHP versions.
$path = untrailingslashit($path);
if ( empty($path) )
$path = untrailingslashit( $path );
if ( empty( $path ) ) {
return false;
}
if ( ! $chmod )
if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR;
}
if ( ! @mkdir($path) )
if ( ! @mkdir( $path ) ) {
return false;
$this->chmod($path, $chmod);
if ( $chown )
$this->chown($path, $chown);
if ( $chgrp )
$this->chgrp($path, $chgrp);
}
$this->chmod( $path, $chmod );
if ( $chown ) {
$this->chown( $path, $chown );
}
if ( $chgrp ) {
$this->chgrp( $path, $chgrp );
}
return true;
}
/**
*
* @param string $path
* @param bool $recursive
* @return bool
*/
public function rmdir($path, $recursive = false) {
return $this->delete($path, $recursive);
public function rmdir( $path, $recursive = false ) {
return $this->delete( $path, $recursive );
}
/**
*
* @param string $path
* @param bool $include_hidden
* @param bool $recursive
* @return bool|array
*/
public function dirlist($path, $include_hidden = true, $recursive = false) {
if ( $this->is_file($path) ) {
$limit_file = basename($path);
$path = dirname($path);
public function dirlist( $path, $include_hidden = true, $recursive = false ) {
if ( $this->is_file( $path ) ) {
$limit_file = basename( $path );
$path = dirname( $path );
} else {
$limit_file = false;
}
if ( ! $this->is_dir($path) )
if ( ! $this->is_dir( $path ) ) {
return false;
}
$dir = @dir($path);
if ( ! $dir )
$dir = @dir( $path );
if ( ! $dir ) {
return false;
}
$ret = array();
while (false !== ($entry = $dir->read()) ) {
$struc = array();
while ( false !== ( $entry = $dir->read() ) ) {
$struc = array();
$struc['name'] = $entry;
if ( '.' == $struc['name'] || '..' == $struc['name'] )
if ( '.' == $struc['name'] || '..' == $struc['name'] ) {
continue;
}
if ( ! $include_hidden && '.' == $struc['name'][0] )
if ( ! $include_hidden && '.' == $struc['name'][0] ) {
continue;
}
if ( $limit_file && $struc['name'] != $limit_file)
if ( $limit_file && $struc['name'] != $limit_file ) {
continue;
}
$struc['perms'] = $this->gethchmod($path.'/'.$entry);
$struc['permsn'] = $this->getnumchmodfromh($struc['perms']);
$struc['number'] = false;
$struc['owner'] = $this->owner($path.'/'.$entry);
$struc['group'] = $this->group($path.'/'.$entry);
$struc['size'] = $this->size($path.'/'.$entry);
$struc['lastmodunix']= $this->mtime($path.'/'.$entry);
$struc['lastmod'] = date('M j',$struc['lastmodunix']);
$struc['time'] = date('h:i:s',$struc['lastmodunix']);
$struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
$struc['perms'] = $this->gethchmod( $path . '/' . $entry );
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] );
$struc['number'] = false;
$struc['owner'] = $this->owner( $path . '/' . $entry );
$struc['group'] = $this->group( $path . '/' . $entry );
$struc['size'] = $this->size( $path . '/' . $entry );
$struc['lastmodunix'] = $this->mtime( $path . '/' . $entry );
$struc['lastmod'] = date( 'M j', $struc['lastmodunix'] );
$struc['time'] = date( 'h:i:s', $struc['lastmodunix'] );
$struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
if ( 'd' == $struc['type'] ) {
if ( $recursive )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
else
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
$ret[ $struc['name'] ] = $struc;
}
$dir->close();
unset($dir);
unset( $dir );
return $ret;
}
}

View file

@ -17,7 +17,6 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
public $link;
/**
*
* @param array $opt
*/
public function __construct( $opt = '' ) {
@ -25,66 +24,76 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$this->errors = new WP_Error();
// Check if possible to use ftp functions.
if ( ! extension_loaded('ftp') ) {
$this->errors->add('no_ftp_ext', __('The ftp PHP extension is not available'));
if ( ! extension_loaded( 'ftp' ) ) {
$this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) );
return;
}
// This Class uses the timeout on a per-connection basis, Others use it on a per-action basis.
if ( ! defined('FS_TIMEOUT') )
define('FS_TIMEOUT', 240);
if ( ! defined( 'FS_TIMEOUT' ) ) {
define( 'FS_TIMEOUT', 240 );
}
if ( empty($opt['port']) )
if ( empty( $opt['port'] ) ) {
$this->options['port'] = 21;
else
} else {
$this->options['port'] = $opt['port'];
}
if ( empty($opt['hostname']) )
$this->errors->add('empty_hostname', __('FTP hostname is required'));
else
if ( empty( $opt['hostname'] ) ) {
$this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) );
} else {
$this->options['hostname'] = $opt['hostname'];
}
// Check if the options provided are OK.
if ( empty($opt['username']) )
$this->errors->add('empty_username', __('FTP username is required'));
else
if ( empty( $opt['username'] ) ) {
$this->errors->add( 'empty_username', __( 'FTP username is required' ) );
} else {
$this->options['username'] = $opt['username'];
}
if ( empty($opt['password']) )
$this->errors->add('empty_password', __('FTP password is required'));
else
if ( empty( $opt['password'] ) ) {
$this->errors->add( 'empty_password', __( 'FTP password is required' ) );
} else {
$this->options['password'] = $opt['password'];
}
$this->options['ssl'] = false;
if ( isset($opt['connection_type']) && 'ftps' == $opt['connection_type'] )
if ( isset( $opt['connection_type'] ) && 'ftps' == $opt['connection_type'] ) {
$this->options['ssl'] = true;
}
}
/**
*
* @return bool
*/
public function connect() {
if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') )
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
else
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) {
$this->link = @ftp_ssl_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
} else {
$this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
}
if ( ! $this->link ) {
$this->errors->add( 'connect',
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf( __( 'Failed to connect to FTP Server %s' ),
sprintf(
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
if ( ! @ftp_login( $this->link,$this->options['username'], $this->options['password'] ) ) {
$this->errors->add( 'auth',
if ( ! @ftp_login( $this->link, $this->options['username'], $this->options['password'] ) ) {
$this->errors->add(
'auth',
/* translators: %s: username */
sprintf( __( 'Username/Password incorrect for %s' ),
sprintf(
__( 'Username/Password incorrect for %s' ),
$this->options['username']
)
);
@ -93,8 +102,9 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
// Set the Connection to use Passive FTP
@ftp_pasv( $this->link, true );
if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT )
@ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT);
if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
@ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
}
return true;
}
@ -109,8 +119,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
* or if the file couldn't be retrieved.
*/
public function get_contents( $file ) {
$tempfile = wp_tempnam($file);
$temp = fopen($tempfile, 'w+');
$tempfile = wp_tempnam( $file );
$temp = fopen( $tempfile, 'w+' );
if ( ! $temp ) {
unlink( $tempfile );
@ -126,33 +136,32 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
fseek( $temp, 0 ); // Skip back to the start of the file being written to
$contents = '';
while ( ! feof($temp) )
$contents .= fread($temp, 8192);
while ( ! feof( $temp ) ) {
$contents .= fread( $temp, 8192 );
}
fclose($temp);
unlink($tempfile);
fclose( $temp );
unlink( $tempfile );
return $contents;
}
/**
*
* @param string $file
* @return array
*/
public function get_contents_array($file) {
return explode("\n", $this->get_contents($file));
public function get_contents_array( $file ) {
return explode( "\n", $this->get_contents( $file ) );
}
/**
*
* @param string $file
* @param string $contents
* @param bool|int $mode
* @return bool
*/
public function put_contents($file, $contents, $mode = false ) {
$tempfile = wp_tempnam($file);
$temp = fopen( $tempfile, 'wb+' );
public function put_contents( $file, $contents, $mode = false ) {
$tempfile = wp_tempnam( $file );
$temp = fopen( $tempfile, 'wb+' );
if ( ! $temp ) {
unlink( $tempfile );
@ -161,7 +170,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
mbstring_binary_safe_encoding();
$data_length = strlen( $contents );
$data_length = strlen( $contents );
$bytes_written = fwrite( $temp, $contents );
reset_mbstring_encoding();
@ -176,334 +185,331 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY );
fclose($temp);
unlink($tempfile);
fclose( $temp );
unlink( $tempfile );
$this->chmod($file, $mode);
$this->chmod( $file, $mode );
return $ret;
}
/**
*
* @return string
*/
public function cwd() {
$cwd = @ftp_pwd($this->link);
if ( $cwd )
$cwd = trailingslashit($cwd);
$cwd = @ftp_pwd( $this->link );
if ( $cwd ) {
$cwd = trailingslashit( $cwd );
}
return $cwd;
}
/**
*
* @param string $dir
* @return bool
*/
public function chdir($dir) {
return @ftp_chdir($this->link, $dir);
public function chdir( $dir ) {
return @ftp_chdir( $this->link, $dir );
}
/**
*
* @param string $file
* @param int $mode
* @param bool $recursive
* @return bool
*/
public function chmod($file, $mode = false, $recursive = false) {
public function chmod( $file, $mode = false, $recursive = false ) {
if ( ! $mode ) {
if ( $this->is_file($file) )
if ( $this->is_file( $file ) ) {
$mode = FS_CHMOD_FILE;
elseif ( $this->is_dir($file) )
} elseif ( $this->is_dir( $file ) ) {
$mode = FS_CHMOD_DIR;
else
} else {
return false;
}
}
// chmod any sub-objects if recursive.
if ( $recursive && $this->is_dir($file) ) {
$filelist = $this->dirlist($file);
foreach ( (array)$filelist as $filename => $filemeta )
$this->chmod($file . '/' . $filename, $mode, $recursive);
if ( $recursive && $this->is_dir( $file ) ) {
$filelist = $this->dirlist( $file );
foreach ( (array) $filelist as $filename => $filemeta ) {
$this->chmod( $file . '/' . $filename, $mode, $recursive );
}
}
// chmod the file or directory
if ( ! function_exists('ftp_chmod') )
return (bool)@ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
return (bool)@ftp_chmod($this->link, $mode, $file);
if ( ! function_exists( 'ftp_chmod' ) ) {
return (bool) @ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
}
return (bool) @ftp_chmod( $this->link, $mode, $file );
}
/**
*
* @param string $file
* @return string
*/
public function owner($file) {
$dir = $this->dirlist($file);
return $dir[$file]['owner'];
public function owner( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['owner'];
}
/**
*
* @param string $file
* @return string
*/
public function getchmod($file) {
$dir = $this->dirlist($file);
return $dir[$file]['permsn'];
public function getchmod( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['permsn'];
}
/**
*
* @param string $file
* @return string
*/
public function group($file) {
$dir = $this->dirlist($file);
return $dir[$file]['group'];
public function group( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['group'];
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @param string|bool $mode
* @return bool
*/
public function copy($source, $destination, $overwrite = false, $mode = false) {
if ( ! $overwrite && $this->exists($destination) )
public function copy( $source, $destination, $overwrite = false, $mode = false ) {
if ( ! $overwrite && $this->exists( $destination ) ) {
return false;
$content = $this->get_contents($source);
if ( false === $content )
}
$content = $this->get_contents( $source );
if ( false === $content ) {
return false;
return $this->put_contents($destination, $content, $mode);
}
return $this->put_contents( $destination, $content, $mode );
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @return bool
*/
public function move($source, $destination, $overwrite = false) {
return ftp_rename($this->link, $source, $destination);
public function move( $source, $destination, $overwrite = false ) {
return ftp_rename( $this->link, $source, $destination );
}
/**
*
* @param string $file
* @param bool $recursive
* @param string $type
* @return bool
*/
public function delete($file, $recursive = false, $type = false) {
if ( empty($file) )
public function delete( $file, $recursive = false, $type = false ) {
if ( empty( $file ) ) {
return false;
if ( 'f' == $type || $this->is_file($file) )
return @ftp_delete($this->link, $file);
if ( !$recursive )
return @ftp_rmdir($this->link, $file);
}
if ( 'f' == $type || $this->is_file( $file ) ) {
return @ftp_delete( $this->link, $file );
}
if ( ! $recursive ) {
return @ftp_rmdir( $this->link, $file );
}
$filelist = $this->dirlist( trailingslashit($file) );
if ( !empty($filelist) )
foreach ( $filelist as $delete_file )
$this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] );
return @ftp_rmdir($this->link, $file);
$filelist = $this->dirlist( trailingslashit( $file ) );
if ( ! empty( $filelist ) ) {
foreach ( $filelist as $delete_file ) {
$this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] );
}
}
return @ftp_rmdir( $this->link, $file );
}
/**
*
* @param string $file
* @return bool
*/
public function exists($file) {
$list = @ftp_nlist($this->link, $file);
public function exists( $file ) {
$list = @ftp_nlist( $this->link, $file );
if ( empty( $list ) && $this->is_dir( $file ) ) {
return true; // File is an empty directory.
}
return !empty($list); //empty list = no file, so invert.
return ! empty( $list ); //empty list = no file, so invert.
}
/**
*
* @param string $file
* @return bool
*/
public function is_file($file) {
return $this->exists($file) && !$this->is_dir($file);
public function is_file( $file ) {
return $this->exists( $file ) && ! $this->is_dir( $file );
}
/**
*
* @param string $path
* @return bool
*/
public function is_dir($path) {
$cwd = $this->cwd();
$result = @ftp_chdir($this->link, trailingslashit($path) );
public function is_dir( $path ) {
$cwd = $this->cwd();
$result = @ftp_chdir( $this->link, trailingslashit( $path ) );
if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
@ftp_chdir($this->link, $cwd);
@ftp_chdir( $this->link, $cwd );
return true;
}
return false;
}
/**
*
* @param string $file
* @return bool
*/
public function is_readable($file) {
public function is_readable( $file ) {
return true;
}
/**
*
* @param string $file
* @return bool
*/
public function is_writable($file) {
public function is_writable( $file ) {
return true;
}
/**
*
* @param string $file
* @return bool
*/
public function atime($file) {
public function atime( $file ) {
return false;
}
/**
*
* @param string $file
* @return int
*/
public function mtime($file) {
return ftp_mdtm($this->link, $file);
public function mtime( $file ) {
return ftp_mdtm( $this->link, $file );
}
/**
*
* @param string $file
* @return int
*/
public function size($file) {
return ftp_size($this->link, $file);
public function size( $file ) {
return ftp_size( $this->link, $file );
}
/**
*
* @param string $file
* @return bool
*/
public function touch($file, $time = 0, $atime = 0) {
public function touch( $file, $time = 0, $atime = 0 ) {
return false;
}
/**
*
* @param string $path
* @param mixed $chmod
* @param mixed $chown
* @param mixed $chgrp
* @return bool
*/
public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
$path = untrailingslashit($path);
if ( empty($path) )
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path );
if ( empty( $path ) ) {
return false;
}
if ( !@ftp_mkdir($this->link, $path) )
if ( ! @ftp_mkdir( $this->link, $path ) ) {
return false;
$this->chmod($path, $chmod);
}
$this->chmod( $path, $chmod );
return true;
}
/**
*
* @param string $path
* @param bool $recursive
* @return bool
*/
public function rmdir($path, $recursive = false) {
return $this->delete($path, $recursive);
public function rmdir( $path, $recursive = false ) {
return $this->delete( $path, $recursive );
}
/**
*
* @staticvar bool $is_windows
* @param string $line
* @return array
*/
public function parselisting($line) {
public function parselisting( $line ) {
static $is_windows = null;
if ( is_null($is_windows) )
$is_windows = stripos( ftp_systype($this->link), 'win') !== false;
if ( is_null( $is_windows ) ) {
$is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false;
}
if ( $is_windows && preg_match('/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer) ) {
if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) {
$b = array();
if ( $lucifer[3] < 70 )
$lucifer[3] +=2000;
else
if ( $lucifer[3] < 70 ) {
$lucifer[3] += 2000;
} else {
$lucifer[3] += 1900; // 4digit year fix
$b['isdir'] = ( $lucifer[7] == '<DIR>');
if ( $b['isdir'] )
}
$b['isdir'] = ( $lucifer[7] == '<DIR>' );
if ( $b['isdir'] ) {
$b['type'] = 'd';
else
} else {
$b['type'] = 'f';
$b['size'] = $lucifer[7];
$b['month'] = $lucifer[1];
$b['day'] = $lucifer[2];
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
}
$b['size'] = $lucifer[7];
$b['month'] = $lucifer[1];
$b['day'] = $lucifer[2];
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
$b['minute'] = $lucifer[5];
$b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {
$b['time'] = @mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) == 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] );
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} elseif ( ! $is_windows && $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ) ) {
//echo $line."\n";
$lcount = count($lucifer);
if ( $lcount < 8 )
$lcount = count( $lucifer );
if ( $lcount < 8 ) {
return '';
$b = array();
$b['isdir'] = $lucifer[0]{0} === 'd';
}
$b = array();
$b['isdir'] = $lucifer[0]{0} === 'd';
$b['islink'] = $lucifer[0]{0} === 'l';
if ( $b['isdir'] )
if ( $b['isdir'] ) {
$b['type'] = 'd';
elseif ( $b['islink'] )
} elseif ( $b['islink'] ) {
$b['type'] = 'l';
else
} else {
$b['type'] = 'f';
$b['perms'] = $lucifer[0];
}
$b['perms'] = $lucifer[0];
$b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
$b['number'] = $lucifer[1];
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
$b['size'] = $lucifer[4];
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
$b['size'] = $lucifer[4];
if ( $lcount == 8 ) {
sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
$b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
$b['time'] = @mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
$b['name'] = $lucifer[7];
} else {
$b['month'] = $lucifer[5];
$b['day'] = $lucifer[6];
if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {
$b['year'] = date("Y");
$b['hour'] = $l2[1];
$b['day'] = $lucifer[6];
if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) {
$b['year'] = date( 'Y' );
$b['hour'] = $l2[1];
$b['minute'] = $l2[2];
} else {
$b['year'] = $lucifer[7];
$b['hour'] = 0;
$b['year'] = $lucifer[7];
$b['hour'] = 0;
$b['minute'] = 0;
}
$b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) );
$b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) );
$b['name'] = $lucifer[8];
}
}
@ -517,54 +523,60 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
}
/**
*
* @param string $path
* @param bool $include_hidden
* @param bool $recursive
* @return bool|array
*/
public function dirlist($path = '.', $include_hidden = true, $recursive = false) {
if ( $this->is_file($path) ) {
$limit_file = basename($path);
$path = dirname($path) . '/';
public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) {
if ( $this->is_file( $path ) ) {
$limit_file = basename( $path );
$path = dirname( $path ) . '/';
} else {
$limit_file = false;
}
$pwd = @ftp_pwd($this->link);
if ( ! @ftp_chdir($this->link, $path) ) // Cant change to folder = folder doesn't exist
$pwd = @ftp_pwd( $this->link );
if ( ! @ftp_chdir( $this->link, $path ) ) { // Cant change to folder = folder doesn't exist
return false;
$list = @ftp_rawlist($this->link, '-a', false);
@ftp_chdir($this->link, $pwd);
}
$list = @ftp_rawlist( $this->link, '-a', false );
@ftp_chdir( $this->link, $pwd );
if ( empty($list) ) // Empty array = non-existent folder (real folder will show . at least)
if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least)
return false;
}
$dirlist = array();
foreach ( $list as $k => $v ) {
$entry = $this->parselisting($v);
if ( empty($entry) )
$entry = $this->parselisting( $v );
if ( empty( $entry ) ) {
continue;
}
if ( '.' == $entry['name'] || '..' == $entry['name'] )
if ( '.' == $entry['name'] || '..' == $entry['name'] ) {
continue;
}
if ( ! $include_hidden && '.' == $entry['name'][0] )
if ( ! $include_hidden && '.' == $entry['name'][0] ) {
continue;
}
if ( $limit_file && $entry['name'] != $limit_file)
if ( $limit_file && $entry['name'] != $limit_file ) {
continue;
}
$dirlist[ $entry['name'] ] = $entry;
}
$ret = array();
foreach ( (array)$dirlist as $struc ) {
foreach ( (array) $dirlist as $struc ) {
if ( 'd' == $struc['type'] ) {
if ( $recursive )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
else
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
$ret[ $struc['name'] ] = $struc;
@ -575,7 +587,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
/**
*/
public function __destruct() {
if ( $this->link )
ftp_close($this->link);
if ( $this->link ) {
ftp_close( $this->link );
}
}
}

View file

@ -20,10 +20,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
public $ftp;
/**
*
* @param array $opt
*/
public function __construct( $opt = '' ) {
public function __construct( $opt = '' ) {
$this->method = 'ftpsockets';
$this->errors = new WP_Error();
@ -33,42 +32,48 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
}
$this->ftp = new ftp();
if ( empty($opt['port']) )
if ( empty( $opt['port'] ) ) {
$this->options['port'] = 21;
else
} else {
$this->options['port'] = (int) $opt['port'];
}
if ( empty($opt['hostname']) )
$this->errors->add('empty_hostname', __('FTP hostname is required'));
else
if ( empty( $opt['hostname'] ) ) {
$this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) );
} else {
$this->options['hostname'] = $opt['hostname'];
}
// Check if the options provided are OK.
if ( empty ($opt['username']) )
$this->errors->add('empty_username', __('FTP username is required'));
else
if ( empty( $opt['username'] ) ) {
$this->errors->add( 'empty_username', __( 'FTP username is required' ) );
} else {
$this->options['username'] = $opt['username'];
}
if ( empty ($opt['password']) )
$this->errors->add('empty_password', __('FTP password is required'));
else
if ( empty( $opt['password'] ) ) {
$this->errors->add( 'empty_password', __( 'FTP password is required' ) );
} else {
$this->options['password'] = $opt['password'];
}
}
/**
*
* @return bool
*/
public function connect() {
if ( ! $this->ftp )
if ( ! $this->ftp ) {
return false;
}
$this->ftp->setTimeout(FS_CONNECT_TIMEOUT);
$this->ftp->setTimeout( FS_CONNECT_TIMEOUT );
if ( ! $this->ftp->SetServer( $this->options['hostname'], $this->options['port'] ) ) {
$this->errors->add( 'connect',
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf( __( 'Failed to connect to FTP Server %s' ),
sprintf(
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
@ -76,9 +81,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
}
if ( ! $this->ftp->connect() ) {
$this->errors->add( 'connect',
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf( __( 'Failed to connect to FTP Server %s' ),
sprintf(
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
@ -86,9 +93,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
}
if ( ! $this->ftp->login( $this->options['username'], $this->options['password'] ) ) {
$this->errors->add( 'auth',
$this->errors->add(
'auth',
/* translators: %s: username */
sprintf( __( 'Username/Password incorrect for %s' ),
sprintf(
__( 'Username/Password incorrect for %s' ),
$this->options['username']
)
);
@ -111,8 +120,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
* or if the file doesn't exist.
*/
public function get_contents( $file ) {
if ( ! $this->exists($file) )
if ( ! $this->exists( $file ) ) {
return false;
}
$temp = wp_tempnam( $file );
@ -123,9 +133,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
mbstring_binary_safe_encoding();
if ( ! $this->ftp->fget($temphandle, $file) ) {
fclose($temphandle);
unlink($temp);
if ( ! $this->ftp->fget( $temphandle, $file ) ) {
fclose( $temphandle );
unlink( $temp );
reset_mbstring_encoding();
@ -137,34 +147,33 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
$contents = '';
while ( ! feof($temphandle) )
$contents .= fread($temphandle, 8192);
while ( ! feof( $temphandle ) ) {
$contents .= fread( $temphandle, 8192 );
}
fclose($temphandle);
unlink($temp);
fclose( $temphandle );
unlink( $temp );
return $contents;
}
/**
*
* @param string $file
* @return array
*/
public function get_contents_array($file) {
return explode("\n", $this->get_contents($file) );
public function get_contents_array( $file ) {
return explode( "\n", $this->get_contents( $file ) );
}
/**
*
* @param string $file
* @param string $contents
* @param int|bool $mode
* @return bool
*/
public function put_contents($file, $contents, $mode = false ) {
public function put_contents( $file, $contents, $mode = false ) {
$temp = wp_tempnam( $file );
if ( ! $temphandle = @fopen($temp, 'w+') ) {
unlink($temp);
if ( ! $temphandle = @fopen( $temp, 'w+' ) ) {
unlink( $temp );
return false;
}
@ -183,146 +192,144 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
$ret = $this->ftp->fput($file, $temphandle);
$ret = $this->ftp->fput( $file, $temphandle );
reset_mbstring_encoding();
fclose($temphandle);
unlink($temp);
fclose( $temphandle );
unlink( $temp );
$this->chmod($file, $mode);
$this->chmod( $file, $mode );
return $ret;
}
/**
*
* @return string
*/
public function cwd() {
$cwd = $this->ftp->pwd();
if ( $cwd )
$cwd = trailingslashit($cwd);
if ( $cwd ) {
$cwd = trailingslashit( $cwd );
}
return $cwd;
}
/**
*
* @param string $file
* @return bool
*/
public function chdir($file) {
return $this->ftp->chdir($file);
public function chdir( $file ) {
return $this->ftp->chdir( $file );
}
/**
*
* @param string $file
* @param int|bool $mode
* @param bool $recursive
* @return bool
*/
public function chmod($file, $mode = false, $recursive = false ) {
public function chmod( $file, $mode = false, $recursive = false ) {
if ( ! $mode ) {
if ( $this->is_file($file) )
if ( $this->is_file( $file ) ) {
$mode = FS_CHMOD_FILE;
elseif ( $this->is_dir($file) )
} elseif ( $this->is_dir( $file ) ) {
$mode = FS_CHMOD_DIR;
else
} else {
return false;
}
}
// chmod any sub-objects if recursive.
if ( $recursive && $this->is_dir($file) ) {
$filelist = $this->dirlist($file);
foreach ( (array)$filelist as $filename => $filemeta )
$this->chmod($file . '/' . $filename, $mode, $recursive);
if ( $recursive && $this->is_dir( $file ) ) {
$filelist = $this->dirlist( $file );
foreach ( (array) $filelist as $filename => $filemeta ) {
$this->chmod( $file . '/' . $filename, $mode, $recursive );
}
}
// chmod the file or directory
return $this->ftp->chmod($file, $mode);
return $this->ftp->chmod( $file, $mode );
}
/**
*
* @param string $file
* @return string
*/
public function owner($file) {
$dir = $this->dirlist($file);
return $dir[$file]['owner'];
public function owner( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['owner'];
}
/**
*
* @param string $file
* @return string
*/
public function getchmod($file) {
$dir = $this->dirlist($file);
return $dir[$file]['permsn'];
public function getchmod( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['permsn'];
}
/**
*
* @param string $file
* @return string
*/
public function group($file) {
$dir = $this->dirlist($file);
return $dir[$file]['group'];
public function group( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['group'];
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @param int|bool $mode
* @return bool
*/
public function copy($source, $destination, $overwrite = false, $mode = false) {
if ( ! $overwrite && $this->exists($destination) )
public function copy( $source, $destination, $overwrite = false, $mode = false ) {
if ( ! $overwrite && $this->exists( $destination ) ) {
return false;
}
$content = $this->get_contents($source);
if ( false === $content )
$content = $this->get_contents( $source );
if ( false === $content ) {
return false;
}
return $this->put_contents($destination, $content, $mode);
return $this->put_contents( $destination, $content, $mode );
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @return bool
*/
public function move($source, $destination, $overwrite = false ) {
return $this->ftp->rename($source, $destination);
public function move( $source, $destination, $overwrite = false ) {
return $this->ftp->rename( $source, $destination );
}
/**
*
* @param string $file
* @param bool $recursive
* @param string $type
* @return bool
*/
public function delete($file, $recursive = false, $type = false) {
if ( empty($file) )
public function delete( $file, $recursive = false, $type = false ) {
if ( empty( $file ) ) {
return false;
if ( 'f' == $type || $this->is_file($file) )
return $this->ftp->delete($file);
if ( !$recursive )
return $this->ftp->rmdir($file);
}
if ( 'f' == $type || $this->is_file( $file ) ) {
return $this->ftp->delete( $file );
}
if ( ! $recursive ) {
return $this->ftp->rmdir( $file );
}
return $this->ftp->mdel($file);
return $this->ftp->mdel( $file );
}
/**
*
* @param string $file
* @return bool
*/
@ -333,141 +340,136 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return true; // File is an empty directory.
}
return !empty( $list ); //empty list = no file, so invert.
return ! empty( $list ); //empty list = no file, so invert.
// Return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server.
}
/**
*
* @param string $file
* @return bool
*/
public function is_file($file) {
if ( $this->is_dir($file) )
public function is_file( $file ) {
if ( $this->is_dir( $file ) ) {
return false;
if ( $this->exists($file) )
return true;
return false;
}
/**
*
* @param string $path
* @return bool
*/
public function is_dir($path) {
$cwd = $this->cwd();
if ( $this->chdir($path) ) {
$this->chdir($cwd);
}
if ( $this->exists( $file ) ) {
return true;
}
return false;
}
/**
*
* @param string $file
* @param string $path
* @return bool
*/
public function is_readable($file) {
return true;
}
/**
*
* @param string $file
* @return bool
*/
public function is_writable($file) {
return true;
}
/**
*
* @param string $file
* @return bool
*/
public function atime($file) {
public function is_dir( $path ) {
$cwd = $this->cwd();
if ( $this->chdir( $path ) ) {
$this->chdir( $cwd );
return true;
}
return false;
}
/**
*
* @param string $file
* @return int
* @return bool
*/
public function mtime($file) {
return $this->ftp->mdtm($file);
public function is_readable( $file ) {
return true;
}
/**
* @param string $file
* @return bool
*/
public function is_writable( $file ) {
return true;
}
/**
* @param string $file
* @return bool
*/
public function atime( $file ) {
return false;
}
/**
* @param string $file
* @return int
*/
public function size($file) {
return $this->ftp->filesize($file);
public function mtime( $file ) {
return $this->ftp->mdtm( $file );
}
/**
* @param string $file
* @return int
*/
public function size( $file ) {
return $this->ftp->filesize( $file );
}
/**
*
* @param string $file
* @param int $time
* @param int $atime
* @return bool
*/
public function touch($file, $time = 0, $atime = 0 ) {
public function touch( $file, $time = 0, $atime = 0 ) {
return false;
}
/**
*
* @param string $path
* @param mixed $chmod
* @param mixed $chown
* @param mixed $chgrp
* @return bool
*/
public function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit($path);
if ( empty($path) )
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path );
if ( empty( $path ) ) {
return false;
}
if ( ! $this->ftp->mkdir($path) )
if ( ! $this->ftp->mkdir( $path ) ) {
return false;
if ( ! $chmod )
}
if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR;
$this->chmod($path, $chmod);
}
$this->chmod( $path, $chmod );
return true;
}
/**
*
* @param string $path
* @param bool $recursive
* @return bool
*/
public function rmdir($path, $recursive = false ) {
return $this->delete($path, $recursive);
public function rmdir( $path, $recursive = false ) {
return $this->delete( $path, $recursive );
}
/**
*
* @param string $path
* @param bool $include_hidden
* @param bool $recursive
* @return bool|array
*/
public function dirlist($path = '.', $include_hidden = true, $recursive = false ) {
if ( $this->is_file($path) ) {
$limit_file = basename($path);
$path = dirname($path) . '/';
public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) {
if ( $this->is_file( $path ) ) {
$limit_file = basename( $path );
$path = dirname( $path ) . '/';
} else {
$limit_file = false;
}
mbstring_binary_safe_encoding();
$list = $this->ftp->dirlist($path);
$list = $this->ftp->dirlist( $path );
if ( empty( $list ) && ! $this->exists( $path ) ) {
reset_mbstring_encoding();
@ -478,25 +480,30 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$ret = array();
foreach ( $list as $struc ) {
if ( '.' == $struc['name'] || '..' == $struc['name'] )
if ( '.' == $struc['name'] || '..' == $struc['name'] ) {
continue;
}
if ( ! $include_hidden && '.' == $struc['name'][0] )
if ( ! $include_hidden && '.' == $struc['name'][0] ) {
continue;
}
if ( $limit_file && $struc['name'] != $limit_file )
if ( $limit_file && $struc['name'] != $limit_file ) {
continue;
}
if ( 'd' == $struc['type'] ) {
if ( $recursive )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
else
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
// Replace symlinks formatted as "source -> target" with just the source name
if ( $struc['islink'] )
if ( $struc['islink'] ) {
$struc['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $struc['name'] );
}
// Add the Octal representation of the file permissions
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] );

View file

@ -46,7 +46,6 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
public $keys = false;
/**
*
* @param array $opt
*/
public function __construct( $opt = '' ) {
@ -54,11 +53,11 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$this->errors = new WP_Error();
//Check if possible to use ssh2 functions.
if ( ! extension_loaded('ssh2') ) {
$this->errors->add('no_ssh2_ext', __('The ssh2 PHP extension is not available'));
if ( ! extension_loaded( 'ssh2' ) ) {
$this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) );
return;
}
if ( !function_exists('stream_get_contents') ) {
if ( ! function_exists( 'stream_get_contents' ) ) {
$this->errors->add(
'ssh2_php_requirement',
sprintf(
@ -71,76 +70,85 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
}
// Set defaults:
if ( empty($opt['port']) )
if ( empty( $opt['port'] ) ) {
$this->options['port'] = 22;
else
} else {
$this->options['port'] = $opt['port'];
if ( empty($opt['hostname']) )
$this->errors->add('empty_hostname', __('SSH2 hostname is required'));
else
$this->options['hostname'] = $opt['hostname'];
// Check if the options provided are OK.
if ( !empty ($opt['public_key']) && !empty ($opt['private_key']) ) {
$this->options['public_key'] = $opt['public_key'];
$this->options['private_key'] = $opt['private_key'];
$this->options['hostkey'] = array('hostkey' => 'ssh-rsa');
$this->keys = true;
} elseif ( empty ($opt['username']) ) {
$this->errors->add('empty_username', __('SSH2 username is required'));
}
if ( !empty($opt['username']) )
$this->options['username'] = $opt['username'];
if ( empty( $opt['hostname'] ) ) {
$this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) );
} else {
$this->options['hostname'] = $opt['hostname'];
}
if ( empty ($opt['password']) ) {
// Check if the options provided are OK.
if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) {
$this->options['public_key'] = $opt['public_key'];
$this->options['private_key'] = $opt['private_key'];
$this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa' );
$this->keys = true;
} elseif ( empty( $opt['username'] ) ) {
$this->errors->add( 'empty_username', __( 'SSH2 username is required' ) );
}
if ( ! empty( $opt['username'] ) ) {
$this->options['username'] = $opt['username'];
}
if ( empty( $opt['password'] ) ) {
// Password can be blank if we are using keys.
if ( !$this->keys )
$this->errors->add('empty_password', __('SSH2 password is required'));
if ( ! $this->keys ) {
$this->errors->add( 'empty_password', __( 'SSH2 password is required' ) );
}
} else {
$this->options['password'] = $opt['password'];
}
}
/**
*
* @return bool
*/
public function connect() {
if ( ! $this->keys ) {
$this->link = @ssh2_connect($this->options['hostname'], $this->options['port']);
$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'] );
} else {
$this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']);
$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] );
}
if ( ! $this->link ) {
$this->errors->add( 'connect',
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf( __( 'Failed to connect to SSH2 Server %s' ),
sprintf(
__( 'Failed to connect to SSH2 Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
if ( !$this->keys ) {
if ( ! @ssh2_auth_password($this->link, $this->options['username'], $this->options['password']) ) {
$this->errors->add( 'auth',
if ( ! $this->keys ) {
if ( ! @ssh2_auth_password( $this->link, $this->options['username'], $this->options['password'] ) ) {
$this->errors->add(
'auth',
/* translators: %s: username */
sprintf( __( 'Username/Password incorrect for %s' ),
sprintf(
__( 'Username/Password incorrect for %s' ),
$this->options['username']
)
);
return false;
}
} else {
if ( ! @ssh2_auth_pubkey_file($this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) {
$this->errors->add( 'auth',
if ( ! @ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) {
$this->errors->add(
'auth',
/* translators: %s: username */
sprintf( __( 'Public and Private keys incorrect for %s' ),
sprintf(
__( 'Public and Private keys incorrect for %s' ),
$this->options['username']
)
);
@ -150,9 +158,11 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$this->sftp_link = ssh2_sftp( $this->link );
if ( ! $this->sftp_link ) {
$this->errors->add( 'connect',
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf( __( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ),
sprintf(
__( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
@ -170,7 +180,6 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
* this, the path is converted to /./ which is semantically the same as /
* See https://bugs.php.net/bug.php?id=64169 for more details.
*
*
* @since 4.4.0
*
* @param string $path The File/Directory path on the remote server to return
@ -184,20 +193,22 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
}
/**
*
* @param string $command
* @param bool $returnbool
* @return bool|string True on success, false on failure. String if the command was executed, `$returnbool`
* is false (default), and data from the resulting stream was retrieved.
*/
public function run_command( $command, $returnbool = false ) {
if ( ! $this->link )
if ( ! $this->link ) {
return false;
}
if ( ! ($stream = ssh2_exec($this->link, $command)) ) {
$this->errors->add( 'command',
if ( ! ( $stream = ssh2_exec( $this->link, $command ) ) ) {
$this->errors->add(
'command',
/* translators: %s: command */
sprintf( __( 'Unable to perform command: %s'),
sprintf(
__( 'Unable to perform command: %s' ),
$command
)
);
@ -207,16 +218,16 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$data = stream_get_contents( $stream );
fclose( $stream );
if ( $returnbool )
return ( $data === false ) ? false : '' != trim($data);
else
if ( $returnbool ) {
return ( $data === false ) ? false : '' != trim( $data );
} else {
return $data;
}
}
return false;
}
/**
*
* @param string $file
* @return string|false
*/
@ -225,34 +236,32 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
}
/**
*
* @param string $file
* @return array
*/
public function get_contents_array($file) {
public function get_contents_array( $file ) {
return file( $this->sftp_path( $file ) );
}
/**
*
* @param string $file
* @param string $contents
* @param bool|int $mode
* @return bool
*/
public function put_contents($file, $contents, $mode = false ) {
public function put_contents( $file, $contents, $mode = false ) {
$ret = file_put_contents( $this->sftp_path( $file ), $contents );
if ( $ret !== strlen( $contents ) )
if ( $ret !== strlen( $contents ) ) {
return false;
}
$this->chmod($file, $mode);
$this->chmod( $file, $mode );
return true;
}
/**
*
* @return bool
*/
public function cwd() {
@ -264,336 +273,340 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
}
/**
*
* @param string $dir
* @return bool|string
*/
public function chdir($dir) {
return $this->run_command('cd ' . $dir, true);
public function chdir( $dir ) {
return $this->run_command( 'cd ' . $dir, true );
}
/**
*
* @param string $file
* @param string $group
* @param bool $recursive
*
* @return bool
*/
public function chgrp($file, $group, $recursive = false ) {
if ( ! $this->exists($file) )
public function chgrp( $file, $group, $recursive = false ) {
if ( ! $this->exists( $file ) ) {
return false;
if ( ! $recursive || ! $this->is_dir($file) )
return $this->run_command(sprintf('chgrp %s %s', escapeshellarg($group), escapeshellarg($file)), true);
return $this->run_command(sprintf('chgrp -R %s %s', escapeshellarg($group), escapeshellarg($file)), true);
}
if ( ! $recursive || ! $this->is_dir( $file ) ) {
return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
}
return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
}
/**
*
* @param string $file
* @param int $mode
* @param bool $recursive
* @return bool|string
*/
public function chmod($file, $mode = false, $recursive = false) {
if ( ! $this->exists($file) )
public function chmod( $file, $mode = false, $recursive = false ) {
if ( ! $this->exists( $file ) ) {
return false;
if ( ! $mode ) {
if ( $this->is_file($file) )
$mode = FS_CHMOD_FILE;
elseif ( $this->is_dir($file) )
$mode = FS_CHMOD_DIR;
else
return false;
}
if ( ! $recursive || ! $this->is_dir($file) )
return $this->run_command(sprintf('chmod %o %s', $mode, escapeshellarg($file)), true);
return $this->run_command(sprintf('chmod -R %o %s', $mode, escapeshellarg($file)), true);
if ( ! $mode ) {
if ( $this->is_file( $file ) ) {
$mode = FS_CHMOD_FILE;
} elseif ( $this->is_dir( $file ) ) {
$mode = FS_CHMOD_DIR;
} else {
return false;
}
}
if ( ! $recursive || ! $this->is_dir( $file ) ) {
return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true );
}
return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true );
}
/**
* Change the ownership of a file / folder.
*
*
* @param string $file Path to the file.
* @param string|int $owner A user name or number.
* @param bool $recursive Optional. If set True changes file owner recursivly. Default False.
* @return bool True on success or false on failure.
*/
public function chown( $file, $owner, $recursive = false ) {
if ( ! $this->exists($file) )
if ( ! $this->exists( $file ) ) {
return false;
if ( ! $recursive || ! $this->is_dir($file) )
return $this->run_command(sprintf('chown %s %s', escapeshellarg($owner), escapeshellarg($file)), true);
return $this->run_command(sprintf('chown -R %s %s', escapeshellarg($owner), escapeshellarg($file)), true);
}
if ( ! $recursive || ! $this->is_dir( $file ) ) {
return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
}
return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
}
/**
*
* @param string $file
* @return string|false
*/
public function owner($file) {
public function owner( $file ) {
$owneruid = @fileowner( $this->sftp_path( $file ) );
if ( ! $owneruid )
if ( ! $owneruid ) {
return false;
if ( ! function_exists('posix_getpwuid') )
}
if ( ! function_exists( 'posix_getpwuid' ) ) {
return $owneruid;
$ownerarray = posix_getpwuid($owneruid);
}
$ownerarray = posix_getpwuid( $owneruid );
return $ownerarray['name'];
}
/**
*
* @param string $file
* @return string
*/
public function getchmod($file) {
public function getchmod( $file ) {
return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 );
}
/**
*
* @param string $file
* @return string|false
*/
public function group($file) {
public function group( $file ) {
$gid = @filegroup( $this->sftp_path( $file ) );
if ( ! $gid )
if ( ! $gid ) {
return false;
if ( ! function_exists('posix_getgrgid') )
}
if ( ! function_exists( 'posix_getgrgid' ) ) {
return $gid;
$grouparray = posix_getgrgid($gid);
}
$grouparray = posix_getgrgid( $gid );
return $grouparray['name'];
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @param int|bool $mode
* @return bool
*/
public function copy($source, $destination, $overwrite = false, $mode = false) {
if ( ! $overwrite && $this->exists($destination) )
public function copy( $source, $destination, $overwrite = false, $mode = false ) {
if ( ! $overwrite && $this->exists( $destination ) ) {
return false;
$content = $this->get_contents($source);
if ( false === $content)
}
$content = $this->get_contents( $source );
if ( false === $content ) {
return false;
return $this->put_contents($destination, $content, $mode);
}
return $this->put_contents( $destination, $content, $mode );
}
/**
*
* @param string $source
* @param string $destination
* @param bool $overwrite
* @return bool
*/
public function move($source, $destination, $overwrite = false) {
public function move( $source, $destination, $overwrite = false ) {
return @ssh2_sftp_rename( $this->sftp_link, $source, $destination );
}
/**
*
* @param string $file
* @param bool $recursive
* @param string|bool $type
* @return bool
*/
public function delete($file, $recursive = false, $type = false) {
if ( 'f' == $type || $this->is_file($file) )
return ssh2_sftp_unlink($this->sftp_link, $file);
if ( ! $recursive )
return ssh2_sftp_rmdir($this->sftp_link, $file);
$filelist = $this->dirlist($file);
if ( is_array($filelist) ) {
foreach ( $filelist as $filename => $fileinfo) {
$this->delete($file . '/' . $filename, $recursive, $fileinfo['type']);
public function delete( $file, $recursive = false, $type = false ) {
if ( 'f' == $type || $this->is_file( $file ) ) {
return ssh2_sftp_unlink( $this->sftp_link, $file );
}
if ( ! $recursive ) {
return ssh2_sftp_rmdir( $this->sftp_link, $file );
}
$filelist = $this->dirlist( $file );
if ( is_array( $filelist ) ) {
foreach ( $filelist as $filename => $fileinfo ) {
$this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] );
}
}
return ssh2_sftp_rmdir($this->sftp_link, $file);
return ssh2_sftp_rmdir( $this->sftp_link, $file );
}
/**
*
* @param string $file
* @return bool
*/
public function exists($file) {
public function exists( $file ) {
return file_exists( $this->sftp_path( $file ) );
}
/**
*
* @param string $file
* @return bool
*/
public function is_file($file) {
public function is_file( $file ) {
return is_file( $this->sftp_path( $file ) );
}
/**
*
* @param string $path
* @return bool
*/
public function is_dir($path) {
public function is_dir( $path ) {
return is_dir( $this->sftp_path( $path ) );
}
/**
*
* @param string $file
* @return bool
*/
public function is_readable($file) {
public function is_readable( $file ) {
return is_readable( $this->sftp_path( $file ) );
}
/**
*
* @param string $file
* @return bool
*/
public function is_writable($file) {
public function is_writable( $file ) {
// PHP will base it's writable checks on system_user === file_owner, not ssh_user === file_owner
return true;
}
/**
*
* @param string $file
* @return int
*/
public function atime($file) {
public function atime( $file ) {
return fileatime( $this->sftp_path( $file ) );
}
/**
*
* @param string $file
* @return int
*/
public function mtime($file) {
public function mtime( $file ) {
return filemtime( $this->sftp_path( $file ) );
}
/**
*
* @param string $file
* @return int
*/
public function size($file) {
public function size( $file ) {
return filesize( $this->sftp_path( $file ) );
}
/**
*
* @param string $file
* @param int $time
* @param int $atime
*/
public function touch($file, $time = 0, $atime = 0) {
public function touch( $file, $time = 0, $atime = 0 ) {
//Not implemented.
}
/**
*
* @param string $path
* @param mixed $chmod
* @param mixed $chown
* @param mixed $chgrp
* @return bool
*/
public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
$path = untrailingslashit($path);
if ( empty($path) )
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path );
if ( empty( $path ) ) {
return false;
}
if ( ! $chmod )
if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR;
if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )
}
if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) {
return false;
if ( $chown )
$this->chown($path, $chown);
if ( $chgrp )
$this->chgrp($path, $chgrp);
}
if ( $chown ) {
$this->chown( $path, $chown );
}
if ( $chgrp ) {
$this->chgrp( $path, $chgrp );
}
return true;
}
/**
*
* @param string $path
* @param bool $recursive
* @return bool
*/
public function rmdir($path, $recursive = false) {
return $this->delete($path, $recursive);
public function rmdir( $path, $recursive = false ) {
return $this->delete( $path, $recursive );
}
/**
*
* @param string $path
* @param bool $include_hidden
* @param bool $recursive
* @return bool|array
*/
public function dirlist($path, $include_hidden = true, $recursive = false) {
if ( $this->is_file($path) ) {
$limit_file = basename($path);
$path = dirname($path);
public function dirlist( $path, $include_hidden = true, $recursive = false ) {
if ( $this->is_file( $path ) ) {
$limit_file = basename( $path );
$path = dirname( $path );
} else {
$limit_file = false;
}
if ( ! $this->is_dir($path) )
if ( ! $this->is_dir( $path ) ) {
return false;
}
$ret = array();
$dir = @dir( $this->sftp_path( $path ) );
if ( ! $dir )
if ( ! $dir ) {
return false;
}
while (false !== ($entry = $dir->read()) ) {
$struc = array();
while ( false !== ( $entry = $dir->read() ) ) {
$struc = array();
$struc['name'] = $entry;
if ( '.' == $struc['name'] || '..' == $struc['name'] )
if ( '.' == $struc['name'] || '..' == $struc['name'] ) {
continue; //Do not care about these folders.
}
if ( ! $include_hidden && '.' == $struc['name'][0] )
if ( ! $include_hidden && '.' == $struc['name'][0] ) {
continue;
}
if ( $limit_file && $struc['name'] != $limit_file )
if ( $limit_file && $struc['name'] != $limit_file ) {
continue;
}
$struc['perms'] = $this->gethchmod($path.'/'.$entry);
$struc['permsn'] = $this->getnumchmodfromh($struc['perms']);
$struc['number'] = false;
$struc['owner'] = $this->owner($path.'/'.$entry);
$struc['group'] = $this->group($path.'/'.$entry);
$struc['size'] = $this->size($path.'/'.$entry);
$struc['lastmodunix']= $this->mtime($path.'/'.$entry);
$struc['lastmod'] = date('M j',$struc['lastmodunix']);
$struc['time'] = date('h:i:s',$struc['lastmodunix']);
$struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
$struc['perms'] = $this->gethchmod( $path . '/' . $entry );
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] );
$struc['number'] = false;
$struc['owner'] = $this->owner( $path . '/' . $entry );
$struc['group'] = $this->group( $path . '/' . $entry );
$struc['size'] = $this->size( $path . '/' . $entry );
$struc['lastmodunix'] = $this->mtime( $path . '/' . $entry );
$struc['lastmod'] = date( 'M j', $struc['lastmodunix'] );
$struc['time'] = date( 'h:i:s', $struc['lastmodunix'] );
$struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
if ( 'd' == $struc['type'] ) {
if ( $recursive )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
else
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
$ret[ $struc['name'] ] = $struc;
}
$dir->close();
unset($dir);
unset( $dir );
return $ret;
}
}

View file

@ -5,7 +5,6 @@
class WP_Importer {
/**
* Class Constructor
*
*/
public function __construct() {}
@ -23,22 +22,22 @@ class WP_Importer {
$hashtable = array();
$limit = 100;
$limit = 100;
$offset = 0;
// Grab all posts in chunks
do {
$meta_key = $importer_name . '_' . $bid . '_permalink';
$sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
$results = $wpdb->get_results( $sql );
$sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
$results = $wpdb->get_results( $sql );
// Increment offset
$offset = ( $limit + $offset );
if ( !empty( $results ) ) {
if ( ! empty( $results ) ) {
foreach ( $results as $r ) {
// Set permalinks into array
$hashtable[$r->meta_value] = intval( $r->post_id );
$hashtable[ $r->meta_value ] = intval( $r->post_id );
}
}
} while ( count( $results ) == $limit );
@ -65,12 +64,13 @@ class WP_Importer {
// Get count of permalinks
$meta_key = $importer_name . '_' . $bid . '_permalink';
$sql = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key );
$sql = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key );
$result = $wpdb->get_results( $sql );
if ( !empty( $result ) )
if ( ! empty( $result ) ) {
$count = intval( $result[0]->cnt );
}
// Unset to save memory.
unset( $results );
@ -91,26 +91,26 @@ class WP_Importer {
$hashtable = array();
$limit = 100;
$limit = 100;
$offset = 0;
// Grab all comments in chunks
do {
$sql = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );
$sql = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );
$results = $wpdb->get_results( $sql );
// Increment offset
$offset = ( $limit + $offset );
if ( !empty( $results ) ) {
if ( ! empty( $results ) ) {
foreach ( $results as $r ) {
// Explode comment_agent key
list ( $ca_bid, $source_comment_id ) = explode( '-', $r->comment_agent );
$source_comment_id = intval( $source_comment_id );
$source_comment_id = intval( $source_comment_id );
// Check if this comment came from this blog
if ( $bid == $ca_bid ) {
$hashtable[$source_comment_id] = intval( $r->comment_ID );
$hashtable[ $source_comment_id ] = intval( $r->comment_ID );
}
}
}
@ -123,7 +123,6 @@ class WP_Importer {
}
/**
*
* @param int $blog_id
* @return int|void
*/
@ -132,32 +131,38 @@ class WP_Importer {
$blog_id = (int) $blog_id;
} else {
$blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
if ( ( ! $parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
exit();
}
if ( empty( $parsed['path'] ) ) {
$parsed['path'] = '/';
}
$blogs = get_sites( array( 'domain' => $parsed['host'], 'number' => 1, 'path' => $parsed['path'] ) );
$blogs = get_sites(
array(
'domain' => $parsed['host'],
'number' => 1,
'path' => $parsed['path'],
)
);
if ( ! $blogs ) {
fwrite( STDERR, "Error: Could not find blog\n" );
exit();
}
$blog = array_shift( $blogs );
$blog = array_shift( $blogs );
$blog_id = (int) $blog->blog_id;
}
if ( function_exists( 'is_multisite' ) ) {
if ( is_multisite() )
if ( is_multisite() ) {
switch_to_blog( $blog_id );
}
}
return $blog_id;
}
/**
*
* @param int $user_id
* @return int|void
*/
@ -168,7 +173,7 @@ class WP_Importer {
$user_id = (int) username_exists( $user_id );
}
if ( !$user_id || !wp_set_current_user( $user_id ) ) {
if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
fwrite( STDERR, "Error: can not find user\n" );
exit();
}
@ -201,11 +206,13 @@ class WP_Importer {
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
$headers = array();
$args = array();
if ( true === $head )
$args = array();
if ( true === $head ) {
$args['method'] = 'HEAD';
if ( !empty( $username ) && !empty( $password ) )
}
if ( ! empty( $username ) && ! empty( $password ) ) {
$headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" );
}
$args['headers'] = $headers;
@ -274,46 +281,49 @@ class WP_Importer {
*/
function get_cli_args( $param, $required = false ) {
$args = $_SERVER['argv'];
if ( ! is_array( $args ) ) {
$args = array();
}
$out = array();
$last_arg = null;
$return = null;
$return = null;
$il = sizeof( $args );
for ( $i = 1, $il; $i < $il; $i++ ) {
if ( (bool) preg_match( "/^--(.+)/", $args[$i], $match ) ) {
$parts = explode( "=", $match[1] );
$key = preg_replace( "/[^a-z0-9]+/", "", $parts[0] );
if ( (bool) preg_match( '/^--(.+)/', $args[ $i ], $match ) ) {
$parts = explode( '=', $match[1] );
$key = preg_replace( '/[^a-z0-9]+/', '', $parts[0] );
if ( isset( $parts[1] ) ) {
$out[$key] = $parts[1];
$out[ $key ] = $parts[1];
} else {
$out[$key] = true;
$out[ $key ] = true;
}
$last_arg = $key;
} elseif ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) {
} elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) {
for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) {
$key = $match[1]{$j};
$out[$key] = true;
$key = $match[1]{$j};
$out[ $key ] = true;
}
$last_arg = $key;
} elseif ( $last_arg !== null ) {
$out[$last_arg] = $args[$i];
$out[ $last_arg ] = $args[ $i ];
}
}
// Check array for specified param
if ( isset( $out[$param] ) ) {
if ( isset( $out[ $param ] ) ) {
// Set return value
$return = $out[$param];
$return = $out[ $param ];
}
// Check for missing required param
if ( !isset( $out[$param] ) && $required ) {
if ( ! isset( $out[ $param ] ) && $required ) {
// Display message and exit
echo "\"$param\" parameter is required but was not specified\n";
exit();

View file

@ -24,8 +24,6 @@ final class WP_Internal_Pointers {
* Individual pointers (e.g. wp390_widgets) can be disabled using the following:
* remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
*
* @static
*
* @param string $hook_suffix The current admin page.
*/
public static function enqueue_scripts( $hook_suffix ) {
@ -47,8 +45,9 @@ final class WP_Internal_Pointers {
);
// Check if screen related pointer is registered
if ( empty( $registered_pointers[ $hook_suffix ] ) )
if ( empty( $registered_pointers[ $hook_suffix ] ) ) {
return;
}
$pointers = (array) $registered_pointers[ $hook_suffix ];
@ -80,8 +79,9 @@ final class WP_Internal_Pointers {
foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
if ( isset( $caps_required[ $pointer ] ) ) {
foreach ( $caps_required[ $pointer ] as $cap ) {
if ( ! current_user_can( $cap ) )
if ( ! current_user_can( $cap ) ) {
continue 2;
}
}
}
@ -90,8 +90,9 @@ final class WP_Internal_Pointers {
$got_pointers = true;
}
if ( ! $got_pointers )
if ( ! $got_pointers ) {
return;
}
// Add pointers script and style to queue
wp_enqueue_style( 'wp-pointer' );
@ -103,15 +104,14 @@ final class WP_Internal_Pointers {
*
* @since 3.3.0
*
* @static
*
* @param string $pointer_id The pointer ID.
* @param string $selector The HTML elements, on which the pointer should be attached.
* @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js).
*/
private static function print_js( $pointer_id, $selector, $args ) {
if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) {
return;
}
?>
<script type="text/javascript">
@ -180,8 +180,8 @@ final class WP_Internal_Pointers {
}
$js_args = array(
'content' => $content,
'position' => $position,
'content' => $content,
'position' => $position,
'pointerClass' => 'wp-pointer arrow-bottom',
'pointerWidth' => 420,
);
@ -193,8 +193,6 @@ final class WP_Internal_Pointers {
*
* @since 3.3.0
*
* @static
*
* @param int $user_id User ID.
*/
public static function dismiss_pointers_for_new_users( $user_id ) {

View file

@ -27,14 +27,15 @@ class WP_Links_List_Table extends WP_List_Table {
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
parent::__construct( array(
'plural' => 'bookmarks',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'plural' => 'bookmarks',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
*
* @return bool
*/
public function ajax_user_can() {
@ -42,7 +43,6 @@ class WP_Links_List_Table extends WP_List_Table {
}
/**
*
* @global int $cat_id
* @global string $s
* @global string $orderby
@ -53,16 +53,23 @@ class WP_Links_List_Table extends WP_List_Table {
wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
$args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
$args = array(
'hide_invisible' => 0,
'hide_empty' => 0,
);
if ( 'all' != $cat_id )
if ( 'all' != $cat_id ) {
$args['category'] = $cat_id;
if ( !empty( $s ) )
}
if ( ! empty( $s ) ) {
$args['search'] = $s;
if ( !empty( $orderby ) )
}
if ( ! empty( $orderby ) ) {
$args['orderby'] = $orderby;
if ( !empty( $order ) )
}
if ( ! empty( $order ) ) {
$args['order'] = $order;
}
$this->items = get_bookmarks( $args );
}
@ -74,50 +81,48 @@ class WP_Links_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
$actions = array();
$actions['delete'] = __( 'Delete' );
return $actions;
}
/**
*
* @global int $cat_id
* @param string $which
*/
protected function extra_tablenav( $which ) {
global $cat_id;
if ( 'top' != $which )
if ( 'top' != $which ) {
return;
?>
}
?>
<div class="alignleft actions">
<?php
<?php
$dropdown_options = array(
'selected' => $cat_id,
'name' => 'cat_id',
'taxonomy' => 'link_category',
'selected' => $cat_id,
'name' => 'cat_id',
'taxonomy' => 'link_category',
'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items,
'hide_empty' => true,
'hierarchical' => 1,
'show_count' => 0,
'orderby' => 'name',
'hide_empty' => true,
'hierarchical' => 1,
'show_count' => 0,
'orderby' => 'name',
);
echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>';
wp_dropdown_categories( $dropdown_options );
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
?>
?>
</div>
<?php
<?php
}
/**
*
* @return array
*/
public function get_columns() {
@ -128,12 +133,11 @@ class WP_Links_List_Table extends WP_List_Table {
'categories' => __( 'Categories' ),
'rel' => __( 'Relationship' ),
'visible' => __( 'Visible' ),
'rating' => __( 'Rating' )
'rating' => __( 'Rating' ),
);
}
/**
*
* @return array
*/
protected function get_sortable_columns() {
@ -141,7 +145,7 @@ class WP_Links_List_Table extends WP_List_Table {
'name' => 'name',
'url' => 'url',
'visible' => 'visible',
'rating' => 'rating'
'rating' => 'rating',
);
}
@ -179,7 +183,8 @@ class WP_Links_List_Table extends WP_List_Table {
*/
public function column_name( $link ) {
$edit_link = get_edit_bookmark_link( $link );
printf( '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',
printf(
'<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',
$edit_link,
/* translators: %s: link name */
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ),
@ -285,14 +290,14 @@ class WP_Links_List_Table extends WP_List_Table {
public function display_rows() {
foreach ( $this->items as $link ) {
$link = sanitize_bookmark( $link );
$link->link_name = esc_attr( $link->link_name );
$link = sanitize_bookmark( $link );
$link->link_name = esc_attr( $link->link_name );
$link->link_category = wp_get_link_cats( $link->link_id );
?>
?>
<tr id="link-<?php echo $link->link_id; ?>">
<?php $this->single_row_columns( $link ) ?>
<?php $this->single_row_columns( $link ); ?>
</tr>
<?php
<?php
}
}
@ -313,9 +318,9 @@ class WP_Links_List_Table extends WP_List_Table {
$edit_link = get_edit_bookmark_link( $link );
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm( '" . esc_js(sprintf(__("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name)) . "' ) ) { return true;}return false;\">" . __('Delete') . "</a>";
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . '</a>';
return $this->row_actions( $actions );
}
}

View file

@ -17,32 +17,31 @@ class _WP_List_Table_Compat extends WP_List_Table {
public $_columns;
public function __construct( $screen, $columns = array() ) {
if ( is_string( $screen ) )
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
$this->_screen = $screen;
if ( !empty( $columns ) ) {
if ( ! empty( $columns ) ) {
$this->_columns = $columns;
add_filter( 'manage_' . $screen->id . '_columns', array( $this, 'get_columns' ), 0 );
}
}
/**
*
* @return array
*/
protected function get_column_info() {
$columns = get_column_headers( $this->_screen );
$hidden = get_hidden_columns( $this->_screen );
$columns = get_column_headers( $this->_screen );
$hidden = get_hidden_columns( $this->_screen );
$sortable = array();
$primary = $this->get_default_primary_column_name();
$primary = $this->get_default_primary_column_name();
return array( $columns, $hidden, $sortable, $primary );
}
/**
*
* @return array
*/
public function get_columns() {

View file

@ -91,10 +91,24 @@ class WP_List_Table {
*
* @var array
*/
protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
'single_row_columns' );
protected $compat_methods = array(
'set_pagination_args',
'get_views',
'get_bulk_actions',
'bulk_actions',
'row_actions',
'months_dropdown',
'view_switcher',
'comments_bubble',
'get_items_per_page',
'pagination',
'get_sortable_columns',
'get_column_info',
'get_table_classes',
'display_tablenav',
'extra_tablenav',
'single_row_columns',
);
/**
* Constructor.
@ -122,21 +136,25 @@ class WP_List_Table {
* }
*/
public function __construct( $args = array() ) {
$args = wp_parse_args( $args, array(
'plural' => '',
'singular' => '',
'ajax' => false,
'screen' => null,
) );
$args = wp_parse_args(
$args,
array(
'plural' => '',
'singular' => '',
'ajax' => false,
'screen' => null,
)
);
$this->screen = convert_to_screen( $args['screen'] );
add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
if ( !$args['plural'] )
if ( ! $args['plural'] ) {
$args['plural'] = $this->screen->base;
}
$args['plural'] = sanitize_key( $args['plural'] );
$args['plural'] = sanitize_key( $args['plural'] );
$args['singular'] = sanitize_key( $args['singular'] );
$this->_args = $args;
@ -149,7 +167,7 @@ class WP_List_Table {
if ( empty( $this->modes ) ) {
$this->modes = array(
'list' => __( 'List View' ),
'excerpt' => __( 'Excerpt View' )
'excerpt' => __( 'Excerpt View' ),
);
}
}
@ -215,7 +233,7 @@ class WP_List_Table {
*
* @since 4.0.0
*
* @param callable $name Method to call.
* @param string $name Method to call.
* @param array $arguments Arguments to pass when calling.
* @return mixed|bool Return value of the callback, false otherwise.
*/
@ -238,6 +256,7 @@ class WP_List_Table {
/**
* Prepares the list of items for displaying.
*
* @uses WP_List_Table::set_pagination_args()
*
* @since 3.1.0
@ -255,14 +274,18 @@ class WP_List_Table {
* @param array|string $args Array or string of arguments with information about the pagination.
*/
protected function set_pagination_args( $args ) {
$args = wp_parse_args( $args, array(
'total_items' => 0,
'total_pages' => 0,
'per_page' => 0,
) );
$args = wp_parse_args(
$args,
array(
'total_items' => 0,
'total_pages' => 0,
'per_page' => 0,
)
);
if ( !$args['total_pages'] && $args['per_page'] > 0 )
if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
$args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
}
// Redirect if page number is invalid and headers are not already sent.
if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
@ -287,8 +310,8 @@ class WP_List_Table {
return $this->get_pagenum();
}
if ( isset( $this->_pagination_args[$key] ) ) {
return $this->_pagination_args[$key];
if ( isset( $this->_pagination_args[ $key ] ) ) {
return $this->_pagination_args[ $key ];
}
}
@ -300,7 +323,7 @@ class WP_List_Table {
* @return bool
*/
public function has_items() {
return !empty( $this->items );
return ! empty( $this->items );
}
/**
@ -321,26 +344,31 @@ class WP_List_Table {
* @param string $input_id ID attribute value for the search input field.
*/
public function search_box( $text, $input_id ) {
if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
return;
}
$input_id = $input_id . '-search-input';
if ( ! empty( $_REQUEST['orderby'] ) )
if ( ! empty( $_REQUEST['orderby'] ) ) {
echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
if ( ! empty( $_REQUEST['order'] ) )
}
if ( ! empty( $_REQUEST['order'] ) ) {
echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
if ( ! empty( $_REQUEST['post_mime_type'] ) )
}
if ( ! empty( $_REQUEST['post_mime_type'] ) ) {
echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
if ( ! empty( $_REQUEST['detached'] ) )
}
if ( ! empty( $_REQUEST['detached'] ) ) {
echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
?>
}
?>
<p class="search-box">
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
<input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" />
<?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?>
<?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?>
</p>
<?php
<?php
}
/**
@ -370,12 +398,13 @@ class WP_List_Table {
*
* @since 3.5.0
*
* @param array $views An array of available list table views.
* @param string[] $views An array of available list table views.
*/
$views = apply_filters( "views_{$this->screen->id}", $views );
if ( empty( $views ) )
if ( empty( $views ) ) {
return;
}
$this->screen->render_screen_reader_content( 'heading_views' );
@ -384,7 +413,7 @@ class WP_List_Table {
$views[ $class ] = "\t<li class='$class'>$view";
}
echo implode( " |</li>\n", $views ) . "</li>\n";
echo "</ul>";
echo '</ul>';
}
/**
@ -420,16 +449,17 @@ class WP_List_Table {
*
* @since 3.5.0
*
* @param array $actions An array of the available bulk actions.
* @param string[] $actions An array of the available bulk actions.
*/
$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
$two = '';
$two = '';
} else {
$two = '2';
}
if ( empty( $this->_actions ) )
if ( empty( $this->_actions ) ) {
return;
}
echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
@ -455,14 +485,17 @@ class WP_List_Table {
* @return string|false The action name or False if no action was selected
*/
public function current_action() {
if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
return false;
}
if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
return $_REQUEST['action'];
}
if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) {
return $_REQUEST['action2'];
}
return false;
}
@ -472,22 +505,23 @@ class WP_List_Table {
*
* @since 3.1.0
*
* @param array $actions The list of actions
* @param bool $always_visible Whether the actions should be always visible
* @param string[] $actions An array of action links.
* @param bool $always_visible Whether the actions should be always visible.
* @return string
*/
protected function row_actions( $actions, $always_visible = false ) {
$action_count = count( $actions );
$i = 0;
$i = 0;
if ( !$action_count )
if ( ! $action_count ) {
return '';
}
$out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
foreach ( $actions as $action => $link ) {
++$i;
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
$out .= "<span class='$action'>$link$sep</span>";
$out .= "<span class='$action'>$link$sep</span>";
}
$out .= '</div>';
@ -528,13 +562,18 @@ class WP_List_Table {
$extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
}
$months = $wpdb->get_results( $wpdb->prepare( "
$months = $wpdb->get_results(
$wpdb->prepare(
"
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
FROM $wpdb->posts
WHERE post_type = %s
$extra_checks
ORDER BY post_date DESC
", $post_type ) );
",
$post_type
)
);
/**
* Filters the 'Months' drop-down results.
@ -548,32 +587,35 @@ class WP_List_Table {
$month_count = count( $months );
if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
return;
}
$m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
?>
?>
<label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
<select name="m" id="filter-by-date">
<option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
<?php
<?php
foreach ( $months as $arc_row ) {
if ( 0 == $arc_row->year )
if ( 0 == $arc_row->year ) {
continue;
}
$month = zeroise( $arc_row->month, 2 );
$year = $arc_row->year;
$year = $arc_row->year;
printf( "<option %s value='%s'>%s</option>\n",
printf(
"<option %s value='%s'>%s</option>\n",
selected( $m, $year . $month, false ),
esc_attr( $arc_row->year . $month ),
/* translators: 1: month name, 2: 4-digit year */
sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
);
}
?>
?>
</select>
<?php
<?php
}
/**
@ -584,24 +626,25 @@ class WP_List_Table {
* @param string $current_mode
*/
protected function view_switcher( $current_mode ) {
?>
?>
<input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
<div class="view-switch">
<?php
foreach ( $this->modes as $mode => $title ) {
$classes = array( 'view-' . $mode );
if ( $current_mode === $mode )
$classes[] = 'current';
printf(
"<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
esc_url( add_query_arg( 'mode', $mode ) ),
implode( ' ', $classes ),
$title
);
<?php
foreach ( $this->modes as $mode => $title ) {
$classes = array( 'view-' . $mode );
if ( $current_mode === $mode ) {
$classes[] = 'current';
}
printf(
"<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
esc_url( add_query_arg( 'mode', $mode ) ),
implode( ' ', $classes ),
$title
);
}
?>
</div>
<?php
<?php
}
/**
@ -616,39 +659,60 @@ class WP_List_Table {
$approved_comments = get_comments_number();
$approved_comments_number = number_format_i18n( $approved_comments );
$pending_comments_number = number_format_i18n( $pending_comments );
$pending_comments_number = number_format_i18n( $pending_comments );
$approved_only_phrase = sprintf( _n( '%s comment', '%s comments', $approved_comments ), $approved_comments_number );
$approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
$pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
$approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
$pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
// No comments at all.
if ( ! $approved_comments && ! $pending_comments ) {
printf( '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
printf(
'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
__( 'No comments' )
);
// Approved comments have different display depending on some conditions.
// Approved comments have different display depending on some conditions.
} elseif ( $approved_comments ) {
printf( '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'approved' ), admin_url( 'edit-comments.php' ) ) ),
printf(
'<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
esc_url(
add_query_arg(
array(
'p' => $post_id,
'comment_status' => 'approved',
),
admin_url( 'edit-comments.php' )
)
),
$approved_comments_number,
$pending_comments ? $approved_phrase : $approved_only_phrase
);
} else {
printf( '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
printf(
'<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
$approved_comments_number,
$pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
);
}
if ( $pending_comments ) {
printf( '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'moderated' ), admin_url( 'edit-comments.php' ) ) ),
printf(
'<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
esc_url(
add_query_arg(
array(
'p' => $post_id,
'comment_status' => 'moderated',
),
admin_url( 'edit-comments.php' )
)
),
$pending_comments_number,
$pending_phrase
);
} else {
printf( '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
printf(
'<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
$pending_comments_number,
$approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
);
@ -665,8 +729,9 @@ class WP_List_Table {
public function get_pagenum() {
$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
$pagenum = $this->_pagination_args['total_pages'];
}
return max( 1, $pagenum );
}
@ -682,8 +747,9 @@ class WP_List_Table {
*/
protected function get_items_per_page( $option, $default = 20 ) {
$per_page = (int) get_user_option( $option );
if ( empty( $per_page ) || $per_page < 1 )
if ( empty( $per_page ) || $per_page < 1 ) {
$per_page = $default;
}
/**
* Filters the number of items to be displayed on each page of the list table.
@ -713,8 +779,8 @@ class WP_List_Table {
return;
}
$total_items = $this->_pagination_args['total_items'];
$total_pages = $this->_pagination_args['total_pages'];
$total_items = $this->_pagination_args['total_items'];
$total_pages = $this->_pagination_args['total_pages'];
$infinite_scroll = false;
if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
@ -726,7 +792,7 @@ class WP_List_Table {
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
$current = $this->get_pagenum();
$current = $this->get_pagenum();
$removable_query_args = wp_removable_query_args();
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
@ -740,25 +806,26 @@ class WP_List_Table {
$disable_first = $disable_last = $disable_prev = $disable_next = false;
if ( $current == 1 ) {
if ( $current == 1 ) {
$disable_first = true;
$disable_prev = true;
}
$disable_prev = true;
}
if ( $current == 2 ) {
$disable_first = true;
}
if ( $current == $total_pages ) {
if ( $current == $total_pages ) {
$disable_last = true;
$disable_next = true;
}
}
if ( $current == $total_pages - 1 ) {
$disable_last = true;
}
if ( $disable_first ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
} else {
$page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
$page_links[] = sprintf(
"<a class='first-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( remove_query_arg( 'paged', $current_url ) ),
__( 'First page' ),
'&laquo;'
@ -766,10 +833,11 @@ class WP_List_Table {
}
if ( $disable_prev ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
} else {
$page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
$page_links[] = sprintf(
"<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
__( 'Previous page' ),
'&lsaquo;'
);
@ -779,29 +847,32 @@ class WP_List_Table {
$html_current_page = $current;
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
} else {
$html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
$html_current_page = sprintf(
"%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
'<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
$current,
strlen( $total_pages )
);
}
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
if ( $disable_next ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
} else {
$page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
$page_links[] = sprintf(
"<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
__( 'Next page' ),
'&rsaquo;'
);
}
if ( $disable_last ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
} else {
$page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
$page_links[] = sprintf(
"<a class='last-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
__( 'Last page' ),
'&raquo;'
@ -862,7 +933,7 @@ class WP_List_Table {
*/
protected function get_default_primary_column_name() {
$columns = $this->get_columns();
$column = '';
$column = '';
if ( empty( $columns ) ) {
return $column;
@ -918,7 +989,7 @@ class WP_List_Table {
* @param string $default Column name default for the specific list table, e.g. 'name'.
* @param string $context Screen ID for specific list table, e.g. 'plugins'.
*/
$column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
$column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
$column = $default;
@ -948,7 +1019,7 @@ class WP_List_Table {
}
$columns = get_column_headers( $this->screen );
$hidden = get_hidden_columns( $this->screen );
$hidden = get_hidden_columns( $this->screen );
$sortable_columns = $this->get_sortable_columns();
/**
@ -965,17 +1036,19 @@ class WP_List_Table {
$sortable = array();
foreach ( $_sortable as $id => $data ) {
if ( empty( $data ) )
if ( empty( $data ) ) {
continue;
}
$data = (array) $data;
if ( !isset( $data[1] ) )
if ( ! isset( $data[1] ) ) {
$data[1] = false;
}
$sortable[$id] = $data;
$sortable[ $id ] = $data;
}
$primary = $this->get_primary_column_name();
$primary = $this->get_primary_column_name();
$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
return $this->_column_headers;
@ -990,7 +1063,7 @@ class WP_List_Table {
*/
public function get_column_count() {
list ( $columns, $hidden ) = $this->get_column_info();
$hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
$hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
return count( $columns ) - count( $hidden );
}
@ -1023,7 +1096,7 @@ class WP_List_Table {
if ( ! empty( $columns['cb'] ) ) {
static $cb_counter = 1;
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
$cb_counter++;
}
@ -1035,24 +1108,25 @@ class WP_List_Table {
$class[] = 'hidden';
}
if ( 'cb' === $column_key )
if ( 'cb' === $column_key ) {
$class[] = 'check-column';
elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
} elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
$class[] = 'num';
}
if ( $column_key === $primary ) {
$class[] = 'column-primary';
}
if ( isset( $sortable[$column_key] ) ) {
list( $orderby, $desc_first ) = $sortable[$column_key];
if ( isset( $sortable[ $column_key ] ) ) {
list( $orderby, $desc_first ) = $sortable[ $column_key ];
if ( $current_orderby === $orderby ) {
$order = 'asc' === $current_order ? 'desc' : 'asc';
$order = 'asc' === $current_order ? 'desc' : 'asc';
$class[] = 'sorted';
$class[] = $current_order;
} else {
$order = $desc_first ? 'desc' : 'asc';
$order = $desc_first ? 'desc' : 'asc';
$class[] = 'sortable';
$class[] = $desc_first ? 'asc' : 'desc';
}
@ -1060,12 +1134,13 @@ class WP_List_Table {
$column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
}
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
$id = $with_id ? "id='$column_key'" : '';
$id = $with_id ? "id='$column_key'" : '';
if ( !empty( $class ) )
if ( ! empty( $class ) ) {
$class = "class='" . join( ' ', $class ) . "'";
}
echo "<$tag $scope $id $class>$column_display_name</$tag>";
}
@ -1082,7 +1157,7 @@ class WP_List_Table {
$this->display_tablenav( 'top' );
$this->screen->render_screen_reader_content( 'heading_list' );
?>
?>
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<thead>
<tr>
@ -1090,10 +1165,13 @@ class WP_List_Table {
</tr>
</thead>
<tbody id="the-list"<?php
<tbody id="the-list"
<?php
if ( $singular ) {
echo " data-wp-lists='list:$singular'";
} ?>>
}
?>
>
<?php $this->display_rows_or_placeholder(); ?>
</tbody>
@ -1104,7 +1182,7 @@ class WP_List_Table {
</tfoot>
</table>
<?php
<?php
$this->display_tablenav( 'bottom' );
}
@ -1132,18 +1210,19 @@ class WP_List_Table {
?>
<div class="tablenav <?php echo esc_attr( $which ); ?>">
<?php if ( $this->has_items() ): ?>
<?php if ( $this->has_items() ) : ?>
<div class="alignleft actions bulkactions">
<?php $this->bulk_actions( $which ); ?>
</div>
<?php endif;
<?php
endif;
$this->extra_tablenav( $which );
$this->pagination( $which );
?>
?>
<br class="clear" />
</div>
<?php
<?php
}
/**
@ -1176,8 +1255,9 @@ class WP_List_Table {
* @since 3.1.0
*/
public function display_rows() {
foreach ( $this->items as $item )
foreach ( $this->items as $item ) {
$this->single_row( $item );
}
}
/**
@ -1194,14 +1274,12 @@ class WP_List_Table {
}
/**
*
* @param object $item
* @param string $column_name
*/
protected function column_default( $item, $column_name ) {}
/**
*
* @param object $item
*/
protected function column_cb( $item ) {}
@ -1248,12 +1326,12 @@ class WP_List_Table {
echo "<td $attributes>";
echo call_user_func( array( $this, 'column_' . $column_name ), $item );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>";
echo '</td>';
} else {
echo "<td $attributes>";
echo $this->column_default( $item, $column_name );
echo $this->handle_row_actions( $item, $column_name, $primary );
echo "</td>";
echo '</td>';
}
}
}
@ -1270,7 +1348,7 @@ class WP_List_Table {
*/
protected function handle_row_actions( $item, $column_name, $primary ) {
return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
}
}
/**
* Handle an incoming ajax request (called from admin-ajax.php)
@ -1298,7 +1376,7 @@ class WP_List_Table {
);
}
if ( isset( $this->_pagination_args['total_pages'] ) ) {
$response['total_pages'] = $this->_pagination_args['total_pages'];
$response['total_pages'] = $this->_pagination_args['total_pages'];
$response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
}
@ -1307,7 +1385,6 @@ class WP_List_Table {
/**
* Send required variables to JavaScript land
*
*/
public function _js_vars() {
$args = array(
@ -1315,7 +1392,7 @@ class WP_List_Table {
'screen' => array(
'id' => $this->screen->id,
'base' => $this->screen->base,
)
),
);
printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );

View file

@ -42,25 +42,25 @@ class WP_Media_List_Table extends WP_List_Table {
$this->modes = array(
'list' => __( 'List View' ),
'grid' => __( 'Grid View' )
'grid' => __( 'Grid View' ),
);
parent::__construct( array(
'plural' => 'media',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'plural' => 'media',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
*
* @return bool
*/
public function ajax_user_can() {
return current_user_can('upload_files');
return current_user_can( 'upload_files' );
}
/**
*
* @global WP_Query $wp_query
* @global array $post_mime_types
* @global array $avail_post_mime_types
@ -71,15 +71,17 @@ class WP_Media_List_Table extends WP_List_Table {
list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
$this->set_pagination_args( array(
'total_items' => $wp_query->found_posts,
'total_pages' => $wp_query->max_num_pages,
'per_page' => $wp_query->query_vars['posts_per_page'],
) );
$this->set_pagination_args(
array(
'total_items' => $wp_query->found_posts,
'total_pages' => $wp_query->max_num_pages,
'per_page' => $wp_query->query_vars['posts_per_page'],
)
);
}
/**
@ -112,7 +114,7 @@ class WP_Media_List_Table extends WP_List_Table {
false
);
$type_links[$mime_type] = sprintf(
$type_links[ $mime_type ] = sprintf(
'<option value="post_mime_type:%s"%s>%s</option>',
esc_attr( $mime_type ),
$selected,
@ -128,7 +130,7 @@ class WP_Media_List_Table extends WP_List_Table {
_x( 'Mine', 'media items' )
);
if ( $this->is_trash || ( defined( 'MEDIA_TRASH') && MEDIA_TRASH ) ) {
if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
$type_links['trash'] = sprintf(
'<option value="trash"%s>%s</option>',
selected( 'trash' === $filter, true, false ),
@ -140,7 +142,6 @@ class WP_Media_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
protected function get_bulk_actions() {
@ -148,7 +149,7 @@ class WP_Media_List_Table extends WP_List_Table {
if ( MEDIA_TRASH ) {
if ( $this->is_trash ) {
$actions['untrash'] = __( 'Restore' );
$actions['delete'] = __( 'Delete Permanently' );
$actions['delete'] = __( 'Delete Permanently' );
} else {
$actions['trash'] = _x( 'Trash', 'verb' );
}
@ -156,8 +157,9 @@ class WP_Media_List_Table extends WP_List_Table {
$actions['delete'] = __( 'Delete Permanently' );
}
if ( $this->detached )
if ( $this->detached ) {
$actions['attach'] = __( 'Attach' );
}
return $actions;
}
@ -169,9 +171,9 @@ class WP_Media_List_Table extends WP_List_Table {
if ( 'bar' !== $which ) {
return;
}
?>
?>
<div class="actions">
<?php
<?php
if ( ! is_singular() ) {
if ( ! $this->is_trash ) {
$this->months_dropdown( 'attachment' );
@ -185,30 +187,32 @@ class WP_Media_List_Table extends WP_List_Table {
if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
} ?>
}
?>
</div>
<?php
<?php
}
/**
*
* @return string
*/
public function current_action() {
if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
return 'attach';
}
if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) )
if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) {
return 'detach';
}
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
return 'delete_all';
}
return parent::current_action();
}
/**
*
* @return bool
*/
public function has_items() {
@ -232,7 +236,7 @@ class WP_Media_List_Table extends WP_List_Table {
$views = $this->get_views();
$this->screen->render_screen_reader_content( 'heading_views' );
?>
?>
<div class="wp-filter">
<div class="filter-items">
<?php $this->view_switcher( $mode ); ?>
@ -248,7 +252,7 @@ class WP_Media_List_Table extends WP_List_Table {
?>
</select>
<?php
<?php
$this->extra_tablenav( 'bar' );
/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
@ -262,25 +266,24 @@ class WP_Media_List_Table extends WP_List_Table {
}
echo '</ul>';
}
?>
?>
</div>
<div class="search-form">
<label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label>
<input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ) ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div>
<input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ); ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div>
</div>
<?php
<?php
}
/**
*
* @return array
*/
public function get_columns() {
$posts_columns = array();
$posts_columns = array();
$posts_columns['cb'] = '<input type="checkbox" />';
/* translators: column name */
$posts_columns['title'] = _x( 'File', 'column name' );
$posts_columns['title'] = _x( 'File', 'column name' );
$posts_columns['author'] = __( 'Author' );
$taxonomies = get_taxonomies_for_attachments( 'objects' );
@ -291,8 +294,8 @@ class WP_Media_List_Table extends WP_List_Table {
*
* @since 3.5.0
*
* @param array $taxonomies An array of registered taxonomies to show for attachments.
* @param string $post_type The post type. Default 'attachment'.
* @param string[] $taxonomies An array of registered taxonomy names to show for attachments.
* @param string $post_type The post type. Default 'attachment'.
*/
$taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
@ -309,10 +312,11 @@ class WP_Media_List_Table extends WP_List_Table {
}
/* translators: column name */
if ( !$this->detached ) {
if ( ! $this->detached ) {
$posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
if ( post_type_supports( 'attachment', 'comments' ) )
if ( post_type_supports( 'attachment', 'comments' ) ) {
$posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
}
}
/* translators: column name */
$posts_columns['date'] = _x( 'Date', 'column name' );
@ -321,15 +325,14 @@ class WP_Media_List_Table extends WP_List_Table {
*
* @since 2.5.0
*
* @param array $posts_columns An array of columns displayed in the Media list table.
* @param bool $detached Whether the list table contains media not attached
* to any posts. Default true.
* @param string[] $posts_columns An array of columns displayed in the Media list table.
* @param bool $detached Whether the list table contains media not attached
* to any posts. Default true.
*/
return apply_filters( 'manage_media_columns', $posts_columns, $this->detached );
}
/**
*
* @return array
*/
protected function get_sortable_columns() {
@ -350,12 +353,16 @@ class WP_Media_List_Table extends WP_List_Table {
* @param WP_Post $post The current WP_Post object.
*/
public function column_cb( $post ) {
if ( current_user_can( 'edit_post', $post->ID ) ) { ?>
<label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>"><?php
echo sprintf( __( 'Select %s' ), _draft_or_post_title() );
?></label>
if ( current_user_can( 'edit_post', $post->ID ) ) {
?>
<label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>">
<?php
echo sprintf( __( 'Select %s' ), _draft_or_post_title() );
?>
</label>
<input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" />
<?php }
<?php
}
}
/**
@ -368,8 +375,8 @@ class WP_Media_List_Table extends WP_List_Table {
public function column_title( $post ) {
list( $mime ) = explode( '/', $post->post_mime_type );
$title = _draft_or_post_title();
$thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
$title = _draft_or_post_title();
$thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
$link_start = $link_end = '';
if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
@ -387,9 +394,11 @@ class WP_Media_List_Table extends WP_List_Table {
<strong<?php echo $class; ?>>
<?php
echo $link_start;
if ( $thumb ) : ?>
if ( $thumb ) :
?>
<span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span>
<?php endif;
<?php
endif;
echo $title . $link_end;
_media_states( $post );
?>
@ -412,8 +421,9 @@ class WP_Media_List_Table extends WP_List_Table {
* @param WP_Post $post The current WP_Post object.
*/
public function column_author( $post ) {
printf( '<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ),
printf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
get_the_author()
);
}
@ -441,7 +451,7 @@ class WP_Media_List_Table extends WP_List_Table {
$h_time = __( 'Unpublished' );
} else {
$m_time = $post->post_date;
$time = get_post_time( 'G', true, $post, false );
$time = get_post_time( 'G', true, $post, false );
if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) {
if ( $t_diff < 0 ) {
$h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
@ -473,26 +483,31 @@ class WP_Media_List_Table extends WP_List_Table {
}
if ( $parent ) {
$title = _draft_or_post_title( $post->post_parent );
$title = _draft_or_post_title( $post->post_parent );
$parent_type = get_post_type_object( $parent->post_type );
if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) {
?>
?>
<strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>">
<?php echo $title ?></a></strong><?php
<?php echo $title; ?></a></strong>
<?php
} elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
?>
<strong><?php echo $title ?></strong><?php
?>
<strong><?php echo $title; ?></strong>
<?php
} else {
_e( '(Private post)' );
}
if ( $user_can_edit ):
$detach_url = add_query_arg( array(
'parent_post_id' => $post->post_parent,
'media[]' => $post->ID,
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] )
), 'upload.php' );
if ( $user_can_edit ) :
$detach_url = add_query_arg(
array(
'parent_post_id' => $post->post_parent,
'media[]' => $post->ID,
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ),
),
'upload.php'
);
printf(
'<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>',
$detach_url,
@ -502,8 +517,10 @@ class WP_Media_List_Table extends WP_List_Table {
);
endif;
} else {
_e( '(Unattached)' ); ?>
<?php if ( $user_can_edit ) {
_e( '(Unattached)' );
?>
<?php
if ( $user_can_edit ) {
$title = _draft_or_post_title( $post->post_parent );
printf(
'<br /><a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>',
@ -561,11 +578,12 @@ class WP_Media_List_Table extends WP_List_Table {
if ( is_array( $terms ) ) {
$out = array();
foreach ( $terms as $t ) {
$posts_in_term_qv = array();
$posts_in_term_qv = array();
$posts_in_term_qv['taxonomy'] = $taxonomy;
$posts_in_term_qv['term'] = $t->slug;
$posts_in_term_qv['term'] = $t->slug;
$out[] = sprintf( '<a href="%s">%s</a>',
$out[] = sprintf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
);
@ -593,7 +611,6 @@ class WP_Media_List_Table extends WP_List_Table {
}
/**
*
* @global WP_Post $post
*/
public function display_rows() {
@ -604,9 +621,10 @@ class WP_Media_List_Table extends WP_List_Table {
$this->comment_pending_count = get_pending_comments_num( $post_ids );
add_filter( 'the_title','esc_html' );
add_filter( 'the_title', 'esc_html' );
while ( have_posts() ) : the_post();
while ( have_posts() ) :
the_post();
if (
( $this->is_trash && $post->post_status != 'trash' )
|| ( ! $this->is_trash && $post->post_status === 'trash' )
@ -614,11 +632,11 @@ class WP_Media_List_Table extends WP_List_Table {
continue;
}
$post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
?>
?>
<tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
<?php $this->single_row_columns( $post ); ?>
</tr>
<?php
<?php
endwhile;
}
@ -662,7 +680,7 @@ class WP_Media_List_Table extends WP_List_Table {
_x( 'Trash', 'verb' )
);
} else {
$delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
$delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
$actions['delete'] = sprintf(
'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
@ -690,9 +708,8 @@ class WP_Media_List_Table extends WP_List_Table {
__( 'Attach' )
);
}
}
else {
if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) {
} else {
if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
$actions['edit'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
get_edit_post_link( $post->ID ),
@ -720,7 +737,7 @@ class WP_Media_List_Table extends WP_List_Table {
);
}
if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
$delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
$delete_ays = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
$actions['delete'] = sprintf(
'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
@ -747,11 +764,11 @@ class WP_Media_List_Table extends WP_List_Table {
*
* @since 2.8.0
*
* @param array $actions An array of action links for each attachment.
* Default 'Edit', 'Delete Permanently', 'View'.
* @param WP_Post $post WP_Post object for the current attachment.
* @param bool $detached Whether the list table contains media not attached
* to any posts. Default true.
* @param string[] $actions An array of action links for each attachment.
* Default 'Edit', 'Delete Permanently', 'View'.
* @param WP_Post $post WP_Post object for the current attachment.
* @param bool $detached Whether the list table contains media not attached
* to any posts. Default true.
*/
return apply_filters( 'media_row_actions', $actions, $post, $this->detached );
}

View file

@ -39,17 +39,18 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
'archived' => array( 'site-archived', __( 'Archived' ) ),
'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
'mature' => array( 'site-mature', __( 'Mature' ) )
'mature' => array( 'site-mature', __( 'Mature' ) ),
);
parent::__construct( array(
'plural' => 'sites',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'plural' => 'sites',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
*
* @return bool
*/
public function ajax_user_can() {
@ -79,22 +80,24 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
$pagenum = $this->get_pagenum();
$s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
$s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
$wild = '';
if ( false !== strpos($s, '*') ) {
if ( false !== strpos( $s, '*' ) ) {
$wild = '*';
$s = trim($s, '*');
$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']) )
if ( ! $s && wp_is_large_network() ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$_GET['orderby'] = $_REQUEST['orderby'] = '';
if ( !isset($_REQUEST['order']) )
}
if ( ! isset( $_REQUEST['order'] ) ) {
$_GET['order'] = $_REQUEST['order'] = 'DESC';
}
}
$args = array(
@ -103,14 +106,14 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
'network_id' => get_current_network_id(),
);
if ( empty($s) ) {
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
$sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
$sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
$reg_blog_ids = $wpdb->get_col( $sql );
if ( $reg_blog_ids ) {
@ -146,7 +149,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
$args['orderby'] = $order_by;
if ( $order_by ) {
$args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
$args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
}
if ( wp_is_large_network() ) {
@ -171,16 +174,23 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
$this->items = array_slice( $_sites, 0, $per_page );
}
$total_sites = get_sites( array_merge( $args, array(
'count' => true,
'offset' => 0,
'number' => 0,
) ) );
$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,
) );
$this->set_pagination_args(
array(
'total_items' => $total_sites,
'per_page' => $per_page,
)
);
}
/**
@ -190,14 +200,14 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( current_user_can( 'delete_sites' ) )
if ( current_user_can( 'delete_sites' ) ) {
$actions['delete'] = __( 'Delete' );
$actions['spam'] = _x( 'Mark as Spam', 'site' );
}
$actions['spam'] = _x( 'Mark as Spam', 'site' );
$actions['notspam'] = _x( 'Not Spam', 'site' );
return $actions;
@ -213,8 +223,9 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
parent::pagination( $which );
if ( 'top' === $which )
if ( 'top' === $which ) {
$this->view_switcher( $mode );
}
}
/**
@ -238,8 +249,8 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
*
* @since MU (3.0.0)
*
* @param array $sites_columns An array of displayed site columns. Default 'cb',
* 'blogname', 'lastupdated', 'registered', 'users'.
* @param string[] $sites_columns An array of displayed site columns. Default 'cb',
* 'blogname', 'lastupdated', 'registered', 'users'.
*/
return apply_filters( 'wpmu_blogs_columns', $sites_columns );
}
@ -265,12 +276,15 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
public function column_cb( $blog ) {
if ( ! is_main_site( $blog['blog_id'] ) ) :
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
?>
<label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php
printf( __( 'Select %s' ), $blogname );
?></label>
<input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
<?php endif;
?>
<label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>">
<?php
printf( __( 'Select %s' ), $blogname );
?>
</label>
<input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ); ?>" />
<?php
endif;
}
/**
@ -296,7 +310,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
public function column_blogname( $blog ) {
global $mode;
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
$blog_states = array();
reset( $this->status_list );
@ -308,11 +322,11 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
$blog_state = '';
if ( ! empty( $blog_states ) ) {
$state_count = count( $blog_states );
$i = 0;
$i = 0;
$blog_state .= ' &mdash; ';
foreach ( $blog_states as $state ) {
++$i;
$sep = ( $i == $state_count ) ? '' : ', ';
$sep = ( $i == $state_count ) ? '' : ', ';
$blog_state .= "<span class='post-state'>$state$sep</span>";
}
}
@ -393,9 +407,15 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
public function column_users( $blog ) {
$user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
if ( ! $user_count ) {
$blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) );
$user_count = count( $blog_users );
unset( $blog_users );
$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 );
}
@ -449,12 +469,11 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
}
/**
*
* @global string $mode
*/
public function display_rows() {
foreach ( $this->items as $blog ) {
$blog = $blog->to_array();
$blog = $blog->to_array();
$class = '';
reset( $this->status_list );
@ -502,19 +521,23 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
// Preordered.
$actions = array(
'edit' => '', 'backend' => '',
'activate' => '', 'deactivate' => '',
'archive' => '', 'unarchive' => '',
'spam' => '', 'unspam' => '',
'delete' => '',
'visit' => '',
'edit' => '',
'backend' => '',
'activate' => '',
'deactivate' => '',
'archive' => '',
'unarchive' => '',
'spam' => '',
'unspam' => '',
'delete' => '',
'visit' => '',
);
$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>';
$actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>';
$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>';
$actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>';
if ( get_network()->site_id != $blog['blog_id'] ) {
if ( $blog['deleted'] == '1' ) {
$actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>';
$actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>';
} else {
$actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
}
@ -522,13 +545,13 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
if ( $blog['archived'] == '1' ) {
$actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>';
} else {
$actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>';
$actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>';
}
if ( $blog['spam'] == '1' ) {
$actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>';
} else {
$actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>';
$actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>';
}
if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) {
@ -536,7 +559,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
}
}
$actions['visit'] = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>';
$actions['visit'] = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>';
/**
* Filters the action links displayed for each site in the Sites list table.
@ -548,10 +571,10 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @param array $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.
* @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 );

View file

@ -37,25 +37,28 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
public function __construct( $args = array() ) {
global $status, $page;
parent::__construct( array(
'plural' => 'themes',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'plural' => 'themes',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
$status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) )
if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) ) {
$status = 'all';
}
$page = $this->get_pagenum();
$this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false;
if ( $this->is_site_themes )
if ( $this->is_site_themes ) {
$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
}
}
/**
*
* @return array
*/
protected function get_table_classes() {
@ -64,18 +67,17 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
}
/**
*
* @return bool
*/
public function ajax_user_can() {
if ( $this->is_site_themes )
if ( $this->is_site_themes ) {
return current_user_can( 'manage_sites' );
else
} else {
return current_user_can( 'manage_network_themes' );
}
}
/**
*
* @global string $status
* @global array $totals
* @global int $page
@ -95,22 +97,22 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @param array $all An array of WP_Theme objects to display in the list table.
* @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
*/
'all' => apply_filters( 'all_themes', wp_get_themes() ),
'search' => array(),
'enabled' => array(),
'all' => apply_filters( 'all_themes', wp_get_themes() ),
'search' => array(),
'enabled' => array(),
'disabled' => array(),
'upgrade' => array(),
'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
'upgrade' => array(),
'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
);
if ( $this->is_site_themes ) {
$themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
$allowed_where = 'site';
$allowed_where = 'site';
} else {
$themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
$allowed_where = 'network';
$allowed_where = 'network';
}
$maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
@ -123,24 +125,26 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
if ( $maybe_update && isset( $current->response[ $key ] ) ) {
$themes['all'][ $key ]->update = true;
$themes['upgrade'][ $key ] = $themes['all'][ $key ];
$themes['upgrade'][ $key ] = $themes['all'][ $key ];
}
$filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
$filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
$themes[ $filter ][ $key ] = $themes['all'][ $key ];
}
if ( $s ) {
$status = 'search';
$status = 'search';
$themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
}
$totals = array();
foreach ( $themes as $type => $list )
foreach ( $themes as $type => $list ) {
$totals[ $type ] = count( $list );
}
if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) {
$status = 'all';
}
$this->items = $themes[ $status ];
WP_Theme::sort_by_name( $this->items );
@ -148,14 +152,18 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$this->has_items = ! empty( $themes['all'] );
$total_this_page = $totals[ $status ];
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
'themes' => $totals,
'totals' => wp_get_update_data(),
) );
wp_localize_script(
'updates',
'_wpUpdatesItemCounts',
array(
'themes' => $totals,
'totals' => wp_get_update_data(),
)
);
if ( $orderby ) {
$orderby = ucfirst( $orderby );
$order = strtoupper( $order );
$order = strtoupper( $order );
if ( $orderby === 'Name' ) {
if ( 'ASC' === $order ) {
@ -168,13 +176,16 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$start = ( $page - 1 ) * $themes_per_page;
if ( $total_this_page > $themes_per_page )
if ( $total_this_page > $themes_per_page ) {
$this->items = array_slice( $this->items, $start, $themes_per_page, true );
}
$this->set_pagination_args( array(
'total_items' => $total_this_page,
'per_page' => $themes_per_page,
) );
$this->set_pagination_args(
array(
'total_items' => $total_this_page,
'per_page' => $themes_per_page,
)
);
}
/**
@ -184,20 +195,24 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
*/
public function _search_callback( $theme ) {
static $term = null;
if ( is_null( $term ) )
if ( is_null( $term ) ) {
$term = wp_unslash( $_REQUEST['s'] );
}
foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
// Don't mark up; Do translate.
if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) {
return true;
}
}
if ( false !== stripos( $theme->get_stylesheet(), $term ) )
if ( false !== stripos( $theme->get_stylesheet(), $term ) ) {
return true;
}
if ( false !== stripos( $theme->get_template(), $term ) )
if ( false !== stripos( $theme->get_template(), $term ) ) {
return true;
}
return false;
}
@ -216,13 +231,15 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$a = $theme_a[ $orderby ];
$b = $theme_b[ $orderby ];
if ( $a == $b )
if ( $a == $b ) {
return 0;
}
if ( 'DESC' === $order )
if ( 'DESC' === $order ) {
return ( $a < $b ) ? 1 : -1;
else
} else {
return ( $a < $b ) ? -1 : 1;
}
}
/**
@ -236,7 +253,6 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
public function get_columns() {
@ -248,12 +264,11 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
protected function get_sortable_columns() {
return array(
'name' => 'name',
'name' => 'name',
);
}
@ -269,7 +284,6 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
}
/**
*
* @global array $totals
* @global string $status
* @return array
@ -279,8 +293,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$status_links = array();
foreach ( $totals as $type => $count ) {
if ( !$count )
if ( ! $count ) {
continue;
}
switch ( $type ) {
case 'all':
@ -295,19 +310,21 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
case 'upgrade':
$text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
break;
case 'broken' :
case 'broken':
$text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
break;
}
if ( $this->is_site_themes )
if ( $this->is_site_themes ) {
$url = 'site-themes.php?id=' . $this->site_id;
else
} else {
$url = 'themes.php';
}
if ( 'search' != $type ) {
$status_links[$type] = sprintf( "<a href='%s'%s>%s</a>",
esc_url( add_query_arg('theme_status', $type, $url) ),
$status_links[ $type ] = sprintf(
"<a href='%s'%s>%s</a>",
esc_url( add_query_arg( 'theme_status', $type, $url ) ),
( $type === $status ) ? ' class="current" aria-current="page"' : '',
sprintf( $text, number_format_i18n( $count ) )
);
@ -326,15 +343,19 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
global $status;
$actions = array();
if ( 'enabled' != $status )
if ( 'enabled' != $status ) {
$actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
if ( 'disabled' != $status )
}
if ( 'disabled' != $status ) {
$actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
}
if ( ! $this->is_site_themes ) {
if ( current_user_can( 'update_themes' ) )
if ( current_user_can( 'update_themes' ) ) {
$actions['update-selected'] = __( 'Update' );
if ( current_user_can( 'delete_themes' ) )
}
if ( current_user_can( 'delete_themes' ) ) {
$actions['delete-selected'] = __( 'Delete' );
}
}
return $actions;
}
@ -342,8 +363,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
/**
*/
public function display_rows() {
foreach ( $this->items as $theme )
foreach ( $this->items as $theme ) {
$this->single_row( $theme );
}
}
/**
@ -354,10 +376,10 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
* @param WP_Theme $theme The current WP_Theme object.
*/
public function column_cb( $theme ) {
$checkbox_id = 'checkbox_' . md5( $theme->get('Name') );
$checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
?>
<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ) ?>" id="<?php echo $checkbox_id ?>" />
<label class="screen-reader-text" for="<?php echo $checkbox_id ?>" ><?php _e( 'Select' ) ?> <?php echo $theme->display( 'Name' ) ?></label>
<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" />
<label class="screen-reader-text" for="<?php echo $checkbox_id; ?>" ><?php _e( 'Select' ); ?> <?php echo $theme->display( 'Name' ); ?></label>
<?php
}
@ -378,31 +400,34 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$context = $status;
if ( $this->is_site_themes ) {
$url = "site-themes.php?id={$this->site_id}&amp;";
$url = "site-themes.php?id={$this->site_id}&amp;";
$allowed = $theme->is_allowed( 'site', $this->site_id );
} else {
$url = 'themes.php?';
$url = 'themes.php?';
$allowed = $theme->is_allowed( 'network' );
}
// Pre-order.
$actions = array(
'enable' => '',
'enable' => '',
'disable' => '',
'delete' => ''
'delete' => '',
);
$stylesheet = $theme->get_stylesheet();
$theme_key = urlencode( $stylesheet );
$theme_key = urlencode( $stylesheet );
if ( ! $allowed ) {
if ( ! $theme->errors() ) {
$url = add_query_arg( array(
'action' => 'enable',
'theme' => $theme_key,
'paged' => $page,
's' => $s,
), $url );
$url = add_query_arg(
array(
'action' => 'enable',
'theme' => $theme_key,
'paged' => $page,
's' => $s,
),
$url
);
if ( $this->is_site_themes ) {
/* translators: %s: theme name */
@ -412,19 +437,23 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
}
$actions['enable'] = sprintf( '<a href="%s" class="edit" aria-label="%s">%s</a>',
$actions['enable'] = sprintf(
'<a href="%s" class="edit" aria-label="%s">%s</a>',
esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ),
esc_attr( $aria_label ),
( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) )
);
}
} else {
$url = add_query_arg( array(
'action' => 'disable',
'theme' => $theme_key,
'paged' => $page,
's' => $s,
), $url );
$url = add_query_arg(
array(
'action' => 'disable',
'theme' => $theme_key,
'paged' => $page,
's' => $s,
),
$url
);
if ( $this->is_site_themes ) {
/* translators: %s: theme name */
@ -434,7 +463,8 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
}
$actions['disable'] = sprintf( '<a href="%s" aria-label="%s">%s</a>',
$actions['disable'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ),
esc_attr( $aria_label ),
( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) )
@ -442,18 +472,22 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
}
if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) {
$url = add_query_arg( array(
'action' => 'delete-selected',
'checked[]' => $theme_key,
'theme_status' => $context,
'paged' => $page,
's' => $s,
), 'themes.php' );
$url = add_query_arg(
array(
'action' => 'delete-selected',
'checked[]' => $theme_key,
'theme_status' => $context,
'paged' => $page,
's' => $s,
),
'themes.php'
);
/* translators: %s: theme name */
$aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) );
$actions['delete'] = sprintf( '<a href="%s" class="delete" aria-label="%s">%s</a>',
$actions['delete'] = sprintf(
'<a href="%s" class="delete" aria-label="%s">%s</a>',
esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
esc_attr( $aria_label ),
__( 'Delete' )
@ -477,7 +511,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
*
* @since 2.8.0
*
* @param array $actions An array of action links.
* @param string[] $actions An array of action links.
* @param WP_Theme $theme The current WP_Theme object.
* @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
*/
@ -493,7 +527,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @param array $actions An array of action links.
* @param string[] $actions An array of action links.
* @param WP_Theme $theme The current WP_Theme object.
* @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
*/
@ -526,8 +560,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
}
$class = ! $allowed ? 'inactive' : 'active';
if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
$class .= ' update';
}
echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
<div class='$class second theme-version-author-uri'>";
@ -535,16 +570,17 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$stylesheet = $theme->get_stylesheet();
$theme_meta = array();
if ( $theme->get('Version') ) {
$theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
if ( $theme->get( 'Version' ) ) {
$theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
}
$theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
$theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
if ( $theme->get('ThemeURI') ) {
if ( $theme->get( 'ThemeURI' ) ) {
/* translators: %s: theme name */
$aria_label = sprintf( __( 'Visit %s homepage' ), $theme->display( 'Name' ) );
$theme_meta[] = sprintf( '<a href="%s" aria-label="%s">%s</a>',
$theme_meta[] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
$theme->display( 'ThemeURI' ),
esc_attr( $aria_label ),
__( 'Visit Theme Site' )
@ -556,7 +592,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @param array $theme_meta An array of the theme's metadata,
* @param string[] $theme_meta An array of the theme's metadata,
* including the version, author, and
* theme URI.
* @param string $stylesheet Directory name of the theme.
@ -618,7 +654,6 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
break;
case 'name':
$active_theme_label = '';
/* The presence of the site_id property means that this is a subsite view and a label for the active theme needs to be added */
@ -632,7 +667,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
}
/* In case this is a child theme, label it properly */
if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet) {
if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
$active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
}
}
@ -641,7 +676,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$this->column_name( $item );
echo "</td>";
echo '</td>';
break;
case 'description':
@ -657,7 +692,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$this->column_default( $item, $column_name );
echo "</td>";
echo '</td>';
break;
}
}
@ -685,17 +720,19 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$class .= ' update';
}
printf( '<tr class="%s" data-slug="%s">',
printf(
'<tr class="%s" data-slug="%s">',
esc_attr( $class ),
esc_attr( $stylesheet )
);
$this->single_row_columns( $theme );
echo "</tr>";
echo '</tr>';
if ( $this->is_site_themes )
if ( $this->is_site_themes ) {
remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
}
/**
* Fires after each row in the Multisite themes list table.

View file

@ -17,7 +17,6 @@
*/
class WP_MS_Users_List_Table extends WP_List_Table {
/**
*
* @return bool
*/
public function ajax_user_can() {
@ -25,7 +24,6 @@ class WP_MS_Users_List_Table extends WP_List_Table {
}
/**
*
* @global string $usersearch
* @global string $role
* @global wpdb $wpdb
@ -43,22 +41,22 @@ class WP_MS_Users_List_Table extends WP_List_Table {
$paged = $this->get_pagenum();
$args = array(
'number' => $users_per_page,
'offset' => ( $paged-1 ) * $users_per_page,
'search' => $usersearch,
'number' => $users_per_page,
'offset' => ( $paged - 1 ) * $users_per_page,
'search' => $usersearch,
'blog_id' => 0,
'fields' => 'all_with_meta'
'fields' => 'all_with_meta',
);
if ( wp_is_large_network( 'users' ) ) {
$args['search'] = ltrim( $args['search'], '*' );
} else if ( '' !== $args['search'] ) {
} elseif ( '' !== $args['search'] ) {
$args['search'] = trim( $args['search'], '*' );
$args['search'] = '*' . $args['search'] . '*';
}
if ( $role === 'super' ) {
$logins = implode( "', '", get_super_admins() );
$logins = implode( "', '", get_super_admins() );
$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
}
@ -67,19 +65,23 @@ class WP_MS_Users_List_Table extends WP_List_Table {
* 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']) )
if ( ! $usersearch && wp_is_large_network( 'users' ) ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
if ( !isset($_REQUEST['order']) )
}
if ( ! isset( $_REQUEST['order'] ) ) {
$_GET['order'] = $_REQUEST['order'] = 'DESC';
}
$args['count_total'] = false;
}
if ( isset( $_REQUEST['orderby'] ) )
if ( isset( $_REQUEST['orderby'] ) ) {
$args['orderby'] = $_REQUEST['orderby'];
}
if ( isset( $_REQUEST['order'] ) )
if ( isset( $_REQUEST['order'] ) ) {
$args['order'] = $_REQUEST['order'];
}
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
@ -96,21 +98,23 @@ class WP_MS_Users_List_Table extends WP_List_Table {
$this->items = $wp_user_search->get_results();
$this->set_pagination_args( array(
'total_items' => $wp_user_search->get_total(),
'per_page' => $users_per_page,
) );
$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' ) )
if ( current_user_can( 'delete_users' ) ) {
$actions['delete'] = __( 'Delete' );
$actions['spam'] = _x( 'Mark as Spam', 'user' );
}
$actions['spam'] = _x( 'Mark as Spam', 'user' );
$actions['notspam'] = _x( 'Not Spam', 'user' );
return $actions;
@ -123,22 +127,21 @@ class WP_MS_Users_List_Table extends WP_List_Table {
}
/**
*
* @global string $role
* @return array
*/
protected function get_views() {
global $role;
$total_users = get_user_count();
$total_users = get_user_count();
$super_admins = get_super_admins();
$total_admins = count( $super_admins );
$current_link_attributes = $role !== 'super' ? ' class="current" aria-current="page"' : '';
$role_links = array();
$role_links['all'] = "<a href='" . network_admin_url( 'users.php' ) . "'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
$role_links = array();
$role_links['all'] = "<a href='" . network_admin_url( 'users.php' ) . "'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
$current_link_attributes = $role === 'super' ? ' class="current" aria-current="page"' : '';
$role_links['super'] = "<a href='" . network_admin_url( 'users.php?role=super' ) . "'$current_link_attributes>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>';
$role_links['super'] = "<a href='" . network_admin_url( 'users.php?role=super' ) . "'$current_link_attributes>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>';
return $role_links;
}
@ -151,7 +154,7 @@ class WP_MS_Users_List_Table extends WP_List_Table {
protected function pagination( $which ) {
global $mode;
parent::pagination ( $which );
parent::pagination( $which );
if ( 'top' === $which ) {
$this->view_switcher( $mode );
@ -159,7 +162,6 @@ class WP_MS_Users_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
public function get_columns() {
@ -169,21 +171,20 @@ class WP_MS_Users_List_Table extends WP_List_Table {
'name' => __( 'Name' ),
'email' => __( 'Email' ),
'registered' => _x( 'Registered', 'user' ),
'blogs' => __( 'Sites' )
'blogs' => __( 'Sites' ),
);
/**
* Filters the columns displayed in the Network Admin Users list table.
*
* @since MU (3.0.0)
*
* @param array $users_columns An array of user columns. Default 'cb', 'username',
* 'name', 'email', 'registered', 'blogs'.
* @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() {
@ -208,7 +209,7 @@ class WP_MS_Users_List_Table extends WP_List_Table {
}
?>
<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
<input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
<?php
}
@ -232,17 +233,28 @@ class WP_MS_Users_List_Table extends WP_List_Table {
*/
public function column_username( $user ) {
$super_admins = get_super_admins();
$avatar = get_avatar( $user->user_email, 32 );
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
$avatar = get_avatar( $user->user_email, 32 );
echo $avatar;
?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
if ( in_array( $user->user_login, $super_admins ) ) {
echo ' &mdash; ' . __( 'Super Admin' );
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
?>
<strong>
<?php
echo $edit;
if ( in_array( $user->user_login, $super_admins ) ) {
echo ' &mdash; ' . __( 'Super Admin' );
}
?>
</strong>
<?php
}
/**
@ -327,12 +339,12 @@ class WP_MS_Users_List_Table extends WP_List_Table {
continue;
}
$path = ( $val->path === '/' ) ? '' : $val->path;
$path = ( $val->path === '/' ) ? '' : $val->path;
echo '<span class="site-' . $val->site_id . '" >';
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . '</a>';
echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . '</a>';
echo ' <small class="row-actions">';
$actions = array();
$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
$actions = array();
$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>';
$class = '';
if ( $val->spam == 1 ) {
@ -356,13 +368,12 @@ class WP_MS_Users_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @param array $actions An array of action links to be displayed.
* Default 'Edit', 'View'.
* @param int $userblog_id The site ID.
* @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, $val->userblog_id );
$i=0;
$i = 0;
$action_count = count( $actions );
foreach ( $actions as $action => $link ) {
++$i;
@ -390,7 +401,10 @@ class WP_MS_Users_List_Table extends WP_List_Table {
foreach ( $this->items as $user ) {
$class = '';
$status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
$status_list = array(
'spam' => 'site-spammed',
'deleted' => 'site-deleted',
);
foreach ( $status_list as $status => $col ) {
if ( $user->$status ) {
@ -433,10 +447,13 @@ class WP_MS_Users_List_Table extends WP_List_Table {
}
$super_admins = get_super_admins();
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
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 ) ) {
$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
@ -447,9 +464,8 @@ class WP_MS_Users_List_Table extends WP_List_Table {
*
* @since 3.2.0
*
* @param array $actions An array of action links to be displayed.
* Default 'Edit', 'Delete'.
* @param WP_User $user WP_User object.
* @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 );

View file

@ -17,18 +17,17 @@
*/
class WP_Plugin_Install_List_Table extends WP_List_Table {
public $order = 'ASC';
public $order = 'ASC';
public $orderby = null;
public $groups = array();
public $groups = array();
private $error;
/**
*
* @return bool
*/
public function ajax_user_can() {
return current_user_can('install_plugins');
return current_user_can( 'install_plugins' );
}
/**
@ -79,7 +78,6 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
}
/**
*
* @global array $tabs
* @global string $tab
* @global int $paged
@ -95,7 +93,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$paged = $this->get_pagenum();
$per_page = 30;
$per_page = 36;
// These are the tabs which are shown on the page
$tabs = array();
@ -123,8 +121,8 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
*
* @since 2.7.0
*
* @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
* 'recommended', 'favorites', and 'upload'.
* @param string[] $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
* 'recommended', 'favorites', and 'upload'.
*/
$tabs = apply_filters( 'install_plugins_tabs', $tabs );
@ -133,27 +131,22 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
*
* @since 2.7.0
*
* @param array $nonmenu_tabs The tabs that don't have a Menu item on the Plugin Install screen.
* @param string[] $nonmenu_tabs The tabs that don't have a menu item on the Plugin Install screen.
*/
$nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
// If a non-valid menu tab has been selected, And it's not a non-menu action.
if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) {
$tab = key( $tabs );
}
$installed_plugins = $this->get_installed_plugins();
$args = array(
'page' => $paged,
'page' => $paged,
'per_page' => $per_page,
'fields' => array(
'last_updated' => true,
'icons' => true,
'active_installs' => true
),
// Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
'locale' => get_user_locale(),
'installed_plugins' => array_keys( $installed_plugins ),
// Send the locale to the API so it can provide context-sensitive results.
'locale' => get_user_locale(),
);
switch ( $tab ) {
@ -176,14 +169,15 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
break;
case 'featured':
$args['fields']['group'] = true;
$this->orderby = 'group';
// No break!
case 'popular':
case 'new':
case 'beta':
$args['browse'] = $tab;
break;
case 'recommended':
$args['browse'] = $tab;
// Include the list of installed plugins so we can get relevant results.
$args['installed_plugins'] = array_keys( $installed_plugins );
break;
case 'favorites':
@ -198,10 +192,11 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
} else {
$user = get_user_option( 'wporg_favorites' );
}
if ( $user )
if ( $user ) {
$args['user'] = $user;
else
} else {
$args = false;
}
add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 );
break;
@ -223,8 +218,9 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
*/
$args = apply_filters( "install_plugins_table_api_args_{$tab}", $args );
if ( !$args )
if ( ! $args ) {
return;
}
$api = plugins_api( 'query_plugins', $args );
@ -239,10 +235,12 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
uasort( $this->items, array( $this, 'order_callback' ) );
}
$this->set_pagination_args( array(
'total_items' => $api->info['results'],
'per_page' => $args['per_page'],
) );
$this->set_pagination_args(
array(
'total_items' => $api->info['results'],
'per_page' => $args['per_page'],
)
);
if ( isset( $api->info['groups'] ) ) {
$this->groups = $api->info['groups'];
@ -261,10 +259,14 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$js_plugins['upgrade'] = array_values( $upgrade_plugins );
}
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
'plugins' => $js_plugins,
'totals' => wp_get_update_data(),
) );
wp_localize_script(
'updates',
'_wpUpdatesItemCounts',
array(
'plugins' => $js_plugins,
'totals' => wp_get_update_data(),
)
);
}
}
@ -277,12 +279,11 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
</div>
<?php } else { ?>
<div class="no-plugin-results"><?php _e( 'No plugins found. Try a different search.' ); ?></div>
<?php
<?php
}
}
/**
*
* @global array $tabs
* @global string $tab
*
@ -293,9 +294,9 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$display_tabs = array();
foreach ( (array) $tabs as $action => $text ) {
$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
$href = self_admin_url('plugin-install.php?tab=' . $action);
$display_tabs['plugin-install-'.$action] = "<a href='$href'$current_link_attributes>$text</a>";
$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
$href = self_admin_url( 'plugin-install.php?tab=' . $action );
$display_tabs[ 'plugin-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>";
}
// No longer a real tab.
unset( $display_tabs['plugin-install-upload'] );
@ -313,7 +314,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$views = apply_filters( "views_{$this->screen->id}", $views );
$this->screen->render_screen_reader_content( 'heading_views' );
?>
?>
<div class="wp-filter">
<ul class="filter-links">
<?php
@ -326,9 +327,9 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
?>
</ul>
<?php install_search_form(); ?>
<?php install_search_form(); ?>
</div>
<?php
<?php
}
/**
@ -345,16 +346,16 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$this->display_tablenav( 'top' );
?>
?>
<div class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<?php
$this->screen->render_screen_reader_content( 'heading_list' );
?>
<?php
$this->screen->render_screen_reader_content( 'heading_list' );
?>
<div id="the-list"<?php echo $data_attr; ?>>
<?php $this->display_rows_or_placeholder(); ?>
</div>
</div>
<?php
<?php
$this->display_tablenav( 'bottom' );
}
@ -370,7 +371,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
if ( 'top' === $which ) {
wp_referer_field();
?>
?>
<div class="tablenav top">
<div class="alignleft actions">
<?php
@ -379,7 +380,8 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
*
* @since 2.7.0
*/
do_action( 'install_plugins_table_header' ); ?>
do_action( 'install_plugins_table_header' );
?>
</div>
<?php $this->pagination( $which ); ?>
<br class="clear" />
@ -389,7 +391,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
<?php $this->pagination( $which ); ?>
<br class="clear" />
</div>
<?php
<?php
}
}
@ -434,16 +436,28 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
public function display_rows() {
$plugins_allowedtags = array(
'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'p' => array(),
'br' => array(),
);
$plugins_group_titles = array(
'Performance' => _x( 'Performance', 'Plugin installer group title' ),
'Social' => _x( 'Social', 'Plugin installer group title' ),
'Tools' => _x( 'Tools', 'Plugin installer group title' ),
'Social' => _x( 'Social', 'Plugin installer group title' ),
'Tools' => _x( 'Tools', 'Plugin installer group title' ),
);
$group = null;
@ -479,7 +493,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
// Remove any HTML from the description.
$description = strip_tags( $plugin['short_description'] );
$version = wp_kses( $plugin['version'], $plugins_allowedtags );
$version = wp_kses( $plugin['version'], $plugins_allowedtags );
$name = strip_tags( $title . ' ' . $version );
@ -488,6 +502,12 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
}
$wp_version = get_bloginfo( 'version' );
$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
$tested_wp = ( empty( $plugin['tested'] ) || version_compare( $wp_version, $plugin['tested'], '<=' ) );
$compatible_wp = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
$action_links = array();
if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
@ -496,35 +516,63 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
/* translators: 1: Plugin name and version. */
$action_links[] = '<a class="install-now button" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Install %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Install Now' ) . '</a>';
if ( $compatible_php && $compatible_wp ) {
$action_links[] = sprintf(
'<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
esc_attr( $name ),
__( 'Install Now' )
);
} else {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Cannot Install', 'plugin' )
);
}
}
break;
case 'update_available':
if ( $status['url'] ) {
/* translators: 1: Plugin name and version */
$action_links[] = '<a class="update-now button aria-button-if-js" data-plugin="' . esc_attr( $status['file'] ) . '" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Update %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Update Now' ) . '</a>';
$action_links[] = sprintf(
'<a class="update-now button aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
esc_attr( $status['file'] ),
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Update %s now' ), $name ) ),
esc_attr( $name ),
__( 'Update Now' )
);
}
break;
case 'latest_installed':
case 'newer_installed':
if ( is_plugin_active( $status['file'] ) ) {
$action_links[] = '<button type="button" class="button button-disabled" disabled="disabled">' . _x( 'Active', 'plugin' ) . '</button>';
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Active', 'plugin' )
);
} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
$button_text = __( 'Activate' );
/* translators: %s: Plugin name */
$button_text = __( 'Activate' );
/* translators: %s: plugin name */
$button_label = _x( 'Activate %s', 'plugin' );
$activate_url = add_query_arg( array(
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
'action' => 'activate',
'plugin' => $status['file'],
), network_admin_url( 'plugins.php' ) );
$activate_url = add_query_arg(
array(
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
'action' => 'activate',
'plugin' => $status['file'],
),
network_admin_url( 'plugins.php' )
);
if ( is_network_admin() ) {
$button_text = __( 'Network Activate' );
/* translators: %s: Plugin name */
$button_text = __( 'Network Activate' );
/* translators: %s: plugin name */
$button_label = _x( 'Network Activate %s', 'plugin' );
$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
}
@ -536,23 +584,34 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$button_text
);
} else {
$action_links[] = '<button type="button" class="button button-disabled" disabled="disabled">' . _x( 'Installed', 'plugin' ) . '</button>';
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Installed', 'plugin' )
);
}
break;
}
}
$details_link = self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
'&amp;TB_iframe=true&amp;width=600&amp;height=550' );
$details_link = self_admin_url(
'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
'&amp;TB_iframe=true&amp;width=600&amp;height=550'
);
/* translators: 1: Plugin name and version. */
$action_links[] = '<a href="' . esc_url( $details_link ) . '" class="thickbox open-plugin-details-modal" aria-label="' . esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '" data-title="' . esc_attr( $name ) . '">' . __( 'More Details' ) . '</a>';
$action_links[] = sprintf(
'<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
esc_url( $details_link ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'More information about %s' ), $name ) ),
esc_attr( $name ),
__( 'More Details' )
);
if ( !empty( $plugin['icons']['svg'] ) ) {
if ( ! empty( $plugin['icons']['svg'] ) ) {
$plugin_icon_url = $plugin['icons']['svg'];
} elseif ( !empty( $plugin['icons']['2x'] ) ) {
} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
$plugin_icon_url = $plugin['icons']['2x'];
} elseif ( !empty( $plugin['icons']['1x'] ) ) {
} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
$plugin_icon_url = $plugin['icons']['1x'];
} else {
$plugin_icon_url = $plugin['icons']['default'];
@ -563,28 +622,78 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
*
* @since 2.7.0
*
* @param array $action_links An array of plugin action hyperlinks. Defaults are links to Details and Install Now.
* @param array $plugin The plugin currently being listed.
* @param string[] $action_links An array of plugin action links. Defaults are links to Details and Install Now.
* @param array $plugin The plugin currently being listed.
*/
$action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
$last_updated_timestamp = strtotime( $plugin['last_updated'] );
?>
?>
<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
<?php
if ( ! $compatible_php || ! $compatible_wp ) {
echo '<div class="notice inline notice-error notice-alt"><p>';
if ( ! $compatible_php && ! $compatible_wp ) {
_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP.' );
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
printf(
/* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
self_admin_url( 'update-core.php' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation();
} elseif ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
} elseif ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: "Update PHP" page URL */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation();
}
} elseif ( ! $compatible_wp ) {
_e( 'This plugin doesn&#8217;t work with your version of WordPress.' );
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
} elseif ( ! $compatible_php ) {
_e( 'This plugin doesn&#8217;t work with your version of PHP.' );
if ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: "Update PHP" page URL */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation();
}
}
echo '</p></div>';
}
?>
<div class="plugin-card-top">
<div class="name column-name">
<h3>
<a href="<?php echo esc_url( $details_link ); ?>" class="thickbox open-plugin-details-modal">
<?php echo $title; ?>
<img src="<?php echo esc_attr( $plugin_icon_url ) ?>" class="plugin-icon" alt="">
<img src="<?php echo esc_attr( $plugin_icon_url ); ?>" class="plugin-icon" alt="">
</a>
</h3>
</div>
<div class="action-links">
<?php
if ( $action_links ) {
echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
}
if ( $action_links ) {
echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
}
?>
</div>
<div class="desc column-description">
@ -594,7 +703,15 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
</div>
<div class="plugin-card-bottom">
<div class="vers column-rating">
<?php wp_star_rating( array( 'rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'] ) ); ?>
<?php
wp_star_rating(
array(
'rating' => $plugin['rating'],
'type' => 'percent',
'number' => $plugin['num_ratings'],
)
);
?>
<span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
</div>
<div class="column-updated">
@ -603,7 +720,11 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
<div class="column-downloaded">
<?php
if ( $plugin['active_installs'] >= 1000000 ) {
$active_installs_text = _x( '1+ Million', 'Active plugin installations' );
$active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
$active_installs_text = sprintf(
_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
number_format_i18n( $active_installs_millions )
);
} elseif ( 0 == $plugin['active_installs'] ) {
$active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
} else {
@ -614,11 +735,9 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
</div>
<div class="column-compatibility">
<?php
$wp_version = get_bloginfo( 'version' );
if ( ! empty( $plugin['tested'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '>' ) ) {
if ( ! $tested_wp ) {
echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
} elseif ( ! empty( $plugin['requires'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '<' ) ) {
} elseif ( ! $compatible_wp ) {
echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
} else {
echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';
@ -627,7 +746,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
</div>
</div>
</div>
<?php
<?php
}
// Close off the group divs of the last one

View file

@ -32,17 +32,21 @@ class WP_Plugins_List_Table extends WP_List_Table {
public function __construct( $args = array() ) {
global $status, $page;
parent::__construct( array(
'plural' => 'plugins',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'plural' => 'plugins',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
$status = 'all';
if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) {
$status = $_REQUEST['plugin_status'];
}
if ( isset($_REQUEST['s']) )
$_SERVER['REQUEST_URI'] = add_query_arg('s', wp_unslash($_REQUEST['s']) );
if ( isset( $_REQUEST['s'] ) ) {
$_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) );
}
$page = $this->get_pagenum();
}
@ -58,11 +62,10 @@ class WP_Plugins_List_Table extends WP_List_Table {
* @return bool
*/
public function ajax_user_can() {
return current_user_can('activate_plugins');
return current_user_can( 'activate_plugins' );
}
/**
*
* @global string $status
* @global array $plugins
* @global array $totals
@ -122,15 +125,16 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
/** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) {
$plugins['dropins'] = get_dropins();
}
if ( current_user_can( 'update_plugins' ) ) {
$current = get_site_transient( 'update_plugins' );
foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
if ( isset( $current->response[ $plugin_file ] ) ) {
$plugins['all'][ $plugin_file ]['update'] = true;
$plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
$plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
}
}
}
@ -164,7 +168,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
foreach ( $recently_activated as $key => $time ) {
if ( $time + WEEK_IN_SECONDS < time() ) {
unset( $recently_activated[$key] );
unset( $recently_activated[ $key ] );
}
}
@ -184,7 +188,6 @@ class WP_Plugins_List_Table extends WP_List_Table {
if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
$plugins['upgrade'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data );
}
} elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) {
$plugins['all'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data );
// Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
@ -226,21 +229,23 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
if ( strlen( $s ) ) {
$status = 'search';
$status = 'search';
$plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
}
$totals = array();
foreach ( $plugins as $type => $list )
foreach ( $plugins as $type => $list ) {
$totals[ $type ] = count( $list );
}
if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) {
$status = 'all';
}
$this->items = array();
foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
// Translate, Don't Apply Markup, Sanitize HTML
$this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
$this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
}
$total_this_page = $totals[ $status ];
@ -250,10 +255,14 @@ class WP_Plugins_List_Table extends WP_List_Table {
$js_plugins[ $key ] = array_keys( (array) $list );
}
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
'plugins' => $js_plugins,
'totals' => wp_get_update_data(),
) );
wp_localize_script(
'updates',
'_wpUpdatesItemCounts',
array(
'plugins' => $js_plugins,
'totals' => wp_get_update_data(),
)
);
if ( ! $orderby ) {
$orderby = 'Name';
@ -269,13 +278,16 @@ class WP_Plugins_List_Table extends WP_List_Table {
$start = ( $page - 1 ) * $plugins_per_page;
if ( $total_this_page > $plugins_per_page )
if ( $total_this_page > $plugins_per_page ) {
$this->items = array_slice( $this->items, $start, $plugins_per_page );
}
$this->set_pagination_args( array(
'total_items' => $total_this_page,
'per_page' => $plugins_per_page,
) );
$this->set_pagination_args(
array(
'total_items' => $total_this_page,
'per_page' => $plugins_per_page,
)
);
}
/**
@ -306,11 +318,12 @@ class WP_Plugins_List_Table extends WP_List_Table {
public function _order_callback( $plugin_a, $plugin_b ) {
global $orderby, $order;
$a = $plugin_a[$orderby];
$b = $plugin_b[$orderby];
$a = $plugin_a[ $orderby ];
$b = $plugin_b[ $orderby ];
if ( $a == $b )
if ( $a == $b ) {
return 0;
}
if ( 'DESC' === $order ) {
return strcasecmp( $b, $a );
@ -320,7 +333,6 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
/**
*
* @global array $plugins
*/
public function no_items() {
@ -329,16 +341,18 @@ class WP_Plugins_List_Table extends WP_List_Table {
if ( ! empty( $_REQUEST['s'] ) ) {
$s = esc_html( wp_unslash( $_REQUEST['s'] ) );
/* translators: %s: plugin search term */
printf( __( 'No plugins found for &#8220;%s&#8221;.' ), $s );
// We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link.
if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) {
echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>';
}
} elseif ( ! empty( $plugins['all'] ) )
} elseif ( ! empty( $plugins['all'] ) ) {
_e( 'No plugins found.' );
else
} else {
_e( 'You do not appear to have any plugins available at this time.' );
}
}
/**
@ -372,7 +386,6 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
/**
*
* @global string $status
* @return array
*/
@ -380,7 +393,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
global $status;
return array(
'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
'name' => __( 'Plugin' ),
'description' => __( 'Description' ),
);
@ -394,7 +407,6 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
/**
*
* @global array $totals
* @global string $status
* @return array
@ -404,39 +416,48 @@ class WP_Plugins_List_Table extends WP_List_Table {
$status_links = array();
foreach ( $totals as $type => $count ) {
if ( !$count )
if ( ! $count ) {
continue;
}
switch ( $type ) {
case 'all':
/* translators: %s: plugin count */
$text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
break;
case 'active':
/* translators: %s: plugin count */
$text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
break;
case 'recently_activated':
/* translators: %s: plugin count */
$text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
break;
case 'inactive':
/* translators: %s: plugin count */
$text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
break;
case 'mustuse':
/* translators: %s: plugin count */
$text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
break;
case 'dropins':
/* translators: %s: plugin count */
$text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
break;
case 'upgrade':
/* translators: %s: plugin count */
$text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
break;
}
if ( 'search' !== $type ) {
$status_links[$type] = sprintf( "<a href='%s'%s>%s</a>",
add_query_arg('plugin_status', $type, 'plugins.php'),
$status_links[ $type ] = sprintf(
"<a href='%s'%s>%s</a>",
add_query_arg( 'plugin_status', $type, 'plugins.php' ),
( $type === $status ) ? ' class="current" aria-current="page"' : '',
sprintf( $text, number_format_i18n( $count ) )
);
);
}
}
@ -444,7 +465,6 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
/**
*
* @global string $status
* @return array
*/
@ -453,17 +473,21 @@ class WP_Plugins_List_Table extends WP_List_Table {
$actions = array();
if ( 'active' != $status )
if ( 'active' != $status ) {
$actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
}
if ( 'inactive' != $status && 'recent' != $status )
if ( 'inactive' != $status && 'recent' != $status ) {
$actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' );
}
if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) {
if ( current_user_can( 'update_plugins' ) )
if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) {
if ( current_user_can( 'update_plugins' ) ) {
$actions['update-selected'] = __( 'Update' );
if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
}
if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) {
$actions['delete-selected'] = __( 'Delete' );
}
}
return $actions;
@ -476,8 +500,9 @@ class WP_Plugins_List_Table extends WP_List_Table {
public function bulk_actions( $which = '' ) {
global $status;
if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
return;
}
parent::bulk_actions( $which );
}
@ -489,21 +514,24 @@ class WP_Plugins_List_Table extends WP_List_Table {
protected function extra_tablenav( $which ) {
global $status;
if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ) ) ) {
return;
}
echo '<div class="alignleft actions">';
if ( 'recently_activated' == $status ) {
submit_button( __( 'Clear List' ), '', 'clear-recent-list', false );
} elseif ( 'top' === $which && 'mustuse' === $status ) {
/* translators: %s: mu-plugins directory name */
echo '<p>' . sprintf( __( 'Files in the %s directory are executed automatically.' ),
echo '<p>' . sprintf(
/* translators: %s: mu-plugins directory name */
__( 'Files in the %s directory are executed automatically.' ),
'<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>'
) . '</p>';
} elseif ( 'top' === $which && 'dropins' === $status ) {
/* translators: %s: wp-content directory name */
echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ),
echo '<p>' . sprintf(
/* translators: %s: wp-content directory name */
__( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ),
'<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>'
) . '</p>';
}
@ -514,24 +542,26 @@ class WP_Plugins_List_Table extends WP_List_Table {
* @return string
*/
public function current_action() {
if ( isset($_POST['clear-recent-list']) )
if ( isset( $_POST['clear-recent-list'] ) ) {
return 'clear-recent-list';
}
return parent::current_action();
}
/**
*
* @global string $status
*/
public function display_rows() {
global $status;
if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) )
if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
return;
}
foreach ( $this->items as $plugin_file => $plugin_data )
foreach ( $this->items as $plugin_file => $plugin_data ) {
$this->single_row( array( $plugin_file, $plugin_data ) );
}
}
/**
@ -546,52 +576,55 @@ class WP_Plugins_List_Table extends WP_List_Table {
global $status, $page, $s, $totals;
list( $plugin_file, $plugin_data ) = $item;
$context = $status;
$screen = $this->screen;
$context = $status;
$screen = $this->screen;
// Pre-order.
$actions = array(
'deactivate' => '',
'activate' => '',
'details' => '',
'delete' => '',
'activate' => '',
'details' => '',
'delete' => '',
);
// Do not restrict by default
$restrict_network_active = false;
$restrict_network_only = false;
$restrict_network_only = false;
if ( 'mustuse' === $context ) {
$is_active = true;
} elseif ( 'dropins' === $context ) {
$dropins = _get_dropins();
$dropins = _get_dropins();
$plugin_name = $plugin_file;
if ( $plugin_file != $plugin_data['Name'] )
if ( $plugin_file != $plugin_data['Name'] ) {
$plugin_name .= '<br/>' . $plugin_data['Name'];
}
if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
$is_active = true;
$is_active = true;
$description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
} elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
$is_active = true;
$is_active = true;
$description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
} else {
$is_active = false;
$is_active = false;
$description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' .
/* translators: 1: drop-in constant name, 2: wp-config.php */
sprintf( __( 'Requires %1$s in %2$s file.' ),
sprintf(
/* translators: 1: drop-in constant name, 2: wp-config.php */
__( 'Requires %1$s in %2$s file.' ),
"<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>",
'<code>wp-config.php</code>'
) . '</p>';
}
if ( $plugin_data['Description'] )
if ( $plugin_data['Description'] ) {
$description .= '<p>' . $plugin_data['Description'] . '</p>';
}
} else {
if ( $screen->in_admin( 'network' ) ) {
$is_active = is_plugin_active_for_network( $plugin_file );
} else {
$is_active = is_plugin_active( $plugin_file );
$is_active = is_plugin_active( $plugin_file );
$restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
$restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
$restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
}
if ( $screen->in_admin( 'network' ) ) {
@ -599,7 +632,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
if ( current_user_can( 'manage_network_plugins' ) ) {
/* translators: %s: plugin name */
$actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>';
}
}
} else {
if ( current_user_can( 'manage_network_plugins' ) ) {
/* translators: %s: plugin name */
@ -635,9 +668,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
$actions['delete'] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
}
} // end if $is_active
} // end if $screen->in_admin( 'network' )
} // end if $screen->in_admin( 'network' )
} // end if $context
$actions = array_filter( $actions );
@ -649,12 +680,12 @@ class WP_Plugins_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @param array $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
* @param string[] $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
*/
$actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
@ -666,12 +697,12 @@ class WP_Plugins_List_Table extends WP_List_Table {
*
* @since 3.1.0
*
* @param array $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
* @param string[] $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
*/
$actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
@ -684,13 +715,13 @@ class WP_Plugins_List_Table extends WP_List_Table {
* @since 2.6.0 The `$context` parameter was added.
* @since 4.9.0 The 'Edit' link was removed from the list of action links.
*
* @param array $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'. With Multisite active this can also include
* 'network_active' and 'network_only' items.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
* @param string[] $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'. With Multisite active this can also include
* 'network_active' and 'network_only' items.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
*/
$actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
@ -703,24 +734,25 @@ class WP_Plugins_List_Table extends WP_List_Table {
* @since 2.7.0
* @since 4.9.0 The 'Edit' link was removed from the list of action links.
*
* @param array $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'. With Multisite active this can also include
* 'network_active' and 'network_only' items.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
* @param string[] $actions An array of plugin action links. By default this can include 'activate',
* 'deactivate', and 'delete'. With Multisite active this can also include
* 'network_active' and 'network_only' items.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
*/
$actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
}
$class = $is_active ? 'active' : 'inactive';
$checkbox_id = "checkbox_" . md5($plugin_data['Name']);
$class = $is_active ? 'active' : 'inactive';
$checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
$checkbox = '';
} else {
$checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"
/* translators: %s: plugin name */
$checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . '</label>'
. "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />";
}
if ( 'dropins' != $context ) {
@ -728,11 +760,13 @@ class WP_Plugins_List_Table extends WP_List_Table {
$plugin_name = $plugin_data['Name'];
}
if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) )
if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) {
$class .= ' update';
}
$plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name );
printf( '<tr class="%s" data-slug="%s" data-plugin="%s">',
printf(
'<tr class="%s" data-slug="%s" data-plugin="%s">',
esc_attr( $class ),
esc_attr( $plugin_slug ),
esc_attr( $plugin_file )
@ -753,7 +787,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
case 'name':
echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>";
echo $this->row_actions( $actions, true );
echo "</td>";
echo '</td>';
break;
case 'description':
$classes = 'column-description desc';
@ -763,26 +797,37 @@ class WP_Plugins_List_Table extends WP_List_Table {
<div class='$class second plugin-version-author-uri'>";
$plugin_meta = array();
if ( !empty( $plugin_data['Version'] ) )
if ( ! empty( $plugin_data['Version'] ) ) {
/* translators: %s: plugin version number */
$plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
if ( !empty( $plugin_data['Author'] ) ) {
}
if ( ! empty( $plugin_data['Author'] ) ) {
$author = $plugin_data['Author'];
if ( !empty( $plugin_data['AuthorURI'] ) )
if ( ! empty( $plugin_data['AuthorURI'] ) ) {
$author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
}
/* translators: %s: plugin version number */
$plugin_meta[] = sprintf( __( 'By %s' ), $author );
}
// Details link using API info, if available
if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) {
$plugin_meta[] = sprintf( '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
'&TB_iframe=true&width=600&height=550' ) ),
$plugin_meta[] = sprintf(
'<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
esc_url(
network_admin_url(
'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
'&TB_iframe=true&width=600&height=550'
)
),
/* translators: %s: plugin name */
esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),
esc_attr( $plugin_name ),
__( 'View details' )
);
} elseif ( ! empty( $plugin_data['PluginURI'] ) ) {
$plugin_meta[] = sprintf( '<a href="%s">%s</a>',
$plugin_meta[] = sprintf(
'<a href="%s">%s</a>',
esc_url( $plugin_data['PluginURI'] ),
__( 'Visit plugin site' )
);
@ -793,19 +838,21 @@ class WP_Plugins_List_Table extends WP_List_Table {
*
* @since 2.8.0
*
* @param array $plugin_meta An array of the plugin's metadata,
* including the version, author,
* author URI, and plugin URI.
* @param string $plugin_file Path to the plugin file, relative to the plugins directory.
* @param array $plugin_data An array of plugin data.
* @param string $status Status of the plugin. Defaults are 'All', 'Active',
* 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
* 'Drop-ins', 'Search'.
* @param string[] $plugin_meta An array of the plugin's metadata,
* including the version, author,
* author URI, and plugin URI.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data.
* @param string $status Status of the plugin. Defaults are 'All', 'Active',
* 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
* 'Drop-ins', 'Search'.
*/
$plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
echo implode( ' | ', $plugin_meta );
echo "</div></td>";
echo '</div>';
echo '</td>';
break;
default:
$classes = "$column_name column-$column_name $class";
@ -818,23 +865,23 @@ class WP_Plugins_List_Table extends WP_List_Table {
* @since 3.1.0
*
* @param string $column_name Name of the column.
* @param string $plugin_file Path to the plugin file.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data.
*/
do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
echo "</td>";
echo '</td>';
}
}
echo "</tr>";
echo '</tr>';
/**
* Fires after each row in the Plugins list table.
*
* @since 2.3.0
*
* @param string $plugin_file Path to the plugin file, relative to the plugins directory.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data.
* @param string $status Status of the plugin. Defaults are 'All', 'Active',
* 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
@ -850,7 +897,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
*
* @since 2.7.0
*
* @param string $plugin_file Path to the plugin file, relative to the plugins directory.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data.
* @param string $status Status of the plugin. Defaults are 'All', 'Active',
* 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',

View file

@ -18,14 +18,13 @@
class WP_Post_Comments_List_Table extends WP_Comments_List_Table {
/**
*
* @return array
*/
protected function get_column_info() {
return array(
array(
'author' => __( 'Author' ),
'comment' => _x( 'Comment', 'column name' ),
'author' => __( 'Author' ),
'comment' => _x( 'Comment', 'column name' ),
),
array(),
array(),
@ -34,40 +33,42 @@ class WP_Post_Comments_List_Table extends WP_Comments_List_Table {
}
/**
*
* @return array
*/
protected function get_table_classes() {
$classes = parent::get_table_classes();
$classes = parent::get_table_classes();
$classes[] = 'wp-list-table';
$classes[] = 'comments-box';
return $classes;
}
/**
*
* @param bool $output_empty
*/
public function display( $output_empty = false ) {
$singular = $this->_args['singular'];
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
<table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" style="display:none;">
<tbody id="the-comment-list"<?php
<tbody id="the-comment-list"
<?php
if ( $singular ) {
echo " data-wp-lists='list:$singular'";
} ?>>
<?php if ( ! $output_empty ) {
}
?>
>
<?php
if ( ! $output_empty ) {
$this->display_rows_or_placeholder();
} ?>
}
?>
</tbody>
</table>
<?php
<?php
}
/**
*
* @param bool $comment_status
* @return int
*/

File diff suppressed because it is too large Load diff

View file

@ -108,6 +108,7 @@ final class WP_Screen {
/**
* The taxonomy associated with the screen, if any.
* The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
*
* @since 3.3.0
* @var string
*/
@ -129,7 +130,7 @@ final class WP_Screen {
*/
private $_help_sidebar = '';
/**
/**
* The accessible hidden headings and text associated with the screen, if any.
*
* @since 4.4.0
@ -140,8 +141,6 @@ final class WP_Screen {
/**
* Stores old string-based help.
*
* @static
*
* @var array
*/
private static $_old_compat_help = array();
@ -159,8 +158,6 @@ final class WP_Screen {
*
* @since 3.3.0
*
* @static
*
* @var array
*/
private static $_registry = array();
@ -194,12 +191,10 @@ final class WP_Screen {
*
* @since 3.3.0
*
* @static
*
* @global string $hook_suffix
*
* @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
* Defaults to the current $hook_suffix global.
* Defaults to the current $hook_suffix global.
* @return WP_Screen Screen object.
*/
public static function get( $hook_name = '' ) {
@ -208,34 +203,36 @@ final class WP_Screen {
}
$post_type = $taxonomy = null;
$in_admin = false;
$action = '';
$in_admin = false;
$action = '';
if ( $hook_name )
if ( $hook_name ) {
$id = $hook_name;
else
} else {
$id = $GLOBALS['hook_suffix'];
}
// For those pesky meta boxes.
if ( $hook_name && post_type_exists( $hook_name ) ) {
$post_type = $id;
$id = 'post'; // changes later. ends up being $base.
$id = 'post'; // changes later. ends up being $base.
} else {
if ( '.php' == substr( $id, -4 ) )
if ( '.php' == substr( $id, -4 ) ) {
$id = substr( $id, 0, -4 );
}
if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
$id = substr( $id, 0, -4 );
$id = substr( $id, 0, -4 );
$action = 'add';
}
}
if ( ! $post_type && $hook_name ) {
if ( '-network' == substr( $id, -8 ) ) {
$id = substr( $id, 0, -8 );
$id = substr( $id, 0, -8 );
$in_admin = 'network';
} elseif ( '-user' == substr( $id, -5 ) ) {
$id = substr( $id, 0, -5 );
$id = substr( $id, 0, -5 );
$in_admin = 'user';
}
@ -243,60 +240,68 @@ final class WP_Screen {
if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
$maybe = substr( $id, 5 );
if ( taxonomy_exists( $maybe ) ) {
$id = 'edit-tags';
$id = 'edit-tags';
$taxonomy = $maybe;
} elseif ( post_type_exists( $maybe ) ) {
$id = 'edit';
$id = 'edit';
$post_type = $maybe;
}
}
if ( ! $in_admin )
if ( ! $in_admin ) {
$in_admin = 'site';
}
} else {
if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) {
$in_admin = 'network';
elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
} elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) {
$in_admin = 'user';
else
} else {
$in_admin = 'site';
}
}
if ( 'index' == $id )
if ( 'index' == $id ) {
$id = 'dashboard';
elseif ( 'front' == $id )
} elseif ( 'front' == $id ) {
$in_admin = false;
}
$base = $id;
// If this is the current screen, see if we can be more accurate for post types and taxonomies.
if ( ! $hook_name ) {
if ( isset( $_REQUEST['post_type'] ) )
if ( isset( $_REQUEST['post_type'] ) ) {
$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
if ( isset( $_REQUEST['taxonomy'] ) )
}
if ( isset( $_REQUEST['taxonomy'] ) ) {
$taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
}
switch ( $base ) {
case 'post' :
if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] )
case 'post':
if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) {
wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
elseif ( isset( $_GET['post'] ) )
} elseif ( isset( $_GET['post'] ) ) {
$post_id = (int) $_GET['post'];
elseif ( isset( $_POST['post_ID'] ) )
} elseif ( isset( $_POST['post_ID'] ) ) {
$post_id = (int) $_POST['post_ID'];
else
} else {
$post_id = 0;
}
if ( $post_id ) {
$post = get_post( $post_id );
if ( $post )
if ( $post ) {
$post_type = $post->post_type;
}
}
break;
case 'edit-tags' :
case 'term' :
if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
case 'edit-tags':
case 'term':
if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) {
$post_type = 'post';
}
break;
case 'upload':
$post_type = 'attachment';
@ -305,25 +310,29 @@ final class WP_Screen {
}
switch ( $base ) {
case 'post' :
if ( null === $post_type )
case 'post':
if ( null === $post_type ) {
$post_type = 'post';
}
$id = $post_type;
break;
case 'edit' :
if ( null === $post_type )
case 'edit':
if ( null === $post_type ) {
$post_type = 'post';
}
$id .= '-' . $post_type;
break;
case 'edit-tags' :
case 'term' :
if ( null === $taxonomy )
case 'edit-tags':
case 'term':
if ( null === $taxonomy ) {
$taxonomy = 'post_tag';
}
// The edit-tags ID does not contain the post type. Look for it in the request.
if ( null === $post_type ) {
$post_type = 'post';
if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
$post_type = $_REQUEST['post_type'];
}
}
$id = 'edit-' . $taxonomy;
@ -340,11 +349,12 @@ final class WP_Screen {
if ( isset( self::$_registry[ $id ] ) ) {
$screen = self::$_registry[ $id ];
if ( $screen === get_current_screen() )
if ( $screen === get_current_screen() ) {
return $screen;
}
} else {
$screen = new WP_Screen();
$screen->id = $id;
$screen = new WP_Screen();
$screen->id = $id;
}
$screen->base = $base;
@ -373,8 +383,8 @@ final class WP_Screen {
public function set_current_screen() {
global $current_screen, $taxnow, $typenow;
$current_screen = $this;
$taxnow = $this->taxonomy;
$typenow = $this->post_type;
$taxnow = $this->taxonomy;
$typenow = $this->post_type;
/**
* Fires after the current screen has been set.
@ -403,8 +413,9 @@ final class WP_Screen {
* @return bool True if the screen is in the indicated admin, false otherwise.
*/
public function in_admin( $admin = null ) {
if ( empty( $admin ) )
if ( empty( $admin ) ) {
return (bool) $this->in_admin;
}
return ( $admin == $this->in_admin );
}
@ -430,8 +441,6 @@ final class WP_Screen {
*
* @since 3.3.0
*
* @static
*
* @param WP_Screen $screen A screen object.
* @param string $help Help text.
*/
@ -448,9 +457,9 @@ final class WP_Screen {
* @param string $parent_file The parent file of the screen. Typically the $parent_file global.
*/
public function set_parentage( $parent_file ) {
$this->parent_file = $parent_file;
$this->parent_file = $parent_file;
list( $this->parent_base ) = explode( '?', $parent_file );
$this->parent_base = str_replace( '.php', '', $this->parent_base );
$this->parent_base = str_replace( '.php', '', $this->parent_base );
}
/**
@ -508,11 +517,13 @@ final class WP_Screen {
* @return string The option value if set, null otherwise.
*/
public function get_option( $option, $key = false ) {
if ( ! isset( $this->_options[ $option ] ) )
if ( ! isset( $this->_options[ $option ] ) ) {
return null;
}
if ( $key ) {
if ( isset( $this->_options[ $option ][ $key ] ) )
if ( isset( $this->_options[ $option ][ $key ] ) ) {
return $this->_options[ $option ][ $key ];
}
return null;
}
return $this->_options[ $option ];
@ -559,8 +570,9 @@ final class WP_Screen {
* @return array Help tab arguments.
*/
public function get_help_tab( $id ) {
if ( ! isset( $this->_help_tabs[ $id ] ) )
if ( ! isset( $this->_help_tabs[ $id ] ) ) {
return null;
}
return $this->_help_tabs[ $id ];
}
@ -589,13 +601,14 @@ final class WP_Screen {
'callback' => false,
'priority' => 10,
);
$args = wp_parse_args( $args, $defaults );
$args = wp_parse_args( $args, $defaults );
$args['id'] = sanitize_html_class( $args['id'] );
// Ensure we have an ID and title.
if ( ! $args['id'] || ! $args['title'] )
if ( ! $args['id'] || ! $args['title'] ) {
return;
}
// Allows for overriding an existing tab with that ID.
$this->_help_tabs[ $args['id'] ] = $args;
@ -661,7 +674,7 @@ final class WP_Screen {
return $this->columns;
}
/**
/**
* Get the accessible hidden headings and text used in the screen.
*
* @since 4.4.0
@ -711,7 +724,7 @@ final class WP_Screen {
'heading_pagination' => __( 'Items list navigation' ),
'heading_list' => __( 'Items list' ),
);
$content = wp_parse_args( $content, $defaults );
$content = wp_parse_args( $content, $defaults );
$this->_screen_reader_content = $content;
}
@ -760,7 +773,6 @@ final class WP_Screen {
* @param string $old_help Help text that appears on the screen.
* @param string $screen_id Screen ID.
* @param WP_Screen $this Current WP_Screen instance.
*
*/
$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
@ -777,29 +789,33 @@ final class WP_Screen {
* @param string $old_help_default Default contextual help text.
*/
$default_help = apply_filters( 'default_contextual_help', '' );
if ( $default_help )
if ( $default_help ) {
$old_help = '<p>' . $default_help . '</p>';
}
}
if ( $old_help ) {
$this->add_help_tab( array(
'id' => 'old-contextual-help',
'title' => __('Overview'),
'content' => $old_help,
) );
$this->add_help_tab(
array(
'id' => 'old-contextual-help',
'title' => __( 'Overview' ),
'content' => $old_help,
)
);
}
$help_sidebar = $this->get_help_sidebar();
$help_class = 'hidden';
if ( ! $help_sidebar )
if ( ! $help_sidebar ) {
$help_class .= ' no-sidebar';
}
// Time to render!
?>
<div id="screen-meta" class="metabox-prefs">
<div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
<div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e( 'Contextual Help Tab' ); ?>">
<div id="contextual-help-back"></div>
<div id="contextual-help-columns">
<div class="contextual-help-tabs">
@ -816,7 +832,7 @@ final class WP_Screen {
<?php echo esc_html( $tab['title'] ); ?>
</a>
</li>
<?php
<?php
$class = '';
endforeach;
?>
@ -832,7 +848,7 @@ final class WP_Screen {
<div class="contextual-help-tabs-wrap">
<?php
$classes = 'help-tab-content active';
foreach ( $this->get_help_tabs() as $tab ):
foreach ( $this->get_help_tabs() as $tab ) :
$panel_id = "tab-panel-{$tab['id']}";
?>
@ -842,11 +858,12 @@ final class WP_Screen {
echo $tab['content'];
// If it exists, fire tab callback.
if ( ! empty( $tab['callback'] ) )
if ( ! empty( $tab['callback'] ) ) {
call_user_func_array( $tab['callback'], array( $this, $tab ) );
}
?>
</div>
<?php
<?php
$classes = 'help-tab-content';
endforeach;
?>
@ -870,33 +887,39 @@ final class WP_Screen {
*/
$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
$this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) {
$this->add_option( 'layout_columns', array( 'max' => $columns[ $this->id ] ) );
}
if ( $this->get_option( 'layout_columns' ) ) {
$this->columns = (int) get_user_option("screen_layout_$this->id");
$this->columns = (int) get_user_option( "screen_layout_$this->id" );
if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) {
$this->columns = $this->get_option( 'layout_columns', 'default' );
}
}
$GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
$GLOBALS['screen_layout_columns'] = $this->columns; // Set the global for back-compat.
// Add screen options
if ( $this->show_screen_options() )
if ( $this->show_screen_options() ) {
$this->render_screen_options();
}
?>
</div>
<?php
if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) {
return;
}
?>
<div id="screen-meta-links">
<?php if ( $this->get_help_tabs() ) : ?>
<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
<button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
</div>
<?php endif;
if ( $this->show_screen_options() ) : ?>
<?php
endif;
if ( $this->show_screen_options() ) :
?>
<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
<button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
</div>
@ -906,7 +929,6 @@ final class WP_Screen {
}
/**
*
* @global array $wp_meta_boxes
*
* @return bool
@ -914,27 +936,21 @@ final class WP_Screen {
public function show_screen_options() {
global $wp_meta_boxes;
if ( is_bool( $this->_show_screen_options ) )
if ( is_bool( $this->_show_screen_options ) ) {
return $this->_show_screen_options;
}
$columns = get_column_headers( $this );
$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
switch ( $this->base ) {
case 'widgets':
$nonce = wp_create_nonce( 'widgets-access' );
$this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=' . urlencode( $nonce ) . '">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=' . urlencode( $nonce ) . '">' . __('Disable accessibility mode') . "</a></p>\n";
break;
case 'post' :
$expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
$expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
$expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
$this->_screen_settings = $expand;
break;
default:
$this->_screen_settings = '';
break;
$this->_screen_settings = '';
if ( 'post' === $this->base ) {
$expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
$expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
$expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
$this->_screen_settings = $expand;
}
/**
@ -950,8 +966,9 @@ final class WP_Screen {
*/
$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
if ( $this->_screen_settings || $this->_options )
if ( $this->_screen_settings || $this->_options ) {
$show_screen = true;
}
/**
* Filters whether to show the Screen Options tab.
@ -976,22 +993,25 @@ final class WP_Screen {
* }
*/
public function render_screen_options( $options = array() ) {
$options = wp_parse_args( $options, array(
'wrap' => true,
) );
$options = wp_parse_args(
$options,
array(
'wrap' => true,
)
);
$wrapper_start = $wrapper_end = $form_start = $form_end = '';
// Output optional wrapper.
if ( $options['wrap'] ) {
$wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">';
$wrapper_end = '</div>';
$wrapper_end = '</div>';
}
// Don't output the form and nonce for the widgets accessibility mode links.
if ( 'widgets' !== $this->base ) {
$form_start = "\n<form id='adv-settings' method='post'>\n";
$form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
$form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
}
echo $wrapper_start . $form_start;
@ -1040,24 +1060,20 @@ final class WP_Screen {
<?php
meta_box_prefs( $this );
if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
if ( isset( $_GET['welcome'] ) ) {
$welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
} else {
$welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
if ( '' === $welcome_checked ) {
$welcome_checked = '1';
}
if ( '2' === $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
$welcome_checked = false;
}
if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
if ( isset( $_GET['welcome'] ) ) {
$welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
} else {
$welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
$welcome_checked = false;
}
echo '<label for="wp_welcome_panel-hide">';
echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
}
echo '<label for="wp_welcome_panel-hide">';
echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
}
?>
</fieldset>
<?php
@ -1122,20 +1138,22 @@ final class WP_Screen {
}
$screen_layout_columns = $this->get_columns();
$num = $this->get_option( 'layout_columns', 'max' );
$num = $this->get_option( 'layout_columns', 'max' );
?>
<fieldset class='columns-prefs'>
<legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php
for ( $i = 1; $i <= $num; ++$i ):
?>
<label class="columns-prefs-<?php echo $i; ?>">
<input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
<?php checked( $screen_layout_columns, $i ); ?> />
<?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
<legend class="screen-layout"><?php _e( 'Layout' ); ?></legend>
<?php
for ( $i = 1; $i <= $num; ++$i ) :
?>
<label class="columns-prefs-<?php echo $i; ?>">
<input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
<?php checked( $screen_layout_columns, $i ); ?> />
<?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
</label>
<?php
endfor; ?>
<?php
endfor;
?>
</fieldset>
<?php
}
@ -1219,15 +1237,20 @@ final class WP_Screen {
return;
}
$view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) );
$view_mode_post_types = get_post_types(
array(
'hierarchical' => false,
'show_ui' => true,
)
);
/**
* Filters the post types that have different view mode options.
*
* @since 4.4.0
*
* @param array $view_mode_post_types Array of post types that can change view modes.
* Default non-hierarchical post types with show_ui on.
* @param string[] $view_mode_post_types Array of post types that can change view modes.
* Default non-hierarchical post types with show_ui on.
*/
$view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
@ -1239,7 +1262,7 @@ final class WP_Screen {
// This needs a submit button
add_filter( 'screen_options_show_submit', '__return_true' );
?>
?>
<fieldset class="metabox-prefs view-mode">
<legend><?php _e( 'View Mode' ); ?></legend>
<label for="list-view-mode">
@ -1251,7 +1274,7 @@ final class WP_Screen {
<?php _e( 'Excerpt View' ); ?>
</label>
</fieldset>
<?php
<?php
}
/**

View file

@ -20,7 +20,7 @@ class WP_Site_Icon {
* @since 4.3.0
* @var int
*/
public $min_size = 512;
public $min_size = 512;
/**
* The size to which to crop the image so that we can display it in the UI nicely.
@ -34,7 +34,7 @@ class WP_Site_Icon {
* List of site icon sizes.
*
* @since 4.3.0
* @var array
* @var int[]
*/
public $site_icon_sizes = array(
/*
@ -96,7 +96,7 @@ class WP_Site_Icon {
'post_content' => $url,
'post_mime_type' => $image_type,
'guid' => $url,
'context' => 'site-icon'
'context' => 'site-icon',
);
return $object;
@ -131,12 +131,12 @@ class WP_Site_Icon {
}
/**
* Adds additional sizes to be made when creating the site_icon images.
* Adds additional sizes to be made when creating the site icon images.
*
* @since 4.3.0
*
* @param array $sizes List of additional sizes.
* @return array Additional image sizes.
* @param array[] $sizes Array of arrays containing information for additional sizes.
* @return array[] Array of arrays containing additional image sizes.
*/
public function additional_sizes( $sizes = array() ) {
$only_crop_sizes = array();
@ -146,7 +146,7 @@ class WP_Site_Icon {
*
* @since 4.3.0
*
* @param array $site_icon_sizes Sizes available for the Site Icon.
* @param int[] $site_icon_sizes Array of sizes available for the Site Icon.
*/
$this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
@ -179,8 +179,8 @@ class WP_Site_Icon {
*
* @since 4.3.0
*
* @param array $sizes List of image sizes.
* @return array List of intermediate image sizes.
* @param string[] $sizes Array of image size names.
* @return string[] Array of image size names.
*/
public function intermediate_image_sizes( $sizes = array() ) {
/** This filter is documented in wp-admin/includes/class-wp-site-icon.php */

View file

@ -38,32 +38,36 @@ class WP_Terms_List_Table extends WP_List_Table {
public function __construct( $args = array() ) {
global $post_type, $taxonomy, $action, $tax;
parent::__construct( array(
'plural' => 'tags',
'singular' => 'tag',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'plural' => 'tags',
'singular' => 'tag',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
$action = $this->screen->action;
$post_type = $this->screen->post_type;
$taxonomy = $this->screen->taxonomy;
if ( empty( $taxonomy ) )
if ( empty( $taxonomy ) ) {
$taxonomy = 'post_tag';
}
if ( ! taxonomy_exists( $taxonomy ) )
if ( ! taxonomy_exists( $taxonomy ) ) {
wp_die( __( 'Invalid taxonomy.' ) );
}
$tax = get_taxonomy( $taxonomy );
// @todo Still needed? Maybe just the show_ui part.
if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) )
if ( empty( $post_type ) || ! in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) {
$post_type = 'post';
}
}
/**
*
* @return bool
*/
public function ajax_user_can() {
@ -105,30 +109,33 @@ class WP_Terms_List_Table extends WP_List_Table {
$tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page );
}
$search = !empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
$search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
$args = array(
'search' => $search,
'page' => $this->get_pagenum(),
'page' => $this->get_pagenum(),
'number' => $tags_per_page,
);
if ( !empty( $_REQUEST['orderby'] ) )
if ( ! empty( $_REQUEST['orderby'] ) ) {
$args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) );
}
if ( !empty( $_REQUEST['order'] ) )
if ( ! empty( $_REQUEST['order'] ) ) {
$args['order'] = trim( wp_unslash( $_REQUEST['order'] ) );
}
$this->callback_args = $args;
$this->set_pagination_args( array(
'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
'per_page' => $tags_per_page,
) );
$this->set_pagination_args(
array(
'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
'per_page' => $tags_per_page,
)
);
}
/**
*
* @return bool
*/
public function has_items() {
@ -143,7 +150,6 @@ class WP_Terms_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
protected function get_bulk_actions() {
@ -157,18 +163,17 @@ class WP_Terms_List_Table extends WP_List_Table {
}
/**
*
* @return string
*/
public function current_action() {
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) )
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) {
return 'bulk-delete';
}
return parent::current_action();
}
/**
*
* @return array
*/
public function get_columns() {
@ -189,7 +194,6 @@ class WP_Terms_List_Table extends WP_List_Table {
}
/**
*
* @return array
*/
protected function get_sortable_columns() {
@ -198,7 +202,7 @@ class WP_Terms_List_Table extends WP_List_Table {
'description' => 'description',
'slug' => 'slug',
'posts' => 'count',
'links' => 'count'
'links' => 'count',
);
}
@ -207,12 +211,15 @@ class WP_Terms_List_Table extends WP_List_Table {
public function display_rows_or_placeholder() {
$taxonomy = $this->screen->taxonomy;
$args = wp_parse_args( $this->callback_args, array(
'page' => 1,
'number' => 20,
'search' => '',
'hide_empty' => 0
) );
$args = wp_parse_args(
$this->callback_args,
array(
'page' => 1,
'number' => 20,
'search' => '',
'hide_empty' => 0,
)
);
$page = $args['page'];
@ -268,22 +275,25 @@ class WP_Terms_List_Table extends WP_List_Table {
foreach ( $terms as $key => $term ) {
if ( $count >= $end )
if ( $count >= $end ) {
break;
}
if ( $term->parent != $parent && empty( $_REQUEST['s'] ) )
if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) {
continue;
}
// If the page starts in a subtree, print the parents.
if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
$my_parents = $parent_ids = array();
$p = $term->parent;
$p = $term->parent;
while ( $p ) {
$my_parent = get_term( $p, $taxonomy );
$my_parent = get_term( $p, $taxonomy );
$my_parents[] = $my_parent;
$p = $my_parent->parent;
if ( in_array( $p, $parent_ids ) ) // Prevent parent loops.
$p = $my_parent->parent;
if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
break;
}
$parent_ids[] = $p;
}
unset( $parent_ids );
@ -303,10 +313,11 @@ class WP_Terms_List_Table extends WP_List_Table {
++$count;
unset( $terms[$key] );
unset( $terms[ $key ] );
if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
if ( isset( $children[ $term->term_id ] ) && empty( $_REQUEST['s'] ) ) {
$this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
}
}
}
@ -317,7 +328,7 @@ class WP_Terms_List_Table extends WP_List_Table {
*/
public function single_row( $tag, $level = 0 ) {
global $taxonomy;
$tag = sanitize_term( $tag, $taxonomy );
$tag = sanitize_term( $tag, $taxonomy );
$this->level = $level;
@ -367,17 +378,25 @@ class WP_Terms_List_Table extends WP_List_Table {
$uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
$edit_link = add_query_arg(
'wp_http_referer',
urlencode( wp_unslash( $uri ) ),
get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type )
);
$edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type );
if ( $edit_link ) {
$edit_link = add_query_arg(
'wp_http_referer',
urlencode( wp_unslash( $uri ) ),
$edit_link
);
$name = sprintf(
'<a class="row-title" href="%s" aria-label="%s">%s</a>',
esc_url( $edit_link ),
/* translators: %s: taxonomy term name */
esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $tag->name ) ),
$name
);
}
$out = sprintf(
'<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong><br />',
esc_url( $edit_link ),
/* translators: %s: taxonomy term name */
esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $tag->name ) ),
'<strong>%s</strong><br />',
$name
);
@ -418,8 +437,8 @@ class WP_Terms_List_Table extends WP_List_Table {
}
$taxonomy = $this->screen->taxonomy;
$tax = get_taxonomy( $taxonomy );
$uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
$tax = get_taxonomy( $taxonomy );
$uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
$edit_link = add_query_arg(
'wp_http_referer',
@ -437,7 +456,7 @@ class WP_Terms_List_Table extends WP_List_Table {
__( 'Edit' )
);
$actions['inline hide-if-no-js'] = sprintf(
'<a href="#" class="editinline aria-button-if-js" aria-label="%s">%s</a>',
'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
/* translators: %s: taxonomy term name */
esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
__( 'Quick&nbsp;Edit' )
@ -452,7 +471,7 @@ class WP_Terms_List_Table extends WP_List_Table {
__( 'Delete' )
);
}
if ( $tax->public ) {
if ( is_taxonomy_viewable( $tax ) ) {
$actions['view'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
get_term_link( $tag ),
@ -468,9 +487,9 @@ class WP_Terms_List_Table extends WP_List_Table {
* @since 2.8.0
* @deprecated 3.0.0 Use {$taxonomy}_row_actions instead.
*
* @param array $actions An array of action links to be displayed. Default
* 'Edit', 'Quick Edit', 'Delete', and 'View'.
* @param WP_Term $tag Term object.
* @param string[] $actions An array of action links to be displayed. Default
* 'Edit', 'Quick Edit', 'Delete', and 'View'.
* @param WP_Term $tag Term object.
*/
$actions = apply_filters( 'tag_row_actions', $actions, $tag );
@ -481,9 +500,9 @@ class WP_Terms_List_Table extends WP_List_Table {
*
* @since 3.0.0
*
* @param array $actions An array of action links to be displayed. Default
* 'Edit', 'Quick Edit', 'Delete', and 'View'.
* @param WP_Term $tag Term object.
* @param string[] $actions An array of action links to be displayed. Default
* 'Edit', 'Quick Edit', 'Delete', and 'View'.
* @param WP_Term $tag Term object.
*/
$actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
@ -521,22 +540,28 @@ class WP_Terms_List_Table extends WP_List_Table {
$tax = get_taxonomy( $this->screen->taxonomy );
$ptype_object = get_post_type_object( $this->screen->post_type );
if ( ! $ptype_object->show_ui )
if ( ! $ptype_object->show_ui ) {
return $count;
}
if ( $tax->query_var ) {
$args = array( $tax->query_var => $tag->slug );
} else {
$args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug );
$args = array(
'taxonomy' => $tax->name,
'term' => $tag->slug,
);
}
if ( 'post' != $this->screen->post_type )
if ( 'post' != $this->screen->post_type ) {
$args['post_type'] = $this->screen->post_type;
}
if ( 'attachment' === $this->screen->post_type )
return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
if ( 'attachment' === $this->screen->post_type ) {
return "<a href='" . esc_url( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
}
return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
}
/**
@ -545,8 +570,9 @@ class WP_Terms_List_Table extends WP_List_Table {
*/
public function column_links( $tag ) {
$count = number_format_i18n( $tag->count );
if ( $count )
if ( $count ) {
$count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>";
}
return $count;
}
@ -579,9 +605,10 @@ class WP_Terms_List_Table extends WP_List_Table {
public function inline_edit() {
$tax = get_taxonomy( $this->screen->taxonomy );
if ( ! current_user_can( $tax->cap->edit_terms ) )
if ( ! current_user_can( $tax->cap->edit_terms ) ) {
return;
?>
}
?>
<form method="get"><table style="display: none"><tbody id="inlineedit">
<tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
@ -593,28 +620,35 @@ class WP_Terms_List_Table extends WP_List_Table {
<span class="title"><?php _ex( 'Name', 'term name' ); ?></span>
<span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
</label>
<?php if ( !global_terms_enabled() ) { ?>
<?php if ( ! global_terms_enabled() ) { ?>
<label>
<span class="title"><?php _e( 'Slug' ); ?></span>
<span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
</label>
<?php } ?>
</div></fieldset>
<?php
<?php
$core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
$core_columns = array(
'cb' => true,
'description' => true,
'name' => true,
'slug' => true,
'posts' => true,
);
list( $columns ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
if ( isset( $core_columns[$column_name] ) )
if ( isset( $core_columns[ $column_name ] ) ) {
continue;
}
/** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
}
?>
?>
<div class="inline-edit-save submit">
<button type="button" class="cancel button alignleft"><?php _e( 'Cancel' ); ?></button>
@ -630,6 +664,6 @@ class WP_Terms_List_Table extends WP_List_Table {
</div>
</td></tr>
</tbody></table></form>
<?php
<?php
}
}

View file

@ -20,7 +20,6 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
public $features = array();
/**
*
* @return bool
*/
public function ajax_user_can() {
@ -28,7 +27,6 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
}
/**
*
* @global array $tabs
* @global string $tab
* @global int $paged
@ -41,30 +39,32 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
global $tabs, $tab, $paged, $type, $theme_field_defaults;
wp_reset_vars( array( 'tab' ) );
$search_terms = array();
$search_terms = array();
$search_string = '';
if ( ! empty( $_REQUEST['s'] ) ){
if ( ! empty( $_REQUEST['s'] ) ) {
$search_string = strtolower( wp_unslash( $_REQUEST['s'] ) );
$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
}
if ( ! empty( $_REQUEST['features'] ) )
if ( ! empty( $_REQUEST['features'] ) ) {
$this->features = $_REQUEST['features'];
}
$paged = $this->get_pagenum();
$per_page = 36;
// These are the tabs which are shown on the page,
$tabs = array();
$tabs = array();
$tabs['dashboard'] = __( 'Search' );
if ( 'search' === $tab )
$tabs['search'] = __( 'Search Results' );
$tabs['upload'] = __( 'Upload' );
if ( 'search' === $tab ) {
$tabs['search'] = __( 'Search Results' );
}
$tabs['upload'] = __( 'Upload' );
$tabs['featured'] = _x( 'Featured', 'themes' );
//$tabs['popular'] = _x( 'Popular', 'themes' );
$tabs['new'] = _x( 'Latest', 'themes' );
$tabs['updated'] = _x( 'Recently Updated', 'themes' );
$tabs['new'] = _x( 'Latest', 'themes' );
$tabs['updated'] = _x( 'Recently Updated', 'themes' );
$nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
@ -76,16 +76,21 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
*
* @since 2.8.0
*
* @param array $nonmenu_tabs The tabs that don't have a menu item on
* the Install Themes screen.
* @param string[] $nonmenu_tabs The tabs that don't have a menu item on
* the Install Themes screen.
*/
$nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
// If a non-valid menu tab has been selected, And it's not a non-menu action.
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) {
$tab = key( $tabs );
}
$args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
$args = array(
'page' => $paged,
'per_page' => $per_page,
'fields' => $theme_field_defaults,
);
switch ( $tab ) {
case 'search':
@ -103,8 +108,8 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
}
if ( ! empty( $this->features ) ) {
$args['tag'] = $this->features;
$_REQUEST['s'] = implode( ',', $this->features );
$args['tag'] = $this->features;
$_REQUEST['s'] = implode( ',', $this->features );
$_REQUEST['type'] = 'tag';
}
@ -112,7 +117,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
break;
case 'featured':
// case 'popular':
// case 'popular':
case 'new':
case 'updated':
$args['browse'] = $tab;
@ -136,21 +141,25 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
*/
$args = apply_filters( "install_themes_table_api_args_{$tab}", $args );
if ( ! $args )
if ( ! $args ) {
return;
}
$api = themes_api( 'query_themes', $args );
if ( is_wp_error( $api ) )
if ( is_wp_error( $api ) ) {
wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
}
$this->items = $api->themes;
$this->set_pagination_args( array(
'total_items' => $api->info['results'],
'per_page' => $args['per_page'],
'infinite_scroll' => true,
) );
$this->set_pagination_args(
array(
'total_items' => $api->info['results'],
'per_page' => $args['per_page'],
'infinite_scroll' => true,
)
);
}
/**
@ -160,7 +169,6 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
}
/**
*
* @global array $tabs
* @global string $tab
* @return array
@ -170,9 +178,9 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
$display_tabs = array();
foreach ( (array) $tabs as $action => $text ) {
$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
$href = self_admin_url('theme-install.php?tab=' . $action);
$display_tabs['theme-install-'.$action] = "<a href='$href'$current_link_attributes>$text</a>";
$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
$href = self_admin_url( 'theme-install.php?tab=' . $action );
$display_tabs[ 'theme-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>";
}
return $display_tabs;
@ -181,8 +189,8 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
/**
*/
public function display() {
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
<div class="tablenav top themes">
<div class="alignleft actions">
<?php
@ -211,11 +219,14 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
public function display_rows() {
$themes = $this->items;
foreach ( $themes as $theme ) {
?>
<div class="available-theme installable-theme"><?php
?>
<div class="available-theme installable-theme">
<?php
$this->single_row( $theme );
?></div>
<?php } // end foreach $theme_names
?>
</div>
<?php
} // end foreach $theme_names
$this->theme_installer();
}
@ -246,54 +257,87 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
public function single_row( $theme ) {
global $themes_allowedtags;
if ( empty( $theme ) )
if ( empty( $theme ) ) {
return;
}
$name = wp_kses( $theme->name, $themes_allowedtags );
$name = wp_kses( $theme->name, $themes_allowedtags );
$author = wp_kses( $theme->author, $themes_allowedtags );
$preview_title = sprintf( __('Preview &#8220;%s&#8221;'), $name );
$preview_url = add_query_arg( array(
'tab' => 'theme-information',
'theme' => $theme->slug,
), self_admin_url( 'theme-install.php' ) );
/* translators: %s: theme name */
$preview_title = sprintf( __( 'Preview &#8220;%s&#8221;' ), $name );
$preview_url = add_query_arg(
array(
'tab' => 'theme-information',
'theme' => $theme->slug,
),
self_admin_url( 'theme-install.php' )
);
$actions = array();
$install_url = add_query_arg( array(
'action' => 'install-theme',
'theme' => $theme->slug,
), self_admin_url( 'update.php' ) );
$install_url = add_query_arg(
array(
'action' => 'install-theme',
'theme' => $theme->slug,
),
self_admin_url( 'update.php' )
);
$update_url = add_query_arg( array(
'action' => 'upgrade-theme',
'theme' => $theme->slug,
), self_admin_url( 'update.php' ) );
$update_url = add_query_arg(
array(
'action' => 'upgrade-theme',
'theme' => $theme->slug,
),
self_admin_url( 'update.php' )
);
$status = $this->_get_theme_status( $theme );
switch ( $status ) {
case 'update_available':
$actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
$actions[] = sprintf(
'<a class="install-now" href="%s" title="%s">%s</a>',
esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ),
/* translators: %s: theme version */
esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ),
__( 'Update' )
);
break;
case 'newer_installed':
case 'latest_installed':
$actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
$actions[] = sprintf(
'<span class="install-now" title="%s">%s</span>',
esc_attr__( 'This theme is already installed and is up to date' ),
_x( 'Installed', 'theme' )
);
break;
case 'install':
default:
$actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
$actions[] = sprintf(
'<a class="install-now" href="%s" title="%s">%s</a>',
esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ),
/* translators: %s: theme name */
esc_attr( sprintf( __( 'Install %s' ), $name ) ),
__( 'Install Now' )
);
break;
}
$actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>';
$actions[] = sprintf(
'<a class="install-theme-preview" href="%s" title="%s">%s</a>',
esc_url( $preview_url ),
/* translators: %s: theme name */
esc_attr( sprintf( __( 'Preview %s' ), $name ) ),
__( 'Preview' )
);
/**
* Filters the install action links for a theme in the Install Themes list table.
*
* @since 3.4.0
*
* @param array $actions An array of theme action hyperlinks. Defaults are
* @param string[] $actions An array of theme action links. Defaults are
* links to Install Now, Preview, and Details.
* @param WP_Theme $theme Theme object.
*/
@ -305,14 +349,19 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
</a>
<h3><?php echo $name; ?></h3>
<div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
<div class="theme-author">
<?php
/* translators: %s: theme author */
printf( __( 'By %s' ), $author );
?>
</div>
<div class="action-links">
<ul>
<?php foreach ( $actions as $action ): ?>
<?php foreach ( $actions as $action ) : ?>
<li><?php echo $action; ?></li>
<?php endforeach; ?>
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li>
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e( 'Details' ); ?></a></li>
</ul>
</div>
@ -375,48 +424,84 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
public function install_theme_info( $theme ) {
global $themes_allowedtags;
if ( empty( $theme ) )
if ( empty( $theme ) ) {
return;
}
$name = wp_kses( $theme->name, $themes_allowedtags );
$name = wp_kses( $theme->name, $themes_allowedtags );
$author = wp_kses( $theme->author, $themes_allowedtags );
$install_url = add_query_arg( array(
'action' => 'install-theme',
'theme' => $theme->slug,
), self_admin_url( 'update.php' ) );
$install_url = add_query_arg(
array(
'action' => 'install-theme',
'theme' => $theme->slug,
),
self_admin_url( 'update.php' )
);
$update_url = add_query_arg( array(
'action' => 'upgrade-theme',
'theme' => $theme->slug,
), self_admin_url( 'update.php' ) );
$update_url = add_query_arg(
array(
'action' => 'upgrade-theme',
'theme' => $theme->slug,
),
self_admin_url( 'update.php' )
);
$status = $this->_get_theme_status( $theme );
?>
<div class="install-theme-info"><?php
switch ( $status ) {
case 'update_available':
echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
break;
case 'newer_installed':
case 'latest_installed':
echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
break;
case 'install':
default:
echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>';
break;
} ?>
<div class="install-theme-info">
<?php
switch ( $status ) {
case 'update_available':
printf(
'<a class="theme-install button button-primary" href="%s" title="%s">%s</a>',
esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ),
/* translators: %s: theme version */
esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ),
__( 'Update' )
);
break;
case 'newer_installed':
case 'latest_installed':
printf(
'<span class="theme-install" title="%s">%s</span>',
esc_attr__( 'This theme is already installed and is up to date' ),
_x( 'Installed', 'theme' )
);
break;
case 'install':
default:
printf(
'<a class="theme-install button button-primary" href="%s">%s</a>',
esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ),
__( 'Install' )
);
break;
}
?>
<h3 class="theme-name"><?php echo $name; ?></h3>
<span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span>
<?php if ( isset( $theme->screenshot_url ) ): ?>
<span class="theme-by">
<?php
/* translators: %s: theme author */
printf( __( 'By %s' ), $author );
?>
</span>
<?php if ( isset( $theme->screenshot_url ) ) : ?>
<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" />
<?php endif; ?>
<div class="theme-details">
<?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?>
<?php
wp_star_rating(
array(
'rating' => $theme->rating,
'type' => 'percent',
'number' => $theme->num_ratings,
)
);
?>
<div class="theme-version">
<strong><?php _e('Version:') ?> </strong>
<strong><?php _e( 'Version:' ); ?> </strong>
<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
</div>
<div class="theme-description">
@ -456,12 +541,13 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
$installed_theme = wp_get_theme( $theme->slug );
if ( $installed_theme->exists() ) {
if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) )
if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) {
$status = 'latest_installed';
elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) )
} elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) {
$status = 'newer_installed';
else
} else {
$status = 'update_available';
}
}
return $status;

View file

@ -18,7 +18,7 @@
class WP_Themes_List_Table extends WP_List_Table {
protected $search_terms = array();
public $features = array();
public $features = array();
/**
* Constructor.
@ -30,14 +30,15 @@ class WP_Themes_List_Table extends WP_List_Table {
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
parent::__construct( array(
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
*
* @return bool
*/
public function ajax_user_can() {
@ -50,16 +51,19 @@ class WP_Themes_List_Table extends WP_List_Table {
public function prepare_items() {
$themes = wp_get_themes( array( 'allowed' => true ) );
if ( ! empty( $_REQUEST['s'] ) )
if ( ! empty( $_REQUEST['s'] ) ) {
$this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) );
}
if ( ! empty( $_REQUEST['features'] ) )
if ( ! empty( $_REQUEST['features'] ) ) {
$this->features = $_REQUEST['features'];
}
if ( $this->search_terms || $this->features ) {
foreach ( $themes as $key => $theme ) {
if ( ! $this->search_theme( $theme ) )
if ( ! $this->search_theme( $theme ) ) {
unset( $themes[ $key ] );
}
}
}
@ -67,17 +71,19 @@ class WP_Themes_List_Table extends WP_List_Table {
WP_Theme::sort_by_name( $themes );
$per_page = 36;
$page = $this->get_pagenum();
$page = $this->get_pagenum();
$start = ( $page - 1 ) * $per_page;
$this->items = array_slice( $themes, $start, $per_page, true );
$this->set_pagination_args( array(
'total_items' => count( $themes ),
'per_page' => $per_page,
'infinite_scroll' => true,
) );
$this->set_pagination_args(
array(
'total_items' => count( $themes ),
'per_page' => $per_page,
'infinite_scroll' => true,
)
);
}
/**
@ -115,8 +121,9 @@ class WP_Themes_List_Table extends WP_List_Table {
* @param string $which
*/
public function tablenav( $which = 'top' ) {
if ( $this->get_pagination_arg( 'total_pages' ) <= 1 )
if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) {
return;
}
?>
<div class="tablenav themes <?php echo $which; ?>">
<?php $this->pagination( $which ); ?>
@ -129,8 +136,8 @@ class WP_Themes_List_Table extends WP_List_Table {
/**
*/
public function display() {
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
<?php $this->tablenav( 'top' ); ?>
<div id="availablethemes">
@ -138,11 +145,10 @@ class WP_Themes_List_Table extends WP_List_Table {
</div>
<?php $this->tablenav( 'bottom' ); ?>
<?php
<?php
}
/**
*
* @return array
*/
public function get_columns() {
@ -166,18 +172,20 @@ class WP_Themes_List_Table extends WP_List_Table {
public function display_rows() {
$themes = $this->items;
foreach ( $themes as $theme ):
?><div class="available-theme"><?php
foreach ( $themes as $theme ) :
?>
<div class="available-theme">
<?php
$template = $theme->get_template();
$stylesheet = $theme->get_stylesheet();
$title = $theme->display('Name');
$version = $theme->display('Version');
$author = $theme->display('Author');
$title = $theme->display( 'Name' );
$version = $theme->display( 'Version' );
$author = $theme->display( 'Author' );
$activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=" . urlencode( $template ) . "&amp;stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
$activate_link = wp_nonce_url( 'themes.php?action=activate&amp;template=' . urlencode( $template ) . '&amp;stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
$actions = array();
$actions = array();
$actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="'
. esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
@ -186,13 +194,14 @@ class WP_Themes_List_Table extends WP_List_Table {
. __( 'Live Preview' ) . '</a>';
}
if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) {
$actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( 'themes.php?action=delete&amp;stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet )
. '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) )
. "' );" . '">' . __( 'Delete' ) . '</a>';
}
/** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
$actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' );
$actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' );
/** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
$actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, 'all' );
@ -216,10 +225,10 @@ class WP_Themes_List_Table extends WP_List_Table {
<div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
<div class="action-links">
<ul>
<?php foreach ( $actions as $action ): ?>
<?php foreach ( $actions as $action ) : ?>
<li><?php echo $action; ?></li>
<?php endforeach; ?>
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li>
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e( 'Details' ); ?></a></li>
</ul>
<?php echo $delete_action; ?>
@ -227,17 +236,21 @@ class WP_Themes_List_Table extends WP_List_Table {
</div>
<div class="themedetaildiv hide-if-js">
<p><strong><?php _e('Version:'); ?></strong> <?php echo $version; ?></p>
<p><?php echo $theme->display('Description'); ?></p>
<?php if ( $theme->parent() ) {
printf( ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>',
<p><strong><?php _e( 'Version:' ); ?></strong> <?php echo $version; ?></p>
<p><?php echo $theme->display( 'Description' ); ?></p>
<?php
if ( $theme->parent() ) {
printf(
' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>',
__( 'https://codex.wordpress.org/Child_Themes' ),
$theme->parent()->display( 'Name' ) );
} ?>
$theme->parent()->display( 'Name' )
);
}
?>
</div>
</div>
<?php
<?php
endforeach;
}
@ -248,14 +261,16 @@ class WP_Themes_List_Table extends WP_List_Table {
public function search_theme( $theme ) {
// Search the features
foreach ( $this->features as $word ) {
if ( ! in_array( $word, $theme->get('Tags') ) )
if ( ! in_array( $word, $theme->get( 'Tags' ) ) ) {
return false;
}
}
// Match all phrases
foreach ( $this->search_terms as $word ) {
if ( in_array( $word, $theme->get('Tags') ) )
if ( in_array( $word, $theme->get( 'Tags' ) ) ) {
continue;
}
foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
// Don't mark up; Do translate.
@ -264,11 +279,13 @@ class WP_Themes_List_Table extends WP_List_Table {
}
}
if ( false !== stripos( $theme->get_stylesheet(), $word ) )
if ( false !== stripos( $theme->get_stylesheet(), $word ) ) {
continue;
}
if ( false !== stripos( $theme->get_template(), $word ) )
if ( false !== stripos( $theme->get_template(), $word ) ) {
continue;
}
return false;
}
@ -287,14 +304,15 @@ class WP_Themes_List_Table extends WP_List_Table {
$search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
$args = array(
'search' => $search_string,
'features' => $this->features,
'paged' => $this->get_pagenum(),
'search' => $search_string,
'features' => $this->features,
'paged' => $this->get_pagenum(),
'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1,
);
if ( is_array( $extra_args ) )
if ( is_array( $extra_args ) ) {
$args = array_merge( $args, $extra_args );
}
printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", wp_json_encode( $args ) );
parent::_js_vars();

View file

@ -25,25 +25,29 @@ class WP_Upgrader_Skin {
* @since 2.8.0
* @var string|bool|WP_Error
*/
public $result = false;
public $result = false;
public $options = array();
/**
*
* @param array $args
*/
public function __construct($args = array()) {
$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
$this->options = wp_parse_args($args, $defaults);
public function __construct( $args = array() ) {
$defaults = array(
'url' => '',
'nonce' => '',
'title' => '',
'context' => false,
);
$this->options = wp_parse_args( $args, $defaults );
}
/**
*
* @param WP_Upgrader $upgrader
*/
public function set_upgrader(&$upgrader) {
if ( is_object($upgrader) )
public function set_upgrader( &$upgrader ) {
if ( is_object( $upgrader ) ) {
$this->upgrader =& $upgrader;
}
$this->add_strings();
}
@ -84,8 +88,8 @@ class WP_Upgrader_Skin {
if ( ! $context ) {
$context = $this->options['context'];
}
if ( !empty($this->options['nonce']) ) {
$url = wp_nonce_url($url, $this->options['nonce']);
if ( ! empty( $this->options['nonce'] ) ) {
$url = wp_nonce_url( $url, $this->options['nonce'] );
}
$extra_fields = array();
@ -115,44 +119,46 @@ class WP_Upgrader_Skin {
}
/**
*
* @param string|WP_Error $errors
*/
public function error($errors) {
if ( ! $this->done_header )
public function error( $errors ) {
if ( ! $this->done_header ) {
$this->header();
if ( is_string($errors) ) {
$this->feedback($errors);
} elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
}
if ( is_string( $errors ) ) {
$this->feedback( $errors );
} elseif ( is_wp_error( $errors ) && $errors->has_errors() ) {
foreach ( $errors->get_error_messages() as $message ) {
if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
$this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
else
$this->feedback($message);
if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
$this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
} else {
$this->feedback( $message );
}
}
}
}
/**
*
* @param string $string
*/
public function feedback($string) {
if ( isset( $this->upgrader->strings[$string] ) )
$string = $this->upgrader->strings[$string];
public function feedback( $string ) {
if ( isset( $this->upgrader->strings[ $string ] ) ) {
$string = $this->upgrader->strings[ $string ];
}
if ( strpos($string, '%') !== false ) {
if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice($args, 1);
$args = array_splice( $args, 1 );
if ( $args ) {
$args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args );
$string = vsprintf($string, $args);
$args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args );
$string = vsprintf( $string, $args );
}
}
if ( empty($string) )
if ( empty( $string ) ) {
return;
show_message($string);
}
show_message( $string );
}
/**
@ -185,7 +191,7 @@ class WP_Upgrader_Skin {
} else {
echo '<script type="text/javascript">
(function( wp ) {
if ( wp && wp.updates.decrementCount ) {
if ( wp && wp.updates && wp.updates.decrementCount )
wp.updates.decrementCount( "' . $type . '" );
}
})( window.wp );

View file

@ -120,10 +120,11 @@ class WP_Upgrader {
* instance.
*/
public function __construct( $skin = null ) {
if ( null == $skin )
if ( null == $skin ) {
$this->skin = new WP_Upgrader_Skin();
else
} else {
$this->skin = $skin;
}
}
/**
@ -135,7 +136,7 @@ class WP_Upgrader {
* @since 2.8.0
*/
public function init() {
$this->skin->set_upgrader($this);
$this->skin->set_upgrader( $this );
$this->generic_strings();
}
@ -145,26 +146,26 @@ class WP_Upgrader {
* @since 2.8.0
*/
public function generic_strings() {
$this->strings['bad_request'] = __('Invalid data provided.');
$this->strings['fs_unavailable'] = __('Could not access filesystem.');
$this->strings['fs_error'] = __('Filesystem error.');
$this->strings['fs_no_root_dir'] = __('Unable to locate WordPress root directory.');
$this->strings['fs_no_content_dir'] = __('Unable to locate WordPress content directory (wp-content).');
$this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress plugin directory.');
$this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress theme directory.');
$this->strings['bad_request'] = __( 'Invalid data provided.' );
$this->strings['fs_unavailable'] = __( 'Could not access filesystem.' );
$this->strings['fs_error'] = __( 'Filesystem error.' );
$this->strings['fs_no_root_dir'] = __( 'Unable to locate WordPress root directory.' );
$this->strings['fs_no_content_dir'] = __( 'Unable to locate WordPress content directory (wp-content).' );
$this->strings['fs_no_plugins_dir'] = __( 'Unable to locate WordPress plugin directory.' );
$this->strings['fs_no_themes_dir'] = __( 'Unable to locate WordPress theme directory.' );
/* translators: %s: directory name */
$this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).');
$this->strings['fs_no_folder'] = __( 'Unable to locate needed folder (%s).' );
$this->strings['download_failed'] = __('Download failed.');
$this->strings['installing_package'] = __('Installing the latest version&#8230;');
$this->strings['no_files'] = __('The package contains no files.');
$this->strings['folder_exists'] = __('Destination folder already exists.');
$this->strings['mkdir_failed'] = __('Could not create directory.');
$this->strings['incompatible_archive'] = __('The package could not be installed.');
$this->strings['files_not_writable'] = __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' );
$this->strings['download_failed'] = __( 'Download failed.' );
$this->strings['installing_package'] = __( 'Installing the latest version&#8230;' );
$this->strings['no_files'] = __( 'The package contains no files.' );
$this->strings['folder_exists'] = __( 'Destination folder already exists.' );
$this->strings['mkdir_failed'] = __( 'Could not create directory.' );
$this->strings['incompatible_archive'] = __( 'The package could not be installed.' );
$this->strings['files_not_writable'] = __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' );
$this->strings['maintenance_start'] = __('Enabling Maintenance mode&#8230;');
$this->strings['maintenance_end'] = __('Disabling Maintenance mode&#8230;');
$this->strings['maintenance_start'] = __( 'Enabling Maintenance mode&#8230;' );
$this->strings['maintenance_end'] = __( 'Disabling Maintenance mode&#8230;' );
}
/**
@ -172,7 +173,7 @@ class WP_Upgrader {
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param array $directories Optional. A list of directories. If any of these do
* not exist, a WP_Error object will be returned.
@ -190,40 +191,48 @@ class WP_Upgrader {
if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) {
$error = true;
if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) {
$error = $wp_filesystem->errors;
}
// Failed to connect, Error and request again
$this->skin->request_filesystem_credentials( $error, $directories[0], $allow_relaxed_file_ownership );
return false;
}
if ( ! is_object($wp_filesystem) )
return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
if ( ! is_object( $wp_filesystem ) ) {
return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] );
}
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors );
}
foreach ( (array)$directories as $dir ) {
foreach ( (array) $directories as $dir ) {
switch ( $dir ) {
case ABSPATH:
if ( ! $wp_filesystem->abspath() )
return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
if ( ! $wp_filesystem->abspath() ) {
return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir'] );
}
break;
case WP_CONTENT_DIR:
if ( ! $wp_filesystem->wp_content_dir() )
return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
if ( ! $wp_filesystem->wp_content_dir() ) {
return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
}
break;
case WP_PLUGIN_DIR:
if ( ! $wp_filesystem->wp_plugins_dir() )
return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
if ( ! $wp_filesystem->wp_plugins_dir() ) {
return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir'] );
}
break;
case get_theme_root():
if ( ! $wp_filesystem->wp_themes_dir() )
return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
if ( ! $wp_filesystem->wp_themes_dir() ) {
return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir'] );
}
break;
default:
if ( ! $wp_filesystem->find_folder($dir) )
if ( ! $wp_filesystem->find_folder( $dir ) ) {
return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) );
}
break;
}
}
@ -252,21 +261,25 @@ class WP_Upgrader {
* @param WP_Upgrader $this The WP_Upgrader instance.
*/
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this );
if ( false !== $reply )
if ( false !== $reply ) {
return $reply;
}
if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote?
if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { //Local file or remote?
return $package; //must be a local file..
}
if ( empty($package) )
return new WP_Error('no_package', $this->strings['no_package']);
if ( empty( $package ) ) {
return new WP_Error( 'no_package', $this->strings['no_package'] );
}
$this->skin->feedback('downloading_package', $package);
$this->skin->feedback( 'downloading_package', $package );
$download_file = download_url($package);
$download_file = download_url( $package );
if ( is_wp_error($download_file) )
return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
if ( is_wp_error( $download_file ) ) {
return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() );
}
return $download_file;
}
@ -276,7 +289,7 @@ class WP_Upgrader {
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $package Full path to the package file.
* @param bool $delete_package Optional. Whether to delete the package file after attempting
@ -286,33 +299,36 @@ class WP_Upgrader {
public function unpack_package( $package, $delete_package = true ) {
global $wp_filesystem;
$this->skin->feedback('unpack_package');
$this->skin->feedback( 'unpack_package' );
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
//Clean up contents of upgrade directory beforehand.
$upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
if ( !empty($upgrade_files) ) {
foreach ( $upgrade_files as $file )
$wp_filesystem->delete($upgrade_folder . $file['name'], true);
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
if ( ! empty( $upgrade_files ) ) {
foreach ( $upgrade_files as $file ) {
$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
}
}
// We need a working directory - Strip off any .tmp or .zip suffixes
$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
// Clean up working directory
if ( $wp_filesystem->is_dir($working_dir) )
$wp_filesystem->delete($working_dir, true);
if ( $wp_filesystem->is_dir( $working_dir ) ) {
$wp_filesystem->delete( $working_dir, true );
}
// Unzip package to working directory
$result = unzip_file( $package, $working_dir );
// Once extracted, delete the package if required.
if ( $delete_package )
unlink($package);
if ( $delete_package ) {
unlink( $package );
}
if ( is_wp_error($result) ) {
$wp_filesystem->delete($working_dir, true);
if ( is_wp_error( $result ) ) {
$wp_filesystem->delete( $working_dir, true );
if ( 'incompatible_archive' == $result->get_error_code() ) {
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
}
@ -355,7 +371,7 @@ class WP_Upgrader {
*
* @since 4.3.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $remote_destination The location on the remote filesystem to be cleared
* @return bool|WP_Error True upon success, WP_Error on failure.
@ -407,7 +423,7 @@ class WP_Upgrader {
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global array $wp_theme_directories
*
* @param array|string $args {
@ -432,19 +448,19 @@ class WP_Upgrader {
global $wp_filesystem, $wp_theme_directories;
$defaults = array(
'source' => '', // Please always pass this
'destination' => '', // and this
'clear_destination' => false,
'clear_working' => false,
'source' => '', // Please always pass this
'destination' => '', // and this
'clear_destination' => false,
'clear_working' => false,
'abort_if_destination_exists' => true,
'hook_extra' => array()
'hook_extra' => array(),
);
$args = wp_parse_args($args, $defaults);
$args = wp_parse_args( $args, $defaults );
// These were previously extract()'d.
$source = $args['source'];
$destination = $args['destination'];
$source = $args['source'];
$destination = $args['destination'];
$clear_destination = $args['clear_destination'];
@set_time_limit( 300 );
@ -473,10 +489,10 @@ class WP_Upgrader {
}
//Retain the Original source and destinations
$remote_source = $args['source'];
$remote_source = $args['source'];
$local_destination = $destination;
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
$remote_destination = $wp_filesystem->find_folder( $local_destination );
//Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
@ -525,12 +541,12 @@ class WP_Upgrader {
if ( in_array( $destination, $protected_directories ) ) {
$remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
$destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
$destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
}
if ( $clear_destination ) {
// We're going to clear the destination if there's something there.
$this->skin->feedback('remove_old');
$this->skin->feedback( 'remove_old' );
$removed = $this->clear_destination( $remote_destination );
@ -549,13 +565,13 @@ class WP_Upgrader {
if ( is_wp_error( $removed ) ) {
return $removed;
}
} elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists($remote_destination) ) {
} elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists( $remote_destination ) ) {
//If we're not clearing the destination folder and something exists there already, Bail.
//But first check to see if there are actually any files in the folder.
$_files = $wp_filesystem->dirlist($remote_destination);
if ( ! empty($_files) ) {
$wp_filesystem->delete($remote_source, true); //Clear out the source files.
return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
$_files = $wp_filesystem->dirlist( $remote_destination );
if ( ! empty( $_files ) ) {
$wp_filesystem->delete( $remote_source, true ); //Clear out the source files.
return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination );
}
}
@ -566,8 +582,8 @@ class WP_Upgrader {
}
}
// Copy new version of item into place.
$result = copy_dir($source, $remote_destination);
if ( is_wp_error($result) ) {
$result = copy_dir( $source, $remote_destination );
if ( is_wp_error( $result ) ) {
if ( $args['clear_working'] ) {
$wp_filesystem->delete( $remote_source, true );
}
@ -579,7 +595,7 @@ class WP_Upgrader {
$wp_filesystem->delete( $remote_source, true );
}
$destination_name = basename( str_replace($local_destination, '', $destination) );
$destination_name = basename( str_replace( $local_destination, '', $destination ) );
if ( '.' == $destination_name ) {
$destination_name = '';
}
@ -597,7 +613,7 @@ class WP_Upgrader {
*/
$res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
if ( is_wp_error($res) ) {
if ( is_wp_error( $res ) ) {
$this->result = $res;
return $res;
}
@ -642,13 +658,13 @@ class WP_Upgrader {
public function run( $options ) {
$defaults = array(
'package' => '', // Please always pass this.
'destination' => '', // And this
'clear_destination' => false,
'package' => '', // Please always pass this.
'destination' => '', // And this
'clear_destination' => false,
'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
'clear_working' => true,
'is_multi' => false,
'hook_extra' => array() // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
'clear_working' => true,
'is_multi' => false,
'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
);
$options = wp_parse_args( $options, $defaults );
@ -675,7 +691,7 @@ class WP_Upgrader {
* @type string $action Type of action. Default 'update'.
* @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'.
* @type bool $bulk Whether the update process is a bulk update. Default true.
* @type string $plugin The base plugin path from the plugins directory.
* @type string $plugin Path to the plugin file relative to the plugins directory.
* @type string $theme The stylesheet or template name of the theme.
* @type string $language_update_type The language pack update type. Accepts 'plugin', 'theme',
* or 'core'.
@ -701,8 +717,8 @@ class WP_Upgrader {
$this->skin->before();
if ( is_wp_error($res) ) {
$this->skin->error($res);
if ( is_wp_error( $res ) ) {
$this->skin->error( $res );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
@ -715,8 +731,8 @@ class WP_Upgrader {
* of the file if the package is a local file)
*/
$download = $this->download_package( $options['package'] );
if ( is_wp_error($download) ) {
$this->skin->error($download);
if ( is_wp_error( $download ) ) {
$this->skin->error( $download );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
@ -728,8 +744,8 @@ class WP_Upgrader {
// Unzips the file into a temporary directory.
$working_dir = $this->unpack_package( $download, $delete_package );
if ( is_wp_error($working_dir) ) {
$this->skin->error($working_dir);
if ( is_wp_error( $working_dir ) ) {
$this->skin->error( $working_dir );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
@ -738,22 +754,24 @@ class WP_Upgrader {
}
// With the given options, this installs it to the destination directory.
$result = $this->install_package( array(
'source' => $working_dir,
'destination' => $options['destination'],
'clear_destination' => $options['clear_destination'],
'abort_if_destination_exists' => $options['abort_if_destination_exists'],
'clear_working' => $options['clear_working'],
'hook_extra' => $options['hook_extra']
) );
$result = $this->install_package(
array(
'source' => $working_dir,
'destination' => $options['destination'],
'clear_destination' => $options['clear_destination'],
'abort_if_destination_exists' => $options['abort_if_destination_exists'],
'clear_working' => $options['clear_working'],
'hook_extra' => $options['hook_extra'],
)
);
$this->skin->set_result($result);
if ( is_wp_error($result) ) {
$this->skin->error($result);
$this->skin->feedback('process_failed');
$this->skin->set_result( $result );
if ( is_wp_error( $result ) ) {
$this->skin->error( $result );
$this->skin->feedback( 'process_failed' );
} else {
// Installation succeeded.
$this->skin->feedback('process_success');
$this->skin->feedback( 'process_success' );
}
$this->skin->after();
@ -813,28 +831,27 @@ class WP_Upgrader {
global $wp_filesystem;
$file = $wp_filesystem->abspath() . '.maintenance';
if ( $enable ) {
$this->skin->feedback('maintenance_start');
$this->skin->feedback( 'maintenance_start' );
// Create maintenance file to signal that we are upgrading
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
$wp_filesystem->delete($file);
$wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
$wp_filesystem->delete( $file );
$wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE );
} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
$this->skin->feedback('maintenance_end');
$wp_filesystem->delete($file);
$this->skin->feedback( 'maintenance_end' );
$wp_filesystem->delete( $file );
}
}
/**
* Creates a lock using WordPress options.
*
* @since 4.5.0
* @static
*
* @param string $lock_name The name of this unique lock.
* @param int $release_timeout Optional. The duration in seconds to respect an existing lock.
* Creates a lock using WordPress options.
*
* @since 4.5.0
*
* @param string $lock_name The name of this unique lock.
* @param int $release_timeout Optional. The duration in seconds to respect an existing lock.
* Default: 1 hour.
* @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise.
*/
* @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise.
*/
public static function create_lock( $lock_name, $release_timeout = null ) {
global $wpdb;
if ( ! $release_timeout ) {
@ -871,16 +888,15 @@ class WP_Upgrader {
}
/**
* Releases an upgrader lock.
*
* @since 4.5.0
* @static
* Releases an upgrader lock.
*
* @since 4.5.0
*
* @see WP_Upgrader::create_lock()
*
* @param string $lock_name The name of this unique lock.
*
* @param string $lock_name The name of this unique lock.
* @return bool True if the lock was successfully released. False on failure.
*/
*/
public static function release_lock( $lock_name ) {
return delete_option( $lock_name . '.lock' );
}

View file

@ -43,30 +43,34 @@ class WP_Users_List_Table extends WP_List_Table {
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
parent::__construct( array(
'singular' => 'user',
'plural' => 'users',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
parent::__construct(
array(
'singular' => 'user',
'plural' => 'users',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
$this->is_site_users = 'site-users-network' === $this->screen->id;
if ( $this->is_site_users )
if ( $this->is_site_users ) {
$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
}
}
/**
* Check the current user's permissions.
*
* @since 3.1.0
* @since 3.1.0
*
* @return bool
*/
public function ajax_user_can() {
if ( $this->is_site_users )
if ( $this->is_site_users ) {
return current_user_can( 'manage_sites' );
else
} else {
return current_user_can( 'list_users' );
}
}
/**
@ -84,40 +88,44 @@ class WP_Users_List_Table extends WP_List_Table {
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
$per_page = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
$per_page = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
$users_per_page = $this->get_items_per_page( $per_page );
$paged = $this->get_pagenum();
if ( 'none' === $role ) {
$args = array(
'number' => $users_per_page,
'offset' => ( $paged-1 ) * $users_per_page,
'number' => $users_per_page,
'offset' => ( $paged - 1 ) * $users_per_page,
'include' => wp_get_users_with_no_role( $this->site_id ),
'search' => $usersearch,
'fields' => 'all_with_meta'
'search' => $usersearch,
'fields' => 'all_with_meta',
);
} else {
$args = array(
'number' => $users_per_page,
'offset' => ( $paged-1 ) * $users_per_page,
'role' => $role,
'offset' => ( $paged - 1 ) * $users_per_page,
'role' => $role,
'search' => $usersearch,
'fields' => 'all_with_meta'
'fields' => 'all_with_meta',
);
}
if ( '' !== $args['search'] )
if ( '' !== $args['search'] ) {
$args['search'] = '*' . $args['search'] . '*';
}
if ( $this->is_site_users )
if ( $this->is_site_users ) {
$args['blog_id'] = $this->site_id;
}
if ( isset( $_REQUEST['orderby'] ) )
if ( isset( $_REQUEST['orderby'] ) ) {
$args['orderby'] = $_REQUEST['orderby'];
}
if ( isset( $_REQUEST['order'] ) )
if ( isset( $_REQUEST['order'] ) ) {
$args['order'] = $_REQUEST['order'];
}
/**
* Filters the query arguments used to retrieve users for the current users list table.
@ -134,10 +142,12 @@ class WP_Users_List_Table extends WP_List_Table {
$this->items = $wp_user_search->get_results();
$this->set_pagination_args( array(
'total_items' => $wp_user_search->get_total(),
'per_page' => $users_per_page,
) );
$this->set_pagination_args(
array(
'total_items' => $wp_user_search->get_total(),
'per_page' => $users_per_page,
)
);
}
/**
@ -173,21 +183,22 @@ class WP_Users_List_Table extends WP_List_Table {
$users_of_blog = count_users( 'time', $this->site_id );
restore_current_blog();
} else {
$url = 'users.php';
$url = 'users.php';
$users_of_blog = count_users();
}
$total_users = $users_of_blog['total_users'];
$avail_roles =& $users_of_blog['avail_roles'];
unset($users_of_blog);
unset( $users_of_blog );
$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
$role_links = array();
$role_links = array();
$role_links['all'] = "<a href='$url'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
foreach ( $wp_roles->get_names() as $this_role => $name ) {
if ( !isset($avail_roles[$this_role]) )
if ( ! isset( $avail_roles[ $this_role ] ) ) {
continue;
}
$current_link_attributes = '';
@ -197,11 +208,11 @@ class WP_Users_List_Table extends WP_List_Table {
$name = translate_user_role( $name );
/* translators: User role name with count */
$name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) );
$role_links[$this_role] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
$name = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
$role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
}
if ( ! empty( $avail_roles['none' ] ) ) {
if ( ! empty( $avail_roles['none'] ) ) {
$current_link_attributes = '';
@ -211,7 +222,7 @@ class WP_Users_List_Table extends WP_List_Table {
$name = __( 'No role' );
/* translators: User role name with count */
$name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles['none' ] ) );
$name = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles['none'] ) );
$role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$current_link_attributes>$name</a>";
}
@ -230,11 +241,13 @@ class WP_Users_List_Table extends WP_List_Table {
$actions = array();
if ( is_multisite() ) {
if ( current_user_can( 'remove_users' ) )
if ( current_user_can( 'remove_users' ) ) {
$actions['remove'] = __( 'Remove' );
}
} else {
if ( current_user_can( 'delete_users' ) )
if ( current_user_can( 'delete_users' ) ) {
$actions['delete'] = __( 'Delete' );
}
}
return $actions;
@ -249,17 +262,17 @@ class WP_Users_List_Table extends WP_List_Table {
* or below the table ("bottom").
*/
protected function extra_tablenav( $which ) {
$id = 'bottom' === $which ? 'new_role2' : 'new_role';
$id = 'bottom' === $which ? 'new_role2' : 'new_role';
$button_id = 'bottom' === $which ? 'changeit2' : 'changeit';
?>
?>
<div class="alignleft actions">
<?php if ( current_user_can( 'promote_users' ) && $this->has_items() ) : ?>
<label class="screen-reader-text" for="<?php echo $id ?>"><?php _e( 'Change role to&hellip;' ) ?></label>
<select name="<?php echo $id ?>" id="<?php echo $id ?>">
<option value=""><?php _e( 'Change role to&hellip;' ) ?></option>
<label class="screen-reader-text" for="<?php echo $id; ?>"><?php _e( 'Change role to&hellip;' ); ?></label>
<select name="<?php echo $id; ?>" id="<?php echo $id; ?>">
<option value=""><?php _e( 'Change role to&hellip;' ); ?></option>
<?php wp_dropdown_roles(); ?>
</select>
<?php
<?php
submit_button( __( 'Change' ), '', $button_id, false );
endif;
@ -273,9 +286,9 @@ class WP_Users_List_Table extends WP_List_Table {
* @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
*/
do_action( 'restrict_manage_users', $which );
?>
?>
</div>
<?php
<?php
/**
* Fires immediately following the closing "actions" div in the tablenav for the users
* list table.
@ -321,11 +334,12 @@ class WP_Users_List_Table extends WP_List_Table {
'name' => __( 'Name' ),
'email' => __( 'Email' ),
'role' => __( 'Role' ),
'posts' => __( 'Posts' )
'posts' => __( 'Posts' ),
);
if ( $this->is_site_users )
if ( $this->is_site_users ) {
unset( $c['posts'] );
}
return $c;
}
@ -353,8 +367,9 @@ class WP_Users_List_Table extends WP_List_Table {
*/
public function display_rows() {
// Query the post counts for this page
if ( ! $this->is_site_users )
if ( ! $this->is_site_users ) {
$post_counts = count_many_users_posts( array_keys( $this->items ) );
}
foreach ( $this->items as $userid => $user_object ) {
echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
@ -380,18 +395,19 @@ class WP_Users_List_Table extends WP_List_Table {
$user_object = get_userdata( (int) $user_object );
}
$user_object->filter = 'display';
$email = $user_object->user_email;
$email = $user_object->user_email;
if ( $this->is_site_users )
if ( $this->is_site_users ) {
$url = "site-users.php?id={$this->site_id}&amp;";
else
} else {
$url = 'users.php?';
}
$user_roles = $this->get_role_list( $user_object );
// Set up the hover actions for this user
$actions = array();
$checkbox = '';
$actions = array();
$checkbox = '';
$super_admin = '';
if ( is_multisite() && current_user_can( 'manage_network_users' ) ) {
@ -405,17 +421,19 @@ class WP_Users_List_Table extends WP_List_Table {
// Set up the user editing link
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) );
if ( current_user_can( 'edit_user', $user_object->ID ) ) {
$edit = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />";
if ( current_user_can( 'edit_user', $user_object->ID ) ) {
$edit = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />";
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
} else {
$edit = "<strong>{$user_object->user_login}{$super_admin}</strong><br />";
}
if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) )
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>";
if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) )
$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
if ( ! is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) {
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . '</a>';
}
if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) ) {
$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . '</a>';
}
// Add a link to the user's author archive, if not empty.
$author_posts_url = get_author_posts_url( $user_object->ID );
@ -434,10 +452,10 @@ class WP_Users_List_Table extends WP_List_Table {
*
* @since 2.8.0
*
* @param array $actions An array of action links to be displayed.
* Default 'Edit', 'Delete' for single site, and
* 'Edit', 'Remove' for Multisite.
* @param WP_User $user_object WP_User object for the currently-listed user.
* @param string[] $actions An array of action links to be displayed.
* Default 'Edit', 'Delete' for single site, and
* 'Edit', 'Remove' for Multisite.
* @param WP_User $user_object WP_User object for the currently listed user.
*/
$actions = apply_filters( 'user_row_actions', $actions, $user_object );
@ -528,7 +546,7 @@ class WP_Users_List_Table extends WP_List_Table {
if ( $primary === $column_name ) {
$r .= $this->row_actions( $actions );
}
$r .= "</td>";
$r .= '</td>';
}
}
$r .= '</tr>';
@ -553,7 +571,7 @@ class WP_Users_List_Table extends WP_List_Table {
* @since 4.4.0
*
* @param WP_User $user_object The WP_User object.
* @return array An array of user roles.
* @return string[] An array of user roles.
*/
protected function get_role_list( $user_object ) {
$wp_roles = wp_roles();
@ -575,8 +593,8 @@ class WP_Users_List_Table extends WP_List_Table {
*
* @since 4.4.0
*
* @param array $role_list An array of user roles.
* @param WP_User $user_object A WP_User object.
* @param string[] $role_list An array of user roles.
* @param WP_User $user_object A WP_User object.
*/
return apply_filters( 'get_role_list', $role_list, $user_object );
}

View file

@ -32,11 +32,14 @@ function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
$date_field = 'comment_date_gmt';
}
return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments
return $wpdb->get_var(
$wpdb->prepare(
"SELECT comment_post_ID FROM $wpdb->comments
WHERE comment_author = %s AND $date_field = %s",
stripslashes( $comment_author ),
stripslashes( $comment_date )
) );
)
);
}
/**
@ -45,40 +48,47 @@ function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
* @since 2.0.0
*/
function edit_comment() {
if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) )
wp_die ( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) {
wp_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
}
if ( isset( $_POST['newcomment_author'] ) )
if ( isset( $_POST['newcomment_author'] ) ) {
$_POST['comment_author'] = $_POST['newcomment_author'];
if ( isset( $_POST['newcomment_author_email'] ) )
}
if ( isset( $_POST['newcomment_author_email'] ) ) {
$_POST['comment_author_email'] = $_POST['newcomment_author_email'];
if ( isset( $_POST['newcomment_author_url'] ) )
}
if ( isset( $_POST['newcomment_author_url'] ) ) {
$_POST['comment_author_url'] = $_POST['newcomment_author_url'];
if ( isset( $_POST['comment_status'] ) )
}
if ( isset( $_POST['comment_status'] ) ) {
$_POST['comment_approved'] = $_POST['comment_status'];
if ( isset( $_POST['content'] ) )
}
if ( isset( $_POST['content'] ) ) {
$_POST['comment_content'] = $_POST['content'];
if ( isset( $_POST['comment_ID'] ) )
}
if ( isset( $_POST['comment_ID'] ) ) {
$_POST['comment_ID'] = (int) $_POST['comment_ID'];
}
foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
if ( ! empty( $_POST[ 'hidden_' . $timeunit ] ) && $_POST[ 'hidden_' . $timeunit ] != $_POST[ $timeunit ] ) {
$_POST['edit_date'] = '1';
break;
}
}
if ( !empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa'];
$mm = $_POST['mm'];
$jj = $_POST['jj'];
$hh = $_POST['hh'];
$mn = $_POST['mn'];
$ss = $_POST['ss'];
$jj = ($jj > 31 ) ? 31 : $jj;
$hh = ($hh > 23 ) ? $hh -24 : $hh;
$mn = ($mn > 59 ) ? $mn -60 : $mn;
$ss = ($ss > 59 ) ? $ss -60 : $ss;
if ( ! empty( $_POST['edit_date'] ) ) {
$aa = $_POST['aa'];
$mm = $_POST['mm'];
$jj = $_POST['jj'];
$hh = $_POST['hh'];
$mn = $_POST['mn'];
$ss = $_POST['ss'];
$jj = ( $jj > 31 ) ? 31 : $jj;
$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
$ss = ( $ss > 59 ) ? $ss - 60 : $ss;
$_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
}
@ -94,10 +104,11 @@ function edit_comment() {
* @return WP_Comment|false Comment if found. False on failure.
*/
function get_comment_to_edit( $id ) {
if ( !$comment = get_comment($id) )
if ( ! $comment = get_comment( $id ) ) {
return false;
}
$comment->comment_ID = (int) $comment->comment_ID;
$comment->comment_ID = (int) $comment->comment_ID;
$comment->comment_post_ID = (int) $comment->comment_post_ID;
$comment->comment_content = format_to_edit( $comment->comment_content );
@ -110,10 +121,10 @@ function get_comment_to_edit( $id ) {
*/
$comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
$comment->comment_author = format_to_edit( $comment->comment_author );
$comment->comment_author = format_to_edit( $comment->comment_author );
$comment->comment_author_email = format_to_edit( $comment->comment_author_email );
$comment->comment_author_url = format_to_edit( $comment->comment_author_url );
$comment->comment_author_url = esc_url($comment->comment_author_url);
$comment->comment_author_url = format_to_edit( $comment->comment_author_url );
$comment->comment_author_url = esc_url( $comment->comment_author_url );
return $comment;
}
@ -132,33 +143,37 @@ function get_pending_comments_num( $post_id ) {
global $wpdb;
$single = false;
if ( !is_array($post_id) ) {
if ( ! is_array( $post_id ) ) {
$post_id_array = (array) $post_id;
$single = true;
$single = true;
} else {
$post_id_array = $post_id;
}
$post_id_array = array_map('intval', $post_id_array);
$post_id_in = "'" . implode("', '", $post_id_array) . "'";
$post_id_array = array_map( 'intval', $post_id_array );
$post_id_in = "'" . implode( "', '", $post_id_array ) . "'";
$pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A );
if ( $single ) {
if ( empty($pending) )
if ( empty( $pending ) ) {
return 0;
else
return absint($pending[0]['num_comments']);
} else {
return absint( $pending[0]['num_comments'] );
}
}
$pending_keyed = array();
// Default to zero pending for all posts in request
foreach ( $post_id_array as $id )
$pending_keyed[$id] = 0;
foreach ( $post_id_array as $id ) {
$pending_keyed[ $id ] = 0;
}
if ( !empty($pending) )
foreach ( $pending as $pend )
$pending_keyed[$pend['comment_post_ID']] = absint($pend['num_comments']);
if ( ! empty( $pending ) ) {
foreach ( $pending as $pend ) {
$pending_keyed[ $pend['comment_post_ID'] ] = absint( $pend['num_comments'] );
}
}
return $pending_keyed;
}
@ -180,8 +195,9 @@ function floated_admin_avatar( $name ) {
* @since 2.7.0
*/
function enqueue_comment_hotkeys_js() {
if ( 'true' == get_user_option( 'comment_shortcuts' ) )
if ( 'true' == get_user_option( 'comment_shortcuts' ) ) {
wp_enqueue_script( 'jquery-table-hotkeys' );
}
}
/**
@ -193,4 +209,4 @@ function comment_footer_die( $msg ) {
echo "<div class='wrap'><p>$msg</p></div>";
include( ABSPATH . 'wp-admin/admin-footer.php' );
die;
}
}

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,7 @@ function wp_credits() {
|| false !== strpos( $wp_version, '-' )
|| ( isset( $results['data']['version'] ) && strpos( $wp_version, $results['data']['version'] ) !== 0 )
) {
$url = "http://api.wordpress.org/core/credits/1.1/?version={$wp_version}&locale={$locale}";
$url = "http://api.wordpress.org/core/credits/1.1/?version={$wp_version}&locale={$locale}";
$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );
if ( wp_http_supports( array( 'ssl' ) ) ) {
@ -35,13 +35,15 @@ function wp_credits() {
$response = wp_remote_get( $url, $options );
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
return false;
}
$results = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! is_array( $results ) )
if ( ! is_array( $results ) ) {
return false;
}
set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
}

File diff suppressed because it is too large Load diff

View file

@ -55,4 +55,4 @@ if ( isset( $_REQUEST['message'] ) && ( $msg = (int) $_REQUEST['message'] ) ) {
} elseif ( ! isset( $messages[ $taxonomy ] ) && isset( $messages['_item'][ $msg ] ) ) {
$message = $messages['_item'][ $msg ];
}
}
}

View file

@ -56,10 +56,15 @@ define( 'WXR_VERSION', '1.2' );
function export_wp( $args = array() ) {
global $wpdb, $post;
$defaults = array( 'content' => 'all', 'author' => false, 'category' => false,
'start_date' => false, 'end_date' => false, 'status' => false,
$defaults = array(
'content' => 'all',
'author' => false,
'category' => false,
'start_date' => false,
'end_date' => false,
'status' => false,
);
$args = wp_parse_args( $args, $defaults );
$args = wp_parse_args( $args, $defaults );
/**
* Fires at the beginning of an export, before any headers are sent.
@ -74,8 +79,8 @@ function export_wp( $args = array() ) {
if ( ! empty( $sitename ) ) {
$sitename .= '.';
}
$date = date( 'Y-m-d' );
$wp_filename = $sitename . 'wordpress.' . $date . '.xml';
$date = date( 'Y-m-d' );
$wp_filename = $sitename . 'WordPress.' . $date . '.xml';
/**
* Filters the export filename.
*
@ -93,38 +98,43 @@ function export_wp( $args = array() ) {
if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) {
$ptype = get_post_type_object( $args['content'] );
if ( ! $ptype->can_export )
if ( ! $ptype->can_export ) {
$args['content'] = 'post';
}
$where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );
} else {
$post_types = get_post_types( array( 'can_export' => true ) );
$esses = array_fill( 0, count($post_types), '%s' );
$where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types );
$esses = array_fill( 0, count( $post_types ), '%s' );
$where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types );
}
if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) )
if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] );
else
} else {
$where .= " AND {$wpdb->posts}.post_status != 'auto-draft'";
}
$join = '';
if ( $args['category'] && 'post' == $args['content'] ) {
if ( $term = term_exists( $args['category'], 'category' ) ) {
$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
$where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] );
}
}
if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) {
if ( $args['author'] )
if ( $args['author'] ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
}
if ( $args['start_date'] )
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) );
if ( $args['start_date'] ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime( $args['start_date'] ) ) );
}
if ( $args['end_date'] )
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) );
if ( $args['end_date'] ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime( '+1 month', strtotime( $args['end_date'] ) ) ) );
}
}
// Grab a snapshot of post IDs, just in case it changes during the export.
@ -136,30 +146,32 @@ function export_wp( $args = array() ) {
*/
$cats = $tags = $terms = array();
if ( isset( $term ) && $term ) {
$cat = get_term( $term['term_id'], 'category' );
$cat = get_term( $term['term_id'], 'category' );
$cats = array( $cat->term_id => $cat );
unset( $term, $cat );
} elseif ( 'all' == $args['content'] ) {
$categories = (array) get_categories( array( 'get' => 'all' ) );
$tags = (array) get_tags( array( 'get' => 'all' ) );
$tags = (array) get_tags( array( 'get' => 'all' ) );
$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
$custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
$custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
// Put categories in order with no child going before its parent.
while ( $cat = array_shift( $categories ) ) {
if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
$cats[$cat->term_id] = $cat;
else
if ( $cat->parent == 0 || isset( $cats[ $cat->parent ] ) ) {
$cats[ $cat->term_id ] = $cat;
} else {
$categories[] = $cat;
}
}
// Put terms in order with no child going before its parent.
while ( $t = array_shift( $custom_terms ) ) {
if ( $t->parent == 0 || isset( $terms[$t->parent] ) )
$terms[$t->term_id] = $t;
else
if ( $t->parent == 0 || isset( $terms[ $t->parent ] ) ) {
$terms[ $t->term_id ] = $t;
} else {
$custom_terms[] = $t;
}
}
unset( $categories, $custom_taxonomies, $custom_terms );
@ -191,12 +203,13 @@ function export_wp( $args = array() ) {
* @return string Site URL.
*/
function wxr_site_url() {
// Multisite: the base URL.
if ( is_multisite() )
if ( is_multisite() ) {
// Multisite: the base URL.
return network_home_url();
// WordPress (single site): the blog URL.
else
} else {
// WordPress (single site): the blog URL.
return get_bloginfo_rss( 'url' );
}
}
/**
@ -207,8 +220,9 @@ function export_wp( $args = array() ) {
* @param object $category Category Object
*/
function wxr_cat_name( $category ) {
if ( empty( $category->name ) )
if ( empty( $category->name ) ) {
return;
}
echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n";
}
@ -221,8 +235,9 @@ function export_wp( $args = array() ) {
* @param object $category Category Object
*/
function wxr_category_description( $category ) {
if ( empty( $category->description ) )
if ( empty( $category->description ) ) {
return;
}
echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n";
}
@ -235,8 +250,9 @@ function export_wp( $args = array() ) {
* @param object $tag Tag Object
*/
function wxr_tag_name( $tag ) {
if ( empty( $tag->name ) )
if ( empty( $tag->name ) ) {
return;
}
echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n";
}
@ -249,8 +265,9 @@ function export_wp( $args = array() ) {
* @param object $tag Tag Object
*/
function wxr_tag_description( $tag ) {
if ( empty( $tag->description ) )
if ( empty( $tag->description ) ) {
return;
}
echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n";
}
@ -263,8 +280,9 @@ function export_wp( $args = array() ) {
* @param object $term Term Object
*/
function wxr_term_name( $term ) {
if ( empty( $term->name ) )
if ( empty( $term->name ) ) {
return;
}
echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n";
}
@ -277,8 +295,9 @@ function export_wp( $args = array() ) {
* @param object $term Term Object
*/
function wxr_term_description( $term ) {
if ( empty( $term->description ) )
if ( empty( $term->description ) ) {
return;
}
echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n";
}
@ -321,22 +340,23 @@ function export_wp( $args = array() ) {
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param array $post_ids Array of post IDs to filter the query by. Optional.
* @param int[] $post_ids Optional. Array of post IDs to filter the query by.
*/
function wxr_authors_list( array $post_ids = null ) {
global $wpdb;
if ( !empty( $post_ids ) ) {
if ( ! empty( $post_ids ) ) {
$post_ids = array_map( 'absint', $post_ids );
$and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
$and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
} else {
$and = '';
}
$authors = array();
$results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
foreach ( (array) $results as $result )
foreach ( (array) $results as $result ) {
$authors[] = get_userdata( $result->post_author );
}
$authors = array_filter( $authors );
@ -359,8 +379,9 @@ function export_wp( $args = array() ) {
*/
function wxr_nav_menu_terms() {
$nav_menus = wp_get_nav_menus();
if ( empty( $nav_menus ) || ! is_array( $nav_menus ) )
if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) {
return;
}
foreach ( $nav_menus as $menu ) {
echo "\t<wp:term>";
@ -381,8 +402,9 @@ function export_wp( $args = array() ) {
$post = get_post();
$taxonomies = get_object_taxonomies( $post->post_type );
if ( empty( $taxonomies ) )
if ( empty( $taxonomies ) ) {
return;
}
$terms = wp_get_object_terms( $post->ID, $taxonomies );
foreach ( (array) $terms as $term ) {
@ -391,19 +413,19 @@ function export_wp( $args = array() ) {
}
/**
*
* @param bool $return_me
* @param string $meta_key
* @return bool
*/
function wxr_filter_postmeta( $return_me, $meta_key ) {
if ( '_edit_lock' == $meta_key )
if ( '_edit_lock' == $meta_key ) {
$return_me = true;
}
return $return_me;
}
add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 );
echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
echo '<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . "\" ?>\n";
?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
@ -423,7 +445,7 @@ function export_wp( $args = array() ) {
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!-- contained in this file into your site. -->
<?php the_generator( 'export' ); ?>
<?php the_generator( 'export' ); ?>
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
@ -442,94 +464,110 @@ function export_wp( $args = array() ) {
<wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
<wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
<?php wxr_authors_list( $post_ids ); ?>
<?php wxr_authors_list( $post_ids ); ?>
<?php foreach ( $cats as $c ) : ?>
<?php foreach ( $cats as $c ) : ?>
<wp:category>
<wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id>
<wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename>
<wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[$c->parent]->slug : '' ); ?></wp:category_parent>
<?php wxr_cat_name( $c );
<wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ); ?></wp:category_parent>
<?php
wxr_cat_name( $c );
wxr_category_description( $c );
wxr_term_meta( $c ); ?>
wxr_term_meta( $c );
?>
</wp:category>
<?php endforeach; ?>
<?php foreach ( $tags as $t ) : ?>
<?php endforeach; ?>
<?php foreach ( $tags as $t ) : ?>
<wp:tag>
<wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id>
<wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug>
<?php wxr_tag_name( $t );
<?php
wxr_tag_name( $t );
wxr_tag_description( $t );
wxr_term_meta( $t ); ?>
wxr_term_meta( $t );
?>
</wp:tag>
<?php endforeach; ?>
<?php foreach ( $terms as $t ) : ?>
<?php endforeach; ?>
<?php foreach ( $terms as $t ) : ?>
<wp:term>
<wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id>
<wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy>
<wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug>
<wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[$t->parent]->slug : '' ); ?></wp:term_parent>
<?php wxr_term_name( $t );
<wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[ $t->parent ]->slug : '' ); ?></wp:term_parent>
<?php
wxr_term_name( $t );
wxr_term_description( $t );
wxr_term_meta( $t ); ?>
wxr_term_meta( $t );
?>
</wp:term>
<?php endforeach; ?>
<?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?>
<?php endforeach; ?>
<?php
if ( 'all' == $args['content'] ) {
wxr_nav_menu_terms();}
?>
<?php
/** This action is documented in wp-includes/feed-rss2.php */
do_action( 'rss2_head' );
?>
<?php if ( $post_ids ) {
/**
* @global WP_Query $wp_query
*/
global $wp_query;
<?php
if ( $post_ids ) {
/**
* @global WP_Query $wp_query
*/
global $wp_query;
// Fake being in the loop.
$wp_query->in_the_loop = true;
// Fake being in the loop.
$wp_query->in_the_loop = true;
// Fetch 20 posts at a time rather than loading the entire table into memory.
while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
$where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
// Fetch 20 posts at a time rather than loading the entire table into memory.
while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
$where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
// Begin Loop.
foreach ( $posts as $post ) {
setup_postdata( $post );
$is_sticky = is_sticky( $post->ID ) ? 1 : 0;
?>
// Begin Loop.
foreach ( $posts as $post ) {
setup_postdata( $post );
$is_sticky = is_sticky( $post->ID ) ? 1 : 0;
?>
<item>
<title><?php
/** This filter is documented in wp-includes/feed.php */
echo apply_filters( 'the_title_rss', $post->post_title );
?></title>
<link><?php the_permalink_rss() ?></link>
<title>
<?php
/** This filter is documented in wp-includes/feed.php */
echo apply_filters( 'the_title_rss', $post->post_title );
?>
</title>
<link><?php the_permalink_rss(); ?></link>
<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
<dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<description></description>
<content:encoded><?php
/**
* Filters the post content used for WXR exports.
*
* @since 2.5.0
*
* @param string $post_content Content of the current post.
*/
echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) );
?></content:encoded>
<excerpt:encoded><?php
/**
* Filters the post excerpt used for WXR exports.
*
* @since 2.6.0
*
* @param string $post_excerpt Excerpt for the current post.
*/
echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) );
?></excerpt:encoded>
<content:encoded>
<?php
/**
* Filters the post content used for WXR exports.
*
* @since 2.5.0
*
* @param string $post_content Content of the current post.
*/
echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) );
?>
</content:encoded>
<excerpt:encoded>
<?php
/**
* Filters the post excerpt used for WXR exports.
*
* @since 2.6.0
*
* @param string $post_excerpt Excerpt for the current post.
*/
echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) );
?>
</excerpt:encoded>
<wp:post_id><?php echo intval( $post->ID ); ?></wp:post_id>
<wp:post_date><?php echo wxr_cdata( $post->post_date ); ?></wp:post_date>
<wp:post_date_gmt><?php echo wxr_cdata( $post->post_date_gmt ); ?></wp:post_date_gmt>
@ -542,36 +580,40 @@ function export_wp( $args = array() ) {
<wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type>
<wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password>
<wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky>
<?php if ( $post->post_type == 'attachment' ) : ?>
<?php if ( $post->post_type == 'attachment' ) : ?>
<wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url>
<?php endif; ?>
<?php wxr_post_taxonomy(); ?>
<?php $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
foreach ( $postmeta as $meta ) :
/**
* Filters whether to selectively skip post meta used for WXR exports.
*
* Returning a truthy value to the filter will skip the current meta
* object from being exported.
*
* @since 3.3.0
*
* @param bool $skip Whether to skip the current post meta. Default false.
* @param string $meta_key Current meta key.
* @param object $meta Current meta object.
*/
if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) )
continue;
?>
<?php endif; ?>
<?php wxr_post_taxonomy(); ?>
<?php
$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
foreach ( $postmeta as $meta ) :
/**
* Filters whether to selectively skip post meta used for WXR exports.
*
* Returning a truthy value to the filter will skip the current meta
* object from being exported.
*
* @since 3.3.0
*
* @param bool $skip Whether to skip the current post meta. Default false.
* @param string $meta_key Current meta key.
* @param object $meta Current meta object.
*/
if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
continue;
}
?>
<wp:postmeta>
<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
</wp:postmeta>
<?php endforeach;
<?php
endforeach;
$_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
$comments = array_map( 'get_comment', $_comments );
foreach ( $comments as $c ) : ?>
$_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
$comments = array_map( 'get_comment', $_comments );
foreach ( $comments as $c ) :
?>
<wp:comment>
<wp:comment_id><?php echo intval( $c->comment_ID ); ?></wp:comment_id>
<wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author>
@ -580,42 +622,44 @@ function export_wp( $args = array() ) {
<wp:comment_author_IP><?php echo wxr_cdata( $c->comment_author_IP ); ?></wp:comment_author_IP>
<wp:comment_date><?php echo wxr_cdata( $c->comment_date ); ?></wp:comment_date>
<wp:comment_date_gmt><?php echo wxr_cdata( $c->comment_date_gmt ); ?></wp:comment_date_gmt>
<wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content>
<wp:comment_content><?php echo wxr_cdata( $c->comment_content ); ?></wp:comment_content>
<wp:comment_approved><?php echo wxr_cdata( $c->comment_approved ); ?></wp:comment_approved>
<wp:comment_type><?php echo wxr_cdata( $c->comment_type ); ?></wp:comment_type>
<wp:comment_parent><?php echo intval( $c->comment_parent ); ?></wp:comment_parent>
<wp:comment_user_id><?php echo intval( $c->user_id ); ?></wp:comment_user_id>
<?php $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
foreach ( $c_meta as $meta ) :
/**
* Filters whether to selectively skip comment meta used for WXR exports.
*
* Returning a truthy value to the filter will skip the current meta
* object from being exported.
*
* @since 4.0.0
*
* @param bool $skip Whether to skip the current comment meta. Default false.
* @param string $meta_key Current meta key.
* @param object $meta Current meta object.
*/
if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) {
continue;
}
?>
<wp:commentmeta>
<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
<?php
$c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
foreach ( $c_meta as $meta ) :
/**
* Filters whether to selectively skip comment meta used for WXR exports.
*
* Returning a truthy value to the filter will skip the current meta
* object from being exported.
*
* @since 4.0.0
*
* @param bool $skip Whether to skip the current comment meta. Default false.
* @param string $meta_key Current meta key.
* @param object $meta Current meta object.
*/
if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) {
continue;
}
?>
<wp:commentmeta>
<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
</wp:commentmeta>
<?php endforeach; ?>
<?php endforeach; ?>
</wp:comment>
<?php endforeach; ?>
</item>
<?php
<?php endforeach; ?>
</item>
<?php
}
}
}
}
} ?>
?>
</channel>
</rss>
<?php
<?php
}

File diff suppressed because it is too large Load diff

View file

@ -9,34 +9,39 @@
/**
* Loads the WP image-editing interface.
*
* @since 2.9.0
*
* @param int $post_id Post ID.
* @param bool|object $msg Optional. Message to display for image editor updates or errors.
* Default false.
*/
function wp_image_editor($post_id, $msg = false) {
$nonce = wp_create_nonce("image_editor-$post_id");
$meta = wp_get_attachment_metadata($post_id);
$thumb = image_get_intermediate_size($post_id, 'thumbnail');
$sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']);
$note = '';
function wp_image_editor( $post_id, $msg = false ) {
$nonce = wp_create_nonce( "image_editor-$post_id" );
$meta = wp_get_attachment_metadata( $post_id );
$thumb = image_get_intermediate_size( $post_id, 'thumbnail' );
$sub_sizes = isset( $meta['sizes'] ) && is_array( $meta['sizes'] );
$note = '';
if ( isset( $meta['width'], $meta['height'] ) )
if ( isset( $meta['width'], $meta['height'] ) ) {
$big = max( $meta['width'], $meta['height'] );
else
die( __('Image data does not exist. Please re-upload the image.') );
} else {
die( __( 'Image data does not exist. Please re-upload the image.' ) );
}
$sizer = $big > 400 ? 400 / $big : 1;
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
$can_restore = false;
if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) )
$can_restore = false;
if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) {
$can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] );
}
if ( $msg ) {
if ( isset($msg->error) )
if ( isset( $msg->error ) ) {
$note = "<div class='error'><p>$msg->error</p></div>";
elseif ( isset($msg->msg) )
} elseif ( isset( $msg->msg ) ) {
$note = "<div class='updated'><p>$msg->msg</p></div>";
}
}
?>
@ -49,10 +54,10 @@ function wp_image_editor($post_id, $msg = false) {
<h2><?php _e( 'Scale Image' ); ?></h2>
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" aria-expanded="false"><span class="screen-reader-text"><?php esc_html_e( 'Scale Image Help' ); ?></span></button>
<div class="imgedit-help">
<p><?php _e('You can proportionally scale the original image. For best results, scaling should be done before you crop, flip, or rotate. Images can only be scaled down, not up.'); ?></p>
<p><?php _e( 'You can proportionally scale the original image. For best results, scaling should be done before you crop, flip, or rotate. Images can only be scaled down, not up.' ); ?></p>
</div>
<?php if ( isset( $meta['width'], $meta['height'] ) ): ?>
<p><?php printf( __('Original dimensions %s'), $meta['width'] . ' &times; ' . $meta['height'] ); ?></p>
<?php if ( isset( $meta['width'], $meta['height'] ) ) : ?>
<p><?php printf( __( 'Original dimensions %s' ), $meta['width'] . ' &times; ' . $meta['height'] ); ?></p>
<?php endif ?>
<div class="imgedit-submit">
@ -68,25 +73,29 @@ function wp_image_editor($post_id, $msg = false) {
</label>
<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span>
<input id="imgedit-scale-button" type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" />
</div>
</div>
</fieldset>
</div>
</div>
</div>
<?php if ( $can_restore ) { ?>
<?php if ( $can_restore ) { ?>
<div class="imgedit-group">
<div class="imgedit-group-top">
<h2><button type="button" onclick="imageEdit.toggleHelp(this);" class="button-link"><?php _e( 'Restore Original Image' ); ?> <span class="dashicons dashicons-arrow-down imgedit-help-toggle"></span></button></h2>
<div class="imgedit-help">
<p><?php _e('Discard any changes and restore the original image.');
<p>
<?php
_e( 'Discard any changes and restore the original image.' );
if ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE )
echo ' '.__('Previously edited copies of the image will not be deleted.');
if ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) {
echo ' ' . __( 'Previously edited copies of the image will not be deleted.' );
}
?></p>
?>
</p>
<div class="imgedit-submit">
<input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'restore')" class="button button-primary" value="<?php esc_attr_e( 'Restore image' ); ?>" <?php echo $can_restore; ?> />
</div>
@ -94,7 +103,7 @@ function wp_image_editor($post_id, $msg = false) {
</div>
</div>
<?php } ?>
<?php } ?>
<div class="imgedit-group">
<div class="imgedit-group-top">
@ -102,13 +111,13 @@ function wp_image_editor($post_id, $msg = false) {
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" aria-expanded="false"><span class="screen-reader-text"><?php esc_html_e( 'Image Crop Help' ); ?></span></button>
<div class="imgedit-help">
<p><?php _e('To crop the image, click on it and drag to make your selection.'); ?></p>
<p><?php _e( 'To crop the image, click on it and drag to make your selection.' ); ?></p>
<p><strong><?php _e('Crop Aspect Ratio'); ?></strong><br />
<?php _e('The aspect ratio is the relationship between the width and height. You can preserve the aspect ratio by holding down the shift key while resizing your selection. Use the input box to specify the aspect ratio, e.g. 1:1 (square), 4:3, 16:9, etc.'); ?></p>
<p><strong><?php _e( 'Crop Aspect Ratio' ); ?></strong><br />
<?php _e( 'The aspect ratio is the relationship between the width and height. You can preserve the aspect ratio by holding down the shift key while resizing your selection. Use the input box to specify the aspect ratio, e.g. 1:1 (square), 4:3, 16:9, etc.' ); ?></p>
<p><strong><?php _e('Crop Selection'); ?></strong><br />
<?php _e('Once you have made your selection, you can adjust it by entering the size in pixels. The minimum selection size is the thumbnail size as set in the Media settings.'); ?></p>
<p><strong><?php _e( 'Crop Selection' ); ?></strong><br />
<?php _e( 'Once you have made your selection, you can adjust it by entering the size in pixels. The minimum selection size is the thumbnail size as set in the Media settings.' ); ?></p>
</div>
</div>
@ -140,15 +149,16 @@ function wp_image_editor($post_id, $msg = false) {
</div>
<?php if ( $thumb && $sub_sizes ) {
<?php
if ( $thumb && $sub_sizes ) {
$thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 );
?>
?>
<div class="imgedit-group imgedit-applyto">
<div class="imgedit-group-top">
<h2><?php _e( 'Thumbnail Settings' ); ?></h2>
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" aria-expanded="false"><span class="screen-reader-text"><?php esc_html_e( 'Thumbnail Settings Help' ); ?></span></button>
<p class="imgedit-help"><?php _e('You can edit the image while preserving the thumbnail. For example, you may wish to have a square thumbnail that displays just a section of the image.'); ?></p>
<p class="imgedit-help"><?php _e( 'You can edit the image while preserving the thumbnail. For example, you may wish to have a square thumbnail that displays just a section of the image.' ); ?></p>
</div>
<figure class="imgedit-thumbnail-preview">
@ -162,15 +172,15 @@ function wp_image_editor($post_id, $msg = false) {
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" />
<?php _e('All image sizes'); ?></label>
<?php _e( 'All image sizes' ); ?></label>
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="thumbnail" />
<?php _e('Thumbnail'); ?></label>
<?php _e( 'Thumbnail' ); ?></label>
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
<?php _e('All sizes except thumbnail'); ?></label>
<?php _e( 'All sizes except thumbnail' ); ?></label>
</fieldset>
</div>
</div>
@ -182,20 +192,27 @@ function wp_image_editor($post_id, $msg = false) {
<div class="imgedit-panel-content wp-clearfix">
<?php echo $note; ?>
<div class="imgedit-menu wp-clearfix">
<button type="button" onclick="imageEdit.crop(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-crop button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Crop' ); ?></span></button><?php
<button type="button" onclick="imageEdit.handleCropToolClick( <?php echo "$post_id, '$nonce'"; ?>, this )" class="imgedit-crop button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Crop' ); ?></span></button>
<?php
// On some setups GD library does not provide imagerotate() - Ticket #11536
if ( wp_image_editor_supports( array( 'mime_type' => get_post_mime_type( $post_id ), 'methods' => array( 'rotate' ) ) ) ) {
$note_no_rotate = '';
?>
<button type="button" class="imgedit-rleft button" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)"><span class="screen-reader-text"><?php esc_html_e( 'Rotate counter-clockwise' ); ?></span></button>
// On some setups GD library does not provide imagerotate() - Ticket #11536
if ( wp_image_editor_supports(
array(
'mime_type' => get_post_mime_type( $post_id ),
'methods' => array( 'rotate' ),
)
) ) {
$note_no_rotate = '';
?>
<button type="button" class="imgedit-rleft button" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)"><span class="screen-reader-text"><?php esc_html_e( 'Rotate counter-clockwise' ); ?></span></button>
<button type="button" class="imgedit-rright button" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)"><span class="screen-reader-text"><?php esc_html_e( 'Rotate clockwise' ); ?></span></button>
<?php } else {
$note_no_rotate = '<p class="note-no-rotate"><em>' . __( 'Image rotation is not supported by your web host.' ) . '</em></p>';
?>
<button type="button" class="imgedit-rleft button disabled" disabled></button>
<button type="button" class="imgedit-rright button disabled" disabled></button>
<?php } ?>
<?php
} else {
$note_no_rotate = '<p class="note-no-rotate"><em>' . __( 'Image rotation is not supported by your web host.' ) . '</em></p>';
?>
<button type="button" class="imgedit-rleft button disabled" disabled></button>
<button type="button" class="imgedit-rright button disabled" disabled></button>
<?php } ?>
<button type="button" onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-flipv button"><span class="screen-reader-text"><?php esc_html_e( 'Flip vertically' ); ?></span></button>
<button type="button" onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-fliph button"><span class="screen-reader-text"><?php esc_html_e( 'Flip horizontally' ); ?></span></button>
@ -213,7 +230,7 @@ function wp_image_editor($post_id, $msg = false) {
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>?action=imgedit-preview&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;rand=<?php echo rand(1, 99999); ?>" alt="" />
<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>?action=imgedit-preview&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;rand=<?php echo rand( 1, 99999 ); ?>" alt="" />
</div>
<div class="imgedit-submit">
@ -224,14 +241,16 @@ function wp_image_editor($post_id, $msg = false) {
</div>
<div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div>
<div class="hidden" id="imgedit-leaving-<?php echo $post_id; ?>"><?php _e("There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor."); ?></div>
<div class="hidden" id="imgedit-leaving-<?php echo $post_id; ?>"><?php _e( "There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor." ); ?></div>
</div>
<?php
<?php
}
/**
* Streams image in WP_Image_Editor to browser.
*
* @since 2.9.0
*
* @param WP_Image_Editor $image The image editor instance.
* @param string $mime_type The mime type of the image.
* @param int $attachment_id The image's attachment post ID.
@ -250,8 +269,9 @@ function wp_stream_image( $image, $mime_type, $attachment_id ) {
*/
$image = apply_filters( 'image_editor_save_pre', $image, $attachment_id );
if ( is_wp_error( $image->stream( $mime_type ) ) )
if ( is_wp_error( $image->stream( $mime_type ) ) ) {
return false;
}
return true;
} else {
@ -285,7 +305,9 @@ function wp_stream_image( $image, $mime_type, $attachment_id ) {
}
/**
* Saves Image to File
* Saves image to file.
*
* @since 2.9.0
*
* @param string $filename
* @param WP_Image_Editor $image
@ -315,8 +337,9 @@ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
*/
$saved = apply_filters( 'wp_save_image_editor_file', null, $filename, $image, $mime_type, $post_id );
if ( null !== $saved )
if ( null !== $saved ) {
return $saved;
}
return $image->save( $filename, $mime_type );
} else {
@ -342,12 +365,12 @@ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
*/
$saved = apply_filters( 'wp_save_image_file', null, $filename, $image, $mime_type, $post_id );
if ( null !== $saved )
if ( null !== $saved ) {
return $saved;
}
switch ( $mime_type ) {
case 'image/jpeg':
/** This filter is documented in wp-includes/class-wp-image-editor.php */
return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );
case 'image/png':
@ -370,9 +393,9 @@ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
* @param int $h Image height in pixels.
* @return float|int Image preview ratio.
*/
function _image_get_preview_ratio($w, $h) {
$max = max($w, $h);
return $max > 400 ? (400 / $max) : 1;
function _image_get_preview_ratio( $w, $h ) {
$max = max( $w, $h );
return $max > 400 ? ( 400 / $max ) : 1;
}
/**
@ -387,12 +410,12 @@ function _image_get_preview_ratio($w, $h) {
* @param float|int $angle Image rotation angle, in degrees.
* @return resource|false GD image resource, false otherwise.
*/
function _rotate_image_resource($img, $angle) {
function _rotate_image_resource( $img, $angle ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' );
if ( function_exists('imagerotate') ) {
$rotated = imagerotate($img, $angle, 0);
if ( is_resource($rotated) ) {
imagedestroy($img);
if ( function_exists( 'imagerotate' ) ) {
$rotated = imagerotate( $img, $angle, 0 );
if ( is_resource( $rotated ) ) {
imagedestroy( $img );
$img = $rotated;
}
}
@ -412,19 +435,19 @@ function _rotate_image_resource($img, $angle) {
* @param bool $vert Whether to flip vertically.
* @return resource (maybe) flipped image resource.
*/
function _flip_image_resource($img, $horz, $vert) {
function _flip_image_resource( $img, $horz, $vert ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::flip()' );
$w = imagesx($img);
$h = imagesy($img);
$dst = wp_imagecreatetruecolor($w, $h);
if ( is_resource($dst) ) {
$sx = $vert ? ($w - 1) : 0;
$sy = $horz ? ($h - 1) : 0;
$w = imagesx( $img );
$h = imagesy( $img );
$dst = wp_imagecreatetruecolor( $w, $h );
if ( is_resource( $dst ) ) {
$sx = $vert ? ( $w - 1 ) : 0;
$sy = $horz ? ( $h - 1 ) : 0;
$sw = $vert ? -$w : $w;
$sh = $horz ? -$h : $h;
if ( imagecopyresampled($dst, $img, 0, 0, $sx, $sy, $w, $h, $sw, $sh) ) {
imagedestroy($img);
if ( imagecopyresampled( $dst, $img, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) {
imagedestroy( $img );
$img = $dst;
}
}
@ -444,11 +467,11 @@ function _flip_image_resource($img, $horz, $vert) {
* @param float $h Source height.
* @return resource (maybe) cropped image resource.
*/
function _crop_image_resource($img, $x, $y, $w, $h) {
$dst = wp_imagecreatetruecolor($w, $h);
if ( is_resource($dst) ) {
if ( imagecopy($dst, $img, 0, 0, $x, $y, $w, $h) ) {
imagedestroy($img);
function _crop_image_resource( $img, $x, $y, $w, $h ) {
$dst = wp_imagecreatetruecolor( $w, $h );
if ( is_resource( $dst ) ) {
if ( imagecopy( $dst, $img, 0, 0, $x, $y, $w, $h ) ) {
imagedestroy( $img );
$img = $dst;
}
}
@ -465,52 +488,55 @@ function _crop_image_resource($img, $x, $y, $w, $h) {
* @return WP_Image_Editor WP_Image_Editor instance with changes applied.
*/
function image_edit_apply_changes( $image, $changes ) {
if ( is_resource( $image ) )
if ( is_resource( $image ) ) {
_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
}
if ( !is_array($changes) )
if ( ! is_array( $changes ) ) {
return $image;
}
// Expand change operations.
foreach ( $changes as $key => $obj ) {
if ( isset($obj->r) ) {
$obj->type = 'rotate';
if ( isset( $obj->r ) ) {
$obj->type = 'rotate';
$obj->angle = $obj->r;
unset($obj->r);
} elseif ( isset($obj->f) ) {
unset( $obj->r );
} elseif ( isset( $obj->f ) ) {
$obj->type = 'flip';
$obj->axis = $obj->f;
unset($obj->f);
} elseif ( isset($obj->c) ) {
unset( $obj->f );
} elseif ( isset( $obj->c ) ) {
$obj->type = 'crop';
$obj->sel = $obj->c;
unset($obj->c);
$obj->sel = $obj->c;
unset( $obj->c );
}
$changes[$key] = $obj;
$changes[ $key ] = $obj;
}
// Combine operations.
if ( count($changes) > 1 ) {
$filtered = array($changes[0]);
if ( count( $changes ) > 1 ) {
$filtered = array( $changes[0] );
for ( $i = 0, $j = 1, $c = count( $changes ); $j < $c; $j++ ) {
$combined = false;
if ( $filtered[$i]->type == $changes[$j]->type ) {
switch ( $filtered[$i]->type ) {
if ( $filtered[ $i ]->type == $changes[ $j ]->type ) {
switch ( $filtered[ $i ]->type ) {
case 'rotate':
$filtered[$i]->angle += $changes[$j]->angle;
$combined = true;
$filtered[ $i ]->angle += $changes[ $j ]->angle;
$combined = true;
break;
case 'flip':
$filtered[$i]->axis ^= $changes[$j]->axis;
$combined = true;
$filtered[ $i ]->axis ^= $changes[ $j ]->axis;
$combined = true;
break;
}
}
if ( !$combined )
$filtered[++$i] = $changes[$j];
if ( ! $combined ) {
$filtered[ ++$i ] = $changes[ $j ];
}
}
$changes = $filtered;
unset($filtered);
unset( $filtered );
}
// Image resource before applying the changes.
@ -522,7 +548,7 @@ function image_edit_apply_changes( $image, $changes ) {
* @since 3.5.0
*
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param array $changes Array of change operations.
* @param array $changes Array of change operations.
*/
$image = apply_filters( 'wp_image_editor_before_change', $image, $changes );
} elseif ( is_resource( $image ) ) {
@ -534,7 +560,7 @@ function image_edit_apply_changes( $image, $changes ) {
* @deprecated 3.5.0 Use wp_image_editor_before_change instead.
*
* @param resource $image GD image resource.
* @param array $changes Array of change operations.
* @param array $changes Array of change operations.
*/
$image = apply_filters( 'image_edit_before_change', $image, $changes );
}
@ -543,26 +569,29 @@ function image_edit_apply_changes( $image, $changes ) {
switch ( $operation->type ) {
case 'rotate':
if ( $operation->angle != 0 ) {
if ( $image instanceof WP_Image_Editor )
if ( $image instanceof WP_Image_Editor ) {
$image->rotate( $operation->angle );
else
} else {
$image = _rotate_image_resource( $image, $operation->angle );
}
}
break;
case 'flip':
if ( $operation->axis != 0 )
if ( $image instanceof WP_Image_Editor )
$image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 );
else
if ( $operation->axis != 0 ) {
if ( $image instanceof WP_Image_Editor ) {
$image->flip( ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
} else {
$image = _flip_image_resource( $image, ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
}
}
break;
case 'crop':
$sel = $operation->sel;
if ( $image instanceof WP_Image_Editor ) {
$size = $image->get_size();
$w = $size['width'];
$h = $size['height'];
$w = $size['width'];
$h = $size['height'];
$scale = 1 / _image_get_preview_ratio( $w, $h ); // discard preview scaling
$image->crop( $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale );
@ -582,6 +611,8 @@ function image_edit_apply_changes( $image, $changes ) {
* Streams image in post to browser, along with enqueued changes
* in $_REQUEST['history']
*
* @since 2.9.0
*
* @param int $post_id
* @return bool
*/
@ -596,21 +627,23 @@ function stream_preview_image( $post_id ) {
return false;
}
$changes = !empty($_REQUEST['history']) ? json_decode( wp_unslash($_REQUEST['history']) ) : null;
if ( $changes )
$changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null;
if ( $changes ) {
$img = image_edit_apply_changes( $img, $changes );
}
// Scale the image.
$size = $img->get_size();
$w = $size['width'];
$h = $size['height'];
$w = $size['width'];
$h = $size['height'];
$ratio = _image_get_preview_ratio( $w, $h );
$w2 = max ( 1, $w * $ratio );
$h2 = max ( 1, $h * $ratio );
$w2 = max( 1, $w * $ratio );
$h2 = max( 1, $h * $ratio );
if ( is_wp_error( $img->resize( $w2, $h2 ) ) )
if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) {
return false;
}
return wp_stream_image( $img, $post->post_mime_type, $post_id );
}
@ -623,78 +656,83 @@ function stream_preview_image( $post_id ) {
* @param int $post_id Attachment post ID.
* @return stdClass Image restoration message object.
*/
function wp_restore_image($post_id) {
$meta = wp_get_attachment_metadata($post_id);
$file = get_attached_file($post_id);
function wp_restore_image( $post_id ) {
$meta = wp_get_attachment_metadata( $post_id );
$file = get_attached_file( $post_id );
$backup_sizes = $old_backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
$restored = false;
$msg = new stdClass;
$restored = false;
$msg = new stdClass;
if ( !is_array($backup_sizes) ) {
$msg->error = __('Cannot load image metadata.');
if ( ! is_array( $backup_sizes ) ) {
$msg->error = __( 'Cannot load image metadata.' );
return $msg;
}
$parts = pathinfo($file);
$suffix = time() . rand(100, 999);
$parts = pathinfo( $file );
$suffix = time() . rand( 100, 999 );
$default_sizes = get_intermediate_image_sizes();
if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) {
if ( isset( $backup_sizes['full-orig'] ) && is_array( $backup_sizes['full-orig'] ) ) {
$data = $backup_sizes['full-orig'];
if ( $parts['basename'] != $data['file'] ) {
if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
// Delete only if it's an edited image.
if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
if ( preg_match( '/-e[0-9]{13}\./', $parts['basename'] ) ) {
wp_delete_file( $file );
}
} elseif ( isset( $meta['width'], $meta['height'] ) ) {
$backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
$backup_sizes[ "full-$suffix" ] = array(
'width' => $meta['width'],
'height' => $meta['height'],
'file' => $parts['basename'],
);
}
}
$restored_file = path_join($parts['dirname'], $data['file']);
$restored = update_attached_file($post_id, $restored_file);
$restored_file = path_join( $parts['dirname'], $data['file'] );
$restored = update_attached_file( $post_id, $restored_file );
$meta['file'] = _wp_relative_upload_path( $restored_file );
$meta['width'] = $data['width'];
$meta['file'] = _wp_relative_upload_path( $restored_file );
$meta['width'] = $data['width'];
$meta['height'] = $data['height'];
}
foreach ( $default_sizes as $default_size ) {
if ( isset($backup_sizes["$default_size-orig"]) ) {
$data = $backup_sizes["$default_size-orig"];
if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
if ( isset( $backup_sizes[ "$default_size-orig" ] ) ) {
$data = $backup_sizes[ "$default_size-orig" ];
if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] != $data['file'] ) {
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
// Delete only if it's an edited image.
if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
$delete_file = path_join( $parts['dirname'], $meta['sizes'][$default_size]['file'] );
if ( preg_match( '/-e[0-9]{13}-/', $meta['sizes'][ $default_size ]['file'] ) ) {
$delete_file = path_join( $parts['dirname'], $meta['sizes'][ $default_size ]['file'] );
wp_delete_file( $delete_file );
}
} else {
$backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
$backup_sizes[ "$default_size-{$suffix}" ] = $meta['sizes'][ $default_size ];
}
}
$meta['sizes'][$default_size] = $data;
$meta['sizes'][ $default_size ] = $data;
} else {
unset($meta['sizes'][$default_size]);
unset( $meta['sizes'][ $default_size ] );
}
}
if ( ! wp_update_attachment_metadata( $post_id, $meta ) ||
( $old_backup_sizes !== $backup_sizes && ! update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ) ) ) {
$msg->error = __('Cannot save image metadata.');
$msg->error = __( 'Cannot save image metadata.' );
return $msg;
}
if ( !$restored )
$msg->error = __('Image metadata is inconsistent.');
else
$msg->msg = __('Image restored successfully.');
if ( ! $restored ) {
$msg->error = __( 'Image metadata is inconsistent.' );
} else {
$msg->msg = __( 'Image restored successfully.' );
}
return $msg;
}
@ -703,75 +741,80 @@ function wp_restore_image($post_id) {
* Saves image to post along with enqueued changes
* in $_REQUEST['history']
*
* @since 2.9.0
*
* @param int $post_id
* @return \stdClass
*/
function wp_save_image( $post_id ) {
$_wp_additional_image_sizes = wp_get_additional_image_sizes();
$return = new stdClass;
$return = new stdClass;
$success = $delete = $scaled = $nocrop = false;
$post = get_post( $post_id );
$post = get_post( $post_id );
$img = wp_get_image_editor( _load_image_to_edit_path( $post_id, 'full' ) );
if ( is_wp_error( $img ) ) {
$return->error = esc_js( __('Unable to create new image.') );
$return->error = esc_js( __( 'Unable to create new image.' ) );
return $return;
}
$fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0;
$fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0;
$target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : '';
$scale = !empty($_REQUEST['do']) && 'scale' == $_REQUEST['do'];
$fwidth = ! empty( $_REQUEST['fwidth'] ) ? intval( $_REQUEST['fwidth'] ) : 0;
$fheight = ! empty( $_REQUEST['fheight'] ) ? intval( $_REQUEST['fheight'] ) : 0;
$target = ! empty( $_REQUEST['target'] ) ? preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['target'] ) : '';
$scale = ! empty( $_REQUEST['do'] ) && 'scale' == $_REQUEST['do'];
if ( $scale && $fwidth > 0 && $fheight > 0 ) {
$size = $img->get_size();
$sX = $size['width'];
$sY = $size['height'];
$sX = $size['width'];
$sY = $size['height'];
// Check if it has roughly the same w / h ratio.
$diff = round($sX / $sY, 2) - round($fwidth / $fheight, 2);
$diff = round( $sX / $sY, 2 ) - round( $fwidth / $fheight, 2 );
if ( -0.1 < $diff && $diff < 0.1 ) {
// Scale the full size image.
if ( $img->resize( $fwidth, $fheight ) )
if ( $img->resize( $fwidth, $fheight ) ) {
$scaled = true;
}
}
if ( !$scaled ) {
$return->error = esc_js( __('Error while saving the scaled image. Please reload the page and try again.') );
if ( ! $scaled ) {
$return->error = esc_js( __( 'Error while saving the scaled image. Please reload the page and try again.' ) );
return $return;
}
} elseif ( !empty($_REQUEST['history']) ) {
$changes = json_decode( wp_unslash($_REQUEST['history']) );
if ( $changes )
$img = image_edit_apply_changes($img, $changes);
} elseif ( ! empty( $_REQUEST['history'] ) ) {
$changes = json_decode( wp_unslash( $_REQUEST['history'] ) );
if ( $changes ) {
$img = image_edit_apply_changes( $img, $changes );
}
} else {
$return->error = esc_js( __('Nothing to save, the image has not changed.') );
$return->error = esc_js( __( 'Nothing to save, the image has not changed.' ) );
return $return;
}
$meta = wp_get_attachment_metadata($post_id);
$meta = wp_get_attachment_metadata( $post_id );
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
if ( !is_array($meta) ) {
$return->error = esc_js( __('Image data does not exist. Please re-upload the image.') );
if ( ! is_array( $meta ) ) {
$return->error = esc_js( __( 'Image data does not exist. Please re-upload the image.' ) );
return $return;
}
if ( !is_array($backup_sizes) )
if ( ! is_array( $backup_sizes ) ) {
$backup_sizes = array();
}
// Generate new filename.
$path = get_attached_file( $post_id );
$basename = pathinfo( $path, PATHINFO_BASENAME );
$dirname = pathinfo( $path, PATHINFO_DIRNAME );
$ext = pathinfo( $path, PATHINFO_EXTENSION );
$dirname = pathinfo( $path, PATHINFO_DIRNAME );
$ext = pathinfo( $path, PATHINFO_EXTENSION );
$filename = pathinfo( $path, PATHINFO_FILENAME );
$suffix = time() . rand(100, 999);
$suffix = time() . rand( 100, 999 );
if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE &&
isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $basename ) {
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE &&
isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] != $basename ) {
if ( 'thumbnail' == $target ) {
$new_path = "{$dirname}/{$filename}-temp.{$ext}";
@ -780,11 +823,11 @@ function wp_save_image( $post_id ) {
}
} else {
while ( true ) {
$filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
$filename .= "-e{$suffix}";
$filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
$filename .= "-e{$suffix}";
$new_filename = "{$filename}.{$ext}";
$new_path = "{$dirname}/$new_filename";
if ( file_exists($new_path) ) {
$new_path = "{$dirname}/$new_filename";
if ( file_exists( $new_path ) ) {
$suffix++;
} else {
break;
@ -793,8 +836,8 @@ function wp_save_image( $post_id ) {
}
// Save the full-size file, also needed to create sub-sizes.
if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) {
$return->error = esc_js( __('Unable to save the image.') );
if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) {
$return->error = esc_js( __( 'Unable to save the image.' ) );
return $return;
}
@ -809,26 +852,31 @@ function wp_save_image( $post_id ) {
}
if ( $tag ) {
$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $basename );
$backup_sizes[ $tag ] = array(
'width' => $meta['width'],
'height' => $meta['height'],
'file' => $basename,
);
}
$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
$meta['file'] = _wp_relative_upload_path( $new_path );
$size = $img->get_size();
$meta['width'] = $size['width'];
$size = $img->get_size();
$meta['width'] = $size['width'];
$meta['height'] = $size['height'];
if ( $success && ('nothumb' == $target || 'all' == $target) ) {
if ( $success && ( 'nothumb' == $target || 'all' == $target ) ) {
$sizes = get_intermediate_image_sizes();
if ( 'nothumb' == $target )
$sizes = array_diff( $sizes, array('thumbnail') );
if ( 'nothumb' == $target ) {
$sizes = array_diff( $sizes, array( 'thumbnail' ) );
}
}
$return->fw = $meta['width'];
$return->fh = $meta['height'];
} elseif ( 'thumbnail' == $target ) {
$sizes = array( 'thumbnail' );
$sizes = array( 'thumbnail' );
$success = $delete = $nocrop = true;
}
@ -852,16 +900,18 @@ function wp_save_image( $post_id ) {
foreach ( $sizes as $size ) {
$tag = false;
if ( isset( $meta['sizes'][$size] ) ) {
if ( isset($backup_sizes["$size-orig"]) ) {
if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes["$size-orig"]['file'] != $meta['sizes'][$size]['file'] )
if ( isset( $meta['sizes'][ $size ] ) ) {
if ( isset( $backup_sizes[ "$size-orig" ] ) ) {
if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes[ "$size-orig" ]['file'] != $meta['sizes'][ $size ]['file'] ) {
$tag = "$size-$suffix";
}
} else {
$tag = "$size-orig";
}
if ( $tag )
$backup_sizes[$tag] = $meta['sizes'][$size];
if ( $tag ) {
$backup_sizes[ $tag ] = $meta['sizes'][ $size ];
}
}
if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
@ -874,7 +924,11 @@ function wp_save_image( $post_id ) {
$crop = ( $nocrop ) ? false : get_option( "{$size}_crop" );
}
$_sizes[ $size ] = array( 'width' => $width, 'height' => $height, 'crop' => $crop );
$_sizes[ $size ] = array(
'width' => $width,
'height' => $height,
'crop' => $crop,
);
}
$meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes ) );
@ -884,17 +938,17 @@ function wp_save_image( $post_id ) {
if ( $success ) {
wp_update_attachment_metadata( $post_id, $meta );
update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes);
update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes );
if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) {
// Check if it's an image edit from attachment edit screen
if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' == $_REQUEST['context'] ) {
$thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true );
$thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true );
$return->thumbnail = $thumb_url[0];
} else {
$file_url = wp_get_attachment_url($post_id);
$file_url = wp_get_attachment_url( $post_id );
if ( ! empty( $meta['sizes']['thumbnail'] ) && $thumb = $meta['sizes']['thumbnail'] ) {
$return->thumbnail = path_join( dirname($file_url), $thumb['file'] );
$return->thumbnail = path_join( dirname( $file_url ), $thumb['file'] );
} else {
$return->thumbnail = "$file_url?w=128&h=128";
}
@ -908,6 +962,6 @@ function wp_save_image( $post_id ) {
wp_delete_file( $new_path );
}
$return->msg = esc_js( __('Image saved') );
$return->msg = esc_js( __( 'Image saved' ) );
return $return;
}

View file

@ -37,15 +37,18 @@ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s
}
$editor = wp_get_image_editor( $src );
if ( is_wp_error( $editor ) )
if ( is_wp_error( $editor ) ) {
return $editor;
}
$src = $editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs );
if ( is_wp_error( $src ) )
if ( is_wp_error( $src ) ) {
return $src;
}
if ( ! $dst_file )
if ( ! $dst_file ) {
$dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
}
/*
* The directory containing the original file may no longer exist when
@ -56,8 +59,9 @@ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s
$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) );
$result = $editor->save( $dst_file );
if ( is_wp_error( $result ) )
if ( is_wp_error( $result ) ) {
return $result;
}
return $dst_file;
}
@ -74,46 +78,50 @@ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s
function wp_generate_attachment_metadata( $attachment_id, $file ) {
$attachment = get_post( $attachment_id );
$metadata = array();
$support = false;
$metadata = array();
$support = false;
$mime_type = get_post_mime_type( $attachment );
if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image( $file ) ) {
$imagesize = getimagesize( $file );
$metadata['width'] = $imagesize[0];
$imagesize = getimagesize( $file );
$metadata['width'] = $imagesize[0];
$metadata['height'] = $imagesize[1];
// Make the file path relative to the upload dir.
$metadata['file'] = _wp_relative_upload_path($file);
$metadata['file'] = _wp_relative_upload_path( $file );
// Make thumbnails and other intermediate sizes.
$_wp_additional_image_sizes = wp_get_additional_image_sizes();
$sizes = array();
foreach ( get_intermediate_image_sizes() as $s ) {
$sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false );
if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) {
$sizes[ $s ] = array(
'width' => '',
'height' => '',
'crop' => false,
);
if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
// For theme-added sizes
$sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] );
$sizes[ $s ]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] );
} else {
// For default sizes set in options
$sizes[$s]['width'] = get_option( "{$s}_size_w" );
$sizes[ $s ]['width'] = get_option( "{$s}_size_w" );
}
if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) {
if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
// For theme-added sizes
$sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] );
$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] );
} else {
// For default sizes set in options
$sizes[$s]['height'] = get_option( "{$s}_size_h" );
$sizes[ $s ]['height'] = get_option( "{$s}_size_h" );
}
if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) {
if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
// For theme-added sizes
$sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop'];
$sizes[ $s ]['crop'] = $_wp_additional_image_sizes[ $s ]['crop'];
} else {
// For default sizes set in options
$sizes[$s]['crop'] = get_option( "{$s}_crop" );
$sizes[ $s ]['crop'] = get_option( "{$s}_crop" );
}
}
@ -122,46 +130,51 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
*
* @since 2.9.0
* @since 4.4.0 Added the `$metadata` argument.
* @since 5.1.0 Added the `$attachment_id` argument.
*
* @param array $sizes An associative array of image sizes.
* @param array $metadata An associative array of image metadata: width, height, file.
* @param array $sizes An associative array of image sizes.
* @param array $metadata An associative array of image metadata: width, height, file.
* @param int $attachment_id Current attachment ID.
*/
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes, $metadata );
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes, $metadata, $attachment_id );
if ( $sizes ) {
$editor = wp_get_image_editor( $file );
if ( ! is_wp_error( $editor ) )
if ( ! is_wp_error( $editor ) ) {
$metadata['sizes'] = $editor->multi_resize( $sizes );
}
} else {
$metadata['sizes'] = array();
}
// Fetch additional metadata from EXIF/IPTC.
$image_meta = wp_read_image_metadata( $file );
if ( $image_meta )
if ( $image_meta ) {
$metadata['image_meta'] = $image_meta;
}
} elseif ( wp_attachment_is( 'video', $attachment ) ) {
$metadata = wp_read_video_metadata( $file );
$support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
$support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
} elseif ( wp_attachment_is( 'audio', $attachment ) ) {
$metadata = wp_read_audio_metadata( $file );
$support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
$support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
}
if ( $support && ! empty( $metadata['image']['data'] ) ) {
// Check for existing cover.
$hash = md5( $metadata['image']['data'] );
$posts = get_posts( array(
'fields' => 'ids',
'post_type' => 'attachment',
'post_mime_type' => $metadata['image']['mime'],
'post_status' => 'inherit',
'posts_per_page' => 1,
'meta_key' => '_cover_hash',
'meta_value' => $hash
) );
$hash = md5( $metadata['image']['data'] );
$posts = get_posts(
array(
'fields' => 'ids',
'post_type' => 'attachment',
'post_mime_type' => $metadata['image']['mime'],
'post_status' => 'inherit',
'posts_per_page' => 1,
'meta_key' => '_cover_hash',
'meta_value' => $hash,
)
);
$exists = reset( $posts );
if ( ! empty( $exists ) ) {
@ -169,20 +182,20 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
} else {
$ext = '.jpg';
switch ( $metadata['image']['mime'] ) {
case 'image/gif':
$ext = '.gif';
break;
case 'image/png':
$ext = '.png';
break;
case 'image/gif':
$ext = '.gif';
break;
case 'image/png':
$ext = '.png';
break;
}
$basename = str_replace( '.', '-', basename( $file ) ) . '-image' . $ext;
$uploaded = wp_upload_bits( $basename, '', $metadata['image']['data'] );
if ( false === $uploaded['error'] ) {
$image_attachment = array(
'post_mime_type' => $metadata['image']['mime'],
'post_type' => 'attachment',
'post_content' => '',
'post_type' => 'attachment',
'post_content' => '',
);
/**
* Filters the parameters for the attachment thumbnail creation.
@ -202,9 +215,9 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id );
}
}
}
// Try to create image thumbnails for PDFs
else if ( 'application/pdf' === $mime_type ) {
} elseif ( 'application/pdf' === $mime_type ) {
// Try to create image thumbnails for PDFs.
$fallback_sizes = array(
'thumbnail',
'medium',
@ -221,7 +234,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
*/
$fallback_sizes = apply_filters( 'fallback_intermediate_image_sizes', $fallback_sizes, $metadata );
$sizes = array();
$sizes = array();
$_wp_additional_image_sizes = wp_get_additional_image_sizes();
foreach ( $fallback_sizes as $s ) {
@ -256,8 +269,8 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
* PDFs may have the same file filename as JPEGs.
* Ensure the PDF preview image does not overwrite any JPEG images that already exist.
*/
$dirname = dirname( $file ) . '/';
$ext = '.' . pathinfo( $file, PATHINFO_EXTENSION );
$dirname = dirname( $file ) . '/';
$ext = '.' . pathinfo( $file, PATHINFO_EXTENSION );
$preview_file = $dirname . wp_unique_filename( $dirname, wp_basename( $file, $ext ) . '-pdf.jpg' );
$uploaded = $editor->save( $preview_file, 'image/jpeg' );
@ -269,7 +282,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
unset( $uploaded['path'] );
if ( ! is_wp_error( $editor ) ) {
$metadata['sizes'] = $editor->multi_resize( $sizes );
$metadata['sizes'] = $editor->multi_resize( $sizes );
$metadata['sizes']['full'] = $uploaded;
}
}
@ -301,10 +314,11 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
* @param string $str
* @return int|float
*/
function wp_exif_frac2dec($str) {
function wp_exif_frac2dec( $str ) {
@list( $n, $d ) = explode( '/', $str );
if ( !empty($d) )
if ( ! empty( $d ) ) {
return $n / $d;
}
return $str;
}
@ -316,9 +330,9 @@ function wp_exif_frac2dec($str) {
* @param string $str
* @return int
*/
function wp_exif_date2ts($str) {
@list( $date, $time ) = explode( ' ', trim($str) );
@list( $y, $m, $d ) = explode( ':', $date );
function wp_exif_date2ts( $str ) {
@list( $date, $time ) = explode( ' ', trim( $str ) );
@list( $y, $m, $d ) = explode( ':', $date );
return strtotime( "{$y}-{$m}-{$d} {$time}" );
}
@ -340,8 +354,9 @@ function wp_exif_date2ts($str) {
* @return bool|array False on failure. Image metadata array on success.
*/
function wp_read_image_metadata( $file ) {
if ( ! file_exists( $file ) )
if ( ! file_exists( $file ) ) {
return false;
}
list( , , $image_type ) = @getimagesize( $file );
@ -352,18 +367,18 @@ function wp_read_image_metadata( $file ) {
* floats, dates to unix timestamps, and everything else to strings.
*/
$meta = array(
'aperture' => 0,
'credit' => '',
'camera' => '',
'caption' => '',
'aperture' => 0,
'credit' => '',
'camera' => '',
'caption' => '',
'created_timestamp' => 0,
'copyright' => '',
'focal_length' => 0,
'iso' => 0,
'shutter_speed' => 0,
'title' => '',
'orientation' => 0,
'keywords' => array(),
'copyright' => '',
'focal_length' => 0,
'iso' => 0,
'shutter_speed' => 0,
'title' => '',
'orientation' => 0,
'keywords' => array(),
);
$iptc = array();
@ -380,10 +395,10 @@ function wp_read_image_metadata( $file ) {
// Headline, "A brief synopsis of the caption."
if ( ! empty( $iptc['2#105'][0] ) ) {
$meta['title'] = trim( $iptc['2#105'][0] );
/*
* Title, "Many use the Title field to store the filename of the image,
* though the field may be used in many ways."
*/
/*
* Title, "Many use the Title field to store the filename of the image,
* though the field may be used in many ways."
*/
} elseif ( ! empty( $iptc['2#005'][0] ) ) {
$meta['title'] = trim( $iptc['2#005'][0] );
}
@ -403,24 +418,27 @@ function wp_read_image_metadata( $file ) {
$meta['caption'] = $caption;
}
if ( ! empty( $iptc['2#110'][0] ) ) // credit
if ( ! empty( $iptc['2#110'][0] ) ) { // credit
$meta['credit'] = trim( $iptc['2#110'][0] );
elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline
} elseif ( ! empty( $iptc['2#080'][0] ) ) { // creator / legacy byline
$meta['credit'] = trim( $iptc['2#080'][0] );
}
if ( ! empty( $iptc['2#055'][0] ) && ! empty( $iptc['2#060'][0] ) ) // created date and time
if ( ! empty( $iptc['2#055'][0] ) && ! empty( $iptc['2#060'][0] ) ) { // created date and time
$meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] );
}
if ( ! empty( $iptc['2#116'][0] ) ) // copyright
if ( ! empty( $iptc['2#116'][0] ) ) { // copyright
$meta['copyright'] = trim( $iptc['2#116'][0] );
}
if ( ! empty( $iptc['2#025'][0] ) ) { // keywords array
$meta['keywords'] = array_values( $iptc['2#025'] );
}
}
}
}
$exif = array();
$exif = array();
/**
* Filters the image types to check for exif data.
@ -458,7 +476,7 @@ function wp_read_image_metadata( $file ) {
if ( empty( $meta['credit'] ) ) {
if ( ! empty( $exif['Artist'] ) ) {
$meta['credit'] = trim( $exif['Artist'] );
} elseif ( ! empty($exif['Author'] ) ) {
} elseif ( ! empty( $exif['Author'] ) ) {
$meta['credit'] = trim( $exif['Author'] );
}
}
@ -529,9 +547,9 @@ function wp_read_image_metadata( $file ) {
* @param string $path File path to test if valid image.
* @return bool True if valid image, false if not valid image.
*/
function file_is_valid_image($path) {
$size = @getimagesize($path);
return !empty($size);
function file_is_valid_image( $path ) {
$size = @getimagesize( $path );
return ! empty( $size );
}
/**
@ -542,9 +560,14 @@ function file_is_valid_image($path) {
* @param string $path File path to test.
* @return bool True if suitable, false if not suitable.
*/
function file_is_displayable_image($path) {
function file_is_displayable_image( $path ) {
$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP );
// IMAGETYPE_ICO is only defined in PHP 5.3+.
if ( defined( 'IMAGETYPE_ICO' ) ) {
$displayable_image_types[] = IMAGETYPE_ICO;
}
$info = @getimagesize( $path );
if ( empty( $info ) ) {
$result = false;
@ -577,24 +600,25 @@ function file_is_displayable_image($path) {
*/
function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) {
$filepath = _load_image_to_edit_path( $attachment_id, $size );
if ( empty( $filepath ) )
if ( empty( $filepath ) ) {
return false;
}
switch ( $mime_type ) {
case 'image/jpeg':
$image = imagecreatefromjpeg($filepath);
$image = imagecreatefromjpeg( $filepath );
break;
case 'image/png':
$image = imagecreatefrompng($filepath);
$image = imagecreatefrompng( $filepath );
break;
case 'image/gif':
$image = imagecreatefromgif($filepath);
$image = imagecreatefromgif( $filepath );
break;
default:
$image = false;
break;
}
if ( is_resource($image) ) {
if ( is_resource( $image ) ) {
/**
* Filters the current image being loaded for editing.
*
@ -605,9 +629,9 @@ function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) {
* @param string $size Image size.
*/
$image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size );
if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
imagealphablending($image, false);
imagesavealpha($image, true);
if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
imagealphablending( $image, false );
imagesavealpha( $image, true );
}
}
return $image;
@ -682,8 +706,9 @@ function _load_image_to_edit_path( $attachment_id, $size = 'full' ) {
*/
function _copy_image_file( $attachment_id ) {
$dst_file = $src_file = get_attached_file( $attachment_id );
if ( ! file_exists( $src_file ) )
if ( ! file_exists( $src_file ) ) {
$src_file = _load_image_to_edit_path( $attachment_id );
}
if ( $src_file ) {
$dst_file = str_replace( basename( $dst_file ), 'copy-' . basename( $dst_file ), $dst_file );
@ -695,8 +720,9 @@ function _copy_image_file( $attachment_id ) {
*/
wp_mkdir_p( dirname( $dst_file ) );
if ( ! @copy( $src_file, $dst_file ) )
if ( ! @copy( $src_file, $dst_file ) ) {
$dst_file = false;
}
} else {
$dst_file = false;
}

View file

@ -53,9 +53,10 @@ function _usort_by_first_member( $a, $b ) {
*/
function register_importer( $id, $name, $description, $callback ) {
global $wp_importers;
if ( is_wp_error( $callback ) )
if ( is_wp_error( $callback ) ) {
return $callback;
$wp_importers[$id] = array ( $name, $description, $callback );
}
$wp_importers[ $id ] = array( $name, $description, $callback );
}
/**
@ -81,13 +82,16 @@ function wp_import_cleanup( $id ) {
function wp_import_handle_upload() {
if ( ! isset( $_FILES['import'] ) ) {
return array(
'error' => __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' )
'error' => __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ),
);
}
$overrides = array( 'test_form' => false, 'test_type' => false );
$overrides = array(
'test_form' => false,
'test_type' => false,
);
$_FILES['import']['name'] .= '.txt';
$upload = wp_handle_upload( $_FILES['import'], $overrides );
$upload = wp_handle_upload( $_FILES['import'], $overrides );
if ( isset( $upload['error'] ) ) {
return $upload;
@ -95,12 +99,12 @@ function wp_import_handle_upload() {
// Construct the object array
$object = array(
'post_title' => basename( $upload['file'] ),
'post_content' => $upload['url'],
'post_title' => basename( $upload['file'] ),
'post_content' => $upload['url'],
'post_mime_type' => $upload['type'],
'guid' => $upload['url'],
'context' => 'import',
'post_status' => 'private'
'guid' => $upload['url'],
'context' => 'import',
'post_status' => 'private',
);
// Save the data
@ -112,7 +116,10 @@ function wp_import_handle_upload() {
*/
wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );
return array( 'file' => $upload['file'], 'id' => $id );
return array(
'file' => $upload['file'],
'id' => $id,
);
}
/**
@ -125,22 +132,25 @@ function wp_import_handle_upload() {
function wp_get_popular_importers() {
include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
$locale = get_user_locale();
$cache_key = 'popular_importers_' . md5( $locale . $wp_version );
$locale = get_user_locale();
$cache_key = 'popular_importers_' . md5( $locale . $wp_version );
$popular_importers = get_site_transient( $cache_key );
if ( ! $popular_importers ) {
$url = add_query_arg( array(
'locale' => $locale,
'version' => $wp_version,
), 'http://api.wordpress.org/core/importers/1.1/' );
$url = add_query_arg(
array(
'locale' => $locale,
'version' => $wp_version,
),
'http://api.wordpress.org/core/importers/1.1/'
);
$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );
if ( wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$response = wp_remote_get( $url, $options );
$response = wp_remote_get( $url, $options );
$popular_importers = json_decode( wp_remote_retrieve_body( $response ), true );
if ( is_array( $popular_importers ) ) {
@ -152,63 +162,67 @@ function wp_get_popular_importers() {
if ( is_array( $popular_importers ) ) {
// If the data was received as translated, return it as-is.
if ( $popular_importers['translated'] )
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 ( $importer['name'] != 'WordPress' )
if ( $importer['name'] != 'WordPress' ) {
// 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' ),
'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' ),
'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' ),
'name' => __( 'LiveJournal' ),
'description' => __( 'Import posts from LiveJournal using their API.' ),
'plugin-slug' => 'livejournal-importer',
'importer-id' => 'livejournal',
),
'movabletype' => array(
'name' => __( 'Movable Type and TypePad' ),
'name' => __( 'Movable Type and TypePad' ),
'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ),
'plugin-slug' => 'movabletype-importer',
'importer-id' => 'mt',
),
'opml' => array(
'name' => __( 'Blogroll' ),
'opml' => array(
'name' => __( 'Blogroll' ),
'description' => __( 'Import links in OPML format.' ),
'plugin-slug' => 'opml-importer',
'importer-id' => 'opml',
),
'rss' => array(
'name' => __( 'RSS' ),
'rss' => array(
'name' => __( 'RSS' ),
'description' => __( 'Import posts from an RSS feed.' ),
'plugin-slug' => 'rss-importer',
'importer-id' => 'rss',
),
'tumblr' => array(
'name' => __( 'Tumblr' ),
'tumblr' => array(
'name' => __( 'Tumblr' ),
'description' => __( 'Import posts &amp; media from Tumblr using their API.' ),
'plugin-slug' => 'tumblr-importer',
'importer-id' => 'tumblr',
),
'wordpress' => array(
'name' => 'WordPress',
'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',

View file

@ -8,7 +8,7 @@
*/
/**
* Fetch an instance of a WP_List_Table class.
* Fetches an instance of a WP_List_Table class.
*
* @access private
* @since 3.1.0
@ -16,39 +16,41 @@
* @global string $hook_suffix
*
* @param string $class The type of the list table, which is the class name.
* @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
* @return object|bool Object on success, false if the class does not exist.
* @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
* @return WP_List_Table|bool List table object on success, false if the class does not exist.
*/
function _get_list_table( $class, $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_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_Themes_List_Table' => 'themes',
'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
'WP_Plugins_List_Table' => 'plugins',
// Network Admin
'WP_MS_Sites_List_Table' => 'ms-sites',
'WP_MS_Users_List_Table' => 'ms-users',
'WP_MS_Themes_List_Table' => 'ms-themes',
'WP_MS_Sites_List_Table' => 'ms-sites',
'WP_MS_Users_List_Table' => 'ms-users',
'WP_MS_Themes_List_Table' => 'ms-themes',
);
if ( isset( $core_classes[ $class ] ) ) {
foreach ( (array) $core_classes[ $class ] as $required )
foreach ( (array) $core_classes[ $class ] as $required ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
}
if ( isset( $args['screen'] ) )
if ( isset( $args['screen'] ) ) {
$args['screen'] = convert_to_screen( $args['screen'] );
elseif ( isset( $GLOBALS['hook_suffix'] ) )
} elseif ( isset( $GLOBALS['hook_suffix'] ) ) {
$args['screen'] = get_current_screen();
else
} else {
$args['screen'] = null;
}
return new $class( $args );
}
@ -65,7 +67,7 @@ function _get_list_table( $class, $args = array() ) {
* @param array $columns An array of columns with column IDs as the keys and translated column names as the values
* @see get_column_headers(), print_column_headers(), get_hidden_columns()
*/
function register_column_headers($screen, $columns) {
function register_column_headers( $screen, $columns ) {
new _WP_List_Table_Compat( $screen, $columns );
}
@ -78,7 +80,7 @@ function register_column_headers($screen, $columns) {
* @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 = new _WP_List_Table_Compat( $screen );
$wp_list_table->print_column_headers( $with_id );
}

File diff suppressed because it is too large Load diff

View file

@ -42,48 +42,51 @@ if ( is_network_admin() ) {
}
// Create list of page plugin hook names.
foreach ($menu as $menu_page) {
if ( false !== $pos = strpos($menu_page[2], '?') ) {
foreach ( $menu as $menu_page ) {
if ( false !== $pos = strpos( $menu_page[2], '?' ) ) {
// Handle post_type=post|page|foo pages.
$hook_name = substr($menu_page[2], 0, $pos);
$hook_args = substr($menu_page[2], $pos + 1);
wp_parse_str($hook_args, $hook_args);
$hook_name = substr( $menu_page[2], 0, $pos );
$hook_args = substr( $menu_page[2], $pos + 1 );
wp_parse_str( $hook_args, $hook_args );
// Set the hook name to be the post type.
if ( isset($hook_args['post_type']) )
if ( isset( $hook_args['post_type'] ) ) {
$hook_name = $hook_args['post_type'];
else
$hook_name = basename($hook_name, '.php');
unset($hook_args);
} else {
$hook_name = basename( $hook_name, '.php' );
}
unset( $hook_args );
} else {
$hook_name = basename($menu_page[2], '.php');
$hook_name = basename( $menu_page[2], '.php' );
}
$hook_name = sanitize_title($hook_name);
$hook_name = sanitize_title( $hook_name );
if ( isset($compat[$hook_name]) )
$hook_name = $compat[$hook_name];
elseif ( !$hook_name )
if ( isset( $compat[ $hook_name ] ) ) {
$hook_name = $compat[ $hook_name ];
} elseif ( ! $hook_name ) {
continue;
}
$admin_page_hooks[$menu_page[2]] = $hook_name;
$admin_page_hooks[ $menu_page[2] ] = $hook_name;
}
unset($menu_page, $compat);
unset( $menu_page, $compat );
$_wp_submenu_nopriv = array();
$_wp_menu_nopriv = array();
$_wp_menu_nopriv = array();
// Loop over submenus and remove pages for which the user does not have privs.
foreach ($submenu as $parent => $sub) {
foreach ($sub as $index => $data) {
if ( ! current_user_can($data[1]) ) {
unset($submenu[$parent][$index]);
$_wp_submenu_nopriv[$parent][$data[2]] = true;
foreach ( $submenu as $parent => $sub ) {
foreach ( $sub as $index => $data ) {
if ( ! current_user_can( $data[1] ) ) {
unset( $submenu[ $parent ][ $index ] );
$_wp_submenu_nopriv[ $parent ][ $data[2] ] = true;
}
}
unset($index, $data);
unset( $index, $data );
if ( empty($submenu[$parent]) )
unset($submenu[$parent]);
if ( empty( $submenu[ $parent ] ) ) {
unset( $submenu[ $parent ] );
}
}
unset($sub, $parent);
unset( $sub, $parent );
/*
* Loop over the top-level menu.
@ -91,10 +94,11 @@ unset($sub, $parent);
* will have the next submenu in line be assigned as the new menu parent.
*/
foreach ( $menu as $id => $data ) {
if ( empty($submenu[$data[2]]) )
if ( empty( $submenu[ $data[2] ] ) ) {
continue;
$subs = $submenu[$data[2]];
$first_sub = reset( $subs );
}
$subs = $submenu[ $data[2] ];
$first_sub = reset( $subs );
$old_parent = $data[2];
$new_parent = $first_sub[2];
/*
@ -102,20 +106,21 @@ foreach ( $menu as $id => $data ) {
* make the first submenu the new parent.
*/
if ( $new_parent != $old_parent ) {
$_wp_real_parent_file[$old_parent] = $new_parent;
$menu[$id][2] = $new_parent;
$_wp_real_parent_file[ $old_parent ] = $new_parent;
$menu[ $id ][2] = $new_parent;
foreach ($submenu[$old_parent] as $index => $data) {
$submenu[$new_parent][$index] = $submenu[$old_parent][$index];
unset($submenu[$old_parent][$index]);
foreach ( $submenu[ $old_parent ] as $index => $data ) {
$submenu[ $new_parent ][ $index ] = $submenu[ $old_parent ][ $index ];
unset( $submenu[ $old_parent ][ $index ] );
}
unset($submenu[$old_parent], $index);
unset( $submenu[ $old_parent ], $index );
if ( isset($_wp_submenu_nopriv[$old_parent]) )
$_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent];
if ( isset( $_wp_submenu_nopriv[ $old_parent ] ) ) {
$_wp_submenu_nopriv[ $new_parent ] = $_wp_submenu_nopriv[ $old_parent ];
}
}
}
unset($id, $data, $subs, $first_sub, $old_parent, $new_parent);
unset( $id, $data, $subs, $first_sub, $old_parent, $new_parent );
if ( is_network_admin() ) {
@ -154,75 +159,75 @@ if ( is_network_admin() ) {
* that the user does not have. Run re-parent loop again.
*/
foreach ( $menu as $id => $data ) {
if ( ! current_user_can($data[1]) )
$_wp_menu_nopriv[$data[2]] = true;
if ( ! current_user_can( $data[1] ) ) {
$_wp_menu_nopriv[ $data[2] ] = true;
}
/*
* If there is only one submenu and it is has same destination as the parent,
* remove the submenu.
*/
if ( ! empty( $submenu[$data[2]] ) && 1 == count ( $submenu[$data[2]] ) ) {
$subs = $submenu[$data[2]];
if ( ! empty( $submenu[ $data[2] ] ) && 1 == count( $submenu[ $data[2] ] ) ) {
$subs = $submenu[ $data[2] ];
$first_sub = reset( $subs );
if ( $data[2] == $first_sub[2] )
unset( $submenu[$data[2]] );
if ( $data[2] == $first_sub[2] ) {
unset( $submenu[ $data[2] ] );
}
}
// If submenu is empty...
if ( empty($submenu[$data[2]]) ) {
if ( empty( $submenu[ $data[2] ] ) ) {
// And user doesn't have privs, remove menu.
if ( isset( $_wp_menu_nopriv[$data[2]] ) ) {
unset($menu[$id]);
if ( isset( $_wp_menu_nopriv[ $data[2] ] ) ) {
unset( $menu[ $id ] );
}
}
}
unset($id, $data, $subs, $first_sub);
unset( $id, $data, $subs, $first_sub );
/**
*
* @param string $add
* @param string $class
* @return string
*/
function add_cssclass($add, $class) {
$class = empty($class) ? $add : $class .= ' ' . $add;
function add_cssclass( $add, $class ) {
$class = empty( $class ) ? $add : $class .= ' ' . $add;
return $class;
}
/**
*
* @param array $menu
* @return array
*/
function add_menu_classes($menu) {
function add_menu_classes( $menu ) {
$first = $lastorder = false;
$i = 0;
$mc = count($menu);
$i = 0;
$mc = count( $menu );
foreach ( $menu as $order => $top ) {
$i++;
if ( 0 == $order ) { // dashboard is always shown/single
$menu[0][4] = add_cssclass('menu-top-first', $top[4]);
$lastorder = 0;
$menu[0][4] = add_cssclass( 'menu-top-first', $top[4] );
$lastorder = 0;
continue;
}
if ( 0 === strpos($top[2], 'separator') && false !== $lastorder ) { // if separator
$first = true;
$c = $menu[$lastorder][4];
$menu[$lastorder][4] = add_cssclass('menu-top-last', $c);
if ( 0 === strpos( $top[2], 'separator' ) && false !== $lastorder ) { // if separator
$first = true;
$c = $menu[ $lastorder ][4];
$menu[ $lastorder ][4] = add_cssclass( 'menu-top-last', $c );
continue;
}
if ( $first ) {
$c = $menu[$order][4];
$menu[$order][4] = add_cssclass('menu-top-first', $c);
$first = false;
$c = $menu[ $order ][4];
$menu[ $order ][4] = add_cssclass( 'menu-top-first', $c );
$first = false;
}
if ( $mc == $i ) { // last item
$c = $menu[$order][4];
$menu[$order][4] = add_cssclass('menu-top-last', $c);
$c = $menu[ $order ][4];
$menu[ $order ][4] = add_cssclass( 'menu-top-last', $c );
}
$lastorder = $order;
@ -238,7 +243,7 @@ function add_menu_classes($menu) {
return apply_filters( 'add_menu_classes', $menu );
}
uksort($menu, "strnatcasecmp"); // make it all pretty
uksort( $menu, 'strnatcasecmp' ); // make it all pretty
/**
* Filters whether to enable custom ordering of the administration menu.
@ -254,7 +259,7 @@ if ( apply_filters( 'custom_menu_order', false ) ) {
foreach ( $menu as $menu_item ) {
$menu_order[] = $menu_item[2];
}
unset($menu_item);
unset( $menu_item );
$default_menu_order = $menu_order;
/**
@ -269,12 +274,11 @@ if ( apply_filters( 'custom_menu_order', false ) ) {
*
* @param array $menu_order An ordered array of menu items.
*/
$menu_order = apply_filters( 'menu_order', $menu_order );
$menu_order = array_flip($menu_order);
$default_menu_order = array_flip($default_menu_order);
$menu_order = apply_filters( 'menu_order', $menu_order );
$menu_order = array_flip( $menu_order );
$default_menu_order = array_flip( $default_menu_order );
/**
*
* @global array $menu_order
* @global array $default_menu_order
*
@ -282,25 +286,26 @@ if ( apply_filters( 'custom_menu_order', false ) ) {
* @param array $b
* @return int
*/
function sort_menu($a, $b) {
function sort_menu( $a, $b ) {
global $menu_order, $default_menu_order;
$a = $a[2];
$b = $b[2];
if ( isset($menu_order[$a]) && !isset($menu_order[$b]) ) {
if ( isset( $menu_order[ $a ] ) && ! isset( $menu_order[ $b ] ) ) {
return -1;
} elseif ( !isset($menu_order[$a]) && isset($menu_order[$b]) ) {
} elseif ( ! isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
return 1;
} elseif ( isset($menu_order[$a]) && isset($menu_order[$b]) ) {
if ( $menu_order[$a] == $menu_order[$b] )
} elseif ( isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
if ( $menu_order[ $a ] == $menu_order[ $b ] ) {
return 0;
return ($menu_order[$a] < $menu_order[$b]) ? -1 : 1;
}
return ( $menu_order[ $a ] < $menu_order[ $b ] ) ? -1 : 1;
} else {
return ($default_menu_order[$a] <= $default_menu_order[$b]) ? -1 : 1;
return ( $default_menu_order[ $a ] <= $default_menu_order[ $b ] ) ? -1 : 1;
}
}
usort($menu, 'sort_menu');
unset($menu_order, $default_menu_order);
usort( $menu, 'sort_menu' );
unset( $menu_order, $default_menu_order );
}
// Prevent adjacent separators
@ -326,11 +331,12 @@ unset( $id, $data, $prev_menu_was_separator );
// Remove the last menu item if it is a separator.
$last_menu_key = array_keys( $menu );
$last_menu_key = array_pop( $last_menu_key );
if ( !empty( $menu ) && 'wp-menu-separator' == $menu[ $last_menu_key ][ 4 ] )
if ( ! empty( $menu ) && 'wp-menu-separator' == $menu[ $last_menu_key ][4] ) {
unset( $menu[ $last_menu_key ] );
}
unset( $last_menu_key );
if ( !user_can_access_admin_page() ) {
if ( ! user_can_access_admin_page() ) {
/**
* Fires when access to an admin page is denied.
@ -342,4 +348,4 @@ if ( !user_can_access_admin_page() ) {
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
}
$menu = add_menu_classes($menu);
$menu = add_menu_classes( $menu );

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -32,13 +32,13 @@ add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2
add_filter( 'import_allow_create_users', 'check_import_new_users' );
// Notices Hooks
add_action( 'admin_notices', 'site_admin_notice' );
add_action( 'admin_notices', 'site_admin_notice' );
add_action( 'network_admin_notices', 'site_admin_notice' );
// Update Hooks
add_action( 'network_admin_notices', 'update_nag', 3 );
add_action( 'network_admin_notices', 'update_nag', 3 );
add_action( 'network_admin_notices', 'maintenance_nag', 10 );
// Network Admin Hooks
add_action( 'add_site_option_new_admin_email', 'update_network_option_new_admin_email', 10, 2 );
add_action( 'add_site_option_new_admin_email', 'update_network_option_new_admin_email', 10, 2 );
add_action( 'update_site_option_new_admin_email', 'update_network_option_new_admin_email', 10, 2 );

View file

@ -16,26 +16,29 @@
* @return array $_FILES array with 'error' key set if file exceeds quota. 'error' is empty otherwise.
*/
function check_upload_size( $file ) {
if ( get_site_option( 'upload_space_check_disabled' ) )
if ( get_site_option( 'upload_space_check_disabled' ) ) {
return $file;
}
if ( $file['error'] != '0' ) // there's already an error
if ( $file['error'] != '0' ) { // there's already an error
return $file;
}
if ( defined( 'WP_IMPORTING' ) )
if ( defined( 'WP_IMPORTING' ) ) {
return $file;
}
$space_left = get_upload_space_available();
$file_size = filesize( $file['tmp_name'] );
if ( $space_left < $file_size ) {
/* translators: 1: Required disk space in kilobytes */
$file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
/* translators: %s: required disk space in kilobytes */
$file['error'] = sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
}
if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
/* translators: 1: Maximum allowed file size in kilobytes */
$file['error'] = sprintf( __( 'This file is too big. Files must be less than %1$s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
/* translators: %s: maximum allowed file size in kilobytes */
$file['error'] = sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
}
if ( upload_is_user_over_quota( false ) ) {
@ -53,6 +56,7 @@ function check_upload_size( $file ) {
* Delete a site.
*
* @since 3.0.0
* @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
@ -69,26 +73,6 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
}
$blog = get_site( $blog_id );
/**
* Fires before a site is deleted.
*
* @since MU (3.0.0)
*
* @param int $blog_id The site ID.
* @param bool $drop True if site's table should be dropped. Default is false.
*/
do_action( 'delete_blog', $blog_id, $drop );
$users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
// Remove users from this blog.
if ( ! empty( $users ) ) {
foreach ( $users as $user_id ) {
remove_user_from_blog( $user_id, $blog_id );
}
}
update_blog_status( $blog_id, 'deleted', 1 );
$current_network = get_network();
@ -110,81 +94,34 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
}
if ( $drop ) {
$uploads = wp_get_upload_dir();
wp_delete_site( $blog_id );
} else {
/** This action is documented in wp-includes/ms-blogs.php */
do_action_deprecated( 'delete_blog', array( $blog_id, false ), '5.1.0' );
$tables = $wpdb->tables( 'blog' );
/**
* Filters the tables to drop when the site is deleted.
*
* @since MU (3.0.0)
*
* @param array $tables The site tables to be dropped.
* @param int $blog_id The ID of the site to drop tables for.
*/
$drop_tables = apply_filters( 'wpmu_drop_tables', $tables, $blog_id );
$users = get_users(
array(
'blog_id' => $blog_id,
'fields' => 'ids',
)
);
foreach ( (array) $drop_tables as $table ) {
$wpdb->query( "DROP TABLE IF EXISTS `$table`" );
}
$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
/**
* Filters the upload base directory to delete when the site is deleted.
*
* @since MU (3.0.0)
*
* @param string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir()
* @param int $blog_id The site ID.
*/
$dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id );
$dir = rtrim( $dir, DIRECTORY_SEPARATOR );
$top_dir = $dir;
$stack = array($dir);
$index = 0;
while ( $index < count( $stack ) ) {
// Get indexed directory from stack
$dir = $stack[$index];
$dh = @opendir( $dir );
if ( $dh ) {
while ( ( $file = @readdir( $dh ) ) !== false ) {
if ( $file == '.' || $file == '..' )
continue;
if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) {
$stack[] = $dir . DIRECTORY_SEPARATOR . $file;
} elseif ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) {
@unlink( $dir . DIRECTORY_SEPARATOR . $file );
}
}
@closedir( $dh );
// Remove users from this blog.
if ( ! empty( $users ) ) {
foreach ( $users as $user_id ) {
remove_user_from_blog( $user_id, $blog_id );
}
$index++;
}
$stack = array_reverse( $stack ); // Last added dirs are deepest
foreach ( (array) $stack as $dir ) {
if ( $dir != $top_dir)
@rmdir( $dir );
}
update_blog_status( $blog_id, 'deleted', 1 );
clean_blog_cache( $blog );
/** This action is documented in wp-includes/ms-blogs.php */
do_action_deprecated( 'deleted_blog', array( $blog_id, false ), '5.1.0' );
}
/**
* Fires after the site is deleted from the network.
*
* @since 4.8.0
*
* @param int $blog_id The site ID.
* @param bool $drop True if site's tables should be dropped. Default is false.
*/
do_action( 'deleted_blog', $blog_id, $drop );
if ( $switch )
if ( $switch ) {
restore_current_blog();
}
}
/**
@ -206,11 +143,12 @@ function wpmu_delete_user( $id ) {
return false;
}
$id = (int) $id;
$id = (int) $id;
$user = new WP_User( $id );
if ( !$user->exists() )
if ( ! $user->exists() ) {
return false;
}
// Global super-administrators are protected, and cannot be deleted.
$_super_admins = get_super_admins();
@ -243,8 +181,9 @@ function wpmu_delete_user( $id ) {
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
if ( $link_ids ) {
foreach ( $link_ids as $link_id )
foreach ( $link_ids as $link_id ) {
wp_delete_link( $link_id );
}
}
restore_current_blog();
@ -252,8 +191,9 @@ function wpmu_delete_user( $id ) {
}
$meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
foreach ( $meta as $mid )
foreach ( $meta as $mid ) {
delete_metadata_by_mid( 'user', $mid );
}
$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
@ -274,8 +214,9 @@ function wpmu_delete_user( $id ) {
* @return bool True if user is over upload space quota, otherwise false.
*/
function upload_is_user_over_quota( $echo = true ) {
if ( get_site_option( 'upload_space_check_disabled' ) )
if ( get_site_option( 'upload_space_check_disabled' ) ) {
return false;
}
$space_allowed = get_space_allowed();
if ( ! is_numeric( $space_allowed ) ) {
@ -284,8 +225,9 @@ function upload_is_user_over_quota( $echo = true ) {
$space_used = get_space_used();
if ( ( $space_allowed - $space_used ) < 0 ) {
if ( $echo )
if ( $echo ) {
_e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' );
}
return true;
} else {
return false;
@ -299,7 +241,7 @@ function upload_is_user_over_quota( $echo = true ) {
*/
function display_space_usage() {
$space_allowed = get_space_allowed();
$space_used = get_space_used();
$space_used = get_space_used();
$percent_used = ( $space_used / $space_allowed ) * 100;
@ -313,10 +255,12 @@ function display_space_usage() {
$space .= __( 'MB' );
}
?>
<strong><?php
<strong>
<?php
/* translators: Storage space that's been used. 1: Percentage of used space, 2: Total space allowed in megabytes or gigabytes */
printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space );
?></strong>
?>
</strong>
<?php
}
@ -348,8 +292,9 @@ function upload_space_setting( $id ) {
$quota = get_option( 'blog_upload_space' );
restore_current_blog();
if ( !$quota )
if ( ! $quota ) {
$quota = '';
}
?>
<tr>
@ -381,8 +326,9 @@ function upload_space_setting( $id ) {
function update_user_status( $id, $pref, $value, $deprecated = null ) {
global $wpdb;
if ( null !== $deprecated )
if ( null !== $deprecated ) {
_deprecated_argument( __FUNCTION__, '3.0.2' );
}
$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
@ -425,8 +371,9 @@ function update_user_status( $id, $pref, $value, $deprecated = null ) {
function refresh_user_details( $id ) {
$id = (int) $id;
if ( !$user = get_userdata( $id ) )
if ( ! $user = get_userdata( $id ) ) {
return false;
}
clean_user_cache( $user );
@ -443,43 +390,218 @@ function refresh_user_details( $id ) {
* then the first two letters of $code is returned.
*/
function format_code_lang( $code = '' ) {
$code = strtolower( substr( $code, 0, 2 ) );
$code = strtolower( substr( $code, 0, 2 ) );
$lang_codes = array(
'aa' => 'Afar', 'ab' => 'Abkhazian', 'af' => 'Afrikaans', 'ak' => 'Akan', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'an' => 'Aragonese', 'hy' => 'Armenian', 'as' => 'Assamese', 'av' => 'Avaric', 'ae' => 'Avestan', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'bm' => 'Bambara', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali',
'bh' => 'Bihari', 'bi' => 'Bislama', 'bs' => 'Bosnian', 'br' => 'Breton', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan; Valencian', 'ch' => 'Chamorro', 'ce' => 'Chechen', 'zh' => 'Chinese', 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', 'cv' => 'Chuvash', 'kw' => 'Cornish', 'co' => 'Corsican', 'cr' => 'Cree',
'cs' => 'Czech', 'da' => 'Danish', 'dv' => 'Divehi; Dhivehi; Maldivian', 'nl' => 'Dutch; Flemish', 'dz' => 'Dzongkha', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'ee' => 'Ewe', 'fo' => 'Faroese', 'fj' => 'Fijjian', 'fi' => 'Finnish', 'fr' => 'French', 'fy' => 'Western Frisian', 'ff' => 'Fulah', 'ka' => 'Georgian', 'de' => 'German', 'gd' => 'Gaelic; Scottish Gaelic',
'ga' => 'Irish', 'gl' => 'Galician', 'gv' => 'Manx', 'el' => 'Greek, Modern', 'gn' => 'Guarani', 'gu' => 'Gujarati', 'ht' => 'Haitian; Haitian Creole', 'ha' => 'Hausa', 'he' => 'Hebrew', 'hz' => 'Herero', 'hi' => 'Hindi', 'ho' => 'Hiri Motu', 'hu' => 'Hungarian', 'ig' => 'Igbo', 'is' => 'Icelandic', 'io' => 'Ido', 'ii' => 'Sichuan Yi', 'iu' => 'Inuktitut', 'ie' => 'Interlingue',
'ia' => 'Interlingua (International Auxiliary Language Association)', 'id' => 'Indonesian', 'ik' => 'Inupiaq', 'it' => 'Italian', 'jv' => 'Javanese', 'ja' => 'Japanese', 'kl' => 'Kalaallisut; Greenlandic', 'kn' => 'Kannada', 'ks' => 'Kashmiri', 'kr' => 'Kanuri', 'kk' => 'Kazakh', 'km' => 'Central Khmer', 'ki' => 'Kikuyu; Gikuyu', 'rw' => 'Kinyarwanda', 'ky' => 'Kirghiz; Kyrgyz',
'kv' => 'Komi', 'kg' => 'Kongo', 'ko' => 'Korean', 'kj' => 'Kuanyama; Kwanyama', 'ku' => 'Kurdish', 'lo' => 'Lao', 'la' => 'Latin', 'lv' => 'Latvian', 'li' => 'Limburgan; Limburger; Limburgish', 'ln' => 'Lingala', 'lt' => 'Lithuanian', 'lb' => 'Luxembourgish; Letzeburgesch', 'lu' => 'Luba-Katanga', 'lg' => 'Ganda', 'mk' => 'Macedonian', 'mh' => 'Marshallese', 'ml' => 'Malayalam',
'mi' => 'Maori', 'mr' => 'Marathi', 'ms' => 'Malay', 'mg' => 'Malagasy', 'mt' => 'Maltese', 'mo' => 'Moldavian', 'mn' => 'Mongolian', 'na' => 'Nauru', 'nv' => 'Navajo; Navaho', 'nr' => 'Ndebele, South; South Ndebele', 'nd' => 'Ndebele, North; North Ndebele', 'ng' => 'Ndonga', 'ne' => 'Nepali', 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
'no' => 'Norwegian', 'ny' => 'Chichewa; Chewa; Nyanja', 'oc' => 'Occitan, Provençal', 'oj' => 'Ojibwa', 'or' => 'Oriya', 'om' => 'Oromo', 'os' => 'Ossetian; Ossetic', 'pa' => 'Panjabi; Punjabi', 'fa' => 'Persian', 'pi' => 'Pali', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ps' => 'Pushto', 'qu' => 'Quechua', 'rm' => 'Romansh', 'ro' => 'Romanian', 'rn' => 'Rundi', 'ru' => 'Russian',
'sg' => 'Sango', 'sa' => 'Sanskrit', 'sr' => 'Serbian', 'hr' => 'Croatian', 'si' => 'Sinhala; Sinhalese', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'se' => 'Northern Sami', 'sm' => 'Samoan', 'sn' => 'Shona', 'sd' => 'Sindhi', 'so' => 'Somali', 'st' => 'Sotho, Southern', 'es' => 'Spanish; Castilian', 'sc' => 'Sardinian', 'ss' => 'Swati', 'su' => 'Sundanese', 'sw' => 'Swahili',
'sv' => 'Swedish', 'ty' => 'Tahitian', 'ta' => 'Tamil', 'tt' => 'Tatar', 'te' => 'Telugu', 'tg' => 'Tajik', 'tl' => 'Tagalog', 'th' => 'Thai', 'bo' => 'Tibetan', 'ti' => 'Tigrinya', 'to' => 'Tonga (Tonga Islands)', 'tn' => 'Tswana', 'ts' => 'Tsonga', 'tk' => 'Turkmen', 'tr' => 'Turkish', 'tw' => 'Twi', 'ug' => 'Uighur; Uyghur', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek',
've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
'aa' => 'Afar',
'ab' => 'Abkhazian',
'af' => 'Afrikaans',
'ak' => 'Akan',
'sq' => 'Albanian',
'am' => 'Amharic',
'ar' => 'Arabic',
'an' => 'Aragonese',
'hy' => 'Armenian',
'as' => 'Assamese',
'av' => 'Avaric',
'ae' => 'Avestan',
'ay' => 'Aymara',
'az' => 'Azerbaijani',
'ba' => 'Bashkir',
'bm' => 'Bambara',
'eu' => 'Basque',
'be' => 'Belarusian',
'bn' => 'Bengali',
'bh' => 'Bihari',
'bi' => 'Bislama',
'bs' => 'Bosnian',
'br' => 'Breton',
'bg' => 'Bulgarian',
'my' => 'Burmese',
'ca' => 'Catalan; Valencian',
'ch' => 'Chamorro',
'ce' => 'Chechen',
'zh' => 'Chinese',
'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic',
'cv' => 'Chuvash',
'kw' => 'Cornish',
'co' => 'Corsican',
'cr' => 'Cree',
'cs' => 'Czech',
'da' => 'Danish',
'dv' => 'Divehi; Dhivehi; Maldivian',
'nl' => 'Dutch; Flemish',
'dz' => 'Dzongkha',
'en' => 'English',
'eo' => 'Esperanto',
'et' => 'Estonian',
'ee' => 'Ewe',
'fo' => 'Faroese',
'fj' => 'Fijjian',
'fi' => 'Finnish',
'fr' => 'French',
'fy' => 'Western Frisian',
'ff' => 'Fulah',
'ka' => 'Georgian',
'de' => 'German',
'gd' => 'Gaelic; Scottish Gaelic',
'ga' => 'Irish',
'gl' => 'Galician',
'gv' => 'Manx',
'el' => 'Greek, Modern',
'gn' => 'Guarani',
'gu' => 'Gujarati',
'ht' => 'Haitian; Haitian Creole',
'ha' => 'Hausa',
'he' => 'Hebrew',
'hz' => 'Herero',
'hi' => 'Hindi',
'ho' => 'Hiri Motu',
'hu' => 'Hungarian',
'ig' => 'Igbo',
'is' => 'Icelandic',
'io' => 'Ido',
'ii' => 'Sichuan Yi',
'iu' => 'Inuktitut',
'ie' => 'Interlingue',
'ia' => 'Interlingua (International Auxiliary Language Association)',
'id' => 'Indonesian',
'ik' => 'Inupiaq',
'it' => 'Italian',
'jv' => 'Javanese',
'ja' => 'Japanese',
'kl' => 'Kalaallisut; Greenlandic',
'kn' => 'Kannada',
'ks' => 'Kashmiri',
'kr' => 'Kanuri',
'kk' => 'Kazakh',
'km' => 'Central Khmer',
'ki' => 'Kikuyu; Gikuyu',
'rw' => 'Kinyarwanda',
'ky' => 'Kirghiz; Kyrgyz',
'kv' => 'Komi',
'kg' => 'Kongo',
'ko' => 'Korean',
'kj' => 'Kuanyama; Kwanyama',
'ku' => 'Kurdish',
'lo' => 'Lao',
'la' => 'Latin',
'lv' => 'Latvian',
'li' => 'Limburgan; Limburger; Limburgish',
'ln' => 'Lingala',
'lt' => 'Lithuanian',
'lb' => 'Luxembourgish; Letzeburgesch',
'lu' => 'Luba-Katanga',
'lg' => 'Ganda',
'mk' => 'Macedonian',
'mh' => 'Marshallese',
'ml' => 'Malayalam',
'mi' => 'Maori',
'mr' => 'Marathi',
'ms' => 'Malay',
'mg' => 'Malagasy',
'mt' => 'Maltese',
'mo' => 'Moldavian',
'mn' => 'Mongolian',
'na' => 'Nauru',
'nv' => 'Navajo; Navaho',
'nr' => 'Ndebele, South; South Ndebele',
'nd' => 'Ndebele, North; North Ndebele',
'ng' => 'Ndonga',
'ne' => 'Nepali',
'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian',
'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
'no' => 'Norwegian',
'ny' => 'Chichewa; Chewa; Nyanja',
'oc' => 'Occitan, Provençal',
'oj' => 'Ojibwa',
'or' => 'Oriya',
'om' => 'Oromo',
'os' => 'Ossetian; Ossetic',
'pa' => 'Panjabi; Punjabi',
'fa' => 'Persian',
'pi' => 'Pali',
'pl' => 'Polish',
'pt' => 'Portuguese',
'ps' => 'Pushto',
'qu' => 'Quechua',
'rm' => 'Romansh',
'ro' => 'Romanian',
'rn' => 'Rundi',
'ru' => 'Russian',
'sg' => 'Sango',
'sa' => 'Sanskrit',
'sr' => 'Serbian',
'hr' => 'Croatian',
'si' => 'Sinhala; Sinhalese',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'se' => 'Northern Sami',
'sm' => 'Samoan',
'sn' => 'Shona',
'sd' => 'Sindhi',
'so' => 'Somali',
'st' => 'Sotho, Southern',
'es' => 'Spanish; Castilian',
'sc' => 'Sardinian',
'ss' => 'Swati',
'su' => 'Sundanese',
'sw' => 'Swahili',
'sv' => 'Swedish',
'ty' => 'Tahitian',
'ta' => 'Tamil',
'tt' => 'Tatar',
'te' => 'Telugu',
'tg' => 'Tajik',
'tl' => 'Tagalog',
'th' => 'Thai',
'bo' => 'Tibetan',
'ti' => 'Tigrinya',
'to' => 'Tonga (Tonga Islands)',
'tn' => 'Tswana',
'ts' => 'Tsonga',
'tk' => 'Turkmen',
'tr' => 'Turkish',
'tw' => 'Twi',
'ug' => 'Uighur; Uyghur',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',
've' => 'Venda',
'vi' => 'Vietnamese',
'vo' => 'Volapük',
'cy' => 'Welsh',
'wa' => 'Walloon',
'wo' => 'Wolof',
'xh' => 'Xhosa',
'yi' => 'Yiddish',
'yo' => 'Yoruba',
'za' => 'Zhuang; Chuang',
'zu' => 'Zulu',
);
/**
* Filters the language codes.
*
* @since MU (3.0.0)
*
* @param array $lang_codes Key/value pair of language codes where key is the short version.
* @param string $code A two-letter designation of the language.
* @param string[] $lang_codes Array of key/value pairs of language codes where key is the short version.
* @param string $code A two-letter designation of the language.
*/
$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
return strtr( $code, $lang_codes );
}
/**
* Synchronize category and post tag slugs when global terms are enabled.
* Synchronizes category and post tag slugs when global terms are enabled.
*
* @since 3.0.0
*
* @param object $term The term.
* @param string $taxonomy The taxonomy for `$term`. Should be 'category' or 'post_tag', as these are
* the only taxonomies which are processed by this function; anything else
* will be returned untouched.
* @return object|array Returns `$term`, after filtering the 'slug' field with sanitize_title()
* if $taxonomy is 'category' or 'post_tag'.
* @param WP_Term|array $term The term.
* @param string $taxonomy The taxonomy for `$term`. Should be 'category' or 'post_tag', as these are
* the only taxonomies which are processed by this function; anything else
* will be returned untouched.
* @return WP_Term|array Returns `$term`, after filtering the 'slug' field with `sanitize_title()`
* if `$taxonomy` is 'category' or 'post_tag'.
*/
function sync_category_tag_slugs( $term, $taxonomy ) {
if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
@ -500,30 +622,33 @@ function sync_category_tag_slugs( $term, $taxonomy ) {
* @access private
*/
function _access_denied_splash() {
if ( ! is_user_logged_in() || is_network_admin() )
if ( ! is_user_logged_in() || is_network_admin() ) {
return;
}
$blogs = get_blogs_of_user( get_current_user_id() );
if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) {
return;
}
$blog_name = get_bloginfo( 'name' );
if ( empty( $blogs ) )
if ( empty( $blogs ) ) {
wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ), 403 );
}
$output = '<p>' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>';
$output = '<p>' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>';
$output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>';
$output .= '<h3>' . __('Your Sites') . '</h3>';
$output .= '<h3>' . __( 'Your Sites' ) . '</h3>';
$output .= '<table>';
foreach ( $blogs as $blog ) {
$output .= '<tr>';
$output .= "<td>{$blog->blogname}</td>";
$output .= '<td><a href="' . esc_url( get_admin_url( $blog->userblog_id ) ) . '">' . __( 'Visit Dashboard' ) . '</a> | ' .
'<a href="' . esc_url( get_home_url( $blog->userblog_id ) ). '">' . __( 'View Site' ) . '</a></td>';
'<a href="' . esc_url( get_home_url( $blog->userblog_id ) ) . '">' . __( 'View Site' ) . '</a></td>';
$output .= '</tr>';
}
@ -554,33 +679,33 @@ function check_import_new_users( $permission ) {
*
* @since 3.0.0
*
* @param array $lang_files Optional. An array of the language files. Default empty array.
* @param string $current Optional. The current language code. Default empty.
* @param string[] $lang_files Optional. An array of the language files. Default empty array.
* @param string $current Optional. The current language code. Default empty.
*/
function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
$flag = false;
$flag = false;
$output = array();
foreach ( (array) $lang_files as $val ) {
$code_lang = basename( $val, '.mo' );
if ( $code_lang == 'en_US' ) { // American English
$flag = true;
$ae = __( 'American English' );
$output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
$flag = true;
$ae = __( 'American English' );
$output[ $ae ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
} elseif ( $code_lang == 'en_GB' ) { // British English
$flag = true;
$be = __( 'British English' );
$output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
$flag = true;
$be = __( 'British English' );
$output[ $be ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
} else {
$translated = format_code_lang( $code_lang );
$output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
$translated = format_code_lang( $code_lang );
$output[ $translated ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html( $translated ) . '</option>';
}
}
if ( $flag === false ) // WordPress english
$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
if ( $flag === false ) { // WordPress english
$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . '</option>';
}
// Order by name
uksort( $output, 'strnatcasecmp' );
@ -590,9 +715,9 @@ function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
*
* @since MU (3.0.0)
*
* @param array $output HTML output of the dropdown.
* @param array $lang_files Available language files.
* @param string $current The current language code.
* @param string[] $output Array of HTML output for the dropdown.
* @param string[] $lang_files Array of available language files.
* @param string $current The current language code.
*/
$output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
@ -621,7 +746,7 @@ function site_admin_notice() {
}
if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) {
echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "</div>";
echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . '</div>';
}
}
@ -638,18 +763,22 @@ function site_admin_notice() {
* @return array The new array of post data after checking for collisions.
*/
function avoid_blog_page_permalink_collision( $data, $postarr ) {
if ( is_subdomain_install() )
if ( is_subdomain_install() ) {
return $data;
if ( $data['post_type'] != 'page' )
}
if ( $data['post_type'] != 'page' ) {
return $data;
if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
}
if ( ! isset( $data['post_name'] ) || $data['post_name'] == '' ) {
return $data;
if ( !is_main_site() )
}
if ( ! is_main_site() ) {
return $data;
}
$post_name = $data['post_name'];
$c = 0;
while( $c < 10 && get_id_from_blogname( $post_name ) ) {
$c = 0;
while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
$post_name .= mt_rand( 1, 10 );
$c ++;
}
@ -675,30 +804,36 @@ function choose_primary_blog() {
<th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
<td>
<?php
$all_blogs = get_blogs_of_user( get_current_user_id() );
$all_blogs = get_blogs_of_user( get_current_user_id() );
$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
if ( count( $all_blogs ) > 1 ) {
$found = false;
?>
<select name="primary_blog" id="primary_blog">
<?php foreach ( (array) $all_blogs as $blog ) {
if ( $primary_blog == $blog->userblog_id )
<?php
foreach ( (array) $all_blogs as $blog ) {
if ( $primary_blog == $blog->userblog_id ) {
$found = true;
?><option value="<?php echo $blog->userblog_id ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ) ?></option><?php
} ?>
}
?>
<option value="<?php echo $blog->userblog_id; ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ); ?></option>
<?php
}
?>
</select>
<?php
if ( !$found ) {
if ( ! $found ) {
$blog = reset( $all_blogs );
update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
}
} elseif ( count( $all_blogs ) == 1 ) {
$blog = reset( $all_blogs );
echo esc_url( get_home_url( $blog->userblog_id ) );
if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
if ( $primary_blog != $blog->userblog_id ) { // Set the primary blog again if it's out of sync with blog list.
update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
}
} else {
echo "N/A";
echo 'N/A';
}
?>
</td>
@ -719,10 +854,11 @@ function choose_primary_blog() {
* @return bool True if network can be edited, otherwise false.
*/
function can_edit_network( $network_id ) {
if ( $network_id == get_current_network_id() )
if ( $network_id == get_current_network_id() ) {
$result = true;
else
} else {
$result = false;
}
/**
* Filters whether this network can be edited from this page.
@ -743,15 +879,14 @@ function can_edit_network( $network_id ) {
* @access private
*/
function _thickbox_path_admin_subfolder() {
?>
?>
<script type="text/javascript">
var tb_pathToImage = "<?php echo includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ); ?>";
</script>
<?php
<?php
}
/**
*
* @param array $users
*/
function confirm_delete_users( $users ) {
@ -773,9 +908,11 @@ function confirm_delete_users( $users ) {
<?php
wp_nonce_field( 'ms-users-delete' );
$site_admins = get_super_admins();
$admin_out = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>'; ?>
$admin_out = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>';
?>
<table class="form-table">
<?php foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
<?php
foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
if ( $user_id != '' && $user_id != '0' ) {
$delete_user = get_userdata( $user_id );
@ -791,23 +928,33 @@ function confirm_delete_users( $users ) {
<th scope="row"><?php echo $delete_user->user_login; ?>
<?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
</th>
<?php $blogs = get_blogs_of_user( $user_id, true );
<?php
$blogs = get_blogs_of_user( $user_id, true );
if ( ! empty( $blogs ) ) {
?>
<td><fieldset><p><legend><?php printf(
<td><fieldset><p><legend>
<?php
printf(
/* translators: user login */
__( 'What should be done with content owned by %s?' ),
'<em>' . $delete_user->user_login . '</em>'
); ?></legend></p>
);
?>
</legend></p>
<?php
foreach ( (array) $blogs as $key => $details ) {
$blog_users = get_users( array( 'blog_id' => $details->userblog_id, 'fields' => array( 'ID', 'user_login' ) ) );
if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
$user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
$user_dropdown = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
$blog_users = get_users(
array(
'blog_id' => $details->userblog_id,
'fields' => array( 'ID', 'user_login' ),
)
);
if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
$user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
$user_dropdown = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
$user_list = '';
$user_list = '';
foreach ( $blog_users as $user ) {
if ( ! in_array( $user->ID, $allusers ) ) {
$user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
@ -821,22 +968,22 @@ function confirm_delete_users( $users ) {
?>
<ul style="list-style:none;">
<li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
<li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
<li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="delete" checked="checked" />
<?php _e( 'Delete all content.' ); ?></label></li>
<li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
<li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="reassign" />
<?php _e( 'Attribute all content to:' ); ?></label>
<?php echo $user_dropdown; ?></li>
</ul>
<?php
}
}
echo "</fieldset></td></tr>";
echo '</fieldset></td></tr>';
} else {
?>
<td><fieldset><p><legend><?php _e( 'User has no sites or content and will be deleted.' ); ?></legend></p>
<?php } ?>
</tr>
<?php
<?php
}
}
@ -846,13 +993,15 @@ function confirm_delete_users( $users ) {
/** This action is documented in wp-admin/users.php */
do_action( 'delete_user_form', $current_user, $allusers );
if ( 1 == count( $users ) ) : ?>
if ( 1 == count( $users ) ) :
?>
<p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
<?php else : ?>
<p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, these users will be permanently removed.' ); ?></p>
<?php endif;
<?php
endif;
submit_button( __('Confirm Deletion'), 'primary' );
submit_button( __( 'Confirm Deletion' ), 'primary' );
?>
</form>
<?php
@ -865,7 +1014,7 @@ function confirm_delete_users( $users ) {
* @since 4.1.0
*/
function network_settings_add_js() {
?>
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
var languageSelect = $( '#WPLANG' );
@ -878,7 +1027,7 @@ jQuery(document).ready( function($) {
});
});
</script>
<?php
<?php
}
/**
@ -915,19 +1064,41 @@ function network_edit_site_nav( $args = array() ) {
* }
* }
*/
$links = apply_filters( 'network_edit_site_nav_links', array(
'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php', 'cap' => 'manage_sites' ),
'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php', 'cap' => 'manage_sites' ),
'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php', 'cap' => 'manage_sites' ),
'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php', 'cap' => 'manage_sites' )
) );
$links = apply_filters(
'network_edit_site_nav_links',
array(
'site-info' => array(
'label' => __( 'Info' ),
'url' => 'site-info.php',
'cap' => 'manage_sites',
),
'site-users' => array(
'label' => __( 'Users' ),
'url' => 'site-users.php',
'cap' => 'manage_sites',
),
'site-themes' => array(
'label' => __( 'Themes' ),
'url' => 'site-themes.php',
'cap' => 'manage_sites',
),
'site-settings' => array(
'label' => __( 'Settings' ),
'url' => 'site-settings.php',
'cap' => 'manage_sites',
),
)
);
// Parse arguments
$r = wp_parse_args( $args, array(
'blog_id' => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0,
'links' => $links,
'selected' => 'site-info',
) );
$r = wp_parse_args(
$args,
array(
'blog_id' => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0,
'links' => $links,
'selected' => 'site-info',
)
);
// Setup the links array
$screen_links = array();
@ -974,13 +1145,13 @@ function network_edit_site_nav( $args = array() ) {
function get_site_screen_help_tab_args() {
return array(
'id' => 'overview',
'title' => __('Overview'),
'title' => __( 'Overview' ),
'content' =>
'<p>' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '</p>' .
'<p>' . __('<strong>Info</strong> &mdash; The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '</p>' .
'<p>' . __('<strong>Users</strong> &mdash; This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '</p>' .
'<p>' . sprintf( __('<strong>Themes</strong> &mdash; This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' .
'<p>' . __('<strong>Settings</strong> &mdash; This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '</p>'
'<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
'<p>' . __( '<strong>Info</strong> &mdash; The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' .
'<p>' . __( '<strong>Users</strong> &mdash; This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' .
'<p>' . sprintf( __( '<strong>Themes</strong> &mdash; This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' .
'<p>' . __( '<strong>Settings</strong> &mdash; This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>',
);
}
@ -992,7 +1163,7 @@ function get_site_screen_help_tab_args() {
* @return string Help sidebar content.
*/
function get_site_screen_help_sidebar_content() {
return '<p><strong>' . __('For more information:') . '</strong></p>' .
'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>') . '</p>' .
'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>';
return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>' ) . '</p>' .
'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>';
}

File diff suppressed because it is too large Load diff

View file

@ -14,12 +14,12 @@
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return Whether a network exists.
* @return string|false Base domain if network exists, otherwise false.
*/
function network_domain_check() {
global $wpdb;
$sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) );
$sql = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
if ( $wpdb->get_var( $sql ) ) {
return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
}
@ -34,8 +34,9 @@ function network_domain_check() {
*/
function allow_subdomain_install() {
$domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) {
return false;
}
return true;
}
@ -51,22 +52,25 @@ function allow_subdomain_install() {
*/
function allow_subdirectory_install() {
global $wpdb;
/**
* Filters whether to enable the subdirectory installation feature in Multisite.
*
* @since 3.0.0
*
* @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false.
*/
if ( apply_filters( 'allow_subdirectory_install', false ) )
/**
* Filters whether to enable the subdirectory installation feature in Multisite.
*
* @since 3.0.0
*
* @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false.
*/
if ( apply_filters( 'allow_subdirectory_install', false ) ) {
return true;
}
if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL )
if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) {
return true;
}
$post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" );
if ( empty( $post ) )
if ( empty( $post ) ) {
return true;
}
return false;
}
@ -78,11 +82,13 @@ function allow_subdirectory_install() {
* @return string Base domain.
*/
function get_clean_basedomain() {
if ( $existing_domain = network_domain_check() )
if ( $existing_domain = network_domain_check() ) {
return $existing_domain;
}
$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
if ( $slash = strpos( $domain, '/' ) )
if ( $slash = strpos( $domain, '/' ) ) {
$domain = substr( $domain, 0, $slash );
}
return $domain;
}
@ -90,7 +96,7 @@ function get_clean_basedomain() {
* Prints step 1 for Network installation process.
*
* @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
* should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
* should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
*
* @since 3.0.0
*
@ -101,7 +107,7 @@ function get_clean_basedomain() {
function network_step1( $errors = false ) {
global $is_apache;
if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . sprintf(
/* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
__( 'The constant %s cannot be defined when creating a network.' ),
@ -125,7 +131,7 @@ function network_step1( $errors = false ) {
die();
}
$hostname = get_clean_basedomain();
$hostname = get_clean_basedomain();
$has_ports = strstr( $hostname, ':' );
if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
@ -147,8 +153,9 @@ function network_step1( $errors = false ) {
$error_codes = array();
if ( is_wp_error( $errors ) ) {
echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>';
foreach ( $errors->get_error_messages() as $error )
foreach ( $errors->get_error_messages() as $error ) {
echo "<p>$error</p>";
}
echo '</div>';
$error_codes = $errors->get_error_codes();
}
@ -172,23 +179,25 @@ function network_step1( $errors = false ) {
if ( isset( $_POST['subdomain_install'] ) ) {
$subdomain_install = (bool) $_POST['subdomain_install'];
} elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing
} elseif ( apache_mod_loaded( 'mod_rewrite' ) ) { // assume nothing
$subdomain_install = true;
} elseif ( !allow_subdirectory_install() ) {
} elseif ( ! allow_subdirectory_install() ) {
$subdomain_install = true;
} else {
$subdomain_install = false;
if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions
echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ';
/* translators: %s: mod_rewrite */
printf( __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
printf(
__( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
'<code>mod_rewrite</code>'
);
echo '</p>';
} elseif ( $is_apache ) {
echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ';
/* translators: %s: mod_rewrite */
printf( __( 'It looks like the Apache %s module is not installed.' ),
printf(
__( 'It looks like the Apache %s module is not installed.' ),
'<code>mod_rewrite</code>'
);
echo '</p>';
@ -197,7 +206,8 @@ function network_step1( $errors = false ) {
if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache)
echo '<p>';
/* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite */
printf( __( 'If %1$s is disabled, ask your administrator to enable that module, or look at the <a href="%2$s">Apache documentation</a> or <a href="%3$s">elsewhere</a> for help setting it up.' ),
printf(
__( 'If %1$s is disabled, ask your administrator to enable that module, or look at the <a href="%2$s">Apache documentation</a> or <a href="%3$s">elsewhere</a> for help setting it up.' ),
'<code>mod_rewrite</code>',
'https://httpd.apache.org/docs/mod/mod_rewrite.html',
'https://www.google.com/search?q=apache+mod_rewrite'
@ -206,7 +216,8 @@ function network_step1( $errors = false ) {
}
}
if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>
if ( allow_subdomain_install() && allow_subdirectory_install() ) :
?>
<h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
<p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories.' ); ?>
<strong><?php _e( 'You cannot change this later.' ); ?></strong></p>
@ -215,48 +226,63 @@ function network_step1( $errors = false ) {
<table class="form-table">
<tr>
<th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
<td><?php printf(
<td>
<?php
printf(
/* translators: 1: hostname */
_x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ),
$hostname
); ?></td>
);
?>
</td>
</tr>
<tr>
<th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
<td><?php printf(
<td>
<?php
printf(
/* translators: 1: hostname */
_x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ),
$hostname
); ?></td>
);
?>
</td>
</tr>
</table>
<?php
<?php
endif;
if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) )
echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) ) {
echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
}
$is_www = ( 0 === strpos( $hostname, 'www.' ) );
if ( $is_www ) :
if ( $is_www ) :
?>
<h3><?php esc_html_e( 'Server Address' ); ?></h3>
<p><?php printf(
/* translators: 1: site url 2: host name 3. www */
<p>
<?php
printf(
/* translators: 1: site url, 2: host name, 3: www */
__( 'We recommend you change your siteurl to %1$s before enabling the network feature. It will still be possible to visit your site using the %3$s prefix with an address like %2$s but any links will not have the %3$s prefix.' ),
'<code>' . substr( $hostname, 4 ) . '</code>',
'<code>' . $hostname . '</code>',
'<code>www</code>'
); ?></p>
);
?>
</p>
<table class="form-table">
<tr>
<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
<td>
<?php printf(
<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
<td>
<?php
printf(
/* translators: %s: host name */
__( 'The internet address of your network will be %s.' ),
'<code>' . $hostname . '</code>'
); ?>
);
?>
</td>
</tr>
</table>
@ -267,45 +293,56 @@ function network_step1( $errors = false ) {
<?php if ( 'localhost' == $hostname ) : ?>
<tr>
<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
<td><?php
<td>
<?php
printf(
/* translators: 1: localhost 2: localhost.localdomain */
/* translators: 1: localhost, 2: localhost.localdomain */
__( 'Because you are using %1$s, the sites in your WordPress network must use sub-directories. Consider using %2$s if you wish to use sub-domains.' ),
'<code>localhost</code>',
'<code>localhost.localdomain</code>'
);
// Uh oh:
if ( !allow_subdirectory_install() )
echo ' <strong>' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
?></td>
if ( ! allow_subdirectory_install() ) {
echo ' <strong>' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
}
?>
</td>
</tr>
<?php elseif ( !allow_subdomain_install() ) : ?>
<?php elseif ( ! allow_subdomain_install() ) : ?>
<tr>
<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
<td><?php
<td>
<?php
_e( 'Because your installation is in a directory, the sites in your WordPress network must use sub-directories.' );
// Uh oh:
if ( !allow_subdirectory_install() )
echo ' <strong>' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
?></td>
if ( ! allow_subdirectory_install() ) {
echo ' <strong>' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
}
?>
</td>
</tr>
<?php elseif ( !allow_subdirectory_install() ) : ?>
<?php elseif ( ! allow_subdirectory_install() ) : ?>
<tr>
<th scope="row"><?php esc_html_e( 'Sub-domain Installation' ); ?></th>
<td><?php _e( 'Because your installation is not new, the sites in your WordPress network must use sub-domains.' );
<td>
<?php
_e( 'Because your installation is not new, the sites in your WordPress network must use sub-domains.' );
echo ' <strong>' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
?></td>
?>
</td>
</tr>
<?php endif; ?>
<?php if ( ! $is_www ) : ?>
<tr>
<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
<td>
<?php printf(
<?php
printf(
/* translators: %s: host name */
__( 'The internet address of your network will be %s.' ),
'<code>' . $hostname . '</code>'
); ?>
);
?>
</td>
</tr>
<?php endif; ?>
@ -354,7 +391,6 @@ function network_step2( $errors = false ) {
$wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
$rewrite_base = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
$location_of_wp_config = $abspath_fix;
if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
$location_of_wp_config = dirname( $abspath_fix );
@ -362,26 +398,28 @@ function network_step2( $errors = false ) {
$location_of_wp_config = trailingslashit( $location_of_wp_config );
// Wildcard DNS message.
if ( is_wp_error( $errors ) )
if ( is_wp_error( $errors ) ) {
echo '<div class="error">' . $errors->get_error_message() . '</div>';
}
if ( $_POST ) {
if ( allow_subdomain_install() )
if ( allow_subdomain_install() ) {
$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
else
} else {
$subdomain_install = false;
}
} else {
if ( is_multisite() ) {
$subdomain_install = is_subdomain_install();
?>
?>
<p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p>
<?php
<?php
} else {
$subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
?>
?>
<div class="error"><p><strong><?php _e( 'Warning:' ); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
<p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p>
<?php
<?php
}
}
@ -390,41 +428,45 @@ function network_step2( $errors = false ) {
$subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
if ( $_POST || ! is_multisite() ) {
?>
?>
<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
<div class="updated inline"><p><?php
if ( file_exists( $home_path . '.htaccess' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: 1: wp-config.php 2: .htaccess */
__( 'We recommend you back up your existing %1$s and %2$s files.' ),
'<code>wp-config.php</code>',
'<code>.htaccess</code>'
);
} elseif ( file_exists( $home_path . 'web.config' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: 1: wp-config.php 2: web.config */
__( 'We recommend you back up your existing %1$s and %2$s files.' ),
'<code>wp-config.php</code>',
'<code>web.config</code>'
);
} else {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: 1: wp-config.php */
__( 'We recommend you back up your existing %s file.' ),
'<code>wp-config.php</code>'
);
}
?></p></div>
<?php
<div class="updated inline"><p>
<?php
if ( file_exists( $home_path . '.htaccess' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: 1: wp-config.php, 2: .htaccess */
__( 'We recommend you back up your existing %1$s and %2$s files.' ),
'<code>wp-config.php</code>',
'<code>.htaccess</code>'
);
} elseif ( file_exists( $home_path . 'web.config' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: 1: wp-config.php, 2: web.config */
__( 'We recommend you back up your existing %1$s and %2$s files.' ),
'<code>wp-config.php</code>',
'<code>web.config</code>'
);
} else {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: %s: wp-config.php */
__( 'We recommend you back up your existing %s file.' ),
'<code>wp-config.php</code>'
);
}
?>
</p></div>
<?php
}
?>
?>
<ol>
<li><p><?php printf(
/* translators: 1: wp-config.php 2: location of wp-config file, 3: translated version of "That's all, stop editing! Happy blogging." */
<li><p>
<?php
printf(
/* translators: 1: wp-config.php, 2: location of wp-config file, 3: translated version of "That's all, stop editing! Happy publishing." */
__( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ),
'<code>wp-config.php</code>',
'<code>' . $location_of_wp_config . '</code>',
@ -433,8 +475,10 @@ function network_step2( $errors = false ) {
* You can check the localized release package or
* https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
*/
'<code>/* ' . __( 'That&#8217;s all, stop editing! Happy blogging.' ) . ' */</code>'
); ?></p>
'<code>/* ' . __( 'That&#8217;s all, stop editing! Happy publishing.' ) . ' */</code>'
);
?>
</p>
<textarea class="code" readonly="readonly" cols="100" rows="7">
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
@ -443,16 +487,26 @@ define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
</textarea>
<?php
$keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
<?php
$keys_salts = array(
'AUTH_KEY' => '',
'SECURE_AUTH_KEY' => '',
'LOGGED_IN_KEY' => '',
'NONCE_KEY' => '',
'AUTH_SALT' => '',
'SECURE_AUTH_SALT' => '',
'LOGGED_IN_SALT' => '',
'NONCE_SALT' => '',
);
foreach ( $keys_salts as $c => $v ) {
if ( defined( $c ) )
if ( defined( $c ) ) {
unset( $keys_salts[ $c ] );
}
}
if ( ! empty( $keys_salts ) ) {
$keys_salts_str = '';
$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
if ( is_wp_error( $from_api ) ) {
foreach ( $keys_salts as $c => $v ) {
$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
@ -464,35 +518,35 @@ define('BLOG_ID_CURRENT_SITE', 1);
}
}
$num_keys_salts = count( $keys_salts );
?>
<p>
?>
<p>
<?php
if ( 1 == $num_keys_salts ) {
printf(
/* translators: 1: wp-config.php */
__( 'This unique authentication key is also missing from your %s file.' ),
'<code>wp-config.php</code>'
);
} else {
printf(
/* translators: 1: wp-config.php */
__( 'These unique authentication keys are also missing from your %s file.' ),
'<code>wp-config.php</code>'
);
}
if ( 1 == $num_keys_salts ) {
printf(
/* translators: %s: wp-config.php */
__( 'This unique authentication key is also missing from your %s file.' ),
'<code>wp-config.php</code>'
);
} else {
printf(
/* translators: %s: wp-config.php */
__( 'These unique authentication keys are also missing from your %s file.' ),
'<code>wp-config.php</code>'
);
}
?>
<?php _e( 'To make your installation more secure, you should also add:' ); ?>
</p>
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
<?php
<?php
}
?>
?>
</li>
<?php
<?php
if ( iis7_supports_permalinks() ) :
// IIS doesn't support RewriteBase, all your RewriteBase are belong to us
$iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
$iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
$iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
$iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
@ -504,14 +558,14 @@ define('BLOG_ID_CURRENT_SITE', 1);
<match url="^index\.php$" ignoreCase="false" />
<action type="None" />
</rule>';
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
$web_config_file .= '
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
$web_config_file .= '
<rule name="WordPress Rule for Files" stopProcessing="true">
<match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
<action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" />
</rule>';
}
$web_config_file .= '
}
$web_config_file .= '
<rule name="WordPress Rule 2" stopProcessing="true">
<match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" />
<action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" />
@ -542,26 +596,28 @@ define('BLOG_ID_CURRENT_SITE', 1);
</configuration>
';
echo '<li><p>';
printf(
/* translators: 1: a filename like .htaccess. 2: a file path. */
__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
'<code>web.config</code>',
'<code>' . $home_path . '</code>'
);
echo '<li><p>';
printf(
/* translators: 1: a filename like .htaccess, 2: a file path */
__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
'<code>web.config</code>',
'<code>' . $home_path . '</code>'
);
echo '</p>';
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) {
echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
}
?>
<textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
<textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
</textarea></li>
</ol>
<?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
<?php
else : // end iis7_supports_permalinks(). construct an htaccess file instead:
$ms_files_rewriting = '';
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
$ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
$ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
}
@ -584,23 +640,26 @@ EOF;
echo '<li><p>';
printf(
/* translators: 1: a filename like .htaccess. 2: a file path. */
/* translators: 1: a filename like .htaccess, 2: a file path */
__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
'<code>.htaccess</code>',
'<code>' . $home_path . '</code>'
);
echo '</p>';
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) {
echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
}
?>
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>">
<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
</ol>
<?php endif; // end IIS/Apache code branches.
<?php
endif; // end IIS/Apache code branches.
if ( !is_multisite() ) { ?>
if ( ! is_multisite() ) {
?>
<p><?php _e( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ); ?> <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log In' ); ?></a></p>
<?php
<?php
}
}

View file

@ -65,7 +65,8 @@ function get_bloginfo() {}
/**
* @ignore
*/
function is_admin() {return true;}
function is_admin() {
return true;}
/**
* @ignore
@ -93,15 +94,15 @@ function includes_url() {}
function wp_guess_url() {}
if ( ! function_exists( 'json_encode' ) ) :
/**
* @ignore
*/
function json_encode() {}
/**
* @ignore
*/
function json_encode() {}
endif;
function get_file( $path ) {
if ( function_exists('realpath') ) {
if ( function_exists( 'realpath' ) ) {
$path = realpath( $path );
}
@ -110,4 +111,4 @@ function get_file( $path ) {
}
return @file_get_contents( $path );
}
}

View file

@ -13,7 +13,7 @@
* @since 4.2.0
*/
function options_discussion_add_js() {
?>
?>
<script>
(function($){
var parent = $( '#show_avatars' ),
@ -23,7 +23,7 @@ function options_discussion_add_js() {
});
})(jQuery);
</script>
<?php
<?php
}
/**
@ -32,7 +32,7 @@ function options_discussion_add_js() {
* @since 3.5.0
*/
function options_general_add_js() {
?>
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
@ -88,7 +88,7 @@ function options_general_add_js() {
});
});
</script>
<?php
<?php
}
/**
@ -97,7 +97,7 @@ function options_general_add_js() {
* @since 3.5.0
*/
function options_reading_add_js() {
?>
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var section = $('#front-static-pages'),
@ -107,10 +107,10 @@ function options_reading_add_js() {
selects.prop( 'disabled', ! staticPage.prop('checked') );
};
check_disabled();
section.find('input:radio').change(check_disabled);
section.find('input:radio').change(check_disabled);
});
</script>
<?php
<?php
}
/**

View file

@ -99,19 +99,27 @@
* for more information on the make-up of possible return values depending on the value of `$action`.
*/
function plugins_api( $action, $args = array() ) {
// include an unmodified $wp_version
include( ABSPATH . WPINC . '/version.php' );
if ( is_array( $args ) ) {
$args = (object) $args;
}
if ( ! isset( $args->per_page ) ) {
$args->per_page = 24;
if ( 'query_plugins' == $action ) {
if ( ! isset( $args->per_page ) ) {
$args->per_page = 24;
}
}
if ( ! isset( $args->locale ) ) {
$args->locale = get_user_locale();
}
if ( ! isset( $args->wp_version ) ) {
$args->wp_version = substr( $wp_version, 0, 3 ); // X.y
}
/**
* Filters the WordPress.org Plugin Installation API arguments.
*
@ -141,22 +149,26 @@ function plugins_api( $action, $args = array() ) {
$res = apply_filters( 'plugins_api', false, $action, $args );
if ( false === $res ) {
// include an unmodified $wp_version
include( ABSPATH . WPINC . '/version.php' );
$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
$url = 'http://api.wordpress.org/plugins/info/1.2/';
$url = add_query_arg(
array(
'action' => $action,
'request' => $args,
),
$url
);
$http_url = $url;
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$http_args = array(
'timeout' => 15,
'timeout' => 15,
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
'body' => array(
'action' => $action,
'request' => serialize( $args )
)
);
$request = wp_remote_post( $url, $http_args );
$request = wp_remote_get( $url, $http_args );
if ( $ssl && is_wp_error( $request ) ) {
trigger_error(
@ -167,11 +179,12 @@ function plugins_api( $action, $args = array() ) {
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
$request = wp_remote_post( $http_url, $http_args );
$request = wp_remote_get( $http_url, $http_args );
}
if ( is_wp_error($request) ) {
$res = new WP_Error( 'plugins_api_failed',
if ( is_wp_error( $request ) ) {
$res = new WP_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -180,9 +193,13 @@ function plugins_api( $action, $args = array() ) {
$request->get_error_message()
);
} else {
$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
if ( ! is_object( $res ) && ! is_array( $res ) ) {
$res = new WP_Error( 'plugins_api_failed',
$res = json_decode( wp_remote_retrieve_body( $request ), true );
if ( is_array( $res ) ) {
// Object casting is required in order to match the info/1.0 format.
$res = (object) $res;
} elseif ( null === $res ) {
$res = new WP_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -191,8 +208,12 @@ function plugins_api( $action, $args = array() ) {
wp_remote_retrieve_body( $request )
);
}
if ( isset( $res->error ) ) {
$res = new WP_Error( 'plugins_api_failed', $res->error );
}
}
} elseif ( !is_wp_error($res) ) {
} elseif ( ! is_wp_error( $res ) ) {
$res->external = true;
}
@ -217,14 +238,16 @@ function plugins_api( $action, $args = array() ) {
* @return array
*/
function install_popular_tags( $args = array() ) {
$key = md5(serialize($args));
if ( false !== ($tags = get_site_transient('poptags_' . $key) ) )
$key = md5( serialize( $args ) );
if ( false !== ( $tags = get_site_transient( 'poptags_' . $key ) ) ) {
return $tags;
}
$tags = plugins_api('hot_tags', $args);
$tags = plugins_api( 'hot_tags', $args );
if ( is_wp_error($tags) )
if ( is_wp_error( $tags ) ) {
return $tags;
}
set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
@ -241,30 +264,36 @@ function install_dashboard() {
<?php display_plugins_table(); ?>
<div class="plugins-popular-tags-wrapper">
<h2><?php _e( 'Popular tags' ) ?></h2>
<p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ) ?></p>
<h2><?php _e( 'Popular tags' ); ?></h2>
<p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p>
<?php
$api_tags = install_popular_tags();
echo '<p class="popular-tags">';
if ( is_wp_error($api_tags) ) {
if ( is_wp_error( $api_tags ) ) {
echo $api_tags->get_error_message();
} else {
//Set up the tags in a way which can be interpreted by wp_generate_tag_cloud()
$tags = array();
foreach ( (array) $api_tags as $tag ) {
$url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
$data = array(
'link' => esc_url( $url ),
'name' => $tag['name'],
'slug' => $tag['slug'],
'id' => sanitize_title_with_dashes( $tag['name'] ),
'count' => $tag['count']
$url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
$data = array(
'link' => esc_url( $url ),
'name' => $tag['name'],
'slug' => $tag['slug'],
'id' => sanitize_title_with_dashes( $tag['name'] ),
'count' => $tag['count'],
);
$tags[ $tag['name'] ] = (object) $data;
}
echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin'), 'multiple_text' => __('%s plugins') ) );
echo wp_generate_tag_cloud(
$tags,
array(
'single_text' => __( '%s plugin' ),
'multiple_text' => __( '%s plugins' ),
)
);
}
echo '</p><br class="clear" /></div>';
}
@ -280,7 +309,8 @@ function install_dashboard() {
function install_search_form( $deprecated = true ) {
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
?><form class="search-form search-plugins" method="get">
?>
<form class="search-form search-plugins" method="get">
<input type="hidden" name="tab" value="search" />
<label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label>
<select name="type" id="typeselector">
@ -289,34 +319,36 @@ function install_search_form( $deprecated = true ) {
<option value="tag"<?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Plugin Installer' ); ?></option>
</select>
<label><span class="screen-reader-text"><?php _e( 'Search Plugins' ); ?></span>
<input type="search" name="s" value="<?php echo esc_attr( $term ) ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />
<input type="search" name="s" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />
</label>
<?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?>
</form><?php
</form>
<?php
}
/**
* Upload from zip
*
* @since 2.8.0
*/
function install_plugins_upload() {
?>
?>
<div class="upload-plugin">
<p class="install-help"><?php _e('If you have a plugin in a .zip format, you may install it by uploading it here.'); ?></p>
<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-plugin'); ?>">
<p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install it by uploading it here.' ); ?></p>
<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>">
<?php wp_nonce_field( 'plugin-upload' ); ?>
<label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label>
<input type="file" id="pluginzip" name="pluginzip" />
<?php submit_button( __( 'Install Now' ), '', 'install-plugin-submit', false ); ?>
</form>
</div>
<?php
<?php
}
/**
* Show a username form for the favorites page
* @since 3.5.0
*
* @since 3.5.0
*/
function install_plugins_favorites_form() {
$user = get_user_option( 'wporg_favorites' );
@ -346,15 +378,15 @@ function display_plugins_table() {
global $wp_list_table;
switch ( current_filter() ) {
case 'install_plugins_favorites' :
case 'install_plugins_favorites':
if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
return;
}
break;
case 'install_plugins_recommended' :
case 'install_plugins_recommended':
echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
break;
case 'install_plugins_beta' :
case 'install_plugins_beta':
printf(
'<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>',
'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/'
@ -385,30 +417,32 @@ function display_plugins_table() {
* @type string $file Plugin filename relative to the plugins directory.
* }
*/
function install_plugin_install_status($api, $loop = false) {
function install_plugin_install_status( $api, $loop = false ) {
// This function is called recursively, $loop prevents further loops.
if ( is_array($api) )
if ( is_array( $api ) ) {
$api = (object) $api;
}
// Default to a "new" plugin
$status = 'install';
$url = false;
$status = 'install';
$url = false;
$update_file = false;
$version = '';
$version = '';
/*
* Check to see if this plugin is known to be installed,
* and has an update awaiting it.
*/
$update_plugins = get_site_transient('update_plugins');
$update_plugins = get_site_transient( 'update_plugins' );
if ( isset( $update_plugins->response ) ) {
foreach ( (array)$update_plugins->response as $file => $plugin ) {
foreach ( (array) $update_plugins->response as $file => $plugin ) {
if ( $plugin->slug === $api->slug ) {
$status = 'update_available';
$status = 'update_available';
$update_file = $file;
$version = $plugin->new_version;
if ( current_user_can('update_plugins') )
$url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
$version = $plugin->new_version;
if ( current_user_can( 'update_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file );
}
break;
}
}
@ -416,36 +450,39 @@ function install_plugin_install_status($api, $loop = false) {
if ( 'install' == $status ) {
if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
$installed_plugin = get_plugins('/' . $api->slug);
if ( empty($installed_plugin) ) {
if ( current_user_can('install_plugins') )
$url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
$installed_plugin = get_plugins( '/' . $api->slug );
if ( empty( $installed_plugin ) ) {
if ( current_user_can( 'install_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
}
} else {
$key = array_keys( $installed_plugin );
$key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
$key = array_keys( $installed_plugin );
$key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
$update_file = $api->slug . '/' . $key;
if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){
if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) {
$status = 'latest_installed';
} elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
$status = 'newer_installed';
} elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) {
$status = 'newer_installed';
$version = $installed_plugin[ $key ]['Version'];
} else {
//If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
if ( ! $loop ) {
delete_site_transient('update_plugins');
delete_site_transient( 'update_plugins' );
wp_update_plugins();
return install_plugin_install_status($api, true);
return install_plugin_install_status( $api, true );
}
}
}
} else {
// "install" & no directory with that slug
if ( current_user_can('install_plugins') )
$url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
if ( current_user_can( 'install_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
}
}
}
if ( isset($_GET['from']) )
if ( isset( $_GET['from'] ) ) {
$url .= '&amp;from=' . urlencode( wp_unslash( $_GET['from'] ) );
}
$file = $update_file;
return compact( 'status', 'url', 'version', 'file' );
@ -465,45 +502,63 @@ function install_plugin_information() {
return;
}
$api = plugins_api( 'plugin_information', array(
'slug' => wp_unslash( $_REQUEST['plugin'] ),
'is_ssl' => is_ssl(),
'fields' => array(
'banners' => true,
'reviews' => true,
'downloaded' => false,
'active_installs' => true
$api = plugins_api(
'plugin_information',
array(
'slug' => wp_unslash( $_REQUEST['plugin'] ),
)
) );
);
if ( is_wp_error( $api ) ) {
wp_die( $api );
}
$plugins_allowedtags = array(
'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),
'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ),
'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ),
'p' => array(), 'br' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'div' => array( 'class' => array() ),
'span' => array( 'class' => array() ),
'p' => array(),
'br' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'h1' => array(),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'h6' => array(),
'img' => array(
'src' => array(),
'class' => array(),
'alt' => array(),
),
'blockquote' => array( 'cite' => true ),
);
$plugins_section_titles = array(
'description' => _x( 'Description', 'Plugin installer section title' ),
'description' => _x( 'Description', 'Plugin installer section title' ),
'installation' => _x( 'Installation', 'Plugin installer section title' ),
'faq' => _x( 'FAQ', 'Plugin installer section title' ),
'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
'other_notes' => _x( 'Other Notes', 'Plugin installer section title' )
'faq' => _x( 'FAQ', 'Plugin installer section title' ),
'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
);
// Sanitize HTML
foreach ( (array) $api->sections as $section_name => $content ) {
$api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
$api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags );
}
foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
@ -517,7 +572,7 @@ function install_plugin_information() {
$section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
$section_titles = array_keys( (array) $api->sections );
$section = reset( $section_titles );
$section = reset( $section_titles );
}
iframe_header( __( 'Plugin Installation' ) );
@ -526,8 +581,8 @@ function install_plugin_information() {
if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
$_with_banner = 'with-banner';
$low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
$high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
$low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
$high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
?>
<style type="text/css">
#plugin-information-title.with-banner {
@ -557,9 +612,14 @@ function install_plugin_information() {
$title = ucwords( str_replace( '_', ' ', $section_name ) );
}
$class = ( $section_name === $section ) ? ' class="current"' : '';
$href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
$href = esc_url( $href );
$class = ( $section_name === $section ) ? ' class="current"' : '';
$href = add_query_arg(
array(
'tab' => $tab,
'section' => $section_name,
)
);
$href = esc_url( $href );
$san_section = esc_attr( $section_name );
echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
}
@ -600,15 +660,21 @@ function install_plugin_information() {
?>
</li>
<?php } if ( isset( $api->active_installs ) ) { ?>
<li><strong><?php _e( 'Active Installations:' ); ?></strong> <?php
if ( $api->active_installs >= 1000000 ) {
_ex( '1+ Million', 'Active plugin installations' );
} elseif ( 0 == $api->active_installs ) {
_ex( 'Less Than 10', 'Active plugin installations' );
} else {
echo number_format_i18n( $api->active_installs ) . '+';
}
?></li>
<li><strong><?php _e( 'Active Installations:' ); ?></strong>
<?php
if ( $api->active_installs >= 1000000 ) {
$active_installs_millions = floor( $api->active_installs / 1000000 );
printf(
_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
number_format_i18n( $active_installs_millions )
);
} elseif ( 0 == $api->active_installs ) {
_ex( 'Less Than 10', 'Active plugin installations' );
} else {
echo number_format_i18n( $api->active_installs ) . '+';
}
?>
</li>
<?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
<li><a target="_blank" href="<?php echo __( 'https://wordpress.org/plugins/' ) . $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a></li>
<?php } if ( ! empty( $api->homepage ) ) { ?>
@ -619,11 +685,21 @@ function install_plugin_information() {
</ul>
<?php if ( ! empty( $api->rating ) ) { ?>
<h3><?php _e( 'Average Rating' ); ?></h3>
<?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?>
<?php
wp_star_rating(
array(
'rating' => $api->rating,
'type' => 'percent',
'number' => $api->num_ratings,
)
);
?>
<p aria-hidden="true" class="fyi-description"><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></p>
<?php }
<?php
}
if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { ?>
if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
?>
<h3><?php _e( 'Reviews' ); ?></h3>
<p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p>
<?php
@ -631,14 +707,19 @@ function install_plugin_information() {
// Avoid div-by-zero.
$_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
/* translators: 1: number of stars (used to determine singular/plural), 2: number of reviews */
$aria_label = esc_attr( sprintf( _n( 'Reviews with %1$d star: %2$s. Opens in a new window.', 'Reviews with %1$d stars: %2$s. Opens in a new window.', $key ),
$key,
number_format_i18n( $ratecount )
) );
$aria_label = esc_attr(
sprintf(
_n( 'Reviews with %1$d star: %2$s. Opens in a new tab.', 'Reviews with %1$d stars: %2$s. Opens in a new tab.', $key ),
$key,
number_format_i18n( $ratecount )
)
);
?>
<div class="counter-container">
<span class="counter-label"><a href="https://wordpress.org/support/plugin/<?php echo $api->slug; ?>/reviews/?filter=<?php echo $key; ?>"
target="_blank" aria-label="<?php echo $aria_label; ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
<span class="counter-label">
<a href="https://wordpress.org/support/plugin/<?php echo $api->slug; ?>/reviews/?filter=<?php echo $key; ?>"
target="_blank" aria-label="<?php echo $aria_label; ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a>
</span>
<span class="counter-back">
<span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
</span>
@ -647,39 +728,70 @@ function install_plugin_information() {
<?php
}
}
if ( ! empty( $api->contributors ) ) { ?>
if ( ! empty( $api->contributors ) ) {
?>
<h3><?php _e( 'Contributors' ); ?></h3>
<ul class="contributors">
<?php
foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
continue;
}
if ( empty( $contrib_username ) ) {
$contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
}
$contrib_username = sanitize_user( $contrib_username );
if ( empty( $contrib_profile ) ) {
echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</li>";
} else {
echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</a></li>";
foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) {
$contrib_name = $contrib_details['display_name'];
if ( ! $contrib_name ) {
$contrib_name = $contrib_username;
}
$contrib_name = esc_html( $contrib_name );
$contrib_profile = esc_url( $contrib_details['profile'] );
$contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) );
echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>";
}
?>
</ul>
<?php if ( ! empty( $api->donate_link ) ) { ?>
<?php if ( ! empty( $api->donate_link ) ) { ?>
<a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<div id="section-holder" class="wrap">
<?php
$wp_version = get_bloginfo( 'version' );
if ( ! empty( $api->tested ) && version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.' ) . '</p></div>';
} elseif ( ! empty( $api->requires ) && version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.' ) . '</p></div>';
$compatible_php = ( empty( $api->requires_php ) || version_compare( phpversion(), $api->requires_php, '>=' ) );
$tested_wp = ( empty( $api->tested ) || version_compare( $wp_version, $api->tested, '<=' ) );
$compatible_wp = ( empty( $api->requires ) || version_compare( $wp_version, $api->requires, '>=' ) );
if ( ! $compatible_php ) {
echo '<div class="notice notice-error notice-alt"><p>';
_e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
if ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: "Update PHP" page URL */
' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
echo '</p>';
wp_update_php_annotation();
} else {
echo '</p>';
}
echo '</div>';
}
if ( ! $tested_wp ) {
echo '<div class="notice notice-warning notice-alt"><p>';
_e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' );
echo '</p></div>';
} elseif ( ! $compatible_wp ) {
echo '<div class="notice notice-error notice-alt"><p>';
_e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
echo '</p></div>';
}
foreach ( (array) $api->sections as $section_name => $content ) {
@ -703,17 +815,24 @@ function install_plugin_information() {
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
if ( $compatible_php && $compatible_wp ) {
echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
} else {
printf(
'<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
_x( 'Cannot Install', 'plugin' )
);
}
}
break;
case 'update_available':
if ( $status['url'] ) {
echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
}
break;
case 'newer_installed':
/* translators: %s: Plugin version */
echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed'), $status['version'] ) . '</a>';
echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
break;
case 'latest_installed':
echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -20,38 +20,45 @@
* Or, false on failure.
*/
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
if ( ! $post = get_post( $post ) )
if ( ! $post = get_post( $post ) ) {
return false;
}
if ( $compare_from ) {
if ( ! $compare_from = get_post( $compare_from ) )
if ( ! $compare_from = get_post( $compare_from ) ) {
return false;
}
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if ( ! $compare_to = get_post( $compare_to ) )
if ( ! $compare_to = get_post( $compare_to ) ) {
return false;
}
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID )
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) {
return false;
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID )
}
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) {
return false;
}
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
$temp = $compare_from;
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
$compare_to = $temp;
}
// Add default title if title field is empty
if ( $compare_from && empty( $compare_from->post_title ) )
if ( $compare_from && empty( $compare_from->post_title ) ) {
$compare_from->post_title = __( '(no title)' );
if ( empty( $compare_to->post_title ) )
}
if ( empty( $compare_to->post_title ) ) {
$compare_to->post_title = __( '(no title)' );
}
$return = array();
@ -76,7 +83,7 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
$args = array(
'show_split_view' => true
'show_split_view' => true,
);
/**
@ -104,14 +111,26 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
// In split screen mode, show the title before/after side by side.
if ( true === $args['show_split_view'] ) {
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
} else {
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td>';
// In single column mode, only show the title once if unchanged.
if ( $compare_from->post_title !== $compare_to->post_title ) {
$diff .= '</tr><tr><td>' . esc_html( $compare_to->post_title ) . '</td>';
}
}
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ( $diff ) {
$return[] = array(
'id' => $field,
'id' => $field,
'name' => $name,
'diff' => $diff,
);
@ -123,7 +142,7 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
*
* @since 4.1.0
*
* @param array $return Revision UI fields. Each item is an array of id, name and diff.
* @param array[] $return Array of revision UI fields. Each item is an array of id, name, and diff.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
@ -143,16 +162,23 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
* @return array An associative array of revision data and related settings.
*/
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
$post = get_post( $post );
$post = get_post( $post );
$authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
$revisions = wp_get_post_revisions(
$post->ID,
array(
'order' => 'ASC',
'check_enabled' => false,
)
);
// If revisions are disabled, we only want autosaves and the current post.
if ( ! wp_revisions_enabled( $post ) ) {
foreach ( $revisions as $revision_id => $revision ) {
if ( ! wp_is_post_autosave( $revision ) )
if ( ! wp_is_post_autosave( $revision ) ) {
unset( $revisions[ $revision_id ] );
}
}
$revisions = array( $post->ID => $post ) + $revisions;
}
@ -162,37 +188,43 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
$can_restore = current_user_can( 'edit_post', $post->ID );
$current_id = false;
$current_id = false;
foreach ( $revisions as $revision ) {
$modified = strtotime( $revision->post_modified );
$modified = strtotime( $revision->post_modified );
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
if ( $can_restore ) {
$restore_link = str_replace( '&amp;', '&', wp_nonce_url(
add_query_arg(
array( 'revision' => $revision->ID,
'action' => 'restore' ),
$restore_link = str_replace(
'&amp;',
'&',
wp_nonce_url(
add_query_arg(
array(
'revision' => $revision->ID,
'action' => 'restore',
),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
) );
),
"restore-post_{$revision->ID}"
)
);
}
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
$autosave = (bool) wp_is_post_autosave( $revision );
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
if ( $current && ! empty( $current_id ) ) {
// If multiple revisions have the same post_modified_gmt, highest ID is current.
if ( $current_id < $revision->ID ) {
$revisions[ $current_id ]['current'] = false;
$current_id = $revision->ID;
$current_id = $revision->ID;
} else {
$current = false;
}
@ -253,7 +285,7 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
'current' => true,
'restoreUrl' => false,
);
$current_id = $post->ID;
$current_id = $post->ID;
}
/*
@ -288,21 +320,23 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
$from = absint( $from );
$diffs = array( array(
'id' => $from . ':' . $selected_revision_id,
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
));
$diffs = array(
array(
'id' => $from . ':' . $selected_revision_id,
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
),
);
return array(
'postId' => $post->ID,
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
'revisionData' => array_values( $revisions ),
'to' => $selected_revision_id,
'from' => $from,
'diffData' => $diffs,
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
'revisionIds' => array_keys( $revisions ),
'postId' => $post->ID,
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
'revisionData' => array_values( $revisions ),
'to' => $selected_revision_id,
'from' => $from,
'diffData' => $diffs,
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
'revisionIds' => array_keys( $revisions ),
);
}
@ -357,14 +391,32 @@ function wp_print_revision_templates() {
{{{ data.attributes.author.avatar }}}
<div class="author-info">
<# if ( data.attributes.autosave ) { #>
<span class="byline"><?php printf( __( 'Autosave by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<span class="byline">
<?php
printf(
__( 'Autosave by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } else if ( data.attributes.current ) { #>
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<span class="byline">
<?php
printf(
__( 'Current Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } else { #>
<span class="byline"><?php printf( __( 'Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<span class="byline">
<?php
printf(
__( 'Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } #>
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
@ -399,5 +451,6 @@ function wp_print_revision_templates() {
{{{ field.diff }}}
<# }); #>
</div>
</script><?php
</script>
<?php
}

File diff suppressed because it is too large Load diff

View file

@ -17,8 +17,9 @@
* @return array Containing the headers in the format id => UI String
*/
function get_column_headers( $screen ) {
if ( is_string( $screen ) )
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
static $column_headers = array();
@ -98,13 +99,15 @@ function get_hidden_columns( $screen ) {
function meta_box_prefs( $screen ) {
global $wp_meta_boxes;
if ( is_string( $screen ) )
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
if ( empty($wp_meta_boxes[$screen->id]) )
if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
return;
}
$hidden = get_hidden_meta_boxes($screen);
$hidden = get_hidden_meta_boxes( $screen );
foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
@ -112,11 +115,13 @@ function meta_box_prefs( $screen ) {
continue;
}
foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
if ( false == $box || ! $box['title'] )
if ( false == $box || ! $box['title'] ) {
continue;
}
// Submit box cannot be hidden
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) {
continue;
}
$widget_title = $box['title'];
@ -144,8 +149,9 @@ function meta_box_prefs( $screen ) {
* @return array Hidden Meta Boxes
*/
function get_hidden_meta_boxes( $screen ) {
if ( is_string( $screen ) )
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
@ -155,10 +161,11 @@ function get_hidden_meta_boxes( $screen ) {
if ( $use_defaults ) {
$hidden = array();
if ( 'post' == $screen->base ) {
if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type )
$hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
else
if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) {
$hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' );
} else {
$hidden = array( 'slugdiv' );
}
}
/**
@ -196,8 +203,9 @@ function get_hidden_meta_boxes( $screen ) {
function add_screen_option( $option, $args = array() ) {
$current_screen = get_current_screen();
if ( ! $current_screen )
if ( ! $current_screen ) {
return;
}
$current_screen->add_option( $option, $args );
}
@ -214,8 +222,9 @@ function add_screen_option( $option, $args = array() ) {
function get_current_screen() {
global $current_screen;
if ( ! isset( $current_screen ) )
if ( ! isset( $current_screen ) ) {
return null;
}
return $current_screen;
}
@ -226,7 +235,7 @@ function get_current_screen() {
* @since 3.0.0
*
* @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
* or an existing screen object.
* or an existing screen object.
*/
function set_current_screen( $hook_name = '' ) {
WP_Screen::get( $hook_name )->set_current_screen();

View file

@ -22,9 +22,10 @@
* @return mixed
*/
function category_exists( $cat_name, $parent = null ) {
$id = term_exists($cat_name, 'category', $parent);
if ( is_array($id) )
$id = term_exists( $cat_name, 'category', $parent );
if ( is_array( $id ) ) {
$id = $id['term_id'];
}
return $id;
}
@ -52,10 +53,16 @@ function get_category_to_edit( $id ) {
* @return int|WP_Error
*/
function wp_create_category( $cat_name, $parent = 0 ) {
if ( $id = category_exists($cat_name, $parent) )
if ( $id = category_exists( $cat_name, $parent ) ) {
return $id;
}
return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) );
return wp_insert_category(
array(
'cat_name' => $cat_name,
'category_parent' => $parent,
)
);
}
/**
@ -63,12 +70,12 @@ function wp_create_category( $cat_name, $parent = 0 ) {
*
* @since 2.0.0
*
* @param array $categories List of categories to create.
* @param int $post_id Optional. The post ID. Default empty.
* @param string[] $categories Array of category names to create.
* @param int $post_id Optional. The post ID. Default empty.
* @return array List of categories to create for the given post.
*/
function wp_create_categories( $categories, $post_id = '' ) {
$cat_ids = array ();
$cat_ids = array();
foreach ( $categories as $category ) {
if ( $id = category_exists( $category ) ) {
$cat_ids[] = $id;
@ -77,8 +84,9 @@ function wp_create_categories( $categories, $post_id = '' ) {
}
}
if ( $post_id )
wp_set_post_categories($post_id, $cat_ids);
if ( $post_id ) {
wp_set_post_categories( $post_id, $cat_ids );
}
return $cat_ids;
}
@ -106,8 +114,15 @@ function wp_create_categories( $categories, $post_id = '' ) {
* 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 );
$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 ) {
@ -120,12 +135,12 @@ function wp_insert_category( $catarr, $wp_error = false ) {
$catarr['cat_ID'] = (int) $catarr['cat_ID'];
// Are we updating or creating?
$update = ! empty ( $catarr['cat_ID'] );
$update = ! empty( $catarr['cat_ID'] );
$name = $catarr['cat_name'];
$name = $catarr['cat_name'];
$description = $catarr['category_description'];
$slug = $catarr['category_nicename'];
$parent = (int) $catarr['category_parent'];
$slug = $catarr['category_nicename'];
$parent = (int) $catarr['category_parent'];
if ( $parent < 0 ) {
$parent = 0;
}
@ -136,7 +151,7 @@ function wp_insert_category( $catarr, $wp_error = false ) {
$parent = 0;
}
$args = compact('name', 'slug', 'parent', 'description');
$args = compact( 'name', 'slug', 'parent', 'description' );
if ( $update ) {
$catarr['cat_ID'] = wp_update_term( $catarr['cat_ID'], $catarr['taxonomy'], $args );
@ -165,23 +180,24 @@ function wp_insert_category( $catarr, $wp_error = false ) {
* @param array $catarr The 'cat_ID' value is required. All other keys are optional.
* @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure.
*/
function wp_update_category($catarr) {
function wp_update_category( $catarr ) {
$cat_ID = (int) $catarr['cat_ID'];
if ( isset($catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) )
if ( isset( $catarr['category_parent'] ) && ( $cat_ID == $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);
$category = wp_slash( $category );
// Merge old and new fields with new fields overwriting old ones.
$catarr = array_merge($category, $catarr);
$catarr = array_merge( $category, $catarr );
return wp_insert_category($catarr);
return wp_insert_category( $catarr );
}
//
@ -196,8 +212,8 @@ function wp_update_category($catarr) {
* @param int|string $tag_name
* @return mixed
*/
function tag_exists($tag_name) {
return term_exists($tag_name, 'post_tag');
function tag_exists( $tag_name ) {
return term_exists( $tag_name, 'post_tag' );
}
/**
@ -208,8 +224,8 @@ function tag_exists($tag_name) {
* @param int|string $tag_name
* @return array|WP_Error
*/
function wp_create_tag($tag_name) {
return wp_create_term( $tag_name, 'post_tag');
function wp_create_tag( $tag_name ) {
return wp_create_term( $tag_name, 'post_tag' );
}
/**
@ -222,7 +238,7 @@ function wp_create_tag($tag_name) {
* @return string|bool|WP_Error
*/
function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
return get_terms_to_edit( $post_id, $taxonomy);
return get_terms_to_edit( $post_id, $taxonomy );
}
/**
@ -236,8 +252,9 @@ function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
*/
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$post_id = (int) $post_id;
if ( !$post_id )
if ( ! $post_id ) {
return false;
}
$terms = get_object_term_cache( $post_id, $taxonomy );
if ( false === $terms ) {
@ -265,8 +282,8 @@ function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
*
* @see get_terms_to_edit()
*
* @param array $terms_to_edit An array of terms.
* @param string $taxonomy The taxonomy for which to retrieve terms. Default 'post_tag'.
* @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 );
@ -282,9 +299,10 @@ function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
* @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
* @return array|WP_Error
*/
function wp_create_term($tag_name, $taxonomy = 'post_tag') {
if ( $id = term_exists($tag_name, $taxonomy) )
function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
if ( $id = term_exists( $tag_name, $taxonomy ) ) {
return $id;
}
return wp_insert_term($tag_name, $taxonomy);
return wp_insert_term( $tag_name, $taxonomy );
}

File diff suppressed because it is too large Load diff

View file

@ -6,21 +6,52 @@
* @subpackage Administration
*/
$themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
'img' => array('src' => array(), 'class' => array(), 'alt' => array())
$themes_allowedtags = array(
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'div' => array(),
'p' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'h1' => array(),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'h6' => array(),
'img' => array(
'src' => array(),
'class' => array(),
'alt' => array(),
),
);
$theme_field_defaults = array( 'description' => true, 'sections' => false, 'tested' => true, 'requires' => true,
'rating' => true, 'downloaded' => true, 'downloadlink' => true, 'last_updated' => true, 'homepage' => true,
'tags' => true, 'num_ratings' => true
$theme_field_defaults = array(
'description' => true,
'sections' => false,
'tested' => true,
'requires' => true,
'rating' => true,
'downloaded' => true,
'downloadlink' => true,
'last_updated' => true,
'homepage' => true,
'tags' => true,
'num_ratings' => true,
);
/**
* Retrieve list of WordPress theme features (aka theme tags)
* Retrieve list of WordPress theme features (aka theme tags).
*
* @since 2.8.0
*
@ -31,15 +62,18 @@ $theme_field_defaults = array( 'description' => true, 'sections' => false, 'test
function install_themes_feature_list() {
_deprecated_function( __FUNCTION__, '3.1.0', 'get_theme_feature_list()' );
if ( !$cache = get_transient( 'wporg_theme_feature_list' ) )
if ( ! $cache = get_transient( 'wporg_theme_feature_list' ) ) {
set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
}
if ( $cache )
if ( $cache ) {
return $cache;
}
$feature_list = themes_api( 'feature_list', array() );
if ( is_wp_error( $feature_list ) )
if ( is_wp_error( $feature_list ) ) {
return array();
}
set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
@ -56,38 +90,41 @@ function install_themes_feature_list() {
function install_theme_search_form( $type_selector = true ) {
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
if ( ! $type_selector )
if ( ! $type_selector ) {
echo '<p class="install-help">' . __( 'Search for themes by keyword.' ) . '</p>';
}
?>
<form id="search-themes" method="get">
<input type="hidden" name="tab" value="search" />
<?php if ( $type_selector ) : ?>
<label class="screen-reader-text" for="typeselector"><?php _e('Type of search'); ?></label>
<label class="screen-reader-text" for="typeselector"><?php _e( 'Type of search' ); ?></label>
<select name="type" id="typeselector">
<option value="term" <?php selected('term', $type) ?>><?php _e('Keyword'); ?></option>
<option value="author" <?php selected('author', $type) ?>><?php _e('Author'); ?></option>
<option value="tag" <?php selected('tag', $type) ?>><?php _ex('Tag', 'Theme Installer'); ?></option>
<option value="term" <?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option>
<option value="author" <?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option>
<option value="tag" <?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Theme Installer' ); ?></option>
</select>
<label class="screen-reader-text" for="s"><?php
switch ( $type ) {
case 'term':
_e( 'Search by keyword' );
break;
case 'author':
_e( 'Search by author' );
break;
case 'tag':
_e( 'Search by tag' );
break;
}
?></label>
<label class="screen-reader-text" for="s">
<?php
switch ( $type ) {
case 'term':
_e( 'Search by keyword' );
break;
case 'author':
_e( 'Search by author' );
break;
case 'tag':
_e( 'Search by tag' );
break;
}
?>
</label>
<?php else : ?>
<label class="screen-reader-text" for="s"><?php _e('Search by keyword'); ?></label>
<label class="screen-reader-text" for="s"><?php _e( 'Search by keyword' ); ?></label>
<?php endif; ?>
<input type="search" name="s" id="s" size="30" value="<?php echo esc_attr($term) ?>" autofocus="autofocus" />
<input type="search" name="s" id="s" size="30" value="<?php echo esc_attr( $term ); ?>" autofocus="autofocus" />
<?php submit_button( __( 'Search' ), '', 'search', false ); ?>
</form>
<?php
<?php
}
/**
@ -97,8 +134,8 @@ function install_theme_search_form( $type_selector = true ) {
*/
function install_themes_dashboard() {
install_theme_search_form( false );
?>
<h4><?php _e('Feature Filter') ?></h4>
?>
<h4><?php _e( 'Feature Filter' ); ?></h4>
<p class="install-help"><?php _e( 'Find a theme based on specific features.' ); ?></p>
<form method="get">
@ -114,8 +151,8 @@ function install_themes_dashboard() {
echo '<ol class="feature-group">';
foreach ( $features as $feature => $feature_name ) {
$feature_name = esc_html( $feature_name );
$feature = esc_attr($feature);
?>
$feature = esc_attr( $feature );
?>
<li>
<input type="checkbox" name="features[]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" />
@ -125,23 +162,24 @@ function install_themes_dashboard() {
<?php } ?>
</ol>
<br class="clear" />
<?php
} ?>
<?php
}
?>
</div>
<br class="clear" />
<?php submit_button( __( 'Find Themes' ), '', 'search' ); ?>
<?php submit_button( __( 'Find Themes' ), '', 'search' ); ?>
</form>
<?php
<?php
}
/**
* @since 2.8.0
*/
function install_themes_upload() {
?>
<p class="install-help"><?php _e('If you have a theme in a .zip format, you may install it by uploading it here.'); ?></p>
<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-theme'); ?>">
?>
<p class="install-help"><?php _e( 'If you have a theme in a .zip format, you may install it by uploading it here.' ); ?></p>
<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-theme' ); ?>">
<?php wp_nonce_field( 'theme-upload' ); ?>
<label class="screen-reader-text" for="themezip"><?php _e( 'Theme zip file' ); ?></label>
<input type="file" id="themezip" name="themezip" />
@ -163,7 +201,7 @@ function display_theme( $theme ) {
_deprecated_function( __FUNCTION__, '3.4.0' );
global $wp_list_table;
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table('WP_Theme_Install_List_Table');
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->prepare_items();
$wp_list_table->single_row( $theme );
@ -180,7 +218,7 @@ function display_themes() {
global $wp_list_table;
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table('WP_Theme_Install_List_Table');
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->prepare_items();
$wp_list_table->display();
@ -199,12 +237,13 @@ function install_theme_information() {
$theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) );
if ( is_wp_error( $theme ) )
if ( is_wp_error( $theme ) ) {
wp_die( $theme );
}
iframe_header( __('Theme Installation') );
iframe_header( __( 'Theme Installation' ) );
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table('WP_Theme_Install_List_Table');
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->theme_installer_single( $theme );
iframe_footer();

View file

@ -11,31 +11,33 @@
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $stylesheet Stylesheet of the theme to delete
* @param string $redirect Redirect to page when complete.
* @return void|bool|WP_Error When void, echoes content.
* @param string $stylesheet Stylesheet of the theme to delete.
* @param string $redirect Redirect to page when complete.
* @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
* Null if filesystem credentials are required to proceed.
*/
function delete_theme($stylesheet, $redirect = '') {
function delete_theme( $stylesheet, $redirect = '' ) {
global $wp_filesystem;
if ( empty($stylesheet) )
if ( empty( $stylesheet ) ) {
return false;
}
if ( empty( $redirect ) ) {
$redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet);
$redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
}
ob_start();
$credentials = request_filesystem_credentials( $redirect );
$data = ob_get_clean();
$data = ob_get_clean();
if ( false === $credentials ) {
if ( ! empty( $data ) ){
include_once( ABSPATH . 'wp-admin/admin-header.php');
if ( ! empty( $data ) ) {
include_once( ABSPATH . 'wp-admin/admin-header.php' );
echo $data;
include( ABSPATH . 'wp-admin/admin-footer.php');
include( ABSPATH . 'wp-admin/admin-footer.php' );
exit;
}
return;
@ -46,20 +48,22 @@ function delete_theme($stylesheet, $redirect = '') {
request_filesystem_credentials( $redirect, '', true ); // Failed to connect, Error and request again.
$data = ob_get_clean();
if ( ! empty($data) ) {
include_once( ABSPATH . 'wp-admin/admin-header.php');
if ( ! empty( $data ) ) {
include_once( ABSPATH . 'wp-admin/admin-header.php' );
echo $data;
include( ABSPATH . 'wp-admin/admin-footer.php');
include( ABSPATH . 'wp-admin/admin-footer.php' );
exit;
}
return;
}
if ( ! is_object($wp_filesystem) )
return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
if ( ! is_object( $wp_filesystem ) ) {
return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
}
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );
}
// Get the base plugin folder.
$themes_dir = $wp_filesystem->wp_themes_dir();
@ -68,8 +72,8 @@ function delete_theme($stylesheet, $redirect = '') {
}
$themes_dir = trailingslashit( $themes_dir );
$theme_dir = trailingslashit( $themes_dir . $stylesheet );
$deleted = $wp_filesystem->delete( $theme_dir, true );
$theme_dir = trailingslashit( $themes_dir . $stylesheet );
$deleted = $wp_filesystem->delete( $theme_dir, true );
if ( ! $deleted ) {
return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) );
@ -84,6 +88,11 @@ function delete_theme($stylesheet, $redirect = '') {
foreach ( $translations as $translation => $data ) {
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
$json_translation_files = glob( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json' );
if ( $json_translation_files ) {
array_map( array( $wp_filesystem, 'delete' ), $json_translation_files );
}
}
}
@ -122,8 +131,8 @@ function get_page_templates( $post = null, $post_type = 'page' ) {
* @param string $containingfolder Path of the theme parent folder
* @return string
*/
function _get_template_edit_filename($fullpath, $containingfolder) {
return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath);
function _get_template_edit_filename( $fullpath, $containingfolder ) {
return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath );
}
/**
@ -155,11 +164,13 @@ function theme_update_available( $theme ) {
function get_theme_update_available( $theme ) {
static $themes_update = null;
if ( !current_user_can('update_themes' ) )
if ( ! current_user_can( 'update_themes' ) ) {
return false;
}
if ( !isset($themes_update) )
$themes_update = get_site_transient('update_themes');
if ( ! isset( $themes_update ) ) {
$themes_update = get_site_transient( 'update_themes' );
}
if ( ! ( $theme instanceof WP_Theme ) ) {
return false;
@ -169,19 +180,28 @@ function get_theme_update_available( $theme ) {
$html = '';
if ( isset($themes_update->response[ $stylesheet ]) ) {
$update = $themes_update->response[ $stylesheet ];
$theme_name = $theme->display('Name');
$details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
$update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
if ( isset( $themes_update->response[ $stylesheet ] ) ) {
$update = $themes_update->response[ $stylesheet ];
$theme_name = $theme->display( 'Name' );
$details_url = add_query_arg(
array(
'TB_iframe' => 'true',
'width' => 1024,
'height' => 800,
),
$update['url']
); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
$update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
if ( !is_multisite() ) {
if ( ! current_user_can('update_themes') ) {
if ( ! is_multisite() ) {
if ( ! current_user_can( 'update_themes' ) ) {
/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
$html = sprintf(
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
$theme_name,
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: theme name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
),
@ -189,10 +209,12 @@ function get_theme_update_available( $theme ) {
);
} elseif ( empty( $update['package'] ) ) {
/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
$html = sprintf(
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
$theme_name,
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: theme name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
),
@ -200,16 +222,19 @@ function get_theme_update_available( $theme ) {
);
} else {
/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
$html = sprintf(
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
$theme_name,
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: theme name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
),
$update['new_version'],
$update_url,
sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"',
sprintf(
'aria-label="%s" id="update-theme" data-slug="%s"',
/* translators: %s: theme name */
esc_attr( sprintf( __( 'Update %s now' ), $theme_name ) ),
$stylesheet
@ -223,7 +248,7 @@ function get_theme_update_available( $theme ) {
}
/**
* Retrieve list of WordPress theme features (aka theme tags)
* Retrieve list of WordPress theme features (aka theme tags).
*
* @since 3.1.0
*
@ -262,7 +287,7 @@ function get_theme_feature_list( $api = true ) {
'theme-options' => __( 'Theme Options' ),
),
__( 'Layout' ) => array(
__( 'Layout' ) => array(
'grid-layout' => __( 'Grid Layout' ),
'one-column' => __( 'One Column' ),
'two-columns' => __( 'Two Columns' ),
@ -270,24 +295,28 @@ function get_theme_feature_list( $api = true ) {
'four-columns' => __( 'Four Columns' ),
'left-sidebar' => __( 'Left Sidebar' ),
'right-sidebar' => __( 'Right Sidebar' ),
)
),
);
if ( ! $api || ! current_user_can( 'install_themes' ) )
if ( ! $api || ! current_user_can( 'install_themes' ) ) {
return $features;
if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) )
set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
if ( !$feature_list ) {
$feature_list = themes_api( 'feature_list', array() );
if ( is_wp_error( $feature_list ) )
return $features;
}
if ( !$feature_list )
if ( ! $feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) {
set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
}
if ( ! $feature_list ) {
$feature_list = themes_api( 'feature_list', array() );
if ( is_wp_error( $feature_list ) ) {
return $features;
}
}
if ( ! $feature_list ) {
return $features;
}
set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
@ -300,15 +329,17 @@ function get_theme_feature_list( $api = true ) {
// Loop over the wporg canonical list and apply translations
$wporg_features = array();
foreach ( (array) $feature_list as $feature_category => $feature_items ) {
if ( isset($category_translations[$feature_category]) )
$feature_category = $category_translations[$feature_category];
$wporg_features[$feature_category] = array();
if ( isset( $category_translations[ $feature_category ] ) ) {
$feature_category = $category_translations[ $feature_category ];
}
$wporg_features[ $feature_category ] = array();
foreach ( $feature_items as $feature ) {
if ( isset($features[$feature_category][$feature]) )
$wporg_features[$feature_category][$feature] = $features[$feature_category][$feature];
else
$wporg_features[$feature_category][$feature] = $feature;
if ( isset( $features[ $feature_category ][ $feature ] ) ) {
$wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ];
} else {
$wporg_features[ $feature_category ][ $feature ] = $feature;
}
}
}
@ -397,19 +428,27 @@ function get_theme_feature_list( $api = true ) {
* for more information on the make-up of possible return objects depending on the value of `$action`.
*/
function themes_api( $action, $args = array() ) {
// include an unmodified $wp_version
include( ABSPATH . WPINC . '/version.php' );
if ( is_array( $args ) ) {
$args = (object) $args;
}
if ( ! isset( $args->per_page ) ) {
$args->per_page = 24;
if ( 'query_themes' == $action ) {
if ( ! isset( $args->per_page ) ) {
$args->per_page = 24;
}
}
if ( ! isset( $args->locale ) ) {
$args->locale = get_user_locale();
}
if ( ! isset( $args->wp_version ) ) {
$args->wp_version = substr( $wp_version, 0, 3 ); // X.y
}
/**
* Filters arguments used to query for installer pages from the WordPress.org Themes API.
*
@ -441,21 +480,24 @@ function themes_api( $action, $args = array() ) {
$res = apply_filters( 'themes_api', false, $action, $args );
if ( ! $res ) {
// include an unmodified $wp_version
include( ABSPATH . WPINC . '/version.php' );
$url = 'http://api.wordpress.org/themes/info/1.2/';
$url = add_query_arg(
array(
'action' => $action,
'request' => $args,
),
$url
);
$url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
$http_url = $url;
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$http_args = array(
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
'body' => array(
'action' => $action,
'request' => serialize( $args )
)
);
$request = wp_remote_post( $url, $http_args );
$request = wp_remote_get( $url, $http_args );
if ( $ssl && is_wp_error( $request ) ) {
if ( ! wp_doing_ajax() ) {
@ -468,11 +510,12 @@ function themes_api( $action, $args = array() ) {
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
}
$request = wp_remote_post( $http_url, $http_args );
$request = wp_remote_get( $http_url, $http_args );
}
if ( is_wp_error($request) ) {
$res = new WP_Error( 'themes_api_failed',
if ( is_wp_error( $request ) ) {
$res = new WP_Error(
'themes_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -481,9 +524,13 @@ function themes_api( $action, $args = array() ) {
$request->get_error_message()
);
} else {
$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
if ( ! is_object( $res ) && ! is_array( $res ) ) {
$res = new WP_Error( 'themes_api_failed',
$res = json_decode( wp_remote_retrieve_body( $request ), true );
if ( is_array( $res ) ) {
// Object casting is required in order to match the info/1.0 format.
$res = (object) $res;
} elseif ( null === $res ) {
$res = new WP_Error(
'themes_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -492,6 +539,21 @@ function themes_api( $action, $args = array() ) {
wp_remote_retrieve_body( $request )
);
}
if ( isset( $res->error ) ) {
$res = new WP_Error( 'themes_api_failed', $res->error );
}
}
// Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects.
if ( 'query_themes' == $action ) {
foreach ( $res->themes as $i => $theme ) {
$res->themes[ $i ] = (object) $theme;
}
}
// Back-compat for info/1.2 API, downgrade the feature_list result back to an array.
if ( 'feature_list' == $action ) {
$res = (array) $res;
}
}
@ -513,8 +575,8 @@ function themes_api( $action, $args = array() ) {
*
* @since 3.8.0
*
* @param array $themes Optional. Array of WP_Theme objects to prepare.
* Defaults to all allowed themes.
* @param WP_Theme[] $themes Optional. Array of theme objects to prepare.
* Defaults to all allowed themes.
*
* @return array An associative array of theme data, sorted by name.
*/
@ -529,9 +591,9 @@ function wp_prepare_themes_for_js( $themes = null ) {
*
* @since 4.2.0
*
* @param array $prepared_themes An associative array of theme data. Default empty array.
* @param null|array $themes An array of WP_Theme objects to prepare, if any.
* @param string $current_theme The current theme slug.
* @param array $prepared_themes An associative array of theme data. Default empty array.
* @param WP_Theme[]|null $themes An array of theme objects to prepare, if any.
* @param string $current_theme The current theme slug.
*/
$prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme );
@ -562,24 +624,26 @@ function wp_prepare_themes_for_js( $themes = null ) {
$parents = array();
foreach ( $themes as $theme ) {
$slug = $theme->get_stylesheet();
$slug = $theme->get_stylesheet();
$encoded_slug = urlencode( $slug );
$parent = false;
if ( $theme->parent() ) {
$parent = $theme->parent();
$parent = $theme->parent();
$parents[ $slug ] = $parent->get_stylesheet();
$parent = $parent->display( 'Name' );
$parent = $parent->display( 'Name' );
}
$customize_action = null;
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$customize_action = esc_url( add_query_arg(
array(
'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
),
wp_customize_url( $slug )
) );
$customize_action = esc_url(
add_query_arg(
array(
'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
),
wp_customize_url( $slug )
)
);
}
$prepared_themes[ $slug ] = array(
@ -594,12 +658,12 @@ function wp_prepare_themes_for_js( $themes = null ) {
'parent' => $parent,
'active' => $slug === $current_theme,
'hasUpdate' => isset( $updates[ $slug ] ),
'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ][ 'package' ] ),
'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
'update' => get_theme_update_available( $theme ),
'actions' => array(
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
'customize' => $customize_action,
'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
),
);
}

View file

@ -20,7 +20,7 @@ function translations_api( $type, $args = null ) {
include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ) ) ) {
return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
}
/**
@ -42,7 +42,7 @@ function translations_api( $type, $args = null ) {
$options = array(
'timeout' => 3,
'body' => array(
'body' => array(
'wp_version' => $wp_version,
'locale' => get_locale(),
'version' => $args['version'], // Version of plugin, theme or core
@ -69,7 +69,8 @@ function translations_api( $type, $args = null ) {
}
if ( is_wp_error( $request ) ) {
$res = new WP_Error( 'translations_api_failed',
$res = new WP_Error(
'translations_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -80,7 +81,8 @@ function translations_api( $type, $args = null ) {
} else {
$res = json_decode( wp_remote_retrieve_body( $request ), true );
if ( ! is_object( $res ) && ! is_array( $res ) ) {
$res = new WP_Error( 'translations_api_failed',
$res = new WP_Error(
'translations_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -162,24 +164,28 @@ function wp_install_language_form( $languages ) {
if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
if ( isset( $languages[ $wp_local_package ] ) ) {
$language = $languages[ $wp_local_package ];
printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
printf(
'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
esc_attr( $language['language'] ),
esc_attr( current( $language['iso'] ) ),
esc_attr( $language['strings']['continue'] ),
in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
esc_html( $language['native_name'] ) );
esc_html( $language['native_name'] )
);
unset( $languages[ $wp_local_package ] );
}
}
foreach ( $languages as $language ) {
printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
printf(
'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
esc_attr( $language['language'] ),
esc_attr( current( $language['iso'] ) ),
esc_attr( $language['strings']['continue'] ),
in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
esc_html( $language['native_name'] ) );
esc_html( $language['native_name'] )
);
}
echo "</select>\n";
echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
@ -224,10 +230,10 @@ function wp_download_language_pack( $download ) {
$translation = (object) $translation;
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new Automatic_Upgrader_Skin;
$upgrader = new Language_Pack_Upgrader( $skin );
$skin = new Automatic_Upgrader_Skin;
$upgrader = new Language_Pack_Upgrader( $skin );
$translation->type = 'core';
$result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
$result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
if ( ! $result || is_wp_error( $result ) ) {
return false;
@ -250,7 +256,7 @@ function wp_can_install_language_pack() {
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new Automatic_Upgrader_Skin;
$skin = new Automatic_Upgrader_Skin;
$upgrader = new Language_Pack_Upgrader( $skin );
$upgrader->init();

File diff suppressed because it is too large Load diff

View file

@ -13,10 +13,12 @@
*/
function get_preferred_from_update_core() {
$updates = get_core_updates();
if ( ! is_array( $updates ) )
if ( ! is_array( $updates ) ) {
return false;
if ( empty( $updates ) )
}
if ( empty( $updates ) ) {
return (object) array( 'response' => 'latest' );
}
return $updates[0];
}
@ -24,36 +26,45 @@ function get_preferred_from_update_core() {
* Get available core updates.
*
* @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
* set $options['available'] to false to skip not-dismissed updates.
* set $options['available'] to false to skip not-dismissed updates.
* @return array|false Array of the update objects on success, false on failure.
*/
function get_core_updates( $options = array() ) {
$options = array_merge( array( 'available' => true, 'dismissed' => false ), $options );
$options = array_merge(
array(
'available' => true,
'dismissed' => false,
),
$options
);
$dismissed = get_site_option( 'dismissed_update_core' );
if ( ! is_array( $dismissed ) )
if ( ! is_array( $dismissed ) ) {
$dismissed = array();
}
$from_api = get_site_transient( 'update_core' );
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
return false;
}
$updates = $from_api->updates;
$result = array();
$result = array();
foreach ( $updates as $update ) {
if ( $update->response == 'autoupdate' )
if ( $update->response == 'autoupdate' ) {
continue;
}
if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
if ( $options['dismissed'] ) {
$update->dismissed = true;
$result[] = $update;
$result[] = $update;
}
} else {
if ( $options['available'] ) {
$update->dismissed = false;
$result[] = $update;
$result[] = $update;
}
}
}
@ -71,22 +82,26 @@ function get_core_updates( $options = array() ) {
*/
function find_core_auto_update() {
$updates = get_site_transient( 'update_core' );
if ( ! $updates || empty( $updates->updates ) )
if ( ! $updates || empty( $updates->updates ) ) {
return false;
}
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$auto_update = false;
$upgrader = new WP_Automatic_Updater;
$upgrader = new WP_Automatic_Updater;
foreach ( $updates->updates as $update ) {
if ( 'autoupdate' != $update->response )
if ( 'autoupdate' != $update->response ) {
continue;
}
if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) )
if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
continue;
}
if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) )
if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
$auto_update = $update;
}
}
return $auto_update;
}
@ -103,8 +118,9 @@ function find_core_auto_update() {
function get_core_checksums( $version, $locale ) {
$url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$options = array(
'timeout' => wp_doing_cron() ? 30 : 3,
@ -123,20 +139,21 @@ function get_core_checksums( $version, $locale ) {
$response = wp_remote_get( $http_url, $options );
}
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
return false;
}
$body = trim( wp_remote_retrieve_body( $response ) );
$body = json_decode( $body, true );
if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
return false;
}
return $body['checksums'];
}
/**
*
* @param object $update
* @return bool
*/
@ -147,24 +164,23 @@ function dismiss_core_update( $update ) {
}
/**
*
* @param string $version
* @param string $locale
* @return bool
*/
function undismiss_core_update( $version, $locale ) {
$dismissed = get_site_option( 'dismissed_update_core' );
$key = $version . '|' . $locale;
$key = $version . '|' . $locale;
if ( ! isset( $dismissed[$key] ) )
if ( ! isset( $dismissed[ $key ] ) ) {
return false;
}
unset( $dismissed[$key] );
unset( $dismissed[ $key ] );
return update_site_option( 'dismissed_update_core', $dismissed );
}
/**
*
* @param string $version
* @param string $locale
* @return object|false
@ -172,94 +188,100 @@ function undismiss_core_update( $version, $locale ) {
function find_core_update( $version, $locale ) {
$from_api = get_site_transient( 'update_core' );
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
return false;
}
$updates = $from_api->updates;
foreach ( $updates as $update ) {
if ( $update->current == $version && $update->locale == $locale )
if ( $update->current == $version && $update->locale == $locale ) {
return $update;
}
}
return false;
}
/**
*
* @param string $msg
* @return string
*/
function core_update_footer( $msg = '' ) {
if ( !current_user_can('update_core') )
if ( ! current_user_can( 'update_core' ) ) {
return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
}
$cur = get_preferred_from_update_core();
if ( ! is_object( $cur ) )
if ( ! is_object( $cur ) ) {
$cur = new stdClass;
}
if ( ! isset( $cur->current ) )
if ( ! isset( $cur->current ) ) {
$cur->current = '';
}
if ( ! isset( $cur->url ) )
if ( ! isset( $cur->url ) ) {
$cur->url = '';
}
if ( ! isset( $cur->response ) )
if ( ! isset( $cur->response ) ) {
$cur->response = '';
}
switch ( $cur->response ) {
case 'development' :
/* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */
return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) );
case 'development':
/* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */
return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) );
case 'upgrade' :
return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>';
case 'upgrade':
return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>';
case 'latest' :
default :
return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
case 'latest':
default:
return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
}
}
/**
*
* @global string $pagenow
* @return false|void
*/
function update_nag() {
if ( is_multisite() && !current_user_can('update_core') )
if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
return false;
}
global $pagenow;
if ( 'update-core.php' == $pagenow )
if ( 'update-core.php' == $pagenow ) {
return;
}
$cur = get_preferred_from_update_core();
if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) {
return false;
}
$version_url = sprintf(
/* translators: %s: WordPress version */
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
sanitize_title( $cur->current )
);
if ( current_user_can( 'update_core' ) ) {
$msg = sprintf(
/* translators: 1: Codex URL to release notes, 2: new WordPress version, 3: URL to network admin, 4: accessibility text */
/* translators: 1: URL to WordPress release notes, 2: new WordPress version, 3: URL to network admin, 4: accessibility text */
__( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
sprintf(
/* translators: %s: WordPress version */
esc_url( __( 'https://codex.wordpress.org/Version_%s' ) ),
$cur->current
),
$version_url,
$cur->current,
network_admin_url( 'update-core.php' ),
esc_attr__( 'Please update WordPress now' )
);
} else {
$msg = sprintf(
/* translators: 1: Codex URL to release notes, 2: new WordPress version */
/* translators: 1: URL to WordPress release notes, 2: new WordPress version */
__( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
sprintf(
/* translators: %s: WordPress version */
esc_url( __( 'https://codex.wordpress.org/Version_%s' ) ),
$cur->current
),
$version_url,
$cur->current
);
}
@ -275,11 +297,12 @@ function update_right_now_message() {
$msg = '';
if ( current_user_can('update_core') ) {
if ( current_user_can( 'update_core' ) ) {
$cur = get_preferred_from_update_core();
if ( isset( $cur->response ) && $cur->response == 'upgrade' )
if ( isset( $cur->response ) && $cur->response == 'upgrade' ) {
$msg .= '<a href="' . network_admin_url( 'update-core.php' ) . '" class="button" aria-describedby="wp-version">' . sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a> ';
}
}
/* translators: 1: version number, 2: theme name */
@ -307,12 +330,12 @@ function update_right_now_message() {
* @return array
*/
function get_plugin_updates() {
$all_plugins = get_plugins();
$all_plugins = get_plugins();
$upgrade_plugins = array();
$current = get_site_transient( 'update_plugins' );
foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {
$current = get_site_transient( 'update_plugins' );
foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
if ( isset( $current->response[ $plugin_file ] ) ) {
$upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
$upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
}
}
@ -324,11 +347,12 @@ function get_plugin_updates() {
* @since 2.9.0
*/
function wp_plugin_update_rows() {
if ( !current_user_can('update_plugins' ) )
if ( ! current_user_can( 'update_plugins' ) ) {
return;
}
$plugins = get_site_transient( 'update_plugins' );
if ( isset($plugins->response) && is_array($plugins->response) ) {
if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
$plugins = array_keys( $plugins->response );
foreach ( $plugins as $plugin_file ) {
add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 );
@ -352,7 +376,10 @@ function wp_plugin_update_row( $file, $plugin_data ) {
$response = $current->response[ $file ];
$plugins_allowedtags = array(
'a' => array( 'href' => array(), 'title' => array() ),
'a' => array(
'href' => array(),
'title' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
@ -360,8 +387,8 @@ function wp_plugin_update_row( $file, $plugin_data ) {
'strong' => array(),
);
$plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
$details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
$plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
$details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
/** @var WP_Plugins_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
@ -377,10 +404,12 @@ function wp_plugin_update_row( $file, $plugin_data ) {
if ( ! current_user_can( 'update_plugins' ) ) {
/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
printf(
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
$plugin_name,
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: plugin name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
),
@ -388,10 +417,12 @@ function wp_plugin_update_row( $file, $plugin_data ) {
);
} elseif ( empty( $response->package ) ) {
/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
printf(
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
$plugin_name,
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: plugin name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
),
@ -399,16 +430,19 @@ function wp_plugin_update_row( $file, $plugin_data ) {
);
} else {
/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
printf(
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
$plugin_name,
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: plugin name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
),
$response->new_version,
wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
sprintf( 'class="update-link" aria-label="%s"',
sprintf(
'class="update-link" aria-label="%s"',
/* translators: %s: plugin name */
esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
)
@ -457,18 +491,18 @@ function wp_plugin_update_row( $file, $plugin_data ) {
}
/**
*
* @return array
*/
function get_theme_updates() {
$current = get_site_transient('update_themes');
$current = get_site_transient( 'update_themes' );
if ( ! isset( $current->response ) )
if ( ! isset( $current->response ) ) {
return array();
}
$update_themes = array();
foreach ( $current->response as $stylesheet => $data ) {
$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
$update_themes[ $stylesheet ]->update = $data;
}
@ -479,11 +513,12 @@ function get_theme_updates() {
* @since 3.1.0
*/
function wp_theme_update_rows() {
if ( !current_user_can('update_themes' ) )
if ( ! current_user_can( 'update_themes' ) ) {
return;
}
$themes = get_site_transient( 'update_themes' );
if ( isset($themes->response) && is_array($themes->response) ) {
if ( isset( $themes->response ) && is_array( $themes->response ) ) {
$themes = array_keys( $themes->response );
foreach ( $themes as $theme ) {
@ -508,11 +543,14 @@ function wp_theme_update_row( $theme_key, $theme ) {
$response = $current->response[ $theme_key ];
$details_url = add_query_arg( array(
'TB_iframe' => 'true',
'width' => 1024,
'height' => 800,
), $current->response[ $theme_key ]['url'] );
$details_url = add_query_arg(
array(
'TB_iframe' => 'true',
'width' => 1024,
'height' => 800,
),
$current->response[ $theme_key ]['url']
);
/** @var WP_MS_Themes_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
@ -522,10 +560,12 @@ function wp_theme_update_row( $theme_key, $theme ) {
echo '<tr class="plugin-update-tr' . $active . '" id="' . esc_attr( $theme->get_stylesheet() . '-update' ) . '" data-slug="' . esc_attr( $theme->get_stylesheet() ) . '"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message notice inline notice-warning notice-alt"><p>';
if ( ! current_user_can( 'update_themes' ) ) {
/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.'),
printf(
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
$theme['Name'],
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: theme name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
),
@ -533,10 +573,12 @@ function wp_theme_update_row( $theme_key, $theme ) {
);
} elseif ( empty( $response['package'] ) ) {
/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ),
printf(
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ),
$theme['Name'],
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: theme name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
),
@ -544,16 +586,19 @@ function wp_theme_update_row( $theme_key, $theme ) {
);
} else {
/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
printf(
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
$theme['Name'],
esc_url( $details_url ),
sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
sprintf(
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: theme name, 2: version number */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
),
$response['new_version'],
wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
sprintf( 'class="update-link" aria-label="%s"',
sprintf(
'class="update-link" aria-label="%s"',
/* translators: %s: theme name */
esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
)
@ -584,7 +629,6 @@ function wp_theme_update_row( $theme_key, $theme ) {
}
/**
*
* @global int $upgrading
* @return false|void
*/
@ -605,17 +649,20 @@ function maintenance_nag() {
* This flag is cleared whenever a successful update occurs using Core_Upgrader.
*/
$comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
if ( version_compare( $failed['attempted'], $wp_version, $comparison ) )
if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
$nag = true;
}
}
if ( ! $nag )
if ( ! $nag ) {
return false;
}
if ( current_user_can('update_core') )
$msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' );
else
$msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.');
if ( current_user_can( 'update_core' ) ) {
$msg = sprintf( __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ), 'update-core.php' );
} else {
$msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
}
echo "<div class='update-nag'>$msg</div>";
}

File diff suppressed because it is too large Load diff

View file

@ -25,77 +25,98 @@ function add_user() {
* @since 2.0.0
*
* @param int $user_id Optional. User ID.
* @return int|WP_Error user id of the updated user
* @return int|WP_Error user id of the updated user.
*/
function edit_user( $user_id = 0 ) {
$wp_roles = wp_roles();
$user = new stdClass;
$user = new stdClass;
$user_id = (int) $user_id;
if ( $user_id ) {
$update = true;
$user->ID = (int) $user_id;
$userdata = get_userdata( $user_id );
$update = true;
$user->ID = $user_id;
$userdata = get_userdata( $user_id );
$user->user_login = wp_slash( $userdata->user_login );
} else {
$update = false;
}
if ( !$update && isset( $_POST['user_login'] ) )
$user->user_login = sanitize_user($_POST['user_login'], true);
$pass1 = $pass2 = '';
if ( isset( $_POST['pass1'] ) )
$pass1 = $_POST['pass1'];
if ( isset( $_POST['pass2'] ) )
$pass2 = $_POST['pass2'];
if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {
$new_role = sanitize_text_field( $_POST['role'] );
$potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false;
// Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
// Multisite super admins can freely edit their blog roles -- they possess all caps.
if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != get_current_user_id() || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) )
$user->role = $new_role;
// If the new role isn't editable by the logged-in user die with error
$editable_roles = get_editable_roles();
if ( ! empty( $new_role ) && empty( $editable_roles[$new_role] ) )
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
if ( ! $update && isset( $_POST['user_login'] ) ) {
$user->user_login = sanitize_user( $_POST['user_login'], true );
}
if ( isset( $_POST['email'] ))
$pass1 = $pass2 = '';
if ( isset( $_POST['pass1'] ) ) {
$pass1 = $_POST['pass1'];
}
if ( isset( $_POST['pass2'] ) ) {
$pass2 = $_POST['pass2'];
}
if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) {
$new_role = sanitize_text_field( $_POST['role'] );
// If the new role isn't editable by the logged-in user die with error.
$editable_roles = get_editable_roles();
if ( ! empty( $new_role ) && empty( $editable_roles[ $new_role ] ) ) {
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
}
$potential_role = isset( $wp_roles->role_objects[ $new_role ] ) ? $wp_roles->role_objects[ $new_role ] : false;
/*
* Don't let anyone with 'promote_users' edit their own role to something without it.
* Multisite super admins can freely edit their roles, they possess all caps.
*/
if (
( is_multisite() && current_user_can( 'manage_network_users' ) ) ||
$user_id !== get_current_user_id() ||
( $potential_role && $potential_role->has_cap( 'promote_users' ) )
) {
$user->role = $new_role;
}
}
if ( isset( $_POST['email'] ) ) {
$user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) );
}
if ( isset( $_POST['url'] ) ) {
if ( empty ( $_POST['url'] ) || $_POST['url'] == 'http://' ) {
if ( empty( $_POST['url'] ) || $_POST['url'] == 'http://' ) {
$user->user_url = '';
} else {
$user->user_url = esc_url_raw( $_POST['url'] );
$protocols = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) );
$user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url;
$protocols = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) );
$user->user_url = preg_match( '/^(' . $protocols . '):/is', $user->user_url ) ? $user->user_url : 'http://' . $user->user_url;
}
}
if ( isset( $_POST['first_name'] ) )
if ( isset( $_POST['first_name'] ) ) {
$user->first_name = sanitize_text_field( $_POST['first_name'] );
if ( isset( $_POST['last_name'] ) )
}
if ( isset( $_POST['last_name'] ) ) {
$user->last_name = sanitize_text_field( $_POST['last_name'] );
if ( isset( $_POST['nickname'] ) )
}
if ( isset( $_POST['nickname'] ) ) {
$user->nickname = sanitize_text_field( $_POST['nickname'] );
if ( isset( $_POST['display_name'] ) )
}
if ( isset( $_POST['display_name'] ) ) {
$user->display_name = sanitize_text_field( $_POST['display_name'] );
}
if ( isset( $_POST['description'] ) )
if ( isset( $_POST['description'] ) ) {
$user->description = trim( $_POST['description'] );
}
foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) {
if ( isset( $_POST[$method] ))
$user->$method = sanitize_text_field( $_POST[$method] );
if ( isset( $_POST[ $method ] ) ) {
$user->$method = sanitize_text_field( $_POST[ $method ] );
}
}
if ( $update ) {
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
$user->syntax_highlighting = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true';
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
$user->syntax_highlighting = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true';
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
$user->locale = '';
$user->locale = '';
if ( isset( $_POST['locale'] ) ) {
$locale = sanitize_text_field( $_POST['locale'] );
@ -114,14 +135,16 @@ function edit_user( $user_id = 0 ) {
$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' == $_POST['comment_shortcuts'] ? 'true' : '';
$user->use_ssl = 0;
if ( !empty($_POST['use_ssl']) )
if ( ! empty( $_POST['use_ssl'] ) ) {
$user->use_ssl = 1;
}
$errors = new WP_Error();
/* checking that username has been typed */
if ( $user->user_login == '' )
if ( $user->user_login == '' ) {
$errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ) );
}
/* checking that nickname has been typed */
if ( $update && empty( $user->nickname ) ) {
@ -145,7 +168,7 @@ function edit_user( $user_id = 0 ) {
}
// Check for "\" in password.
if ( false !== strpos( wp_unslash( $pass1 ), "\\" ) ) {
if ( false !== strpos( wp_unslash( $pass1 ), '\\' ) ) {
$errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
}
@ -154,14 +177,17 @@ function edit_user( $user_id = 0 ) {
$errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
}
if ( !empty( $pass1 ) )
if ( ! empty( $pass1 ) ) {
$user->user_pass = $pass1;
}
if ( !$update && isset( $_POST['user_login'] ) && !validate_username( $_POST['user_login'] ) )
$errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ));
if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) {
$errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
}
if ( !$update && username_exists( $user->user_login ) )
$errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ));
if ( ! $update && username_exists( $user->user_login ) ) {
$errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) );
}
/** This filter is documented in wp-includes/user.php */
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
@ -173,10 +199,10 @@ function edit_user( $user_id = 0 ) {
/* checking email address */
if ( empty( $user->user_email ) ) {
$errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) );
} elseif ( !is_email( $user->user_email ) ) {
} elseif ( ! is_email( $user->user_email ) ) {
$errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ), array( 'form-field' => 'email' ) );
} elseif ( ( $owner_id = email_exists($user->user_email) ) && ( !$update || ( $owner_id != $user->ID ) ) ) {
$errors->add( 'email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array( 'form-field' => 'email' ) );
} elseif ( ( $owner_id = email_exists( $user->user_email ) ) && ( ! $update || ( $owner_id != $user->ID ) ) ) {
$errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ), array( 'form-field' => 'email' ) );
}
/**
@ -190,8 +216,9 @@ function edit_user( $user_id = 0 ) {
*/
do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) );
if ( $errors->get_error_codes() )
if ( $errors->has_errors() ) {
return $errors;
}
if ( $update ) {
$user_id = wp_update_user( $user );
@ -200,14 +227,14 @@ function edit_user( $user_id = 0 ) {
$notify = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';
/**
* Fires after a new user has been created.
*
* @since 4.4.0
*
* @param int $user_id ID of the newly created user.
* @param string $notify Type of notification that should happen. See wp_send_new_user_notifications()
* for more information on possible values.
*/
* Fires after a new user has been created.
*
* @since 4.4.0
*
* @param int $user_id ID of the newly created user.
* @param string $notify Type of notification that should happen. See wp_send_new_user_notifications()
* for more information on possible values.
*/
do_action( 'edit_user_created_user', $user_id, $notify );
}
return $user_id;
@ -217,7 +244,7 @@ function edit_user( $user_id = 0 ) {
* Fetch a filtered list of user roles that the current user is
* allowed to edit.
*
* Simple function who's main purpose is to allow filtering of the
* Simple function whose main purpose is to allow filtering of the
* list of roles in the $wp_roles object so that plugins can remove
* inappropriate ones depending on the situation or user making edits.
* Specifically because without filtering anyone with the edit_users
@ -227,7 +254,7 @@ function edit_user( $user_id = 0 ) {
*
* @since 2.8.0
*
* @return array
* @return array[] Array of arrays containing role information.
*/
function get_editable_roles() {
$all_roles = wp_roles()->roles;
@ -237,7 +264,7 @@ function get_editable_roles() {
*
* @since 2.8.0
*
* @param array $all_roles List of roles.
* @param array[] $all_roles Array of arrays containing role information.
*/
$editable_roles = apply_filters( 'editable_roles', $all_roles );
@ -255,8 +282,9 @@ function get_editable_roles() {
function get_user_to_edit( $user_id ) {
$user = get_userdata( $user_id );
if ( $user )
if ( $user ) {
$user->filter = 'edit';
}
return $user;
}
@ -273,7 +301,7 @@ function get_user_to_edit( $user_id ) {
*/
function get_users_drafts( $user_id ) {
global $wpdb;
$query = $wpdb->prepare("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = %d ORDER BY post_modified DESC", $user_id);
$query = $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = %d ORDER BY post_modified DESC", $user_id );
/**
* Filters the user's drafts query string.
@ -309,11 +337,12 @@ function wp_delete_user( $id, $reassign = null ) {
return false;
}
$id = (int) $id;
$id = (int) $id;
$user = new WP_User( $id );
if ( !$user->exists() )
if ( ! $user->exists() ) {
return false;
}
// Normalize $reassign to null or a user ID. 'novalue' was an older default.
if ( 'novalue' === $reassign ) {
@ -348,36 +377,40 @@ function wp_delete_user( $id, $reassign = null ) {
*
* @since 3.4.0
*
* @param array $post_types_to_delete Post types to delete.
* @param int $id User ID.
* @param string[] $post_types_to_delete Array of post types to delete.
* @param int $id User ID.
*/
$post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id );
$post_types_to_delete = implode( "', '", $post_types_to_delete );
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) );
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) );
if ( $post_ids ) {
foreach ( $post_ids as $post_id )
foreach ( $post_ids as $post_id ) {
wp_delete_post( $post_id );
}
}
// Clean links
$link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) );
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
if ( $link_ids ) {
foreach ( $link_ids as $link_id )
wp_delete_link($link_id);
foreach ( $link_ids as $link_id ) {
wp_delete_link( $link_id );
}
}
} else {
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
$wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) );
$wpdb->update( $wpdb->posts, array( 'post_author' => $reassign ), array( 'post_author' => $id ) );
if ( ! empty( $post_ids ) ) {
foreach ( $post_ids as $post_id )
foreach ( $post_ids as $post_id ) {
clean_post_cache( $post_id );
}
}
$link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) );
$wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) );
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
$wpdb->update( $wpdb->links, array( 'link_owner' => $reassign ), array( 'link_owner' => $id ) );
if ( ! empty( $link_ids ) ) {
foreach ( $link_ids as $link_id )
foreach ( $link_ids as $link_id ) {
clean_bookmark_cache( $link_id );
}
}
}
@ -386,8 +419,9 @@ function wp_delete_user( $id, $reassign = null ) {
remove_user_from_blog( $id, get_current_blog_id() );
} else {
$meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
foreach ( $meta as $mid )
foreach ( $meta as $mid ) {
delete_metadata_by_mid( 'user', $mid );
}
$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
}
@ -415,10 +449,10 @@ function wp_delete_user( $id, $reassign = null ) {
*
* @param int $id User ID.
*/
function wp_revoke_user($id) {
function wp_revoke_user( $id ) {
$id = (int) $id;
$user = new WP_User($id);
$user = new WP_User( $id );
$user->remove_all_caps();
}
@ -429,16 +463,17 @@ function wp_revoke_user($id) {
*
* @param false $errors Deprecated.
*/
function default_password_nag_handler($errors = false) {
function default_password_nag_handler( $errors = false ) {
global $user_ID;
// Short-circuit it.
if ( ! get_user_option('default_password_nag') )
if ( ! get_user_option( 'default_password_nag' ) ) {
return;
}
// get_user_setting = JS saved UI setting. else no-js-fallback code.
if ( 'hide' == get_user_setting('default_password_nag') || isset($_GET['default_password_nag']) && '0' == $_GET['default_password_nag'] ) {
delete_user_setting('default_password_nag');
update_user_option($user_ID, 'default_password_nag', false, true);
if ( 'hide' == get_user_setting( 'default_password_nag' ) || isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag'] ) {
delete_user_setting( 'default_password_nag' );
update_user_option( $user_ID, 'default_password_nag', false, true );
}
}
@ -448,17 +483,18 @@ function default_password_nag_handler($errors = false) {
* @param int $user_ID
* @param object $old_data
*/
function default_password_nag_edit_user($user_ID, $old_data) {
function default_password_nag_edit_user( $user_ID, $old_data ) {
// Short-circuit it.
if ( ! get_user_option('default_password_nag', $user_ID) )
if ( ! get_user_option( 'default_password_nag', $user_ID ) ) {
return;
}
$new_data = get_userdata($user_ID);
$new_data = get_userdata( $user_ID );
// Remove the nag if the password has been changed.
if ( $new_data->user_pass != $old_data->user_pass ) {
delete_user_setting('default_password_nag');
update_user_option($user_ID, 'default_password_nag', false, true);
delete_user_setting( 'default_password_nag' );
update_user_option( $user_ID, 'default_password_nag', false, true );
}
}
@ -470,16 +506,17 @@ function default_password_nag_edit_user($user_ID, $old_data) {
function default_password_nag() {
global $pagenow;
// Short-circuit it.
if ( 'profile.php' == $pagenow || ! get_user_option('default_password_nag') )
if ( 'profile.php' == $pagenow || ! get_user_option( 'default_password_nag' ) ) {
return;
}
echo '<div class="error default-password-nag">';
echo '<p>';
echo '<strong>' . __('Notice:') . '</strong> ';
_e('You&rsquo;re using the auto-generated password for your account. Would you like to change it?');
echo '<strong>' . __( 'Notice:' ) . '</strong> ';
_e( 'You&rsquo;re using the auto-generated password for your account. Would you like to change it?' );
echo '</p><p>';
printf( '<a href="%s">' . __('Yes, take me to my profile page') . '</a> | ', get_edit_profile_url() . '#password' );
printf( '<a href="%s" id="default-password-nag-no">' . __('No thanks, do not remind me again') . '</a>', '?default_password_nag=0' );
printf( '<a href="%s">' . __( 'Yes, take me to my profile page' ) . '</a> | ', get_edit_profile_url() . '#password' );
printf( '<a href="%s" id="default-password-nag-no">' . __( 'No thanks, do not remind me again' ) . '</a>', '?default_password_nag=0' );
echo '</p></div>';
}
@ -487,7 +524,8 @@ function default_password_nag() {
* @since 3.5.0
* @access private
*/
function delete_users_add_js() { ?>
function delete_users_add_js() {
?>
<script>
jQuery(document).ready( function($) {
var submit = $('#submit').prop('disabled', true);
@ -499,7 +537,7 @@ jQuery(document).ready( function($) {
});
});
</script>
<?php
<?php
}
/**
@ -509,34 +547,40 @@ jQuery(document).ready( function($) {
*
* @since 2.7.0
*
* @param object $user User data object
* @param object $user User data object.
*/
function use_ssl_preference($user) {
?>
function use_ssl_preference( $user ) {
?>
<tr class="user-use-ssl-wrap">
<th scope="row"><?php _e('Use https')?></th>
<td><label for="use_ssl"><input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked('1', $user->use_ssl); ?> /> <?php _e('Always use https when visiting the admin'); ?></label></td>
<th scope="row"><?php _e( 'Use https' ); ?></th>
<td><label for="use_ssl"><input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked( '1', $user->use_ssl ); ?> /> <?php _e( 'Always use https when visiting the admin' ); ?></label></td>
</tr>
<?php
<?php
}
/**
*
* @param string $text
* @return string
*/
function admin_created_user_email( $text ) {
$roles = get_editable_roles();
$role = $roles[ $_REQUEST['role'] ];
/* translators: 1: Site name, 2: site URL, 3: role */
return sprintf( __( 'Hi,
$role = $roles[ $_REQUEST['role'] ];
/* translators: 1: site name, 2: site URL, 3: role */
return sprintf(
__(
'Hi,
You\'ve been invited to join \'%1$s\' at
%2$s with the role of %3$s.
If you do not want to join this site please ignore
this email. This invitation will expire in a few days.
Please click the following link to activate your user account:
%%s' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ) );
%%s'
),
wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
home_url(),
wp_specialchars_decode( translate_user_role( $role['name'] ) )
);
}
/**
@ -574,24 +618,26 @@ function _wp_privacy_resend_request( $request_id ) {
* @access private
*
* @param int $request_id Request ID.
* @return int|WP_Error $request Request ID on success or WP_Error.
* @return int|WP_Error $result Request ID on success or WP_Error.
*/
function _wp_privacy_completed_request( $request_id ) {
$request_id = absint( $request_id );
$request_data = wp_get_user_request_data( $request_id );
$request_id = absint( $request_id );
$request = wp_get_user_request_data( $request_id );
if ( ! $request_data ) {
if ( ! $request ) {
return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) );
}
update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() );
$request = wp_update_post( array(
'ID' => $request_id,
'post_status' => 'request-completed',
) );
$result = wp_update_post(
array(
'ID' => $request_id,
'post_status' => 'request-completed',
)
);
return $request;
return $result;
}
/**
@ -712,29 +758,33 @@ function _wp_personal_data_handle_actions() {
*/
function _wp_personal_data_cleanup_requests() {
/** This filter is documented in wp-includes/user.php */
$expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS );
$expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS );
$requests_query = new WP_Query( array(
'post_type' => 'user_request',
'posts_per_page' => -1,
'post_status' => 'request-pending',
'fields' => 'ids',
'date_query' => array(
array(
'column' => 'post_modified_gmt',
'before' => $expires . ' seconds ago',
$requests_query = new WP_Query(
array(
'post_type' => 'user_request',
'posts_per_page' => -1,
'post_status' => 'request-pending',
'fields' => 'ids',
'date_query' => array(
array(
'column' => 'post_modified_gmt',
'before' => $expires . ' seconds ago',
),
),
),
) );
)
);
$request_ids = $requests_query->posts;
foreach ( $request_ids as $request_id ) {
wp_update_post( array(
'ID' => $request_id,
'post_status' => 'request-failed',
'post_password' => '',
) );
wp_update_post(
array(
'ID' => $request_id,
'post_status' => 'request-failed',
'post_password' => '',
)
);
}
}
@ -755,10 +805,13 @@ function _wp_personal_data_export_page() {
// "Borrow" xfn.js for now so we don't have to create new files.
wp_enqueue_script( 'xfn' );
$requests_table = new WP_Privacy_Data_Export_Requests_Table( array(
'plural' => 'privacy_requests',
'singular' => 'privacy_request',
) );
$requests_table = new WP_Privacy_Data_Export_Requests_Table(
array(
'plural' => 'privacy_requests',
'singular' => 'privacy_request',
'screen' => 'export_personal_data',
)
);
$requests_table->process_bulk_action();
$requests_table->prepare_items();
?>
@ -826,10 +879,13 @@ function _wp_personal_data_removal_page() {
// "Borrow" xfn.js for now so we don't have to create new files.
wp_enqueue_script( 'xfn' );
$requests_table = new WP_Privacy_Data_Removal_Requests_Table( array(
'plural' => 'privacy_requests',
'singular' => 'privacy_request',
) );
$requests_table = new WP_Privacy_Data_Removal_Requests_Table(
array(
'plural' => 'privacy_requests',
'singular' => 'privacy_request',
'screen' => 'remove_personal_data',
)
);
$requests_table->process_bulk_action();
$requests_table->prepare_items();
@ -972,7 +1028,7 @@ function _wp_privacy_hook_requests_page() {
*/
function _wp_privacy_requests_screen_options() {
$args = array(
'option' => str_replace( 'tools_page_', '', get_current_screen()->id ) . '_requests_per_page',
'option' => str_replace( 'tools_page_', '', get_current_screen()->id ) . '_requests_per_page',
);
add_screen_option( 'per_page', $args );
}
@ -1036,7 +1092,15 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table {
* @return array Default sortable columns.
*/
protected function get_sortable_columns() {
return array();
// The initial sorting is by 'Requested' (post_date) and descending.
// With initial sorting, the first click on 'Requested' should be ascending.
// With 'Requester' sorting active, the next click on 'Requested' should be descending.
$desc_first = isset( $_GET['orderby'] );
return array(
'email' => 'requester',
'created_timestamp' => array( 'requested', $desc_first ),
);
}
/**
@ -1100,13 +1164,47 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table {
$views = array();
$admin_url = admin_url( 'tools.php?page=' . $this->request_type );
$counts = $this->get_request_counts();
$total_requests = absint( array_sum( (array) $counts ) );
$current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : '';
$views['all'] = '<a href="' . esc_url( $admin_url ) . "\" $current_link_attributes>" . esc_html__( 'All' ) . ' (' . absint( array_sum( (array) $counts ) ) . ')</a>';
$status_label = sprintf(
/* translators: %s: all requests count */
_nx(
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
$total_requests,
'requests'
),
number_format_i18n( $total_requests )
);
$views['all'] = sprintf(
'<a href="%s"%s>%s</a>',
esc_url( $admin_url ),
$current_link_attributes,
$status_label
);
foreach ( $statuses as $status => $label ) {
$post_status = get_post_status_object( $status );
if ( ! $post_status ) {
continue;
}
$current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : '';
$views[ $status ] = '<a href="' . esc_url( add_query_arg( 'filter-status', $status, $admin_url ) ) . "\" $current_link_attributes>" . esc_html( $label ) . ' (' . absint( $counts->$status ) . ')</a>';
$total_status_requests = absint( $counts->{$status} );
$status_label = sprintf(
translate_nooped_plural( $post_status->label_count, $total_status_requests ),
number_format_i18n( $total_status_requests )
);
$status_link = add_query_arg( 'filter-status', $status, $admin_url );
$views[ $status ] = sprintf(
'<a href="%s"%s>%s</a>',
esc_url( $status_link ),
$current_link_attributes,
$status_label
);
}
return $views;
@ -1134,8 +1232,8 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table {
public function process_bulk_action() {
$action = $this->current_action();
$request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array();
$count = 0;
$count = 0;
if ( $request_ids ) {
check_admin_referer( 'bulk-privacy_requests' );
@ -1181,18 +1279,11 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table {
* Prepare items to output.
*
* @since 4.9.6
* @since 5.1.0 Added support for column sorting.
*/
public function prepare_items() {
global $wpdb;
$primary = $this->get_primary_column_name();
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns(),
$primary,
);
$this->items = array();
$posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' );
$args = array(
@ -1204,6 +1295,19 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table {
's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '',
);
$orderby_mapping = array(
'requester' => 'post_title',
'requested' => 'post_date',
);
if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) {
$args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ];
}
if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) {
$args['order'] = strtoupper( $_REQUEST['order'] );
}
if ( ! empty( $_REQUEST['filter-status'] ) ) {
$filter_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : '';
$args['post_status'] = $filter_status;
@ -1461,10 +1565,18 @@ class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table {
submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
break;
case 'request-completed':
echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
'action' => 'delete',
'request_id' => array( $item->ID ),
), admin_url( 'tools.php?page=export_personal_data' ) ), 'bulk-privacy_requests' ) ) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
echo '<a href="' . esc_url(
wp_nonce_url(
add_query_arg(
array(
'action' => 'delete',
'request_id' => array( $item->ID ),
),
admin_url( 'tools.php?page=export_personal_data' )
),
'bulk-privacy_requests'
)
) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
break;
}
}
@ -1575,10 +1687,18 @@ class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table {
submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
break;
case 'request-completed':
echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
'action' => 'delete',
'request_id' => array( $item->ID ),
), admin_url( 'tools.php?page=remove_personal_data' ) ), 'bulk-privacy_requests' ) ) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
echo '<a href="' . esc_url(
wp_nonce_url(
add_query_arg(
array(
'action' => 'delete',
'request_id' => array( $item->ID ),
),
admin_url( 'tools.php?page=remove_personal_data' )
),
'bulk-privacy_requests'
)
) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
break;
}
}

View file

@ -22,29 +22,41 @@ function wp_list_widgets() {
$done = array();
foreach ( $sort as $widget ) {
if ( in_array( $widget['callback'], $done, true ) ) // We already showed this multi-widget
if ( in_array( $widget['callback'], $done, true ) ) { // We already showed this multi-widget
continue;
$sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false );
$done[] = $widget['callback'];
if ( ! isset( $widget['params'][0] ) )
$widget['params'][0] = array();
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
$args['_temp_id'] = "$id_base-__i__";
$args['_multi_num'] = next_widget_id_number($id_base);
$args['_add'] = 'multi';
} else {
$args['_add'] = 'single';
if ( $sidebar )
$args['_hide'] = '1';
}
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
$sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false );
$done[] = $widget['callback'];
if ( ! isset( $widget['params'][0] ) ) {
$widget['params'][0] = array();
}
$args = array(
'widget_id' => $widget['id'],
'widget_name' => $widget['name'],
'_display' => 'template',
);
if ( isset( $wp_registered_widget_controls[ $widget['id'] ]['id_base'] ) && isset( $widget['params'][0]['number'] ) ) {
$id_base = $wp_registered_widget_controls[ $widget['id'] ]['id_base'];
$args['_temp_id'] = "$id_base-__i__";
$args['_multi_num'] = next_widget_id_number( $id_base );
$args['_add'] = 'multi';
} else {
$args['_add'] = 'single';
if ( $sidebar ) {
$args['_hide'] = '1';
}
}
$args = wp_list_widget_controls_dynamic_sidebar(
array(
0 => $args,
1 => $widget['params'][0],
)
);
call_user_func_array( 'wp_widget_control', $args );
}
}
@ -78,8 +90,13 @@ function wp_list_widget_controls( $sidebar, $sidebar_name = '' ) {
echo '<div id="' . esc_attr( $sidebar ) . '" class="widgets-sortables">';
if ( $sidebar_name ) {
$add_to = sprintf(
/* translators: %s: widgets sidebar name. */
__( 'Add to: %s' ),
$sidebar_name
);
?>
<div class="sidebar-name">
<div class="sidebar-name" data-add-to="<?php echo esc_attr( $add_to ); ?>">
<button type="button" class="handlediv hide-if-no-js" aria-expanded="true">
<span class="screen-reader-text"><?php echo esc_html( $sidebar_name ); ?></span>
<span class="toggle-indicator" aria-hidden="true"></span>
@ -120,23 +137,22 @@ function wp_list_widget_controls_dynamic_sidebar( $params ) {
$i++;
$widget_id = $params[0]['widget_id'];
$id = isset($params[0]['_temp_id']) ? $params[0]['_temp_id'] : $widget_id;
$hidden = isset($params[0]['_hide']) ? ' style="display:none;"' : '';
$id = isset( $params[0]['_temp_id'] ) ? $params[0]['_temp_id'] : $widget_id;
$hidden = isset( $params[0]['_hide'] ) ? ' style="display:none;"' : '';
$params[0]['before_widget'] = "<div id='widget-{$i}_{$id}' class='widget'$hidden>";
$params[0]['after_widget'] = "</div>";
$params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated
$params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated
if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) {
$wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
$wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control';
$params[0]['after_widget'] = '</div>';
$params[0]['before_title'] = '%BEG_OF_TITLE%'; // deprecated
$params[0]['after_title'] = '%END_OF_TITLE%'; // deprecated
if ( is_callable( $wp_registered_widgets[ $widget_id ]['callback'] ) ) {
$wp_registered_widgets[ $widget_id ]['_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
$wp_registered_widgets[ $widget_id ]['callback'] = 'wp_widget_control';
}
return $params;
}
/**
*
* @global array $wp_registered_widgets
*
* @param string $id_base
@ -147,8 +163,9 @@ function next_widget_id_number( $id_base ) {
$number = 1;
foreach ( $wp_registered_widgets as $widget_id => $widget ) {
if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) )
$number = max($number, $matches[1]);
if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) ) {
$number = max( $number, $matches[1] );
}
}
$number++;
@ -172,58 +189,63 @@ function next_widget_id_number( $id_base ) {
function wp_widget_control( $sidebar_args ) {
global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets;
$widget_id = $sidebar_args['widget_id'];
$sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false;
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : '-1'; // position of widget in sidebar
$control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array();
$widget = $wp_registered_widgets[$widget_id];
$widget_id = $sidebar_args['widget_id'];
$sidebar_id = isset( $sidebar_args['id'] ) ? $sidebar_args['id'] : false;
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[ $sidebar_id ] ) : '-1'; // position of widget in sidebar
$control = isset( $wp_registered_widget_controls[ $widget_id ] ) ? $wp_registered_widget_controls[ $widget_id ] : array();
$widget = $wp_registered_widgets[ $widget_id ];
$id_format = $widget['id'];
$widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : '';
$id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id;
$multi_number = isset($sidebar_args['_multi_num']) ? $sidebar_args['_multi_num'] : '';
$add_new = isset($sidebar_args['_add']) ? $sidebar_args['_add'] : '';
$id_format = $widget['id'];
$widget_number = isset( $control['params'][0]['number'] ) ? $control['params'][0]['number'] : '';
$id_base = isset( $control['id_base'] ) ? $control['id_base'] : $widget_id;
$width = isset( $control['width'] ) ? $control['width'] : '';
$height = isset( $control['height'] ) ? $control['height'] : '';
$multi_number = isset( $sidebar_args['_multi_num'] ) ? $sidebar_args['_multi_num'] : '';
$add_new = isset( $sidebar_args['_add'] ) ? $sidebar_args['_add'] : '';
$before_form = isset( $sidebar_args['before_form'] ) ? $sidebar_args['before_form'] : '<form method="post">';
$after_form = isset( $sidebar_args['after_form'] ) ? $sidebar_args['after_form'] : '</form>';
$before_form = isset( $sidebar_args['before_form'] ) ? $sidebar_args['before_form'] : '<form method="post">';
$after_form = isset( $sidebar_args['after_form'] ) ? $sidebar_args['after_form'] : '</form>';
$before_widget_content = isset( $sidebar_args['before_widget_content'] ) ? $sidebar_args['before_widget_content'] : '<div class="widget-content">';
$after_widget_content = isset( $sidebar_args['after_widget_content'] ) ? $sidebar_args['after_widget_content'] : '</div>';
$after_widget_content = isset( $sidebar_args['after_widget_content'] ) ? $sidebar_args['after_widget_content'] : '</div>';
$query_arg = array( 'editwidget' => $widget['id'] );
if ( $add_new ) {
$query_arg['addnew'] = 1;
if ( $multi_number ) {
$query_arg['num'] = $multi_number;
$query_arg['num'] = $multi_number;
$query_arg['base'] = $id_base;
}
} else {
$query_arg['sidebar'] = $sidebar_id;
$query_arg['key'] = $key;
$query_arg['key'] = $key;
}
/*
* We aren't showing a widget control, we're outputting a template
* for a multi-widget control.
*/
if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) {
if ( isset( $sidebar_args['_display'] ) && 'template' == $sidebar_args['_display'] && $widget_number ) {
// number == -1 implies a template where id numbers are replaced by a generic '__i__'
$control['params'][0]['number'] = -1;
// With id_base widget id's are constructed like {$id_base}-{$id_number}.
if ( isset($control['id_base']) )
if ( isset( $control['id_base'] ) ) {
$id_format = $control['id_base'] . '-__i__';
}
}
$wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback'];
unset($wp_registered_widgets[$widget_id]['_callback']);
$wp_registered_widgets[ $widget_id ]['callback'] = $wp_registered_widgets[ $widget_id ]['_callback'];
unset( $wp_registered_widgets[ $widget_id ]['_callback'] );
$widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) );
$has_form = 'noform';
$has_form = 'noform';
echo $sidebar_args['before_widget']; ?>
echo $sidebar_args['before_widget'];
?>
<div class="widget-top">
<div class="widget-title-action">
<button type="button" class="widget-action hide-if-no-js" aria-expanded="false">
<span class="screen-reader-text"><?php printf( __( 'Edit widget: %s' ), $widget_title ); ?></span>
<span class="screen-reader-text edit"><?php printf( __( 'Edit widget: %s' ), $widget_title ); ?></span>
<span class="screen-reader-text add"><?php printf( __( 'Add widget: %s' ), $widget_title ); ?></span>
<span class="toggle-indicator" aria-hidden="true"></span>
</button>
<a class="widget-control-edit hide-if-js" href="<?php echo esc_url( add_query_arg( $query_arg ) ); ?>">
@ -242,17 +264,22 @@ function wp_widget_control( $sidebar_args ) {
if ( isset( $control['callback'] ) ) {
$has_form = call_user_func_array( $control['callback'], $control['params'] );
} else {
echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n";
echo "\t\t<p>" . __( 'There are no options for this widget.' ) . "</p>\n";
}
$noform_class = '';
if ( 'noform' === $has_form ) {
$noform_class = ' widget-control-noform';
}
?>
<?php echo $after_widget_content; ?>
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($id_format); ?>" />
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
<input type="hidden" name="widget-width" class="widget-width" value="<?php if (isset( $control['width'] )) echo esc_attr($control['width']); ?>" />
<input type="hidden" name="widget-height" class="widget-height" value="<?php if (isset( $control['height'] )) echo esc_attr($control['height']); ?>" />
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo esc_attr($widget_number); ?>" />
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" />
<input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr($add_new); ?>" />
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr( $id_format ); ?>" />
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr( $id_base ); ?>" />
<input type="hidden" name="widget-width" class="widget-width" value="<?php echo esc_attr( $width ); ?>" />
<input type="hidden" name="widget-height" class="widget-height" value="<?php echo esc_attr( $height ); ?>" />
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo esc_attr( $widget_number ); ?>" />
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr( $multi_number ); ?>" />
<input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr( $add_new ); ?>" />
<div class="widget-control-actions">
<div class="alignleft">
@ -262,7 +289,7 @@ function wp_widget_control( $sidebar_args ) {
<button type="button" class="button-link widget-control-close"><?php _e( 'Done' ); ?></button>
</span>
</div>
<div class="alignright<?php if ( 'noform' === $has_form ) echo ' widget-control-noform'; ?>">
<div class="alignright<?php echo $noform_class; ?>">
<?php submit_button( __( 'Save' ), 'primary widget-control-save right', 'savewidget', false, array( 'id' => 'widget-' . esc_attr( $id_format ) . '-savewidget' ) ); ?>
<span class="spinner"></span>
</div>
@ -272,19 +299,18 @@ function wp_widget_control( $sidebar_args ) {
</div>
<div class="widget-description">
<?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?>
<?php echo ( $widget_description = wp_widget_description( $widget_id ) ) ? "$widget_description\n" : "$widget_title\n"; ?>
</div>
<?php
<?php
echo $sidebar_args['after_widget'];
return $sidebar_args;
}
/**
*
* @param string $classes
* @return string
*/
function wp_widgets_access_body_class($classes) {
function wp_widgets_access_body_class( $classes ) {
return "$classes widgets_access ";
}