Plugin Directory

Changeset 2624427


Ignore:
Timestamp:
11/04/2021 10:33:06 AM (4 years ago)
Author:
qurl
Message:

Fix vulnerability in Custom Posts TAxonomy tree

Location:
dynamic-widgets/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • dynamic-widgets/trunk/dynamic-widgets.php

    r2164838 r2624427  
    55 * Description: Dynamic Widgets gives you full control on which pages your widgets will appear. It lets you dynamicly show or hide widgets on WordPress pages.
    66 * Author: Qurl
    7  * Version: 1.5.16
     7 * Version: 1.6.0
    88 * Author URI: http://www.qurl.nl/
    99 * Tags: widget, widgets, dynamic, sidebar, custom, rules, logic, admin, condition, conditional tags, hide, show, wpml, qtranslate, wpec, buddypress, pods
     
    3939 * Thanks to WordPress formm user @fjaeker for finding and debugging a problem in the Pages module since WordPress 5.
    4040 * Thanks to WordPress forum user @sovabarmak for finding and fixing a bug in Pages childs as a result of the previous Pages fix
     41 * Thanks to Erwan from WPScan to find a vulnerability in processing the Custom Posts Taxonomy tree.
    4142 *
    4243 *
     
    8586    define('DW_TIME_LIMIT', 86400);             // 1 day
    8687    define('DW_URL_AUTHOR', 'http://www.qurl.nl');
    87     define('DW_VERSION', '1.5.16');
     88    define('DW_VERSION', '1.6.0');
    8889    define('DW_WPML_API', '/inc/wpml-api.php');         // WPML Plugin support - API file relative to ICL_PLUGIN_PATH
    8990    define('DW_WPML_ICON', 'img/wpml_icon.png');    // WPML Plugin support - WPML icon
  • dynamic-widgets/trunk/dynwid_admin_save.php

    r2032225 r2624427  
    11<?php
    2 /**
    3  * dynwid_admin_save.php - Saving options to the database
    4  *
    5  * @version $Id$
    6  * @copyright 2011 Jacco Drabbe
    7  */
     2    /**
     3    * dynwid_admin_save.php - Saving options to the database
     4    *
     5    * @version $Id$
     6    * @copyright 2011 Jacco Drabbe
     7    */
    88
    99    defined('ABSPATH') or die("No script kiddies please!");
    1010
    11   // Security - nonce, etc.
    12   $widget_id = ( isset($_POST['widget_id']) && ! empty($_POST['widget_id']) ) ? esc_attr($_POST['widget_id']) : '';
    13   $returnurl = ( isset($_POST['returnurl']) && ! empty($_POST['returnurl']) ) ? esc_url($_POST['returnurl']) : '';
    14 
    15   // In some cases $widget_id appears not to be global (anymore)
     11    // Security - nonce, etc.
     12    $widget_id = ( isset($_POST['widget_id']) && ! empty($_POST['widget_id']) ) ? esc_attr($_POST['widget_id']) : '';
     13    $returnurl = ( isset($_POST['returnurl']) && ! empty($_POST['returnurl']) ) ? esc_url($_POST['returnurl']) : '';
     14
     15    // In some cases $widget_id appears not to be global (anymore)
    1616    $GLOBALS['widget_id'] = $widget_id;
    1717
    18   check_admin_referer('plugin-name-action_edit_' . $widget_id);
    19   if (! array_key_exists($widget_id, $DW->registered_widgets) ) {
    20     wp_die('WidgetID is not valid');
    21   }
    22 
    23   /* Checking basic stuff */
     18    check_admin_referer('plugin-name-action_edit_' . $widget_id);
     19    if ( !array_key_exists($widget_id, $DW->registered_widgets) ) {
     20        wp_die('WidgetID is not valid');
     21    }
     22
     23    /* Checking basic stuff */
    2424    $DW->registerOverrulers();
    25   foreach ( $DW->overrule_maintype as $o ) {
    26     if ( $o != 'date' && $o != 'url' ) {
    27         $act_field = $o . '_act';
    28         if ( isset($_POST[$act_field]) ) {
    29             if ( $_POST[$o] == 'no' && count($_POST[$act_field]) == 0 ) {
    30                 wp_redirect( $_SERVER['REQUEST_URI'] . '&work=none' );
    31                 die();
    32             }
    33         }
    34     }
    35   }
    36 
    37   // Date check
    38   if ( $_POST['date'] == 'no' ) {
    39     $date_start = trim(esc_attr($_POST['date_start']));
    40     $date_end = trim(esc_attr($_POST['date_end']));
    41 
    42     if (! preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_start) && ! preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_end) ) {
    43       wp_redirect( $_SERVER['REQUEST_URI'] . '&work=none' );
    44       die();
    45     }
    46 
    47     if (! empty($date_start) ) {
    48       @list($date_start_year, $date_start_month, $date_start_day ) = explode('-', $date_start);
    49       if (! checkdate($date_start_month, $date_start_day, $date_start_year) ) {
    50         unset($date_start);
    51       }
    52     }
    53     if (! empty($date_end) ) {
    54       @list($date_end_year, $date_end_month, $date_end_day ) = explode('-', $date_end);
    55       if (! checkdate($date_end_month, $date_end_day, $date_end_year) ) {
    56         unset($date_end);
    57       }
    58     }
    59 
    60     if (! empty($date_start) && ! empty($date_end) ) {
    61       if ( mktime(0, 0, 0, $date_start_month, $date_start_day, $date_start_year) > mktime(0, 0, 0, $date_end_month, $date_end_day, $date_end_year) ) {
    62         wp_redirect( $_SERVER['REQUEST_URI'] . '&work=nonedate' );
    63         die();
    64       }
    65     }
    66   }
    67 
    68   // URL
    69   if ( $_POST['url'] == 'no' && empty($_POST['url_value']) ) {
    70     wp_redirect( $_SERVER['REQUEST_URI'] . '&work=none' );
    71     die();
    72   }
     25    foreach ( $DW->overrule_maintype as $o ) {
     26        if ( $o != 'date' && $o != 'url' ) {
     27            $act_field = $o . '_act';
     28            if ( isset($_POST[$act_field]) ) {
     29                if ( $_POST[$o] == 'no' && count($_POST[$act_field]) == 0 ) {
     30                    wp_redirect($_SERVER['REQUEST_URI'] . '&work=none');
     31                    die();
     32                }
     33            }
     34        }
     35    }
     36
     37    // Date check
     38    if ( $_POST['date'] == 'no' ) {
     39        $date_start = trim(esc_attr($_POST['date_start']));
     40        $date_end = trim(esc_attr($_POST['date_end']));
     41
     42        if ( ! preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_start) && ! preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_end) ) {
     43            wp_redirect($_SERVER['REQUEST_URI'] . '&work=none');
     44            die();
     45        }
     46
     47        if ( ! empty($date_start) ) {
     48            @list($date_start_year, $date_start_month, $date_start_day) = explode('-', $date_start);
     49            if ( !checkdate($date_start_month, $date_start_day, $date_start_year) ) {
     50                unset($date_start);
     51            }
     52        }
     53        if ( ! empty($date_end) ) {
     54            @list($date_end_year, $date_end_month, $date_end_day) = explode('-', $date_end);
     55            if ( !checkdate($date_end_month, $date_end_day, $date_end_year) ) {
     56                unset($date_end);
     57            }
     58        }
     59
     60        if ( ! empty($date_start) && ! empty($date_end) ) {
     61            if ( mktime(0, 0, 0, $date_start_month, $date_start_day, $date_start_year) > mktime(0, 0, 0, $date_end_month, $date_end_day, $date_end_year) ) {
     62                wp_redirect($_SERVER['REQUEST_URI'] . '&work=nonedate');
     63                die();
     64            }
     65        }
     66    }
     67
     68    // URL
     69    if ( $_POST['url'] == 'no' && empty($_POST['url_value']) ) {
     70        wp_redirect($_SERVER['REQUEST_URI'] . '&work=none');
     71        die();
     72    }
    7373
    7474    // Domain
    7575    if ( $_POST['domain'] == 'no' && empty($_POST['domain_value']) ) {
    76         wp_redirect( $_SERVER['REQUEST_URI'] . '&work=none' );
     76        wp_redirect($_SERVER['REQUEST_URI'] . '&work=none');
    7777        die();
    7878    }
    7979
    80   // IP
    81   if ( $_POST['ip'] == 'no' && empty($_POST['ip_value']) ) {
    82     wp_redirect( $_SERVER['REQUEST_URI'] . '&work=none' );
    83     die();
    84   }
    85 
    86   // Removing already set options, but keeping individual rules
    87   $dbtable = $GLOBALS['wpdb']->prefix . DW_DB_TABLE;
    88   $query = "SELECT COUNT(1) AS total FROM " . $dbtable . " WHERE widget_id = '" . $widget_id . "' AND maintype = 'individual'";
    89   $count = $GLOBALS['wpdb']->get_var($query);
    90 
    91   if ( $count > 0 && isset($_POST['individual']) && $_POST['individual'] == '1' ) {
    92     $post_types = ( is_array($_POST['post_types']) ) ? $_POST['post_types'] : array();
    93     $post_types = array_merge( array('single_post', 'single_tag'), $post_types );
    94 
    95     foreach ( $post_types as $t ) {
    96             $maintype = (! preg_match('/^single/', $t) ) ? $t . '-post' : $t;
    97 
    98         $query = "SELECT name FROM " . $dbtable . " WHERE widget_id = '" . $widget_id . "' AND maintype = '" . $maintype . "'";
    99         $results = $GLOBALS['wpdb']->get_results($query);
    100 
    101         foreach ( $results as $row ) {
    102             if ( is_numeric($row->name) ) {
    103                 $a = $maintype . '_act';
    104 
    105                 if (! is_array($_POST[$a]) ) {
    106                     $_POST[$a] = array();
    107                 }
    108 
    109                 $_POST[$a][ ] = $row->name;
    110             }
    111         }
    112 
    113     }
    114 
    115   }
    116 
    117   $DW->resetOptions($widget_id);
    118 
    119   // Role
     80    // IP
     81    if ( $_POST['ip'] == 'no' && empty($_POST['ip_value']) ) {
     82        wp_redirect($_SERVER['REQUEST_URI'] . '&work=none');
     83        die();
     84    }
     85
     86    // Removing already set options, but keeping individual rules
     87    $dbtable = $GLOBALS['wpdb']->prefix . DW_DB_TABLE;
     88    $query = "SELECT COUNT(1) AS total FROM " . $dbtable . " WHERE widget_id = '" . $widget_id . "' AND maintype = 'individual'";
     89    $count = $GLOBALS['wpdb']->get_var($query);
     90
     91    if ( $count > 0 && isset($_POST['individual']) && $_POST['individual'] == '1' ) {
     92        $post_types = ( is_array($_POST['post_types']) ) ? $_POST['post_types'] : array();
     93        $post_types = array_merge(array( 'single_post', 'single_tag' ), $post_types);
     94
     95        foreach ( $post_types as $t ) {
     96            $maintype = ( !preg_match('/^single/', $t) ) ? $t . '-post' : $t;
     97
     98            $query = "SELECT name FROM " . $dbtable . " WHERE widget_id = '" . $widget_id . "' AND maintype = '" . $maintype . "'";
     99            $results = $GLOBALS['wpdb']->get_results($query);
     100
     101            foreach ( $results as $row ) {
     102                if ( is_numeric($row->name) ) {
     103                    $a = $maintype . '_act';
     104
     105                    if ( !is_array($_POST[$a]) ) {
     106                        $_POST[$a] = array();
     107                    }
     108
     109                    $_POST[$a][] = $row->name;
     110                }
     111            }
     112
     113        }
     114
     115    }
     116
     117    $DW->resetOptions($widget_id);
     118
     119    // Role
    120120    DWModule::save('role', 'complex');
    121121
    122   // Date
    123   if ( $_POST['date'] == 'no' ) {
    124     $dates = array();
    125     if ( preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_start) ) {
    126       $dates['date_start'] = $date_start;
    127     }
    128     if ( preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_end) ) {
    129       $dates['date_end'] = $date_end;
    130     }
    131 
    132     if ( count($dates) > 0 ) {
    133       $DW->addDate($widget_id, $dates);
    134     }
    135   }
    136 
    137   // Day
    138   DWModule::save('day', 'complex');
    139 
    140   // Week
     122    // Date
     123    if ( $_POST['date'] == 'no' ) {
     124        $dates = array();
     125        if ( preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_start) ) {
     126            $dates['date_start'] = $date_start;
     127        }
     128        if ( preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date_end) ) {
     129            $dates['date_end'] = $date_end;
     130        }
     131
     132        if ( count($dates) > 0 ) {
     133            $DW->addDate($widget_id, $dates);
     134        }
     135    }
     136
     137    // Day
     138    DWModule::save('day', 'complex');
     139
     140    // Week
    141141    DWModule::save('week', 'complex');
    142142
    143   // Browser
     143    // Browser
    144144    DWModule::save('browser', 'complex');
    145145
     
    151151
    152152    // URL
    153     if (! empty($_POST['url_value']) ) {
     153    if ( ! empty($_POST['url_value']) ) {
    154154        $urls = array();
    155155
     
    160160        foreach ( $url_values as $url ) {
    161161            $url = trim($url);
    162             if (! empty($url) ) {
    163                 $urls[ ] = $url;
     162            if ( ! empty($url) ) {
     163                $urls[] = $url;
    164164            }
    165165        }
     
    171171
    172172    // URL
    173     if (! empty($_POST['domain_value']) ) {
     173    if ( ! empty($_POST['domain_value']) ) {
    174174        $domains = array();
    175175
     
    180180        foreach ( $domain_values as $domain ) {
    181181            $url = trim($domain);
    182             if (! empty($domain) ) {
    183                 $domains[ ] = $domain;
     182            if ( ! empty($domain) ) {
     183                $domains[] = $domain;
    184184            }
    185185        }
     
    190190    }
    191191
    192 
    193192    // IP
    194     if (! empty($_POST['ip_value']) ) {
     193    if ( ! empty($_POST['ip_value']) ) {
    195194        $ips = array();
    196195
     
    201200        foreach ( $ip_values as $ip ) {
    202201            $ip = trim($ip);
    203             if (! empty($ip) ) {
    204                 $ips[ ] = $ip;
     202            if ( ! empty($ip) ) {
     203                $ips[] = $ip;
    205204            }
    206205        }
     
    215214
    216215    // Shortcode
    217     if (! empty($_POST['shortcode_value']) ) {
     216    if ( ! empty($_POST['shortcode_value']) ) {
    218217        $value = sanitize_text_field($_POST['shortcode_value']);
    219         if (! empty($value) && substr($value, 0, 1) !== '[' && substr($value, strlen($value)-1) !== ']' ) {
     218        if ( ! empty($value) && substr($value, 0, 1) !== '[' && substr($value, strlen($value) - 1) !== ']' ) {
    220219            $value = '[' . $value . ']';
    221220        }
     
    223222        $match = sanitize_text_field($_POST['shortcode_match']);
    224223        $operator = $_POST['shortcode_operator'];
    225         if (! in_array($operator, array('=', '!=')) ) {
     224        if ( !in_array($operator, array( '=', '!=' )) ) {
    226225            $operator = '=';
    227226        }
    228227
    229         if (! empty($value) ) {
     228        if ( ! empty($value) ) {
    230229            $DW->addShortcode($widget_id, $_POST['shortcode'], $value, $match, $operator);
    231230        }
    232231    }
    233232
    234   // Front Page
    235   DWModule::save('front-page', 'complex');
    236 
    237   // Single Post
     233    // Front Page
     234    DWModule::save('front-page', 'complex');
     235
     236    // Single Post
    238237    DWModule::save('single');
    239238
    240239    // -- Post Taxonomies
    241     if ( isset($_POST['single_tax_list']) && count($_POST['single_tax_list']) > 0 ) {
     240    if ( isset($_POST['single_tax_list']) && is_array($_POST['single_tax_list']) && count($_POST['single_tax_list']) > 0 ) {
    242241        foreach ( $_POST['single_tax_list'] as $tax ) {
     242            $tax = sanitize_text_field($tax);
    243243            $act_tax_field = $tax . '_act';
    244244            // if ( isset($_POST[$act_tax_field]) && count($_POST[$act_tax_field]) > 0 ) {
    245             if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) ) {
     245            if ( isset($_POST[$act_tax_field]) && !empty($_POST[$act_tax_field]) ) {
    246246                if ( substr($_POST[$act_tax_field], 0, 1) == ',' ) {
    247247                    $_POST[$act_tax_field] = substr($_POST[$act_tax_field], 1);
     
    268268    }
    269269
    270   // -- Author
    271   if ( isset($_POST['single_author_act']) && count($_POST['single_author_act']) > 0 ) {
    272     if ( $_POST['single'] == 'yes' ) {
    273       $DW->addSingleOption($widget_id, 'single', '1');
    274     }
    275     $DW->addMultiOption($widget_id, 'single-author', $_POST['single'], $_POST['single_author_act']);
    276   }
    277 
    278   // -- Category
    279   if ( isset($_POST['single_category_act']) && count($_POST['single_category_act']) > 0 ) {
    280     if ( $_POST['single'] == 'yes' && isset($_POST['single_author_act']) && count($_POST['single_author_act']) == 0 ) {
    281       $DW->addSingleOption($widget_id, 'single', '1');
    282     }
    283     $DW->addMultiOption($widget_id, 'single-category', $_POST['single'], $_POST['single_category_act']);
    284   }
     270    // -- Author
     271    if ( isset($_POST['single_author_act']) && is_array($_POST['single_author_act']) && count($_POST['single_author_act']) > 0 ) {
     272        if ( $_POST['single'] == 'yes' ) {
     273            $DW->addSingleOption($widget_id, 'single', '1');
     274        }
     275        $DW->addMultiOption($widget_id, 'single-author', $_POST['single'], $_POST['single_author_act']);
     276    }
     277
     278    // -- Category
     279    if ( isset($_POST['single_category_act']) && is_array($_POST['single_category_act']) && count($_POST['single_category_act']) > 0 ) {
     280        if ( $_POST['single'] == 'yes' && isset($_POST['single_author_act']) && count($_POST['single_author_act']) == 0 ) {
     281            $DW->addSingleOption($widget_id, 'single', '1');
     282        }
     283        $DW->addMultiOption($widget_id, 'single-category', $_POST['single'], $_POST['single_category_act']);
     284    }
    285285
    286286    // ---- Childs
    287     if ( isset($_POST['single_category_act']) && count($_POST['single_category_act']) > 0 && isset($_POST['single_category_childs_act']) && count($_POST['single_category_childs_act']) > 0 ) {
     287    if ( isset($_POST['single_category_act']) && is_array($_POST['single_category_act']) && count($_POST['single_category_act']) > 0 && isset($_POST['single_category_childs_act']) && is_array($_POST['single_category_childs_act']) && count($_POST['single_category_childs_act']) > 0 ) {
    288288        $DW->addChilds($widget_id, 'single-category-childs', $_POST['single'], $_POST['single_category_act'], $_POST['single_category_childs_act']);
    289289    }
    290290
    291   // -- Individual / Posts / Tag
    292   if ( isset($_POST['individual']) && $_POST['individual'] == '1' ) {
    293     $DW->addSingleOption($widget_id, 'individual', '1');
    294     if ( isset($_POST['single_post_act']) && count($_POST['single_post_act']) > 0 ) {
    295       $DW->addMultiOption($widget_id, 'single-post', $_POST['single'], $_POST['single_post_act']);
    296     }
    297     if ( isset($_POST['single_tag_act']) && count($_POST['single_tag_act']) > 0 ) {
    298       $DW->addMultiOption($widget_id, 'single-tag', $_POST['single'], $_POST['single_tag_act']);
    299     }
    300   }
    301 
    302   // Attachment
     291    // -- Individual / Posts / Tag
     292    if ( isset($_POST['individual']) && $_POST['individual'] == '1' ) {
     293        $DW->addSingleOption($widget_id, 'individual', '1');
     294        if ( isset($_POST['single_post_act']) && is_array($_POST['single_post_act']) && count($_POST['single_post_act']) > 0 ) {
     295            $DW->addMultiOption($widget_id, 'single-post', $_POST['single'], $_POST['single_post_act']);
     296        }
     297        if ( isset($_POST['single_tag_act']) && is_array($_POST['single_tag_act']) && count($_POST['single_tag_act']) > 0 ) {
     298            $DW->addMultiOption($widget_id, 'single-tag', $_POST['single'], $_POST['single_tag_act']);
     299        }
     300    }
     301
     302    // Attachment
    303303    DWModule::save('attachment');
    304304
    305   // Pages
     305    // Pages
    306306    // Go through the page_tax_list - Workaround as for some reason get_object_taxonomies() is not always filled
    307307    $page_taxonomy = FALSE;
    308308    $page_tax_list = array();
    309     if ( isset($_POST['page_tax_list']) && count($_POST['page_tax_list']) > 0 ) {
     309    if ( isset($_POST['page_tax_list']) && is_array($_POST['page_tax_list']) && count($_POST['page_tax_list']) > 0 ) {
    310310        foreach ( $_POST['page_tax_list'] as $tax ) {
     311            $tax = sanitize_text_field($tax);
    311312            $act_tax_field = $tax . '_act';
    312313            if ( isset($_POST[$act_tax_field]) && count($_POST[$act_tax_field]) > 0 ) {
     
    317318    }
    318319
    319     if ( (isset($_POST['page_act']) && count($_POST['page_act']) > 0) || $page_taxonomy ) {
    320         if (! isset($_POST['page_act']) ) {
     320    if ( ( isset($_POST['page_act']) && is_array($_POST['page_act']) && count($_POST['page_act']) > 0 ) || $page_taxonomy ) {
     321        // When $page_taxonomy = TRUE
     322        if ( !isset($_POST['page_act']) ) {
    321323            $_POST['page_act'] = array();
    322324        }
     
    331333
    332334    // -- Page Taxonomies
    333     if ( isset($_POST['page_tax_list']) && count($_POST['page_tax_list']) > 0 ) {
     335    if ( isset($_POST['page_tax_list']) && is_array($_POST['page_tax_list']) && count($_POST['page_tax_list']) > 0 ) {
    334336        foreach ( $_POST['page_tax_list'] as $tax ) {
     337            $tax = sanitize_text_field($tax);
     338
    335339            $act_tax_field = $tax . '_act';
    336340            if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) ) {
     
    347351            // ---- Childs >> Can't use DWModule::childSave() cause of $name != $tax, but $name == 'page'
    348352            $act_tax_childs_field = $tax . '_childs_act';
    349             if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) && isset($_POST[$act_tax_childs_field]) && ! empty($_POST[$act_tax_childs_field]) ) {
     353            if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) && isset($_POST[$act_tax_childs_field]) && !empty($_POST[$act_tax_childs_field]) ) {
    350354
    351355                if ( substr($_POST[$act_tax_childs_field], 0, 1) == ',' ) {
     
    360364    }
    361365
    362   // Author
     366    // Author
    363367    DWModule::save('author', 'complex');
    364368
    365   // Categories
     369    // Categories
    366370    DWModule::save('category', 'complex');
    367     DWModule::childSave('category');        // -- Childs
     371    DWModule::childSave('category');      // -- Childs
    368372
    369373    // Tags
    370374    DWModule::save('tag', 'complex');
    371375
    372   // Archive
     376    // Archive
    373377    DWModule::save('archive');
    374378
    375   // Error 404
     379    // Error 404
    376380    DWModule::save('e404');
    377381
    378   // Search
     382    // Search
    379383    DWModule::save('search');
    380384
    381   // Custom Types
    382   if ( isset($_POST['post_types']) ) {
    383     foreach ( $_POST['post_types'] as $type ) {
    384 
    385         if ( isset($_POST['individual']) && $_POST['individual'] == '1' ) {
    386             if ( isset($_POST[$type . '-post_act']) && count($_POST[$type . '-post_act']) > 0 ) {
    387               $DW->addMultiOption($widget_id, $type . '-post', $_POST[$type], $_POST[$type . '-post_act']);
    388             }
    389           }
    390 
    391         // Check taxonomies
    392         $taxonomy = FALSE;
    393 
    394         // Go through the tax_list - Workaround as for some reason get_object_taxonomies() is not always filled
    395         $tax_list = array();
    396         $len = strlen($type);
    397         if ( isset($_POST['tax_list']) && count($_POST['tax_list']) > 0 ) {
    398             foreach ( $_POST['tax_list'] as $tl ) {
    399                 if ( substr($tl, 0, $len) == $type ) {
    400                     $tax_list[] = $tl;
    401                 }
    402             }
    403         }
    404 
    405         foreach ( $tax_list as $tax ) {
    406             $act_tax_field = $tax . '_act';
    407             if ( isset($_POST[$act_tax_field]) && count($_POST[$act_tax_field]) > 0 ) {
    408                 $taxonomy = TRUE;
    409                 break;
    410             }
    411         }
    412 
    413       $act_field = $type . '_act';
    414       if ( (isset($_POST[$act_field]) && count($_POST[$act_field]) > 0) || $taxonomy ) {
    415         if (! isset($_POST[$act_field]) ) {
    416             $_POST[$act_field] = array();
    417         }
    418 
    419         $DW->addMultiOption($widget_id, $type, $_POST[$type], $_POST[$act_field]);
    420       } else if ( $_POST[$type] == 'no' ) {
    421         $DW->addSingleOption($widget_id, $type);
    422       }
    423 
    424         // -- Childs
    425         DWModule::childSave($type);
    426 
    427         // -- Taxonomies
    428         foreach ( $tax_list as $tax ) {
    429             $act_tax_field = $tax . '_act';
    430             if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) ) {
    431 
    432                 if ( substr($_POST[$act_tax_field], 0, 1) == ',' ) {
    433                     $_POST[$act_tax_field] = substr($_POST[$act_tax_field], 1);
    434                 }
    435                 $t = explode(',', $_POST[$act_tax_field]);
    436                 $t = array_unique($t);
     385    // Custom Types
     386    if ( isset($_POST['post_types']) ) {
     387        foreach ( $_POST['post_types'] as $type ) {
     388            $type = sanitize_text_field($type);
     389
     390            if ( isset($_POST['individual']) && sanitize_text_field($_POST['individual']) == '1' ) {
     391                if ( isset($_POST[$type . '-post_act']) && is_array($_POST[$type . '-post_act']) && count($_POST[$type . '-post_act']) > 0 ) {
     392                    $DW->addMultiOption($widget_id, $type . '-post', $_POST[$type], $_POST[$type . '-post_act']);
     393                }
     394            }
     395
     396            // Check taxonomies
     397            $taxonomy = FALSE;
     398
     399            // Go through the tax_list - Workaround as for some reason get_object_taxonomies() is not always filled
     400            $tax_list = array();
     401            $len = strlen($type);
     402            if ( isset($_POST['tax_list']) && is_array($_POST['tax_list']) && count($_POST['tax_list']) > 0 ) {
     403                foreach ( $_POST['tax_list'] as $tl ) {
     404                    $tl = sanitize_text_field($tl);
     405
     406                    if ( substr($tl, 0, $len) == $type ) {
     407                        $tax_list[] = $tl;
     408                    }
     409                }
     410            }
     411
     412            foreach ( $tax_list as $tax ) {
     413                $act_tax_field = $tax . '_act';
     414                if ( isset($_POST[$act_tax_field]) && is_array($_POST[$act_tax_field]) && count($_POST[$act_tax_field]) > 0 ) {
     415                    $taxonomy = TRUE;
     416                    break;
     417                }
     418            }
     419
     420            $act_field = $type . '_act';
     421            if ( ( isset($_POST[$act_field]) && is_array($_POST[$act_tax_field]) && count($_POST[$act_field]) > 0 ) || $taxonomy ) {
     422                // When taxonomy = TRUE
     423                if ( !isset($_POST[$act_field]) ) {
     424                    $_POST[$act_field] = array();
     425                }
     426
     427                $DW->addMultiOption($widget_id, $type, $_POST[$type], $_POST[$act_field]);
     428            } else if ( $_POST[$type] == 'no' ) {
     429                $DW->addSingleOption($widget_id, $type);
     430            }
     431
     432            // -- Childs
     433            DWModule::childSave($type);
     434
     435            // -- Taxonomies
     436            foreach ( $tax_list as $tax ) {
     437                $act_tax_field = $tax . '_act';
     438                if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) ) {
     439
     440                    if ( substr($_POST[$act_tax_field], 0, 1) == ',' ) {
     441                        $_POST[$act_tax_field] = substr($_POST[$act_tax_field], 1);
     442                    }
     443                    $t = explode(',', $_POST[$act_tax_field]);
     444                    $t = array_unique($t);
    437445
    438446                    $DW->addMultiOption($widget_id, $tax, $_POST[$type], $t);
    439             }
    440 
    441             // ---- Childs >> Can't use DWModule::childSave() cause of $name != $tax, but $name == $type
    442             $act_tax_childs_field = $tax . '_childs_act';
    443             if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) && isset($_POST[$act_tax_childs_field]) && ! empty($_POST[$act_tax_childs_field]) ) {
    444 
    445                 if ( substr($_POST[$act_tax_childs_field], 0, 1) == ',' ) {
    446                     $_POST[$act_tax_childs_field] = substr($_POST[$act_tax_childs_field], 1);
    447                 }
    448                 $t_childs = explode(',', $_POST[$act_tax_childs_field]);
    449                 $t_childs = array_unique($t_childs);
    450 
    451                 $DW->addChilds($widget_id, $tax . '-childs', $_POST[$type], $t, $t_childs);
    452             }
    453         }
    454     }
     447                }
     448
     449                // ---- Childs >> Can't use DWModule::childSave() cause of $name != $tax, but $name == $type
     450                $act_tax_childs_field = $tax . '_childs_act';
     451                if ( isset($_POST[$act_tax_field]) && ! empty($_POST[$act_tax_field]) && isset($_POST[$act_tax_childs_field]) && !empty($_POST[$act_tax_childs_field]) ) {
     452
     453                    if ( substr($_POST[$act_tax_childs_field], 0, 1) == ',' ) {
     454                        $_POST[$act_tax_childs_field] = substr($_POST[$act_tax_childs_field], 1);
     455                    }
     456                    $t_childs = explode(',', $_POST[$act_tax_childs_field]);
     457                    $t_childs = array_unique($t_childs);
     458
     459                    $DW->addChilds($widget_id, $tax . '-childs', $_POST[$type], $t, $t_childs);
     460                }
     461            }
     462        }
    455463
    456464        DWModule::save('cp_archive', 'complex');
    457   }
     465    }
    458466
    459467    // Custom Taxonomies
     
    463471            $act_field = $type . '_act';
    464472            if ( isset($_POST[$act_field]) && ! empty($_POST[$act_field]) ) {
    465 /*              if (! is_array($_POST[$act_field]) ) {
    466                     $_POST[$act_field] = array();
    467                 } */
     473                /*              if (! is_array($_POST[$act_field]) ) {
     474                                    $_POST[$act_field] = array();
     475                                } */
    468476
    469477                if ( substr($_POST[$act_field], 0, 1) == ',' ) {
     
    482490    }
    483491
    484   // WPML PLugin support
     492    // WPML PLugin support
    485493    DWModule::save('wpml', 'complex');
    486494
     
    488496    // DWModule::save('qt', 'complex');
    489497
    490   // WPSC/WPEC Plugin support
     498    // WPSC/WPEC Plugin support
    491499    DWModule::save('wpsc', 'complex');
    492500
     
    503511    DWModule::save('pods', 'complex');
    504512
    505   // Redirect to ReturnURL
    506   if (! empty($returnurl) ) {
    507     $q = array();
    508 
    509     // Checking if there are arguments set
    510     $pos = strpos($returnurl, '?');
    511     if ( $pos !== FALSE ) {
    512       // evaluate the args
    513       $query_string = substr($returnurl, ($pos+1));
    514       $args = explode('&', $query_string);
    515       foreach ( $args as $arg ) {
    516         @list($name, $value) = explode('=', $arg);
    517         if ( $name != 'dynwid_save' && $name != 'widget_id' ) {
    518           $q[ ] = $name . '=' . $value;
    519         }
    520       }
    521       $script_url = substr($returnurl, 0, $pos);
    522     } else {
    523       $script_url = $returnurl;
    524     }
    525     $q[ ] = 'dynwid_save=yes';
    526     $q[ ] = 'widget_id=' . $widget_id;
    527 
    528     wp_redirect( $script_url . '?' . implode('&', $q) );
    529     die();
    530   }
     513    // Redirect to ReturnURL
     514    if ( ! empty($returnurl) ) {
     515        $q = array();
     516
     517        // Checking if there are arguments set
     518        $pos = strpos($returnurl, '?');
     519        if ( $pos !== FALSE ) {
     520            // evaluate the args
     521            $query_string = substr($returnurl, ( $pos + 1 ));
     522            $args = explode('&', $query_string);
     523            foreach ( $args as $arg ) {
     524                @list($name, $value) = explode('=', $arg);
     525                if ( $name != 'dynwid_save' && $name != 'widget_id' ) {
     526                    $q[] = $name . '=' . $value;
     527                }
     528            }
     529            $script_url = substr($returnurl, 0, $pos);
     530        } else {
     531            $script_url = $returnurl;
     532        }
     533        $q[] = 'dynwid_save=yes';
     534        $q[] = 'widget_id=' . $widget_id;
     535
     536        wp_redirect($script_url . '?' . implode('&', $q));
     537        die();
     538    }
    531539?>
Note: See TracChangeset for help on using the changeset viewer.