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

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

106 lines 2.7 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 * 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
45 * another. Snippet objects are cached here, and the Snippet class moved
46 * namespace in 3.10. A version that cannot resolve the stored class fatals on
47 * unserialize, which broke the admin for anyone downgrading on a site with a
48 * persistent object cache. Keeping the group distinct per version means the
49 * two never see each other's data, in either direction, without relying on the
50 * other version to clean up after itself.
51 *
52 * @var string
53 */
54 const CACHE_GROUP = CACHE_GROUP_BASE . '_' . PLUGIN_VERSION;
55
56 /**
57 * Namespace used for REST API endpoints.
58 *
59 * @var string
60 */
61 const REST_API_NAMESPACE = 'code-snippets/v';
62
63 /**
64 * Load the Composer autoloader.
65 *
66 * After loading, remove any PSR-4 namespace mappings that do not start with our vendor prefix but have a corresponding
67 * prefixed version, as these are not removed by Imposter and would cause collisions with other plugins that use the same
68 * libraries.
69 *
70 * @var ClassLoader $autoloader Composer autoloader instance.
71 */
72 $autoloader = require dirname( __DIR__, 2 ) . '/vendor/autoload.php';
73
74 if ( $autoloader instanceof ClassLoader ) {
75 $vendor_prefix = __NAMESPACE__ . '\\Vendor\\';
76
77 $prefixes = $autoloader->getPrefixesPsr4();
78
79 foreach ( $prefixes as $namespace => $paths ) {
80 // Remove any non-Code_Snippets namespace that has a corresponding prefixed version.
81 if ( false === strpos( $namespace, $vendor_prefix ) ) {
82 if ( isset( $prefixes[ $vendor_prefix . $namespace ] ) ) {
83 $autoloader->setPsr4( $namespace, [] );
84 }
85 }
86 }
87 }
88
89 /**
90 * Retrieve the instance of the main plugin class.
91 *
92 * @return Plugin
93 * @since 2.6.0
94 */
95 function code_snippets(): Plugin {
96 static $plugin;
97
98 if ( is_null( $plugin ) ) {
99 $plugin = new Plugin();
100 }
101
102 return $plugin;
103 }
104
105 code_snippets()->load_plugin();
106