Example #1
0
 /**
  * Handles pre-Settings Menu actions
  */
 public function onSettingsMenuLoad($current_screen)
 {
     // Extra scripts to include
     list($js_url, $version, $debug) = $this->owner->getResourceUrl();
     // Color picker
     wp_enqueue_script('farbtastic');
     // Slider
     wp_enqueue_script('jquery-ui-core');
     wp_enqueue_script('jquery-ui-mouse');
     wp_enqueue_script('jquery-ui-widget');
     wp_enqueue_script('jquery-ui-slider');
     // Default Functions
     wp_enqueue_script($this->owner->getName() . '-settings', $js_url . 'settings' . $debug . '.js', array($this->owner->getName() . '-functions'), $version);
     // Extra CSS to include
     list($css_url, $version, $debug) = $this->owner->getResourceUrl('css');
     // Color picker
     wp_enqueue_style('farbtastic');
     // Slider
     wp_enqueue_style('jquery-ui-slider', $css_url . 'vendor/jquery-ui-slider' . $debug . '.css', false, $version);
     // Guided Help, Step 1 ("Get Started")
     new \Myatu\WordPress\BackgroundManager\Pointers\AddNewStep1($this->owner->getName());
     // Intro to new features in 1.1
     if ($this->owner->options->last_upgrade == '1.1') {
         new \Myatu\WordPress\BackgroundManager\Pointers\Upgrade1dot1new1($this->owner->getName());
     }
     // Save settings if POST is set
     if (!empty($_POST) && isset($_POST['_nonce'])) {
         if (!wp_verify_nonce($_POST['_nonce'], 'onSettingsMenu')) {
             wp_die(__('You do not have permission to do that [nonce].', $this->owner->getName()));
         }
         // Set options from $_POST
         $this->owner->options->load($_POST, $this->getSettingOptions());
         // Additional options not handled by load():
         // Display settings for Custom Post Types
         $display_on = array();
         foreach (get_post_types(array('_builtin' => false, 'public' => true), 'objects') as $post_type_key => $post_type) {
             // Iterate over existing custom post types, filtering out whether it can be shown or not
             if ($post_type_key !== Main::PT_GALLERY) {
                 $display_on[$post_type_key] = !empty($_POST['display_on'][$post_type_key]);
             }
         }
         $this->owner->options->display_custom_post_types = $display_on;
         // Slightly different, the background color is saved as a theme mod only.
         $background_color = ltrim($_POST['background_color'], '#');
         if (empty($background_color)) {
             remove_theme_mod('background_color');
         } else {
             if (preg_match('/^([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?$/', $background_color)) {
                 set_theme_mod('background_color', $background_color);
             }
         }
         AdminNotice::add(__('Settings have been saved', $this->owner->getName()));
     }
 }
 /**
  * Event called to display Dashboard notices in the notification queue
  *
  * @internal
  */
 public final function _onAdminNotices()
 {
     $queue = $this->internal_options->delayed_notices;
     if (!empty($queue)) {
         foreach ($queue as $notice) {
             AdminNotice::add($notice[0], $notice[1]);
         }
         $this->clearDelayedNotices();
     }
     AdminNotice::display();
 }
Example #3
0
 /**
  * Performs a Save action (initiated by edit form)
  *
  * This will retrieve all neccesary data from the $_REQUEST variable and
  * check against the nonce for validity.
  */
 public function saveUserAction()
 {
     $id = (int) $_REQUEST['edit'];
     $is_new = get_post_status($id) == 'auto-draft';
     if (!isset($_REQUEST['_nonce']) && !wp_verify_nonce($_REQUEST['_nonce'], Main::NONCE_EDIT_GALLERY . $id)) {
         wp_die(__('You do not have permission to do that [nonce].', $this->owner->getName()));
     }
     // Nonce passed, do sanity check on fields
     $post_title = trim($_REQUEST['post_title']);
     if ($post_title == '') {
         AdminNotice::add(__('Please specify a name for this Image Set.', $this->owner->getName()), true);
         return false;
     }
     $saved_id = $this->save($id, $post_title, $_REQUEST['post_content']);
     if (!$saved_id) {
         AdminNotice::add(__('The Image Set could not be saved.', $this->owner->getName()), true);
         return false;
     }
     // Let the user know if the image set was successfuly added or saved.
     $did_what = $is_new ? __('added', $this->owner->getName()) : __('saved', $this->owner->getName());
     $this->owner->addDelayedNotice(sprintf(__('The Image Set was successfully %s.', $this->owner->getName()), $did_what));
     $this->redirectUserActionOrigin(array('edit' => $saved_id));
 }