function pmpro_addon_packages_shortcode($atts, $content = null, $code = "")
{
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_addon_packages show="none" include="subpages"]
    // table of addone packages that are subpages of the page with shortcode and showing no description excerpt
    global $wpdb, $post, $current_user;
    extract(shortcode_atts(array('checkout_button' => __('Buy Now', 'pmproap'), 'levels_button' => __('Choose a Level', 'pmproap'), 'exclude' => NULL, 'layout' => 'table', 'link' => true, 'include' => NULL, 'orderby' => 'menu_order', 'order' => 'ASC', 'thumbnail' => 'thumbnail', 'view_button' => __('View Now', 'pmproap')), $atts));
    // prep exclude array
    $exclude = str_replace(" ", "", $exclude);
    $exclude = explode(",", $exclude);
    //turn 0's into falses
    if ($include == "subpages") {
        $post_type = "page";
        $post_parent = $post->ID;
    } else {
        $post_type = array('post', 'page');
        $post_parent = NULL;
    }
    if ($link === "0" || $link === "false" || $link === "no") {
        $link = false;
    } else {
        $link = true;
    }
    if ($thumbnail && strtolower($thumbnail) != "false") {
        if (strtolower($thumbnail) == "medium") {
            $thumbnail = "medium";
        } elseif (strtolower($thumbnail) == "large") {
            $thumbnail = "large";
        } else {
            $thumbnail = "thumbnail";
        }
    } else {
        $thumbnail = false;
    }
    // get posts
    $args = array('meta_key' => '_pmproap_price', 'meta_compare' => '>', 'meta_value' => '0', "order" => $order, "orderby" => $orderby, 'posts_per_page' => -1, 'post_status' => 'publish', "post_type" => $post_type, "post_parent" => $post_parent, "post__not_in" => $exclude);
    $pmproap_posts = get_posts($args);
    $layout_cols = preg_replace('/[^0-9]/', '', $layout);
    if (!empty($layout_cols)) {
        $pmproap_posts_chunks = array_chunk($pmproap_posts, $layout_cols);
    } else {
        $pmproap_posts_chunks = array_chunk($pmproap_posts, 1);
    }
    ob_start();
    if (!empty($pmproap_posts)) {
        ?>
			<style>
				.pmpro_addon_package td {vertical-align: middle; }
				tr.pmpro_addon_package td.pmpro_addon_package-title h3 {margin: 0; }
				#pmpro_addon_packages h3.pmpro_addon_package-title {margin: 0 0 2rem 0; }
				.pmpro_addon_package td.pmpro_addon_package-thumbnail img {max-width: 100%; height: auto; }
				.pmpro_addon_package td.pmpro_addon_package-buy .pmpro_btn, .pmpro_addon_package td.pmpro_addon_package-view .pmpro_btn {display: block; }
			</style>
		<?php 
        if ($layout == 'table') {
            ?>
				<table id="pmpro_addon_packages" cellpadding="0" cellspacing="0" border="0">					
					<tbody>
					<?php 
            foreach ($pmproap_posts as $post) {
                $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                ?>
							<tr id="pmpro_addon_package-<?php 
                echo $post->ID;
                ?>
" class="pmpro_addon_package">
							<?php 
                if (has_post_thumbnail() && !empty($thumbnail)) {
                    ?>
									<td width="15%" class="pmpro_addon_package-thumbnail">
									<?php 
                    if ($link) {
                        echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail($post->ID, $thumbnail) . '</a>';
                    } else {
                        echo get_the_post_thumbnail($post->ID, $thumbnail);
                    }
                    ?>
									</td>
									<?php 
                }
                ?>
								<td class="pmpro_addon_package-title">
									<h3>
									<?php 
                if (!empty($link)) {
                    echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
                } else {
                    echo get_the_title();
                }
                ?>
									</h3>									
								</td>
								<?php 
                if (!empty($current_user->ID) && pmproap_hasAccess($current_user->ID, $post->ID)) {
                    ?>
										<td width="25%" class="pmpro_addon_package-view"><a class="pmpro_btn" href="<?php 
                    echo the_permalink();
                    ?>
"><?php 
                    echo $view_button;
                    ?>
</a></td>
										<?php 
                } else {
                    //which level to use for checkout link?
                    $text_level_id = pmproap_getLevelIDForCheckoutLink($post->ID, $current_user->ID);
                    ?>
										<td width="25%" class="pmpro_addon_package-buy">
										<?php 
                    if (empty($text_level_id)) {
                        ?>
												<a class="pmpro_btn" href="<?php 
                        echo pmpro_url("levels");
                        ?>
">
													<?php 
                        echo $levels_button;
                        ?>
												</a>
											<?php 
                    } else {
                        //what's the price
                        $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                        ?>
												<a class="pmpro_btn" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID);
                        ?>
">
													<?php 
                        echo $checkout_button;
                        ?>
 &mdash; <span class="pmpro_addon_package-price"><?php 
                        echo pmpro_formatPrice($pmproap_price);
                        ?>
</span>
												</a>
											<?php 
                    }
                    ?>
										</td>
										<?php 
                }
                ?>
							</tr> <!-- end pmpro_addon_package-->
							<?php 
            }
            ?>
					</tbody>
				</table> <!-- end #pmpro_addon_packages -->
				<?php 
        } else {
            ?>
				<div id="pmpro_addon_packages">
					<?php 
            foreach ($pmproap_posts_chunks as $row) {
                ?>
							<div class="row">
						<?php 
                foreach ($row as $post) {
                    $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                    ?>
								<div class="medium-<?php 
                    if ($layout == '2col') {
                        echo '6 ';
                    } elseif ($layout == '3col') {
                        echo '4 text-center ';
                    } elseif ($layout == '4col') {
                        echo '3 text-center ';
                    } else {
                        echo '12 ';
                    }
                    ?>
								columns">
									<article id="pmpro_addon_package-<?php 
                    echo $post->ID;
                    ?>
" class="<?php 
                    echo implode(" ", get_post_class());
                    ?>
 pmpro_addon_package">							
										<header class="entry-header"><h3 class="entry-title pmpro_addon_package-title">
										<?php 
                    if (has_post_thumbnail() && !empty($thumbnail)) {
                        if ($layout == '3col' || $layout == '4col') {
                            $thumbnail_class = "aligncenter";
                        } else {
                            $thumbnail_class = "alignright";
                        }
                        if ($link) {
                            echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail($post->ID, $thumbnail, array('class' => $thumbnail_class)) . '</a>';
                        } else {
                            echo get_the_post_thumbnail($post->ID, $thumbnail, array('class' => $thumbnail_class));
                        }
                    }
                    if (!empty($link)) {
                        echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
                    } else {
                        echo get_the_title();
                    }
                    ?>
									
										</h3></header>
										<div class="entry-content">																		
											<?php 
                    if (!empty($current_user->ID) && pmproap_hasAccess($current_user->ID, $post->ID)) {
                        ?>
													<p class="pmpro_addon_package-view"><a class="pmpro_btn" href="<?php 
                        echo the_permalink();
                        ?>
"><?php 
                        echo $view_button;
                        ?>
</a></p>
													<?php 
                    } else {
                        //which level to use for checkout link?
                        $text_level_id = pmproap_getLevelIDForCheckoutLink($post->ID, $current_user->ID);
                        if (empty($text_level_id)) {
                            ?>
															
														<p class="pmpro_addon_package-buy"><a class="pmpro_btn" href="<?php 
                            echo pmpro_url("levels");
                            ?>
"><?php 
                            echo $levels_button;
                            ?>
</a></p>
														<?php 
                        } else {
                            //what's the price
                            $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                            ?>
														<p class="pmpro_addon_package-buy"><a class="pmpro_btn" href="<?php 
                            echo pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID);
                            ?>
"><?php 
                            echo $checkout_button;
                            ?>
 &mdash; <span class="pmpro_addon_package-price"><?php 
                            echo pmpro_formatPrice($pmproap_price);
                            ?>
</span></a></p>
														<?php 
                        }
                    }
                    ?>
										</div>
									</article> <!-- end pmpro_addon_package-->
								</div>
							<?php 
                }
                ?>
						</div> <!-- end row -->
						<?php 
                if ($layout == '3col' || $layout == '4col') {
                    echo "<hr />";
                }
                ?>
						
					<?php 
            }
            ?>
				</div> <!-- end #pmpro_addon_packages -->
				<?php 
        }
        //Reset Query
        wp_reset_query();
    } else {
        _e('No add on packages found.', 'pmproap');
    }
    $temp_content = ob_get_contents();
    ob_end_clean();
    return $temp_content;
}
function pmproap_pmpro_text_filter($text)
{
    global $wpdb, $current_user, $post, $pmpro_currency_symbol;
    if (!empty($post)) {
        if (pmproap_isPostLocked($post->ID) && !pmproap_hasAccess($current_user->ID, $post->ID)) {
            //which level to use for checkout link?
            $text_level_id = pmproap_getLevelIDForCheckoutLink($post->ID, $current_user->ID);
            if (empty($text_level_id)) {
                $text = "<p>" . __("You must first purchase a membership level before purchasing this content. ", "pmproap") . "</p>";
                $text .= "<p><a href=\"" . pmpro_url("levels") . "\">" . __("Click here to choose a membership level.", "pmproap") . "</a></p>";
            } else {
                //what's the price
                $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                //check for all access levels
                $all_access_levels = apply_filters("pmproap_all_access_levels", array(), $current_user->ID, $post->ID);
                //update text
                if (!empty($all_access_levels)) {
                    $level_names = array();
                    foreach ($all_access_levels as $level_id) {
                        $level = pmpro_getLevel($level_id);
                        $level_names[] = $level->name;
                    }
                    $text = "<p>" . __("This content requires that you purchase additional access. The price is %s or free for our %s members.", pmpro_formatPrice($pmproap_price), pmpro_implodeToEnglish($level_names)) . "</p>";
                    $text .= "<p><a href=\"" . pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID) . "\">" . sprintf(__("Purchase this Content (%s)", 'pmproap'), pmpro_formatPrice($pmproap_price)) . "</a> <a href=\"" . pmpro_url("levels") . "\">" . __("Choose a Membership Level", "pmproap") . "</a></p>";
                } else {
                    $text = "<p>" . sprintf(__("This content requires that you purchase additional access. The price is %s.", "pmproap"), pmpro_formatPrice($pmproap_price)) . "</p>";
                    $text .= "<p><a href=\"" . pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID) . "\">" . __("Click here to checkout", "pmproap") . "</a></p>";
                }
            }
        }
    }
    return $text;
}