Changeset 5826
- Timestamp:
- 07/13/2015 10:28:50 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/abstraction.php
r5823 r5826 18 18 19 19 /** 20 * Lookup and return a global variable 21 * 22 * @since bbPress (r5814) 23 * 24 * @param string $name Name of global variable 25 * @param string $type Type of variable to check with `is_a()` 26 * @param mixed $default Default value to return if no global found 27 * 28 * @return mixed Verified object if valid, Default or null if invalid 29 */ 30 function bbp_get_global_object( $name = '', $type = '', $default = null ) { 31 32 // Bail if no name passed 33 if ( empty( $name ) ) { 34 $retval = $default; 35 36 // Bail if no global exists 37 } elseif ( ! isset( $GLOBALS[ $name ] ) ) { 38 $retval = $default; 39 40 // Bail if not the correct type of global 41 } elseif ( ! empty( $type ) && ! is_a( $GLOBALS[ $name ], $type ) ) { 42 $retval = $default; 43 44 // Global variable exists 45 } else { 46 $retval = $GLOBALS[ $name ]; 47 } 48 49 // Filter & return 50 return apply_filters( 'bbp_get_global_object', $retval, $name, $type, $default ); 51 } 52 53 /** 20 54 * Return the database class being used to interface with the environment. 21 55 * … … 28 62 * @return object 29 63 */ 30 function bbp_get_db() { 31 32 // WordPress's `$wpdb` global 33 if ( isset( $GLOBALS['wpdb'] ) && is_a( $GLOBALS['wpdb'], 'WPDB' ) ) { 34 $retval = $GLOBALS['wpdb']; 35 } 36 37 // Filter & return 38 return apply_filters( 'bbp_get_db', $retval ); 64 function bbp_db() { 65 return bbp_get_global_object( 'wpdb', 'WPDB' ); 39 66 } 40 67 … … 50 77 * @return object 51 78 */ 52 function bbp_get_rewrite() { 53 54 // WordPress `$wp_rewrite` global 55 if ( isset( $GLOBALS['wp_rewrite'] ) && is_a( $GLOBALS['wp_rewrite'], 'WP_Rewrite' ) ) { 56 $retval = $GLOBALS['wp_rewrite']; 57 58 // Mock the expected object 59 } else { 60 $retval = (object) array( 61 'root' => '', 62 'pagination_base' => '', 63 ); 64 } 65 66 // Filter & return 67 return apply_filters( 'bbp_get_rewrite', $retval ); 79 function bbp_rewrite() { 80 return bbp_get_global_object( 'wp_rewrite', 'WP_Rewrite', (object) array( 81 'root' => '', 82 'pagination_base' => '', 83 ) ); 68 84 } 69 85 70 86 /** 71 * Get the URL root87 * Get the root URL 72 88 * 73 89 * @since bbPress (r5814) … … 76 92 */ 77 93 function bbp_get_root_url() { 78 return apply_filters( 'bbp_get_root_url', bbp_ get_rewrite()->root );94 return apply_filters( 'bbp_get_root_url', bbp_rewrite()->root ); 79 95 } 80 96 … … 87 103 */ 88 104 function bbp_get_paged_slug() { 89 return apply_filters( 'bbp_get_paged_slug', bbp_ get_rewrite()->pagination_base );105 return apply_filters( 'bbp_get_paged_slug', bbp_rewrite()->pagination_base ); 90 106 } 91 107 … … 99 115 * @return bool 100 116 */ 101 function bbp_ pretty_urls() {117 function bbp_use_pretty_urls() { 102 118 103 119 // Default 104 120 $retval = false; 105 $rewrite = bbp_ get_rewrite();121 $rewrite = bbp_rewrite(); 106 122 107 123 // Use $wp_rewrite->using_permalinks() if available
Note: See TracChangeset
for help on using the changeset viewer.