PluginProbe ʕ •ᴥ•ʔ
WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager / 2.3.6
WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager v2.3.6
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 week ago auto-insert 4 months ago conditional-logic 6 months ago execute 5 months ago generator 6 months ago lite 9 months ago capabilities.php 2 years ago class-wpcode-abilities-api.php 1 week ago class-wpcode-admin-bar-info.php 2 years ago class-wpcode-auto-insert.php 4 months ago class-wpcode-capabilities.php 3 years ago class-wpcode-conditional-logic.php 4 months ago class-wpcode-error.php 2 years ago class-wpcode-file-cache.php 1 year ago class-wpcode-file-logger.php 1 year ago class-wpcode-generator.php 4 months ago class-wpcode-install.php 1 year ago class-wpcode-library-auth.php 1 year ago class-wpcode-library.php 1 week ago class-wpcode-settings.php 6 months ago class-wpcode-smart-tags.php 11 months ago class-wpcode-snippet-cache.php 4 months ago class-wpcode-snippet-execute.php 1 year ago class-wpcode-snippet.php 1 year ago compat.php 2 years ago global-output.php 1 year ago helpers.php 1 year ago icons.php 5 months ago ihaf.php 3 years ago legacy.php 3 years ago pluggable.php 2 years ago post-type.php 1 week ago safe-mode.php 11 months ago shortcode.php 2 years ago
class-wpcode-auto-insert.php
164 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 $type_name = $type->name ?? '';
89 $this->types[ $type_name ] = $type;
90 if ( isset( $type->category ) ) {
91 $type_category = $type->category ?? '';
92 $this->type_categories[ $type_category ]['types'][ $type_name ] = $type;
93 }
94 }
95
96 /**
97 * Get the types of auto-insert options.
98 *
99 * @return WPCode_Auto_Insert_Type[]
100 */
101 public function get_types() {
102 return $this->types;
103 }
104
105 /**
106 * Get the categories of auto-insert options.
107 *
108 * @return array
109 */
110 public function get_type_categories() {
111 if ( ! isset( $this->categories_with_labels ) ) {
112 $this->define_category_label();
113 }
114
115 return $this->type_categories;
116 }
117
118 /**
119 * Get the categories info for the sidebar admin view.
120 *
121 * @return array
122 */
123 public function get_type_categories_for_sidebar() {
124 $sidebar_categories = array();
125 $categories = $this->get_type_categories();
126
127 foreach ( $categories as $key => $category ) {
128 $sidebar_categories[] = array(
129 'slug' => $key,
130 'name' => $category['label'],
131 );
132 }
133
134 return $sidebar_categories;
135 }
136
137 /**
138 * Get a location label from the class not the term.
139 *
140 * @param string $location The location slug/name.
141 *
142 * @return string
143 */
144 public function get_location_label( $location ) {
145 foreach ( $this->types as $type ) {
146 /**
147 * Added for convenience.
148 *
149 * @var WPCode_Auto_Insert_Type $type
150 */
151 $locations = $type->get_locations();
152 if ( isset( $locations[ $location ] ) ) {
153 if ( isset( $locations[ $location ]['label'] ) ) {
154 return $locations[ $location ]['label'];
155 } else {
156 return $locations[ $location ];
157 }
158 }
159 }
160
161 return '';
162 }
163 }
164