Create Function When Favorite Button Clicked
-
You’d need to use Ajax. Take a look at the Ajax in Plugins article for more info.
Henry:
I’m only looking to basically take the favorites button and modify the function. Is there a guide to this somewhere?
Chris
So, is that how the spam or favorite/un favorite buttons work?
And how about the functions?
Chris
@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-
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
orGET
methods will be in operation.@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.@bfchris2, sorry, the file is here /bp-legacy/buddypress-functions.php
I found it š so, now what do I do with it?
chris
…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 !
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
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
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:
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
You may also follow this similar topic
https://buddypress.org/support/topic/add-new-user-activity-on-button-click/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
- The topic ‘Create Function When Favorite Button Clicked’ is closed to new replies.
bfchris2
@bfchris2
9 years, 3 months ago
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