database = $wpdb; $this->plugin = $plugin; $directory = new \cx_appengine\directory(templates_dir, 'html'); $dictionary = new wordpress_dictionary; $this->templates = new \cx_appengine\templates($directory, $dictionary); $this->settings = new plugin_settings(); $this->tables = new table_names($this->get_database()); $this->versions = new database_versions_manager(); $this->init_cron(); } public function init() { $this->export = new customers_export_page( $this->database, $this->tables, $this->settings ); $this->export->prepare(); $this->translations(); } private function translations() : void { load_plugin_textdomain( 'cx_newsletter', false, $this->plugin.'/translates'); } public function add_schedules(array $intervals) : array { $intervals['cx_newsletter_send'] = []; $intervals['cx_newsletter_send']['interval'] = 60; $intervals['cx_newsletter_send']['display'] = 'cx-newsletter'; return $intervals; } public function register_rest() : void { $this->messages_get = new messages_get_endpoint( $this->database, $this->settings, $this->tables ); $this->messages_send = new messages_send_endpoint( $this->database, $this->settings, $this->tables ); $this->settings_check = new settings_check_endpoint( $this->database, $this->settings, $this->tables ); $registerer = new rest_register('cx-newsletter/v1'); $registerer ->register($this->messages_get) ->register($this->messages_send) ->register($this->settings_check); } private function init_cron() : void { if (wp_next_scheduled('cx_newsletter_email_sender') === false) { wp_schedule_event( time(), 'cx_newsletter_send', 'cx_newsletter_email_sender' ); } } public function email_sender() { $sender = new cron_emails_sender( $this->database, $this->tables, $this->settings ); $sender ->prepare() ->process(); } public function admin() { $this->update(); $this->connect_menu(); $config_panel = new config_panel_view( $this->get_database(), $this->get_settings(), $this->get_templates(), $this->get_tables() ); $dashboard = new dashboard_view( $this->get_database(), $this->get_settings(), $this->get_templates(), $this->get_tables() ); $manage_messages = new manage_messages_view( $this->get_database(), $this->get_settings(), $this->get_templates(), $this->get_tables() ); $manage_customers = new manage_customers_view( $this->get_database(), $this->get_settings(), $this->get_templates(), $this->get_tables() ); $show_campaigns = new show_campaigns_view( $this->get_database(), $this->get_settings(), $this->get_templates(), $this->get_tables() ); $manage_groups = new manage_groups_view( $this->get_database(), $this->get_settings(), $this->get_templates(), $this->get_tables() ); $sending_test = new sending_test_view( $this->get_database(), $this->get_settings(), $this->get_templates(), $this->get_tables() ); $config_panel->connect(); $dashboard->connect(); $manage_messages->connect(); $manage_customers->connect(); $show_campaigns->connect(); $manage_groups->connect(); $sending_test->connect(); } private function connect_menu() : void { add_menu_page( 'cx-newsletter', 'cx-newsletter', 'customize', 'cx_newsletter', '', 'dashicons-art' ); } public function update() { $this ->get_plugin_updater() ->update(); } private function get_plugin_updater() : plugin_updater { return new plugin_updater( $this->get_settings(), $this->get_versions(), $this->get_tables(), $this->get_database() ); } public function install() { $this ->get_plugin_updater() ->install(); } public function remove() { $this ->get_plugin_updater() ->remove(); } protected function get_database() : wpdb { return $this->database; } protected function get_templates() : \cx_appengine\templates { return $this->templates; } protected function get_settings() : settings { return $this->settings; } protected function get_tables() : table_names { return $this->tables; } protected function get_versions() : database_versions_manager { return $this->versions; } private string $plugin; private \cx_appengine\templates $templates; private wpdb $database; private table_names $tables; private settings $settings; private messages_get_endpoint $messages_get; private messages_send_endpoint $messages_send; private settings_check_endpoint $settings_check; private database_versions_manager $versions; }