menu_slug, // The menu slug. array( $this, 'render_dashboard' ), // The rendered output function. apply_filters( 'zip_ai_menu_position', 1 ) // The position of this menu item in the menu. ); } /** * Verify if the user was given authorization to use Zip AI. * * @since 1.0.0 * @return void */ public function verify_authorization() { // If the current user does not have the required capability or the referrer is empty, then abandon ship. if ( ! current_user_can( 'manage_options' ) ) { return; } // Get the nonce. $nonce = ( isset( $_GET['nonce'] ) ) ? sanitize_key( $_GET['nonce'] ) : ''; // If the nonce is not valid, or if there's no token, then abandon ship. if ( false === wp_verify_nonce( $nonce, 'zip_ai_auth_nonce' ) ) { return; } // Redirect to the settings page if the user is trying to revoke the token. if ( isset( $_GET['revoke_zip_ai_authorization_token'] ) && 'definitely' === sanitize_text_field( $_GET['revoke_zip_ai_authorization_token'] ) ) { // Delete the Zip AI settings. Helper::delete_admin_settings_option( 'zip_ai_settings' ); // Redirect to the settings page. $redirection_url = apply_filters( 'zip_ai_revoke_redirection_url', admin_url() ); wp_safe_redirect( $redirection_url ); exit; }//end if // If none of the required data is received, abandon ship. if ( ! isset( $_GET['credit_token'] ) && ! isset( $_GET['token'] ) && ! isset( $_GET['email'] ) ) { return; } // Get the existing options, and update the auth token before updating the option. $db_settings_options = Helper::get_setting(); // Update the auth token if needed. if ( isset( $_GET['credit_token'] ) && is_string( $_GET['credit_token'] ) ) { $db_settings_options['auth_token'] = Utils::encrypt( sanitize_text_field( $_GET['credit_token'] ) ); } // Update the Zip token if needed. if ( isset( $_GET['token'] ) && is_string( $_GET['token'] ) ) { $db_settings_options['zip_token'] = Utils::encrypt( sanitize_text_field( $_GET['token'] ) ); } // Update the email if needed. if ( isset( $_GET['email'] ) && is_string( $_GET['email'] ) ) { $db_settings_options['email'] = sanitize_email( $_GET['email'] ); } // Update the Zip AI settings. Helper::update_admin_settings_option( 'zip_ai_settings', $db_settings_options ); // Redirect to the settings page. if ( apply_filters( 'zip_ai_auth_redirection_flag', true ) ) { $redirection_url = apply_filters( 'zip_ai_auth_redirection_url', admin_url( 'admin.php?page=zip-ai' ) ); wp_safe_redirect( $redirection_url ); exit; } } /** * Setup the Ajax Event to Entirely Disable the Zip AI Library from loading. * * @since 1.0.5 * @return void */ public function disabler_ajax() { // If the current user does not have the required capability, then abandon ship. if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } // Verify the nonce. check_ajax_referer( 'zip_ai_admin_nonce', 'nonce' ); // Have a variable to check if the module was disabled. $is_module_disabled = false; // Check if the Zip AI Assistant was requested to be disabled. if ( ! empty( $_POST['disable_zip_ai_assistant'] ) ) { $is_module_disabled = Module::disable( 'ai_assistant' ); } // Send the status based on whether the Zip AI Library is enabled or not. if ( $is_module_disabled ) { wp_send_json_success(); } else { wp_send_json_error(); } } /** * Setup the AI Assistant Toggle Ajax. * * @since 1.0.0 * @return void */ public function toggle_assistant_status_ajax() { // If the current user does not have the required capability, then abandon ship. if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } // Verify the nonce. check_ajax_referer( 'zip_ai_admin_nonce', 'nonce' ); // If the Zip options is not an array, then send an error. if ( empty( $_POST['enable_zip_chat'] ) || ! is_string( $_POST['enable_zip_chat'] ) ) { wp_send_json_error(); } // Create a variable to check if the assistant module was toggled. $is_module_toggled = false; // Update the enabled status. if ( 'enabled' === sanitize_text_field( $_POST['enable_zip_chat'] ) ) { $is_module_toggled = Module::enable( 'ai_assistant' ); } else { $is_module_toggled = Module::disable( 'ai_assistant' ); } // Send the status based on whether the module was toggled. if ( $is_module_toggled ) { wp_send_json_success(); } else { wp_send_json_error(); } } /** * Render the Zip AI Admin Settings Page. * * @since 1.0.0 * @return void */ public function render_dashboard() { // Render the dashboard app div. ?>