esc_url(admin_url('admin-ajax.php')),'nonce' => wp_create_nonce('ajax-nonce'))); } } if ( !function_exists( 'aha_share' )) { function aha_share() { $nonce = sanitize_key($_POST['_ajax_nonce']); if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) die ( 'Access denied..'); require __DIR__ . "/admin/aha_share.php"; } } if ( !function_exists( 'aha_login' )) { function aha_login() { $nonce = sanitize_key($_POST['_ajax_nonce']); if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) die ( 'Access denied..'); require __DIR__ . "/admin/aha_login.php"; } } if ( !function_exists( 'aha_single_books' )) { function aha_single_books() { $nonce = sanitize_key($_POST['_ajax_nonce']); if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) die ( 'Access denied..'); require __DIR__ . "/admin/aha_single_books.php"; } } if ( !function_exists( 'ajax_ahathat_widget' )) { function ajax_ahathat_widget() { $nonce = sanitize_key($_POST['_ajax_nonce']); if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) die ( 'Access denied..'); $action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : 'list'; echo $action; die(); } } if ( !function_exists( 'aha_save' )) { function aha_save(){ if ( ! isset( $_POST['submit_widget'] ) ) { return; } if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'new-widget' ) ) { die( _( 'Are you cheating?', 'aha' ) ); } if ( ! current_user_can( 'read' ) ) { wp_die( _( 'Permission Denied!', 'aha' ) ); } $errors = array(); $page_url = admin_url( 'admin.php?page=AHAthat_widget' ); $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0; $name = isset( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : ''; // some basic validation if ( ! $name ) { $errors[] = _( 'Error: Name is required', 'aha' ); } // bail out if error found if ( $errors ) { $first_error = reset( $errors ); $redirect_to = add_query_arg( array( 'error' => $first_error ), $page_url ); wp_safe_redirect( $redirect_to ); exit; } $fields = array( 'name' => $name, ); // New or edit? if ( ! $field_id ) { $insert_id = aha_insert_widget( $fields ); } else { $fields['id'] = $field_id; $insert_id = aha_insert_widget( $fields ); } if ( is_wp_error( $insert_id ) ) { $redirect_to = add_query_arg( array( 'message' => 'error' ), $page_url ); } else { $redirect_to = add_query_arg( array( 'message' => 'success' ), $page_url ); } wp_safe_redirect( $redirect_to ); exit; } } add_action( 'admin_init', 'aha_save' ); add_action('wp_ajax_ahathat_widget', 'ajax_ahathat_widget'); add_action('wp_ajax_nopriv_ahathat_widget', 'ajax_ahathat_widget'); add_shortcode("aha_key", "aha_key");