api = new ChatSaleApi(); } function chatsale_check_activation() { if (get_option(self::OPTION_NEED_REDIRECT)) { delete_option(self::OPTION_NEED_REDIRECT); wp_redirect(admin_url('admin.php?page=chatsale-settings')); } } public function create_admin_menu() { add_menu_page( 'ChatSale Settings', 'ChatSale', 'manage_options', 'chatsale-settings', [$this, 'settings_page'], 'dashicons-format-chat' ); } public function settings_page() { include plugin_dir_path(__FILE__) . 'admin/admin-page.php'; } public function set_assistant_settings($settings) { update_option(self::ASSISTANT_SETTINGS, $settings); } public function enqueue_admin_scripts() { wp_enqueue_style('chatsale_lead_form_plugin_css', plugins_url('/assets/css/styles.css', __FILE__)); } public function display_error_notice() { if (get_option(self::OPTION_ERROR)) { echo '
'; echo '

' . esc_html(get_option(self::OPTION_ERROR)) . '

'; echo '
'; delete_option(self::OPTION_ERROR); } } public function display_assistant_code() { $assistant_id = get_option(self::OPTION_ASSISTANT); $show = get_option(self::OPTION_SHOW_FRONT); if ($assistant_id && $show == 'Y' && !is_admin()) { wp_register_script( 'chatsale_lead_form_plugin-assistant', 'https://chat.chatsale.io/lib/chatsale.js', [], null, true ); wp_enqueue_script('chatsale_lead_form_plugin-assistant'); } } public function add_id_to_script( $tag, $handle, $src ) { if ($handle == 'chatsale_lead_form_plugin-assistant') $tag = ''; return $tag; } } new ChatSale(); register_activation_hook(__FILE__, 'chatsale_lead_form_plugin_plugin_activation'); register_deactivation_hook( __FILE__, 'chatsale_lead_form_plugin_plugin_deactivate' ); function chatsale_lead_form_plugin_plugin_activation() { add_option(ChatSale::ASSISTANT_SETTINGS, ''); add_option(ChatSale::SET_UP_STEP, 1); add_option(ChatSale::OPTION_SHOW_FRONT, ''); add_option(ChatSale::OPTION_ACCOUNT, ''); add_option(ChatSale::OPTION_NEED_REDIRECT, true); add_option(ChatSale::OPTION_ASSISTANT, ''); } function chatsale_lead_form_plugin_plugin_deactivate() { delete_option(ChatSale::OPTION_ERROR); delete_option(ChatSale::OPTION_SHOW_FRONT); delete_option(ChatSale::SET_UP_STEP); delete_option(ChatSale::ASSISTANT_SETTINGS); delete_option(ChatSale::OPTION_ASSISTANT); delete_option(ChatSale::OPTION_ACCOUNT); delete_option(ChatSale::OPTION_NEED_REDIRECT); }