bp_activity_set_post_type_tracking_args

Set tracking arguments for a given post type.

Description

bp_activity_set_post_type_tracking_args( (string) $post_type = '', (array) $args = array() ); 

Parameters (2)

0. $post_type — Optional. (string) => ''
The name of the post type, as registered with WordPress. Eg post or page..
1. $args — Optional. (array) => array()
An associative array of tracking parameters. All items are optional.

Options

  • bp_activity_admin_filter (string) => ''

    String to use in the Dashboard > Activity dropdown.

  • bp_activity_front_filter (string) => ''

    String to use in the front-end dropdown.

  • bp_activity_new_post (string) => ''

    String format to use for generating the activity action. Should be a translatable string where %1$s is replaced by a user link and %2$s is the URL of the newly created post.

  • bp_activity_new_post_ms (string) => ''

    String format to use for generating the activity action on Multisite. Should be a translatable string where %1$s is replaced by a user link, %2$s is the URL of the newly created post, and %3$s is a link to the site.

  • component_id (string) => ''

    ID of the BuddyPress component to associate the activity item.

  • action_id (string) => ''

    Value for the type param of the new activity item.

  • format_callback (callable) => null

    Callback for formatting the activity action string. Default: bp_activity_format_activity_action_custom_post_type_post..

  • contexts (array) => null

    The directory contexts in which the filter will show. Default: array( activity ).

  • position (array) => null

    Position of the item in filter dropdowns.

  • singular (string) => ''

    Singular, translatable name of the post type item. If no value is provided, it's pulled from the singular_name of the post type.

array(

    /**
     * String to use in the Dashboard > Activity dropdown.
     *
     * @type string
     * @default ''
     */
    'bp_activity_admin_filter' => '',

    /**
     * String to use in the front-end dropdown.
     *
     * @type string
     * @default ''
     */
    'bp_activity_front_filter' => '',

    /**
     * String format to use for generating the activity action. Should be a translatable string
     * where %1$s is replaced by a user link and %2$s is the URL of the newly created post.
     *
     * @type string
     * @default ''
     */
    'bp_activity_new_post' => '',

    /**
     * String format to use for generating the activity action on Multisite. Should be a
     * translatable string where %1$s is replaced by a user link, %2$s is the URL of the newly created
     * post, and %3$s is a link to the site.
     *
     * @type string
     * @default ''
     */
    'bp_activity_new_post_ms' => '',

    /**
     * ID of the BuddyPress component to associate the activity item.
     *
     * @type string
     * @default ''
     */
    'component_id' => '',

    /**
     * Value for the 'type' param of the new activity item.
     *
     * @type string
     * @default ''
     */
    'action_id' => '',

    /**
     * Callback for formatting the activity action string. Default:
     * 'bp_activity_format_activity_action_custom_post_type_post'.
     *
     * @type callable
     * @default null
     */
    'format_callback' => null,

    /**
     * The directory contexts in which the filter will show. Default: array( 'activity' ).
     *
     * @type array
     * @default null
     */
    'contexts' => null,

    /**
     * Position of the item in filter dropdowns.
     *
     * @type array
     * @default null
     */
    'position' => null,

    /**
     * Singular, translatable name of the post type item. If no value is provided, it's pulled from
     * the 'singular_name' of the post type.
     *
     * @type string
     * @default ''
     */
    'singular' => ''
);        


Usage

  1. if ( !function_exists( 'bp_activity_set_post_type_tracking_args' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // The name of the post type, as registered with WordPress. Eg 'post' or 'page'. 
  5. $post_type = ''; 
  6.  
  7. // An associative array of tracking parameters. All items are optional. 
  8. $args = array( 
  9. 'bp_activity_admin_filter' => '', 
  10. 'bp_activity_front_filter' => '', 
  11. 'bp_activity_new_post' => '', 
  12. 'bp_activity_new_post_ms' => '', 
  13. 'component_id' => '', 
  14. 'action_id' => '', 
  15. 'format_callback' => null, 
  16. 'contexts' => null, 
  17. 'position' => null, 
  18. 'singular' => '' 
  19. ); 
  20.  
  21. // NOTICE! Understand what this does before running. 
  22. $result = bp_activity_set_post_type_tracking_args($post_type, $args); 
  23.  

Defined (1)

The function is defined in the following location(s).

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array() ) { 
  2. global $wp_post_types; 
  3.  
  4. if ( empty( $wp_post_types[ $post_type ] ) || ! post_type_supports( $post_type, 'buddypress-activity' ) || ! is_array( $args ) ) { 
  5. return false; 
  6.  
  7. $activity_labels = array( 
  8. /** Post labels */ 
  9. 'bp_activity_admin_filter',  
  10. 'bp_activity_front_filter',  
  11. 'bp_activity_new_post',  
  12. 'bp_activity_new_post_ms',  
  13. /** Comment labels */ 
  14. 'bp_activity_comments_admin_filter',  
  15. 'bp_activity_comments_front_filter',  
  16. 'bp_activity_new_comment_ms' 
  17. ); 
  18.  
  19. // Labels are loaded into the post type object. 
  20. foreach ( $activity_labels as $label_type ) { 
  21. if ( ! empty( $args[ $label_type ] ) ) { 
  22. $wp_post_types[ $post_type ]->labels->{$label_type} = $args[ $label_type ]; 
  23. unset( $args[ $label_type ] ); 
  24.  
  25. // If there are any additional args, put them in the bp_activity attribute of the post type. 
  26. if ( ! empty( $args ) ) { 
  27. $wp_post_types[ $post_type ]->bp_activity = $args;