prefix . 'akantio_pos_stock_syncs'; } public function findByPosOrderId( string $posOrderId ): ?array { global $wpdb; // No WordPress API exists for querying a plugin's own custom table // except $wpdb directly. $table is built entirely from $wpdb->prefix // (WP config, not user input) and a fixed string literal — never // user-controlled — so it's safe to interpolate; only the actual // value (pos_order_id) needs the %s placeholder $wpdb->prepare() // provides, since prepare() can't parameterize identifiers at all. $table = $this->table(); $row = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,PluginCheck.Security.DirectDB.UnescapedDBParameter $wpdb->prepare( "SELECT * FROM {$table} WHERE pos_order_id = %s", $posOrderId ), // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared ARRAY_A ); return $row ?: null; } public function create( string $posOrderId, array $productUpdates ): void { global $wpdb; // $wpdb->insert() already escapes values internally — this is the // WordPress-recommended safe API for writing to a custom table. $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $this->table(), [ 'pos_order_id' => $posOrderId, 'product_updates' => wp_json_encode( $productUpdates ), 'synced_at' => current_time( 'mysql', true ), ], [ '%s', '%s', '%s' ] ); } }