PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.9.19.4
Pods – Custom Content Types and Fields v2.9.19.4
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 2 weeks ago Ajax 2 weeks ago Asset 2 weeks ago Context 2 weeks ago Customizer 2 weeks ago Debug_Bar 2 weeks ago Dialog 2 weeks ago Documentation 2 weeks ago Duplicate 2 weeks ago Editor 2 weeks ago Image 2 weeks ago JSON_LD 2 weeks ago Languages 2 weeks ago Log 2 weeks ago Meta 2 weeks ago Models 2 weeks ago PUE 2 weeks ago Process 2 weeks ago Promoter 2 weeks ago REST 2 weeks ago Repository 2 weeks ago Service_Providers 2 weeks ago Shortcode 2 weeks ago Support 2 weeks ago Tabbed_View 2 weeks ago Tooltip 2 weeks ago Traits 2 weeks ago Utils 2 weeks ago Validator 2 weeks ago Widget 2 weeks ago Abstract_Deactivation.php 2 weeks ago Abstract_Plugin_Register.php 2 weeks ago App_Shop.php 2 weeks ago Assets.php 2 weeks ago Assets_Pipeline.php 2 weeks ago Autoloader.php 2 weeks ago Cache.php 2 weeks ago Cache_Listener.php 2 weeks ago Changelog_Reader.php 2 weeks ago Container.php 2 weeks ago Context.php 2 weeks ago Cost_Utils.php 2 weeks ago Credits.php 2 weeks ago Customizer.php 2 weeks ago DB_Lock.php 2 weeks ago Data.php 2 weeks ago Date_Utils.php 2 weeks ago Db.php 2 weeks ago Debug.php 2 weeks ago Dependency.php 2 weeks ago Deprecation.php 2 weeks ago Editor.php 2 weeks ago Error.php 2 weeks ago Exception.php 2 weeks ago Extension.php 2 weeks ago Extension_Loader.php 2 weeks ago Feature_Detection.php 2 weeks ago Field.php 2 weeks ago Field_Conditional.php 2 weeks ago Freemius.php 2 weeks ago Log.php 2 weeks ago Main.php 2 weeks ago Notices.php 2 weeks ago Plugin_Meta_Links.php 2 weeks ago Plugins.php 2 weeks ago Plugins_API.php 2 weeks ago Post_History.php 2 weeks ago Post_Transient.php 2 weeks ago Promise.php 2 weeks ago Repository.php 2 weeks ago Rewrite.php 2 weeks ago Settings.php 2 weeks ago Settings_Manager.php 2 weeks ago Settings_Tab.php 2 weeks ago Simple_Table.php 2 weeks ago Support.php 2 weeks ago Tabbed_View.php 2 weeks ago Template.php 2 weeks ago Template_Factory.php 2 weeks ago Template_Part_Cache.php 2 weeks ago Templates.php 2 weeks ago Terms.php 2 weeks ago Timezones.php 2 weeks ago Tracker.php 2 weeks ago Updater.php 2 weeks ago Validate.php 2 weeks ago View_Helpers.php 2 weeks 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