admin
2 years ago
app
2 years ago
base
2 years ago
behaviors
3 years ago
breakpoints
2 years ago
common
2 years ago
debug
3 years ago
document-types
3 years ago
dynamic-tags
2 years ago
editor
2 years ago
experiments
2 years ago
files
2 years ago
frontend
3 years ago
kits
2 years ago
logger
2 years ago
page-assets
3 years ago
responsive
2 years ago
role-manager
3 years ago
schemes
2 years ago
settings
2 years ago
upgrade
2 years ago
utils
2 years ago
documents-manager.php
3 years ago
modules-manager.php
2 years ago
wp-api.php
3 years ago
wp-api.php
61 lines
| 1 | <?php |
| 2 | namespace Elementor\Core; |
| 3 | |
| 4 | use Elementor\Core\Utils\Collection; |
| 5 | |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit; // Exit if accessed directly. |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * This class is responsible for the interaction with WordPress Core API. |
| 12 | * The main benefit is making it easy to mock in testing |
| 13 | * and it can help to create unit tests without the hustle of mocking WordPress itself. |
| 14 | */ |
| 15 | class Wp_Api { |
| 16 | /** |
| 17 | * @var Collection |
| 18 | */ |
| 19 | private $plugins; |
| 20 | |
| 21 | /** |
| 22 | * @return Collection |
| 23 | */ |
| 24 | public function get_plugins() { |
| 25 | if ( ! $this->plugins ) { |
| 26 | $this->plugins = new Collection( get_plugins() ); |
| 27 | } |
| 28 | |
| 29 | return $this->plugins; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @return Collection |
| 34 | */ |
| 35 | public function get_active_plugins() { |
| 36 | return $this->get_plugins() |
| 37 | ->only( get_option( 'active_plugins' ) ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @return object|array |
| 42 | */ |
| 43 | public function plugins_api( $action, $args ) { |
| 44 | return plugins_api( $action, $args ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return bool |
| 49 | */ |
| 50 | public function is_plugin_active( $plugin ) { |
| 51 | return is_plugin_active( $plugin ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @return bool|int|null|true |
| 56 | */ |
| 57 | public function activate_plugin( $plugin ) { |
| 58 | return activate_plugin( $plugin ); |
| 59 | } |
| 60 | } |
| 61 |