PHP code example of automattic / jetpack-feature-flags

1. Go to this page and download the library: Download automattic/jetpack-feature-flags library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

automattic / jetpack-feature-flags example snippets


use Automattic\Jetpack\Feature_Flags\Feature_Flags;

Feature_Flags::register(
	'my-product-new-flow',
	array(
		'default'     => false,
		'description' => 'Enable the new product flow.',
		'owner'       => 'my-product',
	)
);

if ( Feature_Flags::is_enabled( 'my-product-new-flow' ) ) {
	// Load the feature.
}

add_filter(
	'jetpack_feature_flag_enabled',
	static function ( bool $enabled, string $flag_name, array $definition ): bool {
		if ( 'my-product-new-flow' === $flag_name ) {
			return true;
		}

		return $enabled;
	},
	10,
	3
);

add_filter( 'jetpack_feature_flag_enabled_my-product-new-flow', '__return_true' );