/** * Get the query params for collections of plugins. * * @since 0.1.0 * * @return array */ public function get_collection_params() { $params = parent::get_collection_params(); $params['context']['default'] = 'view'; $params['exclude'] = array('description' => __('Ensure result set excludes specific IDs.', 'buddypress'), 'type' => 'array', 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list'); $params['include'] = array('description' => __('Ensure result set includes specific IDs.', 'buddypress'), 'type' => 'array', 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list'); $params['order'] = array('description' => __('Order sort attribute ascending or descending.', 'buddypress'), 'type' => 'string', 'default' => 'desc', 'enum' => array('asc', 'desc'), 'validate_callback' => 'rest_validate_request_arg'); $params['after'] = array('description' => __('Limit result set to items published after a given ISO8601 compliant date.', 'buddypress'), 'type' => 'string', 'format' => 'date-time', 'validate_callback' => 'rest_validate_request_arg'); $params['per_page'] = array('description' => __('Maximum number of results returned per result set.', 'buddypress'), 'default' => 20, 'type' => 'integer', 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg'); $params['page'] = array('description' => __('Offset the result set by a specific number of pages of results.', 'buddypress'), 'default' => 1, 'type' => 'integer', 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg'); $params['author'] = array('description' => __('Limit result set to items created by specific authors.', 'buddypress'), 'type' => 'array', 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg'); $params['status'] = array('default' => 'published', 'description' => __('Limit result set to items with a specific status.', 'buddypress'), 'type' => 'string', 'enum' => array('published', 'spam'), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg'); $params['primary_id'] = array('description' => __('Limit result set to items with a specific prime assocation.', 'buddypress'), 'type' => 'array', 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list'); $params['secondary_id'] = array('description' => __('Limit result set to items with a specific secondary assocation.', 'buddypress'), 'type' => 'array', 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list'); $params['component'] = array('description' => __('Limit result set to items with a specific BuddyPress component.', 'buddypress'), 'type' => 'string', 'enum' => array_keys(bp_core_get_components()), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg'); $params['type'] = array('description' => __('Limit result set to items with a specific activity type.', 'buddypress'), 'type' => 'string', 'enum' => array_keys(bp_activity_get_types()), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg'); $params['search'] = array('description' => __('Limit result set to items that match this search query.', 'buddypress'), 'default' => '', 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg'); return $params; }
/** * Markup for the "filter" part of the form (i.e. which activity type to display) * * @param string $which 'top' or 'bottom' * @since BuddyPress (1.6) */ function extra_tablenav($which) { if ('bottom' == $which) { return; } $selected = !empty($_REQUEST['activity_type']) ? $_REQUEST['activity_type'] : ''; // Get all types of activities, and sort alphabetically. $actions = bp_activity_get_types(); natsort($actions); ?> <div class="alignleft actions"> <select name="activity_type"> <option value="" <?php selected(!$selected); ?> ><?php _e('Show all activity types', 'buddypress'); ?> </option> <?php foreach ($actions as $k => $v) { ?> <option value="<?php echo esc_attr($k); ?> " <?php selected($k, $selected); ?> ><?php echo esc_html($v); ?> </option> <?php } ?> </select> <?php submit_button(__('Filter', 'buddypress'), 'secondary', false, false, array('id' => 'post-query-submit')); ?> </div> <?php }
/** * Echo a list of all registered activity types for use in dropdowns or checkbox lists. * * @since BuddyPress (1.7.0) * * @param string $output Optional. Either 'select' or 'checkbox'. Default: 'select'. * @param array $args { * Optional extra arguments. * @type string $checkbox_name When returning checkboxes, sets the 'name' * attribute. * @type array|string $selected A list of types that should be checked/ * selected. * } */ function bp_activity_types_list($output = 'select', $args = '') { $args = bp_parse_args($args, array('checkbox_name' => 'bp_activity_types', 'selected' => array())); $activities = bp_activity_get_types(); natsort($activities); // Loop through the activity types and output markup foreach ($activities as $type => $description) { // See if we need to preselect the current type $checked = checked(true, in_array($type, (array) $args['selected']), false); $selected = selected(true, in_array($type, (array) $args['selected']), false); // Switch output based on the element switch ($output) { case 'select': printf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($type), $selected, esc_html($description)); break; case 'checkbox': printf('<label style="">%1$s<input type="checkbox" name="%2$s[]" value="%3$s" %4$s/></label>', esc_html($description), esc_attr($args['checkbox_name']), esc_attr($type), $checked); break; } /** * Fires at the end of the listing of activity types. * * This is a variable action hook. The actual hook to use will depend on the output type specified. * Two default hooks are bp_activity_types_list_select and bp_activity_types_list_checkbox. * * @since BuddyPress (1.7.0) * * @param array $args Array of arguments passed into function. * @param string $type Activity type being rendered in the output. * @param string $description Description of the activity type being rendered. */ do_action('bp_activity_types_list_' . $output, $args, $type, $description); } // Backpat with BP-Default for dropdown boxes only if ('select' === $output) { do_action('bp_activity_filter_options'); } }
/** * Echo a list of all registered activity types for use in dropdowns or checkbox lists. * * @since BuddyPress (1.7) * * @param string $output Optional. Either 'select' or 'checkbox'. Default: 'select'. * @param array $args { * Optional extra arguments. * @type string $checkbox_name When returning checkboxes, sets the 'name' * attribute. * @type array|string $selected A list of types that should be checked/ * selected. * } */ function bp_activity_types_list($output = 'select', $args = '') { $args = bp_parse_args($args, array('checkbox_name' => 'bp_activity_types', 'selected' => array())); $activities = bp_activity_get_types(); natsort($activities); // Loop through the activity types and output markup foreach ($activities as $type => $description) { // See if we need to preselect the current type $checked = checked(true, in_array($type, (array) $args['selected']), false); $selected = selected(true, in_array($type, (array) $args['selected']), false); // Switch output based on the element switch ($output) { case 'select': printf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($type), $selected, esc_html($description)); break; case 'checkbox': printf('<label style="">%1$s<input type="checkbox" name="%2$s[]" value="%3$s" %4$s/></label>', esc_html($description), esc_attr($args['checkbox_name']), esc_attr($type), $checked); break; } // Allow custom markup do_action('bp_activity_types_list_' . $output, $args, $type, $description); } // Backpat with BP-Default for dropdown boxes only if ('select' === $output) { do_action('bp_activity_filter_options'); } }
/** * Display function for the allowed activity types * * @package BP Reshare * @subpackage Admin * @since version 1.0 * * @uses bp_get_option() to get the stored setting * @uses bp_activity_get_types() to get the available activity types * @uses esc_html() to sanitize outputs * @return string html output */ public function reshare_types() { $activity_types = bp_activity_get_types(); $reshare_types = bp_get_option('buddyreshare-allowed-types', array('activity_update', 'reshare_update')); foreach ($activity_types as $type => $caption) { if (in_array($type, array('activity_comment', 'friendship_created', 'friendship_accepted', 'new_avatar', 'new_member', 'created_group', 'joined_group'))) { continue; } ?> <input id="buddyreshare-allowed-types-<?php echo $type; ?> " name="buddyreshare-allowed-types[<?php echo $type; ?> ]" type="checkbox" value="1" <?php checked(in_array($type, $reshare_types)); ?> > <label for="buddyreshare-allowed-types-<?php echo $type; ?> "><?php echo esc_html($caption); ?> </label> <br/> <?php } }