Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/helpers/EEH_Template_Validator.helper.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -29,152 +29,152 @@
 block discarded – undo
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
34
-     * @param mixed $variable_to_test
35
-     * @param string $name_of_variable helpful in throwing intelligent errors
36
-     * @param string $class_name eg EE_Answer, EE_Transaction, etc.
37
-     * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
38
-     * @return void
39
-     * @throws EE_Error (indirectly)
40
-     */
41
-    public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42
-    {
43
-        if (!WP_DEBUG) {
44
-            return;
45
-        }
46
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
47
-        if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48
-            return;
49
-        }
50
-        self::verify_is_array($variable_to_test, $name_of_variable);
51
-        foreach ($variable_to_test as $key => $array_element) {
52
-            self::verify_instanceof($array_element, $key, $class_name);
53
-        }
54
-    }
55
-
56
-
57
-
58
-
59
-
60
-    /**
61
-     * throws an EE_Error if $variable_to_test is null
62
-     * @param mixed $variable_to_test
63
-     * @param string $name_of_variable helpful for throwing intelligent errors
64
-     * @return void
65
-     * @throws EE_Error
66
-     */
67
-    public static function verify_isnt_null($variable_to_test, $name_of_variable)
68
-    {
69
-        if (!WP_DEBUG) {
70
-            return;
71
-        }
72
-        if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
73
-            $error[] = esc_html__('Variable named %s is null.', 'event_espresso');
74
-            $error[] = esc_html__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
75
-            throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
76
-        }
77
-    }
78
-
79
-    /**
80
-     * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
81
-     * @param boolean $expression_to_test
82
-     * @param string $expression_string_representation a string representation of your expression
83
-     * for example, if your expression were $var1==23, then this should be '$var1==23'
84
-     * @return void
85
-     * @throws EE_Error
86
-     */
87
-    public static function verify_is_true($expression_to_test, $expression_string_representation)
88
-    {
89
-        if (!WP_DEBUG) {
90
-            return;
91
-        }
92
-        if (!$expression_to_test) {
93
-            $error[] = esc_html__('Template error.', 'event_espresso');
94
-            $error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
95
-            throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
96
-        }
97
-    }
98
-
99
-
100
-
101
-
102
-
103
-    /**
104
-     * For verifying that a variable is indeed an object of class $class_name
105
-     * @param mixed $variable_to_test
106
-     * @param string $name_of_variable helpful when throwing errors
107
-     * @param string $class_name eg, EE_Answer,
108
-     * @return void
109
-     * @throws EE_Error
110
-     */
111
-    public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112
-    {
113
-        if (!WP_DEBUG) {
114
-            return;
115
-        }
116
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
117
-        if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118
-            return;
119
-        }
120
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
121
-            $msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
122
-            $msg[] = esc_html__("It should be of type %s", 'event_espresso');
123
-            throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
124
-        }
125
-    }
126
-
127
-
128
-
129
-
130
-
131
-    /**
132
-     * For verifying that a variable is indeed an array, else throw an EE_Error
133
-     * @param type $variable_to_test
134
-     * @param type $variable_name
135
-     * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
136
-     * @return void
137
-     * @throws EE_Error
138
-     */
139
-    public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140
-    {
141
-        if (!WP_DEBUG) {
142
-            return;
143
-        }
144
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
145
-        if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146
-            return;
147
-        }
148
-        if (!is_array($variable_to_test)) {
149
-            $error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
150
-            $error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
151
-            throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
152
-        }
153
-    }
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-    /**
162
-     * for verifying that a variable is one of the string optiosn supplied
163
-     * @param mixed $variable_to_test
164
-     * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
165
-     * @param array $string_options an array of acceptable values
166
-     * @return void
167
-     * @throws EE_Error
168
-     */
169
-    public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170
-    {
171
-        if (!WP_DEBUG) {
172
-            return;
173
-        }
174
-        if (!in_array($variable_to_test, $string_options)) {
175
-            $msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
176
-            $msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177
-            throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
178
-        }
179
-    }
32
+	/**
33
+	 * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
34
+	 * @param mixed $variable_to_test
35
+	 * @param string $name_of_variable helpful in throwing intelligent errors
36
+	 * @param string $class_name eg EE_Answer, EE_Transaction, etc.
37
+	 * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
38
+	 * @return void
39
+	 * @throws EE_Error (indirectly)
40
+	 */
41
+	public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42
+	{
43
+		if (!WP_DEBUG) {
44
+			return;
45
+		}
46
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
47
+		if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48
+			return;
49
+		}
50
+		self::verify_is_array($variable_to_test, $name_of_variable);
51
+		foreach ($variable_to_test as $key => $array_element) {
52
+			self::verify_instanceof($array_element, $key, $class_name);
53
+		}
54
+	}
55
+
56
+
57
+
58
+
59
+
60
+	/**
61
+	 * throws an EE_Error if $variable_to_test is null
62
+	 * @param mixed $variable_to_test
63
+	 * @param string $name_of_variable helpful for throwing intelligent errors
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 */
67
+	public static function verify_isnt_null($variable_to_test, $name_of_variable)
68
+	{
69
+		if (!WP_DEBUG) {
70
+			return;
71
+		}
72
+		if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
73
+			$error[] = esc_html__('Variable named %s is null.', 'event_espresso');
74
+			$error[] = esc_html__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
75
+			throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
81
+	 * @param boolean $expression_to_test
82
+	 * @param string $expression_string_representation a string representation of your expression
83
+	 * for example, if your expression were $var1==23, then this should be '$var1==23'
84
+	 * @return void
85
+	 * @throws EE_Error
86
+	 */
87
+	public static function verify_is_true($expression_to_test, $expression_string_representation)
88
+	{
89
+		if (!WP_DEBUG) {
90
+			return;
91
+		}
92
+		if (!$expression_to_test) {
93
+			$error[] = esc_html__('Template error.', 'event_espresso');
94
+			$error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
95
+			throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
96
+		}
97
+	}
98
+
99
+
100
+
101
+
102
+
103
+	/**
104
+	 * For verifying that a variable is indeed an object of class $class_name
105
+	 * @param mixed $variable_to_test
106
+	 * @param string $name_of_variable helpful when throwing errors
107
+	 * @param string $class_name eg, EE_Answer,
108
+	 * @return void
109
+	 * @throws EE_Error
110
+	 */
111
+	public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112
+	{
113
+		if (!WP_DEBUG) {
114
+			return;
115
+		}
116
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
117
+		if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118
+			return;
119
+		}
120
+		if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
121
+			$msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
122
+			$msg[] = esc_html__("It should be of type %s", 'event_espresso');
123
+			throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
124
+		}
125
+	}
126
+
127
+
128
+
129
+
130
+
131
+	/**
132
+	 * For verifying that a variable is indeed an array, else throw an EE_Error
133
+	 * @param type $variable_to_test
134
+	 * @param type $variable_name
135
+	 * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
136
+	 * @return void
137
+	 * @throws EE_Error
138
+	 */
139
+	public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140
+	{
141
+		if (!WP_DEBUG) {
142
+			return;
143
+		}
144
+		self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
145
+		if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146
+			return;
147
+		}
148
+		if (!is_array($variable_to_test)) {
149
+			$error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
150
+			$error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
151
+			throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
152
+		}
153
+	}
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+	/**
162
+	 * for verifying that a variable is one of the string optiosn supplied
163
+	 * @param mixed $variable_to_test
164
+	 * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
165
+	 * @param array $string_options an array of acceptable values
166
+	 * @return void
167
+	 * @throws EE_Error
168
+	 */
169
+	public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170
+	{
171
+		if (!WP_DEBUG) {
172
+			return;
173
+		}
174
+		if (!in_array($variable_to_test, $string_options)) {
175
+			$msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
176
+			$msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177
+			throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
178
+		}
179
+	}
180 180
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42 42
     {
43
-        if (!WP_DEBUG) {
43
+        if ( ! WP_DEBUG) {
44 44
             return;
45 45
         }
46
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
46
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
47 47
         if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48 48
             return;
49 49
         }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function verify_isnt_null($variable_to_test, $name_of_variable)
68 68
     {
69
-        if (!WP_DEBUG) {
69
+        if ( ! WP_DEBUG) {
70 70
             return;
71 71
         }
72 72
         if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public static function verify_is_true($expression_to_test, $expression_string_representation)
88 88
     {
89
-        if (!WP_DEBUG) {
89
+        if ( ! WP_DEBUG) {
90 90
             return;
91 91
         }
92
-        if (!$expression_to_test) {
92
+        if ( ! $expression_to_test) {
93 93
             $error[] = esc_html__('Template error.', 'event_espresso');
94 94
             $error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
95 95
             throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
@@ -110,14 +110,14 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112 112
     {
113
-        if (!WP_DEBUG) {
113
+        if ( ! WP_DEBUG) {
114 114
             return;
115 115
         }
116
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
116
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
117 117
         if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118 118
             return;
119 119
         }
120
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
120
+        if ($variable_to_test == null || ! ($variable_to_test instanceof $class_name)) {
121 121
             $msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
122 122
             $msg[] = esc_html__("It should be of type %s", 'event_espresso');
123 123
             throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
      */
139 139
     public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140 140
     {
141
-        if (!WP_DEBUG) {
141
+        if ( ! WP_DEBUG) {
142 142
             return;
143 143
         }
144
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
144
+        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty', 'do_not_allow_empty'));
145 145
         if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146 146
             return;
147 147
         }
148
-        if (!is_array($variable_to_test)) {
148
+        if ( ! is_array($variable_to_test)) {
149 149
             $error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
150 150
             $error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
151 151
             throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170 170
     {
171
-        if (!WP_DEBUG) {
171
+        if ( ! WP_DEBUG) {
172 172
             return;
173 173
         }
174
-        if (!in_array($variable_to_test, $string_options)) {
174
+        if ( ! in_array($variable_to_test, $string_options)) {
175 175
             $msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
176 176
             $msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177 177
             throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 2 patches
Indentation   +666 added lines, -666 removed lines patch added patch discarded remove patch
@@ -25,670 +25,670 @@
 block discarded – undo
25 25
 class EEH_File extends EEH_Base implements EEHI_File
26 26
 {
27 27
 
28
-    /**
29
-     * @var string $_credentials_form
30
-     */
31
-    private static $_credentials_form;
32
-
33
-    protected static $_wp_filesystem_direct;
34
-
35
-    /**
36
-     * @param string|null $filepath the filepath we want to work in. If its in the
37
-     * wp uploads directory, we'll want to just use the filesystem directly.
38
-     * If not provided, we have to assume its not in the uploads directory
39
-     * @throws EE_Error if filesystem credentials are required
40
-     * @return WP_Filesystem_Base
41
-     */
42
-    private static function _get_wp_filesystem($filepath = null)
43
-    {
44
-        if (
45
-            apply_filters(
46
-                'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
47
-                $filepath && EEH_File::is_in_uploads_folder($filepath),
48
-                $filepath
49
-            )
50
-        ) {
51
-            if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
52
-                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
53
-                $method = 'direct';
54
-                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
55
-                // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
56
-                if (! defined('FS_CHMOD_DIR')) {
57
-                    define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
58
-                }
59
-                if (! defined('FS_CHMOD_FILE')) {
60
-                    define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
61
-                }
62
-                require_once($wp_filesystem_direct_file);
63
-                EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
64
-            }
65
-            return EEH_File::$_wp_filesystem_direct;
66
-        }
67
-        global $wp_filesystem;
68
-        // no filesystem setup ???
69
-        if (! $wp_filesystem instanceof WP_Filesystem_Base) {
70
-            // if some eager beaver's just trying to get in there too early...
71
-            // let them do it, because we are one of those eager beavers! :P
72
-            /**
73
-             * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base
74
-             * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process
75
-             * is setup to mostly happen on 'init', and refactoring to have it happen on
76
-             * 'wp_loaded' is too much work on a BETA milestone.
77
-             * So this fix is expected to work if the WP files are owned by the server user,
78
-             * but probably not if the user needs to enter their FTP credentials to modify files
79
-             * and there may be troubles if the WP files are owned by a different user
80
-             * than the server user. But both of these issues should exist in 4.4 and earlier too
81
-             */
82
-            if (false && ! did_action('wp_loaded')) {
83
-                $msg = esc_html__('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');
84
-                if (WP_DEBUG) {
85
-                    $msg .= '<br />' .  esc_html__('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');
86
-                }
87
-                throw new EE_Error($msg);
88
-            } else {
89
-                // should be loaded if we are past the wp_loaded hook...
90
-                if (! function_exists('WP_Filesystem')) {
91
-                    require_once(ABSPATH . 'wp-admin/includes/file.php');
92
-                    require_once(ABSPATH . 'wp-admin/includes/template.php');
93
-                }
94
-                // turn on output buffering so that we can capture the credentials form
95
-                ob_start();
96
-                $credentials = request_filesystem_credentials('');
97
-                // store credentials form for the time being
98
-                EEH_File::$_credentials_form = ob_get_clean();
99
-                // basically check for direct or previously configured access
100
-                if (! WP_Filesystem($credentials)) {
101
-                    // if credentials do NOT exist
102
-                    if ($credentials === false) {
103
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
104
-                        throw new EE_Error(esc_html__('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'));
105
-                    } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
106
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
107
-                        throw new EE_Error(
108
-                            sprintf(
109
-                                esc_html__('WP Filesystem Error: $1%s', 'event_espresso'),
110
-                                $wp_filesystem->errors->get_error_message()
111
-                            )
112
-                        );
113
-                    }
114
-                }
115
-            }
116
-        }
117
-        return $wp_filesystem;
118
-    }
119
-
120
-    /**
121
-     * display_request_filesystem_credentials_form
122
-     */
123
-    public static function display_request_filesystem_credentials_form()
124
-    {
125
-        if (! empty(EEH_File::$_credentials_form)) {
126
-            echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
127
-        }
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    verify_filepath_and_permissions
134
-     *    checks that a file is readable and has sufficient file permissions set to access
135
-     *
136
-     * @access public
137
-     * @param string $full_file_path - full server path to the folder or file
138
-     * @param string $file_name      - name of file if checking a file
139
-     * @param string $file_ext       - file extension (ie: "php") if checking a file
140
-     * @param string $type_of_file   - general type of file (ie: "module"), this is only used to improve error messages
141
-     * @throws EE_Error if filesystem credentials are required
142
-     * @return bool
143
-     */
144
-    public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '')
145
-    {
146
-        // load WP_Filesystem and set file permissions
147
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
148
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
149
-        if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
150
-            $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
151
-            $file_name .= ! empty($file_ext) ? ' file' : ' folder';
152
-            $msg = sprintf(
153
-                esc_html__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
154
-                $file_name,
155
-                '<br />'
156
-            );
157
-            if (EEH_File::exists($full_file_path)) {
158
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
159
-            } else {
160
-                // no file permissions means the file was not found
161
-                $msg .= sprintf(
162
-                    esc_html__('Please ensure the following path is correct: "%s".', 'event_espresso'),
163
-                    $full_file_path
164
-                );
165
-            }
166
-            if (defined('WP_DEBUG') && WP_DEBUG) {
167
-                throw new EE_Error($msg . '||' . $msg);
168
-            }
169
-            return false;
170
-        }
171
-        return true;
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder
178
-     *
179
-     * @access private
180
-     * @param string $full_file_path - full server path to the folder or file
181
-     * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
182
-     * @throws EE_Error if filesystem credentials are required
183
-     * @return string
184
-     */
185
-    private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '')
186
-    {
187
-        // load WP_Filesystem and set file permissions
188
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
189
-        // check file permissions
190
-        $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
191
-        if ($perms) {
192
-            // file permissions exist, but way be set incorrectly
193
-            $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
194
-            $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
195
-            return sprintf(
196
-                esc_html__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
197
-                $type_of_file,
198
-                $perms
199
-            );
200
-        } else {
201
-            // file exists but file permissions could not be read ?!?!
202
-            return sprintf(
203
-                esc_html__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
204
-                $full_file_path
205
-            );
206
-        }
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * ensure_folder_exists_and_is_writable
213
-     * ensures that a folder exists and is writable, will attempt to create folder if it does not exist
214
-     * Also ensures all the parent folders exist, and if not tries to create them.
215
-     * Also, if this function creates the folder, adds a .htaccess file and index.html file
216
-     * @param string $folder
217
-     * @throws EE_Error if the folder exists and is writeable, but for some reason we
218
-     * can't write to it
219
-     * @return bool false if folder isn't writable; true if it exists and is writeable,
220
-     */
221
-    public static function ensure_folder_exists_and_is_writable($folder = '')
222
-    {
223
-        if (empty($folder)) {
224
-            return false;
225
-        }
226
-        // remove ending /
227
-        $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
228
-        $parent_folder = EEH_File::get_parent_folder($folder);
229
-        // add / to folder
230
-        $folder = EEH_File::end_with_directory_separator($folder);
231
-        $wp_filesystem = EEH_File::_get_wp_filesystem($folder);
232
-        if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
233
-            // ok so it doesn't exist. Does its parent? Can we write to it?
234
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
235
-                return false;
236
-            }
237
-            if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
238
-                return false;
239
-            } else {
240
-                if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
241
-                    if (defined('WP_DEBUG') && WP_DEBUG) {
242
-                        $msg = sprintf(esc_html__('"%s" could not be created.', 'event_espresso'), $folder);
243
-                        $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
244
-                        throw new EE_Error($msg);
245
-                    }
246
-                    return false;
247
-                }
248
-                EEH_File::add_index_file($folder);
249
-            }
250
-        } elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
251
-            return false;
252
-        }
253
-        return true;
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * verify_is_writable - checks if a file or folder is writable
260
-     * @param string $full_path      - full server path to file or folder
261
-     * @param string $file_or_folder - whether checking a file or folder
262
-     * @throws EE_Error if filesystem credentials are required
263
-     * @return bool
264
-     */
265
-    public static function verify_is_writable($full_path = '', $file_or_folder = 'folder')
266
-    {
267
-        // load WP_Filesystem and set file permissions
268
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
269
-        $full_path = EEH_File::standardise_directory_separators($full_path);
270
-        if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
271
-            if (defined('WP_DEBUG') && WP_DEBUG) {
272
-                $msg = sprintf(esc_html__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
273
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
274
-                throw new EE_Error($msg);
275
-            }
276
-            return false;
277
-        }
278
-        return true;
279
-    }
280
-
281
-
282
-
283
-    /**
284
-     * ensure_file_exists_and_is_writable
285
-     * ensures that a file exists and is writable, will attempt to create file if it does not exist.
286
-     * Also ensures all the parent folders exist, and if not tries to create them.
287
-     * @param string $full_file_path
288
-     * @throws EE_Error if filesystem credentials are required
289
-     * @return bool
290
-     */
291
-    public static function ensure_file_exists_and_is_writable($full_file_path = '')
292
-    {
293
-        // load WP_Filesystem and set file permissions
294
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
295
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
296
-        $parent_folder = EEH_File::get_parent_folder($full_file_path);
297
-        if (! EEH_File::exists($full_file_path)) {
298
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
299
-                return false;
300
-            }
301
-            if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
302
-                if (defined('WP_DEBUG') && WP_DEBUG) {
303
-                    $msg = sprintf(esc_html__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
304
-                    $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
305
-                    throw new EE_Error($msg);
306
-                }
307
-                return false;
308
-            }
309
-        }
310
-        if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
311
-            return false;
312
-        }
313
-        return true;
314
-    }
315
-
316
-    /**
317
-     * Gets the parent folder. If provided with file, gets the folder that contains it.
318
-     * If provided a folder, gets its parent folder.
319
-     * @param string $file_or_folder_path
320
-     * @return string parent folder, ENDING with a directory separator
321
-     */
322
-    public static function get_parent_folder($file_or_folder_path)
323
-    {
324
-        // find the last /, ignoring a / on the very end
325
-        // eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326
-        // parent folder, "/var/something/"
327
-        $ds = strlen($file_or_folder_path) > 1
328
-            ? strrpos($file_or_folder_path, '/', -2)
329
-            : strlen($file_or_folder_path);
330
-        return substr($file_or_folder_path, 0, $ds + 1);
331
-    }
332
-
333
-    // public static function ensure_folder_exists_recursively( $folder ) {
334
-    //
335
-    // }
336
-
337
-
338
-
339
-    /**
340
-     * get_file_contents
341
-     * @param string $full_file_path
342
-     * @throws EE_Error if filesystem credentials are required
343
-     * @return string
344
-     */
345
-    public static function get_file_contents($full_file_path = '')
346
-    {
347
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
348
-        if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
349
-            // load WP_Filesystem and set file permissions
350
-            $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
351
-            return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
352
-        }
353
-        return '';
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * write_file
360
-     * @param string $full_file_path
361
-     * @param string $file_contents - the content to be written to the file
362
-     * @param string $file_type
363
-     * @throws EE_Error if filesystem credentials are required
364
-     * @return bool
365
-     */
366
-    public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
367
-    {
368
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
369
-        $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
370
-        $folder = EEH_File::remove_filename_from_filepath($full_file_path);
371
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
372
-            if (defined('WP_DEBUG') && WP_DEBUG) {
373
-                $msg = sprintf(esc_html__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
374
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
375
-                throw new EE_Error($msg);
376
-            }
377
-            return false;
378
-        }
379
-        // load WP_Filesystem and set file permissions
380
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
381
-        // write the file
382
-        if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
383
-            if (defined('WP_DEBUG') && WP_DEBUG) {
384
-                $msg = sprintf(esc_html__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
385
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
386
-                throw new EE_Error($msg);
387
-            }
388
-            return false;
389
-        }
390
-        return true;
391
-    }
392
-
393
-    /**
394
-     * Wrapper for WP_Filesystem_Base::delete
395
-     *
396
-     * @param string $filepath
397
-     * @param boolean $recursive
398
-     * @param boolean|string $type 'd' for directory, 'f' for file
399
-     * @throws EE_Error if filesystem credentials are required
400
-     * @return boolean
401
-     */
402
-    public static function delete($filepath, $recursive = false, $type = false)
403
-    {
404
-        $wp_filesystem = EEH_File::_get_wp_filesystem();
405
-        return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false;
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * exists
412
-     * checks if a file exists using the WP filesystem
413
-     * @param string $full_file_path
414
-     * @throws EE_Error if filesystem credentials are required
415
-     * @return bool
416
-     */
417
-    public static function exists($full_file_path = '')
418
-    {
419
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
420
-        return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false;
421
-    }
422
-
423
-
424
-
425
-    /**
426
-     * is_readable
427
-     * checks if a file is_readable using the WP filesystem
428
-     *
429
-     * @param string $full_file_path
430
-     * @throws EE_Error if filesystem credentials are required
431
-     * @return bool
432
-     */
433
-    public static function is_readable($full_file_path = '')
434
-    {
435
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
436
-        if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
437
-            return true;
438
-        } else {
439
-            return false;
440
-        }
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * remove_filename_from_filepath
447
-     * given a full path to a file including the filename itself, this removes  the filename and returns the path, up to, but NOT including the filename OR slash
448
-     *
449
-     * @param string $full_file_path
450
-     * @return string
451
-     */
452
-    public static function remove_filename_from_filepath($full_file_path = '')
453
-    {
454
-        return pathinfo($full_file_path, PATHINFO_DIRNAME);
455
-    }
456
-
457
-
458
-    /**
459
-     * get_filename_from_filepath. Arguably the same as basename()
460
-     *
461
-     * @param string $full_file_path
462
-     * @return string
463
-     */
464
-    public static function get_filename_from_filepath($full_file_path = '')
465
-    {
466
-        return pathinfo($full_file_path, PATHINFO_BASENAME);
467
-    }
468
-
469
-
470
-    /**
471
-     * get_file_extension
472
-     *
473
-     * @param string $full_file_path
474
-     * @return string
475
-     */
476
-    public static function get_file_extension($full_file_path = '')
477
-    {
478
-        return pathinfo($full_file_path, PATHINFO_EXTENSION);
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * add_htaccess_deny_from_all so the webserver cannot access this folder
485
-     * @param string $folder
486
-     * @throws EE_Error if filesystem credentials are required
487
-     * @return bool
488
-     */
489
-    public static function add_htaccess_deny_from_all($folder = '')
490
-    {
491
-        $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
492
-        if (! EEH_File::exists($folder . '.htaccess')) {
493
-            if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
494
-                return false;
495
-            }
496
-        }
497
-
498
-        return true;
499
-    }
500
-
501
-    /**
502
-     * Adds an index file to this folder, so folks can't list all the file's contents
503
-     * @param string $folder
504
-     * @throws EE_Error if filesystem credentials are required
505
-     * @return boolean
506
-     */
507
-    public static function add_index_file($folder)
508
-    {
509
-        $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
510
-        if (! EEH_File::exists($folder . 'index.php')) {
511
-            if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
512
-                return false;
513
-            }
514
-        }
515
-        return true;
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php),
522
-     * extract that classname.
523
-     * @param string $file_path
524
-     * @return string
525
-     */
526
-    public static function get_classname_from_filepath_with_standard_filename($file_path)
527
-    {
528
-        // extract file from path
529
-        $filename = basename($file_path);
530
-        // now remove the first period and everything after
531
-        $pos_of_first_period = strpos($filename, '.');
532
-        return substr($filename, 0, $pos_of_first_period);
533
-    }
534
-
535
-
536
-
537
-    /**
538
-     * standardise_directory_separators
539
-     *  convert all directory separators in a file path.
540
-     * @param string $file_path
541
-     * @return string
542
-     */
543
-    public static function standardise_directory_separators($file_path)
544
-    {
545
-        return str_replace(array( '\\', '/' ), '/', $file_path);
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     * end_with_directory_separator
552
-     *  ensures that file path ends with '/'
553
-     * @param string $file_path
554
-     * @return string
555
-     */
556
-    public static function end_with_directory_separator($file_path)
557
-    {
558
-        return rtrim($file_path, '/\\') . '/';
559
-    }
560
-
561
-
562
-
563
-    /**
564
-     * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators
565
-     * @param $file_path
566
-     * @return string
567
-     */
568
-    public static function standardise_and_end_with_directory_separator($file_path)
569
-    {
570
-        return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * takes the folder name (with or without trailing slash) and finds the files it in,
577
-     * and what the class's name inside of each should be.
578
-     * @param array $folder_paths
579
-     * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically;
580
-     *      if FALSE (Default), returned array will be indexed by the filenames minus extensions.
581
-     *      Set it TRUE if you know there are files in the directory with the same name but different extensions
582
-     * @throws EE_Error if filesystem credentials are required
583
-     * @return array if $index_numerically == TRUE keys are numeric ,
584
-     *      if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
585
-     *       and values are their filepaths
586
-     */
587
-    public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false)
588
-    {
589
-        $class_to_folder_path = array();
590
-        foreach ($folder_paths as $folder_path) {
591
-            $folder_path = self::standardise_and_end_with_directory_separator($folder_path);
592
-            // load WP_Filesystem and set file permissions
593
-            $files_in_folder = glob($folder_path . '*.php');
594
-            $class_to_folder_path = array();
595
-            if ($files_in_folder) {
596
-                foreach ($files_in_folder as $file_path) {
597
-                    // only add files, not folders
598
-                    if (! is_dir($file_path)) {
599
-                        if ($index_numerically) {
600
-                            $class_to_folder_path[] = $file_path;
601
-                        } else {
602
-                            $classname = self::get_classname_from_filepath_with_standard_filename($file_path);
603
-                            $class_to_folder_path[ $classname ] = $file_path;
604
-                        }
605
-                    }
606
-                }
607
-            }
608
-        }
609
-        return $class_to_folder_path;
610
-    }
611
-
612
-
613
-
614
-    /**
615
-     * Copies a file. Mostly a wrapper of WP_Filesystem::copy
616
-     * @param string $source_file
617
-     * @param string $destination_file
618
-     * @param boolean $overwrite
619
-     * @throws EE_Error if filesystem credentials are required
620
-     * @return boolean success
621
-     */
622
-    public static function copy($source_file, $destination_file, $overwrite = false)
623
-    {
624
-        $full_source_path = EEH_File::standardise_directory_separators($source_file);
625
-        if (! EEH_File::exists($full_source_path)) {
626
-            if (defined('WP_DEBUG') && WP_DEBUG) {
627
-                $msg = sprintf(esc_html__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
628
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
629
-                throw new EE_Error($msg);
630
-            }
631
-            return false;
632
-        }
633
-
634
-        $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
635
-        $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
636
-        EEH_File::ensure_folder_exists_and_is_writable($folder);
637
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
638
-            if (defined('WP_DEBUG') && WP_DEBUG) {
639
-                $msg = sprintf(esc_html__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
640
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
641
-                throw new EE_Error($msg);
642
-            }
643
-            return false;
644
-        }
645
-
646
-        // load WP_Filesystem and set file permissions
647
-        $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
648
-        // write the file
649
-        if (
650
-            ! $wp_filesystem->copy(
651
-                EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
652
-                EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
653
-                $overwrite
654
-            )
655
-        ) {
656
-            if (defined('WP_DEBUG') && WP_DEBUG) {
657
-                $msg = sprintf(esc_html__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
658
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
659
-                throw new EE_Error($msg);
660
-            }
661
-            return false;
662
-        }
663
-        return true;
664
-    }
665
-
666
-    /**
667
-     * Reports whether or not the filepath is in the EE uploads folder or not
668
-     * @param string $filepath
669
-     * @return boolean
670
-     */
671
-    public static function is_in_uploads_folder($filepath)
672
-    {
673
-        $uploads = wp_upload_dir();
674
-        return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
675
-    }
676
-
677
-    /**
678
-     * Given a "local" filepath (what you probably thought was the only filepath),
679
-     * converts it into a "remote" filepath (the filepath the currently-in-use
680
-     * $wp_filesystem needs to use access the folder or file).
681
-     * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
682
-     * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
683
-     * is in use, so you need to provide it
684
-     * @param string $local_filepath the filepath to the folder/file locally
685
-     * @throws EE_Error if filesystem credentials are required
686
-     * @return string the remote filepath (eg the filepath the filesystem method, eg
687
-     * ftp or ssh, will use to access the folder
688
-     */
689
-    public static function convert_local_filepath_to_remote_filepath($local_filepath)
690
-    {
691
-        $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
692
-        return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath);
693
-    }
28
+	/**
29
+	 * @var string $_credentials_form
30
+	 */
31
+	private static $_credentials_form;
32
+
33
+	protected static $_wp_filesystem_direct;
34
+
35
+	/**
36
+	 * @param string|null $filepath the filepath we want to work in. If its in the
37
+	 * wp uploads directory, we'll want to just use the filesystem directly.
38
+	 * If not provided, we have to assume its not in the uploads directory
39
+	 * @throws EE_Error if filesystem credentials are required
40
+	 * @return WP_Filesystem_Base
41
+	 */
42
+	private static function _get_wp_filesystem($filepath = null)
43
+	{
44
+		if (
45
+			apply_filters(
46
+				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
47
+				$filepath && EEH_File::is_in_uploads_folder($filepath),
48
+				$filepath
49
+			)
50
+		) {
51
+			if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
52
+				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
53
+				$method = 'direct';
54
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
55
+				// check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
56
+				if (! defined('FS_CHMOD_DIR')) {
57
+					define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
58
+				}
59
+				if (! defined('FS_CHMOD_FILE')) {
60
+					define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
61
+				}
62
+				require_once($wp_filesystem_direct_file);
63
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
64
+			}
65
+			return EEH_File::$_wp_filesystem_direct;
66
+		}
67
+		global $wp_filesystem;
68
+		// no filesystem setup ???
69
+		if (! $wp_filesystem instanceof WP_Filesystem_Base) {
70
+			// if some eager beaver's just trying to get in there too early...
71
+			// let them do it, because we are one of those eager beavers! :P
72
+			/**
73
+			 * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base
74
+			 * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process
75
+			 * is setup to mostly happen on 'init', and refactoring to have it happen on
76
+			 * 'wp_loaded' is too much work on a BETA milestone.
77
+			 * So this fix is expected to work if the WP files are owned by the server user,
78
+			 * but probably not if the user needs to enter their FTP credentials to modify files
79
+			 * and there may be troubles if the WP files are owned by a different user
80
+			 * than the server user. But both of these issues should exist in 4.4 and earlier too
81
+			 */
82
+			if (false && ! did_action('wp_loaded')) {
83
+				$msg = esc_html__('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');
84
+				if (WP_DEBUG) {
85
+					$msg .= '<br />' .  esc_html__('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');
86
+				}
87
+				throw new EE_Error($msg);
88
+			} else {
89
+				// should be loaded if we are past the wp_loaded hook...
90
+				if (! function_exists('WP_Filesystem')) {
91
+					require_once(ABSPATH . 'wp-admin/includes/file.php');
92
+					require_once(ABSPATH . 'wp-admin/includes/template.php');
93
+				}
94
+				// turn on output buffering so that we can capture the credentials form
95
+				ob_start();
96
+				$credentials = request_filesystem_credentials('');
97
+				// store credentials form for the time being
98
+				EEH_File::$_credentials_form = ob_get_clean();
99
+				// basically check for direct or previously configured access
100
+				if (! WP_Filesystem($credentials)) {
101
+					// if credentials do NOT exist
102
+					if ($credentials === false) {
103
+						add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
104
+						throw new EE_Error(esc_html__('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'));
105
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
106
+						add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
107
+						throw new EE_Error(
108
+							sprintf(
109
+								esc_html__('WP Filesystem Error: $1%s', 'event_espresso'),
110
+								$wp_filesystem->errors->get_error_message()
111
+							)
112
+						);
113
+					}
114
+				}
115
+			}
116
+		}
117
+		return $wp_filesystem;
118
+	}
119
+
120
+	/**
121
+	 * display_request_filesystem_credentials_form
122
+	 */
123
+	public static function display_request_filesystem_credentials_form()
124
+	{
125
+		if (! empty(EEH_File::$_credentials_form)) {
126
+			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
127
+		}
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    verify_filepath_and_permissions
134
+	 *    checks that a file is readable and has sufficient file permissions set to access
135
+	 *
136
+	 * @access public
137
+	 * @param string $full_file_path - full server path to the folder or file
138
+	 * @param string $file_name      - name of file if checking a file
139
+	 * @param string $file_ext       - file extension (ie: "php") if checking a file
140
+	 * @param string $type_of_file   - general type of file (ie: "module"), this is only used to improve error messages
141
+	 * @throws EE_Error if filesystem credentials are required
142
+	 * @return bool
143
+	 */
144
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '')
145
+	{
146
+		// load WP_Filesystem and set file permissions
147
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
148
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
149
+		if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
150
+			$file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
151
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
152
+			$msg = sprintf(
153
+				esc_html__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
154
+				$file_name,
155
+				'<br />'
156
+			);
157
+			if (EEH_File::exists($full_file_path)) {
158
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
159
+			} else {
160
+				// no file permissions means the file was not found
161
+				$msg .= sprintf(
162
+					esc_html__('Please ensure the following path is correct: "%s".', 'event_espresso'),
163
+					$full_file_path
164
+				);
165
+			}
166
+			if (defined('WP_DEBUG') && WP_DEBUG) {
167
+				throw new EE_Error($msg . '||' . $msg);
168
+			}
169
+			return false;
170
+		}
171
+		return true;
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder
178
+	 *
179
+	 * @access private
180
+	 * @param string $full_file_path - full server path to the folder or file
181
+	 * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
182
+	 * @throws EE_Error if filesystem credentials are required
183
+	 * @return string
184
+	 */
185
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '')
186
+	{
187
+		// load WP_Filesystem and set file permissions
188
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
189
+		// check file permissions
190
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
191
+		if ($perms) {
192
+			// file permissions exist, but way be set incorrectly
193
+			$type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
194
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
195
+			return sprintf(
196
+				esc_html__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
197
+				$type_of_file,
198
+				$perms
199
+			);
200
+		} else {
201
+			// file exists but file permissions could not be read ?!?!
202
+			return sprintf(
203
+				esc_html__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
204
+				$full_file_path
205
+			);
206
+		}
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * ensure_folder_exists_and_is_writable
213
+	 * ensures that a folder exists and is writable, will attempt to create folder if it does not exist
214
+	 * Also ensures all the parent folders exist, and if not tries to create them.
215
+	 * Also, if this function creates the folder, adds a .htaccess file and index.html file
216
+	 * @param string $folder
217
+	 * @throws EE_Error if the folder exists and is writeable, but for some reason we
218
+	 * can't write to it
219
+	 * @return bool false if folder isn't writable; true if it exists and is writeable,
220
+	 */
221
+	public static function ensure_folder_exists_and_is_writable($folder = '')
222
+	{
223
+		if (empty($folder)) {
224
+			return false;
225
+		}
226
+		// remove ending /
227
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
228
+		$parent_folder = EEH_File::get_parent_folder($folder);
229
+		// add / to folder
230
+		$folder = EEH_File::end_with_directory_separator($folder);
231
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
232
+		if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
233
+			// ok so it doesn't exist. Does its parent? Can we write to it?
234
+			if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
235
+				return false;
236
+			}
237
+			if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
238
+				return false;
239
+			} else {
240
+				if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
241
+					if (defined('WP_DEBUG') && WP_DEBUG) {
242
+						$msg = sprintf(esc_html__('"%s" could not be created.', 'event_espresso'), $folder);
243
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
244
+						throw new EE_Error($msg);
245
+					}
246
+					return false;
247
+				}
248
+				EEH_File::add_index_file($folder);
249
+			}
250
+		} elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
251
+			return false;
252
+		}
253
+		return true;
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * verify_is_writable - checks if a file or folder is writable
260
+	 * @param string $full_path      - full server path to file or folder
261
+	 * @param string $file_or_folder - whether checking a file or folder
262
+	 * @throws EE_Error if filesystem credentials are required
263
+	 * @return bool
264
+	 */
265
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder')
266
+	{
267
+		// load WP_Filesystem and set file permissions
268
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
269
+		$full_path = EEH_File::standardise_directory_separators($full_path);
270
+		if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
271
+			if (defined('WP_DEBUG') && WP_DEBUG) {
272
+				$msg = sprintf(esc_html__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
273
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
274
+				throw new EE_Error($msg);
275
+			}
276
+			return false;
277
+		}
278
+		return true;
279
+	}
280
+
281
+
282
+
283
+	/**
284
+	 * ensure_file_exists_and_is_writable
285
+	 * ensures that a file exists and is writable, will attempt to create file if it does not exist.
286
+	 * Also ensures all the parent folders exist, and if not tries to create them.
287
+	 * @param string $full_file_path
288
+	 * @throws EE_Error if filesystem credentials are required
289
+	 * @return bool
290
+	 */
291
+	public static function ensure_file_exists_and_is_writable($full_file_path = '')
292
+	{
293
+		// load WP_Filesystem and set file permissions
294
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
295
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
296
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
297
+		if (! EEH_File::exists($full_file_path)) {
298
+			if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
299
+				return false;
300
+			}
301
+			if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
302
+				if (defined('WP_DEBUG') && WP_DEBUG) {
303
+					$msg = sprintf(esc_html__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
304
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
305
+					throw new EE_Error($msg);
306
+				}
307
+				return false;
308
+			}
309
+		}
310
+		if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
311
+			return false;
312
+		}
313
+		return true;
314
+	}
315
+
316
+	/**
317
+	 * Gets the parent folder. If provided with file, gets the folder that contains it.
318
+	 * If provided a folder, gets its parent folder.
319
+	 * @param string $file_or_folder_path
320
+	 * @return string parent folder, ENDING with a directory separator
321
+	 */
322
+	public static function get_parent_folder($file_or_folder_path)
323
+	{
324
+		// find the last /, ignoring a / on the very end
325
+		// eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326
+		// parent folder, "/var/something/"
327
+		$ds = strlen($file_or_folder_path) > 1
328
+			? strrpos($file_or_folder_path, '/', -2)
329
+			: strlen($file_or_folder_path);
330
+		return substr($file_or_folder_path, 0, $ds + 1);
331
+	}
332
+
333
+	// public static function ensure_folder_exists_recursively( $folder ) {
334
+	//
335
+	// }
336
+
337
+
338
+
339
+	/**
340
+	 * get_file_contents
341
+	 * @param string $full_file_path
342
+	 * @throws EE_Error if filesystem credentials are required
343
+	 * @return string
344
+	 */
345
+	public static function get_file_contents($full_file_path = '')
346
+	{
347
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
348
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
349
+			// load WP_Filesystem and set file permissions
350
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
351
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
352
+		}
353
+		return '';
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * write_file
360
+	 * @param string $full_file_path
361
+	 * @param string $file_contents - the content to be written to the file
362
+	 * @param string $file_type
363
+	 * @throws EE_Error if filesystem credentials are required
364
+	 * @return bool
365
+	 */
366
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
367
+	{
368
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
369
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
370
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
371
+		if (! EEH_File::verify_is_writable($folder, 'folder')) {
372
+			if (defined('WP_DEBUG') && WP_DEBUG) {
373
+				$msg = sprintf(esc_html__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
374
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
375
+				throw new EE_Error($msg);
376
+			}
377
+			return false;
378
+		}
379
+		// load WP_Filesystem and set file permissions
380
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
381
+		// write the file
382
+		if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
383
+			if (defined('WP_DEBUG') && WP_DEBUG) {
384
+				$msg = sprintf(esc_html__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
385
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
386
+				throw new EE_Error($msg);
387
+			}
388
+			return false;
389
+		}
390
+		return true;
391
+	}
392
+
393
+	/**
394
+	 * Wrapper for WP_Filesystem_Base::delete
395
+	 *
396
+	 * @param string $filepath
397
+	 * @param boolean $recursive
398
+	 * @param boolean|string $type 'd' for directory, 'f' for file
399
+	 * @throws EE_Error if filesystem credentials are required
400
+	 * @return boolean
401
+	 */
402
+	public static function delete($filepath, $recursive = false, $type = false)
403
+	{
404
+		$wp_filesystem = EEH_File::_get_wp_filesystem();
405
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false;
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * exists
412
+	 * checks if a file exists using the WP filesystem
413
+	 * @param string $full_file_path
414
+	 * @throws EE_Error if filesystem credentials are required
415
+	 * @return bool
416
+	 */
417
+	public static function exists($full_file_path = '')
418
+	{
419
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
420
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false;
421
+	}
422
+
423
+
424
+
425
+	/**
426
+	 * is_readable
427
+	 * checks if a file is_readable using the WP filesystem
428
+	 *
429
+	 * @param string $full_file_path
430
+	 * @throws EE_Error if filesystem credentials are required
431
+	 * @return bool
432
+	 */
433
+	public static function is_readable($full_file_path = '')
434
+	{
435
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
436
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
437
+			return true;
438
+		} else {
439
+			return false;
440
+		}
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * remove_filename_from_filepath
447
+	 * given a full path to a file including the filename itself, this removes  the filename and returns the path, up to, but NOT including the filename OR slash
448
+	 *
449
+	 * @param string $full_file_path
450
+	 * @return string
451
+	 */
452
+	public static function remove_filename_from_filepath($full_file_path = '')
453
+	{
454
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
455
+	}
456
+
457
+
458
+	/**
459
+	 * get_filename_from_filepath. Arguably the same as basename()
460
+	 *
461
+	 * @param string $full_file_path
462
+	 * @return string
463
+	 */
464
+	public static function get_filename_from_filepath($full_file_path = '')
465
+	{
466
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
467
+	}
468
+
469
+
470
+	/**
471
+	 * get_file_extension
472
+	 *
473
+	 * @param string $full_file_path
474
+	 * @return string
475
+	 */
476
+	public static function get_file_extension($full_file_path = '')
477
+	{
478
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * add_htaccess_deny_from_all so the webserver cannot access this folder
485
+	 * @param string $folder
486
+	 * @throws EE_Error if filesystem credentials are required
487
+	 * @return bool
488
+	 */
489
+	public static function add_htaccess_deny_from_all($folder = '')
490
+	{
491
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
492
+		if (! EEH_File::exists($folder . '.htaccess')) {
493
+			if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
494
+				return false;
495
+			}
496
+		}
497
+
498
+		return true;
499
+	}
500
+
501
+	/**
502
+	 * Adds an index file to this folder, so folks can't list all the file's contents
503
+	 * @param string $folder
504
+	 * @throws EE_Error if filesystem credentials are required
505
+	 * @return boolean
506
+	 */
507
+	public static function add_index_file($folder)
508
+	{
509
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
510
+		if (! EEH_File::exists($folder . 'index.php')) {
511
+			if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
512
+				return false;
513
+			}
514
+		}
515
+		return true;
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php),
522
+	 * extract that classname.
523
+	 * @param string $file_path
524
+	 * @return string
525
+	 */
526
+	public static function get_classname_from_filepath_with_standard_filename($file_path)
527
+	{
528
+		// extract file from path
529
+		$filename = basename($file_path);
530
+		// now remove the first period and everything after
531
+		$pos_of_first_period = strpos($filename, '.');
532
+		return substr($filename, 0, $pos_of_first_period);
533
+	}
534
+
535
+
536
+
537
+	/**
538
+	 * standardise_directory_separators
539
+	 *  convert all directory separators in a file path.
540
+	 * @param string $file_path
541
+	 * @return string
542
+	 */
543
+	public static function standardise_directory_separators($file_path)
544
+	{
545
+		return str_replace(array( '\\', '/' ), '/', $file_path);
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 * end_with_directory_separator
552
+	 *  ensures that file path ends with '/'
553
+	 * @param string $file_path
554
+	 * @return string
555
+	 */
556
+	public static function end_with_directory_separator($file_path)
557
+	{
558
+		return rtrim($file_path, '/\\') . '/';
559
+	}
560
+
561
+
562
+
563
+	/**
564
+	 * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators
565
+	 * @param $file_path
566
+	 * @return string
567
+	 */
568
+	public static function standardise_and_end_with_directory_separator($file_path)
569
+	{
570
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * takes the folder name (with or without trailing slash) and finds the files it in,
577
+	 * and what the class's name inside of each should be.
578
+	 * @param array $folder_paths
579
+	 * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically;
580
+	 *      if FALSE (Default), returned array will be indexed by the filenames minus extensions.
581
+	 *      Set it TRUE if you know there are files in the directory with the same name but different extensions
582
+	 * @throws EE_Error if filesystem credentials are required
583
+	 * @return array if $index_numerically == TRUE keys are numeric ,
584
+	 *      if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
585
+	 *       and values are their filepaths
586
+	 */
587
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false)
588
+	{
589
+		$class_to_folder_path = array();
590
+		foreach ($folder_paths as $folder_path) {
591
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
592
+			// load WP_Filesystem and set file permissions
593
+			$files_in_folder = glob($folder_path . '*.php');
594
+			$class_to_folder_path = array();
595
+			if ($files_in_folder) {
596
+				foreach ($files_in_folder as $file_path) {
597
+					// only add files, not folders
598
+					if (! is_dir($file_path)) {
599
+						if ($index_numerically) {
600
+							$class_to_folder_path[] = $file_path;
601
+						} else {
602
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
603
+							$class_to_folder_path[ $classname ] = $file_path;
604
+						}
605
+					}
606
+				}
607
+			}
608
+		}
609
+		return $class_to_folder_path;
610
+	}
611
+
612
+
613
+
614
+	/**
615
+	 * Copies a file. Mostly a wrapper of WP_Filesystem::copy
616
+	 * @param string $source_file
617
+	 * @param string $destination_file
618
+	 * @param boolean $overwrite
619
+	 * @throws EE_Error if filesystem credentials are required
620
+	 * @return boolean success
621
+	 */
622
+	public static function copy($source_file, $destination_file, $overwrite = false)
623
+	{
624
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
625
+		if (! EEH_File::exists($full_source_path)) {
626
+			if (defined('WP_DEBUG') && WP_DEBUG) {
627
+				$msg = sprintf(esc_html__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
628
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
629
+				throw new EE_Error($msg);
630
+			}
631
+			return false;
632
+		}
633
+
634
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
635
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
636
+		EEH_File::ensure_folder_exists_and_is_writable($folder);
637
+		if (! EEH_File::verify_is_writable($folder, 'folder')) {
638
+			if (defined('WP_DEBUG') && WP_DEBUG) {
639
+				$msg = sprintf(esc_html__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
640
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
641
+				throw new EE_Error($msg);
642
+			}
643
+			return false;
644
+		}
645
+
646
+		// load WP_Filesystem and set file permissions
647
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
648
+		// write the file
649
+		if (
650
+			! $wp_filesystem->copy(
651
+				EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
652
+				EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
653
+				$overwrite
654
+			)
655
+		) {
656
+			if (defined('WP_DEBUG') && WP_DEBUG) {
657
+				$msg = sprintf(esc_html__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
658
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
659
+				throw new EE_Error($msg);
660
+			}
661
+			return false;
662
+		}
663
+		return true;
664
+	}
665
+
666
+	/**
667
+	 * Reports whether or not the filepath is in the EE uploads folder or not
668
+	 * @param string $filepath
669
+	 * @return boolean
670
+	 */
671
+	public static function is_in_uploads_folder($filepath)
672
+	{
673
+		$uploads = wp_upload_dir();
674
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
675
+	}
676
+
677
+	/**
678
+	 * Given a "local" filepath (what you probably thought was the only filepath),
679
+	 * converts it into a "remote" filepath (the filepath the currently-in-use
680
+	 * $wp_filesystem needs to use access the folder or file).
681
+	 * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
682
+	 * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
683
+	 * is in use, so you need to provide it
684
+	 * @param string $local_filepath the filepath to the folder/file locally
685
+	 * @throws EE_Error if filesystem credentials are required
686
+	 * @return string the remote filepath (eg the filepath the filesystem method, eg
687
+	 * ftp or ssh, will use to access the folder
688
+	 */
689
+	public static function convert_local_filepath_to_remote_filepath($local_filepath)
690
+	{
691
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
692
+		return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath);
693
+	}
694 694
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -48,16 +48,16 @@  discard block
 block discarded – undo
48 48
                 $filepath
49 49
             )
50 50
         ) {
51
-            if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
52
-                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
51
+            if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
52
+                require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
53 53
                 $method = 'direct';
54
-                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
54
+                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
55 55
                 // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
56
-                if (! defined('FS_CHMOD_DIR')) {
57
-                    define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
56
+                if ( ! defined('FS_CHMOD_DIR')) {
57
+                    define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
58 58
                 }
59
-                if (! defined('FS_CHMOD_FILE')) {
60
-                    define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
59
+                if ( ! defined('FS_CHMOD_FILE')) {
60
+                    define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
61 61
                 }
62 62
                 require_once($wp_filesystem_direct_file);
63 63
                 EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         }
67 67
         global $wp_filesystem;
68 68
         // no filesystem setup ???
69
-        if (! $wp_filesystem instanceof WP_Filesystem_Base) {
69
+        if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
70 70
             // if some eager beaver's just trying to get in there too early...
71 71
             // let them do it, because we are one of those eager beavers! :P
72 72
             /**
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
             if (false && ! did_action('wp_loaded')) {
83 83
                 $msg = esc_html__('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');
84 84
                 if (WP_DEBUG) {
85
-                    $msg .= '<br />' .  esc_html__('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');
85
+                    $msg .= '<br />'.esc_html__('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');
86 86
                 }
87 87
                 throw new EE_Error($msg);
88 88
             } else {
89 89
                 // should be loaded if we are past the wp_loaded hook...
90
-                if (! function_exists('WP_Filesystem')) {
91
-                    require_once(ABSPATH . 'wp-admin/includes/file.php');
92
-                    require_once(ABSPATH . 'wp-admin/includes/template.php');
90
+                if ( ! function_exists('WP_Filesystem')) {
91
+                    require_once(ABSPATH.'wp-admin/includes/file.php');
92
+                    require_once(ABSPATH.'wp-admin/includes/template.php');
93 93
                 }
94 94
                 // turn on output buffering so that we can capture the credentials form
95 95
                 ob_start();
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
                 // store credentials form for the time being
98 98
                 EEH_File::$_credentials_form = ob_get_clean();
99 99
                 // basically check for direct or previously configured access
100
-                if (! WP_Filesystem($credentials)) {
100
+                if ( ! WP_Filesystem($credentials)) {
101 101
                     // if credentials do NOT exist
102 102
                     if ($credentials === false) {
103
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
103
+                        add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
104 104
                         throw new EE_Error(esc_html__('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'));
105 105
                     } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
106
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
106
+                        add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
107 107
                         throw new EE_Error(
108 108
                             sprintf(
109 109
                                 esc_html__('WP Filesystem Error: $1%s', 'event_espresso'),
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public static function display_request_filesystem_credentials_form()
124 124
     {
125
-        if (! empty(EEH_File::$_credentials_form)) {
126
-            echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
125
+        if ( ! empty(EEH_File::$_credentials_form)) {
126
+            echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
127 127
         }
128 128
     }
129 129
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
         // load WP_Filesystem and set file permissions
147 147
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
148 148
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
149
-        if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
150
-            $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
149
+        if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
150
+            $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
151 151
             $file_name .= ! empty($file_ext) ? ' file' : ' folder';
152 152
             $msg = sprintf(
153 153
                 esc_html__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                 );
165 165
             }
166 166
             if (defined('WP_DEBUG') && WP_DEBUG) {
167
-                throw new EE_Error($msg . '||' . $msg);
167
+                throw new EE_Error($msg.'||'.$msg);
168 168
             }
169 169
             return false;
170 170
         }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
191 191
         if ($perms) {
192 192
             // file permissions exist, but way be set incorrectly
193
-            $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
193
+            $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
194 194
             $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
195 195
             return sprintf(
196 196
                 esc_html__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
         // add / to folder
230 230
         $folder = EEH_File::end_with_directory_separator($folder);
231 231
         $wp_filesystem = EEH_File::_get_wp_filesystem($folder);
232
-        if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
232
+        if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
233 233
             // ok so it doesn't exist. Does its parent? Can we write to it?
234
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
234
+            if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
235 235
                 return false;
236 236
             }
237
-            if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
237
+            if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
238 238
                 return false;
239 239
             } else {
240
-                if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
240
+                if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
241 241
                     if (defined('WP_DEBUG') && WP_DEBUG) {
242 242
                         $msg = sprintf(esc_html__('"%s" could not be created.', 'event_espresso'), $folder);
243 243
                         $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
                 }
248 248
                 EEH_File::add_index_file($folder);
249 249
             }
250
-        } elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
250
+        } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
251 251
             return false;
252 252
         }
253 253
         return true;
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         // load WP_Filesystem and set file permissions
268 268
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
269 269
         $full_path = EEH_File::standardise_directory_separators($full_path);
270
-        if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
270
+        if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
271 271
             if (defined('WP_DEBUG') && WP_DEBUG) {
272 272
                 $msg = sprintf(esc_html__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
273 273
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
@@ -294,11 +294,11 @@  discard block
 block discarded – undo
294 294
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
295 295
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
296 296
         $parent_folder = EEH_File::get_parent_folder($full_file_path);
297
-        if (! EEH_File::exists($full_file_path)) {
298
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
297
+        if ( ! EEH_File::exists($full_file_path)) {
298
+            if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
299 299
                 return false;
300 300
             }
301
-            if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
301
+            if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
302 302
                 if (defined('WP_DEBUG') && WP_DEBUG) {
303 303
                     $msg = sprintf(esc_html__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
304 304
                     $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
                 return false;
308 308
             }
309 309
         }
310
-        if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
310
+        if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
311 311
             return false;
312 312
         }
313 313
         return true;
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
     public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
367 367
     {
368 368
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
369
-        $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
369
+        $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
370 370
         $folder = EEH_File::remove_filename_from_filepath($full_file_path);
371
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
371
+        if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
372 372
             if (defined('WP_DEBUG') && WP_DEBUG) {
373 373
                 $msg = sprintf(esc_html__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
374 374
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
         // load WP_Filesystem and set file permissions
380 380
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
381 381
         // write the file
382
-        if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
382
+        if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
383 383
             if (defined('WP_DEBUG') && WP_DEBUG) {
384 384
                 $msg = sprintf(esc_html__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
385 385
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
     public static function add_htaccess_deny_from_all($folder = '')
490 490
     {
491 491
         $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
492
-        if (! EEH_File::exists($folder . '.htaccess')) {
493
-            if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
492
+        if ( ! EEH_File::exists($folder.'.htaccess')) {
493
+            if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
494 494
                 return false;
495 495
             }
496 496
         }
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
     public static function add_index_file($folder)
508 508
     {
509 509
         $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
510
-        if (! EEH_File::exists($folder . 'index.php')) {
511
-            if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
510
+        if ( ! EEH_File::exists($folder.'index.php')) {
511
+            if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
512 512
                 return false;
513 513
             }
514 514
         }
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
      */
543 543
     public static function standardise_directory_separators($file_path)
544 544
     {
545
-        return str_replace(array( '\\', '/' ), '/', $file_path);
545
+        return str_replace(array('\\', '/'), '/', $file_path);
546 546
     }
547 547
 
548 548
 
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
      */
556 556
     public static function end_with_directory_separator($file_path)
557 557
     {
558
-        return rtrim($file_path, '/\\') . '/';
558
+        return rtrim($file_path, '/\\').'/';
559 559
     }
560 560
 
561 561
 
@@ -590,17 +590,17 @@  discard block
 block discarded – undo
590 590
         foreach ($folder_paths as $folder_path) {
591 591
             $folder_path = self::standardise_and_end_with_directory_separator($folder_path);
592 592
             // load WP_Filesystem and set file permissions
593
-            $files_in_folder = glob($folder_path . '*.php');
593
+            $files_in_folder = glob($folder_path.'*.php');
594 594
             $class_to_folder_path = array();
595 595
             if ($files_in_folder) {
596 596
                 foreach ($files_in_folder as $file_path) {
597 597
                     // only add files, not folders
598
-                    if (! is_dir($file_path)) {
598
+                    if ( ! is_dir($file_path)) {
599 599
                         if ($index_numerically) {
600 600
                             $class_to_folder_path[] = $file_path;
601 601
                         } else {
602 602
                             $classname = self::get_classname_from_filepath_with_standard_filename($file_path);
603
-                            $class_to_folder_path[ $classname ] = $file_path;
603
+                            $class_to_folder_path[$classname] = $file_path;
604 604
                         }
605 605
                     }
606 606
                 }
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
     public static function copy($source_file, $destination_file, $overwrite = false)
623 623
     {
624 624
         $full_source_path = EEH_File::standardise_directory_separators($source_file);
625
-        if (! EEH_File::exists($full_source_path)) {
625
+        if ( ! EEH_File::exists($full_source_path)) {
626 626
             if (defined('WP_DEBUG') && WP_DEBUG) {
627 627
                 $msg = sprintf(esc_html__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
628 628
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
         $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
635 635
         $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
636 636
         EEH_File::ensure_folder_exists_and_is_writable($folder);
637
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
637
+        if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
638 638
             if (defined('WP_DEBUG') && WP_DEBUG) {
639 639
                 $msg = sprintf(esc_html__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
640 640
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
@@ -689,6 +689,6 @@  discard block
 block discarded – undo
689 689
     public static function convert_local_filepath_to_remote_filepath($local_filepath)
690 690
     {
691 691
         $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
692
-        return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath);
692
+        return str_replace(WP_CONTENT_DIR.'/', $wp_filesystem->wp_content_dir(), $local_filepath);
693 693
     }
694 694
 }
Please login to merge, or discard this patch.
core/Factory.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -18,32 +18,32 @@
 block discarded – undo
18 18
 class Factory
19 19
 {
20 20
 
21
-    /**
22
-     * @param string $class_name
23
-     * @param array  $arguments
24
-     * @return mixed|null
25
-     * @throws EE_Error
26
-     */
27
-    public static function create($class_name, $arguments = array())
28
-    {
29
-        if (empty($class_name)) {
30
-            throw new EE_Error(
31
-                esc_html__('You must provide a class name in order to instantiate it.', 'event_espresso')
32
-            );
33
-        }
34
-        switch ($class_name) {
35
-            case 'Request':
36
-            case 'EE_Request':
37
-                $object = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
38
-                break;
39
-            case 'Iframe':
40
-                $title = isset($arguments['title']) ? $arguments['title'] : null;
41
-                $content = isset($arguments['content']) ? $arguments['content'] : null;
42
-                $object = new Iframe($title, $content);
43
-                break;
44
-            default:
45
-                $object = new $class_name($arguments);
46
-        }
47
-        return $object;
48
-    }
21
+	/**
22
+	 * @param string $class_name
23
+	 * @param array  $arguments
24
+	 * @return mixed|null
25
+	 * @throws EE_Error
26
+	 */
27
+	public static function create($class_name, $arguments = array())
28
+	{
29
+		if (empty($class_name)) {
30
+			throw new EE_Error(
31
+				esc_html__('You must provide a class name in order to instantiate it.', 'event_espresso')
32
+			);
33
+		}
34
+		switch ($class_name) {
35
+			case 'Request':
36
+			case 'EE_Request':
37
+				$object = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
38
+				break;
39
+			case 'Iframe':
40
+				$title = isset($arguments['title']) ? $arguments['title'] : null;
41
+				$content = isset($arguments['content']) ? $arguments['content'] : null;
42
+				$object = new Iframe($title, $content);
43
+				break;
44
+			default:
45
+				$object = new $class_name($arguments);
46
+		}
47
+		return $object;
48
+	}
49 49
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidFilePathException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,27 +15,27 @@
 block discarded – undo
15 15
 class InvalidFilePathException extends InvalidArgumentException
16 16
 {
17 17
 
18
-    /**
19
-     * InvalidClassException constructor.
20
-     *
21
-     * @param string     $file_path
22
-     * @param string     $message
23
-     * @param int        $code
24
-     * @param \Exception $previous
25
-     */
26
-    public function __construct($file_path, $message = '', $code = 0, \Exception $previous = null)
27
-    {
28
-        if (empty($message)) {
29
-            $message = sprintf(
30
-                esc_html__(
31
-                    'The "%1$s" file is either missing or could not be read due to permissions. Please ensure that the following path is correct and verify that the file permissions are correct:%2$s %3$s',
32
-                    'event_espresso'
33
-                ),
34
-                basename($file_path),
35
-                '<br />',
36
-                $file_path
37
-            );
38
-        }
39
-        parent::__construct($message, $code, $previous);
40
-    }
18
+	/**
19
+	 * InvalidClassException constructor.
20
+	 *
21
+	 * @param string     $file_path
22
+	 * @param string     $message
23
+	 * @param int        $code
24
+	 * @param \Exception $previous
25
+	 */
26
+	public function __construct($file_path, $message = '', $code = 0, \Exception $previous = null)
27
+	{
28
+		if (empty($message)) {
29
+			$message = sprintf(
30
+				esc_html__(
31
+					'The "%1$s" file is either missing or could not be read due to permissions. Please ensure that the following path is correct and verify that the file permissions are correct:%2$s %3$s',
32
+					'event_espresso'
33
+				),
34
+				basename($file_path),
35
+				'<br />',
36
+				$file_path
37
+			);
38
+		}
39
+		parent::__construct($message, $code, $previous);
40
+	}
41 41
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidStatusException.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@
 block discarded – undo
7 7
 
8 8
 class InvalidStatusException extends InvalidArgumentException
9 9
 {
10
-    /**
11
-     * InvalidStatusException constructor.
12
-     * @param string $status the invalid status id that was supplied
13
-     * @param string $domain the name of the domain, model, or class that the status belongs to
14
-     * @param string $message custom message
15
-     * @param int $code
16
-     * @param Exception|null $previous
17
-     */
18
-    public function __construct($status, $domain, $message = '', $code = 0, Exception $previous = null)
19
-    {
20
-        if (empty($message)) {
21
-            $message = sprintf(
22
-                esc_html__(
23
-                    '"%1$s" is not a valid %2$s status',
24
-                    'event_espresso'
25
-                ),
26
-                $status,
27
-                $domain
28
-            );
29
-        }
30
-        parent::__construct($message, $code, $previous);
31
-    }
10
+	/**
11
+	 * InvalidStatusException constructor.
12
+	 * @param string $status the invalid status id that was supplied
13
+	 * @param string $domain the name of the domain, model, or class that the status belongs to
14
+	 * @param string $message custom message
15
+	 * @param int $code
16
+	 * @param Exception|null $previous
17
+	 */
18
+	public function __construct($status, $domain, $message = '', $code = 0, Exception $previous = null)
19
+	{
20
+		if (empty($message)) {
21
+			$message = sprintf(
22
+				esc_html__(
23
+					'"%1$s" is not a valid %2$s status',
24
+					'event_espresso'
25
+				),
26
+				$status,
27
+				$domain
28
+			);
29
+		}
30
+		parent::__construct($message, $code, $previous);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidIdentifierException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,28 +16,28 @@
 block discarded – undo
16 16
 class InvalidIdentifierException extends InvalidArgumentException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidIdentifierException constructor.
21
-     *
22
-     * @param string     $actual   the identifier that was supplied
23
-     * @param string     $expected example of an acceptable identifier
24
-     * @param string     $message
25
-     * @param int        $code
26
-     * @param Exception $previous
27
-     */
28
-    public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null)
29
-    {
30
-        if (empty($message)) {
31
-            $message = sprintf(
32
-                esc_html__(
33
-                    'The supplied identifier "%1$s" is invalid. A value like "%2$s" was expected.',
34
-                    'event_espresso'
35
-                ),
36
-                $actual,
37
-                $expected
38
-            );
39
-        }
40
-        parent::__construct($message, $code, $previous);
41
-    }
19
+	/**
20
+	 * InvalidIdentifierException constructor.
21
+	 *
22
+	 * @param string     $actual   the identifier that was supplied
23
+	 * @param string     $expected example of an acceptable identifier
24
+	 * @param string     $message
25
+	 * @param int        $code
26
+	 * @param Exception $previous
27
+	 */
28
+	public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null)
29
+	{
30
+		if (empty($message)) {
31
+			$message = sprintf(
32
+				esc_html__(
33
+					'The supplied identifier "%1$s" is invalid. A value like "%2$s" was expected.',
34
+					'event_espresso'
35
+				),
36
+				$actual,
37
+				$expected
38
+			);
39
+		}
40
+		parent::__construct($message, $code, $previous);
41
+	}
42 42
 }
43 43
 // Location: core/exceptions/InvalidIdentifierException.php
Please login to merge, or discard this patch.
core/exceptions/InvalidDataTypeException.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,46 +16,46 @@
 block discarded – undo
16 16
 class InvalidDataTypeException extends InvalidArgumentException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidDataTypeException constructor
21
-     *
22
-     * @param string    $var_name  name of the variable that was of the wrong type ie: "$my_var"
23
-     * @param mixed     $variable  the actual variable that was of the wrong data type, ie: $my_var
24
-     * @param string    $expected  data type we wanted ie: "integer", "string", "array", etc.
25
-     *                             or an entire rewrite of: "{something something} was expected."
26
-     * @param string    $message
27
-     * @param int       $code
28
-     * @param Exception $previous
29
-     */
30
-    public function __construct($var_name, $variable, $expected, $message = '', $code = 0, Exception $previous = null)
31
-    {
32
-        if (empty($message)) {
33
-            $expected = strpos(' was expected.', $expected) === false
34
-                ? $this->addIndefiniteArticle($expected) . ' was expected.'
35
-                : $expected;
36
-            $message = sprintf(
37
-                esc_html__(
38
-                    'The supplied data for "%1$s" was %2$s, but %3$s',
39
-                    'event_espresso'
40
-                ),
41
-                $var_name,
42
-                $this->addIndefiniteArticle(gettype($variable)),
43
-                $expected
44
-            );
45
-        }
46
-        parent::__construct($message, $code, $previous);
47
-    }
19
+	/**
20
+	 * InvalidDataTypeException constructor
21
+	 *
22
+	 * @param string    $var_name  name of the variable that was of the wrong type ie: "$my_var"
23
+	 * @param mixed     $variable  the actual variable that was of the wrong data type, ie: $my_var
24
+	 * @param string    $expected  data type we wanted ie: "integer", "string", "array", etc.
25
+	 *                             or an entire rewrite of: "{something something} was expected."
26
+	 * @param string    $message
27
+	 * @param int       $code
28
+	 * @param Exception $previous
29
+	 */
30
+	public function __construct($var_name, $variable, $expected, $message = '', $code = 0, Exception $previous = null)
31
+	{
32
+		if (empty($message)) {
33
+			$expected = strpos(' was expected.', $expected) === false
34
+				? $this->addIndefiniteArticle($expected) . ' was expected.'
35
+				: $expected;
36
+			$message = sprintf(
37
+				esc_html__(
38
+					'The supplied data for "%1$s" was %2$s, but %3$s',
39
+					'event_espresso'
40
+				),
41
+				$var_name,
42
+				$this->addIndefiniteArticle(gettype($variable)),
43
+				$expected
44
+			);
45
+		}
46
+		parent::__construct($message, $code, $previous);
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * @param $string
52
-     * @return string
53
-     */
54
-    protected function addIndefiniteArticle($string)
55
-    {
56
-        if (strtolower($string) === 'null') {
57
-            return $string;
58
-        }
59
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
60
-    }
50
+	/**
51
+	 * @param $string
52
+	 * @return string
53
+	 */
54
+	protected function addIndefiniteArticle($string)
55
+	{
56
+		if (strtolower($string) === 'null') {
57
+			return $string;
58
+		}
59
+		return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     {
32 32
         if (empty($message)) {
33 33
             $expected = strpos(' was expected.', $expected) === false
34
-                ? $this->addIndefiniteArticle($expected) . ' was expected.'
34
+                ? $this->addIndefiniteArticle($expected).' was expected.'
35 35
                 : $expected;
36 36
             $message = sprintf(
37 37
                 esc_html__(
@@ -56,6 +56,6 @@  discard block
 block discarded – undo
56 56
         if (strtolower($string) === 'null') {
57 57
             return $string;
58 58
         }
59
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
59
+        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string;
60 60
     }
61 61
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidClassException.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
15 15
 class InvalidClassException extends DomainException
16 16
 {
17 17
 
18
-    /**
19
-     * InvalidClassException constructor.
20
-     *
21
-     * @param string     $class_name
22
-     * @param string     $message
23
-     * @param int        $code
24
-     * @param \Exception $previous
25
-     */
26
-    public function __construct($class_name, $message = '', $code = 0, \Exception $previous = null)
27
-    {
28
-        if (empty($message)) {
29
-            $message = sprintf(
30
-                esc_html__('The "%1$s" Class is either missing or invalid.', 'event_espresso'),
31
-                $class_name
32
-            );
33
-        }
34
-        parent::__construct($message, $code, $previous);
35
-    }
18
+	/**
19
+	 * InvalidClassException constructor.
20
+	 *
21
+	 * @param string     $class_name
22
+	 * @param string     $message
23
+	 * @param int        $code
24
+	 * @param \Exception $previous
25
+	 */
26
+	public function __construct($class_name, $message = '', $code = 0, \Exception $previous = null)
27
+	{
28
+		if (empty($message)) {
29
+			$message = sprintf(
30
+				esc_html__('The "%1$s" Class is either missing or invalid.', 'event_espresso'),
31
+				$class_name
32
+			);
33
+		}
34
+		parent::__construct($message, $code, $previous);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidEntityException.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -16,33 +16,33 @@
 block discarded – undo
16 16
 class InvalidEntityException extends InvalidArgumentException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidEntityException constructor.
21
-     *
22
-     * @param mixed     $actual   the actual object (or thing) we got
23
-     * @param string    $expected classname of the entity we wanted
24
-     * @param string    $message
25
-     * @param int       $code
26
-     * @param Exception $previous
27
-     */
28
-    public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null)
29
-    {
30
-        if (empty($message)) {
31
-            ob_start();
32
-            var_dump($actual);
33
-            $object = ob_get_clean();
34
-            $message = sprintf(
35
-                esc_html__(
36
-                    'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s',
37
-                    'event_espresso'
38
-                ),
39
-                is_object($actual)
40
-                    ? get_class($actual)
41
-                    : gettype($actual),
42
-                $expected,
43
-                $object
44
-            );
45
-        }
46
-        parent::__construct($message, $code, $previous);
47
-    }
19
+	/**
20
+	 * InvalidEntityException constructor.
21
+	 *
22
+	 * @param mixed     $actual   the actual object (or thing) we got
23
+	 * @param string    $expected classname of the entity we wanted
24
+	 * @param string    $message
25
+	 * @param int       $code
26
+	 * @param Exception $previous
27
+	 */
28
+	public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null)
29
+	{
30
+		if (empty($message)) {
31
+			ob_start();
32
+			var_dump($actual);
33
+			$object = ob_get_clean();
34
+			$message = sprintf(
35
+				esc_html__(
36
+					'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s',
37
+					'event_espresso'
38
+				),
39
+				is_object($actual)
40
+					? get_class($actual)
41
+					: gettype($actual),
42
+				$expected,
43
+				$object
44
+			);
45
+		}
46
+		parent::__construct($message, $code, $previous);
47
+	}
48 48
 }
Please login to merge, or discard this patch.