function form($instance) { global $current_user; get_currentuserinfo(); //get antenna ID $aid = get_cat_if_user_lang($current_user->ID); //get antenna's children $children = get_categories('child_of=' . $aid . '&hide_empty=0'); // prints the form on the widgets page $catid = isset($instance['catid']) ? defined('ICL_LANGUAGE_CODE') ? icl_object_id($instance['catid'], 'category', false, ICL_LANGUAGE_CODE) : $instance['catid'] : $children[0]->term_id; $defaults = array('catid' => $catid, 'title' => ''); $instance = wp_parse_args((array) $instance, $defaults); //if admin access to all categories if ($current_user->ID == 1) { $aid = 0; } $args = array('hide_empty' => 0, 'hierarchical' => 1, 'id' => $this->get_field_id('catid'), 'name' => $this->get_field_name('catid'), 'selected' => $catid, 'child_of' => $aid, 'show_option_none' => __('None', 'iftheme')); ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title'); ?> </label> <input type="text" name="<?php echo $this->get_field_name('title'); ?> " id="<?php echo $this->get_field_id('title'); ?> " value="<?php echo $instance['title']; ?> " size="20" /><div class="description"><?php _e("You can custom the widget title here. Default is the category name you choose in the Category parent field below.", 'iftheme'); ?> </div> </p> <p> <label for="<?php echo $this->get_field_id('catid'); ?> "><?php _e('Category parent', 'iftheme'); ?> </label> <?php wp_dropdown_categories($args); ?> </p> <?php }
function checklist_args_limit($args) { add_action('admin_footer', array(__CLASS__, 'script')); $args['checked_ontop'] = false; global $current_user; $uid = $current_user->ID; if ($uid != 1) { if (function_exists('get_cat_if_user_lang')) { $cat = get_cat_if_user_lang($uid); if (!$cat) { return; } $args['descendants_and_self'] = $cat; } } unset($args['popular_cats']); //Pas efficace !!! //echo '<pre>'; print_r($cat);echo '</pre>';//wp_terms_checklist //$args['descendants_and_self'] = 1; return $args; }
function if_restrict_categories($categories) { global $current_user; get_currentuserinfo(); $a = get_cat_if_user_lang($current_user->ID); $onPostPage = strpos($_SERVER['PHP_SELF'], 'edit-tags.php'); if (is_admin() && $onPostPage && !current_user_can('level_10')) { //if (is_admin() && $onPostPage) { $size = count($categories); for ($i = 0; $i < $size; $i++) { if (is_object($categories[$i])) { //if($categories[$i]->parent != $a && $categories[$i]->term_id != $a){ if (!cat_is_ancestor_of($a, $categories[$i]->term_id) && $categories[$i]->term_id != $a) { unset($categories[$i]); } } } } return $categories; }