/**
  * 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;
 }
Example #2
0
 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();
     }
 }
Example #3
0
 function create_object($args)
 {
     $group_id = xprofile_insert_field_group($args);
     return $group_id;
 }
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;
}