PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
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 3.0.1 All 64 releases
code-snippets / php / Core / load.php

load.php in Code Snippets 3.10.0, at php/Core/load.php

89 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Initialise and load the plugin under the proper namespace.
4 *
5 * @package Code_Snippets
6 */
7
8 namespace Code_Snippets;
9
10 use Composer\Autoload\ClassLoader;
11
12 /**
13 * The version number for this release of the plugin.
14 * This will later be used for upgrades and enqueuing files.
15 *
16 * This should be set to the 'Plugin Version' value defined
17 * in the plugin header.
18 *
19 * @var string A PHP-standardized version number string.
20 */
21 const PLUGIN_VERSION = CODE_SNIPPETS_VERSION;
22
23 /**
24 * The full path to the main file of this plugin.
25 *
26 * This can later be used with functions such as
27 * plugin_dir_path(), plugins_url() and plugin_basename()
28 * to retrieve information about plugin paths.
29 *
30 * @var string
31 */
32 const PLUGIN_FILE = CODE_SNIPPETS_FILE;
33
34 /**
35 * Name of the group used for caching data.
36 *
37 * @var string
38 */
39 const CACHE_GROUP = 'code_snippets';
40
41 /**
42 * Namespace used for REST API endpoints.
43 *
44 * @var string
45 */
46 const REST_API_NAMESPACE = 'code-snippets/v';
47
48 /**
49 * Load the Composer autoloader.
50 *
51 * After loading, remove any PSR-4 namespace mappings that do not start with our vendor prefix but have a corresponding
52 * prefixed version, as these are not removed by Imposter and would cause collisions with other plugins that use the same
53 * libraries.
54 *
55 * @var ClassLoader $autoloader Composer autoloader instance.
56 */
57 $autoloader = require dirname( __DIR__, 2 ) . '/vendor/autoload.php';
58
59 if ( $autoloader instanceof ClassLoader ) {
60 $vendor_prefix = __NAMESPACE__ . '\\Vendor\\';
61
62 foreach ( $autoloader->getPrefixesPsr4() as $namespace => $paths ) {
63 // Remove any non-Code_Snippets namespace that has a corresponding prefixed version.
64 if ( false === strpos( $namespace, $vendor_prefix ) ) {
65 if ( isset( $prefixes[ $vendor_prefix . $namespace ] ) ) {
66 $autoloader->setPsr4( $namespace, [] );
67 }
68 }
69 }
70 }
71
72 /**
73 * Retrieve the instance of the main plugin class.
74 *
75 * @return Plugin
76 * @since 2.6.0
77 */
78 function code_snippets(): Plugin {
79 static $plugin;
80
81 if ( is_null( $plugin ) ) {
82 $plugin = new Plugin();
83 }
84
85 return $plugin;
86 }
87
88 code_snippets()->load_plugin();
89