Example #1
0
 /**
  * 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;
 }
 /**
  * @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;
 }
Example #3
0
/**
 * 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;
    }
}
Example #4
0
 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.');
             }
         }
     }
 }
 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;
 }
Example #6
0
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";
}
Example #7
0
 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
 }
 /**
  * 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;
 }
Example #9
0
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
 /**
  * _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;
 }
 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));
 }
Example #13
0
/**
 * 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;
}
Example #14
0
 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();
 }
 /**
  * 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;
 }
Example #16
0
 function index_action()
 {
     $router = $this->get_registry()->get_utility('I_Router');
     $url = $this->param('uri') ? $router->get_url($uri) : admin_url('/admin.php?' . $router->get_querystring());
     // Request filesystem credentials from user
     $creds = request_filesystem_credentials($url, '', FALSE, ABSPATH, array());
     if (WP_Filesystem($creds)) {
         global $wp_filesystem;
     }
 }
 public function index_action()
 {
     $router = C_Router::get_instance();
     $url = $this->param('uri') ? $router->get_url($this->param('uri')) : admin_url('/admin.php?' . $router->get_querystring());
     // Request filesystem credentials from user
     $creds = request_filesystem_credentials($url, '', FALSE, ABSPATH, array());
     if (WP_Filesystem($creds)) {
         global $wp_filesystem;
     }
 }
 private function get_creds()
 {
     $access_type = get_filesystem_method();
     if ($access_type === 'direct') {
         $creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, array());
     } else {
         $creds = $this->get_ftp_creds($access_type);
     }
     return $creds;
 }
 function request_filesystem_credentials($error = false)
 {
     $url = $this->options['url'];
     $context = $this->options['context'];
     if (!empty($this->options['nonce'])) {
         $url = wp_nonce_url($url, $this->options['nonce']);
     }
     return request_filesystem_credentials($url, '', $error, $context);
     //Possible to bring inline, Leaving as is for now.
 }
Example #20
0
 /**
  *
  * @param bool   $error
  * @param string $context
  * @param bool   $allow_relaxed_file_ownership
  * @return type
  */
 public function request_filesystem_credentials($error = false, $context = false, $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);
 }
Example #21
0
 public function __construct()
 {
     require_once ABSPATH . 'wp-admin/includes/file.php';
     $upload_dir = wp_upload_dir();
     if (get_filesystem_method(array(), $upload_dir['basedir']) !== 'direct' || !WP_Filesystem(request_filesystem_credentials(admin_url()))) {
         self::$useFS = false;
         add_action('wp_ajax_wpservefile', array($this, 'serve_file'));
         add_action('wp_ajax_nopriv_wpservefile', array($this, 'serve_file'));
     } else {
         self::$useFS = true;
     }
 }
 /**
  * Attempt to initiate WP_Filesystem
  *
  * If this fails, $use_filesystem is set to false and all methods in this class should use native php fallbacks
  * Thwarts `request_filesystem_credentials()` attempt to display a form for obtaining creds from users
  *
  * TODO: provide notice and input in wp-admin for users when this fails
  */
 public function maybe_init_wp_filesystem()
 {
     ob_start();
     $this->credentials = request_filesystem_credentials('', '', false, false, null);
     $ob_contents = ob_get_contents();
     ob_end_clean();
     if (wp_filesystem($this->credentials)) {
         global $wp_filesystem;
         $this->wp_filesystem = $wp_filesystem;
         $this->use_filesystem = true;
     }
 }
Example #23
0
function wpbsui_initFileSystem()
{
    // get file system access
    $url = wp_nonce_url('tools.php?page=wpbsui_page', 'wpbsui-page');
    if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
        return false;
    }
    if (!WP_Filesystem($creds)) {
        request_filesystem_credentials($url, '', true, false, null);
        return false;
    }
    return true;
}
 function connect_fs($url, $method, $context, $fields = null)
 {
     global $wp_filesystem;
     if (false === ($credentials = request_filesystem_credentials($url, $method, false, $context, $fields))) {
         return false;
     }
     //check if credentials are correct or not.
     if (!WP_Filesystem($credentials)) {
         request_filesystem_credentials($url, $method, true, $context);
         return false;
     }
     return true;
 }
/**
 * Install a plugin
 */
function siteorigin_plugin_activation_do_plugin_install()
{
    /** All plugin information will be stored in an array for processing */
    $plugin = array();
    /** Checks for actions from hover links to process the installation */
    if (isset($_GET[sanitize_key('plugin')]) && (isset($_GET[sanitize_key('siteorigin-pa-install')]) && 'install-plugin' == $_GET[sanitize_key('siteorigin-pa-install')]) && current_user_can('install_plugins')) {
        check_admin_referer('siteorigin-pa-install');
        $plugin['name'] = $_GET['plugin_name'];
        // Plugin name
        $plugin['slug'] = $_GET['plugin'];
        // Plugin slug
        if (!empty($_GET['plugin_source'])) {
            $plugin['source'] = $_GET['plugin_source'];
        } else {
            $plugin['source'] = false;
        }
        /** Pass all necessary information via URL if WP_Filesystem is needed */
        $url = wp_nonce_url(add_query_arg(array('page' => 'siteorigin_plugin_activation', 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'siteorigin-pa-install' => 'install-plugin'), admin_url('themes.php')), 'siteorigin-pa-install');
        $method = '';
        // Leave blank so WP_Filesystem can populate it as necessary
        $fields = array(sanitize_key('siteorigin-pa-install'));
        // Extra fields to pass to WP_Filesystem
        if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) {
            return true;
        }
        if (!WP_Filesystem($creds)) {
            request_filesystem_credentials($url, $method, true, false, $fields);
            // Setup WP_Filesystem
            return true;
        }
        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
        /** Prep variables for Plugin_Installer_Skin class */
        $title = sprintf(__('Installing %s', 'vantage'), $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'];
        // Find the source of the plugin
        $source = !empty($plugin['source']) ? $plugin['source'] : 'http://downloads.wordpress.org/plugin/' . urlencode($plugin['slug']) . '.zip';
        /** Create a new instance of Plugin_Upgrader */
        $upgrader = new Plugin_Upgrader($skin = new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api')));
        /** Perform the action and install the plugin from the $source urldecode() */
        $upgrader->install($source);
        /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */
        wp_cache_flush();
    }
}
 static function check_credentials()
 {
     // Get user credentials for WP filesystem API
     $demo_import_page_url = wp_nonce_url('themes.php?page=radium_demo_installer', 'radium_demo_installer');
     if (false === ($creds = request_filesystem_credentials($demo_import_page_url, '', false, false, null))) {
         return new WP_Error('XML_parse_error', __('There was an error when reading this WXR file', 'wordpress-importer'));
     }
     // Now we have 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($demo_import_page_url, '', true, false, null);
         return true;
     }
 }
 /**
  * Initiate and returns the $wp_filesystem object
  *
  * @return $wp_filesystem
  */
 public static function get_wp_filesystem_object()
 {
     global $wp_filesystem;
     // 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, self::get_htaccess_file_path());
     // Return $wp_filesystem if everything is working.
     if (WP_Filesystem($credentials, self::get_htaccess_file_path())) {
         return $wp_filesystem;
     }
     // Return null if the WP_Filesystem() check failed.
     return null;
 }
 function can_write_files()
 {
     $access_type = get_filesystem_method();
     ob_start();
     $creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, null);
     $_c = ob_get_clean();
     if ($access_type === 'direct' || WP_Filesystem($creds)) {
         return true;
     }
     $this->errors[] = "WordPress does not have access to it's own file system!";
     $this->consequences[] = "Images, CSS Files, Cache Files will be included with an alternative inline method, which is slower.";
     $this->solutions[] = "\r\n        <ol>\r\n        <li>\r\n        You will have to fill in FTP credentials into the wp-config.php file.<br><br>\r\n        <strong>define( 'FTP_USER', 'username' );<br>\r\n        define( 'FTP_PASS', 'password' );<br>\r\n        define( 'FTP_HOST', 'ftp.example.org' );</strong> <br><br>\r\n        In some cases more constants might be required. <br>\r\n        Please read: <a href='https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants'>WordPress Upgrage Constants</a> \r\n        </li>\r\n        <li>\r\n        ADVANCED USERS ONLY!<br><br>\r\n        Change ownership of the WordPress directory and all of its contents via SSH for the <strong>www-data</strong> process.<br><br>\r\n        \r\n        <a href='http://stackoverflow.com/questions/18352682/correct-file-permissions-for-wordpress'>Changing Ownership if WordPress is in the ROOT directory</a>\r\n        </li>\r\n        </ol>";
     return false;
 }
Example #29
0
 /**
  * [connect description]
  * @return [type]         [description]
  */
 public function connect()
 {
     // Try to setup WP_Filesystem
     if (FALSE === ($creds = request_filesystem_credentials($this->_url, $this->_method, FALSE, FALSE, $this->_fields))) {
         // A form has just been output asking the user to verify file ownership
         return FALSE;
     }
     // If the user enters the credentials but the credentials can't be verified to setup WP_Filesystem, output the form again
     if (!WP_Filesystem($creds)) {
         // This time produce the error that tells the user there was an error connecting
         request_filesystem_credentials($this->_url, $this->_method, TRUE, FALSE, $this->_fields);
         return FALSE;
     }
     return TRUE;
 }
Example #30
0
 function install($url, $args)
 {
     global $wpdb, $wp_filesystem;
     /*
      * Use WordPress WP_Filesystem methods to install DB
      */
     // Check Credentials
     if (false === ($creds = request_filesystem_credentials($url, NULL, false, false, $args))) {
         // Not yet valid, a form will have been presented - drop out.
         return array('HideForm' => true);
     }
     if (!WP_Filesystem($creds)) {
         // our credentials were no good, ask the user for them again
         request_filesystem_credentials($url, NULL, true, false, $args);
         return array('HideForm' => true);
     }
     /* Skip the download if it has already been done */
     if (!is_readable($this->temp_file)) {
         $temp_file = download_url($this->remote_file);
         if (is_wp_error($temp_file)) {
             return array('Success' => False, 'Message' => __('ip2nation install: Failed to download file: ', 'amazon-link') . $temp_file->get_error_message());
         }
         $result = unzip_file($temp_file, $this->temp_dir);
         if (is_wp_error($result)) {
             unlink($temp_file);
             return array('Success' => False, 'Message' => __('ip2nation install: Failed to unzip file: ', 'amazon-link') . $result->get_error_message());
         }
     }
     // Install the database
     // This can take a while on slow servers, disable aborts until
     // I do a proper jquery progress version.
     set_time_limit(0);
     ignore_user_abort(true);
     // Process database file
     $sql = $wp_filesystem->get_contents($this->temp_file);
     $lines = explode(';', $sql);
     unset($sql);
     $queries = 0;
     foreach ($lines as $line) {
         $line = trim($line);
         if (!empty($line) && $wpdb->query($line . ';') === FALSE) {
             return array('Success' => False, 'Message' => '=' . $line . '=' . sprintf(__('ip2nation install: Database downloaded and unzipped but failed to install [%s]', 'amazon-link'), $wpdb->last_error));
         }
         $queries++;
     }
     $wp_filesystem->delete($this->temp_dir, true);
     return array('Success' => True, 'Message' => sprintf(__('ip2nation install: Database downloaded and installed successfully. %s queries executed.', 'amazon-link'), $queries));
 }