Changeset 4498
- Timestamp:
- 11/24/2012 06:36:00 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/includes/users/template-tags.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/users/template-tags.php
r4365 r4498 494 494 $args = array( 'text' => $args ); 495 495 496 $ defaults =array(496 $r = bbp_parse_args( $args, array( 497 497 'text' => __( 'Admin', 'bbpress' ), 498 498 'before' => '', 499 499 'after' => '' 500 ); 501 $args = bbp_parse_args( $args, $defaults, 'get_admin_link' ); 502 extract( $args, EXTR_SKIP ); 503 504 $uri = admin_url(); 505 $retval = $before . '<a href="' . $uri . '">' . $text . '</a>' . $after; 506 507 return apply_filters( 'bbp_get_admin_link', $retval, $args ); 500 ), 'get_admin_link' ); 501 502 $retval = $r['before'] . '<a href="' . admin_url() . '">' . $r['text'] . '</a>' . $r['after']; 503 504 return apply_filters( 'bbp_get_admin_link', $retval, $r ); 508 505 } 509 506 … … 532 529 function bbp_get_author_ip( $args = '' ) { 533 530 534 // Default arguments 535 $defaults = array( 536 'post_id' => 0, 531 // Used as post id 532 $post_id = is_numeric( $args ) ? (int) $args : 0; 533 $r = bbp_parse_args( $args, array( 534 'post_id' => $post_id, 537 535 'before' => '<span class="bbp-author-ip">(', 538 536 'after' => ')</span>' 539 ); 540 541 $r = bbp_parse_args( $args, $defaults, 'get_author_ip' ); 542 extract( $r ); 543 544 // Used as post id 545 if ( is_numeric( $args ) ) 546 $post_id = $args; 537 ), 'get_author_ip' ); 547 538 548 539 // Get the author IP meta value 549 $author_ip = get_post_meta( $ post_id, '_bbp_author_ip', true );540 $author_ip = get_post_meta( $r['post_id'], '_bbp_author_ip', true ); 550 541 if ( !empty( $author_ip ) ) { 551 $author_ip = $ before . $author_ip . $after;542 $author_ip = $r['before'] . $author_ip . $r['after']; 552 543 553 544 // No IP address … … 556 547 } 557 548 558 return apply_filters( 'bbp_get_author_ip', $author_ip, $ args);549 return apply_filters( 'bbp_get_author_ip', $author_ip, $r ); 559 550 } 560 551 … … 822 813 return; 823 814 824 $ defaults = array(815 $r = bbp_parse_args( $args, array( 825 816 'subscribe' => __( 'Subscribe', 'bbpress' ), 826 817 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ), … … 829 820 'before' => ' | ', 830 821 'after' => '' 831 ); 832 $args = bbp_parse_args( $args, $defaults, 'get_user_subscribe_link' ); 833 extract( $args ); 822 ), 'get_user_subscribe_link' ); 834 823 835 824 // Validate user and topic ID's 836 $user_id = bbp_get_user_id( $ user_id, true, true );837 $topic_id = bbp_get_topic_id( $ topic_id);825 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 826 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 838 827 if ( empty( $user_id ) || empty( $topic_id ) ) { 839 828 return false; … … 848 837 $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id ); 849 838 if ( !empty( $is_subscribed ) ) { 850 $text = $ unsubscribe;839 $text = $r['unsubscribe']; 851 840 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id ); 852 841 } else { 853 $text = $ subscribe;842 $text = $r['subscribe']; 854 843 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id ); 855 844 } … … 867 856 } 868 857 869 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );870 $ is_subscribed = $is_subscribed ? 'is-subscribed' : '';871 $html = '<span id="subscription-toggle">' . $before . '<span id="subscribe-' . $topic_id . '" class="' . $is_subscribed . '"><a href="' . $url . '" class="dim:subscription-toggle:subscribe-' . $topic_id . ':is-subscribed">' . $text . '</a></span>' . $after. '</span>';858 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) ); 859 $subscribed = $is_subscribed ? ' class="is_subscribed"' : ''; 860 $html = '<span id="subscription-toggle">' . $r['before'] . '<span id="subscribe-' . $topic_id . '"' . $subscribed . '><a href="' . $url . '" class="dim:subscription-toggle:subscribe-' . $topic_id . ':is-subscribed">' . $text . '</a></span>' . $r['after'] . '</span>'; 872 861 873 862 // Return the link 874 return apply_filters( 'bbp_get_user_subscribe_link', $html, $ args, $user_id, $topic_id );863 return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id ); 875 864 } 876 865 … … 1349 1338 function bbp_get_author_link( $args = '' ) { 1350 1339 1351 // Default arguments1352 $ defaults =array(1353 'post_id' => 0,1340 $post_id = is_numeric( $args ) ? (int) $args : 0; 1341 $r = bbp_parse_args( $args, array( 1342 'post_id' => $post_id, 1354 1343 'link_title' => '', 1355 1344 'type' => 'both', 1356 1345 'size' => 80 1357 ); 1358 $r = bbp_parse_args( $args, $defaults, 'get_author_link' ); 1359 extract( $r ); 1360 1361 // Used as reply_id 1362 if ( is_numeric( $args ) ) 1363 $post_id = $args; 1346 ), 'get_author_link' ); 1364 1347 1365 1348 // Confirmed topic 1366 if ( bbp_is_topic( $ post_id) ) {1367 return bbp_get_topic_author_link( $ args);1349 if ( bbp_is_topic( $r['post_id'] ) ) { 1350 return bbp_get_topic_author_link( $r ); 1368 1351 1369 1352 // Confirmed reply 1370 } elseif ( bbp_is_reply( $post_id ) ) { 1371 return bbp_get_reply_author_link( $args ); 1353 } elseif ( bbp_is_reply( $r['post_id'] ) ) { 1354 return bbp_get_reply_author_link( $r ); 1355 } 1372 1356 1373 1357 // Get the post author and proceed 1374 } else { 1375 $user_id = get_post_field( 'post_author', $post_id ); 1376 } 1358 $user_id = get_post_field( 'post_author', $r['post_id'] ); 1377 1359 1378 1360 // Neither a reply nor a topic, so could be a revision 1379 if ( !empty( $ post_id) ) {1361 if ( !empty( $r['post_id'] ) ) { 1380 1362 1381 1363 // Generate title with the display name of the author 1382 if ( empty( $ link_title) ) {1383 $ link_title = sprintf( !bbp_is_reply_anonymous( $post_id) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), get_the_author_meta( 'display_name', $user_id ) );1364 if ( empty( $r['link_title'] ) ) { 1365 $r['link_title'] = sprintf( !bbp_is_reply_anonymous( $r['post_id'] ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), get_the_author_meta( 'display_name', $user_id ) ); 1384 1366 } 1385 1367 1386 1368 // Assemble some link bits 1387 $link_title = !empty( $ link_title ) ? ' title="' . $link_title. '"' : '';1369 $link_title = !empty( $r['link_title'] ) ? ' title="' . $r['link_title'] . '"' : ''; 1388 1370 $author_url = bbp_get_user_profile_url( $user_id ); 1389 $anonymous = bbp_is_reply_anonymous( $ post_id);1371 $anonymous = bbp_is_reply_anonymous( $r['post_id'] ); 1390 1372 1391 1373 // Get avatar 1392 if ( 'avatar' == $ type || 'both' == $type) {1393 $author_links[] = get_avatar( $user_id, $ size);1374 if ( 'avatar' == $r['type'] || 'both' == $r['type'] ) { 1375 $author_links[] = get_avatar( $user_id, $r['size'] ); 1394 1376 } 1395 1377 1396 1378 // Get display name 1397 if ( 'name' == $ type || 'both' == $type) {1379 if ( 'name' == $r['type'] || 'both' == $r['type'] ) { 1398 1380 $author_links[] = get_the_author_meta( 'display_name', $user_id ); 1399 1381 } … … 1416 1398 } 1417 1399 1418 return apply_filters( 'bbp_get_author_link', $author_link, $ args);1400 return apply_filters( 'bbp_get_author_link', $author_link, $r ); 1419 1401 } 1420 1402 … … 1444 1426 1445 1427 // Default arguments 1446 $ defaults =array(1428 $r = bbp_parse_args( $args, array( 1447 1429 'user_id' => bbp_get_current_user_id(), 1448 1430 'forum_id' => bbp_get_forum_id(), 1449 1431 'check_ancestors' => false 1450 ); 1451 $r = bbp_parse_args( $args, $defaults, 'user_can_view_forum' ); 1452 extract( $r ); 1432 ), 'user_can_view_forum' ); 1453 1433 1454 1434 // Validate parsed values 1455 $user_id = bbp_get_user_id ( $ user_id, false, false );1456 $forum_id = bbp_get_forum_id( $ forum_id);1435 $user_id = bbp_get_user_id ( $r['user_id'], false, false ); 1436 $forum_id = bbp_get_forum_id( $r['forum_id'] ); 1457 1437 $retval = false; 1458 1438 … … 1462 1442 1463 1443 // Forum is public, and user can read forums or is not logged in 1464 } elseif ( bbp_is_forum_public ( $forum_id, $ check_ancestors) ) {1444 } elseif ( bbp_is_forum_public ( $forum_id, $r['check_ancestors'] ) ) { 1465 1445 $retval = true; 1466 1446 1467 1447 // Forum is private, and user can see it 1468 } elseif ( bbp_is_forum_private( $forum_id, $ check_ancestors ) && current_user_can('read_private_forums' ) ) {1448 } elseif ( bbp_is_forum_private( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_private_forums' ) ) { 1469 1449 $retval = true; 1470 1450 1471 1451 // Forum is hidden, and user can see it 1472 } elseif ( bbp_is_forum_hidden ( $forum_id, $ check_ancestors ) && current_user_can('read_hidden_forums' ) ) {1452 } elseif ( bbp_is_forum_hidden ( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_hidden_forums' ) ) { 1473 1453 $retval = true; 1474 1454 }
Note: See TracChangeset
for help on using the changeset viewer.