function get_antennas_details() { //get all antenna users $users = get_antenna_users(); //count the number of user $nb = count($users); if ($nb === 1) { //if only 1 user, we assume that it's the admin user so $user->ID = 1 $categ_admin = get_cat_if_user(1); $antenna = get_cat_slug($categ_admin); $options = get_option('iftheme_theme_options_' . $antenna, iftheme_get_default_theme_options()); //cf. theme-options.php for keys of the option array //adding useful infos to $options $options['aid'] = $categ_admin; $options['slug'] = $antenna; } else { //more than 1 user foreach ($users as $k => $o) { $categ = get_cat_if_user($o->ID); //$categ = function_exists('icl_object_id') ? icl_object_id($categ, 'category', TRUE) : $categ; $antenna = get_cat_slug($categ) ? get_cat_slug($categ) : __('You must assign a category to this user : '******'iftheme') . $o->display_name; $options[$categ] = get_option('iftheme_theme_options_' . $antenna, iftheme_get_default_theme_options()); //cf. theme-options.php for keys of the option array //unset country options for non admin user //@todo: posibility to have multiple admin. Maybe check user's roles more then his ID if ($o->ID != 1) { unset($options[$categ]['bg_frame_country']); unset($options[$categ]['background_img_country']); unset($options[$categ]['theme_home_categ_country']); } //adding useful infos to $options $options[$categ]['aid'] = !$categ ? null : $categ; $options[$categ]['slug'] = $antenna; } } return $options; }
function extendUser_antenna($user_id) { global $profileuser; global $sitepress; $default_lg = isset($sitepress) ? $sitepress->get_default_language() : get_site_lang(); $userID = $user_id->ID; $userRole = $profileuser->roles[0]; $antennaz = get_antenna_users(); //display only top level categories even if no posts assign to it //FYI : add in array $args 'exclude'=>1 if you're not using the default category; $args = array('parent' => 0, 'hide_empty' => 0); $categories = get_categories($args); //exclude categories that are allready in use foreach ($antennaz as $k => $o) { $cat = get_user_meta($o->ID, 'categ_to_antenna', true); $usedCateg[$cat]['cat'] = $cat; $usedCateg[$cat]['user'] = $o->ID; } foreach ($categories as $c => $v) { $tid = function_exists('icl_object_id') ? icl_object_id($v->term_id, 'category', true, $default_lg) : $v->term_id; if (isset($usedCateg[$tid]['cat']) && $userID != $usedCateg[$tid]['user']) { unset($categories[$c]); } } if ($userRole == "administrator" || $userRole == "antenna" && current_user_can('publish_posts')) { ?> <h3><?php echo __('Category assigned to this Antenna', 'iftheme'); ?> </h3> <?php if (!empty($categories)) { ?> <table class="form-table if-form-table"> <tr> <?php foreach ($categories as $category) { $categID = function_exists('icl_object_id') ? icl_object_id($category->term_id, 'category', true, $default_lg) : $category->term_id; ?> <th scope="row"><label for="<?php echo $category->slug; ?> "><?php echo $category->name; ?> </label></th> <td><input type="radio" name="categ_to_antenna" value="<?php echo $categID; ?> " <?php checked(get_user_meta($userID, "categ_to_antenna", true), $categID); ?> /></td> <?php } ?> </tr> </table> <?php } else { ?> <?php if ($userRole == "administrator") { ?> <?php $categAdmin = get_category(get_user_meta(1, 'categ_to_antenna', true)); ?> <table class="form-table if-form-table"> <tr> <th scope="row"><label for="<?php echo $categAdmin->slug; ?> "><?php echo $categAdmin->name; ?> </label></th> <td><input type="radio" name="categ_to_antenna" value="<?php echo $categAdmin->cat_ID; ?> " <?php checked(get_user_meta(1, "categ_to_antenna", true), $categAdmin->cat_ID); ?> /></td> </tr> </table> <?php } else { ?> <?php _e('You must create another top level category to assign to this user', 'iftheme'); ?> <?php //defined('ICL_LANGUAGE_CODE') ? _e('Or there is no category in this language', 'iftheme') : ''; ?> <?php } ?> <?php } } }