# top-10/4.5.2/includes/class-feature-manager.php

WebberZone Top 10 — Popular Posts, version 4.5.2. 153 lines.

- Page: https://pluginprobe.com/plugins/top-10/4.5.2/code/includes/class-feature-manager.php
- Raw: https://pluginprobe.com/plugins/top-10/4.5.2/raw/includes/class-feature-manager.php
- Modified: 2026-10-08T02:44:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/top-10/4.5.2/code/includes/class-feature-manager.php#L10-L20`.

```php
<?php
/**
 * Feature Manager.
 *
 * Central gate that decides which optional plugin features are loaded.
 *
 * @package WebberZone\Top_Ten
 */

namespace WebberZone\Top_Ten;

if ( ! defined( 'WPINC' ) ) {
	die;
}

/**
 * Feature Manager class.
 *
 * All features default to enabled — a missing settings key means the feature is on, so
 * upgrades see no change in behaviour. Reads the raw settings option directly instead
 * of tptn_get_option(), which would load the admin Settings class on every request;
 * this makes the check safe to call at plugins_loaded.
 *
 * @since 4.4.0
 */
class Feature_Manager {

	/**
	 * Cached copy of the settings option.
	 *
	 * @since 4.4.0
	 *
	 * @var array|null
	 */
	private static $settings = null;

	/**
	 * Get the map of toggleable features.
	 *
	 * @since 4.4.0
	 *
	 * @return array Associative array of feature ID => array with 'setting' and 'default' keys.
	 */
	public static function get_features(): array {
		$features = array(
			'blocks'                  => array(
				'setting' => 'enable_blocks',
				'default' => true,
			),
			'feed'                    => array(
				'setting' => 'enable_feed',
				'default' => true,
			),
			'legacy_widgets'          => array(
				'setting' => 'enable_legacy_widgets',
				'default' => true,
			),
			'rest_api'                => array(
				'setting' => 'enable_rest_api',
				'default' => true,
			),
			'lazy_load'               => array(
				'setting' => 'enable_lazy_load',
				'default' => true,
			),
			'query_block'             => array(
				'setting' => 'enable_query_block',
				'default' => true,
			),
			'featured_image_block'    => array(
				'setting' => 'enable_featured_image_block',
				'default' => true,
			),
			'popular_posts_pro_block' => array(
				'setting' => 'enable_popular_posts_pro_block',
				'default' => true,
			),
			'fast_tracker'            => array(
				'setting' => 'enable_fast_tracker',
				'default' => true,
			),
			'pro_dashboard_widgets'   => array(
				'setting' => 'enable_pro_dashboard_widgets',
				'default' => true,
			),
			'popular_authors'         => array(
				'setting' => 'enable_popular_authors',
				'default' => true,
			),
			'page_builders'           => array(
				'setting' => 'enable_page_builders',
				'default' => true,
			),
			'sitewide_tracking'       => array(
				'setting' => 'enable_sitewide_tracking',
				'default' => true,
			),
			'daily_table_rollup'      => array(
				'setting' => 'enable_daily_table_rollup',
				'default' => true,
			),
		);

		/**
		 * Filter the map of toggleable features.
		 *
		 * @since 4.4.0
		 *
		 * @param array $features Associative array of feature ID => array with 'setting' and 'default' keys.
		 */
		return apply_filters( 'tptn_features', $features );
	}

	/**
	 * Whether a feature is enabled.
	 *
	 * A feature is enabled when its setting is missing (default) or truthy.
	 * Unknown feature IDs are treated as enabled.
	 *
	 * @since 4.4.0
	 *
	 * @param string $feature Feature ID.
	 * @return bool Whether the feature is enabled.
	 */
	public static function is_enabled( string $feature ): bool {
		$features = self::get_features();

		if ( isset( $features[ $feature ] ) ) {
			$setting = $features[ $feature ]['setting'];
			$default = ! empty( $features[ $feature ]['default'] );

			if ( null === self::$settings ) {
				$settings       = get_option( 'tptn_settings' );
				self::$settings = is_array( $settings ) ? $settings : array();
			}

			$enabled = isset( self::$settings[ $setting ] ) ? ! empty( self::$settings[ $setting ] ) : $default;
		} else {
			$enabled = true;
		}

		/**
		 * Filter whether a feature is enabled.
		 *
		 * @since 4.4.0
		 *
		 * @param bool   $enabled Whether the feature is enabled.
		 * @param string $feature Feature ID.
		 */
		return (bool) apply_filters( 'tptn_feature_enabled', $enabled, $feature );
	}
}

```
