get_charset_collate(); $table_name = $wpdb->prefix . 'fea_submissions'; $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, title text NOT NULL, created_at datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, user int NOT NULL, fields longtext NOT NULL, form text NOT NULL, status text NOT NULL, UNIQUE KEY id (id) ) $charset_collate;"; include_once ABSPATH . 'wp-admin/includes/upgrade.php'; maybe_create_table( $table_name, $sql ); } public function insert_submission( $args ) { global $wpdb; if( empty( $args['created_at'] ) ){ $args['created_at'] = current_time( 'mysql' ); } if ( empty( $args['title'] ) ) { $args['title'] = '(no name)'; } $wpdb->insert( $wpdb->prefix . 'fea_submissions', $args ); $submits_count = get_option( 'frontend_admin_submissions_all_time', 0 ); $submits_count++; update_option( 'frontend_admin_submissions_all_time', $submits_count ); return $wpdb->insert_id; } public function update_submission( $id, $args ) { if ( isset( $args['fields'] ) && is_array( $args['fields'] ) ) { $args['fields'] = fea_encrypt( json_encode( $args['fields'] ) ); } global $wpdb; $wpdb->update( $wpdb->prefix . 'fea_submissions', $args, array( 'id' => $id ) ); } public function approve_submission( $id ) { global $wpdb; $submission = $this->get_submission( $id ); if ( $submission->status == 'pending' ) { $form = $this->get_form( $submission ); foreach ( fea_instance()->local_actions as $action ) { $name = $action->get_name(); $form = $action->run( $form ); } $wpdb->update( $wpdb->prefix . 'fea_submissions', array( 'status' => 'approved' ), array( 'id' => $id ) ); } } public function get_submission( $id = 0 ) { if ( ! $id ) { return $id; } global $wpdb; $id = (int) $id; $submission = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fea_submissions WHERE id = %d", $id ) ); $submission = maybe_unserialize( $submission ); $submission = wp_unslash( $submission ); return $submission; } public function get_status_label( $slug ) { switch ( $slug ) { case 'in_progress': return __( 'In Progress', 'frontend-admin' ); case 'require_approval': return __( 'Pending Approval', 'frontend-admin' ); case 'verify_email': return __( 'Pending Email Verification', 'frontend-admin' ); case 'email_verified': return __( 'Email Verified', 'frontend-admin' ); case 'pending_payment': return __( 'Pending Payment', 'frontend-admin' ); case 'payment_received': return __( 'Payment Received', 'frontend-admin' ); case 'approved': return __( 'Approved', 'frontend-admin' ); default: return $slug; } } /** * Retrieve submissions data from the database * * @param array $args query arguments * * @return mixed */ /** * Retrieve submissions data from the database * * @param array $args query arguments * * @return mixed */ public static function get_submissions( $args = array() ) { if ( ! current_user_can( 'edit_posts' ) ) { return false; } // Parse and sanitize request parameters $args = wp_parse_args( $args, [ 'orderby' => isset( $_REQUEST['orderby'] ) ? sanitize_key( $_REQUEST['orderby'] ) : '', 'order' => isset( $_REQUEST['order'] ) ? strtoupper( sanitize_text_field( $_REQUEST['order'] ) ) : '', 'per_page' => isset( $_REQUEST['per_page'] ) ? (int) $_REQUEST['per_page'] : 10, 'paged' => isset( $_REQUEST['paged'] ) ? max( 1, (int) $_REQUEST['paged'] ) : 1, ] ); // Allowlisted columns and order directions $allowed_orderby = [ 'created_at', 'title', 'status' ]; // Modify this list to match your DB columns $allowed_order = [ 'ASC', 'DESC' ]; $orderby = in_array( $args['orderby'], $allowed_orderby, true ) ? $args['orderby'] : 'created_at'; $order = in_array( $args['order'], $allowed_order, true ) ? $args['order'] : 'DESC'; $per_page = (int) $args['per_page']; $current_page = (int) $args['paged']; $offset = ( $current_page - 1 ) * $per_page; // Base query - update table name accordingly global $wpdb; $table = $wpdb->prefix . 'fea_submissions'; $sql = "SELECT * FROM `$table`"; // Append search query if any if ( ! empty( $_REQUEST['s'] ) ) { $search = sanitize_text_field( $_REQUEST['s'] ); $sql .= $wpdb->prepare( ' WHERE title LIKE %s', '%' . $wpdb->esc_like( $search ) . '%' ); } // Append ORDER BY $sql .= " ORDER BY `$orderby` $order"; // Pagination if ( $per_page !== -1 ) { $sql .= $wpdb->prepare( ' LIMIT %d OFFSET %d', $per_page, $offset ); } // Append WHERE clause if any filters are applied if ( ! empty( $args['form'] ) ) { $sql .= $wpdb->prepare( ' WHERE form = %s', $args['form'] ); } global $current_screen; // Execute query $results = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- values are added with $wpdb->prepare() and identifiers come from an allowlist above. // Send response return $results; } /** * Returns the count of records in the database. * * @return null|string */ public static function record_count( $args = array() ) { global $wpdb; $sql = "SELECT COUNT(form) FROM {$wpdb->prefix}fea_submissions"; if ( ! empty( $args['form'] ) ) { $form = true; $sql .= $wpdb->prepare( ' WHERE form = %s', $args['form'] ); } if ( ! empty( $args['form_key'] ) ) { if ( isset( $form ) ) { $sql .= ' OR'; } else { $sql .= ' WHERE'; } $sql .= $wpdb->prepare( ' form = %s', $args['form_key'] ); $form = true; } if ( ! empty( $args['form_id'] ) ) { if ( isset( $form ) ) { $sql .= ' OR'; } else { $sql .= ' WHERE'; } $sql .= $wpdb->prepare( ' form = %d', $args['form_id'] ); } return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- values are added with $wpdb->prepare() and identifiers come from an allowlist above. } public function delete_submission( $id = 0 ) { if ( $id == 0 ) { return $id; } global $wpdb; $wpdb->delete( $wpdb->prefix . 'fea_submissions', array( 'id' => $id ) ); return 1; } public function display_submissions() { include_once __DIR__ . '/list.php'; $display_list = true; if ( isset( $_REQUEST['id'] ) ) { $submission_id = absint( $_REQUEST['id'] ); $submission = $this->get_submission( $submission_id ); if ( $submission ) { $user = get_user_by( 'ID', $submission->user ); if ( is_object( $user ) ) { $title = $user->display_name . ' (' . $user->user_login . ')'; } else { $title = '--'; } ?>
fields ), true ); $record = $record['record'] ?? $record; if ( ! empty( $record['approved_by'] ) ) { $approver = get_user_by( 'ID', $record['approved_by'] ); if ( is_object( $approver ) ) { echo '' . esc_html( sprintf( /* translators: 1: value 2: value 3: value */ __( 'Approved by %1$s (%2$s) on %3$s', 'frontend-admin' ), $approver->display_name, $approver->user_login, $record['approved_at'] ?? '' ) ) . '
'; } } $action = fea_instance()->submissions_list->current_action(); if ( $action == 'edit' ) { $form = $this->get_form( $submission, array(), true, true ); if( ! $form ){ echo ''. esc_html__( 'Form not found.', 'frontend-admin' ) .'