Skip to:
Content

BuddyPress.org

Ticket #5272: bp-blogs-template.php.patch

File bp-blogs-template.php.patch, 6.0 KB (added by lenasterg, 10 years ago)

Patched file /bp-blogs/bp-blogs-template.php

  • bp-blogs-template.php

     
    161161         *
    162162         * @see BP_Blogs_Blog::get() for a description of parameters.
    163163         *
    164          * @param string $type See {@link BP_Blogs_Blog::get()}.
     164         * @param array $args {
     165     *     An array of arguments. All items are optional.
     166     * @param string $type See {@link BP_Blogs_Blog::get()}.
    165167         * @param string $page See {@link BP_Blogs_Blog::get()}.
    166168         * @param string $per_page See {@link BP_Blogs_Blog::get()}.
    167169         * @param string $max See {@link BP_Blogs_Blog::get()}.
     
    169171         * @param string $search_terms See {@link BP_Blogs_Blog::get()}.
    170172         * @param string $page_arg The string used as a query parameter in
    171173         *        pagination links. Default: 'bpage'.
     174         * @param bool $show_hidden Get also the private blogs of user
     175     *
     176     * }
    172177         */
    173         function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage' ) {
     178         function __construct($args) {
     179        // Backward compatibility with old method of passing arguments
     180        if (!is_array($args) || func_num_args() > 1) {
     181            _deprecated_argument(__METHOD__, '2.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__));
    174182
    175                 $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
    176                 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     183            $old_args_keys = array(
     184                0 => 'type',
     185                1 => 'page',
     186                2 => 'per_page',
     187                3 => 'max',
     188                4 => 'user_id',
     189                5 => 'search_terms',
     190                6 => 'page_arg',
     191                7 => 'show_hidden'
     192            );
    177193
     194            $func_args = func_get_args();
     195            $args = bp_core_parse_args_array($old_args_keys, $func_args);
     196        }
     197
     198        $defaults = array(
     199            'type' => 'active',
     200            'page' => 1,
     201            'per_page' => 20,
     202            'max' => false,
     203            'user_id' => '0',
     204            'search_terms' => false, // Pass search terms to filter on the blog title or description.
     205            'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679
     206            'show_hidden' => false
     207        );
     208        $r = wp_parse_args($args, $defaults);
     209        extract($r);
     210
     211        $this->pag_page = isset($_REQUEST[$page_arg]) ? intval($_REQUEST[$page_arg]) : $page;
     212        $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page;
     213               
    178214                if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
    179                         $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
     215                        $this->blogs = BP_Blogs_Blog::get_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page, $show_hidden);
    180216                else
    181                         $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
     217                 $this->blogs = bp_blogs_get_blogs(array('type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'show_hidden' => $show_hidden));
    182218
    183219                if ( !$max || $max >= (int) $this->blogs['total'] )
    184220                        $this->total_blog_count = (int) $this->blogs['total'];
     
    331367 *     @type int $user_id The ID of the user whose blogs should be retrieved.
    332368 *           When viewing a user profile page, 'user_id' defaults to the ID of
    333369 *           the displayed user. Otherwise the default is false.
     370 *              @type bool $show_hidden. Whether to show private blogs or not
    334371 * }
    335372 * @return bool Returns true when blogs are found, otherwise false.
    336373 */
     
    359396                'page_arg'     => 'bpage',        // See https://buddypress.trac.wordpress.org/ticket/3679
    360397
    361398                'user_id'      => $user_id,       // Pass a user_id to limit to only blogs this user has higher than subscriber access to
    362                 'search_terms' => $search_terms   // Pass search terms to filter on the blog title or description.
     399                'search_terms' => $search_terms,   // Pass search terms to filter on the blog title or description.
     400                'show_hidden' => false
    363401        );
    364402
    365403        $r = wp_parse_args( $args, $defaults );
     
    378416                }
    379417        }
    380418
    381         $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg );
     419        $args = array('type' => $type, 'page' => $page, 'per_page' => $per_page, 'max' => $max, 'user_id' => $user_id, 'search_terms' => $search_terms, 'page_arg' => $page_arg, 'show_hidden' => $show_hidden);
     420    $blogs_template = new BP_Blogs_Template($args);
    382421        return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template );
    383422}
    384423
     
    833872 * Output the total number of blogs for a given user.
    834873 *
    835874 * @param int $user_id ID of the user.
     875 * @param bool $show_hidden  Whether to count also hidden blogs.
    836876 */
    837 function bp_total_blog_count_for_user( $user_id = 0 ) {
    838         echo bp_get_total_blog_count_for_user( $user_id );
     877function bp_total_blog_count_for_user($user_id = 0, $show_hidden = false) {
     878    echo bp_get_total_blog_count_for_user($user_id, $show_hidden);
    839879}
    840880        /**
    841881         * Return the total number of blogs for a given user.
    842882         *
    843883         * @param int $user_id ID of the user.
     884         * @param bool $show_hidden  whether to count also private blogs of user
    844885         * @return int Total number of blogs for the user.
    845886         */
    846         function bp_get_total_blog_count_for_user( $user_id = 0 ) {
    847                 return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
    848         }
     887        function bp_get_total_blog_count_for_user($user_id = 0, $show_hidden = false) {
     888    return apply_filters('bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user($user_id, $show_hidden));
     889}
    849890        add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
    850891
    851892