Skip to:
Content

BuddyPress.org

Ticket #5938: bp-activity-functions-5938.diff

File bp-activity-functions-5938.diff, 20.5 KB (added by tw2113, 10 years ago)
  • src/bp-activity/bp-activity-functions.php

     
    4545 * @return bool $retval True to enable mentions, false to disable.
    4646 */
    4747function bp_activity_do_mentions() {
     48
     49        /**
     50         * Filters whether or not mentions are enabled.
     51         *
     52         * @since BuddyPress (1.8.0)
     53         *
     54         * @param bool $enabled The enabled status of mentions.
     55         */
    4856        return (bool) apply_filters( 'bp_activity_do_mentions', true );
    4957}
    5058
     
    6169                bp_is_user_active() &&
    6270                ( bp_is_activity_component() || bp_is_blog_page() && is_singular() && comments_open() || is_admin() );
    6371
     72        /**
     73         * Filters whether or not BuddyPress should load mentions scripts and assets.
     74         *
     75         * @since BuddyPress (2.1.0)
     76         *
     77         * @param bool $retval The status of if scripts and assets should be loaded.
     78         */
    6479        return (bool) apply_filters( 'bp_activity_maybe_load_mentions_scripts', $retval );
    6580}
    6681
     
    333348                $bp->activity->actions->{$component_id} = new stdClass;
    334349        }
    335350
     351        /**
     352         * Filters the action type being set for the current activity item.
     353         *
     354         * @since BuddyPress (1.1.0)
     355         *
     356         * @param array    $array Array of arguments for action type being set.
     357         * @param string   $component_id ID of the current component being set.
     358         * @param string   $type Action type being set.
     359         * @param string   $description Action description for action being set.
     360         * @param callable $format_callback Callback for formatting the action string.
     361         * @param string   $label String to describe this action in the activity stream filter dropdown.
     362         * @param array    $context Activity stream contexts where the filter should appear. 'activity', 'member', 'member_groups', 'group'.
     363         */
    336364        $bp->activity->actions->{$component_id}->{$type} = apply_filters( 'bp_activity_set_action', array(
    337365                'key'             => $type,
    338366                'value'           => $description,
     
    367395                ? $bp->activity->actions->{$component_id}->{$key}
    368396                : false;
    369397
     398        /**
     399         * Filters the current action by component and key.
     400         *
     401         * @since BuddyPress (1.1.0)
     402         *
     403         * @param string|bool $retval The action key.
     404         * @param string      $component_id The unique string ID of the component.
     405         * @param string      $key The action key.
     406         */
    370407        return apply_filters( 'bp_activity_get_action', $retval, $component_id, $key );
    371408}
    372409
     
    392429        // This was a mis-named activity type from before BP 1.6
    393430        unset( $actions['friends_register_activity_action'] );
    394431
     432        /**
     433         * Filters the available activity types.
     434         *
     435         * @since BuddyPress (1.7.0)
     436         *
     437         * @param array $actions Array of registered activity types.
     438         */
    395439        return apply_filters( 'bp_activity_get_types', $actions );
    396440}
    397441
     
    418462        // Get favorites for user
    419463        $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
    420464
     465        /**
     466         * Filters the favorited activity items for a specified user.
     467         *
     468         * @since BuddyPress (1.2.0)
     469         *
     470         * @param array $favs Array of user's favorited activity items.
     471         */
    421472        return apply_filters( 'bp_activity_get_user_favorites', $favs );
    422473}
    423474
     
    473524        // Update activity meta counts
    474525        if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) {
    475526
    476                 // Execute additional code
     527                /**
     528                 * Fires if bp_activity_update_meta() for favorite_count is successful and before returning a true value for success.
     529                 *
     530                 * @since BuddyPress (1.2.1)
     531                 *
     532                 * @param int $activity_id ID of the activity item being favorited.
     533                 * @param int $user_id ID of the user doing the favoriting.
     534                 */
    477535                do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
    478536
    479537                // Success
     
    481539
    482540        // Saving meta was unsuccessful for an unknown reason
    483541        } else {
    484                 // Execute additional code
     542
     543                /**
     544                 * Fires if bp_activity_update_meta() for favorite_count is unsuccessful and before returning a false value for failure.
     545                 *
     546                 * @since BuddyPress (1.5.0)
     547                 *
     548                 * @param int $activity_id ID of the activity item being favorited.
     549                 * @param int $user_id ID of the user doing the favoriting.
     550                 */
    485551                do_action( 'bp_activity_add_user_favorite_fail', $activity_id, $user_id );
    486552
    487553                return false;
     
    538604                        // Update users favorites
    539605                        if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) {
    540606
    541                                 // Execute additional code
     607                                /**
     608                                 * Fires if bp_update_user_meta() is successful and before returning a true value for success.
     609                                 *
     610                                 * @since BuddyPress (1.2.1)
     611                                 *
     612                                 * @param int $activity_id ID of the activity item being unfavorited.
     613                                 * @param int $user_id ID of the user doing the unfavoriting.
     614                                 */
    542615                                do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
    543616
    544617                                // Success
     
    572645 * @return int|null The ID of the located activity item. Null if none is found.
    573646 */
    574647function bp_activity_check_exists_by_content( $content ) {
     648
     649        /**
     650         * Filters the results of the check for if an activity item exists by specified content.
     651         *
     652         * @since BuddyPress (1.1.0)
     653         *
     654         * @param BP_Activity_Activity $content_exists ID of the activity if found, else null.
     655         */
    575656        return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
    576657}
    577658
     
    586667 * @return string Date last updated.
    587668 */
    588669function bp_activity_get_last_updated() {
     670
     671        /**
     672         * Filters the value for the last updated time for an activity item.
     673         *
     674         * @since BuddyPress (1.1.0)
     675         *
     676         * @param BP_Activity_Activity $last_updated Date last updated.
     677         */
    589678        return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
    590679}
    591680
     
    676765        $retval = get_metadata( 'activity', $activity_id, $meta_key, $single );
    677766        remove_filter( 'query', 'bp_filter_metaid_column_name' );
    678767
    679         // Filter result before returning
     768        /**
     769         * Filters the metadata for a specified activity item.
     770         *
     771         * @since BuddyPress (1.5.0)
     772         *
     773         * @param mixed  $retval The meta values for the activity item.
     774         * @param int    $activity_id ID of the activity item.
     775         * @param string $meta_key Meta key for the value being requested.
     776         * @param bool   $single Whether to return one matched meta key row or all.
     777         */
    680778        return apply_filters( 'bp_activity_get_meta', $retval, $activity_id, $meta_key, $single );
    681779}
    682780
     
    757855        // Execute additional code
    758856        do_action( 'bp_activity_remove_data', $user_id ); // Deprecated! Do not use!
    759857
    760         // Use this going forward
     858        /**
     859         * Fires after the removal of all of a user's activity data.
     860         *
     861         * @since BuddyPress (1.5.0)
     862         *
     863         * @param int $user_id ID of the user being deleted.
     864         */
    761865        do_action( 'bp_activity_remove_all_user_data', $user_id );
    762866}
    763867add_action( 'wpmu_delete_user',  'bp_activity_remove_all_user_data' );
     
    820924        // Mark all of this user's activities as spam
    821925        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) );
    822926
    823         // Call an action for plugins to use
     927        /**
     928         * Fires after all activity data from a user has been marked as spam.
     929         *
     930         * @since BuddyPress (1.6.0)
     931         *
     932         * @param int   $user_id ID of the user whose activity is being marked as spam.
     933         * @param array $activities Array of activity items being marked as spam.
     934         */
    824935        do_action( 'bp_activity_spam_all_user_data', $user_id, $activities['activities'] );
    825936}
    826937add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' );
     
    880991                unset( $activity_obj );
    881992        }
    882993
    883         // Mark all of this user's activities as spam
     994        // Mark all of this user's activities as not spam
    884995        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) );
    885996
    886         // Call an action for plugins to use
     997        /**
     998         * Fires after all activity data from a user has been marked as ham.
     999         *
     1000         * @since BuddyPress (1.6.0)
     1001         *
     1002         * @param int   $user_id ID of the user whose activity is being marked as ham.
     1003         * @param array $activities Array of activity items being marked as ham.
     1004         */
    8871005        do_action( 'bp_activity_ham_all_user_data', $user_id, $activities['activities'] );
    8881006}
    8891007add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' );
     
    9131031                __( 'Activity Comments', 'buddypress' )
    9141032        );
    9151033
     1034        /**
     1035         * Fires at the end of the activity actions registration.
     1036         *
     1037         * Allows for plugin authors to add their own activity actions along side the core actions.
     1038         *
     1039         * @since BuddyPress (1.6.0)
     1040         */
    9161041        do_action( 'bp_activity_register_activity_actions' );
    9171042
    9181043        // Backpat. Don't use this.
     
    9421067        // We apply the format_callback as a filter
    9431068        add_filter( 'bp_activity_generate_action_string', buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
    9441069
    945         // Generate the action string (run through the filter defined above)
     1070        /**
     1071         * Filters the string for the activity action being returned.
     1072         *
     1073         * @since BuddyPress (2.0.0)
     1074         *
     1075         * @param BP_Activity_Activity $action Action string being requested.
     1076         * @param BP_Activity_Activity $activity Activity item object.
     1077         */
    9461078        $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity );
    9471079
    9481080        // Remove the filter for future activity items
     
    9621094 */
    9631095function bp_activity_format_activity_action_activity_update( $action, $activity ) {
    9641096        $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
     1097
     1098        /**
     1099         * Filters the formatted activity action update string.
     1100         *
     1101         * @since BuddyPress (1.2.0)
     1102         *
     1103         * @param string               $action Activity action string value.
     1104         * @param BP_Activity_Activity $activity Activity item object.
     1105         */
    9651106        return apply_filters( 'bp_activity_new_update_action', $action, $activity );
    9661107}
    9671108
     
    9761117 */
    9771118function bp_activity_format_activity_action_activity_comment( $action, $activity ) {
    9781119        $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
     1120
     1121        /**
     1122         * Filters the formatted activity action comment string.
     1123         *
     1124         * @since BuddyPress (1.2.0)
     1125         *
     1126         * @param string               $action Activity action string value.
     1127         * @param BP_Activity_Activity $activity Activity item object.
     1128         */
    9791129        return apply_filters( 'bp_activity_comment_action', $action, $activity );
    9801130}
    9811131
     
    10841234                ) );
    10851235        }
    10861236
     1237        /**
     1238         * Filters the requested activity item(s).
     1239         *
     1240         * @since BuddyPress (1.2.0)
     1241         *
     1242         * @param BP_Activity_Activity $activity Requested activity object.
     1243         * @param array                $r Arguments used for the activity query.
     1244         */
    10871245        return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) );
    10881246}
    10891247
     
    11311289                'update_meta_cache' => $r['update_meta_cache'],
    11321290        );
    11331291
     1292        /**
     1293         * Filters the requested specific activity item.
     1294         *
     1295         * @since BuddyPress (1.2.0)
     1296         *
     1297         * @param BP_Activity_Activity $activity Requested activity object.
     1298         * @param array                $args Original passed in arguments.
     1299         * @param array                $get_args Constructed arguments used with request.
     1300         */
    11341301        return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $get_args ), $args, $get_args );
    11351302}
    11361303
     
    12331400        }
    12341401
    12351402        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
     1403
     1404        /**
     1405         * Fires at the end of the execution of adding a new activity item, before the returning of the new activity item ID.
     1406         *
     1407         * @since BuddyPress (1.1.0)
     1408         *
     1409         * @param array $r Array of parsed arguments for the activity item being added.
     1410         */
    12361411        do_action( 'bp_activity_add', $r );
    12371412
    12381413        return $activity->id;
     
    12791454        $activity_content = $r['content'];
    12801455        $primary_link     = bp_core_get_userlink( $r['user_id'], false, true );
    12811456
     1457        /**
     1458         * Filters the new activity content for current activity item.
     1459         *
     1460         * @since BuddyPress (1.2.0)
     1461         *
     1462         * @param string $activity_content Activity content posted by user.
     1463         */
     1464        $add_content = apply_filters( 'bp_activity_new_update_content', $activity_content );
     1465
     1466        /**
     1467         * Filters the activity primary link for current activity item.
     1468         *
     1469         * @since BuddyPress (1.2.0)
     1470         *
     1471         * @param string $primary_link Link to the profile for the user who posted the activity.
     1472         */
     1473        $add_primary_link = apply_filters( 'bp_activity_new_update_primary_link', $primary_link );
     1474
    12821475        // Now write the values
    12831476        $activity_id = bp_activity_add( array(
    12841477                'user_id'      => $r['user_id'],
    1285                 'content'      => apply_filters( 'bp_activity_new_update_content', $activity_content ),
    1286                 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
     1478                'content'      => $add_content,
     1479                'primary_link' => $add_primary_link,
    12871480                'component'    => buddypress()->activity->id,
    12881481                'type'         => 'activity_update',
    12891482        ) );
    12901483
     1484        /**
     1485         * Filters the latest update content for the activity item.
     1486         *
     1487         * @since BuddyPress (1.6.0)
     1488         *
     1489         * @param string $r Content of the activity update.
     1490         * @param string $activity_content Content of the activity update.
     1491         */
    12911492        $activity_content = apply_filters( 'bp_activity_latest_update_content', $r['content'], $activity_content );
    12921493
    12931494        // Add this update to the "latest update" usermeta so it can be fetched anywhere.
     
    12961497                'content' => $activity_content
    12971498        ) );
    12981499
     1500        /**
     1501         * Fires at the end of an activity post update, before the returning of the updated activity item ID.
     1502         *
     1503         * @since BuddyPress (1.2.0)
     1504         *
     1505         * @param string $content Content of the activity post update.
     1506         * @param int    $user_id ID of the user posting the activity update.
     1507         * @param int    $activity_id ID of the activity item being updated.
     1508         */
    12991509        do_action( 'bp_activity_posted_update', $r['content'], $r['user_id'], $activity_id );
    13001510
    13011511        return $activity_id;
     
    13741584        // Check to see if the parent activity is hidden, and if so, hide this comment publically.
    13751585        $is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0;
    13761586
     1587        /**
     1588         * Filters the content of a new comment.
     1589         *
     1590         * @since BuddyPress (1.2.0)
     1591         *
     1592         * @param string $r Content for the newly posted comment.
     1593         */
     1594        $comment_content = apply_filters( 'bp_activity_comment_content', $r['content'] );
     1595
    13771596        // Insert the activity comment
    13781597        $comment_id = bp_activity_add( array(
    13791598                'id'                => $r['id'],
    1380                 'content'           => apply_filters( 'bp_activity_comment_content', $r['content'] ),
     1599                'content'           => $comment_content,
    13811600                'component'         => buddypress()->activity->id,
    13821601                'type'              => 'activity_comment',
    13831602                'user_id'           => $r['user_id'],
     
    13981617        }
    13991618        wp_cache_delete( $activity_id, 'bp_activity' );
    14001619
     1620        /**
     1621         * Fires near the end of an activity comment posting, before the returning of the comment ID.
     1622         *
     1623         * @since BuddyPress (1.2.0)
     1624         *
     1625         * @param int   $comment_id ID of the newly posted activity comment.
     1626         * @param array $r Array of parsed comment arguments.
     1627         * @param int   $activity ID of the activity item being commented on.
     1628         */
    14011629        do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity );
    14021630
    14031631        if ( empty( $comment_id ) ) {
     
    14341662                'date_recorded'     => false,
    14351663        ) );
    14361664
     1665        /**
     1666         * Filters the activity ID being requested.
     1667         *
     1668         * @since BuddyPress (1.2.0)
     1669         *
     1670         * @param BP_Activity_Activity ID returned by BP_Activity_Activity get_id method with provided arguments.
     1671         */
    14371672        return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id(
    14381673                $r['user_id'],
    14391674                $r['component'],
     
    14951730                'hide_sitewide'     => false
    14961731        ) );
    14971732
     1733        /**
     1734         * Fires before an activity item proceeds to be deleted.
     1735         *
     1736         * @since BuddyPress (1.5.0)
     1737         *
     1738         * @param array $args Array of arguments to be used with the activity deletion.
     1739         */
    14981740        do_action( 'bp_before_activity_delete', $args );
    14991741
    15001742        // Adjust the new mention count of any mentioned member
     
    15171759                }
    15181760        }
    15191761
     1762        /**
     1763         * Fires after the activity item has been deleted.
     1764         *
     1765         * @since BuddyPress (1.0.0)
     1766         *
     1767         * @param array $args Array of arguments used with the activity deletion.
     1768         */
    15201769        do_action( 'bp_activity_delete', $args );
     1770
     1771        /**
     1772         * Fires after the activity item has been deleted.
     1773         *
     1774         * @since BuddyPress (1.2.0)
     1775         *
     1776         * @param array $activity_ids_deleted Array of affected activity item IDs.
     1777         */
    15211778        do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
    15221779
    15231780        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
     
    15311788         * You should use bp_activity_delete() instead.
    15321789         *
    15331790         * @since BuddyPress (1.1.0)
    1534          * @deprecated BuddyPress (1.2)
     1791         * @deprecated BuddyPress (1.2.0)
    15351792         *
    15361793         * @uses wp_parse_args()
    15371794         * @uses bp_activity_delete()
     
    15741831         * You should use bp_activity_delete() instead.
    15751832         *
    15761833         * @since BuddyPress (1.1.0)
    1577          * @deprecated BuddyPress (1.2)
     1834         * @deprecated BuddyPress (1.2.0)
    15781835         *
    15791836         * @uses bp_activity_delete()
    15801837         *
     
    15991856         * You should use bp_activity_delete() instead.
    16001857         *
    16011858         * @since BuddyPress (1.1.0)
    1602          * @deprecated BuddyPress (1.2)
     1859         * @deprecated BuddyPress (1.2.0)
    16031860         *
    16041861         * @uses bp_activity_delete()
    16051862         *
     
    16351892 * @return bool True on success, false on failure
    16361893 */
    16371894function bp_activity_delete_comment( $activity_id, $comment_id ) {
    1638         /***
     1895
     1896        /**
     1897         * Filters whether BuddyPress should delete an activity comment or not.
     1898         *
    16391899         * You may want to hook into this filter if you want to override this function and
    16401900         * handle the deletion of child comments differently. Make sure you return false.
     1901         *
     1902         * @since BuddyPress (1.2.0)
     1903         *
     1904         * @param bool $true Whether BuddyPress should continue or not.
     1905         * @param int  $activity_id ID of the root activity item being deleted.
     1906         * @param int  $comment_id ID of the comment being deleted.
    16411907         */
    16421908        if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) {
    16431909                return false;
     
    16571923        // Recalculate the comment tree
    16581924        BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
    16591925
     1926        /**
     1927         * Fires at the end of the deletion of an activity comment, before the returning of success.
     1928         *
     1929         * @since BuddyPress (1.2.0)
     1930         *
     1931         * @param int $activity_id ID of the activity that has had a comment deleted from.
     1932         * @param int $comment_id ID of the comment that was deleted.
     1933         */
    16601934        do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
    16611935
    16621936        return true;
     
    17332007                }
    17342008        }
    17352009
     2010        /**
     2011         * Filters the activity permalink for the specified activity item.
     2012         *
     2013         * @since BuddyPress (1.2.0)
     2014         *
     2015         * @param array $array Array holding activity permalink and activity item object.
     2016         */
    17362017        return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );
    17372018}
    17382019
     
    18122093                }
    18132094        }
    18142095
     2096        /**
     2097         * Filters the activity content that had a thumbnail replace images.
     2098         *
     2099         * @since BuddyPress (1.2.0)
     2100         *
     2101         * @param string $content Activity content that had images replaced in.
     2102         * @param array  $matches Array of all image tags found in the posted content.
     2103         * @param array  $args Arguments passed into function creating the activity update.
     2104         */
    18152105        return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches, $args );
    18162106}
    18172107
     
    18232113 * @return bool True if user is allowed to mark activity items as spam.
    18242114 */
    18252115function bp_activity_user_can_mark_spam() {
     2116
     2117        /**
     2118         * Filters if the current user should be able to mark items as spam.
     2119         *
     2120         * @since BuddyPress (1.6.0)
     2121         *
     2122         * @param bool $moderate Whether or not the current user has bp_moderate capability.
     2123         */
    18262124        return apply_filters( 'bp_activity_user_can_mark_spam', bp_current_user_can( 'bp_moderate' ) );
    18272125}
    18282126
     
    18612159                add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 );
    18622160        }
    18632161
     2162        /**
     2163         * Fires at the end of the process to mark an activity item as spam.
     2164         *
     2165         * @since BuddyPress (1.6.0)
     2166         *
     2167         * @param BP_Activity_Activity $activity Activity item being marked as spam.
     2168         * @param string               $source Source of determination of spam status. For example "by_a_person" or "by_akismet".
     2169         */
    18642170        do_action( 'bp_activity_mark_as_spam', $activity, $source );
    18652171}
    18662172
     
    18992205                add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 );
    19002206        }
    19012207
     2208        /**
     2209         * Fires at the end of the process to mark an activity item as ham.
     2210         *
     2211         * @since BuddyPress (1.6.0)
     2212         *
     2213         * @param BP_Activity_Activity $activity Activity item being marked as ham.
     2214         * @param string               $source Source of determination of ham status. For example "by_a_person" or "by_akismet".
     2215         */
    19022216        do_action( 'bp_activity_mark_as_ham', $activity, $source );
    19032217}
    19042218