/** * @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; }
/** * @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... // let them do it, because we are one of those eager beavers! :P /** * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process * is setup to mostly happen on 'init', and refactoring to have it happen on * 'wp_loaded' is too much work on a BETA milestone. * So this fix is expected to work if the WP files are owned by the server user, * but probably not if the user needs to enter their FTP credentials to modify files * and there may be troubles if the WP files are owned by a different user * than the server user. But both of these issues should exist in 4.4 and earlier too */ if (FALSE && !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'; require_once ABSPATH . 'wp-admin/includes/template.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; }
/** * @param string|null $filepath the filepath we want to work in. If its in the * wp uploads directory, we'll want to just use the filesystem directly. * If not provided, we have to assume its not in the uploads directory * @throws EE_Error if filesystem credentials are required * @return WP_Filesystem_Base */ private static function _get_wp_filesystem($filepath = null) { if (apply_filters('FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', $filepath && EEH_File::is_in_uploads_folder($filepath), $filepath)) { if (!EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; $method = 'direct'; $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); //check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() if (!defined('FS_CHMOD_DIR')) { define('FS_CHMOD_DIR', fileperms(ABSPATH) & 0777 | 0755); } if (!defined('FS_CHMOD_FILE')) { define('FS_CHMOD_FILE', fileperms(ABSPATH . 'index.php') & 0777 | 0644); } require_once $wp_filesystem_direct_file; EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); } return EEH_File::$_wp_filesystem_direct; } 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... // let them do it, because we are one of those eager beavers! :P /** * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process * is setup to mostly happen on 'init', and refactoring to have it happen on * 'wp_loaded' is too much work on a BETA milestone. * So this fix is expected to work if the WP files are owned by the server user, * but probably not if the user needs to enter their FTP credentials to modify files * and there may be troubles if the WP files are owned by a different user * than the server user. But both of these issues should exist in 4.4 and earlier too */ if (FALSE && !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'; require_once ABSPATH . 'wp-admin/includes/template.php'; } // 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(); // basically check for direct or previously configured access if (!WP_Filesystem($credentials)) { // 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')); } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); throw new EE_Error(sprintf(__('WP Filesystem Error: $1%s', 'event_espresso'), $wp_filesystem->errors->get_error_message())); } } } } return $wp_filesystem; }