PHP code example of alleyinteractive / wp-experimental-features

1. Go to this page and download the library: Download alleyinteractive/wp-experimental-features 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/ */

    

alleyinteractive / wp-experimental-features example snippets


/**
 * Define available feature flags.
 *
 * @param array $flags Feature flags that have been defined for the Experimental Features plugin.
 *
 * @return array The modified list of feature flags.
 */
function filter_experimental_features_flags( $flags ): array {
	$flags['my-cool-feature'] = __( 'My Cool Feature', 'my-textdomain' );

	return $flags;
}
add_filter(
	'experimental_features_flags',
	__NAMESPACE__ . '\filter_experimental_features_flags'
);

$is_enabled = apply_filters(
	'experimental_features_flag',
	false,
	'my-cool-feature'
);

/**
 * A helper function for determining if a feature flag is enabled.
 *
 * @param string $slug The feature flag slug to check.
 *
 * @return bool True if enabled, false if not.
 */
function my_theme_flag_enabled( string $slug ): bool {
	return (bool) apply_filters(
		'experimental_features_flag',
		false,
		$slug
	);
}

add_action( 'experimental_features_show_admin_bar', '__return_false' )

add_action(
	'experimental_features_flags_updated',
	function( $enabled, $disabled ) {
		// ...
	},
	10,
	2,
);

add_action( 'experimental_features_flag_enabled_{feature-flag}', function() { ... } );

add_action( 'experimental_features_flag_disabled_{feature-flag}', function() { ... } );

add_filter( 'experimental_features_rest_api_enabled', '__return_true' );

add_filter(
	'experimental_features_rest_permission_callback',
	function () {
		return current_user_can( 'manage_options' );
	},
);

add_filter(
	'experimental_features_rest_api_flags',
	function ( $flags ) {
		return array_filter(
			$flags,
			 function ( $flag ) {
				// Only return the 'my-cool-feature' flag.
				return 'my-cool-feature' === $flag;
			},
			ARRAY_FILTER_USE_KEY
		);
	}
);