add_features( [ // ... ] ); register_setting( 'flatsome-features', 'flatsome_features' ); } /** * Add settings for experimental features. * * @param array $features Experiments to add. */ private function add_features( array $features ) { foreach ( $features as $id => $args ) { add_settings_field( $id, $args['title'], [ $this, 'render_field' ], 'flatsome-features', 'flatsome_' . $args['section'] . '_section', array_merge( $args, [ 'id' => $id ] ) ); } } /** * Renders above the «Features» settings. */ public function render_features_section() {} /** * Renders above the «Experimental features» settings. */ public function render_experimental_features_section() { global $wp_settings_fields; if ( empty( $wp_settings_fields['flatsome-features']['flatsome_experimental_features_section'] ) ) { echo '
' . esc_html__( 'There are currently no experimental features in development.', 'flatsome' ) . '
'; } else { echo '' . esc_html__( "Features that are testable while they're in development. These features are likely to change, so avoid using them in production.", 'flatsome' ) . '
'; } } /** * Renders a checkbox field for a feature. * * @param array $args Field arguments. */ public function render_field( array $args ) { global $wp_version; $value = flatsome_is_feature_enabled( $args['id'] ) ? 1 : 0; $id = 'flatsome-feature-' . $args['id']; $is_php_supported = isset( $args['requires_php'] ) ? version_compare( PHP_VERSION, $args['requires_php'], '>=' ) : true; $is_wp_supported = isset( $args['requires_at_least'] ) ? version_compare( $wp_version, $args['requires_at_least'], '>=' ) : true; $disabled = ! $is_php_supported || ! $is_wp_supported; echo ''; $styles = 'margin-top:6px;padding-left:calc(20px + 0.25rem);color:#a7aaad;font-size:13px;'; if ( $value && ! empty( $args['links'] ) ) { echo '' . sprintf( esc_html__( 'This feature requires PHP version %s or higher.', 'flatsome' ), $args['requires_php'] ) . '
'; } if ( ! $is_wp_supported ) { // translators: %s: WordPress version. echo '' . sprintf( esc_html__( 'This feature requires WordPress version %s or higher.', 'flatsome' ), $args['requires_at_least'] ) . '
'; } echo '