public function wpmf_change_folder()
 {
     global $current_user;
     $wpmfjson = array();
     $id = (int) $_POST['id'] | 0;
     $_SESSION['wpmf-current-folder'] = $id;
     $taxo = Wp_Media_Folder::get_taxonomy();
     if (isset($_COOKIE['wpmf_folder_order']) && empty($_SESSION['wpmf_folder_orderby']) && empty($_SESSION['wpmf_folder_order'])) {
         $sortbys = explode('-', $_COOKIE['wpmf_folder_order']);
         $orderby = $sortbys[0];
         $order = $sortbys[1];
     } else {
         if (isset($_SESSION['wpmf_folder_orderby'])) {
             $orderby = $_SESSION['wpmf_folder_orderby'];
         } else {
             $orderby = 'name';
         }
         if (isset($_SESSION['wpmf_folder_order'])) {
             $order = $_SESSION['wpmf_folder_order'];
         } else {
             $order = 'ASC';
         }
     }
     $terms_child = get_terms($taxo, array('orderby' => $orderby, 'order' => $order, 'parent' => $id, 'hide_empty' => false));
     $wpmfjson['terms'] = $terms_child;
     $wpmf_active_media = get_option('wpmf_active_media');
     $user_roles = $current_user->roles;
     if (isset($_SESSION['wpmf_display_media']) && $_SESSION['wpmf_display_media'] == 'yes') {
         $terms = get_terms($taxo, array('orderby' => 'id', 'order' => 'ASC', 'hide_empty' => false));
         $id1 = array();
         foreach ($terms as $term) {
             if ($term->term_group == get_current_user_id()) {
                 if ($term->parent != 0) {
                     $term_parent = get_term($term->parent, $taxo);
                     if ($term_parent->term_group != null && $term_parent->term_group == get_current_user_id()) {
                         $id1[] = $term->term_id;
                     }
                 } else {
                     $id1[] = $term->term_id;
                 }
             }
         }
         $wpmfjson['id1'] = $id1;
     }
     wp_send_json($wpmfjson);
 }
 public function wpmf_change_folder()
 {
     global $current_user;
     $id = (int) $_POST['id'] | 0;
     $_SESSION['wpmf-current-folder'] = $id;
     $taxo = Wp_Media_Folder::get_taxonomy();
     $wpmf_active_media = get_option('wpmf_active_media');
     $user_roles = $current_user->roles;
     if (isset($_SESSION['wpmf_display_media']) && $_SESSION['wpmf_display_media'] == 'yes') {
         $terms = get_terms($taxo, array('orderby' => 'id', 'order' => 'ASC', 'hide_empty' => false));
         $id1 = array();
         foreach ($terms as $term) {
             if ($term->term_group == get_current_user_id()) {
                 if ($term->parent != 0) {
                     $term_parent = get_term($term->parent, $taxo);
                     if ($term_parent->term_group != null && $term_parent->term_group == get_current_user_id()) {
                         $id1[] = $term->term_id;
                     }
                 } else {
                     $id1[] = $term->term_id;
                 }
             }
         }
         wp_send_json($id1);
     }
 }
 public function wpmf_auto_create_folder()
 {
     $taxo = Wp_Media_Folder::get_taxonomy();
     $roles = array('administrator', 'editor', 'author');
     $users = get_users();
     foreach ($users as $user) {
         $user_data = get_userdata($user->ID);
         $user_roles = $user_data->roles;
         if (in_array($user_roles[0], $roles)) {
             $inserted = wp_insert_term($user->user_login, $taxo, array('parent' => 0));
             if (!is_wp_error($inserted)) {
                 $updateted = wp_update_term($inserted['term_id'], $taxo, array('term_group' => $user->ID));
             }
         }
     }
 }