function _get_purchased_contents($post_types, $id, $start, $rows, $gifted = false) { global $wpdb; // array or string if (!is_array($post_types)) { $post_types = array($post_types); } // impode $post_types_in = mgm_map_for_in($post_types); // gifted $gifted_sql = $gifted ? "AND is_gift = 'Y'" : "AND is_gift = 'N'"; // from $sql_from = " FROM " . $wpdb->posts . " A JOIN " . TBL_MGM_POST_PURCHASES . " B ON(A.ID = B.post_id) \r\r\n\t\t\t\t\t WHERE post_status = 'publish' AND post_type IN ( {$post_types_in} ) {$gifted_sql}"; // sql $sql = "SELECT DISTINCT(A.ID), post_type, post_title, post_date, post_content, user_id,guest_token {$sql_from} \r\r\n\t\t ORDER BY post_date DESC LIMIT {$start},{$rows}"; // get posts $results = $wpdb->get_results($sql); // init $posts = array(); // check if ($results) { // loop foreach ($results as $post) { // get object $post_obj = mgm_get_post($post->ID); // check if (mgm_post_is_purchasable($post->ID, $post_obj)) { // stip short code $post->post_content = mgm_strip_shortcode($post->post_content); // access type $access_types = $post_obj->get_access_membership_types(); // access delay $access_delays = $post_obj->get_access_delay(); // init $access_settings = array(); // loop foreach ($access_types as $access_type) { // delay $delay = isset($access_delays[$access_type]) ? (int) $access_delays[$access_type] : 0; // set $access_settings[] = array('membership_type' => array('code' => $access_type, 'name' => mgm_get_membership_type_name($access_type)), 'access_delay' => sprintf(__('%d day', 'mgm'), $delay)); } // access $post->access_settings = $access_settings; // user if ((int) $post->user_id > 0) { // user $user = get_userdata($post->user_id); $user_info = array('by' => 'user', 'id' => $post->user_id, 'username' => $user->user_login, 'email' => $user->user_email); // gifted if ($gifted) { $post->gift = array_slice($user_info, 1); } else { $post->purchase = $user_info; } } else { $post->purchase = array('by' => 'guest', 'token' => $post->guest_token); } // unset unset($post->guest_token, $post->user_id); // set $posts[] = $post; } } } // return return $posts; }
/** * clean content */ private function _clean_content($posts) { // init $_posts = array(); // check if (count($posts) > 0) { // loop foreach ($posts as $id => $post) { // trim $post->post_content = mgm_strip_shortcode($post->post_content); // store $_posts[] = $post; } } // return return $_posts; }