| @@ -62,72 +62,64 @@ | ||
| 62 | 62 | |
| 63 | 63 | /* Scripts and styles including. |
| 64 | 64 | --------------------------------------------------------------------------------------------*/ |
| 65 | 65 | |
| 66 | - if ( ! function_exists( 'fs_asset_url' ) ) { | |
| 67 | - /** | |
| 68 | - * Generates an absolute URL to the given path. This function ensures that the URL will be correct whether the asset | |
| 69 | - * is inside a plugin's folder or a theme's folder. | |
| 70 | - * | |
| 71 | - * Examples: | |
| 72 | - * 1. "themes" folder | |
| 73 | - * Path: C:/xampp/htdocs/fswp/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css | |
| 74 | - * URL: http://fswp:8080/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css | |
| 75 | - * | |
| 76 | - * 2. "plugins" folder | |
| 77 | - * Path: C:/xampp/htdocs/fswp/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css | |
| 78 | - * URL: http://fswp:8080/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css | |
| 79 | - * | |
| 80 | - * @author Leo Fajardo (@leorw) | |
| 81 | - * @since 1.2.2 | |
| 82 | - * | |
| 83 | - * @param string $asset_abs_path Asset's absolute path. | |
| 84 | - * | |
| 85 | - * @return string Asset's URL. | |
| 86 | - */ | |
| 87 | - function fs_asset_url( $asset_abs_path ) { | |
| 88 | - $wp_content_dir = fs_normalize_path( WP_CONTENT_DIR ); | |
| 89 | - $asset_abs_path = fs_normalize_path( $asset_abs_path ); | |
| 66 | + /** | |
| 67 | + * Generates an absolute URL to the given path. This function ensures that the URL will be correct whether the asset | |
| 68 | + * is inside a plugin's folder or a theme's folder. | |
| 69 | + * | |
| 70 | + * Examples: | |
| 71 | + * 1. "themes" folder | |
| 72 | + * Path: C:/xampp/htdocs/fswp/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css | |
| 73 | + * URL: http://fswp:8080/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css | |
| 74 | + * | |
| 75 | + * 2. "plugins" folder | |
| 76 | + * Path: C:/xampp/htdocs/fswp/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css | |
| 77 | + * URL: http://fswp:8080/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css | |
| 78 | + * | |
| 79 | + * @author Leo Fajardo (@leorw) | |
| 80 | + * @since 1.2.2 | |
| 81 | + * | |
| 82 | + * @param string $asset_abs_path Asset's absolute path. | |
| 83 | + * | |
| 84 | + * @return string Asset's URL. | |
| 85 | + */ | |
| 86 | + function fs_asset_url( $asset_abs_path ) { | |
| 87 | + $wp_content_dir = fs_normalize_path( WP_CONTENT_DIR ); | |
| 88 | + $asset_abs_path = fs_normalize_path( $asset_abs_path ); | |
| 90 | 89 | |
| 91 | - if ( 0 === strpos( $asset_abs_path, $wp_content_dir ) ) { | |
| 92 | - // Handle both theme and plugin assets located in the standard directories. | |
| 93 | - $asset_rel_path = str_replace( $wp_content_dir, '', $asset_abs_path ); | |
| 94 | - $asset_url = content_url( fs_normalize_path( $asset_rel_path ) ); | |
| 90 | + if ( 0 === strpos( $asset_abs_path, $wp_content_dir ) ) { | |
| 91 | + // Handle both theme and plugin assets located in the standard directories. | |
| 92 | + $asset_rel_path = str_replace( $wp_content_dir, '', $asset_abs_path ); | |
| 93 | + $asset_url = content_url( fs_normalize_path( $asset_rel_path ) ); | |
| 94 | + } else { | |
| 95 | + $wp_plugins_dir = fs_normalize_path( WP_PLUGIN_DIR ); | |
| 96 | + if ( 0 === strpos( $asset_abs_path, $wp_plugins_dir ) ) { | |
| 97 | + // Try to handle plugin assets that may be located in a non-standard plugins directory. | |
| 98 | + $asset_rel_path = str_replace( $wp_plugins_dir, '', $asset_abs_path ); | |
| 99 | + $asset_url = plugins_url( fs_normalize_path( $asset_rel_path ) ); | |
| 95 | 100 | } else { |
| 96 | - $wp_plugins_dir = fs_normalize_path( WP_PLUGIN_DIR ); | |
| 97 | - if ( 0 === strpos( $asset_abs_path, $wp_plugins_dir ) ) { | |
| 98 | - // Try to handle plugin assets that may be located in a non-standard plugins directory. | |
| 99 | - $asset_rel_path = str_replace( $wp_plugins_dir, '', $asset_abs_path ); | |
| 100 | - $asset_url = plugins_url( fs_normalize_path( $asset_rel_path ) ); | |
| 101 | - } else { | |
| 102 | - // Try to handle theme assets that may be located in a non-standard themes directory. | |
| 103 | - $active_theme_stylesheet = get_stylesheet(); | |
| 104 | - $wp_themes_dir = fs_normalize_path( trailingslashit( get_theme_root( $active_theme_stylesheet ) ) ); | |
| 105 | - $asset_rel_path = str_replace( $wp_themes_dir, '', fs_normalize_path( $asset_abs_path ) ); | |
| 106 | - $asset_url = trailingslashit( get_theme_root_uri( $active_theme_stylesheet ) ) . fs_normalize_path( $asset_rel_path ); | |
| 107 | - } | |
| 101 | + // Try to handle theme assets that may be located in a non-standard themes directory. | |
| 102 | + $active_theme_stylesheet = get_stylesheet(); | |
| 103 | + $wp_themes_dir = fs_normalize_path( trailingslashit( get_theme_root( $active_theme_stylesheet ) ) ); | |
| 104 | + $asset_rel_path = str_replace( $wp_themes_dir, '', fs_normalize_path( $asset_abs_path ) ); | |
| 105 | + $asset_url = trailingslashit( get_theme_root_uri( $active_theme_stylesheet ) ) . fs_normalize_path( $asset_rel_path ); | |
| 108 | 106 | } |
| 107 | + } | |
| 109 | 108 | |
| 110 | - return $asset_url; | |
| 111 | - } | |
| 109 | + return $asset_url; | |
| 112 | 110 | } |
| 113 | 111 | |
| 114 | - if ( ! function_exists( 'fs_enqueue_local_style' ) ) { | |
| 115 | - function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) { | |
| 116 | - wp_enqueue_style( $handle, fs_asset_url( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ), $deps, $ver, $media ); | |
| 117 | - } | |
| 112 | + function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) { | |
| 113 | + wp_enqueue_style( $handle, fs_asset_url( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ), $deps, $ver, $media ); | |
| 118 | 114 | } |
| 119 | 115 | |
| 120 | - if ( ! function_exists( 'fs_enqueue_local_script' ) ) { | |
| 121 | - function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = true ) { | |
| 122 | - wp_enqueue_script( $handle, fs_asset_url( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ), $deps, $ver, $in_footer ); | |
| 123 | - } | |
| 116 | + function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) { | |
| 117 | + wp_enqueue_script( $handle, fs_asset_url( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ), $deps, $ver, $in_footer ); | |
| 124 | 118 | } |
| 125 | 119 | |
| 126 | - if ( ! function_exists( 'fs_img_url' ) ) { | |
| 127 | - function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) { | |
| 128 | - return ( fs_asset_url( $img_dir . '/' . trim( $path, '/' ) ) ); | |
| 129 | - } | |
| 120 | + function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) { | |
| 121 | + return ( fs_asset_url( $img_dir . '/' . trim( $path, '/' ) ) ); | |
| 130 | 122 | } |
| 131 | 123 | |
| 132 | 124 | #-------------------------------------------------------------------------------- |
| 133 | 125 | #region Request handlers. |
| @@ -132,141 +124,57 @@ | ||
| 132 | 124 | #-------------------------------------------------------------------------------- |
| 133 | 125 | #region Request handlers. |
| 134 | 126 | #-------------------------------------------------------------------------------- |
| 135 | 127 | |
| 136 | - if ( ! function_exists( 'fs_request_get_raw' ) ) { | |
| 128 | + if ( ! function_exists( 'fs_request_get' ) ) { | |
| 137 | 129 | /** |
| 138 | - * A helper function to fetch GET/POST user input with an optional default value when the input is not set. | |
| 139 | - * This function does not do sanitization. It is up to the caller to properly sanitize and validate the input. | |
| 140 | - * | |
| 141 | - * The return of this function is always unslashed. | |
| 142 | - * | |
| 143 | - * @since 2.5.10 | |
| 144 | - * | |
| 145 | 130 | * @param string $key |
| 146 | 131 | * @param mixed $def |
| 147 | - * @param string|bool $type When set to 'get', it will look for the value passed via query string. When | |
| 148 | - * set to 'post', it will look for the value passed via the POST request's body. Otherwise, | |
| 149 | - * it will check if the parameter was passed using any of the mentioned two methods. | |
| 132 | + * @param string|bool $type Since 1.2.1.7 - when set to 'get' will look for the value passed via querystring, when | |
| 133 | + * set to 'post' will look for the value passed via the POST request's body, otherwise, | |
| 134 | + * will check if the parameter was passed in any of the two. | |
| 150 | 135 | * |
| 151 | 136 | * @return mixed |
| 152 | 137 | */ |
| 153 | - function fs_request_get_raw( $key, $def = false, $type = false ) { | |
| 138 | + function fs_request_get( $key, $def = false, $type = false ) { | |
| 154 | 139 | if ( is_string( $type ) ) { |
| 155 | 140 | $type = strtolower( $type ); |
| 156 | 141 | } |
| 157 | 142 | |
| 158 | - /** | |
| 159 | - * Note to WordPress.org reviewers: | |
| 160 | - * This is a helper function to fetch GET/POST user input with an optional default value when the input is not set. The actual sanitization is done in the scope of the function's usage. | |
| 161 | - */ | |
| 162 | 143 | switch ( $type ) { |
| 163 | 144 | case 'post': |
| 164 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 165 | 145 | $value = isset( $_POST[ $key ] ) ? $_POST[ $key ] : $def; |
| 166 | 146 | break; |
| 167 | 147 | case 'get': |
| 168 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 169 | 148 | $value = isset( $_GET[ $key ] ) ? $_GET[ $key ] : $def; |
| 170 | 149 | break; |
| 171 | 150 | default: |
| 172 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 173 | 151 | $value = isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def; |
| 174 | 152 | break; |
| 175 | 153 | } |
| 176 | 154 | |
| 177 | - // Don't unslash if the value itself is empty (empty string, null, empty array etc). | |
| 178 | - return empty( $value ) ? $value : wp_unslash( $value ); | |
| 155 | + return $value; | |
| 179 | 156 | } |
| 180 | 157 | } |
| 181 | 158 | |
| 182 | - if ( ! function_exists( 'fs_sanitize_input' ) ) { | |
| 183 | - /** | |
| 184 | - * Sanitizes input recursively (if an array). | |
| 185 | - * | |
| 186 | - * @param mixed $input | |
| 187 | - * | |
| 188 | - * @return mixed | |
| 189 | - * @uses sanitize_text_field() | |
| 190 | - * @since 2.5.10 | |
| 191 | - */ | |
| 192 | - function fs_sanitize_input( $input ) { | |
| 193 | - if ( is_array( $input ) ) { | |
| 194 | - foreach ( $input as $key => $value ) { | |
| 195 | - $input[ $key ] = fs_sanitize_input( $value ); | |
| 196 | - } | |
| 197 | - } else { | |
| 198 | - // Allow empty values to pass through as-is, like `null`, `''`, `0`, `'0'` etc. | |
| 199 | - $input = empty( $input ) ? $input : sanitize_text_field( $input ); | |
| 200 | - } | |
| 201 | - | |
| 202 | - return $input; | |
| 203 | - } | |
| 204 | - } | |
| 205 | - | |
| 206 | - if ( ! function_exists( 'fs_request_get' ) ) { | |
| 207 | - /** | |
| 208 | - * A helper method to fetch GET/POST user input with an optional default value when the input is not set. | |
| 209 | - * | |
| 210 | - * @author Vova Feldman (@svovaf) | |
| 211 | - * | |
| 212 | - * @note The return value is always sanitized with sanitize_text_field(). | |
| 213 | - * | |
| 214 | - * @param string $key | |
| 215 | - * @param mixed $def | |
| 216 | - * @param string|bool $type Since 1.2.1.7 - when set to 'get' will look for the value passed via querystring, when | |
| 217 | - * set to 'post' will look for the value passed via the POST request's body, otherwise, | |
| 218 | - * will check if the parameter was passed in any of the two. | |
| 219 | - * | |
| 220 | - * | |
| 221 | - * @return mixed | |
| 222 | - */ | |
| 223 | - function fs_request_get( $key, $def = false, $type = false ) { | |
| 224 | - return fs_sanitize_input( fs_request_get_raw( $key, $def, $type ) ); | |
| 225 | - } | |
| 226 | - } | |
| 227 | - | |
| 228 | 159 | if ( ! function_exists( 'fs_request_has' ) ) { |
| 229 | 160 | function fs_request_has( $key ) { |
| 230 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 231 | 161 | return isset( $_REQUEST[ $key ] ); |
| 232 | 162 | } |
| 233 | 163 | } |
| 234 | 164 | |
| 235 | 165 | if ( ! function_exists( 'fs_request_get_bool' ) ) { |
| 236 | - /** | |
| 237 | - * A helper method to fetch GET/POST user boolean input with an optional default value when the input is not set. | |
| 238 | - * | |
| 239 | - * @author Vova Feldman (@svovaf) | |
| 240 | - * | |
| 241 | - * @param string $key | |
| 242 | - * @param bool $def | |
| 243 | - * | |
| 244 | - * @return bool|mixed | |
| 245 | - */ | |
| 246 | 166 | function fs_request_get_bool( $key, $def = false ) { |
| 247 | - $val = fs_request_get( $key, null ); | |
| 248 | - | |
| 249 | - if ( is_null( $val ) ) { | |
| 167 | + if ( ! isset( $_REQUEST[ $key ] ) ) { | |
| 250 | 168 | return $def; |
| 251 | 169 | } |
| 252 | 170 | |
| 253 | - if ( is_bool( $val ) ) { | |
| 254 | - return $val; | |
| 255 | - } else if ( is_numeric( $val ) ) { | |
| 256 | - if ( 1 == $val ) { | |
| 257 | - return true; | |
| 258 | - } else if ( 0 == $val ) { | |
| 259 | - return false; | |
| 260 | - } | |
| 261 | - } else if ( is_string( $val ) ) { | |
| 262 | - $val = strtolower( $val ); | |
| 171 | + if ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) { | |
| 172 | + return true; | |
| 173 | + } | |
| 263 | 174 | |
| 264 | - if ( 'true' === $val ) { | |
| 265 | - return true; | |
| 266 | - } else if ( 'false' === $val ) { | |
| 267 | - return false; | |
| 268 | - } | |
| 175 | + if ( 0 == $_REQUEST[ $key ] || 'false' === strtolower( $_REQUEST[ $key ] ) ) { | |
| 176 | + return false; | |
| 269 | 177 | } |
| 270 | 178 | |
| 271 | 179 | return $def; |
| 272 | 180 | } |
| @@ -285,9 +193,8 @@ | ||
| 285 | 193 | } |
| 286 | 194 | |
| 287 | 195 | if ( ! function_exists( 'fs_get_action' ) ) { |
| 288 | 196 | function fs_get_action( $action_key = 'action' ) { |
| 289 | - // phpcs:disable WordPress.Security.NonceVerification.Recommended | |
| 290 | 197 | if ( ! empty( $_REQUEST[ $action_key ] ) && is_string( $_REQUEST[ $action_key ] ) ) { |
| 291 | 198 | return strtolower( $_REQUEST[ $action_key ] ); |
| 292 | 199 | } |
| 293 | 200 | |
| @@ -299,9 +206,8 @@ | ||
| 299 | 206 | } |
| 300 | 207 | } |
| 301 | 208 | |
| 302 | 209 | return false; |
| 303 | - // phpcs:enable WordPress.Security.NonceVerification.Recommended | |
| 304 | 210 | } |
| 305 | 211 | } |
| 306 | 212 | |
| 307 | 213 | if ( ! function_exists( 'fs_request_is_action' ) ) { |
| @@ -379,194 +285,141 @@ | ||
| 379 | 285 | } |
| 380 | 286 | |
| 381 | 287 | /* Core UI. |
| 382 | 288 | --------------------------------------------------------------------------------------------*/ |
| 383 | - if ( ! function_exists( 'fs_ui_action_button' ) ) { | |
| 384 | - /** | |
| 385 | - * @param number $module_id | |
| 386 | - * @param string $page | |
| 387 | - * @param string $action | |
| 388 | - * @param string $title | |
| 389 | - * @param string $button_class | |
| 390 | - * @param array $params | |
| 391 | - * @param bool $is_primary | |
| 392 | - * @param bool $is_small | |
| 393 | - * @param string|bool $icon_class Optional class for an icon (since 1.1.7). | |
| 394 | - * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7). | |
| 395 | - * @param string $method Since 1.1.7 | |
| 396 | - * | |
| 397 | - * @uses fs_ui_get_action_button() | |
| 398 | - */ | |
| 399 | - function fs_ui_action_button( | |
| 289 | + /** | |
| 290 | + * @param number $module_id | |
| 291 | + * @param string $page | |
| 292 | + * @param string $action | |
| 293 | + * @param string $title | |
| 294 | + * @param string $button_class | |
| 295 | + * @param array $params | |
| 296 | + * @param bool $is_primary | |
| 297 | + * @param bool $is_small | |
| 298 | + * @param string|bool $icon_class Optional class for an icon (since 1.1.7). | |
| 299 | + * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7). | |
| 300 | + * @param string $method Since 1.1.7 | |
| 301 | + * | |
| 302 | + * @uses fs_ui_get_action_button() | |
| 303 | + */ | |
| 304 | + function fs_ui_action_button( | |
| 305 | + $module_id, | |
| 306 | + $page, | |
| 307 | + $action, | |
| 308 | + $title, | |
| 309 | + $button_class = '', | |
| 310 | + $params = array(), | |
| 311 | + $is_primary = true, | |
| 312 | + $is_small = false, | |
| 313 | + $icon_class = false, | |
| 314 | + $confirmation = false, | |
| 315 | + $method = 'GET' | |
| 316 | + ) { | |
| 317 | + echo fs_ui_get_action_button( | |
| 400 | 318 | $module_id, |
| 401 | 319 | $page, |
| 402 | 320 | $action, |
| 403 | 321 | $title, |
| 404 | - $button_class = '', | |
| 405 | - $params = array(), | |
| 406 | - $is_primary = true, | |
| 407 | - $is_small = false, | |
| 408 | - $icon_class = false, | |
| 409 | - $confirmation = false, | |
| 410 | - $method = 'GET' | |
| 411 | - ) { | |
| 412 | - echo fs_ui_get_action_button( | |
| 413 | - $module_id, | |
| 414 | - $page, | |
| 322 | + $button_class, | |
| 323 | + $params, | |
| 324 | + $is_primary, | |
| 325 | + $is_small, | |
| 326 | + $icon_class, | |
| 327 | + $confirmation, | |
| 328 | + $method | |
| 329 | + ); | |
| 330 | + } | |
| 331 | + | |
| 332 | + /** | |
| 333 | + * @author Vova Feldman (@svovaf) | |
| 334 | + * @since 1.1.7 | |
| 335 | + * | |
| 336 | + * @param number $module_id | |
| 337 | + * @param string $page | |
| 338 | + * @param string $action | |
| 339 | + * @param string $title | |
| 340 | + * @param string $button_class | |
| 341 | + * @param array $params | |
| 342 | + * @param bool $is_primary | |
| 343 | + * @param bool $is_small | |
| 344 | + * @param string|bool $icon_class Optional class for an icon. | |
| 345 | + * @param string|bool $confirmation Optional confirmation message before submit. | |
| 346 | + * @param string $method | |
| 347 | + * | |
| 348 | + * @return string | |
| 349 | + */ | |
| 350 | + function fs_ui_get_action_button( | |
| 351 | + $module_id, | |
| 352 | + $page, | |
| 353 | + $action, | |
| 354 | + $title, | |
| 355 | + $button_class = '', | |
| 356 | + $params = array(), | |
| 357 | + $is_primary = true, | |
| 358 | + $is_small = false, | |
| 359 | + $icon_class = false, | |
| 360 | + $confirmation = false, | |
| 361 | + $method = 'GET' | |
| 362 | + ) { | |
| 363 | + // Prepend icon (if set). | |
| 364 | + $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title; | |
| 365 | + | |
| 366 | + if ( is_string( $confirmation ) ) { | |
| 367 | + return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>', | |
| 368 | + freemius( $module_id )->_get_admin_page_url( $page, $params ), | |
| 369 | + $method, | |
| 415 | 370 | $action, |
| 416 | - $title, | |
| 417 | - $button_class, | |
| 418 | - $params, | |
| 419 | - $is_primary, | |
| 420 | - $is_small, | |
| 421 | - $icon_class, | |
| 371 | + wp_nonce_field( $action, '_wpnonce', true, false ), | |
| 372 | + 'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ), | |
| 422 | 373 | $confirmation, |
| 423 | - $method | |
| 374 | + $title | |
| 424 | 375 | ); |
| 376 | + } else if ( 'GET' !== strtoupper( $method ) ) { | |
| 377 | + return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>', | |
| 378 | + freemius( $module_id )->_get_admin_page_url( $page, $params ), | |
| 379 | + $method, | |
| 380 | + $action, | |
| 381 | + wp_nonce_field( $action, '_wpnonce', true, false ), | |
| 382 | + 'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ), | |
| 383 | + $title | |
| 384 | + ); | |
| 385 | + } else { | |
| 386 | + return sprintf( '<a href="%s" class="%s">%s</a></form>', | |
| 387 | + wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ), | |
| 388 | + 'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ), | |
| 389 | + $title | |
| 390 | + ); | |
| 425 | 391 | } |
| 426 | 392 | } |
| 427 | 393 | |
| 428 | - if ( ! function_exists( 'fs_ui_get_action_button' ) ) { | |
| 429 | - /** | |
| 430 | - * @author Vova Feldman (@svovaf) | |
| 431 | - * @since 1.1.7 | |
| 432 | - * | |
| 433 | - * @param number $module_id | |
| 434 | - * @param string $page | |
| 435 | - * @param string $action | |
| 436 | - * @param string $title | |
| 437 | - * @param string $button_class | |
| 438 | - * @param array $params | |
| 439 | - * @param bool $is_primary | |
| 440 | - * @param bool $is_small | |
| 441 | - * @param string|bool $icon_class Optional class for an icon. | |
| 442 | - * @param string|bool $confirmation Optional confirmation message before submit. | |
| 443 | - * @param string $method | |
| 444 | - * | |
| 445 | - * @return string | |
| 446 | - */ | |
| 447 | - function fs_ui_get_action_button( | |
| 448 | - $module_id, | |
| 449 | - $page, | |
| 450 | - $action, | |
| 451 | - $title, | |
| 452 | - $button_class = '', | |
| 453 | - $params = array(), | |
| 454 | - $is_primary = true, | |
| 455 | - $is_small = false, | |
| 456 | - $icon_class = false, | |
| 457 | - $confirmation = false, | |
| 458 | - $method = 'GET' | |
| 459 | - ) { | |
| 460 | - // Prepend icon (if set). | |
| 461 | - $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title; | |
| 394 | + function fs_ui_action_link( $module_id, $page, $action, $title, $params = array() ) { | |
| 395 | + ?><a class="" | |
| 396 | + href="<?php echo wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php | |
| 397 | + } | |
| 462 | 398 | |
| 463 | - if ( is_string( $confirmation ) ) { | |
| 464 | - return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>', | |
| 465 | - freemius( $module_id )->_get_admin_page_url( $page, $params ), | |
| 466 | - $method, | |
| 467 | - $action, | |
| 468 | - wp_nonce_field( $action, '_wpnonce', true, false ), | |
| 469 | - 'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ), | |
| 470 | - $confirmation, | |
| 471 | - $title | |
| 472 | - ); | |
| 473 | - } else if ( 'GET' !== strtoupper( $method ) ) { | |
| 474 | - return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>', | |
| 475 | - freemius( $module_id )->_get_admin_page_url( $page, $params ), | |
| 476 | - $method, | |
| 477 | - $action, | |
| 478 | - wp_nonce_field( $action, '_wpnonce', true, false ), | |
| 479 | - 'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ), | |
| 480 | - $title | |
| 481 | - ); | |
| 482 | - } else { | |
| 483 | - return sprintf( '<a href="%s" class="%s">%s</a></form>', | |
| 484 | - wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ), | |
| 485 | - 'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ), | |
| 486 | - $title | |
| 487 | - ); | |
| 488 | - } | |
| 399 | + /*function fs_error_handler($errno, $errstr, $errfile, $errline) | |
| 400 | + { | |
| 401 | + if (false === strpos($errfile, 'freemius/')) | |
| 402 | + { | |
| 403 | + // @todo Dump Freemius errors to local log. | |
| 489 | 404 | } |
| 490 | 405 | |
| 491 | - function fs_ui_action_link( $module_id, $page, $action, $title, $params = array() ) { | |
| 492 | - ?><a class="" | |
| 493 | - href="<?php echo wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php | |
| 494 | - } | |
| 406 | +// switch ($errno) { | |
| 407 | +// case E_USER_ERROR: | |
| 408 | +// break; | |
| 409 | +// case E_WARNING: | |
| 410 | +// case E_USER_WARNING: | |
| 411 | +// break; | |
| 412 | +// case E_NOTICE: | |
| 413 | +// case E_USER_NOTICE: | |
| 414 | +// break; | |
| 415 | +// default: | |
| 416 | +// break; | |
| 417 | +// } | |
| 495 | 418 | } |
| 496 | 419 | |
| 497 | - if ( ! function_exists( 'fs_get_entity' ) ) { | |
| 498 | - /** | |
| 499 | - * @author Leo Fajardo (@leorw) | |
| 500 | - * @since 2.3.1 | |
| 501 | - * | |
| 502 | - * @param mixed $entity | |
| 503 | - * @param string $class | |
| 504 | - * | |
| 505 | - * @return FS_Plugin|FS_User|FS_Site|FS_Plugin_License|FS_Plugin_Plan|FS_Plugin_Tag|FS_Subscription | |
| 506 | - */ | |
| 507 | - function fs_get_entity( $entity, $class ) { | |
| 508 | - if ( ! is_object( $entity ) || $entity instanceof $class ) { | |
| 509 | - return $entity; | |
| 510 | - } | |
| 420 | + set_error_handler('fs_error_handler');*/ | |
| 511 | 421 | |
| 512 | - return new $class( $entity ); | |
| 513 | - } | |
| 514 | - } | |
| 515 | - | |
| 516 | - if ( ! function_exists( 'fs_get_entities' ) ) { | |
| 517 | - /** | |
| 518 | - * @author Leo Fajardo (@leorw) | |
| 519 | - * @since 2.3.1 | |
| 520 | - * | |
| 521 | - * @param mixed $entities | |
| 522 | - * @param string $class_name | |
| 523 | - * | |
| 524 | - * @return FS_Plugin[]|FS_User[]|FS_Site[]|FS_Plugin_License[]|FS_Plugin_Plan[]|FS_Plugin_Tag[]|FS_Subscription[] | |
| 525 | - */ | |
| 526 | - function fs_get_entities( $entities, $class_name ) { | |
| 527 | - if ( ! is_array( $entities ) || empty( $entities ) ) { | |
| 528 | - return $entities; | |
| 529 | - } | |
| 530 | - | |
| 531 | - // Get first element. | |
| 532 | - $first_array_element = reset( $entities ); | |
| 533 | - | |
| 534 | - if ( $first_array_element instanceof $class_name ) { | |
| 535 | - /** | |
| 536 | - * If the first element of the array is an instance of the context class, assume that all other | |
| 537 | - * elements are instances of the class. | |
| 538 | - */ | |
| 539 | - return $entities; | |
| 540 | - } | |
| 541 | - | |
| 542 | - if ( | |
| 543 | - is_array( $first_array_element ) && | |
| 544 | - ! empty( $first_array_element ) | |
| 545 | - ) { | |
| 546 | - $first_array_element = reset( $first_array_element ); | |
| 547 | - | |
| 548 | - if ( $first_array_element instanceof $class_name ) { | |
| 549 | - /** | |
| 550 | - * If the first element of the `$entities` array is an array whose first element is an instance of the | |
| 551 | - * context class, assume that all other objects are instances of the class. | |
| 552 | - */ | |
| 553 | - return $entities; | |
| 554 | - } | |
| 555 | - } | |
| 556 | - | |
| 557 | - foreach ( $entities as $key => $entities_or_entity ) { | |
| 558 | - if ( is_array( $entities_or_entity ) ) { | |
| 559 | - $entities[ $key ] = fs_get_entities( $entities_or_entity, $class_name ); | |
| 560 | - } else { | |
| 561 | - $entities[ $key ] = fs_get_entity( $entities_or_entity, $class_name ); | |
| 562 | - } | |
| 563 | - } | |
| 564 | - | |
| 565 | - return $entities; | |
| 566 | - } | |
| 567 | - } | |
| 568 | - | |
| 569 | 422 | if ( ! function_exists( 'fs_nonce_url' ) ) { |
| 570 | 423 | /** |
| 571 | 424 | * Retrieve URL with nonce added to URL query. |
| 572 | 425 | * |
| @@ -587,35 +440,8 @@ | ||
| 587 | 440 | return add_query_arg( $name, wp_create_nonce( $action ), $actionurl ); |
| 588 | 441 | } |
| 589 | 442 | } |
| 590 | 443 | |
| 591 | - if ( ! function_exists( 'fs_parse_url_params' ) ) { | |
| 592 | - /** | |
| 593 | - * Returns the query parameters of the given URL if there are any. | |
| 594 | - * | |
| 595 | - * @param string $url | |
| 596 | - * @param bool $html_entity_decode | |
| 597 | - * | |
| 598 | - * @return array<string, string> Key value pair where key represents the parameter name and value represents the parameter value. | |
| 599 | - */ | |
| 600 | - function fs_parse_url_params( $url, $html_entity_decode = false ) { | |
| 601 | - $query_str = parse_url( $url, PHP_URL_QUERY ); | |
| 602 | - $url_params = array(); | |
| 603 | - | |
| 604 | - if ( empty( $query_str ) ) { | |
| 605 | - return $url_params; | |
| 606 | - } | |
| 607 | - | |
| 608 | - if ( $html_entity_decode ) { | |
| 609 | - $query_str = html_entity_decode( $query_str ); | |
| 610 | - } | |
| 611 | - | |
| 612 | - parse_str( $query_str, $url_params ); | |
| 613 | - | |
| 614 | - return $url_params; | |
| 615 | - } | |
| 616 | - } | |
| 617 | - | |
| 618 | 444 | if ( ! function_exists( 'fs_starts_with' ) ) { |
| 619 | 445 | /** |
| 620 | 446 | * Check if string starts with. |
| 621 | 447 | * |
| @@ -778,77 +604,73 @@ | ||
| 778 | 604 | } |
| 779 | 605 | |
| 780 | 606 | #endregion Url Canonization ------------------------------------------------------------------ |
| 781 | 607 | |
| 782 | - if ( ! function_exists( 'fs_download_image' ) ) { | |
| 783 | - /** | |
| 784 | - * @author Vova Feldman (@svovaf) | |
| 785 | - * | |
| 786 | - * @since 1.2.2 Changed to usage of WP_Filesystem_Direct. | |
| 787 | - * | |
| 788 | - * @param string $from URL | |
| 789 | - * @param string $to File path. | |
| 790 | - * | |
| 791 | - * @return bool Is successfully downloaded. | |
| 792 | - */ | |
| 793 | - function fs_download_image( $from, $to ) { | |
| 794 | - $dir = dirname( $to ); | |
| 608 | + /** | |
| 609 | + * @author Vova Feldman (@svovaf) | |
| 610 | + * | |
| 611 | + * @since 1.2.2 Changed to usage of WP_Filesystem_Direct. | |
| 612 | + * | |
| 613 | + * @param string $from URL | |
| 614 | + * @param string $to File path. | |
| 615 | + * | |
| 616 | + * @return bool Is successfully downloaded. | |
| 617 | + */ | |
| 618 | + function fs_download_image( $from, $to ) { | |
| 619 | + $dir = dirname( $to ); | |
| 795 | 620 | |
| 796 | - if ( 'direct' !== get_filesystem_method( array(), $dir ) ) { | |
| 797 | - return false; | |
| 798 | - } | |
| 621 | + if ( 'direct' !== get_filesystem_method( array(), $dir ) ) { | |
| 622 | + return false; | |
| 623 | + } | |
| 799 | 624 | |
| 800 | - if ( ! class_exists( 'WP_Filesystem_Direct' ) ) { | |
| 801 | - require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; | |
| 802 | - require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; | |
| 803 | - } | |
| 625 | + if ( ! class_exists( 'WP_Filesystem_Direct' ) ) { | |
| 626 | + require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; | |
| 627 | + require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; | |
| 628 | + } | |
| 804 | 629 | |
| 805 | - $fs = new WP_Filesystem_Direct( '' ); | |
| 806 | - $tmpfile = download_url( $from ); | |
| 630 | + $fs = new WP_Filesystem_Direct( '' ); | |
| 631 | + $tmpfile = download_url( $from ); | |
| 807 | 632 | |
| 808 | - if ( $tmpfile instanceof WP_Error ) { | |
| 809 | - // Issue downloading the file. | |
| 810 | - return false; | |
| 811 | - } | |
| 633 | + if ( $tmpfile instanceof WP_Error ) { | |
| 634 | + // Issue downloading the file. | |
| 635 | + return false; | |
| 636 | + } | |
| 812 | 637 | |
| 813 | - $fs->copy( $tmpfile, $to ); | |
| 814 | - $fs->delete( $tmpfile ); | |
| 638 | + $fs->copy( $tmpfile, $to ); | |
| 639 | + $fs->delete( $tmpfile ); | |
| 815 | 640 | |
| 816 | - return true; | |
| 817 | - } | |
| 641 | + return true; | |
| 818 | 642 | } |
| 819 | 643 | |
| 820 | 644 | /* General Utilities |
| 821 | 645 | --------------------------------------------------------------------------------------------*/ |
| 822 | 646 | |
| 823 | - if ( ! function_exists( 'fs_sort_by_priority' ) ) { | |
| 824 | - /** | |
| 825 | - * Sorts an array by the value of the priority key. | |
| 826 | - * | |
| 827 | - * @author Daniel Iser (@danieliser) | |
| 828 | - * @since 1.1.7 | |
| 829 | - * | |
| 830 | - * @param $a | |
| 831 | - * @param $b | |
| 832 | - * | |
| 833 | - * @return int | |
| 834 | - */ | |
| 835 | - function fs_sort_by_priority( $a, $b ) { | |
| 647 | + /** | |
| 648 | + * Sorts an array by the value of the priority key. | |
| 649 | + * | |
| 650 | + * @author Daniel Iser (@danieliser) | |
| 651 | + * @since 1.1.7 | |
| 652 | + * | |
| 653 | + * @param $a | |
| 654 | + * @param $b | |
| 655 | + * | |
| 656 | + * @return int | |
| 657 | + */ | |
| 658 | + function fs_sort_by_priority( $a, $b ) { | |
| 836 | 659 | |
| 837 | - // If b has a priority and a does not, b wins. | |
| 838 | - if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) { | |
| 839 | - return 1; | |
| 840 | - } // If b has a priority and a does not, b wins. | |
| 841 | - elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) { | |
| 842 | - return - 1; | |
| 843 | - } // If neither has a priority or both priorities are equal it's a tie. | |
| 844 | - elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) { | |
| 845 | - return 0; | |
| 846 | - } | |
| 660 | + // If b has a priority and a does not, b wins. | |
| 661 | + if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) { | |
| 662 | + return 1; | |
| 663 | + } // If b has a priority and a does not, b wins. | |
| 664 | + elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) { | |
| 665 | + return - 1; | |
| 666 | + } // If neither has a priority or both priorities are equal its a tie. | |
| 667 | + elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) { | |
| 668 | + return 0; | |
| 669 | + } | |
| 847 | 670 | |
| 848 | - // If both have priority return the winner. | |
| 849 | - return ( $a['priority'] < $b['priority'] ) ? - 1 : 1; | |
| 850 | - } | |
| 671 | + // If both have priority return the winner. | |
| 672 | + return ( $a['priority'] < $b['priority'] ) ? - 1 : 1; | |
| 851 | 673 | } |
| 852 | 674 | |
| 853 | 675 | #-------------------------------------------------------------------------------- |
| 854 | 676 | #region Localization |
| @@ -853,14 +675,8 @@ | ||
| 853 | 675 | #-------------------------------------------------------------------------------- |
| 854 | 676 | #region Localization |
| 855 | 677 | #-------------------------------------------------------------------------------- |
| 856 | 678 | |
| 857 | - global $fs_text_overrides; | |
| 858 | - | |
| 859 | - if ( ! isset( $fs_text_overrides ) ) { | |
| 860 | - $fs_text_overrides = array(); | |
| 861 | - } | |
| 862 | - | |
| 863 | 679 | if ( ! function_exists( 'fs_text' ) ) { |
| 864 | 680 | /** |
| 865 | 681 | * Retrieve a translated text by key. |
| 866 | 682 | * |
| @@ -871,12 +687,14 @@ | ||
| 871 | 687 | * @param string $slug |
| 872 | 688 | * |
| 873 | 689 | * @return string |
| 874 | 690 | * |
| 875 | - * @global $fs_text_overrides | |
| 691 | + * @global $fs_text , $fs_text_overrides | |
| 876 | 692 | */ |
| 877 | 693 | function fs_text( $key, $slug = 'freemius' ) { |
| 878 | - global $fs_text_overrides; | |
| 694 | + global $fs_text, | |
| 695 | + $fs_module_info_text, | |
| 696 | + $fs_text_overrides; | |
| 879 | 697 | |
| 880 | 698 | if ( isset( $fs_text_overrides[ $slug ] ) ) { |
| 881 | 699 | if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) { |
| 882 | 700 | return $fs_text_overrides[ $slug ][ $key ]; |
| @@ -887,8 +705,24 @@ | ||
| 887 | 705 | return $fs_text_overrides[ $slug ][ $lower_key ]; |
| 888 | 706 | } |
| 889 | 707 | } |
| 890 | 708 | |
| 709 | + if ( ! isset( $fs_text ) ) { | |
| 710 | + $dir = defined( 'WP_FS__DIR_INCLUDES' ) ? | |
| 711 | + WP_FS__DIR_INCLUDES : | |
| 712 | + dirname( __FILE__ ); | |
| 713 | + | |
| 714 | + require_once $dir . '/i18n.php'; | |
| 715 | + } | |
| 716 | + | |
| 717 | + if ( isset( $fs_text[ $key ] ) ) { | |
| 718 | + return $fs_text[ $key ]; | |
| 719 | + } | |
| 720 | + | |
| 721 | + if ( isset( $fs_module_info_text[ $key ] ) ) { | |
| 722 | + return $fs_module_info_text[ $key ]; | |
| 723 | + } | |
| 724 | + | |
| 891 | 725 | return $key; |
| 892 | 726 | } |
| 893 | 727 | |
| 894 | 728 | #region Private |
| @@ -1230,9 +1064,9 @@ | ||
| 1230 | 1064 | * @param string $context Context information for the translators. |
| 1231 | 1065 | * @param string $key String key for overrides. |
| 1232 | 1066 | * @param string $slug Module slug for overrides. |
| 1233 | 1067 | * |
| 1234 | - * @return void | |
| 1068 | + * @return string | |
| 1235 | 1069 | */ |
| 1236 | 1070 | function fs_esc_js_echo_x_inline( $text, $context, $key = '', $slug = 'freemius' ) { |
| 1237 | 1071 | echo esc_js( _fs_text_x_inline( $text, $context, $key, $slug ) ); |
| 1238 | 1072 | } |
| @@ -1420,9 +1254,9 @@ | ||
| 1420 | 1254 | */ |
| 1421 | 1255 | function fs_is_plugin_uninstall() { |
| 1422 | 1256 | return ( |
| 1423 | 1257 | defined( 'WP_UNINSTALL_PLUGIN' ) || |
| 1424 | - ( 0 < did_action( 'pre_uninstall_plugin' ) ) | |
| 1258 | + ( 0 < did_action( 'update_option_uninstall_plugins' ) ) | |
| 1425 | 1259 | ); |
| 1426 | 1260 | } |
| 1427 | 1261 | } |
| 1428 | 1262 | |
| @@ -1484,22 +1318,5 @@ | ||
| 1484 | 1318 | array( "fs_{$tag}_{$module_unique_affix}" ), |
| 1485 | 1319 | array_slice( $args, 2 ) ) |
| 1486 | 1320 | ); |
| 1487 | 1321 | } |
| 1488 | - } | |
| 1489 | - | |
| 1490 | - if ( ! function_exists( 'fs_get_optional_constant' ) ) { | |
| 1491 | - /** | |
| 1492 | - * Gets the value of an optional constant. If the constant is not defined, the default value will be returned. | |
| 1493 | - * | |
| 1494 | - * @author Swashata Ghosh (@swashata) | |
| 1495 | - * @since 2.5.12.5 | |
| 1496 | - * | |
| 1497 | - * @param string $constant_name | |
| 1498 | - * @param mixed $default_value | |
| 1499 | - * | |
| 1500 | - * @return mixed | |
| 1501 | - */ | |
| 1502 | - function fs_get_optional_constant( $constant_name, $default_value = null ) { | |
| 1503 | - return defined( $constant_name ) ? constant( $constant_name ) : $default_value; | |
| 1504 | - } | |
| 1505 | - } | |
| 1322 | + } | |