), ); } public function enqueueTabStyles() { parent::enqueueTabStyles(); wp_enqueue_auto_versioned_style( 'ame-tweak-manager-css', plugins_url('tweaks.css', __FILE__) ); } public function handleSettingsForm($post = array()) { parent::handleSettingsForm($post); $submittedSettings = json_decode($post['settings'], true); //To save space, filter out tweaks that are not enabled for anyone and have no other settings. //Most tweaks only have "id" and "enabledForActor" properties. $basicProperties = array('id' => true, 'enabledForActor' => true); $submittedSettings['tweaks'] = array_filter( $submittedSettings['tweaks'], function ($settings) use ($basicProperties) { if ( !empty($settings['enabledForActor']) ) { return true; } $additionalProperties = array_diff_key($settings, $basicProperties); return !empty($additionalProperties); } ); //User-defined tweaks must have a type. $submittedSettings['tweaks'] = array_filter( $submittedSettings['tweaks'], function ($settings) { return empty($settings['isUserDefined']) || !empty($settings['typeId']); } ); //TODO: Give other components an opportunity to validate and sanitize tweak settings. E.g. a filter. //Sanitize CSS with FILTER_SANITIZE_FULL_SPECIAL_CHARS if unfiltered_html is not enabled. Always strip . //Build a lookup array of user-defined tweaks so that we can register them later //without iterating through the entire list. $userDefinedTweakIds = array(); foreach ($submittedSettings['tweaks'] as $properties) { if ( !empty($properties['isUserDefined']) && !empty($properties['id']) ) { $userDefinedTweakIds[$properties['id']] = true; } } //We use an incrementing suffix to ensure each user-defined tweak gets a unique ID. $lastUserTweakSuffix = ameUtils::get($this->loadSettings(), 'lastUserTweakSuffix', 0); $newSuffix = ameUtils::get($submittedSettings, 'lastUserTweakSuffix', 0); if ( is_scalar($newSuffix) && is_numeric($newSuffix) ) { $newSuffix = max(intval($newSuffix), 0); if ( $newSuffix < 10000000 ) { $lastUserTweakSuffix = $newSuffix; } } $this->settings['tweaks'] = $submittedSettings['tweaks']; $this->settings['userDefinedTweaks'] = $userDefinedTweakIds; $this->settings['lastUserTweakSuffix'] = $lastUserTweakSuffix; $this->saveSettings(); $params = array('updated' => 1); if ( !empty($post['selected_actor']) ) { $params['selected_actor'] = strval($post['selected_actor']); } wp_redirect($this->getTabUrl($params)); exit; } } class ameTweakSection { private $id; private $label; private $priority = 0; public function __construct($id, $label) { $this->id = $id; $this->label = $label; } public function getId() { return $this->id; } public function getLabel() { return $this->label; } public function getPriority() { return $this->priority; } public function setPriority($priority) { $this->priority = $priority; return $this; } }