Skip to:
Content

BuddyPress.org

Changeset 14260


Ignore:
Timestamp:
08/02/2026 11:33:11 PM (5 days ago)
Author:
espellcaste
Message:

Blogs: Improve function-call and array formatting.

Make multiline calls and arrays easier to read and consistently formatted throughout the Blogs component.

Props espellcaste.
See #9174.

Location:
trunk/src/bp-blogs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-activity.php

    r14251 r14260  
    460460
    461461        // Check for an existing entry and update if one exists.
    462         $id = bp_activity_get_activity_id( array(
    463                 'user_id'           => $r['user_id'],
    464                 'component'         => $r['component'],
    465                 'type'              => $r['type'],
    466                 'item_id'           => $r['item_id'],
    467                 'secondary_item_id' => $r['secondary_item_id'],
    468         ) );
    469 
    470         return bp_activity_add( array( 'id' => $id, 'user_id' => $r['user_id'], 'action' => $r['action'], 'content' => $r['content'], 'primary_link' => $r['primary_link'], 'component' => $r['component'], 'type' => $r['type'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'recorded_time' => $r['recorded_time'], 'hide_sitewide' => $r['hide_sitewide'] ) );
     462        $id = bp_activity_get_activity_id(
     463                array(
     464                        'user_id'           => $r['user_id'],
     465                        'component'         => $r['component'],
     466                        'type'              => $r['type'],
     467                        'item_id'           => $r['item_id'],
     468                        'secondary_item_id' => $r['secondary_item_id'],
     469                )
     470        );
     471
     472        return bp_activity_add(
     473                array(
     474                        'id' => $id,
     475                        'user_id' => $r['user_id'],
     476                        'action' => $r['action'],
     477                        'content' => $r['content'],
     478                        'primary_link' => $r['primary_link'],
     479                        'component' => $r['component'],
     480                        'type' => $r['type'],
     481                        'item_id' => $r['item_id'],
     482                        'secondary_item_id' => $r['secondary_item_id'],
     483                        'recorded_time' => $r['recorded_time'],
     484                        'hide_sitewide' => $r['hide_sitewide'],
     485                )
     486        );
    471487}
    472488
     
    606622        // Only record this activity if the blog is public.
    607623        if ( ! $is_private && ! $no_activity && bp_blogs_is_blog_trackable( $recorded_blog->blog_id, $recorded_blog->user_id ) ) {
    608                 bp_blogs_record_activity( array(
    609                         'user_id'      => $recorded_blog->user_id,
    610 
    611                         /**
    612                          * Filters the activity created blog primary link.
    613                          *
    614                          * @since 1.1.0
    615                          *
    616                          * @param string $link    Blog primary link.
    617                          * @param int    $blog_id Blog ID.
    618                          */
    619                         'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', bp_blogs_get_blogmeta( $recorded_blog->blog_id, 'url' ), $recorded_blog->blog_id ),
    620                         'type'         => 'new_blog',
    621                         'item_id'      => $recorded_blog->blog_id
    622                 ) );
     624                bp_blogs_record_activity(
     625                        array(
     626                                'user_id'      => $recorded_blog->user_id,
     627
     628                                /**
     629                                 * Filters the activity created blog primary link.
     630                                 *
     631                                 * @since 1.1.0
     632                                 *
     633                                 * @param string $link    Blog primary link.
     634                                 * @param int    $blog_id Blog ID.
     635                                 */
     636                                'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', bp_blogs_get_blogmeta( $recorded_blog->blog_id, 'url' ), $recorded_blog->blog_id ),
     637                                'type'         => 'new_blog',
     638                                'item_id'      => $recorded_blog->blog_id,
     639                        )
     640                );
    623641        }
    624642}
     
    637655                'item_id'   => $blog_id,
    638656                'component' => buddypress()->blogs->id,
    639                 'type'      => 'new_blog'
     657                'type'      => 'new_blog',
    640658        );
    641659
     
    661679 */
    662680function bp_blogs_delete_activity_for_site( $blog_id ) {
    663         bp_blogs_delete_activity( array(
    664                 'item_id'   => $blog_id,
    665                 'component' => buddypress()->blogs->id,
    666                 'type'      => false
    667         ) );
     681        bp_blogs_delete_activity(
     682                array(
     683                        'item_id'   => $blog_id,
     684                        'component' => buddypress()->blogs->id,
     685                        'type'      => false,
     686                )
     687        );
    668688}
    669689add_action( 'bp_blogs_remove_data_for_blog', 'bp_blogs_delete_activity_for_site' );
     
    709729        do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );
    710730
    711         bp_blogs_delete_activity( array(
    712                 'item_id'           => $blog_id,
    713                 'secondary_item_id' => $post_id,
    714                 'component'         => buddypress()->blogs->id,
    715                 'type'              => 'new_blog_post'
    716         ) );
     731        bp_blogs_delete_activity(
     732                array(
     733                        'item_id'           => $blog_id,
     734                        'secondary_item_id' => $post_id,
     735                        'component'         => buddypress()->blogs->id,
     736                        'type'              => 'new_blog_post',
     737                )
     738        );
    717739
    718740        /**
     
    794816                'comment_parent'       => (int) $comment_parent,
    795817                'user_id'              => $params['user_id'],
    796                 'comment_approved'     => 1
     818                'comment_approved'     => 1,
    797819        );
    798820
     
    885907
    886908        // Fetch the activity comments for the activity item.
    887         $activity = bp_activity_get( array(
    888                 'in'               => $activity_id,
    889                 'display_comments' => 'stream',
    890                 'spam'             => 'all',
    891         ) );
     909        $activity = bp_activity_get(
     910                array(
     911                        'in'               => $activity_id,
     912                        'display_comments' => 'stream',
     913                        'spam'             => 'all',
     914                )
     915        );
    892916
    893917        // Get all activity comment IDs for the pending deleted item.
     
    973997                } else {
    974998                        // Update the blog post comment.
    975                         wp_update_comment( array(
    976                                 'comment_ID'       => $post_comment_id,
    977                                 'comment_content'  => $activity->content,
    978                         ) );
     999                        wp_update_comment(
     1000                                array(
     1001                                        'comment_ID'       => $post_comment_id,
     1002                                        'comment_content'  => $activity->content,
     1003                                )
     1004                        );
    9791005                }
    9801006        }
     
    10861112                        'column'  => 'id',
    10871113                        'value'   => $activity_ids,
    1088                         'compare' => 'IN'
     1114                        'compare' => 'IN',
    10891115                ),
    10901116        );
  • trunk/src/bp-blogs/bp-blogs-filters.php

    r14250 r14260  
    1010/** Display Filters **********************************************************/
    1111
    12 add_filter( 'bp_get_blog_latest_post_title', 'wptexturize'   );
     12add_filter( 'bp_get_blog_latest_post_title', 'wptexturize' );
    1313add_filter( 'bp_get_blog_latest_post_title', 'convert_chars' );
    14 add_filter( 'bp_get_blog_latest_post_title', 'trim'          );
    15 
    16 add_filter( 'bp_blog_latest_post_content', 'wptexturize'        );
    17 add_filter( 'bp_blog_latest_post_content', 'convert_smilies'    );
    18 add_filter( 'bp_blog_latest_post_content', 'convert_chars'      );
    19 add_filter( 'bp_blog_latest_post_content', 'wpautop'            );
    20 add_filter( 'bp_blog_latest_post_content', 'shortcode_unautop'  );
     14add_filter( 'bp_get_blog_latest_post_title', 'trim' );
     15
     16add_filter( 'bp_blog_latest_post_content', 'wptexturize' );
     17add_filter( 'bp_blog_latest_post_content', 'convert_smilies' );
     18add_filter( 'bp_blog_latest_post_content', 'convert_chars' );
     19add_filter( 'bp_blog_latest_post_content', 'wpautop' );
     20add_filter( 'bp_blog_latest_post_content', 'shortcode_unautop' );
    2121add_filter( 'bp_blog_latest_post_content', 'prepend_attachment' );
    2222
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r14256 r14260  
    192192
    193193                // Get all users.
    194                 $users = get_users( array(
    195                         'blog_id' => $blog->blog_id,
    196                         'fields'  => 'ID'
    197                 ) );
     194                $users = get_users(
     195                        array(
     196                                'blog_id' => $blog->blog_id,
     197                                'fields'  => 'ID',
     198                        )
     199                );
    198200
    199201                // Continue on if no users exist for this site (how did this happen?).
     
    224226
    225227                // We have more blogs; record offset and re-run function.
    226                 if ( ! empty( $blog_ids  ) ) {
     228                if ( ! empty( $blog_ids ) ) {
    227229                        bp_update_option( '_bp_record_blogs_offset', $r['limit'] + $r['offset'] );
    228                         bp_blogs_record_existing_blogs( array(
    229                                 'offset'   => $r['limit'] + $r['offset'],
    230                                 'limit'    => $r['limit'],
    231                                 'blog_ids' => $r['blog_ids'],
    232                                 'site_id'  => $r['site_id']
    233                         ) );
     230                        bp_blogs_record_existing_blogs(
     231                                array(
     232                                        'offset'   => $r['limit'] + $r['offset'],
     233                                        'limit'    => $r['limit'],
     234                                        'blog_ids' => $r['blog_ids'],
     235                                        'site_id'  => $r['site_id'],
     236                                )
     237                        );
    234238
    235239                        // Bail since we have more blogs to record.
     
    573577                // Save site icon URL as blogmeta.
    574578                bp_blogs_update_blogmeta( $blog_id, 'site_icon_url_thumb', bp_blogs_get_site_icon_url( $blog_id, bp_core_avatar_thumb_width() ) );
    575                 bp_blogs_update_blogmeta( $blog_id, 'site_icon_url_full', bp_blogs_get_site_icon_url( $blog_id, bp_core_avatar_full_width()  ) );
     579                bp_blogs_update_blogmeta( $blog_id, 'site_icon_url_full', bp_blogs_get_site_icon_url( $blog_id, bp_core_avatar_full_width() ) );
    576580        }
    577581}
     
    685689                                // Query for activity comments connected to a blog post.
    686690                                unset( $args['filter'] );
    687                                 $args['meta_query']       = array( array(
    688                                         'key'     => 'bp_blogs_' . $post->post_type . '_comment_id',
    689                                         'value'   => $comment_ids,
    690                                         'compare' => 'IN',
    691                                 ) );
     691                                $args['meta_query']       = array(
     692                                        array(
     693                                                'key'     => 'bp_blogs_' . $post->post_type . '_comment_id',
     694                                                'value'   => $comment_ids,
     695                                                'compare' => 'IN',
     696                                        ),
     697                                );
    692698                                $args['type']             = 'activity_comment';
    693699                                $args['display_comments'] = 'stream';
     
    759765                if ( isset( $activity_post_object->action_id ) && isset( $activity_post_object->component_id ) ) {
    760766                        // Find the parent 'new_post_type' activity entry.
    761                         $parent_activity_id = bp_activity_get_activity_id( array(
    762                                 'component'         => $activity_post_object->component_id,
    763                                 'type'              => $activity_post_object->action_id,
    764                                 'item_id'           => $blog_id,
    765                                 'secondary_item_id' => $comment->comment_post_ID
    766                         ) );
     767                        $parent_activity_id = bp_activity_get_activity_id(
     768                                array(
     769                                        'component'         => $activity_post_object->component_id,
     770                                        'type'              => $activity_post_object->action_id,
     771                                        'item_id'           => $blog_id,
     772                                        'secondary_item_id' => $comment->comment_post_ID,
     773                                )
     774                        );
    767775
    768776                        // Try to create a new activity item for the parent blog post.
     
    912920}
    913921add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
    914 add_action( 'profile_update', 'bp_blogs_add_user_to_blog'        );
    915 add_action( 'user_register', 'bp_blogs_add_user_to_blog'        );
     922add_action( 'profile_update', 'bp_blogs_add_user_to_blog' );
     923add_action( 'user_register', 'bp_blogs_add_user_to_blog' );
    916924
    917925/**
     
    10661074                if ( ! empty( $activity_id ) ) {
    10671075                        // Fetch the activity comments for the activity item.
    1068                         $activity = bp_activity_get( array(
    1069                                 'in'               => $activity_id,
    1070                                 'display_comments' => 'stream',
    1071                                 'spam'             => 'all',
    1072                         ) );
     1076                        $activity = bp_activity_get(
     1077                                array(
     1078                                        'in'               => $activity_id,
     1079                                        'display_comments' => 'stream',
     1080                                        'spam'             => 'all',
     1081                                )
     1082                        );
    10731083
    10741084                        // Get all activity comment IDs for the pending deleted item.
     
    10791089                                // Delete activity items.
    10801090                                foreach ( $activity_ids as $activity_id ) {
    1081                                         bp_activity_delete( array(
    1082                                                 'id' => $activity_id
    1083                                         ) );
     1091                                        bp_activity_delete(
     1092                                                array(
     1093                                                        'id' => $activity_id,
     1094                                                )
     1095                                        );
    10841096                                }
    10851097
     
    11351147                                'value'   => implode( ',', (array) $activity_ids ),
    11361148                                'compare' => 'IN',
    1137                         )
    1138                 )
     1149                        ),
     1150                ),
    11391151        );
    11401152
     
    12721284                        'type'     => 'random',
    12731285                        'per_page' => $per_page,
    1274                         'page'     => $page
     1286                        'page'     => $page,
    12751287                )
    12761288        );
  • trunk/src/bp-blogs/bp-blogs-template.php

    r14251 r14260  
    9292                array_intersect_key( $path_chunks, $supported_chunks ),
    9393                array(
    94                         'component_id' => 'blogs'
     94                        'component_id' => 'blogs',
    9595                )
    9696        );
     
    463463                                }
    464464
    465                                 $avatar = sprintf( '<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" />',
     465                                $avatar = sprintf(
     466                                        '<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" />',
    466467                                        esc_url( $site_icon ),
    467468                                        esc_attr( "{$r['class']} avatar-{$size}" ),
     
    11351136                 * }
    11361137                 */
    1137                 $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
     1138                $filtered_results = apply_filters(
     1139                        'signup_another_blog_init',
     1140                        array(
     1141                                'blogname' => $blogname,
     1142                                'blog_title' => $blog_title,
     1143                                'errors' => $errors,
     1144                        )
     1145                );
    11381146                $blogname         = $filtered_results['blogname'];
    11391147                $blog_title       = $filtered_results['blog_title'];
     
    12721280                        $url = sprintf(
    12731281                                /* translators: %s is the site domain and path. */
    1274                                 __( '%sblogname', 'buddypress'),
     1282                                __( '%sblogname', 'buddypress' ),
    12751283                                $current_site->domain . $current_site->path
    12761284                        );
     
    12811289                        sprintf(
    12821290                                /* translators: %s is the site url. */
    1283                                 esc_html__( 'Your address will be %s', 'buddypress' ), esc_url( $url )
     1291                                esc_html__( 'Your address will be %s', 'buddypress' ),
     1292                                esc_url( $url )
    12841293                        ),
    12851294                        esc_html__( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!', 'buddypress' )
     
    12901299        ?>
    12911300        <p>
    1292                 <label for="blog_title"><?php esc_html_e('Site Title:', 'buddypress') ?></label>
     1301                <label for="blog_title"><?php esc_html_e( 'Site Title:', 'buddypress' ) ?></label>
    12931302                <input name="blog_title" type="text" id="blog_title" value="<?php echo esc_html( $blog_title ); ?>" />
    12941303
     
    13071316                        <label class="checkbox" for="blog_public_on">
    13081317                                <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php checked( ! isset( $_POST['blog_public'] ) || 1 === (int) $_POST['blog_public'] ); ?> />
    1309                                 <strong><?php esc_html_e( 'Yes', 'buddypress'); ?></strong>
     1318                                <strong><?php esc_html_e( 'Yes', 'buddypress' ); ?></strong>
    13101319                        </label>
    13111320                </p>
     
    13141323                        <label class="checkbox" for="blog_public_off">
    13151324                                <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php checked( isset( $_POST['blog_public'] ) && 0 === (int) $_POST['blog_public'] ); ?> />
    1316                                 <strong><?php esc_html_e( 'No', 'buddypress'); ?></strong>
     1325                                <strong><?php esc_html_e( 'No', 'buddypress' ); ?></strong>
    13171326                        </label>
    13181327                </p>
     
    13801389         * }
    13811390         */
    1382         $meta = apply_filters( 'add_signup_meta', array( 'lang_id' => 1, 'public' => $public ) );
     1391        $meta = apply_filters(
     1392                'add_signup_meta',
     1393                array(
     1394                        'lang_id' => 1,
     1395                        'public' => $public,
     1396                )
     1397        );
    13831398
    13841399        return wpmu_create_blog(
     
    13861401                $blog['path'],
    13871402                $blog['blog_title'],
    1388                 $current_user->ID, $meta,
     1403                $current_user->ID,
     1404                $meta,
    13891405                $current_site->id
    13901406        );
Note: See TracChangeset for help on using the changeset viewer.