<?php abstract class amePersistentModule extends ameModule { /** * @var string Database option where module settings are stored. */ protected $optionName = ''; /** * @var array|null Module settings. NULL when settings haven't been loaded yet. */ protected $settings = null; /** * @var array Default module settings. */ protected $defaultSettings = array(); public function __construct($menuEditor) { if ( $this->optionName === '' ) { throw new LogicException(__CLASS__ . '::$optionName is an empty string. You must set it to a valid option name.'); } parent::__construct($menuEditor); } public function loadSettings() { if ( isset($this->settings) ) { return $this->settings; } $json = $this->getScopedOption($this->optionName, null); if ( is_string($json) && !empty($json) ) { $settings = json_decode($json, true); if ( !is_array($settings) ) { $settings = array(); //JSON decoding failed, fall back to an empty array. } } else { $settings = array(); } $this->settings = array_merge($this->defaultSettings, $settings); return $this->settings; } public function saveSettings() { $settings = wp_json_encode($this->settings); //Save per site or site-wide based on plugin configuration. $this->setScopedOption($this->optionName, $settings); } public function mergeSettingsWith($newSettings) { $this->settings = array_merge($this->loadSettings(), $newSettings); return $this->settings; } protected function getTemplateVariables($templateName) { $variables = parent::getTemplateVariables($templateName); if ( $templateName === $this->moduleId ) { $variables = array_merge( $variables, array( 'settings' => $this->loadSettings(), ) ); } return $variables; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
PHP-CSS-Parser | Folder | 0755 |
|
|
capabilities | Folder | 0755 |
|
|
.htaccess | File | 188 B | 0644 |
|
AmeAutoloader.php | File | 1.2 KB | 0644 |
|
access-test-runner.php | File | 8.16 KB | 0644 |
|
admin-menu-editor-mu.php | File | 2.11 KB | 0644 |
|
ame-option.php | File | 6.15 KB | 0644 |
|
ame-utils.php | File | 21.7 KB | 0644 |
|
auto-versioning.php | File | 5.09 KB | 0644 |
|
basic-dependencies.php | File | 1.86 KB | 0644 |
|
bbpress-role-override.php | File | 1.81 KB | 0644 |
|
cap-suggestion-box.php | File | 416 B | 0644 |
|
consistency-check.php | File | 3.6 KB | 0644 |
|
editor-page.php | File | 30.44 KB | 0644 |
|
generate-menu-dashicons.php | File | 3.79 KB | 0644 |
|
menu-editor-core.php | File | 193.51 KB | 0644 |
|
menu-item.php | File | 29.27 KB | 0644 |
|
menu.php | File | 19.63 KB | 0644 |
|
module.php | File | 4.4 KB | 0644 |
|
persistent-module.php | File | 1.74 KB | 0644 |
|
reflection-callable.php | File | 2.04 KB | 0644 |
|
role-utils.php | File | 10.63 KB | 0644 |
|
settings-page.php | File | 17.83 KB | 0644 |
|
shadow_plugin_framework.php | File | 12.61 KB | 0644 |
|
shortcodes.php | File | 3.38 KB | 0644 |
|
test-access-screen.php | File | 2.17 KB | 0644 |
|
version-conflict-check.php | File | 819 B | 0644 |
|