get_menu_icon(), // Icon 25 // Position (after Comments) ); // Add dashboard as the first submenu (to rename the first item) add_submenu_page( 'advanced-widget-kit-for-elementor', esc_html__('Dashboard', 'advanced-widget-kit-for-elementor'), esc_html__('Dashboard', 'advanced-widget-kit-for-elementor'), 'manage_options', 'advanced-widget-kit-for-elementor', [$this, 'dashboard_page'] ); // Add form entries submenu add_submenu_page( 'advanced-widget-kit-for-elementor', esc_html__('Form Entries', 'advanced-widget-kit-for-elementor'), esc_html__('Form Entries', 'advanced-widget-kit-for-elementor'), 'manage_options', 'awke-form-entries', [$this, 'form_entries_page'] ); // Add custom post types submenu add_submenu_page( 'advanced-widget-kit-for-elementor', esc_html__('Custom Post Types', 'advanced-widget-kit-for-elementor'), esc_html__('Custom Post Types', 'advanced-widget-kit-for-elementor'), 'manage_options', 'awke-custom-post-types', [$this, 'custom_post_types_page'] ); // Add voice input settings submenu add_submenu_page( 'advanced-widget-kit-for-elementor', esc_html__('Voice Input Settings', 'advanced-widget-kit-for-elementor'), esc_html__('Voice Input Settings', 'advanced-widget-kit-for-elementor'), 'manage_options', 'awke-voice-settings', [$this, 'voice_settings_page'] ); // Add general settings submenu add_submenu_page( 'advanced-widget-kit-for-elementor', esc_html__('Settings', 'advanced-widget-kit-for-elementor'), esc_html__('Settings', 'advanced-widget-kit-for-elementor'), 'manage_options', 'advanced-widget-kit-settings', [$this, 'settings_page'] ); // Store hook for later use if (isset($hook)) { add_action('load-' . $hook, [$this, 'admin_page_load']); } } /** * Admin Init * * Initialize admin functionality. * * @since 1.0.0 * @access public */ public function admin_init() { // Register settings with sanitization register_setting('awke_settings_group', 'awke_settings', [ 'sanitize_callback' => [$this, 'sanitize_settings'] ]); } /** * Sanitize Settings * * @since 1.0.0 * @param array $input Settings input * @return array Sanitized settings */ public function sanitize_settings($input) { $sanitized = []; if (isset($input['enabled_widgets']) && is_array($input['enabled_widgets'])) { $sanitized['enabled_widgets'] = []; foreach ($input['enabled_widgets'] as $key => $value) { $sanitized['enabled_widgets'][sanitize_key($key)] = (bool) $value; } } if (isset($input['version'])) { $sanitized['version'] = sanitize_text_field($input['version']); } return $sanitized; } /** * Admin Page Load * * Called when our admin page is loaded. * * @since 1.0.0 * @access public */ public function admin_page_load() { // Check user capabilities again if (!current_user_can('manage_options')) { wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'advanced-widget-kit-for-elementor')); } } /** * Enqueue Admin Assets * * Enqueue CSS and JS for admin page. * * @since 1.0.0 * @access public */ public function enqueue_admin_assets() { // Get current screen $screen = get_current_screen(); // Only load on our plugin pages if (!$screen || (strpos($screen->id, 'advanced-widget-kit') === false && strpos($screen->id, 'awke-') === false)) { return; } // Enqueue main admin assets wp_enqueue_style( 'awke-admin-styles', AWKE_URL . 'admin/css/admin.css', [], AWKE_VERSION ); wp_enqueue_script( 'awke-admin-scripts', AWKE_URL . 'admin/js/admin.js', ['jquery'], AWKE_VERSION, true ); // Enqueue CPT manager assets if on CPT page if ($screen && strpos($screen->id, 'awke-custom-post-types') !== false) { wp_enqueue_style( 'awke-cpt-styles', AWKE_URL . 'admin/css/custom-post-types.css', ['awke-admin-styles'], AWKE_VERSION ); wp_enqueue_script( 'awke-cpt-scripts', AWKE_URL . 'admin/js/custom-post-types.js', ['jquery', 'awke-admin-scripts'], AWKE_VERSION, true ); } // Localize script for AJAX wp_localize_script('awke-admin-scripts', 'awke_admin', [ 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('awke_ajax_nonce'), 'cpt_list_url' => admin_url('admin.php?page=awke-custom-post-types'), 'strings' => [ 'confirm_disable' => esc_html__('Are you sure you want to disable this widget?', 'advanced-widget-kit-for-elementor'), 'saving' => esc_html__('Saving...', 'advanced-widget-kit-for-elementor'), 'saved' => esc_html__('Saved!', 'advanced-widget-kit-for-elementor'), 'error' => esc_html__('Error occurred!', 'advanced-widget-kit-for-elementor'), 'widget_enabled' => esc_html__('Widget enabled successfully!', 'advanced-widget-kit-for-elementor'), 'widget_disabled' => esc_html__('Widget disabled successfully!', 'advanced-widget-kit-for-elementor'), ], 'version' => AWKE_VERSION, ]); } /** * Get Menu Icon * * Return the menu icon for the plugin. * * @since 1.0.0 * @access private * @return string Menu icon */ private function get_menu_icon() { // Use a custom SVG icon or dashicon return 'data:image/svg+xml;base64,' . base64_encode(' '); } /** * Dashboard Page * * Render the dashboard page. * * @since 1.0.0 * @access public */ public function dashboard_page() { require_once AWKE_PATH . 'admin/views/dashboard.php'; } /** * Custom Post Types Page * * Render the custom post types management page. * * @since 2.1.0 * @access public */ public function custom_post_types_page() { // Check if we're adding/editing a CPT if (isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id'])) { require_once AWKE_PATH . 'admin/views/custom-post-type-edit.php'; } elseif (isset($_GET['action']) && $_GET['action'] === 'add') { require_once AWKE_PATH . 'admin/views/custom-post-type-edit.php'; } else { require_once AWKE_PATH . 'admin/views/custom-post-types.php'; } } /** * Voice Input Settings Page * * Render the voice input settings page. * * @since 2.4.0 * @access public */ public function voice_settings_page() { // Handle settings save if (isset($_POST['awke_save_voice_settings']) && check_admin_referer('awke_voice_settings_nonce')) { update_option('awke_voice_enabled', isset($_POST['awke_voice_enabled']) ? '1' : '0'); update_option('awke_voice_language', sanitize_text_field($_POST['awke_voice_language'])); echo '

' . esc_html__('Voice Input Settings saved successfully!', 'advanced-widget-kit-for-elementor') . '

'; } // Get current settings $voice_enabled = get_option('awke_voice_enabled', '1'); $voice_language = get_option('awke_voice_language', 'en-US'); $languages = AWKE_Voice_Input::get_supported_languages(); ?>

🎤

🎤

  • ✅
  • ✅
  • ✅
  • ✅
  • ✅

' . esc_html__('Settings saved successfully!', 'advanced-widget-kit-for-elementor') . '

'; } ?>

prefix . 'awke_form_entries'; // Handle actions if (isset($_GET['action'])) { switch ($_GET['action']) { case 'view': $entry_id = isset($_GET['entry']) ? intval($_GET['entry']) : 0; if ($entry_id) { $entry = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE id = %d", $entry_id), ARRAY_A); if ($entry) { // Update status to read $wpdb->update( $table_name, ['status' => 'read'], ['id' => $entry_id], ['%s'], ['%d'] ); // Show entry details require_once AWKE_PATH . 'admin/views/form-entry-view.php'; return; } } break; case 'delete': $entry_id = isset($_GET['entry']) ? intval($_GET['entry']) : 0; if ($entry_id && check_admin_referer('delete_entry_' . $entry_id)) { $wpdb->delete($table_name, ['id' => $entry_id], ['%d']); wp_redirect(remove_query_arg(['action', 'entry', '_wpnonce'])); exit; } break; case 'export_csv': $this->export_entries_csv(); break; } } // Handle bulk actions if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'bulk-form_entries')) { $list_table = new AWKE_Form_Entries_List_Table(); $list_table->process_bulk_action(); } // Load the form entries view require_once AWKE_PATH . 'admin/views/form-entries.php'; } /** * Export Entries CSV * * Export form entries as CSV file. * * @since 2.0.1 * @access private */ private function export_entries_csv() { global $wpdb; $table_name = $wpdb->prefix . 'awke_form_entries'; // Get all entries $entries = $wpdb->get_results("SELECT * FROM $table_name ORDER BY submitted_at DESC", ARRAY_A); // Set headers for CSV download header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="form-entries-' . date('Y-m-d') . '.csv"'); // Create output stream $output = fopen('php://output', 'w'); // Add CSV headers fputcsv($output, ['ID', 'Form ID', 'Fields', 'IP Address', 'User Agent', 'Submitted At', 'Status']); // Add entries foreach ($entries as $entry) { $fields = json_decode($entry['field_data'], true); $fields_text = ''; foreach ($fields as $field) { $fields_text .= $field['label'] . ': ' . $field['value'] . ' | '; } $fields_text = rtrim($fields_text, ' | '); fputcsv($output, [ $entry['id'], $entry['form_id'], $fields_text, $entry['user_ip'], $entry['user_agent'], get_date_from_gmt($entry['submitted_at']), $entry['status'] ]); } fclose($output); exit; } /** * Ajax Toggle Widget * * Handle AJAX request to toggle widget status. * * @since 1.0.0 * @access public */ public function ajax_toggle_widget() { // Verify nonce if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'awke_ajax_nonce')) { wp_die(esc_html__('Security check failed', 'advanced-widget-kit-for-elementor')); } // Check user capabilities if (!current_user_can('manage_options')) { wp_die(esc_html__('You do not have sufficient permissions', 'advanced-widget-kit-for-elementor')); } $widget_key = isset($_POST['widget']) ? sanitize_text_field(wp_unslash($_POST['widget'])) : ''; $status = isset($_POST['status']) ? (bool) $_POST['status'] : false; // Update widget status AWKE_Elementor::instance()->update_widget_status($widget_key, $status); wp_send_json_success([ 'message' => esc_html__('Widget status updated successfully', 'advanced-widget-kit-for-elementor'), 'widget' => $widget_key, 'status' => $status ]); } /** * Ajax Get Form Entries Count * * Handle AJAX request to get unread form entries count. * * @since 2.0.1 * @access public */ public function ajax_get_form_entries_count() { // Verify nonce if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'awke_ajax_nonce')) { wp_send_json_error(['message' => esc_html__('Security check failed', 'advanced-widget-kit-for-elementor')]); } // Check user capabilities if (!current_user_can('manage_options')) { wp_send_json_error(['message' => esc_html__('You do not have sufficient permissions', 'advanced-widget-kit-for-elementor')]); } global $wpdb; $table_name = $wpdb->prefix . 'awke_form_entries'; // Check if table exists $table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name; if (!$table_exists) { wp_send_json_success(['count' => 0]); } // Get unread entries count $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name WHERE status = 'unread'"); wp_send_json_success([ 'count' => (int) $count, 'message' => sprintf( /* translators: %d: number of unread entries */ esc_html__('You have %d unread form entries', 'advanced-widget-kit-for-elementor'), $count ) ]); } /** * Plugin Action Links * * Add action links to the plugin page. * * @since 1.0.0 * @access public * @param array $links Existing links * @return array Modified links */ public function plugin_action_links($links) { $dashboard_link = sprintf( '%s', admin_url('admin.php?page=advanced-widget-kit-for-elementor'), esc_html__('Dashboard', 'advanced-widget-kit-for-elementor') ); $voice_link = sprintf( '%s', admin_url('admin.php?page=awke-voice-settings'), esc_html__('Voice Settings', 'advanced-widget-kit-for-elementor') ); $settings_link = sprintf( '%s', admin_url('admin.php?page=advanced-widget-kit-for-elementor-settings'), esc_html__('Settings', 'advanced-widget-kit-for-elementor') ); $pro_link = sprintf( '%s', 'https://awk.ainixit.com/', esc_html__('Upgrade to Pro', 'advanced-widget-kit-for-elementor') ); array_unshift($links, $dashboard_link, $voice_link, $settings_link, $pro_link); return $links; } /** * Get System Info * * Get system information for the dashboard. * * @since 1.0.0 * @access public * @return array */ public function get_system_info() { global $wp_version; return [ 'wp_version' => $wp_version, 'php_version' => PHP_VERSION, 'elementor_version' => defined('ELEMENTOR_VERSION') ? ELEMENTOR_VERSION : esc_html__('Not installed', 'advanced-widget-kit-for-elementor'), 'awke_version' => AWKE_VERSION, 'active_theme' => wp_get_theme()->get('Name'), 'memory_limit' => ini_get('memory_limit'), 'max_execution_time' => ini_get('max_execution_time'), ]; } /** * Get Widget Stats * * Get statistics about widgets. * * @since 1.0.0 * @access public * @return array */ public function get_widget_stats() { $enabled_widgets = AWKE_Elementor::instance()->get_enabled_widgets(); $free_widgets = [ 'button' => esc_html__('Button Widget', 'advanced-widget-kit-for-elementor'), 'testimonial' => esc_html__('Testimonial Widget', 'advanced-widget-kit-for-elementor'), 'pricing-table' => esc_html__('Pricing Table Widget', 'advanced-widget-kit-for-elementor'), 'image-box' => esc_html__('Image Box Widget', 'advanced-widget-kit-for-elementor'), 'icon-list' => esc_html__('Icon List Widget', 'advanced-widget-kit-for-elementor'), 'header' => esc_html__('Header Widget', 'advanced-widget-kit-for-elementor'), 'advanced-heading' => esc_html__('Advanced Heading Widget', 'advanced-widget-kit-for-elementor'), 'advanced-carousel' => esc_html__('Advanced Carousel Widget', 'advanced-widget-kit-for-elementor'), 'advanced-image-gallery' => esc_html__('Advanced Image Gallery Widget', 'advanced-widget-kit-for-elementor'), 'advanced-contact-form' => esc_html__('Advanced Contact Form Widget', 'advanced-widget-kit-for-elementor'), 'advanced-social-icons' => esc_html__('Advanced Social Icons Widget', 'advanced-widget-kit-for-elementor'), 'advanced-posts' => esc_html__('Advanced Posts Widget', 'advanced-widget-kit-for-elementor'), ]; $enabled_count = 0; foreach ($free_widgets as $key => $name) { if (isset($enabled_widgets[$key]) && $enabled_widgets[$key]) { $enabled_count++; } } return [ 'total_free' => count($free_widgets), 'enabled_free' => $enabled_count, 'total_pro' => 15, // Pro widgets count 'enabled_pro' => 0, // Will be overridden by Pro plugin ]; } }