Changeset 7457 for trunk/bp-core/bp-core-theme-compatibility.php
- Timestamp:
- 10/23/2013 12:14:44 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-theme-compatibility.php
r7432 r7457 2 2 3 3 /** 4 * BuddyPress Core Theme Compatibility 4 * BuddyPress Core Theme Compatibility. 5 5 * 6 6 * @package BuddyPress … … 26 26 27 27 /** 28 * Theme Compatibility base class 28 * Theme Compatibility base class. 29 29 * 30 30 * This is only intended to be extended, and is included here as a basic guide 31 * for future Theme Packs to use. @link BP_Legacyis a good example of31 * for future Theme Packs to use. {@link BP_Legacy} is a good example of 32 32 * extending this class. 33 33 * 34 * @since BuddyPress (1.7) 35 * @todo We should probably do something similar to BP_Component::start() 34 * @since BuddyPress (1.7.0) 35 * 36 * @todo We should probably do something similar to BP_Component::start(). 37 * @todo If this is only intended to be extended, it should be abstract. 38 * 39 * @param array $properties { 40 * An array of properties describing the theme compat package. 41 * @type string $id ID of the package. Must be unique. 42 * @type string $name Name of the theme. This should match the name given 43 * in style.css. 44 * @type string $version Theme version. Used for busting script and style 45 * browser caches. 46 * @type string $dir Filesystem path of the theme. 47 * @type string $url Base URL of the theme. 48 * } 36 49 */ 37 50 class BP_Theme_Compat { 38 51 39 52 /** 40 * Should be like: 41 * 42 * array( 43 * 'id' => ID of the theme (should be unique) 44 * 'name' => Name of the theme (should match style.css) 45 * 'version' => Theme version for cache busting scripts and styling 46 * 'dir' => Path to theme 47 * 'url' => URL to theme 48 * ); 53 * Template package properties, as passed to the constructor. 54 * 49 55 * @var array 50 56 */ … … 54 60 * Pass the $properties to the object on creation. 55 61 * 56 * @since BuddyPress (1.7) 57 * @param array $properties 62 * @since BuddyPress (1.7.0) 58 63 */ 59 64 public function __construct( Array $properties = array() ) { … … 61 66 } 62 67 63 64 /** 65 * Set up the BuddyPress-specific theme compat methods 68 /** 69 * Set up the BuddyPress-specific theme compat methods. 66 70 * 67 71 * Themes shoud use this method in their constructor. 68 72 * 69 * @since BuddyPress (1.7 )73 * @since BuddyPress (1.7.0) 70 74 */ 71 75 protected function start() { … … 81 85 82 86 /** 83 * Meant to be extended in your class. 84 * 85 * @since BuddyPress (1.7) 87 * Set up global data for your template package. 88 * 89 * Meant to be overridden in your class. See 90 * {@link BP_Legacy::setup_globals()} for an example. 91 * 92 * @since BuddyPress (1.7.0) 86 93 */ 87 94 protected function setup_globals() {} 88 95 89 96 /** 90 * Meant to be extended in your class. 91 * 92 * @since BuddyPress (1.7) 97 * Set up theme hooks for your template package. 98 * 99 * Meant to be overridden in your class. See 100 * {@link BP_Legacy::setup_actions()} for an example. 101 * 102 * @since BuddyPress (1.7.0) 93 103 */ 94 104 protected function setup_actions() {} … … 97 107 * Set a theme's property. 98 108 * 99 * @since BuddyPress (1.7) 100 * @param string $property 101 * @param mixed $value 102 * @return mixed 109 * @since BuddyPress (1.7.0) 110 * 111 * @param string $property Property name. 112 * @param mixed $value Property value. 113 * @return bool True on success, false on failure. 103 114 */ 104 115 public function __set( $property, $value ) { … … 109 120 * Get a theme's property. 110 121 * 111 * @since BuddyPress (1.7) 112 * @param string $property 113 * @param mixed $value 114 * @return mixed 122 * @since BuddyPress (1.7.0) 123 * 124 * @param string $property Property name. 125 * @return mixed The value of the property if it exists, otherwise an 126 * empty string. 115 127 */ 116 128 public function __get( $property ) { … … 122 134 123 135 /** 124 * Setup the default theme compat theme 125 * 126 * @since BuddyPress (1.7) 127 * @param BP_Theme_Compat $theme 136 * Set up the default theme compat theme. 137 * 138 * @since BuddyPress (1.7.0) 139 * 140 * @param string $theme Optional. The unique ID identifier of a theme package. 128 141 */ 129 142 function bp_setup_theme_compat( $theme = '' ) { … … 140 153 141 154 /** 142 * Get s the name of the BuddyPress compatable theme used, in the event the143 * currently active WordPress theme does not explicitly support BuddyPress.155 * Get the ID of the theme package being used. 156 * 144 157 * This can be filtered or set manually. Tricky theme authors can override the 145 158 * default and include their own BuddyPress compatability layers for their themes. 146 159 * 147 * @since BuddyPress (1.7) 160 * @since BuddyPress (1.7.0) 161 * 148 162 * @uses apply_filters() 149 * @return string 163 * 164 * @return string ID of the theme package in use. 150 165 */ 151 166 function bp_get_theme_compat_id() { … … 154 169 155 170 /** 156 * Get s the name of the BuddyPress compatable theme used, in the event the157 * currently active WordPress theme does not explicitly support BuddyPress.171 * Get the name of the theme package being used. 172 * 158 173 * This can be filtered or set manually. Tricky theme authors can override the 159 174 * default and include their own BuddyPress compatability layers for their themes. 160 175 * 161 * @since BuddyPress (1.7) 176 * @since BuddyPress (1.7.0) 177 * 162 178 * @uses apply_filters() 163 * @return string 179 * 180 * @return string Name of the theme package currently in use. 164 181 */ 165 182 function bp_get_theme_compat_name() { … … 168 185 169 186 /** 170 * Get s the version of the BuddyPress compatable theme used, in the event the171 * currently active WordPress theme does not explicitly support BuddyPress.187 * Get the version of the theme package being used. 188 * 172 189 * This can be filtered or set manually. Tricky theme authors can override the 173 190 * default and include their own BuddyPress compatability layers for their themes. 174 191 * 175 * @since BuddyPress (1.7) 192 * @since BuddyPress (1.7.0) 193 * 176 194 * @uses apply_filters() 177 * @return string 195 * 196 * @return string The version string of the theme package currently in use. 178 197 */ 179 198 function bp_get_theme_compat_version() { … … 182 201 183 202 /** 184 * Get s the BuddyPress compatable theme used in the event the currently active185 * WordPress theme does not explicitly support BuddyPress. This can be filtered,203 * Get the absolute path of the theme package being used. 204 * 186 205 * or set manually. Tricky theme authors can override the default and include 187 206 * their own BuddyPress compatability layers for their themes. 188 207 * 189 * @since BuddyPress (1.7) 208 * @since BuddyPress (1.7.0) 209 * 190 210 * @uses apply_filters() 191 * @return string 211 * 212 * @return string The absolute path of the theme package currently in use. 192 213 */ 193 214 function bp_get_theme_compat_dir() { … … 196 217 197 218 /** 198 * Gets the BuddyPress compatable theme used in the event the currently active 199 * WordPress theme does not explicitly support BuddyPress. This can be filtered, 200 * or set manually. Tricky theme authors can override the default and include 201 * their own BuddyPress compatability layers for their themes. 202 * 203 * @since BuddyPress (1.7) 219 * Get the URL of the theme package being used. 220 * 221 * This can be filtered, or set manually. Tricky theme authors can override 222 * the default and include their own BuddyPress compatability layers for their 223 * themes. 224 * 225 * @since BuddyPress (1.7.0) 226 * 204 227 * @uses apply_filters() 205 * @return string 228 * 229 * @return string URL of the theme package currently in use. 206 230 */ 207 231 function bp_get_theme_compat_url() { … … 213 237 * 214 238 * If the current theme's need for theme compat hasn't yet been detected, we 215 * do so using bp_detect_theme_compat_with_current_theme() 239 * do so using bp_detect_theme_compat_with_current_theme(). 216 240 * 217 241 * @since BuddyPress (1.9.0) … … 219 243 * @uses bp_detect_theme_compat_with_current_theme() 220 244 * 221 * @return bool True if the current theme needs theme compatibility 245 * @return bool True if the current theme needs theme compatibility. 222 246 */ 223 247 function bp_use_theme_compat_with_current_theme() { … … 277 301 278 302 /** 279 * Gets true/false if the current, loaded page uses theme compatibility 280 * 281 * @since BuddyPress (1.7) 282 * @return bool 303 * Is the current page using theme compatibility? 304 * 305 * @since BuddyPress (1.7.0) 306 * 307 * @return bool True if the current page uses theme compatibility. 283 308 */ 284 309 function bp_is_theme_compat_active() { … … 292 317 293 318 /** 294 * Sets true/false if page is currently inside theme compatibility 295 * 296 * @since BuddyPress (1.7) 297 * @param bool $set 298 * @return bool 319 * Set the flag that tells whether the current page is using theme compatibility. 320 * 321 * @since BuddyPress (1.7.0) 322 * 323 * @param bool $set True to set the flag to true, false to set it to false. 324 * @return bool Returns the value of $set. 299 325 */ 300 326 function bp_set_theme_compat_active( $set = true ) { … … 305 331 306 332 /** 307 * Set the theme compat templates global 333 * Set the theme compat templates global. 308 334 * 309 335 * Stash possible template files for the current query. Useful if plugins want 310 336 * to override them, or see what files are being scanned for inclusion. 311 337 * 312 * @since BuddyPress (1.7) 338 * @since BuddyPress (1.7.0) 339 * 340 * @param array $templates The template stack. 341 * @return array The template stack (value of $templates). 313 342 */ 314 343 function bp_set_theme_compat_templates( $templates = array() ) { … … 319 348 320 349 /** 321 * Set the theme compat template global 350 * Set the theme compat template global. 322 351 * 323 352 * Stash the template file for the current query. Useful if plugins want 324 353 * to override it, or see what file is being included. 325 354 * 326 * @since BuddyPress (1.7) 355 * @since BuddyPress (1.7.0) 356 * 357 * @param string $template The template currently in use. 358 * @return string The template currently in use (value of $template). 327 359 */ 328 360 function bp_set_theme_compat_template( $template = '' ) { … … 333 365 334 366 /** 335 * Set the theme compat original_template global 367 * Set the theme compat original_template global. 336 368 * 337 369 * Stash the original template file for the current query. Useful for checking 338 370 * if BuddyPress was able to find a more appropriate template. 339 371 * 340 * @since BuddyPress (1.7) 372 * @since BuddyPress (1.7.0) 373 * 374 * @param string $template The template originally selected by WP. 375 * @return string The template originally selected by WP (value of $template). 341 376 */ 342 377 function bp_set_theme_compat_original_template( $template = '' ) { … … 347 382 348 383 /** 349 * Set the theme compat original_template global 350 * 351 * Stash the original template file for the current query. Useful for checking 352 * if BuddyPress was able to find a more appropriate template. 353 * 354 * @since BuddyPress (1.7) 384 * Check whether a given template is the one that WP originally selected to display current page. 385 * 386 * @since BuddyPress (1.7.0) 387 * 388 * @param string $template The template name to check. 389 * @return bool True if the value of $template is the same as the 390 * "original_template" originally selected by WP. Otherwise false. 355 391 */ 356 392 function bp_is_theme_compat_original_template( $template = '' ) { … … 364 400 365 401 /** 366 * Register a new BuddyPress theme package to the active theme packages array 367 * 368 * The $theme parameter is an array, which takes the following values: 369 * 370 * 'id' - ID for your theme package; should be alphanumeric only 371 * 'name' - Name of your theme package 372 * 'version' - Version of your theme package 373 * 'dir' - Directory where your theme package resides 374 * 'url' - URL where your theme package resides 402 * Register a new BuddyPress theme package in the active theme packages array. 375 403 * 376 404 * For an example of how this function is used, see: … … 379 407 * @since BuddyPress (1.7) 380 408 * 381 * @param array $theme The theme package arguments. See phpDoc for more details. 409 * @see BP_Theme_Compat for a description of the $theme parameter arguments. 410 * 411 * @param array $theme See {@link BP_Theme_Compat}. 382 412 * @param bool $override If true, overrides whatever package is currently set. 413 * Default: true. 383 414 */ 384 415 function bp_register_theme_package( $theme = array(), $override = true ) { … … 405 436 406 437 /** 407 * This fun little function fills up some WordPress globals with dummy data to 408 * stop your average page template from complaining about it missing. 409 * 410 * @since BuddyPress (1.7) 411 * @global WP_Query $wp_query 412 * @global object $post 413 * @param array $args 438 * Populate various WordPress globals with dummy data to prevent errors. 439 * 440 * This dummy data is necessary because theme compatibility essentially fakes 441 * WordPress into thinking that there is content where, in fact, there is none 442 * (at least, no WordPress post content). By providing dummy data, we ensure 443 * that template functions - things like is_page() - don't throw errors. 444 * 445 * @since BuddyPress (1.7.0) 446 * 447 * @global WP_Query $wp_query WordPress database access object. 448 * @global object $post Current post object. 449 * 450 * @param array $args Array of optional arguments. Arguments parallel the 451 * properties of {@link WP_Post}; see that class for more details. 414 452 */ 415 453 function bp_theme_compat_reset_post( $args = array() ) { … … 522 560 523 561 /** 524 * Reset main query vars and filter 'the_content' to output a BuddyPress 525 * template part as needed. 526 * 527 * @since BuddyPress (1.7) 528 * 529 * @param string $template 530 * @uses bp_is_single_user() To check if page is single user 531 * @uses bp_get_single_user_template() To get user template 532 * @uses bp_is_single_user_edit() To check if page is single user edit 533 * @uses bp_get_single_user_edit_template() To get user edit template 534 * @uses bp_is_single_view() To check if page is single view 535 * @uses bp_get_single_view_template() To get view template 536 * @uses bp_is_forum_edit() To check if page is forum edit 537 * @uses bp_get_forum_edit_template() To get forum edit template 538 * @uses bp_is_topic_merge() To check if page is topic merge 539 * @uses bp_get_topic_merge_template() To get topic merge template 540 * @uses bp_is_topic_split() To check if page is topic split 541 * @uses bp_get_topic_split_template() To get topic split template 542 * @uses bp_is_topic_edit() To check if page is topic edit 543 * @uses bp_get_topic_edit_template() To get topic edit template 544 * @uses bp_is_reply_edit() To check if page is reply edit 545 * @uses bp_get_reply_edit_template() To get reply edit template 546 * @uses bp_set_theme_compat_template() To set the global theme compat template 562 * Reset main query vars and filter 'the_content' to output a BuddyPress template part as needed. 563 * 564 * @since BuddyPress (1.7.0) 565 * 566 * @uses bp_is_single_user() To check if page is single user. 567 * @uses bp_get_single_user_template() To get user template. 568 * @uses bp_is_single_user_edit() To check if page is single user edit. 569 * @uses bp_get_single_user_edit_template() To get user edit template. 570 * @uses bp_is_single_view() To check if page is single view. 571 * @uses bp_get_single_view_template() To get view template. 572 * @uses bp_is_forum_edit() To check if page is forum edit. 573 * @uses bp_get_forum_edit_template() To get forum edit template. 574 * @uses bp_is_topic_merge() To check if page is topic merge. 575 * @uses bp_get_topic_merge_template() To get topic merge template. 576 * @uses bp_is_topic_split() To check if page is topic split. 577 * @uses bp_get_topic_split_template() To get topic split template. 578 * @uses bp_is_topic_edit() To check if page is topic edit. 579 * @uses bp_get_topic_edit_template() To get topic edit template. 580 * @uses bp_is_reply_edit() To check if page is reply edit. 581 * @uses bp_get_reply_edit_template() To get reply edit template. 582 * @uses bp_set_theme_compat_template() To set the global theme compat template. 583 * 584 * @param string $template Template name. 585 * @return string $template Template name. 547 586 */ 548 587 function bp_template_include_theme_compat( $template = '' ) { … … 596 635 597 636 /** 637 * Conditionally replace 'the_content'. 638 * 598 639 * Replaces the_content() if the post_type being displayed is one that would 599 640 * normally be handled by BuddyPress, but proper single page templates do not 600 641 * exist in the currently active theme. 601 642 * 602 * @since BuddyPress (1.7) 603 * @param string $content 604 * @return string 643 * @since BuddyPress (1.7.0) 644 * 645 * @param string $content Original post content. 646 * @return string $content Post content, potentially modified. 605 647 */ 606 648 function bp_replace_the_content( $content = '' ) { … … 635 677 636 678 /** 637 * Are we replacing the_content 638 * 639 * @since BuddyPress (1.8) 640 * @return bool 679 * Are we currently replacing the_content? 680 * 681 * @since BuddyPress (1.8.0) 682 * 683 * @return bool True if the_content is currently in the process of being 684 * filtered and replaced. 641 685 */ 642 686 function bp_do_theme_compat() { … … 647 691 648 692 /** 649 * Removes all filters from a WordPress filter, and stashes them in the $bp 650 * global in the event they need to be restored later. 651 * 652 * @since BuddyPress (1.7) 693 * Remove all filters from a WordPress filter hook. 694 * 695 * Removed filters are stashed in the $bp global, in case they need to be 696 * restored later. 697 * 698 * @since BuddyPress (1.7.0) 699 * 653 700 * @global WP_filter $wp_filter 654 701 * @global array $merged_filters 655 * @param string $tag 656 * @param int $priority 657 * @return bool 702 * 703 * @param string $tag The filter tag to remove filters from. 704 * @param int $priority Optional. If present, only those callbacks attached 705 * at a given priority will be removed. Otherwise, all callbacks 706 * attached to the tag will be removed, regardless of priority. 707 * @return bool True on success. 658 708 */ 659 709 function bp_remove_all_filters( $tag, $priority = false ) { … … 699 749 700 750 /** 701 * Restore s filters from the $bp global that were removed using702 * bp_remove_all_filters()703 * 704 * @since BuddyPress (1.7)751 * Restore filters that were removed using bp_remove_all_filters(). 752 * 753 * @since BuddyPress (1.7.0) 754 * 705 755 * @global WP_filter $wp_filter 706 756 * @global array $merged_filters 707 * @param string $tag 708 * @param int $priority 709 * @return bool 757 * 758 * @param string $tag The tag to which filters should be restored. 759 * @param int $priority Optional. If present, only those filters that were 760 * originally attached to the tag with $priority will be restored. 761 * Otherwise, all available filters will be restored, regardless of 762 * priority. 763 * @return bool True on success. 710 764 */ 711 765 function bp_restore_all_filters( $tag, $priority = false ) { … … 751 805 752 806 /** 753 * Force comments_status to 'closed' for BuddyPress post types 754 * 755 * @since BuddyPress (1.7) 756 * @param bool $open True if open, false if closed 757 * @param int $post_id ID of the post to check 758 * @return bool True if open, false if closed 807 * Force comments_status to 'closed' for BuddyPress post types. 808 * 809 * @since BuddyPress (1.7.0) 810 * 811 * @param bool $open True if open, false if closed. 812 * @param int $post_id ID of the post to check. 813 * @return bool True if open, false if closed. 759 814 */ 760 815 function bp_comments_open( $open, $post_id = 0 ) {
Note: See TracChangeset
for help on using the changeset viewer.