/** * The init function for this class, adds actions and filters. * */ public static function init() { if (is_admin()) { if (!Tribe__Main::instance()->doing_ajax()) { // Logic for sorting events by event category or tags add_filter('posts_clauses', array(__CLASS__, 'sort_by_tax'), 10, 2); // Logic for sorting events by start or end date add_filter('posts_clauses', array(__CLASS__, 'sort_by_event_date'), 11, 2); add_filter('posts_fields', array(__CLASS__, 'events_search_fields'), 10, 2); // Pagination add_filter('post_limits', array(__CLASS__, 'events_search_limits'), 10, 2); add_filter('tribe_apm_headers_' . Tribe__Events__Main::POSTTYPE, array(__CLASS__, 'column_headers_check')); add_filter('views_edit-tribe_events', array(__CLASS__, 'update_event_counts')); } /** * The following actions will need to be fired on AJAX calls, the logic above is required. * * Registers custom event columns category/start date/end date */ add_action('manage_posts_custom_column', array(__CLASS__, 'custom_columns'), 10, 2); add_filter('manage_' . Tribe__Events__Main::POSTTYPE . '_posts_columns', array(__CLASS__, 'column_headers')); // Registers event start/end date as sortable columns add_action('manage_edit-' . Tribe__Events__Main::POSTTYPE . '_sortable_columns', array(__CLASS__, 'register_sortable_columns'), 10, 2); } }
/** * Create a clean way of fetching API variables * * @return stdClass|WP_Error */ public function api() { // Make it an Object $api = (object) $this->api; if (defined('EVENT_AGGREGATOR_API_BASE_URL')) { $api->domain = EVENT_AGGREGATOR_API_BASE_URL; } // Since we don't need to fetch this key elsewhere $api->key = get_option('pue_install_key_event_aggregator'); /** * Creates a clean way to filter and redirect to another API domain/path * @var stdClass */ $api = (object) apply_filters('tribe_aggregator_api', $api); // The user doesn't have a license key if (empty($api->key)) { return tribe_error('core:aggregator:invalid-service-key'); } $aggregator = Tribe__Events__Aggregator::instance(); $plugin_name = $aggregator->filter_pue_plugin_name('', 'event-aggregator'); $pue_notices = Tribe__Main::instance()->pue_notices(); $has_notice = $pue_notices->has_notice($plugin_name); // The user doesn't have a valid license key if (empty($api->key) || $has_notice) { return tribe_error('core:aggregator:invalid-service-key'); } return $api; }
/** * Event date & upcoming filters should not be removed when the query is being done via AJAX * * We have to segregate the AJAX tests because we're going to twiddle the DOING_AJAX constant * * @test */ public function it_should_not_remove_date_filters_when_doing_ajax() { Tribe__Main::instance()->doing_ajax(true); $query = new WP_Query(); $query->parse_query(['post_type' => Tribe__Events__Main::POSTTYPE]); $this->assertFalse(Tribe__Events__Query::should_remove_date_filters($query), 'Date filters should not be removed when doing AJAX stuff'); Tribe__Main::instance()->doing_ajax(false); }
/** * Render the debug logging to the php error log. This can be over-ridden by removing the filter. * * @param string $title - message to display in log * @param string|bool $data - optional data to display * @param string $format - optional format (log|warning|error|notice) * * @return void */ public static function render($title, $data = false, $format = 'log') { $format = ucfirst($format); if (Tribe__Settings_Manager::instance()->get_option('debugEvents')) { $plugin = basename(dirname(Tribe__Main::instance()->plugin_path)); error_log("{$plugin}/common - {$format}: {$title}"); if ($data && $data != '') { error_log("{$plugin}/common - {$format}: " . print_r($data, true)); } } }
/** * A private method to prevent it to be created twice. * It will add the methods and setup any dependencies */ private function __construct() { add_filter('admin_title', array($this, 'filter_admin_title'), 10, 2); // Configure the Base Tabs $this->register('Tribe__Events__Aggregator__Tabs__New'); $this->register('Tribe__Events__Aggregator__Tabs__Scheduled'); $this->register('Tribe__Events__Aggregator__Tabs__History'); if (!empty($_GET['id']) || Tribe__Main::instance()->doing_ajax()) { $this->register('Tribe__Events__Aggregator__Tabs__Edit'); } }
/** * Sets up the textdomain stuff */ function event_tickets_plus_setup_textdomain() { tribe_init_tickets_plus_autoloading(); $mopath = trailingslashit(basename(dirname(__FILE__))) . 'lang/'; $domain = 'event-tickets-plus'; // If we don't have Common classes load the old fashioned way if (!class_exists('Tribe__Main')) { load_plugin_textdomain($domain, false, $mopath); } else { // This will load `wp-content/languages/plugins` files first Tribe__Main::instance()->load_text_domain($domain, $mopath); } define('EVENT_TICKETS_PLUS_TEXTDOMAIN_LOADED', true); }
/** * Register the Methods in the correct places */ private function __construct() { // Not in the admin we don't even care if (!is_admin()) { return; } // Before we bail on the add_action('wp_ajax_tribe_notice_dismiss', array($this, 'maybe_dismiss')); // Doing AJAX? bail. if (Tribe__Main::instance()->doing_ajax()) { return; } // Hook the actual rendering of notices add_action('current_screen', array($this, 'hook'), 20); // Add our notice dismissal script tribe_asset(Tribe__Main::instance(), 'tribe-notice-dismiss', 'notice-dismiss.js', array('jquery'), 'admin_enqueue_scripts'); }
/** * Shows message if the plugin can't load due to TEC not being installed. */ function tribe_show_fail_message() { if (!current_user_can('activate_plugins')) { return; } $mopath = trailingslashit(basename(dirname(__FILE__))) . 'lang/'; $domain = 'tribe-events-calendar-pro'; // If we don't have Common classes load the old fashioned way if (!class_exists('Tribe__Main')) { load_plugin_textdomain($domain, false, $mopath); } else { // This will load `wp-content/languages/plugins` files first Tribe__Main::instance()->load_text_domain($domain, $mopath); } $url = 'plugin-install.php?tab=plugin-information&plugin=the-events-calendar&TB_iframe=true'; $title = __('The Events Calendar', 'tribe-events-calendar-pro'); echo '<div class="error"><p>' . sprintf(__('To begin using Events Calendar PRO, please install the latest version of <a href="%s" class="thickbox" title="%s">The Events Calendar</a>.', 'tribe-events-calendar-pro'), esc_url($url), $title) . '</p></div>'; }
/** * Initializes admin-specific items for the events admin list dashboard page. Hooked to the * current_screen action * * @param WP_Screen $screen WP Admin screen object for the current page */ public function init_admin_list_screen($screen) { // If we are dealing with a AJAX call just drop these checks if (!Tribe__Main::instance()->doing_ajax()) { if ('edit' !== $screen->base) { return; } if (self::POSTTYPE !== $screen->post_type) { return; } } Tribe__Events__Admin_List::init(); }
/** * Returns whether or not the event date & upcoming filters should be removed from the query * * @since 4.0 * @param WP_Query $query WP_Query object * @return boolean */ public static function should_remove_date_filters($query) { // if we're doing ajax, let's keep the date filters if (Tribe__Main::instance()->doing_ajax()) { return false; } // otherwise, let's remove the date filters if we're in the admin dashboard and the query is // and event query on the tribe_events edit page return is_admin() && $query->tribe_is_event_query && Tribe__Admin__Helpers::instance()->is_screen('edit-' . Tribe__Events__Main::POSTTYPE); }
/** * Returns the currently enabled logging object or null if it is not * available. * * @return Tribe__Log__Logger|null */ protected function current_logger() { return Tribe__Main::instance()->log()->get_current_logger(); }
// Creates the Extra Help section $help->add_section('extra-help', __('Getting More Help', 'tribe-common'), 20); $help->add_section_content('extra-help', __('While the resources above help solve a majority of the issues we see, there are times you might be looking for extra support. If you need assistance using our plugins and would like us to take a look, please follow these steps:', 'tribe-common'), 0); $help->add_section_content('extra-help', array('type' => 'ol', sprintf(__('%s. All of the common (and not-so-common) answers to questions we see are here. It’s often the fastest path to finding an answer!', 'tribe-common'), '<strong><a href="http://m.tri.be/18j9" target="_blank">' . __('Check our Knowledgebase', 'tribe-common') . '</a></strong>'), sprintf(__('%s. Testing for an existing conflict is the best start for in-depth troubleshooting. We will often ask you to follow these steps when opening a new thread, so doing this ahead of time will be super helpful.', 'tribe-common'), '<strong><a href="http://m.tri.be/18jh" target="_blank">' . __('Test for a theme or plugin conflict', 'tribe-common') . '</a></strong>'), sprintf(__('%s. There are very few issues we haven’t seen and it’s likely another user has already asked your question and gotten an answer from our support staff. While posting to the forums is open only to paid customers, they are open for anyone to search and review.', 'tribe-common'), '<strong><a href="http://m.tri.be/4w/" target="_blank">' . __('Search our support forum', 'tribe-common') . '</a></strong>')), 10); // By default these three will be gathered $help->add_section_content('extra-help', __('Please note that all hands-on support is provided via the forums. You can email or tweet at us… ​but we will probably point you back to the forums 😄', 'tribe-common'), 40); $help->add_section_content('extra-help', '<div style="text-align: right;"><a href="http://m.tri.be/18ji" target="_blank" class="button">' . __('Read more about our support policy', 'tribe-common') . '</a></div>', 40); // Creates the System Info section $help->add_section('system-info', __('System Information', 'tribe-common'), 30); $help->add_section_content('system-info', __('The details of your calendar plugin and settings is often needed for you or our staff to help troubleshoot an issue. Please opt-in below to automatically share your system information with our support team. This will allow us to assist you faster if you post in our forums.', 'tribe-common'), 0); $help->add_section_content('system-info', Tribe__Support::opt_in(), 10); $help->add_section_content('system-info', '<div class="system-info-copy"><button data-clipboard-action="copy" class="system-info-copy-btn" data-clipboard-target=".support-stats" ><span class="dashicons dashicons-clipboard license-btn"></span>' . __('Copy to clipboard', 'tribe-common') . '</button></div>', 10); $help->add_section('template-changes', __('Recent Template Changes', 'tribe-common'), 40); $help->add_section_content('template-changes', Tribe__Support__Template_Checker_Report::generate()); $help->add_section('event-log', __('Event Log', 'tribe-common'), 50); $help->add_section_content('event-log', Tribe__Main::instance()->log()->admin()->display_log()); ?> <div id="tribe-help-general"> <?php $help->get_sections(); ?> </div> <div id="tribe-help-sidebar"> <?php /** * Fires at the top of the sidebar on Settings > Help tab */ do_action('tribe_help_sidebar_before'); foreach ($plugins as $key => $plugin) {
/** * Asset calls for vendor packages * * @param string $name * @param array $deps Dependents */ public static function asset_package($name, $deps = array()) { $common = Tribe__Main::instance(); $prefix = 'tribe-events'; // setup plugin resources & 3rd party vendor urls $vendor_url = trailingslashit($common->plugin_url) . 'vendor/'; self::handle_asset_package_request($name, $deps, $vendor_url, $prefix, $common); }
/** * Hooks into the venue save and if we don't have Geo Data for that address, * it calls the Google Maps API and grabs the Lat and Lng for that venue. * * @param $venueId * @param $data * * @return bool */ public function save_venue_geodata($venueId, $data) { $_address = !empty($data['Address']) ? $data['Address'] : ''; $_city = !empty($data['City']) ? $data['City'] : ''; $_province = !empty($data['Province']) ? $data['Province'] : ''; $_state = !empty($data['State']) ? $data['State'] : ''; $_zip = !empty($data['Zip']) ? $data['Zip'] : ''; $_country = !empty($data['Country']) ? $data['Country'] : ''; $overwrite = !empty($data['OverwriteCoords']) ? 1 : 0; $_lat = !empty($data['Lat']) && is_numeric($data['Lat']) ? (double) $data['Lat'] : false; $_lng = !empty($data['Lng']) && is_numeric($data['Lng']) ? (double) $data['Lng'] : false; $reset = false; // Check the Overwrite data, otherwise just reset it if ($overwrite && false !== $_lat && false !== $_lng) { update_post_meta($venueId, self::OVERWRITE, 1); update_post_meta($venueId, self::LAT, (string) $_lat); update_post_meta($venueId, self::LNG, (string) $_lng); delete_transient(self::ESTIMATION_CACHE_KEY); return true; } else { if (1 === (int) get_post_meta($venueId, self::OVERWRITE, true)) { $reset = true; } update_post_meta($venueId, self::OVERWRITE, 0); } $address = trim($_address . ' ' . $_city . ' ' . $_province . ' ' . $_state . ' ' . $_zip . ' ' . $_country); if (empty($address)) { return false; } // If the address didn't change, doesn't make sense to query google again for the geo data if ($address === get_post_meta($venueId, self::ADDRESS, true) && true !== $reset) { return false; } $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address); $data = wp_remote_get(apply_filters('tribe_events_pro_geocode_request_url', $url)); if (is_wp_error($data) || !isset($data['body'])) { Tribe__Main::instance()->log()->log_warning(sprintf(_x('Geocode request failed ($1%s - $2%s)', 'debug geodata', 'tribe-events-calendar-pro'), is_wp_error($data) ? $data->get_error_code() : _x('empty response', 'debug geodata'), $url), __METHOD__); return false; } $data_arr = json_decode($data['body']); if (isset($data_arr->status) && 'OVER_QUERY_LIMIT' === $data_arr->status) { if ($this->over_query_limit_displayed) { return false; } set_transient('tribe-google-over-limit', 1, time() + MINUTE_IN_SECONDS); $this->over_query_limit_displayed = true; return false; } if (!empty($data_arr->results[0]->geometry->location->lat)) { update_post_meta($venueId, self::LAT, (string) $data_arr->results[0]->geometry->location->lat); } if (!empty($data_arr->results[0]->geometry->location->lng)) { update_post_meta($venueId, self::LNG, (string) $data_arr->results[0]->geometry->location->lng); } // Saving the aggregated address so we don't need to ping google on every save update_post_meta($venueId, self::ADDRESS, $address); delete_transient(self::ESTIMATION_CACHE_KEY); return true; }
protected function default_readme_file() { return dirname(Tribe__Main::instance()->plugin_path) . '/readme.txt'; }
/** * Get all possible translations for a String based on the given Languages and Domains * * WARNING: This function is slow because it deals with files, so don't overuse it! * Differently from the `get_i18n_strings` method this will not use any domain that's not specified. * * @todo Include support for the `load_theme_textdomain` + `load_muplugin_textdomain` * * @param array $strings An array of strings (required) * @param array $languages Which l10n to fetch the string (required) * @param array $domains Possible Domains to re-load * * @return array A multi level array with the possible translations for the given strings */ public function get_i18n_strings_for_domains($strings, $languages, $domains = array('default')) { foreach ($languages as $language) { $this->_locale = $language; foreach ((array) $domains as $domain => $file) { // Configure the language add_filter('locale', array($this, '_set_locale')); // Reload it with the correct language unload_textdomain($domain); if ('default' === $domain) { load_default_textdomain(); } else { Tribe__Main::instance()->load_text_domain($domain, $file); } // Loop on the strings the build the possible translations foreach ($strings as $key => $value) { $value = is_array($value) ? reset($value) : $value; if (!is_string($value)) { continue; } // Make sure we have an Array $strings[$key] = (array) $strings[$key]; // Grab the possible strings for Default and Any other domain if ('default' === $domain) { $strings[$key][] = __($value); $strings[$key][] = __(strtolower($value)); $strings[$key][] = __(ucfirst($value)); } else { $strings[$key][] = __($value, $domain); $strings[$key][] = __(strtolower($value), $domain); $strings[$key][] = __(ucfirst($value), $domain); } } // Set back to the default language remove_filter('locale', array($this, '_set_locale')); // Reload it with the correct language unload_textdomain($domain); if ('default' === $domain) { load_default_textdomain(); } else { Tribe__Main::instance()->load_text_domain($domain, $file); } } } // Prevent Empty Strings and Duplicates foreach ($strings as $key => $value) { $strings[$key] = array_filter(array_unique(array_map('sanitize_title_with_dashes', (array) $value))); } return $strings; }
/** * Check for plugin updates. * * The results are stored in the DB option specified in $pue_option_name. * * @param array $updates * */ public function check_for_updates($updates = array()) { $state = $this->get_option($this->pue_option_name, false, false); if (empty($state)) { $state = new StdClass(); $state->lastCheck = 0; $state->checkedVersion = ''; $state->update = null; } $state->lastCheck = time(); $state->checkedVersion = $this->get_installed_version(); $this->update_option($this->pue_option_name, $state); //Save before checking in case something goes wrong $state->update = $this->request_update(); // If a null update was returned, skip the end of the function. if ($state->update == null) { $this->update_option($this->pue_option_name, $state); return $updates; } //Is there an update to insert? if (version_compare($state->update->version, $this->get_installed_version(), '>')) { if (empty($updates)) { $updates = (object) array('response' => array()); } $updates->response[$this->get_plugin_file()] = $state->update->to_wp_format(); // If the key has expired we should register an appropriate admin notice if ($this->plugin_info->api_expired) { Tribe__Main::instance()->pue_notices()->add_notice(Tribe__PUE__Notices::EXPIRED_KEY, $this->plugin_name); } } $this->update_option($this->pue_option_name, $state); return $updates; }
/** * Renders the Shop App page */ public function do_menu_page() { $remote = $this->get_all_products(); if (!empty($remote)) { $products = null; if (property_exists($remote, 'data')) { $products = $remote->data; } $banner = null; if (property_exists($remote, 'banner')) { $banner = $remote->banner; } if (empty($products)) { return; } $categories = array_unique(wp_list_pluck($products, 'category')); include_once Tribe__Main::instance()->plugin_path . 'src/admin-views/app-shop.php'; } }
/** * Load textdomain for localization * * @return void */ public function loadTextDomain() { $mopath = $this->pluginDir . 'lang/'; $domain = 'tribe-events-calendar-pro'; // If we don't have Common classes load the old fashioned way if (!class_exists('Tribe__Main')) { load_plugin_textdomain($domain, false, $mopath); } else { // This will load `wp-content/languages/plugins` files first Tribe__Main::instance()->load_text_domain($domain, $mopath); } }
/** * Allows us to log if we are using WP_CLI to fire this cron task * * @see http://wp-cli.org/docs/internal-api/#output * * @param string $type What kind of log is this * @param string $message message displayed * * @return void */ public function log($type = 'colorize', $message = '') { // Log on our Structure Tribe__Main::instance()->log()->log_debug($message, 'aggregator'); // Only go further if we have WP_CLI if (!class_exists('WP_CLI')) { return false; } switch ($type) { case 'error': WP_CLI::error($message); break; case 'warning': WP_CLI::warning($message); break; case 'success': WP_CLI::success($message); break; case 'debug': WP_CLI::debug($message, 'aggregator'); break; case 'colorize': default: WP_CLI::log(WP_CLI::colorize($message)); break; } }
/** * Finalize the initialization of this plugin */ public function plugins_loaded() { // It's possible we'll have initialized already (if the plugin has been embedded as a vendor lib // within another plugin, for example) in which case we need not repeat the process if ($this->has_initialized) { return; } if (class_exists('TribeEvents', false) || class_exists('Tribe__Events__Main') && !version_compare(Tribe__Events__Main::VERSION, self::MIN_TEC_VERSION, '>=')) { add_action('admin_notices', array($this, 'tec_compatibility_notice')); /** * Fires if Event Tickets cannot load due to compatibility or other problems. */ do_action('tribe_tickets_plugin_failed_to_load'); return; } $this->init_autoloading(); // initialize the common libraries $this->common(); Tribe__Main::instance()->load_text_domain('event-tickets', $this->plugin_dir . 'lang/'); $this->hooks(); $this->has_initialized = true; $this->rsvp(); $this->user_event_confirmation_list_shortcode(); // Load the Hooks on JSON_LD Tribe__Tickets__JSON_LD__Order::hook(); /** * Fires once Event Tickets has completed basic setup. */ do_action('tribe_tickets_plugin_loaded'); }
/** * Renders the Shop App page */ public function do_menu_page() { $products = $this->get_all_products(); include_once Tribe__Main::instance()->plugin_path . 'src/admin-views/app-shop.php'; }
/** * Sets up the Javascript needed to facilitate the ajax loop on the frontend. */ public function notice_assets() { $plugin = Tribe__Main::instance(); $script = trailingslashit($plugin->plugin_url) . 'src/resources/js/events-admin-timezone-updater.js'; $handle = 'tribe-events-ajax-timezone-update'; wp_enqueue_script($handle, $script, array('jquery'), false, true); wp_localize_script($handle, 'tribe_timezone_update', array('continue' => $this->update_needed(), 'failure_msg' => __('A problem stopped the timezone update process from completing. Please refresh and try again.', 'the-events-calendar'), 'check' => wp_create_nonce('timezone-settings'))); }
/** * Create the help tab */ public function do_help_tab() { include_once Tribe__Main::instance()->plugin_path . 'src/admin-views/tribe-options-help.php'; }
<?php /* Description: An event settings framework for managing shared options Version: 4.1 Author: Modern Tribe, Inc. Author URI: http://m.tri.be/1x Text Domain: tribe-common License: GPLv2 or later */ /* Copyright 2009-2015 by Modern Tribe Inc and the contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // the main plugin class require_once dirname(__FILE__) . '/src/Tribe/Main.php'; Tribe__Main::instance();
/** * Renders the notice itself (the provided HTML will be wrapped in a suitable container div). * * @param string $slug * @param string $inner_html */ protected function render_notice($slug, $inner_html) { $spirit_animal = esc_url(Tribe__Main::instance()->plugin_url . 'src/resources/images/spirit-animal.png'); $html = '<div class="api-check"> <div class="tribe-spirit-animal"> <img src="' . $spirit_animal . '"/> </div> <div class="notice-content">' . $inner_html . '</div> </div>'; Tribe__Admin__Notices::instance()->render($slug, $html); }
/** * Matcher for administration pages action * * @param string|array|null $action What will be checked to see if we return true or false * * @return boolean */ public function is_action($action = null) { global $current_screen; // Not in the admin we don't even care if (!is_admin()) { return false; } // Doing AJAX? bail. if (Tribe__Main::instance()->doing_ajax()) { return false; } // Avoid Notices by checking the object type of WP_Screen if (!$current_screen instanceof WP_Screen) { return false; } // Match any of the pages set if (!is_scalar($action) && in_array($current_screen->action, (array) $action)) { return true; } // Match a specific page if ($current_screen->action === $action) { return true; } return false; }
/** * Enquues a script to handle live refresh of the date previews. */ public function live_refresh_script() { $url = Tribe__Template_Factory::getMinFile(tribe_resource_url('admin-date-preview.js', false, null, Tribe__Main::instance()), true); wp_enqueue_script('tribe-date-live-refresh', $url, array('jquery'), false, true); }