[ 'slug' => 'essential-addons-elementor', 'plugin_file' => 'essential-addons-elementor/essential_adons_elementor.php', 'platform' => 'elementor', 'name' => 'Essential Addons Pro', 'main_file' => 'essential_adons_elementor.php', 'free_slug' => 'essential-addons-for-elementor-lite', ], 'essential-blocks-pro/essential-blocks-pro.php' => [ 'slug' => 'essential-blocks-pro', 'plugin_file' => 'essential-blocks-pro/essential-blocks-pro.php', 'platform' => 'gutenberg', 'name' => 'Essential Blocks Pro', 'main_file' => 'essential-blocks-pro.php', 'free_slug' => 'essential-blocks', ], ]; /** * Resolve a dependency descriptor to its catalog entry, or null. * * Matches on `plugin_file` FIRST and `slug` only as a fallback: a slug can be reused by * an unrelated plugin, a plugin file cannot. A descriptor whose slug matches but whose * plugin file does not is NOT a match — that combination is exactly what a spoofed * entry would look like. * * @param array $dependency Dependency descriptor (`plugin_file`, `slug`, `plugin_original_slug`). * @return array|null */ public static function find( array $dependency ) { $plugin_file = isset( $dependency['plugin_file'] ) && is_string( $dependency['plugin_file'] ) ? $dependency['plugin_file'] : ''; if ( '' !== $plugin_file && isset( self::PLUGINS[ $plugin_file ] ) ) { return self::PLUGINS[ $plugin_file ]; } // A descriptor that names a plugin file we do not know is not a match, even if its // slug is one of ours — the file is the identity. if ( '' !== $plugin_file ) { return null; } foreach ( [ 'slug', 'plugin_original_slug' ] as $key ) { $slug = isset( $dependency[ $key ] ) && is_string( $dependency[ $key ] ) ? $dependency[ $key ] : ''; if ( '' === $slug ) { continue; } foreach ( self::PLUGINS as $entry ) { if ( $entry['slug'] === $slug ) { return $entry; } } } return null; } /** * Whether this dependency is one Templately may obtain. * * @param array $dependency Dependency descriptor. * @return bool */ public static function is_provisionable( array $dependency ): bool { return null !== self::find( $dependency ); } /** * Every provisionable plugin file, for parity checks and tests. * * @return string[] */ public static function plugin_files(): array { return array_keys( self::PLUGINS ); } }