/** * profile_fields_screen() * * Adds extra field to profile screen */ function register_profile_fields() { //HACK: to allow options global $bp; (array) ($bp->profile->field_types[] = 'option'); if (BPSP_Roles::field_group_id_from_name(__('Courseware', 'bpsp'))) { return false; } $bpsp_group_id = xprofile_insert_field_group(array(name => __('Courseware', 'bpsp'), description => __('Students and Teachers fields. Do not delete as long as you use BuddyPress ScholarPress Courseware!', 'bpsp'), can_delete => false)); if (!$bpsp_group_id) { wp_die(__('BuddyPress Courseware error when saving xProfile group.', 'bpsp')); } /* Create the radio buttons */ xprofile_insert_field(array(field_group_id => $bpsp_group_id, name => __('Role', 'bpsp'), can_delete => false, description => __('Your role when using Courseware. Every request requires moderation. Please be patient until an administrator reviews it.', 'bpsp'), is_required => false, type => 'radio')); $bpsp_field_id = xprofile_get_field_id_from_name(__('Role', 'bpsp')); if (!$bpsp_field_id) { wp_die(__('BuddyPress Courseware error when saving xProfile field.', 'bpsp')); } /* Create the radio options */ xprofile_insert_field(array(field_group_id => $bpsp_group_id, parent_id => $bpsp_field_id, name => __('Teacher', 'bpsp'), can_delete => false, is_required => false, type => 'option')); xprofile_insert_field(array(field_group_id => $bpsp_group_id, parent_id => $bpsp_field_id, name => __('Student', 'bpsp'), can_delete => false, is_required => false, type => 'option', is_default_option => true)); xprofile_insert_field(array(field_group_id => $bpsp_group_id, parent_id => $bpsp_field_id, name => __('Apply for Teacher', 'bpsp'), can_delete => false, is_required => false, type => 'option')); if (!xprofile_get_field_id_from_name(__('Teacher', 'bpsp')) || !xprofile_get_field_id_from_name(__('Student', 'bpsp')) || !xprofile_get_field_id_from_name(__('Apply for Teacher', 'bpsp'))) { wp_die(__('BuddyPress Courseware error when saving xProfile field options.', 'bpsp')); } return true; }
function wplms_setup_settings($file) { global $wpdb; //flush_rewrite_rules(); //Set important settings update_option('permalink_structure', '/%postname%/'); update_option('membership_active', 'yes'); update_option('require_name_email', ''); update_option('comment_moderation', ''); update_option('comment_whitelist', ''); update_option('comment_registration', 1); update_option('posts_per_page', 6); update_option('comments_per_page', 5); update_option('users_can_register', 1); update_option('default_role', 'student'); $bp_active_components = array('xprofile' => 1, 'settings' => 1, 'friends' => 1, 'messages' => 1, 'activity' => 1, 'notifications' => 1, 'members' => 1); update_option('bp-active-components', $bp_active_components); $options_pages = array('take_course_page' => 'course-status', 'create_course' => 'edit-course', 'certificate_page' => 'default-certificate-template'); $bp_pages = array('activity' => 'activity', 'members' => 'members', 'course' => 'all-courses', 'register' => 'register', 'activate' => 'activate'); $options_panel = array('last_tab' => 10, 'header_fix' => 1, 'course_search' => 0, 'loop_number' => 5, 'take_course_page' => 268, 'create_course' => 2087, 'instructor_add_students' => 1, 'instructor_assign_badges' => 1, 'instructor_extend_subscription' => 1, 'certificate_page' => 1063, 'course_duration_display_parameter' => 86400, 'google_fonts' => array('0' => 'Roboto', '1' => 'Raleway'), 'top_footer_columns' => 'col-md-3 col-sm-6', 'bottom_footer_columns' => 'col-md-3 col-sm-6'); foreach ($options_pages as $key => $page) { $page_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", "{$page}")); if (isset($page_id) && is_numeric($page_id)) { $options_panel[$key] = $page_id; } else { unset($options_panel[$key]); } } update_option(THEME_SHORT_NAME, $options_panel); foreach ($bp_pages as $key => $page) { $page_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", "{$page}")); if (isset($page_id) && is_numeric($page_id)) { $bp_pages[$key] = $page_id; } else { unset($bp_pages[$key]); } } update_option('bp-pages', $bp_pages); /*==================================================*/ /* WIDGETS AND SIDEBARS /*==================================================*/ if ($file == 'sampledata') { $sidebars_file = apply_filters('wplms_setup_sidebars_file', VIBE_PATH . '/setup/data/sidebars.txt'); if (file_exists($sidebars_file)) { $myfile = fopen($sidebars_file, "r") or die("Unable to open file!" . $sidebars_file); while (!feof($myfile)) { $string = fgets($myfile); } fclose($myfile); $code = base64_decode(trim($string)); if (is_string($code)) { $code = unserialize($code); if (is_array($code)) { update_option('sidebars_widgets', $code); } } } //================= $widgets_file = apply_filters('wplms_setup_widgets_file', VIBE_PATH . '/setup/data/widgets.txt'); if (file_exists($widgets_file)) { $myfile = fopen($widgets_file, "r") or die("Unable to open file!" . $widgets_file); while (!feof($myfile)) { $string = fgets($myfile); } fclose($myfile); $code = base64_decode(trim($string)); if (is_string($code)) { $code = unserialize($code); if (is_array($code)) { foreach ($code as $key => $option) { update_option($key, $option); } } } } // Setup Homepage $page = 'home'; $page_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", "{$page}")); if (isset($page_id) && is_numeric($page_id)) { update_option('show_on_front', 'page'); update_option('page_on_front', $page_id); } // Setup Menus $wplms_menus = array('top-menu' => 1, 'main-menu' => 1, 'mobile-menu' => 1, 'footer-menu' => 1); // End HomePage setup //Set Menus to Locations $vibe_menus = wp_get_nav_menus(); if (!empty($vibe_menus) && !empty($wplms_menus)) { // Check if menus are imported //Grab Menu values foreach ($wplms_menus as $key => $menu_item) { $term_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug = %s LIMIT 1;", "{$key}")); if (isset($term_id) && is_numeric($term_id)) { $wplms_menus[$key] = $term_id; } else { unset($wplms_menus[$key]); } } //update the theme set_theme_mod('nav_menu_locations', $wplms_menus); } //End Menu setup // Set WooCommerce Pages $pages = array('cart' => 'woocommerce_cart_page_id', 'checkout' => 'woocommerce_checkout_page_id', 'myaccount' => 'woocommerce_myaccount_page_id', 'shop' => 'woocommerce_shop_page_id'); foreach ($pages as $page => $option_name) { $page_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", "{$page}")); if (isset($page_id) && is_numeric($page_id)) { update_option($option_name, $page_id); } } //Set WooCommerce options delete_option('_wc_needs_pages'); delete_option('_wc_needs_update'); delete_transient('_wc_activation_redirect'); // End WooCommerce setup //Save BuddyPress settings if (function_exists('xprofile_insert_field_group')) { $field_group = array('name' => 'Instructor', 'description' => 'Instructor only field group'); $group_id = xprofile_insert_field_group($field_group); $fields = array(array('field_group_id' => 1, 'type' => 'textbox', 'name' => 'Location', 'description' => 'Student Location'), array('field_group_id' => 1, 'type' => 'textarea', 'name' => 'Bio', 'description' => 'About Student'), array('field_group_id' => $group_id, 'type' => 'textbox', 'name' => 'Speciality', 'description' => 'Instructor Speciality')); foreach ($fields as $field) { xprofile_insert_field($field); } } // Import Sample Slider $this->vibe_import_sample_slider(); } }
/** * @group xprofile_insert_field * @ticket BP6137 */ public function test_xprofile_insert_field_should_set_is_default_option_to_true_for_existing_option() { $g = $this->factory->xprofile_group->create(); $parent = $this->factory->xprofile_field->create(array('field_group_id' => $g, 'type' => 'selectbox', 'name' => 'Parent')); $f = xprofile_insert_field(array('field_group_id' => $g, 'parent_id' => $parent, 'type' => 'option', 'name' => 'Option 1', 'field_order' => 5, 'is_default_option' => false)); $this->assertNotEmpty($f); $field = new BP_XProfile_Field($f); $this->assertEquals(0, $field->is_default_option); $f = xprofile_insert_field(array('field_id' => $f, 'field_group_id' => $g, 'type' => 'textbox', 'is_default_option' => true)); $field2 = new BP_XProfile_Field($f); $this->assertEquals(1, $field2->is_default_option); }
function create_object($args) { $field_id = xprofile_insert_field($args); return $field_id; }
public static function setUserFieldList($fieldListWP, $fieldListBP, $user_id = 1) { if ($fieldListWP != null) { // If need more complexy display_name can use - bp_core_get_user_displayname if (empty($fieldListWP['display_name'])) { $fieldListWP['display_name'] = $fieldListWP['last_name'] . ' ' . $fieldListWP['first_name']; } $user = get_user_by("id", $user_id); // don't update password and email unset($fieldListWP["user_pass"]); unset($fieldListWP["user_email"]); $fieldListWP["ID"] = $user_id; wp_update_user($fieldListWP); } $groupParam = array('user_id' => $user_id, 'fetch_fields' => true, 'fetch_field_data' => true); $group = bp_xprofile_get_groups($groupParam)[0]; $newFieldOpt = array('field_group_id' => $group->id, 'name' => '', 'type' => 'textbox', 'is_required' => true, 'can_delete' => false); foreach ($fieldListBP as $key => $val) { $hasCurrentField = true; foreach ($group->fields as $field) { // delete name field if ($field->name == 'name') { xprofile_delete_field($field->id); } if ($field->name == $key) { $hasCurrentField = false; break; } } if ($hasCurrentField) { $newFieldOpt['name'] = $key; $fieldId = xprofile_insert_field($newFieldOpt); } $fieldSetId = xprofile_set_field_data($key, $user_id, $val); } }
function bpdd_import_users_profile() { /** @var $wpdb WPDB */ global $bp, $wpdb; $data = array(); $xprofile_structure = (require_once dirname(__FILE__) . '/data/xprofile_structure.php'); // first import profile groups foreach ($xprofile_structure as $group_type => $group_data) { $group_id = xprofile_insert_field_group(array('name' => $group_data['name'], 'description' => $group_data['desc'])); // then import fields foreach ($group_data['fields'] as $field_type => $field_data) { $field_id = xprofile_insert_field(array('field_group_id' => $group_id, 'parent_id' => 0, 'type' => $field_type, 'name' => $field_data['name'], 'description' => $field_data['desc'], 'is_required' => $field_data['required'], 'order_by' => 'custom')); if ($field_id) { bp_xprofile_update_field_meta($field_id, 'default_visibility', $field_data['default-visibility']); bp_xprofile_update_field_meta($field_id, 'allow_custom_visibility', $field_data['allow-custom-visibility']); $data[$field_id]['type'] = $field_type; // finally import options if (!empty($field_data['options'])) { foreach ($field_data['options'] as $option) { $option_id = xprofile_insert_field(array('field_group_id' => $group_id, 'parent_id' => $field_id, 'type' => 'option', 'name' => $option['name'], 'can_delete' => true, 'is_default_option' => $option['is_default_option'], 'option_order' => $option['option_order'])); $data[$field_id]['options'][$option_id] = $option['name']; } } else { $data[$field_id]['options'] = array(); } } } } $xprofile_data = (require_once dirname(__FILE__) . '/data/xprofile_data.php'); $users = bpdd_get_random_users_ids(0); // now import profile fields data for all fields for each user $count = 0; foreach ($users as $user_id) { foreach ($data as $field_id => $field_data) { switch ($field_data['type']) { case 'datebox': case 'textarea': case 'number': case 'textbox': case 'url': case 'selectbox': case 'radio': if (xprofile_set_field_data($field_id, $user_id, $xprofile_data[$field_data['type']][array_rand($xprofile_data[$field_data['type']])])) { $count++; } break; case 'checkbox': case 'multiselectbox': if (xprofile_set_field_data($field_id, $user_id, explode(',', $xprofile_data[$field_data['type']][array_rand($xprofile_data[$field_data['type']])]))) { $count++; } break; } } } return $count; }
function bp_ning_import_process_profiles() { $ning_id_array = get_option('bp_ning_user_array', array()); $field_key = get_option('bp_ning_profile_mapping', array()); if (empty($_POST['pf']) && empty($field_key)) { return true; } if (empty($field_key)) { $fields = $_POST['pf']; // Keep track of renamed fields foreach ((array) $fields as $key => $field) { // Check to see if the user provided an alternative name for the field if ($_POST['pfn'][$key]) { $newfield = $_POST['pfn'][$key]; $fields[$key] = $newfield; $field_key[$field] = $newfield; } else { $field_key[$field] = $field; $newfield = $field; } // Create the field $args = array('field_group_id' => 1, 'name' => $newfield, 'type' => 'textbox', 'is_required' => false); if (!xprofile_get_field_id_from_name($newfield)) { xprofile_insert_field($args); } } // Get the field ids for the just-created fields. Todo: patch the core so that xprofile_insert_field() returns the id foreach ((array) $fields as $field) { $field_ids[$field] = xprofile_get_field_id_from_name($field); } update_option('bp_ning_profile_mapping', $field_key); } // Populate the new fields $members = bp_ning_import_prepare_json('members'); $imported = get_option('bp_ning_profiles_imported', array()); $counter = 0; foreach ((array) $members as $member) { $member = (array) $member; $ncommented_id = $member['contributorName']; if (isset($imported[$ncommented_id])) { continue; } if ($counter >= 600) { update_option('bp_ning_profiles_imported', $imported); printf(__('%d out of %d member profiles done.'), count($imported), count($members)); return false; } $commented_id = $ning_id_array[$ncommented_id]; $commented_username = bp_core_get_username($commented_id); // Create @replies for all comments if (isset($member['comments']) && !get_user_meta($commented_id, 'ning_comments_imported') && function_exists('bp_activity_at_name_filter')) { global $bp; $comments = $member['comments']; $ncommented_id = $member['contributorName']; $commented_id = $ning_id_array[$ncommented_id]; $commented_username = bp_core_get_username($commented_id); foreach ((array) $comments as $comment) { $ncommenter_id = $comment->contributorName; $commenter_id = $ning_id_array[$ncommenter_id]; $ndate = strtotime($comment->createdDate); $date_created = date("Y-m-d H:i:s", $ndate); $from_user_link = bp_core_get_userlink($commenter_id); $activity_action = sprintf(__('%s posted an update:', 'buddypress'), $from_user_link); $activity_content = '@' . $commented_username . ' ' . $comment->description; $primary_link = bp_core_get_userlink($commenter_id, false, true); $args = array('user_id' => $commenter_id, 'action' => $activity_action, 'content' => bp_activity_at_name_filter($activity_content), 'primary_link' => $primary_link, 'component' => $bp->activity->id, 'type' => 'activity_update', 'recorded_time' => $date_created); bp_activity_add($args); } update_user_meta($commented_id, 'ning_comments_imported', 1); } else { update_user_meta($commented_id, 'ning_comments_imported', 1); } $profile_imported = get_user_meta($commented_id, 'ning_profile_imported'); if (isset($member['profileQuestions']) && !$profile_imported) { $questions = (array) $member['profileQuestions']; foreach ($questions as $q => $a) { $member[$q] = $a; } unset($member['profileQuestions']); } if (!$profile_imported) { xprofile_set_field_data(get_option('bp-xprofile-fullname-field-name'), $commented_id, $member['fullName']); foreach ((array) $member as $key => $value) { if (!array_key_exists($key, $field_key)) { continue; } $bp_field_name = $field_key[$key]; $user = get_user_by('email', $member['email']); if (!xprofile_get_field_data($bp_field_name, $user->ID)) { xprofile_set_field_data($bp_field_name, $user->ID, $value); } } } update_user_meta($commented_id, 'ning_profile_imported', 1); $counter++; $imported[$ncommented_id] = true; } update_option('bp_ning_profiles_imported', $imported); unset($members); return true; }