| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package Freemius |
| 4 | 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | |
| 5 | + * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 | |
| 6 | 6 | * @since 1.0.3 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -31,8 +31,11 @@ | ||
| 31 | 31 | * @var int ABSPATH length. |
| 32 | 32 | */ |
| 33 | 33 | private static $_abspathLength; |
| 34 | 34 | |
| 35 | + /** | |
| 36 | + * @var FS_Logger[] $LOGGERS | |
| 37 | + */ | |
| 35 | 38 | private static $LOGGERS = array(); |
| 36 | 39 | private static $LOG = array(); |
| 37 | 40 | private static $CNT = 0; |
| 38 | 41 | private static $_HOOKED_FOOTER = false; |
| @@ -37,11 +40,12 @@ | ||
| 37 | 40 | private static $CNT = 0; |
| 38 | 41 | private static $_HOOKED_FOOTER = false; |
| 39 | 42 | |
| 40 | 43 | private function __construct( $id, $on = false, $echo = false ) { |
| 44 | + $bt = debug_backtrace(); | |
| 45 | + | |
| 41 | 46 | $this->_id = $id; |
| 42 | 47 | |
| 43 | - $bt = debug_backtrace(); | |
| 44 | 48 | $caller = $bt[2]; |
| 45 | 49 | |
| 46 | 50 | if ( false !== strpos( $caller['file'], 'plugins' ) ) { |
| 47 | 51 | $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' ); |
| @@ -122,9 +126,8 @@ | ||
| 122 | 126 | } |
| 123 | 127 | |
| 124 | 128 | self::hook_footer(); |
| 125 | 129 | } |
| 126 | - | |
| 127 | 130 | function echo_on() { |
| 128 | 131 | $this->on(); |
| 129 | 132 | |
| 130 | 133 | $this->_echo = true; |
| @@ -141,9 +144,9 @@ | ||
| 141 | 144 | function get_file() { |
| 142 | 145 | return $this->_file_start; |
| 143 | 146 | } |
| 144 | 147 | |
| 145 | - private function _log( &$message, $type = 'log', $wrapper ) { | |
| 148 | + private function _log( &$message, $type, $wrapper = false ) { | |
| 146 | 149 | if ( ! $this->is_on() ) { |
| 147 | 150 | return; |
| 148 | 151 | } |
| 149 | 152 | |
| @@ -219,9 +222,12 @@ | ||
| 219 | 222 | * @param bool $wrapper |
| 220 | 223 | */ |
| 221 | 224 | function api_error( $api_result, $wrapper = false ) { |
| 222 | 225 | $message = ''; |
| 223 | - if ( is_object( $api_result ) && isset( $api_result->error ) ) { | |
| 226 | + if ( is_object( $api_result ) && | |
| 227 | + ! empty( $api_result->error ) && | |
| 228 | + ! empty( $api_result->error->message ) | |
| 229 | + ) { | |
| 224 | 230 | $message = $api_result->error->message; |
| 225 | 231 | } else if ( is_object( $api_result ) ) { |
| 226 | 232 | $message = var_export( $api_result, true ); |
| 227 | 233 | } else if ( is_string( $api_result ) ) { |
| @@ -315,8 +321,13 @@ | ||
| 315 | 321 | global $wpdb; |
| 316 | 322 | |
| 317 | 323 | $table = "{$wpdb->prefix}fs_logger"; |
| 318 | 324 | |
| 325 | + /** | |
| 326 | + * Drop logging table in any case. | |
| 327 | + */ | |
| 328 | + $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" ); | |
| 329 | + | |
| 319 | 330 | if ( $is_on ) { |
| 320 | 331 | /** |
| 321 | 332 | * Create logging table. |
| 322 | 333 | * |
| @@ -324,9 +335,9 @@ | ||
| 324 | 335 | * dbDelta must use KEY and not INDEX for indexes. |
| 325 | 336 | * |
| 326 | 337 | * @link https://core.trac.wordpress.org/ticket/2695 |
| 327 | 338 | */ |
| 328 | - $result = $wpdb->query( "CREATE TABLE {$table} ( | |
| 339 | + $result = $wpdb->query( "CREATE TABLE IF NOT EXISTS {$table} ( | |
| 329 | 340 | `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 330 | 341 | `process_id` INT UNSIGNED NOT NULL, |
| 331 | 342 | `user_name` VARCHAR(64) NOT NULL, |
| 332 | 343 | `logger` VARCHAR(128) NOT NULL, |
| @@ -343,17 +354,13 @@ | ||
| 343 | 354 | KEY `process_id` (`process_id` ASC), |
| 344 | 355 | KEY `process_logger` (`process_id` ASC, `logger` ASC), |
| 345 | 356 | KEY `function` (`function` ASC), |
| 346 | 357 | KEY `type` (`type` ASC))" ); |
| 347 | - } else { | |
| 348 | - /** | |
| 349 | - * Drop logging table. | |
| 350 | - */ | |
| 351 | - $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" ); | |
| 352 | 358 | } |
| 353 | 359 | |
| 354 | 360 | if ( false !== $result ) { |
| 355 | 361 | update_option( 'fs_storage_logger', ( $is_on ? 1 : 0 ) ); |
| 362 | + self::$_isStorageLoggingOn = $is_on; | |
| 356 | 363 | } |
| 357 | 364 | |
| 358 | 365 | return ( false !== $result ); |
| 359 | 366 | } |
| @@ -684,5 +691,5 @@ | ||
| 684 | 691 | return rtrim( $upload_dir['url'], '/' ) . $filename; |
| 685 | 692 | } |
| 686 | 693 | |
| 687 | 694 | #endregion |
| 688 | - } | |
| 695 | + } | |