| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Calculator Builder | CalcHub |
| 4 |
* Plugin URI: https://wordpress.org/plugins/calculator-builder/ |
| 5 |
* Description: Easily create Online calculators |
| 6 |
* Author: CalcHub |
| 7 |
* Author URI: https://calchub.xyz |
| 8 |
* Version: 1.6 |
| 9 |
* Text Domain: calculator-builder |
| 10 |
* License: GPL-2.0+ |
| 11 |
* Domain Path: languages |
| 12 |
* Requires PHP: 7.4 |
| 13 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 14 |
* |
| 15 |
* @package CALCHUB |
| 16 |
* @category Core |
| 17 |
* @author CalcHub |
| 18 |
* @version 0.4.4 |
| 19 |
*/ |
| 20 |
|
| 21 |
// Exit if accessed directly. |
| 22 |
defined( 'ABSPATH' ) || exit; |
| 23 |
|
| 24 |
if ( ! class_exists( 'Calculator_Builder' ) ) : |
| 25 |
|
| 26 |
/** |
| 27 |
* Main WP_Plugin Class. |
| 28 |
* |
| 29 |
* @since 1.0 |
| 30 |
*/ |
| 31 |
final class Calculator_Builder { |
| 32 |
|
| 33 |
private static $instance; |
| 34 |
public $admin; |
| 35 |
public $public; |
| 36 |
public $tools; |
| 37 |
public $db; |
| 38 |
public $sanitize; |
| 39 |
public $notices; |
| 40 |
|
| 41 |
/** |
| 42 |
* Main CalcHub Instance. |
| 43 |
* |
| 44 |
* Insures that only one instance of WP_Plugin exists in memory at any one |
| 45 |
* time. Also prevents needing to define globals all over the place. |
| 46 |
* |
| 47 |
* @static |
| 48 |
* @staticvar array $instance |
| 49 |
*/ |
| 50 |
public static function instance() { |
| 51 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Calculator_Builder ) ) { |
| 52 |
self::$instance = new self; |
| 53 |
|
| 54 |
self::$instance->setup_constants(); |
| 55 |
self::$instance->includes(); |
| 56 |
|
| 57 |
self::$instance->admin = new Calculator_Builder_Admin(); |
| 58 |
self::$instance->public = new Calculator_Builder_Public(); |
| 59 |
self::$instance->tools = new CalcHub_Export_Import(); |
| 60 |
self::$instance->db = new CalcHub_DB(); |
| 61 |
self::$instance->sanitize = new CalcHub_Sanitize(); |
| 62 |
self::$instance->notices = new CalcHub_Notices(); |
| 63 |
|
| 64 |
if ( has_filter( 'calchub_settings_menu_file' ) ) { |
| 65 |
self::$instance->settings = new CalcHub_Settings(); |
| 66 |
} |
| 67 |
|
| 68 |
register_activation_hook( __FILE__, [ self::$instance, 'plugin_activate' ] ); |
| 69 |
add_action( 'plugins_loaded', [ self::$instance, 'text_domain' ] ); |
| 70 |
if ( get_option( 'calculator_builder_data' ) !== '1.3.1' ) { |
| 71 |
add_action( 'admin_init', [ self::$instance, 'plugin_updater' ] ); |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
return self::$instance; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Setup plugin constants. |
| 81 |
* |
| 82 |
* @access private |
| 83 |
* @return void |
| 84 |
* @since 0.4 |
| 85 |
*/ |
| 86 |
private function setup_constants() { |
| 87 |
// Plugin version. |
| 88 |
if ( ! defined( 'CALCHUB_VERSION' ) ) { |
| 89 |
define( 'CALCHUB_VERSION', '1.6' ); |
| 90 |
} |
| 91 |
|
| 92 |
// Plugin Admin slug. |
| 93 |
if ( ! defined( 'CALCHUB_PLUGIN_SLUG' ) ) { |
| 94 |
define( 'CALCHUB_PLUGIN_SLUG', 'calchub' ); |
| 95 |
} |
| 96 |
|
| 97 |
// Plugin Root File. |
| 98 |
if ( ! defined( 'CALCHUB_PLUGIN_FILE' ) ) { |
| 99 |
define( 'CALCHUB_PLUGIN_FILE', __FILE__ ); |
| 100 |
} |
| 101 |
|
| 102 |
// Plugin Base Name. |
| 103 |
if ( ! defined( 'CALCHUB_PLUGIN_BASE' ) ) { |
| 104 |
define( 'CALCHUB_PLUGIN_BASE', plugin_basename( CALCHUB_PLUGIN_FILE ) ); |
| 105 |
} |
| 106 |
|
| 107 |
// Plugin Folder Path. |
| 108 |
if ( ! defined( 'CALCHUB_PLUGIN_DIR' ) ) { |
| 109 |
define( 'CALCHUB_PLUGIN_DIR', plugin_dir_path( CALCHUB_PLUGIN_FILE ) ); |
| 110 |
} |
| 111 |
|
| 112 |
// Plugin Folder URL. |
| 113 |
if ( ! defined( 'CALCHUB_PLUGIN_URL' ) ) { |
| 114 |
define( 'CALCHUB_PLUGIN_URL', plugin_dir_url( CALCHUB_PLUGIN_FILE ) ); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
/** |
| 120 |
* Throw error on object clone. |
| 121 |
* The whole idea of the singleton design pattern is that there is a single |
| 122 |
* object therefore, we don't want the object to be cloned. |
| 123 |
* |
| 124 |
* @return void |
| 125 |
* @access protected |
| 126 |
*/ |
| 127 |
public function __clone() { |
| 128 |
// Cloning instances of the class is forbidden. |
| 129 |
_doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'calculator-builder' ), '1.0' ); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Disable unserializing of the class. |
| 134 |
* |
| 135 |
* @return void |
| 136 |
* @access protected |
| 137 |
*/ |
| 138 |
public function __wakeup() { |
| 139 |
// Unserializing instances of the class is forbidden. |
| 140 |
_doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'calculator-builder' ), '1.0' ); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
/** |
| 145 |
* Include required files. |
| 146 |
* |
| 147 |
* @access private |
| 148 |
* @since 1.0 |
| 149 |
*/ |
| 150 |
private function includes() { |
| 151 |
// Admin |
| 152 |
require_once CALCHUB_PLUGIN_DIR . 'admin/class-admin.php'; |
| 153 |
require_once CALCHUB_PLUGIN_DIR . 'public/class-public.php'; |
| 154 |
if ( ! class_exists( 'JavaScriptPacker' ) ) { |
| 155 |
require_once CALCHUB_PLUGIN_DIR . 'inc/class-js-packer.php'; |
| 156 |
} |
| 157 |
require_once CALCHUB_PLUGIN_DIR . 'inc/class-calchub-list-table.php'; |
| 158 |
require_once CALCHUB_PLUGIN_DIR . 'inc/class-calchub-export-import.php'; |
| 159 |
require_once CALCHUB_PLUGIN_DIR . 'inc/class-calchub-db.php'; |
| 160 |
require_once CALCHUB_PLUGIN_DIR . 'inc/class-calchub-sanitize.php'; |
| 161 |
require_once CALCHUB_PLUGIN_DIR . 'inc/class-calchub-notices.php'; |
| 162 |
require_once CALCHUB_PLUGIN_DIR . 'inc/class-calchub-settings.php'; |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Activate the plugin. |
| 167 |
* create the database |
| 168 |
* create the folder in wp-upload |
| 169 |
* |
| 170 |
* @access public |
| 171 |
* @return void |
| 172 |
*/ |
| 173 |
public function plugin_activate(): void { |
| 174 |
self::$instance->db->create_table(); |
| 175 |
update_option( 'calculator_builder_data', '1.3.1' ); |
| 176 |
} |
| 177 |
|
| 178 |
public function plugin_updater(): void { |
| 179 |
self::$instance->db->create_table(); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Download the folder with languages. |
| 184 |
* |
| 185 |
* @access public |
| 186 |
* @return void |
| 187 |
*/ |
| 188 |
public function text_domain() { |
| 189 |
$languages_folder = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; |
| 190 |
load_plugin_textdomain( 'calculator-builder', false, $languages_folder ); |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
endif; // End if class_exists check. |
| 196 |
|
| 197 |
/** |
| 198 |
* The main function for that returns WP_Plugin |
| 199 |
* |
| 200 |
* @since 1.0 |
| 201 |
*/ |
| 202 |
function CALCHUB() { |
| 203 |
return Calculator_Builder::instance(); |
| 204 |
} |
| 205 |
|
| 206 |
// Get Running. |
| 207 |
CALCHUB(); |
| 208 |
|