本文整理汇总了PHP中request_filesystem_credentials函数的典型用法代码示例。如果您正苦于以下问题:PHP request_filesystem_credentials函数的具体用法?PHP request_filesystem_credentials怎么用?PHP request_filesystem_credentials使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request_filesystem_credentials函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unzip_file
/**
* Unzip the uploaded file and pass back the directory name
* of the unzipped file
*/
public static function unzip_file($zipfile)
{
$parts = pathinfo($zipfile);
$updir = wp_upload_dir();
$ziprel = strstr($zipfile, 'gravity_forms');
// Construct the name of the directory the zipfile was uploaded to
$from = $updir['basedir'] . '/' . $ziprel;
// Construct the name of the directory to unzip the file
$paths = pathinfo($from);
$basedir = $paths['dirname'];
$filename = $paths['filename'];
$to = $basedir;
/*
* Now we need to prepare the WP_Filesystem so we can access our
* zip directory and files.
*/
$url = wp_nonce_url('themes.php?page=example', 'example-theme-options');
if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
echo "Prospector error: creds failed for files system<br/>";
return false;
}
if (!WP_Filesystem($creds)) {
echo "Prospector error: WP_Filesystem failed<br/>";
return false;
}
$wperr = unzip_file($from, $to);
if (true !== $wperr) {
print_r($wperr);
/* XXX - Print this out better */
return false;
}
// Success!!
return $to;
}
示例2: _get_wp_filesystem
/**
* @throws EE_Error
* @return WP_Filesystem_Base
*/
private static function _get_wp_filesystem()
{
global $wp_filesystem;
// no filesystem setup ???
if (!$wp_filesystem instanceof WP_Filesystem_Base) {
// if some eager beaver's just trying to get in there too early...
if (!did_action('wp_loaded')) {
$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
if (WP_DEBUG) {
$msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
}
throw new EE_Error($msg);
} else {
// should be loaded if we are past the wp_loaded hook...
if (!function_exists('WP_Filesystem')) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
// basically check for direct or previously configured access
if (!WP_Filesystem()) {
// turn on output buffering so that we can capture the credentials form
ob_start();
$credentials = request_filesystem_credentials('');
// store credentials form for the time being
EEH_File::$_credentials_form = ob_get_clean();
// if credentials do NOT exist
if ($credentials === FALSE) {
add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
}
}
}
}
return $wp_filesystem;
}
示例3: audiotheme_framework_not_a_theme
/**
* Move the framework to the plugins directory.
*
* @since 1.2.0
*/
function audiotheme_framework_not_a_theme()
{
global $wp_filesystem;
if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'audiotheme-theme-to-plugin')) {
return false;
}
$move_url = wp_nonce_url('themes.php', 'audiotheme-theme-to-plugin');
if (false === ($credentials = request_filesystem_credentials($move_url))) {
return true;
}
if (!WP_Filesystem($credentials)) {
// Credentials weren't good, ask again.
request_filesystem_credentials($move_url);
return true;
}
$plugin_dir = $wp_filesystem->wp_plugins_dir() . 'audiotheme/';
$theme_dir = trailingslashit(get_template_directory());
// Check if the framework plugin directory already exists.
if (is_dir($plugin_dir)) {
$redirect = add_query_arg('atmovemsg', 'plugin-exists', admin_url('themes.php'));
wp_safe_redirect(esc_url_raw($redirect));
exit;
}
// Move the plugin.
if ($wp_filesystem->move($theme_dir, $plugin_dir)) {
// @todo Any way to re-activate the previous theme?
wp_safe_redirect(esc_url_raw(admin_url('plugins.php')));
exit;
} else {
$redirect = add_query_arg('atmovemsg', 'move-failed', admin_url('themes.php'));
wp_safe_redirect(esc_url_raw($redirect));
exit;
}
}
示例4: _validate_form
protected function _validate_form()
{
$url = wp_nonce_url('admin.php?page=vimeography-my-themes');
if (false === ($creds = request_filesystem_credentials($url))) {
// if we get here, then we don't have credentials yet,
// but have just produced a form for the user to fill in,
// so stop processing for now
return true;
// stop the normal page form from displaying
}
// now we have some credentials, try to get the wp_filesystem running
if (!WP_Filesystem($creds)) {
// our credentials were no good, ask the user for them again
request_filesystem_credentials($url);
return true;
}
if (empty($_FILES)) {
return;
}
// if this fails, check_admin_referer() will automatically print a "failed" page and die.
if (!empty($_FILES) && check_admin_referer('vimeography-install-theme', 'vimeography-theme-verification')) {
$name = substr(wp_filter_nohtml_kses($_FILES['vimeography-theme']['name']), 0, -4);
if ($_FILES['vimeography-theme']['type'] != 'application/zip') {
$this->messages[] = array('type' => 'error', 'heading' => 'Ruh Roh.', 'message' => 'Make sure you are uploading the actual .zip file, not a subfolder or file.');
} else {
global $wp_filesystem;
if (!unzip_file($_FILES['vimeography-theme']['tmp_name'], VIMEOGRAPHY_THEME_PATH)) {
$this->messages[] = array('type' => 'error', 'heading' => 'Ruh Roh.', 'message' => 'The theme could not be installed.');
} else {
$this->messages[] = array('type' => 'success', 'heading' => 'Theme installed.', 'message' => 'You can now use the "' . $name . '" theme in your galleries.');
}
}
}
}
示例5: filesystem_init
function filesystem_init($form_url, $method = '', $context = false, $fields = null)
{
global $wp_filesystem;
if (!empty($this->creds)) {
return true;
}
ob_start();
/* dESiGNERz-CREW.iNFO for PRO users - first attempt to get credentials */
if (false === ($this->creds = request_filesystem_credentials($form_url, $method, false, $context))) {
$this->creds = array();
$this->parent->ftp_form = ob_get_contents();
ob_end_clean();
/**
* if we comes here - we don't have credentials
* so the request for them is displaying
* no need for further processing
**/
return false;
}
/* dESiGNERz-CREW.iNFO for PRO users - now we got some credentials - try to use them*/
if (!WP_Filesystem($this->creds)) {
$this->creds = array();
/* dESiGNERz-CREW.iNFO for PRO users - incorrect connection data - ask for credentials again, now with error message */
request_filesystem_credentials($form_url, '', true, $context);
$this->parent->ftp_form = ob_get_contents();
ob_end_clean();
return false;
}
return true;
}
示例6: export
function export()
{
global $wpdb;
$px_table_name = $wpdb->prefix . 'gcm_users';
$query = "SELECT * FROM {$px_table_name}";
$datas = $wpdb->get_results($query);
$url = wp_nonce_url('admin.php?page=px-gcm-export', 'px-gcm-export');
if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
return true;
}
if (!WP_Filesystem($creds)) {
// our credentials were not good, ask the user for them again
request_filesystem_credentials($url, '', true, false, null);
return true;
}
global $wp_filesystem;
$contentdir = trailingslashit($wp_filesystem->wp_content_dir());
$in = "Databse ID;GCM Registration ID;Device OS;Device Model;Created At;Messages sent to this Device;\n";
foreach ($datas as $data) {
$in .= $data->id . ";" . $data->gcm_regid . ";" . $data->os . ";" . $data->model . ";" . $data->created_at . ";" . $data->send_msg . "\n";
}
mb_convert_encoding($in, "ISO-8859-1", "UTF-8");
if (!$wp_filesystem->put_contents($contentdir . 'GCM-Export.csv', $in, FS_CHMOD_FILE)) {
echo 'Failed saving file';
}
return content_url() . "/GCM-Export.csv";
}
示例7: update_plugins
private function update_plugins()
{
global $king, $wp_filesystem;
require_once ABSPATH . 'wp-admin/includes/file.php';
$fields = array('action', '_wp_http_referer', '_wpnonce');
$canUnZip = false;
if (false !== ($creds = request_filesystem_credentials('', '', false, false, $fields))) {
if (!WP_Filesystem($creds)) {
request_filesystem_credentials($url, $method, true, false, $fields);
} else {
$canUnZip = true;
}
}
if ($canUnZip == true) {
$direct = ABSPATH . DS . 'wp-content' . DS . 'plugins';
$path = THEME_PATH . DS . 'core' . DS . 'sample' . DS . 'plugins' . DS;
$plugins = array('linstar-helper', 'LayerSlider', 'contact-form-7', 'js_composer');
foreach ($plugins as $plugin) {
$tmpfile = $path . $plugin . '.zip';
if (!is_dir($direct . DS . $plugin)) {
unzip_file($tmpfile, $direct);
} else {
@rename($direct . DS . $plugin, $direct . DS . $plugin . '_tmpl');
if (unzip_file($tmpfile, $direct)) {
self::removeDir($direct . DS . $plugin . '_tmpl');
} else {
@rename($direct . DS . $plugin . '_tmpl', $direct . DS . $plugin);
}
}
}
//end foreach
}
//end if canUnZip
}
示例8: is_writable
/**
* check if the path is writable. To make the check .
*
* @param string $path
* @return boolean
*/
public function is_writable($path)
{
global $wp_filesystem;
// try without credentials
$writable = WP_Filesystem(false, $path);
// We consider the directory as writable if it uses the direct transport,
// otherwise credentials would be needed
if (true === $writable) {
return true;
}
// if the user has FTP and sockets defined
if ($this->is_ftp_or_sockets($wp_filesystem->method) && $this->are_ftp_constants_defined()) {
$creds = request_filesystem_credentials('', $wp_filesystem->method, false, $path);
$writable = WP_Filesystem($creds, $path);
if (true === $writable) {
return true;
}
}
if ($this->is_ssh($wp_filesystem->method) && $this->are_ssh_constants_defined()) {
$creds = request_filesystem_credentials('', $wp_filesystem->method, false, $path);
$writable = WP_Filesystem($creds, $path);
if (true === $writable) {
return true;
}
}
return false;
}
示例9: save_temp_image
/**
* Save the submitted image as a temporary file.
*
* @todo Revisit file handling.
*
* @param string $img Base64 encoded image.
* @return false|string File name on success, false on failure.
*/
protected function save_temp_image($img)
{
// Strip the "data:image/png;base64," part and decode the image.
$img = explode(',', $img);
$img = isset($img[1]) ? base64_decode($img[1]) : base64_decode($img[0]);
if (!$img) {
return false;
}
// Upload to tmp folder.
$filename = 'user-feedback-' . date('Y-m-d-H-i');
$tempfile = wp_tempnam($filename);
if (!$tempfile) {
return false;
}
// WordPress adds a .tmp file extension, but we want .png.
if (rename($tempfile, $filename . '.png')) {
$tempfile = $filename . '.png';
}
if (!WP_Filesystem(request_filesystem_credentials(''))) {
return false;
}
/**
* WordPress Filesystem API.
*
* @var \WP_Filesystem_Base $wp_filesystem
*/
global $wp_filesystem;
$success = $wp_filesystem->put_contents($tempfile, $img);
if (!$success) {
return false;
}
return $tempfile;
}
示例10: save_file
/**
* Save the redirect file
*
* @return bool
*/
public function save_file()
{
global $wp_filesystem;
// Generate file content
$file_content = $this->generate_file_content();
if (null == $file_content) {
return false;
}
// Set the filesystem URL
$url = wp_nonce_url('admin.php?page=wpseo_redirects#top#settings', 'update-htaccess');
// Get the credentials
$credentials = request_filesystem_credentials($url, '', false, WPSEO_Redirect_File_Manager::get_htaccess_file_path());
// Check if WP_Filesystem is working
if (WP_Filesystem($credentials, WPSEO_Redirect_File_Manager::get_htaccess_file_path())) {
// Read current htaccess
$htaccess = '';
if (file_exists(WPSEO_Redirect_File_Manager::get_htaccess_file_path())) {
$htaccess = file_get_contents(WPSEO_Redirect_File_Manager::get_htaccess_file_path());
}
$htaccess = preg_replace("`# BEGIN YOAST REDIRECTS.*# END YOAST REDIRECTS" . PHP_EOL . "`is", "", $htaccess);
// New Redirects
$file_content = "# BEGIN YOAST REDIRECTS" . PHP_EOL . "<IfModule mod_rewrite.c>" . PHP_EOL . "RewriteEngine On" . PHP_EOL . $file_content . "</IfModule>" . PHP_EOL . "# END YOAST REDIRECTS" . PHP_EOL;
// Prepend our redirects to htaccess file
$htaccess = $file_content . $htaccess;
// Update the .htaccess file
$wp_filesystem->put_contents(WPSEO_Redirect_File_Manager::get_htaccess_file_path(), $htaccess, FS_CHMOD_FILE);
}
}
示例11: _request_filesystem_credentials
/**
* _request_filesystem_credentials
* if attempting to enable full logging, WordPress may require filesystem credentials for FTP or SSH depending on the server
*
* @access protected
* @param bool $show_errors
* @return bool
*/
protected function _request_filesystem_credentials($show_errors = TRUE)
{
require_once ABSPATH . 'wp-admin/includes/file.php';
$url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'request_filesystem_credentials'), $this->_admin_base_url);
$credentials = request_filesystem_credentials($url);
if ($credentials == FALSE) {
if ($show_errors) {
EE_Error::get_notices(FALSE);
EE_Error::reset_notices();
EE_Error::add_error(__('Connection settings are missing or incorrect. Please verify that the connection settings below are correct.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
add_filter('FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', '__return_false');
}
return FALSE;
}
// now we have some credentials, try to get the wp_filesystem running
$WP_Filesystem = WP_Filesystem($credentials);
if (!$WP_Filesystem) {
if ($show_errors) {
EE_Error::get_notices(FALSE);
EE_Error::reset_notices();
EE_Error::add_error(__('There was an error connecting to the server. Please verify that the connection settings below are correct.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
add_filter('FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', '__return_false');
}
// our credentials were no good, ask the user for them again
request_filesystem_credentials($url);
return FALSE;
}
EE_Registry::instance()->CFG->admin->use_full_logging = TRUE;
return TRUE;
}
开发者ID:robert-osborne,项目名称:event-espresso-core-1,代码行数:38,代码来源:Extend_General_Settings_Admin_Page.core.php
示例12: request_filesystem_credentials
function request_filesystem_credentials($error = false)
{
$url = 'admin.php?page=themify&action=upgrade&type=' . $this->type . '&login=false';
if (!empty($this->options['nonce'])) {
$url = wp_nonce_url($url, $this->options['nonce']);
}
return request_filesystem_credentials($url, '', $error, false, array($this->cookies));
}
示例13: delete_theme
/**
* Remove a theme
*
* @since 2.8.0
*
* @param string $stylesheet Stylesheet of the theme to delete
* @param string $redirect Redirect to page when complete.
* @return mixed
*/
function delete_theme($stylesheet, $redirect = '') {
global $wp_filesystem;
if ( empty($stylesheet) )
return false;
ob_start();
if ( empty( $redirect ) )
$redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet);
if ( false === ($credentials = request_filesystem_credentials($redirect)) ) {
$data = ob_get_contents();
ob_end_clean();
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) ) {
request_filesystem_credentials($url, '', true); // Failed to connect, Error and request again
$data = ob_get_contents();
ob_end_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->get_error_code() )
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) );
// Force refresh of theme update information
delete_site_transient('update_themes');
return true;
}
示例14: install
function install()
{
$plugin = array('name' => 'Clef', 'slug' => 'wpclef');
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
// Need for plugins_api
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// Need for upgrade classes
require_once 'plugin-install.php';
$api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false)));
if (is_wp_error($api)) {
$this->clef_install_errors = array($api->get_error_message());
add_action('admin_notices', array(&$this, 'clef_install_errors'));
return;
} elseif (isset($api->download_link)) {
$plugin['source'] = $api->download_link;
} else {
$this->clef_install_errors = array('Error trying to download Clef');
add_action('admin_notices', array(&$this, 'clef_install_errors'));
return;
}
/** Pass all necessary information via URL if WP_Filesystem is needed */
$url = wp_nonce_url(add_query_arg(array('page' => 'bruteprotect-clef', 'bruteprotect-clef-action' => 'install'), admin_url('admin.php')), 'bruteprotect-clef-install');
$method = '';
// Leave blank so WP_Filesystem can populate it as necessary
$fields = array(sanitize_key('bruteprotect-clef-install'));
// Extra fields to pass to WP_Filesystem
if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) {
return;
}
if (!WP_Filesystem($creds)) {
request_filesystem_credentials($url, $method, true, false, $fields);
// Setup WP_Filesystem
return;
}
/** Set type, based on whether the source starts with http:// or https:// */
$type = preg_match('|^http(s)?://|', $plugin['source']) ? 'web' : 'upload';
/** Prep variables for Plugin_Installer_Skin class */
$title = sprintf('Installing %s', $plugin['name']);
$url = add_query_arg(array('action' => 'install-plugin', 'plugin' => $plugin['slug']), 'update.php');
if (isset($_GET['from'])) {
$url .= add_query_arg('from', urlencode(stripslashes($_GET['from'])), $url);
}
$nonce = 'install-plugin_' . $plugin['slug'];
$source = $plugin['source'];
/** Create a new instance of Plugin_Upgrader */
$upgrader = new Plugin_Upgrader($skin = new Silent_Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api')));
/** Perform the action and install the plugin from the $source urldecode() */
$upgrader->install($source);
if (!empty($skin->errors)) {
$this->clef_install_errors = $skin->errors;
add_action('admin_notices', array(&$this, 'clef_install_errors'));
return;
}
/** Flush plugins cache so we can make sure that the installed plugins list is always up to date */
wp_cache_flush();
}
示例15: fs_connect
/**
* Connect to the filesystem.
*
* @since 1.0.0
*
* @param array $directories Optional. A list of directories. If any of these do
* not exist, a {@see 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 {@see WP_Error} otherwise.
*/
public function fs_connect($directories = array(), $allow_relaxed_file_ownership = false)
{
global $wp_filesystem;
$url = admin_url('options.php');
if (false === ($credentials = request_filesystem_credentials($url, '', false, false, array(), $allow_relaxed_file_ownership))) {
return false;
}
if (empty($directories)) {
$dirs = $directories;
} else {
$dirs = $directories[0];
}
if (!WP_Filesystem($credentials, $dirs, $allow_relaxed_file_ownership)) {
$error = true;
if (is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code()) {
$error = $wp_filesystem->errors;
}
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;
}