/** * parse and output postpack buy button * * @since 2.0 * * @param int $postpack_id * @return string $html */ function mgm_parse_postpack_template($postpack_id) { global $post; // logged in if (is_user_logged_in()) { // return return mgm_get_postpack_template($postpack_id); } // guest token - issue #1396 if (isset($_GET['guest_token'])) { $pack_purchased = false; // list of posts if ($postpack_posts = mgm_get_postpack_posts($postpack_id)) { // init string $post_string = '<ul>'; // loop foreach ($postpack_posts as $i => $pack_post) { // check if user has purchased $access = mgm_user_has_purchased_post($pack_post->post_id, NULL, strip_tags($_GET['guest_token'])); // set if ($access) { // get post $post = get_post($pack_post->post_id); $post_url = get_permalink($post->ID) . '?guest_token=' . strip_tags($_GET['guest_token']); // append $post_string .= sprintf('<li><a href="%s">%s</a></li>', $post_url, $post->post_title); $pack_purchased = true; } } // end $post_string .= '</ul>'; } if ($pack_purchased) { return $post_string; } } // show links // login url $login_url = $post->ID > 0 ? mgm_get_custom_url('login', false, array('redirect_to' => get_permalink($post->ID))) : ''; // template $template = mgm_get_template('private_text_template', array(), 'templates'); // message $message = mgm_get_template('private_text_purchasable_pack_login', array(), 'messages'); //issue #863 $message = str_replace('[purchase_options]', '', $message); $message = __($message, 'mgm'); $message .= '[purchase_options]'; // message - issue #1396 $message = mgm_get_content_purchase_options($message, $login_url, $post->ID, $postpack_id); // message $message = str_replace('[message]', $message, $template); // return return sprintf('<div class="mgm_private_no_access">%s</div>', $message); }
/** * generate guest purchase post form - issue #1396 * * @param int post id * @return string html */ function mgm_guest_purchase_postpack_form($postpack_id, $postpack_post_id) { global $wpdb; // get postpack $postpack = mgm_get_postpack($postpack_id); // validate if (!$postpack->id) { return __('Bad data', 'mgm'); } // return - issue #1396 return mgm_get_postpack_template($postpack_id, true, $postpack_post_id); }