post_author ) ) return; if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) return; if ( current_user_can( 'manage_options' ) ) return; // Admin saves bypass // Force pending status remove_action( 'save_post_product', [ $this, 'intercept_save' ], 10 ); wp_update_post( [ 'ID' => $post_id, 'post_status' => 'pending' ] ); add_action( 'save_post_product', [ $this, 'intercept_save' ], 10, 2 ); global $wpdb; $exists = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}vv_product_approvals WHERE product_id=%d AND status='pending'", $post_id ) ); if ( ! $exists ) { $wpdb->insert( "{$wpdb->prefix}vv_product_approvals", [ 'product_id' => $post_id, 'vendor_id' => (int) $post->post_author, 'status' => 'pending', ] ); } } public static function admin_page() { global $wpdb; // Handle approve/reject if ( isset( $_POST['vv_approval_action'], $_POST['vv_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['vv_nonce'] ), 'vv_approval_action' ) ) { $pid = (int) $_POST['product_id']; $action = sanitize_text_field( $_POST['vv_approval_action'] ); $notes = sanitize_textarea_field( $_POST['admin_notes'] ?? '' ); $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}vv_product_approvals WHERE product_id=%d", $pid ) ); if ( $row ) { if ( $action === 'approve' ) { wp_update_post( [ 'ID' => $pid, 'post_status' => 'publish' ] ); $wpdb->update( "{$wpdb->prefix}vv_product_approvals", [ 'status' => 'approved', 'admin_notes' => $notes, 'reviewed_at' => current_time('mysql') ], [ 'id' => $row->id ] ); do_action( 'vv_product_approved', $row->vendor_id, $pid ); echo '
Product approved and published.
Product rejected.
| Product | Vendor | Submitted | Status | Notes | Actions |
|---|---|---|---|---|---|
| ' . esc_html( $a->post_title ) . ' | '; echo '' . esc_html( $a->vendor_name ) . ' | '; echo '' . esc_html( date('Y-m-d', strtotime($a->submitted_at)) ) . ' | '; $badge = ['pending'=>'#f0c040','approved'=>'#00a32a','rejected'=>'#d63638'][$a->status] ?? '#999'; echo '' . esc_html($a->status) . ' | '; echo '' . esc_html( $a->admin_notes ) . ' | '; echo ''; if ( $a->status === 'pending' ) { echo ''; } echo ' |