Exemplo n.º 1
0
 public function save_site_options()
 {
     $page = empty($_POST['page']) ? key($this->p->cf['*']['lib']['sitesubmenu']) : $_POST['page'];
     if (empty($_POST[NGFB_NONCE])) {
         $this->p->debug->log('Nonce token validation post field missing.');
         wp_redirect($this->p->util->get_admin_url($page));
         exit;
     } elseif (!wp_verify_nonce($_POST[NGFB_NONCE], $this->get_nonce())) {
         $this->p->notice->err(__('Nonce token validation failed for network options (update ignored).', NGFB_TEXTDOM), true);
         wp_redirect($this->p->util->get_admin_url($page));
         exit;
     } elseif (!current_user_can('manage_network_options')) {
         $this->p->notice->err(__('Insufficient privileges to modify network options.', NGFB_TEXTDOM), true);
         wp_redirect($this->p->util->get_admin_url($page));
         exit;
     }
     $def_opts = $this->p->opt->get_site_defaults();
     $opts = empty($_POST[NGFB_SITE_OPTIONS_NAME]) ? $def_opts : SucomUtil::restore_checkboxes($_POST[NGFB_SITE_OPTIONS_NAME]);
     $opts = array_merge($this->p->site_options, $opts);
     $opts = $this->p->opt->sanitize($opts, $def_opts);
     // cleanup excess options and sanitize
     $opts = apply_filters($this->p->cf['lca'] . '_save_site_options', $opts);
     update_site_option(NGFB_SITE_OPTIONS_NAME, $opts);
     // store message in user options table
     $this->p->notice->inf(__('Plugin settings have been updated.', NGFB_TEXTDOM), true);
     wp_redirect($this->p->util->get_admin_url($page) . '&settings-updated=true');
     exit;
     // stop here
 }
Exemplo n.º 2
0
 protected function get_submit_opts($id, $mod = false)
 {
     $defs = $this->get_defaults(false, $mod);
     unset($defs['options_filtered']);
     unset($defs['options_version']);
     $prev = $this->get_options($id);
     unset($prev['options_filtered']);
     unset($prev['options_version']);
     $opts = empty($_POST[NGFB_META_NAME]) ? array() : $_POST[NGFB_META_NAME];
     $opts = SucomUtil::restore_checkboxes($opts);
     $opts = array_merge($prev, $opts);
     $opts = $this->p->opt->sanitize($opts, $defs, false, $mod);
     // network is false
     if ($mod !== false) {
         $opts = apply_filters($this->p->cf['lca'] . '_save_meta_options', $opts, $mod, $id);
     }
     foreach ($defs as $key => $def_val) {
         if (array_key_exists($key, $opts)) {
             if ($opts[$key] == -1 || $opts[$key] === '') {
                 unset($opts[$key]);
             }
         }
     }
     if (empty($opts['buttons_disabled'])) {
         unset($opts['buttons_disabled']);
     }
     foreach (array('rp', 'og') as $meta_pre) {
         if (empty($opts[$meta_pre . '_img_id'])) {
             unset($opts[$meta_pre . '_img_id_pre']);
         }
         $force_regen = false;
         foreach (array('width', 'height', 'crop', 'crop_x', 'crop_y') as $key) {
             // if option is the same as the default, then unset it
             if (isset($opts[$meta_pre . '_img_' . $key]) && isset($defs[$meta_pre . '_img_' . $key]) && $opts[$meta_pre . '_img_' . $key] === $defs[$meta_pre . '_img_' . $key]) {
                 unset($opts[$meta_pre . '_img_' . $key]);
             }
             if ($mod !== false) {
                 if (!empty($this->p->options['plugin_auto_img_resize'])) {
                     $check_current = isset($opts[$meta_pre . '_img_' . $key]) ? $opts[$meta_pre . '_img_' . $key] : '';
                     $check_previous = isset($prev[$meta_pre . '_img_' . $key]) ? $prev[$meta_pre . '_img_' . $key] : '';
                     if ($check_current !== $check_previous) {
                         $force_regen = true;
                     }
                 }
             }
         }
         if ($force_regen === true) {
             set_transient($this->p->cf['lca'] . '_' . $mod . '_' . $id . '_regen_' . $meta_pre, true);
         }
     }
     return $opts;
 }