*/ class Epicformbuilder { /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. * * @since 1.0.0 * @access protected * @var Epicformbuilder_Loader $loader Maintains and registers all hooks for the plugin. */ protected $loader; /** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { $this->init_loader(); $this->define_common_hooks(); $this->define_admin_hooks(); $this->define_public_hooks(); $this->define_preview_hooks(); $this->define_elementor_hooks(); $this->define_gutenberg_hooks(); } /** * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.0.0 * @access private */ private function init_loader() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once plugin_dir_path( __DIR__ ) . 'includes/class-epicformbuilder-loader.php'; $this->loader = new Epicformbuilder_Loader(); } /** * Register all the hooks related to the common functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_common_hooks() { $this->loader->add_action( 'http_api_debug', Epicformbuilder_Services_Logger::get_instance(), 'log_http_api', 10, 5 ); $this->loader->add_action( 'wp_error_added', Epicformbuilder_Services_Logger::get_instance(), 'log_wp_error', 10, 4 ); $privacy = new Epicformbuilder_Privacy(); $this->loader->add_filter( 'wp_privacy_personal_data_exporters', $privacy, 'register_exporters' ); $this->loader->add_filter( 'wp_privacy_personal_data_erasers', $privacy, 'register_erasers' ); $this->loader->add_action( 'admin_init', $privacy, 'add_policy_content' ); if ( is_multisite() ) { // Settings and log paths are cached in statics, which would // otherwise outlive a switch_to_blog() call and serve one site's // data while another is current. $this->loader->add_action( 'switch_blog', Epicformbuilder_Services_Settings::get_instance(), 'reset' ); $this->loader->add_action( 'switch_blog', Epicformbuilder_Services_Logger::get_instance(), 'reset' ); // The anonymized_utc column check is cached in a static for the // same reason. A stale `true` surviving a switch_to_blog() on a // partially-migrated multisite would make find_by_email() apply // an `anonymized_utc IS NULL` predicate against a table that // does not have the column on the newly current site, erroring // the query and silently emptying an export or erasure -- the // exact bug that cache exists to prevent (see // Epicformbuilder_Repositories_Submissions::find_by_email()). // The check is a bare static with no owning instance to hand // the loader above, so it is registered directly instead. add_action( 'switch_blog', [ Epicformbuilder_Repositories_Submissions::class, 'reset_anonymized_column_cache' ] ); } } /** * Register all the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { /** * The class responsible for defining all actions that occur in the admin area. */ require_once plugin_dir_path( __DIR__ ) . 'admin/class-epicformbuilder-admin.php'; $plugin_admin = new Epicformbuilder_Admin(); $this->loader->add_action( 'init', $plugin_admin, 'register_scripts_and_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'menu' ); $this->loader->add_action( 'admin_post_epicforms_protected_download', $plugin_admin, 'protected_download' ); /* Initialise config endpoint to fetch Admin application configuration */ $rest_api_admin_config = new Epicformbuilder_REST_Admin_Config_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_admin_config, 'register_routes' ); $rest_api_statistics = new Epicformbuilder_REST_Admin_Statistics_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_statistics, 'register_routes' ); $rest_api_submissions = new Epicformbuilder_REST_Admin_Submissions_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_submissions, 'register_routes' ); $rest_api_forms = new Epicformbuilder_REST_Admin_Forms_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_forms, 'register_routes' ); $rest_api_form = new Epicformbuilder_REST_Admin_Forms_Statistics_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_form, 'register_routes' ); $rest_api_form_export = new Epicformbuilder_REST_Admin_Form_Export_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_form_export, 'register_routes' ); $rest_api_form_draft = new Epicformbuilder_REST_Admin_Form_Draft_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_form_draft, 'register_routes' ); $rest_api_settings = new Epicformbuilder_REST_Admin_Settings_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_settings, 'register_routes' ); $rest_api_logs = new Epicformbuilder_REST_Admin_Logs_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_logs, 'register_routes' ); } /** * Register all the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once plugin_dir_path( __DIR__ ) . 'public/class-epicformbuilder-public.php'; $plugin_public = new Epicformbuilder_Public(); $this->loader->add_action( 'init', $plugin_public, 'register_scripts_and_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_shortcode( 'epicforms', $plugin_public, 'epicforms_shortcode' ); // Rest API hooks. Initialise config endpoint to fetch Public application configuration. $rest_api_public_config = new Epicformbuilder_REST_Public_Config_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_public_config, 'register_routes' ); $rest_api_form = new Epicformbuilder_REST_Public_Form_Controller(); $this->loader->add_action( 'rest_api_init', $rest_api_form, 'register_routes' ); // Form submission hooks. $form_statistics_update = new Epicformbuilder_Actions_Update_Form_Statistics_On_Submission(); $this->loader->add_action( 'epicforms_submission_after_create', $form_statistics_update, 'do', 10, 2 ); $send_owner_notification_email = new Epicformbuilder_Actions_Send_Owner_Notification_Email(); $this->loader->add_action( 'epicforms_submission_after_create', $send_owner_notification_email, 'do', 10, 2 ); $submission_view = new Epicformbuilder_Actions_Mark_Submission_As_Viewed(); $this->loader->add_action( 'epicforms_submission_view', $submission_view, 'do' ); } /** * Register all the hooks related to the form preview functionality * of the plugin. * * @since 1.0.0 */ private function define_preview_hooks() { require_once plugin_dir_path( __DIR__ ) . 'admin/class-epicformbuilder-wordpress-preview.php'; new Epicformbuilder_WordPress_Preview(); } /** * Register all the hooks related to the Elementor integration * of the plugin. * * @since 1.0.0 */ private function define_elementor_hooks() { add_action( 'elementor/widgets/register', function ( $widgets_manager ) { require_once plugin_dir_path( __DIR__ ) . 'includes/integrations/class-epicformbuilder-integrations-elementor.php'; $widgets_manager->register( new Epicformbuilder_Integrations_Elementor( [], null ) ); } ); } /** * Register all the hooks related to the Gutenberg integration * of the plugin. * * @since 1.0.0 */ private function define_gutenberg_hooks() { add_action( 'init', function () { require_once plugin_dir_path( __DIR__ ) . 'includes/integrations/class-epicformbuilder-integrations-gutenberg.php'; new Epicformbuilder_Integrations_Gutenberg(); } ); } /** * Run the loader to execute all the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } }