/**
 * Displays a list of restricted pages the currently logged-in user has access to
 *
 * @since       1.5.0
 * @param       array $atts The attributes to pass to the shortcode
 * @param       string $content The content of the shortcode
 * @return      string $content The data to return for the shortcode
 */
function edd_cr_pages_shortcode($atts, $content = null)
{
    $atts = shortcode_atts(array('class' => ''), $atts);
    if (is_user_logged_in()) {
        $pages = array();
        $purchases = edd_get_users_purchases(get_current_user_id(), -1);
        if ($purchases) {
            foreach ($purchases as $purchase) {
                $restricted = edd_cr_get_restricted_pages($purchase->ID);
                if (empty($restricted)) {
                    continue;
                }
                $page_ids = wp_list_pluck($restricted, 'ID');
                $pages = array_unique(array_merge($page_ids, $pages));
            }
            if (!empty($pages)) {
                $content = '<ul class="edd_cr_pages">';
                foreach ($pages as $page_id) {
                    $content .= '<li><a href="' . esc_url(get_permalink($page_id)) . '">' . get_the_title($page_id) . '</a></li>';
                }
                $content .= '</ul>';
            } else {
                $content = '<div class="edd_cr_no_pages">' . __('You have not purchased access to any content.', 'edd-cr') . '</div>';
            }
        } else {
            $content = '<div class="edd_cr_no_pages">' . __('You have not purchased access to any content.', 'edd-cr') . '</div>';
        }
    } else {
        $content = '<div class="edd_cr_not_logged_in">' . __('You must be logged in to access your purchased content.', 'edd-cr') . '</div>';
    }
    return $content;
}
/**
 * Add email template tags
 *
 * @since       1.3.0
 * @param       int $payment_id The payment ID
 * @return      string $page_list The list of accessible pages
 */
function edd_cr_add_template_tags($payment_id)
{
    // Get the array of restricted pages for this payment
    $meta = edd_cr_get_restricted_pages($payment_id);
    // No pages? Quit!
    if (empty($meta)) {
        return '';
    }
    $page_list = '<div class="edd_cr_accessible_pages">' . __('Pages', 'edd-cr') . '</div>';
    $page_list .= '<ul>';
    foreach ($meta as $post) {
        $page_list .= '<li><a href="' . esc_url(get_permalink($post->ID)) . '">' . $post->post_title . '</a></li>';
    }
    $page_list .= '</ul>';
    $page_list .= '</li>';
    return $page_list;
}