| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The file that defines the core plugin class |
| 5 |
* |
| 6 |
* A class definition that includes attributes and functions used across both the |
| 7 |
* public-facing side of the site and the admin area. |
| 8 |
* |
| 9 |
* @link https://ays-pro.com/ |
| 10 |
* @since 1.0.0 |
| 11 |
* |
| 12 |
* @package Chart_Builder |
| 13 |
* @subpackage Chart_Builder/includes |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* The core plugin class. |
| 18 |
* |
| 19 |
* This is used to define internationalization, admin-specific hooks, and |
| 20 |
* public-facing site hooks. |
| 21 |
* |
| 22 |
* Also maintains the unique identifier of this plugin as well as the current |
| 23 |
* version of the plugin. |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
* @package Chart_Builder |
| 27 |
* @subpackage Chart_Builder/includes |
| 28 |
* @author Chart Builder Team <info@ays-pro.com> |
| 29 |
*/ |
| 30 |
class Chart_Builder { |
| 31 |
|
| 32 |
/** |
| 33 |
* The loader that's responsible for maintaining and registering all hooks that power |
| 34 |
* the plugin. |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* @access protected |
| 38 |
* @var Chart_Builder_Loader $loader Maintains and registers all hooks for the plugin. |
| 39 |
*/ |
| 40 |
protected $loader; |
| 41 |
|
| 42 |
/** |
| 43 |
* The unique identifier of this plugin. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* @access protected |
| 47 |
* @var string $plugin_name The string used to uniquely identify this plugin. |
| 48 |
*/ |
| 49 |
protected $plugin_name; |
| 50 |
|
| 51 |
/** |
| 52 |
* The current version of the plugin. |
| 53 |
* |
| 54 |
* @since 1.0.0 |
| 55 |
* @access protected |
| 56 |
* @var string $version The current version of the plugin. |
| 57 |
*/ |
| 58 |
protected $version; |
| 59 |
|
| 60 |
/** |
| 61 |
* Define the core functionality of the plugin. |
| 62 |
* |
| 63 |
* Set the plugin name and the plugin version that can be used throughout the plugin. |
| 64 |
* Load the dependencies, define the locale, and set the hooks for the admin area and |
| 65 |
* the public-facing side of the site. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
*/ |
| 69 |
public function __construct() { |
| 70 |
if ( defined( 'CHART_BUILDER_VERSION' ) ) { |
| 71 |
$this->version = CHART_BUILDER_VERSION; |
| 72 |
} else { |
| 73 |
$this->version = '1.0.0'; |
| 74 |
} |
| 75 |
$this->plugin_name = "chart-builder"; |
| 76 |
|
| 77 |
$this->load_dependencies(); |
| 78 |
$this->set_locale(); |
| 79 |
$this->define_admin_hooks(); |
| 80 |
$this->define_public_hooks(); |
| 81 |
$this->define_integrations_hooks(); |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Load the required dependencies for this plugin. |
| 87 |
* |
| 88 |
* Include the following files that make up the plugin: |
| 89 |
* |
| 90 |
* - Chart_Builder_Loader. Orchestrates the hooks of the plugin. |
| 91 |
* - Chart_Builder_i18n. Defines internationalization functionality. |
| 92 |
* - Chart_Builder_Admin. Defines all hooks for the admin area. |
| 93 |
* - Chart_Builder_Public. Defines all hooks for the public side of the site. |
| 94 |
* |
| 95 |
* Create an instance of the loader which will be used to register the hooks |
| 96 |
* with WordPress. |
| 97 |
* |
| 98 |
* @since 1.0.0 |
| 99 |
* @access private |
| 100 |
*/ |
| 101 |
private function load_dependencies() { |
| 102 |
|
| 103 |
if ( ! class_exists( 'WP_List_Table' ) ) { |
| 104 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* The classes responsible for defining all actions including db that occur in the plugin area. |
| 109 |
*/ |
| 110 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-chart-builder-functions.php'; |
| 111 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-chart-builder-settings-db-actions.php'; |
| 112 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-chart-builder-db-actions.php'; |
| 113 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-chart-builder-actions.php'; |
| 114 |
|
| 115 |
/** |
| 116 |
* The class responsible for defining all functions for getting all form integrations |
| 117 |
*/ |
| 118 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-chart-builder-integrations.php'; |
| 119 |
|
| 120 |
/** |
| 121 |
* The class responsible for orchestrating the actions and filters of the |
| 122 |
* core plugin. |
| 123 |
*/ |
| 124 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-chart-builder-loader.php'; |
| 125 |
|
| 126 |
/** |
| 127 |
* The class responsible for defining internationalization functionality |
| 128 |
* of the plugin. |
| 129 |
*/ |
| 130 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-chart-builder-i18n.php'; |
| 131 |
|
| 132 |
/** |
| 133 |
* The class responsible for defining all actions that occur in the admin area. |
| 134 |
*/ |
| 135 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-chart-builder-admin.php'; |
| 136 |
|
| 137 |
/** |
| 138 |
* The class responsible for defining all actions that occur in the public-facing |
| 139 |
* side of the site. |
| 140 |
*/ |
| 141 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-chart-builder-public.php'; |
| 142 |
|
| 143 |
$this->loader = new Chart_Builder_Loader(); |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Define the locale for this plugin for internationalization. |
| 149 |
* |
| 150 |
* Uses the Chart_Builder_i18n class in order to set the domain and to register the hook |
| 151 |
* with WordPress. |
| 152 |
* |
| 153 |
* @since 1.0.0 |
| 154 |
* @access private |
| 155 |
*/ |
| 156 |
private function set_locale() { |
| 157 |
|
| 158 |
$plugin_i18n = new Chart_Builder_i18n(); |
| 159 |
|
| 160 |
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Register all of the hooks related to the admin area functionality |
| 166 |
* of the plugin. |
| 167 |
* |
| 168 |
* @since 1.0.0 |
| 169 |
* @access private |
| 170 |
*/ |
| 171 |
private function define_admin_hooks() { |
| 172 |
|
| 173 |
$plugin_admin = new Chart_Builder_Admin( $this->get_plugin_name(), $this->get_version() ); |
| 174 |
|
| 175 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 176 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 177 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'disable_scripts', 100 ); |
| 178 |
|
| 179 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' ); |
| 180 |
|
| 181 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_charts_submenu', 115 ); |
| 182 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_add_new_submenu', 120 ); |
| 183 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_general_settings_submenu', 125 ); |
| 184 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_dashboard_submenu', 130 ); |
| 185 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_featured_plugins_submenu', 135 ); |
| 186 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_chart_features_submenu', 145 ); |
| 187 |
|
| 188 |
|
| 189 |
// Add Chart page sources contents |
| 190 |
$this->loader->add_action( 'ays_cb_chart_page_sources_contents', $plugin_admin, 'ays_chart_page_source_contents', 10, 3 ); |
| 191 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_admin, 'source_contents_import_from_csv_settings', 40, 2 ); |
| 192 |
// $this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_admin, 'source_contents_import_from_wordpress_settings', 50, 2 ); |
| 193 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_admin, 'source_contents_import_from_db_settings', 60, 2 ); |
| 194 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_admin, 'source_contents_import_from_external_db_settings', 65, 2 ); |
| 195 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_admin, 'source_contents_quiz_maker_integration_settings', 70, 2 ); |
| 196 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_admin, 'source_contents_woocommerce_integration_settings', 80, 2 ); |
| 197 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_admin, 'source_contents_manual_settings', 90, 2 ); |
| 198 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings_chartjs', $plugin_admin, 'source_contents_manual_settings_chartjs', 90, 2 ); |
| 199 |
|
| 200 |
// Add Chart page settings contents |
| 201 |
$this->loader->add_action( 'ays_cb_chart_page_settings_contents', $plugin_admin, 'ays_chart_page_settings_contents', 10, 3 ); |
| 202 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_general_settings', 50, 2 ); |
| 203 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_tooltip_settings', 70, 2 ); |
| 204 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_legend_settings', 80, 2 ); |
| 205 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_horizontal_axis_settings', 90, 2 ); |
| 206 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_vertical_axis_settings', 100, 2 ); |
| 207 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_animation_settings', 110, 2 ); |
| 208 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_live_chart_settings', 115, 2 ); |
| 209 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings', $plugin_admin, 'settings_contents_export_options', 120, 2 ); |
| 210 |
$this->loader->add_filter( 'ays_cb_chart_page_settings_contents_settings_chartjs', $plugin_admin, 'settings_contents_general_settings_chartjs', 50, 2 ); |
| 211 |
|
| 212 |
// Add Chart page styles contents |
| 213 |
$this->loader->add_action( 'ays_cb_chart_page_styles_contents', $plugin_admin, 'ays_chart_page_styles_contents', 10, 3 ); |
| 214 |
$this->loader->add_filter( 'ays_cb_chart_page_styles_contents_settings', $plugin_admin, 'settings_contents_chart_styles_settings', 50, 2 ); |
| 215 |
$this->loader->add_filter( 'ays_cb_chart_page_styles_contents_settings', $plugin_admin, 'settings_contents_chart_area_styles_settings', 60, 2 ); |
| 216 |
$this->loader->add_filter( 'ays_cb_chart_page_styles_contents_settings', $plugin_admin, 'settings_contents_title_styles_settings', 70, 2 ); |
| 217 |
$this->loader->add_filter( 'ays_cb_chart_page_styles_contents_settings', $plugin_admin, 'settings_contents_description_styles_settings', 80, 2 ); |
| 218 |
$this->loader->add_filter( 'ays_cb_chart_page_styles_contents_settings_chartjs', $plugin_admin, 'settings_contents_title_styles_settings_chartjs', 70, 2 ); |
| 219 |
$this->loader->add_filter( 'ays_cb_chart_page_styles_contents_settings_chartjs', $plugin_admin, 'settings_contents_description_styles_settings_chartjs', 80, 2 ); |
| 220 |
|
| 221 |
// Add Chart page advanced settings contents |
| 222 |
$this->loader->add_action( 'ays_cb_chart_page_advanced_settings_contents', $plugin_admin, 'ays_chart_page_advanced_settings_contents', 10, 3 ); |
| 223 |
$this->loader->add_filter( 'ays_cb_chart_page_advanced_settings_contents_settings', $plugin_admin, 'settings_contents_advanced_settings', 50, 2 ); |
| 224 |
$this->loader->add_filter( 'ays_cb_chart_page_advanced_settings_contents_settings', $plugin_admin, 'settings_contents_slices_settings', 60, 2 ); |
| 225 |
$this->loader->add_filter( 'ays_cb_chart_page_advanced_settings_contents_settings', $plugin_admin, 'settings_contents_series_settings', 70, 2 ); |
| 226 |
$this->loader->add_filter( 'ays_cb_chart_page_advanced_settings_contents_settings', $plugin_admin, 'settings_contents_row_settings', 80, 2 ); |
| 227 |
$this->loader->add_filter( 'ays_cb_chart_page_advanced_settings_contents_settings_chartjs', $plugin_admin, 'settings_contents_advanced_settings_chartjs', 50, 2 ); |
| 228 |
|
| 229 |
// Add Settings link to the plugin |
| 230 |
$plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' ); |
| 231 |
$this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links' ); |
| 232 |
|
| 233 |
|
| 234 |
// Admin AJAX action |
| 235 |
$this->loader->add_action( 'wp_ajax_ays_chart_admin_ajax', $plugin_admin, 'ays_admin_ajax' ); |
| 236 |
$this->loader->add_action( 'wp_ajax_nopriv_ays_chart_admin_ajax', $plugin_admin, 'ays_admin_ajax' ); |
| 237 |
$this->loader->add_action( 'wp_ajax_deactivate_plugin_option_cb', $plugin_admin, 'deactivate_plugin_option'); |
| 238 |
$this->loader->add_action( 'wp_ajax_nopriv_deactivate_plugin_option_cb', $plugin_admin, 'deactivate_plugin_option'); |
| 239 |
|
| 240 |
$this->loader->add_action( 'wp_ajax_ays_chart_install_plugin', $plugin_admin, 'ays_chart_install_plugin' ); |
| 241 |
$this->loader->add_action( 'wp_ajax_nopriv_ays_chart_install_plugin', $plugin_admin, 'ays_chart_install_plugin' ); |
| 242 |
|
| 243 |
$this->loader->add_action( 'wp_ajax_ays_chart_activate_plugin', $plugin_admin, 'ays_chart_activate_plugin' ); |
| 244 |
$this->loader->add_action( 'wp_ajax_nopriv_ays_chart_activate_plugin', $plugin_admin, 'ays_chart_activate_plugin' ); |
| 245 |
|
| 246 |
$this->loader->add_action( 'elementor/widgets/widgets_registered', $plugin_admin, 'chart_builder_el_widgets_registered' ); |
| 247 |
|
| 248 |
$this->loader->add_action( 'in_admin_footer', $plugin_admin, 'chart_builder_admin_footer', 1 ); |
| 249 |
|
| 250 |
// Sale Banner |
| 251 |
$this->loader->add_action( 'admin_notices', $plugin_admin, 'ays_chart_sale_banner', 1 ); |
| 252 |
$this->loader->add_action( 'wp_ajax_ays_chart_dismiss_button', $plugin_admin, 'ays_chart_dismiss_button' ); |
| 253 |
$this->loader->add_action( 'wp_ajax_nopriv_ays_chart_dismiss_button', $plugin_admin, 'ays_chart_dismiss_button' ); |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Register all of the hooks related to the public-facing functionality |
| 258 |
* of the plugin. |
| 259 |
* |
| 260 |
* @since 1.0.0 |
| 261 |
* @access private |
| 262 |
*/ |
| 263 |
private function define_public_hooks() { |
| 264 |
|
| 265 |
$plugin_public = new Chart_Builder_Public( $this->get_plugin_name(), $this->get_version() ); |
| 266 |
|
| 267 |
// $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 268 |
// $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Register all of the hooks related to the integrations functionality |
| 274 |
* of the plugin. |
| 275 |
* |
| 276 |
* @since 1.0.0 |
| 277 |
* @access private |
| 278 |
*/ |
| 279 |
private function define_integrations_hooks() { |
| 280 |
|
| 281 |
$plugin_integrations = new Chart_Builder_Integrations( $this->get_plugin_name(), $this->get_version() ); |
| 282 |
|
| 283 |
// Form Maker Integrations / form page |
| 284 |
$this->loader->add_action( 'ays_cb_chart_page_integrations', $plugin_integrations, 'ays_chart_page_integrations_content' ); |
| 285 |
|
| 286 |
// Form Maker Integrations / settings page |
| 287 |
$this->loader->add_action( 'ays_cb_settings_page_integrations', $plugin_integrations, 'ays_settings_page_integrations_content' ); |
| 288 |
|
| 289 |
|
| 290 |
// ===== Google integration ===== |
| 291 |
|
| 292 |
// Google integration / settings page |
| 293 |
$this->loader->add_filter( 'ays_cb_settings_page_integrations_contents', $plugin_integrations, 'ays_settings_page_google_sheet_content', 50, 2 ); |
| 294 |
$this->loader->add_filter( 'ays_cb_chart_page_sources_contents_settings', $plugin_integrations, 'source_contents_import_from_google_sheet_settings', 50, 2 ); |
| 295 |
|
| 296 |
// ===== Google integration ===== |
| 297 |
|
| 298 |
// ===== Database integration ===== |
| 299 |
$this->loader->add_filter( 'ays_cb_settings_page_integrations_contents', $plugin_integrations, 'ays_settings_page_database_content', 50, 3 ); |
| 300 |
|
| 301 |
// ===== Database integration ===== |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
/** |
| 306 |
* Run the loader to execute all of the hooks with WordPress. |
| 307 |
* |
| 308 |
* @since 1.0.0 |
| 309 |
*/ |
| 310 |
public function run() { |
| 311 |
$this->loader->run(); |
| 312 |
} |
| 313 |
|
| 314 |
/** |
| 315 |
* The name of the plugin used to uniquely identify it within the context of |
| 316 |
* WordPress and to define internationalization functionality. |
| 317 |
* |
| 318 |
* @since 1.0.0 |
| 319 |
* @return string The name of the plugin. |
| 320 |
*/ |
| 321 |
public function get_plugin_name() { |
| 322 |
return $this->plugin_name; |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 327 |
* |
| 328 |
* @since 1.0.0 |
| 329 |
* @return Chart_Builder_Loader Orchestrates the hooks of the plugin. |
| 330 |
*/ |
| 331 |
public function get_loader() { |
| 332 |
return $this->loader; |
| 333 |
} |
| 334 |
|
| 335 |
/** |
| 336 |
* Retrieve the version number of the plugin. |
| 337 |
* |
| 338 |
* @since 1.0.0 |
| 339 |
* @return string The version number of the plugin. |
| 340 |
*/ |
| 341 |
public function get_version() { |
| 342 |
return $this->version; |
| 343 |
} |
| 344 |
|
| 345 |
} |
| 346 |
|