Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/24/2012 06:36:00 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Extract:

  • Remove extract() usages from /users/template-tag.php.
  • See #2056.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/users/template-tags.php

    r4365 r4498  
    494494                        $args = array( 'text' => $args );
    495495
    496                 $defaults = array(
     496                $r = bbp_parse_args( $args, array(
    497497                        'text'   => __( 'Admin', 'bbpress' ),
    498498                        'before' => '',
    499499                        '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 );
    508505        }
    509506
     
    532529        function bbp_get_author_ip( $args = '' ) {
    533530
    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,
    537535                        'before'  => '<span class="bbp-author-ip">(',
    538536                        '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' );
    547538
    548539                // 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 );
    550541                if ( !empty( $author_ip ) ) {
    551                         $author_ip = $before . $author_ip . $after;
     542                        $author_ip = $r['before'] . $author_ip . $r['after'];
    552543
    553544                // No IP address
     
    556547                }
    557548
    558                 return apply_filters( 'bbp_get_author_ip', $author_ip, $args );
     549                return apply_filters( 'bbp_get_author_ip', $author_ip, $r );
    559550        }
    560551
     
    822813                        return;
    823814
    824                 $defaults = array (
     815                $r = bbp_parse_args( $args, array(
    825816                        'subscribe'   => __( 'Subscribe',   'bbpress' ),
    826817                        'unsubscribe' => __( 'Unsubscribe', 'bbpress' ),
     
    829820                        'before'      => '&nbsp;|&nbsp;',
    830821                        'after'       => ''
    831                 );
    832                 $args = bbp_parse_args( $args, $defaults, 'get_user_subscribe_link' );
    833                 extract( $args );
     822                ), 'get_user_subscribe_link' );
    834823
    835824                // 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'] );
    838827                if ( empty( $user_id ) || empty( $topic_id ) ) {
    839828                        return false;
     
    848837                $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id );
    849838                if ( !empty( $is_subscribed ) ) {
    850                         $text       = $unsubscribe;
     839                        $text       = $r['unsubscribe'];
    851840                        $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );
    852841                } else {
    853                         $text       = $subscribe;
     842                        $text       = $r['subscribe'];
    854843                        $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id );
    855844                }
     
    867856                }
    868857
    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>';
    872861
    873862                // 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 );
    875864        }
    876865
     
    13491338        function bbp_get_author_link( $args = '' ) {
    13501339
    1351                 // Default arguments
    1352                 $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,
    13541343                        'link_title' => '',
    13551344                        'type'       => 'both',
    13561345                        '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' );
    13641347
    13651348                // 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 );
    13681351
    13691352                // 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                }
    13721356
    13731357                // 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'] );
    13771359
    13781360                // Neither a reply nor a topic, so could be a revision
    1379                 if ( !empty( $post_id ) ) {
     1361                if ( !empty( $r['post_id'] ) ) {
    13801362
    13811363                        // 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 ) );
    13841366                        }
    13851367
    13861368                        // Assemble some link bits
    1387                         $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
     1369                        $link_title = !empty( $r['link_title'] ) ? ' title="' . $r['link_title'] . '"' : '';
    13881370                        $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'] );
    13901372
    13911373                        // 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'] );
    13941376                        }
    13951377
    13961378                        // Get display name
    1397                         if ( 'name' == $type   || 'both' == $type ) {
     1379                        if ( 'name' == $r['type'] || 'both' == $r['type'] ) {
    13981380                                $author_links[] = get_the_author_meta( 'display_name', $user_id );
    13991381                        }
     
    14161398                }
    14171399
    1418                 return apply_filters( 'bbp_get_author_link', $author_link, $args );
     1400                return apply_filters( 'bbp_get_author_link', $author_link, $r );
    14191401        }
    14201402
     
    14441426
    14451427        // Default arguments
    1446         $defaults = array(
     1428        $r = bbp_parse_args( $args, array(
    14471429                'user_id'         => bbp_get_current_user_id(),
    14481430                'forum_id'        => bbp_get_forum_id(),
    14491431                'check_ancestors' => false
    1450         );
    1451         $r = bbp_parse_args( $args, $defaults, 'user_can_view_forum' );
    1452         extract( $r );
     1432        ), 'user_can_view_forum' );
    14531433
    14541434        // 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'] );
    14571437        $retval   = false;
    14581438
     
    14621442
    14631443        // 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'] ) ) {
    14651445                $retval = true;
    14661446
    14671447        // 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' ) ) {
    14691449                $retval = true;
    14701450
    14711451        // 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'  ) ) {
    14731453                $retval = true;
    14741454        }
Note: See TracChangeset for help on using the changeset viewer.