← All changes
|
jetpack_vendor/automattic/jetpack-forms/src/class-jetpack-forms.php
+19
-29
16.3-a.3
→
16.3-beta
View file →
| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Forms; |
| 9 | 9 | |
| 10 | -use Automattic\Jetpack\Feature_Flags\Feature_Flags; | |
| 10 | +use Automattic\Jetpack\Current_Plan; | |
| 11 | 11 | use Automattic\Jetpack\Forms\ContactForm\Feedback_Source; |
| 12 | 12 | use Automattic\Jetpack\Forms\ContactForm\Util; |
| 13 | 13 | use Automattic\Jetpack\Forms\Dashboard\Dashboard; |
| 14 | 14 | /** |
| @@ -15,41 +15,19 @@ | ||
| 15 | 15 | * Understands the Jetpack Forms package. |
| 16 | 16 | */ |
| 17 | 17 | class Jetpack_Forms { |
| 18 | 18 | |
| 19 | - const PACKAGE_VERSION = '8.2.0'; | |
| 19 | + const PACKAGE_VERSION = '8.3.0'; | |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Name of the feature flag gating field conditional logic. | |
| 22 | + * Plan feature slug gating field conditional logic. | |
| 23 | 23 | */ |
| 24 | - const CONDITIONAL_LOGIC_FLAG = 'forms-conditional-logic'; | |
| 24 | + const CONDITIONAL_LOGIC_FEATURE = 'form-conditional-logic'; | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Register the package's feature flags. | |
| 28 | - * | |
| 29 | - * Registration is unconditional and happens as the package loads, so the full set stays | |
| 30 | - * discoverable through `Feature_Flags::all()` and nothing can call `is_enabled()` on an | |
| 31 | - * unregistered flag. | |
| 32 | - * | |
| 33 | - * @return void | |
| 34 | - */ | |
| 35 | - public static function register_feature_flags() { | |
| 36 | - Feature_Flags::register( | |
| 37 | - self::CONDITIONAL_LOGIC_FLAG, | |
| 38 | - array( | |
| 39 | - 'default' => false, | |
| 40 | - 'description' => 'Show or hide a form field based on the answer to another field.', | |
| 41 | - 'owner' => 'jetpack-forms', | |
| 42 | - ) | |
| 43 | - ); | |
| 44 | - } | |
| 45 | - | |
| 46 | - /** | |
| 47 | 27 | * Load the contact form module. |
| 48 | 28 | */ |
| 49 | 29 | public static function load_contact_form() { |
| 50 | - self::register_feature_flags(); | |
| 51 | - | |
| 52 | 30 | Util::init(); |
| 53 | 31 | |
| 54 | 32 | if ( self::is_feedback_dashboard_enabled() ) { |
| 55 | 33 | $dashboard = new Dashboard(); |
| @@ -160,21 +138,33 @@ | ||
| 160 | 138 | return apply_filters( 'jetpack_forms_is_integrations_enabled', true ); |
| 161 | 139 | } |
| 162 | 140 | |
| 163 | 141 | /** |
| 164 | - * Returns true if field conditional logic is enabled. | |
| 142 | + * Returns true if the site's plan includes field conditional logic. | |
| 165 | 143 | * |
| 166 | 144 | * One switch for the whole feature: the editor panel, the front-end show/hide, and the |
| 167 | 145 | * submission-time enforcement in validation and storage. Gating them together means a |
| 168 | 146 | * form can never hide a field from the visitor while still requiring it on submit. |
| 169 | 147 | * |
| 170 | - * Turning the flag off on a form that already has conditions is safe: the conditions are | |
| 148 | + * Losing the plan on a form that already has conditions is safe: the conditions are | |
| 171 | 149 | * simply ignored, so every field renders, validates and stores as an ordinary field. |
| 172 | 150 | * |
| 173 | 151 | * @return boolean |
| 174 | 152 | */ |
| 175 | 153 | public static function is_conditional_logic_enabled() { |
| 176 | - return Feature_Flags::is_enabled( self::CONDITIONAL_LOGIC_FLAG ); | |
| 154 | + // Fail closed on WordPress.com until its WPCOM_Features copy knows the slug, or supports() | |
| 155 | + // falls back to the Jetpack free plan, which includes it. Drop once that copy ships. | |
| 156 | + $supported = ( ! function_exists( 'wpcom_feature_exists' ) || wpcom_feature_exists( self::CONDITIONAL_LOGIC_FEATURE ) ) | |
| 157 | + && Current_Plan::supports( self::CONDITIONAL_LOGIC_FEATURE ); | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Whether field conditional logic is available on this site. | |
| 161 | + * | |
| 162 | + * @since 8.3.0 | |
| 163 | + * | |
| 164 | + * @param bool $supported Whether the site's plan includes conditional logic. | |
| 165 | + */ | |
| 166 | + return (bool) apply_filters( 'jetpack_forms_conditional_logic_enabled', $supported ); | |
| 177 | 167 | } |
| 178 | 168 | |
| 179 | 169 | /** |
| 180 | 170 | * Returns true if webhooks are enabled. |