Ticket #7661: 7661.r8934.diff
| File 7661.r8934.diff, 20.0 KB (added by , 17 years ago) |
|---|
-
widgets.php
1 1 <?php 2 /** 3 * API for creating dynamic sidebar without hardcoding functionality into 4 * themes. Includes both internal WordPress routines and theme use routines. 5 * 6 * This functionality was found in a plugin before WordPress 2.2 release which 7 * included it in the core from that point on. 8 * 9 * @link http://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets 10 * @link http://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API 11 * 12 * @package WordPress 13 * @subpackage Widgets 14 */ 2 15 3 16 /* Global Variables */ 4 17 18 /** @ignore */ 5 19 global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls; 6 20 21 /** 22 * Stores the sidebars, since many themes can have more than one. 23 * 24 * @global array $wp_registered_sidebars 25 * @since 2.2.0 26 */ 7 27 $wp_registered_sidebars = array(); 28 29 /** 30 * Stores the registered widgets. 31 * 32 * @global array $wp_registered_widgets 33 * @since 2.2.0 34 */ 8 35 $wp_registered_widgets = array(); 36 37 /** 38 * 39 * @global array $wp_registered_widget_controls 40 * @since 2.2.0 41 */ 9 42 $wp_registered_widget_controls = array(); 10 43 11 44 /* Template tags & API functions */ 12 45 46 /** 47 * Creates multiple sidebars. 48 * 49 * If you wanted to quickly create multiple sidebars for a theme or internally. 50 * This function will allow you to do so. If you don't pass the 'name' and/or 51 * 'id' in $args, then they will be built for you. 52 * 53 * The default for the name is "Sidebar #", with '#' being replaced with the 54 * number the sidebar is currently when greater than one. If first sidebar, the 55 * name will be just "Sidebar". The default for id is "sidebar-" followed by the 56 * number the sidebar creation is currently at. 57 * 58 * @since 2.2.0 59 * 60 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here. 61 * @uses parse_str() Converts a string to an array to be used in the rest of the function. 62 * @uses register_sidebar() Sends single sidebar information [name, id] to this 63 * function to handle building the sidebar. 64 * 65 * @param int $number Number of sidebars to create. 66 * @param string|array $args Builds Sidebar based off of 'name' and 'id' values. 67 */ 13 68 function register_sidebars($number = 1, $args = array()) { 14 69 global $wp_registered_sidebars; 15 70 $number = (int) $number; … … 40 95 } 41 96 } 42 97 98 /** 99 * Builds the definition for a single sidebar and returns the ID. 100 * 101 * The $args parameter takes either a string or an array with 'name' and 'id' 102 * contained in either usage. It will be noted that the values will be applied 103 * to all sidebars, so if creating more than one, it will be advised to allow 104 * for WordPress to create the defaults for you. 105 * 106 * Example for string would be <code>'name=whatever;id=whatever1'</code> and for 107 * the array it would be <code>array( 108 * 'name' => 'whatever', 109 * 'id' => 'whatever1')</code>. 110 * 111 * name - The name of the sidebar, which presumably the title which will be 112 * displayed. 113 * id - The unique identifier by which the sidebar will be called by. 114 * before_widget - The content that will prepended to the widgets when they are 115 * displayed. 116 * after_widget - The content that will be appended to the widgets when they are 117 * displayed. 118 * before_title - The content that will be prepended to the title when displayed. 119 * after_title - the content that will be appended to the title when displayed. 120 * 121 * <em>Content</em> is assumed to be HTML and should be formatted as such, but 122 * doesn't have to be. 123 * 124 * @since 2.2.0 125 * @uses $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID. 126 * @uses parse_str() Converts a string to an array to be used in the rest of the function. 127 * @usedby register_sidebars() 128 * 129 * @param string|array $args Builds Sidebar based off of 'name' and 'id' values 130 * @return string The sidebar id that was added. 131 */ 43 132 function register_sidebar($args = array()) { 44 133 global $wp_registered_sidebars; 45 134 … … 64 153 return $sidebar['id']; 65 154 } 66 155 156 /** 157 * Removes a sidebar from the list. 158 * 159 * @since 2.2.0 160 * 161 * @uses $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID. 162 * 163 * @param string $name The ID of the sidebar when it was added. 164 */ 67 165 function unregister_sidebar( $name ) { 68 166 global $wp_registered_sidebars; 69 167 … … 71 169 unset( $wp_registered_sidebars[$name] ); 72 170 } 73 171 172 /** 173 * {@internal Missing Short Description}} 174 * 175 * {@internal Missing Long Description}} 176 * 177 * @since 2.2.0 178 * @uses wp_register_sidebar_widget() Passes the compiled arguments. 179 * 180 * @param string $name 181 * @param callback $output_callback 182 * @param string $classname 183 */ 74 184 function register_sidebar_widget($name, $output_callback, $classname = '') { 75 185 // Compat 76 186 if ( is_array($name) ) { … … 92 202 call_user_func_array('wp_register_sidebar_widget', $args); 93 203 } 94 204 205 /** 206 * {@internal Missing Short Description}} 207 * 208 * {@internal Missing Long Description}} 209 * 210 * @since 2.2.0 211 * 212 * @uses $wp_registered_widgets {@internal Missing Description}} 213 * @uses $wp_register_widget_defaults {@internal Missing Description}} 214 * 215 * @param int $id {@internal Missing Description}} 216 * @param string $name {@internal Missing Description}} 217 * @param callback $output_callback {@internal Missing Description}} 218 * @param array|string $options {@internal Missing Description}} 219 * @return null Will return if $output_callback is empty 220 */ 95 221 function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) { 96 222 global $wp_registered_widgets; 97 223 … … 116 242 $wp_registered_widgets[$id] = $widget; 117 243 } 118 244 245 /** 246 * {@internal Missing Short Description}} 247 * 248 * {@internal Missing Long Description}} 249 * 250 * @since 2.5.0 251 * 252 * @param unknown_type $id 253 * @return unknown 254 */ 119 255 function wp_widget_description( $id ) { 120 256 if ( !is_scalar($id) ) 121 257 return; … … 126 262 return wp_specialchars( $wp_registered_widgets[$id]['description'] ); 127 263 } 128 264 265 /** 266 * Alias of {@link wp_unregister_sidebar_widget()}. 267 * 268 * @see wp_unregister_sidebar_widget() 269 * 270 * @since 2.2.0 271 * 272 * @param int $id Same as wp_unregister_sidebar_widget() 273 */ 129 274 function unregister_sidebar_widget($id) { 130 275 return wp_unregister_sidebar_widget($id); 131 276 } 132 277 278 /** 279 * {@internal Missing Short Description}} 280 * 281 * {@internal Missing Long Description}} 282 * 283 * @since 2.2.0 284 * 285 * @param int $id {@internal Missing Description}} 286 */ 133 287 function wp_unregister_sidebar_widget($id) { 134 288 wp_register_sidebar_widget($id, '', ''); 135 289 wp_unregister_widget_control($id); 136 290 } 137 291 292 /** 293 * {@internal Missing Short Description}} 294 * 295 * {@internal Missing Long Description}} 296 * 297 * @since 2.2.0 298 * 299 * @param unknown_type $name {@internal Missing Description}} 300 * @param unknown_type $control_callback {@internal Missing Description}} 301 * @param unknown_type $width {@internal Missing Description}} 302 * @param unknown_type $height {@internal Missing Description}} 303 */ 138 304 function register_widget_control($name, $control_callback, $width = '', $height = '') { 139 305 // Compat 140 306 if ( is_array($name) ) { … … 164 330 * id_base: for multi-widgets (widgets which allow multiple instances such as the text widget), an id_base must be provided. 165 331 * the widget id will ennd up looking like {$id_base}-{$unique_number} 166 332 */ 333 /** 334 * {@internal Missing Short Description}} 335 * 336 * {@internal Missing Long Description}} 337 * 338 * @since 2.2.0 339 * 340 * @param int $id {@internal Missing Description}} 341 * @param string $name {@internal Missing Description}} 342 * @param callback $control_callback {@internal Missing Description}} 343 * @param array|string $options {@internal Missing Description}} 344 */ 167 345 function wp_register_widget_control($id, $name, $control_callback, $options = array()) { 168 346 global $wp_registered_widget_controls; 169 347 … … 193 371 $wp_registered_widget_controls[$id] = $widget; 194 372 } 195 373 374 /** 375 * Alias of {@link wp_unregister_widget_control()}. 376 * 377 * @since 2.2.0 378 * @see wp_unregister_widget_control() 379 * 380 * @param int $id Widget ID 381 */ 196 382 function unregister_widget_control($id) { 197 383 return wp_unregister_widget_control($id); 198 384 } 199 385 386 /** 387 * {@internal Missing Short Description}} 388 * 389 * {@internal Missing Long Description}} 390 * 391 * @since 2.2.0 392 * @uses wp_register_widget_control() {@internal Missing Description}} 393 * 394 * @param int $id {@internal Missing Description}} 395 */ 200 396 function wp_unregister_widget_control($id) { 201 397 return wp_register_widget_control($id, '', ''); 202 398 } 203 399 400 /** 401 * {@internal Missing Short Description}} 402 * 403 * {@internal Missing Long Description}} 404 * 405 * @since 2.2.0 406 * 407 * @param unknown_type $index 408 * @return unknown 409 */ 204 410 function dynamic_sidebar($index = 1) { 205 411 global $wp_registered_sidebars, $wp_registered_widgets; 206 412 … … 254 460 return $did_one; 255 461 } 256 462 463 /** 464 * {@internal Missing Short Description}} 465 * 466 * {@internal Missing Long Description}} 467 * 468 * @since 2.2.0 469 * 470 * @param unknown_type $callback 257 471 /* @return mixed false if widget is not active or id of sidebar in which the widget is active 258 472 */ 259 473 function is_active_widget($callback, $widget_id = false) { … … 271 485 return false; 272 486 } 273 487 488 /** 489 * {@internal Missing Short Description}} 490 * 491 * {@internal Missing Long Description}} 492 * 493 * @since 2.2.0 494 * 495 * @return unknown 496 */ 274 497 function is_dynamic_sidebar() { 275 498 global $wp_registered_widgets, $wp_registered_sidebars; 276 499 $sidebars_widgets = get_option('sidebars_widgets'); … … 286 509 287 510 /* Internal Functions */ 288 511 512 /** 513 * {@internal Missing Short Description}} 514 * 515 * {@internal Missing Long Description}} 516 * 517 * @since 2.2.0 518 * @access private 519 * 520 * @param unknown_type $update 521 * @return unknown 522 */ 289 523 function wp_get_sidebars_widgets($update = true) { 290 524 global $wp_registered_widgets, $wp_registered_sidebars; 291 525 … … 364 598 return $sidebars_widgets; 365 599 } 366 600 601 /** 602 * {@internal Missing Short Description}} 603 * 604 * {@internal Missing Long Description}} 605 * 606 * @since 2.2.0 607 * @access private 608 * @uses update_option() 609 * 610 * @param unknown_type $sidebars_widgets 611 */ 367 612 function wp_set_sidebars_widgets( $sidebars_widgets ) { 368 613 update_option( 'sidebars_widgets', $sidebars_widgets ); 369 614 } 370 615 616 /** 617 * {@internal Missing Short Description}} 618 * 619 * {@internal Missing Long Description}} 620 * 621 * @since 2.2.0 622 * @access private 623 * 624 * @return unknown 625 */ 371 626 function wp_get_widget_defaults() { 372 627 global $wp_registered_sidebars; 373 628 … … 381 636 382 637 /* Default Widgets */ 383 638 639 /** 640 * {@internal Missing Short Description}} 641 * 642 * {@internal Missing Long Description}} 643 * 644 * @since 2.2.0 645 * 646 * @param array $args Widget arguments. 647 */ 384 648 function wp_widget_pages( $args ) { 385 649 extract( $args ); 386 650 $options = get_option( 'widget_pages' ); … … 407 671 } 408 672 } 409 673 674 /** 675 * {@internal Missing Short Description}} 676 * 677 * {@internal Missing Long Description}} 678 * 679 * @since 2.2.0 680 */ 410 681 function wp_widget_pages_control() { 411 682 $options = $newoptions = get_option('widget_pages'); 412 683 if ( $_POST['pages-submit'] ) { … … 448 719 <?php 449 720 } 450 721 722 /** 723 * {@internal Missing Short Description}} 724 * 725 * {@internal Missing Long Description}} 726 * 727 * @since 2.2.0 728 * 729 * @param array $args Widget arguments. 730 */ 451 731 function wp_widget_links($args) { 452 732 extract($args, EXTR_SKIP); 453 733 … … 459 739 ))); 460 740 } 461 741 742 /** 743 * {@internal Missing Short Description}} 744 * 745 * {@internal Missing Long Description}} 746 * 747 * @since 2.2.0 748 * 749 * @param array $args Widget arguments. 750 */ 462 751 function wp_widget_search($args) { 463 752 extract($args); 464 753 $searchform_template = get_template_directory() . '/searchform.php'; … … 479 768 echo $after_widget; 480 769 } 481 770 771 /** 772 * {@internal Missing Short Description}} 773 * 774 * {@internal Missing Long Description}} 775 * 776 * @since 2.2.0 777 * 778 * @param array $args Widget arguments. 779 */ 482 780 function wp_widget_archives($args) { 483 781 extract($args); 484 782 $options = get_option('widget_archives'); … … 504 802 echo $after_widget; 505 803 } 506 804 805 /** 806 * {@internal Missing Short Description}} 807 * 808 * {@internal Missing Long Description}} 809 * 810 * @since 2.2.0 811 */ 507 812 function wp_widget_archives_control() { 508 813 $options = $newoptions = get_option('widget_archives'); 509 814 if ( $_POST["archives-submit"] ) { … … 529 834 <?php 530 835 } 531 836 837 /** 838 * {@internal Missing Short Description}} 839 * 840 * {@internal Missing Long Description}} 841 * 842 * @since 2.2.0 843 * 844 * @param array $args Widget Arguments 845 */ 532 846 function wp_widget_meta($args) { 533 847 extract($args); 534 848 $options = get_option('widget_meta'); … … 547 861 <?php echo $after_widget; ?> 548 862 <?php 549 863 } 864 865 /** 866 * {@internal Missing Short Description}} 867 * 868 * {@internal Missing Long Description}} 869 * 870 * @since 2.2.0 871 */ 550 872 function wp_widget_meta_control() { 551 873 $options = $newoptions = get_option('widget_meta'); 552 874 if ( $_POST["meta-submit"] ) { … … 563 885 <?php 564 886 } 565 887 888 /** 889 * {@internal Missing Short Description}} 890 * 891 * {@internal Missing Long Description}} 892 * 893 * @since 2.2.0 894 * 895 * @param array $args Widget arguments. 896 */ 566 897 function wp_widget_calendar($args) { 567 898 extract($args); 568 899 $options = get_option('widget_calendar'); … … 576 907 echo $after_widget; 577 908 } 578 909 910 /** 911 * {@internal Missing Short Description}} 912 * 913 * {@internal Missing Long Description}} 914 * 915 * @since 2.2.0 916 */ 579 917 function wp_widget_calendar_control() { 580 918 $options = $newoptions = get_option('widget_calendar'); 581 919 if ( $_POST["calendar-submit"] ) { … … 592 930 <?php 593 931 } 594 932 595 // See large comment section at end of this file 933 /** 934 * Display the Text widget, depending on the widget number. 935 * 936 * Supports multiple text widgets and keeps track of the widget number by using 937 * the $widget_args parameter. The option 'widget_text' is used to store the 938 * content for the widgets. The content and title are passed through the 939 * 'widget_text' and 'widget_title' filters respectively. 940 * 941 * @since 2.2.0 942 * 943 * @param array $args Widget arguments. 944 * @param int $number Widget number. 945 */ 596 946 function wp_widget_text($args, $widget_args = 1) { 597 947 extract( $args, EXTR_SKIP ); 598 948 if ( is_numeric($widget_args) ) … … 614 964 <?php 615 965 } 616 966 967 /** 968 * {@internal Missing Short Description}} 969 * 970 * {@internal Missing Long Description}} 971 * 972 * @since 2.2.0 973 * 974 * @param int $widget_args Widget number. 975 */ 617 976 function wp_widget_text_control($widget_args) { 618 977 global $wp_registered_widgets; 619 978 static $updated = false; … … 676 1035 <?php 677 1036 } 678 1037 1038 /** 1039 * {@internal Missing Short Description}} 1040 * 1041 * {@internal Missing Long Description}} 1042 * 1043 * @since 2.2.0 1044 */ 679 1045 function wp_widget_text_register() { 680 1046 if ( !$options = get_option('widget_text') ) 681 1047 $options = array(); … … 700 1066 } 701 1067 } 702 1068 1069 /** 1070 * {@internal Missing Short Description}} 1071 * 1072 * {@internal Missing Long Description}} 1073 * 1074 * @since 2.2.0 1075 * 1076 * @param unknown_type $args 1077 * @param unknown_type $number 1078 */ 703 1079 // See large comment section at end of this file 704 1080 function wp_widget_categories($args, $widget_args = 1) { 705 1081 extract($args, EXTR_SKIP); … … 755 1131 echo $after_widget; 756 1132 } 757 1133 1134 /** 1135 * {@internal Missing Short Description}} 1136 * 1137 * {@internal Missing Long Description}} 1138 * 1139 * @since 2.2.0 1140 * 1141 * @param unknown_type $number 1142 */ 758 1143 function wp_widget_categories_control( $widget_args ) { 759 1144 global $wp_registered_widgets; 760 1145 static $updated = false; … … 841 1226 <?php 842 1227 } 843 1228 1229 /** 1230 * {@internal Missing Short Description}} 1231 * 1232 * {@internal Missing Long Description}} 1233 * 1234 * @since 2.3.0 1235 */ 844 1236 function wp_widget_categories_register() { 845 1237 if ( !$options = get_option( 'widget_categories' ) ) 846 1238 $options = array(); … … 869 1261 } 870 1262 } 871 1263 1264 /** 1265 * {@internal Missing Short Description}} 1266 * 1267 * {@internal Missing Long Description}} 1268 * 1269 * @since 2.3.0 1270 * 1271 * @return unknown 1272 */ 872 1273 function wp_widget_categories_upgrade() { 873 1274 $options = get_option( 'widget_categories' ); 874 1275 … … 896 1297 return $newoptions; 897 1298 } 898 1299 1300 /** 1301 * {@internal Missing Short Description}} 1302 * 1303 * {@internal Missing Long Description}} 1304 * 1305 * @since 2.2.0 1306 * 1307 * @param unknown_type $args 1308 * @return unknown 1309 */ 899 1310 function wp_widget_recent_entries($args) { 900 1311 if ( '%BEG_OF_TITLE%' != $args['before_title'] ) { 901 1312 if ( $output = wp_cache_get('widget_recent_entries', 'widget') ) … … 935 1346 /** 936 1347 * Remove recent entries widget items cache. 937 1348 * 938 * @since unknown 1349 * {@internal Missing Long Description}} 1350 * 1351 * @since 2.2.0 939 1352 */ 940 1353 function wp_flush_widget_recent_entries() { 941 1354 wp_cache_delete('widget_recent_entries', 'widget'); … … 945 1358 add_action('deleted_post', 'wp_flush_widget_recent_entries'); 946 1359 add_action('switch_theme', 'wp_flush_widget_recent_entries'); 947 1360 1361 /** 1362 * {@internal Missing Short Description}} 1363 * 1364 * {@internal Missing Long Description}} 1365 * 1366 * @since 2.2.0 1367 */ 948 1368 function wp_widget_recent_entries_control() { 949 1369 $options = $newoptions = get_option('widget_recent_entries'); 950 1370 if ( $_POST["recent-entries-submit"] ) { … … 971 1391 <?php 972 1392 } 973 1393 1394 /** 1395 * {@internal Missing Short Description}} 1396 * 1397 * {@internal Missing Long Description}} 1398 * 1399 * @since 2.2.0 1400 * 1401 * @param unknown_type $args 1402 */ 974 1403 function wp_widget_recent_comments($args) { 975 1404 global $wpdb, $comments, $comment; 976 1405 extract($args, EXTR_SKIP); … … 1002 1431 /** 1003 1432 * Remove the cache for recent comments widget. 1004 1433 * 1005 * @since unknown 1434 * {@internal Missing Long Description}} 1435 * 1436 * @since 2.2.0 1006 1437 */ 1007 1438 function wp_delete_recent_comments_cache() { 1008 1439 wp_cache_delete( 'recent_comments', 'widget' ); … … 1010 1441 add_action( 'comment_post', 'wp_delete_recent_comments_cache' ); 1011 1442 add_action( 'wp_set_comment_status', 'wp_delete_recent_comments_cache' ); 1012 1443 1444 /** 1445 * {@internal Missing Short Description}} 1446 * 1447 * {@internal Missing Long Description}} 1448 * 1449 * @since 2.2.0 1450 */ 1013 1451 function wp_widget_recent_comments_control() { 1014 1452 $options = $newoptions = get_option('widget_recent_comments'); 1015 1453 if ( $_POST["recent-comments-submit"] ) { … … 1038 1476 /** 1039 1477 * Display the style for recent comments widget. 1040 1478 * 1041 * @since unknown 1479 * {@internal Missing Long Description}} 1480 * 1481 * @since 2.2.0 1042 1482 */ 1043 1483 function wp_widget_recent_comments_style() { 1044 1484 ?> … … 1046 1486 <?php 1047 1487 } 1048 1488 1489 /** 1490 * {@internal Missing Short Description}} 1491 * 1492 * {@internal Missing Long Description}} 1493 * 1494 * @since 2.2.0 1495 */ 1049 1496 function wp_widget_recent_comments_register() { 1050 1497 $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) ); 1051 1498 wp_register_sidebar_widget('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments', $widget_ops); … … 1055 1502 add_action('wp_head', 'wp_widget_recent_comments_style'); 1056 1503 } 1057 1504 1505 /** 1506 * {@internal Missing Short Description}} 1507 * 1508 * {@internal Missing Long Description}} 1509 * 1510 * @since 2.2.0 1511 * 1512 * @param unknown_type $args 1513 * @param unknown_type $number 1514 */ 1058 1515 // See large comment section at end of this file 1059 1516 function wp_widget_rss($args, $widget_args = 1) { 1060 1517 extract($args, EXTR_SKIP); … … 1190 1647 } 1191 1648 } 1192 1649 1650 /** 1651 * wp_widget_rss_control() - {@internal Missing Short Description}} 1652 * 1653 * {@internal Missing Long Description}} 1654 * 1655 * @since 2.2.0 1656 * 1657 * @param unknown_type $widget_args 1658 */ 1193 1659 function wp_widget_rss_control($widget_args) { 1194 1660 global $wp_registered_widgets; 1195 1661 static $updated = false; … … 1384 1850 /** 1385 1851 * Register RSS widget to allow multiple RSS widgets. 1386 1852 * 1387 * @since unknown1853 * @since 2.2.0 1388 1854 */ 1389 1855 function wp_widget_rss_register() { 1390 1856 if ( !$options = get_option('widget_rss') ) … … 1411 1877 } 1412 1878 1413 1879 /** 1414 * Display tag cloud WordPresswidget.1880 * Display tag cloud widget. 1415 1881 * 1416 * @since unknown1882 * @since 2.3.0 1417 1883 * 1418 1884 * @param array $args Widget arguments. 1419 1885 */ … … 1433 1899 * 1434 1900 * Displays management form for changing the tag cloud widget title. 1435 1901 * 1436 * @since unknown1902 * @since 2.3.0 1437 1903 */ 1438 1904 function wp_widget_tag_cloud_control() { 1439 1905 $options = $newoptions = get_option('widget_tag_cloud'); … … 1462 1928 * Calls 'widgets_init' action after all of the WordPress widgets have been 1463 1929 * registered. 1464 1930 * 1465 * @since unknown1931 * @since 2.2.0 1466 1932 */ 1467 1933 function wp_widgets_init() { 1468 1934 if ( !is_blog_installed() )