Plugin Directory

Changeset 1435680


Ignore:
Timestamp:
06/13/2016 09:32:40 AM (10 years ago)
Author:
designerbydesign
Message:

Fixing admin sanitisation bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • xml-news-sitemap/trunk/gns_xml.php

    r1344021 r1435680  
    9292            if ( empty($settings)) {
    9393                $settings = array();
    94                 $settings['gns_xml_custom_post_types'] = (array) array("post");
     94                $settings['gns_xml_custom_post_types'] = array("post");
    9595                $settings['gns_xml_url'] = (string) get_site_url() . "/sitemap-news.xml";
    9696                $settings['gns_xml_pubname'] = (string) get_bloginfo( 'name' );
    97                 $settings['gns_xml_genres'] = (array) array("Blog");
     97                $settings['gns_xml_genres'] = array("Blog");
    9898                $settings['gns_xml_publanguage'] = (string) get_locale();
    9999                $settings['gns_xml_pubaccess'] = (string) 'na';
     100                $settings['gns_xml_cats'] = array();
    100101                update_option('gns_xml_options', $settings);
    101102            }
     
    113114            if (isset($_POST['gns_xml_settings']) && current_user_can('manage_options') && check_admin_referer('gns_xml_settings')) {
    114115                $settings = $this->getSettings();
    115                 if(!array($_POST['gns_xml_custom_post_types'])){
     116                if(isset($_POST['gns_xml_custom_post_types']) && !array($_POST['gns_xml_custom_post_types'])){
    116117                     return new WP_Error( 'broke', __( "Oops you can't post that!" ) );
    117118                } else {
    118                     $settings['gns_xml_custom_post_types'] = sanitize_text_field($_POST['gns_xml_custom_post_types']);
    119                     $settings['gns_xml_cats'] = sanitize_text_field($_POST["post_category"]);
    120                     $settings['gns_xml_pubaccess'] = sanitize_text_field($_POST['gns_xml_pubaccess']);
    121                     $settings['gns_xml_genres'] = sanitize_text_field($_POST['gns_xml_genres']);
     119                    if(isset($_POST['gns_xml_custom_post_types'])){
     120                        foreach($_POST["gns_xml_custom_post_types"] as $option){
     121                            $settings['gns_xml_custom_post_types'][] = sanitize_text_field($option);
     122                        }
     123                    }
     124                    if(isset($_POST["post_category"]) && is_array($_POST["post_category"])){
     125                        foreach($_POST["post_category"] as $option){
     126                            $settings['gns_xml_cats'][] = sanitize_text_field($option);
     127                        }
     128                    }
     129                    if(isset($_POST["gns_xml_pubaccess"]) && is_array($_POST["gns_xml_pubaccess"])){
     130                        $settings['gns_xml_pubaccess'] = sanitize_text_field($_POST["gns_xml_pubaccess"]);
     131                    }
     132                    if(isset($_POST["gns_xml_genres"]) && is_array($_POST["gns_xml_genres"])){
     133                        foreach($_POST["gns_xml_genres"] as $option){
     134                            $settings['gns_xml_genres'][] = sanitize_text_field($option);
     135                        }
     136                    }
    122137                }
    123138                if(!is_string($_POST['gns_xml_url']) || !is_string($_POST['gns_xml_pubname']) || !is_string($_POST['gns_xml_publanguage'])){
     
    224239            $output .= '<select class="index-list widefat" name="gns_xml_pubaccess">';
    225240            foreach($this->_access as $key => $value){
    226 
    227241                if($gns_xml_pubaccess != "" && $key == $gns_xml_pubaccess){
    228242                    $selected = 'selected';
     
    238252            $output .= '<p class="label"><strong>'.__('Genres').'</strong></p>';
    239253            $output .= '<select class="index-list widefat" name="gns_xml_genres[]" multiple="multiple">';
    240             foreach($this->_genres as $key => $value){
    241                 if(!empty($gns_xml_genres) && in_array($key, $gns_xml_genres)){
     254
     255            if(isset($gns_xml_genres) && is_array($gns_xml_genres)){
     256                foreach($this->_genres as $key => $value){
     257                    if(!empty($gns_xml_genres) && in_array($key, $gns_xml_genres)){
    242258                    $selected = 'selected';
    243                 } elseif (!empty($settings['gns_xml_genres']) && in_array($key, $settings['gns_xml_genres'])) {
     259                    } else {
     260                        $selected = '';
     261                    }
     262                    $output .= '<option value="'.$key.'" '.$selected.'>'. __($value).'</option>';
     263                }
     264            } else {
     265                foreach($this->_genres as $key => $value){
     266                if (!empty($settings['gns_xml_genres']) && in_array($key, $settings['gns_xml_genres'])) {
    244267                    $selected = 'selected';
    245268                } else {
     
    248271                $output .= '<option value="'.$key.'" '.$selected.'>'. __($value).'</option>';
    249272            }
     273            }
     274
    250275            $output .= '</select>';
    251276            $output .= '<p class="label"><label for="gns_xml_publanguage"><strong>'.__('Language').'</strong></label></p>';
     
    272297
    273298            if ( isset($_POST['gns_xml_include']) && $_POST['gns_xml_include'] != "" ) {
    274                 //print_r($_POST['gns_xml_include']);
    275                 update_post_meta( $post_id, 'gns_xml_include', sanitize_meta($_POST['gns_xml_include']) );
    276                 update_post_meta( $post_id, 'gns_xml_pubaccess', sanitize_meta($_POST['gns_xml_pubaccess']) );
    277                 update_post_meta( $post_id, 'gns_xml_genres', sanitize_meta(serialize($_POST['gns_xml_genres'])) );
     299                update_post_meta( $post_id, 'gns_xml_include', sanitize_text_field($_POST['gns_xml_include']) );
     300                update_post_meta( $post_id, 'gns_xml_pubaccess', sanitize_text_field($_POST['gns_xml_pubaccess']) );
     301                if(isset($_POST['gns_xml_genres']) && is_array($_POST['gns_xml_genres'])){
     302                    $genres = array();
     303                    foreach($_POST["gns_xml_genres"] as $option){
     304                        $genres[] = sanitize_text_field($option);
     305                    }
     306
     307                    update_post_meta( $post_id, 'gns_xml_genres', serialize($genres) );
     308                }
    278309                update_post_meta( $post_id, 'gns_xml_publanguage', sanitize_meta($_POST['gns_xml_publanguage']) );
    279310
Note: See TracChangeset for help on using the changeset viewer.