Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/26/2022 02:08:37 PM (2 years ago)
Author:
imath
Message:

Improve the new_blog_post activity type layout

These type of activities are generated when a blog post is published. If [13298] already brought some improvements making the included post featured image clickable, this changeset complement the first one:

  • by adding the post title into the activity content and linking it as well as the "read more" ellipsis to the post permalink. This "read more" link is generated using the WordPress the_content_more_link filter which means if your theme is using this filter to adapt the "read more" link, these adaptations will also be applied to the activity "read more" link.
  • by changing the markup used into these activities and by adding some CSS rules to make them looks more like WordPress embeds.

Props teeboy4real

Fixes #8052

File:
1 edited

Legend:

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

    r13298 r13305  
    34613461    );
    34623462
    3463     $post_url = '';
     3463    $post_url        = '';
     3464    $post_title      = '';
     3465    $bp_excerpt_args = array(
     3466        'html'              => false,
     3467        'filter_shortcodes' => true,
     3468        'strip_tags'        => true,
     3469        'remove_links'      => true,
     3470    );
    34643471    // Get the WP_Post object if this activity type is a blog post.
    34653472    if ( $activity['type'] === 'new_blog_post' ) {
    3466         $content  = get_post( $activity['secondary_item_id'] );
    3467         $post_url = $content->guid;
     3473        $content    = get_post( $activity['secondary_item_id'] );
     3474        $post_url   = $content->guid;
     3475        $post_title = sprintf(
     3476            '<strong><a href="%1$s">%2$s</a></strong>',
     3477            esc_url( $post_url ),
     3478            esc_html( $content->post_title )
     3479        );
     3480
     3481        $more_text  = sprintf(
     3482            '<span>%s</span>',
     3483            trim( __( ' [&hellip;]', 'buddypress' ) )
     3484        );
     3485
     3486        /** This filter is documented in wp-admin/includes/post-template.php */
     3487        $bp_excerpt_args['ending'] = apply_filters(
     3488            'the_content_more_link',
     3489            sprintf(
     3490                ' <a href="%1$s">%2$s</a>',
     3491                esc_url( $post_url ),
     3492                $more_text
     3493            ),
     3494            $more_text
     3495        );
    34683496    }
    34693497
     
    35803608
    35813609    // Generate a text excerpt for this activity item (and remove any oEmbeds URLs).
    3582     $summary = bp_create_excerpt( html_entity_decode( $content ), 225, array(
    3583         'html' => false,
    3584         'filter_shortcodes' => true,
    3585         'strip_tags'        => true,
    3586         'remove_links'      => true
    3587     ) );
     3610    $summary_parts = array(
     3611        str_replace(
     3612            array( "\n", "\r" ),
     3613            ' ',
     3614            trim( bp_create_excerpt( html_entity_decode( $content ), 225, $bp_excerpt_args ) )
     3615        ),
     3616    );
    35883617
    35893618    if ( $use_media_type === 'embeds' ) {
    3590         $summary .= PHP_EOL . PHP_EOL . $extracted_media['url'];
     3619        $summary_parts[] = PHP_EOL . PHP_EOL . $extracted_media['url'];
    35913620    } elseif ( $use_media_type === 'images' ) {
    35923621        $extracted_media_url = isset( $extracted_media['url'] ) ? $extracted_media['url'] : '';
     3622        $image_tag           = sprintf( '<img src="%s"> ', esc_url( $extracted_media_url ) );
    35933623
    35943624        if ( $post_url ) {
    3595             $summary .= sprintf( '<a href="%1$s" class="activity-post-featured-image"><img src="%2$s"></a>', esc_url( $post_url ), esc_url( $extracted_media_url ) );
    3596         } else {
    3597             $summary .= sprintf( ' <img src="%s">', esc_url( $extracted_media_url ) );
     3625            $image_tag = sprintf( '<a href="%1$s" class="activity-post-featured-image">%2$s</a> ', esc_url( $post_url ), trim( $image_tag ) );
     3626            array_unshift( $summary_parts, $image_tag );
    35983627        }
    35993628    } elseif ( in_array( $use_media_type, array( 'audio', 'videos' ), true ) ) {
    3600         $summary .= PHP_EOL . PHP_EOL . $extracted_media['original'];  // Full shortcode.
    3601     }
     3629        $summary_parts[] = PHP_EOL . PHP_EOL . $extracted_media['original'];  // Full shortcode.
     3630    }
     3631
     3632    if ( $post_title ) {
     3633        array_unshift( $summary_parts, $post_title );
     3634    }
     3635
     3636    // Join summary parts.
     3637    $summary = implode( '', $summary_parts );
    36023638
    36033639    /**
Note: See TracChangeset for help on using the changeset viewer.