Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to override class BP_Activity_Activity in bp-activity-classes.php?


  • nhalation
    Participant

    @nhalation

    Hello. I ran into an error when posting status updates to my activity feed. I was getting a PHP error message which indicated that a thumbnail URL could not be empty — which meant that the activity feed was trying to attach a thumbnail image to every status update, even when there should not be any.

    I took a look at bp-activity-classes.php on the line specified by the error message, which led me to this chunk of code in ‘public function save() {…}’:

    		if(isset($_POST['thumbnail'])){
    
    			$url = $_POST['thumbnail'];
    			$img = $_SERVER['DOCUMENT_ROOT'].'/staging/images/activity_images/'.date('YmdHis').'.jpg';
    			file_put_contents($img, file_get_contents($url));
    			$file = str_replace($_SERVER['DOCUMENT_ROOT'], '', $img);
    			$this->thumbnail = $file;
    		}

    Logically, I’m not sure why that didn’t just recognize that a thumbnail hadn’t been set. However, I just spitballed it and edited this to:

    if(isset($_POST['thumbnail'])){
    
    			$url = $_POST['thumbnail'];
    			if($url != ''){
    			$img = $_SERVER['DOCUMENT_ROOT'].'/staging/images/activity_images/'.date('YmdHis').'.jpg';
    			file_put_contents($img, file_get_contents($url));
    			$file = str_replace($_SERVER['DOCUMENT_ROOT'], '', $img);
    			$this->thumbnail = $file;
    			    }
    		}

    And that fixed it up.

    The issue is that I don’t want to edit the core file, to stay update-friendly I want to add this to my bp-custom.php file. I’m just not sure of the correct method.

    Thanks in advance!

  • The topic ‘How to override class BP_Activity_Activity in bp-activity-classes.php?’ is closed to new replies.
Skip to toolbar