function top_contributors_sc($atts) { $taxonomyLookup = array('destination' => 'tr-destination', 'subregion' => 'tr-subregion', 'sub-region' => 'tr-subregion', 'region' => 'tr-region', 'city' => 'tr-city', 'country' => 'tr-country', 'continent' => 'tr-continent', 'state' => 'tr-state', 'activity-category' => 'tr-activity-category'); if (!isset($atts['parent']) || !array_key_exists($atts['parent'], $taxonomyLookup)) { return 'top-contributors: parent attribute not valid! Must be one of {' . implode(", ", array_keys($taxonomyLookup)) . "}."; } if (!isset($atts['parentterm'])) { return 'top-contributors: parentterm attribute not set!'; } if (!isset($atts['max'])) { $atts['max'] = 15; } if (!isset($atts['title'])) { $atts['title'] = "Top Contributors"; } $title = $atts['title']; $targetTaxonomy = $atts['parent']; $targetTerm = $atts['parentterm']; $targetPostTypes = array('post', 'guide', 'gear-review'); $maxPostCount = $atts['max']; $queryArgs = array('posts_per_page' => -1, 'orderby' => 'name', 'order' => 'ASC', 'role' => 'author'); $query = new WP_User_Query($queryArgs); $userCount = $query->get_total(); $userQueryResults = $query->get_results(); $usersDisplayed = 0; $usersHidden = 0; $resultData = array(); foreach ($userQueryResults as $user) { $authorUrl = get_author_posts_url($user->ID); //'/authors/'.$user->nickname; $userName = $user->nickname; //$avatar = get_user_meta($user->ID, 'wpcf-tr-user-profile-image', true); //$avatarExt = substr($avatar,strlen($avatar)-4, 4); //$avatar = substr($avatar,0,strlen($avatar)-4) . "-wpcf_200x200" . $avatarExt; //big hack, but i need to get the image with the correct aspect ratio... $avatar = types_render_usermeta_field('tr-user-profile-image', array('user_id' => $user->ID, 'url' => true, 'width' => 200, 'height' => 200, 'resize' => 'crop')); $postCount = 0; foreach ($targetPostTypes as $postType) { //get all posts of each type from this author for this location $queryArgs = array('author' => $user->ID, 'post_type' => $postType, 'tax_query' => array(array('taxonomy' => $taxonomyLookup[$targetTaxonomy], 'field' => 'slug', 'terms' => $targetTerm))); $query = new WP_Query($queryArgs); $postCount += $query->found_posts; } if ($postCount > 0) { $resultData[] = array('url' => $authorUrl, 'name' => $userName, 'post_count' => $postCount, 'avatar' => $avatar); $usersDisplayed++; } else { $usersHidden++; } if ($usersDisplayed == $maxPostCount) { break; } } //Generate the output $res = top_contributors_format_result($title, $resultData); //$res .= "parentTaxSlug=$parentTaxSlug<br>"; //$res .= "parentTermSlug=$parentTermSlug<br>"; //$res .= "targetPostType=$targetPostType<br>"; //$res .= "maxPostCount=$maxPostCount<br>"; //$res .= $query->request . "<br>"; //$res .= "Users found: $userCount<br>"; //$res .= "Users displayed: $usersDisplayed<br>"; //$res .= "Users hidden: $usersHidden<br>"; wp_reset_postdata(); return $res; }
function page_access() { global $user; global $sitepress; // the the language in use now _log("> page_access() to "); $current_language = $sitepress->get_current_language(); global $current_user; get_currentuserinfo(); // _log($current_user); if (is_user_logged_in()) { _log("language on this page: " . $current_language); _log("default language: " . $sitepress->get_default_language()); $can_access_sectors = types_render_usermeta_field("access-to-sector", array("separator" => ",", "output" => "raw", "user_current" => true)); _log("logged in user as: " . $current_user->user_login); _log("user can access these sectors: " . $can_access_sectors); $can_access_sectors_array = explode(", ", $can_access_sectors); _log("is current language OK to access: " . (in_array($current_language, $can_access_sectors_array) ? "yes" : "no")); // check if if (!in_array($current_language, $can_access_sectors_array)) { _log("go to alternative language or front-page"); // TODO } $can_access_leader_pages = types_render_usermeta_field("access-to-leader-pages", array("output" => "raw", "user_current" => true)); _log("access to leader pages: " . ($can_access_leader_pages == 1 ? "yes" : "no")); if (!$can_access_leader_pages) { _log("go back or to front-page"); // TODO } } else { _log("visitor"); // no access!!?? // go to register page? // TODO } // _log($sitepress); // default: //_log(&$this); // no return }