/** * Connect to the filesystem. * * @since 2.8.0 * @access public * * @global WP_Filesystem_Base $wp_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->get_error_code()) { $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->get_error_code()) { 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; }
/** * Tests to see if we can and should update a specific item. * * @since 3.7.0 * * @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); } /** * Filter 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; }
static function get_possible_failures() { $result = array(); // Lets check some reasons why it might not be working as expected include_once ABSPATH . '/wp-admin/includes/admin.php'; include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; $upgrader = new WP_Automatic_Updater(); if ($upgrader->is_disabled()) { $result[] = 'autoupdates-disabled'; } if (!is_main_site()) { $result[] = 'is-not-main-site'; } if (!is_main_network()) { $result[] = 'is-not-main-network'; } if ($upgrader->is_vcs_checkout(ABSPATH)) { $result[] = 'site-on-vcs'; } if ($upgrader->is_vcs_checkout(WP_PLUGIN_DIR)) { $result[] = 'plugin-directory-on-vcs'; } if ($upgrader->is_vcs_checkout(WP_CONTENT_DIR)) { $result[] = 'content-directory-on-vcs'; } $lock = get_option('auto_updater.lock'); if ($lock > time() - HOUR_IN_SECONDS) { $result[] = 'lock-is-set'; } $skin = new Automatic_Upgrader_Skin(); include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/template.php'; if (!$skin->request_filesystem_credentials(false, ABSPATH, false)) { $result[] = 'no-system-write-access'; } if (!$skin->request_filesystem_credentials(false, WP_PLUGIN_DIR, false)) { $result[] = 'no-plugin-directory-write-access'; } if (!$skin->request_filesystem_credentials(false, WP_CONTENT_DIR, false)) { $result[] = 'no-wp-content-directory-write-access'; } return $result; }
static function can_auto_update($context, $skin = false) { if (!$skin) { $skin = new Automatic_Upgrader_Skin(); } return (bool) $skin->request_filesystem_credentials(false, $context); }