PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,152 @@
<?php
/**
* Administration API: Default admin hooks
*
* @package WordPress
* @subpackage Administration
* @since 4.3.0
*/
// Bookmark hooks.
add_action( 'admin_page_access_denied', 'wp_link_manager_disabled_message' );
// Dashboard hooks.
add_action( 'activity_box_end', 'wp_dashboard_quota' );
// Media hooks.
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( 'post-plupload-upload-ui', 'media_upload_flash_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( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 );
add_filter( 'media_upload_gallery', 'media_upload_gallery' );
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_head', 'wp_color_scheme_settings' );
add_action( 'admin_head', 'wp_site_icon' );
add_action( 'admin_head', '_ipad_meta' );
// Privacy tools
add_action( 'admin_menu', '_wp_privacy_hook_requests_page' );
add_action( 'load-tools_page_export_personal_data', '_wp_privacy_requests_screen_options' );
add_action( 'load-tools_page_remove_personal_data', '_wp_privacy_requests_screen_options' );
// Prerendering.
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-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_page_on_front', 'update_home_siteurl', 10, 2 );
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( '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( 'wp_refresh_nonces', 'wp_refresh_post_nonces', 10, 3 );
add_filter( 'wp_refresh_nonces', 'wp_refresh_heartbeat_nonces' );
add_filter( 'heartbeat_settings', 'wp_heartbeat_set_suspension' );
// Nav Menu hooks.
add_action( 'admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items' );
// Plugin hooks.
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_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' ) );
// Theme hooks.
add_action( 'customize_controls_print_footer_scripts', 'customize_themes_print_templates' );
// Theme Install hooks.
add_action( 'install_themes_pre_theme-information', 'install_theme_information' );
// User hooks.
add_action( 'admin_init', 'default_password_nag_handler' );
add_action( 'admin_notices', 'default_password_nag' );
add_action( 'admin_notices', 'new_user_email_admin_notice' );
add_action( 'profile_update', 'default_password_nag_edit_user', 10, 2 );
add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
// Update hooks.
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', 'maintenance_nag', 10 );
add_filter( 'update_footer', 'core_update_footer' );
// Update Core hooks.
add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );
// Upgrade hooks.
add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
add_action( 'upgrader_process_complete', 'wp_version_check', 10, 0 );
add_action( 'upgrader_process_complete', 'wp_update_plugins', 10, 0 );
add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
// Privacy hooks
add_filter( 'wp_privacy_personal_data_erasure_page', 'wp_privacy_process_personal_data_erasure_page', 10, 5 );
add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 );
add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
add_action( 'wp_privacy_personal_data_erased', '_wp_privacy_send_erasure_fulfillment_notification', 10 );
// Privacy policy text changes check.
add_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'text_change_check' ), 100 );
// Show a "postbox" with the text suggestions for a privacy policy.
add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'notice' ) );
// Add the suggested policy text from WordPress.
add_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'add_suggested_content' ), 1 );
// Update the cached policy info when the policy page is updated.
add_action( 'post_updated', array( 'WP_Privacy_Policy_Content', '_policy_page_updated' ) );
// Append '(Draft)' to draft page titles in the privacy page dropdown.
add_filter( 'list_pages', '_wp_privacy_settings_filter_draft_page_titles', 10, 2 );

View File

@ -0,0 +1,87 @@
<?php
/**
* Core Administration API
*
* @package WordPress
* @subpackage Administration
* @since 2.3.0
*/
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
* load_default_textdomain() will not have done so in this context.
*/
load_textdomain( 'default', WP_LANG_DIR . '/admin-' . get_locale() . '.mo' );
}
/** WordPress Administration Hooks */
require_once( ABSPATH . 'wp-admin/includes/admin-filters.php' );
/** WordPress Bookmark Administration API */
require_once( ABSPATH . 'wp-admin/includes/bookmark.php' );
/** WordPress Comment Administration API */
require_once( ABSPATH . 'wp-admin/includes/comment.php' );
/** WordPress Administration File API */
require_once( ABSPATH . 'wp-admin/includes/file.php' );
/** WordPress Image Administration API */
require_once( ABSPATH . 'wp-admin/includes/image.php' );
/** WordPress Media Administration API */
require_once( ABSPATH . 'wp-admin/includes/media.php' );
/** WordPress Import Administration API */
require_once( ABSPATH . 'wp-admin/includes/import.php' );
/** WordPress Misc Administration API */
require_once( ABSPATH . 'wp-admin/includes/misc.php' );
/** WordPress Options Administration API */
require_once( ABSPATH . 'wp-admin/includes/options.php' );
/** WordPress Plugin Administration API */
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
/** WordPress Post Administration API */
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' );
/** WordPress Taxonomy Administration API */
require_once( ABSPATH . 'wp-admin/includes/taxonomy.php' );
/** WordPress Template Administration API */
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' );
/** WordPress Theme Administration API */
require_once( ABSPATH . 'wp-admin/includes/theme.php' );
/** WordPress User Administration API */
require_once( ABSPATH . 'wp-admin/includes/user.php' );
/** WordPress Site Icon API */
require_once( ABSPATH . 'wp-admin/includes/class-wp-site-icon.php' );
/** WordPress Update Administration API */
require_once( ABSPATH . 'wp-admin/includes/update.php' );
/** WordPress Deprecated Administration API */
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' );
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,327 @@
<?php
/**
* WordPress Bookmark Administration API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Add a link to using values provided in $_POST.
*
* @since 2.0.0
*
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
*/
function add_link() {
return edit_link();
}
/**
* Updates or inserts a link using values provided in $_POST.
*
* @since 2.0.0
*
* @param int $link_id Optional. ID of the link to edit. Default 0.
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
*/
function edit_link( $link_id = 0 ) {
if ( ! current_user_can( 'manage_links' ) ) {
wp_die(
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
'<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>',
403
);
}
$_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_visible'] = 'Y';
}
if ( ! empty( $link_id ) ) {
$_POST['link_id'] = $link_id;
return wp_update_link( $_POST );
} else {
return wp_insert_link( $_POST );
}
}
/**
* Retrieves the default link for editing.
*
* @since 2.0.0
*
* @return stdClass Default link object.
*/
function get_default_link_to_edit() {
$link = new stdClass;
if ( isset( $_GET['linkurl'] ) ) {
$link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) );
} else {
$link->link_url = '';
}
if ( isset( $_GET['name'] ) ) {
$link->link_name = esc_attr( wp_unslash( $_GET['name'] ) );
} else {
$link->link_name = '';
}
$link->link_visible = 'Y';
return $link;
}
/**
* Deletes a specified link from the database.
*
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $link_id ID of the link to delete
* @return true Always true.
*/
function wp_delete_link( $link_id ) {
global $wpdb;
/**
* Fires before a link is deleted.
*
* @since 2.0.0
*
* @param int $link_id ID of the link to delete.
*/
do_action( 'delete_link', $link_id );
wp_delete_object_term_relationships( $link_id, 'link_category' );
$wpdb->delete( $wpdb->links, array( 'link_id' => $link_id ) );
/**
* Fires after a link has been deleted.
*
* @since 2.2.0
*
* @param int $link_id ID of the deleted link.
*/
do_action( 'deleted_link', $link_id );
clean_bookmark_cache( $link_id );
return true;
}
/**
* Retrieves the link categories associated with the link specified.
*
* @since 2.1.0
*
* @param int $link_id Link ID to look up
* @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' ) );
return array_unique( $cats );
}
/**
* Retrieves link data based on its ID.
*
* @since 2.0.0
*
* @param int|stdClass $link Link ID or object to retrieve.
* @return object Link object for editing.
*/
function get_link_to_edit( $link ) {
return get_bookmark( $link, OBJECT, 'edit' );
}
/**
* Inserts/updates links into/in the database.
*
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param array $linkdata Elements that make up the link to insert.
* @param bool $wp_error Optional. Whether to return a WP_Error object on failure. Default false.
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
*/
function wp_insert_link( $linkdata, $wp_error = false ) {
global $wpdb;
$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' ) );
$link_id = $r['link_id'];
$link_name = $r['link_name'];
$link_url = $r['link_url'];
$update = false;
if ( ! empty( $link_id ) ) {
$update = true;
}
if ( trim( $link_name ) == '' ) {
if ( trim( $link_url ) != '' ) {
$link_name = $link_url;
} else {
return 0;
}
}
if ( trim( $link_url ) == '' ) {
return 0;
}
$link_rating = ( ! empty( $r['link_rating'] ) ) ? $r['link_rating'] : 0;
$link_image = ( ! empty( $r['link_image'] ) ) ? $r['link_image'] : '';
$link_target = ( ! empty( $r['link_target'] ) ) ? $r['link_target'] : '';
$link_visible = ( ! empty( $r['link_visible'] ) ) ? $r['link_visible'] : 'Y';
$link_owner = ( ! empty( $r['link_owner'] ) ) ? $r['link_owner'] : get_current_user_id();
$link_notes = ( ! empty( $r['link_notes'] ) ) ? $r['link_notes'] : '';
$link_description = ( ! empty( $r['link_description'] ) ) ? $r['link_description'] : '';
$link_rss = ( ! empty( $r['link_rss'] ) ) ? $r['link_rss'] : '';
$link_rel = ( ! empty( $r['link_rel'] ) ) ? $r['link_rel'] : '';
$link_category = ( ! empty( $r['link_category'] ) ) ? $r['link_category'] : array();
// Make sure we set a valid category.
if ( ! is_array( $link_category ) || 0 == count( $link_category ) ) {
$link_category = array( get_option( 'default_link_category' ) );
}
if ( $update ) {
if ( false === $wpdb->update( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ), compact( 'link_id' ) ) ) {
if ( $wp_error ) {
return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
} else {
return 0;
}
}
} else {
if ( false === $wpdb->insert( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ) ) ) {
if ( $wp_error ) {
return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
} else {
return 0;
}
}
$link_id = (int) $wpdb->insert_id;
}
wp_set_link_cats( $link_id, $link_category );
if ( $update ) {
/**
* Fires after a link was updated in the database.
*
* @since 2.0.0
*
* @param int $link_id ID of the link that was updated.
*/
do_action( 'edit_link', $link_id );
} else {
/**
* Fires after a link was added to the database.
*
* @since 2.0.0
*
* @param int $link_id ID of the link that was added.
*/
do_action( 'add_link', $link_id );
}
clean_bookmark_cache( $link_id );
return $link_id;
}
/**
* Update link with the specified link categories.
*
* @since 2.1.0
*
* @param int $link_id ID of the link to update.
* @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 ) ) {
$link_categories = array( get_option( 'default_link_category' ) );
}
$link_categories = array_map( 'intval', $link_categories );
$link_categories = array_unique( $link_categories );
wp_set_object_terms( $link_id, $link_categories, 'link_category' );
clean_bookmark_cache( $link_id );
}
/**
* Updates a link in the database.
*
* @since 2.0.0
*
* @param array $linkdata Link data to update.
* @return int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success.
*/
function wp_update_link( $linkdata ) {
$link_id = (int) $linkdata['link_id'];
$link = get_bookmark( $link_id, ARRAY_A );
// Escape data pulled from DB.
$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'] ) ) {
$link_cats = $linkdata['link_category'];
} else {
$link_cats = $link['link_category'];
}
// Merge old and new fields with new fields overwriting old ones.
$linkdata = array_merge( $link, $linkdata );
$linkdata['link_category'] = $link_cats;
return wp_insert_link( $linkdata );
}
/**
* Outputs the 'disabled' message for the WordPress Link Manager.
*
* @since 3.5.0
* @access private
*
* @global string $pagenow
*/
function wp_link_manager_disabled_message() {
global $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' );
remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
if ( $really_can_manage_links && current_user_can( 'install_plugins' ) ) {
$link = network_admin_url( 'plugin-install.php?tab=search&amp;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 ) );
}
wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) );
}

View File

@ -0,0 +1,118 @@
<?php
/**
* Upgrader API: Automatic_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Upgrader Skin for Automatic WordPress Upgrades
*
* This skin is designed to be used when no output is intended, all output
* is captured and stored for the caller to process and log/email/discard.
*
* @since 3.7.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see Bulk_Upgrader_Skin
*/
class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
protected $messages = array();
/**
* Determines whether the upgrader needs FTP/SSH details in order to connect
* to the filesystem.
*
* @since 3.7.0
* @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
*
* @see request_filesystem_credentials()
*
* @param bool $error Optional. Whether the current request has failed to connect.
* Default false.
* @param string $context Optional. Full path to the directory that is tested
* for being writable. Default empty.
* @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
* @return bool True on success, false on failure.
*/
public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
if ( $context ) {
$this->options['context'] = $context;
}
// TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
// This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
ob_start();
$result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
ob_end_clean();
return $result;
}
/**
* @return array
*/
public function get_upgrade_messages() {
return $this->messages;
}
/**
* @param string|array|WP_Error $data
*/
public function feedback( $data ) {
if ( is_wp_error( $data ) ) {
$string = $data->get_error_message();
} elseif ( is_array( $data ) ) {
return;
} else {
$string = $data;
}
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 ) ) {
$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,
)
);
if ( empty( $string ) ) {
return;
}
$this->messages[] = $string;
}
/**
*/
public function header() {
ob_start();
}
/**
*/
public function footer() {
$output = ob_get_clean();
if ( ! empty( $output ) ) {
$this->feedback( $output );
}
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* Upgrader API: Bulk_Plugin_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Bulk Plugin Upgrader Skin for WordPress Plugin Upgrades.
*
* @since 3.0.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see Bulk_Upgrader_Skin
*/
class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
public $plugin_info = array(); // Plugin_Upgrader::bulk_upgrade() will fill this in.
public function add_strings() {
parent::add_strings();
/* 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'] );
}
/**
* @param string $title
*/
public function after( $title = '' ) {
parent::after( $this->plugin_info['Title'] );
$this->decrement_update_count( 'plugin' );
}
/**
*/
public function bulk_footer() {
parent::bulk_footer();
$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>',
);
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 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 ) );
}
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* Upgrader API: Bulk_Plugin_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Bulk Theme Upgrader Skin for WordPress Theme Upgrades.
*
* @since 3.0.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see Bulk_Upgrader_Skin
*/
class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
public $theme_info = array(); // Theme_Upgrader::bulk_upgrade() will fill this in.
public function add_strings() {
parent::add_strings();
/* 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' ) );
}
/**
* @param string $title
*/
public function after( $title = '' ) {
parent::after( $this->theme_info->display( 'Name' ) );
$this->decrement_update_count( 'theme' );
}
/**
*/
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>',
);
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 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 ) );
}
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* Upgrader API: Bulk_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Generic Bulk Upgrader Skin for WordPress Upgrades.
*
* @since 3.0.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see WP_Upgrader_Skin
*/
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
public $in_loop = false;
/**
* @var string|false
*/
public $error = false;
/**
* @param array $args
*/
public function __construct( $args = array() ) {
$defaults = array(
'url' => '',
'nonce' => '',
);
$args = wp_parse_args( $args, $defaults );
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.' );
/* 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: %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 ];
}
if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( $args ) {
$args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args );
$string = vsprintf( $string, $args );
}
}
if ( empty( $string ) ) {
return;
}
if ( $this->in_loop ) {
echo "$string<br />\n";
} else {
echo "<p>$string</p>\n";
}
}
/**
*/
public function header() {
// Nothing, This will be displayed within a iframe.
}
/**
*/
public function footer() {
// Nothing, This will be displayed within a iframe.
}
/**
* @param string|WP_Error $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 ) ) {
$messages = array();
foreach ( $error->get_error_messages() as $emessage ) {
if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) {
$messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
} else {
$messages[] = $emessage;
}
}
$this->error = implode( ', ', $messages );
}
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
}
/**
*/
public function bulk_header() {
$this->feedback( 'skin_upgrade_start' );
}
/**
*/
public function bulk_footer() {
$this->feedback( 'skin_upgrade_end' );
}
/**
* @param string $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>';
// 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>';
$this->flush_output();
}
/**
* @param string $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>';
} else {
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>';
}
if ( $this->result && ! is_wp_error( $this->result ) ) {
if ( ! $this->error ) {
echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' .
'<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) .
' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' .
'</p></div>';
}
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
}
$this->reset();
$this->flush_output();
}
/**
*/
public function reset() {
$this->in_loop = false;
$this->error = false;
}
/**
*/
public function flush_output() {
wp_ob_end_flush_all();
flush();
}
}

View File

@ -0,0 +1,387 @@
<?php
/**
* Upgrade API: Core_Upgrader class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Core class used for updating core.
*
* It allows for WordPress to upgrade itself in combination with
* the wp-admin/includes/update-core.php file.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
*
* @see WP_Upgrader
*/
class Core_Upgrader extends WP_Upgrader {
/**
* Initialize the upgrade strings.
*
* @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.' );
/* 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['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' );
}
/**
* Upgrade WordPress core.
*
* @since 2.8.0
*
* @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.
* @param array $args {
* Optional. Arguments for upgrading WordPress core. Default empty array.
*
* @type bool $pre_check_md5 Whether to check the file checksums before
* attempting the upgrade. Default true.
* @type bool $attempt_rollback Whether to attempt to rollback the chances if
* there is a problem. Default false.
* @type bool $do_rollback Whether to perform this "upgrade" as a rollback.
* Default false.
* }
* @return null|false|WP_Error False or WP_Error on failure, null on success.
*/
public function upgrade( $current, $args = array() ) {
global $wp_filesystem;
include( ABSPATH . WPINC . '/version.php' ); // $wp_version;
$start_time = time();
$defaults = array(
'pre_check_md5' => true,
'attempt_rollback' => false,
'do_rollback' => false,
'allow_relaxed_file_ownership' => false,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$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'] );
}
$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() );
$partial = true;
if ( $parsed_args['do_rollback'] ) {
$partial = false;
} 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
* a reinstallation. If we cross the new_bundled version number, then use
* 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 ) {
$to_download = 'rollback';
} 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 ) ) {
$to_download = 'new_bundled';
} elseif ( $current->packages->no_content ) {
$to_download = 'no_content';
} else {
$to_download = 'full';
}
// Lock to prevent multiple Core Updates occurring
$lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS );
if ( ! $lock ) {
return new WP_Error( 'locked', $this->strings['locked'] );
}
$download = $this->download_package( $current->packages->$to_download );
if ( is_wp_error( $download ) ) {
WP_Upgrader::release_lock( 'core_updater' );
return $download;
}
$working_dir = $this->unpack_package( $download );
if ( is_wp_error( $working_dir ) ) {
WP_Upgrader::release_lock( 'core_updater' );
return $working_dir;
}
// 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 );
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 );
require_once( ABSPATH . 'wp-admin/includes/update-core.php' );
if ( ! function_exists( 'update_core' ) ) {
WP_Upgrader::release_lock( 'core_updater' );
return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] );
}
$result = update_core( $working_dir, $wp_dir );
// In the event of an issue, we may be able to roll back.
if ( $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) {
$try_rollback = false;
if ( is_wp_error( $result ) ) {
$error_code = $result->get_error_code();
/*
* Not all errors are equal. These codes are critical: copy_failed__copy_dir,
* 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' ) ) {
$try_rollback = true;
} elseif ( false !== strpos( $error_code, '__copy_dir' ) ) {
$try_rollback = true;
} elseif ( 'disk_full' === $error_code ) {
$try_rollback = true;
}
}
if ( $try_rollback ) {
/** This filter is documented in wp-admin/includes/update-core.php */
apply_filters( 'update_feedback', $result );
/** This filter is documented in wp-admin/includes/update-core.php */
apply_filters( 'update_feedback', $this->strings['start_rollback'] );
$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,
)
);
}
}
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
do_action(
'upgrader_process_complete',
$this,
array(
'action' => 'update',
'type' => 'core',
)
);
// Clear the current updates
delete_site_transient( 'update_core' );
if ( ! $parsed_args['do_rollback'] ) {
$stats = array(
'update_type' => $current->response,
'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'] : '',
'time_taken' => time() - $start_time,
'reported' => $wp_version,
'attempted' => $current->version,
);
if ( is_wp_error( $result ) ) {
$stats['success'] = false;
// Did a rollback occur?
if ( ! empty( $try_rollback ) ) {
$stats['error_code'] = $original_result->get_error_code();
$stats['error_data'] = $original_result->get_error_data();
// Was the rollback successful? If not, collect its error too.
$stats['rollback'] = ! is_wp_error( $rollback_result );
if ( is_wp_error( $rollback_result ) ) {
$stats['rollback_code'] = $rollback_result->get_error_code();
$stats['rollback_data'] = $rollback_result->get_error_data();
}
} else {
$stats['error_code'] = $result->get_error_code();
$stats['error_data'] = $result->get_error_data();
}
}
wp_version_check( $stats );
}
WP_Upgrader::release_lock( 'core_updater' );
return $result;
}
/**
* Determines if this WordPress Core version should update to an offered version or not.
*
* @since 3.7.0
*
* @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_is_development_version = (bool) strpos( $wp_version, '-' );
// Defaults:
$upgrade_dev = true;
$upgrade_minor = true;
$upgrade_major = false;
// WP_AUTO_UPDATE_CORE = true (all), 'minor', false.
if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
if ( false === WP_AUTO_UPDATE_CORE ) {
// Defaults to turned off, unless a filter allows it
$upgrade_dev = $upgrade_minor = $upgrade_major = false;
} elseif ( true === WP_AUTO_UPDATE_CORE ) {
// ALL updates for core
$upgrade_dev = $upgrade_minor = $upgrade_major = true;
} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
// Only minor updates for core
$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 ) {
return false;
}
// 2: If we're running a newer version, that's a nope
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'] ) ) {
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' ) ) {
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'] ) {
return false;
}
}
// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2
if ( $current_is_development_version ) {
/**
* Filters whether to enable automatic core updates for development versions.
*
* @since 3.7.0
*
* @param bool $upgrade_dev Whether to enable automatic updates for
* development versions.
*/
if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) {
return false;
}
// Else fall through to minor + major branches below.
}
// 4: Minor In-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4)
if ( $current_branch == $new_branch ) {
/**
* Filters whether to enable minor automatic core updates.
*
* @since 3.7.0
*
* @param bool $upgrade_minor Whether to enable minor automatic core updates.
*/
return apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
}
// 5: Major version updates (3.7.0 -> 3.8.0 -> 3.9.1)
if ( version_compare( $new_branch, $current_branch, '>' ) ) {
/**
* Filters whether to enable major automatic core updates.
*
* @since 3.7.0
*
* @param bool $upgrade_major Whether to enable major automatic core updates.
*/
return apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
}
// If we're not sure, we don't want it
return false;
}
/**
* Compare the disk file checksums against the expected checksums.
*
* @since 3.7.0
*
* @global string $wp_version
* @global string $wp_local_package
*
* @return bool True if the checksums match, otherwise false.
*/
public function check_files() {
global $wp_version, $wp_local_package;
$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
if ( ! is_array( $checksums ) ) {
return false;
}
foreach ( $checksums as $file => $checksum ) {
// Skip files which get updated
if ( 'wp-content' == substr( $file, 0, 10 ) ) {
continue;
}
if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,132 @@
<?php
/**
* Upgrade API: File_Upload_Upgrader class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Core class used for handling file uploads.
*
* This class handles the upload process and passes it as if it's a local file
* to the Upgrade/Installer functions.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
*/
class File_Upload_Upgrader {
/**
* The full path to the file package.
*
* @since 2.8.0
* @var string $package
*/
public $package;
/**
* The name of the file.
*
* @since 2.8.0
* @var string $filename
*/
public $filename;
/**
* The ID of the attachment post for this file.
*
* @since 3.3.0
* @var int $id
*/
public $id = 0;
/**
* Construct the upgrader for a form.
*
* @since 2.8.0
*
* @param string $form The name of the form the file was uploaded from.
* @param string $urlholder The name of the `GET` parameter that holds the filename.
*/
public function __construct( $form, $urlholder ) {
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 ( isset( $file['error'] ) ) {
wp_die( $file['error'] );
}
$this->filename = $_FILES[ $form ]['name'];
$this->package = $file['file'];
// Construct the object array
$object = array(
'post_title' => $this->filename,
'post_content' => $file['url'],
'post_mime_type' => $file['type'],
'guid' => $file['url'],
'context' => 'upgrader',
'post_status' => 'private',
);
// Save the data.
$this->id = wp_insert_attachment( $object, $file['file'] );
// 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 ] ) ) {
// Numeric Package = previously uploaded file, see above.
$this->id = (int) $_GET[ $urlholder ];
$attachment = get_post( $this->id );
if ( empty( $attachment ) ) {
wp_die( __( 'Please select a file' ) );
}
$this->filename = $attachment->post_title;
$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'] ) ) {
wp_die( $uploads['error'] );
}
$this->filename = sanitize_file_name( $_GET[ $urlholder ] );
$this->package = $uploads['basedir'] . '/' . $this->filename;
if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) {
wp_die( __( 'Please select a file' ) );
}
}
}
/**
* Delete the attachment/uploaded file.
*
* @since 3.2.2
*
* @return bool Whether the cleanup was successful.
*/
public function cleanup() {
if ( $this->id ) {
wp_delete_attachment( $this->id );
} elseif ( file_exists( $this->package ) ) {
return @unlink( $this->package );
}
return true;
}
}

View File

@ -0,0 +1,186 @@
<?php
/**
* PemFTP - A Ftp implementation in pure PHP
*
* @package PemFTP
* @since 2.5.0
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
* @license LGPL http://www.opensource.org/licenses/lgpl-license.html
*/
/**
* FTP implementation using fsockopen to connect.
*
* @package PemFTP
* @subpackage Pure
* @since 2.5.0
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
* @license LGPL http://www.opensource.org/licenses/lgpl-license.html
*/
class ftp_pure extends ftp_base {
function __construct($verb=FALSE, $le=FALSE) {
parent::__construct(false, $verb, $le);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function _settimeout($sock) {
if(!@stream_set_timeout($sock, $this->_timeout)) {
$this->PushError('_settimeout','socket set send timeout');
$this->_quit();
return FALSE;
}
return TRUE;
}
function _connect($host, $port) {
$this->SendMSG("Creating socket");
$sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
if (!$sock) {
$this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
return FALSE;
}
$this->_connected=true;
return $sock;
}
function _readmsg($fnction="_readmsg"){
if(!$this->_connected) {
$this->PushError($fnction, 'Connect first');
return FALSE;
}
$result=true;
$this->_message="";
$this->_code=0;
$go=true;
do {
$tmp=@fgets($this->_ftp_control_sock, 512);
if($tmp===false) {
$go=$result=false;
$this->PushError($fnction,'Read failed');
} else {
$this->_message.=$tmp;
if(preg_match("/^([0-9]{3})(-(.*[".CRLF."]{1,2})+\\1)? [^".CRLF."]+[".CRLF."]{1,2}$/", $this->_message, $regs)) $go=false;
}
} while($go);
if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
$this->_code=(int)$regs[1];
return $result;
}
function _exec($cmd, $fnction="_exec") {
if(!$this->_ready) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
$status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
if($status===false) {
$this->PushError($fnction,'socket write failed');
return FALSE;
}
$this->_lastaction=time();
if(!$this->_readmsg($fnction)) return FALSE;
return TRUE;
}
function _data_prepare($mode=FTP_ASCII) {
if(!$this->_settype($mode)) return FALSE;
if($this->_passive) {
if(!$this->_exec("PASV", "pasv")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
$this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
$this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
$this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
if(!$this->_ftp_data_sock) {
$this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")");
$this->_data_close();
return FALSE;
}
else $this->_ftp_data_sock;
} else {
$this->SendMSG("Only passive connections available!");
return FALSE;
}
return TRUE;
}
function _data_read($mode=FTP_ASCII, $fp=NULL) {
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Only passive connections available!");
return FALSE;
}
while (!feof($this->_ftp_data_sock)) {
$block=fread($this->_ftp_data_sock, $this->_ftp_buff_size);
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
else $out.=$block;
}
return $out;
}
function _data_write($mode=FTP_ASCII, $fp=NULL) {
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Only passive connections available!");
return FALSE;
}
if(is_resource($fp)) {
while(!feof($fp)) {
$block=fread($fp, $this->_ftp_buff_size);
if(!$this->_data_write_block($mode, $block)) return false;
}
} elseif(!$this->_data_write_block($mode, $fp)) return false;
return TRUE;
}
function _data_write_block($mode, $block) {
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
do {
if(($t=@fwrite($this->_ftp_data_sock, $block))===FALSE) {
$this->PushError("_data_write","Can't write to socket");
return FALSE;
}
$block=substr($block, $t);
} while(!empty($block));
return true;
}
function _data_close() {
@fclose($this->_ftp_data_sock);
$this->SendMSG("Disconnected data from remote host");
return TRUE;
}
function _quit($force=FALSE) {
if($this->_connected or $force) {
@fclose($this->_ftp_control_sock);
$this->_connected=false;
$this->SendMSG("Socket closed");
}
}
}
?>

View File

@ -0,0 +1,246 @@
<?php
/**
* PemFTP - A Ftp implementation in pure PHP
*
* @package PemFTP
* @since 2.5.0
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
* @license LGPL http://www.opensource.org/licenses/lgpl-license.html
*/
/**
* Socket Based FTP implementation
*
* @package PemFTP
* @subpackage Socket
* @since 2.5.0
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
* @license LGPL http://www.opensource.org/licenses/lgpl-license.html
*/
class ftp_sockets extends ftp_base {
function __construct($verb=FALSE, $le=FALSE) {
parent::__construct(true, $verb, $le);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function _settimeout($sock) {
if(!@socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
$this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock)));
@socket_close($sock);
return FALSE;
}
if(!@socket_set_option($sock, SOL_SOCKET , SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
$this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock)));
@socket_close($sock);
return FALSE;
}
return true;
}
function _connect($host, $port) {
$this->SendMSG("Creating socket");
if(!($sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
$this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock)));
return FALSE;
}
if(!$this->_settimeout($sock)) return FALSE;
$this->SendMSG("Connecting to \"".$host.":".$port."\"");
if (!($res = @socket_connect($sock, $host, $port))) {
$this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock)));
@socket_close($sock);
return FALSE;
}
$this->_connected=true;
return $sock;
}
function _readmsg($fnction="_readmsg"){
if(!$this->_connected) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
$result=true;
$this->_message="";
$this->_code=0;
$go=true;
do {
$tmp=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ);
if($tmp===false) {
$go=$result=false;
$this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock)));
} else {
$this->_message.=$tmp;
$go = !preg_match("/^([0-9]{3})(-.+\\1)? [^".CRLF."]+".CRLF."$/Us", $this->_message, $regs);
}
} while($go);
if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
$this->_code=(int)$regs[1];
return $result;
}
function _exec($cmd, $fnction="_exec") {
if(!$this->_ready) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
$status=@socket_write($this->_ftp_control_sock, $cmd.CRLF);
if($status===false) {
$this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream)));
return FALSE;
}
$this->_lastaction=time();
if(!$this->_readmsg($fnction)) return FALSE;
return TRUE;
}
function _data_prepare($mode=FTP_ASCII) {
if(!$this->_settype($mode)) return FALSE;
$this->SendMSG("Creating data socket");
$this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->_ftp_data_sock < 0) {
$this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock)));
return FALSE;
}
if(!$this->_settimeout($this->_ftp_data_sock)) {
$this->_data_close();
return FALSE;
}
if($this->_passive) {
if(!$this->_exec("PASV", "pasv")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
$this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
$this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
$this->PushError("_data_prepare","socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
else $this->_ftp_temp_sock=$this->_ftp_data_sock;
} else {
if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) {
$this->PushError("_data_prepare","can't get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock)));
$this->_data_close();
return FALSE;
}
if(!@socket_bind($this->_ftp_data_sock,$addr)){
$this->PushError("_data_prepare","can't bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
if(!@socket_listen($this->_ftp_data_sock)) {
$this->PushError("_data_prepare","can't listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
$this->PushError("_data_prepare","can't get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock)));
$this->_data_close();
return FALSE;
}
if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
}
return TRUE;
}
function _data_read($mode=FTP_ASCII, $fp=NULL) {
$NewLine=$this->_eol_code[$this->OS_local];
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
if($this->_ftp_temp_sock===FALSE) {
$this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
$this->_data_close();
return FALSE;
}
}
while(($block=@socket_read($this->_ftp_temp_sock, $this->_ftp_buff_size, PHP_BINARY_READ))!==false) {
if($block==="") break;
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
else $out.=$block;
}
return $out;
}
function _data_write($mode=FTP_ASCII, $fp=NULL) {
$NewLine=$this->_eol_code[$this->OS_local];
if(is_resource($fp)) $out=0;
else $out="";
if(!$this->_passive) {
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
if($this->_ftp_temp_sock===FALSE) {
$this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
$this->_data_close();
return false;
}
}
if(is_resource($fp)) {
while(!feof($fp)) {
$block=fread($fp, $this->_ftp_buff_size);
if(!$this->_data_write_block($mode, $block)) return false;
}
} elseif(!$this->_data_write_block($mode, $fp)) return false;
return true;
}
function _data_write_block($mode, $block) {
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
do {
if(($t=@socket_write($this->_ftp_temp_sock, $block))===FALSE) {
$this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
$this->_data_close();
return FALSE;
}
$block=substr($block, $t);
} while(!empty($block));
return true;
}
function _data_close() {
@socket_close($this->_ftp_temp_sock);
@socket_close($this->_ftp_data_sock);
$this->SendMSG("Disconnected data from remote host");
return TRUE;
}
function _quit() {
if($this->_connected) {
@socket_close($this->_ftp_control_sock);
$this->_connected=false;
$this->SendMSG("Socket closed");
}
}
}
?>

View File

@ -0,0 +1,912 @@
<?php
/**
* PemFTP - A Ftp implementation in pure PHP
*
* @package PemFTP
* @since 2.5
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
* @license LGPL http://www.opensource.org/licenses/lgpl-license.html
*/
/**
* Defines the newline characters, if not defined already.
*
* This can be redefined.
*
* @since 2.5
* @var string
*/
if(!defined('CRLF')) define('CRLF',"\r\n");
/**
* Sets whatever to autodetect ASCII mode.
*
* This can be redefined.
*
* @since 2.5
* @var int
*/
if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1);
/**
*
* This can be redefined.
* @since 2.5
* @var int
*/
if(!defined("FTP_BINARY")) define("FTP_BINARY", 1);
/**
*
* This can be redefined.
* @since 2.5
* @var int
*/
if(!defined("FTP_ASCII")) define("FTP_ASCII", 0);
/**
* Whether to force FTP.
*
* This can be redefined.
*
* @since 2.5
* @var bool
*/
if(!defined('FTP_FORCE')) define('FTP_FORCE', true);
/**
* @since 2.5
* @var string
*/
define('FTP_OS_Unix','u');
/**
* @since 2.5
* @var string
*/
define('FTP_OS_Windows','w');
/**
* @since 2.5
* @var string
*/
define('FTP_OS_Mac','m');
/**
* PemFTP base class
*
*/
class ftp_base {
/* Public variables */
var $LocalEcho;
var $Verbose;
var $OS_local;
var $OS_remote;
/* Private variables */
var $_lastaction;
var $_errors;
var $_type;
var $_umask;
var $_timeout;
var $_passive;
var $_host;
var $_fullhost;
var $_port;
var $_datahost;
var $_dataport;
var $_ftp_control_sock;
var $_ftp_data_sock;
var $_ftp_temp_sock;
var $_ftp_buff_size;
var $_login;
var $_password;
var $_connected;
var $_ready;
var $_code;
var $_message;
var $_can_restore;
var $_port_available;
var $_curtype;
var $_features;
var $_error_array;
var $AuthorizedTransferMode;
var $OS_FullName;
var $_eol_code;
var $AutoAsciiExt;
/* Constructor */
function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) {
$this->LocalEcho=$le;
$this->Verbose=$verb;
$this->_lastaction=NULL;
$this->_error_array=array();
$this->_eol_code=array(FTP_OS_Unix=>"\n", FTP_OS_Mac=>"\r", FTP_OS_Windows=>"\r\n");
$this->AuthorizedTransferMode=array(FTP_AUTOASCII, FTP_ASCII, FTP_BINARY);
$this->OS_FullName=array(FTP_OS_Unix => 'UNIX', FTP_OS_Windows => 'WINDOWS', FTP_OS_Mac => 'MACOS');
$this->AutoAsciiExt=array("ASP","BAT","C","CPP","CSS","CSV","JS","H","HTM","HTML","SHTML","INI","LOG","PHP3","PHTML","PL","PERL","SH","SQL","TXT");
$this->_port_available=($port_mode==TRUE);
$this->SendMSG("Staring FTP client class".($this->_port_available?"":" without PORT mode support"));
$this->_connected=FALSE;
$this->_ready=FALSE;
$this->_can_restore=FALSE;
$this->_code=0;
$this->_message="";
$this->_ftp_buff_size=4096;
$this->_curtype=NULL;
$this->SetUmask(0022);
$this->SetType(FTP_AUTOASCII);
$this->SetTimeout(30);
$this->Passive(!$this->_port_available);
$this->_login="anonymous";
$this->_password="anon@ftp.com";
$this->_features=array();
$this->OS_local=FTP_OS_Unix;
$this->OS_remote=FTP_OS_Unix;
$this->features=array();
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
}
function ftp_base($port_mode=FALSE) {
$this->__construct($port_mode);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Public functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function parselisting($line) {
$is_windows = ($this->OS_remote == FTP_OS_Windows);
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 { $lucifer[3]+=1900; } // 4digit year fix
$b['isdir'] = ($lucifer[7]=="<DIR>");
if ( $b['isdir'] )
$b['type'] = 'd';
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['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];
} else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
//echo $line."\n";
$lcount=count($lucifer);
if ($lcount<8) return '';
$b = array();
$b['isdir'] = $lucifer[0]{0} === "d";
$b['islink'] = $lucifer[0]{0} === "l";
if ( $b['isdir'] )
$b['type'] = 'd';
elseif ( $b['islink'] )
$b['type'] = 'l';
else
$b['type'] = 'f';
$b['perms'] = $lucifer[0];
$b['number'] = $lucifer[1];
$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']);
$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['minute'] = $l2[2];
} else {
$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['name'] = $lucifer[8];
}
}
return $b;
}
function SendMSG($message = "", $crlf=true) {
if ($this->Verbose) {
echo $message.($crlf?CRLF:"");
flush();
}
return TRUE;
}
function SetType($mode=FTP_AUTOASCII) {
if(!in_array($mode, $this->AuthorizedTransferMode)) {
$this->SendMSG("Wrong type");
return FALSE;
}
$this->_type=$mode;
$this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
return TRUE;
}
function _settype($mode=FTP_ASCII) {
if($this->_ready) {
if($mode==FTP_BINARY) {
if($this->_curtype!=FTP_BINARY) {
if(!$this->_exec("TYPE I", "SetType")) return FALSE;
$this->_curtype=FTP_BINARY;
}
} elseif($this->_curtype!=FTP_ASCII) {
if(!$this->_exec("TYPE A", "SetType")) return FALSE;
$this->_curtype=FTP_ASCII;
}
} else return FALSE;
return TRUE;
}
function Passive($pasv=NULL) {
if(is_null($pasv)) $this->_passive=!$this->_passive;
else $this->_passive=$pasv;
if(!$this->_port_available and !$this->_passive) {
$this->SendMSG("Only passive connections available!");
$this->_passive=TRUE;
return FALSE;
}
$this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
return TRUE;
}
function SetServer($host, $port=21, $reconnect=true) {
if(!is_long($port)) {
$this->verbose=true;
$this->SendMSG("Incorrect port syntax");
return FALSE;
} else {
$ip=@gethostbyname($host);
$dns=@gethostbyaddr($host);
if(!$ip) $ip=$host;
if(!$dns) $dns=$host;
// Validate the IPAddress PHP4 returns -1 for invalid, PHP5 false
// -1 === "255.255.255.255" which is the broadcast address which is also going to be invalid
$ipaslong = ip2long($ip);
if ( ($ipaslong == false) || ($ipaslong === -1) ) {
$this->SendMSG("Wrong host name/address \"".$host."\"");
return FALSE;
}
$this->_host=$ip;
$this->_fullhost=$dns;
$this->_port=$port;
$this->_dataport=$port-1;
}
$this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
if($reconnect){
if($this->_connected) {
$this->SendMSG("Reconnecting");
if(!$this->quit(FTP_FORCE)) return FALSE;
if(!$this->connect()) return FALSE;
}
}
return TRUE;
}
function SetUmask($umask=0022) {
$this->_umask=$umask;
umask($this->_umask);
$this->SendMSG("UMASK 0".decoct($this->_umask));
return TRUE;
}
function SetTimeout($timeout=30) {
$this->_timeout=$timeout;
$this->SendMSG("Timeout ".$this->_timeout);
if($this->_connected)
if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
return TRUE;
}
function connect($server=NULL) {
if(!empty($server)) {
if(!$this->SetServer($server)) return false;
}
if($this->_ready) return true;
$this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
$this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\"");
return FALSE;
}
$this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
do {
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
$this->_lastaction=time();
} while($this->_code<200);
$this->_ready=true;
$syst=$this->systype();
if(!$syst) $this->SendMSG("Can't detect remote OS");
else {
if(preg_match("/win|dos|novell/i", $syst[0])) $this->OS_remote=FTP_OS_Windows;
elseif(preg_match("/os/i", $syst[0])) $this->OS_remote=FTP_OS_Mac;
elseif(preg_match("/(li|u)nix/i", $syst[0])) $this->OS_remote=FTP_OS_Unix;
else $this->OS_remote=FTP_OS_Mac;
$this->SendMSG("Remote OS: ".$this->OS_FullName[$this->OS_remote]);
}
if(!$this->features()) $this->SendMSG("Can't get features list. All supported - disabled");
else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
return TRUE;
}
function quit($force=false) {
if($this->_ready) {
if(!$this->_exec("QUIT") and !$force) return FALSE;
if(!$this->_checkCode() and !$force) return FALSE;
$this->_ready=false;
$this->SendMSG("Session finished");
}
$this->_quit();
return TRUE;
}
function login($user=NULL, $pass=NULL) {
if(!is_null($user)) $this->_login=$user;
else $this->_login="anonymous";
if(!is_null($pass)) $this->_password=$pass;
else $this->_password="anon@anon.com";
if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
if(!$this->_checkCode()) return FALSE;
if($this->_code!=230) {
if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
if(!$this->_checkCode()) return FALSE;
}
$this->SendMSG("Authentication succeeded");
if(empty($this->_features)) {
if(!$this->features()) $this->SendMSG("Can't get features list. All supported - disabled");
else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
}
return TRUE;
}
function pwd() {
if(!$this->_exec("PWD", "pwd")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return preg_replace("/^[0-9]{3} \"(.+)\".*$/s", "\\1", $this->_message);
}
function cdup() {
if(!$this->_exec("CDUP", "cdup")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return true;
}
function chdir($pathname) {
if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function rmdir($pathname) {
if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function mkdir($pathname) {
if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function rename($from, $to) {
if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
if(!$this->_checkCode()) return FALSE;
if($this->_code==350) {
if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
if(!$this->_checkCode()) return FALSE;
} else return FALSE;
return TRUE;
}
function filesize($pathname) {
if(!isset($this->_features["SIZE"])) {
$this->PushError("filesize", "not supported by server");
return FALSE;
}
if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
}
function abort() {
if(!$this->_exec("ABOR", "abort")) return FALSE;
if(!$this->_checkCode()) {
if($this->_code!=426) return FALSE;
if(!$this->_readmsg("abort")) return FALSE;
if(!$this->_checkCode()) return FALSE;
}
return true;
}
function mdtm($pathname) {
if(!isset($this->_features["MDTM"])) {
$this->PushError("mdtm", "not supported by server");
return FALSE;
}
if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
if(!$this->_checkCode()) return FALSE;
$mdtm = preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
$date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
$timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
return $timestamp;
}
function systype() {
if(!$this->_exec("SYST", "systype")) return FALSE;
if(!$this->_checkCode()) return FALSE;
$DATA = explode(" ", $this->_message);
return array($DATA[1], $DATA[3]);
}
function delete($pathname) {
if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function site($command, $fnction="site") {
if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function chmod($pathname, $mode) {
if(!$this->site( sprintf('CHMOD %o %s', $mode, $pathname), "chmod")) return FALSE;
return TRUE;
}
function restore($from) {
if(!isset($this->_features["REST"])) {
$this->PushError("restore", "not supported by server");
return FALSE;
}
if($this->_curtype!=FTP_BINARY) {
$this->PushError("restore", "can't restore in ASCII mode");
return FALSE;
}
if(!$this->_exec("REST ".$from, "resore")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function features() {
if(!$this->_exec("FEAT", "features")) return FALSE;
if(!$this->_checkCode()) return FALSE;
$f=preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
$this->_features=array();
foreach($f as $k=>$v) {
$v=explode(" ", trim($v));
$this->_features[array_shift($v)]=$v;
}
return true;
}
function rawlist($pathname="", $arg="") {
return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
}
function nlist($pathname="", $arg="") {
return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
}
function is_exists($pathname) {
return $this->file_exists($pathname);
}
function file_exists($pathname) {
$exists=true;
if(!$this->_exec("RNFR ".$pathname, "rename")) $exists=FALSE;
else {
if(!$this->_checkCode()) $exists=FALSE;
$this->abort();
}
if($exists) $this->SendMSG("Remote file ".$pathname." exists");
else $this->SendMSG("Remote file ".$pathname." does not exist");
return $exists;
}
function fget($fp, $remotefile, $rest=0) {
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($remotefile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("RETR ".$remotefile, "get")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$out=$this->_data_read($mode, $fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $out;
}
function get($remotefile, $localfile=NULL, $rest=0) {
if(is_null($localfile)) $localfile=$remotefile;
if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
$fp = @fopen($localfile, "w");
if (!$fp) {
$this->PushError("get","can't open local file", "Cannot create \"".$localfile."\"");
return FALSE;
}
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($remotefile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
fclose($fp);
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("RETR ".$remotefile, "get")) {
$this->_data_close();
fclose($fp);
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
fclose($fp);
return FALSE;
}
$out=$this->_data_read($mode, $fp);
fclose($fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $out;
}
function fput($remotefile, $fp, $rest=0) {
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($remotefile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("STOR ".$remotefile, "put")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$ret=$this->_data_write($mode, $fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $ret;
}
function put($localfile, $remotefile=NULL, $rest=0) {
if(is_null($remotefile)) $remotefile=$localfile;
if (!file_exists($localfile)) {
$this->PushError("put","can't open local file", "No such file or directory \"".$localfile."\"");
return FALSE;
}
$fp = @fopen($localfile, "r");
if (!$fp) {
$this->PushError("put","can't open local file", "Cannot read file \"".$localfile."\"");
return FALSE;
}
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($localfile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
fclose($fp);
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("STOR ".$remotefile, "put")) {
$this->_data_close();
fclose($fp);
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
fclose($fp);
return FALSE;
}
$ret=$this->_data_write($mode, $fp);
fclose($fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $ret;
}
function mput($local=".", $remote=NULL, $continious=false) {
$local=realpath($local);
if(!@file_exists($local)) {
$this->PushError("mput","can't open local folder", "Cannot stat folder \"".$local."\"");
return FALSE;
}
if(!is_dir($local)) return $this->put($local, $remote);
if(empty($remote)) $remote=".";
elseif(!$this->file_exists($remote) and !$this->mkdir($remote)) return FALSE;
if($handle = opendir($local)) {
$list=array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") $list[]=$file;
}
closedir($handle);
} else {
$this->PushError("mput","can't open local folder", "Cannot read folder \"".$local."\"");
return FALSE;
}
if(empty($list)) return TRUE;
$ret=true;
foreach($list as $el) {
if(is_dir($local."/".$el)) $t=$this->mput($local."/".$el, $remote."/".$el);
else $t=$this->put($local."/".$el, $remote."/".$el);
if(!$t) {
$ret=FALSE;
if(!$continious) break;
}
}
return $ret;
}
function mget($remote, $local=".", $continious=false) {
$list=$this->rawlist($remote, "-lA");
if($list===false) {
$this->PushError("mget","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
return FALSE;
}
if(empty($list)) return true;
if(!@file_exists($local)) {
if(!@mkdir($local)) {
$this->PushError("mget","can't create local folder", "Cannot create folder \"".$local."\"");
return FALSE;
}
}
foreach($list as $k=>$v) {
$list[$k]=$this->parselisting($v);
if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
}
$ret=true;
foreach($list as $el) {
if($el["type"]=="d") {
if(!$this->mget($remote."/".$el["name"], $local."/".$el["name"], $continious)) {
$this->PushError("mget", "can't copy folder", "Can't copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
$ret=false;
if(!$continious) break;
}
} else {
if(!$this->get($remote."/".$el["name"], $local."/".$el["name"])) {
$this->PushError("mget", "can't copy file", "Can't copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
$ret=false;
if(!$continious) break;
}
}
@chmod($local."/".$el["name"], $el["perms"]);
$t=strtotime($el["date"]);
if($t!==-1 and $t!==false) @touch($local."/".$el["name"], $t);
}
return $ret;
}
function mdel($remote, $continious=false) {
$list=$this->rawlist($remote, "-la");
if($list===false) {
$this->PushError("mdel","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
return false;
}
foreach($list as $k=>$v) {
$list[$k]=$this->parselisting($v);
if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
}
$ret=true;
foreach($list as $el) {
if ( empty($el) )
continue;
if($el["type"]=="d") {
if(!$this->mdel($remote."/".$el["name"], $continious)) {
$ret=false;
if(!$continious) break;
}
} else {
if (!$this->delete($remote."/".$el["name"])) {
$this->PushError("mdel", "can't delete file", "Can't delete remote file \"".$remote."/".$el["name"]."\"");
$ret=false;
if(!$continious) break;
}
}
}
if(!$this->rmdir($remote)) {
$this->PushError("mdel", "can't delete folder", "Can't delete remote folder \"".$remote."/".$el["name"]."\"");
$ret=false;
}
return $ret;
}
function mmkdir($dir, $mode = 0777) {
if(empty($dir)) return FALSE;
if($this->is_exists($dir) or $dir == "/" ) return TRUE;
if(!$this->mmkdir(dirname($dir), $mode)) return false;
$r=$this->mkdir($dir, $mode);
$this->chmod($dir,$mode);
return $r;
}
function glob($pattern, $handle=NULL) {
$path=$output=null;
if(PHP_OS=='WIN32') $slash='\\';
else $slash='/';
$lastpos=strrpos($pattern,$slash);
if(!($lastpos===false)) {
$path=substr($pattern,0,-$lastpos-1);
$pattern=substr($pattern,$lastpos);
} else $path=getcwd();
if(is_array($handle) and !empty($handle)) {
foreach($handle as $dir) {
if($this->glob_pattern_match($pattern,$dir))
$output[]=$dir;
}
} else {
$handle=@opendir($path);
if($handle===false) return false;
while($dir=readdir($handle)) {
if($this->glob_pattern_match($pattern,$dir))
$output[]=$dir;
}
closedir($handle);
}
if(is_array($output)) return $output;
return false;
}
function glob_pattern_match($pattern,$string) {
$out=null;
$chunks=explode(';',$pattern);
foreach($chunks as $pattern) {
$escape=array('$','^','.','{','}','(',')','[',']','|');
while(strpos($pattern,'**')!==false)
$pattern=str_replace('**','*',$pattern);
foreach($escape as $probe)
$pattern=str_replace($probe,"\\$probe",$pattern);
$pattern=str_replace('?*','*',
str_replace('*?','*',
str_replace('*',".*",
str_replace('?','.{1,1}',$pattern))));
$out[]=$pattern;
}
if(count($out)==1) return($this->glob_regexp("^$out[0]$",$string));
else {
foreach($out as $tester)
if($this->my_regexp("^$tester$",$string)) return true;
}
return false;
}
function glob_regexp($pattern,$probe) {
$sensitive=(PHP_OS!='WIN32');
return ($sensitive?
preg_match( '/' . preg_quote( $pattern, '/' ) . '/', $probe ) :
preg_match( '/' . preg_quote( $pattern, '/' ) . '/i', $probe )
);
}
function dirlist($remote) {
$list=$this->rawlist($remote, "-la");
if($list===false) {
$this->PushError("dirlist","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
return false;
}
$dirlist = array();
foreach($list as $k=>$v) {
$entry=$this->parselisting($v);
if ( empty($entry) )
continue;
if($entry["name"]=="." or $entry["name"]=="..")
continue;
$dirlist[$entry['name']] = $entry;
}
return $dirlist;
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function _checkCode() {
return ($this->_code<400 and $this->_code>0);
}
function _list($arg="", $cmd="LIST", $fnction="_list") {
if(!$this->_data_prepare()) return false;
if(!$this->_exec($cmd.$arg, $fnction)) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$out="";
if($this->_code<200) {
$out=$this->_data_read();
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
if($out === FALSE ) return FALSE;
$out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
// $this->SendMSG(implode($this->_eol_code[$this->OS_local], $out));
}
return $out;
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Partie : gestion des erreurs -->
// <!-- --------------------------------------------------------------------------------------- -->
// Gnre une erreur pour traitement externe la classe
function PushError($fctname,$msg,$desc=false){
$error=array();
$error['time']=time();
$error['fctname']=$fctname;
$error['msg']=$msg;
$error['desc']=$desc;
if($desc) $tmp=' ('.$desc.')'; else $tmp='';
$this->SendMSG($fctname.': '.$msg.$tmp);
return(array_push($this->_error_array,$error));
}
// Rcupre une erreur externe
function PopError(){
if(count($this->_error_array)) return(array_pop($this->_error_array));
else return(false);
}
}
$mod_sockets = extension_loaded( 'sockets' );
if ( ! $mod_sockets && function_exists( 'dl' ) && is_callable( 'dl' ) ) {
$prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : '';
@dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX );
$mod_sockets = extension_loaded( 'sockets' );
}
require_once dirname( __FILE__ ) . "/class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php";
if ( $mod_sockets ) {
class ftp extends ftp_sockets {}
} else {
class ftp extends ftp_pure {}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Upgrader API: Language_Pack_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Translation Upgrader Skin for WordPress Translation Upgrades.
*
* @since 3.7.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @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 $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 );
if ( $args['skip_header_footer'] ) {
$this->done_header = true;
$this->done_footer = true;
$this->display_footer_actions = false;
}
parent::__construct( $args );
}
/**
*/
public function before() {
$name = $this->upgrader->get_name_for_update( $this->language_update );
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 ) {
echo '<div class="lp-error">';
parent::error( $error );
echo '</div>';
}
/**
*/
public function after() {
echo '</div>';
}
/**
*/
public function bulk_footer() {
$this->decrement_update_count( 'translation' );
$update_actions = array();
$update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>';
/**
* Filters the list of action links available following a translations update.
*
* @since 3.7.0
*
* @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 ) {
$this->feedback( implode( ' | ', $update_actions ) );
}
}
}

View File

@ -0,0 +1,472 @@
<?php
/**
* Upgrade API: Language_Pack_Upgrader class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Core class used for updating/installing language packs (translations)
* for plugins, themes, and core.
*
* @since 3.7.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
*
* @see WP_Upgrader
*/
class Language_Pack_Upgrader extends WP_Upgrader {
/**
* Result of the language pack upgrade.
*
* @since 3.7.0
* @var array|WP_Error $result
* @see WP_Upgrader::$result
*/
public $result;
/**
* Whether a bulk upgrade/installation is being performed.
*
* @since 3.7.0
* @var bool $bulk
*/
public $bulk = true;
/**
* Asynchronously upgrades language packs after other upgrades have been made.
*
* Hooked to the {@see 'upgrader_process_complete'} action by default.
*
* @since 3.7.0
*
* @param false|WP_Upgrader $upgrader Optional. WP_Upgrader instance or false. If `$upgrader` is
* a Language_Pack_Upgrader instance, the method will bail to
* avoid recursion. Otherwise unused. Default false.
*/
public static function async_upgrade( $upgrader = false ) {
// Avoid recursion.
if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader ) {
return;
}
// Nothing to do?
$language_updates = wp_get_translation_updates();
if ( ! $language_updates ) {
return;
}
/*
* Avoid messing with VCS installations, at least for now.
* Noted: this is not the ideal way to accomplish this.
*/
$check_vcs = new WP_Automatic_Updater;
if ( $check_vcs->is_vcs_checkout( WP_CONTENT_DIR ) ) {
return;
}
foreach ( $language_updates as $key => $language_update ) {
$update = ! empty( $language_update->autoupdate );
/**
* Filters whether to asynchronously update translation for core, a plugin, or a theme.
*
* @since 4.0.0
*
* @param bool $update Whether to update.
* @param object $language_update The update offer.
*/
$update = apply_filters( 'async_update_translation', $update, $language_update );
if ( ! $update ) {
unset( $language_updates[ $key ] );
}
}
if ( empty( $language_updates ) ) {
return;
}
// Re-use the automatic upgrader skin if the parent upgrader is using it.
if ( $upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin ) {
$skin = $upgrader->skin;
} else {
$skin = new Language_Pack_Upgrader_Skin(
array(
'skip_header_footer' => true,
)
);
}
$lp_upgrader = new Language_Pack_Upgrader( $skin );
$lp_upgrader->bulk_upgrade( $language_updates );
}
/**
* Initialize the upgrade strings.
*
* @since 3.7.0
*/
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.' );
/* 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['remove_old'] = __( 'Removing the old version of the translation&#8230;' );
$this->strings['remove_old_failed'] = __( 'Could not remove the old translation.' );
}
/**
* Upgrade a language pack.
*
* @since 3.7.0
*
* @param string|false $update Optional. Whether an update offer is available. Default false.
* @param array $args Optional. Other optional arguments, see
* Language_Pack_Upgrader::bulk_upgrade(). Default empty array.
* @return array|bool|WP_Error The result of the upgrade, or a WP_Error object instead.
*/
public function upgrade( $update = false, $args = array() ) {
if ( $update ) {
$update = array( $update );
}
$results = $this->bulk_upgrade( $update, $args );
if ( ! is_array( $results ) ) {
return $results;
}
return $results[0];
}
/**
* Bulk upgrade language packs.
*
* @since 3.7.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @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.
*/
public function bulk_upgrade( $language_updates = array(), $args = array() ) {
global $wp_filesystem;
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->upgrade_strings();
if ( ! $language_updates ) {
$language_updates = wp_get_translation_updates();
}
if ( empty( $language_updates ) ) {
$this->skin->header();
$this->skin->set_result( true );
$this->skin->feedback( 'up_to_date' );
$this->skin->bulk_footer();
$this->skin->footer();
return true;
}
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' );
remove_all_filters( 'upgrader_clear_destination' );
remove_all_filters( 'upgrader_post_install' );
remove_all_filters( 'upgrader_source_selection' );
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ), 10, 2 );
$this->skin->header();
// Connect to the Filesystem first.
$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
if ( ! $res ) {
$this->skin->footer();
return false;
}
$results = array();
$this->update_count = count( $language_updates );
$this->update_current = 0;
/*
* The filesystem's mkdir() is not recursive. Make sure WP_LANG_DIR exists,
* 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 ) ) {
return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination );
}
}
$language_updates_results = array();
foreach ( $language_updates as $language_update ) {
$this->skin->language_update = $language_update;
$destination = WP_LANG_DIR;
if ( 'plugin' == $language_update->type ) {
$destination .= '/plugins';
} elseif ( 'theme' == $language_update->type ) {
$destination .= '/themes';
}
$this->update_current++;
$options = array(
'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(
'language_update_type' => $language_update->type,
'language_update' => $language_update,
),
);
$result = $this->run( $options );
$results[] = $this->result;
// Prevent credentials auth screen from displaying multiple times.
if ( false === $result ) {
break;
}
$language_updates_results[] = array(
'language' => $language_update->language,
'type' => $language_update->type,
'slug' => isset( $language_update->slug ) ? $language_update->slug : 'default',
'version' => $language_update->version,
);
}
// Remove upgrade hooks which are not required for translation updates.
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
remove_action( 'upgrader_process_complete', 'wp_version_check' );
remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
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,
)
);
// Re-add upgrade hooks.
add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
add_action( 'upgrader_process_complete', 'wp_version_check', 10, 0 );
add_action( 'upgrader_process_complete', 'wp_update_plugins', 10, 0 );
add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
$this->skin->bulk_footer();
$this->skin->footer();
// Clean up our hooks, in case something else does an upgrade on this connection.
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
if ( $parsed_args['clear_update_cache'] ) {
wp_clean_update_cache();
}
return $results;
}
/**
* Check the package source to make sure there are .mo and .po files.
*
* Hooked to the {@see 'upgrader_source_selection'} filter by
* Language_Pack_Upgrader::bulk_upgrade().
*
* @since 3.7.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
*
* @param string|WP_Error $source
* @param string $remote_source
*/
public function check_package( $source, $remote_source ) {
global $wp_filesystem;
if ( is_wp_error( $source ) ) {
return $source;
}
// Check that the folder contains a valid language.
$files = $wp_filesystem->dirlist( $remote_source );
// 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 ) ) {
$po = true;
} elseif ( '.mo' == substr( $file, -3 ) ) {
$mo = true;
}
}
if ( ! $mo || ! $po ) {
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>'
)
);
}
return $source;
}
/**
* Get the name of an item being updated.
*
* @since 3.7.0
*
* @param object $update The data for an update.
* @return string The name of the item being updated.
*/
public function get_name_for_update( $update ) {
switch ( $update->type ) {
case 'core':
return 'WordPress'; // Not translated
case 'theme':
$theme = wp_get_theme( $update->slug );
if ( $theme->exists() ) {
return $theme->Get( 'Name' );
}
break;
case 'plugin':
$plugin_data = get_plugins( '/' . $update->slug );
$plugin_data = reset( $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;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,105 @@
<?php
/**
* Upgrader API: Plugin_Installer_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Plugin Installer Skin for WordPress Plugin Installer.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see WP_Upgrader_Skin
*/
class Plugin_Installer_Skin extends WP_Upgrader_Skin {
public $api;
public $type;
/**
* @param array $args
*/
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();
parent::__construct( $args );
}
/**
*/
public function before() {
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 );
}
}
/**
*/
public function after() {
$plugin_file = $this->upgrader->plugin_info();
$install_actions = array();
$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>';
} 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>';
}
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
$install_actions['network_activate'] = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Network Activate' ) . '</a>';
unset( $install_actions['activate_plugin'] );
}
if ( 'import' == $from ) {
$install_actions['importers_page'] = '<a href="' . admin_url( 'import.php' ) . '" target="_parent">' . __( 'Return to Importers' ) . '</a>';
} elseif ( $this->type == 'web' ) {
$install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '" target="_parent">' . __( 'Return to Plugin Installer' ) . '</a>';
} elseif ( 'upload' == $this->type && 'plugins' == $from ) {
$install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '">' . __( 'Return to Plugin Installer' ) . '</a>';
} else {
$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 ) ) {
unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
} elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) ) {
unset( $install_actions['activate_plugin'] );
}
/**
* Filters the list of action links available following a single plugin installation.
*
* @since 2.7.0
*
* @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 );
if ( ! empty( $install_actions ) ) {
$this->feedback( implode( ' ', (array) $install_actions ) );
}
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* Upgrader API: Plugin_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Plugin Upgrader Skin for WordPress Plugin Upgrades.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see WP_Upgrader_Skin
*/
class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
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 );
$this->plugin = $args['plugin'];
$this->plugin_active = is_plugin_active( $this->plugin );
$this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
parent::__construct( $args );
}
/**
*/
public function after() {
$this->plugin = $this->upgrader->plugin_info();
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>',
);
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 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 ) );
}
}
}

View File

@ -0,0 +1,487 @@
<?php
/**
* Upgrade API: Plugin_Upgrader class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Core class used for upgrading/installing plugins.
*
* It is designed to upgrade/install plugins from a local zip, remote zip URL,
* or uploaded zip file.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
*
* @see WP_Upgrader
*/
class Plugin_Upgrader extends WP_Upgrader {
/**
* Plugin upgrade result.
*
* @since 2.8.0
* @var array|WP_Error $result
*
* @see WP_Upgrader::$result
*/
public $result;
/**
* Whether a bulk upgrade/installation is being performed.
*
* @since 2.9.0
* @var bool $bulk
*/
public $bulk = false;
/**
* Initialize the upgrade strings.
*
* @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.' );
/* 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.' );
}
/**
* Initialize the installation strings.
*
* @since 2.8.0
*/
public function install_strings() {
$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.' );
}
/**
* Install a plugin package.
*
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
*
* @param string $package The full local path or URI of the package.
* @param array $args {
* Optional. Other arguments for installing a plugin package. Default empty array.
*
* @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
* Default true.
* }
* @return bool|WP_Error True if the installation was successful, false or a WP_Error otherwise.
*/
public function install( $package, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->install_strings();
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',
),
)
);
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
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'] );
return true;
}
/**
* Upgrade a plugin.
*
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
*
* @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.
*
* @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
* Default true.
* }
* @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
*/
public function upgrade( $plugin, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->upgrade_strings();
$current = get_site_transient( 'update_plugins' );
if ( ! isset( $current->response[ $plugin ] ) ) {
$this->skin->before();
$this->skin->set_result( false );
$this->skin->error( 'up_to_date' );
$this->skin->after();
return false;
}
// 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 );
//'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',
),
)
);
// 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' ) );
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'] );
return true;
}
/**
* Bulk upgrade several plugins at once.
*
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
*
* @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.
* }
* @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(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->bulk = true;
$this->upgrade_strings();
$current = get_site_transient( 'update_plugins' );
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 ) );
if ( ! $res ) {
$this->skin->footer();
return false;
}
$this->skin->bulk_header();
/*
* Only start maintenance mode if:
* - running Multisite and there are one or more plugins specified, OR
* - a plugin with an update available is currently active.
* @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 );
}
$results = array();
$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 );
if ( ! isset( $current->response[ $plugin ] ) ) {
$this->skin->set_result( 'up_to_date' );
$this->skin->before();
$this->skin->feedback( 'up_to_date' );
$this->skin->after();
$results[ $plugin ] = true;
continue;
}
// Get the URL to the zip file.
$r = $current->response[ $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,
),
)
);
$results[ $plugin ] = $this->result;
// Prevent credentials auth screen from displaying multiple times
if ( false === $result ) {
break;
}
} //end foreach $plugins
$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,
)
);
$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' ) );
return $results;
}
/**
* Check a source package to be sure it contains a plugin.
*
* This function is added to the {@see 'upgrader_source_selection'} filter by
* Plugin_Upgrader::install().
*
* @since 3.3.0
*
* @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 ) {
global $wp_filesystem;
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.
return $source;
}
// Check the folder contains at least 1 valid plugin.
$plugins_found = false;
$files = glob( $working_directory . '*.php' );
if ( $files ) {
foreach ( $files as $file ) {
$info = get_plugin_data( $file, false, false );
if ( ! empty( $info['Name'] ) ) {
$plugins_found = true;
break;
}
}
}
if ( ! $plugins_found ) {
return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
}
return $source;
}
/**
* Retrieve the path to the file that contains the plugin info.
*
* This isn't used internally in the class, but is called by the skins.
*
* @since 2.8.0
*
* @return string|false The full path to the main plugin file, or false.
*/
public function plugin_info() {
if ( ! is_array( $this->result ) ) {
return false;
}
if ( empty( $this->result['destination_name'] ) ) {
return false;
}
$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
return $this->result['destination_name'] . '/' . $pluginfiles[0];
}
/**
* Deactivates a plugin before it is upgraded.
*
* Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
*
* @since 2.8.0
* @since 4.1.0 Added a return value.
*
* @param bool|WP_Error $return Upgrade offer return.
* @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 ) {
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() ) {
return $return;
}
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
if ( empty( $plugin ) ) {
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
}
if ( is_plugin_active( $plugin ) ) {
//Deactivate the plugin silently, Prevent deactivation hooks from running.
deactivate_plugins( $plugin, true );
}
return $return;
}
/**
* Delete the old plugin during an upgrade.
*
* Hooked to the {@see 'upgrader_clear_destination'} filter by
* Plugin_Upgrader::upgrade() and Plugin_Upgrader::bulk_upgrade().
*
* @since 2.8.0
*
* @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 ) {
global $wp_filesystem;
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'] );
}
$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.
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 ( ! $deleted ) {
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
}
return true;
}
}

View File

@ -0,0 +1,124 @@
<?php
/**
* Upgrader API: Theme_Installer_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Theme Installer Skin for the WordPress Theme Installer.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see WP_Upgrader_Skin
*/
class Theme_Installer_Skin extends WP_Upgrader_Skin {
public $api;
public $type;
/**
* @param array $args
*/
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();
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 );
}
}
/**
*/
public function after() {
if ( empty( $this->upgrader->result['destination_name'] ) ) {
return;
}
$theme_info = $this->upgrader->theme_info();
if ( empty( $theme_info ) ) {
return;
}
$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 = 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(
array(
'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">';
$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">';
$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' ) ) {
$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' ) {
$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' ) ) {
$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' ) ) {
unset( $install_actions['activate'], $install_actions['preview'] );
}
/**
* Filters the list of action links available following a single theme installation.
*
* @since 2.8.0
*
* @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 ) );
}
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* Upgrader API: Theme_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Theme Upgrader Skin for WordPress Theme Upgrades.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see WP_Upgrader_Skin
*/
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 );
$this->theme = $args['theme'];
parent::__construct( $args );
}
/**
*/
public function after() {
$this->decrement_update_count( 'theme' );
$update_actions = array();
if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
$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 = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
$customize_url = add_query_arg(
array(
'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">';
$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">';
$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">';
$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() ) {
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>';
/**
* Filters the list of action links available following a single theme update.
*
* @since 2.8.0
*
* @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 ) );
}
}
}

View File

@ -0,0 +1,648 @@
<?php
/**
* Upgrade API: Theme_Upgrader class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Core class used for upgrading/installing themes.
*
* It is designed to upgrade/install themes from a local zip, remote zip URL,
* or uploaded zip file.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
*
* @see WP_Upgrader
*/
class Theme_Upgrader extends WP_Upgrader {
/**
* Result of the theme upgrade offer.
*
* @since 2.8.0
* @var array|WP_Error $result
* @see WP_Upgrader::$result
*/
public $result;
/**
* Whether multiple themes are being upgraded/installed in bulk.
*
* @since 2.9.0
* @var bool $bulk
*/
public $bulk = false;
/**
* Initialize the upgrade strings.
*
* @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.' );
/* 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.' );
}
/**
* Initialize the installation strings.
*
* @since 2.8.0
*/
public function install_strings() {
$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.' );
/* 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;' );
/* translators: 1: theme name, 2: version */
$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.' );
/* translators: 1: theme name, 2: version */
$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>' );
}
/**
* Check if a child theme is being installed and we need to install its parent.
*
* Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::install().
*
* @since 3.4.0
*
* @param bool $install_result
* @param array $hook_extra
* @param array $child_result
* @return type
*/
public function check_parent_theme_filter( $install_result, $hook_extra, $child_result ) {
// Check to see if we need to install a parent theme
$theme_info = $this->theme_info();
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' ) );
// 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.
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' ) );
return $install_result;
}
// Backup required data we're going to override:
$child_api = $this->skin->api;
$child_success_message = $this->strings['process_success'];
// Override them
$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 );
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,
)
);
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 );
// Reset child's result and data
$this->result = $child_result;
$this->skin->api = $child_api;
$this->strings['process_success'] = $child_success_message;
return $install_result;
}
/**
* Don't display the activate and preview actions to the user.
*
* Hooked to the {@see 'install_theme_complete_actions'} filter by
* Theme_Upgrader::check_parent_theme_filter() when installing
* a child theme and installing the parent theme fails.
*
* @since 3.4.0
*
* @param array $actions Preview actions.
* @return array
*/
public function hide_activate_preview_actions( $actions ) {
unset( $actions['activate'], $actions['preview'] );
return $actions;
}
/**
* Install a theme package.
*
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
*
* @param string $package The full local path or URI of the package.
* @param array $args {
* Optional. Other arguments for installing a theme package. Default empty array.
*
* @type bool $clear_update_cache Whether to clear the updates cache if successful.
* Default true.
* }
*
* @return bool|WP_Error True if the installation was successful, false or a WP_Error object otherwise.
*/
public function install( $package, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$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 );
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',
),
)
);
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' ) );
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'] );
return true;
}
/**
* Upgrade a theme.
*
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
*
* @param string $theme The theme slug.
* @param array $args {
* Optional. Other arguments for upgrading a theme. Default empty array.
*
* @type bool $clear_update_cache Whether to clear the update cache if successful.
* Default true.
* }
* @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
*/
public function upgrade( $theme, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->upgrade_strings();
// Is an update available?
$current = get_site_transient( 'update_themes' );
if ( ! isset( $current->response[ $theme ] ) ) {
$this->skin->before();
$this->skin->set_result( false );
$this->skin->error( 'up_to_date' );
$this->skin->after();
return false;
}
$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 );
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',
),
)
);
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' ) );
if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
return true;
}
/**
* Upgrade several themes at once.
*
* @since 3.0.0
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
*
* @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.
* Default true.
* }
* @return array[]|false An array of results, or false if unable to connect to the filesystem.
*/
public function bulk_upgrade( $themes, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->bulk = true;
$this->upgrade_strings();
$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 );
$this->skin->header();
// Connect to the Filesystem first.
$res = $this->fs_connect( array( WP_CONTENT_DIR ) );
if ( ! $res ) {
$this->skin->footer();
return false;
}
$this->skin->bulk_header();
// Only start maintenance mode if:
// - running Multisite and there are one or more themes specified, OR
// - 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 ) {
$maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
}
if ( $maintenance ) {
$this->maintenance_mode( true );
}
$results = array();
$this->update_count = count( $themes );
$this->update_current = 0;
foreach ( $themes as $theme ) {
$this->update_current++;
$this->skin->theme_info = $this->theme_info( $theme );
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;
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,
),
)
);
$results[ $theme ] = $this->result;
// Prevent credentials auth screen from displaying multiple times
if ( false === $result ) {
break;
}
} //end foreach $plugins
$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,
)
);
$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' ) );
return $results;
}
/**
* Check that the package source contains a valid theme.
*
* Hooked to the {@see 'upgrader_source_selection'} filter by Theme_Upgrader::install().
* It will return an error if the theme doesn't have style.css or index.php
* files.
*
* @since 3.3.0
*
* @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.
*/
public function check_package( $source ) {
global $wp_filesystem;
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.
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'],
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',
)
);
if ( empty( $info['Name'] ) ) {
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>'
)
);
}
// 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'],
sprintf(
/* translators: %s: index.php */
__( 'The theme is missing the %s file.' ),
'<code>index.php</code>'
)
);
}
return $source;
}
/**
* Turn on maintenance mode before attempting to upgrade the current theme.
*
* Hooked to the {@see 'upgrader_pre_install'} filter by Theme_Upgrader::upgrade() and
* Theme_Upgrader::bulk_upgrade().
*
* @since 2.8.0
*
* @param bool|WP_Error $return
* @param array $theme
* @return bool|WP_Error
*/
public function current_before( $return, $theme ) {
if ( is_wp_error( $return ) ) {
return $return;
}
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
if ( $theme != get_stylesheet() ) { //If not current
return $return;
}
//Change to maintenance mode now.
if ( ! $this->bulk ) {
$this->maintenance_mode( true );
}
return $return;
}
/**
* Turn off maintenance mode after upgrading the current theme.
*
* Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::upgrade()
* and Theme_Upgrader::bulk_upgrade().
*
* @since 2.8.0
*
* @param bool|WP_Error $return
* @param array $theme
* @return bool|WP_Error
*/
public function current_after( $return, $theme ) {
if ( is_wp_error( $return ) ) {
return $return;
}
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
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'] ) {
wp_clean_themes_cache();
$stylesheet = $this->result['destination_name'];
switch_theme( $stylesheet );
}
//Time to remove maintenance mode
if ( ! $this->bulk ) {
$this->maintenance_mode( false );
}
return $return;
}
/**
* Delete the old theme during an upgrade.
*
* Hooked to the {@see 'upgrader_clear_destination'} filter by Theme_Upgrader::upgrade()
* and Theme_Upgrader::bulk_upgrade().
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
*
* @param bool $removed
* @param string $local_destination
* @param string $remote_destination
* @param array $theme
* @return bool
*/
public function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
global $wp_filesystem;
if ( is_wp_error( $removed ) ) {
return $removed; // Pass errors through.
}
if ( ! isset( $theme['theme'] ) ) {
return $removed;
}
$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 ) ) {
return false;
}
}
return true;
}
/**
* Get the WP_Theme object for a theme.
*
* @since 2.8.0
* @since 3.0.0 The `$theme` argument was added.
*
* @param string $theme The directory name of the theme. This is optional, and if not supplied,
* the directory name from the last result will be used.
* @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 ) {
if ( empty( $theme ) ) {
if ( ! empty( $this->result['destination_name'] ) ) {
$theme = $this->result['destination_name'];
} else {
return false;
}
}
return wp_get_theme( $theme );
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
* Taxonomy API: Walker_Category_Checklist class
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Core walker class to output an unordered list of category checkbox input elements.
*
* @since 2.5.1
*
* @see Walker
* @see wp_category_checklist()
* @see wp_terms_checklist()
*/
class Walker_Category_Checklist extends Walker {
public $tree_type = 'category';
public $db_fields = array(
'parent' => 'parent',
'id' => 'term_id',
); //TODO: decouple this
/**
* Starts the list before the elements are added.
*
* @see Walker:start_lvl()
*
* @since 2.5.1
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of category. Used for tab indentation.
* @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 );
$output .= "$indent<ul class='children'>\n";
}
/**
* Ends the list of after the elements are added.
*
* @see Walker::end_lvl()
*
* @since 2.5.1
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of category. Used for tab indentation.
* @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 );
$output .= "$indent</ul>\n";
}
/**
* Start the element output.
*
* @see Walker::start_el()
*
* @since 2.5.1
*
* @param string $output Used to append additional content (passed by reference).
* @param object $category The current term object.
* @param int $depth Depth of the term in reference to parents. Default 0.
* @param array $args An array of arguments. @see wp_terms_checklist()
* @param int $id ID of the current term.
*/
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
if ( empty( $args['taxonomy'] ) ) {
$taxonomy = 'category';
} else {
$taxonomy = $args['taxonomy'];
}
if ( $taxonomy == 'category' ) {
$name = 'post_category';
} else {
$name = 'tax_input[' . $taxonomy . ']';
}
$args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
$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';
if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
$inner_class .= ' selected';
$aria_checked = 'true';
}
/** This filter is documented in wp-includes/category-template.php */
$output .= "\n" . '<li' . $class . '>' .
'<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
' tabindex="0" role="checkbox" aria-checked="' . $aria_checked . '">' .
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
} 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 . '"' .
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>';
}
}
/**
* Ends the element output, if needed.
*
* @see Walker::end_el()
*
* @since 2.5.1
*
* @param string $output Used to append additional content (passed by reference).
* @param object $category The current term object.
* @param int $depth Depth of the term in reference to parents. Default 0.
* @param array $args An array of arguments. @see wp_terms_checklist()
*/
public function end_el( &$output, $category, $depth = 0, $args = array() ) {
$output .= "</li>\n";
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* Navigation Menu API: Walker_Nav_Menu_Checklist class
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Create HTML list of nav menu input items.
*
* @since 3.0.0
* @uses Walker_Nav_Menu
*/
class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
/**
* @param array $fields
*/
public function __construct( $fields = false ) {
if ( $fields ) {
$this->db_fields = $fields;
}
}
/**
* Starts the list before the elements are added.
*
* @see Walker_Nav_Menu::start_lvl()
*
* @since 3.0.0
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of page. Used for padding.
* @param array $args Not used.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class='children'>\n";
}
/**
* Ends the list of after the elements are added.
*
* @see Walker_Nav_Menu::end_lvl()
*
* @since 3.0.0
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of page. Used for padding.
* @param array $args Not used.
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent</ul>";
}
/**
* Start the element output.
*
* @see Walker_Nav_Menu::start_el()
*
* @since 3.0.0
*
* @global int $_nav_menu_placeholder
*
* @param string $output Used to append additional content (passed by reference).
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args Not used.
* @param int $id Not used.
*/
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;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$output .= $indent . '<li>';
$output .= '<label class="menu-item-title">';
$output .= '<input type="checkbox" class="menu-item-checkbox';
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 ) . '" /> ';
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 ) {
/* 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>';
// 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 ) . '" />';
}
} // Walker_Nav_Menu_Checklist

View File

@ -0,0 +1,266 @@
<?php
/**
* Navigation Menu API: Walker_Nav_Menu_Edit class
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Create HTML list of nav menu input items.
*
* @since 3.0.0
*
* @see Walker_Nav_Menu
*/
class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
/**
* Starts the list before the elements are added.
*
* @see Walker_Nav_Menu::start_lvl()
*
* @since 3.0.0
*
* @param string $output Passed by reference.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args Not used.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {}
/**
* Ends the list of after the elements are added.
*
* @see Walker_Nav_Menu::end_lvl()
*
* @since 3.0.0
*
* @param string $output Passed by reference.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args Not used.
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {}
/**
* Start the element output.
*
* @see Walker_Nav_Menu::start_el()
* @since 3.0.0
*
* @global int $_wp_nav_menu_max_depth
*
* @param string $output Used to append additional content (passed by reference).
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args Not used.
* @param int $id Not used.
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $_wp_nav_menu_max_depth;
$_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 );
$removed_args = array(
'action',
'customlink-tab',
'edit-menu-item',
'menu-item',
'page-tab',
'_wpnonce',
);
$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 ) ) {
$original_title = false;
}
} elseif ( 'post_type' == $item->type ) {
$original_object = get_post( $item->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 ) {
$original_title = $original_object->labels->archives;
}
}
$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' ),
);
$title = $item->title;
if ( ! empty( $item->_invalid ) ) {
$classes[] = 'menu-item-invalid';
/* translators: %s: title of menu item which is invalid */
$title = sprintf( __( '%s (Invalid)' ), $item->title );
} 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 = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
$submenu_text = '';
if ( 0 == $depth ) {
$submenu_text = 'style="display: none;"';
}
?>
<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
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'move-up-menu-item',
'menu-item' => $item_id,
),
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>
|
<a href="
<?php
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'move-down-menu-item',
'menu-item' => $item_id,
),
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>
</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>
</span>
</div>
</div>
<div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
<?php if ( 'custom' == $item->type ) : ?>
<p class="field-url description description-wide">
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
<?php _e( 'URL' ); ?><br />
<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
</label>
</p>
<?php endif; ?>
<p class="description description-wide">
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
<?php _e( 'Navigation Label' ); ?><br />
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
</label>
</p>
<p class="field-title-attribute field-attr-title description description-wide">
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
<?php _e( 'Title Attribute' ); ?><br />
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
</label>
</p>
<p class="field-link-target description">
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
<?php _e( 'Open link in a new tab' ); ?>
</label>
</p>
<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 ) ); ?>" />
</label>
</p>
<p class="field-xfn description description-thin">
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
<?php _e( 'Link Relationship (XFN)' ); ?><br />
<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
</label>
</p>
<p class="field-description description description-wide">
<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>
</label>
</p>
<fieldset class="field-move hide-if-no-js description description-wide">
<span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span>
<button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></button>
<button type="button" class="button-link menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></button>
<button type="button" class="button-link menus-move menus-move-left" data-dir="left"></button>
<button type="button" class="button-link menus-move menus-move-right" data-dir="right"></button>
<button type="button" class="button-link menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></button>
</fieldset>
<div class="menu-item-actions description-wide submitbox">
<?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
<p class="link-to-original">
<?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(
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(
'edit-menu-item' => $item_id,
'cancel' => time(),
),
admin_url( 'nav-menus.php' )
)
);
?>
#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; ?>" />
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
</div><!-- .menu-item-settings-->
<ul class="menu-item-transport"></ul>
<?php
$output .= ob_get_clean();
}
} // Walker_Nav_Menu_Edit

View File

@ -0,0 +1,128 @@
<?php
/**
* Upgrader API: WP_Ajax_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Upgrader Skin for Ajax WordPress upgrades.
*
* This skin is designed to be used for Ajax updates.
*
* @since 4.6.0
*
* @see Automatic_Upgrader_Skin
*/
class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
/**
* Holds the WP_Error object.
*
* @since 4.6.0
* @var null|WP_Error
*/
protected $errors = null;
/**
* Constructor.
*
* @since 4.6.0
*
* @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct().
*/
public function __construct( $args = array() ) {
parent::__construct( $args );
$this->errors = new WP_Error();
}
/**
* Retrieves the list of errors.
*
* @since 4.6.0
*
* @return WP_Error Errors during an upgrade.
*/
public function get_errors() {
return $this->errors;
}
/**
* Retrieves a string for error messages.
*
* @since 4.6.0
*
* @return string Error messages during an upgrade.
*/
public function get_error_messages() {
$messages = array();
foreach ( $this->errors->get_error_codes() as $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 );
}
}
return implode( ', ', $messages );
}
/**
* Stores a log entry for an error.
*
* @since 4.6.0
*
* @param string|WP_Error $errors Errors.
*/
public function error( $errors ) {
if ( is_string( $errors ) ) {
$string = $errors;
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
$string = $this->upgrader->strings[ $string ];
}
if ( false !== strpos( $string, '%' ) ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( ! empty( $args ) ) {
$string = vsprintf( $string, $args );
}
}
// 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 );
} 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 ) );
}
}
$args = func_get_args();
call_user_func_array( array( $this, 'parent::error' ), $args );
}
/**
* Stores a log entry.
*
* @since 4.6.0
*
* @param string|array|WP_Error $data Log entry data.
*/
public function feedback( $data ) {
if ( is_wp_error( $data ) ) {
foreach ( $data->get_error_codes() as $error_code ) {
$this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
}
}
$args = func_get_args();
call_user_func_array( array( $this, 'parent::feedback' ), $args );
}
}

View File

@ -0,0 +1,989 @@
<?php
/**
* Upgrade API: WP_Automatic_Updater class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Core class used for handling automatic background updates.
*
* @since 3.7.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
*/
class WP_Automatic_Updater {
/**
* Tracks update results during processing.
*
* @var array
*/
protected $update_results = array();
/**
* Whether the entire automatic updater is disabled.
*
* @since 3.7.0
*/
public function is_disabled() {
// Background updates are disabled if you don't want file changes.
if ( ! wp_is_file_mod_allowed( 'automatic_updater' ) ) {
return true;
}
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;
/**
* Filters whether to entirely disable background updates.
*
* There are more fine-grained filters and controls for selective disabling.
* This filter parallels the AUTOMATIC_UPDATER_DISABLED constant in name.
*
* This also disables update notification emails. That may change in the future.
*
* @since 3.7.0
*
* @param bool $disabled Whether the updater should be disabled.
*/
return apply_filters( 'automatic_updater_disabled', $disabled );
}
/**
* Check for version control checkouts.
*
* Checks for Subversion, Git, Mercurial, and Bazaar. It recursively looks up the
* filesystem to the top of the drive, erring on the side of detecting a VCS
* checkout somewhere.
*
* ABSPATH is always checked in addition to whatever $context is (which may be the
* wp-content directory, for example). The underlying assumption is that if you are
* using version control *anywhere*, then you should be making decisions for
* how things get updated.
*
* @since 3.7.0
*
* @param string $context The filesystem path to check, in addition to ABSPATH.
*/
public function is_vcs_checkout( $context ) {
$context_dirs = array( untrailingslashit( $context ) );
if ( $context !== ABSPATH ) {
$context_dirs[] = untrailingslashit( ABSPATH );
}
$vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' );
$check_dirs = array();
foreach ( $context_dirs as $context_dir ) {
// Walk up from $context_dir to the root.
do {
$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 ) ) {
break;
}
// Continue one level at a time.
} while ( $context_dir = dirname( $context_dir ) );
}
$check_dirs = array_unique( $check_dirs );
// 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" ) ) {
break 2;
}
}
}
/**
* Filters whether the automatic updater should consider a filesystem
* location to be potentially managed by a version control system.
*
* @since 3.7.0
*
* @param bool $checkout Whether a VCS checkout was discovered at $context
* or ABSPATH, or anywhere higher.
* @param string $context The filesystem context (a path) against which
* filesystem status should be checked.
*/
return apply_filters( 'automatic_updates_is_vcs_checkout', $checkout, $context );
}
/**
* Tests to see if we can and should update a specific item.
*
* @since 3.7.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $type The type of update being checked: 'core', 'theme',
* 'plugin', 'translation'.
* @param object $item The update offer.
* @param string $context The filesystem context (a path) against which filesystem
* access and status should be checked.
*/
public function should_update( $type, $item, $context ) {
// Used to see if WP_Filesystem is set up to allow unattended updates.
$skin = new Automatic_Upgrader_Skin;
if ( $this->is_disabled() ) {
return false;
}
// Only relax the filesystem checks when the update doesn't include new files
$allow_relaxed_file_ownership = false;
if ( 'core' == $type && isset( $item->new_files ) && ! $item->new_files ) {
$allow_relaxed_file_ownership = true;
}
// 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 ) {
$this->send_core_update_notification_email( $item );
}
return false;
}
// Next up, is this an item we can update?
if ( 'core' == $type ) {
$update = Core_Upgrader::should_update_to_version( $item->current );
} else {
$update = ! empty( $item->autoupdate );
}
/**
* Filters whether to automatically update core, a plugin, a theme, or a language.
*
* The dynamic portion of the hook name, `$type`, refers to the type of update
* being checked. Can be 'core', 'theme', 'plugin', or 'translation'.
*
* Generally speaking, plugins, themes, and major core versions are not updated
* 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'},
* and {@see 'allow_major_auto_core_updates'} filters for a more straightforward way to
* adjust core updates.
*
* @since 3.7.0
*
* @param bool $update Whether to update.
* @param object $item The update offer.
*/
$update = apply_filters( "auto_update_{$type}", $update, $item );
if ( ! $update ) {
if ( 'core' == $type ) {
$this->send_core_update_notification_email( $item );
}
return false;
}
// If it's a core update, are we actually compatible with its requirements?
if ( 'core' == $type ) {
global $wpdb;
$php_compat = version_compare( phpversion(), $item->php_version, '>=' );
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
$mysql_compat = true;
} else {
$mysql_compat = version_compare( $wpdb->db_version(), $item->mysql_version, '>=' );
}
if ( ! $php_compat || ! $mysql_compat ) {
return false;
}
}
return true;
}
/**
* Notifies an administrator of a core update.
*
* @since 3.7.0
*
* @param object $item The update offer.
*/
protected function send_core_update_notification_email( $item ) {
$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 ) {
return false;
}
// See if we need to notify users of a core update.
$notify = ! empty( $item->notify_email );
/**
* Filters whether to notify the site administrator of a new core update.
*
* By default, administrators are notified when the update offer received
* from WordPress.org sets a particular flag. This allows some discretion
* in if and when to notify.
*
* This filter is only evaluated once per release. If the same email address
* was already notified of the same new version, WordPress won't repeatedly
* email the administrator.
*
* This filter is also used on about.php to check if a plugin has disabled
* these notifications.
*
* @since 3.7.0
*
* @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 ) ) {
return false;
}
$this->send_email( 'manual', $item );
return true;
}
/**
* Update an item, if appropriate.
*
* @since 3.7.0
*
* @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
* @param object $item The update offer.
*
* @return null|WP_Error
*/
public function update( $type, $item ) {
$skin = new Automatic_Upgrader_Skin;
switch ( $type ) {
case 'core':
// The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter.
add_filter( 'update_feedback', array( $skin, 'feedback' ) );
$upgrader = new Core_Upgrader( $skin );
$context = ABSPATH;
break;
case 'plugin':
$upgrader = new Plugin_Upgrader( $skin );
$context = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR
break;
case 'theme':
$upgrader = new Theme_Upgrader( $skin );
$context = get_theme_root( $item->theme );
break;
case 'translation':
$upgrader = new Language_Pack_Upgrader( $skin );
$context = WP_CONTENT_DIR; // WP_LANG_DIR;
break;
}
// Determine whether we can and should perform this update.
if ( ! $this->should_update( $type, $item, $context ) ) {
return false;
}
/**
* Fires immediately prior to an auto-update.
*
* @since 4.4.0
*
* @param string $type The type of update being checked: 'core', 'theme', 'plugin', or 'translation'.
* @param object $item The update offer.
* @param string $context The filesystem context (a path) against which filesystem access and status
* should be checked.
*/
do_action( 'pre_auto_update', $type, $item, $context );
$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' );
/* 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'];
/* 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;
}
$allow_relaxed_file_ownership = false;
if ( 'core' == $type && isset( $item->new_files ) && ! $item->new_files ) {
$allow_relaxed_file_ownership = true;
}
// 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,
)
);
// If the filesystem is unavailable, false is returned.
if ( false === $upgrade_result ) {
$upgrade_result = new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
}
if ( 'core' == $type ) {
if ( is_wp_error( $upgrade_result ) && ( 'up_to_date' == $upgrade_result->get_error_code() || 'locked' == $upgrade_result->get_error_code() ) ) {
// These aren't actual errors, treat it as a skipped-update instead to avoid triggering the post-core update failure routines.
return false;
}
// Core doesn't output this, so let's append it so we don't get confused.
if ( is_wp_error( $upgrade_result ) ) {
$skin->error( __( 'Installation Failed' ), $upgrade_result );
} else {
$skin->feedback( __( 'WordPress updated successfully' ) );
}
}
$this->update_results[ $type ][] = (object) array(
'item' => $item,
'result' => $upgrade_result,
'name' => $item_name,
'messages' => $skin->get_upgrade_messages(),
);
return $upgrade_result;
}
/**
* Kicks off the background update process, looping through all pending updates.
*
* @since 3.7.0
*/
public function run() {
if ( $this->is_disabled() ) {
return;
}
if ( ! is_main_network() || ! is_main_site() ) {
return;
}
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 );
remove_action( 'upgrader_process_complete', 'wp_version_check' );
remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
remove_action( 'upgrader_process_complete', 'wp_update_themes' );
// Next, Plugins
wp_update_plugins(); // Check for Plugin updates
$plugin_updates = get_site_transient( 'update_plugins' );
if ( $plugin_updates && ! empty( $plugin_updates->response ) ) {
foreach ( $plugin_updates->response as $plugin ) {
$this->update( 'plugin', $plugin );
}
// Force refresh of plugin update information
wp_clean_plugins_cache();
}
// 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 ) ) {
foreach ( $theme_updates->response as $theme ) {
$this->update( 'theme', (object) $theme );
}
// Force refresh of theme update information
wp_clean_themes_cache();
}
// Next, Process any core update
wp_version_check(); // Check for Core updates
$core_update = find_core_auto_update();
if ( $core_update ) {
$this->update( 'core', $core_update );
}
// Clean up, and check for any pending translations
// (Core_Upgrader checks for core updates)
$theme_stats = array();
if ( isset( $this->update_results['theme'] ) ) {
foreach ( $this->update_results['theme'] as $upgrade ) {
$theme_stats[ $upgrade->item->theme ] = ( true === $upgrade->result );
}
}
wp_update_themes( $theme_stats ); // Check for Theme updates
$plugin_stats = array();
if ( isset( $this->update_results['plugin'] ) ) {
foreach ( $this->update_results['plugin'] as $upgrade ) {
$plugin_stats[ $upgrade->item->plugin ] = ( true === $upgrade->result );
}
}
wp_update_plugins( $plugin_stats ); // Check for Plugin updates
// Finally, Process any new translations
$language_updates = wp_get_translation_updates();
if ( $language_updates ) {
foreach ( $language_updates as $update ) {
$this->update( 'translation', $update );
}
// Clear existing caches
wp_clean_update_cache();
wp_version_check(); // check for Core updates
wp_update_themes(); // Check for Theme updates
wp_update_plugins(); // Check for Plugin updates
}
// Send debugging email to admin for all development installations.
if ( ! empty( $this->update_results ) ) {
$development_version = false !== strpos( get_bloginfo( 'version' ), '-' );
/**
* Filters whether to send a debugging email for each automatic background update.
*
* @since 3.7.0
*
* @param bool $development_version By default, emails are sent if the
* install is a development version.
* Return false to avoid the email.
*/
if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) ) {
$this->send_debug_email();
}
if ( ! empty( $this->update_results['core'] ) ) {
$this->after_core_update( $this->update_results['core'][0] );
}
/**
* Fires after all automatic updates have run.
*
* @since 3.8.0
*
* @param array $update_results The results of all attempted updates.
*/
do_action( 'automatic_updates_complete', $this->update_results );
}
WP_Upgrader::release_lock( 'auto_updater' );
}
/**
* If we tried to perform a core update, check if we should send an email,
* and if we need to avoid processing future updates.
*
* @since 3.7.0
*
* @param object $update_result The result of the core update. Includes the update offer and result.
*/
protected function after_core_update( $update_result ) {
$wp_version = get_bloginfo( 'version' );
$core_update = $update_result->item;
$result = $update_result->result;
if ( ! is_wp_error( $result ) ) {
$this->send_email( 'success', $core_update );
return;
}
$error_code = $result->get_error_code();
// Any of these WP_Error codes are critical failures, as in they occurred after we started to copy core files.
// We should not try to perform a background update again until there is a successful one-click update performed by the user.
$critical = false;
if ( $error_code === 'disk_full' || false !== strpos( $error_code, '__copy_dir' ) ) {
$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;
$rollback_result = $result->get_error_data()->rollback;
} elseif ( false !== strpos( $error_code, 'do_rollback' ) ) {
$critical = true;
}
if ( $critical ) {
$critical_data = array(
'attempted' => $core_update->current,
'current' => $wp_version,
'error_code' => $error_code,
'error_data' => $result->get_error_data(),
'timestamp' => time(),
'critical' => true,
);
if ( isset( $rollback_result ) ) {
$critical_data['rollback_code'] = $rollback_result->get_error_code();
$critical_data['rollback_data'] = $rollback_result->get_error_data();
}
update_site_option( 'auto_core_update_failed', $critical_data );
$this->send_email( 'critical', $core_update, $result );
return;
}
/*
* Any other WP_Error code (like download_failed or files_not_writable) occurs before
* we tried to copy over core files. Thus, the failures are early and graceful.
*
* We should avoid trying to perform a background update again for the same version.
* But we can try again if another version is released.
*
* For certain 'transient' failures, like download_failed, we should allow retries.
* 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 = 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 ),
)
);
if ( $send ) {
$this->send_email( 'fail', $core_update, $result );
}
}
/**
* Sends an email upon the completion or failure of a background core update.
*
* @since 3.7.0
*
* @param string $type The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'.
* @param object $core_update The update offer that was attempted.
* @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(),
)
);
$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 ) {
$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, '>' ) );
/**
* Filters whether to send an email following an automatic background core update.
*
* @since 3.7.0
*
* @param bool $send Whether to send the email. Default true.
* @param string $type The type of email to send. Can be one of
* 'success', 'fail', 'critical'.
* @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 ) ) {
return;
}
switch ( $type ) {
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).
/* 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.
/* translators: 1: Site name. */
$subject = __( '[%1$s] URGENT: Your site may be down due to a failed update' );
break;
default:
return;
}
// If the auto update is not to the latest version, say that the current version of WP is available instead.
$version = 'success' === $type ? $core_update->current : $next_user_core_update->current;
$subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $version );
$body = '';
switch ( $type ) {
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 ) {
$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 );
/* 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' );
}
break;
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 ) {
$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 ) {
/* 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 {
/* 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." );
$body .= "\n\n" . __( "Please check out your site now. It's possible that everything is working. If it says you need to update, you should do so:" );
$body .= "\n" . network_admin_url( 'update-core.php' );
break;
}
$critical_support = 'critical' === $type && ! empty( $core_update->support_email );
if ( $critical_support ) {
// Support offer if available.
/* 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.' );
$body .= "\n" . __( 'https://wordpress.org/support/' );
}
// Updates are important!
if ( $type != 'success' || $newer_version_available ) {
$body .= "\n\n" . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' );
}
if ( $critical_support ) {
$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.
if ( $type == 'success' && ! $newer_version_available && ( get_plugin_updates() || get_theme_updates() ) ) {
$body .= "\n\n" . __( 'You also have some plugins or themes with updates available. Update them now:' );
$body .= "\n" . network_admin_url();
}
$body .= "\n\n" . __( 'The WordPress Team' ) . "\n";
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() ) {
$errors = array( $result, $result->get_error_data()->update, $result->get_error_data()->rollback );
} else {
$errors = array( $result );
}
foreach ( $errors as $error ) {
if ( ! is_wp_error( $error ) ) {
continue;
}
$error_code = $error->get_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() ) {
$body .= "\n" . $error->get_error_message();
}
$error_data = $error->get_error_data();
if ( $error_data ) {
$body .= "\n" . implode( ', ', (array) $error_data );
}
}
$body .= "\n";
}
$to = get_site_option( 'admin_email' );
$headers = '';
$email = compact( 'to', 'subject', 'body', 'headers' );
/**
* Filters the email sent following an automatic background core update.
*
* @since 3.7.0
*
* @param array $email {
* Array of email arguments that will be passed to wp_mail().
*
* @type string $to The email recipient. An array of emails
* can be returned, as handled by wp_mail().
* @type string $subject The email's subject.
* @type string $body The email message body.
* @type string $headers Any email headers, defaults to no headers.
* }
* @param string $type The type of email being sent. Can be one of
* 'success', 'fail', 'manual', 'critical'.
* @param object $core_update The update offer that was attempted.
* @param mixed $result The result for the core update. Can be WP_Error.
*/
$email = apply_filters( 'auto_core_update_email', $email, $type, $core_update, $result );
wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );
}
/**
* Prepares and sends an email of a full log of background update results, useful for debugging and geekery.
*
* @since 3.7.0
*/
protected function send_debug_email() {
$update_count = 0;
foreach ( $this->update_results as $type => $updates ) {
$update_count += count( $updates );
}
$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++;
}
$body[] = '';
}
// Plugins, Themes, Translations
foreach ( array( 'plugin', 'theme', 'translation' ) as $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(
'plugin' => __( 'The following plugins were successfully updated:' ),
'theme' => __( 'The following themes were successfully updated:' ),
'translation' => __( 'The following translations were successfully updated:' ),
);
$body[] = $messages[ $type ];
foreach ( wp_list_pluck( $success_items, 'name' ) as $name ) {
/* translators: %s: name of plugin / theme / translations */
$body[] = ' * ' . sprintf( __( 'SUCCESS: %s' ), $name );
}
}
if ( $success_items != $this->update_results[ $type ] ) {
// Failed updates
$messages = array(
'plugin' => __( 'The following plugins failed to update:' ),
'theme' => __( 'The following themes failed to update:' ),
'translation' => __( 'The following translations failed to update:' ),
);
$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++;
}
}
}
$body[] = '';
}
$site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
if ( $failures ) {
$body[] = trim(
__(
"BETA TESTING?
=============
This debugging email is sent when you are using a development version of WordPress.
If you think these failures might be due to a bug in WordPress, could you report it?
* 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"
)
);
$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[] = '';
foreach ( array( 'core', 'plugin', 'theme', 'translation' ) as $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 ) );
}
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() ) {
$results = (array) $update->result->get_error_data();
}
foreach ( $results as $result_type => $result ) {
if ( ! is_wp_error( $result ) ) {
continue;
}
if ( 'rollback' === $result_type ) {
/* translators: 1: Error code, 2: Error message. */
$body[] = ' ' . sprintf( __( 'Rollback Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() );
} else {
/* translators: 1: Error code, 2: Error message. */
$body[] = ' ' . sprintf( __( 'Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() );
}
if ( $result->get_error_data() ) {
$body[] = ' ' . implode( ', ', (array) $result->get_error_data() );
}
}
}
$body[] = '';
}
}
$email = array(
'to' => get_site_option( 'admin_email' ),
'subject' => $subject,
'body' => implode( "\n", $body ),
'headers' => '',
);
/**
* Filters the debug email that can be sent following an automatic
* background core update.
*
* @since 3.8.0
*
* @param array $email {
* Array of email arguments that will be passed to wp_mail().
*
* @type string $to The email recipient. An array of emails
* can be returned, as handled by wp_mail().
* @type string $subject Email subject.
* @type string $body Email message body.
* @type string $headers Any email headers. Default empty.
* }
* @param int $failures The number of failures encountered while upgrading.
* @param mixed $results The results of all attempted updates.
*/
$email = apply_filters( 'automatic_updates_debug_email', $email, $failures, $this->update_results );
wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );
}
}

View File

@ -0,0 +1,861 @@
<?php
/**
* List Table API: WP_Comments_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying comments in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_Comments_List_Table extends WP_List_Table {
public $checkbox = true;
public $pending_count = array();
public $extra_items;
private $user_can;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global int $post_id
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
global $post_id;
$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
if ( get_option( 'show_avatars' ) ) {
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,
)
);
}
public function floated_admin_avatar( $name, $comment_ID ) {
$comment = get_comment( $comment_ID );
$avatar = get_avatar( $comment, 32, 'mystery' );
return "$avatar $name";
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'edit_posts' );
}
/**
* @global int $post_id
* @global string $comment_status
* @global string $search
* @global string $comment_type
*/
public function prepare_items() {
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', 'mine', 'moderated', 'approved', 'spam', 'trash' ) ) ) {
$comment_status = 'all';
}
$comment_type = ! empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
$post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : '';
$user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
$orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : '';
$order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
$comments_per_page = $this->get_per_page( $comment_status );
$doing_ajax = wp_doing_ajax();
if ( isset( $_REQUEST['number'] ) ) {
$number = (int) $_REQUEST['number'];
} else {
$number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
}
$page = $this->get_pagenum();
if ( isset( $_REQUEST['start'] ) ) {
$start = $_REQUEST['start'];
} else {
$start = ( $page - 1 ) * $comments_per_page;
}
if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) {
$start += $_REQUEST['offset'];
}
$status_map = array(
'mine' => '',
'moderated' => 'hold',
'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,
'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->extra_items = array_slice( $_comments, $comments_per_page );
$_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
$this->pending_count = get_pending_comments_num( $_comment_post_ids );
}
$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,
)
);
}
/**
* @param string $comment_status
* @return int
*/
public function get_per_page( $comment_status = 'all' ) {
$comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
/**
* Filters the number of comments listed per page in the comments list table.
*
* @since 2.6.0
*
* @param int $comments_per_page The number of comments to list per page.
* @param string $comment_status The comment status name. Default 'All'.
*/
return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
}
/**
* @global string $comment_status
*/
public function no_items() {
global $comment_status;
if ( 'moderated' === $comment_status ) {
_e( 'No comments awaiting moderation.' );
} else {
_e( 'No comments found.' );
}
}
/**
* @global int $post_id
* @global string $comment_status
* @global string $comment_type
*/
protected function get_views() {
global $post_id, $comment_status, $comment_type;
$status_links = array();
$num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
$stati = array(
/* translators: %s: all comments count */
'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>',
'Pending <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: approved comments count */
'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 <span class="count">(%s)</span>',
'Spam <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: trashed comments count */
'trash' => _nx_noop(
'Trash <span class="count">(%s)</span>',
'Trash <span class="count">(%s)</span>',
'comments'
),
);
if ( ! EMPTY_TRASH_DAYS ) {
unset( $stati['trash'] );
}
$link = admin_url( 'edit-comments.php' );
if ( ! empty( $comment_type ) && 'all' != $comment_type ) {
$link = add_query_arg( 'comment_type', $comment_type, $link );
}
foreach ( $stati as $status => $label ) {
$current_link_attributes = '';
if ( $status === $comment_status ) {
$current_link_attributes = ' class="current" aria-current="page"';
}
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 ) {
$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'] ) )
$link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link );
*/
$status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf(
translate_nooped_plural( $label, $num_comments->$status ),
sprintf(
'<span class="%s-count">%s</span>',
( 'moderated' === $status ) ? 'pending' : $status,
number_format_i18n( $num_comments->$status )
)
) . '</a>';
}
/**
* Filters the comment status links.
*
* @since 2.5.0
* @since 5.1.0 The 'Mine' link was added.
*
* @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
*/
protected function get_bulk_actions() {
global $comment_status;
$actions = array();
if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) {
$actions['unapprove'] = __( 'Unapprove' );
}
if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) {
$actions['approve'] = __( 'Approve' );
}
if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) ) {
$actions['spam'] = _x( 'Mark as Spam', 'comment' );
}
if ( 'trash' === $comment_status ) {
$actions['untrash'] = __( 'Restore' );
} elseif ( 'spam' === $comment_status ) {
$actions['unspam'] = _x( 'Not Spam', 'comment' );
}
if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = __( 'Delete Permanently' );
} else {
$actions['trash'] = __( 'Move to Trash' );
}
return $actions;
}
/**
* @global string $comment_status
* @global string $comment_type
*
* @param string $which
*/
protected function extra_tablenav( $which ) {
global $comment_status, $comment_type;
static $has_items;
if ( ! isset( $has_items ) ) {
$has_items = $this->has_items();
}
?>
<div class="alignleft actions">
<?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
/**
* Filters the comment types dropdown menu.
*
* @since 2.7.0
*
* @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' ),
)
);
foreach ( $comment_types as $type => $label ) {
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
}
?>
</select>
<?php
/**
* Fires just before the Filter submit button for comment types.
*
* @since 3.5.0
*/
do_action( 'restrict_manage_comments' );
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
}
if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $has_items ) {
wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
$title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
submit_button( $title, 'apply', 'delete_all', false );
}
/**
* Fires after the Filter submit button for comment types.
*
* @since 2.5.0
*
* @param string $comment_status The comment status name. Default 'All'.
*/
do_action( 'manage_comments_nav', $comment_status );
echo '</div>';
}
/**
* @return string|false
*/
public function current_action() {
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
return 'delete_all';
}
return parent::current_action();
}
/**
* @global int $post_id
*
* @return array
*/
public function get_columns() {
global $post_id;
$columns = array();
if ( $this->checkbox ) {
$columns['cb'] = '<input type="checkbox" />';
}
$columns['author'] = __( 'Author' );
$columns['comment'] = _x( 'Comment', 'column name' );
if ( ! $post_id ) {
/* translators: column name or table row header */
$columns['response'] = __( 'In Response To' );
}
$columns['date'] = _x( 'Submitted On', 'column name' );
return $columns;
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'author' => 'comment_author',
'response' => 'comment_post_ID',
'date' => 'comment_date',
);
}
/**
* Get the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'comment'.
*/
protected function get_default_primary_column_name() {
return 'comment';
}
/**
*/
public function display() {
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>
<?php $this->print_column_headers(); ?>
</tr>
</thead>
<tbody id="the-comment-list" data-wp-lists="list:comment">
<?php $this->display_rows_or_placeholder(); ?>
</tbody>
<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>
<tfoot>
<tr>
<?php $this->print_column_headers( false ); ?>
</tr>
</tfoot>
</table>
<?php
$this->display_tablenav( 'bottom' );
}
/**
* @global WP_Post $post
* @global WP_Comment $comment
*
* @param WP_Comment $item
*/
public function single_row( $item ) {
global $post, $comment;
$comment = $item;
$the_comment_class = wp_get_comment_status( $comment );
if ( ! $the_comment_class ) {
$the_comment_class = '';
}
$the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) );
if ( $comment->comment_post_ID > 0 ) {
$post = get_post( $comment->comment_post_ID );
}
$this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
$this->single_row_columns( $comment );
echo "</tr>\n";
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;
if ( $primary !== $column_name ) {
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" ) );
$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" );
$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" );
// Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
$actions = array(
'approve' => '',
'unapprove' => '',
'reply' => '',
'quickedit' => '',
'edit' => '',
'spam' => '',
'unspam' => '',
'trash' => '',
'untrash' => '',
'delete' => '',
);
// Not looking at all comments.
if ( $comment_status && 'all' != $comment_status ) {
if ( 'approved' === $the_comment_status ) {
$actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved' class='vim-u vim-destructive' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
} elseif ( 'unapproved' === $the_comment_status ) {
$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['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>';
}
if ( 'spam' !== $the_comment_status ) {
$actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
} elseif ( 'spam' === $the_comment_status ) {
$actions['unspam'] = "<a href='$unspam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1' class='vim-z vim-destructive' aria-label='" . esc_attr__( 'Restore this comment from the spam' ) . "'>" . _x( 'Not Spam', 'comment' ) . '</a>';
}
if ( 'trash' === $the_comment_status ) {
$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 ) {
$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>';
$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' ) );
$actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
}
/** This filter is documented in wp-admin/includes/dashboard.php */
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$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() ) {
$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 ) ) {
$action .= ' approve';
} else {
$action .= ' unapprove';
}
}
$out .= "<span class='$action'>$sep$link</span>";
}
$out .= '</div>';
$out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
return $out;
}
/**
* @param WP_Comment $comment The comment object.
*/
public function column_cb( $comment ) {
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
}
}
/**
* @param WP_Comment $comment The comment object.
*/
public function column_comment( $comment ) {
echo '<div class="comment-author">';
$this->column_author( $comment );
echo '</div>';
if ( $comment->comment_parent ) {
$parent = get_comment( $comment->comment_parent );
if ( $parent ) {
$parent_link = esc_url( get_comment_link( $parent ) );
$name = get_comment_author( $parent );
printf(
/* translators: %s: comment link */
__( 'In reply to %s.' ),
'<a href="' . $parent_link . '">' . $name . '</a>'
);
}
}
comment_text( $comment );
if ( $this->user_can ) {
/** This filter is documented in wp-admin/includes/comment.php */
$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
}
}
/**
* @global string $comment_status
*
* @param WP_Comment $comment The comment object.
*/
public function column_author( $comment ) {
global $comment_status;
$author_url = get_comment_author_url( $comment );
$author_url_display = untrailingslashit( preg_replace( '|^http(s)?://(www\.)?|i', '', $author_url ) );
if ( strlen( $author_url_display ) > 50 ) {
$author_url_display = wp_html_excerpt( $author_url_display, 49, '&hellip;' );
}
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 ) );
}
if ( $this->user_can ) {
if ( ! empty( $comment->comment_author_email ) ) {
/** This filter is documented in wp-includes/comment-template.php */
$email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
if ( ! empty( $email ) && '@' !== $email ) {
printf( '<a href="%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) );
}
}
$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' )
);
if ( 'spam' === $comment_status ) {
$author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
}
printf( '<a href="%1$s">%2$s</a>', esc_url( $author_ip_url ), esc_html( $author_ip ) );
}
}
}
/**
* @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' ),
/* 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 ) ) {
printf(
'<a href="%s">%s</a>',
esc_url( get_comment_link( $comment ) ),
$submitted
);
} else {
echo $submitted;
}
echo '</div>';
}
/**
* @param WP_Comment $comment The comment object.
*/
public function column_response( $comment ) {
$post = get_post();
if ( ! $post ) {
return;
}
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 ];
}
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 .= esc_html( get_the_title( $post->ID ) ) . '</a>';
} else {
$post_link = esc_html( get_the_title( $post->ID ) );
}
echo '<div class="response-links">';
if ( 'attachment' === $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) {
echo $thumb;
}
echo $post_link;
$post_type_object = get_post_type_object( $post->post_type );
echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>';
echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">';
$this->comments_bubble( $post->ID, $pending_comments );
echo '</span> ';
echo '</div>';
}
/**
* @param WP_Comment $comment The comment object.
* @param string $column_name The custom column's name.
*/
public function column_default( $comment, $column_name ) {
/**
* Fires when the default column output is displayed for a single row.
*
* @since 2.8.0
*
* @param string $column_name The custom column's name.
* @param int $comment->comment_ID The custom column's unique ID number.
*/
do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
}
}

View File

@ -0,0 +1,464 @@
<?php
/**
* Administration: Community Events class.
*
* @package WordPress
* @subpackage Administration
* @since 4.8.0
*/
/**
* Class WP_Community_Events.
*
* A client for api.wordpress.org/events.
*
* @since 4.8.0
*/
class WP_Community_Events {
/**
* ID for a WordPress user account.
*
* @since 4.8.0
*
* @var int
*/
protected $user_id = 0;
/**
* Stores location data for the user.
*
* @since 4.8.0
*
* @var bool|array
*/
protected $user_location = false;
/**
* Constructor for WP_Community_Events.
*
* @since 4.8.0
*
* @param int $user_id WP user ID.
* @param bool|array $user_location Stored location data for the user.
* false to pass no location;
* array to pass a location {
* @type string $description The name of the location
* @type string $latitude The latitude in decimal degrees notation, without the degree
* symbol. e.g.: 47.615200.
* @type string $longitude The longitude in decimal degrees notation, without the degree
* symbol. e.g.: -122.341100.
* @type string $country The ISO 3166-1 alpha-2 country code. e.g.: BR
* }
*/
public function __construct( $user_id, $user_location = false ) {
$this->user_id = absint( $user_id );
$this->user_location = $user_location;
}
/**
* Gets data about events near a particular location.
*
* Cached events will be immediately returned if the `user_location` property
* is set for the current user, and cached events exist for that location.
*
* Otherwise, this method sends a request to the w.org Events API with location
* data. The API will send back a recognized location based on the data, along
* with nearby events.
*
* The browser's request for events is proxied with this method, rather
* than having the browser make the request directly to api.wordpress.org,
* because it allows results to be cached server-side and shared with other
* users and sites in the network. This makes the process more efficient,
* since increasing the number of visits that get cached data means users
* don't have to wait as often; if the user's browser made the request
* directly, it would also need to make a second request to WP in order to
* pass the data for caching. Having WP make the request also introduces
* the opportunity to anonymize the IP before sending it to w.org, which
* mitigates possible privacy concerns.
*
* @since 4.8.0
*
* @param string $location_search Optional. City name to help determine the location.
* e.g., "Seattle". Default empty string.
* @param string $timezone Optional. Timezone to help determine the location.
* Default empty string.
* @return array|WP_Error A WP_Error on failure; an array with location and events on
* success.
*/
public function get_events( $location_search = '', $timezone = '' ) {
$cached_events = $this->get_cached_events();
if ( ! $location_search && $cached_events ) {
return $cached_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 );
$request_args['user-agent'] = 'WordPress/' . $wp_version . '; ' . home_url( '/' );
if ( wp_http_supports( array( 'ssl' ) ) ) {
$api_url = set_url_scheme( $api_url, 'https' );
}
$response = wp_remote_get( $api_url, $request_args );
$response_code = wp_remote_retrieve_response_code( $response );
$response_body = json_decode( wp_remote_retrieve_body( $response ), true );
$response_error = null;
if ( is_wp_error( $response ) ) {
$response_error = $response;
} elseif ( 200 !== $response_code ) {
$response_error = new WP_Error(
'api-error',
/* translators: %d: numeric HTTP status code, e.g. 400, 403, 500, 504, etc. */
sprintf( __( 'Invalid API response code (%d)' ), $response_code )
);
} elseif ( ! isset( $response_body['location'], $response_body['events'] ) ) {
$response_error = new WP_Error(
'api-invalid-response',
isset( $response_body['error'] ) ? $response_body['error'] : __( 'Unknown API error.' )
);
}
if ( is_wp_error( $response_error ) ) {
return $response_error;
} else {
$expiration = false;
if ( isset( $response_body['ttl'] ) ) {
$expiration = $response_body['ttl'];
unset( $response_body['ttl'] );
}
/*
* The IP in the response is usually the same as the one that was sent
* in the request, but in some cases it is different. In those cases,
* it's important to reset it back to the IP from the request.
*
* For example, if the IP sent in the request is private (e.g., 192.168.1.100),
* then the API will ignore that and use the corresponding public IP instead,
* and the public IP will get returned. If the public IP were saved, though,
* then get_cached_events() would always return `false`, because the transient
* would be generated based on the public IP when saving the cache, but generated
* based on the private IP when retrieving the cache.
*/
if ( ! empty( $response_body['location']['ip'] ) ) {
$response_body['location']['ip'] = $request_args['body']['ip'];
}
/*
* The API doesn't return a description for latitude/longitude requests,
* but the description is already saved in the user location, so that
* one can be used instead.
*/
if ( $this->coordinates_match( $request_args['body'], $response_body['location'] ) && empty( $response_body['location']['description'] ) ) {
$response_body['location']['description'] = $this->user_location['description'];
}
$this->cache_events( $response_body, $expiration );
$response_body = $this->trim_events( $response_body );
$response_body = $this->format_event_data_time( $response_body );
return $response_body;
}
}
/**
* Builds an array of args to use in an HTTP request to the w.org Events API.
*
* @since 4.8.0
*
* @param string $search Optional. City search string. Default empty string.
* @param string $timezone Optional. Timezone string. Default empty string.
* @return array The request args.
*/
protected function get_request_args( $search = '', $timezone = '' ) {
$args = array(
'number' => 5, // Get more than three in case some get trimmed out.
'ip' => self::get_unsafe_client_ip(),
);
/*
* Include the minimal set of necessary arguments, in order to increase the
* chances of a cache-hit on the API side.
*/
if ( empty( $search ) && isset( $this->user_location['latitude'], $this->user_location['longitude'] ) ) {
$args['latitude'] = $this->user_location['latitude'];
$args['longitude'] = $this->user_location['longitude'];
} else {
$args['locale'] = get_user_locale( $this->user_id );
if ( $timezone ) {
$args['timezone'] = $timezone;
}
if ( $search ) {
$args['location'] = $search;
}
}
// Wrap the args in an array compatible with the second parameter of `wp_remote_get()`.
return array(
'body' => $args,
);
}
/**
* Determines the user's actual IP address and attempts to partially
* anonymize an IP address by converting it to a network ID.
*
* Geolocating the network ID usually returns a similar location as the
* actual IP, but provides some privacy for the user.
*
* $_SERVER['REMOTE_ADDR'] cannot be used in all cases, such as when the user
* is making their request through a proxy, or when the web server is behind
* a proxy. In those cases, $_SERVER['REMOTE_ADDR'] is set to the proxy address rather
* than the user's actual address.
*
* Modified from https://stackoverflow.com/a/2031935/450127, MIT license.
* Modified from https://github.com/geertw/php-ip-anonymizer, MIT license.
*
* SECURITY WARNING: This function is _NOT_ intended to be used in
* circumstances where the authenticity of the IP address matters. This does
* _NOT_ guarantee that the returned address is valid or accurate, and it can
* be easily spoofed.
*
* @since 4.8.0
*
* @return false|string The anonymized address on success; the given address
* or false on failure.
*/
public static function get_unsafe_client_ip() {
$client_ip = false;
// In order of preference, with the best ones for this purpose first.
$address_headers = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR',
);
foreach ( $address_headers as $header ) {
if ( array_key_exists( $header, $_SERVER ) ) {
/*
* HTTP_X_FORWARDED_FOR can contain a chain of comma-separated
* addresses. The first one is the original client. It can't be
* trusted for authenticity, but we don't need to for this purpose.
*/
$address_chain = explode( ',', $_SERVER[ $header ] );
$client_ip = trim( $address_chain[0] );
break;
}
}
if ( ! $client_ip ) {
return false;
}
$anon_ip = wp_privacy_anonymize_ip( $client_ip, true );
if ( '0.0.0.0' === $anon_ip || '::' === $anon_ip ) {
return false;
}
return $anon_ip;
}
/**
* Test if two pairs of latitude/longitude coordinates match each other.
*
* @since 4.8.0
*
* @param array $a The first pair, with indexes 'latitude' and 'longitude'.
* @param array $b The second pair, with indexes 'latitude' and 'longitude'.
* @return bool True if they match, false if they don't.
*/
protected function coordinates_match( $a, $b ) {
if ( ! isset( $a['latitude'], $a['longitude'], $b['latitude'], $b['longitude'] ) ) {
return false;
}
return $a['latitude'] === $b['latitude'] && $a['longitude'] === $b['longitude'];
}
/**
* Generates a transient key based on user location.
*
* This could be reduced to a one-liner in the calling functions, but it's
* intentionally a separate function because it's called from multiple
* functions, and having it abstracted keeps the logic consistent and DRY,
* which is less prone to errors.
*
* @since 4.8.0
*
* @param array $location Should contain 'latitude' and 'longitude' indexes.
* @return bool|string false on failure, or a string on success.
*/
protected function get_events_transient_key( $location ) {
$key = false;
if ( isset( $location['ip'] ) ) {
$key = 'community-events-' . md5( $location['ip'] );
} elseif ( isset( $location['latitude'], $location['longitude'] ) ) {
$key = 'community-events-' . md5( $location['latitude'] . $location['longitude'] );
}
return $key;
}
/**
* Caches an array of events data from the Events API.
*
* @since 4.8.0
*
* @param array $events Response body from the API request.
* @param int|bool $expiration Optional. Amount of time to cache the events. Defaults to false.
* @return bool true if events were cached; false if not.
*/
protected function cache_events( $events, $expiration = false ) {
$set = false;
$transient_key = $this->get_events_transient_key( $events['location'] );
$cache_expiration = $expiration ? absint( $expiration ) : HOUR_IN_SECONDS * 12;
if ( $transient_key ) {
$set = set_site_transient( $transient_key, $events, $cache_expiration );
}
return $set;
}
/**
* Gets cached events.
*
* @since 4.8.0
*
* @return false|array false on failure; an array containing `location`
* and `events` items on success.
*/
public function get_cached_events() {
$cached_response = get_site_transient( $this->get_events_transient_key( $this->user_location ) );
$cached_response = $this->trim_events( $cached_response );
return $this->format_event_data_time( $cached_response );
}
/**
* Adds formatted date and time items for each event in an API response.
*
* This has to be called after the data is pulled from the cache, because
* the cached events are shared by all users. If it was called before storing
* the cache, then all users would see the events in the localized data/time
* of the user who triggered the cache refresh, rather than their own.
*
* @since 4.8.0
*
* @param array $response_body The response which contains the events.
* @return array The response with dates and times formatted.
*/
protected function format_event_data_time( $response_body ) {
if ( isset( $response_body['events'] ) ) {
foreach ( $response_body['events'] as $key => $event ) {
$timestamp = strtotime( $event['date'] );
/*
* The `date_format` option is not used because it's important
* in this context to keep the day of the week in the formatted date,
* so that users can tell at a glance if the event is on a day they
* are available, without having to open the link.
*/
/* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://secure.php.net/date. */
$response_body['events'][ $key ]['formatted_date'] = date_i18n( __( 'l, M j, Y' ), $timestamp );
$response_body['events'][ $key ]['formatted_time'] = date_i18n( get_option( 'time_format' ), $timestamp );
}
}
return $response_body;
}
/**
* Prepares the event list for presentation.
*
* Discards expired events, and makes WordCamps "sticky." Attendees need more
* advanced notice about WordCamps than they do for meetups, so camps should
* appear in the list sooner. If a WordCamp is coming up, the API will "stick"
* it in the response, even if it wouldn't otherwise appear. When that happens,
* the event will be at the end of the list, and will need to be moved into a
* higher position, so that it doesn't get trimmed off.
*
* @since 4.8.0
* @since 4.9.7 Stick a WordCamp to the final list.
*
* @param array $response_body The response body which contains the events.
* @return array The response body with events trimmed.
*/
protected function trim_events( $response_body ) {
if ( isset( $response_body['events'] ) ) {
$wordcamps = array();
$current_timestamp = current_time( 'timestamp' );
foreach ( $response_body['events'] as $key => $event ) {
/*
* Skip WordCamps, because they might be multi-day events.
* Save a copy so they can be pinned later.
*/
if ( 'wordcamp' === $event['type'] ) {
$wordcamps[] = $event;
continue;
}
$event_timestamp = strtotime( $event['date'] );
if ( $current_timestamp > $event_timestamp && ( $current_timestamp - $event_timestamp ) > DAY_IN_SECONDS ) {
unset( $response_body['events'][ $key ] );
}
}
$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 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] );
}
}
return $response_body;
}
/**
* Logs responses to Events API requests.
*
* @since 4.8.0
* @deprecated 4.9.0 Use a plugin instead. See #41217 for an example.
*
* @param string $message A description of what occurred.
* @param array $details Details that provide more context for the
* log entry.
*/
protected function maybe_log_events_response( $message, $details ) {
_deprecated_function( __METHOD__, '4.9.0' );
if ( ! WP_DEBUG_LOG ) {
return;
}
error_log(
sprintf(
'%s: %s. Details: %s',
__METHOD__,
trim( $message, '.' ),
wp_json_encode( $details )
)
);
}
}

View File

@ -0,0 +1,819 @@
<?php
/**
* Base WordPress Filesystem
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* Base WordPress Filesystem class for which Filesystem implementations extend
*
* @since 2.5.0
*/
class WP_Filesystem_Base {
/**
* Whether to display debug data for the connection.
*
* @since 2.5.0
* @var bool
*/
public $verbose = false;
/**
* Cached list of local filepaths to mapped remote filepaths.
*
* @since 2.7.0
* @var array
*/
public $cache = array();
/**
* The Access method of the current connection, Set automatically.
*
* @since 2.5.0
* @var string
*/
public $method = '';
/**
* @var WP_Error
*/
public $errors = null;
/**
*/
public $options = array();
/**
* Return the path on the remote filesystem of ABSPATH.
*
* @since 2.7.0
*
* @return string The location of the remote path.
*/
public function 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 ) ) {
$folder = '/';
}
return $folder;
}
/**
* Return the path on the remote filesystem of WP_CONTENT_DIR.
*
* @since 2.7.0
*
* @return string The location of the remote path.
*/
public function wp_content_dir() {
return $this->find_folder( WP_CONTENT_DIR );
}
/**
* Return the path on the remote filesystem of WP_PLUGIN_DIR.
*
* @since 2.7.0
*
* @return string The location of the remote path.
*/
public function wp_plugins_dir() {
return $this->find_folder( WP_PLUGIN_DIR );
}
/**
* Return the path on the remote filesystem of the Themes Directory.
*
* @since 2.7.0
*
* @param string $theme The Theme stylesheet or template for the directory.
* @return string The location of the remote path.
*/
public function wp_themes_dir( $theme = false ) {
$theme_root = get_theme_root( $theme );
// Account for relative theme roots
if ( '/themes' == $theme_root || ! is_dir( $theme_root ) ) {
$theme_root = WP_CONTENT_DIR . $theme_root;
}
return $this->find_folder( $theme_root );
}
/**
* Return the path on the remote filesystem of WP_LANG_DIR.
*
* @since 3.2.0
*
* @return string The location of the remote path.
*/
public function wp_lang_dir() {
return $this->find_folder( WP_LANG_DIR );
}
/**
* Locate a folder on the remote filesystem.
*
* @since 2.5.0
* @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() instead.
* @see WP_Filesystem::abspath()
* @see WP_Filesystem::wp_content_dir()
* @see WP_Filesystem::wp_plugins_dir()
* @see WP_Filesystem::wp_themes_dir()
* @see WP_Filesystem::wp_lang_dir()
*
* @param string $base The folder to start searching from.
* @param bool $echo True to display debug information.
* Default false.
* @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()' );
$this->verbose = $echo;
return $this->abspath();
}
/**
* Locate a folder on the remote filesystem.
*
* @since 2.5.0
* @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
* @see WP_Filesystem::abspath()
* @see WP_Filesystem::wp_content_dir()
* @see WP_Filesystem::wp_plugins_dir()
* @see WP_Filesystem::wp_themes_dir()
* @see WP_Filesystem::wp_lang_dir()
*
* @param string $base The folder to start searching from.
* @param bool $echo True to display debug information.
* @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()' );
$this->verbose = $echo;
return $this->abspath();
}
/**
* Locate a folder on the remote filesystem.
*
* Assumes that on Windows systems, Stripping off the Drive
* letter is OK Sanitizes \\ to / in windows filepaths.
*
* @since 2.7.0
*
* @param string $folder the folder to locate.
* @return string|false The location of the remote path, false on failure.
*/
public function find_folder( $folder ) {
if ( isset( $this->cache[ $folder ] ) ) {
return $this->cache[ $folder ];
}
if ( stripos( $this->method, 'ftp' ) !== false ) {
$constant_overrides = array(
'FTP_BASE' => ABSPATH,
'FTP_CONTENT_DIR' => WP_CONTENT_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 ) ) {
continue;
}
if ( $folder === $dir ) {
return trailingslashit( constant( $constant ) );
}
}
// Prefix Matches ( folder = CONSTANT/subdir )
foreach ( $constant_overrides as $constant => $dir ) {
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 );
if ( $this->is_dir( $potential_folder ) ) {
$this->cache[ $folder ] = $potential_folder;
return $potential_folder;
}
}
}
} elseif ( 'direct' == $this->method ) {
$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
if ( isset( $this->cache[ $folder ] ) ) {
return $this->cache[ $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 ) ) {
$this->cache[ $folder ] = $return;
}
return $return;
}
/**
* Locate a folder on the remote filesystem.
*
* Expects Windows sanitized path.
*
* @since 2.7.0
*
* @param string $folder The folder to locate.
* @param string $base The folder to start searching from.
* @param bool $loop If the function has recursed, Internal use only.
* @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() );
}
$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_part_keys = array_keys( $folder_parts );
$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 ) {
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
* the current folder, If it's found, change into it and follow through looking
* for it. If it cant find WordPress down that route, it'll continue onto the next
* 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 ] ) ) {
// Let's try that folder:
$newdir = trailingslashit( path_join( $base, $key ) );
if ( $this->verbose ) {
/* translators: %s: directory name */
printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir );
}
// 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 ) ) {
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 ( $this->verbose ) {
/* translators: %s: directory name */
printf( "\n" . __( 'Found %s' ) . "<br/>\n", $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 ) {
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/....
return $this->search_for_folder( $folder, '/', true );
}
/**
* Return the *nix-style file permissions for a file.
*
* From the PHP documentation page for fileperms().
*
* @link https://secure.php.net/manual/en/function.fileperms.php
*
* @since 2.5.0
*
* @param string $file String filename.
* @return string The *nix-style representation of permissions.
*/
public function gethchmod( $file ) {
$perms = intval( $this->getchmod( $file ), 8 );
if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket
$info = 's';
} elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link
$info = 'l';
} elseif ( ( $perms & 0x8000 ) == 0x8000 ) { // Regular
$info = '-';
} elseif ( ( $perms & 0x6000 ) == 0x6000 ) { // Block special
$info = 'b';
} elseif ( ( $perms & 0x4000 ) == 0x4000 ) { // Directory
$info = 'd';
} elseif ( ( $perms & 0x2000 ) == 0x2000 ) { // Character special
$info = 'c';
} elseif ( ( $perms & 0x1000 ) == 0x1000 ) { // FIFO pipe
$info = 'p';
} else { // Unknown
$info = 'u';
}
// Owner
$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' : '-' ) );
// World
$info .= ( ( $perms & 0x0004 ) ? 'r' : '-' );
$info .= ( ( $perms & 0x0002 ) ? 'w' : '-' );
$info .= ( ( $perms & 0x0001 ) ?
( ( $perms & 0x0200 ) ? 't' : 'x' ) :
( ( $perms & 0x0200 ) ? 'T' : '-' ) );
return $info;
}
/**
* Gets the permissions of the specified file or filepath in their octal format
*
* @since 2.5.0
* @param string $file
* @return string the last 3 characters of the octal number
*/
public function getchmod( $file ) {
return '777';
}
/**
* Convert *nix-style file permissions to a octal number.
*
* 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
*
* @param string $mode string The *nix-style file permission.
* @return int octal representation
*/
public function getnumchmodfromh( $mode ) {
$realmode = '';
$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 ];
}
}
$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[1] + $mode[2] + $mode[3];
$newmode .= $mode[4] + $mode[5] + $mode[6];
$newmode .= $mode[7] + $mode[8] + $mode[9];
return $newmode;
}
/**
* Determine if the string provided contains binary characters.
*
* @since 2.7.0
*
* @param string $text String to test against.
* @return bool true if string is binary, false otherwise.
*/
public function is_binary( $text ) {
return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
}
/**
* Change the ownership of a file / folder.
*
* Default behavior is to do nothing, override this in your subclass, if desired.
*
* @since 2.5.0
*
* @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 recursivly. Defaults to False.
* @return bool Returns true on success or false on failure.
*/
public function chown( $file, $owner, $recursive = false ) {
return false;
}
/**
* Connect filesystem.
*
* @since 2.5.0
* @abstract
*
* @return bool True on success or false on failure (always true for WP_Filesystem_Direct).
*/
public function connect() {
return true;
}
/**
* Read entire file into a string.
*
* @since 2.5.0
* @abstract
*
* @param string $file Name of the file to read.
* @return mixed|bool Returns the read data or false on failure.
*/
public function get_contents( $file ) {
return false;
}
/**
* Read entire file into an array.
*
* @since 2.5.0
* @abstract
*
* @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 false;
}
/**
* Write a string to a file.
*
* @since 2.5.0
* @abstract
*
* @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.
* @return bool False on failure.
*/
public function put_contents( $file, $contents, $mode = false ) {
return false;
}
/**
* Get the current working directory.
*
* @since 2.5.0
* @abstract
*
* @return string|bool The current working directory on success, or false on failure.
*/
public function cwd() {
return false;
}
/**
* Change current directory.
*
* @since 2.5.0
* @abstract
*
* @param string $dir The new current directory.
* @return bool|string
*/
public function chdir( $dir ) {
return false;
}
/**
* Change the file group.
*
* @since 2.5.0
* @abstract
*
* @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. Defaults to False.
* @return bool|string
*/
public function chgrp( $file, $group, $recursive = false ) {
return false;
}
/**
* Change filesystem permissions.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to the file.
* @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
* @param bool $recursive Optional. If set True changes file group recursively. Defaults to False.
* @return bool|string
*/
public function chmod( $file, $mode = false, $recursive = false ) {
return false;
}
/**
* Get the file owner.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to the file.
* @return string|bool Username of the user or false on error.
*/
public function owner( $file ) {
return false;
}
/**
* Get the file's group.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to the file.
* @return string|bool The group or false on error.
*/
public function group( $file ) {
return false;
}
/**
* Copy a file.
*
* @since 2.5.0
* @abstract
*
* @param string $source Path to the source file.
* @param string $destination Path to the destination file.
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists.
* Default false.
* @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs.
* Default false.
* @return bool True if file copied successfully, False otherwise.
*/
public function copy( $source, $destination, $overwrite = false, $mode = false ) {
return false;
}
/**
* Move a file.
*
* @since 2.5.0
* @abstract
*
* @param string $source Path to the source file.
* @param string $destination Path to the destination file.
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists.
* Default false.
* @return bool True if file copied successfully, False otherwise.
*/
public function move( $source, $destination, $overwrite = false ) {
return false;
}
/**
* Delete a file or directory.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to the file.
* @param bool $recursive Optional. If set True changes file group recursively. Defaults to False.
* Default false.
* @param bool $type Type of resource. 'f' for file, 'd' for directory.
* Default false.
* @return bool True if the file or directory was deleted, false on failure.
*/
public function delete( $file, $recursive = false, $type = false ) {
return false;
}
/**
* Check if a file or directory exists.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to file/directory.
* @return bool Whether $file exists or not.
*/
public function exists( $file ) {
return false;
}
/**
* Check if resource is a file.
*
* @since 2.5.0
* @abstract
*
* @param string $file File path.
* @return bool Whether $file is a file.
*/
public function is_file( $file ) {
return false;
}
/**
* Check if resource is a directory.
*
* @since 2.5.0
* @abstract
*
* @param string $path Directory path.
* @return bool Whether $path is a directory.
*/
public function is_dir( $path ) {
return false;
}
/**
* Check if a file is readable.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to file.
* @return bool Whether $file is readable.
*/
public function is_readable( $file ) {
return false;
}
/**
* Check if a file or directory is writable.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to file.
* @return bool Whether $file is writable.
*/
public function is_writable( $file ) {
return false;
}
/**
* Gets the file's last access time.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to file.
* @return int|bool Unix timestamp representing last access time.
*/
public function atime( $file ) {
return false;
}
/**
* Gets the file modification time.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to file.
* @return int|bool Unix timestamp representing modification time.
*/
public function mtime( $file ) {
return false;
}
/**
* Gets the file size (in bytes).
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to file.
* @return int|bool Size of the file in bytes.
*/
public function size( $file ) {
return false;
}
/**
* Set the access and modification times of a file.
*
* Note: If $file doesn't exist, it will be created.
*
* @since 2.5.0
* @abstract
*
* @param string $file Path to file.
* @param int $time Optional. Modified time to set for file.
* Default 0.
* @param int $atime Optional. Access time to set for file.
* Default 0.
* @return bool Whether operation was successful or not.
*/
public function touch( $file, $time = 0, $atime = 0 ) {
return false;
}
/**
* Create a directory.
*
* @since 2.5.0
* @abstract
*
* @param string $path Path for new directory.
* @param mixed $chmod Optional. The permissions as octal number, (or False to skip chmod)
* Default false.
* @param mixed $chown Optional. A user name or number (or False to skip chown)
* Default false.
* @param mixed $chgrp Optional. A group name or number (or False to skip chgrp).
* Default false.
* @return bool False if directory cannot be created, true otherwise.
*/
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
return false;
}
/**
* Delete a directory.
*
* @since 2.5.0
* @abstract
*
* @param string $path Path to directory.
* @param bool $recursive Optional. Whether to recursively remove files/directories.
* Default false.
* @return bool Whether directory is deleted successfully or not.
*/
public function rmdir( $path, $recursive = false ) {
return false;
}
/**
* Get details for files in a directory or a specific file.
*
* @since 2.5.0
* @abstract
*
* @param string $path Path to directory or file.
* @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
* Default true.
* @param bool $recursive Optional. Whether to recursively include file details in nested directories.
* Default false.
* @return array|bool {
* Array of files. False if unable to list directory contents.
*
* @type string $name Name of the file/directory.
* @type string $perms *nix representation of permissions.
* @type int $permsn Octal representation of permissions.
* @type string $owner Owner name or ID.
* @type int $size Size of file in bytes.
* @type int $lastmodunix Last modified unix timestamp.
* @type mixed $lastmod Last modified month (3 letter) and day (without leading 0).
* @type int $time Last modified time.
* @type string $type Type of resource. 'f' for file, 'd' for directory.
* @type mixed $files If a directory and $recursive is true, contains another array of files.
* }
*/
public function dirlist( $path, $include_hidden = true, $recursive = false ) {
return false;
}
} // WP_Filesystem_Base

View File

@ -0,0 +1,500 @@
<?php
/**
* WordPress Direct Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* WordPress Filesystem Class for direct PHP file and folder manipulation.
*
* @since 2.5.0
*
* @see WP_Filesystem_Base
*/
class WP_Filesystem_Direct extends WP_Filesystem_Base {
/**
* constructor
*
* @param mixed $arg ignored argument
*/
public function __construct( $arg ) {
$this->method = 'direct';
$this->errors = new WP_Error();
}
/**
* 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 );
}
/**
* 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 );
}
/**
* 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.
* Default false.
* @return bool False upon failure, true otherwise.
*/
public function put_contents( $file, $contents, $mode = false ) {
$fp = @fopen( $file, 'wb' );
if ( ! $fp ) {
return false;
}
mbstring_binary_safe_encoding();
$data_length = strlen( $contents );
$bytes_written = fwrite( $fp, $contents );
reset_mbstring_encoding();
fclose( $fp );
if ( $data_length !== $bytes_written ) {
return false;
}
$this->chmod( $file, $mode );
return true;
}
/**
* Gets the current working directory
*
* @return string|bool the current working directory on success, or false on failure.
*/
public function cwd() {
return @getcwd();
}
/**
* 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 );
}
/**
* 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 ) ) {
return false;
}
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 );
}
return true;
}
/**
* 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 ) {
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 @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 );
}
return true;
}
/**
* 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 ) ) {
return false;
}
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 );
}
return true;
}
/**
* 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 ) {
return false;
}
if ( ! function_exists( 'posix_getpwuid' ) ) {
return $owneruid;
}
$ownerarray = posix_getpwuid( $owneruid );
return $ownerarray['name'];
}
/**
* Gets file permissions
*
* 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 ) {
return substr( decoct( @fileperms( $file ) ), -3 );
}
/**
* @param string $file
* @return string|false
*/
public function group( $file ) {
$gid = @filegroup( $file );
if ( ! $gid ) {
return false;
}
if ( ! function_exists( 'posix_getgrgid' ) ) {
return $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 ) ) {
return false;
}
$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 ) ) {
return false;
}
// Try using rename first. if that fails (for example, source is read only) try copy.
if ( @rename( $source, $destination ) ) {
return true;
}
if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) {
$this->delete( $source );
return true;
} else {
return false;
}
}
/**
* @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.
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 );
}
// At this point it's a folder, and we're in recursive mode
$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'] ) ) {
$retval = false;
}
}
}
if ( file_exists( $file ) && ! @rmdir( $file ) ) {
$retval = false;
}
return $retval;
}
/**
* @param string $file
* @return bool
*/
public function exists( $file ) {
return @file_exists( $file );
}
/**
* @param string $file
* @return bool
*/
public function is_file( $file ) {
return @is_file( $file );
}
/**
* @param string $path
* @return bool
*/
public function is_dir( $path ) {
return @is_dir( $path );
}
/**
* @param string $file
* @return bool
*/
public function is_readable( $file ) {
return @is_readable( $file );
}
/**
* @param string $file
* @return bool
*/
public function is_writable( $file ) {
return @is_writable( $file );
}
/**
* @param string $file
* @return int
*/
public function atime( $file ) {
return @fileatime( $file );
}
/**
* @param string $file
* @return int
*/
public function mtime( $file ) {
return @filemtime( $file );
}
/**
* @param string $file
* @return int
*/
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 ) {
$time = time();
}
if ( $atime == 0 ) {
$atime = time();
}
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 ) {
// Safe mode fails with a trailing slash under certain PHP versions.
$path = untrailingslashit( $path );
if ( empty( $path ) ) {
return false;
}
if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR;
}
if ( ! @mkdir( $path ) ) {
return false;
}
$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 );
}
/**
* @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 );
} else {
$limit_file = false;
}
if ( ! $this->is_dir( $path ) ) {
return false;
}
$dir = @dir( $path );
if ( ! $dir ) {
return false;
}
$ret = array();
while ( false !== ( $entry = $dir->read() ) ) {
$struc = array();
$struc['name'] = $entry;
if ( '.' == $struc['name'] || '..' == $struc['name'] ) {
continue;
}
if ( ! $include_hidden && '.' == $struc['name'][0] ) {
continue;
}
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';
if ( 'd' == $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
$ret[ $struc['name'] ] = $struc;
}
$dir->close();
unset( $dir );
return $ret;
}
}

View File

@ -0,0 +1,594 @@
<?php
/**
* WordPress FTP Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* WordPress Filesystem Class for implementing FTP.
*
* @since 2.5.0
*
* @see WP_Filesystem_Base
*/
class WP_Filesystem_FTPext extends WP_Filesystem_Base {
public $link;
/**
* @param array $opt
*/
public function __construct( $opt = '' ) {
$this->method = 'ftpext';
$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' ) );
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 ( empty( $opt['port'] ) ) {
$this->options['port'] = 21;
} else {
$this->options['port'] = $opt['port'];
}
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 {
$this->options['username'] = $opt['username'];
}
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'] ) {
$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 ( ! $this->link ) {
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
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',
/* translators: %s: username */
sprintf(
__( 'Username/Password incorrect for %s' ),
$this->options['username']
)
);
return false;
}
// 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 );
}
return true;
}
/**
* Retrieves the file contents.
*
* @since 2.5.0
*
* @param string $file Filename.
* @return string|false File contents on success, false if no temp file could be opened,
* or if the file couldn't be retrieved.
*/
public function get_contents( $file ) {
$tempfile = wp_tempnam( $file );
$temp = fopen( $tempfile, 'w+' );
if ( ! $temp ) {
unlink( $tempfile );
return false;
}
if ( ! @ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) {
fclose( $temp );
unlink( $tempfile );
return false;
}
fseek( $temp, 0 ); // Skip back to the start of the file being written to
$contents = '';
while ( ! feof( $temp ) ) {
$contents .= fread( $temp, 8192 );
}
fclose( $temp );
unlink( $tempfile );
return $contents;
}
/**
* @param string $file
* @return array
*/
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+' );
if ( ! $temp ) {
unlink( $tempfile );
return false;
}
mbstring_binary_safe_encoding();
$data_length = strlen( $contents );
$bytes_written = fwrite( $temp, $contents );
reset_mbstring_encoding();
if ( $data_length !== $bytes_written ) {
fclose( $temp );
unlink( $tempfile );
return false;
}
fseek( $temp, 0 ); // Skip back to the start of the file being written to
$ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY );
fclose( $temp );
unlink( $tempfile );
$this->chmod( $file, $mode );
return $ret;
}
/**
* @return string
*/
public function 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 );
}
/**
* @param string $file
* @param int $mode
* @param bool $recursive
* @return bool
*/
public function chmod( $file, $mode = false, $recursive = false ) {
if ( ! $mode ) {
if ( $this->is_file( $file ) ) {
$mode = FS_CHMOD_FILE;
} elseif ( $this->is_dir( $file ) ) {
$mode = FS_CHMOD_DIR;
} 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 );
}
}
// 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 );
}
/**
* @param string $file
* @return string
*/
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'];
}
/**
* @param string $file
* @return string
*/
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 ) ) {
return false;
}
$content = $this->get_contents( $source );
if ( false === $content ) {
return false;
}
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 );
}
/**
* @param string $file
* @param bool $recursive
* @param string $type
* @return bool
*/
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 );
}
$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 );
if ( empty( $list ) && $this->is_dir( $file ) ) {
return true; // File is an empty directory.
}
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 );
}
/**
* @param string $path
* @return bool
*/
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 );
return true;
}
return false;
}
/**
* @param string $file
* @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 ) {
return false;
}
/**
* @param string $file
* @return int
*/
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 );
}
/**
* @param string $file
* @return bool
*/
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 ) ) {
return false;
}
if ( ! @ftp_mkdir( $this->link, $path ) ) {
return false;
}
$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 );
}
/**
* @staticvar bool $is_windows
* @param string $line
* @return array
*/
public function parselisting( $line ) {
static $is_windows = null;
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 ) ) {
$b = array();
if ( $lucifer[3] < 70 ) {
$lucifer[3] += 2000;
} else {
$lucifer[3] += 1900; // 4digit year fix
}
$b['isdir'] = ( $lucifer[7] == '<DIR>' );
if ( $b['isdir'] ) {
$b['type'] = 'd';
} 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['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 ) ) {
//echo $line."\n";
$lcount = count( $lucifer );
if ( $lcount < 8 ) {
return '';
}
$b = array();
$b['isdir'] = $lucifer[0]{0} === 'd';
$b['islink'] = $lucifer[0]{0} === 'l';
if ( $b['isdir'] ) {
$b['type'] = 'd';
} elseif ( $b['islink'] ) {
$b['type'] = 'l';
} else {
$b['type'] = 'f';
}
$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];
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'] );
$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['minute'] = $l2[2];
} else {
$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['name'] = $lucifer[8];
}
}
// Replace symlinks formatted as "source -> target" with just the source name
if ( isset( $b['islink'] ) && $b['islink'] ) {
$b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
}
return $b;
}
/**
* @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 ) . '/';
} else {
$limit_file = false;
}
$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 );
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 ) ) {
continue;
}
if ( '.' == $entry['name'] || '..' == $entry['name'] ) {
continue;
}
if ( ! $include_hidden && '.' == $entry['name'][0] ) {
continue;
}
if ( $limit_file && $entry['name'] != $limit_file ) {
continue;
}
$dirlist[ $entry['name'] ] = $entry;
}
$ret = array();
foreach ( (array) $dirlist as $struc ) {
if ( 'd' == $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
$ret[ $struc['name'] ] = $struc;
}
return $ret;
}
/**
*/
public function __destruct() {
if ( $this->link ) {
ftp_close( $this->link );
}
}
}

View File

@ -0,0 +1,524 @@
<?php
/**
* WordPress FTP Sockets Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* WordPress Filesystem Class for implementing FTP Sockets.
*
* @since 2.5.0
*
* @see WP_Filesystem_Base
*/
class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
/**
* @var ftp
*/
public $ftp;
/**
* @param array $opt
*/
public function __construct( $opt = '' ) {
$this->method = 'ftpsockets';
$this->errors = new WP_Error();
// Check if possible to use ftp functions.
if ( ! @include_once( ABSPATH . 'wp-admin/includes/class-ftp.php' ) ) {
return;
}
$this->ftp = new ftp();
if ( empty( $opt['port'] ) ) {
$this->options['port'] = 21;
} else {
$this->options['port'] = (int) $opt['port'];
}
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 {
$this->options['username'] = $opt['username'];
}
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 ) {
return false;
}
$this->ftp->setTimeout( FS_CONNECT_TIMEOUT );
if ( ! $this->ftp->SetServer( $this->options['hostname'], $this->options['port'] ) ) {
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf(
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
if ( ! $this->ftp->connect() ) {
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf(
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
if ( ! $this->ftp->login( $this->options['username'], $this->options['password'] ) ) {
$this->errors->add(
'auth',
/* translators: %s: username */
sprintf(
__( 'Username/Password incorrect for %s' ),
$this->options['username']
)
);
return false;
}
$this->ftp->SetType( FTP_BINARY );
$this->ftp->Passive( true );
$this->ftp->setTimeout( FS_TIMEOUT );
return true;
}
/**
* Retrieves the file contents.
*
* @since 2.5.0
*
* @param string $file Filename.
* @return string|false File contents on success, false if no temp file could be opened,
* or if the file doesn't exist.
*/
public function get_contents( $file ) {
if ( ! $this->exists( $file ) ) {
return false;
}
$temp = wp_tempnam( $file );
if ( ! $temphandle = fopen( $temp, 'w+' ) ) {
unlink( $temp );
return false;
}
mbstring_binary_safe_encoding();
if ( ! $this->ftp->fget( $temphandle, $file ) ) {
fclose( $temphandle );
unlink( $temp );
reset_mbstring_encoding();
return ''; // Blank document, File does exist, It's just blank.
}
reset_mbstring_encoding();
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
$contents = '';
while ( ! feof( $temphandle ) ) {
$contents .= fread( $temphandle, 8192 );
}
fclose( $temphandle );
unlink( $temp );
return $contents;
}
/**
* @param string $file
* @return array
*/
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 ) {
$temp = wp_tempnam( $file );
if ( ! $temphandle = @fopen( $temp, 'w+' ) ) {
unlink( $temp );
return false;
}
// The FTP class uses string functions internally during file download/upload
mbstring_binary_safe_encoding();
$bytes_written = fwrite( $temphandle, $contents );
if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) {
fclose( $temphandle );
unlink( $temp );
reset_mbstring_encoding();
return false;
}
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
$ret = $this->ftp->fput( $file, $temphandle );
reset_mbstring_encoding();
fclose( $temphandle );
unlink( $temp );
$this->chmod( $file, $mode );
return $ret;
}
/**
* @return string
*/
public function cwd() {
$cwd = $this->ftp->pwd();
if ( $cwd ) {
$cwd = trailingslashit( $cwd );
}
return $cwd;
}
/**
* @param string $file
* @return bool
*/
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 ) {
if ( ! $mode ) {
if ( $this->is_file( $file ) ) {
$mode = FS_CHMOD_FILE;
} elseif ( $this->is_dir( $file ) ) {
$mode = FS_CHMOD_DIR;
} 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 );
}
}
// chmod the file or directory
return $this->ftp->chmod( $file, $mode );
}
/**
* @param string $file
* @return string
*/
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'];
}
/**
* @param string $file
* @return string
*/
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 ) ) {
return false;
}
$content = $this->get_contents( $source );
if ( false === $content ) {
return false;
}
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 );
}
/**
* @param string $file
* @param bool $recursive
* @param string $type
* @return bool
*/
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 );
}
return $this->ftp->mdel( $file );
}
/**
* @param string $file
* @return bool
*/
public function exists( $file ) {
$list = $this->ftp->nlist( $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 $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 ) ) {
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 );
return true;
}
return false;
}
/**
* @param string $file
* @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 ) {
return false;
}
/**
* @param string $file
* @return int
*/
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 ) {
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 ) ) {
return false;
}
if ( ! $this->ftp->mkdir( $path ) ) {
return false;
}
if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR;
}
$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 );
}
/**
* @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 ) . '/';
} else {
$limit_file = false;
}
mbstring_binary_safe_encoding();
$list = $this->ftp->dirlist( $path );
if ( empty( $list ) && ! $this->exists( $path ) ) {
reset_mbstring_encoding();
return false;
}
$ret = array();
foreach ( $list as $struc ) {
if ( '.' == $struc['name'] || '..' == $struc['name'] ) {
continue;
}
if ( ! $include_hidden && '.' == $struc['name'][0] ) {
continue;
}
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 {
$struc['files'] = array();
}
}
// Replace symlinks formatted as "source -> target" with just the source name
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'] );
$ret[ $struc['name'] ] = $struc;
}
reset_mbstring_encoding();
return $ret;
}
/**
*/
public function __destruct() {
$this->ftp->quit();
}
}

View File

@ -0,0 +1,612 @@
<?php
/**
* WordPress Filesystem Class for implementing SSH2
*
* To use this class you must follow these steps for PHP 5.2.6+
*
* @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes
*
* Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now, But many users have found the latest versions work)
*
* cd /usr/src
* wget http://surfnet.dl.sourceforge.net/sourceforge/libssh2/libssh2-0.14.tar.gz
* tar -zxvf libssh2-0.14.tar.gz
* cd libssh2-0.14/
* ./configure
* make all install
*
* Note: Do not leave the directory yet!
*
* Enter: pecl install -f ssh2
*
* Copy the ssh.so file it creates to your PHP Module Directory.
* Open up your PHP.INI file and look for where extensions are placed.
* Add in your PHP.ini file: extension=ssh2.so
*
* Restart Apache!
* Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp exist.
*
* Note: as of WordPress 2.8, This utilises the PHP5+ function 'stream_get_contents'
*
* @since 2.7.0
*
* @package WordPress
* @subpackage Filesystem
*/
class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
/**
*/
public $link = false;
/**
* @var resource
*/
public $sftp_link;
public $keys = false;
/**
* @param array $opt
*/
public function __construct( $opt = '' ) {
$this->method = 'ssh2';
$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' ) );
return;
}
if ( ! function_exists( 'stream_get_contents' ) ) {
$this->errors->add(
'ssh2_php_requirement',
sprintf(
/* translators: %s: stream_get_contents() */
__( 'The ssh2 PHP extension is available, however, we require the PHP5 function %s' ),
'<code>stream_get_contents()</code>'
)
);
return;
}
// Set defaults:
if ( empty( $opt['port'] ) ) {
$this->options['port'] = 22;
} 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['password'] ) ) {
// Password can be blank if we are using keys.
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'] );
} else {
$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] );
}
if ( ! $this->link ) {
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
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',
/* translators: %s: username */
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',
/* translators: %s: username */
sprintf(
__( 'Public and Private keys incorrect for %s' ),
$this->options['username']
)
);
return false;
}
}
$this->sftp_link = ssh2_sftp( $this->link );
if ( ! $this->sftp_link ) {
$this->errors->add(
'connect',
/* translators: %s: hostname:port */
sprintf(
__( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
return true;
}
/**
* Gets the ssh2.sftp PHP stream wrapper path to open for the given file.
*
* This method also works around a PHP bug where the root directory (/) cannot
* be opened by PHP functions, causing a false failure. In order to work around
* 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
* @return string The ssh2.sftp:// wrapped path to use.
*/
public function sftp_path( $path ) {
if ( '/' === $path ) {
$path = '/./';
}
return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
}
/**
* @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 ) {
return false;
}
if ( ! ( $stream = ssh2_exec( $this->link, $command ) ) ) {
$this->errors->add(
'command',
/* translators: %s: command */
sprintf(
__( 'Unable to perform command: %s' ),
$command
)
);
} else {
stream_set_blocking( $stream, true );
stream_set_timeout( $stream, FS_TIMEOUT );
$data = stream_get_contents( $stream );
fclose( $stream );
if ( $returnbool ) {
return ( $data === false ) ? false : '' != trim( $data );
} else {
return $data;
}
}
return false;
}
/**
* @param string $file
* @return string|false
*/
public function get_contents( $file ) {
return file_get_contents( $this->sftp_path( $file ) );
}
/**
* @param string $file
* @return array
*/
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 ) {
$ret = file_put_contents( $this->sftp_path( $file ), $contents );
if ( $ret !== strlen( $contents ) ) {
return false;
}
$this->chmod( $file, $mode );
return true;
}
/**
* @return bool
*/
public function cwd() {
$cwd = ssh2_sftp_realpath( $this->sftp_link, '.' );
if ( $cwd ) {
$cwd = trailingslashit( trim( $cwd ) );
}
return $cwd;
}
/**
* @param string $dir
* @return bool|string
*/
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 ) ) {
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 );
}
/**
* @param string $file
* @param int $mode
* @param bool $recursive
* @return bool|string
*/
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 );
}
/**
* 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 ) ) {
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 );
}
/**
* @param string $file
* @return string|false
*/
public function owner( $file ) {
$owneruid = @fileowner( $this->sftp_path( $file ) );
if ( ! $owneruid ) {
return false;
}
if ( ! function_exists( 'posix_getpwuid' ) ) {
return $owneruid;
}
$ownerarray = posix_getpwuid( $owneruid );
return $ownerarray['name'];
}
/**
* @param string $file
* @return string
*/
public function getchmod( $file ) {
return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 );
}
/**
* @param string $file
* @return string|false
*/
public function group( $file ) {
$gid = @filegroup( $this->sftp_path( $file ) );
if ( ! $gid ) {
return false;
}
if ( ! function_exists( 'posix_getgrgid' ) ) {
return $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 ) ) {
return false;
}
$content = $this->get_contents( $source );
if ( false === $content ) {
return false;
}
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 @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'] );
}
}
return ssh2_sftp_rmdir( $this->sftp_link, $file );
}
/**
* @param string $file
* @return bool
*/
public function exists( $file ) {
return file_exists( $this->sftp_path( $file ) );
}
/**
* @param string $file
* @return bool
*/
public function is_file( $file ) {
return is_file( $this->sftp_path( $file ) );
}
/**
* @param string $path
* @return bool
*/
public function is_dir( $path ) {
return is_dir( $this->sftp_path( $path ) );
}
/**
* @param string $file
* @return bool
*/
public function is_readable( $file ) {
return is_readable( $this->sftp_path( $file ) );
}
/**
* @param string $file
* @return bool
*/
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 ) {
return fileatime( $this->sftp_path( $file ) );
}
/**
* @param string $file
* @return int
*/
public function mtime( $file ) {
return filemtime( $this->sftp_path( $file ) );
}
/**
* @param string $file
* @return int
*/
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 ) {
//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 ) ) {
return false;
}
if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR;
}
if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) {
return false;
}
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 );
}
/**
* @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 );
} else {
$limit_file = false;
}
if ( ! $this->is_dir( $path ) ) {
return false;
}
$ret = array();
$dir = @dir( $this->sftp_path( $path ) );
if ( ! $dir ) {
return false;
}
while ( false !== ( $entry = $dir->read() ) ) {
$struc = array();
$struc['name'] = $entry;
if ( '.' == $struc['name'] || '..' == $struc['name'] ) {
continue; //Do not care about these folders.
}
if ( ! $include_hidden && '.' == $struc['name'][0] ) {
continue;
}
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';
if ( 'd' == $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
$ret[ $struc['name'] ] = $struc;
}
$dir->close();
unset( $dir );
return $ret;
}
}

View File

@ -0,0 +1,333 @@
<?php
/**
* WP_Importer base class
*/
class WP_Importer {
/**
* Class Constructor
*/
public function __construct() {}
/**
* Returns array with imported permalinks from WordPress database
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $importer_name
* @param string $bid
* @return array
*/
public function get_imported_posts( $importer_name, $bid ) {
global $wpdb;
$hashtable = array();
$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 );
// Increment offset
$offset = ( $limit + $offset );
if ( ! empty( $results ) ) {
foreach ( $results as $r ) {
// Set permalinks into array
$hashtable[ $r->meta_value ] = intval( $r->post_id );
}
}
} while ( count( $results ) == $limit );
// Unset to save memory.
unset( $results, $r );
return $hashtable;
}
/**
* Return count of imported permalinks from WordPress database
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $importer_name
* @param string $bid
* @return int
*/
public function count_imported_posts( $importer_name, $bid ) {
global $wpdb;
$count = 0;
// 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 );
$result = $wpdb->get_results( $sql );
if ( ! empty( $result ) ) {
$count = intval( $result[0]->cnt );
}
// Unset to save memory.
unset( $results );
return $count;
}
/**
* Set array with imported comments from WordPress database
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $bid
* @return array
*/
public function get_imported_comments( $bid ) {
global $wpdb;
$hashtable = array();
$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 );
$results = $wpdb->get_results( $sql );
// Increment offset
$offset = ( $limit + $offset );
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 );
// Check if this comment came from this blog
if ( $bid == $ca_bid ) {
$hashtable[ $source_comment_id ] = intval( $r->comment_ID );
}
}
}
} while ( count( $results ) == $limit );
// Unset to save memory.
unset( $results, $r );
return $hashtable;
}
/**
* @param int $blog_id
* @return int|void
*/
public function set_blog( $blog_id ) {
if ( is_numeric( $blog_id ) ) {
$blog_id = (int) $blog_id;
} else {
$blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
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'],
)
);
if ( ! $blogs ) {
fwrite( STDERR, "Error: Could not find blog\n" );
exit();
}
$blog = array_shift( $blogs );
$blog_id = (int) $blog->blog_id;
}
if ( function_exists( 'is_multisite' ) ) {
if ( is_multisite() ) {
switch_to_blog( $blog_id );
}
}
return $blog_id;
}
/**
* @param int $user_id
* @return int|void
*/
public function set_user( $user_id ) {
if ( is_numeric( $user_id ) ) {
$user_id = (int) $user_id;
} else {
$user_id = (int) username_exists( $user_id );
}
if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
fwrite( STDERR, "Error: can not find user\n" );
exit();
}
return $user_id;
}
/**
* Sort by strlen, longest string first
*
* @param string $a
* @param string $b
* @return int
*/
public function cmpr_strlen( $a, $b ) {
return strlen( $b ) - strlen( $a );
}
/**
* GET URL
*
* @param string $url
* @param string $username
* @param string $password
* @param bool $head
* @return array
*/
public function get_page( $url, $username = '', $password = '', $head = false ) {
// Increase the timeout
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
$headers = array();
$args = array();
if ( true === $head ) {
$args['method'] = 'HEAD';
}
if ( ! empty( $username ) && ! empty( $password ) ) {
$headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" );
}
$args['headers'] = $headers;
return wp_safe_remote_request( $url, $args );
}
/**
* Bump up the request timeout for http requests
*
* @param int $val
* @return int
*/
public function bump_request_timeout( $val ) {
return 60;
}
/**
* Check if user has exceeded disk quota
*
* @return bool
*/
public function is_user_over_quota() {
if ( function_exists( 'upload_is_user_over_quota' ) ) {
if ( upload_is_user_over_quota() ) {
return true;
}
}
return false;
}
/**
* Replace newlines, tabs, and multiple spaces with a single space
*
* @param string $string
* @return string
*/
public function min_whitespace( $string ) {
return preg_replace( '|[\r\n\t ]+|', ' ', $string );
}
/**
* Resets global variables that grow out of control during imports.
*
* @since 3.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global array $wp_actions
*/
public function stop_the_insanity() {
global $wpdb, $wp_actions;
// Or define( 'WP_IMPORTING', true );
$wpdb->queries = array();
// Reset $wp_actions to keep it from growing out of control
$wp_actions = array();
}
}
/**
* Returns value of command line params.
* Exits when a required param is not set.
*
* @param string $param
* @param bool $required
* @return mixed
*/
function get_cli_args( $param, $required = false ) {
$args = $_SERVER['argv'];
if ( ! is_array( $args ) ) {
$args = array();
}
$out = array();
$last_arg = 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 ( isset( $parts[1] ) ) {
$out[ $key ] = $parts[1];
} else {
$out[ $key ] = true;
}
$last_arg = $key;
} 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;
}
$last_arg = $key;
} elseif ( $last_arg !== null ) {
$out[ $last_arg ] = $args[ $i ];
}
}
// Check array for specified param
if ( isset( $out[ $param ] ) ) {
// Set return value
$return = $out[ $param ];
}
// Check for missing required param
if ( ! isset( $out[ $param ] ) && $required ) {
// Display message and exit
echo "\"$param\" parameter is required but was not specified\n";
exit();
}
return $return;
}

View File

@ -0,0 +1,201 @@
<?php
/**
* Administration API: WP_Internal_Pointers class
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Core class used to implement an internal admin pointers API.
*
* @since 3.3.0
*/
final class WP_Internal_Pointers {
/**
* Initializes the new feature pointers.
*
* @since 3.3.0
*
* All pointers can be disabled using the following:
* remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
*
* 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' ) );
*
* @param string $hook_suffix The current admin page.
*/
public static function enqueue_scripts( $hook_suffix ) {
/*
* Register feature pointers
*
* Format:
* array(
* hook_suffix => pointer callback
* )
*
* Example:
* array(
* 'themes.php' => 'wp390_widgets'
* )
*/
$registered_pointers = array(
'index.php' => 'wp496_privacy',
);
// Check if screen related pointer is registered
if ( empty( $registered_pointers[ $hook_suffix ] ) ) {
return;
}
$pointers = (array) $registered_pointers[ $hook_suffix ];
/*
* Specify required capabilities for feature pointers
*
* Format:
* array(
* pointer callback => Array of required capabilities
* )
*
* Example:
* array(
* 'wp390_widgets' => array( 'edit_theme_options' )
* )
*/
$caps_required = array(
'wp496_privacy' => array(
'manage_privacy_options',
'export_others_personal_data',
'erase_others_personal_data',
),
);
// Get dismissed pointers
$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
$got_pointers = false;
foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
if ( isset( $caps_required[ $pointer ] ) ) {
foreach ( $caps_required[ $pointer ] as $cap ) {
if ( ! current_user_can( $cap ) ) {
continue 2;
}
}
}
// Bind pointer print function
add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
$got_pointers = true;
}
if ( ! $got_pointers ) {
return;
}
// Add pointers script and style to queue
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );
}
/**
* Print the pointer JavaScript data.
*
* @since 3.3.0
*
* @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'] ) ) {
return;
}
?>
<script type="text/javascript">
(function($){
var options = <?php echo wp_json_encode( $args ); ?>, setup;
if ( ! options )
return;
options = $.extend( options, {
close: function() {
$.post( ajaxurl, {
pointer: '<?php echo $pointer_id; ?>',
action: 'dismiss-wp-pointer'
});
}
});
setup = function() {
$('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
};
if ( options.position && options.position.defer_loading )
$(window).bind( 'load.wp-pointers', setup );
else
$(document).ready( setup );
})( jQuery );
</script>
<?php
}
public static function pointer_wp330_toolbar() {}
public static function pointer_wp330_media_uploader() {}
public static function pointer_wp330_saving_widgets() {}
public static function pointer_wp340_customize_current_theme_link() {}
public static function pointer_wp340_choose_image_from_library() {}
public static function pointer_wp350_media() {}
public static function pointer_wp360_revisions() {}
public static function pointer_wp360_locks() {}
public static function pointer_wp390_widgets() {}
public static function pointer_wp410_dfw() {}
/**
* Display a pointer for the new privacy tools.
*
* @since 4.9.6
*/
public static function pointer_wp496_privacy() {
$content = '<h3>' . __( 'Personal Data and Privacy' ) . '</h3>';
$content .= '<h4>' . __( 'Personal Data Export and Erasure' ) . '</h4>';
$content .= '<p>' . __( 'New <strong>Tools</strong> have been added to help you with personal data export and erasure requests.' ) . '</p>';
$content .= '<h4>' . __( 'Privacy Policy' ) . '</h4>';
$content .= '<p>' . __( 'Create or select your site&#8217;s privacy policy page under <strong>Settings &gt; Privacy</strong> to keep your users informed and aware.' ) . '</p>';
if ( is_rtl() ) {
$position = array(
'edge' => 'right',
'align' => 'bottom',
);
} else {
$position = array(
'edge' => 'left',
'align' => 'bottom',
);
}
$js_args = array(
'content' => $content,
'position' => $position,
'pointerClass' => 'wp-pointer arrow-bottom',
'pointerWidth' => 420,
);
self::print_js( 'wp496_privacy', '#menu-tools', $js_args );
}
/**
* Prevents new users from seeing existing 'new feature' pointers.
*
* @since 3.3.0
*
* @param int $user_id User ID.
*/
public static function dismiss_pointers_for_new_users( $user_id ) {
add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp496_privacy' );
}
}

View File

@ -0,0 +1,326 @@
<?php
/**
* List Table API: WP_Links_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying links in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Tsble
*/
class WP_Links_List_Table extends WP_List_Table {
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
parent::__construct(
array(
'plural' => 'bookmarks',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'manage_links' );
}
/**
* @global int $cat_id
* @global string $s
* @global string $orderby
* @global string $order
*/
public function prepare_items() {
global $cat_id, $s, $orderby, $order;
wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
$args = array(
'hide_invisible' => 0,
'hide_empty' => 0,
);
if ( 'all' != $cat_id ) {
$args['category'] = $cat_id;
}
if ( ! empty( $s ) ) {
$args['search'] = $s;
}
if ( ! empty( $orderby ) ) {
$args['orderby'] = $orderby;
}
if ( ! empty( $order ) ) {
$args['order'] = $order;
}
$this->items = get_bookmarks( $args );
}
/**
*/
public function no_items() {
_e( 'No links found.' );
}
/**
* @return array
*/
protected function get_bulk_actions() {
$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 ) {
return;
}
?>
<div class="alignleft actions">
<?php
$dropdown_options = array(
'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',
);
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
}
/**
* @return array
*/
public function get_columns() {
return array(
'cb' => '<input type="checkbox" />',
'name' => _x( 'Name', 'link name' ),
'url' => __( 'URL' ),
'categories' => __( 'Categories' ),
'rel' => __( 'Relationship' ),
'visible' => __( 'Visible' ),
'rating' => __( 'Rating' ),
);
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'name' => 'name',
'url' => 'url',
'visible' => 'visible',
'rating' => 'rating',
);
}
/**
* Get the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'name'.
*/
protected function get_default_primary_column_name() {
return 'name';
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
*
* @param object $link The current link object.
*/
public function column_cb( $link ) {
?>
<label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
<input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
<?php
}
/**
* Handles the link name column output.
*
* @since 4.3.0
*
* @param object $link The current link object.
*/
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>',
$edit_link,
/* translators: %s: link name */
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ),
$link->link_name
);
}
/**
* Handles the link URL column output.
*
* @since 4.3.0
*
* @param object $link The current link object.
*/
public function column_url( $link ) {
$short_url = url_shorten( $link->link_url );
echo "<a href='$link->link_url'>$short_url</a>";
}
/**
* Handles the link categories column output.
*
* @since 4.3.0
*
* @global int $cat_id
*
* @param object $link The current link object.
*/
public function column_categories( $link ) {
global $cat_id;
$cat_names = array();
foreach ( $link->link_category as $category ) {
$cat = get_term( $category, 'link_category', OBJECT, 'display' );
if ( is_wp_error( $cat ) ) {
echo $cat->get_error_message();
}
$cat_name = $cat->name;
if ( $cat_id != $category ) {
$cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
}
$cat_names[] = $cat_name;
}
echo implode( ', ', $cat_names );
}
/**
* Handles the link relation column output.
*
* @since 4.3.0
*
* @param object $link The current link object.
*/
public function column_rel( $link ) {
echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
}
/**
* Handles the link visibility column output.
*
* @since 4.3.0
*
* @param object $link The current link object.
*/
public function column_visible( $link ) {
if ( 'Y' === $link->link_visible ) {
_e( 'Yes' );
} else {
_e( 'No' );
}
}
/**
* Handles the link rating column output.
*
* @since 4.3.0
*
* @param object $link The current link object.
*/
public function column_rating( $link ) {
echo $link->link_rating;
}
/**
* Handles the default column output.
*
* @since 4.3.0
*
* @param object $link Link object.
* @param string $column_name Current column name.
*/
public function column_default( $link, $column_name ) {
/**
* Fires for each registered custom link column.
*
* @since 2.1.0
*
* @param string $column_name Name of the custom column.
* @param int $link_id Link ID.
*/
do_action( 'manage_link_custom_column', $column_name, $link->link_id );
}
public function display_rows() {
foreach ( $this->items as $link ) {
$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 ); ?>
</tr>
<?php
}
}
/**
* Generates and displays row action links.
*
* @since 4.3.0
*
* @param object $link Link being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row action output for links.
*/
protected function handle_row_actions( $link, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
$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>';
return $this->row_actions( $actions );
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* Helper functions for displaying a list of items in an ajaxified HTML table.
*
* @package WordPress
* @subpackage List_Table
* @since 4.7.0
*/
/**
* Helper class to be used only by back compat functions
*
* @since 3.1.0
*/
class _WP_List_Table_Compat extends WP_List_Table {
public $_screen;
public $_columns;
public function __construct( $screen, $columns = array() ) {
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
$this->_screen = $screen;
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 );
$sortable = array();
$primary = $this->get_default_primary_column_name();
return array( $columns, $hidden, $sortable, $primary );
}
/**
* @return array
*/
public function get_columns() {
return $this->_columns;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,794 @@
<?php
/**
* List Table API: WP_Media_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying media items in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_Media_List_Table extends WP_List_Table {
/**
* Holds the number of pending comments for each post.
*
* @since 4.4.0
* @var array
*/
protected $comment_pending_count = array();
private $detached;
private $is_trash;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
$this->detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] );
$this->modes = array(
'list' => __( 'List View' ),
'grid' => __( 'Grid View' ),
);
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' );
}
/**
* @global WP_Query $wp_query
* @global array $post_mime_types
* @global array $avail_post_mime_types
* @global string $mode
*/
public function prepare_items() {
global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
$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'],
)
);
}
/**
* @global array $post_mime_types
* @global array $avail_post_mime_types
* @return array
*/
protected function get_views() {
global $post_mime_types, $avail_post_mime_types;
$type_links = array();
$filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter'];
$type_links['all'] = sprintf(
'<option value=""%s>%s</option>',
selected( $filter, true, false ),
__( 'All media items' )
);
foreach ( $post_mime_types as $mime_type => $label ) {
if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
continue;
}
$selected = selected(
$filter && 0 === strpos( $filter, 'post_mime_type:' ) &&
wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ),
true,
false
);
$type_links[ $mime_type ] = sprintf(
'<option value="post_mime_type:%s"%s>%s</option>',
esc_attr( $mime_type ),
$selected,
$label[0]
);
}
$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . __( 'Unattached' ) . '</option>';
$type_links['mine'] = sprintf(
'<option value="mine"%s>%s</option>',
selected( 'mine' === $filter, true, false ),
_x( 'Mine', 'media items' )
);
if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
$type_links['trash'] = sprintf(
'<option value="trash"%s>%s</option>',
selected( 'trash' === $filter, true, false ),
_x( 'Trash', 'attachment filter' )
);
}
return $type_links;
}
/**
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( MEDIA_TRASH ) {
if ( $this->is_trash ) {
$actions['untrash'] = __( 'Restore' );
$actions['delete'] = __( 'Delete Permanently' );
} else {
$actions['trash'] = _x( 'Trash', 'verb' );
}
} else {
$actions['delete'] = __( 'Delete Permanently' );
}
if ( $this->detached ) {
$actions['attach'] = __( 'Attach' );
}
return $actions;
}
/**
* @param string $which
*/
protected function extra_tablenav( $which ) {
if ( 'bar' !== $which ) {
return;
}
?>
<div class="actions">
<?php
if ( ! is_singular() ) {
if ( ! $this->is_trash ) {
$this->months_dropdown( 'attachment' );
}
/** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
}
if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
}
?>
</div>
<?php
}
/**
* @return string
*/
public function current_action() {
if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
return 'attach';
}
if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) {
return 'detach';
}
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
return 'delete_all';
}
return parent::current_action();
}
/**
* @return bool
*/
public function has_items() {
return have_posts();
}
/**
*/
public function no_items() {
_e( 'No media files found.' );
}
/**
* Override parent views so we can use the filter bar display.
*
* @global string $mode List table view mode.
*/
public function views() {
global $mode;
$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 ); ?>
<label for="attachment-filter" class="screen-reader-text"><?php _e( 'Filter by type' ); ?></label>
<select class="attachment-filters" name="attachment-filter" id="attachment-filter">
<?php
if ( ! empty( $views ) ) {
foreach ( $views as $class => $view ) {
echo "\t$view\n";
}
}
?>
</select>
<?php
$this->extra_tablenav( 'bar' );
/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
$views = apply_filters( "views_{$this->screen->id}", array() );
// Back compat for pre-4.0 view links.
if ( ! empty( $views ) ) {
echo '<ul class="filter-links">';
foreach ( $views as $class => $view ) {
echo "<li class='$class'>$view</li>";
}
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>
</div>
<?php
}
/**
* @return array
*/
public function get_columns() {
$posts_columns = array();
$posts_columns['cb'] = '<input type="checkbox" />';
/* translators: column name */
$posts_columns['title'] = _x( 'File', 'column name' );
$posts_columns['author'] = __( 'Author' );
$taxonomies = get_taxonomies_for_attachments( 'objects' );
$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
/**
* Filters the taxonomy columns for attachments in the Media list table.
*
* @since 3.5.0
*
* @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' );
foreach ( $taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
$column_key = 'categories';
} elseif ( 'post_tag' === $taxonomy ) {
$column_key = 'tags';
} else {
$column_key = 'taxonomy-' . $taxonomy;
}
$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
}
/* translators: column name */
if ( ! $this->detached ) {
$posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
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' );
/**
* Filters the Media list table columns.
*
* @since 2.5.0
*
* @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() {
return array(
'title' => 'title',
'author' => 'author',
'parent' => 'parent',
'comments' => 'comment_count',
'date' => array( 'date', true ),
);
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
*
* @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>
<input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" />
<?php
}
}
/**
* Handles the title column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
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' => '' ) );
$link_start = $link_end = '';
if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
$link_start = sprintf(
'<a href="%s" aria-label="%s">',
get_edit_post_link( $post->ID ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) )
);
$link_end = '</a>';
}
$class = $thumb ? ' class="has-media-icon"' : '';
?>
<strong<?php echo $class; ?>>
<?php
echo $link_start;
if ( $thumb ) :
?>
<span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span>
<?php
endif;
echo $title . $link_end;
_media_states( $post );
?>
</strong>
<p class="filename">
<span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span>
<?php
$file = get_attached_file( $post->ID );
echo esc_html( wp_basename( $file ) );
?>
</p>
<?php
}
/**
* Handles the author column output.
*
* @since 4.3.0
*
* @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' ) ),
get_the_author()
);
}
/**
* Handles the description column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_desc( $post ) {
echo has_excerpt() ? $post->post_excerpt : '';
}
/**
* Handles the date column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_date( $post ) {
if ( '0000-00-00 00:00:00' === $post->post_date ) {
$h_time = __( 'Unpublished' );
} else {
$m_time = $post->post_date;
$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 ) );
} else {
$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
}
} else {
$h_time = mysql2date( __( 'Y/m/d' ), $m_time );
}
}
echo $h_time;
}
/**
* Handles the parent column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_parent( $post ) {
$user_can_edit = current_user_can( 'edit_post', $post->ID );
if ( $post->post_parent > 0 ) {
$parent = get_post( $post->post_parent );
} else {
$parent = false;
}
if ( $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
} elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
?>
<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'
);
printf(
'<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>',
$detach_url,
/* translators: %s: title of the post the attachment is attached to */
esc_attr( sprintf( __( 'Detach from &#8220;%s&#8221;' ), $title ) ),
__( 'Detach' )
);
endif;
} else {
_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>',
$post->ID,
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $title ) ),
__( 'Attach' )
);
}
}
}
/**
* Handles the comments column output.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_comments( $post ) {
echo '<div class="post-com-count-wrapper">';
if ( isset( $this->comment_pending_count[ $post->ID ] ) ) {
$pending_comments = $this->comment_pending_count[ $post->ID ];
} else {
$pending_comments = get_pending_comments_num( $post->ID );
}
$this->comments_bubble( $post->ID, $pending_comments );
echo '</div>';
}
/**
* Handles output for the default column.
*
* @since 4.3.0
*
* @param WP_Post $post The current WP_Post object.
* @param string $column_name Current column name.
*/
public function column_default( $post, $column_name ) {
if ( 'categories' === $column_name ) {
$taxonomy = 'category';
} elseif ( 'tags' === $column_name ) {
$taxonomy = 'post_tag';
} elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
$taxonomy = substr( $column_name, 9 );
} else {
$taxonomy = false;
}
if ( $taxonomy ) {
$terms = get_the_terms( $post->ID, $taxonomy );
if ( is_array( $terms ) ) {
$out = array();
foreach ( $terms as $t ) {
$posts_in_term_qv = array();
$posts_in_term_qv['taxonomy'] = $taxonomy;
$posts_in_term_qv['term'] = $t->slug;
$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' ) )
);
}
/* translators: used between list items, there is a space after the comma */
echo join( __( ', ' ), $out );
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>';
}
return;
}
/**
* Fires for each custom column in the Media list table.
*
* Custom columns are registered using the {@see 'manage_media_columns'} filter.
*
* @since 2.5.0
*
* @param string $column_name Name of the custom column.
* @param int $post_id Attachment ID.
*/
do_action( 'manage_media_custom_column', $column_name, $post->ID );
}
/**
* @global WP_Post $post
*/
public function display_rows() {
global $post, $wp_query;
$post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
reset( $wp_query->posts );
$this->comment_pending_count = get_pending_comments_num( $post_ids );
add_filter( 'the_title', 'esc_html' );
while ( have_posts() ) :
the_post();
if (
( $this->is_trash && $post->post_status != 'trash' )
|| ( ! $this->is_trash && $post->post_status === 'trash' )
) {
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
endwhile;
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'title'.
*/
protected function get_default_primary_column_name() {
return 'title';
}
/**
* @param WP_Post $post
* @param string $att_title
*
* @return array
*/
private function _get_row_actions( $post, $att_title ) {
$actions = array();
if ( $this->detached ) {
if ( current_user_can( 'edit_post', $post->ID ) ) {
$actions['edit'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
get_edit_post_link( $post->ID ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
__( 'Edit' )
);
}
if ( current_user_can( 'delete_post', $post->ID ) ) {
if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
$actions['trash'] = sprintf(
'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
_x( 'Trash', 'verb' )
);
} else {
$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 ),
$delete_ays,
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
__( 'Delete Permanently' )
);
}
}
$actions['view'] = sprintf(
'<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
get_permalink( $post->ID ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
__( 'View' )
);
if ( current_user_can( 'edit_post', $post->ID ) ) {
$actions['attach'] = sprintf(
'<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>',
$post->ID,
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $att_title ) ),
__( 'Attach' )
);
}
} 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 ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
__( 'Edit' )
);
}
if ( current_user_can( 'delete_post', $post->ID ) ) {
if ( $this->is_trash ) {
$actions['untrash'] = sprintf(
'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $att_title ) ),
__( 'Restore' )
);
} elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
$actions['trash'] = sprintf(
'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
_x( 'Trash', 'verb' )
);
}
if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
$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 ),
$delete_ays,
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
__( 'Delete Permanently' )
);
}
}
if ( ! $this->is_trash ) {
$actions['view'] = sprintf(
'<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
get_permalink( $post->ID ),
/* translators: %s: attachment title */
esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
__( 'View' )
);
}
}
/**
* Filters the action links for each attachment in the Media list table.
*
* @since 2.8.0
*
* @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 );
}
/**
* Generates and displays row action links.
*
* @since 4.3.0
*
* @param object $post Attachment being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row actions output for media attachments.
*/
protected function handle_row_actions( $post, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
$att_title = _draft_or_post_title();
return $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
}
}

View File

@ -0,0 +1,582 @@
<?php
/**
* List Table API: WP_MS_Sites_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying sites in a list table for the network admin.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_MS_Sites_List_Table extends WP_List_Table {
/**
* Site status list.
*
* @since 4.3.0
* @var array
*/
public $status_list;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
$this->status_list = array(
'archived' => array( 'site-archived', __( 'Archived' ) ),
'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
'mature' => array( 'site-mature', __( 'Mature' ) ),
);
parent::__construct(
array(
'plural' => 'sites',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'manage_sites' );
}
/**
* Prepares the list of sites for display.
*
* @since 3.1.0
*
* @global string $s
* @global string $mode
* @global wpdb $wpdb
*/
public function prepare_items() {
global $s, $mode, $wpdb;
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
set_user_setting( 'sites_list_mode', $mode );
} else {
$mode = get_user_setting( 'sites_list_mode', 'list' );
}
$per_page = $this->get_items_per_page( 'sites_network_per_page' );
$pagenum = $this->get_pagenum();
$s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
$wild = '';
if ( false !== strpos( $s, '*' ) ) {
$wild = '*';
$s = trim( $s, '*' );
}
/*
* If the network is large and a search is not being performed, show only
* the latest sites with no paging in order to avoid expensive count queries.
*/
if ( ! $s && wp_is_large_network() ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$_GET['orderby'] = $_REQUEST['orderby'] = '';
}
if ( ! isset( $_REQUEST['order'] ) ) {
$_GET['order'] = $_REQUEST['order'] = 'DESC';
}
}
$args = array(
'number' => intval( $per_page ),
'offset' => intval( ( $pagenum - 1 ) * $per_page ),
'network_id' => get_current_network_id(),
);
if ( empty( $s ) ) {
// Nothing to do.
} elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
// IPv4 address
$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 ) {
$args['site__in'] = $reg_blog_ids;
}
} elseif ( is_numeric( $s ) && empty( $wild ) ) {
$args['ID'] = $s;
} else {
$args['search'] = $s;
if ( ! is_subdomain_install() ) {
$args['search_columns'] = array( 'path' );
}
}
$order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
if ( 'registered' === $order_by ) {
// registered is a valid field name.
} elseif ( 'lastupdated' === $order_by ) {
$order_by = 'last_updated';
} elseif ( 'blogname' === $order_by ) {
if ( is_subdomain_install() ) {
$order_by = 'domain';
} else {
$order_by = 'path';
}
} elseif ( 'blog_id' === $order_by ) {
$order_by = 'id';
} elseif ( ! $order_by ) {
$order_by = false;
}
$args['orderby'] = $order_by;
if ( $order_by ) {
$args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
}
if ( wp_is_large_network() ) {
$args['no_found_rows'] = true;
} else {
$args['no_found_rows'] = false;
}
/**
* Filters the arguments for the site query in the sites list table.
*
* @since 4.6.0
*
* @param array $args An array of get_sites() arguments.
*/
$args = apply_filters( 'ms_sites_list_table_query_args', $args );
$_sites = get_sites( $args );
if ( is_array( $_sites ) ) {
update_site_cache( $_sites );
$this->items = array_slice( $_sites, 0, $per_page );
}
$total_sites = get_sites(
array_merge(
$args,
array(
'count' => true,
'offset' => 0,
'number' => 0,
)
)
);
$this->set_pagination_args(
array(
'total_items' => $total_sites,
'per_page' => $per_page,
)
);
}
/**
*/
public function no_items() {
_e( 'No sites found.' );
}
/**
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( current_user_can( 'delete_sites' ) ) {
$actions['delete'] = __( 'Delete' );
}
$actions['spam'] = _x( 'Mark as Spam', 'site' );
$actions['notspam'] = _x( 'Not Spam', 'site' );
return $actions;
}
/**
* @global string $mode List table view mode.
*
* @param string $which
*/
protected function pagination( $which ) {
global $mode;
parent::pagination( $which );
if ( 'top' === $which ) {
$this->view_switcher( $mode );
}
}
/**
* @return array
*/
public function get_columns() {
$sites_columns = array(
'cb' => '<input type="checkbox" />',
'blogname' => __( 'URL' ),
'lastupdated' => __( 'Last Updated' ),
'registered' => _x( 'Registered', 'site' ),
'users' => __( 'Users' ),
);
if ( has_filter( 'wpmublogsaction' ) ) {
$sites_columns['plugins'] = __( 'Actions' );
}
/**
* Filters the displayed site columns in Sites list table.
*
* @since MU (3.0.0)
*
* @param string[] $sites_columns An array of displayed site columns. Default 'cb',
* 'blogname', 'lastupdated', 'registered', 'users'.
*/
return apply_filters( 'wpmu_blogs_columns', $sites_columns );
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'blogname' => 'blogname',
'lastupdated' => 'lastupdated',
'registered' => 'blog_id',
);
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
*
* @param array $blog Current site.
*/
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;
}
/**
* Handles the ID column output.
*
* @since 4.4.0
*
* @param array $blog Current site.
*/
public function column_id( $blog ) {
echo $blog['blog_id'];
}
/**
* Handles the site name column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param array $blog Current site.
*/
public function column_blogname( $blog ) {
global $mode;
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
$blog_states = array();
reset( $this->status_list );
foreach ( $this->status_list as $status => $col ) {
if ( $blog[ $status ] == 1 ) {
$blog_states[] = $col[1];
}
}
$blog_state = '';
if ( ! empty( $blog_states ) ) {
$state_count = count( $blog_states );
$i = 0;
$blog_state .= ' &mdash; ';
foreach ( $blog_states as $state ) {
++$i;
$sep = ( $i == $state_count ) ? '' : ', ';
$blog_state .= "<span class='post-state'>$state$sep</span>";
}
}
?>
<strong>
<a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname; ?></a>
<?php echo $blog_state; ?>
</strong>
<?php
if ( 'list' !== $mode ) {
switch_to_blog( $blog['blog_id'] );
echo '<p>';
printf(
/* translators: 1: site name, 2: site tagline. */
__( '%1$s &#8211; %2$s' ),
get_option( 'blogname' ),
'<em>' . get_option( 'blogdescription ' ) . '</em>'
);
echo '</p>';
restore_current_blog();
}
}
/**
* Handles the lastupdated column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param array $blog Current site.
*/
public function column_lastupdated( $blog ) {
global $mode;
if ( 'list' === $mode ) {
$date = __( 'Y/m/d' );
} else {
$date = __( 'Y/m/d g:i:s a' );
}
echo ( $blog['last_updated'] === '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] );
}
/**
* Handles the registered column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param array $blog Current site.
*/
public function column_registered( $blog ) {
global $mode;
if ( 'list' === $mode ) {
$date = __( 'Y/m/d' );
} else {
$date = __( 'Y/m/d g:i:s a' );
}
if ( $blog['registered'] === '0000-00-00 00:00:00' ) {
echo '&#x2014;';
} else {
echo mysql2date( $date, $blog['registered'] );
}
}
/**
* Handles the users column output.
*
* @since 4.3.0
*
* @param array $blog Current site.
*/
public function column_users( $blog ) {
$user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
if ( ! $user_count ) {
$blog_users = new WP_User_Query(
array(
'blog_id' => $blog['blog_id'],
'fields' => 'ID',
'number' => 1,
'count_total' => true,
)
);
$user_count = $blog_users->get_total();
wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
}
printf(
'<a href="%s">%s</a>',
esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
number_format_i18n( $user_count )
);
}
/**
* Handles the plugins column output.
*
* @since 4.3.0
*
* @param array $blog Current site.
*/
public function column_plugins( $blog ) {
if ( has_filter( 'wpmublogsaction' ) ) {
/**
* Fires inside the auxiliary 'Actions' column of the Sites list table.
*
* By default this column is hidden unless something is hooked to the action.
*
* @since MU (3.0.0)
*
* @param int $blog_id The site ID.
*/
do_action( 'wpmublogsaction', $blog['blog_id'] );
}
}
/**
* Handles output for the default column.
*
* @since 4.3.0
*
* @param array $blog Current site.
* @param string $column_name Current column name.
*/
public function column_default( $blog, $column_name ) {
/**
* Fires for each registered custom column in the Sites list table.
*
* @since 3.1.0
*
* @param string $column_name The name of the column to display.
* @param int $blog_id The site ID.
*/
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
}
/**
* @global string $mode
*/
public function display_rows() {
foreach ( $this->items as $blog ) {
$blog = $blog->to_array();
$class = '';
reset( $this->status_list );
foreach ( $this->status_list as $status => $col ) {
if ( $blog[ $status ] == 1 ) {
$class = " class='{$col[0]}'";
}
}
echo "<tr{$class}>";
$this->single_row_columns( $blog );
echo '</tr>';
}
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'blogname'.
*/
protected function get_default_primary_column_name() {
return 'blogname';
}
/**
* Generates and displays row action links.
*
* @since 4.3.0
*
* @param object $blog Site being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row actions output.
*/
protected function handle_row_actions( $blog, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return;
}
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
// Preordered.
$actions = array(
'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>';
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>';
} 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>';
}
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>';
}
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>';
}
if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) {
$actions['delete'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] ), 'deleteblog_' . $blog['blog_id'] ) ) . '">' . __( 'Delete' ) . '</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.
*
* The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
* default for each site. The site's status determines whether to show the
* 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and
* 'Not Spam' or 'Spam' link for each site.
*
* @since 3.1.0
*
* @param string[] $actions An array of action links to be displayed.
* @param int $blog_id The site ID.
* @param string $blogname Site path, formatted depending on whether it is a sub-domain
* or subdirectory multisite installation.
*/
$actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
return $this->row_actions( $actions );
}
}

View File

@ -0,0 +1,763 @@
<?php
/**
* List Table API: WP_MS_Themes_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying themes in a list table for the network admin.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_MS_Themes_List_Table extends WP_List_Table {
public $site_id;
public $is_site_themes;
private $has_items;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global string $status
* @global int $page
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
global $status, $page;
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' ) ) ) {
$status = 'all';
}
$page = $this->get_pagenum();
$this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false;
if ( $this->is_site_themes ) {
$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
}
}
/**
* @return array
*/
protected function get_table_classes() {
// todo: remove and add CSS for .themes
return array( 'widefat', 'plugins' );
}
/**
* @return bool
*/
public function ajax_user_can() {
if ( $this->is_site_themes ) {
return current_user_can( 'manage_sites' );
} else {
return current_user_can( 'manage_network_themes' );
}
}
/**
* @global string $status
* @global array $totals
* @global int $page
* @global string $orderby
* @global string $order
* @global string $s
*/
public function prepare_items() {
global $status, $totals, $page, $orderby, $order, $s;
wp_reset_vars( array( 'orderby', 'order', 's' ) );
$themes = array(
/**
* Filters the full array of WP_Theme objects to list in the Multisite
* themes list table.
*
* @since 3.1.0
*
* @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
*/
'all' => apply_filters( 'all_themes', wp_get_themes() ),
'search' => array(),
'enabled' => array(),
'disabled' => array(),
'upgrade' => array(),
'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
);
if ( $this->is_site_themes ) {
$themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
$allowed_where = 'site';
} else {
$themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
$allowed_where = 'network';
}
$maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
foreach ( (array) $themes['all'] as $key => $theme ) {
if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
unset( $themes['all'][ $key ] );
continue;
}
if ( $maybe_update && isset( $current->response[ $key ] ) ) {
$themes['all'][ $key ]->update = true;
$themes['upgrade'][ $key ] = $themes['all'][ $key ];
}
$filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
$themes[ $filter ][ $key ] = $themes['all'][ $key ];
}
if ( $s ) {
$status = 'search';
$themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
}
$totals = array();
foreach ( $themes as $type => $list ) {
$totals[ $type ] = count( $list );
}
if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) {
$status = 'all';
}
$this->items = $themes[ $status ];
WP_Theme::sort_by_name( $this->items );
$this->has_items = ! empty( $themes['all'] );
$total_this_page = $totals[ $status ];
wp_localize_script(
'updates',
'_wpUpdatesItemCounts',
array(
'themes' => $totals,
'totals' => wp_get_update_data(),
)
);
if ( $orderby ) {
$orderby = ucfirst( $orderby );
$order = strtoupper( $order );
if ( $orderby === 'Name' ) {
if ( 'ASC' === $order ) {
$this->items = array_reverse( $this->items );
}
} else {
uasort( $this->items, array( $this, '_order_callback' ) );
}
}
$start = ( $page - 1 ) * $themes_per_page;
if ( $total_this_page > $themes_per_page ) {
$this->items = array_slice( $this->items, $start, $themes_per_page, true );
}
$this->set_pagination_args(
array(
'total_items' => $total_this_page,
'per_page' => $themes_per_page,
)
);
}
/**
* @staticvar string $term
* @param WP_Theme $theme
* @return bool
*/
public function _search_callback( $theme ) {
static $term = null;
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 ) ) {
return true;
}
}
if ( false !== stripos( $theme->get_stylesheet(), $term ) ) {
return true;
}
if ( false !== stripos( $theme->get_template(), $term ) ) {
return true;
}
return false;
}
// Not used by any core columns.
/**
* @global string $orderby
* @global string $order
* @param array $theme_a
* @param array $theme_b
* @return int
*/
public function _order_callback( $theme_a, $theme_b ) {
global $orderby, $order;
$a = $theme_a[ $orderby ];
$b = $theme_b[ $orderby ];
if ( $a == $b ) {
return 0;
}
if ( 'DESC' === $order ) {
return ( $a < $b ) ? 1 : -1;
} else {
return ( $a < $b ) ? -1 : 1;
}
}
/**
*/
public function no_items() {
if ( $this->has_items ) {
_e( 'No themes found.' );
} else {
_e( 'You do not appear to have any themes available at this time.' );
}
}
/**
* @return array
*/
public function get_columns() {
return array(
'cb' => '<input type="checkbox" />',
'name' => __( 'Theme' ),
'description' => __( 'Description' ),
);
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'name' => 'name',
);
}
/**
* Gets the name of the primary column.
*
* @since 4.3.0
*
* @return string Unalterable name of the primary column name, in this case, 'name'.
*/
protected function get_primary_column_name() {
return 'name';
}
/**
* @global array $totals
* @global string $status
* @return array
*/
protected function get_views() {
global $totals, $status;
$status_links = array();
foreach ( $totals as $type => $count ) {
if ( ! $count ) {
continue;
}
switch ( $type ) {
case 'all':
$text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
break;
case 'enabled':
$text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
break;
case 'disabled':
$text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
break;
case 'upgrade':
$text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
break;
case 'broken':
$text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
break;
}
if ( $this->is_site_themes ) {
$url = 'site-themes.php?id=' . $this->site_id;
} 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 ) ),
( $type === $status ) ? ' class="current" aria-current="page"' : '',
sprintf( $text, number_format_i18n( $count ) )
);
}
}
return $status_links;
}
/**
* @global string $status
*
* @return array
*/
protected function get_bulk_actions() {
global $status;
$actions = array();
if ( 'enabled' != $status ) {
$actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
}
if ( 'disabled' != $status ) {
$actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
}
if ( ! $this->is_site_themes ) {
if ( current_user_can( 'update_themes' ) ) {
$actions['update-selected'] = __( 'Update' );
}
if ( current_user_can( 'delete_themes' ) ) {
$actions['delete-selected'] = __( 'Delete' );
}
}
return $actions;
}
/**
*/
public function display_rows() {
foreach ( $this->items as $theme ) {
$this->single_row( $theme );
}
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
*
* @param WP_Theme $theme The current WP_Theme object.
*/
public function column_cb( $theme ) {
$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>
<?php
}
/**
* Handles the name column output.
*
* @since 4.3.0
*
* @global string $status
* @global int $page
* @global string $s
*
* @param WP_Theme $theme The current WP_Theme object.
*/
public function column_name( $theme ) {
global $status, $page, $s;
$context = $status;
if ( $this->is_site_themes ) {
$url = "site-themes.php?id={$this->site_id}&amp;";
$allowed = $theme->is_allowed( 'site', $this->site_id );
} else {
$url = 'themes.php?';
$allowed = $theme->is_allowed( 'network' );
}
// Pre-order.
$actions = array(
'enable' => '',
'disable' => '',
'delete' => '',
);
$stylesheet = $theme->get_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
);
if ( $this->is_site_themes ) {
/* translators: %s: theme name */
$aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) );
} else {
/* translators: %s: theme name */
$aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
}
$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
);
if ( $this->is_site_themes ) {
/* translators: %s: theme name */
$aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) );
} else {
/* translators: %s: theme name */
$aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
}
$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' ) )
);
}
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'
);
/* 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>',
esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
esc_attr( $aria_label ),
__( 'Delete' )
);
}
/**
* Filters the action links displayed for each theme in the Multisite
* themes list table.
*
* The action links displayed are determined by the theme's status, and
* which Multisite themes list table is being displayed - the Network
* themes list table (themes.php), which displays all installed themes,
* or the Site themes list table (site-themes.php), which displays the
* non-network enabled themes when editing a site in the Network admin.
*
* The default action links for the Network themes list table include
* 'Network Enable', 'Network Disable', and 'Delete'.
*
* The default action links for the Site themes list table include
* 'Enable', and 'Disable'.
*
* @since 2.8.0
*
* @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'.
*/
$actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
/**
* Filters the action links of a specific theme in the Multisite themes
* list table.
*
* The dynamic portion of the hook name, `$stylesheet`, refers to the
* directory name of the theme, which in most cases is synonymous
* with the template name.
*
* @since 3.1.0
*
* @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'.
*/
$actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context );
echo $this->row_actions( $actions, true );
}
/**
* Handles the description column output.
*
* @since 4.3.0
*
* @global string $status
* @global array $totals
*
* @param WP_Theme $theme The current WP_Theme object.
*/
public function column_description( $theme ) {
global $status, $totals;
if ( $theme->errors() ) {
$pre = $status === 'broken' ? __( 'Broken Theme:' ) . ' ' : '';
echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
}
if ( $this->is_site_themes ) {
$allowed = $theme->is_allowed( 'site', $this->site_id );
} else {
$allowed = $theme->is_allowed( 'network' );
}
$class = ! $allowed ? 'inactive' : 'active';
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'>";
$stylesheet = $theme->get_stylesheet();
$theme_meta = array();
if ( $theme->get( 'Version' ) ) {
$theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
}
$theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
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->display( 'ThemeURI' ),
esc_attr( $aria_label ),
__( 'Visit Theme Site' )
);
}
/**
* Filters the array of row meta for each theme in the Multisite themes
* list table.
*
* @since 3.1.0
*
* @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.
* @param WP_Theme $theme WP_Theme object.
* @param string $status Status of the theme.
*/
$theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
echo implode( ' | ', $theme_meta );
echo '</div>';
}
/**
* Handles default column output.
*
* @since 4.3.0
*
* @param WP_Theme $theme The current WP_Theme object.
* @param string $column_name The current column name.
*/
public function column_default( $theme, $column_name ) {
$stylesheet = $theme->get_stylesheet();
/**
* Fires inside each custom column of the Multisite themes list table.
*
* @since 3.1.0
*
* @param string $column_name Name of the column.
* @param string $stylesheet Directory name of the theme.
* @param WP_Theme $theme Current WP_Theme object.
*/
do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
}
/**
* Handles the output for a single table row.
*
* @since 4.3.0
*
* @param WP_Theme $item The current WP_Theme object.
*/
public function single_row_columns( $item ) {
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
$extra_classes = '';
if ( in_array( $column_name, $hidden ) ) {
$extra_classes .= ' hidden';
}
switch ( $column_name ) {
case 'cb':
echo '<th scope="row" class="check-column">';
$this->column_cb( $item );
echo '</th>';
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 */
if ( ! empty( $this->site_id ) ) {
$stylesheet = get_blog_option( $this->site_id, 'stylesheet' );
$template = get_blog_option( $this->site_id, 'template' );
/* Add a label for the active template */
if ( $item->get_template() === $template ) {
$active_theme_label = ' &mdash; ' . __( 'Active Theme' );
}
/* In case this is a child theme, label it properly */
if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
$active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
}
}
echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
$this->column_name( $item );
echo '</td>';
break;
case 'description':
echo "<td class='column-description desc{$extra_classes}'>";
$this->column_description( $item );
echo '</td>';
break;
default:
echo "<td class='$column_name column-$column_name{$extra_classes}'>";
$this->column_default( $item, $column_name );
echo '</td>';
break;
}
}
}
/**
* @global string $status
* @global array $totals
*
* @param WP_Theme $theme
*/
public function single_row( $theme ) {
global $status, $totals;
if ( $this->is_site_themes ) {
$allowed = $theme->is_allowed( 'site', $this->site_id );
} else {
$allowed = $theme->is_allowed( 'network' );
}
$stylesheet = $theme->get_stylesheet();
$class = ! $allowed ? 'inactive' : 'active';
if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
$class .= ' update';
}
printf(
'<tr class="%s" data-slug="%s">',
esc_attr( $class ),
esc_attr( $stylesheet )
);
$this->single_row_columns( $theme );
echo '</tr>';
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.
*
* @since 3.1.0
*
* @param string $stylesheet Directory name of the theme.
* @param WP_Theme $theme Current WP_Theme object.
* @param string $status Status of the theme.
*/
do_action( 'after_theme_row', $stylesheet, $theme, $status );
/**
* Fires after each specific row in the Multisite themes list table.
*
* The dynamic portion of the hook name, `$stylesheet`, refers to the
* directory name of the theme, most often synonymous with the template
* name of the theme.
*
* @since 3.5.0
*
* @param string $stylesheet Directory name of the theme.
* @param WP_Theme $theme Current WP_Theme object.
* @param string $status Status of the theme.
*/
do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status );
}
}

View File

@ -0,0 +1,473 @@
<?php
/**
* List Table API: WP_MS_Users_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying users in a list table for the network admin.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_MS_Users_List_Table extends WP_List_Table {
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'manage_network_users' );
}
/**
* @global string $usersearch
* @global string $role
* @global wpdb $wpdb
* @global string $mode
*/
public function prepare_items() {
global $usersearch, $role, $wpdb, $mode;
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
$users_per_page = $this->get_items_per_page( 'users_network_per_page' );
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
$paged = $this->get_pagenum();
$args = array(
'number' => $users_per_page,
'offset' => ( $paged - 1 ) * $users_per_page,
'search' => $usersearch,
'blog_id' => 0,
'fields' => 'all_with_meta',
);
if ( wp_is_large_network( 'users' ) ) {
$args['search'] = ltrim( $args['search'], '*' );
} elseif ( '' !== $args['search'] ) {
$args['search'] = trim( $args['search'], '*' );
$args['search'] = '*' . $args['search'] . '*';
}
if ( $role === 'super' ) {
$logins = implode( "', '", get_super_admins() );
$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
}
/*
* If the network is large and a search is not being performed,
* show only the latest users with no paging in order to avoid
* expensive count queries.
*/
if ( ! $usersearch && wp_is_large_network( 'users' ) ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
}
if ( ! isset( $_REQUEST['order'] ) ) {
$_GET['order'] = $_REQUEST['order'] = 'DESC';
}
$args['count_total'] = false;
}
if ( isset( $_REQUEST['orderby'] ) ) {
$args['orderby'] = $_REQUEST['orderby'];
}
if ( isset( $_REQUEST['order'] ) ) {
$args['order'] = $_REQUEST['order'];
}
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
set_user_setting( 'network_users_list_mode', $mode );
} else {
$mode = get_user_setting( 'network_users_list_mode', 'list' );
}
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
$args = apply_filters( 'users_list_table_query_args', $args );
// Query the user IDs for this page
$wp_user_search = new WP_User_Query( $args );
$this->items = $wp_user_search->get_results();
$this->set_pagination_args(
array(
'total_items' => $wp_user_search->get_total(),
'per_page' => $users_per_page,
)
);
}
/**
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( current_user_can( 'delete_users' ) ) {
$actions['delete'] = __( 'Delete' );
}
$actions['spam'] = _x( 'Mark as Spam', 'user' );
$actions['notspam'] = _x( 'Not Spam', 'user' );
return $actions;
}
/**
*/
public function no_items() {
_e( 'No users found.' );
}
/**
* @global string $role
* @return array
*/
protected function get_views() {
global $role;
$total_users = get_user_count();
$super_admins = get_super_admins();
$total_admins = count( $super_admins );
$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>';
$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>';
return $role_links;
}
/**
* @global string $mode List table view mode.
*
* @param string $which
*/
protected function pagination( $which ) {
global $mode;
parent::pagination( $which );
if ( 'top' === $which ) {
$this->view_switcher( $mode );
}
}
/**
* @return array
*/
public function get_columns() {
$users_columns = array(
'cb' => '<input type="checkbox" />',
'username' => __( 'Username' ),
'name' => __( 'Name' ),
'email' => __( 'Email' ),
'registered' => _x( 'Registered', 'user' ),
'blogs' => __( 'Sites' ),
);
/**
* Filters the columns displayed in the Network Admin Users list table.
*
* @since MU (3.0.0)
*
* @param string[] $users_columns An array of user columns. Default 'cb', 'username',
* 'name', 'email', 'registered', 'blogs'.
*/
return apply_filters( 'wpmu_users_columns', $users_columns );
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'username' => 'login',
'name' => 'name',
'email' => 'email',
'registered' => 'id',
);
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_cb( $user ) {
if ( is_super_admin( $user->ID ) ) {
return;
}
?>
<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 ); ?>" />
<?php
}
/**
* Handles the ID column output.
*
* @since 4.4.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_id( $user ) {
echo $user->ID;
}
/**
* Handles the username column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_username( $user ) {
$super_admins = get_super_admins();
$avatar = get_avatar( $user->user_email, 32 );
echo $avatar;
if ( current_user_can( 'edit_user', $user->ID ) ) {
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
$edit = "<a href=\"{$edit_link}\">{$user->user_login}</a>";
} else {
$edit = $user->user_login;
}
?>
<strong>
<?php
echo $edit;
if ( in_array( $user->user_login, $super_admins ) ) {
echo ' &mdash; ' . __( 'Super Admin' );
}
?>
</strong>
<?php
}
/**
* Handles the name column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_name( $user ) {
if ( $user->first_name && $user->last_name ) {
echo "$user->first_name $user->last_name";
} elseif ( $user->first_name ) {
echo $user->first_name;
} elseif ( $user->last_name ) {
echo $user->last_name;
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . _x( 'Unknown', 'name' ) . '</span>';
}
}
/**
* Handles the email column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_email( $user ) {
echo "<a href='" . esc_url( "mailto:$user->user_email" ) . "'>$user->user_email</a>";
}
/**
* Handles the registered date column output.
*
* @since 4.3.0
*
* @global string $mode List table view mode.
*
* @param WP_User $user The current WP_User object.
*/
public function column_registered( $user ) {
global $mode;
if ( 'list' === $mode ) {
$date = __( 'Y/m/d' );
} else {
$date = __( 'Y/m/d g:i:s a' );
}
echo mysql2date( $date, $user->user_registered );
}
/**
* @since 4.3.0
*
* @param WP_User $user
* @param string $classes
* @param string $data
* @param string $primary
*/
protected function _column_blogs( $user, $classes, $data, $primary ) {
echo '<td class="', $classes, ' has-row-actions" ', $data, '>';
echo $this->column_blogs( $user );
echo $this->handle_row_actions( $user, 'blogs', $primary );
echo '</td>';
}
/**
* Handles the sites column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_blogs( $user ) {
$blogs = get_blogs_of_user( $user->ID, true );
if ( ! is_array( $blogs ) ) {
return;
}
foreach ( $blogs as $val ) {
if ( ! can_edit_network( $val->site_id ) ) {
continue;
}
$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 ' <small class="row-actions">';
$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 ) {
$class .= 'site-spammed ';
}
if ( $val->mature == 1 ) {
$class .= 'site-mature ';
}
if ( $val->deleted == 1 ) {
$class .= 'site-deleted ';
}
if ( $val->archived == 1 ) {
$class .= 'site-archived ';
}
$actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
/**
* Filters the action links displayed next the sites a user belongs to
* in the Network Admin Users list table.
*
* @since 3.1.0
*
* @param string[] $actions An array of action links to be displayed. Default 'Edit', 'View'.
* @param int $userblog_id The site ID.
*/
$actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
$i = 0;
$action_count = count( $actions );
foreach ( $actions as $action => $link ) {
++$i;
$sep = ( $i == $action_count ) ? '' : ' | ';
echo "<span class='$action'>$link$sep</span>";
}
echo '</small></span><br/>';
}
}
/**
* Handles the default column output.
*
* @since 4.3.0
*
* @param WP_User $user The current WP_User object.
* @param string $column_name The current column name.
*/
public function column_default( $user, $column_name ) {
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
}
public function display_rows() {
foreach ( $this->items as $user ) {
$class = '';
$status_list = array(
'spam' => 'site-spammed',
'deleted' => 'site-deleted',
);
foreach ( $status_list as $status => $col ) {
if ( $user->$status ) {
$class .= " $col";
}
}
?>
<tr class="<?php echo trim( $class ); ?>">
<?php $this->single_row_columns( $user ); ?>
</tr>
<?php
}
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'username'.
*/
protected function get_default_primary_column_name() {
return 'username';
}
/**
* Generates and displays row action links.
*
* @since 4.3.0
*
* @param object $user User being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row actions output for users in Multisite.
*/
protected function handle_row_actions( $user, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
$super_admins = get_super_admins();
$actions = array();
if ( current_user_can( 'edit_user', $user->ID ) ) {
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
}
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
$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>';
}
/**
* Filters the action links displayed under each user in the Network Admin Users list table.
*
* @since 3.2.0
*
* @param string[] $actions An array of action links to be displayed. Default 'Edit', 'Delete'.
* @param WP_User $user WP_User object.
*/
$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
return $this->row_actions( $actions );
}
}

View File

@ -0,0 +1,757 @@
<?php
/**
* List Table API: WP_Plugin_Install_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying plugins to install in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_Plugin_Install_List_Table extends WP_List_Table {
public $order = 'ASC';
public $orderby = null;
public $groups = array();
private $error;
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'install_plugins' );
}
/**
* Return the list of known plugins.
*
* Uses the transient data from the updates API to determine the known
* installed plugins.
*
* @since 4.9.0
* @access protected
*
* @return array
*/
protected function get_installed_plugins() {
$plugins = array();
$plugin_info = get_site_transient( 'update_plugins' );
if ( isset( $plugin_info->no_update ) ) {
foreach ( $plugin_info->no_update as $plugin ) {
$plugin->upgrade = false;
$plugins[ $plugin->slug ] = $plugin;
}
}
if ( isset( $plugin_info->response ) ) {
foreach ( $plugin_info->response as $plugin ) {
$plugin->upgrade = true;
$plugins[ $plugin->slug ] = $plugin;
}
}
return $plugins;
}
/**
* Return a list of slugs of installed plugins, if known.
*
* Uses the transient data from the updates API to determine the slugs of
* known installed plugins. This might be better elsewhere, perhaps even
* within get_plugins().
*
* @since 4.0.0
*
* @return array
*/
protected function get_installed_plugin_slugs() {
return array_keys( $this->get_installed_plugins() );
}
/**
* @global array $tabs
* @global string $tab
* @global int $paged
* @global string $type
* @global string $term
*/
public function prepare_items() {
include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
global $tabs, $tab, $paged, $type, $term;
wp_reset_vars( array( 'tab' ) );
$paged = $this->get_pagenum();
$per_page = 36;
// These are the tabs which are shown on the page
$tabs = array();
if ( 'search' === $tab ) {
$tabs['search'] = __( 'Search Results' );
}
if ( $tab === 'beta' || false !== strpos( get_bloginfo( 'version' ), '-' ) ) {
$tabs['beta'] = _x( 'Beta Testing', 'Plugin Installer' );
}
$tabs['featured'] = _x( 'Featured', 'Plugin Installer' );
$tabs['popular'] = _x( 'Popular', 'Plugin Installer' );
$tabs['recommended'] = _x( 'Recommended', 'Plugin Installer' );
$tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
if ( current_user_can( 'upload_plugins' ) ) {
// No longer a real tab. Here for filter compatibility.
// Gets skipped in get_views().
$tabs['upload'] = __( 'Upload Plugin' );
}
$nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item.
/**
* Filters the tabs shown on the Plugin Install screen.
*
* @since 2.7.0
*
* @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 );
/**
* Filters tabs not associated with a menu item on the Plugin Install screen.
*
* @since 2.7.0
*
* @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 ) ) ) {
$tab = key( $tabs );
}
$installed_plugins = $this->get_installed_plugins();
$args = array(
'page' => $paged,
'per_page' => $per_page,
// Send the locale to the API so it can provide context-sensitive results.
'locale' => get_user_locale(),
);
switch ( $tab ) {
case 'search':
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
switch ( $type ) {
case 'tag':
$args['tag'] = sanitize_title_with_dashes( $term );
break;
case 'term':
$args['search'] = $term;
break;
case 'author':
$args['author'] = $term;
break;
}
break;
case 'featured':
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':
$action = 'save_wporg_username_' . get_current_user_id();
if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action ) ) {
$user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
// If the save url parameter is passed with a falsey value, don't save the favorite user.
if ( ! isset( $_GET['save'] ) || $_GET['save'] ) {
update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
}
} else {
$user = get_user_option( 'wporg_favorites' );
}
if ( $user ) {
$args['user'] = $user;
} else {
$args = false;
}
add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 );
break;
default:
$args = false;
break;
}
/**
* Filters API request arguments for each Plugin Install screen tab.
*
* The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
* Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
*
* @since 3.7.0
*
* @param array|bool $args Plugin Install API arguments.
*/
$args = apply_filters( "install_plugins_table_api_args_{$tab}", $args );
if ( ! $args ) {
return;
}
$api = plugins_api( 'query_plugins', $args );
if ( is_wp_error( $api ) ) {
$this->error = $api;
return;
}
$this->items = $api->plugins;
if ( $this->orderby ) {
uasort( $this->items, array( $this, 'order_callback' ) );
}
$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'];
}
if ( $installed_plugins ) {
$js_plugins = array_fill_keys(
array( 'all', 'search', 'active', 'inactive', 'recently_activated', 'mustuse', 'dropins' ),
array()
);
$js_plugins['all'] = array_values( wp_list_pluck( $installed_plugins, 'plugin' ) );
$upgrade_plugins = wp_filter_object_list( $installed_plugins, array( 'upgrade' => true ), 'and', 'plugin' );
if ( $upgrade_plugins ) {
$js_plugins['upgrade'] = array_values( $upgrade_plugins );
}
wp_localize_script(
'updates',
'_wpUpdatesItemCounts',
array(
'plugins' => $js_plugins,
'totals' => wp_get_update_data(),
)
);
}
}
/**
*/
public function no_items() {
if ( isset( $this->error ) ) { ?>
<div class="inline error"><p><?php echo $this->error->get_error_message(); ?></p>
<p class="hide-if-no-js"><button class="button try-again"><?php _e( 'Try Again' ); ?></button></p>
</div>
<?php } else { ?>
<div class="no-plugin-results"><?php _e( 'No plugins found. Try a different search.' ); ?></div>
<?php
}
}
/**
* @global array $tabs
* @global string $tab
*
* @return array
*/
protected function get_views() {
global $tabs, $tab;
$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>";
}
// No longer a real tab.
unset( $display_tabs['plugin-install-upload'] );
return $display_tabs;
}
/**
* Override parent views so we can use the filter bar display.
*/
public function views() {
$views = $this->get_views();
/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
$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
if ( ! empty( $views ) ) {
foreach ( $views as $class => $view ) {
$views[ $class ] = "\t<li class='$class'>$view";
}
echo implode( " </li>\n", $views ) . "</li>\n";
}
?>
</ul>
<?php install_search_form(); ?>
</div>
<?php
}
/**
* Override the parent display() so we can provide a different container.
*/
public function display() {
$singular = $this->_args['singular'];
$data_attr = '';
if ( $singular ) {
$data_attr = " data-wp-lists='list:$singular'";
}
$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' );
?>
<div id="the-list"<?php echo $data_attr; ?>>
<?php $this->display_rows_or_placeholder(); ?>
</div>
</div>
<?php
$this->display_tablenav( 'bottom' );
}
/**
* @global string $tab
*
* @param string $which
*/
protected function display_tablenav( $which ) {
if ( $GLOBALS['tab'] === 'featured' ) {
return;
}
if ( 'top' === $which ) {
wp_referer_field();
?>
<div class="tablenav top">
<div class="alignleft actions">
<?php
/**
* Fires before the Plugin Install table header pagination is displayed.
*
* @since 2.7.0
*/
do_action( 'install_plugins_table_header' );
?>
</div>
<?php $this->pagination( $which ); ?>
<br class="clear" />
</div>
<?php } else { ?>
<div class="tablenav bottom">
<?php $this->pagination( $which ); ?>
<br class="clear" />
</div>
<?php
}
}
/**
* @return array
*/
protected function get_table_classes() {
return array( 'widefat', $this->_args['plural'] );
}
/**
* @return array
*/
public function get_columns() {
return array();
}
/**
* @param object $plugin_a
* @param object $plugin_b
* @return int
*/
private function order_callback( $plugin_a, $plugin_b ) {
$orderby = $this->orderby;
if ( ! isset( $plugin_a->$orderby, $plugin_b->$orderby ) ) {
return 0;
}
$a = $plugin_a->$orderby;
$b = $plugin_b->$orderby;
if ( $a == $b ) {
return 0;
}
if ( 'DESC' === $this->order ) {
return ( $a < $b ) ? 1 : -1;
} else {
return ( $a < $b ) ? -1 : 1;
}
}
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(),
);
$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' ),
);
$group = null;
foreach ( (array) $this->items as $plugin ) {
if ( is_object( $plugin ) ) {
$plugin = (array) $plugin;
}
// Display the group heading if there is one
if ( isset( $plugin['group'] ) && $plugin['group'] != $group ) {
if ( isset( $this->groups[ $plugin['group'] ] ) ) {
$group_name = $this->groups[ $plugin['group'] ];
if ( isset( $plugins_group_titles[ $group_name ] ) ) {
$group_name = $plugins_group_titles[ $group_name ];
}
} else {
$group_name = $plugin['group'];
}
// Starting a new group, close off the divs of the last one
if ( ! empty( $group ) ) {
echo '</div></div>';
}
echo '<div class="plugin-group"><h3>' . esc_html( $group_name ) . '</h3>';
// needs an extra wrapping div for nth-child selectors to work
echo '<div class="plugin-items">';
$group = $plugin['group'];
}
$title = wp_kses( $plugin['name'], $plugins_allowedtags );
// Remove any HTML from the description.
$description = strip_tags( $plugin['short_description'] );
$version = wp_kses( $plugin['version'], $plugins_allowedtags );
$name = strip_tags( $title . ' ' . $version );
$author = wp_kses( $plugin['author'], $plugins_allowedtags );
if ( ! empty( $author ) ) {
$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' ) ) {
$status = install_plugin_install_status( $plugin );
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
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'] ) {
$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[] = 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_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' )
);
if ( is_network_admin() ) {
$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 );
}
$action_links[] = sprintf(
'<a href="%1$s" class="button activate-now" aria-label="%2$s">%3$s</a>',
esc_url( $activate_url ),
esc_attr( sprintf( $button_label, $plugin['name'] ) ),
$button_text
);
} else {
$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'
);
$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'] ) ) {
$plugin_icon_url = $plugin['icons']['svg'];
} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
$plugin_icon_url = $plugin['icons']['2x'];
} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
$plugin_icon_url = $plugin['icons']['1x'];
} else {
$plugin_icon_url = $plugin['icons']['default'];
}
/**
* Filters the install action links for a plugin.
*
* @since 2.7.0
*
* @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="">
</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>';
}
?>
</div>
<div class="desc column-description">
<p><?php echo $description; ?></p>
<p class="authors"><?php echo $author; ?></p>
</div>
</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'],
)
);
?>
<span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
</div>
<div class="column-updated">
<strong><?php _e( 'Last Updated:' ); ?></strong> <?php printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) ); ?>
</div>
<div class="column-downloaded">
<?php
if ( $plugin['active_installs'] >= 1000000 ) {
$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 {
$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
}
printf( __( '%s Active Installations' ), $active_installs_text );
?>
</div>
<div class="column-compatibility">
<?php
if ( ! $tested_wp ) {
echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
} 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>';
}
?>
</div>
</div>
</div>
<?php
}
// Close off the group divs of the last one
if ( ! empty( $group ) ) {
echo '</div></div>';
}
}
}

View File

@ -0,0 +1,919 @@
<?php
/**
* List Table API: WP_Plugins_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying installed plugins in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_Plugins_List_Table extends WP_List_Table {
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global string $status
* @global int $page
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
global $status, $page;
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' ) ) ) {
$status = $_REQUEST['plugin_status'];
}
if ( isset( $_REQUEST['s'] ) ) {
$_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) );
}
$page = $this->get_pagenum();
}
/**
* @return array
*/
protected function get_table_classes() {
return array( 'widefat', $this->_args['plural'] );
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'activate_plugins' );
}
/**
* @global string $status
* @global array $plugins
* @global array $totals
* @global int $page
* @global string $orderby
* @global string $order
* @global string $s
*/
public function prepare_items() {
global $status, $plugins, $totals, $page, $orderby, $order, $s;
wp_reset_vars( array( 'orderby', 'order' ) );
/**
* Filters the full array of plugins to list in the Plugins list table.
*
* @since 3.0.0
*
* @see get_plugins()
*
* @param array $all_plugins An array of plugins to display in the list table.
*/
$all_plugins = apply_filters( 'all_plugins', get_plugins() );
$plugins = array(
'all' => $all_plugins,
'search' => array(),
'active' => array(),
'inactive' => array(),
'recently_activated' => array(),
'upgrade' => array(),
'mustuse' => array(),
'dropins' => array(),
);
$screen = $this->screen;
if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
/**
* Filters whether to display the advanced plugins list table.
*
* There are two types of advanced plugins - must-use and drop-ins -
* which can be used in a single site or Multisite network.
*
* The $type parameter allows you to differentiate between the type of advanced
* plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
*
* @since 3.0.0
*
* @param bool $show Whether to show the advanced plugins for the specified
* plugin type. Default true.
* @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
*/
if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) {
$plugins['mustuse'] = get_mu_plugins();
}
/** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
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 ];
}
}
}
}
if ( ! $screen->in_admin( 'network' ) ) {
$show = current_user_can( 'manage_network_plugins' );
/**
* Filters whether to display network-active plugins alongside plugins active for the current site.
*
* This also controls the display of inactive network-only plugins (plugins with
* "Network: true" in the plugin header).
*
* Plugins cannot be network-activated or network-deactivated from this screen.
*
* @since 4.4.0
*
* @param bool $show Whether to show network-active plugins. Default is whether the current
* user can manage network plugins (ie. a Super Admin).
*/
$show_network_active = apply_filters( 'show_network_active_plugins', $show );
}
set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
if ( $screen->in_admin( 'network' ) ) {
$recently_activated = get_site_option( 'recently_activated', array() );
} else {
$recently_activated = get_option( 'recently_activated', array() );
}
foreach ( $recently_activated as $key => $time ) {
if ( $time + WEEK_IN_SECONDS < time() ) {
unset( $recently_activated[ $key ] );
}
}
if ( $screen->in_admin( 'network' ) ) {
update_site_option( 'recently_activated', $recently_activated );
} else {
update_option( 'recently_activated', $recently_activated );
}
$plugin_info = get_site_transient( 'update_plugins' );
foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
// Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
if ( isset( $plugin_info->response[ $plugin_file ] ) ) {
$plugins['all'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data );
// Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
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
if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
$plugins['upgrade'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data );
}
}
// Filter into individual sections
if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
if ( $show_network_active ) {
// On the non-network screen, show inactive network-only plugins if allowed
$plugins['inactive'][ $plugin_file ] = $plugin_data;
} else {
// On the non-network screen, filter out network-only plugins as long as they're not individually active
unset( $plugins['all'][ $plugin_file ] );
}
} elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
if ( $show_network_active ) {
// On the non-network screen, show network-active plugins if allowed
$plugins['active'][ $plugin_file ] = $plugin_data;
} else {
// On the non-network screen, filter out network-active plugins
unset( $plugins['all'][ $plugin_file ] );
}
} elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
|| ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
// On the non-network screen, populate the active list with plugins that are individually activated
// On the network-admin screen, populate the active list with plugins that are network activated
$plugins['active'][ $plugin_file ] = $plugin_data;
} else {
if ( isset( $recently_activated[ $plugin_file ] ) ) {
// Populate the recently activated list with plugins that have been recently activated
$plugins['recently_activated'][ $plugin_file ] = $plugin_data;
}
// Populate the inactive list with plugins that aren't activated
$plugins['inactive'][ $plugin_file ] = $plugin_data;
}
}
if ( strlen( $s ) ) {
$status = 'search';
$plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
}
$totals = array();
foreach ( $plugins as $type => $list ) {
$totals[ $type ] = count( $list );
}
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 );
}
$total_this_page = $totals[ $status ];
$js_plugins = array();
foreach ( $plugins as $key => $list ) {
$js_plugins[ $key ] = array_keys( (array) $list );
}
wp_localize_script(
'updates',
'_wpUpdatesItemCounts',
array(
'plugins' => $js_plugins,
'totals' => wp_get_update_data(),
)
);
if ( ! $orderby ) {
$orderby = 'Name';
} else {
$orderby = ucfirst( $orderby );
}
$order = strtoupper( $order );
uasort( $this->items, array( $this, '_order_callback' ) );
$plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
$start = ( $page - 1 ) * $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,
)
);
}
/**
* @global string $s URL encoded search term.
*
* @param array $plugin
* @return bool
*/
public function _search_callback( $plugin ) {
global $s;
foreach ( $plugin as $value ) {
if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) {
return true;
}
}
return false;
}
/**
* @global string $orderby
* @global string $order
* @param array $plugin_a
* @param array $plugin_b
* @return int
*/
public function _order_callback( $plugin_a, $plugin_b ) {
global $orderby, $order;
$a = $plugin_a[ $orderby ];
$b = $plugin_b[ $orderby ];
if ( $a == $b ) {
return 0;
}
if ( 'DESC' === $order ) {
return strcasecmp( $b, $a );
} else {
return strcasecmp( $a, $b );
}
}
/**
* @global array $plugins
*/
public function no_items() {
global $plugins;
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'] ) ) {
_e( 'No plugins found.' );
} else {
_e( 'You do not appear to have any plugins available at this time.' );
}
}
/**
* Displays the search box.
*
* @since 4.6.0
*
* @param string $text The 'submit' button label.
* @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() ) {
return;
}
$input_id = $input_id . '-search-input';
if ( ! empty( $_REQUEST['orderby'] ) ) {
echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
}
if ( ! empty( $_REQUEST['order'] ) ) {
echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
}
?>
<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 ); ?>" class="wp-filter-search" name="s" value="<?php _admin_search_query(); ?>" placeholder="<?php esc_attr_e( 'Search installed plugins...' ); ?>"/>
<?php submit_button( $text, 'hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?>
</p>
<?php
}
/**
* @global string $status
* @return array
*/
public function get_columns() {
global $status;
return array(
'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
'name' => __( 'Plugin' ),
'description' => __( 'Description' ),
);
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array();
}
/**
* @global array $totals
* @global string $status
* @return array
*/
protected function get_views() {
global $totals, $status;
$status_links = array();
foreach ( $totals as $type => $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' ),
( $type === $status ) ? ' class="current" aria-current="page"' : '',
sprintf( $text, number_format_i18n( $count ) )
);
}
}
return $status_links;
}
/**
* @global string $status
* @return array
*/
protected function get_bulk_actions() {
global $status;
$actions = array();
if ( 'active' != $status ) {
$actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
}
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' ) ) {
$actions['update-selected'] = __( 'Update' );
}
if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) {
$actions['delete-selected'] = __( 'Delete' );
}
}
return $actions;
}
/**
* @global string $status
* @param string $which
*/
public function bulk_actions( $which = '' ) {
global $status;
if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
return;
}
parent::bulk_actions( $which );
}
/**
* @global string $status
* @param string $which
*/
protected function extra_tablenav( $which ) {
global $status;
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 ) {
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 ) {
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>';
}
echo '</div>';
}
/**
* @return string
*/
public function current_action() {
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' ) ) ) {
return;
}
foreach ( $this->items as $plugin_file => $plugin_data ) {
$this->single_row( array( $plugin_file, $plugin_data ) );
}
}
/**
* @global string $status
* @global int $page
* @global string $s
* @global array $totals
*
* @param array $item
*/
public function single_row( $item ) {
global $status, $page, $s, $totals;
list( $plugin_file, $plugin_data ) = $item;
$context = $status;
$screen = $this->screen;
// Pre-order.
$actions = array(
'deactivate' => '',
'activate' => '',
'details' => '',
'delete' => '',
);
// Do not restrict by default
$restrict_network_active = false;
$restrict_network_only = false;
if ( 'mustuse' === $context ) {
$is_active = true;
} elseif ( 'dropins' === $context ) {
$dropins = _get_dropins();
$plugin_name = $plugin_file;
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;
$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;
$description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
} else {
$is_active = false;
$description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' .
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'] ) {
$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 );
$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 );
}
if ( $screen->in_admin( 'network' ) ) {
if ( $is_active ) {
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 */
$actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Activate' ) . '</a>';
}
if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
/* translators: %s: plugin name */
$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>';
}
}
} else {
if ( $restrict_network_active ) {
$actions = array(
'network_active' => __( 'Network Active' ),
);
} elseif ( $restrict_network_only ) {
$actions = array(
'network_only' => __( 'Network Only' ),
);
} elseif ( $is_active ) {
if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) {
/* 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( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
}
} else {
if ( current_user_can( 'activate_plugin', $plugin_file ) ) {
/* translators: %s: plugin name */
$actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Activate' ) . '</a>';
}
if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
/* translators: %s: plugin name */
$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 $context
$actions = array_filter( $actions );
if ( $screen->in_admin( 'network' ) ) {
/**
* Filters the action links displayed for each plugin in the Network Admin Plugins list table.
*
* @since 3.1.0
*
* @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 );
/**
* Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table.
*
* The dynamic portion of the hook name, `$plugin_file`, refers to the path
* to the plugin file, relative to the plugins directory.
*
* @since 3.1.0
*
* @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 );
} else {
/**
* Filters the action links displayed for each plugin in the Plugins list table.
*
* @since 2.5.0
* @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 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 );
/**
* Filters the list of action links displayed for a specific plugin in the Plugins list table.
*
* The dynamic portion of the hook name, `$plugin_file`, refers to the path
* to the plugin file, relative to the plugins directory.
*
* @since 2.7.0
* @since 4.9.0 The 'Edit' link was removed from the list of action links.
*
* @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'] );
if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
$checkbox = '';
} else {
/* 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 ) {
$description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
$plugin_name = $plugin_data['Name'];
}
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">',
esc_attr( $class ),
esc_attr( $plugin_slug ),
esc_attr( $plugin_file )
);
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
$extra_classes = '';
if ( in_array( $column_name, $hidden ) ) {
$extra_classes = ' hidden';
}
switch ( $column_name ) {
case 'cb':
echo "<th scope='row' class='check-column'>$checkbox</th>";
break;
case 'name':
echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>";
echo $this->row_actions( $actions, true );
echo '</td>';
break;
case 'description':
$classes = 'column-description desc';
echo "<td class='$classes{$extra_classes}'>
<div class='plugin-description'>$description</div>
<div class='$class second plugin-version-author-uri'>";
$plugin_meta = array();
if ( ! empty( $plugin_data['Version'] ) ) {
/* translators: %s: plugin version number */
$plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
}
if ( ! empty( $plugin_data['Author'] ) ) {
$author = $plugin_data['Author'];
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'
)
),
/* 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>',
esc_url( $plugin_data['PluginURI'] ),
__( 'Visit plugin site' )
);
}
/**
* Filters the array of row meta for each plugin in the Plugins list table.
*
* @since 2.8.0
*
* @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>';
echo '</td>';
break;
default:
$classes = "$column_name column-$column_name $class";
echo "<td class='$classes{$extra_classes}'>";
/**
* Fires inside each custom column of the Plugins list table.
*
* @since 3.1.0
*
* @param string $column_name Name of the column.
* @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 '</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 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'.
*/
do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
/**
* Fires after each specific row in the Plugins list table.
*
* The dynamic portion of the hook name, `$plugin_file`, refers to the path
* to the plugin file, relative to the plugins directory.
*
* @since 2.7.0
*
* @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'.
*/
do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status );
}
/**
* Gets the name of the primary column for this specific list table.
*
* @since 4.3.0
*
* @return string Unalterable name for the primary column, in this case, 'name'.
*/
protected function get_primary_column_name() {
return 'name';
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* List Table API: WP_Post_Comments_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Core class used to implement displaying post comments in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_Comments_List_Table
*/
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' ),
),
array(),
array(),
'comment',
);
}
/**
* @return array
*/
protected function 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' );
?>
<table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" style="display:none;">
<tbody id="the-comment-list"
<?php
if ( $singular ) {
echo " data-wp-lists='list:$singular'";
}
?>
>
<?php
if ( ! $output_empty ) {
$this->display_rows_or_placeholder();
}
?>
</tbody>
</table>
<?php
}
/**
* @param bool $comment_status
* @return int
*/
public function get_per_page( $comment_status = false ) {
return 10;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,233 @@
<?php
/**
* Administration API: WP_Site_Icon class
*
* @package WordPress
* @subpackage Administration
* @since 4.3.0
*/
/**
* Core class used to implement site icon functionality.
*
* @since 4.3.0
*/
class WP_Site_Icon {
/**
* The minimum size of the site icon.
*
* @since 4.3.0
* @var int
*/
public $min_size = 512;
/**
* The size to which to crop the image so that we can display it in the UI nicely.
*
* @since 4.3.0
* @var int
*/
public $page_crop = 512;
/**
* List of site icon sizes.
*
* @since 4.3.0
* @var int[]
*/
public $site_icon_sizes = array(
/*
* Square, medium sized tiles for IE11+.
*
* See https://msdn.microsoft.com/library/dn455106(v=vs.85).aspx
*/
270,
/*
* App icon for Android/Chrome.
*
* @link https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android
* @link https://developer.chrome.com/multidevice/android/installtohomescreen
*/
192,
/*
* App icons up to iPhone 6 Plus.
*
* See https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html
*/
180,
// Our regular Favicon.
32,
);
/**
* Registers actions and filters.
*
* @since 4.3.0
*/
public function __construct() {
add_action( 'delete_attachment', array( $this, 'delete_attachment_data' ) );
add_filter( 'get_post_metadata', array( $this, 'get_post_metadata' ), 10, 4 );
}
/**
* Creates an attachment 'object'.
*
* @since 4.3.0
*
* @param string $cropped Cropped image URL.
* @param int $parent_attachment_id Attachment ID of parent image.
* @return array Attachment object.
*/
public function create_attachment_object( $cropped, $parent_attachment_id ) {
$parent = get_post( $parent_attachment_id );
$parent_url = wp_get_attachment_url( $parent->ID );
$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
$size = @getimagesize( $cropped );
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
$object = array(
'ID' => $parent_attachment_id,
'post_title' => basename( $cropped ),
'post_content' => $url,
'post_mime_type' => $image_type,
'guid' => $url,
'context' => 'site-icon',
);
return $object;
}
/**
* Inserts an attachment.
*
* @since 4.3.0
*
* @param array $object Attachment object.
* @param string $file File path of the attached image.
* @return int Attachment ID
*/
public function insert_attachment( $object, $file ) {
$attachment_id = wp_insert_attachment( $object, $file );
$metadata = wp_generate_attachment_metadata( $attachment_id, $file );
/**
* Filters the site icon attachment metadata.
*
* @since 4.3.0
*
* @see wp_generate_attachment_metadata()
*
* @param array $metadata Attachment metadata.
*/
$metadata = apply_filters( 'site_icon_attachment_metadata', $metadata );
wp_update_attachment_metadata( $attachment_id, $metadata );
return $attachment_id;
}
/**
* Adds additional sizes to be made when creating the site icon images.
*
* @since 4.3.0
*
* @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();
/**
* Filters the different dimensions that a site icon is saved in.
*
* @since 4.3.0
*
* @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 );
// Use a natural sort of numbers.
natsort( $this->site_icon_sizes );
$this->site_icon_sizes = array_reverse( $this->site_icon_sizes );
// ensure that we only resize the image into
foreach ( $sizes as $name => $size_array ) {
if ( isset( $size_array['crop'] ) ) {
$only_crop_sizes[ $name ] = $size_array;
}
}
foreach ( $this->site_icon_sizes as $size ) {
if ( $size < $this->min_size ) {
$only_crop_sizes[ 'site_icon-' . $size ] = array(
'width ' => $size,
'height' => $size,
'crop' => true,
);
}
}
return $only_crop_sizes;
}
/**
* Adds Site Icon sizes to the array of image sizes on demand.
*
* @since 4.3.0
*
* @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 */
$this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
foreach ( $this->site_icon_sizes as $size ) {
$sizes[] = 'site_icon-' . $size;
}
return $sizes;
}
/**
* Deletes the Site Icon when the image file is deleted.
*
* @since 4.3.0
*
* @param int $post_id Attachment ID.
*/
public function delete_attachment_data( $post_id ) {
$site_icon_id = get_option( 'site_icon' );
if ( $site_icon_id && $post_id == $site_icon_id ) {
delete_option( 'site_icon' );
}
}
/**
* Adds custom image sizes when meta data for an image is requested, that happens to be used as Site Icon.
*
* @since 4.3.0
*
* @param null|array|string $value The value get_metadata() should return a single metadata value, or an
* array of values.
* @param int $post_id Post ID.
* @param string $meta_key Meta key.
* @param string|array $single Meta value, or an array of values.
* @return array|null|string The attachment metadata value, array of values, or null.
*/
public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
if ( $single && '_wp_attachment_backup_sizes' === $meta_key ) {
$site_icon_id = get_option( 'site_icon' );
if ( $post_id == $site_icon_id ) {
add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) );
}
}
return $value;
}
}

View File

@ -0,0 +1,669 @@
<?php
/**
* List Table API: WP_Terms_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying terms in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_Terms_List_Table extends WP_List_Table {
public $callback_args;
private $level;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global string $post_type
* @global string $taxonomy
* @global string $action
* @global object $tax
*
* @param array $args An associative array of arguments.
*/
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,
)
);
$action = $this->screen->action;
$post_type = $this->screen->post_type;
$taxonomy = $this->screen->taxonomy;
if ( empty( $taxonomy ) ) {
$taxonomy = 'post_tag';
}
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 ) ) ) ) {
$post_type = 'post';
}
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms );
}
/**
*/
public function prepare_items() {
$tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' );
if ( 'post_tag' === $this->screen->taxonomy ) {
/**
* Filters the number of terms displayed per page for the Tags list table.
*
* @since 2.8.0
*
* @param int $tags_per_page Number of tags to be displayed. Default 20.
*/
$tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
/**
* Filters the number of terms displayed per page for the Tags list table.
*
* @since 2.7.0
* @deprecated 2.8.0 Use edit_tags_per_page instead.
*
* @param int $tags_per_page Number of tags to be displayed. Default 20.
*/
$tags_per_page = apply_filters( 'tagsperpage', $tags_per_page );
} elseif ( 'category' === $this->screen->taxonomy ) {
/**
* Filters the number of terms displayed per page for the Categories list table.
*
* @since 2.8.0
*
* @param int $tags_per_page Number of categories to be displayed. Default 20.
*/
$tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page );
}
$search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
$args = array(
'search' => $search,
'page' => $this->get_pagenum(),
'number' => $tags_per_page,
);
if ( ! empty( $_REQUEST['orderby'] ) ) {
$args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) );
}
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,
)
);
}
/**
* @return bool
*/
public function has_items() {
// todo: populate $this->items in prepare_items()
return true;
}
/**
*/
public function no_items() {
echo get_taxonomy( $this->screen->taxonomy )->labels->not_found;
}
/**
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) ) {
$actions['delete'] = __( 'Delete' );
}
return $actions;
}
/**
* @return string
*/
public function current_action() {
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() {
$columns = array(
'cb' => '<input type="checkbox" />',
'name' => _x( 'Name', 'term name' ),
'description' => __( 'Description' ),
'slug' => __( 'Slug' ),
);
if ( 'link_category' === $this->screen->taxonomy ) {
$columns['links'] = __( 'Links' );
} else {
$columns['posts'] = _x( 'Count', 'Number/count of items' );
}
return $columns;
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'name' => 'name',
'description' => 'description',
'slug' => 'slug',
'posts' => 'count',
'links' => 'count',
);
}
/**
*/
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,
)
);
$page = $args['page'];
// Set variable because $args['number'] can be subsequently overridden.
$number = $args['number'];
$args['offset'] = $offset = ( $page - 1 ) * $number;
// Convert it to table rows.
$count = 0;
if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) {
// We'll need the full set of terms then.
$args['number'] = $args['offset'] = 0;
}
$terms = get_terms( $taxonomy, $args );
if ( empty( $terms ) || ! is_array( $terms ) ) {
echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
$this->no_items();
echo '</td></tr>';
return;
}
if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) {
if ( ! empty( $args['search'] ) ) {// Ignore children on searches.
$children = array();
} else {
$children = _get_term_hierarchy( $taxonomy );
}
// Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake
$this->_rows( $taxonomy, $terms, $children, $offset, $number, $count );
} else {
foreach ( $terms as $term ) {
$this->single_row( $term );
}
}
}
/**
* @param string $taxonomy
* @param array $terms
* @param array $children
* @param int $start
* @param int $per_page
* @param int $count
* @param int $parent
* @param int $level
*/
private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent = 0, $level = 0 ) {
$end = $start + $per_page;
foreach ( $terms as $key => $term ) {
if ( $count >= $end ) {
break;
}
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;
while ( $p ) {
$my_parent = get_term( $p, $taxonomy );
$my_parents[] = $my_parent;
$p = $my_parent->parent;
if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
break;
}
$parent_ids[] = $p;
}
unset( $parent_ids );
$num_parents = count( $my_parents );
while ( $my_parent = array_pop( $my_parents ) ) {
echo "\t";
$this->single_row( $my_parent, $level - $num_parents );
$num_parents--;
}
}
if ( $count >= $start ) {
echo "\t";
$this->single_row( $term, $level );
}
++$count;
unset( $terms[ $key ] );
if ( isset( $children[ $term->term_id ] ) && empty( $_REQUEST['s'] ) ) {
$this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
}
}
}
/**
* @global string $taxonomy
* @param WP_Term $tag Term object.
* @param int $level
*/
public function single_row( $tag, $level = 0 ) {
global $taxonomy;
$tag = sanitize_term( $tag, $taxonomy );
$this->level = $level;
echo '<tr id="tag-' . $tag->term_id . '">';
$this->single_row_columns( $tag );
echo '</tr>';
}
/**
* @param WP_Term $tag Term object.
* @return string
*/
public function column_cb( $tag ) {
if ( current_user_can( 'delete_term', $tag->term_id ) ) {
return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>'
. '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />';
}
return '&nbsp;';
}
/**
* @param WP_Term $tag Term object.
* @return string
*/
public function column_name( $tag ) {
$taxonomy = $this->screen->taxonomy;
$pad = str_repeat( '&#8212; ', max( 0, $this->level ) );
/**
* Filters display of the term name in the terms list table.
*
* The default output may include padding due to the term's
* current level in the term hierarchy.
*
* @since 2.5.0
*
* @see WP_Terms_List_Table::column_name()
*
* @param string $pad_tag_name The term name, padded if not top-level.
* @param WP_Term $tag Term object.
*/
$name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
$qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
$uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
$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>%s</strong><br />',
$name
);
$out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
$out .= '<div class="name">' . $qe_data->name . '</div>';
/** This filter is documented in wp-admin/edit-tag-form.php */
$out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>';
$out .= '<div class="parent">' . $qe_data->parent . '</div></div>';
return $out;
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'name'.
*/
protected function get_default_primary_column_name() {
return 'name';
}
/**
* Generates and displays row action links.
*
* @since 4.3.0
*
* @param WP_Term $tag Tag being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row actions output for terms.
*/
protected function handle_row_actions( $tag, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
$taxonomy = $this->screen->taxonomy;
$tax = get_taxonomy( $taxonomy );
$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 )
);
$actions = array();
if ( current_user_can( 'edit_term', $tag->term_id ) ) {
$actions['edit'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
esc_url( $edit_link ),
/* translators: %s: taxonomy term name */
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $tag->name ) ),
__( 'Edit' )
);
$actions['inline hide-if-no-js'] = sprintf(
'<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' )
);
}
if ( current_user_can( 'delete_term', $tag->term_id ) ) {
$actions['delete'] = sprintf(
'<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>',
wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ),
/* translators: %s: taxonomy term name */
esc_attr( sprintf( __( 'Delete &#8220;%s&#8221;' ), $tag->name ) ),
__( 'Delete' )
);
}
if ( is_taxonomy_viewable( $tax ) ) {
$actions['view'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
get_term_link( $tag ),
/* translators: %s: taxonomy term name */
esc_attr( sprintf( __( 'View &#8220;%s&#8221; archive' ), $tag->name ) ),
__( 'View' )
);
}
/**
* Filters the action links displayed for each term in the Tags list table.
*
* @since 2.8.0
* @deprecated 3.0.0 Use {$taxonomy}_row_actions instead.
*
* @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 );
/**
* Filters the action links displayed for each term in the terms list table.
*
* The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
*
* @since 3.0.0
*
* @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 );
return $this->row_actions( $actions );
}
/**
* @param WP_Term $tag Term object.
* @return string
*/
public function column_description( $tag ) {
if ( $tag->description ) {
return $tag->description;
} else {
return '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . __( 'No description' ) . '</span>';
}
}
/**
* @param WP_Term $tag Term object.
* @return string
*/
public function column_slug( $tag ) {
/** This filter is documented in wp-admin/edit-tag-form.php */
return apply_filters( 'editable_slug', $tag->slug, $tag );
}
/**
* @param WP_Term $tag Term object.
* @return string
*/
public function column_posts( $tag ) {
$count = number_format_i18n( $tag->count );
$tax = get_taxonomy( $this->screen->taxonomy );
$ptype_object = get_post_type_object( $this->screen->post_type );
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,
);
}
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>";
}
return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
}
/**
* @param WP_Term $tag Term object.
* @return string
*/
public function column_links( $tag ) {
$count = number_format_i18n( $tag->count );
if ( $count ) {
$count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>";
}
return $count;
}
/**
* @param WP_Term $tag Term object.
* @param string $column_name
* @return string
*/
public function column_default( $tag, $column_name ) {
/**
* Filters the displayed columns in the terms list table.
*
* The dynamic portion of the hook name, `$this->screen->taxonomy`,
* refers to the slug of the current taxonomy.
*
* @since 2.8.0
*
* @param string $string Blank string.
* @param string $column_name Name of the column.
* @param int $term_id Term ID.
*/
return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
}
/**
* Outputs the hidden row displayed when inline editing
*
* @since 3.1.0
*/
public function inline_edit() {
$tax = get_taxonomy( $this->screen->taxonomy );
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">
<fieldset>
<legend class="inline-edit-legend"><?php _e( 'Quick Edit' ); ?></legend>
<div class="inline-edit-col">
<label>
<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() ) { ?>
<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
$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 ] ) ) {
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>
<button type="button" class="save button button-primary alignright"><?php echo $tax->labels->update_item; ?></button>
<span class="spinner"></span>
<?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
<input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" />
<input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" />
<br class="clear" />
<div class="notice notice-error notice-alt inline hidden">
<p class="error"></p>
</div>
</div>
</td></tr>
</tbody></table></form>
<?php
}
}

View File

@ -0,0 +1,555 @@
<?php
/**
* List Table API: WP_Theme_Install_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying themes to install in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_Themes_List_Table
*/
class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
public $features = array();
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'install_themes' );
}
/**
* @global array $tabs
* @global string $tab
* @global int $paged
* @global string $type
* @global array $theme_field_defaults
*/
public function prepare_items() {
include( ABSPATH . 'wp-admin/includes/theme-install.php' );
global $tabs, $tab, $paged, $type, $theme_field_defaults;
wp_reset_vars( array( 'tab' ) );
$search_terms = array();
$search_string = '';
if ( ! empty( $_REQUEST['s'] ) ) {
$search_string = strtolower( wp_unslash( $_REQUEST['s'] ) );
$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
}
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['dashboard'] = __( 'Search' );
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' );
$nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
/** This filter is documented in wp-admin/theme-install.php */
$tabs = apply_filters( 'install_themes_tabs', $tabs );
/**
* Filters tabs not associated with a menu item on the Install Themes screen.
*
* @since 2.8.0
*
* @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 ) ) ) {
$tab = key( $tabs );
}
$args = array(
'page' => $paged,
'per_page' => $per_page,
'fields' => $theme_field_defaults,
);
switch ( $tab ) {
case 'search':
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
switch ( $type ) {
case 'tag':
$args['tag'] = array_map( 'sanitize_key', $search_terms );
break;
case 'term':
$args['search'] = $search_string;
break;
case 'author':
$args['author'] = $search_string;
break;
}
if ( ! empty( $this->features ) ) {
$args['tag'] = $this->features;
$_REQUEST['s'] = implode( ',', $this->features );
$_REQUEST['type'] = 'tag';
}
add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 );
break;
case 'featured':
// case 'popular':
case 'new':
case 'updated':
$args['browse'] = $tab;
break;
default:
$args = false;
break;
}
/**
* Filters API request arguments for each Install Themes screen tab.
*
* The dynamic portion of the hook name, `$tab`, refers to the theme install
* tabs. Default tabs are 'dashboard', 'search', 'upload', 'featured',
* 'new', and 'updated'.
*
* @since 3.7.0
*
* @param array $args An array of themes API arguments.
*/
$args = apply_filters( "install_themes_table_api_args_{$tab}", $args );
if ( ! $args ) {
return;
}
$api = themes_api( 'query_themes', $args );
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,
)
);
}
/**
*/
public function no_items() {
_e( 'No themes match your request.' );
}
/**
* @global array $tabs
* @global string $tab
* @return array
*/
protected function get_views() {
global $tabs, $tab;
$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>";
}
return $display_tabs;
}
/**
*/
public function display() {
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
<div class="tablenav top themes">
<div class="alignleft actions">
<?php
/**
* Fires in the Install Themes list table header.
*
* @since 2.8.0
*/
do_action( 'install_themes_table_header' );
?>
</div>
<?php $this->pagination( 'top' ); ?>
<br class="clear" />
</div>
<div id="availablethemes">
<?php $this->display_rows_or_placeholder(); ?>
</div>
<?php
$this->tablenav( 'bottom' );
}
/**
*/
public function display_rows() {
$themes = $this->items;
foreach ( $themes as $theme ) {
?>
<div class="available-theme installable-theme">
<?php
$this->single_row( $theme );
?>
</div>
<?php
} // end foreach $theme_names
$this->theme_installer();
}
/**
* Prints a theme from the WordPress.org API.
*
* @since 3.1.0
*
* @global array $themes_allowedtags
*
* @param object $theme {
* An object that contains theme data returned by the WordPress.org API.
*
* @type string $name Theme name, e.g. 'Twenty Nineteen'.
* @type string $slug Theme slug, e.g. 'twentynineteen'.
* @type string $version Theme version, e.g. '1.1'.
* @type string $author Theme author username, e.g. 'melchoyce'.
* @type string $preview_url Preview URL, e.g. 'http://2019.wordpress.net/'.
* @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentynineteen/'.
* @type float $rating Rating score.
* @type int $num_ratings The number of ratings.
* @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentynineteen/'.
* @type string $description Theme description.
* @type string $download_link Theme ZIP download URL.
* }
*/
public function single_row( $theme ) {
global $themes_allowedtags;
if ( empty( $theme ) ) {
return;
}
$name = wp_kses( $theme->name, $themes_allowedtags );
$author = wp_kses( $theme->author, $themes_allowedtags );
/* 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' )
);
$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[] = 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[] = 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[] = 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[] = 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 string[] $actions An array of theme action links. Defaults are
* links to Install Now, Preview, and Details.
* @param WP_Theme $theme Theme object.
*/
$actions = apply_filters( 'theme_install_actions', $actions, $theme );
?>
<a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>">
<img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" />
</a>
<h3><?php echo $name; ?></h3>
<div class="theme-author">
<?php
/* translators: %s: theme author */
printf( __( 'By %s' ), $author );
?>
</div>
<div class="action-links">
<ul>
<?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>
</ul>
</div>
<?php
$this->install_theme_info( $theme );
}
/**
* Prints the wrapper for the theme installer.
*/
public function theme_installer() {
?>
<div id="theme-installer" class="wp-full-overlay expanded">
<div class="wp-full-overlay-sidebar">
<div class="wp-full-overlay-header">
<a href="#" class="close-full-overlay button"><?php _e( 'Close' ); ?></a>
<span class="theme-install"></span>
</div>
<div class="wp-full-overlay-sidebar-content">
<div class="install-theme-info"></div>
</div>
<div class="wp-full-overlay-footer">
<button type="button" class="collapse-sidebar button" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
<span class="collapse-sidebar-arrow"></span>
<span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
</button>
</div>
</div>
<div class="wp-full-overlay-main"></div>
</div>
<?php
}
/**
* Prints the wrapper for the theme installer with a provided theme's data.
* Used to make the theme installer work for no-js.
*
* @param object $theme - A WordPress.org Theme API object.
*/
public function theme_installer_single( $theme ) {
?>
<div id="theme-installer" class="wp-full-overlay single-theme">
<div class="wp-full-overlay-sidebar">
<?php $this->install_theme_info( $theme ); ?>
</div>
<div class="wp-full-overlay-main">
<iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe>
</div>
</div>
<?php
}
/**
* Prints the info for a theme (to be used in the theme installer modal).
*
* @global array $themes_allowedtags
*
* @param object $theme - A WordPress.org Theme API object.
*/
public function install_theme_info( $theme ) {
global $themes_allowedtags;
if ( empty( $theme ) ) {
return;
}
$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' )
);
$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':
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
/* 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,
)
);
?>
<div class="theme-version">
<strong><?php _e( 'Version:' ); ?> </strong>
<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
</div>
<div class="theme-description">
<?php echo wp_kses( $theme->description, $themes_allowedtags ); ?>
</div>
</div>
<input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" />
</div>
<?php
}
/**
* Send required variables to JavaScript land
*
* @since 3.4.0
*
* @global string $tab Current tab within Themes->Install screen
* @global string $type Type of search.
*
* @param array $extra_args Unused.
*/
public function _js_vars( $extra_args = array() ) {
global $tab, $type;
parent::_js_vars( compact( 'tab', 'type' ) );
}
/**
* Check to see if the theme is already installed.
*
* @since 3.4.0
*
* @param object $theme - A WordPress.org Theme API object.
* @return string Theme status.
*/
private function _get_theme_status( $theme ) {
$status = 'install';
$installed_theme = wp_get_theme( $theme->slug );
if ( $installed_theme->exists() ) {
if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) {
$status = 'latest_installed';
} elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) {
$status = 'newer_installed';
} else {
$status = 'update_available';
}
}
return $status;
}
}

View File

@ -0,0 +1,320 @@
<?php
/**
* List Table API: WP_Themes_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying installed themes in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_Themes_List_Table extends WP_List_Table {
protected $search_terms = array();
public $features = array();
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
parent::__construct(
array(
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* @return bool
*/
public function ajax_user_can() {
// Do not check edit_theme_options here. Ajax calls for available themes require switch_themes.
return current_user_can( 'switch_themes' );
}
/**
*/
public function prepare_items() {
$themes = wp_get_themes( array( 'allowed' => true ) );
if ( ! empty( $_REQUEST['s'] ) ) {
$this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) );
}
if ( ! empty( $_REQUEST['features'] ) ) {
$this->features = $_REQUEST['features'];
}
if ( $this->search_terms || $this->features ) {
foreach ( $themes as $key => $theme ) {
if ( ! $this->search_theme( $theme ) ) {
unset( $themes[ $key ] );
}
}
}
unset( $themes[ get_option( 'stylesheet' ) ] );
WP_Theme::sort_by_name( $themes );
$per_page = 36;
$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,
)
);
}
/**
*/
public function no_items() {
if ( $this->search_terms || $this->features ) {
_e( 'No items found.' );
return;
}
$blog_id = get_current_blog_id();
if ( is_multisite() ) {
if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) {
printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ), network_admin_url( 'theme-install.php' ) );
return;
} elseif ( current_user_can( 'manage_network_themes' ) ) {
printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ) );
return;
}
// Else, fallthrough. install_themes doesn't help if you can't enable it.
} else {
if ( current_user_can( 'install_themes' ) ) {
printf( __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) );
return;
}
}
// Fallthrough.
printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
}
/**
* @param string $which
*/
public function tablenav( $which = 'top' ) {
if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) {
return;
}
?>
<div class="tablenav themes <?php echo $which; ?>">
<?php $this->pagination( $which ); ?>
<span class="spinner"></span>
<br class="clear" />
</div>
<?php
}
/**
*/
public function display() {
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
<?php $this->tablenav( 'top' ); ?>
<div id="availablethemes">
<?php $this->display_rows_or_placeholder(); ?>
</div>
<?php $this->tablenav( 'bottom' ); ?>
<?php
}
/**
* @return array
*/
public function get_columns() {
return array();
}
/**
*/
public function display_rows_or_placeholder() {
if ( $this->has_items() ) {
$this->display_rows();
} else {
echo '<div class="no-items">';
$this->no_items();
echo '</div>';
}
}
/**
*/
public function display_rows() {
$themes = $this->items;
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' );
$activate_link = wp_nonce_url( 'themes.php?action=activate&amp;template=' . urlencode( $template ) . '&amp;stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
$actions = array();
$actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="'
. esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">'
. __( 'Live Preview' ) . '</a>';
}
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' );
/** 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' );
$delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : '';
unset( $actions['delete'] );
?>
<span class="screenshot hide-if-customize">
<?php if ( $screenshot = $theme->get_screenshot() ) : ?>
<img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
<?php endif; ?>
</span>
<a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize">
<?php if ( $screenshot = $theme->get_screenshot() ) : ?>
<img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
<?php endif; ?>
</a>
<h3><?php echo $title; ?></h3>
<div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
<div class="action-links">
<ul>
<?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>
</ul>
<?php echo $delete_action; ?>
<?php theme_update_available( $theme ); ?>
</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>',
__( 'https://codex.wordpress.org/Child_Themes' ),
$theme->parent()->display( 'Name' )
);
}
?>
</div>
</div>
<?php
endforeach;
}
/**
* @param WP_Theme $theme
* @return bool
*/
public function search_theme( $theme ) {
// Search the features
foreach ( $this->features as $word ) {
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' ) ) ) {
continue;
}
foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
// Don't mark up; Do translate.
if ( false !== stripos( strip_tags( $theme->display( $header, false, true ) ), $word ) ) {
continue 2;
}
}
if ( false !== stripos( $theme->get_stylesheet(), $word ) ) {
continue;
}
if ( false !== stripos( $theme->get_template(), $word ) ) {
continue;
}
return false;
}
return true;
}
/**
* Send required variables to JavaScript land
*
* @since 3.4.0
*
* @param array $extra_args
*/
public function _js_vars( $extra_args = array() ) {
$search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
$args = array(
'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 ) ) {
$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

@ -0,0 +1,209 @@
<?php
/**
* Upgrader API: WP_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
*
* @since 2.8.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*/
class WP_Upgrader_Skin {
public $upgrader;
public $done_header = false;
public $done_footer = false;
/**
* Holds the result of an upgrade.
*
* @since 2.8.0
* @var string|bool|WP_Error
*/
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 );
}
/**
* @param WP_Upgrader $upgrader
*/
public function set_upgrader( &$upgrader ) {
if ( is_object( $upgrader ) ) {
$this->upgrader =& $upgrader;
}
$this->add_strings();
}
/**
*/
public function add_strings() {
}
/**
* Sets the result of an upgrade.
*
* @since 2.8.0
*
* @param string|bool|WP_Error $result The result of an upgrade.
*/
public function set_result( $result ) {
$this->result = $result;
}
/**
* Displays a form to the user to request for their FTP/SSH details in order
* to connect to the filesystem.
*
* @since 2.8.0
* @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
*
* @see request_filesystem_credentials()
*
* @param bool $error Optional. Whether the current request has failed to connect.
* Default false.
* @param string $context Optional. Full path to the directory that is tested
* for being writable. Default empty.
* @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
* @return bool False on failure, true on success.
*/
public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
$url = $this->options['url'];
if ( ! $context ) {
$context = $this->options['context'];
}
if ( ! empty( $this->options['nonce'] ) ) {
$url = wp_nonce_url( $url, $this->options['nonce'] );
}
$extra_fields = array();
return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
}
/**
*/
public function header() {
if ( $this->done_header ) {
return;
}
$this->done_header = true;
echo '<div class="wrap">';
echo '<h1>' . $this->options['title'] . '</h1>';
}
/**
*/
public function footer() {
if ( $this->done_footer ) {
return;
}
$this->done_footer = true;
echo '</div>';
}
/**
* @param string|WP_Error $errors
*/
public function error( $errors ) {
if ( ! $this->done_header ) {
$this->header();
}
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 );
}
}
}
}
/**
* @param string $string
*/
public function feedback( $string ) {
if ( isset( $this->upgrader->strings[ $string ] ) ) {
$string = $this->upgrader->strings[ $string ];
}
if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( $args ) {
$args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args );
$string = vsprintf( $string, $args );
}
}
if ( empty( $string ) ) {
return;
}
show_message( $string );
}
/**
*/
public function before() {}
/**
*/
public function after() {}
/**
* Output JavaScript that calls function to decrement the update counts.
*
* @since 3.9.0
*
* @param string $type Type of update count to decrement. Likely values include 'plugin',
* 'theme', 'translation', etc.
*/
protected function decrement_update_count( $type ) {
if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
return;
}
if ( defined( 'IFRAME_REQUEST' ) ) {
echo '<script type="text/javascript">
if ( window.postMessage && JSON ) {
window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
}
</script>';
} else {
echo '<script type="text/javascript">
(function( wp ) {
if ( wp && wp.updates && wp.updates.decrementCount )
wp.updates.decrementCount( "' . $type . '" );
}
})( window.wp );
</script>';
}
}
/**
*/
public function bulk_header() {}
/**
*/
public function bulk_footer() {}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* The User Interface "Skins" for the WordPress File Upgrader
*
* @package WordPress
* @subpackage Upgrader
* @since 2.8.0
*/
_deprecated_file( basename( __FILE__ ), '4.7.0', 'class-wp-upgrader.php' );
/** WP_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
/** Plugin_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader-skin.php';
/** Theme_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader-skin.php';
/** Bulk_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-bulk-upgrader-skin.php';
/** Bulk_Plugin_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-bulk-plugin-upgrader-skin.php';
/** Bulk_Theme_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-bulk-theme-upgrader-skin.php';
/** Plugin_Installer_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-plugin-installer-skin.php';
/** Theme_Installer_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-theme-installer-skin.php';
/** Language_Pack_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader-skin.php';
/** Automatic_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php';
/** WP_Ajax_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';

View File

@ -0,0 +1,922 @@
<?php
/**
* Upgrade API: WP_Upgrader class
*
* Requires skin classes and WP_Upgrader subclasses for backward compatibility.
*
* @package WordPress
* @subpackage Upgrader
* @since 2.8.0
*/
/** WP_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
/** Plugin_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader-skin.php';
/** Theme_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader-skin.php';
/** Bulk_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-bulk-upgrader-skin.php';
/** Bulk_Plugin_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-bulk-plugin-upgrader-skin.php';
/** Bulk_Theme_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-bulk-theme-upgrader-skin.php';
/** Plugin_Installer_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-plugin-installer-skin.php';
/** Theme_Installer_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-theme-installer-skin.php';
/** Language_Pack_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader-skin.php';
/** Automatic_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php';
/** WP_Ajax_Upgrader_Skin class */
require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
/**
* Core class used for upgrading/installing a local set of files via
* the Filesystem Abstraction classes from a Zip file.
*
* @since 2.8.0
*/
class WP_Upgrader {
/**
* The error/notification strings used to update the user on the progress.
*
* @since 2.8.0
* @var array $strings
*/
public $strings = array();
/**
* The upgrader skin being used.
*
* @since 2.8.0
* @var Automatic_Upgrader_Skin|WP_Upgrader_Skin $skin
*/
public $skin = null;
/**
* The result of the installation.
*
* This is set by WP_Upgrader::install_package(), only when the package is installed
* successfully. It will then be an array, unless a WP_Error is returned by the
* {@see 'upgrader_post_install'} filter. In that case, the WP_Error will be assigned to
* it.
*
* @since 2.8.0
*
* @var WP_Error|array $result {
* @type string $source The full path to the source the files were installed from.
* @type string $source_files List of all the files in the source directory.
* @type string $destination The full path to the installation destination folder.
* @type string $destination_name The name of the destination folder, or empty if `$destination`
* and `$local_destination` are the same.
* @type string $local_destination The full local path to the destination folder. This is usually
* the same as `$destination`.
* @type string $remote_destination The full remote path to the destination folder
* (i.e., from `$wp_filesystem`).
* @type bool $clear_destination Whether the destination folder was cleared.
* }
*/
public $result = array();
/**
* The total number of updates being performed.
*
* Set by the bulk update methods.
*
* @since 3.0.0
* @var int $update_count
*/
public $update_count = 0;
/**
* The current update if multiple updates are being performed.
*
* Used by the bulk update methods, and incremented for each update.
*
* @since 3.0.0
* @var int
*/
public $update_current = 0;
/**
* Construct the upgrader with a skin.
*
* @since 2.8.0
*
* @param WP_Upgrader_Skin $skin The upgrader skin to use. Default is a WP_Upgrader_Skin.
* instance.
*/
public function __construct( $skin = null ) {
if ( null == $skin ) {
$this->skin = new WP_Upgrader_Skin();
} else {
$this->skin = $skin;
}
}
/**
* Initialize the upgrader.
*
* This will set the relationship between the skin being used and this upgrader,
* and also add the generic strings to `WP_Upgrader::$strings`.
*
* @since 2.8.0
*/
public function init() {
$this->skin->set_upgrader( $this );
$this->generic_strings();
}
/**
* Add the generic strings to WP_Upgrader::$strings.
*
* @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.' );
/* translators: %s: directory name */
$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['maintenance_start'] = __( 'Enabling Maintenance mode&#8230;' );
$this->strings['maintenance_end'] = __( 'Disabling Maintenance mode&#8230;' );
}
/**
* Connect to the filesystem.
*
* @since 2.8.0
*
* @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.
* Default empty array.
* @param bool $allow_relaxed_file_ownership Whether to allow relaxed file ownership.
* Default false.
* @return bool|WP_Error True if able to connect, false or a WP_Error otherwise.
*/
public function fs_connect( $directories = array(), $allow_relaxed_file_ownership = false ) {
global $wp_filesystem;
if ( false === ( $credentials = $this->skin->request_filesystem_credentials( false, $directories[0], $allow_relaxed_file_ownership ) ) ) {
return false;
}
if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) {
$error = true;
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_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 ) {
switch ( $dir ) {
case ABSPATH:
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'] );
}
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'] );
}
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'] );
}
break;
default:
if ( ! $wp_filesystem->find_folder( $dir ) ) {
return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) );
}
break;
}
}
return true;
} //end fs_connect();
/**
* Download a package.
*
* @since 2.8.0
*
* @param string $package The URI of the package. If this is the full path to an
* existing local file, it will be returned untouched.
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
*/
public function download_package( $package ) {
/**
* Filters whether to return the package.
*
* @since 3.7.0
*
* @param bool $reply Whether to bail without returning the package.
* Default false.
* @param string $package The package file name.
* @param WP_Upgrader $this The WP_Upgrader instance.
*/
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this );
if ( false !== $reply ) {
return $reply;
}
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'] );
}
$this->skin->feedback( 'downloading_package', $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() );
}
return $download_file;
}
/**
* Unpack a compressed package file.
*
* @since 2.8.0
*
* @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
* to unpack it. Default true.
* @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure.
*/
public function unpack_package( $package, $delete_package = true ) {
global $wp_filesystem;
$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 );
}
}
// 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 );
}
// Unzip package to working directory
$result = unzip_file( $package, $working_dir );
// Once extracted, delete the package if required.
if ( $delete_package ) {
unlink( $package );
}
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() );
}
return $result;
}
return $working_dir;
}
/**
* Flatten the results of WP_Filesystem::dirlist() for iterating over.
*
* @since 4.9.0
* @access protected
*
* @param array $nested_files Array of files as returned by WP_Filesystem::dirlist()
* @param string $path Relative path to prepend to child nodes. Optional.
* @return array $files A flattened array of the $nested_files specified.
*/
protected function flatten_dirlist( $nested_files, $path = '' ) {
$files = array();
foreach ( $nested_files as $name => $details ) {
$files[ $path . $name ] = $details;
// Append children recursively
if ( ! empty( $details['files'] ) ) {
$children = $this->flatten_dirlist( $details['files'], $path . $name . '/' );
// Merge keeping possible numeric keys, which array_merge() will reindex from 0..n
$files = $files + $children;
}
}
return $files;
}
/**
* Clears the directory where this item is going to be installed into.
*
* @since 4.3.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;
$files = $wp_filesystem->dirlist( $remote_destination, true, true );
// False indicates that the $remote_destination doesn't exist.
if ( false === $files ) {
return true;
}
// Flatten the file list to iterate over
$files = $this->flatten_dirlist( $files );
// Check all files are writable before attempting to clear the destination.
$unwritable_files = array();
// Check writability.
foreach ( $files as $filename => $file_details ) {
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {
// Attempt to alter permissions to allow writes and try again.
$wp_filesystem->chmod( $remote_destination . $filename, ( 'd' == $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) );
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {
$unwritable_files[] = $filename;
}
}
}
if ( ! empty( $unwritable_files ) ) {
return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );
}
if ( ! $wp_filesystem->delete( $remote_destination, true ) ) {
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
}
return true;
}
/**
* Install a package.
*
* Copies the contents of a package form a source directory, and installs them in
* a destination directory. Optionally removes the source. It can also optionally
* clear out the destination folder if it already exists.
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global array $wp_theme_directories
*
* @param array|string $args {
* Optional. Array or string of arguments for installing a package. Default empty array.
*
* @type string $source Required path to the package source. Default empty.
* @type string $destination Required path to a folder to install the package in.
* Default empty.
* @type bool $clear_destination Whether to delete any files already in the destination
* folder. Default false.
* @type bool $clear_working Whether to delete the files form the working directory
* after copying to the destination. Default false.
* @type bool $abort_if_destination_exists Whether to abort the installation if
* the destination folder already exists. Default true.
* @type array $hook_extra Extra arguments to pass to the filter hooks called by
* WP_Upgrader::install_package(). Default empty array.
* }
*
* @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.
*/
public function install_package( $args = array() ) {
global $wp_filesystem, $wp_theme_directories;
$defaults = array(
'source' => '', // Please always pass this
'destination' => '', // and this
'clear_destination' => false,
'clear_working' => false,
'abort_if_destination_exists' => true,
'hook_extra' => array(),
);
$args = wp_parse_args( $args, $defaults );
// These were previously extract()'d.
$source = $args['source'];
$destination = $args['destination'];
$clear_destination = $args['clear_destination'];
@set_time_limit( 300 );
if ( empty( $source ) || empty( $destination ) ) {
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
}
$this->skin->feedback( 'installing_package' );
/**
* Filters the install response before the installation has started.
*
* Returning a truthy value, or one that could be evaluated as a WP_Error
* will effectively short-circuit the installation, returning that value
* instead.
*
* @since 2.8.0
*
* @param bool|WP_Error $response Response.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
if ( is_wp_error( $res ) ) {
return $res;
}
//Retain the Original source and destinations
$remote_source = $args['source'];
$local_destination = $destination;
$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.
if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents.
$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
} elseif ( count( $source_files ) == 0 ) {
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
} else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename.
$source = trailingslashit( $args['source'] );
}
/**
* Filters the source file location for the upgrade package.
*
* @since 2.8.0
* @since 4.4.0 The $hook_extra parameter became available.
*
* @param string $source File source location.
* @param string $remote_source Remote file source location.
* @param WP_Upgrader $this WP_Upgrader instance.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
if ( is_wp_error( $source ) ) {
return $source;
}
// Has the source location changed? If so, we need a new source_files list.
if ( $source !== $remote_source ) {
$source_files = array_keys( $wp_filesystem->dirlist( $source ) );
}
/*
* Protection against deleting files in any important base directories.
* Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
* destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
* to copy the directory into the directory, whilst they pass the source
* as the actual files to copy.
*/
$protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
if ( is_array( $wp_theme_directories ) ) {
$protected_directories = array_merge( $protected_directories, $wp_theme_directories );
}
if ( in_array( $destination, $protected_directories ) ) {
$remote_destination = trailingslashit( $remote_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' );
$removed = $this->clear_destination( $remote_destination );
/**
* Filters whether the upgrader cleared the destination.
*
* @since 2.8.0
*
* @param mixed $removed Whether the destination was cleared. true on success, WP_Error on failure
* @param string $local_destination The local package destination.
* @param string $remote_destination The remote package destination.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
if ( is_wp_error( $removed ) ) {
return $removed;
}
} 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 );
}
}
//Create destination if needed
if ( ! $wp_filesystem->exists( $remote_destination ) ) {
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
}
}
// Copy new version of item into place.
$result = copy_dir( $source, $remote_destination );
if ( is_wp_error( $result ) ) {
if ( $args['clear_working'] ) {
$wp_filesystem->delete( $remote_source, true );
}
return $result;
}
//Clear the Working folder?
if ( $args['clear_working'] ) {
$wp_filesystem->delete( $remote_source, true );
}
$destination_name = basename( str_replace( $local_destination, '', $destination ) );
if ( '.' == $destination_name ) {
$destination_name = '';
}
$this->result = compact( 'source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination' );
/**
* Filters the installation response after the installation has finished.
*
* @since 2.8.0
*
* @param bool $response Installation response.
* @param array $hook_extra Extra arguments passed to hooked filters.
* @param array $result Installation result data.
*/
$res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
if ( is_wp_error( $res ) ) {
$this->result = $res;
return $res;
}
//Bombard the calling function will all the info which we've just used.
return $this->result;
}
/**
* Run an upgrade/installation.
*
* Attempts to download the package (if it is not a local file), unpack it, and
* install it in the destination folder.
*
* @since 2.8.0
*
* @param array $options {
* Array or string of arguments for upgrading/installing a package.
*
* @type string $package The full path or URI of the package to install.
* Default empty.
* @type string $destination The full path to the destination folder.
* Default empty.
* @type bool $clear_destination Whether to delete any files already in the
* destination folder. Default false.
* @type bool $clear_working Whether to delete the files form the working
* directory after copying to the destination.
* Default false.
* @type bool $abort_if_destination_exists Whether to abort the installation if the destination
* folder already exists. When true, `$clear_destination`
* should be false. Default true.
* @type bool $is_multi Whether this run is one of multiple upgrade/installation
* actions being performed in bulk. When true, the skin
* WP_Upgrader::header() and WP_Upgrader::footer()
* aren't called. Default false.
* @type array $hook_extra Extra arguments to pass to the filter hooks called by
* WP_Upgrader::run().
* }
* @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error,
* or false if unable to connect to the filesystem.
*/
public function run( $options ) {
$defaults = array(
'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.
);
$options = wp_parse_args( $options, $defaults );
/**
* Filters the package options before running an update.
*
* See also {@see 'upgrader_process_complete'}.
*
* @since 4.3.0
*
* @param array $options {
* Options used by the upgrader.
*
* @type string $package Package for update.
* @type string $destination Update location.
* @type bool $clear_destination Clear the destination resource.
* @type bool $clear_working Clear the working resource.
* @type bool $abort_if_destination_exists Abort if the Destination directory exists.
* @type bool $is_multi Whether the upgrader is running multiple times.
* @type array $hook_extra {
* Extra hook arguments.
*
* @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 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'.
* @type object $language_update The language pack update offer.
* }
* }
*/
$options = apply_filters( 'upgrader_package_options', $options );
if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times
$this->skin->header();
}
// Connect to the Filesystem first.
$res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) );
// Mainly for non-connected filesystem.
if ( ! $res ) {
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return false;
}
$this->skin->before();
if ( is_wp_error( $res ) ) {
$this->skin->error( $res );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return $res;
}
/*
* Download the package (Note, This just returns the filename
* 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 );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return $download;
}
$delete_package = ( $download != $options['package'] ); // Do not delete a "local" file
// 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 );
$this->skin->after();
if ( ! $options['is_multi'] ) {
$this->skin->footer();
}
return $working_dir;
}
// 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'],
)
);
$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->after();
if ( ! $options['is_multi'] ) {
/**
* Fires when the upgrader process is complete.
*
* See also {@see 'upgrader_package_options'}.
*
* @since 3.6.0
* @since 3.7.0 Added to WP_Upgrader::run().
* @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`.
*
* @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a
* Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
* @param array $hook_extra {
* Array of bulk item update data.
*
* @type string $action Type of action. Default 'update'.
* @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'.
* @type bool $bulk Whether the update process is a bulk update. Default true.
* @type array $plugins Array of the basename paths of the plugins' main files.
* @type array $themes The theme slugs.
* @type array $translations {
* Array of translations update data.
*
* @type string $language The locale the translation is for.
* @type string $type Type of translation. Accepts 'plugin', 'theme', or 'core'.
* @type string $slug Text domain the translation is for. The slug of a theme/plugin or
* 'default' for core translations.
* @type string $version The version of a theme, plugin, or core.
* }
* }
*/
do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
$this->skin->footer();
}
return $result;
}
/**
* Toggle maintenance mode for the site.
*
* Creates/deletes the maintenance file to enable/disable maintenance mode.
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
*
* @param bool $enable True to enable maintenance mode, false to disable.
*/
public function maintenance_mode( $enable = false ) {
global $wp_filesystem;
$file = $wp_filesystem->abspath() . '.maintenance';
if ( $enable ) {
$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 );
} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
$this->skin->feedback( 'maintenance_end' );
$wp_filesystem->delete( $file );
}
}
/**
* 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.
*/
public static function create_lock( $lock_name, $release_timeout = null ) {
global $wpdb;
if ( ! $release_timeout ) {
$release_timeout = HOUR_IN_SECONDS;
}
$lock_option = $lock_name . '.lock';
// Try to lock.
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time() ) );
if ( ! $lock_result ) {
$lock_result = get_option( $lock_option );
// If a lock couldn't be created, and there isn't a lock, bail.
if ( ! $lock_result ) {
return false;
}
// Check to see if the lock is still valid. If it is, bail.
if ( $lock_result > ( time() - $release_timeout ) ) {
return false;
}
// There must exist an expired lock, clear it and re-gain it.
WP_Upgrader::release_lock( $lock_name );
return WP_Upgrader::create_lock( $lock_name, $release_timeout );
}
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
update_option( $lock_option, time() );
return true;
}
/**
* Releases an upgrader lock.
*
* @since 4.5.0
*
* @see WP_Upgrader::create_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' );
}
}
/** Plugin_Upgrader class */
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
/** Theme_Upgrader class */
require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader.php';
/** Language_Pack_Upgrader class */
require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader.php';
/** Core_Upgrader class */
require_once ABSPATH . 'wp-admin/includes/class-core-upgrader.php';
/** File_Upload_Upgrader class */
require_once ABSPATH . 'wp-admin/includes/class-file-upload-upgrader.php';
/** WP_Automatic_Updater class */
require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';

View File

@ -0,0 +1,602 @@
<?php
/**
* List Table API: WP_Users_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying users in a list table.
*
* @since 3.1.0
* @access private
*
* @see WP_List_Table
*/
class WP_Users_List_Table extends WP_List_Table {
/**
* Site ID to generate the Users list table for.
*
* @since 3.1.0
* @var int
*/
public $site_id;
/**
* Whether or not the current Users list table is for Multisite.
*
* @since 3.1.0
* @var bool
*/
public $is_site_users;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
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 ) {
$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
}
}
/**
* Check the current user's permissions.
*
* @since 3.1.0
*
* @return bool
*/
public function ajax_user_can() {
if ( $this->is_site_users ) {
return current_user_can( 'manage_sites' );
} else {
return current_user_can( 'list_users' );
}
}
/**
* Prepare the users list for display.
*
* @since 3.1.0
*
* @global string $role
* @global string $usersearch
*/
public function prepare_items() {
global $role, $usersearch;
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
$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,
'include' => wp_get_users_with_no_role( $this->site_id ),
'search' => $usersearch,
'fields' => 'all_with_meta',
);
} else {
$args = array(
'number' => $users_per_page,
'offset' => ( $paged - 1 ) * $users_per_page,
'role' => $role,
'search' => $usersearch,
'fields' => 'all_with_meta',
);
}
if ( '' !== $args['search'] ) {
$args['search'] = '*' . $args['search'] . '*';
}
if ( $this->is_site_users ) {
$args['blog_id'] = $this->site_id;
}
if ( isset( $_REQUEST['orderby'] ) ) {
$args['orderby'] = $_REQUEST['orderby'];
}
if ( isset( $_REQUEST['order'] ) ) {
$args['order'] = $_REQUEST['order'];
}
/**
* Filters the query arguments used to retrieve users for the current users list table.
*
* @since 4.4.0
*
* @param array $args Arguments passed to WP_User_Query to retrieve items for the current
* users list table.
*/
$args = apply_filters( 'users_list_table_query_args', $args );
// Query the user IDs for this page
$wp_user_search = new WP_User_Query( $args );
$this->items = $wp_user_search->get_results();
$this->set_pagination_args(
array(
'total_items' => $wp_user_search->get_total(),
'per_page' => $users_per_page,
)
);
}
/**
* Output 'no users' message.
*
* @since 3.1.0
*/
public function no_items() {
_e( 'No users found.' );
}
/**
* Return an associative array listing all the views that can be used
* with this table.
*
* Provides a list of roles and user count for that role for easy
* Filtersing of the user table.
*
* @since 3.1.0
*
* @global string $role
*
* @return array An array of HTML links, one for each view.
*/
protected function get_views() {
global $role;
$wp_roles = wp_roles();
if ( $this->is_site_users ) {
$url = 'site-users.php?id=' . $this->site_id;
switch_to_blog( $this->site_id );
$users_of_blog = count_users( 'time', $this->site_id );
restore_current_blog();
} else {
$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 );
$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
$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 ] ) ) {
continue;
}
$current_link_attributes = '';
if ( $this_role === $role ) {
$current_link_attributes = ' class="current" aria-current="page"';
}
$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>";
}
if ( ! empty( $avail_roles['none'] ) ) {
$current_link_attributes = '';
if ( 'none' === $role ) {
$current_link_attributes = ' class="current" aria-current="page"';
}
$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'] ) );
$role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$current_link_attributes>$name</a>";
}
return $role_links;
}
/**
* Retrieve an associative array of bulk actions available on this table.
*
* @since 3.1.0
*
* @return array Array of bulk actions.
*/
protected function get_bulk_actions() {
$actions = array();
if ( is_multisite() ) {
if ( current_user_can( 'remove_users' ) ) {
$actions['remove'] = __( 'Remove' );
}
} else {
if ( current_user_can( 'delete_users' ) ) {
$actions['delete'] = __( 'Delete' );
}
}
return $actions;
}
/**
* Output the controls to allow user roles to be changed in bulk.
*
* @since 3.1.0
*
* @param string $which Whether this is being invoked above ("top")
* or below the table ("bottom").
*/
protected function extra_tablenav( $which ) {
$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>
<?php wp_dropdown_roles(); ?>
</select>
<?php
submit_button( __( 'Change' ), '', $button_id, false );
endif;
/**
* Fires just before the closing div containing the bulk role-change controls
* in the Users list table.
*
* @since 3.5.0
* @since 4.6.0 The `$which` parameter was added.
*
* @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
*/
do_action( 'restrict_manage_users', $which );
?>
</div>
<?php
/**
* Fires immediately following the closing "actions" div in the tablenav for the users
* list table.
*
* @since 4.9.0
*
* @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
*/
do_action( 'manage_users_extra_tablenav', $which );
}
/**
* Capture the bulk action required, and return it.
*
* Overridden from the base class implementation to capture
* the role change drop-down.
*
* @since 3.1.0
*
* @return string The bulk action required.
*/
public function current_action() {
if ( ( isset( $_REQUEST['changeit'] ) || isset( $_REQUEST['changeit2'] ) ) &&
( ! empty( $_REQUEST['new_role'] ) || ! empty( $_REQUEST['new_role2'] ) ) ) {
return 'promote';
}
return parent::current_action();
}
/**
* Get a list of columns for the list table.
*
* @since 3.1.0
*
* @return array Array in which the key is the ID of the column,
* and the value is the description.
*/
public function get_columns() {
$c = array(
'cb' => '<input type="checkbox" />',
'username' => __( 'Username' ),
'name' => __( 'Name' ),
'email' => __( 'Email' ),
'role' => __( 'Role' ),
'posts' => __( 'Posts' ),
);
if ( $this->is_site_users ) {
unset( $c['posts'] );
}
return $c;
}
/**
* Get a list of sortable columns for the list table.
*
* @since 3.1.0
*
* @return array Array of sortable columns.
*/
protected function get_sortable_columns() {
$c = array(
'username' => 'login',
'email' => 'email',
);
return $c;
}
/**
* Generate the list table rows.
*
* @since 3.1.0
*/
public function display_rows() {
// Query the post counts for this page
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 );
}
}
/**
* Generate HTML for a single row on the users.php admin panel.
*
* @since 3.1.0
* @since 4.2.0 The `$style` parameter was deprecated.
* @since 4.4.0 The `$role` parameter was deprecated.
*
* @param WP_User $user_object The current user object.
* @param string $style Deprecated. Not used.
* @param string $role Deprecated. Not used.
* @param int $numposts Optional. Post count to display for this user. Defaults
* to zero, as in, a new user has made zero posts.
* @return string Output for a single row.
*/
public function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
if ( ! ( $user_object instanceof WP_User ) ) {
$user_object = get_userdata( (int) $user_object );
}
$user_object->filter = 'display';
$email = $user_object->user_email;
if ( $this->is_site_users ) {
$url = "site-users.php?id={$this->site_id}&amp;";
} else {
$url = 'users.php?';
}
$user_roles = $this->get_role_list( $user_object );
// Set up the hover actions for this user
$actions = array();
$checkbox = '';
$super_admin = '';
if ( is_multisite() && current_user_can( 'manage_network_users' ) ) {
if ( in_array( $user_object->user_login, get_super_admins(), true ) ) {
$super_admin = ' &mdash; ' . __( 'Super Admin' );
}
}
// Check if the user for this row is editable
if ( current_user_can( 'list_users' ) ) {
// 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 />";
$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>';
}
// Add a link to the user's author archive, if not empty.
$author_posts_url = get_author_posts_url( $user_object->ID );
if ( $author_posts_url ) {
$actions['view'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
esc_url( $author_posts_url ),
/* translators: %s: author's display name */
esc_attr( sprintf( __( 'View posts by %s' ), $user_object->display_name ) ),
__( 'View' )
);
}
/**
* Filters the action links displayed under each user in the Users list table.
*
* @since 2.8.0
*
* @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 );
// Role classes.
$role_classes = esc_attr( implode( ' ', array_keys( $user_roles ) ) );
// Set up the checkbox ( because the user is editable, otherwise it's empty )
$checkbox = '<label class="screen-reader-text" for="user_' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>'
. "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='{$role_classes}' value='{$user_object->ID}' />";
} else {
$edit = "<strong>{$user_object->user_login}{$super_admin}</strong>";
}
$avatar = get_avatar( $user_object->ID, 32 );
// Comma-separated list of user roles.
$roles_list = implode( ', ', $user_roles );
$r = "<tr id='user-$user_object->ID'>";
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
$classes = "$column_name column-$column_name";
if ( $primary === $column_name ) {
$classes .= ' has-row-actions column-primary';
}
if ( 'posts' === $column_name ) {
$classes .= ' num'; // Special case for that column
}
if ( in_array( $column_name, $hidden ) ) {
$classes .= ' hidden';
}
$data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
$attributes = "class='$classes' $data";
if ( 'cb' === $column_name ) {
$r .= "<th scope='row' class='check-column'>$checkbox</th>";
} else {
$r .= "<td $attributes>";
switch ( $column_name ) {
case 'username':
$r .= "$avatar $edit";
break;
case 'name':
if ( $user_object->first_name && $user_object->last_name ) {
$r .= "$user_object->first_name $user_object->last_name";
} elseif ( $user_object->first_name ) {
$r .= $user_object->first_name;
} elseif ( $user_object->last_name ) {
$r .= $user_object->last_name;
} else {
$r .= '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . _x( 'Unknown', 'name' ) . '</span>';
}
break;
case 'email':
$r .= "<a href='" . esc_url( "mailto:$email" ) . "'>$email</a>";
break;
case 'role':
$r .= esc_html( $roles_list );
break;
case 'posts':
if ( $numposts > 0 ) {
$r .= "<a href='edit.php?author=$user_object->ID' class='edit'>";
$r .= '<span aria-hidden="true">' . $numposts . '</span>';
$r .= '<span class="screen-reader-text">' . sprintf( _n( '%s post by this author', '%s posts by this author', $numposts ), number_format_i18n( $numposts ) ) . '</span>';
$r .= '</a>';
} else {
$r .= 0;
}
break;
default:
/**
* Filters the display output of custom columns in the Users list table.
*
* @since 2.8.0
*
* @param string $output Custom column output. Default empty.
* @param string $column_name Column name.
* @param int $user_id ID of the currently-listed user.
*/
$r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
}
if ( $primary === $column_name ) {
$r .= $this->row_actions( $actions );
}
$r .= '</td>';
}
}
$r .= '</tr>';
return $r;
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'username'.
*/
protected function get_default_primary_column_name() {
return 'username';
}
/**
* Returns an array of user roles for a given user object.
*
* @since 4.4.0
*
* @param WP_User $user_object The WP_User object.
* @return string[] An array of user roles.
*/
protected function get_role_list( $user_object ) {
$wp_roles = wp_roles();
$role_list = array();
foreach ( $user_object->roles as $role ) {
if ( isset( $wp_roles->role_names[ $role ] ) ) {
$role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] );
}
}
if ( empty( $role_list ) ) {
$role_list['none'] = _x( 'None', 'no user roles' );
}
/**
* Filters the returned array of roles for a user.
*
* @since 4.4.0
*
* @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

@ -0,0 +1,212 @@
<?php
/**
* WordPress Comment Administration API.
*
* @package WordPress
* @subpackage Administration
* @since 2.3.0
*/
/**
* Determine if a comment exists based on author and date.
*
* For best performance, use `$timezone = 'gmt'`, which queries a field that is properly indexed. The default value
* for `$timezone` is 'blog' for legacy reasons.
*
* @since 2.0.0
* @since 4.4.0 Added the `$timezone` parameter.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $comment_author Author of the comment.
* @param string $comment_date Date of the comment.
* @param string $timezone Timezone. Accepts 'blog' or 'gmt'. Default 'blog'.
*
* @return mixed Comment post ID on success.
*/
function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
global $wpdb;
$date_field = 'comment_date';
if ( 'gmt' === $timezone ) {
$date_field = 'comment_date_gmt';
}
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 )
)
);
}
/**
* Update a comment with values provided in $_POST.
*
* @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 ( isset( $_POST['newcomment_author'] ) ) {
$_POST['comment_author'] = $_POST['newcomment_author'];
}
if ( isset( $_POST['newcomment_author_email'] ) ) {
$_POST['comment_author_email'] = $_POST['newcomment_author_email'];
}
if ( isset( $_POST['newcomment_author_url'] ) ) {
$_POST['comment_author_url'] = $_POST['newcomment_author_url'];
}
if ( isset( $_POST['comment_status'] ) ) {
$_POST['comment_approved'] = $_POST['comment_status'];
}
if ( isset( $_POST['content'] ) ) {
$_POST['comment_content'] = $_POST['content'];
}
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 ] ) {
$_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;
$_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
}
wp_update_comment( $_POST );
}
/**
* Returns a WP_Comment object based on comment ID.
*
* @since 2.0.0
*
* @param int $id ID of comment to retrieve.
* @return WP_Comment|false Comment if found. False on failure.
*/
function get_comment_to_edit( $id ) {
if ( ! $comment = get_comment( $id ) ) {
return false;
}
$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 );
/**
* Filters the comment content before editing.
*
* @since 2.0.0
*
* @param string $comment->comment_content Comment content.
*/
$comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
$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 );
return $comment;
}
/**
* Get the number of pending comments on a post or posts
*
* @since 2.3.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int|array $post_id Either a single Post ID or an array of Post IDs
* @return int|array Either a single Posts pending comments as an int or an array of ints keyed on the Post IDs
*/
function get_pending_comments_num( $post_id ) {
global $wpdb;
$single = false;
if ( ! is_array( $post_id ) ) {
$post_id_array = (array) $post_id;
$single = true;
} else {
$post_id_array = $post_id;
}
$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 ) ) {
return 0;
} 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;
}
if ( ! empty( $pending ) ) {
foreach ( $pending as $pend ) {
$pending_keyed[ $pend['comment_post_ID'] ] = absint( $pend['num_comments'] );
}
}
return $pending_keyed;
}
/**
* Add avatars to relevant places in admin, or try to.
*
* @since 2.5.0
*
* @param string $name User name.
* @return string Avatar with Admin name.
*/
function floated_admin_avatar( $name ) {
$avatar = get_avatar( get_comment(), 32, 'mystery' );
return "$avatar $name";
}
/**
* @since 2.7.0
*/
function enqueue_comment_hotkeys_js() {
if ( 'true' == get_user_option( 'comment_shortcuts' ) ) {
wp_enqueue_script( 'jquery-table-hotkeys' );
}
}
/**
* Display error message at bottom of comments.
*
* @param string $msg Error Message. Assumed to contain HTML and be sanitized.
*/
function comment_footer_die( $msg ) {
echo "<div class='wrap'><p>$msg</p></div>";
include( ABSPATH . 'wp-admin/admin-footer.php' );
die;
}

View File

@ -0,0 +1,554 @@
<?php
/**
* Translation API: Continent and city translations for timezone selection
*
* This file is not included anywhere. It exists solely for use by xgettext.
*
* @package WordPress
* @subpackage i18n
* @since 2.8.0
*/
__( 'Africa', 'continents-cities' );
__( 'Abidjan', 'continents-cities' );
__( 'Accra', 'continents-cities' );
__( 'Addis Ababa', 'continents-cities' );
__( 'Algiers', 'continents-cities' );
__( 'Asmara', 'continents-cities' );
__( 'Asmera', 'continents-cities' );
__( 'Bamako', 'continents-cities' );
__( 'Bangui', 'continents-cities' );
__( 'Banjul', 'continents-cities' );
__( 'Bissau', 'continents-cities' );
__( 'Blantyre', 'continents-cities' );
__( 'Brazzaville', 'continents-cities' );
__( 'Bujumbura', 'continents-cities' );
__( 'Cairo', 'continents-cities' );
__( 'Casablanca', 'continents-cities' );
__( 'Ceuta', 'continents-cities' );
__( 'Conakry', 'continents-cities' );
__( 'Dakar', 'continents-cities' );
__( 'Dar es Salaam', 'continents-cities' );
__( 'Djibouti', 'continents-cities' );
__( 'Douala', 'continents-cities' );
__( 'El Aaiun', 'continents-cities' );
__( 'Freetown', 'continents-cities' );
__( 'Gaborone', 'continents-cities' );
__( 'Harare', 'continents-cities' );
__( 'Johannesburg', 'continents-cities' );
__( 'Juba', 'continents-cities' );
__( 'Kampala', 'continents-cities' );
__( 'Khartoum', 'continents-cities' );
__( 'Kigali', 'continents-cities' );
__( 'Kinshasa', 'continents-cities' );
__( 'Lagos', 'continents-cities' );
__( 'Libreville', 'continents-cities' );
__( 'Lome', 'continents-cities' );
__( 'Luanda', 'continents-cities' );
__( 'Lubumbashi', 'continents-cities' );
__( 'Lusaka', 'continents-cities' );
__( 'Malabo', 'continents-cities' );
__( 'Maputo', 'continents-cities' );
__( 'Maseru', 'continents-cities' );
__( 'Mbabane', 'continents-cities' );
__( 'Mogadishu', 'continents-cities' );
__( 'Monrovia', 'continents-cities' );
__( 'Nairobi', 'continents-cities' );
__( 'Ndjamena', 'continents-cities' );
__( 'Niamey', 'continents-cities' );
__( 'Nouakchott', 'continents-cities' );
__( 'Ouagadougou', 'continents-cities' );
__( 'Porto-Novo', 'continents-cities' );
__( 'Sao Tome', 'continents-cities' );
__( 'Timbuktu', 'continents-cities' );
__( 'Tripoli', 'continents-cities' );
__( 'Tunis', 'continents-cities' );
__( 'Windhoek', 'continents-cities' );
__( 'America', 'continents-cities' );
__( 'Adak', 'continents-cities' );
__( 'Anchorage', 'continents-cities' );
__( 'Anguilla', 'continents-cities' );
__( 'Antigua', 'continents-cities' );
__( 'Araguaina', 'continents-cities' );
__( 'Argentina', 'continents-cities' );
__( 'Buenos Aires', 'continents-cities' );
__( 'Catamarca', 'continents-cities' );
__( 'ComodRivadavia', 'continents-cities' );
__( 'Cordoba', 'continents-cities' );
__( 'Jujuy', 'continents-cities' );
__( 'La Rioja', 'continents-cities' );
__( 'Mendoza', 'continents-cities' );
__( 'Rio Gallegos', 'continents-cities' );
__( 'Salta', 'continents-cities' );
__( 'San Juan', 'continents-cities' );
__( 'San Luis', 'continents-cities' );
__( 'Tucuman', 'continents-cities' );
__( 'Ushuaia', 'continents-cities' );
__( 'Aruba', 'continents-cities' );
__( 'Asuncion', 'continents-cities' );
__( 'Atikokan', 'continents-cities' );
__( 'Atka', 'continents-cities' );
__( 'Bahia', 'continents-cities' );
__( 'Bahia Banderas', 'continents-cities' );
__( 'Barbados', 'continents-cities' );
__( 'Belem', 'continents-cities' );
__( 'Belize', 'continents-cities' );
__( 'Blanc-Sablon', 'continents-cities' );
__( 'Boa Vista', 'continents-cities' );
__( 'Bogota', 'continents-cities' );
__( 'Boise', 'continents-cities' );
__( 'Buenos Aires', 'continents-cities' );
__( 'Cambridge Bay', 'continents-cities' );
__( 'Campo Grande', 'continents-cities' );
__( 'Cancun', 'continents-cities' );
__( 'Caracas', 'continents-cities' );
__( 'Catamarca', 'continents-cities' );
__( 'Cayenne', 'continents-cities' );
__( 'Cayman', 'continents-cities' );
__( 'Chicago', 'continents-cities' );
__( 'Chihuahua', 'continents-cities' );
__( 'Coral Harbour', 'continents-cities' );
__( 'Cordoba', 'continents-cities' );
__( 'Costa Rica', 'continents-cities' );
__( 'Creston', 'continents-cities' );
__( 'Cuiaba', 'continents-cities' );
__( 'Curacao', 'continents-cities' );
__( 'Danmarkshavn', 'continents-cities' );
__( 'Dawson', 'continents-cities' );
__( 'Dawson Creek', 'continents-cities' );
__( 'Denver', 'continents-cities' );
__( 'Detroit', 'continents-cities' );
__( 'Dominica', 'continents-cities' );
__( 'Edmonton', 'continents-cities' );
__( 'Eirunepe', 'continents-cities' );
__( 'El Salvador', 'continents-cities' );
__( 'Ensenada', 'continents-cities' );
__( 'Fort Nelson', 'continents-cities' );
__( 'Fort Wayne', 'continents-cities' );
__( 'Fortaleza', 'continents-cities' );
__( 'Glace Bay', 'continents-cities' );
__( 'Godthab', 'continents-cities' );
__( 'Goose Bay', 'continents-cities' );
__( 'Grand Turk', 'continents-cities' );
__( 'Grenada', 'continents-cities' );
__( 'Guadeloupe', 'continents-cities' );
__( 'Guatemala', 'continents-cities' );
__( 'Guayaquil', 'continents-cities' );
__( 'Guyana', 'continents-cities' );
__( 'Halifax', 'continents-cities' );
__( 'Havana', 'continents-cities' );
__( 'Hermosillo', 'continents-cities' );
__( 'Indiana', 'continents-cities' );
__( 'Indianapolis', 'continents-cities' );
__( 'Knox', 'continents-cities' );
__( 'Marengo', 'continents-cities' );
__( 'Petersburg', 'continents-cities' );
__( 'Tell City', 'continents-cities' );
__( 'Vevay', 'continents-cities' );
__( 'Vincennes', 'continents-cities' );
__( 'Winamac', 'continents-cities' );
__( 'Indianapolis', 'continents-cities' );
__( 'Inuvik', 'continents-cities' );
__( 'Iqaluit', 'continents-cities' );
__( 'Jamaica', 'continents-cities' );
__( 'Jujuy', 'continents-cities' );
__( 'Juneau', 'continents-cities' );
__( 'Kentucky', 'continents-cities' );
__( 'Louisville', 'continents-cities' );
__( 'Monticello', 'continents-cities' );
__( 'Knox IN', 'continents-cities' );
__( 'Kralendijk', 'continents-cities' );
__( 'La Paz', 'continents-cities' );
__( 'Lima', 'continents-cities' );
__( 'Los Angeles', 'continents-cities' );
__( 'Louisville', 'continents-cities' );
__( 'Lower Princes', 'continents-cities' );
__( 'Maceio', 'continents-cities' );
__( 'Managua', 'continents-cities' );
__( 'Manaus', 'continents-cities' );
__( 'Marigot', 'continents-cities' );
__( 'Martinique', 'continents-cities' );
__( 'Matamoros', 'continents-cities' );
__( 'Mazatlan', 'continents-cities' );
__( 'Mendoza', 'continents-cities' );
__( 'Menominee', 'continents-cities' );
__( 'Merida', 'continents-cities' );
__( 'Metlakatla', 'continents-cities' );
__( 'Mexico City', 'continents-cities' );
__( 'Miquelon', 'continents-cities' );
__( 'Moncton', 'continents-cities' );
__( 'Monterrey', 'continents-cities' );
__( 'Montevideo', 'continents-cities' );
__( 'Montreal', 'continents-cities' );
__( 'Montserrat', 'continents-cities' );
__( 'Nassau', 'continents-cities' );
__( 'New York', 'continents-cities' );
__( 'Nipigon', 'continents-cities' );
__( 'Nome', 'continents-cities' );
__( 'Noronha', 'continents-cities' );
__( 'North Dakota', 'continents-cities' );
__( 'Beulah', 'continents-cities' );
__( 'Center', 'continents-cities' );
__( 'New Salem', 'continents-cities' );
__( 'Ojinaga', 'continents-cities' );
__( 'Panama', 'continents-cities' );
__( 'Pangnirtung', 'continents-cities' );
__( 'Paramaribo', 'continents-cities' );
__( 'Phoenix', 'continents-cities' );
__( 'Port of Spain', 'continents-cities' );
__( 'Port-au-Prince', 'continents-cities' );
__( 'Porto Acre', 'continents-cities' );
__( 'Porto Velho', 'continents-cities' );
__( 'Puerto Rico', 'continents-cities' );
__( 'Punta Arenas', 'continents-cities' );
__( 'Rainy River', 'continents-cities' );
__( 'Rankin Inlet', 'continents-cities' );
__( 'Recife', 'continents-cities' );
__( 'Regina', 'continents-cities' );
__( 'Resolute', 'continents-cities' );
__( 'Rio Branco', 'continents-cities' );
__( 'Rosario', 'continents-cities' );
__( 'Santa Isabel', 'continents-cities' );
__( 'Santarem', 'continents-cities' );
__( 'Santiago', 'continents-cities' );
__( 'Santo Domingo', 'continents-cities' );
__( 'Sao Paulo', 'continents-cities' );
__( 'Scoresbysund', 'continents-cities' );
__( 'Shiprock', 'continents-cities' );
__( 'Sitka', 'continents-cities' );
__( 'St Barthelemy', 'continents-cities' );
__( 'St Johns', 'continents-cities' );
__( 'St Kitts', 'continents-cities' );
__( 'St Lucia', 'continents-cities' );
__( 'St Thomas', 'continents-cities' );
__( 'St Vincent', 'continents-cities' );
__( 'Swift Current', 'continents-cities' );
__( 'Tegucigalpa', 'continents-cities' );
__( 'Thule', 'continents-cities' );
__( 'Thunder Bay', 'continents-cities' );
__( 'Tijuana', 'continents-cities' );
__( 'Toronto', 'continents-cities' );
__( 'Tortola', 'continents-cities' );
__( 'Vancouver', 'continents-cities' );
__( 'Virgin', 'continents-cities' );
__( 'Whitehorse', 'continents-cities' );
__( 'Winnipeg', 'continents-cities' );
__( 'Yakutat', 'continents-cities' );
__( 'Yellowknife', 'continents-cities' );
__( 'Antarctica', 'continents-cities' );
__( 'Casey', 'continents-cities' );
__( 'Davis', 'continents-cities' );
__( 'DumontDUrville', 'continents-cities' );
__( 'Macquarie', 'continents-cities' );
__( 'Mawson', 'continents-cities' );
__( 'McMurdo', 'continents-cities' );
__( 'Palmer', 'continents-cities' );
__( 'Rothera', 'continents-cities' );
__( 'South Pole', 'continents-cities' );
__( 'Syowa', 'continents-cities' );
__( 'Troll', 'continents-cities' );
__( 'Vostok', 'continents-cities' );
__( 'Arctic', 'continents-cities' );
__( 'Longyearbyen', 'continents-cities' );
__( 'Asia', 'continents-cities' );
__( 'Aden', 'continents-cities' );
__( 'Almaty', 'continents-cities' );
__( 'Amman', 'continents-cities' );
__( 'Anadyr', 'continents-cities' );
__( 'Aqtau', 'continents-cities' );
__( 'Aqtobe', 'continents-cities' );
__( 'Ashgabat', 'continents-cities' );
__( 'Ashkhabad', 'continents-cities' );
__( 'Atyrau', 'continents-cities' );
__( 'Baghdad', 'continents-cities' );
__( 'Bahrain', 'continents-cities' );
__( 'Baku', 'continents-cities' );
__( 'Bangkok', 'continents-cities' );
__( 'Barnaul', 'continents-cities' );
__( 'Beirut', 'continents-cities' );
__( 'Bishkek', 'continents-cities' );
__( 'Brunei', 'continents-cities' );
__( 'Calcutta', 'continents-cities' );
__( 'Chita', 'continents-cities' );
__( 'Choibalsan', 'continents-cities' );
__( 'Chongqing', 'continents-cities' );
__( 'Chungking', 'continents-cities' );
__( 'Colombo', 'continents-cities' );
__( 'Dacca', 'continents-cities' );
__( 'Damascus', 'continents-cities' );
__( 'Dhaka', 'continents-cities' );
__( 'Dili', 'continents-cities' );
__( 'Dubai', 'continents-cities' );
__( 'Dushanbe', 'continents-cities' );
__( 'Famagusta', 'continents-cities' );
__( 'Gaza', 'continents-cities' );
__( 'Harbin', 'continents-cities' );
__( 'Hebron', 'continents-cities' );
__( 'Ho Chi Minh', 'continents-cities' );
__( 'Hong Kong', 'continents-cities' );
__( 'Hovd', 'continents-cities' );
__( 'Irkutsk', 'continents-cities' );
__( 'Istanbul', 'continents-cities' );
__( 'Jakarta', 'continents-cities' );
__( 'Jayapura', 'continents-cities' );
__( 'Jerusalem', 'continents-cities' );
__( 'Kabul', 'continents-cities' );
__( 'Kamchatka', 'continents-cities' );
__( 'Karachi', 'continents-cities' );
__( 'Kashgar', 'continents-cities' );
__( 'Kathmandu', 'continents-cities' );
__( 'Katmandu', 'continents-cities' );
__( 'Khandyga', 'continents-cities' );
__( 'Kolkata', 'continents-cities' );
__( 'Krasnoyarsk', 'continents-cities' );
__( 'Kuala Lumpur', 'continents-cities' );
__( 'Kuching', 'continents-cities' );
__( 'Kuwait', 'continents-cities' );
__( 'Macao', 'continents-cities' );
__( 'Macau', 'continents-cities' );
__( 'Magadan', 'continents-cities' );
__( 'Makassar', 'continents-cities' );
__( 'Manila', 'continents-cities' );
__( 'Muscat', 'continents-cities' );
__( 'Nicosia', 'continents-cities' );
__( 'Novokuznetsk', 'continents-cities' );
__( 'Novosibirsk', 'continents-cities' );
__( 'Omsk', 'continents-cities' );
__( 'Oral', 'continents-cities' );
__( 'Phnom Penh', 'continents-cities' );
__( 'Pontianak', 'continents-cities' );
__( 'Pyongyang', 'continents-cities' );
__( 'Qatar', 'continents-cities' );
__( 'Qyzylorda', 'continents-cities' );
__( 'Rangoon', 'continents-cities' );
__( 'Riyadh', 'continents-cities' );
__( 'Saigon', 'continents-cities' );
__( 'Sakhalin', 'continents-cities' );
__( 'Samarkand', 'continents-cities' );
__( 'Seoul', 'continents-cities' );
__( 'Shanghai', 'continents-cities' );
__( 'Singapore', 'continents-cities' );
__( 'Srednekolymsk', 'continents-cities' );
__( 'Taipei', 'continents-cities' );
__( 'Tashkent', 'continents-cities' );
__( 'Tbilisi', 'continents-cities' );
__( 'Tehran', 'continents-cities' );
__( 'Tel Aviv', 'continents-cities' );
__( 'Thimbu', 'continents-cities' );
__( 'Thimphu', 'continents-cities' );
__( 'Tokyo', 'continents-cities' );
__( 'Tomsk', 'continents-cities' );
__( 'Ujung Pandang', 'continents-cities' );
__( 'Ulaanbaatar', 'continents-cities' );
__( 'Ulan Bator', 'continents-cities' );
__( 'Urumqi', 'continents-cities' );
__( 'Ust-Nera', 'continents-cities' );
__( 'Vientiane', 'continents-cities' );
__( 'Vladivostok', 'continents-cities' );
__( 'Yakutsk', 'continents-cities' );
__( 'Yangon', 'continents-cities' );
__( 'Yekaterinburg', 'continents-cities' );
__( 'Yerevan', 'continents-cities' );
__( 'Atlantic', 'continents-cities' );
__( 'Azores', 'continents-cities' );
__( 'Bermuda', 'continents-cities' );
__( 'Canary', 'continents-cities' );
__( 'Cape Verde', 'continents-cities' );
__( 'Faeroe', 'continents-cities' );
__( 'Faroe', 'continents-cities' );
__( 'Jan Mayen', 'continents-cities' );
__( 'Madeira', 'continents-cities' );
__( 'Reykjavik', 'continents-cities' );
__( 'South Georgia', 'continents-cities' );
__( 'St Helena', 'continents-cities' );
__( 'Stanley', 'continents-cities' );
__( 'Australia', 'continents-cities' );
__( 'ACT', 'continents-cities' );
__( 'Adelaide', 'continents-cities' );
__( 'Brisbane', 'continents-cities' );
__( 'Broken Hill', 'continents-cities' );
__( 'Canberra', 'continents-cities' );
__( 'Currie', 'continents-cities' );
__( 'Darwin', 'continents-cities' );
__( 'Eucla', 'continents-cities' );
__( 'Hobart', 'continents-cities' );
__( 'LHI', 'continents-cities' );
__( 'Lindeman', 'continents-cities' );
__( 'Lord Howe', 'continents-cities' );
__( 'Melbourne', 'continents-cities' );
__( 'NSW', 'continents-cities' );
__( 'North', 'continents-cities' );
__( 'Perth', 'continents-cities' );
__( 'Queensland', 'continents-cities' );
__( 'South', 'continents-cities' );
__( 'Sydney', 'continents-cities' );
__( 'Tasmania', 'continents-cities' );
__( 'Victoria', 'continents-cities' );
__( 'West', 'continents-cities' );
__( 'Yancowinna', 'continents-cities' );
__( 'Etc', 'continents-cities' );
__( 'GMT', 'continents-cities' );
__( 'GMT+0', 'continents-cities' );
__( 'GMT+1', 'continents-cities' );
__( 'GMT+10', 'continents-cities' );
__( 'GMT+11', 'continents-cities' );
__( 'GMT+12', 'continents-cities' );
__( 'GMT+2', 'continents-cities' );
__( 'GMT+3', 'continents-cities' );
__( 'GMT+4', 'continents-cities' );
__( 'GMT+5', 'continents-cities' );
__( 'GMT+6', 'continents-cities' );
__( 'GMT+7', 'continents-cities' );
__( 'GMT+8', 'continents-cities' );
__( 'GMT+9', 'continents-cities' );
__( 'GMT-0', 'continents-cities' );
__( 'GMT-1', 'continents-cities' );
__( 'GMT-10', 'continents-cities' );
__( 'GMT-11', 'continents-cities' );
__( 'GMT-12', 'continents-cities' );
__( 'GMT-13', 'continents-cities' );
__( 'GMT-14', 'continents-cities' );
__( 'GMT-2', 'continents-cities' );
__( 'GMT-3', 'continents-cities' );
__( 'GMT-4', 'continents-cities' );
__( 'GMT-5', 'continents-cities' );
__( 'GMT-6', 'continents-cities' );
__( 'GMT-7', 'continents-cities' );
__( 'GMT-8', 'continents-cities' );
__( 'GMT-9', 'continents-cities' );
__( 'GMT0', 'continents-cities' );
__( 'Greenwich', 'continents-cities' );
__( 'UCT', 'continents-cities' );
__( 'UTC', 'continents-cities' );
__( 'Universal', 'continents-cities' );
__( 'Zulu', 'continents-cities' );
__( 'Europe', 'continents-cities' );
__( 'Amsterdam', 'continents-cities' );
__( 'Andorra', 'continents-cities' );
__( 'Astrakhan', 'continents-cities' );
__( 'Athens', 'continents-cities' );
__( 'Belfast', 'continents-cities' );
__( 'Belgrade', 'continents-cities' );
__( 'Berlin', 'continents-cities' );
__( 'Bratislava', 'continents-cities' );
__( 'Brussels', 'continents-cities' );
__( 'Bucharest', 'continents-cities' );
__( 'Budapest', 'continents-cities' );
__( 'Busingen', 'continents-cities' );
__( 'Chisinau', 'continents-cities' );
__( 'Copenhagen', 'continents-cities' );
__( 'Dublin', 'continents-cities' );
__( 'Gibraltar', 'continents-cities' );
__( 'Guernsey', 'continents-cities' );
__( 'Helsinki', 'continents-cities' );
__( 'Isle of Man', 'continents-cities' );
__( 'Istanbul', 'continents-cities' );
__( 'Jersey', 'continents-cities' );
__( 'Kaliningrad', 'continents-cities' );
__( 'Kiev', 'continents-cities' );
__( 'Kirov', 'continents-cities' );
__( 'Lisbon', 'continents-cities' );
__( 'Ljubljana', 'continents-cities' );
__( 'London', 'continents-cities' );
__( 'Luxembourg', 'continents-cities' );
__( 'Madrid', 'continents-cities' );
__( 'Malta', 'continents-cities' );
__( 'Mariehamn', 'continents-cities' );
__( 'Minsk', 'continents-cities' );
__( 'Monaco', 'continents-cities' );
__( 'Moscow', 'continents-cities' );
__( 'Nicosia', 'continents-cities' );
__( 'Oslo', 'continents-cities' );
__( 'Paris', 'continents-cities' );
__( 'Podgorica', 'continents-cities' );
__( 'Prague', 'continents-cities' );
__( 'Riga', 'continents-cities' );
__( 'Rome', 'continents-cities' );
__( 'Samara', 'continents-cities' );
__( 'San Marino', 'continents-cities' );
__( 'Sarajevo', 'continents-cities' );
__( 'Saratov', 'continents-cities' );
__( 'Simferopol', 'continents-cities' );
__( 'Skopje', 'continents-cities' );
__( 'Sofia', 'continents-cities' );
__( 'Stockholm', 'continents-cities' );
__( 'Tallinn', 'continents-cities' );
__( 'Tirane', 'continents-cities' );
__( 'Tiraspol', 'continents-cities' );
__( 'Ulyanovsk', 'continents-cities' );
__( 'Uzhgorod', 'continents-cities' );
__( 'Vaduz', 'continents-cities' );
__( 'Vatican', 'continents-cities' );
__( 'Vienna', 'continents-cities' );
__( 'Vilnius', 'continents-cities' );
__( 'Volgograd', 'continents-cities' );
__( 'Warsaw', 'continents-cities' );
__( 'Zagreb', 'continents-cities' );
__( 'Zaporozhye', 'continents-cities' );
__( 'Zurich', 'continents-cities' );
__( 'Indian', 'continents-cities' );
__( 'Antananarivo', 'continents-cities' );
__( 'Chagos', 'continents-cities' );
__( 'Christmas', 'continents-cities' );
__( 'Cocos', 'continents-cities' );
__( 'Comoro', 'continents-cities' );
__( 'Kerguelen', 'continents-cities' );
__( 'Mahe', 'continents-cities' );
__( 'Maldives', 'continents-cities' );
__( 'Mauritius', 'continents-cities' );
__( 'Mayotte', 'continents-cities' );
__( 'Reunion', 'continents-cities' );
__( 'Pacific', 'continents-cities' );
__( 'Apia', 'continents-cities' );
__( 'Auckland', 'continents-cities' );
__( 'Bougainville', 'continents-cities' );
__( 'Chatham', 'continents-cities' );
__( 'Chuuk', 'continents-cities' );
__( 'Easter', 'continents-cities' );
__( 'Efate', 'continents-cities' );
__( 'Enderbury', 'continents-cities' );
__( 'Fakaofo', 'continents-cities' );
__( 'Fiji', 'continents-cities' );
__( 'Funafuti', 'continents-cities' );
__( 'Galapagos', 'continents-cities' );
__( 'Gambier', 'continents-cities' );
__( 'Guadalcanal', 'continents-cities' );
__( 'Guam', 'continents-cities' );
__( 'Honolulu', 'continents-cities' );
__( 'Johnston', 'continents-cities' );
__( 'Kiritimati', 'continents-cities' );
__( 'Kosrae', 'continents-cities' );
__( 'Kwajalein', 'continents-cities' );
__( 'Majuro', 'continents-cities' );
__( 'Marquesas', 'continents-cities' );
__( 'Midway', 'continents-cities' );
__( 'Nauru', 'continents-cities' );
__( 'Niue', 'continents-cities' );
__( 'Norfolk', 'continents-cities' );
__( 'Noumea', 'continents-cities' );
__( 'Pago Pago', 'continents-cities' );
__( 'Palau', 'continents-cities' );
__( 'Pitcairn', 'continents-cities' );
__( 'Pohnpei', 'continents-cities' );
__( 'Ponape', 'continents-cities' );
__( 'Port Moresby', 'continents-cities' );
__( 'Rarotonga', 'continents-cities' );
__( 'Saipan', 'continents-cities' );
__( 'Samoa', 'continents-cities' );
__( 'Tahiti', 'continents-cities' );
__( 'Tarawa', 'continents-cities' );
__( 'Tongatapu', 'continents-cities' );
__( 'Truk', 'continents-cities' );
__( 'Wake', 'continents-cities' );
__( 'Wallis', 'continents-cities' );
__( 'Yap', 'continents-cities' );

View File

@ -0,0 +1,78 @@
<?php
/**
* WordPress Credits Administration API.
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Retrieve the contributor credits.
*
* @since 3.2.0
*
* @return array|false A list of all of the contributors, or false on error.
*/
function wp_credits() {
// include an unmodified $wp_version
include( ABSPATH . WPINC . '/version.php' );
$locale = get_user_locale();
$results = get_site_transient( 'wordpress_credits_' . $locale );
if ( ! is_array( $results )
|| 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}";
$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 );
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 ) ) {
return false;
}
set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
}
return $results;
}
/**
* Retrieve the link to a contributor's WordPress.org profile page.
*
* @access private
* @since 3.2.0
*
* @param string $display_name The contributor's display name (passed by reference).
* @param string $username The contributor's username.
* @param string $profiles URL to the contributor's WordPress.org profile page.
*/
function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
$display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>';
}
/**
* Retrieve the link to an external library used in WordPress.
*
* @access private
* @since 3.2.0
*
* @param string $data External library data (passed by reference).
*/
function _wp_credits_build_object_link( &$data ) {
$data = '<a href="' . esc_url( $data[1] ) . '">' . esc_html( $data[0] ) . '</a>';
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
<?php
/**
* Edit Tags Administration: Messages
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
$messages = array();
// 0 = unused. Messages start at index 1.
$messages['_item'] = array(
0 => '',
1 => __( 'Item added.' ),
2 => __( 'Item deleted.' ),
3 => __( 'Item updated.' ),
4 => __( 'Item not added.' ),
5 => __( 'Item not updated.' ),
6 => __( 'Items deleted.' ),
);
$messages['category'] = array(
0 => '',
1 => __( 'Category added.' ),
2 => __( 'Category deleted.' ),
3 => __( 'Category updated.' ),
4 => __( 'Category not added.' ),
5 => __( 'Category not updated.' ),
6 => __( 'Categories deleted.' ),
);
$messages['post_tag'] = array(
0 => '',
1 => __( 'Tag added.' ),
2 => __( 'Tag deleted.' ),
3 => __( 'Tag updated.' ),
4 => __( 'Tag not added.' ),
5 => __( 'Tag not updated.' ),
6 => __( 'Tags deleted.' ),
);
/**
* Filters the messages displayed when a tag is updated.
*
* @since 3.7.0
*
* @param array $messages The messages to be displayed.
*/
$messages = apply_filters( 'term_updated_messages', $messages );
$message = false;
if ( isset( $_REQUEST['message'] ) && ( $msg = (int) $_REQUEST['message'] ) ) {
if ( isset( $messages[ $taxonomy ][ $msg ] ) ) {
$message = $messages[ $taxonomy ][ $msg ];
} elseif ( ! isset( $messages[ $taxonomy ] ) && isset( $messages['_item'][ $msg ] ) ) {
$message = $messages['_item'][ $msg ];
}
}

View File

@ -0,0 +1,665 @@
<?php
/**
* WordPress Export Administration API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Version number for the export format.
*
* Bump this when something changes that might affect compatibility.
*
* @since 2.5.0
*/
define( 'WXR_VERSION', '1.2' );
/**
* Generates the WXR export file for download.
*
* Default behavior is to export all content, however, note that post content will only
* be exported for post types with the `can_export` argument enabled. Any posts with the
* 'auto-draft' status will be skipped.
*
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global WP_Post $post Global `$post`.
*
* @param array $args {
* Optional. Arguments for generating the WXR export file for download. Default empty array.
*
* @type string $content Type of content to export. If set, only the post content of this post type
* will be exported. Accepts 'all', 'post', 'page', 'attachment', or a defined
* custom post. If an invalid custom post type is supplied, every post type for
* which `can_export` is enabled will be exported instead. If a valid custom post
* type is supplied but `can_export` is disabled, then 'posts' will be exported
* instead. When 'all' is supplied, only post types with `can_export` enabled will
* be exported. Default 'all'.
* @type string $author Author to export content for. Only used when `$content` is 'post', 'page', or
* 'attachment'. Accepts false (all) or a specific author ID. Default false (all).
* @type string $category Category (slug) to export content for. Used only when `$content` is 'post'. If
* set, only post content assigned to `$category` will be exported. Accepts false
* or a specific category slug. Default is false (all categories).
* @type string $start_date Start date to export content from. Expected date format is 'Y-m-d'. Used only
* when `$content` is 'post', 'page' or 'attachment'. Default false (since the
* beginning of time).
* @type string $end_date End date to export content to. Expected date format is 'Y-m-d'. Used only when
* `$content` is 'post', 'page' or 'attachment'. Default false (latest publish date).
* @type string $status Post status to export posts for. Used only when `$content` is 'post' or 'page'.
* Accepts false (all statuses except 'auto-draft'), or a specific status, i.e.
* 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', or
* 'trash'. Default false (all statuses except 'auto-draft').
* }
*/
function export_wp( $args = array() ) {
global $wpdb, $post;
$defaults = array(
'content' => 'all',
'author' => false,
'category' => false,
'start_date' => false,
'end_date' => false,
'status' => false,
);
$args = wp_parse_args( $args, $defaults );
/**
* Fires at the beginning of an export, before any headers are sent.
*
* @since 2.3.0
*
* @param array $args An array of export arguments.
*/
do_action( 'export_wp', $args );
$sitename = sanitize_key( get_bloginfo( 'name' ) );
if ( ! empty( $sitename ) ) {
$sitename .= '.';
}
$date = date( 'Y-m-d' );
$wp_filename = $sitename . 'WordPress.' . $date . '.xml';
/**
* Filters the export filename.
*
* @since 4.4.0
*
* @param string $wp_filename The name of the file for download.
* @param string $sitename The site name.
* @param string $date Today's date, formatted.
*/
$filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date );
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename=' . $filename );
header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) {
$ptype = get_post_type_object( $args['content'] );
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 );
}
if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] );
} 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)";
$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'] ) {
$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['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.
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
/*
* Get the requested terms ready, empty unless posts filtered by category
* or all content.
*/
$cats = $tags = $terms = array();
if ( isset( $term ) && $term ) {
$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' ) );
$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
$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 {
$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 {
$custom_terms[] = $t;
}
}
unset( $categories, $custom_taxonomies, $custom_terms );
}
/**
* Wrap given string in XML CDATA tag.
*
* @since 2.1.0
*
* @param string $str String to wrap in XML CDATA tag.
* @return string
*/
function wxr_cdata( $str ) {
if ( ! seems_utf8( $str ) ) {
$str = utf8_encode( $str );
}
// $str = ent2ncr(esc_html($str));
$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
return $str;
}
/**
* Return the URL of the site
*
* @since 2.5.0
*
* @return string Site URL.
*/
function wxr_site_url() {
if ( is_multisite() ) {
// Multisite: the base URL.
return network_home_url();
} else {
// WordPress (single site): the blog URL.
return get_bloginfo_rss( 'url' );
}
}
/**
* Output a cat_name XML tag from a given category object
*
* @since 2.1.0
*
* @param object $category Category Object
*/
function wxr_cat_name( $category ) {
if ( empty( $category->name ) ) {
return;
}
echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n";
}
/**
* Output a category_description XML tag from a given category object
*
* @since 2.1.0
*
* @param object $category Category Object
*/
function wxr_category_description( $category ) {
if ( empty( $category->description ) ) {
return;
}
echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n";
}
/**
* Output a tag_name XML tag from a given tag object
*
* @since 2.3.0
*
* @param object $tag Tag Object
*/
function wxr_tag_name( $tag ) {
if ( empty( $tag->name ) ) {
return;
}
echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n";
}
/**
* Output a tag_description XML tag from a given tag object
*
* @since 2.3.0
*
* @param object $tag Tag Object
*/
function wxr_tag_description( $tag ) {
if ( empty( $tag->description ) ) {
return;
}
echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n";
}
/**
* Output a term_name XML tag from a given term object
*
* @since 2.9.0
*
* @param object $term Term Object
*/
function wxr_term_name( $term ) {
if ( empty( $term->name ) ) {
return;
}
echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n";
}
/**
* Output a term_description XML tag from a given term object
*
* @since 2.9.0
*
* @param object $term Term Object
*/
function wxr_term_description( $term ) {
if ( empty( $term->description ) ) {
return;
}
echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n";
}
/**
* Output term meta XML tags for a given term object.
*
* @since 4.6.0
*
* @param WP_Term $term Term object.
*/
function wxr_term_meta( $term ) {
global $wpdb;
$termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) );
foreach ( $termmeta as $meta ) {
/**
* Filters whether to selectively skip term meta used for WXR exports.
*
* Returning a truthy value to the filter will skip the current meta
* object from being exported.
*
* @since 4.6.0
*
* @param bool $skip Whether to skip the current piece of term meta. Default false.
* @param string $meta_key Current meta key.
* @param object $meta Current meta object.
*/
if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) {
printf( "\t\t<wp:termmeta>\n\t\t\t<wp:meta_key>%s</wp:meta_key>\n\t\t\t<wp:meta_value>%s</wp:meta_value>\n\t\t</wp:termmeta>\n", wxr_cdata( $meta->meta_key ), wxr_cdata( $meta->meta_value ) );
}
}
}
/**
* Output list of authors with posts
*
* @since 3.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @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 ) ) {
$post_ids = array_map( 'absint', $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 ) {
$authors[] = get_userdata( $result->post_author );
}
$authors = array_filter( $authors );
foreach ( $authors as $author ) {
echo "\t<wp:author>";
echo '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>';
echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>';
echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>';
echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
echo '<wp:author_last_name>' . wxr_cdata( $author->last_name ) . '</wp:author_last_name>';
echo "</wp:author>\n";
}
}
/**
* Output all navigation menu terms
*
* @since 3.1.0
*/
function wxr_nav_menu_terms() {
$nav_menus = wp_get_nav_menus();
if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) {
return;
}
foreach ( $nav_menus as $menu ) {
echo "\t<wp:term>";
echo '<wp:term_id>' . intval( $menu->term_id ) . '</wp:term_id>';
echo '<wp:term_taxonomy>nav_menu</wp:term_taxonomy>';
echo '<wp:term_slug>' . wxr_cdata( $menu->slug ) . '</wp:term_slug>';
wxr_term_name( $menu );
echo "</wp:term>\n";
}
}
/**
* Output list of taxonomy terms, in XML tag format, associated with a post
*
* @since 2.3.0
*/
function wxr_post_taxonomy() {
$post = get_post();
$taxonomies = get_object_taxonomies( $post->post_type );
if ( empty( $taxonomies ) ) {
return;
}
$terms = wp_get_object_terms( $post->ID, $taxonomies );
foreach ( (array) $terms as $term ) {
echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n";
}
}
/**
* @param bool $return_me
* @param string $meta_key
* @return bool
*/
function wxr_filter_postmeta( $return_me, $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";
?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->
<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
<!-- 4. Activate & Run Importer. -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. You will first be asked to map the authors in this export file to users -->
<!-- on the site. For each author, you may choose to map to an -->
<!-- existing user on the site or to create a new user. -->
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!-- contained in this file into your site. -->
<?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/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
>
<channel>
<title><?php bloginfo_rss( 'name' ); ?></title>
<link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description>
<pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
<language><?php bloginfo_rss( 'language' ); ?></language>
<wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
<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 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 );
wxr_category_description( $c );
wxr_term_meta( $c );
?>
</wp:category>
<?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 );
wxr_tag_description( $t );
wxr_term_meta( $t );
?>
</wp:tag>
<?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 );
wxr_term_description( $t );
wxr_term_meta( $t );
?>
</wp:term>
<?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;
// 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" );
// 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>
<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>
<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>
<wp:comment_status><?php echo wxr_cdata( $post->comment_status ); ?></wp:comment_status>
<wp:ping_status><?php echo wxr_cdata( $post->ping_status ); ?></wp:ping_status>
<wp:post_name><?php echo wxr_cdata( $post->post_name ); ?></wp:post_name>
<wp:status><?php echo wxr_cdata( $post->post_status ); ?></wp:status>
<wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent>
<wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order>
<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' ) : ?>
<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;
}
?>
<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:postmeta>
<?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 ) :
?>
<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>
<wp:comment_author_email><?php echo wxr_cdata( $c->comment_author_email ); ?></wp:comment_author_email>
<wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
<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_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>
</wp:commentmeta>
<?php endforeach; ?>
</wp:comment>
<?php endforeach; ?>
</item>
<?php
}
}
}
?>
</channel>
</rss>
<?php
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,967 @@
<?php
/**
* WordPress Image Editor
*
* @package WordPress
* @subpackage Administration
*/
/**
* 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 = '';
if ( isset( $meta['width'], $meta['height'] ) ) {
$big = max( $meta['width'], $meta['height'] );
} 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 = $backup_sizes['full-orig']['file'] != basename( $meta['file'] );
}
if ( $msg ) {
if ( isset( $msg->error ) ) {
$note = "<div class='error'><p>$msg->error</p></div>";
} elseif ( isset( $msg->msg ) ) {
$note = "<div class='updated'><p>$msg->msg</p></div>";
}
}
?>
<div class="imgedit-wrap wp-clearfix">
<div id="imgedit-panel-<?php echo $post_id; ?>">
<div class="imgedit-settings">
<div class="imgedit-group">
<div class="imgedit-group-top">
<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>
</div>
<?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">
<fieldset class="imgedit-scale">
<legend><?php _e( 'New dimensions:' ); ?></legend>
<div class="nowrap">
<label><span class="screen-reader-text"><?php _e( 'scale width' ); ?></span>
<input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
</label>
<span class="imgedit-separator">&times;</span>
<label><span class="screen-reader-text"><?php _e( 'scale height' ); ?></span>
<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
</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>
</fieldset>
</div>
</div>
</div>
<?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.' );
if ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) {
echo ' ' . __( 'Previously edited copies of the image will not be deleted.' );
}
?>
</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>
</div>
</div>
</div>
<?php } ?>
<div class="imgedit-group">
<div class="imgedit-group-top">
<h2><?php _e( 'Image Crop' ); ?></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( '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><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>
</div>
</div>
<fieldset class="imgedit-crop-ratio">
<legend><?php _e( 'Aspect ratio:' ); ?></legend>
<div class="nowrap">
<label><span class="screen-reader-text"><?php _e( 'crop ratio width' ); ?></span>
<input type="text" id="imgedit-crop-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" />
</label>
<span class="imgedit-separator">:</span>
<label><span class="screen-reader-text"><?php _e( 'crop ratio height' ); ?></span>
<input type="text" id="imgedit-crop-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" />
</label>
</div>
</fieldset>
<fieldset id="imgedit-crop-sel-<?php echo $post_id; ?>" class="imgedit-crop-sel">
<legend><?php _e( 'Selection:' ); ?></legend>
<div class="nowrap">
<label><span class="screen-reader-text"><?php _e( 'selection width' ); ?></span>
<input type="text" id="imgedit-sel-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" />
</label>
<span class="imgedit-separator">&times;</span>
<label><span class="screen-reader-text"><?php _e( 'selection height' ); ?></span>
<input type="text" id="imgedit-sel-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" />
</label>
</div>
</fieldset>
</div>
<?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>
</div>
<figure class="imgedit-thumbnail-preview">
<img src="<?php echo $thumb['url']; ?>" width="<?php echo $thumb_img[0]; ?>" height="<?php echo $thumb_img[1]; ?>" class="imgedit-size-preview" alt="" draggable="false" />
<figcaption class="imgedit-thumbnail-preview-caption"><?php _e( 'Current thumbnail' ); ?></figcaption>
</figure>
<div id="imgedit-save-target-<?php echo $post_id; ?>" class="imgedit-save-target">
<fieldset>
<legend><strong><?php _e( 'Apply changes to:' ); ?></strong></legend>
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" />
<?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>
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
<?php _e( 'All sizes except thumbnail' ); ?></label>
</fieldset>
</div>
</div>
<?php } ?>
</div>
<div class="imgedit-panel-content wp-clearfix">
<?php echo $note; ?>
<div class="imgedit-menu wp-clearfix">
<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>
<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 } ?>
<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>
<button type="button" id="image-undo-<?php echo $post_id; ?>" onclick="imageEdit.undo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-undo button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Undo' ); ?></span></button>
<button type="button" id="image-redo-<?php echo $post_id; ?>" onclick="imageEdit.redo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-redo button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Redo' ); ?></span></button>
<?php echo $note_no_rotate; ?>
</div>
<input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" />
<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
<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="" />
</div>
<div class="imgedit-submit">
<input type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button imgedit-cancel-btn" value="<?php esc_attr_e( 'Cancel' ); ?>" />
<input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button button-primary imgedit-submit-btn" value="<?php esc_attr_e( 'Save' ); ?>" />
</div>
</div>
</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>
<?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.
* @return bool True on success, false on failure.
*/
function wp_stream_image( $image, $mime_type, $attachment_id ) {
if ( $image instanceof WP_Image_Editor ) {
/**
* Filters the WP_Image_Editor instance for the image to be streamed to the browser.
*
* @since 3.5.0
*
* @param WP_Image_Editor $image The image editor instance.
* @param int $attachment_id The attachment post ID.
*/
$image = apply_filters( 'image_editor_save_pre', $image, $attachment_id );
if ( is_wp_error( $image->stream( $mime_type ) ) ) {
return false;
}
return true;
} else {
_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
/**
* Filters the GD image resource to be streamed to the browser.
*
* @since 2.9.0
* @deprecated 3.5.0 Use image_editor_save_pre instead.
*
* @param resource $image Image resource to be streamed.
* @param int $attachment_id The attachment post ID.
*/
$image = apply_filters( 'image_save_pre', $image, $attachment_id );
switch ( $mime_type ) {
case 'image/jpeg':
header( 'Content-Type: image/jpeg' );
return imagejpeg( $image, null, 90 );
case 'image/png':
header( 'Content-Type: image/png' );
return imagepng( $image );
case 'image/gif':
header( 'Content-Type: image/gif' );
return imagegif( $image );
default:
return false;
}
}
}
/**
* Saves image to file.
*
* @since 2.9.0
*
* @param string $filename
* @param WP_Image_Editor $image
* @param string $mime_type
* @param int $post_id
* @return bool
*/
function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
if ( $image instanceof WP_Image_Editor ) {
/** This filter is documented in wp-admin/includes/image-edit.php */
$image = apply_filters( 'image_editor_save_pre', $image, $post_id );
/**
* Filters whether to skip saving the image file.
*
* Returning a non-null value will short-circuit the save method,
* returning that value instead.
*
* @since 3.5.0
*
* @param mixed $override Value to return instead of saving. Default null.
* @param string $filename Name of the file to be saved.
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param string $mime_type Image mime type.
* @param int $post_id Post ID.
*/
$saved = apply_filters( 'wp_save_image_editor_file', null, $filename, $image, $mime_type, $post_id );
if ( null !== $saved ) {
return $saved;
}
return $image->save( $filename, $mime_type );
} else {
_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
/** This filter is documented in wp-admin/includes/image-edit.php */
$image = apply_filters( 'image_save_pre', $image, $post_id );
/**
* Filters whether to skip saving the image file.
*
* Returning a non-null value will short-circuit the save method,
* returning that value instead.
*
* @since 2.9.0
* @deprecated 3.5.0 Use wp_save_image_editor_file instead.
*
* @param mixed $override Value to return instead of saving. Default null.
* @param string $filename Name of the file to be saved.
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param string $mime_type Image mime type.
* @param int $post_id Post ID.
*/
$saved = apply_filters( 'wp_save_image_file', null, $filename, $image, $mime_type, $post_id );
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':
return imagepng( $image, $filename );
case 'image/gif':
return imagegif( $image, $filename );
default:
return false;
}
}
}
/**
* Image preview ratio. Internal use only.
*
* @since 2.9.0
*
* @ignore
* @param int $w Image width in pixels.
* @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;
}
/**
* Returns an image resource. Internal use only.
*
* @since 2.9.0
* @deprecated 3.5.0 Use WP_Image_Editor::rotate()
* @see WP_Image_Editor::rotate()
*
* @ignore
* @param resource $img Image resource.
* @param float|int $angle Image rotation angle, in degrees.
* @return resource|false GD image resource, false otherwise.
*/
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 );
$img = $rotated;
}
}
return $img;
}
/**
* Flips an image resource. Internal use only.
*
* @since 2.9.0
* @deprecated 3.5.0 Use WP_Image_Editor::flip()
* @see WP_Image_Editor::flip()
*
* @ignore
* @param resource $img Image resource.
* @param bool $horz Whether to flip horizontally.
* @param bool $vert Whether to flip vertically.
* @return resource (maybe) flipped image resource.
*/
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;
$sw = $vert ? -$w : $w;
$sh = $horz ? -$h : $h;
if ( imagecopyresampled( $dst, $img, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) {
imagedestroy( $img );
$img = $dst;
}
}
return $img;
}
/**
* Crops an image resource. Internal use only.
*
* @since 2.9.0
*
* @ignore
* @param resource $img Image resource.
* @param float $x Source point x-coordinate.
* @param float $y Source point y-cooredinate.
* @param float $w Source width.
* @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 );
$img = $dst;
}
}
return $img;
}
/**
* Performs group of changes on Editor specified.
*
* @since 2.9.0
*
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param array $changes Array of change operations.
* @return WP_Image_Editor WP_Image_Editor instance with changes applied.
*/
function image_edit_apply_changes( $image, $changes ) {
if ( is_resource( $image ) ) {
_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
}
if ( ! is_array( $changes ) ) {
return $image;
}
// Expand change operations.
foreach ( $changes as $key => $obj ) {
if ( isset( $obj->r ) ) {
$obj->type = 'rotate';
$obj->angle = $obj->r;
unset( $obj->r );
} elseif ( isset( $obj->f ) ) {
$obj->type = 'flip';
$obj->axis = $obj->f;
unset( $obj->f );
} elseif ( isset( $obj->c ) ) {
$obj->type = 'crop';
$obj->sel = $obj->c;
unset( $obj->c );
}
$changes[ $key ] = $obj;
}
// Combine operations.
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 ) {
case 'rotate':
$filtered[ $i ]->angle += $changes[ $j ]->angle;
$combined = true;
break;
case 'flip':
$filtered[ $i ]->axis ^= $changes[ $j ]->axis;
$combined = true;
break;
}
}
if ( ! $combined ) {
$filtered[ ++$i ] = $changes[ $j ];
}
}
$changes = $filtered;
unset( $filtered );
}
// Image resource before applying the changes.
if ( $image instanceof WP_Image_Editor ) {
/**
* Filters the WP_Image_Editor instance before applying changes to the image.
*
* @since 3.5.0
*
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param array $changes Array of change operations.
*/
$image = apply_filters( 'wp_image_editor_before_change', $image, $changes );
} elseif ( is_resource( $image ) ) {
/**
* Filters the GD image resource before applying changes to the image.
*
* @since 2.9.0
* @deprecated 3.5.0 Use wp_image_editor_before_change instead.
*
* @param resource $image GD image resource.
* @param array $changes Array of change operations.
*/
$image = apply_filters( 'image_edit_before_change', $image, $changes );
}
foreach ( $changes as $operation ) {
switch ( $operation->type ) {
case 'rotate':
if ( $operation->angle != 0 ) {
if ( $image instanceof WP_Image_Editor ) {
$image->rotate( $operation->angle );
} 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 {
$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'];
$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 );
} else {
$scale = 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // discard preview scaling
$image = _crop_image_resource( $image, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale );
}
break;
}
}
return $image;
}
/**
* Streams image in post to browser, along with enqueued changes
* in $_REQUEST['history']
*
* @since 2.9.0
*
* @param int $post_id
* @return bool
*/
function stream_preview_image( $post_id ) {
$post = get_post( $post_id );
wp_raise_memory_limit( 'admin' );
$img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );
if ( is_wp_error( $img ) ) {
return false;
}
$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'];
$ratio = _image_get_preview_ratio( $w, $h );
$w2 = max( 1, $w * $ratio );
$h2 = max( 1, $h * $ratio );
if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) {
return false;
}
return wp_stream_image( $img, $post->post_mime_type, $post_id );
}
/**
* Restores the metadata for a given attachment.
*
* @since 2.9.0
*
* @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 );
$backup_sizes = $old_backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
$restored = false;
$msg = new stdClass;
if ( ! is_array( $backup_sizes ) ) {
$msg->error = __( 'Cannot load image metadata.' );
return $msg;
}
$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'] ) ) {
$data = $backup_sizes['full-orig'];
if ( $parts['basename'] != $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}\./', $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'],
);
}
}
$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['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 ) {
// 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'] );
wp_delete_file( $delete_file );
}
} else {
$backup_sizes[ "$default_size-{$suffix}" ] = $meta['sizes'][ $default_size ];
}
}
$meta['sizes'][ $default_size ] = $data;
} else {
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.' );
return $msg;
}
if ( ! $restored ) {
$msg->error = __( 'Image metadata is inconsistent.' );
} else {
$msg->msg = __( 'Image restored successfully.' );
}
return $msg;
}
/**
* 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;
$success = $delete = $scaled = $nocrop = false;
$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 $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'];
if ( $scale && $fwidth > 0 && $fheight > 0 ) {
$size = $img->get_size();
$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 );
if ( -0.1 < $diff && $diff < 0.1 ) {
// Scale the full size image.
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.' ) );
return $return;
}
} 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 $return;
}
$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.' ) );
return $return;
}
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 );
$filename = pathinfo( $path, PATHINFO_FILENAME );
$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 ( 'thumbnail' == $target ) {
$new_path = "{$dirname}/{$filename}-temp.{$ext}";
} else {
$new_path = $path;
}
} else {
while ( true ) {
$filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
$filename .= "-e{$suffix}";
$new_filename = "{$filename}.{$ext}";
$new_path = "{$dirname}/$new_filename";
if ( file_exists( $new_path ) ) {
$suffix++;
} else {
break;
}
}
}
// 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.' ) );
return $return;
}
if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
$tag = false;
if ( isset( $backup_sizes['full-orig'] ) ) {
if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] !== $basename ) {
$tag = "full-$suffix";
}
} else {
$tag = 'full-orig';
}
if ( $tag ) {
$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'];
$meta['height'] = $size['height'];
if ( $success && ( 'nothumb' == $target || 'all' == $target ) ) {
$sizes = get_intermediate_image_sizes();
if ( 'nothumb' == $target ) {
$sizes = array_diff( $sizes, array( 'thumbnail' ) );
}
}
$return->fw = $meta['width'];
$return->fh = $meta['height'];
} elseif ( 'thumbnail' == $target ) {
$sizes = array( 'thumbnail' );
$success = $delete = $nocrop = true;
}
/*
* We need to remove any existing resized image files because
* a new crop or rotate could generate different sizes (and hence, filenames),
* keeping the new resized images from overwriting the existing image files.
* https://core.trac.wordpress.org/ticket/32171
*/
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) {
foreach ( $meta['sizes'] as $size ) {
if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) {
$delete_file = path_join( $dirname, $size['file'] );
wp_delete_file( $delete_file );
}
}
}
if ( isset( $sizes ) ) {
$_sizes = array();
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'] ) {
$tag = "$size-$suffix";
}
} else {
$tag = "$size-orig";
}
if ( $tag ) {
$backup_sizes[ $tag ] = $meta['sizes'][ $size ];
}
}
if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
$width = intval( $_wp_additional_image_sizes[ $size ]['width'] );
$height = intval( $_wp_additional_image_sizes[ $size ]['height'] );
$crop = ( $nocrop ) ? false : $_wp_additional_image_sizes[ $size ]['crop'];
} else {
$height = get_option( "{$size}_size_h" );
$width = get_option( "{$size}_size_w" );
$crop = ( $nocrop ) ? false : get_option( "{$size}_crop" );
}
$_sizes[ $size ] = array(
'width' => $width,
'height' => $height,
'crop' => $crop,
);
}
$meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes ) );
}
unset( $img );
if ( $success ) {
wp_update_attachment_metadata( $post_id, $meta );
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 );
$return->thumbnail = $thumb_url[0];
} else {
$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'] );
} else {
$return->thumbnail = "$file_url?w=128&h=128";
}
}
}
} else {
$delete = true;
}
if ( $delete ) {
wp_delete_file( $new_path );
}
$return->msg = esc_js( __( 'Image saved' ) );
return $return;
}

View File

@ -0,0 +1,731 @@
<?php
/**
* File contains all the administration image manipulation functions.
*
* @package WordPress
* @subpackage Administration
*/
/**
* Crop an Image to a given size.
*
* @since 2.1.0
*
* @param string|int $src The source file or Attachment ID.
* @param int $src_x The start x position to crop from.
* @param int $src_y The start y position to crop from.
* @param int $src_w The width to crop.
* @param int $src_h The height to crop.
* @param int $dst_w The destination width.
* @param int $dst_h The destination height.
* @param int $src_abs Optional. If the source crop points are absolute.
* @param string $dst_file Optional. The destination file to write to.
* @return string|WP_Error New filepath on success, WP_Error on failure.
*/
function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
$src_file = $src;
if ( is_numeric( $src ) ) { // Handle int as attachment ID
$src_file = get_attached_file( $src );
if ( ! file_exists( $src_file ) ) {
// If the file doesn't exist, attempt a URL fopen on the src link.
// This can occur with certain file replication plugins.
$src = _load_image_to_edit_path( $src, 'full' );
} else {
$src = $src_file;
}
}
$editor = wp_get_image_editor( $src );
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 ) ) {
return $src;
}
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
* using a replication plugin.
*/
wp_mkdir_p( dirname( $dst_file ) );
$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) );
$result = $editor->save( $dst_file );
if ( is_wp_error( $result ) ) {
return $result;
}
return $dst_file;
}
/**
* Generate post thumbnail attachment meta data.
*
* @since 2.1.0
*
* @param int $attachment_id Attachment Id to process.
* @param string $file Filepath of the Attached image.
* @return mixed Metadata for attachment.
*/
function wp_generate_attachment_metadata( $attachment_id, $file ) {
$attachment = get_post( $attachment_id );
$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];
$metadata['height'] = $imagesize[1];
// Make the file path relative to the upload dir.
$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'] ) ) {
// For theme-added sizes
$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" );
}
if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
// For theme-added sizes
$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" );
}
if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
// For theme-added sizes
$sizes[ $s ]['crop'] = $_wp_additional_image_sizes[ $s ]['crop'];
} else {
// For default sizes set in options
$sizes[ $s ]['crop'] = get_option( "{$s}_crop" );
}
}
/**
* Filters the image sizes automatically generated when uploading an image.
*
* @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 int $attachment_id Current attachment ID.
*/
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes, $metadata, $attachment_id );
if ( $sizes ) {
$editor = wp_get_image_editor( $file );
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 ) {
$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' );
} 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' );
}
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,
)
);
$exists = reset( $posts );
if ( ! empty( $exists ) ) {
update_post_meta( $attachment_id, '_thumbnail_id', $exists );
} else {
$ext = '.jpg';
switch ( $metadata['image']['mime'] ) {
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' => '',
);
/**
* Filters the parameters for the attachment thumbnail creation.
*
* @since 3.9.0
*
* @param array $image_attachment An array of parameters to create the thumbnail.
* @param array $metadata Current attachment metadata.
* @param array $uploaded An array containing the thumbnail path and url.
*/
$image_attachment = apply_filters( 'attachment_thumbnail_args', $image_attachment, $metadata, $uploaded );
$sub_attachment_id = wp_insert_attachment( $image_attachment, $uploaded['file'] );
add_post_meta( $sub_attachment_id, '_cover_hash', $hash );
$attach_data = wp_generate_attachment_metadata( $sub_attachment_id, $uploaded['file'] );
wp_update_attachment_metadata( $sub_attachment_id, $attach_data );
update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id );
}
}
} elseif ( 'application/pdf' === $mime_type ) {
// Try to create image thumbnails for PDFs.
$fallback_sizes = array(
'thumbnail',
'medium',
'large',
);
/**
* Filters the image sizes generated for non-image mime types.
*
* @since 4.7.0
*
* @param array $fallback_sizes An array of image size names.
* @param array $metadata Current attachment metadata.
*/
$fallback_sizes = apply_filters( 'fallback_intermediate_image_sizes', $fallback_sizes, $metadata );
$sizes = array();
$_wp_additional_image_sizes = wp_get_additional_image_sizes();
foreach ( $fallback_sizes as $s ) {
if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
$sizes[ $s ]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] );
} else {
$sizes[ $s ]['width'] = get_option( "{$s}_size_w" );
}
if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] );
} else {
$sizes[ $s ]['height'] = get_option( "{$s}_size_h" );
}
if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
$sizes[ $s ]['crop'] = $_wp_additional_image_sizes[ $s ]['crop'];
} else {
// Force thumbnails to be soft crops.
if ( 'thumbnail' !== $s ) {
$sizes[ $s ]['crop'] = get_option( "{$s}_crop" );
}
}
}
// Only load PDFs in an image editor if we're processing sizes.
if ( ! empty( $sizes ) ) {
$editor = wp_get_image_editor( $file );
if ( ! is_wp_error( $editor ) ) { // No support for this type of 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 );
$preview_file = $dirname . wp_unique_filename( $dirname, wp_basename( $file, $ext ) . '-pdf.jpg' );
$uploaded = $editor->save( $preview_file, 'image/jpeg' );
unset( $editor );
// Resize based on the full size image, rather than the source.
if ( ! is_wp_error( $uploaded ) ) {
$editor = wp_get_image_editor( $uploaded['path'] );
unset( $uploaded['path'] );
if ( ! is_wp_error( $editor ) ) {
$metadata['sizes'] = $editor->multi_resize( $sizes );
$metadata['sizes']['full'] = $uploaded;
}
}
}
}
}
// Remove the blob of binary data from the array.
if ( $metadata ) {
unset( $metadata['image']['data'] );
}
/**
* Filters the generated attachment meta data.
*
* @since 2.1.0
*
* @param array $metadata An array of attachment meta data.
* @param int $attachment_id Current attachment ID.
*/
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
}
/**
* Convert a fraction string to a decimal.
*
* @since 2.5.0
*
* @param string $str
* @return int|float
*/
function wp_exif_frac2dec( $str ) {
@list( $n, $d ) = explode( '/', $str );
if ( ! empty( $d ) ) {
return $n / $d;
}
return $str;
}
/**
* Convert the exif date format to a unix timestamp.
*
* @since 2.5.0
*
* @param string $str
* @return int
*/
function wp_exif_date2ts( $str ) {
@list( $date, $time ) = explode( ' ', trim( $str ) );
@list( $y, $m, $d ) = explode( ':', $date );
return strtotime( "{$y}-{$m}-{$d} {$time}" );
}
/**
* Get extended image metadata, exif or iptc as available.
*
* Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso
* created_timestamp, focal_length, shutter_speed, and title.
*
* The IPTC metadata that is retrieved is APP13, credit, byline, created date
* and time, caption, copyright, and title. Also includes FNumber, Model,
* DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.
*
* @todo Try other exif libraries if available.
* @since 2.5.0
*
* @param string $file
* @return bool|array False on failure. Image metadata array on success.
*/
function wp_read_image_metadata( $file ) {
if ( ! file_exists( $file ) ) {
return false;
}
list( , , $image_type ) = @getimagesize( $file );
/*
* EXIF contains a bunch of data we'll probably never need formatted in ways
* that are difficult to use. We'll normalize it and just extract the fields
* that are likely to be useful. Fractions and numbers are converted to
* floats, dates to unix timestamps, and everything else to strings.
*/
$meta = array(
'aperture' => 0,
'credit' => '',
'camera' => '',
'caption' => '',
'created_timestamp' => 0,
'copyright' => '',
'focal_length' => 0,
'iso' => 0,
'shutter_speed' => 0,
'title' => '',
'orientation' => 0,
'keywords' => array(),
);
$iptc = array();
/*
* Read IPTC first, since it might contain data not available in exif such
* as caption, description etc.
*/
if ( is_callable( 'iptcparse' ) ) {
@getimagesize( $file, $info );
if ( ! empty( $info['APP13'] ) ) {
$iptc = @iptcparse( $info['APP13'] );
// 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."
*/
} elseif ( ! empty( $iptc['2#005'][0] ) ) {
$meta['title'] = trim( $iptc['2#005'][0] );
}
if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption
$caption = trim( $iptc['2#120'][0] );
mbstring_binary_safe_encoding();
$caption_length = strlen( $caption );
reset_mbstring_encoding();
if ( empty( $meta['title'] ) && $caption_length < 80 ) {
// Assume the title is stored in 2:120 if it's short.
$meta['title'] = $caption;
}
$meta['caption'] = $caption;
}
if ( ! empty( $iptc['2#110'][0] ) ) { // credit
$meta['credit'] = trim( $iptc['2#110'][0] );
} 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
$meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] );
}
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();
/**
* Filters the image types to check for exif data.
*
* @since 2.5.0
*
* @param array $image_types Image types to check for exif data.
*/
$exif_image_types = apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) );
if ( is_callable( 'exif_read_data' ) && in_array( $image_type, $exif_image_types ) ) {
$exif = @exif_read_data( $file );
if ( ! empty( $exif['ImageDescription'] ) ) {
mbstring_binary_safe_encoding();
$description_length = strlen( $exif['ImageDescription'] );
reset_mbstring_encoding();
if ( empty( $meta['title'] ) && $description_length < 80 ) {
// Assume the title is stored in ImageDescription
$meta['title'] = trim( $exif['ImageDescription'] );
}
if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) ) {
$meta['caption'] = trim( $exif['COMPUTED']['UserComment'] );
}
if ( empty( $meta['caption'] ) ) {
$meta['caption'] = trim( $exif['ImageDescription'] );
}
} elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) ) {
$meta['caption'] = trim( $exif['Comments'] );
}
if ( empty( $meta['credit'] ) ) {
if ( ! empty( $exif['Artist'] ) ) {
$meta['credit'] = trim( $exif['Artist'] );
} elseif ( ! empty( $exif['Author'] ) ) {
$meta['credit'] = trim( $exif['Author'] );
}
}
if ( empty( $meta['copyright'] ) && ! empty( $exif['Copyright'] ) ) {
$meta['copyright'] = trim( $exif['Copyright'] );
}
if ( ! empty( $exif['FNumber'] ) ) {
$meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 );
}
if ( ! empty( $exif['Model'] ) ) {
$meta['camera'] = trim( $exif['Model'] );
}
if ( empty( $meta['created_timestamp'] ) && ! empty( $exif['DateTimeDigitized'] ) ) {
$meta['created_timestamp'] = wp_exif_date2ts( $exif['DateTimeDigitized'] );
}
if ( ! empty( $exif['FocalLength'] ) ) {
$meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] );
}
if ( ! empty( $exif['ISOSpeedRatings'] ) ) {
$meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings'];
$meta['iso'] = trim( $meta['iso'] );
}
if ( ! empty( $exif['ExposureTime'] ) ) {
$meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] );
}
if ( ! empty( $exif['Orientation'] ) ) {
$meta['orientation'] = $exif['Orientation'];
}
}
foreach ( array( 'title', 'caption', 'credit', 'copyright', 'camera', 'iso' ) as $key ) {
if ( $meta[ $key ] && ! seems_utf8( $meta[ $key ] ) ) {
$meta[ $key ] = utf8_encode( $meta[ $key ] );
}
}
foreach ( $meta['keywords'] as $key => $keyword ) {
if ( ! seems_utf8( $keyword ) ) {
$meta['keywords'][ $key ] = utf8_encode( $keyword );
}
}
$meta = wp_kses_post_deep( $meta );
/**
* Filters the array of meta data read from an image's exif data.
*
* @since 2.5.0
* @since 4.4.0 The `$iptc` parameter was added.
* @since 5.0.0 The `$exif` parameter was added.
*
* @param array $meta Image meta data.
* @param string $file Path to image file.
* @param int $image_type Type of image, one of the `IMAGETYPE_XXX` constants.
* @param array $iptc IPTC data.
* @param array $exif EXIF data.
*/
return apply_filters( 'wp_read_image_metadata', $meta, $file, $image_type, $iptc, $exif );
}
/**
* Validate that file is an image.
*
* @since 2.5.0
*
* @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 );
}
/**
* Validate that file is suitable for displaying within a web page.
*
* @since 2.5.0
*
* @param string $path File path to test.
* @return bool True if suitable, false if not suitable.
*/
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;
} elseif ( ! in_array( $info[2], $displayable_image_types ) ) {
$result = false;
} else {
$result = true;
}
/**
* Filters whether the current image is displayable in the browser.
*
* @since 2.5.0
*
* @param bool $result Whether the image can be displayed. Default true.
* @param string $path Path to the image.
*/
return apply_filters( 'file_is_displayable_image', $result, $path );
}
/**
* Load an image resource for editing.
*
* @since 2.9.0
*
* @param string $attachment_id Attachment ID.
* @param string $mime_type Image mime type.
* @param string $size Optional. Image size, defaults to 'full'.
* @return resource|false The resulting image resource on success, false on failure.
*/
function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) {
$filepath = _load_image_to_edit_path( $attachment_id, $size );
if ( empty( $filepath ) ) {
return false;
}
switch ( $mime_type ) {
case 'image/jpeg':
$image = imagecreatefromjpeg( $filepath );
break;
case 'image/png':
$image = imagecreatefrompng( $filepath );
break;
case 'image/gif':
$image = imagecreatefromgif( $filepath );
break;
default:
$image = false;
break;
}
if ( is_resource( $image ) ) {
/**
* Filters the current image being loaded for editing.
*
* @since 2.9.0
*
* @param resource $image Current image.
* @param string $attachment_id Attachment ID.
* @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 );
}
}
return $image;
}
/**
* Retrieve the path or url of an attachment's attached file.
*
* If the attached file is not present on the local filesystem (usually due to replication plugins),
* then the url of the file is returned if url fopen is supported.
*
* @since 3.4.0
* @access private
*
* @param string $attachment_id Attachment ID.
* @param string $size Optional. Image size, defaults to 'full'.
* @return string|false File path or url on success, false on failure.
*/
function _load_image_to_edit_path( $attachment_id, $size = 'full' ) {
$filepath = get_attached_file( $attachment_id );
if ( $filepath && file_exists( $filepath ) ) {
if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) {
/**
* Filters the path to the current image.
*
* The filter is evaluated for all image sizes except 'full'.
*
* @since 3.1.0
*
* @param string $path Path to the current image.
* @param string $attachment_id Attachment ID.
* @param string $size Size of the image.
*/
$filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size );
}
} elseif ( function_exists( 'fopen' ) && true == ini_get( 'allow_url_fopen' ) ) {
/**
* Filters the image URL if not in the local filesystem.
*
* The filter is only evaluated if fopen is enabled on the server.
*
* @since 3.1.0
*
* @param string $image_url Current image URL.
* @param string $attachment_id Attachment ID.
* @param string $size Size of the image.
*/
$filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size );
}
/**
* Filters the returned path or URL of the current image.
*
* @since 2.9.0
*
* @param string|bool $filepath File path or URL to current image, or false.
* @param string $attachment_id Attachment ID.
* @param string $size Size of the image.
*/
return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size );
}
/**
* Copy an existing image file.
*
* @since 3.4.0
* @access private
*
* @param string $attachment_id Attachment ID.
* @return string|false New file path on success, false on failure.
*/
function _copy_image_file( $attachment_id ) {
$dst_file = $src_file = get_attached_file( $attachment_id );
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 );
$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) );
/*
* The directory containing the original file may no longer
* exist when using a replication plugin.
*/
wp_mkdir_p( dirname( $dst_file ) );
if ( ! @copy( $src_file, $dst_file ) ) {
$dst_file = false;
}
} else {
$dst_file = false;
}
return $dst_file;
}

View File

@ -0,0 +1,231 @@
<?php
/**
* WordPress Administration Importer API.
*
* @package WordPress
* @subpackage Administration
*/
/**
* Retrieve list of importers.
*
* @since 2.0.0
*
* @global array $wp_importers
* @return array
*/
function get_importers() {
global $wp_importers;
if ( is_array( $wp_importers ) ) {
uasort( $wp_importers, '_usort_by_first_member' );
}
return $wp_importers;
}
/**
* Sorts a multidimensional array by first member of each top level member
*
* Used by uasort() as a callback, should not be used directly.
*
* @since 2.9.0
* @access private
*
* @param array $a
* @param array $b
* @return int
*/
function _usort_by_first_member( $a, $b ) {
return strnatcasecmp( $a[0], $b[0] );
}
/**
* Register importer for WordPress.
*
* @since 2.0.0
*
* @global array $wp_importers
*
* @param string $id Importer tag. Used to uniquely identify importer.
* @param string $name Importer name and title.
* @param string $description Importer description.
* @param callable $callback Callback to run.
* @return WP_Error Returns WP_Error when $callback is WP_Error.
*/
function register_importer( $id, $name, $description, $callback ) {
global $wp_importers;
if ( is_wp_error( $callback ) ) {
return $callback;
}
$wp_importers[ $id ] = array( $name, $description, $callback );
}
/**
* Cleanup importer.
*
* Removes attachment based on ID.
*
* @since 2.0.0
*
* @param string $id Importer ID.
*/
function wp_import_cleanup( $id ) {
wp_delete_attachment( $id );
}
/**
* Handle importer uploading and add attachment.
*
* @since 2.0.0
*
* @return array Uploaded file's details on success, error message on failure
*/
function wp_import_handle_upload() {
if ( ! isset( $_FILES['import'] ) ) {
return array(
'error' => __( '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,
);
$_FILES['import']['name'] .= '.txt';
$upload = wp_handle_upload( $_FILES['import'], $overrides );
if ( isset( $upload['error'] ) ) {
return $upload;
}
// Construct the object array
$object = array(
'post_title' => basename( $upload['file'] ),
'post_content' => $upload['url'],
'post_mime_type' => $upload['type'],
'guid' => $upload['url'],
'context' => 'import',
'post_status' => 'private',
);
// Save the data
$id = wp_insert_attachment( $object, $upload['file'] );
/*
* Schedule a cleanup for one day from now in case of failed
* import or missing wp_import_cleanup() call.
*/
wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );
return array(
'file' => $upload['file'],
'id' => $id,
);
}
/**
* Returns a list from WordPress.org of popular importer plugins.
*
* @since 3.5.0
*
* @return array Importers with metadata for each.
*/
function wp_get_popular_importers() {
include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $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/'
);
$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 );
$popular_importers = json_decode( wp_remote_retrieve_body( $response ), true );
if ( is_array( $popular_importers ) ) {
set_site_transient( $cache_key, $popular_importers, 2 * DAY_IN_SECONDS );
} else {
$popular_importers = false;
}
}
if ( is_array( $popular_importers ) ) {
// If the data was received as translated, return it as-is.
if ( $popular_importers['translated'] ) {
return $popular_importers['importers'];
}
foreach ( $popular_importers['importers'] as &$importer ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
$importer['description'] = translate( $importer['description'] );
if ( $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' ),
'description' => __( 'Import posts, comments, and users from a Blogger blog.' ),
'plugin-slug' => 'blogger-importer',
'importer-id' => 'blogger',
),
'wpcat2tag' => array(
'name' => __( 'Categories and Tags Converter' ),
'description' => __( 'Convert existing categories to tags or tags to categories, selectively.' ),
'plugin-slug' => 'wpcat2tag-importer',
'importer-id' => 'wp-cat2tag',
),
'livejournal' => array(
'name' => __( 'LiveJournal' ),
'description' => __( 'Import posts from LiveJournal using their API.' ),
'plugin-slug' => 'livejournal-importer',
'importer-id' => 'livejournal',
),
'movabletype' => array(
'name' => __( 'Movable Type and TypePad' ),
'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ),
'plugin-slug' => 'movabletype-importer',
'importer-id' => 'mt',
),
'opml' => array(
'name' => __( 'Blogroll' ),
'description' => __( 'Import links in OPML format.' ),
'plugin-slug' => 'opml-importer',
'importer-id' => 'opml',
),
'rss' => array(
'name' => __( 'RSS' ),
'description' => __( 'Import posts from an RSS feed.' ),
'plugin-slug' => 'rss-importer',
'importer-id' => 'rss',
),
'tumblr' => array(
'name' => __( 'Tumblr' ),
'description' => __( 'Import posts &amp; media from Tumblr using their API.' ),
'plugin-slug' => 'tumblr-importer',
'importer-id' => 'tumblr',
),
'wordpress' => array(
'name' => 'WordPress',
'description' => __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ),
'plugin-slug' => 'wordpress-importer',
'importer-id' => 'wordpress',
),
);
}

View File

@ -0,0 +1,86 @@
<?php
/**
* Helper functions for displaying a list of items in an ajaxified HTML table.
*
* @package WordPress
* @subpackage List_Table
* @since 3.1.0
*/
/**
* Fetches an instance of a WP_List_Table class.
*
* @access private
* @since 3.1.0
*
* @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 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_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',
// Network Admin
'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 ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
}
if ( isset( $args['screen'] ) ) {
$args['screen'] = convert_to_screen( $args['screen'] );
} elseif ( isset( $GLOBALS['hook_suffix'] ) ) {
$args['screen'] = get_current_screen();
} else {
$args['screen'] = null;
}
return new $class( $args );
}
return false;
}
/**
* Register column headers for a particular screen.
*
* @since 2.7.0
*
* @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
* @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 ) {
new _WP_List_Table_Compat( $screen, $columns );
}
/**
* Prints column headers for a particular screen.
*
* @since 2.7.0
*
* @param string|WP_Screen $screen The screen hook name or screen object.
* @param bool $with_id Whether to set the id attribute or not.
*/
function print_column_headers( $screen, $with_id = true ) {
$wp_list_table = new _WP_List_Table_Compat( $screen );
$wp_list_table->print_column_headers( $with_id );
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,351 @@
<?php
/**
* Build Administration Menu.
*
* @package WordPress
* @subpackage Administration
*/
if ( is_network_admin() ) {
/**
* Fires before the administration menu loads in the Network Admin.
*
* The hook fires before menus and sub-menus are removed based on user privileges.
*
* @private
* @since 3.1.0
*/
do_action( '_network_admin_menu' );
} elseif ( is_user_admin() ) {
/**
* Fires before the administration menu loads in the User Admin.
*
* The hook fires before menus and sub-menus are removed based on user privileges.
*
* @private
* @since 3.1.0
*/
do_action( '_user_admin_menu' );
} else {
/**
* Fires before the administration menu loads in the admin.
*
* The hook fires before menus and sub-menus are removed based on user privileges.
*
* @private
* @since 2.2.0
*/
do_action( '_admin_menu' );
}
// Create list of page plugin hook names.
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 );
// Set the hook name to be the 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( $menu_page[2], '.php' );
}
$hook_name = sanitize_title( $hook_name );
if ( isset( $compat[ $hook_name ] ) ) {
$hook_name = $compat[ $hook_name ];
} elseif ( ! $hook_name ) {
continue;
}
$admin_page_hooks[ $menu_page[2] ] = $hook_name;
}
unset( $menu_page, $compat );
$_wp_submenu_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;
}
}
unset( $index, $data );
if ( empty( $submenu[ $parent ] ) ) {
unset( $submenu[ $parent ] );
}
}
unset( $sub, $parent );
/*
* Loop over the top-level menu.
* Menus for which the original parent is not accessible due to lack of privileges
* will have the next submenu in line be assigned as the new menu parent.
*/
foreach ( $menu as $id => $data ) {
if ( empty( $submenu[ $data[2] ] ) ) {
continue;
}
$subs = $submenu[ $data[2] ];
$first_sub = reset( $subs );
$old_parent = $data[2];
$new_parent = $first_sub[2];
/*
* If the first submenu is not the same as the assigned parent,
* 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;
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 );
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 );
if ( is_network_admin() ) {
/**
* Fires before the administration menu loads in the Network Admin.
*
* @since 3.1.0
*
* @param string $context Empty context.
*/
do_action( 'network_admin_menu', '' );
} elseif ( is_user_admin() ) {
/**
* Fires before the administration menu loads in the User Admin.
*
* @since 3.1.0
*
* @param string $context Empty context.
*/
do_action( 'user_admin_menu', '' );
} else {
/**
* Fires before the administration menu loads in the admin.
*
* @since 1.5.0
*
* @param string $context Empty context.
*/
do_action( 'admin_menu', '' );
}
/*
* Remove menus that have no accessible submenus and require privileges
* 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 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] ];
$first_sub = reset( $subs );
if ( $data[2] == $first_sub[2] ) {
unset( $submenu[ $data[2] ] );
}
}
// If submenu is empty...
if ( empty( $submenu[ $data[2] ] ) ) {
// And user doesn't have privs, remove menu.
if ( isset( $_wp_menu_nopriv[ $data[2] ] ) ) {
unset( $menu[ $id ] );
}
}
}
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;
return $class;
}
/**
* @param array $menu
* @return array
*/
function add_menu_classes( $menu ) {
$first = $lastorder = false;
$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;
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 );
continue;
}
if ( $first ) {
$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 );
}
$lastorder = $order;
}
/**
* Filters administration menus array with classes added for top-level items.
*
* @since 2.7.0
*
* @param array $menu Associative array of administration menu items.
*/
return apply_filters( 'add_menu_classes', $menu );
}
uksort( $menu, 'strnatcasecmp' ); // make it all pretty
/**
* Filters whether to enable custom ordering of the administration menu.
*
* See the {@see 'menu_order'} filter for reordering menu items.
*
* @since 2.8.0
*
* @param bool $custom Whether custom ordering is enabled. Default false.
*/
if ( apply_filters( 'custom_menu_order', false ) ) {
$menu_order = array();
foreach ( $menu as $menu_item ) {
$menu_order[] = $menu_item[2];
}
unset( $menu_item );
$default_menu_order = $menu_order;
/**
* Filters the order of administration menu items.
*
* A truthy value must first be passed to the {@see 'custom_menu_order'} filter
* for this filter to work. Use the following to enable custom menu ordering:
*
* add_filter( 'custom_menu_order', '__return_true' );
*
* @since 2.8.0
*
* @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 );
/**
* @global array $menu_order
* @global array $default_menu_order
*
* @param array $a
* @param array $b
* @return int
*/
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 ] ) ) {
return -1;
} 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 ] ) {
return 0;
}
return ( $menu_order[ $a ] < $menu_order[ $b ] ) ? -1 : 1;
} else {
return ( $default_menu_order[ $a ] <= $default_menu_order[ $b ] ) ? -1 : 1;
}
}
usort( $menu, 'sort_menu' );
unset( $menu_order, $default_menu_order );
}
// Prevent adjacent separators
$prev_menu_was_separator = false;
foreach ( $menu as $id => $data ) {
if ( false === stristr( $data[4], 'wp-menu-separator' ) ) {
// This item is not a separator, so falsey the toggler and do nothing
$prev_menu_was_separator = false;
} else {
// The previous item was a separator, so unset this one
if ( true === $prev_menu_was_separator ) {
unset( $menu[ $id ] );
}
// This item is a separator, so truthy the toggler and move on
$prev_menu_was_separator = true;
}
}
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] ) {
unset( $menu[ $last_menu_key ] );
}
unset( $last_menu_key );
if ( ! user_can_access_admin_page() ) {
/**
* Fires when access to an admin page is denied.
*
* @since 2.5.0
*/
do_action( 'admin_page_access_denied' );
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
}
$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

@ -0,0 +1,44 @@
<?php
/**
* Multisite Administration hooks
*
* @package WordPress
* @subpackage Administration
* @since 4.3.0
*/
// Media Hooks.
add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
// User Hooks
add_action( 'user_admin_notices', 'new_user_email_admin_notice' );
add_action( 'network_admin_notices', 'new_user_email_admin_notice' );
add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
// Site Hooks.
add_action( 'wpmueditblogaction', 'upload_space_setting' );
// Network hooks
add_action( 'update_site_option_admin_email', 'wp_network_admin_email_change_notification', 10, 4 );
// Taxonomy Hooks
add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
// Post Hooks.
add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
// Tools Hooks.
add_filter( 'import_allow_create_users', 'check_import_new_users' );
// Notices Hooks
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', 'maintenance_nag', 10 );
// Network Admin Hooks
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

@ -0,0 +1,105 @@
<?php
/**
* Multisite: Deprecated admin functions from past versions and WordPress MU
*
* These functions should not be used and will be removed in a later version.
* It is suggested to use for the alternatives instead when available.
*
* @package WordPress
* @subpackage Deprecated
* @since 3.0.0
*/
/**
* Outputs the WPMU menu.
*
* @deprecated 3.0.0
*/
function wpmu_menu() {
_deprecated_function(__FUNCTION__, '3.0.0' );
// Deprecated. See #11763.
}
/**
* Determines if the available space defined by the admin has been exceeded by the user.
*
* @deprecated 3.0.0 Use is_upload_space_available()
* @see is_upload_space_available()
*/
function wpmu_checkAvailableSpace() {
_deprecated_function(__FUNCTION__, '3.0.0', 'is_upload_space_available()' );
if ( !is_upload_space_available() )
wp_die( __('Sorry, you must delete files before you can upload any more.') );
}
/**
* WPMU options.
*
* @deprecated 3.0.0
*/
function mu_options( $options ) {
_deprecated_function(__FUNCTION__, '3.0.0' );
return $options;
}
/**
* Deprecated functionality for activating a network-only plugin.
*
* @deprecated 3.0.0 Use activate_plugin()
* @see activate_plugin()
*/
function activate_sitewide_plugin() {
_deprecated_function(__FUNCTION__, '3.0.0', 'activate_plugin()' );
return false;
}
/**
* Deprecated functionality for deactivating a network-only plugin.
*
* @deprecated 3.0.0 Use deactivate_plugin()
* @see deactivate_plugin()
*/
function deactivate_sitewide_plugin( $plugin = false ) {
_deprecated_function(__FUNCTION__, '3.0.0', 'deactivate_plugin()' );
}
/**
* Deprecated functionality for determining if the current plugin is network-only.
*
* @deprecated 3.0.0 Use is_network_only_plugin()
* @see is_network_only_plugin()
*/
function is_wpmu_sitewide_plugin( $file ) {
_deprecated_function(__FUNCTION__, '3.0.0', 'is_network_only_plugin()' );
return is_network_only_plugin( $file );
}
/**
* Deprecated functionality for getting themes network-enabled themes.
*
* @deprecated 3.4.0 Use WP_Theme::get_allowed_on_network()
* @see WP_Theme::get_allowed_on_network()
*/
function get_site_allowed_themes() {
_deprecated_function( __FUNCTION__, '3.4.0', 'WP_Theme::get_allowed_on_network()' );
return array_map( 'intval', WP_Theme::get_allowed_on_network() );
}
/**
* Deprecated functionality for getting themes allowed on a specific site.
*
* @deprecated 3.4.0 Use WP_Theme::get_allowed_on_site()
* @see WP_Theme::get_allowed_on_site()
*/
function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
_deprecated_function( __FUNCTION__, '3.4.0', 'WP_Theme::get_allowed_on_site()' );
return array_map( 'intval', WP_Theme::get_allowed_on_site( $blog_id ) );
}
/**
* Deprecated functionality for determining whether a file is deprecated.
*
* @deprecated 3.5.0
*/
function ms_deprecated_blogs_file() {}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,665 @@
<?php
/**
* WordPress Network Administration API.
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Check for an existing network.
*
* @since 3.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @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 ) );
if ( $wpdb->get_var( $sql ) ) {
return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
}
return false;
}
/**
* Allow subdomain installation
*
* @since 3.0.0
* @return bool Whether subdomain installation is allowed
*/
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 ) ) {
return false;
}
return true;
}
/**
* Allow subdirectory installation.
*
* @since 3.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return bool Whether subdirectory installation is allowed
*/
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 ) ) {
return true;
}
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 ) ) {
return true;
}
return false;
}
/**
* Get base domain of network.
*
* @since 3.0.0
* @return string Base domain.
*/
function get_clean_basedomain() {
if ( $existing_domain = network_domain_check() ) {
return $existing_domain;
}
$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
if ( $slash = strpos( $domain, '/' ) ) {
$domain = substr( $domain, 0, $slash );
}
return $domain;
}
/**
* 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.
*
* @since 3.0.0
*
* @global bool $is_apache
*
* @param WP_Error $errors
*/
function network_step1( $errors = false ) {
global $is_apache;
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.' ),
'<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
) . '</p></div>';
echo '</div>';
include( ABSPATH . 'wp-admin/admin-footer.php' );
die();
}
$active_plugins = get_option( 'active_plugins' );
if ( ! empty( $active_plugins ) ) {
echo '<div class="updated"><p><strong>' . __( 'Warning:' ) . '</strong> ' . sprintf(
/* translators: %s: Plugins screen URL */
__( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ),
admin_url( 'plugins.php?plugin_status=active' )
) . '</p></div>';
echo '<p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
echo '</div>';
include( ABSPATH . 'wp-admin/admin-footer.php' );
die();
}
$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>';
echo '<p>' . sprintf(
/* translators: %s: port number */
__( 'You cannot use port numbers such as %s.' ),
'<code>' . $has_ports . '</code>'
) . '</p>';
echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
echo '</div>';
include( ABSPATH . 'wp-admin/admin-footer.php' );
die();
}
echo '<form method="post">';
wp_nonce_field( 'install-network-1' );
$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 ) {
echo "<p>$error</p>";
}
echo '</div>';
$error_codes = $errors->get_error_codes();
}
if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) {
$site_name = $_POST['sitename'];
} else {
/* translators: %s: Default network name */
$site_name = sprintf( __( '%s Sites' ), get_option( 'blogname' ) );
}
if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) {
$admin_email = $_POST['email'];
} else {
$admin_email = get_option( 'admin_email' );
}
?>
<p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
<p><?php _e( 'Fill in the information below and you&#8217;ll be on your way to creating a network of WordPress sites. We will create configuration files in the next step.' ); ?></p>
<?php
if ( isset( $_POST['subdomain_install'] ) ) {
$subdomain_install = (bool) $_POST['subdomain_install'];
} elseif ( apache_mod_loaded( 'mod_rewrite' ) ) { // assume nothing
$subdomain_install = true;
} 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.' ),
'<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.' ),
'<code>mod_rewrite</code>'
);
echo '</p>';
}
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.' ),
'<code>mod_rewrite</code>',
'https://httpd.apache.org/docs/mod/mod_rewrite.html',
'https://www.google.com/search?q=apache+mod_rewrite'
);
echo '</p></div>';
}
}
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>
<p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
<?php // @todo: Link to an MS readme? ?>
<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(
/* translators: 1: hostname */
_x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ),
$hostname
);
?>
</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(
/* translators: 1: hostname */
_x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ),
$hostname
);
?>
</td>
</tr>
</table>
<?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>';
}
$is_www = ( 0 === strpos( $hostname, 'www.' ) );
if ( $is_www ) :
?>
<h3><?php esc_html_e( 'Server Address' ); ?></h3>
<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>
<table class="form-table">
<tr>
<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>
<?php endif; ?>
<h3><?php esc_html_e( 'Network Details' ); ?></h3>
<table class="form-table">
<?php if ( 'localhost' == $hostname ) : ?>
<tr>
<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
<td>
<?php
printf(
/* 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>
</tr>
<?php elseif ( ! allow_subdomain_install() ) : ?>
<tr>
<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
<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>
</tr>
<?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.' );
echo ' <strong>' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
?>
</td>
</tr>
<?php endif; ?>
<?php if ( ! $is_www ) : ?>
<tr>
<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>
<?php endif; ?>
<tr>
<th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
<td>
<input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
<p class="description">
<?php _e( 'What would you like to call your network?' ); ?>
</p>
</td>
</tr>
<tr>
<th scope='row'><?php esc_html_e( 'Network Admin Email' ); ?></th>
<td>
<input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
<p class="description">
<?php _e( 'Your email address.' ); ?>
</p>
</td>
</tr>
</table>
<?php submit_button( __( 'Install' ), 'primary', 'submit' ); ?>
</form>
<?php
}
/**
* Prints step 2 for Network installation process.
*
* @since 3.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param WP_Error $errors
*/
function network_step2( $errors = false ) {
global $wpdb;
$hostname = get_clean_basedomain();
$slashed_home = trailingslashit( get_option( 'home' ) );
$base = parse_url( $slashed_home, PHP_URL_PATH );
$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
$abspath_fix = str_replace( '\\', '/', ABSPATH );
$home_path = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
$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 );
}
$location_of_wp_config = trailingslashit( $location_of_wp_config );
// Wildcard DNS message.
if ( is_wp_error( $errors ) ) {
echo '<div class="error">' . $errors->get_error_message() . '</div>';
}
if ( $_POST ) {
if ( allow_subdomain_install() ) {
$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
} 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
} 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
}
}
$subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
$subdir_replacement_01 = $subdomain_install ? '' : '$1';
$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: %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 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>',
/*
* translators: This string should only be translated if wp-config-sample.php is localized.
* 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 publishing.' ) . ' */</code>'
);
?>
</p>
<textarea class="code" readonly="readonly" cols="100" rows="7">
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
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' => '',
);
foreach ( $keys_salts as $c => $v ) {
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/' );
if ( is_wp_error( $from_api ) ) {
foreach ( $keys_salts as $c => $v ) {
$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
}
} else {
$from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
foreach ( $keys_salts as $c => $v ) {
$keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
}
}
$num_keys_salts = count( $keys_salts );
?>
<p>
<?php
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
}
?>
</li>
<?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_replacement = $subdomain_install ? '' : '{R:1}';
$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress Rule 1" stopProcessing="true">
<match url="^index\.php$" ignoreCase="false" />
<action type="None" />
</rule>';
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 .= '
<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" />
</rule>
<rule name="WordPress Rule 3" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="WordPress Rule 4" stopProcessing="true">
<match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" />
<action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
</rule>
<rule name="WordPress Rule 5" stopProcessing="true">
<match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
<action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
</rule>
<rule name="WordPress Rule 6" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</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 '</p>';
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></li>
</ol>
<?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 .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
}
$htaccess_file = <<<EOF
RewriteEngine On
RewriteBase {$base}
RewriteRule ^index\.php$ - [L]
{$ms_files_rewriting}
# add a trailing slash to /wp-admin
RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
RewriteRule . index.php [L]
EOF;
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>.htaccess</code>',
'<code>' . $home_path . '</code>'
);
echo '</p>';
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>
</ol>
<?php
endif; // end IIS/Apache code branches.
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
}
}

View File

@ -0,0 +1,114 @@
<?php
/**
* Noop functions for load-scripts.php and load-styles.php.
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* @ignore
*/
function __() {}
/**
* @ignore
*/
function _x() {}
/**
* @ignore
*/
function add_filter() {}
/**
* @ignore
*/
function esc_attr() {}
/**
* @ignore
*/
function apply_filters() {}
/**
* @ignore
*/
function get_option() {}
/**
* @ignore
*/
function is_lighttpd_before_150() {}
/**
* @ignore
*/
function add_action() {}
/**
* @ignore
*/
function did_action() {}
/**
* @ignore
*/
function do_action_ref_array() {}
/**
* @ignore
*/
function get_bloginfo() {}
/**
* @ignore
*/
function is_admin() {
return true;}
/**
* @ignore
*/
function site_url() {}
/**
* @ignore
*/
function admin_url() {}
/**
* @ignore
*/
function home_url() {}
/**
* @ignore
*/
function includes_url() {}
/**
* @ignore
*/
function wp_guess_url() {}
if ( ! function_exists( 'json_encode' ) ) :
/**
* @ignore
*/
function json_encode() {}
endif;
function get_file( $path ) {
if ( function_exists( 'realpath' ) ) {
$path = realpath( $path );
}
if ( ! $path || ! @is_file( $path ) ) {
return '';
}
return @file_get_contents( $path );
}

View File

@ -0,0 +1,124 @@
<?php
/**
* WordPress Options Administration API.
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Output JavaScript to toggle display of additional settings if avatars are disabled.
*
* @since 4.2.0
*/
function options_discussion_add_js() {
?>
<script>
(function($){
var parent = $( '#show_avatars' ),
children = $( '.avatar-settings' );
parent.change(function(){
children.toggleClass( 'hide-if-js', ! this.checked );
});
})(jQuery);
</script>
<?php
}
/**
* Display JavaScript on the page.
*
* @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(),
homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
$( '#blogname' ).on( 'input', function() {
var title = $.trim( $( this ).val() ) || homeURL;
// Truncate to 40 characters.
if ( 40 < title.length ) {
title = title.substring( 0, 40 ) + '\u2026';
}
$siteName.text( title );
});
$("input[name='date_format']").click(function(){
if ( "date_format_custom_radio" != $(this).attr("id") )
$( 'input[name="date_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
});
$( 'input[name="date_format_custom"]' ).on( 'click input', function() {
$( '#date_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='time_format']").click(function(){
if ( "time_format_custom_radio" != $(this).attr("id") )
$( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
});
$( 'input[name="time_format_custom"]' ).on( 'click input', function() {
$( '#time_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
var format = $( this ),
fieldset = format.closest( 'fieldset' ),
example = fieldset.find( '.example' ),
spinner = fieldset.find( '.spinner' );
spinner.addClass( 'is-active' );
$.post( ajaxurl, {
action: 'date_format_custom' == format.attr( 'name' ) ? 'date_format' : 'time_format',
date : format.val()
}, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
});
var languageSelect = $( '#WPLANG' );
$( 'form' ).submit( function() {
// Don't show a spinner for English and installed languages,
// as there is nothing to download.
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
}
});
});
</script>
<?php
}
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_reading_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var section = $('#front-static-pages'),
staticPage = section.find('input:radio[value="page"]'),
selects = section.find('select'),
check_disabled = function(){
selects.prop( 'disabled', ! staticPage.prop('checked') );
};
check_disabled();
section.find('input:radio').change(check_disabled);
});
</script>
<?php
}
/**
* Render the site charset setting.
*
* @since 3.5.0
*/
function options_reading_blog_charset() {
echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
echo '<p class="description">' . __( 'The <a href="https://codex.wordpress.org/Glossary#Character_set">character encoding</a> of your site (UTF-8 is recommended)' ) . '</p>';
}

View File

@ -0,0 +1,846 @@
<?php
/**
* WordPress Plugin Install Administration API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Retrieves plugin installer pages from the WordPress.org Plugins API.
*
* It is possible for a plugin to override the Plugin API result with three
* filters. Assume this is for plugins, which can extend on the Plugin Info to
* offer more choices. This is very powerful and must be used with care when
* overriding the filters.
*
* The first filter, {@see 'plugins_api_args'}, is for the args and gives the action
* as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that
* an object is returned.
*
* The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org
* Plugin Installation API entirely. If `$action` is 'query_plugins' or 'plugin_information',
* an object MUST be passed. If `$action` is 'hot_tags' or 'hot_categories', an array MUST
* be passed.
*
* Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the
* response object or array, depending on the `$action` type.
*
* Supported arguments per action:
*
* | Argument Name | query_plugins | plugin_information | hot_tags | hot_categories |
* | -------------------- | :-----------: | :----------------: | :------: | :------------: |
* | `$slug` | No | Yes | No | No |
* | `$per_page` | Yes | No | No | No |
* | `$page` | Yes | No | No | No |
* | `$number` | No | No | Yes | Yes |
* | `$search` | Yes | No | No | No |
* | `$tag` | Yes | No | No | No |
* | `$author` | Yes | No | No | No |
* | `$user` | Yes | No | No | No |
* | `$browse` | Yes | No | No | No |
* | `$locale` | Yes | Yes | No | No |
* | `$installed_plugins` | Yes | No | No | No |
* | `$is_ssl` | Yes | Yes | No | No |
* | `$fields` | Yes | Yes | No | No |
*
* @since 2.7.0
*
* @param string $action API action to perform: 'query_plugins', 'plugin_information',
* 'hot_tags' or 'hot_categories'.
* @param array|object $args {
* Optional. Array or object of arguments to serialize for the Plugin Info API.
*
* @type string $slug The plugin slug. Default empty.
* @type int $per_page Number of plugins per page. Default 24.
* @type int $page Number of current page. Default 1.
* @type int $number Number of tags or categories to be queried.
* @type string $search A search term. Default empty.
* @type string $tag Tag to filter plugins. Default empty.
* @type string $author Username of an plugin author to filter plugins. Default empty.
* @type string $user Username to query for their favorites. Default empty.
* @type string $browse Browse view: 'popular', 'new', 'beta', 'recommended'.
* @type string $locale Locale to provide context-sensitive results. Default is the value
* of get_locale().
* @type string $installed_plugins Installed plugins to provide context-sensitive results.
* @type bool $is_ssl Whether links should be returned with https or not. Default false.
* @type array $fields {
* Array of fields which should or should not be returned.
*
* @type bool $short_description Whether to return the plugin short description. Default true.
* @type bool $description Whether to return the plugin full description. Default false.
* @type bool $sections Whether to return the plugin readme sections: description, installation,
* FAQ, screenshots, other notes, and changelog. Default false.
* @type bool $tested Whether to return the 'Compatible up to' value. Default true.
* @type bool $requires Whether to return the required WordPress version. Default true.
* @type bool $rating Whether to return the rating in percent and total number of ratings.
* Default true.
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default true.
* @type bool $downloaded Whether to return the download count. Default true.
* @type bool $downloadlink Whether to return the download link for the package. Default true.
* @type bool $last_updated Whether to return the date of the last update. Default true.
* @type bool $added Whether to return the date when the plugin was added to the wordpress.org
* repository. Default true.
* @type bool $tags Whether to return the assigned tags. Default true.
* @type bool $compatibility Whether to return the WordPress compatibility list. Default true.
* @type bool $homepage Whether to return the plugin homepage link. Default true.
* @type bool $versions Whether to return the list of all available versions. Default false.
* @type bool $donate_link Whether to return the donation link. Default true.
* @type bool $reviews Whether to return the plugin reviews. Default false.
* @type bool $banners Whether to return the banner images links. Default false.
* @type bool $icons Whether to return the icon links. Default false.
* @type bool $active_installs Whether to return the number of active installations. Default false.
* @type bool $group Whether to return the assigned group. Default false.
* @type bool $contributors Whether to return the list of contributors. Default false.
* }
* }
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
* {@link https://developer.wordpress.org/reference/functions/plugins_api/ function reference article}
* 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 ( '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.
*
* Important: An object MUST be returned to this filter.
*
* @since 2.7.0
*
* @param object $args Plugin API arguments.
* @param string $action The type of information being requested from the Plugin Installation API.
*/
$args = apply_filters( 'plugins_api_args', $args, $action );
/**
* Filters the response for the current WordPress.org Plugin Installation API request.
*
* Passing a non-false value will effectively short-circuit the WordPress.org API request.
*
* If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
* If `$action` is 'hot_tags' or 'hot_categories', an array should be passed.
*
* @since 2.7.0
*
* @param false|object|array $result The result object or array. Default false.
* @param string $action The type of information being requested from the Plugin Installation API.
* @param object $args Plugin API arguments.
*/
$res = apply_filters( 'plugins_api', false, $action, $args );
if ( false === $res ) {
$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,
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
);
$request = wp_remote_get( $url, $http_args );
if ( $ssl && is_wp_error( $request ) ) {
trigger_error(
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>.' ),
__( 'https://wordpress.org/support/' )
) . ' ' . __( '(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_get( $http_url, $http_args );
}
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>.' ),
__( 'https://wordpress.org/support/' )
),
$request->get_error_message()
);
} else {
$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>.' ),
__( 'https://wordpress.org/support/' )
),
wp_remote_retrieve_body( $request )
);
}
if ( isset( $res->error ) ) {
$res = new WP_Error( 'plugins_api_failed', $res->error );
}
}
} elseif ( ! is_wp_error( $res ) ) {
$res->external = true;
}
/**
* Filters the Plugin Installation API response results.
*
* @since 2.7.0
*
* @param object|WP_Error $res Response object or WP_Error.
* @param string $action The type of information being requested from the Plugin Installation API.
* @param object $args Plugin API arguments.
*/
return apply_filters( 'plugins_api_result', $res, $action, $args );
}
/**
* Retrieve popular WordPress plugin tags.
*
* @since 2.7.0
*
* @param array $args
* @return array
*/
function install_popular_tags( $args = array() ) {
$key = md5( serialize( $args ) );
if ( false !== ( $tags = get_site_transient( 'poptags_' . $key ) ) ) {
return $tags;
}
$tags = plugins_api( 'hot_tags', $args );
if ( is_wp_error( $tags ) ) {
return $tags;
}
set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
return $tags;
}
/**
* @since 2.7.0
*/
function install_dashboard() {
?>
<p><?php printf( __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%1$s">WordPress Plugin Directory</a> or upload a plugin in .zip format by clicking the button at the top of this page.' ), __( 'https://wordpress.org/plugins/' ) ); ?></p>
<?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>
<?php
$api_tags = install_popular_tags();
echo '<p class="popular-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'],
);
$tags[ $tag['name'] ] = (object) $data;
}
echo wp_generate_tag_cloud(
$tags,
array(
'single_text' => __( '%s plugin' ),
'multiple_text' => __( '%s plugins' ),
)
);
}
echo '</p><br class="clear" /></div>';
}
/**
* Displays a search form for searching plugins.
*
* @since 2.7.0
* @since 4.6.0 The `$type_selector` parameter was deprecated.
*
* @param bool $deprecated Not used.
*/
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">
<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">
<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', '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...' ); ?>" />
</label>
<?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?>
</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' ); ?>">
<?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
}
/**
* Show a username form for the favorites page
*
* @since 3.5.0
*/
function install_plugins_favorites_form() {
$user = get_user_option( 'wporg_favorites' );
$action = 'save_wporg_username_' . get_current_user_id();
?>
<p class="install-help"><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p>
<form method="get">
<input type="hidden" name="tab" value="favorites" />
<p>
<label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label>
<input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" />
<input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
<input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" />
</p>
</form>
<?php
}
/**
* Display plugin content based on plugin list.
*
* @since 2.7.0
*
* @global WP_List_Table $wp_list_table
*/
function display_plugins_table() {
global $wp_list_table;
switch ( current_filter() ) {
case 'install_plugins_favorites':
if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
return;
}
break;
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':
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/'
);
break;
}
?>
<form id="plugin-filter" method="post">
<?php $wp_list_table->display(); ?>
</form>
<?php
}
/**
* Determine the status we can perform on a plugin.
*
* @since 3.0.0
*
* @param array|object $api Data about the plugin retrieved from the API.
* @param bool $loop Optional. Disable further loops. Default false.
* @return array {
* Plugin installation status data.
*
* @type string $status Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
* @type string $url Plugin installation URL.
* @type string $version The most recent version of the plugin.
* @type string $file Plugin filename relative to the plugins directory.
* }
*/
function install_plugin_install_status( $api, $loop = false ) {
// This function is called recursively, $loop prevents further loops.
if ( is_array( $api ) ) {
$api = (object) $api;
}
// Default to a "new" plugin
$status = 'install';
$url = false;
$update_file = false;
$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' );
if ( isset( $update_plugins->response ) ) {
foreach ( (array) $update_plugins->response as $file => $plugin ) {
if ( $plugin->slug === $api->slug ) {
$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 );
}
break;
}
}
}
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 );
}
} 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
$update_file = $api->slug . '/' . $key;
if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) {
$status = 'latest_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' );
wp_update_plugins();
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 ( isset( $_GET['from'] ) ) {
$url .= '&amp;from=' . urlencode( wp_unslash( $_GET['from'] ) );
}
$file = $update_file;
return compact( 'status', 'url', 'version', 'file' );
}
/**
* Display plugin information in dialog box form.
*
* @since 2.7.0
*
* @global string $tab
*/
function install_plugin_information() {
global $tab;
if ( empty( $_REQUEST['plugin'] ) ) {
return;
}
$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(),
),
'blockquote' => array( 'cite' => true ),
);
$plugins_section_titles = array(
'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' ),
);
// Sanitize HTML
foreach ( (array) $api->sections as $section_name => $content ) {
$api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags );
}
foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
if ( isset( $api->$key ) ) {
$api->$key = wp_kses( $api->$key, $plugins_allowedtags );
}
}
$_tab = esc_attr( $tab );
$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 );
}
iframe_header( __( 'Plugin Installation' ) );
$_with_banner = '';
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'];
?>
<style type="text/css">
#plugin-information-title.with-banner {
background-image: url( <?php echo esc_url( $low ); ?> );
}
@media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) {
#plugin-information-title.with-banner {
background-image: url( <?php echo esc_url( $high ); ?> );
}
}
</style>
<?php
}
echo '<div id="plugin-information-scrollable">';
echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
foreach ( (array) $api->sections as $section_name => $content ) {
if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
continue;
}
if ( isset( $plugins_section_titles[ $section_name ] ) ) {
$title = $plugins_section_titles[ $section_name ];
} else {
$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 );
$san_section = esc_attr( $section_name );
echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
}
echo "</div>\n";
?>
<div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
<div class="fyi">
<ul>
<?php if ( ! empty( $api->version ) ) { ?>
<li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
<?php } if ( ! empty( $api->author ) ) { ?>
<li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li>
<?php } if ( ! empty( $api->last_updated ) ) { ?>
<li><strong><?php _e( 'Last Updated:' ); ?></strong>
<?php
/* translators: %s: Time since the last update */
printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) );
?>
</li>
<?php } if ( ! empty( $api->requires ) ) { ?>
<li>
<strong><?php _e( 'Requires WordPress Version:' ); ?></strong>
<?php
/* translators: %s: version number */
printf( __( '%s or higher' ), $api->requires );
?>
</li>
<?php } if ( ! empty( $api->tested ) ) { ?>
<li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
<?php } if ( ! empty( $api->requires_php ) ) { ?>
<li>
<strong><?php _e( 'Requires PHP Version:' ); ?></strong>
<?php
/* translators: %s: version number */
printf( __( '%s or higher' ), $api->requires_php );
?>
</li>
<?php } if ( isset( $api->active_installs ) ) { ?>
<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 ) ) { ?>
<li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a></li>
<?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
<li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a></li>
<?php } ?>
</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,
)
);
?>
<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
}
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
foreach ( $api->ratings as $key => $ratecount ) {
// 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 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-back">
<span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
</span>
<span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span>
</div>
<?php
}
}
if ( ! empty( $api->contributors ) ) {
?>
<h3><?php _e( 'Contributors' ); ?></h3>
<ul class="contributors">
<?php
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 ) ) { ?>
<a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
<?php } ?>
<?php } ?>
</div>
<div id="section-holder" class="wrap">
<?php
$wp_version = get_bloginfo( 'version' );
$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 ) {
$content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
$content = links_add_target( $content, '_blank' );
$san_section = esc_attr( $section_name );
$display = ( $section_name === $section ) ? 'block' : 'none';
echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
echo $content;
echo "\t</div>\n";
}
echo "</div>\n";
echo "</div>\n";
echo "</div>\n"; // #plugin-information-scrollable
echo "<div id='$tab-footer'>\n";
if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
$status = install_plugin_install_status( $api );
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
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>';
}
break;
case 'newer_installed':
/* translators: %s: Plugin version */
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>';
break;
}
}
echo "</div>\n";
iframe_footer();
exit;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,456 @@
<?php
/**
* WordPress Administration Revisions API
*
* @package WordPress
* @subpackage Administration
* @since 3.6.0
*/
/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $compare_from The revision ID to compare from.
* @param int $compare_to The revision ID to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
if ( ! $post = get_post( $post ) ) {
return false;
}
if ( $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 ) ) {
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 ) {
return false;
}
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;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ( $compare_from && empty( $compare_from->post_title ) ) {
$compare_from->post_title = __( '(no title)' );
}
if ( empty( $compare_to->post_title ) ) {
$compare_to->post_title = __( '(no title)' );
}
$return = array();
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
/**
* Contextually filter a post revision field.
*
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
* fields of the revision object being iterated over in a foreach statement.
*
* @since 3.6.0
*
* @param string $compare_from->$field The current revision field to compare to or from.
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post object to compare to or from.
* @param string null The context of whether the current revision is the old
* or the new one. Values are 'to' or 'from'.
*/
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
/** This filter is documented in wp-admin/includes/revision.php */
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
$args = array(
'show_split_view' => true,
);
/**
* Filters revisions text diff options.
*
* Filters the options passed to wp_text_diff() when viewing a post revision.
*
* @since 4.1.0
*
* @param array $args {
* Associative array of options to pass to wp_text_diff().
*
* @type bool $show_split_view True for split view (two columns), false for
* un-split view (single column). Default true.
* }
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
$diff = wp_text_diff( $content_from, $content_to, $args );
if ( ! $diff && 'post_title' === $field ) {
// 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>';
// 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,
'name' => $name,
'diff' => $diff,
);
}
}
/**
* Filters the fields displayed in the post revision diff UI.
*
* @since 4.1.0
*
* @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.
*/
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
}
/**
* Prepare revisions for JavaScript.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $selected_revision_id The selected revision ID.
* @param int $from Optional. The revision ID to compare from.
*
* @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 );
$authors = array();
$now_gmt = time();
$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 ) ) {
unset( $revisions[ $revision_id ] );
}
}
$revisions = array( $post->ID => $post ) + $revisions;
}
$show_avatars = get_option( 'show_avatars' );
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
$can_restore = current_user_can( 'edit_post', $post->ID );
$current_id = false;
foreach ( $revisions as $revision ) {
$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',
),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
)
);
}
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'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;
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;
} else {
$current = false;
}
} elseif ( $current ) {
$current_id = $revision->ID;
}
$revisions_data = array(
'id' => $revision->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $revision->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
'autosave' => $autosave,
'current' => $current,
'restoreUrl' => $can_restore ? $restore_link : false,
);
/**
* Filters the array of revisions used on the revisions screen.
*
* @since 4.4.0
*
* @param array $revisions_data {
* The bootstrapped data for the revisions screen.
*
* @type int $id Revision ID.
* @type string $title Title for the revision's parent WP_Post object.
* @type int $author Revision post author ID.
* @type string $date Date the revision was modified.
* @type string $dateShort Short-form version of the date the revision was modified.
* @type string $timeAgo GMT-aware amount of time ago the revision was modified.
* @type bool $autosave Whether the revision is an autosave.
* @type bool $current Whether the revision is both not an autosave and the post
* modified date matches the revision modified date (GMT-aware).
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise.
* }
* @param WP_Post $revision The revision's WP_Post object.
* @param WP_Post $post The revision's parent WP_Post object.
*/
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
}
/**
* If we only have one revision, the initial revision is missing; This happens
* when we have an autsosave and the user has clicked 'View the Autosave'
*/
if ( 1 === sizeof( $revisions ) ) {
$revisions[ $post->ID ] = array(
'id' => $post->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $post->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
'autosave' => false,
'current' => true,
'restoreUrl' => false,
);
$current_id = $post->ID;
}
/*
* If a post has been saved since the last revision (no revisioned fields
* were changed), we may not have a "current" revision. Mark the latest
* revision as "current".
*/
if ( empty( $current_id ) ) {
if ( $revisions[ $revision->ID ]['autosave'] ) {
$revision = end( $revisions );
while ( $revision['autosave'] ) {
$revision = prev( $revisions );
}
$current_id = $revision['id'];
} else {
$current_id = $revision->ID;
}
$revisions[ $current_id ]['current'] = true;
}
// Now, grab the initial diff.
$compare_two_mode = is_numeric( $from );
if ( ! $compare_two_mode ) {
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
if ( $found ) {
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
$from = reset( $from );
} else {
$from = 0;
}
}
$from = absint( $from );
$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 ),
);
}
/**
* Print JavaScript templates required for the revisions experience.
*
* @since 4.1.0
*
* @global WP_Post $post The global `$post` object.
*/
function wp_print_revision_templates() {
global $post;
?><script id="tmpl-revisions-frame" type="text/html">
<div class="revisions-control-frame"></div>
<div class="revisions-diff-frame"></div>
</script>
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</div>
<div class="revisions-next">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
</div>
</script>
<script id="tmpl-revisions-checkbox" type="text/html">
<div class="revision-toggle-compare-mode">
<label>
<input type="checkbox" class="compare-two-revisions"
<#
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
#> checked="checked"<#
}
#>
/>
<?php esc_html_e( 'Compare any two revisions' ); ?>
</label>
</div>
</script>
<script id="tmpl-revisions-meta" type="text/html">
<# if ( ! _.isUndefined( data.attributes ) ) { #>
<div class="diff-title">
<# if ( 'from' === data.type ) { #>
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
<# } else if ( 'to' === data.type ) { #>
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
<# } #>
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
{{{ 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>
<# } else if ( data.attributes.current ) { #>
<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="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
</div>
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
disabled="disabled"
<?php } else { ?>
<# if ( data.attributes.current ) { #>
disabled="disabled"
<# } #>
<?php } ?>
<# if ( data.attributes.autosave ) { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
<# } else { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
<# } #>
<# } #>
</div>
<# if ( 'tooltip' === data.type ) { #>
<div class="revisions-tooltip-arrow"><span></span></div>
<# } #>
<# } #>
</script>
<script id="tmpl-revisions-diff" type="text/html">
<div class="loading-indicator"><span class="spinner"></span></div>
<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
<div class="diff">
<# _.each( data.fields, function( field ) { #>
<h3>{{ field.name }}</h3>
{{{ field.diff }}}
<# }); #>
</div>
</script>
<?php
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,242 @@
<?php
/**
* WordPress Administration Screen API.
*
* @package WordPress
* @subpackage Administration
*/
/**
* Get the column headers for a screen
*
* @since 2.7.0
*
* @staticvar array $column_headers
*
* @param string|WP_Screen $screen The screen you want the headers for
* @return array Containing the headers in the format id => UI String
*/
function get_column_headers( $screen ) {
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
static $column_headers = array();
if ( ! isset( $column_headers[ $screen->id ] ) ) {
/**
* Filters the column headers for a list table on a specific screen.
*
* The dynamic portion of the hook name, `$screen->id`, refers to the
* ID of a specific screen. For example, the screen ID for the Posts
* list table is edit-post, so the filter for that screen would be
* manage_edit-post_columns.
*
* @since 3.0.0
*
* @param array $columns An array of column headers. Default empty.
*/
$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
}
return $column_headers[ $screen->id ];
}
/**
* Get a list of hidden columns.
*
* @since 2.7.0
*
* @param string|WP_Screen $screen The screen you want the hidden columns for
* @return array
*/
function get_hidden_columns( $screen ) {
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
$hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
$use_defaults = ! is_array( $hidden );
if ( $use_defaults ) {
$hidden = array();
/**
* Filters the default list of hidden columns.
*
* @since 4.4.0
*
* @param array $hidden An array of columns hidden by default.
* @param WP_Screen $screen WP_Screen object of the current screen.
*/
$hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
}
/**
* Filters the list of hidden columns.
*
* @since 4.4.0
* @since 4.4.1 Added the `use_defaults` parameter.
*
* @param array $hidden An array of hidden columns.
* @param WP_Screen $screen WP_Screen object of the current screen.
* @param bool $use_defaults Whether to show the default columns.
*/
return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults );
}
/**
* Prints the meta box preferences for screen meta.
*
* @since 2.7.0
*
* @global array $wp_meta_boxes
*
* @param WP_Screen $screen
*/
function meta_box_prefs( $screen ) {
global $wp_meta_boxes;
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
return;
}
$hidden = get_hidden_meta_boxes( $screen );
foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
continue;
}
foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
if ( false == $box || ! $box['title'] ) {
continue;
}
// Submit box cannot be hidden
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) {
continue;
}
$widget_title = $box['title'];
if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
$widget_title = $box['args']['__widget_basename'];
}
printf(
'<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>',
esc_attr( $box['id'] ),
checked( in_array( $box['id'], $hidden ), false, false ),
$widget_title
);
}
}
}
}
/**
* Get Hidden Meta Boxes
*
* @since 2.7.0
*
* @param string|WP_Screen $screen Screen identifier
* @return array Hidden Meta Boxes
*/
function get_hidden_meta_boxes( $screen ) {
if ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
$use_defaults = ! is_array( $hidden );
// Hide slug boxes by default
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 {
$hidden = array( 'slugdiv' );
}
}
/**
* Filters the default list of hidden meta boxes.
*
* @since 3.1.0
*
* @param array $hidden An array of meta boxes hidden by default.
* @param WP_Screen $screen WP_Screen object of the current screen.
*/
$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
}
/**
* Filters the list of hidden meta boxes.
*
* @since 3.3.0
*
* @param array $hidden An array of hidden meta boxes.
* @param WP_Screen $screen WP_Screen object of the current screen.
* @param bool $use_defaults Whether to show the default meta boxes.
* Default true.
*/
return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
}
/**
* Register and configure an admin screen option
*
* @since 3.1.0
*
* @param string $option An option name.
* @param mixed $args Option-dependent arguments.
*/
function add_screen_option( $option, $args = array() ) {
$current_screen = get_current_screen();
if ( ! $current_screen ) {
return;
}
$current_screen->add_option( $option, $args );
}
/**
* Get the current screen object
*
* @since 3.1.0
*
* @global WP_Screen $current_screen
*
* @return WP_Screen|null Current screen object or null when screen not defined.
*/
function get_current_screen() {
global $current_screen;
if ( ! isset( $current_screen ) ) {
return null;
}
return $current_screen;
}
/**
* Set the current screen object
*
* @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.
*/
function set_current_screen( $hook_name = '' ) {
WP_Screen::get( $hook_name )->set_current_screen();
}

View File

@ -0,0 +1,308 @@
<?php
/**
* WordPress Taxonomy Administration API.
*
* @package WordPress
* @subpackage Administration
*/
//
// Category
//
/**
* Check whether a category exists.
*
* @since 2.0.0
*
* @see term_exists()
*
* @param int|string $cat_name Category name.
* @param int $parent Optional. ID of parent term.
* @return mixed
*/
function category_exists( $cat_name, $parent = null ) {
$id = term_exists( $cat_name, 'category', $parent );
if ( is_array( $id ) ) {
$id = $id['term_id'];
}
return $id;
}
/**
* Get category object for given ID and 'edit' filter context.
*
* @since 2.0.0
*
* @param int $id
* @return object
*/
function get_category_to_edit( $id ) {
$category = get_term( $id, 'category', OBJECT, 'edit' );
_make_cat_compat( $category );
return $category;
}
/**
* Add a new category to the database if it does not already exist.
*
* @since 2.0.0
*
* @param int|string $cat_name
* @param int $parent
* @return int|WP_Error
*/
function wp_create_category( $cat_name, $parent = 0 ) {
if ( $id = category_exists( $cat_name, $parent ) ) {
return $id;
}
return wp_insert_category(
array(
'cat_name' => $cat_name,
'category_parent' => $parent,
)
);
}
/**
* Create categories for the given post.
*
* @since 2.0.0
*
* @param string[] $categories Array of category names to create.
* @param int $post_id Optional. The post ID. Default empty.
* @return array List of categories to create for the given post.
*/
function wp_create_categories( $categories, $post_id = '' ) {
$cat_ids = array();
foreach ( $categories as $category ) {
if ( $id = category_exists( $category ) ) {
$cat_ids[] = $id;
} elseif ( $id = wp_create_category( $category ) ) {
$cat_ids[] = $id;
}
}
if ( $post_id ) {
wp_set_post_categories( $post_id, $cat_ids );
}
return $cat_ids;
}
/**
* Updates an existing Category or creates a new Category.
*
* @since 2.0.0
* @since 2.5.0 $wp_error parameter was added.
* @since 3.0.0 The 'taxonomy' argument was added.
*
* @param array $catarr {
* Array of arguments for inserting a new category.
*
* @type int $cat_ID Category ID. A non-zero value updates an existing category.
* Default 0.
* @type string $taxonomy Taxonomy slug. Default 'category'.
* @type string $cat_name Category name. Default empty.
* @type string $category_description Category description. Default empty.
* @type string $category_nicename Category nice (display) name. Default empty.
* @type int|string $category_parent Category parent ID. Default empty.
* }
* @param bool $wp_error Optional. Default false.
* @return int|object The ID number of the new or updated Category on success. Zero or a WP_Error on failure,
* depending on param $wp_error.
*/
function wp_insert_category( $catarr, $wp_error = false ) {
$cat_defaults = array(
'cat_ID' => 0,
'taxonomy' => 'category',
'cat_name' => '',
'category_description' => '',
'category_nicename' => '',
'category_parent' => '',
);
$catarr = wp_parse_args( $catarr, $cat_defaults );
if ( trim( $catarr['cat_name'] ) == '' ) {
if ( ! $wp_error ) {
return 0;
} else {
return new WP_Error( 'cat_name', __( 'You did not enter a category name.' ) );
}
}
$catarr['cat_ID'] = (int) $catarr['cat_ID'];
// Are we updating or creating?
$update = ! empty( $catarr['cat_ID'] );
$name = $catarr['cat_name'];
$description = $catarr['category_description'];
$slug = $catarr['category_nicename'];
$parent = (int) $catarr['category_parent'];
if ( $parent < 0 ) {
$parent = 0;
}
if ( empty( $parent )
|| ! term_exists( $parent, $catarr['taxonomy'] )
|| ( $catarr['cat_ID'] && term_is_ancestor_of( $catarr['cat_ID'], $parent, $catarr['taxonomy'] ) ) ) {
$parent = 0;
}
$args = compact( 'name', 'slug', 'parent', 'description' );
if ( $update ) {
$catarr['cat_ID'] = wp_update_term( $catarr['cat_ID'], $catarr['taxonomy'], $args );
} else {
$catarr['cat_ID'] = wp_insert_term( $catarr['cat_name'], $catarr['taxonomy'], $args );
}
if ( is_wp_error( $catarr['cat_ID'] ) ) {
if ( $wp_error ) {
return $catarr['cat_ID'];
} else {
return 0;
}
}
return $catarr['cat_ID']['term_id'];
}
/**
* Aliases wp_insert_category() with minimal args.
*
* If you want to update only some fields of an existing category, call this
* function with only the new values set inside $catarr.
*
* @since 2.0.0
*
* @param array $catarr The 'cat_ID' value is required. All other keys are optional.
* @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure.
*/
function wp_update_category( $catarr ) {
$cat_ID = (int) $catarr['cat_ID'];
if ( isset( $catarr['category_parent'] ) && ( $cat_ID == $catarr['category_parent'] ) ) {
return false;
}
// First, get all of the original fields
$category = get_term( $cat_ID, 'category', ARRAY_A );
_make_cat_compat( $category );
// Escape data pulled from DB.
$category = wp_slash( $category );
// Merge old and new fields with new fields overwriting old ones.
$catarr = array_merge( $category, $catarr );
return wp_insert_category( $catarr );
}
//
// Tags
//
/**
* Check whether a post tag with a given name exists.
*
* @since 2.3.0
*
* @param int|string $tag_name
* @return mixed
*/
function tag_exists( $tag_name ) {
return term_exists( $tag_name, 'post_tag' );
}
/**
* Add a new tag to the database if it does not already exist.
*
* @since 2.3.0
*
* @param int|string $tag_name
* @return array|WP_Error
*/
function wp_create_tag( $tag_name ) {
return wp_create_term( $tag_name, 'post_tag' );
}
/**
* Get comma-separated list of tags available to edit.
*
* @since 2.3.0
*
* @param int $post_id
* @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
* @return string|bool|WP_Error
*/
function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
return get_terms_to_edit( $post_id, $taxonomy );
}
/**
* Get comma-separated list of terms available to edit for the given post ID.
*
* @since 2.8.0
*
* @param int $post_id
* @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
* @return string|bool|WP_Error
*/
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$post_id = (int) $post_id;
if ( ! $post_id ) {
return false;
}
$terms = get_object_term_cache( $post_id, $taxonomy );
if ( false === $terms ) {
$terms = wp_get_object_terms( $post_id, $taxonomy );
wp_cache_add( $post_id, wp_list_pluck( $terms, 'term_id' ), $taxonomy . '_relationships' );
}
if ( ! $terms ) {
return false;
}
if ( is_wp_error( $terms ) ) {
return $terms;
}
$term_names = array();
foreach ( $terms as $term ) {
$term_names[] = $term->name;
}
$terms_to_edit = esc_attr( join( ',', $term_names ) );
/**
* Filters the comma-separated list of terms available to edit.
*
* @since 2.8.0
*
* @see get_terms_to_edit()
*
* @param string $terms_to_edit A comma-separated list of term names.
* @param string $taxonomy The taxonomy name for which to retrieve terms.
*/
$terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy );
return $terms_to_edit;
}
/**
* Add a new term to the database if it does not already exist.
*
* @since 2.8.0
*
* @param int|string $tag_name
* @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 ) ) {
return $id;
}
return wp_insert_term( $tag_name, $taxonomy );
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,251 @@
<?php
/**
* WordPress Theme Installation Administration API
*
* @package WordPress
* @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(),
),
);
$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).
*
* @since 2.8.0
*
* @deprecated since 3.1.0 Use get_theme_feature_list() instead.
*
* @return array
*/
function install_themes_feature_list() {
_deprecated_function( __FUNCTION__, '3.1.0', 'get_theme_feature_list()' );
if ( ! $cache = get_transient( 'wporg_theme_feature_list' ) ) {
set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
}
if ( $cache ) {
return $cache;
}
$feature_list = themes_api( 'feature_list', array() );
if ( is_wp_error( $feature_list ) ) {
return array();
}
set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
return $feature_list;
}
/**
* Display search form for searching themes.
*
* @since 2.8.0
*
* @param bool $type_selector
*/
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 ) {
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>
<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>
</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>
<?php else : ?>
<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" />
<?php submit_button( __( 'Search' ), '', 'search', false ); ?>
</form>
<?php
}
/**
* Display tags filter for themes.
*
* @since 2.8.0
*/
function install_themes_dashboard() {
install_theme_search_form( false );
?>
<h4><?php _e( 'Feature Filter' ); ?></h4>
<p class="install-help"><?php _e( 'Find a theme based on specific features.' ); ?></p>
<form method="get">
<input type="hidden" name="tab" value="search" />
<?php
$feature_list = get_theme_feature_list();
echo '<div class="feature-filter">';
foreach ( (array) $feature_list as $feature_name => $features ) {
$feature_name = esc_html( $feature_name );
echo '<div class="feature-name">' . $feature_name . '</div>';
echo '<ol class="feature-group">';
foreach ( $features as $feature => $feature_name ) {
$feature_name = esc_html( $feature_name );
$feature = esc_attr( $feature );
?>
<li>
<input type="checkbox" name="features[]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" />
<label for="feature-id-<?php echo $feature; ?>"><?php echo $feature_name; ?></label>
</li>
<?php } ?>
</ol>
<br class="clear" />
<?php
}
?>
</div>
<br class="clear" />
<?php submit_button( __( 'Find Themes' ), '', 'search' ); ?>
</form>
<?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' ); ?>">
<?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" />
<?php submit_button( __( 'Install Now' ), '', 'install-theme-submit', false ); ?>
</form>
<?php
}
/**
* Prints a theme on the Install Themes pages.
*
* @deprecated 3.4.0
*
* @global WP_Theme_Install_List_Table $wp_list_table
*
* @param object $theme
*/
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->prepare_items();
$wp_list_table->single_row( $theme );
}
/**
* Display theme content based on theme list.
*
* @since 2.8.0
*
* @global WP_Theme_Install_List_Table $wp_list_table
*/
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->prepare_items();
$wp_list_table->display();
}
/**
* Display theme information in dialog box form.
*
* @since 2.8.0
*
* @global WP_Theme_Install_List_Table $wp_list_table
*/
function install_theme_information() {
global $wp_list_table;
$theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) );
if ( is_wp_error( $theme ) ) {
wp_die( $theme );
}
iframe_header( __( 'Theme Installation' ) );
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->theme_installer_single( $theme );
iframe_footer();
exit;
}

View File

@ -0,0 +1,770 @@
<?php
/**
* WordPress Theme Administration API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Remove a theme
*
* @since 2.8.0
*
* @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 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 = '' ) {
global $wp_filesystem;
if ( empty( $stylesheet ) ) {
return false;
}
if ( empty( $redirect ) ) {
$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();
if ( false === $credentials ) {
if ( ! empty( $data ) ) {
include_once( ABSPATH . 'wp-admin/admin-header.php' );
echo $data;
include( ABSPATH . 'wp-admin/admin-footer.php' );
exit;
}
return;
}
if ( ! WP_Filesystem( $credentials ) ) {
ob_start();
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' );
echo $data;
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_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();
if ( empty( $themes_dir ) ) {
return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
}
$themes_dir = trailingslashit( $themes_dir );
$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 ) );
}
$theme_translations = wp_get_installed_translations( 'themes' );
// Remove language files, silently.
if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
$translations = $theme_translations[ $stylesheet ];
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 );
}
}
}
// Remove the theme from allowed themes on the network.
if ( is_multisite() ) {
WP_Theme::network_disable_theme( $stylesheet );
}
// Force refresh of theme update information.
delete_site_transient( 'update_themes' );
return true;
}
/**
* Get the Page Templates available in this theme
*
* @since 1.5.0
* @since 4.7.0 Added the `$post_type` parameter.
*
* @param WP_Post|null $post Optional. The post being edited, provided for context.
* @param string $post_type Optional. Post type to get the templates for. Default 'page'.
* @return array Key is the template name, value is the filename of the template
*/
function get_page_templates( $post = null, $post_type = 'page' ) {
return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
}
/**
* Tidies a filename for url display by the theme editor.
*
* @since 2.9.0
* @access private
*
* @param string $fullpath Full path to the theme file
* @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 );
}
/**
* Check if there is an update for a theme available.
*
* Will display link, if there is an update available.
*
* @since 2.7.0
* @see get_theme_update_available()
*
* @param WP_Theme $theme Theme data object.
*/
function theme_update_available( $theme ) {
echo get_theme_update_available( $theme );
}
/**
* Retrieve the update link if there is a theme update available.
*
* Will return a link if there is an update available.
*
* @since 3.8.0
*
* @staticvar object $themes_update
*
* @param WP_Theme $theme WP_Theme object.
* @return false|string HTML for the update link, or false if invalid info was passed.
*/
function get_theme_update_available( $theme ) {
static $themes_update = null;
if ( ! current_user_can( 'update_themes' ) ) {
return false;
}
if ( ! isset( $themes_update ) ) {
$themes_update = get_site_transient( 'update_themes' );
}
if ( ! ( $theme instanceof WP_Theme ) ) {
return false;
}
$stylesheet = $theme->get_stylesheet();
$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 ( ! 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>',
$theme_name,
esc_url( $details_url ),
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']
);
} 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>',
$theme_name,
esc_url( $details_url ),
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']
);
} 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>',
$theme_name,
esc_url( $details_url ),
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"',
/* translators: %s: theme name */
esc_attr( sprintf( __( 'Update %s now' ), $theme_name ) ),
$stylesheet
)
);
}
}
}
return $html;
}
/**
* Retrieve list of WordPress theme features (aka theme tags).
*
* @since 3.1.0
*
* @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true.
* @return array Array of features keyed by category with translations keyed by slug.
*/
function get_theme_feature_list( $api = true ) {
// Hard-coded list is used if api not accessible.
$features = array(
__( 'Subject' ) => array(
'blog' => __( 'Blog' ),
'e-commerce' => __( 'E-Commerce' ),
'education' => __( 'Education' ),
'entertainment' => __( 'Entertainment' ),
'food-and-drink' => __( 'Food & Drink' ),
'holiday' => __( 'Holiday' ),
'news' => __( 'News' ),
'photography' => __( 'Photography' ),
'portfolio' => __( 'Portfolio' ),
),
__( 'Features' ) => array(
'accessibility-ready' => __( 'Accessibility Ready' ),
'custom-background' => __( 'Custom Background' ),
'custom-colors' => __( 'Custom Colors' ),
'custom-header' => __( 'Custom Header' ),
'custom-logo' => __( 'Custom Logo' ),
'editor-style' => __( 'Editor Style' ),
'featured-image-header' => __( 'Featured Image Header' ),
'featured-images' => __( 'Featured Images' ),
'footer-widgets' => __( 'Footer Widgets' ),
'full-width-template' => __( 'Full Width Template' ),
'post-formats' => __( 'Post Formats' ),
'sticky-post' => __( 'Sticky Post' ),
'theme-options' => __( 'Theme Options' ),
),
__( 'Layout' ) => array(
'grid-layout' => __( 'Grid Layout' ),
'one-column' => __( 'One Column' ),
'two-columns' => __( 'Two Columns' ),
'three-columns' => __( 'Three Columns' ),
'four-columns' => __( 'Four Columns' ),
'left-sidebar' => __( 'Left Sidebar' ),
'right-sidebar' => __( 'Right Sidebar' ),
),
);
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 ) {
return $features;
}
set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
$category_translations = array(
'Layout' => __( 'Layout' ),
'Features' => __( 'Features' ),
'Subject' => __( 'Subject' ),
);
// 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();
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;
}
}
}
return $wporg_features;
}
/**
* Retrieves theme installer pages from the WordPress.org Themes API.
*
* It is possible for a theme to override the Themes API result with three
* filters. Assume this is for themes, which can extend on the Theme Info to
* offer more choices. This is very powerful and must be used with care, when
* overriding the filters.
*
* The first filter, {@see 'themes_api_args'}, is for the args and gives the action
* as the second parameter. The hook for {@see 'themes_api_args'} must ensure that
* an object is returned.
*
* The second filter, {@see 'themes_api'}, allows a plugin to override the WordPress.org
* Theme API entirely. If `$action` is 'query_themes', 'theme_information', or 'feature_list',
* an object MUST be passed. If `$action` is 'hot_tags', an array should be passed.
*
* Finally, the third filter, {@see 'themes_api_result'}, makes it possible to filter the
* response object or array, depending on the `$action` type.
*
* Supported arguments per action:
*
* | Argument Name | 'query_themes' | 'theme_information' | 'hot_tags' | 'feature_list' |
* | -------------------| :------------: | :-----------------: | :--------: | :--------------: |
* | `$slug` | No | Yes | No | No |
* | `$per_page` | Yes | No | No | No |
* | `$page` | Yes | No | No | No |
* | `$number` | No | No | Yes | No |
* | `$search` | Yes | No | No | No |
* | `$tag` | Yes | No | No | No |
* | `$author` | Yes | No | No | No |
* | `$user` | Yes | No | No | No |
* | `$browse` | Yes | No | No | No |
* | `$locale` | Yes | Yes | No | No |
* | `$fields` | Yes | Yes | No | No |
*
* @since 2.8.0
*
* @param string $action API action to perform: 'query_themes', 'theme_information',
* 'hot_tags' or 'feature_list'.
* @param array|object $args {
* Optional. Array or object of arguments to serialize for the Themes API.
*
* @type string $slug The theme slug. Default empty.
* @type int $per_page Number of themes per page. Default 24.
* @type int $page Number of current page. Default 1.
* @type int $number Number of tags to be queried.
* @type string $search A search term. Default empty.
* @type string $tag Tag to filter themes. Default empty.
* @type string $author Username of an author to filter themes. Default empty.
* @type string $user Username to query for their favorites. Default empty.
* @type string $browse Browse view: 'featured', 'popular', 'updated', 'favorites'.
* @type string $locale Locale to provide context-sensitive results. Default is the value of get_locale().
* @type array $fields {
* Array of fields which should or should not be returned.
*
* @type bool $description Whether to return the theme full description. Default false.
* @type bool $sections Whether to return the theme readme sections: description, installation,
* FAQ, screenshots, other notes, and changelog. Default false.
* @type bool $rating Whether to return the rating in percent and total number of ratings.
* Default false.
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default false.
* @type bool $downloaded Whether to return the download count. Default false.
* @type bool $downloadlink Whether to return the download link for the package. Default false.
* @type bool $last_updated Whether to return the date of the last update. Default false.
* @type bool $tags Whether to return the assigned tags. Default false.
* @type bool $homepage Whether to return the theme homepage link. Default false.
* @type bool $screenshots Whether to return the screenshots. Default false.
* @type int $screenshot_count Number of screenshots to return. Default 1.
* @type bool $screenshot_url Whether to return the URL of the first screenshot. Default false.
* @type bool $photon_screenshots Whether to return the screenshots via Photon. Default false.
* @type bool $template Whether to return the slug of the parent theme. Default false.
* @type bool $parent Whether to return the slug, name and homepage of the parent theme. Default false.
* @type bool $versions Whether to return the list of all available versions. Default false.
* @type bool $theme_url Whether to return theme's URL. Default false.
* @type bool $extended_author Whether to return nicename or nicename and display name. Default false.
* }
* }
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
* {@link https://developer.wordpress.org/reference/functions/themes_api/ function reference article}
* 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 ( '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.
*
* Important: An object MUST be returned to this filter.
*
* @since 2.8.0
*
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API.
* @param string $action Requested action. Likely values are 'theme_information',
* 'feature_list', or 'query_themes'.
*/
$args = apply_filters( 'themes_api_args', $args, $action );
/**
* Filters whether to override the WordPress.org Themes API.
*
* Passing a non-false value will effectively short-circuit the WordPress.org API request.
*
* If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST
* be passed. If `$action` is 'hot_tags', an array should be passed.
*
* @since 2.8.0
*
* @param false|object|array $override Whether to override the WordPress.org Themes API. Default false.
* @param string $action Requested action. Likely values are 'theme_information',
* 'feature_list', or 'query_themes'.
* @param object $args Arguments used to query for installer pages from the Themes API.
*/
$res = apply_filters( 'themes_api', false, $action, $args );
if ( ! $res ) {
$url = 'http://api.wordpress.org/themes/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(
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
);
$request = wp_remote_get( $url, $http_args );
if ( $ssl && is_wp_error( $request ) ) {
if ( ! wp_doing_ajax() ) {
trigger_error(
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>.' ),
__( 'https://wordpress.org/support/' )
) . ' ' . __( '(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_get( $http_url, $http_args );
}
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>.' ),
__( 'https://wordpress.org/support/' )
),
$request->get_error_message()
);
} else {
$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>.' ),
__( 'https://wordpress.org/support/' )
),
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;
}
}
/**
* Filters the returned WordPress.org Themes API response.
*
* @since 2.8.0
*
* @param array|object|WP_Error $res WordPress.org Themes API response.
* @param string $action Requested action. Likely values are 'theme_information',
* 'feature_list', or 'query_themes'.
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API.
*/
return apply_filters( 'themes_api_result', $res, $action, $args );
}
/**
* Prepare themes for JavaScript.
*
* @since 3.8.0
*
* @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.
*/
function wp_prepare_themes_for_js( $themes = null ) {
$current_theme = get_stylesheet();
/**
* Filters theme data before it is prepared for JavaScript.
*
* Passing a non-empty array will result in wp_prepare_themes_for_js() returning
* early with that value instead.
*
* @since 4.2.0
*
* @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 );
if ( ! empty( $prepared_themes ) ) {
return $prepared_themes;
}
// Make sure the current theme is listed first.
$prepared_themes[ $current_theme ] = array();
if ( null === $themes ) {
$themes = wp_get_themes( array( 'allowed' => true ) );
if ( ! isset( $themes[ $current_theme ] ) ) {
$themes[ $current_theme ] = wp_get_theme();
}
}
$updates = array();
if ( current_user_can( 'update_themes' ) ) {
$updates_transient = get_site_transient( 'update_themes' );
if ( isset( $updates_transient->response ) ) {
$updates = $updates_transient->response;
}
}
WP_Theme::sort_by_name( $themes );
$parents = array();
foreach ( $themes as $theme ) {
$slug = $theme->get_stylesheet();
$encoded_slug = urlencode( $slug );
$parent = false;
if ( $theme->parent() ) {
$parent = $theme->parent();
$parents[ $slug ] = $parent->get_stylesheet();
$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 )
)
);
}
$prepared_themes[ $slug ] = array(
'id' => $slug,
'name' => $theme->display( 'Name' ),
'screenshot' => array( $theme->get_screenshot() ), // @todo multiple
'description' => $theme->display( 'Description' ),
'author' => $theme->display( 'Author', false, true ),
'authorAndUri' => $theme->display( 'Author' ),
'version' => $theme->display( 'Version' ),
'tags' => $theme->display( 'Tags' ),
'parent' => $parent,
'active' => $slug === $current_theme,
'hasUpdate' => isset( $updates[ $slug ] ),
'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,
'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,
),
);
}
// Remove 'delete' action if theme has an active child
if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) {
unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
}
/**
* Filters the themes prepared for JavaScript, for themes.php.
*
* Could be useful for changing the order, which is by name by default.
*
* @since 3.8.0
*
* @param array $prepared_themes Array of themes.
*/
$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
$prepared_themes = array_values( $prepared_themes );
return array_filter( $prepared_themes );
}
/**
* Print JS templates for the theme-browsing UI in the Customizer.
*
* @since 4.2.0
*/
function customize_themes_print_templates() {
?>
<script type="text/html" id="tmpl-customize-themes-details-view">
<div class="theme-backdrop"></div>
<div class="theme-wrap wp-clearfix" role="document">
<div class="theme-header">
<button type="button" class="left dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show previous theme' ); ?></span></button>
<button type="button" class="right dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show next theme' ); ?></span></button>
<button type="button" class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close details dialog' ); ?></span></button>
</div>
<div class="theme-about wp-clearfix">
<div class="theme-screenshots">
<# if ( data.screenshot && data.screenshot[0] ) { #>
<div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div>
<# } else { #>
<div class="screenshot blank"></div>
<# } #>
</div>
<div class="theme-info">
<# if ( data.active ) { #>
<span class="current-label"><?php _e( 'Current Theme' ); ?></span>
<# } #>
<h2 class="theme-name">{{{ data.name }}}<span class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></span></h2>
<h3 class="theme-author"><?php printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); ?></h3>
<# if ( data.stars && 0 != data.num_ratings ) { #>
<div class="theme-rating">
{{{ data.stars }}}
<span class="num-ratings">
<?php
/* translators: %s: number of ratings */
echo sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' );
?>
</span>
</div>
<# } #>
<# if ( data.hasUpdate ) { #>
<div class="notice notice-warning notice-alt notice-large" data-slug="{{ data.id }}">
<h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
{{{ data.update }}}
</div>
<# } #>
<# if ( data.parent ) { #>
<p class="parent-theme"><?php printf( __( 'This is a child theme of %s.' ), '<strong>{{{ data.parent }}}</strong>' ); ?></p>
<# } #>
<p class="theme-description">{{{ data.description }}}</p>
<# if ( data.tags ) { #>
<p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{{ data.tags }}}</p>
<# } #>
</div>
</div>
<div class="theme-actions">
<# if ( data.active ) { #>
<button type="button" class="button button-primary customize-theme"><?php _e( 'Customize' ); ?></button>
<# } else if ( 'installed' === data.type ) { #>
<?php if ( current_user_can( 'delete_themes' ) ) { ?>
<# if ( data.actions && data.actions['delete'] ) { #>
<a href="{{{ data.actions['delete'] }}}" data-slug="{{ data.id }}" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a>
<# } #>
<?php } ?>
<button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button>
<# } else { #>
<button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button>
<button type="button" class="button button-primary theme-install preview" data-slug="{{ data.id }}"><?php _e( 'Install &amp; Preview' ); ?></button>
<# } #>
</div>
</div>
</script>
<?php
}

View File

@ -0,0 +1,270 @@
<?php
/**
* WordPress Translation Installation Administration API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Retrieve translations from WordPress Translation API.
*
* @since 4.0.0
*
* @param string $type Type of translations. Accepts 'plugins', 'themes', 'core'.
* @param array|object $args Translation API arguments. Optional.
* @return object|WP_Error On success an object of translations, WP_Error on failure.
*/
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.' ) );
}
/**
* Allows a plugin to override the WordPress.org Translation Installation API entirely.
*
* @since 4.0.0
*
* @param bool|array $result The result object. Default false.
* @param string $type The type of translations being requested.
* @param object $args Translation API arguments.
*/
$res = apply_filters( 'translations_api', false, $type, $args );
if ( false === $res ) {
$url = $http_url = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$options = array(
'timeout' => 3,
'body' => array(
'wp_version' => $wp_version,
'locale' => get_locale(),
'version' => $args['version'], // Version of plugin, theme or core
),
);
if ( 'core' !== $type ) {
$options['body']['slug'] = $args['slug']; // Plugin or theme slug
}
$request = wp_remote_post( $url, $options );
if ( $ssl && is_wp_error( $request ) ) {
trigger_error(
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>.' ),
__( 'https://wordpress.org/support/' )
) . ' ' . __( '(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, $options );
}
if ( is_wp_error( $request ) ) {
$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>.' ),
__( 'https://wordpress.org/support/' )
),
$request->get_error_message()
);
} else {
$res = json_decode( wp_remote_retrieve_body( $request ), true );
if ( ! is_object( $res ) && ! is_array( $res ) ) {
$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>.' ),
__( 'https://wordpress.org/support/' )
),
wp_remote_retrieve_body( $request )
);
}
}
}
/**
* Filters the Translation Installation API response results.
*
* @since 4.0.0
*
* @param object|WP_Error $res Response object or WP_Error.
* @param string $type The type of translations being requested.
* @param object $args Translation API arguments.
*/
return apply_filters( 'translations_api_result', $res, $type, $args );
}
/**
* Get available translations from the WordPress.org API.
*
* @since 4.0.0
*
* @see translations_api()
*
* @return array Array of translations, each an array of data. If the API response results
* in an error, an empty array will be returned.
*/
function wp_get_available_translations() {
if ( ! wp_installing() && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) {
return $translations;
}
include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
$api = translations_api( 'core', array( 'version' => $wp_version ) );
if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
return array();
}
$translations = array();
// Key the array with the language code for now.
foreach ( $api['translations'] as $translation ) {
$translations[ $translation['language'] ] = $translation;
}
if ( ! defined( 'WP_INSTALLING' ) ) {
set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
}
return $translations;
}
/**
* Output the select form for the language selection on the installation screen.
*
* @since 4.0.0
*
* @global string $wp_local_package
*
* @param array $languages Array of available languages (populated via the Translation API).
*/
function wp_install_language_form( $languages ) {
global $wp_local_package;
$installed_languages = get_available_languages();
echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
echo "<select size='14' name='language' id='language'>\n";
echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
echo "\n";
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",
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'] )
);
unset( $languages[ $wp_local_package ] );
}
}
foreach ( $languages as $language ) {
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'] )
);
}
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>';
}
/**
* Download a language pack.
*
* @since 4.0.0
*
* @see wp_get_available_translations()
*
* @param string $download Language code to download.
* @return string|bool Returns the language code if successfully downloaded
* (or already installed), or false on failure.
*/
function wp_download_language_pack( $download ) {
// Check if the translation is already installed.
if ( in_array( $download, get_available_languages() ) ) {
return $download;
}
if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) {
return false;
}
// Confirm the translation is one we can download.
$translations = wp_get_available_translations();
if ( ! $translations ) {
return false;
}
foreach ( $translations as $translation ) {
if ( $translation['language'] === $download ) {
$translation_to_load = true;
break;
}
}
if ( empty( $translation_to_load ) ) {
return false;
}
$translation = (object) $translation;
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new Automatic_Upgrader_Skin;
$upgrader = new Language_Pack_Upgrader( $skin );
$translation->type = 'core';
$result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
if ( ! $result || is_wp_error( $result ) ) {
return false;
}
return $translation->language;
}
/**
* Check if WordPress has access to the filesystem without asking for
* credentials.
*
* @since 4.0.0
*
* @return bool Returns true on success, false on failure.
*/
function wp_can_install_language_pack() {
if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
return false;
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new Automatic_Upgrader_Skin;
$upgrader = new Language_Pack_Upgrader( $skin );
$upgrader->init();
$check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
if ( ! $check || is_wp_error( $check ) ) {
return false;
}
return true;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,811 @@
<?php
/**
* WordPress Administration Update API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Selects the first update version from the update_core option.
*
* @return object|array|false The response from the API on success, false on failure.
*/
function get_preferred_from_update_core() {
$updates = get_core_updates();
if ( ! is_array( $updates ) ) {
return false;
}
if ( empty( $updates ) ) {
return (object) array( 'response' => 'latest' );
}
return $updates[0];
}
/**
* 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.
* @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
);
$dismissed = get_site_option( 'dismissed_update_core' );
if ( ! is_array( $dismissed ) ) {
$dismissed = array();
}
$from_api = get_site_transient( 'update_core' );
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
return false;
}
$updates = $from_api->updates;
$result = array();
foreach ( $updates as $update ) {
if ( $update->response == 'autoupdate' ) {
continue;
}
if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
if ( $options['dismissed'] ) {
$update->dismissed = true;
$result[] = $update;
}
} else {
if ( $options['available'] ) {
$update->dismissed = false;
$result[] = $update;
}
}
}
return $result;
}
/**
* Gets the best available (and enabled) Auto-Update for WordPress Core.
*
* If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the installation allows it, else, 1.2.3
*
* @since 3.7.0
*
* @return array|false False on failure, otherwise the core update offering.
*/
function find_core_auto_update() {
$updates = get_site_transient( 'update_core' );
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;
foreach ( $updates->updates as $update ) {
if ( 'autoupdate' != $update->response ) {
continue;
}
if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
continue;
}
if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
$auto_update = $update;
}
}
return $auto_update;
}
/**
* Gets and caches the checksums for the given version of WordPress.
*
* @since 3.7.0
*
* @param string $version Version string to query.
* @param string $locale Locale to query.
* @return bool|array False on failure. An array of checksums on success.
*/
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' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$options = array(
'timeout' => wp_doing_cron() ? 30 : 3,
);
$response = wp_remote_get( $url, $options );
if ( $ssl && is_wp_error( $response ) ) {
trigger_error(
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>.' ),
__( 'https://wordpress.org/support/' )
) . ' ' . __( '(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
);
$response = wp_remote_get( $http_url, $options );
}
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'] ) ) {
return false;
}
return $body['checksums'];
}
/**
* @param object $update
* @return bool
*/
function dismiss_core_update( $update ) {
$dismissed = get_site_option( 'dismissed_update_core' );
$dismissed[ $update->current . '|' . $update->locale ] = true;
return update_site_option( 'dismissed_update_core', $dismissed );
}
/**
* @param string $version
* @param string $locale
* @return bool
*/
function undismiss_core_update( $version, $locale ) {
$dismissed = get_site_option( 'dismissed_update_core' );
$key = $version . '|' . $locale;
if ( ! isset( $dismissed[ $key ] ) ) {
return false;
}
unset( $dismissed[ $key ] );
return update_site_option( 'dismissed_update_core', $dismissed );
}
/**
* @param string $version
* @param string $locale
* @return object|false
*/
function find_core_update( $version, $locale ) {
$from_api = get_site_transient( 'update_core' );
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 ) {
return $update;
}
}
return false;
}
/**
* @param string $msg
* @return string
*/
function core_update_footer( $msg = '' ) {
if ( ! current_user_can( 'update_core' ) ) {
return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
}
$cur = get_preferred_from_update_core();
if ( ! is_object( $cur ) ) {
$cur = new stdClass;
}
if ( ! isset( $cur->current ) ) {
$cur->current = '';
}
if ( ! isset( $cur->url ) ) {
$cur->url = '';
}
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 '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' ) );
}
}
/**
* @global string $pagenow
* @return false|void
*/
function update_nag() {
if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
return false;
}
global $pagenow;
if ( 'update-core.php' == $pagenow ) {
return;
}
$cur = get_preferred_from_update_core();
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: 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>.' ),
$version_url,
$cur->current,
network_admin_url( 'update-core.php' ),
esc_attr__( 'Please update WordPress now' )
);
} else {
$msg = sprintf(
/* 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.' ),
$version_url,
$cur->current
);
}
echo "<div class='update-nag'>$msg</div>";
}
// Called directly from dashboard
function update_right_now_message() {
$theme_name = wp_get_theme();
if ( current_user_can( 'switch_themes' ) ) {
$theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
}
$msg = '';
if ( current_user_can( 'update_core' ) ) {
$cur = get_preferred_from_update_core();
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 */
$content = __( 'WordPress %1$s running %2$s theme.' );
/**
* Filters the text displayed in the 'At a Glance' dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'.
*
* @since 4.4.0
*
* @param string $content Default text.
*/
$content = apply_filters( 'update_right_now_text', $content );
$msg .= sprintf( '<span id="wp-version">' . $content . '</span>', get_bloginfo( 'version', 'display' ), $theme_name );
echo "<p id='wp-version-message'>$msg</p>";
}
/**
* @since 2.9.0
*
* @return array
*/
function get_plugin_updates() {
$all_plugins = get_plugins();
$upgrade_plugins = array();
$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 ]->update = $current->response[ $plugin_file ];
}
}
return $upgrade_plugins;
}
/**
* @since 2.9.0
*/
function wp_plugin_update_rows() {
if ( ! current_user_can( 'update_plugins' ) ) {
return;
}
$plugins = get_site_transient( 'update_plugins' );
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 );
}
}
}
/**
* Displays update information for a plugin.
*
* @param string $file Plugin basename.
* @param array $plugin_data Plugin information.
* @return false|void
*/
function wp_plugin_update_row( $file, $plugin_data ) {
$current = get_site_transient( 'update_plugins' );
if ( ! isset( $current->response[ $file ] ) ) {
return false;
}
$response = $current->response[ $file ];
$plugins_allowedtags = array(
'a' => array(
'href' => array(),
'title' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'em' => array(),
'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' );
/** @var WP_Plugins_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
if ( is_network_admin() || ! is_multisite() ) {
if ( is_network_admin() ) {
$active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
} else {
$active_class = is_plugin_active( $file ) ? ' active' : '';
}
echo '<tr class="plugin-update-tr' . $active_class . '" id="' . esc_attr( $response->slug . '-update' ) . '" data-slug="' . esc_attr( $response->slug ) . '" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $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_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>.' ),
$plugin_name,
esc_url( $details_url ),
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
);
} 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>' ),
$plugin_name,
esc_url( $details_url ),
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
);
} 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>.' ),
$plugin_name,
esc_url( $details_url ),
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"',
/* translators: %s: plugin name */
esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
)
);
}
/**
* Fires at the end of the update message container in each
* row of the plugins list table.
*
* The dynamic portion of the hook name, `$file`, refers to the path
* of the plugin's primary file relative to the plugins directory.
*
* @since 2.8.0
*
* @param array $plugin_data {
* An array of plugin metadata.
*
* @type string $name The human-readable name of the plugin.
* @type string $plugin_uri Plugin URI.
* @type string $version Plugin version.
* @type string $description Plugin description.
* @type string $author Plugin author.
* @type string $author_uri Plugin author URI.
* @type string $text_domain Plugin text domain.
* @type string $domain_path Relative path to the plugin's .mo file(s).
* @type bool $network Whether the plugin can only be activated network wide.
* @type string $title The human-readable title of the plugin.
* @type string $author_name Plugin author's name.
* @type bool $update Whether there's an available update. Default null.
* }
* @param array $response {
* An array of metadata about the available plugin update.
*
* @type int $id Plugin ID.
* @type string $slug Plugin slug.
* @type string $new_version New plugin version.
* @type string $url Plugin URL.
* @type string $package Plugin update package URL.
* }
*/
do_action( "in_plugin_update_message-{$file}", $plugin_data, $response );
echo '</p></div></td></tr>';
}
}
/**
* @return array
*/
function get_theme_updates() {
$current = get_site_transient( 'update_themes' );
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 ]->update = $data;
}
return $update_themes;
}
/**
* @since 3.1.0
*/
function wp_theme_update_rows() {
if ( ! current_user_can( 'update_themes' ) ) {
return;
}
$themes = get_site_transient( 'update_themes' );
if ( isset( $themes->response ) && is_array( $themes->response ) ) {
$themes = array_keys( $themes->response );
foreach ( $themes as $theme ) {
add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 );
}
}
}
/**
* Displays update information for a theme.
*
* @param string $theme_key Theme stylesheet.
* @param WP_Theme $theme Theme object.
* @return false|void
*/
function wp_theme_update_row( $theme_key, $theme ) {
$current = get_site_transient( 'update_themes' );
if ( ! isset( $current->response[ $theme_key ] ) ) {
return false;
}
$response = $current->response[ $theme_key ];
$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' );
$active = $theme->is_allowed( 'network' ) ? ' active' : '';
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>.' ),
$theme['Name'],
esc_url( $details_url ),
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']
);
} 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>' ),
$theme['Name'],
esc_url( $details_url ),
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']
);
} 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>.' ),
$theme['Name'],
esc_url( $details_url ),
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"',
/* translators: %s: theme name */
esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
)
);
}
/**
* Fires at the end of the update message container in each
* row of the themes list table.
*
* The dynamic portion of the hook name, `$theme_key`, refers to
* the theme slug as found in the WordPress.org themes repository.
*
* @since 3.1.0
*
* @param WP_Theme $theme The WP_Theme object.
* @param array $response {
* An array of metadata about the available theme update.
*
* @type string $new_version New theme version.
* @type string $url Theme URL.
* @type string $package Theme update package URL.
* }
*/
do_action( "in_theme_update_message-{$theme_key}", $theme, $response );
echo '</p></div></td></tr>';
}
/**
* @global int $upgrading
* @return false|void
*/
function maintenance_nag() {
include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
global $upgrading;
$nag = isset( $upgrading );
if ( ! $nag ) {
$failed = get_site_option( 'auto_core_update_failed' );
/*
* If an update failed critically, we may have copied over version.php but not other files.
* In that case, if the installation claims we're running the version we attempted, nag.
* This is serious enough to err on the side of nagging.
*
* If we simply failed to update before we tried to copy any files, then assume things are
* OK if they are now running the latest.
*
* This flag is cleared whenever a successful update occurs using Core_Upgrader.
*/
$comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
$nag = true;
}
}
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.' );
}
echo "<div class='update-nag'>$msg</div>";
}
/**
* Prints the JavaScript templates for update admin notices.
*
* Template takes one argument with four values:
*
* param {object} data {
* Arguments for admin notice.
*
* @type string id ID of the notice.
* @type string className Class names for the notice.
* @type string message The notice's message.
* @type string type The type of update the notice is for. Either 'plugin' or 'theme'.
* }
*
* @since 4.6.0
*/
function wp_print_admin_notice_templates() {
?>
<script id="tmpl-wp-updates-admin-notice" type="text/html">
<div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
</script>
<script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
<div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errors ) { #>notice-error<# } else { #>notice-success<# } #>">
<p>
<# if ( data.successes ) { #>
<# if ( 1 === data.successes ) { #>
<# if ( 'plugin' === data.type ) { #>
<?php
/* translators: %s: Number of plugins */
printf( __( '%s plugin successfully updated.' ), '{{ data.successes }}' );
?>
<# } else { #>
<?php
/* translators: %s: Number of themes */
printf( __( '%s theme successfully updated.' ), '{{ data.successes }}' );
?>
<# } #>
<# } else { #>
<# if ( 'plugin' === data.type ) { #>
<?php
/* translators: %s: Number of plugins */
printf( __( '%s plugins successfully updated.' ), '{{ data.successes }}' );
?>
<# } else { #>
<?php
/* translators: %s: Number of themes */
printf( __( '%s themes successfully updated.' ), '{{ data.successes }}' );
?>
<# } #>
<# } #>
<# } #>
<# if ( data.errors ) { #>
<button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
<# if ( 1 === data.errors ) { #>
<?php
/* translators: %s: Number of failed updates */
printf( __( '%s update failed.' ), '{{ data.errors }}' );
?>
<# } else { #>
<?php
/* translators: %s: Number of failed updates */
printf( __( '%s updates failed.' ), '{{ data.errors }}' );
?>
<# } #>
<span class="screen-reader-text"><?php _e( 'Show more details' ); ?></span>
<span class="toggle-indicator" aria-hidden="true"></span>
</button>
<# } #>
</p>
<# if ( data.errors ) { #>
<ul class="bulk-action-errors hidden">
<# _.each( data.errorMessages, function( errorMessage ) { #>
<li>{{ errorMessage }}</li>
<# } ); #>
</ul>
<# } #>
</div>
</script>
<?php
}
/**
* Prints the JavaScript templates for update and deletion rows in list tables.
*
* The update template takes one argument with four values:
*
* param {object} data {
* Arguments for the update row
*
* @type string slug Plugin slug.
* @type string plugin Plugin base name.
* @type string colspan The number of table columns this row spans.
* @type string content The row content.
* }
*
* The delete template takes one argument with four values:
*
* param {object} data {
* Arguments for the update row
*
* @type string slug Plugin slug.
* @type string plugin Plugin base name.
* @type string name Plugin name.
* @type string colspan The number of table columns this row spans.
* }
*
* @since 4.6.0
*/
function wp_print_update_row_templates() {
?>
<script id="tmpl-item-update-row" type="text/template">
<tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
<td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
{{{ data.content }}}
</td>
</tr>
</script>
<script id="tmpl-item-deleted-row" type="text/template">
<tr class="plugin-deleted-tr inactive deleted" id="{{ data.slug }}-deleted" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
<td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
<# if ( data.plugin ) { #>
<?php
printf(
/* translators: %s: Plugin name */
_x( '%s was successfully deleted.', 'plugin' ),
'<strong>{{{ data.name }}}</strong>'
);
?>
<# } else { #>
<?php
printf(
/* translators: %s: Theme name */
_x( '%s was successfully deleted.', 'theme' ),
'<strong>{{{ data.name }}}</strong>'
);
?>
<# } #>
</td>
</tr>
</script>
<?php
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,316 @@
<?php
/**
* WordPress Widgets Administration API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Display list of the available widgets.
*
* @since 2.5.0
*
* @global array $wp_registered_widgets
* @global array $wp_registered_widget_controls
*/
function wp_list_widgets() {
global $wp_registered_widgets, $wp_registered_widget_controls;
$sort = $wp_registered_widgets;
usort( $sort, '_sort_name_callback' );
$done = array();
foreach ( $sort as $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],
)
);
call_user_func_array( 'wp_widget_control', $args );
}
}
/**
* Callback to sort array by a 'name' key.
*
* @since 3.1.0
* @access private
*
* @return int
*/
function _sort_name_callback( $a, $b ) {
return strnatcasecmp( $a['name'], $b['name'] );
}
/**
* Show the widgets and their settings for a sidebar.
* Used in the admin widget config screen.
*
* @since 2.5.0
*
* @param string $sidebar Sidebar ID.
* @param string $sidebar_name Optional. Sidebar name. Default empty.
*/
function wp_list_widget_controls( $sidebar, $sidebar_name = '' ) {
add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
$description = wp_sidebar_description( $sidebar );
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" 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>
</button>
<h2><?php echo esc_html( $sidebar_name ); ?> <span class="spinner"></span></h2>
</div>
<?php
}
if ( ! empty( $description ) ) {
?>
<div class="sidebar-description">
<p class="description"><?php echo $description; ?></p>
</div>
<?php
}
dynamic_sidebar( $sidebar );
echo '</div>';
}
/**
* Retrieves the widget control arguments.
*
* @since 2.5.0
*
* @global array $wp_registered_widgets
*
* @staticvar int $i
*
* @param array $params
* @return array
*/
function wp_list_widget_controls_dynamic_sidebar( $params ) {
global $wp_registered_widgets;
static $i = 0;
$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;"' : '';
$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';
}
return $params;
}
/**
* @global array $wp_registered_widgets
*
* @param string $id_base
* @return int
*/
function next_widget_id_number( $id_base ) {
global $wp_registered_widgets;
$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] );
}
}
$number++;
return $number;
}
/**
* Meta widget used to display the control form for a widget.
*
* Called from dynamic_sidebar().
*
* @since 2.5.0
*
* @global array $wp_registered_widgets
* @global array $wp_registered_widget_controls
* @global array $sidebars_widgets
*
* @param array $sidebar_args
* @return array
*/
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 ];
$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_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>';
$query_arg = array( 'editwidget' => $widget['id'] );
if ( $add_new ) {
$query_arg['addnew'] = 1;
if ( $multi_number ) {
$query_arg['num'] = $multi_number;
$query_arg['base'] = $id_base;
}
} else {
$query_arg['sidebar'] = $sidebar_id;
$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 ) {
// 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'] ) ) {
$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'] );
$widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) );
$has_form = 'noform';
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 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 ) ); ?>">
<span class="edit"><?php _ex( 'Edit', 'widget' ); ?></span>
<span class="add"><?php _ex( 'Add', 'widget' ); ?></span>
<span class="screen-reader-text"><?php echo $widget_title; ?></span>
</a>
</div>
<div class="widget-title"><h3><?php echo $widget_title; ?><span class="in-widget-title"></span></h3></div>
</div>
<div class="widget-inside">
<?php echo $before_form; ?>
<?php echo $before_widget_content; ?>
<?php
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";
}
$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 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">
<button type="button" class="button-link button-link-delete widget-control-remove"><?php _e( 'Delete' ); ?></button>
<span class="widget-control-close-wrapper">
|
<button type="button" class="button-link widget-control-close"><?php _e( 'Done' ); ?></button>
</span>
</div>
<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>
<br class="clear" />
</div>
<?php echo $after_form; ?>
</div>
<div class="widget-description">
<?php echo ( $widget_description = wp_widget_description( $widget_id ) ) ? "$widget_description\n" : "$widget_title\n"; ?>
</div>
<?php
echo $sidebar_args['after_widget'];
return $sidebar_args;
}
/**
* @param string $classes
* @return string
*/
function wp_widgets_access_body_class( $classes ) {
return "$classes widgets_access ";
}