%s', esc_url( admin_url( 'admin.php?page=att-consent' ) ), esc_html__( 'Settings', 'att-consent' ) ); array_unshift( $links, $settings_link ); return $links; } /** * Register the admin menu page. */ public function add_menu_page() { add_menu_page( __( 'ATT Consent', 'att-consent' ), __( 'Cookie Consent', 'att-consent' ), 'manage_options', 'att-consent', array( $this, 'render_settings_page' ), 'dashicons-shield', 81 ); } /** * Enqueue admin assets. * * @param string $hook_suffix The current admin page hook. */ public function enqueue_assets( $hook_suffix ) { if ( 'toplevel_page_att-consent' !== $hook_suffix ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'att-consent-admin', ATT_CC_PLUGIN_URL . 'admin/css/admin.css', array(), ATT_CC_VERSION ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_script( 'att-consent-admin', ATT_CC_PLUGIN_URL . 'admin/js/admin.js', array( 'jquery', 'wp-color-picker' ), ATT_CC_VERSION, true ); wp_localize_script( 'att-consent-admin', 'attCCAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'att_cc_admin' ), 'strings' => array( 'confirmDelete' => __( 'Are you sure you want to delete this script?', 'att-consent' ), 'saved' => __( 'Script saved.', 'att-consent' ), 'deleted' => __( 'Script deleted.', 'att-consent' ), 'error' => __( 'An error occurred. Please try again.', 'att-consent' ), ), ) ); } /** * Render the settings page. */ public function render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $active_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'general'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tabs = array( 'general' => __( 'General', 'att-consent' ), 'appearance' => __( 'Appearance', 'att-consent' ), 'categories' => __( 'Categories', 'att-consent' ), 'scripts' => __( 'Custom Scripts', 'att-consent' ), 'advanced' => __( 'Advanced', 'att-consent' ), ); $settings = ATT_Consent::get_settings(); ?>

' . esc_html__( 'Settings saved.', 'att-consent' ) . '

'; } ?>
10000 ) { $settings['wait_for_update'] = 10000; } break; } $settings = apply_filters( 'att_consent_settings_save', $settings, $tab ); update_option( 'att_consent_settings', $settings ); wp_safe_redirect( admin_url( 'admin.php?page=att-consent&tab=' . $tab . '&saved=1' ) ); exit; } /** * AJAX: Save a custom script. */ public function ajax_save_script() { check_ajax_referer( 'att_cc_admin', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $data = array( 'id' => absint( $_POST['script_id'] ?? 0 ) ?: null, 'name' => $_POST['name'] ?? '', 'snippet' => $_POST['snippet'] ?? '', 'category' => $_POST['category'] ?? 'analytics', 'placement' => $_POST['placement'] ?? 'head', 'status' => $_POST['status'] ?? 'active', 'priority' => $_POST['priority'] ?? 10, ); $result = ATT_Consent_Scripts_Manager::save_script( $data ); if ( false !== $result ) { wp_send_json_success( array( 'id' => $result, 'scripts' => ATT_Consent_Scripts_Manager::get_all_scripts(), ) ); } else { wp_send_json_error( 'Failed to save script.' ); } } /** * AJAX: Delete a custom script. */ public function ajax_delete_script() { check_ajax_referer( 'att_cc_admin', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $id = absint( $_POST['script_id'] ?? 0 ); if ( ! $id ) { wp_send_json_error( 'Invalid ID.' ); } if ( ATT_Consent_Scripts_Manager::delete_script( $id ) ) { wp_send_json_success( array( 'scripts' => ATT_Consent_Scripts_Manager::get_all_scripts(), ) ); } else { wp_send_json_error( 'Failed to delete script.' ); } } /** * AJAX: Get a single script for editing. */ public function ajax_get_script() { check_ajax_referer( 'att_cc_admin', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $id = absint( $_POST['script_id'] ?? 0 ); $script = ATT_Consent_Scripts_Manager::get_script( $id ); if ( $script ) { wp_send_json_success( $script ); } else { wp_send_json_error( 'Script not found.' ); } } }