Changeset 890021
- Timestamp:
- 04/09/2014 11:21:21 AM (12 years ago)
- Location:
- custom-sidebars/trunk
- Files:
-
- 2 edited
-
customsidebars.php (modified) (71 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-sidebars/trunk/customsidebars.php
r836632 r890021 4 4 Plugin URI: http://wordpress.org/plugins/custom-sidebars/ 5 5 Description: Allows to create your own widgetized areas and custom sidebars, and select what sidebars to use for each post or page. 6 Version: 1. 46 Version: 1.5 7 7 Author: WPMUDEV 8 8 Author URI: http://premium.wpmudev.org/ … … 11 11 12 12 /* 13 This plugin was originally developed by Javier Marquez. 14 http:// marquex.es/13 This plugin was originally developed by Javier Marquez. 14 http://arqex.com/ 15 15 */ 16 16 … … 18 18 19 19 class CustomSidebars{ 20 20 21 21 var $message = ''; 22 22 var $message_class = ''; 23 23 24 24 //The name of the option that stores the info of the new bars. 25 25 var $option_name = "cs_sidebars"; … … 27 27 //replacements. The value is stored in $this->options 28 28 var $option_modifiable = "cs_modifiable"; 29 30 29 30 31 31 var $sidebar_prefix = 'cs-'; 32 32 var $postmeta_key = '_cs_replacements'; … … 34 34 var $ignore_post_types = array('attachment', 'revision', 'nav_menu_item', 'pt-widget'); 35 35 var $options = array(); 36 36 37 37 var $replaceable_sidebars = array(); 38 38 var $replacements = array(); 39 39 var $replacements_todo; 40 40 41 41 function CustomSidebars(){ 42 42 $this->retrieveOptions(); … … 46 46 $this->replacements[$sb] = FALSE; 47 47 } 48 48 49 49 function retrieveOptions(){ 50 50 $this->options = get_option($this->option_modifiable); 51 51 } 52 52 53 53 function getCustomSidebars(){ 54 54 $sidebars = get_option($this->option_name); … … 57 57 return array(); 58 58 } 59 59 60 60 function getThemeSidebars($include_custom_sidebars = FALSE){ 61 62 global $wp_registered_sidebars; 61 62 global $wp_registered_sidebars; 63 63 $allsidebars = $wp_registered_sidebars; 64 64 ksort($allsidebars); 65 65 if($include_custom_sidebars) 66 66 return $allsidebars; 67 67 68 68 $themesidebars = array(); 69 69 foreach($allsidebars as $key => $sb){ … … 71 71 $themesidebars[$key] = $sb; 72 72 } 73 73 74 74 return $themesidebars; 75 75 } 76 76 77 77 function registerCustomSidebars(){ 78 78 $sb = $this->getCustomSidebars(); … … 83 83 } 84 84 } 85 85 86 86 function replaceSidebars(){ 87 87 global $_wp_sidebars_widgets, $post, $wp_registered_sidebars, $wp_registered_widgets; 88 88 89 89 $original_widgets = $_wp_sidebars_widgets; 90 90 91 91 $updated = FALSE; 92 92 93 93 $replaceables = $this->replaceable_sidebars; 94 94 $defaults = $this->getDefaultReplacements(); 95 95 96 96 do_action('cs_predetermineReplacements'); 97 97 98 98 $this->determineReplacements($defaults); 99 99 100 100 foreach($this->replacements as $sb_name => $replacement_info){ 101 101 if($replacement_info){ … … 135 135 global $post; 136 136 137 $replacements = get_post_meta($ post->ID, $this->postmeta_key, TRUE);137 $replacements = get_post_meta($this->originalPostId, $this->postmeta_key, TRUE); 138 138 foreach($this->replaceable_sidebars as $sidebar){ 139 139 if(is_array($replacements) && !empty($replacements[$sidebar])){ … … 160 160 foreach($this->replaceable_sidebars as $sidebar){ 161 161 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', 164 164 $sidebar_category); 165 165 $this->replacements_todo--; … … 195 195 if($current_category != 0) 196 196 $category_object = get_category($current_category); 197 } 197 } 198 198 return; 199 199 } 200 200 201 201 //Search comes before because searches with no results are recognized as post types archives 202 202 if(is_search()){ … … 207 207 return; 208 208 } 209 209 210 210 //post type archive 211 211 if(!is_category() && !is_singular() && get_post_type()!='post'){ … … 222 222 if(is_page()){ 223 223 global $post; 224 $replacements = get_post_meta($ post->ID, $this->postmeta_key, TRUE);224 $replacements = get_post_meta($this->originalPostId, $this->postmeta_key, TRUE); 225 225 foreach($this->replaceable_sidebars as $sidebar){ 226 226 if(is_array($replacements) && !empty($replacements[$sidebar])){ … … 229 229 } 230 230 } 231 231 232 232 //Parent sidebar 233 233 if($post->post_parent != 0 && $this->replacements_todo > 0){ … … 240 240 } 241 241 } 242 242 243 243 //Page Post-type sidebar 244 244 if($this->replacements_todo > 0){ … … 252 252 return; 253 253 } 254 254 255 255 if(is_home()){ 256 256 foreach($this->replaceable_sidebars as $sidebar){ … … 260 260 return; 261 261 } 262 262 263 263 if(is_tag()){ 264 264 foreach($this->replaceable_sidebars as $sidebar){ … … 268 268 return; 269 269 } 270 270 271 271 if(is_author()){ 272 272 foreach($this->replaceable_sidebars as $sidebar){ … … 276 276 return; 277 277 } 278 279 278 279 280 280 if(is_date()){ 281 281 foreach($this->replaceable_sidebars as $sidebar){ … … 286 286 } 287 287 } 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 289 297 function checkAndFixSidebar($sidebar, $replacement, $method, $extra_index){ 290 298 global $wp_registered_sidebars; 291 292 299 300 293 301 if(isset($wp_registered_sidebars[$replacement])) 294 302 return true; 295 303 296 304 if($method == 'particular'){ 297 305 global $post; … … 299 307 if($sidebars && isset($sidebars[$sidebar])){ 300 308 unset($sidebars[$sidebar]); 301 update_post_meta($post->ID, $this->postmeta_key, $sidebars); 309 update_post_meta($post->ID, $this->postmeta_key, $sidebars); 302 310 } 303 311 } … … 310 318 if($extra_index == 1 && isset($this->options[$method]) && isset($this->options[$method][$sidebar])){ 311 319 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 317 325 return false; 318 326 } 319 327 320 328 function replace_before_after_widget($sidebar){ 321 329 return (trim($sidebar['before_widget']) != '' OR … … 324 332 trim($sidebar['after_title']) != ''); 325 333 } 326 334 327 335 function deleteSidebar(){ 328 336 if(! current_user_can($this->cap_required) ) 329 337 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 334 342 $newsidebars = array(); 335 343 $deleted = FALSE; 336 344 337 345 $custom = $this->getCustomSidebars(); 338 346 339 347 if(!empty($custom)){ 340 348 341 349 foreach($custom as $sb){ 342 350 if($sb['id']!=$_REQUEST['delete']) … … 346 354 } 347 355 }//endif custom 348 356 349 357 //update option 350 358 update_option( $this->option_name, $newsidebars ); 351 359 352 360 $this->refreshSidebarsWidgets(); 353 361 354 362 if($deleted) 355 363 $this->setMessage(sprintf(__('The sidebar "%s" has been deleted.','custom-sidebars'), $_REQUEST['delete'])); … … 357 365 $this->setError(sprintf(__('There was not any sidebar called "%s" and it could not been deleted.','custom-sidebars'), $_GET['delete'])); 358 366 } 359 367 360 368 function createPage(){ 361 369 362 370 //$this->refreshSidebarsWidgets(); 363 371 if(!empty($_POST)){ … … 369 377 check_admin_referer('custom-sidebars-update'); 370 378 $this->updateSidebar(); 371 } 379 } 372 380 else if(isset($_POST['update-modifiable'])){ 373 381 $this->updateModifiable(); … … 377 385 else if(isset($_POST['update-defaults-posts']) OR isset($_POST['update-defaults-pages'])){ 378 386 $this->storeDefaults(); 379 380 } 381 387 388 } 389 382 390 else if(isset($_POST['reset-sidebars'])) 383 $this->resetSidebars(); 384 391 $this->resetSidebars(); 392 385 393 $this->retrieveOptions(); 386 394 } 387 395 else if(!empty($_GET['delete'])){ 388 396 $this->deleteSidebar(); 389 $this->retrieveOptions(); 397 $this->retrieveOptions(); 390 398 } 391 399 else if(!empty($_GET['p'])){ … … 395 403 return new WP_Error('cscantdelete', __('You do not have permission to delete sidebars','custom-sidebars')); 396 404 include('views/edit.php'); 397 return; 398 } 399 } 400 405 return; 406 } 407 } 408 401 409 $customsidebars = $this->getCustomSidebars(); 402 410 $themesidebars = $this->getThemeSidebars(); … … 405 413 $modifiable = $this->replaceable_sidebars; 406 414 $post_types = $this->getPostTypes(); 407 415 408 416 $deletenonce = wp_create_nonce('custom-sidebars-delete'); 409 417 410 418 //var_dump($defaults); 411 419 412 420 //Form 413 421 if(!empty($_GET['p'])){ … … 416 424 if(sizeof($categories)==1 && $categories[0]->cat_ID == 1) 417 425 unset($categories[0]); 418 426 419 427 include('views/defaults.php'); 420 428 } … … 422 430 include('views/edit.php'); 423 431 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 431 439 function addSubMenus(){ 432 440 $page = add_submenu_page('themes.php', __('Custom sidebars','custom-sidebars'), __('Custom sidebars','custom-sidebars'), $this->cap_required, 'customsidebars', array($this, 'createPage')); 433 441 434 442 add_action('admin_print_scripts-' . $page, array($this, 'addScripts')); 435 443 } 436 444 437 445 function addScripts(){ 438 446 wp_enqueue_script('post'); 439 447 } 440 448 441 449 function addStyles($hook){ 442 450 $dir = basename(dirname(__FILE__)); … … 446 454 wp_enqueue_style('thickbox.css', includes_url() . 'js/thickbox/thickbox.css', null, '1.0'); 447 455 } 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 451 459 function addMetaBox(){ 452 460 global $post; … … 454 462 if($post_type && !(array_search($post_type, $this->ignore_post_types))){ 455 463 $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) 457 465 add_meta_box('customsidebars-mb', 'Sidebars', array($this,'printMetabox'), $post_type, 'side'); 458 466 } 459 467 } 460 468 461 469 function printMetabox(){ 462 470 global $post, $wp_registered_sidebars; 463 471 464 472 $replacements = $this->getReplacements($post->ID); 465 473 466 474 //$available = array_merge(array(''), $this->getThemeSidebars(TRUE)); 467 475 $available = $wp_registered_sidebars; … … 477 485 } 478 486 } 479 487 480 488 include('metabox.php'); 481 489 } 482 490 483 491 function loadTextDomain(){ 484 492 load_plugin_textdomain( 'custom-sidebars', false, dirname(plugin_basename( __FILE__ )) . "/lang/"); 485 493 } 486 494 487 495 function getReplacements($postid){ 488 496 $replacements = get_post_meta($postid, $this->postmeta_key, TRUE); … … 493 501 return $replacements; 494 502 } 495 503 496 504 function getModifiableSidebars(){ 497 505 if( $modifiable = $this->options ) //get_option($this->option_modifiable) ) 498 506 return $modifiable['modifiable']; 499 return array(); 500 } 501 507 return array(); 508 } 509 502 510 function getDefaultReplacements(){ 503 511 if( $defaults = $this->options ){//get_option($this->option_modifiable) ) … … 507 515 return $defaults; 508 516 } 509 return array(); 510 } 511 517 return array(); 518 } 519 512 520 function updateModifiable(){ 513 521 check_admin_referer('custom-sidebars-options', 'options_wpnonce'); 514 522 $options = $this->options ? $this->options : array(); 515 523 516 524 //Modifiable bars 517 525 if(isset($_POST['modifiable']) && is_array($_POST['modifiable'])) 518 526 $options['modifiable'] = $_POST['modifiable']; 519 527 520 528 521 529 if($this->options !== FALSE) 522 530 update_option($this->option_modifiable, $options); 523 531 else 524 532 add_option($this->option_modifiable, $options); 525 533 526 534 $this->setMessage(__('The custom sidebars settings has been updated successfully.','custom-sidebars')); 527 535 } 528 536 529 537 function storeDefaults(){ 530 538 531 539 $options = $this->options; 532 540 $modifiable = $this->replaceable_sidebars; 533 541 534 542 //Post-types posts and lists. Posts data are called default in order to keep backwards compatibility; 535 543 536 544 $options['defaults'] = array(); 537 545 $options['post_type_pages'] = array(); 538 546 539 547 foreach($this->getPostTypes() as $pt){ 540 548 if(!empty($modifiable)){ … … 543 551 if(! isset($options['defaults'][$pt])) 544 552 $options['defaults'][$pt] = array(); 545 553 546 554 $options['defaults'][$pt][$m] = $_POST["type_posts_{$pt}_$m"]; 547 555 } 548 556 549 557 if(isset($_POST["type_page_{$pt}_$m"]) && $_POST["type_page_{$pt}_$m"]!=''){ 550 558 if(! isset($options['post_type_pages'][$pt])) 551 559 $options['post_type_pages'][$pt] = array(); 552 560 553 561 $options['post_type_pages'][$pt][$m] = $_POST["type_page_{$pt}_$m"]; 554 562 } … … 556 564 } 557 565 } 558 559 566 567 560 568 //Category posts and post lists. 561 569 562 570 $options['category_posts'] = array(); 563 571 $options['category_pages'] = array(); … … 570 578 if(! isset($options['category_posts'][$catid])) 571 579 $options['category_posts'][$catid] = array(); 572 580 573 581 $options['category_posts'][$catid][$m] = $_POST["category_posts_{$catid}_$m"]; 574 582 } 575 583 576 584 if(isset($_POST["category_page_{$catid}_$m"]) && $_POST["category_page_{$catid}_$m"]!=''){ 577 585 if(! isset($options['category_pages'][$catid])) 578 586 $options['category_pages'][$catid] = array(); 579 587 580 588 $options['category_pages'][$catid][$m] = $_POST["category_page_{$catid}_$m"]; 581 589 } … … 583 591 } 584 592 } 585 593 586 594 // Blog page 587 595 588 596 $options['blog'] = array(); 589 597 if(!empty($modifiable)){ … … 592 600 if(! isset($options['blog'])) 593 601 $options['blog'] = array(); 594 602 595 603 $options['blog'][$m] = $_POST["blog_page_$m"]; 596 604 } 597 605 } 598 606 } 599 607 600 608 // Tag page 601 609 602 610 $options['tags'] = array(); 603 611 if(!empty($modifiable)){ … … 606 614 if(! isset($options['tags'])) 607 615 $options['tags'] = array(); 608 616 609 617 $options['tags'][$m] = $_POST["tag_page_$m"]; 610 618 } 611 619 } 612 620 } 613 621 614 622 // Author page 615 623 616 624 $options['authors'] = array(); 617 625 if(!empty($modifiable)){ … … 620 628 if(! isset($options['authors'])) 621 629 $options['authors'] = array(); 622 630 623 631 $options['authors'][$m] = $_POST["authors_page_$m"]; 624 632 } 625 633 } 626 634 } 627 635 628 636 // Search page 629 637 $options['search'] = array(); … … 633 641 if(! isset($options['search'])) 634 642 $options['search'] = array(); 635 643 636 644 $options['search'][$m] = $_POST["search_page_$m"]; 637 645 } 638 646 } 639 647 } 640 648 641 649 // Date archive 642 650 $options['date'] = array(); … … 646 654 if(! isset($options['date'])) 647 655 $options['date'] = array(); 648 656 649 657 $options['date'][$m] = $_POST["date_page_$m"]; 650 658 } 651 659 } 652 660 } 653 654 661 662 655 663 //Store defaults 656 664 if($this->options !== FALSE) … … 660 668 add_option($this->option_modifiable, $options); 661 669 } 662 670 663 671 $this->setMessage(__('The default sidebars have been updated successfully.','custom-sidebars')); 664 665 } 666 672 673 } 674 667 675 function storeReplacements( $post_id ){ 668 676 if(! current_user_can($this->cap_required)) … … 670 678 // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want 671 679 // 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 ) 673 681 return $post_id; 674 682 675 683 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, 678 686 //no sidebars data is recieved and the sidebars would be deleted. 679 687 if($action != 'editpost') 680 688 return $post_id; 681 689 682 690 // make sure meta is added to the post, not a revision 683 691 if ( $the_post = wp_is_post_revision($post_id) ) 684 692 $post_id = $the_post; 685 693 686 694 $sidebars = $this->replaceable_sidebars; 687 695 $data = array(); … … 707 715 } 708 716 } 709 717 710 718 function storeSidebar(){ 711 719 $name = stripslashes(trim($_POST['sidebar_name'])); … … 729 737 'after_title' => '', 730 738 ) ; 731 732 739 740 733 741 //update option 734 742 update_option( $this->option_name, $sidebars ); 735 743 736 744 $this->refreshSidebarsWidgets(); 737 745 738 746 $this->setMessage( __('The sidebar has been created successfully.','custom-sidebars')); 739 740 747 748 741 749 } 742 750 else … … 755 763 ) ); 756 764 add_option($this->option_name, $sidebars); 757 758 765 766 759 767 $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 766 774 function updateSidebar(){ 767 775 $id = stripslashes(trim($_POST['cs_id'])); … … 772 780 $before_title = stripslashes(trim($_POST['cs_before_title'])); 773 781 $after_title = stripslashes(trim($_POST['cs_after_title'])); 774 782 775 783 $sidebars = $this->getCustomSidebars(); 776 777 //Check the id 784 785 //Check the id 778 786 $url = parse_url($_POST['_wp_http_referer']); 779 787 if(! DOING_AJAX){ … … 786 794 return new WP_Error(__('The operation is not secure and it cannot be completed.','custom-sidebars')); 787 795 } 788 796 789 797 $newsidebars = array(); 790 798 foreach($sidebars as $sb){ … … 802 810 ) ; 803 811 } 804 812 805 813 //update option 806 814 update_option( $this->option_name, $newsidebars ); 807 815 $this->refreshSidebarsWidgets(); 808 816 809 817 $this->setMessage( sprintf(__('The sidebar "%s" has been updated successfully.','custom-sidebars'), $id )); 810 818 } 811 819 812 820 function widgetSidebarContent(){ 813 821 include 'views/widgets.php'; 814 822 } 815 823 816 824 function getSidebar($id, $sidebars){ 817 825 $sidebar = false; … … 825 833 return $sidebar; 826 834 } 827 835 828 836 function message($echo = TRUE){ 829 837 $message = ''; 830 838 if(!empty($this->message)) 831 839 $message = '<div id="message" class="' . $this->message_class . '"><p><strong>' . $this->message . '</strong></p></div>'; 832 840 833 841 if($echo) 834 842 echo $message; 835 843 else 836 return $message; 837 } 838 844 return $message; 845 } 846 839 847 function setMessage($text){ 840 848 $this->message = $text; 841 849 $this->message_class = 'updated'; 842 850 } 843 851 844 852 function setError($text){ 845 853 $this->message = $text; 846 854 $this->message_class = 'error'; 847 855 } 848 856 849 857 function getPostTypes(){ 850 858 $pt = get_post_types(); 851 859 $ptok = array(); 852 860 853 861 foreach($pt as $t){ 854 862 if(array_search($t, $this->ignore_post_types) === FALSE) 855 863 $ptok[] = $t; 856 864 } 857 858 return $ptok; 859 } 860 865 866 return $ptok; 867 } 868 861 869 function getEmptyWidget(){ 862 870 return array( … … 869 877 ); 870 878 } 871 879 872 880 function refreshSidebarsWidgets(){ 873 881 $widgetized_sidebars = get_option('sidebars_widgets'); 874 882 $delete_widgetized_sidebars = array(); 875 883 $cs_sidebars = get_option($this->option_name); 876 884 877 885 foreach($widgetized_sidebars as $id => $bar){ 878 886 if(substr($id,0,3)=='cs-'){ … … 886 894 } 887 895 } 888 889 896 897 890 898 foreach($cs_sidebars as $cs){ 891 899 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 896 904 foreach($delete_widgetized_sidebars as $id){ 897 905 unset($widgetized_sidebars[$id]); 898 906 } 899 907 900 908 update_option('sidebars_widgets', $widgetized_sidebars); 901 902 } 903 909 910 } 911 904 912 function resetSidebars(){ 905 913 if(! current_user_can($this->cap_required) ) 906 914 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 910 918 delete_option($this->option_modifiable); 911 919 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(); 915 923 foreach($widgetized_sidebars as $id => $bar){ 916 924 if(substr($id,0,3)=='cs-'){ … … 928 936 } 929 937 } 930 938 931 939 foreach($delete_widgetized_sidebars as $id){ 932 940 unset($widgetized_sidebars[$id]); 933 941 } 934 942 935 943 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 940 948 function getSortedCategories(){ 941 949 $unorderedcats = get_the_category(); … … 943 951 return $unorderedcats; 944 952 } 945 953 946 954 function cmpCatLevel($cat1, $cat2){ 947 955 $l1 = $this->getCategoryLevel($cat1->cat_ID); … … 949 957 if($l1 == $l2) 950 958 return strcasecmp($cat1->name, $cat1->name); 951 else 959 else 952 960 return $l1 < $l2 ? 1 : -1; 953 961 } 954 962 955 963 function getCategoryLevel($catid){ 956 964 if($catid == 0) 957 965 return 0; 958 966 959 967 $cat = &get_category($catid); 960 968 return 1 + $this->getCategoryLevel($cat->category_parent); 961 969 } 962 970 963 971 function jsonResponse($obj){ 964 972 header('Content-Type: application/json'); … … 966 974 die(); 967 975 } 968 976 969 977 function ajaxHandler(){ 970 978 if($_REQUEST['cs_action'] == 'where'){ … … 972 980 die; 973 981 } 974 982 975 983 $nonce = $_POST['nonce']; 976 984 $action = $_POST['cs_action']; … … 983 991 $this->jsonResponse( $response ); 984 992 } 985 993 986 994 $response = array(); 987 995 if($action == 'cs-create-sidebar'){ … … 997 1005 $response = $this->ajaxDeleteSidebar(); 998 1006 } 999 1000 1007 1008 1001 1009 $response['nonce'] = wp_create_nonce($action); 1002 1010 $this->jsonResponse($response); 1003 1011 } 1004 1005 1012 1013 1006 1014 function ajaxSetDefaults(){ 1007 1015 try{ … … 1018 1026 ); 1019 1027 } 1020 1028 1021 1029 function ajaxCreateSidebar(){ 1022 1030 $this->storeSidebar(); 1023 1031 1024 1032 if($this->message_class == 'error') 1025 1033 return array( … … 1027 1035 'message' => $this->message 1028 1036 ); 1029 1037 1030 1038 return array( 1031 1039 'success' => true, … … 1036 1044 ); 1037 1045 } 1038 1046 1039 1047 function ajaxDeleteSidebar(){ 1040 1048 $this->deleteSidebar(); 1041 1042 return array( 1049 1050 return array( 1043 1051 'message' => $this->message, 1044 1052 'success' => $this->message_class != 'error' 1045 1053 ); 1046 1054 } 1047 1055 1048 1056 function ajaxEditSidebar(){ 1049 1057 $id = trim($_POST['cs_id']); … … 1054 1062 $_POST['cs_after_title'] = $sidebar['cs_after_title']; 1055 1063 $this->updateSidebar(); 1056 1064 1057 1065 $sidebar = $this->getSidebar($id, $this->getCustomSidebars()); 1058 1066 return array( … … 1063 1071 ); 1064 1072 } 1065 1073 1066 1074 function ajaxShowWhere(){ 1067 1075 $customsidebars = $this->getCustomSidebars(); … … 1101 1109 1102 1110 if(!isset($plugin_sidebars)){ 1103 $plugin_sidebars = new CustomSidebars(); 1111 $plugin_sidebars = new CustomSidebars(); 1104 1112 add_action( 'widgets_init', array($plugin_sidebars,'registerCustomSidebars') ); 1105 1113 add_action( 'widgets_admin_page', array($plugin_sidebars,'widgetSidebarContent')); 1106 1114 add_action( 'admin_menu', array($plugin_sidebars,'addSubMenus')); 1107 add_action( 'wp_head', array($plugin_sidebars,'replaceSidebars'));1108 1115 add_action('add_meta_boxes', array($plugin_sidebars,'addMetaBox')); 1109 1116 add_action( 'save_post', array($plugin_sidebars,'storeReplacements')); 1110 1117 add_action( 'init', array($plugin_sidebars,'loadTextDomain')); 1111 1118 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 1112 1124 //AJAX actions 1113 1125 add_action( 'wp_ajax_cs-ajax', array($plugin_sidebars, 'ajaxHandler')); 1114 1126 1115 1127 add_filter('admin_body_class', array($plugin_sidebars, 'checkMP6')); 1116 1128 1117 1129 } 1118 1130 if(! class_exists('CustomSidebarsEmptyPlugin')){ … … 1127 1139 //Nothing, just a dummy plugin to display nothing 1128 1140 } 1129 function widget($args, $instance) { 1141 function widget($args, $instance) { 1130 1142 echo ''; 1131 1143 } -
custom-sidebars/trunk/readme.txt
r836632 r890021 1 === Plugin Name ===1 === Plugin Name === 2 2 Contributors: WPMUDEV, marquex 3 3 Donate link: http://marquex.es/donate 4 4 Tags: custom sidebars, widgets, sidebars, custom, sidebar, widget, personalize 5 5 Requires at least: 3.3 6 Tested up to: 3. 6.16 Tested up to: 3.8.2 7 7 Stable tag: trunk 8 8 … … 31 31 = Translations = 32 32 33 Translations are welcome! Iwill write your name down here if you donate your translation work. Thanks very much to:34 35 * English - marquex36 * Spanish - marquex33 Translations 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) 37 37 * German - [Markus Vocke, Professionelles Webdesign](http://www.web-funk.de) 38 38 * Dutch - Herman Boswijk … … 109 109 110 110 == Changelog == 111 = 1.5 = 112 * Added: Custom sidebars now works with buddypress pages. 111 113 112 114 = 1.4 =
Note: See TracChangeset
for help on using the changeset viewer.