• Resolved magland

    (@magland)


    With this plugin you can add video, link or images.

    Is there anyway to add a ‘video’, ‘link’ or ‘image’ class to the li element based on what the user has posted?

    I can see the class is outbout in my theme via:

    <li class="<?php bp_activity_css_class(); ?>" id="activity-<?php bp_activity_id(); ?>">

    When processed this outputs source such as:

    <li class="activity activity_update activity-item date-recorded-1493197675" id="activity-115">

    If the user posts an image I would like it to include something like:

    <li class="activity activity_update <strong>activityplus_image</strong> activity-item date-recorded-1493197675" id="activity-115">

    I would like to be able to style the activity posts differently based on the content posted. To do this i need the class on the li element.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter magland

    (@magland)

    Within the function ajax_update_activity_contents in class_bpfb_binder.php there is already some logic I can use to detect image, video or link. I have added a custom variable here containing the class I want to use.

    		if (!empty($_POST['data'])) {
    			if (!empty($_POST['data']['bpfb_video_url'])) {
    				$bpfb_code = $codec->create_video_tag($_POST['data']['bpfb_video_url']);
    				
    				// added by matt 26/04/2017
    				$customClass = "activityplus_video";
    			}
    			if (!empty($_POST['data']['bpfb_link_url'])) {
    				$bpfb_code = $codec->create_link_tag(
    					$_POST['data']['bpfb_link_url'],
    					$_POST['data']['bpfb_link_title'],
    					$_POST['data']['bpfb_link_body'],
    					$_POST['data']['bpfb_link_image']
    				);
    				
    				// added by matt 26/04/2017
    				$customClass = "activityplus_link";
    			}
    			if (!empty($_POST['data']['bpfb_photos'])) {
    				$images = $this->move_images($_POST['data']['bpfb_photos']);
    				$bpfb_code = $codec->create_images_tag($images);
    				
    				// added by matt 26/04/2017
    				$customClass = "activityplus_images";
    			}
    		}

    Further down there is a code block where the activity/entry.php template is loaded and processed:

    		if ($aid) {
    			ob_start();
    			if ( bp_has_activities ( 'include=' . $aid ) ) {
    				while ( bp_activities() ) {
    					bp_the_activity();
    					if (function_exists('bp_locate_template')) bp_locate_template( array( 'activity/entry.php' ), true );
    					else locate_template( array( 'activity/entry.php' ), true );
    				}
    			}
    			$activity = ob_get_clean();
    			
    			// added by matt 26/04/2017
    			$activity = str_replace("class=\"activity activity_update", "class=\"activity ".$customClass." activity_update", $activity);
    		}

    I’ve used a simple string replace to add in my custom class and this works for now.

    Obviously this is not ideal as I have modified the core plugin files. I would be interested to know if there is a more elegant solution.

    Thread Starter magland

    (@magland)

    Turns out my method doesn’t work, it only works when the activity is first posted and injected into the feed. If you then refresh the feed page my custom classes aren’t there anymore… ??

    Thread Starter magland

    (@magland)

    The addition of the code below worked and means I can remove the ugly string_replace and pull in the meta value within my activity/entry.php

    		if ($bpfb_code) {
    			$content = !empty($_POST['content']) ? $_POST['content'] : '';
    			$content .= "\n{$bpfb_code}";
    			$content = apply_filters('bp_activity_post_update_content', $content);
    			$aid = $gid ?
    				groups_post_update(array('content' => $content, 'group_id' => $gid))
    				:
    				bp_activity_post_update(array('content' => $content))
    			;
    			global $blog_id;
    			bp_activity_update_meta($aid, 'bpfb_blog_id', $blog_id);
    			
    			// added by matt 26/04/2017
    			bp_activity_add_meta($aid, 'customClass', $customClass);
    			
    		}
    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @magland,

    Thank you for sharing this solution with us. Let me check with developer if it is possible to do that outside the plugin core files.

    kind regards,
    Kasia

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add class to activity’ is closed to new replies.