Exemplo n.º 1
0
 public function SaveOptions()
 {
     $existing_values = SerializeStringToArray(get_option($this->prefix));
     if (isset($existing_values) && $existing_values && count($existing_values) >= 1) {
         if (isset($_POST[$this->prefix("update_options")]) && $_POST[$this->prefix("update_options")] === $this->prefix("update_options")) {
             foreach ($existing_values as $value) {
                 $dbvalue = "";
                 if (isset($_POST[$value['meta_key']]) && $_POST[$value['meta_key']]) {
                     if (is_array($_POST[$value['meta_key']]) && count($_POST[$value['meta_key']]) >= 1) {
                         $dbvalue = array();
                         foreach ($_POST[$value['meta_key']] as $selected_value) {
                             $selected_value = BBWPSanitization::Textfield($selected_value);
                             if ($selected_value) {
                                 $dbvalue[] = $selected_value;
                             }
                         }
                     } else {
                         if ($value['field_type'] == 'textarea' || $value['field_type'] == 'editor') {
                             $dbvalue = BBWPSanitization::Textarea($_POST[$value['meta_key']]);
                         } else {
                             $dbvalue = BBWPSanitization::Textfield($_POST[$value['meta_key']]);
                         }
                     }
                 } else {
                     if (isset($value['default_value'])) {
                         $dbvalue = $value['default_value'];
                     }
                 }
                 if (is_array($dbvalue)) {
                     $dbvalue = ArrayToSerializeString($dbvalue);
                 }
                 if ($this->saveType === "option") {
                     update_option($value['meta_key'], $dbvalue);
                 } elseif ($this->saveType === "user" && is_numeric($this->dataID) && $this->dataID >= 1) {
                     update_user_meta($this->dataID, $value['meta_key'], $dbvalue);
                 } elseif ($this->saveType === "post" && is_numeric($this->dataID) && $this->dataID >= 1) {
                     update_post_meta($this->dataID, $value['meta_key'], $dbvalue);
                 } elseif ($this->saveType === "term" && is_numeric($this->dataID) && $this->dataID >= 1) {
                     update_term_meta($this->dataID, $value['meta_key'], $dbvalue);
                 } elseif ($this->saveType === "comment" && is_numeric($this->dataID) && $this->dataID >= 1) {
                     update_comment_meta($this->dataID, $value['meta_key'], $dbvalue);
                 }
             }
             if ($this->saveType == "option") {
                 update_option("bbwp_update_message", 'Your setting have been updated.');
             }
         }
     }
 }
 public function input_handle()
 {
     if (isset($_GET['page']) && $_GET['page'] === $this->prefix) {
         /* metabox input handling */
         if (isset($_POST['create_new_metabox']) && $_POST['create_new_metabox'] === $this->prefix('create_new_metabox') && isset($_POST['user_created_metaboxes'])) {
             $update = false;
             $update_message = 'Your setting have been updated.';
             $existing_values = SerializeStringToArray(get_option($this->prefix('user_created_metaboxes')));
             $new_values = array();
             if (isset($_POST['metabox_location']) && is_array($_POST['metabox_location']) && count($_POST['metabox_location']) >= 1) {
                 $new_values['metabox_location'] = $_POST['metabox_location'];
             }
             if (isset($_POST['metabox_pages'])) {
                 $new_values['metabox_pages'] = $_POST['metabox_pages'];
             }
             if (isset($_POST['metabox_context'])) {
                 $new_values['metabox_context'] = $_POST['metabox_context'];
             }
             if (isset($_POST['metabox_priority'])) {
                 $new_values['metabox_priority'] = $_POST['metabox_priority'];
             }
             $value = BBWPSanitization::Textfield($_POST['user_created_metaboxes']);
             $key = sanitize_key($_POST['user_created_metaboxes']);
             if (isset($_POST['update_created_metabox']) && array_key_exists($_POST['update_created_metabox'], $existing_values)) {
                 $key = $_POST['update_created_metabox'];
                 $update = true;
                 $update_message = '<p>Your setting have been updated.</p><p><a href="?page=' . $_GET['page'] . '">← Back to Main Page</a></p>';
             }
             if ($update == false && $key && array_key_exists($key, $existing_values)) {
                 update_option("bbwp_error_message", 'There was some problem. Please try again with different meta box name.');
             } elseif ($value && $key) {
                 $new_values['metabox_id'] = $key;
                 $new_values['metabox_title'] = $value;
                 $existing_values[$key] = $new_values;
                 update_option($this->prefix('user_created_metaboxes'), ArrayToSerializeString($existing_values));
                 $this->set_bbcf_option("selected_metabox", $key);
                 update_option("bbwp_update_message", $update_message);
             }
         }
         if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['metabox_id']) && $_GET['metabox_id']) {
             $this->DeleteMetaBoxes($_GET['metabox_id'], $this->prefix("user_created_metaboxes"));
         }
         if (isset($_POST['sort_fields']) && $_POST['sort_fields'] === $this->prefix('user_created_metaboxes')) {
             if (isset($_POST['bulk_action']) && $_POST['bulk_action'] === 'delete' && isset($_POST['fields']) && is_array($_POST['fields']) && count($_POST['fields']) >= 1) {
                 $this->DeleteMetaBoxes($_POST['fields'], $this->prefix("user_created_metaboxes"));
             } elseif (isset($_POST['sort_field']) && is_array($_POST['sort_field']) && count($_POST['sort_field']) >= 1) {
                 BBWPFieldTypes::SortFields($_POST['sort_field'], $this->prefix("user_created_metaboxes"));
             }
         }
         /* meta box inputs end here */
         /* create new option page form input start */
         if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['page_slug']) && $_GET['page_slug']) {
             BBWPFieldTypes::DeleteFields($_GET['page_slug'], $this->prefix("user_created_pages"));
         }
         if (isset($_POST['sort_fields']) && $_POST['sort_fields'] === $this->prefix('user_created_pages')) {
             if (isset($_POST['bulk_action']) && $_POST['bulk_action'] === 'delete' && isset($_POST['fields']) && is_array($_POST['fields']) && count($_POST['fields']) >= 1) {
                 BBWPFieldTypes::DeleteFields($_POST['fields'], $this->prefix("user_created_pages"));
             } elseif (isset($_POST['sort_field']) && is_array($_POST['sort_field']) && count($_POST['sort_field']) >= 1) {
                 BBWPFieldTypes::SortFields($_POST['sort_field'], $this->prefix("user_created_pages"));
             }
         }
         if (isset($_POST['create_new_option_page']) && $_POST['create_new_option_page'] === $this->prefix('create_new_option_page')) {
             if (isset($_POST['user_created_pages']) && $_POST['user_created_pages'] && isset($_POST['parent_menu']) && $_POST['parent_menu']) {
                 $update = false;
                 $update_message = 'Your setting have been updated.';
                 $existing_values = SerializeStringToArray(get_option($this->prefix('user_created_pages')));
                 $value = BBWPSanitization::Textfield($_POST['user_created_pages']);
                 $key = sanitize_key($_POST['user_created_pages']);
                 $parent_menu = sanitize_key($_POST['parent_menu']);
                 if (isset($_POST['update_created_option_page']) && array_key_exists($_POST['update_created_option_page'], $existing_values)) {
                     $key = $_POST['update_created_option_page'];
                     $update = true;
                     $update_message = '<p>Your setting have been updated.</p><p><a href="?page=' . sanitize_key($_GET['page']) . '">← Back to Main Page</a></p>';
                 }
                 if ($update == false && array_key_exists($key, $existing_values)) {
                     update_option("bbwp_error_message", 'There was some problem. Please try again with different page name.');
                 } elseif ($value && $parent_menu && $key) {
                     $existing_values[$key] = array('page_slug' => $key, 'page_title' => $value, 'parent_menu' => $parent_menu);
                     update_option($this->prefix('user_created_pages'), ArrayToSerializeString($existing_values));
                     update_option("bbwp_update_message", $update_message);
                 }
             }
         }
         /* create new option page form input start */
         if (isset($_POST[$this->prefix("current_selected_metabox")]) && array_key_exists($_POST[$this->prefix("current_selected_metabox")], SerializeStringToArray(get_option($this->prefix('user_created_metaboxes'))))) {
             $this->set_bbcf_option("selected_metabox", $_POST[$this->prefix("current_selected_metabox")]);
             update_option("bbwp_update_message", 'Your setting have been updated.');
         }
         $current_selected_metabox = $this->get_bbcf_option("selected_metabox");
         if ($current_selected_metabox) {
             $BBWPFieldTypes = new BBWPFieldTypes($this->prefix($current_selected_metabox));
             if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['meta_key']) && $_GET['meta_key']) {
                 BBWPFieldTypes::DeleteFields($_GET['meta_key'], $this->prefix($current_selected_metabox));
             }
             if (isset($_POST['sort_fields']) && $_POST['sort_fields'] === $this->prefix($current_selected_metabox)) {
                 if (isset($_POST['bulk_action']) && $_POST['bulk_action'] === 'delete' && isset($_POST['fields']) && is_array($_POST['fields']) && count($_POST['fields']) >= 1) {
                     BBWPFieldTypes::DeleteFields($_POST['fields'], $this->prefix($current_selected_metabox));
                 } elseif (isset($_POST['sort_field']) && is_array($_POST['sort_field']) && count($_POST['sort_field']) >= 1) {
                     BBWPFieldTypes::SortFields($_POST['sort_field'], $this->prefix($current_selected_metabox));
                 }
             }
             $BBWPFieldTypes->UpdateFields();
         }
     }
     // if isset page end here
 }