PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / tribe-common / src / Tribe / Extension_Loader.php
pods / tribe-common / src / Tribe Last commit date
Admin 1 week ago Ajax 1 week ago Asset 1 week ago Context 1 week ago Customizer 1 week ago Debug_Bar 1 week ago Dialog 1 week ago Documentation 1 week ago Duplicate 1 week ago Editor 1 week ago Image 1 week ago JSON_LD 1 week ago Languages 1 week ago Log 1 week ago Meta 1 week ago Models 1 week ago PUE 1 week ago Process 1 week ago Promoter 1 week ago REST 1 week ago Repository 1 week ago Service_Providers 1 week ago Shortcode 1 week ago Support 1 week ago Tabbed_View 1 week ago Tooltip 1 week ago Traits 1 week ago Utils 1 week ago Validator 1 week ago Widget 1 week ago Abstract_Deactivation.php 1 week ago Abstract_Plugin_Register.php 1 week ago App_Shop.php 1 week ago Assets.php 1 week ago Assets_Pipeline.php 1 week ago Autoloader.php 1 week ago Cache.php 1 week ago Cache_Listener.php 1 week ago Changelog_Reader.php 1 week ago Container.php 1 week ago Context.php 1 week ago Cost_Utils.php 1 week ago Credits.php 1 week ago Customizer.php 1 week ago DB_Lock.php 1 week ago Data.php 1 week ago Date_Utils.php 1 week ago Db.php 1 week ago Debug.php 1 week ago Dependency.php 1 week ago Deprecation.php 1 week ago Editor.php 1 week ago Error.php 1 week ago Exception.php 1 week ago Extension.php 1 week ago Extension_Loader.php 1 week ago Feature_Detection.php 1 week ago Field.php 1 week ago Field_Conditional.php 1 week ago Freemius.php 1 week ago Log.php 1 week ago Main.php 1 week ago Notices.php 1 week ago Plugin_Meta_Links.php 1 week ago Plugins.php 1 week ago Plugins_API.php 1 week ago Post_History.php 1 week ago Post_Transient.php 1 week ago Promise.php 1 week ago Repository.php 1 week ago Rewrite.php 1 week ago Settings.php 1 week ago Settings_Manager.php 1 week ago Settings_Tab.php 1 week ago Simple_Table.php 1 week ago Support.php 1 week ago Tabbed_View.php 1 week ago Template.php 1 week ago Template_Factory.php 1 week ago Template_Part_Cache.php 1 week ago Templates.php 1 week ago Terms.php 1 week ago Timezones.php 1 week ago Tracker.php 1 week ago Updater.php 1 week ago Validate.php 1 week ago View_Helpers.php 1 week ago
Extension_Loader.php
169 lines
1 <?php
2 defined( 'WPINC' ) || die; // Do not load directly.
3
4 /**
5 * Class Tribe__Extension_Loader
6 */
7 class Tribe__Extension_Loader {
8
9 /**
10 * Plugin header data
11 *
12 * @var array {
13 * Plugin header data
14 *
15 * @param array $plugin_basename Plugin header key/value pairs.
16 * }
17 */
18 private $plugin_data = [];
19
20 /**
21 * Class instance.
22 *
23 * @var Tribe__Extension_Loader The singleton instance.
24 */
25 private static $instance;
26
27 /**
28 * Returns the singleton instance of this class.
29 *
30 * @return Tribe__Extension_Loader instance.
31 */
32 public static function instance() {
33 return null === self::$instance ? new self() : self::$instance;
34 }
35
36 /**
37 * Intializes each extension.
38 */
39 private function __construct() {
40 $prefixes = self::get_extension_file_prefixes();
41 $extension_filepaths = Tribe__Utils__Plugins::get_plugins_with_prefix( $prefixes );
42
43 foreach ( $extension_filepaths as $plugin_file ) {
44 $this->instantiate_extension( $plugin_file );
45 }
46 }
47
48 /**
49 * Gets tribe extension plugin foldername prefixes
50 *
51 * @return array Prefixes
52 */
53 public static function get_extension_file_prefixes() {
54 $prefixes = [ 'tribe-ext-' ];
55
56 /**
57 * Filter which plugin folder prefixes are considered tribe extensions.
58 *
59 * @param array $prefixes Extension plugin folder name prefixes.
60 */
61 return apply_filters( 'tribe_extension_prefixes', $prefixes );
62 }
63
64 /**
65 * Instantiates an extension based on info in its plugin file header.
66 *
67 * @param string $plugin_file Full path to extension's plugin file header.
68 *
69 * @return bool Indicates if extension was instantiated successfully.
70 */
71 public function instantiate_extension( $plugin_file ) {
72 $p_data = $this->get_cached_plugin_data( $plugin_file );
73 $p_folder = trailingslashit( dirname( $plugin_file ) );
74 $success = false;
75
76 // Nothing to instantiate if class is not set.
77 if ( empty( $p_data['ExtensionClass'] ) ) {
78 return $success;
79 }
80
81 // Default to plugin file when empty.
82 $class_file = ! empty( $p_data['ExtensionFile'] ) ? $p_folder . $p_data['ExtensionFile'] : $plugin_file;
83
84 // Include file.
85 if ( file_exists( $class_file ) ) {
86 // Prevent loading class twice in edge cases where require_once wouldn't work.
87 if ( ! class_exists( $p_data['ExtensionClass'] ) ) {
88 require( $class_file );
89 }
90 } else {
91 _doing_it_wrong(
92 esc_html( $class_file ),
93 'Extension file does not exist, please specify valid extension file.',
94 '4.3'
95 );
96 }
97
98 // Class instantiation.
99 if ( class_exists( $p_data['ExtensionClass'] ) ) {
100 $extension_args = [
101 'file' => $plugin_file,
102 'plugin_data' => $p_data,
103 ];
104
105 // Instantiates extension instance.
106 $extension = call_user_func(
107 [ $p_data['ExtensionClass'], 'instance' ],
108 $p_data['ExtensionClass'],
109 $extension_args
110 );
111
112 if ( null !== $extension ) {
113 $success = true;
114 }
115 } else {
116 _doing_it_wrong(
117 esc_html( $p_data['ExtensionClass'] ),
118 'Specified extension class does not exist. Please double check that this class is declared in the extension file.',
119 '4.3'
120 );
121 }
122
123 return $success;
124 }
125
126 /**
127 * Retrieves plugin data from cache if it exists.
128 *
129 * @param string $plugin_path Path to plugin header file.
130 *
131 * @return array|null Plugin data or null.
132 */
133 public function get_cached_plugin_data( $plugin_path ) {
134 $plugin_basename = plugin_basename( $plugin_path );
135
136 if ( ! array_key_exists( $plugin_basename, $this->plugin_data ) ) {
137 $this->plugin_data[ $plugin_basename ] = Tribe__Utils__Plugins::get_plugin_data( $plugin_path );
138 }
139
140 return $this->plugin_data[ $plugin_basename ];
141 }
142
143 /**
144 * Prevent cloning the singleton with 'clone' operator
145 *
146 * @return void
147 */
148 public function __clone() {
149 _doing_it_wrong(
150 __FUNCTION__,
151 'Can not use this method on singletons.',
152 '4.3'
153 );
154 }
155
156 /**
157 * Prevent unserializing the singleton instance
158 *
159 * @return void
160 */
161 public function __wakeup() {
162 _doing_it_wrong(
163 __FUNCTION__,
164 'Can not use this method on singletons.',
165 '4.3'
166 );
167 }
168 }
169