<?php ini_set('display_errors', 1); include "../../../../wp-load.php"; include_once 'functions.php'; $username = $_POST['username']; $password = $_POST['password']; $data = array(); $user = ml_login_wordpress($username, $password); if (get_class($user) == "WP_User") { // Get capabilities from Groups plugin if it's present if (class_exists('Groups_User')) { $group_user = new Groups_User($user->ID); $data['user'] = array(); $data['user']['name'] = "{$user->user_firstname} {$user->user_lastname}"; $data['groups'] = array(); $data['capabilities'] = array(); $groups = $group_user->__get('groups'); foreach ($groups as $group) { $g = array(); $g['id'] = $group->group_id; $g['name'] = $group->name; $data['groups'][] = $g; //capabilities $capabilities = $group->__get('capabilities'); if ($capabilities != NULL) { foreach ($capabilities as $capability) { $data['capabilities'][] = $capability->__get('capability'); } } }
/** * Get posts from database * * @param $query_array * @param $user_category * @param $real_offset * * @return array */ function ml_get_posts($query_array, $user_category, $real_offset) { if (!isset($_POST["post_id"])) { wp_reset_postdata(); $query = new WP_Query($query_array); $posts = $query->get_posts(); wp_reset_postdata(); if ($user_category == null) { $sticky_category_1 = get_option('sticky_category_1'); $sticky_category_2 = get_option('sticky_category_2'); } //must be the second, first because the first will be prepended if ($sticky_category_2 && ($real_offset == null || $real_offset == 0)) { //loading second 3 posts of the sticky category $cat = ml_get_category($sticky_category_2); if ($cat) { $query_array['posts_per_page'] = get_option('ml_sticky_category_2_posts', 3); $query_array['category_name'] = null; $query_array['category'] = null; $query_array['cat'] = $cat->cat_ID; $cat_2_posts = get_posts($query_array); foreach ($cat_2_posts as $p) { $p->sticky = true; foreach ($posts as $i => $v) { if ($v->ID == $p->ID) { array_splice($posts, $i, 1); } } } $posts = array_merge($cat_2_posts, $posts); } } if ($sticky_category_1 && ($real_offset == null || $real_offset == 0)) { //loading first 3 posts of the sticky category $cat = get_category($sticky_category_1); if ($cat) { $query_array['posts_per_page'] = get_option('ml_sticky_category_1_posts', 3); $query_array['category_name'] = null; $query_array['category'] = null; $query_array['cat'] = $cat->cat_ID; $cat_1_posts = get_posts($query_array); foreach ($cat_1_posts as $p) { $p->sticky = true; foreach ($posts as $i => $v) { if ($v->ID == $p->ID) { array_splice($posts, $i, 1); } } } $posts = array_merge($cat_1_posts, $posts); } } } else { $single_post_id = $_POST['post_id']; $posts = array(); $posts[0] = get_post($single_post_id); } //subscriptions system enabled? if (ml_subscriptions_enable()) { //user login using $_POST['username'] and $_POST['password'] $user = ml_login_wordpress($_POST['username'], $_POST['password']); if (get_class($user) == "WP_User") { //loggedin //subscriptions: filter posts using capabilities $posts = ml_subscriptions_filter_posts($posts, $user->ID); } else { $posts = ml_subscriptions_filter_posts($posts, null); } } return $posts; }