/* Plugin Name: Wp Mn Pg Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates Description: A brief description of the Plugin. Version: 1.0 Author: vagenas Author URI: http://URI_Of_The_Plugin_Author License: A "Slug" license name e.g. GPL2 */ require_once 'vendor/autoload.php'; $defaultOptions = ['text' => 'This is a text field', 'color' => '#ffaa33', 'date' => date('Y-m-d'), 'dateTime' => date('Y-m-dTH:i:s'), 'dateTimeLocal' => date('Y-m-dTH:i:s'), 'email' => '*****@*****.**', 'hidden' => '', 'image' => '', 'month' => '10', 'multiSelect' => [], 'number' => 7, 'password' => '', 'postType' => '', 'postTypeMultiple' => [], 'radio' => 2, 'range' => '', 'search' => '', 'select' => '', 'select2' => '', 'select2multiple' => [1, 2], 'switch' => 1, 'taxonomies' => '', 'taxonomiesMultiple' => [], 'tel' => '', 'textArea' => '', 'time' => date('H:i:s'), 'url' => '', 'week' => 25]; $selectOptions = ['Option 1' => 1, 'Option 2' => 2, 'Option 3' => 3, 'Option 4' => 4, 'Option 5' => 5, 'Option 6' => 6]; $radioOptions = ['Option 1' => 1, 'Option 2' => 2, 'Option 3' => 3, 'Option 4' => 4]; $selectOptionGroups = ['Option 1' => 1, 'Option 2' => 2, 'Group 1' => ['Group 1 Option 1' => 11, 'Group 1 Option 2' => 12, 'Group 1 Option 3' => 13, 'Group 1 Option 4' => 14, 'Group 1 Option 5' => 15, 'Group 1 Option 6' => 16], 'Option 3' => 3, 'Option 4' => 4, 'Group 2' => ['Group 2 Option 1' => 21, 'Group 2 Option 2' => 22, 'Group 2 Option 3' => 23, 'Group 2 Option 4' => 24, 'Group 2 Option 5' => 25, 'Group 2 Option 6' => 26], 'Option 5' => 5, 'Option 6' => 6]; $optionsObj = \Pan\MenuPages\Options::getInstance('wp_menu_pages_demo', $defaultOptions); $wpMenuPages = new \Pan\MenuPages\WpMenuPages(__FILE__, $optionsObj); $mainPage = $wpMenuPages->maybeCreatePage('My Settings'); $subPage = $wpMenuPages->maybeCreateSubPage($mainPage, 'Sub Page Demo'); $tabsMainPage = new \Pan\MenuPages\PageElements\Containers\CnrTabbedSettings($mainPage, \Pan\MenuPages\Pages\Page::POSITION_MAIN); $tabsSubPage = new \Pan\MenuPages\PageElements\Containers\CnrTabs($subPage, \Pan\MenuPages\Pages\Page::POSITION_MAIN); $tabsNoFields = new \Pan\MenuPages\PageElements\Containers\CnrTabs($mainPage, \Pan\MenuPages\Pages\Page::POSITION_ASIDE); $rawTab = new \Pan\MenuPages\PageElements\Components\CmpTab($tabsNoFields, 'CmpRaw CmpTab'); $anotherRawTab = new \Pan\MenuPages\PageElements\Components\CmpTab($tabsNoFields, 'Another CmpRaw CmpTab'); $tabTextFields = $tabsMainPage->addTab('Text Fields'); $tabDateTimeFields = $tabsMainPage->addTab('Date-Time Fields', true); $tabSelectFields = $tabsMainPage->addTab('Select Fields'); $tabRadioFields = $tabsMainPage->addTab('Radio Fields'); $tabMediaFields = $tabsMainPage->addTab('Media Fields'); $tabNumberFieldsDemo = $tabsMainPage->addTab('Number Fields'); $tabOtherFields = $tabsSubPage->addTab('Other Fields');
/** * @param $name * @param null $default * * @return null * @author Panagiotis Vagenas <*****@*****.**> * @since 1.0.0 */ public function getPageOption($name, $default = null) { return $this->options->getPageOption($this, $name, $default); }
/** * WpMenuPages constructor. * * @param string $pluginBaseFile Absolute path to plugin main file * @param array|Options $options An instance of {@link Options} or an array with default options * @param string $optionsBaseName In case the $options param is an array this should be a string * defining the name of the options array as stored in DB * * @throws \InvalidArgumentException If $pluginBaseFile is empty or pointing to non readable file * @throws \InvalidArgumentException If $options isn't an instance of {@link Options} and is not an array * and $optionsBaseName is empty * @throws \Exception If symlinks are used and couldn't resolve $pluginBaseFile path * @since 1.0.0 * @author Panagiotis Vagenas <*****@*****.**> */ public function __construct($pluginBaseFile, $options, $optionsBaseName = '') { if (empty($pluginBaseFile) || !file_exists($pluginBaseFile) || !is_readable($pluginBaseFile)) { throw new \InvalidArgumentException('Invalid argument $pluginBaseFile in ' . __METHOD__); } $pluginBaseFile = wp_normalize_path($pluginBaseFile); $pluginIsSymlink = strpos($pluginBaseFile, ABSPATH) !== 0; $pagesIsSymlink = strpos(__FILE__, ABSPATH) !== 0; if ($pluginIsSymlink) { $pluginFolderName = dirname(plugin_basename($pluginBaseFile)); $this->pluginBasePath = trailingslashit(WP_PLUGIN_DIR) . $pluginFolderName; $this->pluginBaseFile = trailingslashit($this->pluginBasePath) . basename($pluginBaseFile); } else { $this->pluginBasePath = dirname($pluginBaseFile); $this->pluginBaseFile = realpath($pluginBaseFile); } if ($pagesIsSymlink) { $this->basePath = dirname(dirname(dirname(__FILE__))); $this->basePathRelToPlugin = str_replace($this->pluginBasePath, '', $this->basePath); $dirItr = new \RecursiveDirectoryIterator($this->pluginBasePath, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \RecursiveDirectoryIterator::SKIP_DOTS); $itr = new \RecursiveIteratorIterator($dirItr); $res = new \RegexIterator($itr, '/WpMenuPages\\.php/', \RecursiveIteratorIterator::LEAVES_ONLY); $res->next(); /** @var \SplFileInfo $wpMenuPagesFile */ $wpMenuPagesFile = $res->current(); if (!$wpMenuPagesFile instanceof \SplFileInfo) { // TODO Message throw new \Exception('Something went awfully wrong!'); } $this->basePath = dirname(dirname($wpMenuPagesFile->getPath())); } else { $this->basePath = dirname(dirname(dirname(__FILE__))); } $this->basePathRelToPlugin = str_replace($this->pluginBasePath, '', $this->basePath); if ($options instanceof Options) { $this->options = $options; } elseif (is_array($options) && !empty($optionsBaseName)) { $this->options = Options::getInstance($optionsBaseName, $options); } else { throw new \InvalidArgumentException('Invalid argument $options in ' . __METHOD__); } add_action('admin_init', function () { $this->pluginMetaData = get_plugin_data($this->pluginBaseFile); }); }