PluginProbe
Code Snippets / 2.14.0
Code Snippets v2.14.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 / code-snippets.php

code-snippets.php in Code Snippets 2.14.0, at code-snippets.php

104 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Code Snippets - An easy, clean and simple way to add code snippets to your site.
4 *
5 * If you're interested in helping to develop Code Snippets, or perhaps contribute
6 * to the localization, please see https://github.com/sheabunge/code-snippets
7 *
8 * @package Code_Snippets
9 * @author Shea Bunge <shea@sheabunge.com>
10 * @copyright 2012-2020 Shea Bunge
11 * @license MIT http://opensource.org/licenses/MIT
12 * @version 2.14.0
13 * @link https://github.com/sheabunge/code-snippets
14 */
15
16 /*
17 Plugin Name: Code Snippets
18 Plugin URI: https://github.com/sheabunge/code-snippets
19 Description: An easy, clean and simple way to run code snippets on your site. No need to edit to your theme's functions.php file again!
20 Author: Code Snippets Pro
21 Author URI: https://codesnippets.pro
22 Version: 2.14.0
23 License: MIT
24 License URI: license.txt
25 Text Domain: code-snippets
26 Domain Path: /languages
27 */
28
29 /* Exit if accessed directly */
30 if ( ! defined( 'ABSPATH' ) ) {
31 return;
32 }
33
34 /**
35 * The full path to the main file of this plugin
36 *
37 * This can later be passed to functions such as
38 * plugin_dir_path(), plugins_url() and plugin_basename()
39 * to retrieve information about plugin paths
40 *
41 * @since 2.0
42 * @var string
43 */
44 define( 'CODE_SNIPPETS_FILE', __FILE__ );
45
46 /**
47 * Enable autoloading of plugin classes
48 * @param $class_name
49 */
50 function code_snippets_autoload( $class_name ) {
51
52 /* Only autoload classes from this plugin */
53 if ( 'Code_Snippet' !== $class_name && 'Code_Snippets' !== substr( $class_name, 0, 13 ) ) {
54 return;
55 }
56
57 /* Remove namespace from class name */
58 $class_file = str_replace( 'Code_Snippets_', '', $class_name );
59
60 if ( 'Code_Snippet' === $class_name ) {
61 $class_file = 'Snippet';
62 }
63
64 /* Convert class name format to file name format */
65 $class_file = strtolower( $class_file );
66 $class_file = str_replace( '_', '-', $class_file );
67
68 $class_path = dirname( __FILE__ ) . '/php/';
69
70 if ( 'Menu' === substr( $class_name, -4, 4 ) ) {
71 $class_path .= 'admin-menus/';
72 }
73
74 /* Load the class */
75 require_once $class_path . "class-{$class_file}.php";
76 }
77
78 try {
79 spl_autoload_register( 'code_snippets_autoload' );
80 } catch ( Exception $e ) {
81 new WP_Error( $e->getCode(), $e->getMessage() );
82 }
83
84 /**
85 * Retrieve the instance of the main plugin class
86 *
87 * @since 2.6.0
88 * @return Code_Snippets
89 */
90 function code_snippets() {
91 static $plugin;
92
93 if ( is_null( $plugin ) ) {
94 $plugin = new Code_Snippets( '2.14.0', __FILE__ );
95 }
96
97 return $plugin;
98 }
99
100 code_snippets()->load_plugin();
101
102 /* Execute the snippets once the plugins are loaded */
103 add_action( 'plugins_loaded', 'execute_active_snippets', 1 );
104