Changeset 10356 for trunk/src/bp-core/bp-core-functions.php
- Timestamp:
- 11/15/2015 07:57:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-functions.php
r10110 r10356 47 47 * 48 48 * @since 1.6.0 49 * 49 50 * @return string The BuddyPress database version. 50 51 */ … … 109 110 * @since 2.2.0 110 111 * 111 * @param 112 * @param 113 * @param 114 * @return array 112 * @param array $items The items to be sorted. Its constituent items can be either associative arrays or objects. 113 * @param string|int $key The array index or property name to sort by. 114 * @param string $type Sort type. 'alpha' for alphabetical, 'num' for numeric. Default: 'alpha'. 115 * @return array $items The sorted array. 115 116 */ 116 117 function bp_sort_by_key( $items, $key, $type = 'alpha' ) { … … 158 159 * @since 1.9.0 159 160 * 160 * @param 161 * @param 162 * @return array 161 * @param array $items The items to be sorted. Its constituent items can be either associative arrays or objects. 162 * @param string|int $key The array index or property name to sort by. 163 * @return array $items The sorted array. 163 164 */ 164 165 function bp_alpha_sort_by_key( $items, $key ) { … … 171 172 * @param int $number The number to be formatted. 172 173 * @param bool $decimals Whether to use decimals. See {@link number_format_i18n()}. 173 *174 174 * @return string The formatted number. 175 175 */ 176 176 function bp_core_number_format( $number = 0, $decimals = false ) { 177 177 178 // Force number to 0 if needed 178 // Force number to 0 if needed. 179 179 if ( ! is_numeric( $number ) ) { 180 180 $number = 0; … … 227 227 * @param array $old_args_keys Old argument indexs, keyed to their positions. 228 228 * @param array $func_args The parameters passed to the originating function. 229 *230 229 * @return array $new_args The parsed arguments. 231 230 */ … … 256 255 * @param array $defaults Array that serves as the defaults. 257 256 * @param string $filter_key String to key the filters from. 258 *259 257 * @return array Merged user defined values with defaults. 260 258 */ 261 259 function bp_parse_args( $args, $defaults = array(), $filter_key = '' ) { 262 260 263 // Setup a temporary array from $args 261 // Setup a temporary array from $args. 264 262 if ( is_object( $args ) ) { 265 263 $r = get_object_vars( $args ); … … 270 268 } 271 269 272 // Passively filter the args before the parse 270 // Passively filter the args before the parse. 273 271 if ( !empty( $filter_key ) ) { 274 272 … … 285 283 } 286 284 287 // Parse 285 // Parse. 288 286 if ( is_array( $defaults ) && !empty( $defaults ) ) { 289 287 $r = array_merge( $defaults, $r ); 290 288 } 291 289 292 // Aggressively filter the args after the parse 290 // Aggressively filter the args after the parse. 293 291 if ( !empty( $filter_key ) ) { 294 292 … … 305 303 } 306 304 307 // Return the parsed results 305 // Return the parsed results. 308 306 return $r; 309 307 } … … 316 314 * @since 2.2.0 317 315 * 318 * @param string $page_arg The $_REQUEST argument to look for. 319 * @param int $page The original page value to fall back to. 320 * 321 * @return int A sanitized integer value, good for pagination. 316 * @param string $page_arg The $_REQUEST argument to look for. 317 * @param int $page The original page value to fall back to. 318 * @return int A sanitized integer value, good for pagination. 322 319 */ 323 320 function bp_sanitize_pagination_arg( $page_arg = '', $page = 1 ) { 324 321 325 // Check if request overrides exist 322 // Check if request overrides exist. 326 323 if ( isset( $_REQUEST[ $page_arg ] ) ) { 327 324 328 // Get the absolute integer value of the override 325 // Get the absolute integer value of the override. 329 326 $int = absint( $_REQUEST[ $page_arg ] ); 330 327 331 328 // If override is 0, do not use it. This prevents unlimited result sets. 332 // @see https://buddypress.trac.wordpress.org/ticket/5796 329 // @see https://buddypress.trac.wordpress.org/ticket/5796. 333 330 if ( $int ) { 334 331 $page = $int; … … 348 345 * 349 346 * @param string $order The 'order' string, as passed to the SQL constructor. 350 *351 347 * @return string The sanitized value 'DESC' or 'ASC'. 352 348 */ … … 369 365 * 370 366 * @param string $text The raw text to be escaped. 371 *372 367 * @return string Text in the form of a LIKE phrase. Not SQL safe. Run through 373 368 * wpdb::prepare() before use. … … 420 415 function bp_use_wp_admin_bar() { 421 416 422 // Default to true (to avoid loading deprecated BuddyBar code) 417 // Default to true (to avoid loading deprecated BuddyBar code). 423 418 $use_admin_bar = true; 424 419 … … 464 459 ); 465 460 466 // only add legacy forums if it is enabled467 // prevents conflicts with bbPress, which also uses the same 'forums' id 461 // Only add legacy forums if it is enabled 462 // prevents conflicts with bbPress, which also uses the same 'forums' id. 468 463 if ( class_exists( 'BP_Forums_Component' ) ) { 469 464 $components[] = 'forums'; … … 481 476 * pages. When running save routines, use 'all' to avoid removing data related to inactive 482 477 * components. Default: 'active'. 483 *484 478 * @return array|string An array of page IDs, keyed by component names, or an 485 479 * empty string if the list is not found. … … 488 482 $page_ids = bp_get_option( 'bp-pages' ); 489 483 490 // Ensure that empty indexes are unset. Should only matter in edge cases 484 // Ensure that empty indexes are unset. Should only matter in edge cases. 491 485 if ( !empty( $page_ids ) && is_array( $page_ids ) ) { 492 486 foreach( (array) $page_ids as $component_name => $page_id ) { … … 526 520 * Store the list of BP directory pages in the appropriate meta table. 527 521 * 528 * bp-pages data is stored in site_options (falls back to options on non-MS),522 * The bp-pages data is stored in site_options (falls back to options on non-MS), 529 523 * in an array keyed by blog_id. This allows you to change your 530 524 * bp_get_root_blog_id() and go through the setup process again. … … 549 543 global $wpdb; 550 544 551 // Look in cache first 545 // Look in cache first. 552 546 $pages = wp_cache_get( 'directory_pages', 'bp' ); 553 547 554 548 if ( false === $pages ) { 555 549 556 // Set pages as standard class 550 // Set pages as standard class. 557 551 $pages = new stdClass; 558 552 559 // Get pages and IDs 553 // Get pages and IDs. 560 554 $page_ids = bp_core_get_directory_page_ids(); 561 555 if ( !empty( $page_ids ) ) { 562 556 563 557 // Always get page data from the root blog, except on multiblog mode, when it comes 564 // from the current blog 558 // from the current blog. 565 559 $posts_table_name = bp_is_multiblog_mode() ? $wpdb->posts : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'posts'; 566 560 $page_ids_sql = implode( ',', wp_parse_id_list( $page_ids ) ); … … 579 573 $slug[] = $page_name->post_name; 580 574 581 // Get the slug 575 // Get the slug. 582 576 while ( $page_name->post_parent != 0 ) { 583 577 $parent = $wpdb->get_results( $wpdb->prepare( "SELECT post_name, post_parent FROM {$posts_table_name} WHERE ID = %d", $page_name->post_parent ) ); … … 635 629 $pages = bp_core_get_directory_page_ids( 'all' ); 636 630 637 // Delete any existing pages 631 // Delete any existing pages. 638 632 if ( 'delete' === $existing ) { 639 633 foreach ( (array) $pages as $page_id ) { … … 661 655 662 656 // Register and Activate are not components, but need pages when 663 // registration is enabled 657 // registration is enabled. 664 658 if ( bp_get_signup_allowed() ) { 665 659 foreach ( array( 'register', 'activate' ) as $slug ) { … … 670 664 } 671 665 672 // No need for a Sites directory unless we're on multisite 666 // No need for a Sites directory unless we're on multisite. 673 667 if ( ! is_multisite() && isset( $pages_to_create['sites'] ) ) { 674 668 unset( $pages_to_create['sites'] ); 675 669 } 676 670 677 // Members must always have a page, no matter what 671 // Members must always have a page, no matter what. 678 672 if ( ! isset( $pages['members'] ) && ! isset( $pages_to_create['members'] ) ) { 679 673 $pages_to_create['members'] = $page_titles['members']; 680 674 } 681 675 682 // Create the pages 676 // Create the pages. 683 677 foreach ( $pages_to_create as $component_name => $page_name ) { 684 678 $exists = get_page_by_path( $component_name ); 685 679 686 // If page already exists, use it 680 // If page already exists, use it. 687 681 if ( ! empty( $exists ) ) { 688 682 $pages[ $component_name ] = $exists->ID; … … 698 692 } 699 693 700 // Save the page mapping 694 // Save the page mapping. 701 695 bp_update_option( 'bp-pages', $pages ); 702 696 … … 711 705 * 712 706 * Bails early on multisite installations when not viewing the root site. 707 * 713 708 * @link https://buddypress.trac.wordpress.org/ticket/6226 714 709 * … … 719 714 function bp_core_on_directory_page_delete( $post_id ) { 720 715 721 // Stop if we are not on the main BP root blog 716 // Stop if we are not on the main BP root blog. 722 717 if ( ! bp_is_root_blog() ) { 723 718 return; … … 756 751 * 757 752 * @param string $root_slug The root slug, which comes from $bp->pages->[component]->slug. 758 *759 753 * @return string The short slug for use in the middle of URLs. 760 754 */ … … 793 787 $match = false; 794 788 795 // Check if the slug is registered in the $bp->pages global 789 // Check if the slug is registered in the $bp->pages global. 796 790 foreach ( (array) $bp->pages as $key => $page ) { 797 791 if ( $key == $slug || $page->slug == $slug ) { … … 800 794 } 801 795 802 // Maybe create the add_root array 796 // Maybe create the add_root array. 803 797 if ( empty( $bp->add_root ) ) { 804 798 $bp->add_root = array(); 805 799 } 806 800 807 // If there was no match, add a page for this root component 801 // If there was no match, add a page for this root component. 808 802 if ( empty( $match ) ) { 809 803 $add_root_items = $bp->add_root(); … … 812 806 } 813 807 814 // Make sure that this component is registered as requiring a top-level directory 808 // Make sure that this component is registered as requiring a top-level directory. 815 809 if ( isset( $bp->{$slug} ) ) { 816 810 $bp->loaded_components[$bp->{$slug}->slug] = $bp->{$slug}->id; … … 824 818 function bp_core_create_root_component_page() { 825 819 826 // Get BuddyPress 820 // Get BuddyPress. 827 821 $bp = buddypress(); 828 822 … … 890 884 // This ensures that the version of bp-default in the regular themes 891 885 // directory will always take precedence, as part of a migration away 892 // from the version packaged with BuddyPress 886 // from the version packaged with BuddyPress. 893 887 foreach ( array_values( (array) $GLOBALS['wp_theme_directories'] ) as $directory ) { 894 888 if ( is_dir( $directory . '/bp-default' ) ) { … … 898 892 899 893 // If the current theme is bp-default (or a bp-default child), BP 900 // should register its directory 894 // should register its directory. 901 895 $register = 'bp-default' === get_stylesheet() || 'bp-default' === get_template(); 902 896 903 // Legacy sites continue to have the theme registered 897 // Legacy sites continue to have the theme registered. 904 898 if ( empty( $register ) && ( 1 == get_site_option( '_bp_retain_bp_default' ) ) ) { 905 899 $register = true; … … 921 915 * Return the domain for the root blog. 922 916 * 923 * eg: http://example.com OR https://example.com917 * Eg: http://example.com OR https://example.com 924 918 * 925 919 * @uses get_blog_option() WordPress function to fetch blog meta. … … 1009 1003 $site_path = '/'; 1010 1004 } else { 1011 // Unset the first three segments (http(s)://example.com part) 1005 // Unset the first three segments (http(s)://example.com part). 1012 1006 unset( $site_path[0] ); 1013 1007 unset( $site_path[1] ); … … 1042 1036 * @param string $type See the 'type' parameter in {@link current_time()}. 1043 1037 * Default: 'mysql'. 1044 *1045 1038 * @return string Current time in 'Y-m-d h:i:s' format. 1046 1039 */ … … 1080 1073 * @param int|bool $newer_date Optional. Unix timestamp of date to compare older 1081 1074 * date to. Default: false (current time). 1082 *1083 1075 * @return string String representing the time since the older date, eg 1084 1076 * "2 hours and 50 minutes". … … 1127 1119 $ago_text = apply_filters( 'bp_core_time_since_ago_text', __( '%s ago', 'buddypress' ) ); 1128 1120 1129 // array of time period chunks1121 // Array of time period chunks. 1130 1122 $chunks = array( 1131 1123 YEAR_IN_SECONDS, … … 1151 1143 $newer_date = ( !$newer_date ) ? bp_core_current_time( true, 'timestamp' ) : $newer_date; 1152 1144 1153 // Difference in seconds 1145 // Difference in seconds. 1154 1146 $since = $newer_date - $older_date; 1155 1147 … … 1166 1158 } else { 1167 1159 1168 // Step one: the first chunk 1160 // Step one: the first chunk. 1169 1161 for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) { 1170 1162 $seconds = $chunks[$i]; 1171 1163 1172 // Finding the biggest chunk (if the chunk fits, break) 1164 // Finding the biggest chunk (if the chunk fits, break). 1173 1165 $count = floor( $since / $seconds ); 1174 1166 if ( 0 != $count ) { … … 1177 1169 } 1178 1170 1179 // If $i iterates all the way to $j, then the event happened 0 seconds ago 1171 // If $i iterates all the way to $j, then the event happened 0 seconds ago. 1180 1172 if ( !isset( $chunks[$i] ) ) { 1181 1173 $output = $right_now_text; … … 1183 1175 } else { 1184 1176 1185 // Set output var 1177 // Set output var. 1186 1178 switch ( $seconds ) { 1187 1179 case YEAR_IN_SECONDS : … … 1212 1204 // We've left the quirk in place, since fractions of a 1213 1205 // minute are not a useful piece of information for our 1214 // purposes 1206 // purposes. 1215 1207 if ( $i + 2 < $j ) { 1216 1208 $seconds2 = $chunks[$i + 1]; 1217 1209 $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ); 1218 1210 1219 // Add to output var 1211 // Add to output var. 1220 1212 if ( 0 != $count2 ) { 1221 1213 $output .= _x( ',', 'Separator in time since', 'buddypress' ) . ' '; … … 1243 1235 } 1244 1236 1245 // No output, so happened right now 1237 // No output, so happened right now. 1246 1238 if ( ! (int) trim( $output ) ) { 1247 1239 $output = $right_now_text; … … 1250 1242 } 1251 1243 1252 // Append 'ago' to the end of time-since if not 'right now' 1244 // Append 'ago' to the end of time-since if not 'right now'. 1253 1245 if ( $output != $right_now_text ) { 1254 1246 $output = sprintf( $ago_text, $output ); … … 1278 1270 function bp_core_add_message( $message, $type = '' ) { 1279 1271 1280 // Success is the default 1272 // Success is the default. 1281 1273 if ( empty( $type ) ) { 1282 1274 $type = 'success'; 1283 1275 } 1284 1276 1285 // Send the values to the cookie for page reload display 1277 // Send the values to the cookie for page reload display. 1286 1278 @setcookie( 'bp-message', $message, time() + 60 * 60 * 24, COOKIEPATH ); 1287 1279 @setcookie( 'bp-message-type', $type, time() + 60 * 60 * 24, COOKIEPATH ); 1288 1280 1289 // Get BuddyPress 1281 // Get BuddyPress. 1290 1282 $bp = buddypress(); 1291 1283 1292 /** *1284 /** 1293 1285 * Send the values to the $bp global so we can still output messages 1294 1286 * without a page reload … … 1312 1304 function bp_core_setup_message() { 1313 1305 1314 // Get BuddyPress 1306 // Get BuddyPress. 1315 1307 $bp = buddypress(); 1316 1308 … … 1343 1335 function bp_core_render_message() { 1344 1336 1345 // Get BuddyPress 1337 // Get BuddyPress. 1346 1338 $bp = buddypress(); 1347 1339 … … 1395 1387 function bp_core_record_activity() { 1396 1388 1397 // Bail if user is not logged in 1389 // Bail if user is not logged in. 1398 1390 if ( ! is_user_logged_in() ) { 1399 1391 return false; 1400 1392 } 1401 1393 1402 // Get the user ID 1394 // Get the user ID. 1403 1395 $user_id = bp_loggedin_user_id(); 1404 1396 1405 // Bail if user is not active 1397 // Bail if user is not active. 1406 1398 if ( bp_is_user_inactive( $user_id ) ) { 1407 1399 return false; 1408 1400 } 1409 1401 1410 // Get the user's last activity 1402 // Get the user's last activity. 1411 1403 $activity = bp_get_user_last_activity( $user_id ); 1412 1404 1413 // Make sure it's numeric 1405 // Make sure it's numeric. 1414 1406 if ( ! is_numeric( $activity ) ) { 1415 1407 $activity = strtotime( $activity ); 1416 1408 } 1417 1409 1418 // Get current time 1410 // Get current time. 1419 1411 $current_time = bp_core_current_time(); 1420 1412 1421 // Use this action to detect the very first activity for a given member 1413 // Use this action to detect the very first activity for a given member. 1422 1414 if ( empty( $activity ) ) { 1423 1415 … … 1434 1426 } 1435 1427 1436 // If it's been more than 5 minutes, record a newer last-activity time 1428 // If it's been more than 5 minutes, record a newer last-activity time. 1437 1429 if ( empty( $activity ) || ( strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) ) ) { 1438 1430 bp_update_user_last_activity( $user_id, $current_time ); … … 1449 1441 * @param int|string $last_activity_date The date of last activity. 1450 1442 * @param string $string A sprintf()-able statement of the form 'active %s'. 1451 *1452 1443 * @return string $last_active A string of the form '3 years ago'. 1453 1444 */ 1454 1445 function bp_core_get_last_activity( $last_activity_date = '', $string = '' ) { 1455 1446 1456 // Setup a default string if none was passed 1447 // Setup a default string if none was passed. 1457 1448 $string = empty( $string ) 1458 ? '%s' // Gettext placeholder 1449 ? '%s' // Gettext placeholder. 1459 1450 : $string; 1460 1451 1461 // Use the string if a last activity date was passed 1452 // Use the string if a last activity date was passed. 1462 1453 $last_active = empty( $last_activity_date ) 1463 1454 ? __( 'Not recently active', 'buddypress' ) … … 1499 1490 * 1500 1491 * @param string|bool $key The usermeta meta_key. 1501 *1502 1492 * @return string $key The usermeta meta_key. 1503 1493 */ … … 1529 1519 * @param string $key The meta key to retrieve. 1530 1520 * @param bool $single Whether to return a single value. 1531 *1532 1521 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single 1533 * is true.1522 * is true. 1534 1523 */ 1535 1524 function bp_get_user_meta( $user_id, $key, $single = false ) { … … 1553 1542 * @param mixed $value Metadata value. 1554 1543 * @param mixed $prev_value Optional. Previous value to check before removing. 1555 *1556 1544 * @return bool False on failure, true on success. 1557 1545 */ … … 1575 1563 * @param string $key The meta key to delete. 1576 1564 * @param mixed $value Optional. Metadata value. 1577 *1578 1565 * @return bool False for failure. True for success. 1579 1566 */ … … 1591 1578 function bp_embed_init() { 1592 1579 1593 // Get BuddyPress 1580 // Get BuddyPress. 1594 1581 $bp = buddypress(); 1595 1582 … … 1709 1696 * obeys {@link force_ssl_admin()} and {@link is_ssl()}. 'http' 1710 1697 * or 'https' can be passed to force those schemes. 1711 *1712 1698 * @return string Admin url link with optional path appended. 1713 1699 */ 1714 1700 function bp_get_admin_url( $path = '', $scheme = 'admin' ) { 1715 1701 1716 // Links belong in network admin 1702 // Links belong in network admin. 1717 1703 if ( bp_core_do_network_admin() ) { 1718 1704 $url = network_admin_url( $path, $scheme ); 1719 1705 1720 // Links belong in site admin 1706 // Links belong in site admin. 1721 1707 } else { 1722 1708 $url = admin_url( $path, $scheme ); … … 1743 1729 function bp_core_do_network_admin() { 1744 1730 1745 // Default 1731 // Default. 1746 1732 $retval = bp_is_network_activated(); 1747 1733 … … 1793 1779 * 1794 1780 * @param int $blog_id Optional. Default: the ID of the current blog. 1795 *1796 1781 * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id(). 1797 1782 */ 1798 1783 function bp_is_root_blog( $blog_id = 0 ) { 1799 1784 1800 // Assume false 1785 // Assume false. 1801 1786 $is_root_blog = false; 1802 1787 1803 // Use current blog if no ID is passed 1788 // Use current blog if no ID is passed. 1804 1789 if ( empty( $blog_id ) || ! is_int( $blog_id ) ) { 1805 1790 $blog_id = get_current_blog_id(); 1806 1791 } 1807 1792 1808 // Compare to root blog ID 1793 // Compare to root blog ID. 1809 1794 if ( bp_get_root_blog_id() === $blog_id ) { 1810 1795 $is_root_blog = true; … … 1876 1861 function bp_is_multiblog_mode() { 1877 1862 1878 // Setup some default values 1863 // Setup some default values. 1879 1864 $retval = false; 1880 1865 $is_multisite = is_multisite(); … … 1882 1867 $is_multiblog = defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG; 1883 1868 1884 // Multisite, Network Activated, and Specifically Multiblog 1869 // Multisite, Network Activated, and Specifically Multiblog. 1885 1870 if ( $is_multisite && $network_active && $is_multiblog ) { 1886 1871 $retval = true; 1887 1872 1888 // Multisite, but not network activated 1873 // Multisite, but not network activated. 1889 1874 } elseif ( $is_multisite && ! $network_active ) { 1890 1875 $retval = true; … … 1915 1900 function bp_is_network_activated() { 1916 1901 1917 // Default to is_multisite() 1902 // Default to is_multisite(). 1918 1903 $retval = is_multisite(); 1919 1904 1920 // Check the sitewide plugins array 1905 // Check the sitewide plugins array. 1921 1906 $base = buddypress()->basename; 1922 1907 $plugins = get_site_option( 'active_sitewide_plugins' ); 1923 1908 1924 // Override is_multisite() if not network activated 1909 // Override is_multisite() if not network activated. 1925 1910 if ( ! is_array( $plugins ) || ! isset( $plugins[ $base ] ) ) { 1926 1911 $retval = false; … … 2056 2041 * @param string $action Action nonce. 2057 2042 * @param string $query_arg Where to look for nonce in $_REQUEST. 2058 *2059 2043 * @return bool True if the nonce is verified, otherwise false. 2060 2044 */ 2061 2045 function bp_verify_nonce_request( $action = '', $query_arg = '_wpnonce' ) { 2062 2046 2063 /* *Home URL **************************************************************/2047 /* Home URL **************************************************************/ 2064 2048 2065 2049 // Parse home_url() into pieces to remove query-strings, strange characters, … … 2067 2051 $parsed_home = parse_url( home_url( '/', ( is_ssl() ? 'https' : 'http' ) ) ); 2068 2052 2069 // Maybe include the port, if it's included in home_url() 2053 // Maybe include the port, if it's included in home_url(). 2070 2054 if ( isset( $parsed_home['port'] ) ) { 2071 2055 $parsed_host = $parsed_home['host'] . ':' . $parsed_home['port']; … … 2074 2058 } 2075 2059 2076 // Set the home URL for use in comparisons 2060 // Set the home URL for use in comparisons. 2077 2061 $home_url = trim( strtolower( $parsed_home['scheme'] . '://' . $parsed_host . $parsed_home['path'] ), '/' ); 2078 2062 2079 /* *Requested URL *********************************************************/2080 2081 // Maybe include the port, if it's included in home_url() 2063 /* Requested URL *********************************************************/ 2064 2065 // Maybe include the port, if it's included in home_url(). 2082 2066 if ( isset( $parsed_home['port'] ) && false === strpos( $_SERVER['HTTP_HOST'], ':' ) ) { 2083 2067 $request_host = $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT']; … … 2086 2070 } 2087 2071 2088 // Build the currently requested URL 2072 // Build the currently requested URL. 2089 2073 $scheme = is_ssl() ? 'https://' : 'http://'; 2090 2074 $requested_url = strtolower( $scheme . $request_host . $_SERVER['REQUEST_URI'] ); 2091 2075 2092 /* *Look for match ********************************************************/2076 /* Look for match ********************************************************/ 2093 2077 2094 2078 /** … … 2103 2087 $matched_url = apply_filters( 'bp_verify_nonce_request_url', $requested_url ); 2104 2088 2105 // Check the nonce 2089 // Check the nonce. 2106 2090 $result = isset( $_REQUEST[$query_arg] ) ? wp_verify_nonce( $_REQUEST[$query_arg], $action ) : false; 2107 2091 2108 // Nonce check failed 2092 // Nonce check failed. 2109 2093 if ( empty( $result ) || empty( $action ) || ( strpos( $matched_url, $home_url ) !== 0 ) ) { 2110 2094 $result = false; … … 2130 2114 * 2131 2115 * @since 1.9.0 2116 * 2132 2117 * @return bool 2133 2118 */ … … 2140 2125 * 2141 2126 * @since 1.9.0 2127 * 2142 2128 * @return bool 2143 2129 */ … … 2180 2166 ) ); 2181 2167 2182 // Try custom locations in WP_LANG_DIR 2168 // Try custom locations in WP_LANG_DIR. 2183 2169 foreach ( $locations as $location ) { 2184 2170 if ( load_textdomain( 'buddypress', $location . $mofile_custom ) ) { … … 2187 2173 } 2188 2174 2189 // default to WP and glotpress2175 // Default to WP and glotpress. 2190 2176 return load_plugin_textdomain( $domain ); 2191 2177 } … … 2319 2305 function bp_nav_menu_get_loggedin_pages() { 2320 2306 2321 // Try to catch the cached version first 2307 // Try to catch the cached version first. 2322 2308 if ( ! empty( buddypress()->wp_nav_menu_items->loggedin ) ) { 2323 2309 return buddypress()->wp_nav_menu_items->loggedin; 2324 2310 } 2325 2311 2326 // Pull up a list of items registered in BP's top-level nav array 2312 // Pull up a list of items registered in BP's top-level nav array. 2327 2313 $bp_menu_items = buddypress()->bp_nav; 2328 2314 2329 // Alphabetize 2315 // Alphabetize. 2330 2316 $bp_menu_items = bp_alpha_sort_by_key( $bp_menu_items, 'name' ); 2331 2317 … … 2338 2324 ); 2339 2325 2340 // If there's nothing to show, we're done 2326 // If there's nothing to show, we're done. 2341 2327 if ( count( $bp_menu_items ) < 1 ) { 2342 2328 return false; … … 2347 2333 foreach ( $bp_menu_items as $bp_item ) { 2348 2334 2349 // Remove <span>number</span> 2335 // Remove <span>number</span>. 2350 2336 $item_name = preg_replace( '/([.0-9]+)/', '', $bp_item['name'] ); 2351 2337 $item_name = trim( strip_tags( $item_name ) ); … … 2389 2375 function bp_nav_menu_get_loggedout_pages() { 2390 2376 2391 // Try to catch the cached version first 2377 // Try to catch the cached version first. 2392 2378 if ( ! empty( buddypress()->wp_nav_menu_items->loggedout ) ) { 2393 2379 return buddypress()->wp_nav_menu_items->loggedout; … … 2405 2391 2406 2392 // The Register page will not always be available (ie, when 2407 // registration is disabled) 2393 // registration is disabled). 2408 2394 $bp_directory_page_ids = bp_core_get_directory_page_ids(); 2409 2395 … … 2417 2403 } 2418 2404 2419 // If there's nothing to show, we're done 2405 // If there's nothing to show, we're done. 2420 2406 if ( count( $bp_menu_items ) < 1 ) { 2421 2407 return false; … … 2458 2444 * @param string $slug The slug of the nav item: login, register, or one of the 2459 2445 * slugs from buddypress()->bp_nav. 2460 *2461 2446 * @return string $nav_item_url The URL generated for the current user. 2462 2447 */ … … 2482 2467 * @since 2.1.0 2483 2468 * 2484 * @param array $args 2485 * 2469 * @param array $args Array of args for the suggestions. 2486 2470 * @return array|WP_Error Array of results. If there were any problems, returns a WP_Error object. 2487 2471 */ … … 2566 2550 $need_switch = (bool) ( is_multisite() && ! bp_is_root_blog() ); 2567 2551 2568 // Maybe juggle to root blog 2552 // Maybe juggle to root blog. 2569 2553 if ( true === $need_switch ) { 2570 2554 switch_to_blog( bp_get_root_blog_id() ); 2571 2555 } 2572 2556 2573 // Get the upload directory (maybe for root blog) 2557 // Get the upload directory (maybe for root blog). 2574 2558 $wp_upload_dir = wp_upload_dir(); 2575 2559 2576 // Maybe juggle back to current blog 2560 // Maybe juggle back to current blog. 2577 2561 if ( true === $need_switch ) { 2578 2562 restore_current_blog(); 2579 2563 } 2580 2564 2581 // Bail if an error occurred 2565 // Bail if an error occurred. 2582 2566 if ( ! empty( $wp_upload_dir['error'] ) ) { 2583 2567 return false;
Note: See TracChangeset
for help on using the changeset viewer.