PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
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 / Core / load.php

load.php in Code Snippets 4.0.0-beta.2, at php/Core/load.php

99 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Initialize 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 * Base name of the group used for caching data.
36 *
37 * @var string
38 */
39 const CACHE_GROUP_BASE = 'code_snippets';
40
41 /**
42 * Name of the group used for caching data.
43 *
44 * Scoped to the plugin version, so data cached by one version is never read by another.
45 *
46 * @var string
47 */
48 const CACHE_GROUP = CACHE_GROUP_BASE . '_' . PLUGIN_VERSION;
49
50 /**
51 * Namespace used for REST API endpoints.
52 *
53 * @var string
54 */
55 const REST_API_NAMESPACE = 'code-snippets/v';
56
57 /**
58 * Load the Composer autoloader.
59 *
60 * After loading, remove any PSR-4 namespace mappings that do not start with our vendor prefix but have a corresponding
61 * prefixed version. These are not removed by Imposter and would cause collisions with other plugins that use the same libraries.
62 *
63 * @var ClassLoader $autoloader Composer autoloader instance.
64 */
65 $autoloader = require dirname( __DIR__, 2 ) . '/vendor/autoload.php';
66
67 if ( $autoloader instanceof ClassLoader ) {
68 $vendor_prefix = __NAMESPACE__ . '\\Vendor\\';
69
70 $prefixes = $autoloader->getPrefixesPsr4();
71
72 foreach ( $prefixes as $namespace => $paths ) {
73 // Remove any non-Code_Snippets namespace that has a corresponding prefixed version.
74 if ( false === strpos( $namespace, $vendor_prefix ) ) {
75 if ( isset( $prefixes[ $vendor_prefix . $namespace ] ) ) {
76 $autoloader->setPsr4( $namespace, [] );
77 }
78 }
79 }
80 }
81
82 /**
83 * Retrieve the instance of the main plugin class.
84 *
85 * @return Plugin
86 * @since 2.6.0
87 */
88 function code_snippets(): Plugin {
89 static $plugin;
90
91 if ( is_null( $plugin ) ) {
92 $plugin = new Plugin();
93 }
94
95 return $plugin;
96 }
97
98 code_snippets()->load_plugin();
99