tec_is_file_from_plugins( string $file, string $plugin_files )

Checks if a file is from one of the specified plugins.


Parameters

$file

(string) (Required) The path of the file to check.

$plugin_files

(string) (Required) A set of plugin main files to check, e.g. the-events-calendar.php.


Top ↑

Return

(bool) Whether the file is from one of the specified plugins.


Top ↑

Source

File: src/functions/files.php

	function tec_is_file_from_plugins( string $file, string ...$plugin_files ): bool {
		static $wp_active_and_valid_plugins = null;

		if ( empty( $wp_active_and_valid_plugins ) ) {
			// The list is expensive to generate, so we cache it.
			$wp_active_and_valid_plugins = wp_get_active_and_valid_plugins();
		}

		$plugin_dirs = array_map(
			'dirname',
			array_filter( $wp_active_and_valid_plugins, static function ( string $plugin ) use ( $plugin_files ): bool {
				return in_array( basename( $plugin ), $plugin_files, true );
			} )
		);

		foreach ( $plugin_dirs as $plugin_dir ) {
			if ( strpos( $file, $plugin_dir ) !== false ) {
				return true;
			}
		}

		return false;
	}

Top ↑

Changelog

Changelog
Version Description
5.0.0 Introduced.