| 1 |
<?php |
| 2 |
namespace Dudlewebs\WPMCS; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Counter { |
| 7 |
private static $instance = null; |
| 8 |
private $assets_url; |
| 9 |
private $version; |
| 10 |
private $token; |
| 11 |
|
| 12 |
/** |
| 13 |
* Admin constructor. |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
$this->assets_url = WPMCS_ASSETS_URL; |
| 18 |
$this->version = WPMCS_VERSION; |
| 19 |
$this->token = WPMCS_TOKEN; |
| 20 |
|
| 21 |
// Initialize setup |
| 22 |
// $this->init(); |
| 23 |
} |
| 24 |
/** |
| 25 |
* |
| 26 |
* Add Count |
| 27 |
* @since 1.0.0 |
| 28 |
* |
| 29 |
*/ |
| 30 |
public static function add( $property = 'uploaded' ){ |
| 31 |
$settings_key = Schema::getConstant('COUNTER_KEY'); |
| 32 |
$current = Utils::get_option( $property, 0, Schema::getConstant('COUNTER_KEY') ); |
| 33 |
$current++; |
| 34 |
return Utils::update_option( $property, $current, Schema::getConstant('COUNTER_KEY') ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* |
| 39 |
* Add Count |
| 40 |
* @since 1.0.0 |
| 41 |
* |
| 42 |
*/ |
| 43 |
public static function remove( $property = 'uploaded' ){ |
| 44 |
$settings_key = Schema::getConstant('COUNTER_KEY'); |
| 45 |
$current = Utils::get_option( $property, 0, Schema::getConstant('COUNTER_KEY') ); |
| 46 |
$current--; |
| 47 |
return Utils::update_option( $property, $current, Schema::getConstant('COUNTER_KEY') ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get Count |
| 52 |
* @since 1.0.0 |
| 53 |
*/ |
| 54 |
public static function get( $property = 'uploaded' ) { |
| 55 |
return Utils::get_option( $property, 0, Schema::getConstant('COUNTER_KEY') ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Update Count |
| 60 |
* @since 1.0.0 |
| 61 |
*/ |
| 62 |
public static function update( $property, $value ) { |
| 63 |
return Utils::update_option( $property, $value, Schema::getConstant('COUNTER_KEY') ); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
public static function instance(){ |
| 68 |
if (is_null(self::$instance)) { |
| 69 |
self::$instance = new self(); |
| 70 |
} |
| 71 |
return self::$instance; |
| 72 |
} |
| 73 |
} |