/** * Configures an admin bar object adding menus, groups and nodes to it. * * @param WP_Admin_Bar $wp_admin_bar * * @return array An array of menus to add to the admin bar. */ public function configure(WP_Admin_Bar $wp_admin_bar) { $main = Tribe__Events__Main::instance(); $wp_admin_bar->add_menu(array('id' => 'tribe-events', 'title' => '<span class="ab-icon dashicons-before dashicons-calendar"></span>' . sprintf(__('%s', 'the-events-calendar'), $main->plural_event_label), 'href' => $main->getLink('home'))); $wp_admin_bar->add_group(array('id' => 'tribe-events-group', 'parent' => 'tribe-events')); $wp_admin_bar->add_group(array('id' => 'tribe-events-add-ons-group', 'parent' => 'tribe-events')); $wp_admin_bar->add_group(array('id' => 'tribe-events-settings-group', 'parent' => 'tribe-events')); if (current_user_can('edit_tribe_events')) { $wp_admin_bar->add_group(array('id' => 'tribe-events-import-group', 'parent' => 'tribe-events-add-ons-group')); } $wp_admin_bar->add_menu(array('id' => 'tribe-events-view-calendar', 'title' => esc_html__('View Calendar', 'the-events-calendar'), 'href' => $main->getLink('home'), 'parent' => 'tribe-events-group')); if (current_user_can('edit_tribe_events')) { $wp_admin_bar->add_menu(array('id' => 'tribe-events-add-event', 'title' => sprintf(esc_html__('Add %s', 'the-events-calendar'), $main->singular_event_label), 'href' => trailingslashit(get_admin_url()) . 'post-new.php?post_type=' . Tribe__Events__Main::POSTTYPE, 'parent' => 'tribe-events-group')); } if (current_user_can('edit_tribe_events')) { $wp_admin_bar->add_menu(array('id' => 'tribe-events-edit-events', 'title' => sprintf(esc_html__('Edit %s', 'the-events-calendar'), $main->plural_event_label), 'href' => trailingslashit(get_admin_url()) . 'edit.php?post_type=' . Tribe__Events__Main::POSTTYPE, 'parent' => 'tribe-events-group')); } if (current_user_can('publish_tribe_events')) { $import_node = $wp_admin_bar->get_node('tribe-events-import'); if (!is_object($import_node)) { $wp_admin_bar->add_node(array('id' => 'tribe-events-import', 'title' => esc_html__('Import', 'the-events-calendar'), 'parent' => 'tribe-events-import-group', 'href' => esc_url(add_query_arg(array('post_type' => Tribe__Events__Main::POSTTYPE, 'page' => 'aggregator'), admin_url('edit.php'))))); } } if (current_user_can('manage_options')) { $hide_all_settings = Tribe__Settings_Manager::get_network_option('allSettingsTabsHidden', '0'); if ($hide_all_settings == '0') { $wp_admin_bar->add_menu(array('id' => 'tribe-events-settings', 'title' => esc_html__('Settings', 'the-events-calendar'), 'href' => Tribe__Settings::instance()->get_url(), 'parent' => 'tribe-events-settings-group')); } // Only show help link if it's not blocked in network admin. $hidden_settings_tabs = Tribe__Settings_Manager::get_network_option('hideSettingsTabs', array()); if (!in_array('help', $hidden_settings_tabs)) { $href = esc_url(add_query_arg(array('post_type' => Tribe__Events__Main::POSTTYPE, 'page' => 'tribe-help'), admin_url('edit.php'))); $wp_admin_bar->add_menu(array('id' => 'tribe-events-help', 'title' => esc_html__('Help', 'the-events-calendar'), 'href' => $href, 'parent' => 'tribe-events-settings-group')); } } }
/** * create the main option page * * @return void */ public function addPage() { if (!$this->should_setup_pages()) { return; } if (!is_multisite() || is_multisite() && '0' == Tribe__Settings_Manager::get_network_option('allSettingsTabsHidden', '0')) { if (post_type_exists('tribe_events')) { self::$parent_page = 'edit.php?post_type=tribe_events'; } else { self::$parent_page = 'admin.php?page=tribe-common'; add_menu_page(esc_html__('Events', 'tribe-common'), esc_html__('Events', 'tribe-common'), apply_filters('tribe_common_event_page_capability', 'manage_options'), self::$parent_slug, null, 'dashicons-calendar', 6); } $this->admin_page = add_submenu_page($this->get_parent_slug(), esc_html__('Events Settings', 'tribe-common'), esc_html__('Settings', 'tribe-common'), $this->requiredCap, self::$parent_slug, array($this, 'generatePage')); } }
/** * Get value for a specific network option * * @param string $optionName name of option * @param string $default default value * * @return mixed results of option query */ public function getNetworkOption($optionName, $default = '') { _deprecated_function(__METHOD__, '4.0', 'Tribe__Settings_Manager::get_network_option'); return Tribe__Settings_Manager::get_network_option($optionName, $default); }
/** * Get Network Options * * Retrieve specific key from options array, optionally provide a default return value * * @category Events * @param string $optionName Name of the option to retrieve. * @param string $default Value to return if no such option is found. * * @return mixed Value of the option if found. * @todo Abstract this function out of template tags or otherwise secure it from other namespace conflicts. */ function tribe_get_network_option($optionName, $default = '') { return Tribe__Settings_Manager::get_network_option($optionName, $default); }
/** * displays the content for the tab * * @return void */ public function doContent() { if ($this->display_callback && is_callable($this->display_callback)) { call_user_func($this->display_callback); return; } $sent_data = get_option('tribe_settings_sent_data', array()); if (is_array($this->fields) && !empty($this->fields)) { foreach ($this->fields as $key => $field) { if (isset($sent_data[$key])) { // if we just saved [or attempted to], get the value that was inputed $value = $sent_data[$key]; } else { // Some options should always be stored at network level $network_option = isset($field['network_option']) ? (bool) $field['network_option'] : false; if (is_network_admin()) { $parent_option = isset($field['parent_option']) ? $field['parent_option'] : Tribe__Main::OPTIONNAMENETWORK; } if (!is_network_admin()) { $parent_option = isset($field['parent_option']) ? $field['parent_option'] : Tribe__Main::OPTIONNAME; } // get the field's parent_option in order to later get the field's value $parent_option = apply_filters('tribe_settings_do_content_parent_option', $parent_option, $key); $default = isset($field['default']) ? $field['default'] : null; $default = apply_filters('tribe_settings_field_default', $default, $field); if (!$parent_option) { // no parent option, get the straight up value if ($network_option || is_network_admin()) { $value = get_site_option($key, $default); } else { $value = get_option($key, $default); } } else { // there's a parent option if ($parent_option == Tribe__Main::OPTIONNAME) { // get the options from Tribe__Settings_Manager if we're getting the main array $value = Tribe__Settings_Manager::get_option($key, $default); } elseif ($parent_option == Tribe__Main::OPTIONNAMENETWORK) { $value = Tribe__Settings_Manager::get_network_option($key, $default); } else { // else, get the parent option normally if (is_network_admin()) { $options = (array) get_site_option($parent_option); } else { $options = (array) get_option($parent_option); } $value = isset($options[$key]) ? $options[$key] : $default; } } } // escape the value for display if (!empty($field['esc_display']) && function_exists($field['esc_display'])) { $value = $field['esc_display']($value); } elseif (is_string($value)) { $value = esc_attr(stripslashes($value)); } // filter the value $value = apply_filters('tribe_settings_get_option_value_pre_display', $value, $key, $field); // create the field new Tribe__Field($key, $field, $value); } } else { // no fields setup for this tab yet echo '<p>' . esc_html__('There are no fields setup for this tab yet.', 'tribe-common') . '</p>'; } }
/** * Add the buttons/dropdown to the admin toolbar * * @return null */ public function addToolbarItems() { if ((!defined('TRIBE_DISABLE_TOOLBAR_ITEMS') || !TRIBE_DISABLE_TOOLBAR_ITEMS) && !is_network_admin()) { global $wp_admin_bar; $wp_admin_bar->add_menu(array('id' => 'tribe-events', 'title' => '<span class="ab-icon dashicons-before dashicons-calendar"></span>' . sprintf(__('%s', 'the-events-calendar'), $this->plural_event_label), 'href' => $this->getLink('home'))); $wp_admin_bar->add_group(array('id' => 'tribe-events-group', 'parent' => 'tribe-events')); $wp_admin_bar->add_group(array('id' => 'tribe-events-add-ons-group', 'parent' => 'tribe-events')); $wp_admin_bar->add_group(array('id' => 'tribe-events-settings-group', 'parent' => 'tribe-events')); if (current_user_can('edit_tribe_events')) { $wp_admin_bar->add_group(array('id' => 'tribe-events-import-group', 'parent' => 'tribe-events-add-ons-group')); } $wp_admin_bar->add_menu(array('id' => 'tribe-events-view-calendar', 'title' => esc_html__('View Calendar', 'the-events-calendar'), 'href' => $this->getLink('home'), 'parent' => 'tribe-events-group')); if (current_user_can('edit_tribe_events')) { $wp_admin_bar->add_menu(array('id' => 'tribe-events-add-event', 'title' => sprintf(esc_html__('Add %s', 'the-events-calendar'), $this->singular_event_label), 'href' => trailingslashit(get_admin_url()) . 'post-new.php?post_type=' . self::POSTTYPE, 'parent' => 'tribe-events-group')); } if (current_user_can('edit_tribe_events')) { $wp_admin_bar->add_menu(array('id' => 'tribe-events-edit-events', 'title' => sprintf(esc_html__('Edit %s', 'the-events-calendar'), $this->plural_event_label), 'href' => trailingslashit(get_admin_url()) . 'edit.php?post_type=' . self::POSTTYPE, 'parent' => 'tribe-events-group')); } if (current_user_can('publish_tribe_events')) { $import_node = $wp_admin_bar->get_node('tribe-events-import'); if (!is_object($import_node)) { $wp_admin_bar->add_menu(array('id' => 'tribe-events-import', 'title' => esc_html__('Import', 'the-events-calendar'), 'parent' => 'tribe-events-import-group')); } $wp_admin_bar->add_menu(array('id' => 'tribe-csv-import', 'title' => esc_html__('CSV', 'the-events-calendar'), 'href' => esc_url(add_query_arg(array('post_type' => self::POSTTYPE, 'page' => 'events-importer', 'tab' => 'csv'), admin_url('edit.php'))), 'parent' => 'tribe-events-import')); } if (current_user_can('manage_options')) { $hide_all_settings = Tribe__Settings_Manager::get_network_option('allSettingsTabsHidden', '0'); if ($hide_all_settings == '0') { $wp_admin_bar->add_menu(array('id' => 'tribe-events-settings', 'title' => esc_html__('Settings', 'the-events-calendar'), 'href' => Tribe__Settings::instance()->get_url(), 'parent' => 'tribe-events-settings-group')); } // Only show help link if it's not blocked in network admin. $hidden_settings_tabs = Tribe__Settings_Manager::get_network_option('hideSettingsTabs', array()); if (!in_array('help', $hidden_settings_tabs)) { $wp_admin_bar->add_menu(array('id' => 'tribe-events-help', 'title' => esc_html__('Help', 'the-events-calendar'), 'href' => Tribe__Settings::instance()->get_url(array('tab' => 'help')), 'parent' => 'tribe-events-settings-group')); } } } }