bp_activity_add (|字符串数组args美元''

添加活动项。

描述

参数

args美元

数组|字符串(可选)一个参数数组。

  • “id”
    (int | bool)传递活动ID以更新现有项,或传递false以创建新项。默认值:false。
  • “行动”
    (字符串)可选的。活动的动作/描述,典型的类似于“Joe发布了一个更新”。传递给这个参数的值将存储在数据库中,并在无法找到活动项的format_callback时用作回退(例如,当组件被禁用时)。只要你已经为你的$类型注册了一个format_callback,就没有必要包含这个参数- BP会自动生成它。看到bp_activity_set_action ()
  • “内容”
    (字符串)可选的。活动项的内容。
  • “组件”
    (字符串)与活动项关联的组件的唯一名称——“groups”、“profile”等。
  • “类型”
    (字符串)特定的活动类型,用于目录过滤。“new_blog_post”,“activity_update”等。
  • “primary_link”
    (字符串)可选的。此项目的URL,如RSS提要中使用的。默认为此活动项的永久链接页面的URL。
  • “user_id”
    (int | bool)可选的。与活动项关联的用户ID。如果项目与任何用户无关,则可以设置为false或0。Default:当前登录用户的ID。
  • “item_id”
    (int)可选的。关联项的ID。
  • “secondary_item_id”
    (int)可选的。次要关联项的ID。
  • “date_recorded”
    (字符串)可选的。记录项目时的GMT时间,格式为Y-m-d h:i:s。默认为当前时间。
  • “hide_sitewide”
    (保龄球)项目应该隐藏在站点范围的流吗?默认值:false。
  • “is_spam”
    (保龄球)该项目是否应该被标记为垃圾邮件?默认值:false。
  • “隐私”
    (字符串)活动隐私默认:公共。
  • “error_type”
    (字符串)可选的。错误类型。'bool'或'wp_error'。默认值:“bool”。

默认值:“

返回

(WP_Error | bool | int)成功时的活动ID。错误的错误。

文件:bp-activity / bp-activity-functions.php

function bp_activity_add($args = ") {$r = bp_parse_args($args, array('id' => false, //传递一个现有的活动id来更新现有的条目。'action' => ", //活动操作,例如:"Jon Doe发布了一个更新" 'content' => ", //可选:活动项的内容,例如:“BuddyPress太棒了!”'component' => false, //组件的名称/ID,例如groups, profile, mycomponent。'type' => false, //活动类型,例如activity_update, profile_updated。'primary_link' => ", //可选:RSS提要中此项目的主URL(默认为activity permalink)。'user_id' => bp_loggedin_user_id(), //可选:记录活动的用户,如果这个活动不是为一个用户,可以为false。'item_id' => false, //可选:记录的具体项的ID,如blog_id。'secondary_item_id' => false, //可选:用于进一步过滤的第二个ID,例如comment_id。 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded. 'hide_sitewide' => false, // Should this be hidden on the sitewide activity feed? 'is_spam' => false, // Is this activity item to be marked as spam? 'privacy' => 'public', // privacy of the activity 'error_type' => 'bool' ), 'activity_add' ); // Make sure we are backwards compatible. if ( empty( $r['component'] ) && !empty( $r['component_name'] ) ) { $r['component'] = $r['component_name']; } if ( empty( $r['type'] ) && !empty( $r['component_action'] ) ) { $r['type'] = $r['component_action']; } // Setup activity to be added. $activity = new BP_Activity_Activity( $r['id'] ); $activity->user_id = $r['user_id']; $activity->component = $r['component']; $activity->type = $r['type']; $activity->content = $r['content']; $activity->primary_link = $r['primary_link']; $activity->item_id = $r['item_id']; $activity->secondary_item_id = $r['secondary_item_id']; $activity->date_recorded = $r['recorded_time']; $activity->hide_sitewide = $r['hide_sitewide']; $activity->is_spam = $r['is_spam']; $activity->privacy = $r['privacy']; $activity->error_type = $r['error_type']; $activity->action = ! empty( $r['action'] ) ? $r['action'] : bp_activity_generate_action_string( $activity ); $save = $activity->save(); if ( 'wp_error' === $r['error_type'] && is_wp_error( $save ) ) { return $save; } elseif ('bool' === $r['error_type'] && false === $save ) { return false; } // If this is an activity comment, rebuild the tree. if ( 'activity_comment' === $activity->type ) { // Also clear the comment cache for the parent activity ID. wp_cache_delete( $activity->item_id, 'bp_activity_comments' ); BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id ); } wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); /** * Fires at the end of the execution of adding a new activity item, before returning the new activity item ID. * * @since BuddyPress 1.1.0 * * @param array $r Array of parsed arguments for the activity item being added. */ do_action( 'bp_activity_add', $r ); return $activity->id; }

更新日志

更新日志
版本 描述
BuddyPress 2.6.0添加了'error_type'参数到$args。 BuddyPress 2.6.0添加了'error_type'参数到$args。
BuddyPress 1.1.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队