/** * Load Titan Framework. * * @link http://www.titanframework.net/embedding-titan-framework-in-your-project/ * @since 3.0.0 */ public function load_titan_framework() { /* * When using the embedded framework, use it only if the framework * plugin isn't activated. */ // Don't do anything when we're activating a plugin to prevent errors // on redeclaring Titan classes if (!empty($_GET['action']) && !empty($_GET['plugin'])) { if ($_GET['action'] == 'activate') { return; } } // Check if the framework plugin is activated $useEmbeddedFramework = true; $activePlugins = get_option('active_plugins'); if (is_array($activePlugins)) { foreach ($activePlugins as $plugin) { if (is_string($plugin)) { if (stripos($plugin, '/titan-framework.php') !== false) { $useEmbeddedFramework = false; break; } } } } // Use the embedded Titan Framework if ($useEmbeddedFramework && !class_exists('TitanFramework')) { require_once WPAS_PATH . 'vendor/gambitph/titan-framework/titan-framework.php'; } /* * Start your Titan code below */ $titan = TitanFramework::getInstance('wpas'); $settings = $titan->createContainer(array('type' => 'admin-page', 'name' => __('Settings', 'awesome-support'), 'title' => __('Awesome Support Settings', 'awesome-support'), 'id' => 'wpas-settings', 'parent' => 'edit.php?post_type=ticket', 'capability' => 'settings_tickets')); /** * Get plugin core options * * @var (array) * @see admin/includes/settings.php */ $options = wpas_get_settings(); /* Parse options */ foreach ($options as $tab => $content) { /* Add a new tab */ $tab = $settings->createTab(array('name' => $content['name'], 'title' => isset($content['title']) ? $content['title'] : $content['name'], 'id' => $tab)); /* Add all options to current tab */ foreach ($content['options'] as $option) { $tab->createOption($option); if (isset($option['type']) && 'heading' === $option['type'] && isset($option['options']) && is_array($option['options'])) { foreach ($option['options'] as $opt) { $tab->createOption($opt); } } } $tab->createOption(array('type' => 'save')); } }
/** * Get the list of all options * * This function filters the settings to remove all the hierarchy and only returns * an array of options. * * @since 3.3 * @return array */ function wpas_get_raw_settings() { $settings = wpas_get_settings(); if (empty($settings)) { return array(); } $just_options = array(); foreach ($settings as $tab => $contents) { if (!isset($contents['options'])) { continue; } foreach ($contents['options'] as $option) { if (isset($option['id']) && !array_key_exists($option['id'], $just_options)) { $just_options[$option['id']] = $option; } } } return $just_options; }