/** * Verify the captcha answer * * @since 1.0.3 * * @return void Adds error element to BP's signup errors object. */ public static function validate_captcha_registration_field() { if (!isset($_POST['g-recaptcha-response']) || !($validated = self::captcha_verification())) { buddypress()->signup->errors['failed_recaptcha_verification'] = self::$error_message; } do_action('ncr_failed_recaptcha_verification', $validated); }
/** * Enqueue the jQuery libraries for handling drag/drop/sort. * * @since 1.5.0 */ function xprofile_add_admin_js() { if (!empty($_GET['page']) && strpos($_GET['page'], 'bp-profile-setup') !== false) { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-ui-mouse'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_script('jquery-ui-sortable'); $min = bp_core_get_minified_asset_suffix(); wp_enqueue_script('xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array('jquery', 'jquery-ui-sortable'), bp_get_version()); // Localize strings. // supports_options_field_types is a dynamic list of field // types that support options, for use in showing/hiding the // "please enter options for this field" section. $strings = array('do_settings_section_field_types' => array(), 'do_autolink' => ''); foreach (bp_xprofile_get_field_types() as $field_type => $field_type_class) { $field = new $field_type_class(); if ($field->do_settings_section()) { $strings['do_settings_section_field_types'][] = $field_type; } } // Load 'autolink' setting into JS so that we can provide smart defaults when switching field type. if (!empty($_GET['field_id'])) { $field_id = intval($_GET['field_id']); // Pull the raw data from the DB so we can tell whether the admin has saved a value yet. $strings['do_autolink'] = bp_xprofile_get_meta($field_id, 'field', 'do_autolink'); } wp_localize_script('xprofile-admin-js', 'XProfileAdmin', $strings); } }
/** * Load the component into the $bp global. * * @since 1.0.0 */ function bp_mute_load_component() { if (!bp_is_active('activity')) { return; } buddypress()->mute = new Mute_Component(); }
/** * @ticket BP7237 * @ticket BP6643 * @ticket BP7245 */ public function test_last_activity_should_bust_activity_with_last_activity_cache() { global $wpdb; $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $time_1 = date('Y-m-d H:i:s', time() - HOUR_IN_SECONDS); $time_2 = date('Y-m-d H:i:s', time() - HOUR_IN_SECONDS * 2); bp_update_user_last_activity($u1, $time_1); bp_update_user_last_activity($u2, $time_2); $activity_args_a = array('filter' => array('object' => buddypress()->members->id, 'action' => 'last_activity'), 'max' => 1); $activity_args_b = array('filter' => array('action' => 'new_member'), 'fields' => 'ids'); // Prime bp_activity and bp_activity_with_last_activity caches. $a1 = bp_activity_get($activity_args_a); $expected = array($u1, $u2); $found = array_map('intval', wp_list_pluck($a1['activities'], 'user_id')); $this->assertSame($expected, $found); $b1 = bp_activity_get($activity_args_b); // Bump u2 activity so it should appear first. $new_time = date('Y-m-d H:i:s', time() - HOUR_IN_SECONDS); bp_update_user_last_activity($u2, $new_time); $a2 = bp_activity_get($activity_args_a); $expected = array($u2, $u1); $found = array_map('intval', wp_list_pluck($a2['activities'], 'user_id')); $this->assertSame($expected, $found); $num_queries = $wpdb->num_queries; // bp_activity cache should not have been touched. $b2 = bp_activity_get($activity_args_b); $this->assertEqualSets($b1, $b2); $this->assertSame($num_queries, $wpdb->num_queries); }
public function setUp() { parent::setUp(); buddypress()->members->types = array(); $this->old_current_user = get_current_user_id(); $this->set_current_user($this->factory->user->create(array('user_login' => 'paulgibbs', 'role' => 'subscriber'))); }
/** * Enqueue @mentions JS. * * @since 2.1.0 */ function bp_activity_mentions_script() { if (!bp_activity_maybe_load_mentions_scripts()) { return; } // Special handling for New/Edit screens in wp-admin. if (is_admin()) { if (!get_current_screen() || !in_array(get_current_screen()->base, array('page', 'post')) || !post_type_supports(get_current_screen()->post_type, 'editor')) { return; } } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array('jquery', 'jquery-atwho'), bp_get_version(), true); wp_enqueue_style('bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version()); wp_style_add_data('bp-mentions-css', 'rtl', true); if ($min) { wp_style_add_data('bp-mentions-css', 'suffix', $min); } // If the script has been enqueued, let's attach our mentions TinyMCE init callback. add_filter('tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2); /** * Fires at the end of the Activity Mentions script. * * This is the hook where BP components can add their own prefetched results * friends to the page for quicker @mentions lookups. * * @since 2.1.0 */ do_action('bp_activity_mentions_prime_results'); }
/** * Register member types. * * If the field type is set and has options. These options will dynamically build the member type * Use the name to set options into the xProfile Field Admin UI eg: Has CF * * @since 1.0.0 */ function cfbgr_register_member_types() { $saved_option = (int) bp_get_option('cfbgr_xfield_id', 0); if (empty($saved_option)) { return; } $field = xprofile_get_field($saved_option); // This case means the option was not deleted when it oughts to be if (empty($field->type_obj) || !is_a($field->type_obj, 'CF_BG_Member_Type_Field_Type')) { bp_delete_option('cfbgr_xfield_id'); return; } // Object cache this field buddypress()->groups->restrictions->member_type_field = $field; $options = $field->get_children(true); if (!is_array($options)) { return; } foreach ($options as $member_type) { if (empty($member_type->name)) { continue; } bp_register_member_type(sanitize_key($member_type->name), array('labels' => array('name' => $member_type->name))); } }
/** * Profile is default component so let's make it the first tab of xprofile nav */ function templatepack_maybe_change_nav_position() { $bp = buddypress(); if (defined('BP_DEFAULT_COMPONENT') && 'profile' == BP_DEFAULT_COMPONENT) { $bp->bp_nav['profile']['position'] = 1; } }
function test_bp_core_ajax_url() { $forced = force_ssl_admin(); // (1) HTTPS off force_ssl_admin(false); $_SERVER['HTTPS'] = 'off'; // (1a) Front-end $this->go_to('/'); $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http')); // (1b) Dashboard $this->go_to('/wp-admin'); $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http')); // (2) FORCE_SSL_ADMIN force_ssl_admin(true); // (2a) Front-end $this->go_to('/'); $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http')); // (2b) Dashboard $this->go_to('/wp-admin'); $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'https')); force_ssl_admin($forced); // (3) Multisite, root blog other than 1 if (is_multisite()) { $original_root_blog = bp_get_root_blog_id(); $blog_id = $this->factory->blog->create(array('path' => '/path' . rand() . time() . '/')); buddypress()->root_blog_id = $blog_id; $blog_url = get_blog_option($blog_id, 'siteurl'); $this->go_to(trailingslashit($blog_url)); buddypress()->root_blog_id = $original_root_blog; $ajax_url = bp_core_ajax_url(); $this->go_to('/'); $this->assertEquals($blog_url . '/wp-admin/admin-ajax.php', $ajax_url); } }
/** * set current component_type to groups if we are on groups page * @see mpp_get_current_component() * @param type $component * @return type */ function mpp_current_component_type_for_groups($component) { if (bp_is_active('groups') && bp_is_group()) { return buddypress()->groups->id; } return $component; }
/** * Bootstrap the XProfile component. */ function bp_setup_xprofile() { $bp = buddypress(); if (!isset($bp->profile->id)) { $bp->profile = new BP_XProfile_Component(); } }
function mpp_gallery_archive_redirect() { if (is_post_type_archive(mpp_get_gallery_post_type()) && mediapress()->is_bp_active() && mpp_get_option('has_gallery_directory') && isset(buddypress()->pages->mediapress->id)) { wp_safe_redirect(get_permalink(buddypress()->pages->mediapress->id), 301); exit(0); } }
/** * @group get_total_count * @ticket BP5300 */ public function test_get_total_count_null_component_name() { $u = $this->factory->user->create(); $n1 = $this->factory->notification->create(array('component_name' => 'groups', 'user_id' => $u)); $n2 = $this->factory->notification->create(array('component_name' => 'messages', 'user_id' => $u)); // temporarily turn on groups, shut off messages $groups_toggle = isset(buddypress()->active_components['groups']); $messages_toggle = isset(buddypress()->active_components['messages']); buddypress()->active_components['groups'] = 1; unset(buddypress()->active_components['messages']); $n = BP_Notifications_Notification::get_total_count(array('user_id' => $u)); // Check that the correct items are pulled up $this->assertEquals(1, $n); // reset copmonent toggles if ($groups_toggle) { buddypress()->active_components['groups'] = 1; } else { unset(buddypress()->active_components['groups']); } if ($messages_toggle) { buddypress()->active_components['messages'] = 1; } else { unset(buddypress()->active_components['messages']); } }
/** * Add the User Admin top-level menu to user pages. * * @since 1.5.0 */ function bp_members_admin_bar_user_admin_menu() { global $wp_admin_bar; // Only show if viewing a user if (!bp_is_user()) { return false; } // Don't show this menu to non site admins or if you're viewing your own profile if (!current_user_can('edit_users') || bp_is_my_profile()) { return false; } $bp = buddypress(); // Unique ID for the 'My Account' menu $bp->user_admin_menu_id = 'user-admin'; // Add the top-level User Admin button $wp_admin_bar->add_menu(array('id' => $bp->user_admin_menu_id, 'title' => __('Edit Member', 'buddypress'), 'href' => bp_displayed_user_domain())); if (bp_is_active('xprofile')) { // User Admin > Edit this user's profile $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => $bp->user_admin_menu_id . '-edit-profile', 'title' => __("Edit Profile", 'buddypress'), 'href' => bp_get_members_component_link('profile', 'edit'))); // User Admin > Edit this user's avatar if (buddypress()->avatar->show_avatars) { $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => $bp->user_admin_menu_id . '-change-avatar', 'title' => __("Edit Profile Photo", 'buddypress'), 'href' => bp_get_members_component_link('profile', 'change-avatar'))); } } if (bp_is_active('settings')) { // User Admin > Spam/unspam $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => $bp->user_admin_menu_id . '-user-capabilities', 'title' => __('User Capabilities', 'buddypress'), 'href' => bp_displayed_user_domain() . 'settings/capabilities/')); // User Admin > Delete Account $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => $bp->user_admin_menu_id . '-delete-user', 'title' => __('Delete Account', 'buddypress'), 'href' => bp_displayed_user_domain() . 'settings/delete-account/')); } }
/** * Enqueue the jQuery libraries for handling drag/drop/sort. * * @since 1.5.0 */ function xprofile_add_admin_js() { if (!empty($_GET['page']) && strpos($_GET['page'], 'bp-profile-setup') !== false) { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-ui-mouse'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_script('jquery-ui-sortable'); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array('jquery', 'jquery-ui-sortable'), bp_get_version()); // Localize strings. // supports_options_field_types is a dynamic list of field // types that support options, for use in showing/hiding the // "please enter options for this field" section. $strings = array('supports_options_field_types' => array()); foreach (bp_xprofile_get_field_types() as $field_type => $field_type_class) { $field = new $field_type_class(); if ($field->supports_options) { $strings['supports_options_field_types'][] = $field_type; } } wp_localize_script('xprofile-admin-js', 'XProfileAdmin', $strings); } }
function cfbgr_migrate_xprofile_as_member_types() { global $wpdb; $buddypress = buddypress(); // Description of this tool, displayed to the user $statement = __('Migrating/Resetting xProfile data as member types: %s', 'buddypress-group-restrictions'); // Default to failure text $result = __('No xProfile data needs to be migrated or reset.', 'buddypress-group-restrictions'); // Default to unrepaired $repair = 0; $field = (int) bp_get_option('cfbgr_xfield_id', 0); if (empty($field)) { return array(0, sprintf($statement, $result)); } $member_types = bp_get_member_types(); // Walk through all users on the site $user_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->users}"); foreach ($user_ids as $user_id) { $value = sanitize_key(xprofile_get_field_data($field, $user_id)); // Do we have a matching member type ? if (isset($member_types[$value])) { // Set member types if empty or different if ($value !== bp_get_member_type($user_id)) { bp_set_member_type($user_id, $value); $repair += 1; } } } $result = sprintf(__('%d migrated or reset', 'buddypress-group-restrictions'), $repair); // All done! return array(0, sprintf($statement, $result)); }
/** * Load the Forums directory. */ function bp_forums_directory_forums_setup() { // Get BuddyPress once $bp = buddypress(); if (bp_is_forums_component() && (!bp_current_action() || 'tag' == bp_current_action() && bp_action_variables()) && !bp_current_item()) { if (!bp_forums_has_directory()) { return false; } if (!bp_forums_is_installed_correctly()) { bp_core_add_message(__('The forums component has not been set up yet.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain()); } bp_update_is_directory(true, 'forums'); do_action('bbpress_init'); // Check to see if the user has posted a new topic from the forums page. if (isset($_POST['submit_topic']) && bp_is_active('forums')) { check_admin_referer('bp_forums_new_topic'); $bp->groups->current_group = groups_get_group(array('group_id' => $_POST['topic_group_id'])); if (!empty($bp->groups->current_group->id)) { // Auto join this user if they are not yet a member of this group if (!bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) { groups_join_group($bp->groups->current_group->id); } $error_message = ''; $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id'); if (!empty($forum_id)) { if (empty($_POST['topic_title'])) { $error_message = __('Please provide a title for your forum topic.', 'buddypress'); } else { if (empty($_POST['topic_text'])) { $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress'); } } if ($error_message) { bp_core_add_message($error_message, 'error'); $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum'; } else { if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) { bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error'); $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum'; } else { bp_core_add_message(__('The topic was created successfully', 'buddypress')); $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/'; } } bp_core_redirect($redirect); } else { bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error'); bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink())); } } else { bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error'); bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink())); } } do_action('bp_forums_directory_forums_setup'); bp_core_load_template(apply_filters('bp_forums_template_directory_forums_setup', 'forums/index')); } }
/** * Includes. */ protected function includes() { require buddypress()->follow->path . '/modules/activity-functions.php'; // Add dependant hooks for the 'activity' module if (true === (bool) apply_filters('bp_follow_enable_activity', false)) { require buddypress()->follow->path . '/modules/activity-module.php'; } }
/** * If you start me up.. */ public static function start() { $bp = buddypress(); if (empty($bp->core->front_end_attachments)) { $bp->core->front_end_attachments = new self(); } return $bp->core->front_end_attachments; }
public function bp_displayed_user_fullname($default) { if (!buddypress()->displayed_user->userdata) { return $default; } buddypress()->displayed_user->userdata->id = buddypress()->displayed_user->userdata->ID; return $this->display_name(buddypress()->displayed_user->userdata, $default); }
function tearDown() { parent::tearDown(); $bp = buddypress(); _unregister_post_type('using_old_filter'); remove_filter('bp_blogs_record_post_post_types', array($this, 'filter_post_types'), 10); remove_filter('bp_blogs_record_comment_post_types', array($this, 'filter_post_types'), 10); }
/** * Let's start */ public static function start() { $bp = buddypress(); if (empty($bp->altctrl)) { $bp->altctrl = new self(); } return $bp->altctrl; }
function messages_add_autocomplete_css() { if (bp_is_messages_component() && bp_is_current_action('compose')) { $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style('bp-messages-autocomplete', buddypress()->plugin_url . "bp-messages/css/autocomplete/jquery.autocompletefb{$min}.css", array(), bp_get_version()); wp_print_styles(); } }
function plugin_registers_post_type() { $activity_categories = cjtheme_activity_categories(); foreach ($activity_categories as $key => $activity_category) { $args = array('public' => true, 'labels' => array('name' => __($activity_category, 'cjtheme'), 'singular_name' => __($activity_category, 'cjtheme'), 'bp_activity_admin_filter' => 'New activity published in ' . $activity_category, 'bp_activity_front_filter' => __($activity_category, 'cjtheme'), 'bp_activity_new_post' => __('%1$s posted a new <a href="%2$s">question</a>', 'cjtheme'), 'bp_activity_new_post_ms' => __('%1$s posted a new <a href="%2$s">question</a>, on the site %3$s', 'cjtheme')), 'supports' => array('title', 'editor', 'buddypress-activity'), 'bp_activity' => array('component_id' => buddypress()->activity->id, 'action_id' => $key, 'contexts' => array('activity', 'member'), 'position' => 40, 'activity_comment' => true)); register_post_type($key, $args); } }
/** * Get all plural labels * * @return type array */ function bmt_plural_labels_array() { $member_types = buddypress()->members->types; $user_ids = array(); foreach ($member_types as $key => $member_type) { $user_ids[$key] = $member_type->labels['name']; } return $user_ids; }
/** * Component global variables * * You'll want to customize the values in here, so they match whatever your * needs are. * * @since BuddyPress Templates (1.0) */ protected function setup_globals() { $bp = buddypress(); $this->id = 'templatepack'; $this->name = __('BuddyPress Templates', 'buddypress'); $this->version = bp_get_version(); $this->dir = plugin_dir_path(__FILE__); $this->url = plugin_dir_url(__FILE__); }
function __construct() { $widget_ops = array('description' => __('A dynamic list of recently active, popular, and newest groups', 'buddypress'), 'classname' => 'widget_bp_groups_widget buddypress widget'); parent::__construct(false, _x('(BuddyPress) Groups', 'widget name', 'buddypress'), $widget_ops); if (is_active_widget(false, false, $this->id_base) && !is_admin() && !is_network_admin()) { $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array('jquery'), bp_get_version()); } }
/** * Component global variables * * You'll want to customize the values in here, so they match whatever your * needs are. * * @since BuddyPress (1.7) * @access private */ protected function setup_globals() { $bp = buddypress(); $this->id = 'legacy'; $this->name = __('BuddyPress Legacy', 'buddypress'); $this->version = bp_get_version(); $this->dir = trailingslashit($bp->themes_dir . '/bp-legacy'); $this->url = trailingslashit($bp->themes_url . '/bp-legacy'); }
public function tearDown() { $bp = buddypress(); $bp->activity->actions = $this->reset_actions; if ($this->reset_actions_sorted) { $bp->activity->actions_sorted = true; } else { unset($bp->activity->actions_sorted); } }
public function setup_settings_privacy_nav($wp_admin_nav) { // Setup the logged in user variables if (is_rtmedia_privacy_user_overide()) { $settings_link = trailingslashit(bp_loggedin_user_domain() . bp_get_settings_slug()); // Add the "Profile" subnav item $wp_admin_nav[] = array('parent' => 'my-account-' . buddypress()->settings->id, 'id' => 'my-account-' . buddypress()->settings->id . '-privacy', 'title' => _x('Privacy', 'My Account Privacy sub nav', 'rtmedia'), 'href' => trailingslashit($settings_link . 'privacy')); } return $wp_admin_nav; }