Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
maybe_limit_to_marketplace_plugins
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2/**
3 * Features related to the WordPress.com Marketplace.
4 *
5 * @package wpcomsh
6 */
7
8/**
9 * Limits the output of all plugins to only Marketplace plugins when it's a plugin list request and the site only has
10 * access to Marketplace plugins.
11 *
12 * @param array $plugins All plugins.
13 * @return array
14 */
15function maybe_limit_to_marketplace_plugins( $plugins ) {
16    if ( ! wpcomsh_is_plugin_list_request() || wpcom_site_has_feature( WPCOM_Features::INSTALL_PLUGINS ) ) {
17        return $plugins;
18    }
19    // Also check for sites that can list plugins, but can't purchase plugins.
20    if ( wpcom_site_has_feature( WPCOM_Features::LIST_INSTALLED_PLUGINS ) && ! wpcom_site_has_feature( WPCOM_Features::INSTALL_PURCHASED_PLUGINS ) ) {
21        return $plugins;
22    }
23
24    return array_filter(
25        $plugins,
26        function ( $plugin_file ) {
27            // Woocommerce is never purchased, and might not be on this site, but should be shown if it's installed.
28            return $plugin_file === 'woocommerce/woocommerce.php' || wpcomsh_is_marketplace_plugin( $plugin_file );
29        },
30        ARRAY_FILTER_USE_KEY
31    );
32}
33add_filter( 'all_plugins', 'maybe_limit_to_marketplace_plugins' );