PluginProbe ʕ •ᴥ•ʔ
WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager / 2.2.4
WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager v2.2.4
2.3.6 trunk 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5.0 1.6.0 1.6.1 1.6.2 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.13.1 2.0.2 2.0.3 2.0.4 2.0.4.1 2.0.4.2 2.0.4.3 2.0.4.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.2 2.1.3 2.1.3.1 2.1.4 2.1.4.1 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.2.4 2.2.4.1 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.2.1 2.3.3 2.3.4 2.3.5
insert-headers-and-footers / includes / class-wpcode-auto-insert.php
insert-headers-and-footers / includes Last commit date
admin 1 year ago auto-insert 1 year ago conditional-logic 1 year ago execute 1 year ago generator 2 years ago lite 1 year ago capabilities.php 2 years ago class-wpcode-admin-bar-info.php 2 years ago class-wpcode-auto-insert.php 1 year ago class-wpcode-capabilities.php 3 years ago class-wpcode-conditional-logic.php 1 year ago class-wpcode-error.php 2 years ago class-wpcode-file-cache.php 1 year ago class-wpcode-file-logger.php 3 years ago class-wpcode-generator.php 3 years ago class-wpcode-install.php 2 years ago class-wpcode-library-auth.php 1 year ago class-wpcode-library.php 1 year ago class-wpcode-settings.php 2 years ago class-wpcode-smart-tags.php 2 years ago class-wpcode-snippet-cache.php 2 years ago class-wpcode-snippet-execute.php 1 year ago class-wpcode-snippet.php 1 year ago compat.php 2 years ago global-output.php 2 years ago helpers.php 1 year ago icons.php 1 year ago ihaf.php 3 years ago legacy.php 3 years ago pluggable.php 2 years ago post-type.php 1 year ago safe-mode.php 2 years ago shortcode.php 2 years ago
class-wpcode-auto-insert.php
162 lines
1 <?php
2 /**
3 * Central handler of auto-inserting snippets.
4 * Loads the different types and processes them.
5 *
6 * @package WPCode
7 */
8
9 /**
10 * Class WPCode_Auto_Insert.
11 */
12 class WPCode_Auto_Insert {
13
14 /**
15 * The auto-insert types.
16 *
17 * @var array
18 */
19 public $types = array();
20
21 /**
22 * The auto-insert categories.
23 *
24 * @var array
25 */
26 public $type_categories = array();
27
28 public $categories_with_labels;
29
30 /**
31 * Constructor.
32 */
33 public function __construct() {
34 $this->hooks();
35 }
36
37 /**
38 * Add hooks.
39 *
40 * @return void
41 */
42 private function hooks() {
43 add_action( 'plugins_loaded', array( $this, 'load_types' ), 1 );
44 }
45
46 /**
47 * Define the categories of auto-insert types.
48 *
49 * @return void
50 */
51 public function define_category_label() {
52 $categories_labels = array(
53 'global' => __( 'Global', 'insert-headers-and-footers' ),
54 'page' => __( 'Page-Specific', 'insert-headers-and-footers' ),
55 'ecommerce' => __( 'eCommerce', 'insert-headers-and-footers' ),
56 );
57
58 // Add the labels to the $this->type_categories array.
59 foreach ( $categories_labels as $key => $category ) {
60 $this->type_categories[ $key ]['label'] = $category;
61 }
62
63 $this->categories_with_labels = true;
64 }
65
66 /**
67 * Load and initialize the different types of auto-insert types.
68 *
69 * @return void
70 */
71 public function load_types() {
72 require_once WPCODE_PLUGIN_PATH . 'includes/auto-insert/class-wpcode-auto-insert-type.php';
73 require_once WPCODE_PLUGIN_PATH . 'includes/auto-insert/class-wpcode-auto-insert-everywhere.php';
74 require_once WPCODE_PLUGIN_PATH . 'includes/auto-insert/class-wpcode-auto-insert-site-wide.php';
75 require_once WPCODE_PLUGIN_PATH . 'includes/auto-insert/class-wpcode-auto-insert-single.php';
76 require_once WPCODE_PLUGIN_PATH . 'includes/auto-insert/class-wpcode-auto-insert-archive.php';
77 require_once WPCODE_PLUGIN_PATH . 'includes/auto-insert/class-wpcode-auto-insert-admin.php';
78 }
79
80 /**
81 * Register an auto-insert type.
82 *
83 * @param WPCode_Auto_Insert_Type $type The type to add to the available types.
84 *
85 * @return void
86 */
87 public function register_type( $type ) {
88 $this->types[ $type->name ] = $type;
89 if ( isset( $type->category ) ) {
90 $this->type_categories[ $type->category ]['types'][ $type->name ] = $type;
91 }
92 }
93
94 /**
95 * Get the types of auto-insert options.
96 *
97 * @return WPCode_Auto_Insert_Type[]
98 */
99 public function get_types() {
100 return $this->types;
101 }
102
103 /**
104 * Get the categories of auto-insert options.
105 *
106 * @return array
107 */
108 public function get_type_categories() {
109 if ( ! isset( $this->categories_with_labels ) ) {
110 $this->define_category_label();
111 }
112
113 return $this->type_categories;
114 }
115
116 /**
117 * Get the categories info for the sidebar admin view.
118 *
119 * @return array
120 */
121 public function get_type_categories_for_sidebar() {
122 $sidebar_categories = array();
123 $categories = $this->get_type_categories();
124
125 foreach ( $categories as $key => $category ) {
126 $sidebar_categories[] = array(
127 'slug' => $key,
128 'name' => $category['label'],
129 );
130 }
131
132 return $sidebar_categories;
133 }
134
135 /**
136 * Get a location label from the class not the term.
137 *
138 * @param string $location The location slug/name.
139 *
140 * @return string
141 */
142 public function get_location_label( $location ) {
143 foreach ( $this->types as $type ) {
144 /**
145 * Added for convenience.
146 *
147 * @var WPCode_Auto_Insert_Type $type
148 */
149 $locations = $type->get_locations();
150 if ( isset( $locations[ $location ] ) ) {
151 if ( isset( $locations[ $location ]['label'] ) ) {
152 return $locations[ $location ]['label'];
153 } else {
154 return $locations[ $location ];
155 }
156 }
157 }
158
159 return '';
160 }
161 }
162