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
Main.php
718 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Main Tribe Common class. |
| 4 | */ |
| 5 | |
| 6 | // Don't load directly |
| 7 | use Tribe\DB_Lock; |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | die( '-1' ); |
| 11 | } |
| 12 | |
| 13 | if ( class_exists( 'Tribe__Main' ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | class Tribe__Main { |
| 18 | const EVENTSERROROPT = '_tribe_events_errors'; |
| 19 | const OPTIONNAME = 'tribe_events_calendar_options'; |
| 20 | const OPTIONNAMENETWORK = 'tribe_events_calendar_network_options'; |
| 21 | |
| 22 | const VERSION = '4.13.0.1'; |
| 23 | |
| 24 | const FEED_URL = 'https://theeventscalendar.com/feed/'; |
| 25 | |
| 26 | protected $plugin_context; |
| 27 | protected $plugin_context_class; |
| 28 | |
| 29 | public static $tribe_url = 'http://tri.be/'; |
| 30 | public static $tec_url = 'https://theeventscalendar.com/'; |
| 31 | |
| 32 | public $plugin_dir; |
| 33 | public $plugin_path; |
| 34 | public $plugin_url; |
| 35 | |
| 36 | /** |
| 37 | * Static Singleton Holder |
| 38 | * @var self |
| 39 | */ |
| 40 | protected static $instance; |
| 41 | |
| 42 | /** |
| 43 | * Get (and instantiate, if necessary) the instance of the class |
| 44 | * |
| 45 | * @param mixed $context An instance of the Main class of the plugin that instantiated Common |
| 46 | * |
| 47 | * @return self |
| 48 | */ |
| 49 | public static function instance( $context = null ) { |
| 50 | if ( ! self::$instance ) { |
| 51 | self::$instance = new self( $context ); |
| 52 | } |
| 53 | |
| 54 | return self::$instance; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Constructor for Common Class |
| 59 | * |
| 60 | * We are using a `public` constructor here for backwards compatibility. |
| 61 | * |
| 62 | * The way our code used to work we would have `new Tribe__Main()` called directly |
| 63 | * which causes fatals if you have an older version of Core/Tickets active along side a new one |
| 64 | */ |
| 65 | public function __construct( $context = null ) { |
| 66 | if ( self::$instance ) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | require_once realpath( dirname( dirname( dirname( __FILE__ ) ) ) . '/vendor/autoload.php' ); |
| 71 | |
| 72 | // the DI container class |
| 73 | require_once dirname( __FILE__ ) . '/Container.php'; |
| 74 | |
| 75 | if ( is_object( $context ) ) { |
| 76 | $this->plugin_context = $context; |
| 77 | $this->plugin_context_class = get_class( $context ); |
| 78 | } |
| 79 | |
| 80 | $this->plugin_path = trailingslashit( dirname( dirname( dirname( __FILE__ ) ) ) ); |
| 81 | $this->plugin_dir = trailingslashit( basename( $this->plugin_path ) ); |
| 82 | $parent_plugin_dir = trailingslashit( plugin_basename( $this->plugin_path ) ); |
| 83 | $this->plugin_url = plugins_url( $parent_plugin_dir === $this->plugin_dir ? $this->plugin_dir : $parent_plugin_dir ); |
| 84 | |
| 85 | $this->promoter_connector(); |
| 86 | |
| 87 | add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ], 1 ); |
| 88 | add_action( 'tribe_common_loaded', [ $this, 'tribe_common_app_store' ], 10 ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * |
| 93 | */ |
| 94 | public function plugins_loaded() { |
| 95 | |
| 96 | $this->init_autoloading(); |
| 97 | |
| 98 | $this->bind_implementations(); |
| 99 | $this->init_libraries(); |
| 100 | $this->add_hooks(); |
| 101 | |
| 102 | /** |
| 103 | * Runs once all common libs are loaded and initial hooks are in place. |
| 104 | * |
| 105 | * @since 4.3 |
| 106 | */ |
| 107 | do_action( 'tribe_common_loaded' ); |
| 108 | |
| 109 | /** |
| 110 | * Runs to register loaded plugins |
| 111 | * |
| 112 | * @since 4.9 |
| 113 | */ |
| 114 | do_action( 'tribe_plugins_loaded ' ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Setup the autoloader for common files |
| 119 | */ |
| 120 | protected function init_autoloading() { |
| 121 | if ( ! class_exists( 'Tribe__Autoloader' ) ) { |
| 122 | require_once dirname( __FILE__ ) . '/Autoloader.php'; |
| 123 | } |
| 124 | |
| 125 | $autoloader = Tribe__Autoloader::instance(); |
| 126 | |
| 127 | $prefixes = [ 'Tribe__' => dirname( __FILE__ ) ]; |
| 128 | $autoloader->register_prefixes( $prefixes ); |
| 129 | |
| 130 | foreach ( glob( $this->plugin_path . 'src/deprecated/*.php' ) as $file ) { |
| 131 | $class_name = str_replace( '.php', '', basename( $file ) ); |
| 132 | $autoloader->register_class( $class_name, $file ); |
| 133 | } |
| 134 | |
| 135 | $autoloader->register_autoloader(); |
| 136 | } |
| 137 | |
| 138 | public function tribe_common_app_store() { |
| 139 | Tribe__Extension_Loader::instance(); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Gets the instantiated context of this class. I.e. the object that instantiated this one. |
| 144 | */ |
| 145 | public function context() { |
| 146 | return $this->plugin_context; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Gets the class name of the instantiated plugin context of this class. I.e. the class name of the object that instantiated this one. |
| 151 | */ |
| 152 | public function context_class() { |
| 153 | return $this->plugin_context_class; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * initializes all required libraries |
| 158 | */ |
| 159 | public function init_libraries() { |
| 160 | require_once $this->plugin_path . 'src/functions/utils.php'; |
| 161 | require_once $this->plugin_path . 'src/functions/url.php'; |
| 162 | require_once $this->plugin_path . 'src/functions/query.php'; |
| 163 | require_once $this->plugin_path . 'src/functions/multibyte.php'; |
| 164 | require_once $this->plugin_path . 'src/functions/template-tags/general.php'; |
| 165 | require_once $this->plugin_path . 'src/functions/template-tags/date.php'; |
| 166 | require_once $this->plugin_path . 'src/functions/template-tags/html.php'; |
| 167 | require_once $this->plugin_path . 'src/functions/template-tags/post.php'; |
| 168 | |
| 169 | Tribe__Debug::instance(); |
| 170 | tribe( 'assets' ); |
| 171 | tribe( 'assets.pipeline' ); |
| 172 | tribe( 'settings.manager' ); |
| 173 | tribe( 'tracker' ); |
| 174 | tribe( 'plugins.api' ); |
| 175 | tribe( 'pue.notices' ); |
| 176 | tribe( 'ajax.dropdown' ); |
| 177 | tribe( 'logger' ); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Registers resources that can/should be enqueued |
| 182 | */ |
| 183 | public function load_assets() { |
| 184 | // These ones are only registered |
| 185 | tribe_assets( |
| 186 | $this, |
| 187 | [ |
| 188 | [ 'tribe-accessibility-css', 'accessibility.css' ], |
| 189 | [ 'tribe-query-string', 'utils/query-string.js' ], |
| 190 | [ 'tribe-clipboard', 'vendor/clipboard/clipboard.js' ], |
| 191 | [ 'datatables', 'vendor/datatables/datatables.js', [ 'jquery' ] ], |
| 192 | [ 'tribe-select2', 'vendor/tribe-selectWoo/dist/js/selectWoo.full.js', [ 'jquery' ] ], |
| 193 | [ 'tribe-select2-css', 'vendor/tribe-selectWoo/dist/css/selectWoo.css' ], |
| 194 | [ 'tribe-utils-camelcase', 'utils-camelcase.js', [ 'underscore' ] ], |
| 195 | [ 'tribe-moment', 'vendor/momentjs/moment.js' ], |
| 196 | [ 'tribe-tooltipster', 'vendor/tooltipster/tooltipster.bundle.js', [ 'jquery' ] ], |
| 197 | [ 'tribe-tooltipster-css', 'vendor/tooltipster/tooltipster.bundle.css' ], |
| 198 | [ 'datatables-css', 'datatables.css' ], |
| 199 | [ 'tribe-datatables', 'tribe-datatables.js', [ 'datatables' ] ], |
| 200 | [ 'tribe-bumpdown', 'bumpdown.js', [ 'jquery', 'underscore', 'hoverIntent' ] ], |
| 201 | [ 'tribe-bumpdown-css', 'bumpdown.css' ], |
| 202 | [ 'tribe-buttonset-style', 'buttonset.css' ], |
| 203 | [ 'tribe-dropdowns', 'dropdowns.js', [ 'jquery', 'underscore', 'tribe-select2', 'tribe-common' ] ], |
| 204 | [ 'tribe-jquery-timepicker', 'vendor/jquery-tribe-timepicker/jquery.timepicker.js', [ 'jquery' ] ], |
| 205 | [ 'tribe-jquery-timepicker-css', 'vendor/jquery-tribe-timepicker/jquery.timepicker.css' ], |
| 206 | [ 'tribe-timepicker', 'timepicker.js', [ 'jquery', 'tribe-jquery-timepicker' ] ], |
| 207 | [ 'tribe-attrchange', 'vendor/attrchange/js/attrchange.js' ], |
| 208 | ] |
| 209 | ); |
| 210 | |
| 211 | tribe_assets( |
| 212 | $this, |
| 213 | [ |
| 214 | [ 'tribe-common-skeleton-style', 'common-skeleton.css' ], |
| 215 | [ 'tribe-common-full-style', 'common-full.css', [ 'tribe-common-skeleton-style' ] ], |
| 216 | ], |
| 217 | null |
| 218 | ); |
| 219 | |
| 220 | // These ones will be enqueued on `admin_enqueue_scripts` if the conditional method on filter is met |
| 221 | tribe_assets( |
| 222 | $this, |
| 223 | [ |
| 224 | [ 'tribe-ui', 'tribe-ui.css' ], |
| 225 | [ 'tribe-buttonset', 'buttonset.js', [ 'jquery', 'underscore' ] ], |
| 226 | [ 'tribe-common-admin', 'tribe-common-admin.css', [ 'tribe-dependency-style', 'tribe-bumpdown-css', 'tribe-buttonset-style', 'tribe-select2-css' ] ], |
| 227 | [ 'tribe-validation', 'validation.js', [ 'jquery', 'underscore', 'tribe-common', 'tribe-utils-camelcase', 'tribe-tooltipster' ] ], |
| 228 | [ 'tribe-validation-style', 'validation.css', [ 'tribe-tooltipster-css' ] ], |
| 229 | [ 'tribe-dependency', 'dependency.js', [ 'jquery', 'underscore', 'tribe-common' ] ], |
| 230 | [ 'tribe-dependency-style', 'dependency.css', [ 'tribe-select2-css' ] ], |
| 231 | [ 'tribe-pue-notices', 'pue-notices.js', [ 'jquery' ] ], |
| 232 | [ 'tribe-datepicker', 'datepicker.css' ], |
| 233 | ], |
| 234 | 'admin_enqueue_scripts', |
| 235 | [ |
| 236 | 'conditionals' => [ $this, 'should_load_common_admin_css' ], |
| 237 | 'priority' => 5, |
| 238 | ] |
| 239 | ); |
| 240 | |
| 241 | tribe_asset( |
| 242 | $this, |
| 243 | 'tribe-common', |
| 244 | 'tribe-common.js', |
| 245 | [], |
| 246 | 'admin_enqueue_scripts', |
| 247 | [ |
| 248 | 'priority' => 0, |
| 249 | ] |
| 250 | ); |
| 251 | |
| 252 | tribe_asset( |
| 253 | $this, |
| 254 | 'tribe-admin-url-fragment-scroll', |
| 255 | 'admin/url-fragment-scroll.js', |
| 256 | [ 'tribe-common' ], |
| 257 | 'admin_enqueue_scripts', |
| 258 | [ |
| 259 | 'conditionals' => [ $this, 'should_load_common_admin_css' ], |
| 260 | 'priority' => 5, |
| 261 | ] |
| 262 | ); |
| 263 | |
| 264 | tribe( Tribe__Admin__Help_Page::class )->register_assets(); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Load Common's text domain, then fire the hook for other plugins to do the same. |
| 269 | * |
| 270 | * Make sure this fires on 'init', per WordPress best practices. |
| 271 | * |
| 272 | * @since 4.12.0 |
| 273 | * |
| 274 | * @return bool |
| 275 | */ |
| 276 | public function hook_load_text_domain() { |
| 277 | $loaded = $this->load_text_domain( |
| 278 | 'tribe-common', |
| 279 | basename( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/common/lang/' |
| 280 | ); |
| 281 | |
| 282 | /** |
| 283 | * After attempting (hopefully successfully) to load Common's text domain. |
| 284 | * |
| 285 | * Load other plugin text domains on this hook, but make sure they're setup on this hook prior to 'init'. |
| 286 | * |
| 287 | * @since 4.12.0 |
| 288 | * |
| 289 | * @param bool $loaded Whether or not Common's text domain was loaded. |
| 290 | * |
| 291 | * @return bool |
| 292 | */ |
| 293 | do_action( 'tribe_load_text_domains', $loaded ); |
| 294 | |
| 295 | return $loaded; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Load All localization data create by `asset.data` |
| 300 | * |
| 301 | * @since 4.7 |
| 302 | * |
| 303 | * @return void |
| 304 | */ |
| 305 | public function load_localize_data() { |
| 306 | $datepicker_months = array_values( Tribe__Date_Utils::get_localized_months_full() ); |
| 307 | |
| 308 | tribe( 'asset.data' )->add( 'tribe_l10n_datatables', [ |
| 309 | 'aria' => [ |
| 310 | 'sort_ascending' => __( ': activate to sort column ascending', 'tribe-common' ), |
| 311 | 'sort_descending' => __( ': activate to sort column descending', 'tribe-common' ), |
| 312 | ], |
| 313 | 'length_menu' => __( 'Show _MENU_ entries', 'tribe-common' ), |
| 314 | 'empty_table' => __( 'No data available in table', 'tribe-common' ), |
| 315 | 'info' => __( 'Showing _START_ to _END_ of _TOTAL_ entries', 'tribe-common' ), |
| 316 | 'info_empty' => __( 'Showing 0 to 0 of 0 entries', 'tribe-common' ), |
| 317 | 'info_filtered' => __( '(filtered from _MAX_ total entries)', 'tribe-common' ), |
| 318 | 'zero_records' => __( 'No matching records found', 'tribe-common' ), |
| 319 | 'search' => __( 'Search:', 'tribe-common' ), |
| 320 | 'all_selected_text' => __( 'All items on this page were selected. ', 'tribe-common' ), |
| 321 | 'select_all_link' => __( 'Select all pages', 'tribe-common' ), |
| 322 | 'clear_selection' => __( 'Clear Selection.', 'tribe-common' ), |
| 323 | 'pagination' => [ |
| 324 | 'all' => __( 'All', 'tribe-common' ), |
| 325 | 'next' => __( 'Next', 'tribe-common' ), |
| 326 | 'previous' => __( 'Previous', 'tribe-common' ), |
| 327 | ], |
| 328 | 'select' => [ |
| 329 | 'rows' => [ |
| 330 | 0 => '', |
| 331 | '_' => __( ': Selected %d rows', 'tribe-common' ), |
| 332 | 1 => __( ': Selected 1 row', 'tribe-common' ), |
| 333 | ], |
| 334 | ], |
| 335 | 'datepicker' => [ |
| 336 | 'dayNames' => Tribe__Date_Utils::get_localized_weekdays_full(), |
| 337 | 'dayNamesShort' => Tribe__Date_Utils::get_localized_weekdays_short(), |
| 338 | 'dayNamesMin' => Tribe__Date_Utils::get_localized_weekdays_initial(), |
| 339 | 'monthNames' => $datepicker_months, |
| 340 | 'monthNamesShort' => $datepicker_months, // We deliberately use full month names here, |
| 341 | 'monthNamesMin' => array_values( Tribe__Date_Utils::get_localized_months_short() ), |
| 342 | 'nextText' => esc_html__( 'Next', 'the-events-calendar' ), |
| 343 | 'prevText' => esc_html__( 'Prev', 'the-events-calendar' ), |
| 344 | 'currentText' => esc_html__( 'Today', 'the-events-calendar' ), |
| 345 | 'closeText' => esc_html__( 'Done', 'the-events-calendar' ), |
| 346 | 'today' => esc_html__( 'Today', 'the-events-calendar' ), |
| 347 | 'clear' => esc_html__( 'Clear', 'the-events-calendar' ), |
| 348 | ], |
| 349 | ] ); |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Adds core hooks |
| 354 | */ |
| 355 | public function add_hooks() { |
| 356 | add_action( 'plugins_loaded', [ 'Tribe__App_Shop', 'instance' ] ); |
| 357 | add_action( 'plugins_loaded', [ $this, 'tribe_plugins_loaded' ], PHP_INT_MAX ); |
| 358 | |
| 359 | // Register for the assets to be available everywhere |
| 360 | add_action( 'tribe_common_loaded', [ $this, 'load_assets' ], 1 ); |
| 361 | add_action( 'init', [ $this, 'hook_load_text_domain' ] ); |
| 362 | add_action( 'init', [ $this, 'load_localize_data' ] ); |
| 363 | add_action( 'plugins_loaded', [ 'Tribe__Admin__Notices', 'instance' ], 1 ); |
| 364 | add_action( 'admin_enqueue_scripts', [ $this, 'store_admin_notices' ] ); |
| 365 | |
| 366 | add_filter( 'body_class', [ $this, 'add_js_class' ] ); |
| 367 | add_action( 'wp_footer', [ $this, 'toggle_js_class' ] ); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Adds `tribe-no-js` class to all pages when common is active. |
| 372 | * |
| 373 | * @since 4.3.4 |
| 374 | * |
| 375 | * @param array|string $classes Previous classes on body. |
| 376 | * |
| 377 | * @return array All classes that will be printed on `<body>`. |
| 378 | */ |
| 379 | public function add_js_class( $classes = [] ) { |
| 380 | if ( ! is_array( $classes ) ) { |
| 381 | $classes = explode( ' ', $classes ); |
| 382 | } |
| 383 | |
| 384 | $classes[] = 'tribe-no-js'; |
| 385 | |
| 386 | return array_filter( array_unique( $classes ) ); |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Removes `tribe-no-js` and replaces with `tribe-js` when the Javascript of the page is enabled. |
| 391 | * |
| 392 | * @since 4.3.4 |
| 393 | * |
| 394 | * @return void This method only prints HTML to the screen no return. |
| 395 | */ |
| 396 | public function toggle_js_class() { |
| 397 | ?> |
| 398 | <script> |
| 399 | ( function ( body ) { |
| 400 | 'use strict'; |
| 401 | body.className = body.className.replace( /\btribe-no-js\b/, 'tribe-js' ); |
| 402 | } )( document.body ); |
| 403 | </script> |
| 404 | <?php |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Tells us if we're on an admin screen that needs the Common admin CSS. |
| 409 | * |
| 410 | * Currently this includes post type screens, the Plugins page, Settings pages |
| 411 | * and tabs, Tribe App Shop page, and the Help screen. |
| 412 | * |
| 413 | * @since 4.5.7 |
| 414 | * |
| 415 | * @return bool Whether we should load Common Admin CSS or not. |
| 416 | */ |
| 417 | public function should_load_common_admin_css() { |
| 418 | $helper = Tribe__Admin__Helpers::instance(); |
| 419 | |
| 420 | // Are we on a post type screen? |
| 421 | $is_post_type = $helper->is_post_type_screen(); |
| 422 | |
| 423 | // Are we on the Plugins page? |
| 424 | $is_plugins = $helper->is_screen( 'plugins' ); |
| 425 | |
| 426 | // Are we on the Widgets page? |
| 427 | $is_widgets = $helper->is_screen( 'widgets' ); |
| 428 | |
| 429 | // Are we viewing a generic Tribe screen? |
| 430 | // Includes: Events > Settings, Events > Help, App Shop page, and more. |
| 431 | $is_tribe_screen = $helper->is_screen(); |
| 432 | |
| 433 | return $is_post_type || $is_plugins || $is_widgets || $is_tribe_screen; |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * A Helper method to load text domain |
| 438 | * First it tries to load the wp-content/languages translation then if falls to the try to load $dir language files. |
| 439 | * |
| 440 | * @since 4.0.1 Introduced. |
| 441 | * @since 4.2 Included $domain and $dir params. |
| 442 | * |
| 443 | * @param string $domain The text domain that will be loaded. |
| 444 | * @param string|false $dir What directory should be used to try to load if the default doesn't work. |
| 445 | * |
| 446 | * @return bool If it was able to load the text domain. |
| 447 | */ |
| 448 | public function load_text_domain( $domain, $dir = false ) { |
| 449 | // Added safety just in case this runs twice... |
| 450 | if ( is_textdomain_loaded( $domain ) && ! $GLOBALS['l10n'][ $domain ] instanceof NOOP_Translations ) { |
| 451 | return true; |
| 452 | } |
| 453 | |
| 454 | $locale = get_locale(); |
| 455 | $plugin_rel_path = WP_LANG_DIR . '/plugins/'; |
| 456 | |
| 457 | /** |
| 458 | * Allows users to filter the file location for a given text domain.. |
| 459 | * Be careful when using this filter, it will apply across the whole plugin suite. |
| 460 | * |
| 461 | * @param string $plugin_rel_path The relative path for the language files. |
| 462 | * @param string $domain Which plugin domain we are trying to load. |
| 463 | * @param string $locale Which Language we will load. |
| 464 | * @param string|bool $dir If there was a custom directory passed on the method call. |
| 465 | */ |
| 466 | $plugin_rel_path = apply_filters( 'tribe_load_text_domain', $plugin_rel_path, $domain, $locale, $dir ); |
| 467 | |
| 468 | $loaded = load_plugin_textdomain( $domain, false, $plugin_rel_path ); |
| 469 | |
| 470 | if ( $dir !== false && ! $loaded ) { |
| 471 | return load_plugin_textdomain( $domain, false, $dir ); |
| 472 | } |
| 473 | |
| 474 | return $loaded; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Returns the post types registered by Tribe plugins. |
| 479 | * |
| 480 | * @since 4.0.1 Introduced the method. |
| 481 | * |
| 482 | * @return array Slugs for all Post Types registered. |
| 483 | */ |
| 484 | public static function get_post_types() { |
| 485 | /** |
| 486 | * We default the post type array to empty in tribe-common. Plugins like TEC add to it. |
| 487 | * |
| 488 | * @since 4.0.1 |
| 489 | * |
| 490 | * @param array Slugs for all Post Types registered. |
| 491 | */ |
| 492 | return apply_filters( 'tribe_post_types', [] ); |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Insert an array after a specified key within another array. |
| 497 | * |
| 498 | * @param $key |
| 499 | * @param $source_array |
| 500 | * @param $insert_array |
| 501 | * |
| 502 | * @return array |
| 503 | */ |
| 504 | public static function array_insert_after_key( $key, $source_array, $insert_array ) { |
| 505 | if ( array_key_exists( $key, $source_array ) ) { |
| 506 | $position = array_search( $key, array_keys( $source_array ) ) + 1; |
| 507 | $source_array = array_slice( $source_array, 0, $position, true ) + $insert_array + array_slice( $source_array, $position, null, true ); |
| 508 | } else { |
| 509 | // If no key is found, then add it to the end of the array. |
| 510 | $source_array += $insert_array; |
| 511 | } |
| 512 | |
| 513 | return $source_array; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Insert an array immediately before a specified key within another array. |
| 518 | * |
| 519 | * @param $key |
| 520 | * @param $source_array |
| 521 | * @param $insert_array |
| 522 | * |
| 523 | * @return array |
| 524 | */ |
| 525 | public static function array_insert_before_key( $key, $source_array, $insert_array ) { |
| 526 | if ( array_key_exists( $key, $source_array ) ) { |
| 527 | $position = array_search( $key, array_keys( $source_array ) ); |
| 528 | $source_array = array_slice( $source_array, 0, $position, true ) + $insert_array + array_slice( $source_array, $position, null, true ); |
| 529 | } else { |
| 530 | // If no key is found, then add it to the end of the array. |
| 531 | $source_array += $insert_array; |
| 532 | } |
| 533 | |
| 534 | return $source_array; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * Get the Post ID from a passed integer, a passed WP_Post object, or the current post. |
| 539 | * |
| 540 | * Helper function for getting Post ID. Accepts `null` or a Post ID. If attempting |
| 541 | * to detect $post object and it is not found, returns `false` to avoid a PHP Notice. |
| 542 | * |
| 543 | * @param null|int|WP_Post $candidate Post ID or object, `null` to get the ID of the global post object. |
| 544 | * |
| 545 | * @return int|false The ID of the passed or global post, `false` if the passes object is not a post or the global |
| 546 | * post is not set. |
| 547 | */ |
| 548 | public static function post_id_helper( $candidate = null ) { |
| 549 | $candidate_post = get_post( $candidate ); |
| 550 | |
| 551 | return $candidate_post instanceof WP_Post ? $candidate_post->ID : false; |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * Adds a hook |
| 556 | * |
| 557 | */ |
| 558 | public function store_admin_notices( $page ) { |
| 559 | if ( 'plugins.php' !== $page ) { |
| 560 | return; |
| 561 | } |
| 562 | $notices = apply_filters( 'tribe_plugin_notices', [] ); |
| 563 | wp_localize_script( 'tribe-pue-notices', 'tribe_plugin_notices', $notices ); |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * Runs tribe_plugins_loaded action, should be hooked to the end of plugins_loaded |
| 568 | */ |
| 569 | public function tribe_plugins_loaded() { |
| 570 | tribe( 'admin.notice.php.version' ); |
| 571 | tribe( 'cache' ); |
| 572 | tribe_singleton( 'feature-detection', 'Tribe__Feature_Detection' ); |
| 573 | tribe_register_provider( 'Tribe__Service_Providers__Processes' ); |
| 574 | |
| 575 | if ( ! defined( 'TRIBE_HIDE_MARKETING_NOTICES' ) ) { |
| 576 | tribe( 'admin.notice.marketing' ); |
| 577 | } |
| 578 | |
| 579 | tribe( \Tribe\Admin\Notice\WP_Version::class ); |
| 580 | |
| 581 | /** |
| 582 | * Runs after all plugins including Tribe ones have loaded |
| 583 | * |
| 584 | * @since 4.3 |
| 585 | */ |
| 586 | do_action( 'tribe_plugins_loaded' ); |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * Registers the slug bound to the implementations in the container. |
| 591 | * |
| 592 | * @since 4.4 |
| 593 | * |
| 594 | * @return void Implementation of components loader doesn't return anything. |
| 595 | */ |
| 596 | public function bind_implementations() { |
| 597 | tribe_singleton( 'settings.manager', 'Tribe__Settings_Manager' ); |
| 598 | tribe_singleton( 'settings', 'Tribe__Settings', [ 'hook' ] ); |
| 599 | tribe_singleton( 'ajax.dropdown', 'Tribe__Ajax__Dropdown', [ 'hook' ] ); |
| 600 | tribe_singleton( 'assets', 'Tribe__Assets' ); |
| 601 | tribe_singleton( 'assets.pipeline', 'Tribe__Assets_Pipeline', [ 'hook' ] ); |
| 602 | tribe_singleton( 'asset.data', 'Tribe__Asset__Data', [ 'hook' ] ); |
| 603 | tribe_singleton( 'admin.helpers', 'Tribe__Admin__Helpers' ); |
| 604 | tribe_singleton( 'tracker', 'Tribe__Tracker', [ 'hook' ] ); |
| 605 | tribe_singleton( 'chunker', 'Tribe__Meta__Chunker', [ 'set_post_types', 'hook' ] ); |
| 606 | tribe_singleton( 'cache', 'Tribe__Cache', [ 'hook' ] ); |
| 607 | tribe_singleton( 'languages.locations', 'Tribe__Languages__Locations' ); |
| 608 | tribe_singleton( 'plugins.api', new Tribe__Plugins_API ); |
| 609 | tribe_singleton( 'logger', 'Tribe__Log' ); |
| 610 | tribe_singleton( 'cost-utils', [ 'Tribe__Cost_Utils', 'instance' ] ); |
| 611 | tribe_singleton( 'post-duplicate.strategy-factory', 'Tribe__Duplicate__Strategy_Factory' ); |
| 612 | tribe_singleton( 'post-duplicate', 'Tribe__Duplicate__Post' ); |
| 613 | tribe_singleton( 'context', 'Tribe__Context' ); |
| 614 | tribe_singleton( 'post-transient', 'Tribe__Post_Transient' ); |
| 615 | tribe_singleton( 'db', 'Tribe__Db' ); |
| 616 | tribe_singleton( 'db-lock', DB_Lock::class ); |
| 617 | tribe_singleton( 'freemius', 'Tribe__Freemius' ); |
| 618 | tribe_singleton( 'customizer', 'Tribe__Customizer' ); |
| 619 | |
| 620 | tribe_singleton( Tribe__Dependency::class, Tribe__Dependency::class ); |
| 621 | |
| 622 | tribe_singleton( 'callback', 'Tribe__Utils__Callback' ); |
| 623 | tribe_singleton( 'pue.notices', 'Tribe__PUE__Notices' ); |
| 624 | |
| 625 | tribe_singleton( Tribe__Admin__Help_Page::class, Tribe__Admin__Help_Page::class ); |
| 626 | |
| 627 | tribe_singleton( 'admin.notice.php.version', 'Tribe__Admin__Notice__Php_Version', [ 'hook' ] ); |
| 628 | tribe_singleton( 'admin.notice.marketing', 'Tribe__Admin__Notice__Marketing', [ 'hook' ] ); |
| 629 | tribe_singleton( \Tribe\Admin\Notice\WP_Version::class, \Tribe\Admin\Notice\WP_Version::class, [ 'hook' ] ); |
| 630 | |
| 631 | tribe_register_provider( Tribe__Editor__Provider::class ); |
| 632 | tribe_register_provider( Tribe__Service_Providers__Debug_Bar::class ); |
| 633 | tribe_register_provider( Tribe__Service_Providers__Promoter::class ); |
| 634 | tribe_register_provider( Tribe\Service_Providers\Tooltip::class ); |
| 635 | tribe_register_provider( Tribe\Service_Providers\Dialog::class ); |
| 636 | tribe_register_provider( Tribe\Service_Providers\PUE::class ); |
| 637 | tribe_register_provider( Tribe\Service_Providers\Shortcodes::class ); |
| 638 | tribe_register_provider( Tribe\Service_Providers\Body_Classes::class ); |
| 639 | tribe_register_provider( Tribe\Log\Service_Provider::class ); |
| 640 | tribe_register_provider( Tribe\Service_Providers\Crons::class ); |
| 641 | tribe_register_provider( Tribe\Service_Providers\Widgets::class ); |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Create the Promoter connector singleton early to allow hook into the filters early. |
| 646 | * |
| 647 | * Add a filter to determine_current_user during the setup of common library. |
| 648 | * |
| 649 | * @since 4.9.20 |
| 650 | * |
| 651 | * @return void Internal method without any return. |
| 652 | */ |
| 653 | public function promoter_connector() { |
| 654 | tribe_singleton( 'promoter.connector', 'Tribe__Promoter__Connector' ); |
| 655 | |
| 656 | add_filter( |
| 657 | 'determine_current_user', |
| 658 | tribe_callback( 'promoter.connector', 'authenticate_user_with_connector' ) |
| 659 | ); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | /************************ |
| 664 | * * |
| 665 | * Deprecated Methods * |
| 666 | * * |
| 667 | ************************/ |
| 668 | // @codingStandardsIgnoreStart |
| 669 | |
| 670 | /** |
| 671 | * Helper function to indicate whether the current execution context is AJAX |
| 672 | * |
| 673 | * This method exists to allow us test code that behaves differently depending on the execution |
| 674 | * context. |
| 675 | * |
| 676 | * @since 4.0 |
| 677 | * |
| 678 | * @todo Add warning with '_deprecated_function' |
| 679 | * |
| 680 | * @param bool $doing_ajax An injectable status to override the `DOING_AJAX` check. |
| 681 | * |
| 682 | * @deprecated 4.7.12 |
| 683 | * |
| 684 | * @return boolean |
| 685 | */ |
| 686 | public function doing_ajax( $doing_ajax = null ) { |
| 687 | return tribe( 'context' )->doing_ajax( $doing_ajax ); |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Manages PUE license key notifications. |
| 692 | * |
| 693 | * It's important for the sanity of our users that only one instance of this object |
| 694 | * be created. However, multiple Tribe__Main objects can and will be instantiated, hence |
| 695 | * why for the time being we need to make this field static. |
| 696 | * |
| 697 | * @see https://central.tri.be/issues/65755 |
| 698 | * |
| 699 | * @deprecated 4.7.10 |
| 700 | * |
| 701 | * @return Tribe__PUE__Notices |
| 702 | */ |
| 703 | public function pue_notices() { |
| 704 | return tribe( 'pue.notices' ); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * |
| 709 | * @deprecated 4.7.10 |
| 710 | * |
| 711 | * @return Tribe__Log |
| 712 | */ |
| 713 | public function log() { |
| 714 | return tribe( 'logger' ); |
| 715 | } |
| 716 | // @codingStandardsIgnoreEnd |
| 717 | } |
| 718 |