Skip to:
Content
Pages
Categories
Search
Top
Bottom

Create Function When Favorite Button Clicked

  • @bfchris2

    Participant

    Hello:

    Trying to insert a new function that uses the “favorite” button in Users Activity Stream.
    Instead of “favoriting”, I’d like it to basically mimic the spam button, but instead of writing to the is_spam row in the activity table, I’d like it to write to a new row I’ve created. Same functions, etc.

    How can I rename and revamp the favorite button function to do this?

    Thanks in advance for any assistance.

    Chris

Viewing 15 replies - 1 through 15 (of 15 total)
  • @henrywright

    Moderator

    You’d need to use Ajax. Take a look at the Ajax in Plugins article for more info.

    @bfchris2

    Participant

    Henry:

    I’m only looking to basically take the favorites button and modify the function. Is there a guide to this somewhere?

    Chris

    @bfchris2

    Participant

    So, is that how the spam or favorite/un favorite buttons work?

    And how about the functions?

    Chris

    @danbp

    Participant

    @bfchris2,

    take a look here, as a starting point.

    Check also in bp-templates/bp-legacy/buddypress/buddypress-functions.php:1169 and in /plugins/buddypress/bp-activity/bp-activity-actions.php:436

    If you need complementary information about BP code, functions, etc, search here.

    @bfchris2

    Participant

    @danbp..
    Thanks. I don’t have buddypress-functions.php in my legacy/buddypress folder? Any thoughts?
    bp-activity-actions.php I do have however.

    -c-

    @henrywright

    Moderator

    So, is that how the spam or favorite/un favorite buttons work?

    Maybe. It will depend if you have JavaScript enabled in your browser. If you do, then Ajax will be working. If you don’t, it’s likely the traditional POST or GET methods will be in operation.

    @bfchris2

    Participant

    @henrywright…javascript *is enabled yes.
    What I’m wanting to do, is duplicate those buttons with a new function close to how is_spam functions where it writes a “1” to a row in a db table. I can add the buttons in /activity/entry.php etc..but just need to know how exactly/where to copy the is_spam functionality and where to add to fire off a “replica”. if that makes sense.

    @danbp

    Participant

    @bfchris2, sorry, the file is here /bp-legacy/buddypress-functions.php

    @bfchris2

    Participant

    I found it šŸ˜‰ so, now what do I do with it?

    chris

    @danbp

    Participant

    …euh…read through the code, find some dev comments and try to get further… ?

    I tried to answer to your question: only looking to basically take the favorites button and modify the function. Both files contain functions related to “favorite”.

    Though it would be more clear to all of us if you explain precisely what you’re trying to achive ? Instead of trying to explain (awkwardly) what you imagine may work, give details about what you try to do and code you used to do that.

    You say you create a function you want to add to favorite button. But this button should not favorite something, but either mimic is_span, but without using is_span !!!

    Sounds like if you asked for how to make beer, but without water to get a milk flavour.

    Please, make explicit questions !

    Providing Support at the BuddyPress Forums

    @bfchris2

    Participant

    @danbp:

    Here’s what I have done so far:

    /activity/entry.php

    <!-- BEGIN Custom Commenting Buttons -->
    
    				<a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( 'Is Milestone?', 'buddypress' ); ?>"><?php _e( 'Is Milestone?', 'buddypress' ); ?></a>
    				<a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( ' Is Momentum Point?', 'buddypress' ); ?>"><?php _e( 'Is Momentum Point?', 'buddypress' ); ?></a>
    
    <!-- END Custom Commenting Buttons -->

    (Just grabbed the button code for “unfavorite/favorite”, so I could have placeholders for my 2 custom buttons)

    /bp-custom.php
    (code taken from bp-activity-functions.php, well the is_spam piece).

    
    // Mark each as milestone
    	foreach ( (array) $activities['activities'] as $activity ) {
    
    		// Create an activity object
    		$activity_obj = new BP_Activity_Activity;
    		foreach ( $activity as $k => $v ) {
    			$activity_obj->$k = $v;
    		}
    
    		// Mark as milestone
    		bp_activity_mark_as_milestone( $activity_obj );
    
    		// Tidy up
    		unset( $activity_obj );
    	}
    
    	// Mark all of this user's activities as milestone
    	$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_milestone = 1 WHERE user_id = %d", $user_id ) );
    	
    		// Mark each as momentum point
    	foreach ( (array) $activities['activities'] as $activity ) {
    
    		// Create an activity object
    		$activity_obj = new BP_Activity_Activity;
    		foreach ( $activity as $k => $v ) {
    			$activity_obj->$k = $v;
    		}
    
    		// Mark as momentum point
    		bp_activity_mark_as_momentum( $activity_obj );
    
    		// Tidy up
    		unset( $activity_obj );
    	}
    
    	// Mark all of this user's activities as momentum point
    	$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_momentum_point = 1 WHERE user_id = %d", $user_id ) );
    

    Hope this helps make sense of things somewhat.

    Chris

    @bfchris2

    Participant

    Hereā€™s what I have done so far:

    /activity/entry.php

    <!-- BEGIN Custom Commenting Buttons -->
    
    				<a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( 'Is Milestone?', 'buddypress' ); ?>"><?php _e( 'Is Milestone?', 'buddypress' ); ?></a>
    				<a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( ' Is Momentum Point?', 'buddypress' ); ?>"><?php _e( 'Is Momentum Point?', 'buddypress' ); ?></a>
    
    <!-- END Custom Commenting Buttons -->

    (Just grabbed the button code for ā€œunfavorite/favoriteā€, so I could have placeholders for my 2 custom buttons)

    /bp-custom.php
    (code taken from bp-activity-functions.php, well the is_spam piece).

    
    // Mark each as milestone
    	foreach ( (array) $activities['activities'] as $activity ) {
    
    		// Create an activity object
    		$activity_obj = new BP_Activity_Activity;
    		foreach ( $activity as $k => $v ) {
    			$activity_obj->$k = $v;
    		}
    
    		// Mark as milestone
    		bp_activity_mark_as_milestone( $activity_obj );
    
    		// Tidy up
    		unset( $activity_obj );
    	}
    
    	// Mark all of this user's activities as milestone
    	$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_milestone = 1 WHERE user_id = %d", $user_id ) );
    	
    		// Mark each as momentum point
    	foreach ( (array) $activities['activities'] as $activity ) {
    
    		// Create an activity object
    		$activity_obj = new BP_Activity_Activity;
    		foreach ( $activity as $k => $v ) {
    			$activity_obj->$k = $v;
    		}
    
    		// Mark as momentum point
    		bp_activity_mark_as_momentum( $activity_obj );
    
    		// Tidy up
    		unset( $activity_obj );
    	}
    
    	// Mark all of this user's activities as momentum point
    	$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_momentum_point = 1 WHERE user_id = %d", $user_id ) );
    

    Hope this helps make sense of things somewhat.

    Chris

    @danbp

    Participant

    You didn’t explain what you want to do. What should Momentum and Milestone do ? Where are they living ? Are this activty types or CPT, something from a plugin ?

    As is, your second snippet do nothing from within bp-custom. Function name is missing and eventually filter or action name also.

    Insert your buttons by using the meta action filter which is avaible in entry.php

    function bfchris() {
    echo 'Button test >';
    ?>
    <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( 'Is Milestone?', 'buddypress' ); ?>"><?php _e( 'Is Milestone?', 'buddypress' ); ?></a>
    <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( ' Is Momentum Point?', 'buddypress' ); ?>"><?php _e( 'Is Momentum Point?', 'buddypress' ); ?></a>
    <?php
    }
    add_action( 'bp_activity_entry_meta' , 'bfchris' );

    Read from here for global information:

    Posting Activity from Plugins

    Here for an example:
    https://buddypress.org/support/topic/cant-seem-to-get-bp-2-2s-post-types-activities-working/

    And here for what you have to do for your specific activities

    Add custom filters to loops and enjoy them within your plugin

    @danbp

    Participant

    @bfchris2

    Participant

    @danbp:

    I have the buttons displaying fine in entry.php..thanks for that info however.
    To answer your questions milestones and momentum buttons really only need to act like the “spam” button, which when clicked, writes a “1” to the is_spam row in bp_activity table. So, I’ve created is_momentum and is_milestone rows in my db, and just need the logic on how I can get those buttons we have created to act like the “spam” button EXCEPT writing to a new row in table. ANd how to name the “php bp_activity_unfavorite_link” part of the button. That’s all.

    Hope that’s more clear now.

    Chris

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Create Function When Favorite Button Clicked’ is closed to new replies.
Skip to toolbar