← All changes
|
includes/_front_end/class-fe-form-source-resolver.php
+50
-25
11.4
→
11.9
View file →
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Front-End Booking Form Source Resolver |
| 4 | 4 | * |
| @@ -108,22 +108,22 @@ | ||
| 108 | 108 | if ( 'preview' !== $status ) { |
| 109 | 109 | $status = 'published'; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - // If BFB runtime is not present. | |
| 113 | - if ( ! class_exists( 'WPBC_BFB_Form_Loader' ) ) { | |
| 114 | - return self::missing_bfb_result( 'bfb_loader_missing' ); | |
| 115 | - } | |
| 112 | + // If BFB runtime is not present. | |
| 113 | + if ( ! class_exists( 'WPBC_BFB_Form_Loader' ) ) { | |
| 114 | + return self::filter_resolution( self::missing_bfb_result( 'bfb_loader_missing' ), $req ); | |
| 115 | + } | |
| 116 | 116 | |
| 117 | - // If storage is not available. | |
| 118 | - if ( ! class_exists( 'WPBC_BFB_Form_Storage' ) || ! method_exists( 'WPBC_BFB_Form_Storage', 'get_form_row_by_key' ) ) { | |
| 119 | - return self::missing_bfb_result( 'bfb_storage_missing' ); | |
| 120 | - } | |
| 117 | + // If storage is not available. | |
| 118 | + if ( ! class_exists( 'WPBC_BFB_Form_Storage' ) || ! method_exists( 'WPBC_BFB_Form_Storage', 'get_form_row_by_key' ) ) { | |
| 119 | + return self::filter_resolution( self::missing_bfb_result( 'bfb_storage_missing' ), $req ); | |
| 120 | + } | |
| 121 | 121 | |
| 122 | - // Optional: if table does not exist, return missing. | |
| 123 | - if ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) { | |
| 124 | - return self::missing_bfb_result( 'bfb_table_missing' ); | |
| 125 | - } | |
| 122 | + // Optional: if table does not exist, return missing. | |
| 123 | + if ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) { | |
| 124 | + return self::filter_resolution( self::missing_bfb_result( 'bfb_table_missing' ), $req ); | |
| 125 | + } | |
| 126 | 126 | |
| 127 | 127 | // --------------------------------------------------------------------- |
| 128 | 128 | // Step B: determine owner_user_id (MultiUser, filterable). |
| 129 | 129 | // --------------------------------------------------------------------- |
| @@ -203,21 +203,46 @@ | ||
| 203 | 203 | 'bfb_loader_args' => $bfb_args, |
| 204 | 204 | 'fallback_chain' => $fallback_chain, |
| 205 | 205 | ); |
| 206 | 206 | |
| 207 | - /** | |
| 208 | - * // Info: Hook for addons. Final override point (future scopes, preview rules, etc). | |
| 209 | - * | |
| 210 | - * @param array $result | |
| 211 | - * @param array $req | |
| 212 | - */ | |
| 213 | - return (array) apply_filters( 'wpbc_fe_form_source_resolution', $result, $req ); | |
| 214 | - } | |
| 215 | - | |
| 216 | - return self::missing_bfb_result( 'bfb_form_not_found', $fallback_chain ); | |
| 217 | - } | |
| 218 | - | |
| 219 | - // --------------------------------------------------------------------- | |
| 207 | + return self::filter_resolution( $result, $req ); | |
| 208 | + } | |
| 209 | + | |
| 210 | + return self::filter_resolution( self::missing_bfb_result( 'bfb_form_not_found', $fallback_chain ), $req ); | |
| 211 | + } | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * Apply the final source-resolution extension point to every outcome. | |
| 215 | + * | |
| 216 | + * Preview and other non-persistent sources may be authoritative even when a | |
| 217 | + * matching database row does not exist. Applying the filter to both resolved | |
| 218 | + * and missing results lets those sources participate without creating a | |
| 219 | + * temporary Form Builder record. | |
| 220 | + * | |
| 221 | + * @param array $result Normalized resolver result. | |
| 222 | + * @param array $req Original normalized request context. | |
| 223 | + * | |
| 224 | + * @return array Filtered resolver result. | |
| 225 | + */ | |
| 226 | + private static function filter_resolution( $result, $req ) { | |
| 227 | + | |
| 228 | + $result = is_array( $result ) ? $result : array(); | |
| 229 | + $req = is_array( $req ) ? $req : array(); | |
| 230 | + | |
| 231 | + /** | |
| 232 | + * Filter the final booking-form source resolution. | |
| 233 | + * | |
| 234 | + * This hook runs for successful database resolutions and controlled missing | |
| 235 | + * results so authenticated, non-persistent sources can provide a complete | |
| 236 | + * replacement contract. | |
| 237 | + * | |
| 238 | + * @param array $result Normalized resolver result. | |
| 239 | + * @param array $req Source request context. | |
| 240 | + */ | |
| 241 | + return (array) apply_filters( 'wpbc_fe_form_source_resolution', $result, $req ); | |
| 242 | + } | |
| 243 | + | |
| 244 | + // --------------------------------------------------------------------- | |
| 220 | 245 | // Internals |
| 221 | 246 | // --------------------------------------------------------------------- |
| 222 | 247 | |
| 223 | 248 | /** |