PluginProbe
Code Snippets / 4.0.0-beta.1
Code Snippets v4.0.0-beta.1
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / php / migration / importers / plugins / manager.php

manager.php in Code Snippets 4.0.0-beta.1, at php/migration/importers/plugins/manager.php

61 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets;
4
5 use WP_REST_Server;
6 use const Code_Snippets\REST_API_NAMESPACE;
7
8 class Plugins_Import_Manager {
9
10 const VERSION = 1;
11
12 private $plugin_importers = [];
13
14 public function __construct() {
15 $this->init_plugin_importers();
16 add_action( 'rest_api_init', [ $this, 'register_rest_routes' ] );
17 }
18
19 private function init_plugin_importers() {
20 $this->plugin_importers = [
21 'insert-headers-and-footers' => new Insert_Headers_And_Footers_Importer(),
22 'header-footer-code-manager' => new Header_Footer_Code_Manager_Importer(),
23 'insert-php-code-snippet' => new Insert_PHP_Code_Snippet_Importer(),
24 ];
25 }
26
27 public function get_importer( string $source ) {
28 return $this->plugin_importers[ $source ] ?? null;
29 }
30
31 public function get_importers() {
32 if ( empty( $this->plugin_importers ) ) {
33 $this->init_plugin_importers();
34 }
35
36 $plugins_list = [];
37
38 foreach ( $this->plugin_importers as $importer ) {
39 $plugins_list[] = [
40 'name' => $importer->get_name(),
41 'title' => $importer->get_title(),
42 'is_active' => $importer::is_active(),
43 ];
44 }
45
46 return $plugins_list;
47 }
48
49 public function register_rest_routes() {
50 $namespace = REST_API_NAMESPACE . self::VERSION;
51
52 register_rest_route( $namespace, 'importers', [
53 'methods' => WP_REST_Server::READABLE,
54 'callback' => [ $this, 'get_importers' ],
55 'permission_callback' => function() {
56 return current_user_can( 'manage_options' );
57 },
58 ] );
59 }
60 }
61