Plugin Directory

Changeset 890021


Ignore:
Timestamp:
04/09/2014 11:21:21 AM (12 years ago)
Author:
marquex
Message:

Added buddypress pages support.

Location:
custom-sidebars/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • custom-sidebars/trunk/customsidebars.php

    r836632 r890021  
    44Plugin URI: http://wordpress.org/plugins/custom-sidebars/
    55Description: Allows to create your own widgetized areas and custom sidebars, and select what sidebars to use for each post or page.
    6 Version: 1.4
     6Version: 1.5
    77Author: WPMUDEV
    88Author URI: http://premium.wpmudev.org/
     
    1111
    1212/*
    13 This plugin was originally developed by Javier Marquez. 
    14 http://marquex.es/
     13This plugin was originally developed by Javier Marquez.
     14http://arqex.com/
    1515*/
    1616
     
    1818
    1919class CustomSidebars{
    20    
     20
    2121    var $message = '';
    2222    var $message_class = '';
    23    
     23
    2424    //The name of the option that stores the info of the new bars.
    2525    var $option_name = "cs_sidebars";
     
    2727    //replacements. The value is stored in $this->options
    2828    var $option_modifiable = "cs_modifiable";
    29    
    30    
     29
     30
    3131    var $sidebar_prefix = 'cs-';
    3232    var $postmeta_key = '_cs_replacements';
     
    3434    var $ignore_post_types = array('attachment', 'revision', 'nav_menu_item', 'pt-widget');
    3535    var $options = array();
    36    
     36
    3737    var $replaceable_sidebars = array();
    3838    var $replacements = array();
    3939    var $replacements_todo;
    40    
     40
    4141    function CustomSidebars(){
    4242        $this->retrieveOptions();
     
    4646            $this->replacements[$sb] = FALSE;
    4747    }
    48    
     48
    4949    function retrieveOptions(){
    5050        $this->options = get_option($this->option_modifiable);
    5151    }
    52    
     52
    5353    function getCustomSidebars(){
    5454        $sidebars = get_option($this->option_name);
     
    5757        return array();
    5858    }
    59    
     59
    6060    function getThemeSidebars($include_custom_sidebars = FALSE){
    61        
    62         global $wp_registered_sidebars;     
     61
     62        global $wp_registered_sidebars;
    6363        $allsidebars = $wp_registered_sidebars;
    6464        ksort($allsidebars);
    6565        if($include_custom_sidebars)
    6666            return $allsidebars;
    67        
     67
    6868        $themesidebars = array();
    6969        foreach($allsidebars as $key => $sb){
     
    7171                $themesidebars[$key] = $sb;
    7272        }
    73        
     73
    7474        return $themesidebars;
    7575    }
    76    
     76
    7777    function registerCustomSidebars(){
    7878        $sb = $this->getCustomSidebars();
     
    8383        }
    8484    }
    85    
     85
    8686    function replaceSidebars(){
    8787        global $_wp_sidebars_widgets, $post, $wp_registered_sidebars, $wp_registered_widgets;
    88        
     88
    8989        $original_widgets = $_wp_sidebars_widgets;
    90        
     90
    9191        $updated = FALSE;
    92        
     92
    9393        $replaceables = $this->replaceable_sidebars;
    9494        $defaults = $this->getDefaultReplacements();
    95        
     95
    9696        do_action('cs_predetermineReplacements');
    97        
     97
    9898        $this->determineReplacements($defaults);
    99        
     99
    100100        foreach($this->replacements as $sb_name => $replacement_info){
    101101            if($replacement_info){
     
    135135            global $post;
    136136
    137             $replacements = get_post_meta($post->ID, $this->postmeta_key, TRUE);
     137            $replacements = get_post_meta($this->originalPostId, $this->postmeta_key, TRUE);
    138138            foreach($this->replaceable_sidebars as $sidebar){
    139139                if(is_array($replacements) && !empty($replacements[$sidebar])){
     
    160160                    foreach($this->replaceable_sidebars as $sidebar){
    161161                        if(!$this->replacements[$sidebar] && !empty($defaults['category_posts'][$categories[$i]->cat_ID][$sidebar])){
    162                             $this->replacements[$sidebar] = array($defaults['category_posts'][$categories[$i]->cat_ID][$sidebar], 
    163                                                                     'category_posts', 
     162                            $this->replacements[$sidebar] = array($defaults['category_posts'][$categories[$i]->cat_ID][$sidebar],
     163                                                                    'category_posts',
    164164                                                                    $sidebar_category);
    165165                            $this->replacements_todo--;
     
    195195                if($current_category != 0)
    196196                    $category_object = get_category($current_category);
    197             }   
     197            }
    198198            return;
    199199        }
    200                
     200
    201201        //Search comes before because searches with no results are recognized as post types archives
    202202        if(is_search()){
     
    207207            return;
    208208        }
    209        
     209
    210210        //post type archive
    211211        if(!is_category() && !is_singular() && get_post_type()!='post'){
     
    222222        if(is_page()){
    223223            global $post;
    224             $replacements = get_post_meta($post->ID, $this->postmeta_key, TRUE);
     224            $replacements = get_post_meta($this->originalPostId, $this->postmeta_key, TRUE);
    225225            foreach($this->replaceable_sidebars as $sidebar){
    226226                if(is_array($replacements) && !empty($replacements[$sidebar])){
     
    229229                }
    230230            }
    231                        
     231
    232232                        //Parent sidebar
    233233                        if($post->post_parent != 0 && $this->replacements_todo > 0){
     
    240240                            }
    241241                        }
    242                        
     242
    243243            //Page Post-type sidebar
    244244            if($this->replacements_todo > 0){
     
    252252            return;
    253253        }
    254        
     254
    255255        if(is_home()){
    256256            foreach($this->replaceable_sidebars as $sidebar){
     
    260260            return;
    261261        }
    262        
     262
    263263        if(is_tag()){
    264264            foreach($this->replaceable_sidebars as $sidebar){
     
    268268            return;
    269269        }
    270        
     270
    271271        if(is_author()){
    272272            foreach($this->replaceable_sidebars as $sidebar){
     
    276276            return;
    277277        }
    278                
    279                
     278
     279
    280280                if(is_date()){
    281281                    foreach($this->replaceable_sidebars as $sidebar){
     
    286286                }
    287287    }
    288    
     288    /**
     289     * Stores the original post id before any plugin (buddypress) can modify this data, to show the proper sidebar.
     290     * @return null
     291     */
     292    function storeOriginalPostId(){
     293        global $post;
     294        $this->originalPostId = $post->ID;
     295    }
     296
    289297    function checkAndFixSidebar($sidebar, $replacement, $method, $extra_index){
    290298        global $wp_registered_sidebars;
    291        
    292        
     299
     300
    293301        if(isset($wp_registered_sidebars[$replacement]))
    294302            return true;
    295        
     303
    296304        if($method == 'particular'){
    297305            global $post;
     
    299307            if($sidebars && isset($sidebars[$sidebar])){
    300308                unset($sidebars[$sidebar]);
    301                 update_post_meta($post->ID, $this->postmeta_key, $sidebars);   
     309                update_post_meta($post->ID, $this->postmeta_key, $sidebars);
    302310            }
    303311        }
     
    310318                if($extra_index == 1 && isset($this->options[$method]) && isset($this->options[$method][$sidebar])){
    311319                    unset($this->options[$method][$sidebar]);
    312                     update_option($this->option_modifiable, $this->options);               
    313                 }
    314             }
    315         }
    316        
     320                    update_option($this->option_modifiable, $this->options);
     321                }
     322            }
     323        }
     324
    317325        return false;
    318326    }
    319    
     327
    320328    function replace_before_after_widget($sidebar){
    321329        return (trim($sidebar['before_widget']) != '' OR
     
    324332            trim($sidebar['after_title']) != '');
    325333    }
    326    
     334
    327335    function deleteSidebar(){
    328336        if(! current_user_can($this->cap_required) )
    329337            return new WP_Error('cscantdelete', __('You do not have permission to delete sidebars','custom-sidebars'));
    330        
    331                 if(! DOING_AJAX && ! wp_verify_nonce($_REQUEST['_n'], 'custom-sidebars-delete') ) 
    332                         die('Security check stop your request.'); 
    333        
     338
     339                if(! DOING_AJAX && ! wp_verify_nonce($_REQUEST['_n'], 'custom-sidebars-delete') )
     340                        die('Security check stop your request.');
     341
    334342        $newsidebars = array();
    335343        $deleted = FALSE;
    336        
     344
    337345        $custom = $this->getCustomSidebars();
    338        
     346
    339347        if(!empty($custom)){
    340        
     348
    341349        foreach($custom as $sb){
    342350            if($sb['id']!=$_REQUEST['delete'])
     
    346354        }
    347355        }//endif custom
    348        
     356
    349357        //update option
    350358        update_option( $this->option_name, $newsidebars );
    351359
    352360        $this->refreshSidebarsWidgets();
    353        
     361
    354362        if($deleted)
    355363            $this->setMessage(sprintf(__('The sidebar "%s" has been deleted.','custom-sidebars'), $_REQUEST['delete']));
     
    357365            $this->setError(sprintf(__('There was not any sidebar called "%s" and it could not been deleted.','custom-sidebars'), $_GET['delete']));
    358366    }
    359    
     367
    360368    function createPage(){
    361        
     369
    362370        //$this->refreshSidebarsWidgets();
    363371        if(!empty($_POST)){
     
    369377                check_admin_referer('custom-sidebars-update');
    370378                $this->updateSidebar();
    371             }       
     379            }
    372380            else if(isset($_POST['update-modifiable'])){
    373381                $this->updateModifiable();
     
    377385            else if(isset($_POST['update-defaults-posts']) OR isset($_POST['update-defaults-pages'])){
    378386                $this->storeDefaults();
    379            
    380             }
    381                
     387
     388            }
     389
    382390            else if(isset($_POST['reset-sidebars']))
    383                 $this->resetSidebars();         
    384                
     391                $this->resetSidebars();
     392
    385393            $this->retrieveOptions();
    386394        }
    387395        else if(!empty($_GET['delete'])){
    388396            $this->deleteSidebar();
    389             $this->retrieveOptions();           
     397            $this->retrieveOptions();
    390398        }
    391399        else if(!empty($_GET['p'])){
     
    395403                    return new WP_Error('cscantdelete', __('You do not have permission to delete sidebars','custom-sidebars'));
    396404                include('views/edit.php');
    397                 return; 
    398             }
    399         }
    400        
     405                return;
     406            }
     407        }
     408
    401409        $customsidebars = $this->getCustomSidebars();
    402410        $themesidebars = $this->getThemeSidebars();
     
    405413        $modifiable = $this->replaceable_sidebars;
    406414        $post_types = $this->getPostTypes();
    407        
     415
    408416        $deletenonce = wp_create_nonce('custom-sidebars-delete');
    409        
     417
    410418        //var_dump($defaults);
    411        
     419
    412420        //Form
    413421        if(!empty($_GET['p'])){
     
    416424                if(sizeof($categories)==1 && $categories[0]->cat_ID == 1)
    417425                    unset($categories[0]);
    418                    
     426
    419427                include('views/defaults.php');
    420428            }
     
    422430                include('views/edit.php');
    423431            else
    424                 include('views/settings.php'); 
    425                
    426         }
    427         else       
    428                     include('views/settings.php');     
    429     }
    430    
     432                include('views/settings.php');
     433
     434        }
     435        else
     436                    include('views/settings.php');
     437    }
     438
    431439    function addSubMenus(){
    432440        $page = add_submenu_page('themes.php', __('Custom sidebars','custom-sidebars'), __('Custom sidebars','custom-sidebars'), $this->cap_required, 'customsidebars', array($this, 'createPage'));
    433        
     441
    434442        add_action('admin_print_scripts-' . $page, array($this, 'addScripts'));
    435443    }
    436    
     444
    437445    function addScripts(){
    438446        wp_enqueue_script('post');
    439447    }
    440    
     448
    441449    function addStyles($hook){
    442450        $dir = basename(dirname(__FILE__));
     
    446454            wp_enqueue_style('thickbox.css', includes_url() . 'js/thickbox/thickbox.css', null, '1.0');
    447455        }
    448         wp_enqueue_style( 'cs_style', plugins_url( 'cs_style.css', __FILE__ ) );       
    449     }
    450    
     456        wp_enqueue_style( 'cs_style', plugins_url( 'cs_style.css', __FILE__ ) );
     457    }
     458
    451459    function addMetaBox(){
    452460        global $post;
     
    454462        if($post_type && !(array_search($post_type, $this->ignore_post_types))){
    455463            $post_type_object = get_post_type_object($post_type);
    456             if($post_type_object->publicly_queryable || $post_type_object->public) 
     464            if($post_type_object->publicly_queryable || $post_type_object->public)
    457465                add_meta_box('customsidebars-mb', 'Sidebars', array($this,'printMetabox'), $post_type, 'side');
    458466        }
    459467    }
    460    
     468
    461469    function printMetabox(){
    462470        global $post, $wp_registered_sidebars;
    463        
     471
    464472        $replacements = $this->getReplacements($post->ID);
    465            
     473
    466474        //$available = array_merge(array(''), $this->getThemeSidebars(TRUE));
    467475        $available = $wp_registered_sidebars;
     
    477485            }
    478486        }
    479        
     487
    480488        include('metabox.php');
    481489    }
    482    
     490
    483491    function loadTextDomain(){
    484492        load_plugin_textdomain( 'custom-sidebars', false, dirname(plugin_basename( __FILE__ )) . "/lang/");
    485493    }
    486    
     494
    487495    function getReplacements($postid){
    488496        $replacements = get_post_meta($postid, $this->postmeta_key, TRUE);
     
    493501        return $replacements;
    494502    }
    495    
     503
    496504    function getModifiableSidebars(){
    497505        if( $modifiable = $this->options ) //get_option($this->option_modifiable) )
    498506            return $modifiable['modifiable'];
    499         return array(); 
    500     }
    501    
     507        return array();
     508    }
     509
    502510    function getDefaultReplacements(){
    503511        if( $defaults = $this->options ){//get_option($this->option_modifiable) )
     
    507515            return $defaults;
    508516        }
    509         return array(); 
    510     }
    511    
     517        return array();
     518    }
     519
    512520    function updateModifiable(){
    513521        check_admin_referer('custom-sidebars-options', 'options_wpnonce');
    514522        $options = $this->options ? $this->options : array();
    515        
     523
    516524        //Modifiable bars
    517525        if(isset($_POST['modifiable']) && is_array($_POST['modifiable']))
    518526            $options['modifiable'] = $_POST['modifiable'];
    519527
    520        
     528
    521529        if($this->options !== FALSE)
    522530            update_option($this->option_modifiable, $options);
    523531        else
    524532            add_option($this->option_modifiable, $options);
    525            
     533
    526534        $this->setMessage(__('The custom sidebars settings has been updated successfully.','custom-sidebars'));
    527535    }
    528    
     536
    529537    function storeDefaults(){
    530        
     538
    531539        $options = $this->options;
    532540        $modifiable = $this->replaceable_sidebars;
    533        
     541
    534542        //Post-types posts and lists. Posts data are called default in order to keep backwards compatibility;
    535        
     543
    536544        $options['defaults'] = array();
    537545        $options['post_type_pages'] = array();
    538        
     546
    539547        foreach($this->getPostTypes() as $pt){
    540548            if(!empty($modifiable)){
     
    543551                        if(! isset($options['defaults'][$pt]))
    544552                            $options['defaults'][$pt] = array();
    545                        
     553
    546554                        $options['defaults'][$pt][$m] = $_POST["type_posts_{$pt}_$m"];
    547555                    }
    548                    
     556
    549557                    if(isset($_POST["type_page_{$pt}_$m"]) && $_POST["type_page_{$pt}_$m"]!=''){
    550558                        if(! isset($options['post_type_pages'][$pt]))
    551559                            $options['post_type_pages'][$pt] = array();
    552                        
     560
    553561                        $options['post_type_pages'][$pt][$m] = $_POST["type_page_{$pt}_$m"];
    554562                    }
     
    556564            }
    557565        }
    558        
    559        
     566
     567
    560568        //Category posts and post lists.
    561        
     569
    562570        $options['category_posts'] = array();
    563571        $options['category_pages'] = array();
     
    570578                        if(! isset($options['category_posts'][$catid]))
    571579                            $options['category_posts'][$catid] = array();
    572                        
     580
    573581                        $options['category_posts'][$catid][$m] = $_POST["category_posts_{$catid}_$m"];
    574582                    }
    575                    
     583
    576584                    if(isset($_POST["category_page_{$catid}_$m"]) && $_POST["category_page_{$catid}_$m"]!=''){
    577585                        if(! isset($options['category_pages'][$catid]))
    578586                            $options['category_pages'][$catid] = array();
    579                        
     587
    580588                        $options['category_pages'][$catid][$m] = $_POST["category_page_{$catid}_$m"];
    581589                    }
     
    583591            }
    584592        }
    585        
     593
    586594        // Blog page
    587        
     595
    588596        $options['blog'] = array();
    589597        if(!empty($modifiable)){
     
    592600                    if(! isset($options['blog']))
    593601                        $options['blog'] = array();
    594                    
     602
    595603                    $options['blog'][$m] = $_POST["blog_page_$m"];
    596604                }
    597605            }
    598606        }
    599        
     607
    600608        // Tag page
    601        
     609
    602610        $options['tags'] = array();
    603611        if(!empty($modifiable)){
     
    606614                    if(! isset($options['tags']))
    607615                        $options['tags'] = array();
    608                    
     616
    609617                    $options['tags'][$m] = $_POST["tag_page_$m"];
    610618                }
    611619            }
    612620        }
    613        
     621
    614622        // Author page
    615        
     623
    616624        $options['authors'] = array();
    617625        if(!empty($modifiable)){
     
    620628                    if(! isset($options['authors']))
    621629                        $options['authors'] = array();
    622                    
     630
    623631                    $options['authors'][$m] = $_POST["authors_page_$m"];
    624632                }
    625633            }
    626634        }
    627                
     635
    628636                // Search page
    629637                $options['search'] = array();
     
    633641                    if(! isset($options['search']))
    634642                        $options['search'] = array();
    635                    
     643
    636644                    $options['search'][$m] = $_POST["search_page_$m"];
    637645                }
    638646            }
    639647        }
    640                
     648
    641649                // Date archive
    642650                $options['date'] = array();
     
    646654                    if(! isset($options['date']))
    647655                        $options['date'] = array();
    648                    
     656
    649657                    $options['date'][$m] = $_POST["date_page_$m"];
    650658                }
    651659            }
    652660        }
    653        
    654        
     661
     662
    655663        //Store defaults
    656664        if($this->options !== FALSE)
     
    660668            add_option($this->option_modifiable, $options);
    661669        }
    662            
     670
    663671        $this->setMessage(__('The default sidebars have been updated successfully.','custom-sidebars'));
    664        
    665     }
    666    
     672
     673    }
     674
    667675    function storeReplacements( $post_id ){
    668676        if(! current_user_can($this->cap_required))
     
    670678        // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want
    671679        // to do anything (Copied and pasted from wordpress add_metabox_tutorial)
    672         if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
     680        if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
    673681            return $post_id;
    674            
     682
    675683        global $action;
    676        
    677         //Get sure we are editing the post normaly, if we are bulk editing or quick editing, 
     684
     685        //Get sure we are editing the post normaly, if we are bulk editing or quick editing,
    678686        //no sidebars data is recieved and the sidebars would be deleted.
    679687        if($action != 'editpost')
    680688            return $post_id;
    681            
     689
    682690        // make sure meta is added to the post, not a revision
    683691        if ( $the_post = wp_is_post_revision($post_id) )
    684692            $post_id = $the_post;
    685        
     693
    686694        $sidebars = $this->replaceable_sidebars;
    687695        $data = array();
     
    707715        }
    708716    }
    709    
     717
    710718    function storeSidebar(){
    711719        $name = stripslashes(trim($_POST['sidebar_name']));
     
    729737                        'after_title' => '',
    730738                        ) ;
    731                        
    732                    
     739
     740
    733741                    //update option
    734742                    update_option( $this->option_name, $sidebars );
    735                        
     743
    736744                    $this->refreshSidebarsWidgets();
    737                    
     745
    738746                    $this->setMessage( __('The sidebar has been created successfully.','custom-sidebars'));
    739                    
    740                    
     747
     748
    741749                }
    742750                else
     
    755763                        ) );
    756764                add_option($this->option_name, $sidebars);
    757                
    758                
     765
     766
    759767                $this->refreshSidebarsWidgets();
    760                
    761                 $this->setMessage( __('The sidebar has been created successfully.','custom-sidebars'));                 
    762             }
    763         }
    764     }
    765    
     768
     769                $this->setMessage( __('The sidebar has been created successfully.','custom-sidebars'));
     770            }
     771        }
     772    }
     773
    766774    function updateSidebar(){
    767775        $id = stripslashes(trim($_POST['cs_id']));
     
    772780        $before_title = stripslashes(trim($_POST['cs_before_title']));
    773781        $after_title = stripslashes(trim($_POST['cs_after_title']));
    774        
     782
    775783        $sidebars = $this->getCustomSidebars();
    776        
    777         //Check the id     
     784
     785        //Check the id
    778786        $url = parse_url($_POST['_wp_http_referer']);
    779787        if(! DOING_AJAX){
     
    786794                            return new WP_Error(__('The operation is not secure and it cannot be completed.','custom-sidebars'));
    787795                }
    788        
     796
    789797        $newsidebars = array();
    790798        foreach($sidebars as $sb){
     
    802810                        ) ;
    803811        }
    804        
     812
    805813        //update option
    806814        update_option( $this->option_name, $newsidebars );
    807815        $this->refreshSidebarsWidgets();
    808        
     816
    809817        $this->setMessage( sprintf(__('The sidebar "%s" has been updated successfully.','custom-sidebars'), $id ));
    810818    }
    811    
     819
    812820    function widgetSidebarContent(){
    813821        include 'views/widgets.php';
    814822        }
    815    
     823
    816824    function getSidebar($id, $sidebars){
    817825        $sidebar = false;
     
    825833        return $sidebar;
    826834    }
    827    
     835
    828836    function message($echo = TRUE){
    829837        $message = '';
    830838        if(!empty($this->message))
    831839            $message = '<div id="message" class="' . $this->message_class . '"><p><strong>' . $this->message . '</strong></p></div>';
    832        
     840
    833841        if($echo)
    834842            echo $message;
    835843        else
    836             return $message;       
    837     }
    838    
     844            return $message;
     845    }
     846
    839847    function setMessage($text){
    840848        $this->message = $text;
    841849        $this->message_class = 'updated';
    842850    }
    843    
     851
    844852    function setError($text){
    845853        $this->message = $text;
    846854        $this->message_class = 'error';
    847855    }
    848    
     856
    849857    function getPostTypes(){
    850858        $pt = get_post_types();
    851859        $ptok = array();
    852        
     860
    853861        foreach($pt as $t){
    854862            if(array_search($t, $this->ignore_post_types) === FALSE)
    855863                $ptok[] = $t;
    856864        }
    857        
    858         return $ptok; 
    859     }
    860    
     865
     866        return $ptok;
     867    }
     868
    861869    function getEmptyWidget(){
    862870        return array(
     
    869877        );
    870878    }
    871    
     879
    872880    function refreshSidebarsWidgets(){
    873881        $widgetized_sidebars = get_option('sidebars_widgets');
    874882        $delete_widgetized_sidebars = array();
    875883        $cs_sidebars = get_option($this->option_name);
    876        
     884
    877885        foreach($widgetized_sidebars as $id => $bar){
    878886            if(substr($id,0,3)=='cs-'){
     
    886894            }
    887895        }
    888        
    889        
     896
     897
    890898        foreach($cs_sidebars as $cs){
    891899            if(array_search($cs['id'], array_keys($widgetized_sidebars))===FALSE){
    892                 $widgetized_sidebars[$cs['id']] = array(); 
    893             }
    894         }
    895        
     900                $widgetized_sidebars[$cs['id']] = array();
     901            }
     902        }
     903
    896904        foreach($delete_widgetized_sidebars as $id){
    897905            unset($widgetized_sidebars[$id]);
    898906        }
    899        
     907
    900908        update_option('sidebars_widgets', $widgetized_sidebars);
    901        
    902     }
    903    
     909
     910    }
     911
    904912    function resetSidebars(){
    905913        if(! current_user_can($this->cap_required) )
    906914            return new WP_Error('cscantdelete', __('You do not have permission to delete sidebars','custom-sidebars'));
    907            
    908         if (! wp_verify_nonce($_REQUEST['reset-n'], 'custom-sidebars-delete') ) die('Security check stopped your request.'); 
    909        
     915
     916        if (! wp_verify_nonce($_REQUEST['reset-n'], 'custom-sidebars-delete') ) die('Security check stopped your request.');
     917
    910918        delete_option($this->option_modifiable);
    911919        delete_option($this->option_name);
    912        
    913         $widgetized_sidebars = get_option('sidebars_widgets'); 
    914         $delete_widgetized_sidebars = array(); 
     920
     921        $widgetized_sidebars = get_option('sidebars_widgets');
     922        $delete_widgetized_sidebars = array();
    915923        foreach($widgetized_sidebars as $id => $bar){
    916924            if(substr($id,0,3)=='cs-'){
     
    928936            }
    929937        }
    930        
     938
    931939        foreach($delete_widgetized_sidebars as $id){
    932940            unset($widgetized_sidebars[$id]);
    933941        }
    934        
     942
    935943        update_option('sidebars_widgets', $widgetized_sidebars);
    936        
    937         $this->setMessage( __('The Custom Sidebars data has been removed successfully,','custom-sidebars'));   
    938     }
    939    
     944
     945        $this->setMessage( __('The Custom Sidebars data has been removed successfully,','custom-sidebars'));
     946    }
     947
    940948    function getSortedCategories(){
    941949        $unorderedcats = get_the_category();
     
    943951        return $unorderedcats;
    944952    }
    945    
     953
    946954    function cmpCatLevel($cat1, $cat2){
    947955        $l1 = $this->getCategoryLevel($cat1->cat_ID);
     
    949957        if($l1 == $l2)
    950958            return strcasecmp($cat1->name, $cat1->name);
    951         else 
     959        else
    952960            return $l1 < $l2 ? 1 : -1;
    953961    }
    954    
     962
    955963    function getCategoryLevel($catid){
    956964        if($catid == 0)
    957965            return 0;
    958        
     966
    959967        $cat = &get_category($catid);
    960968        return 1 + $this->getCategoryLevel($cat->category_parent);
    961969    }
    962        
     970
    963971        function jsonResponse($obj){
    964972            header('Content-Type: application/json');
     
    966974            die();
    967975        }
    968        
     976
    969977        function ajaxHandler(){
    970978            if($_REQUEST['cs_action'] == 'where'){
     
    972980                die;
    973981            }
    974            
     982
    975983            $nonce = $_POST['nonce'];
    976984            $action = $_POST['cs_action'];
     
    983991                $this->jsonResponse( $response );
    984992            }
    985            
     993
    986994            $response = array();
    987995            if($action == 'cs-create-sidebar'){
     
    9971005                $response = $this->ajaxDeleteSidebar();
    9981006            }
    999            
    1000            
     1007
     1008
    10011009            $response['nonce'] = wp_create_nonce($action);
    10021010            $this->jsonResponse($response);
    10031011        }
    1004        
    1005        
     1012
     1013
    10061014        function ajaxSetDefaults(){
    10071015            try{
     
    10181026            );
    10191027        }
    1020        
     1028
    10211029        function ajaxCreateSidebar(){
    10221030            $this->storeSidebar();
    1023            
     1031
    10241032            if($this->message_class == 'error')
    10251033                return array(
     
    10271035                   'message' => $this->message
    10281036                );
    1029            
     1037
    10301038            return array(
    10311039                'success' => true,
     
    10361044            );
    10371045        }
    1038        
     1046
    10391047        function ajaxDeleteSidebar(){
    10401048            $this->deleteSidebar();
    1041            
    1042             return array( 
     1049
     1050            return array(
    10431051                'message' => $this->message,
    10441052                'success' => $this->message_class != 'error'
    10451053            );
    10461054        }
    1047        
     1055
    10481056        function ajaxEditSidebar(){
    10491057            $id = trim($_POST['cs_id']);
     
    10541062            $_POST['cs_after_title'] = $sidebar['cs_after_title'];
    10551063            $this->updateSidebar();
    1056            
     1064
    10571065            $sidebar = $this->getSidebar($id, $this->getCustomSidebars());
    10581066            return array(
     
    10631071            );
    10641072        }
    1065        
     1073
    10661074        function ajaxShowWhere(){
    10671075            $customsidebars = $this->getCustomSidebars();
     
    11011109
    11021110if(!isset($plugin_sidebars)){
    1103     $plugin_sidebars = new CustomSidebars();   
     1111    $plugin_sidebars = new CustomSidebars();
    11041112    add_action( 'widgets_init', array($plugin_sidebars,'registerCustomSidebars') );
    11051113    add_action( 'widgets_admin_page', array($plugin_sidebars,'widgetSidebarContent'));
    11061114    add_action( 'admin_menu', array($plugin_sidebars,'addSubMenus'));
    1107     add_action( 'wp_head', array($plugin_sidebars,'replaceSidebars'));
    11081115    add_action('add_meta_boxes',  array($plugin_sidebars,'addMetaBox'));
    11091116    add_action( 'save_post', array($plugin_sidebars,'storeReplacements'));
    11101117    add_action( 'init', array($plugin_sidebars,'loadTextDomain'));
    11111118    add_action( 'admin_enqueue_scripts', array($plugin_sidebars,'addStyles'));
     1119
     1120    //Frontend
     1121    add_action( 'wp_head', array($plugin_sidebars,'replaceSidebars'));
     1122    add_action( 'wp', array($plugin_sidebars, 'storeOriginalPostId'));
     1123
    11121124    //AJAX actions
    11131125    add_action( 'wp_ajax_cs-ajax', array($plugin_sidebars, 'ajaxHandler'));
    11141126
    11151127    add_filter('admin_body_class', array($plugin_sidebars, 'checkMP6'));
    1116        
     1128
    11171129}
    11181130if(! class_exists('CustomSidebarsEmptyPlugin')){
     
    11271139        //Nothing, just a dummy plugin to display nothing
    11281140    }
    1129     function widget($args, $instance) {     
     1141    function widget($args, $instance) {
    11301142        echo '';
    11311143    }
  • custom-sidebars/trunk/readme.txt

    r836632 r890021  
    1 === Plugin Name ===
     1=== Plugin Name ===
    22Contributors: WPMUDEV, marquex
    33Donate link: http://marquex.es/donate
    44Tags: custom sidebars, widgets, sidebars, custom, sidebar, widget, personalize
    55Requires at least: 3.3
    6 Tested up to: 3.6.1
     6Tested up to: 3.8.2
    77Stable tag: trunk
    88
     
    3131= Translations =
    3232
    33 Translations are welcome! I will write your name down here if you donate your translation work. Thanks very much to:
    34 
    35 *   English - marquex
    36 *   Spanish - marquex
     33Translations are welcome! We will write your name down here if you donate your translation work. Thanks very much to:
     34
     35*   English - Javi Marquez (http://arqex.com)
     36*   Spanish - Javi Marquez (http://arqex.com)
    3737*   German - [Markus Vocke, Professionelles Webdesign](http://www.web-funk.de)
    3838*   Dutch - Herman Boswijk
     
    109109
    110110== Changelog ==
     111= 1.5 =
     112*       Added: Custom sidebars now works with buddypress pages.
    111113
    112114= 1.4 =
Note: See TracChangeset for help on using the changeset viewer.