$envelope MetaBackstop's envelope. * @return array|WP_Error */ public function replay( ActionDescriptor $action, array $envelope ): array|WP_Error { $post_id = absint( $envelope['post_id'] ?? 0 ); $key = is_string( $envelope['key'] ?? null ) ? $envelope['key'] : ''; if ( null === MetaBackstop::field( (string) get_post_type( $post_id ), $key ) ) { return new WP_Error( 'adafwc_meta_not_guarded', __( 'This is not a store value the add-on guards.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ); } if ( ! current_user_can( 'edit_post', $post_id ) ) { return new WP_Error( 'adafwc_meta_forbidden', __( 'The agent\'s WordPress user may no longer edit this.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ); } $value = $envelope['value'] ?? null; $written = match ( $envelope['operation'] ?? 'update' ) { 'add' => add_post_meta( $post_id, $key, $value ), 'delete' => delete_post_meta( $post_id, $key, $value ), default => update_post_meta( $post_id, $key, $value ), }; if ( in_array( get_post_type( $post_id ), array( 'product', 'product_variation' ), true ) ) { wc_delete_product_transients( $post_id ); } return array( 'written' => false !== $written ); } }