Skip to content

Commit

Permalink
* BUG FIX: Fixed issue with levels set with 0 site credits.
Browse files Browse the repository at this point in the history
* ENHANCEMENT: You can now set the number of site credits for a level by editing that level on the main site. These values will default to the value set via the pmpron_site_credits filter. You can remove your custom pmpron_site_credits filter code or continue to use the filter which will override the value set for the level.
* ENHANCEMENT: Added pmpron_getSiteCredits($level_id) function to get the number of site credits for a given level. This will get the option for the level and also apply the pmpron_site_credits filter.
* ENHANCEMENT: Improving readme documentation and updating add on name.
  • Loading branch information
ideadude committed May 27, 2017
1 parent 82a311f commit 42290ef
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 276 deletions.
103 changes: 40 additions & 63 deletions pages/manage-sites.php
Expand Up @@ -2,13 +2,10 @@
/*
Preheader
*/
function pmpron_manage_sites_preheader()
{
if(!is_admin())
{
function pmpron_manage_sites_preheader() {
if(!is_admin()) {
global $post, $current_user;
if(!empty($post->post_content) && strpos($post->post_content, "[pmpron_manage_sites]") !== false)
{
if(!empty($post->post_content) && strpos($post->post_content, "[pmpron_manage_sites]") !== false) {
/*
Preheader operations here.
*/
Expand All @@ -17,8 +14,7 @@ function pmpron_manage_sites_preheader()
global $current_user;
$credits = $current_user->pmpron_site_credits;

if(empty($credits))
{
if(empty($credits)) {
//redirect to levels
wp_redirect(pmpro_url("levels"));
exit;
Expand All @@ -31,83 +27,64 @@ function pmpron_manage_sites_preheader()
/*
Shortcode Wrapper
*/
function pmpron_manage_sites_shortcode($atts, $content=null, $code="")
{
function pmpron_manage_sites_shortcode($atts, $content=null, $code="") {
ob_start();

global $current_user;
global $current_user, $pmpro_msg, $pmpro_msgt;

//adding a site?
if(!empty($_POST['addsite']))
{
if(!empty($_POST['addsite'])) {
$sitename = $_REQUEST['sitename'];
$sitetitle = $_REQUEST['sitetitle'];

if(!empty($sitename) && !empty($sitetitle))
{
if(pmpron_checkSiteName($sitename))
{
$blog_id = pmpron_addSite($sitename, $sitetitle);
if(is_wp_error($blog_id))
{
$pmpro_msg = "Error creating site.";
$pmpro_msgt = "pmpro_error";
}
else
{
$pmpro_msg = "Your site has been created.";
$pmpro_msgt = "pmpro_success";
}
if(pmpron_checkSiteName( $sitename, $sitetitle )) {
$blog_id = pmpron_addSite($sitename, $sitetitle);
if(is_wp_error($blog_id)) {
$pmpro_msg = "Error creating site.";
$pmpro_msgt = "pmpro_error";
} else {
$pmpro_msg = "Your site has been created.";
$pmpro_msgt = "pmpro_success";
}
else
{
//error set in checkSiteName
}
}
else
{
$pmpro_msg = "Please enter a site name and title.";
$pmpro_msgt = "pmpro_error";
} else {
//error message shown below
}
}
else
{
} else {
//default values for form
$sitename = "";
$sitetitle = "";
$sitename = '';
$sitetitle = '';
}

//show page
$blog_ids = pmpron_getBlogsForUser($current_user->ID);

?>
<p class="pmpro_message <?php if( count($blog_ids) >= intval($current_user->pmpron_site_credits) ) { ?>pmpro_error<?php } ?>">
<?php if(!empty($pmpro_msg)) { ?>
<div class="pmpro_message <?php echo $pmpro_msgt;?>"><?php echo $pmpro_msg;?></div>
<?php } ?>
<div class="pmpro_message <?php if( count($blog_ids) >= intval($current_user->pmpron_site_credits) ) { ?>pmpro_error<?php } ?>">
<?php if( count($blog_ids) >= intval($current_user->pmpron_site_credits) ) { ?>
You have used <?php echo intval($current_user->pmpron_site_credits); ?> of <?php echo intval($current_user->pmpron_site_credits);?> site credits.
<?php echo sprintf('You have used %s of %s site credits.', intval($current_user->pmpron_site_credits), intval($current_user->pmpron_site_credits), 'pmpro-network'); ?>
<?php if(count($blog_ids) > intval($current_user->pmpron_site_credits)) { ?>
<?php echo (count($blog_ids) - intval($current_user->pmpron_site_credits)); ?> of your sites have been deactivated.
<?php echo sprintf('%s of your sites have been deactivated.', count($blog_ids) - intval($current_user->pmpron_site_credits), 'pmpro-network'); ?>
<?php } ?>
<?php } else { ?>
You have used <?php echo count($blog_ids);?> of <?php echo intval($current_user->pmpron_site_credits);?> site credits.
<?php echo sprintf('You have used %s of %s site credits.', count($blog_ids), intval($current_user->pmpron_site_credits), 'pmpro-network'); ?>
<?php } ?>
</p>
</div>

<?php if($current_user->pmpron_site_credits > count($blog_ids)) { ?>
<form class="pmpro_form" action="" method="post">
<table id="pmpro_add_site" class="pmpro_checkout" width="100%" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Add a Site</th>
<th><?php _e('Add a Site', 'pmpro-network'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<?php if(!empty($pmpro_msg)) { ?>
<p class="pmpro_message <?php echo $pmpro_msgt;?>"><?php echo $pmpro_msg;?></p>
<?php } ?>
<td>
<div>
<label for="sitename"><?php _e('Site Name') ?></label>
<label for="sitename"><?php _e('Site Name', 'pmpro-network'); ?></label>
<input id="sitename" name="sitename" type="text" class="input" size="30" value="<?php echo esc_attr(stripslashes($sitename)); ?>" />
<?php
global $current_site;
Expand All @@ -118,11 +95,11 @@ function pmpron_manage_sites_shortcode($atts, $content=null, $code="")
else
$site = __( '{site name}' ) . '.' . $site_domain . $current_site->path;

echo '<div class="leftmar"><strong>' . sprintf( __('Your address will be %s.'), $site ) . '</strong><br />' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed, so choose carefully!' ) . '</div>';
echo '<div class="leftmar"><strong>' . sprintf( __('Your address will be %s'), $site ) . '</strong>.<br />' . __( 'Your <em>Site Name</em> must be at least 4 characters (letters/numbers only). Once your site is created the site name cannot be changed.' ) . '</div>';
?>
</div>
<div>
<label for="sitetitle"><?php _e('Site Title')?></label>
<label for="sitetitle"><?php _e('Site Title', 'pmpro-network'); ?></label>
<input id="sitetitle" name="sitetitle" type="text" class="input" size="30" value="<?php echo esc_attr(stripslashes($sitetitle)); ?>" />
</div>
<div class="leftmar">
Expand All @@ -138,18 +115,18 @@ function pmpron_manage_sites_shortcode($atts, $content=null, $code="")
<?php } ?>

<?php if(!empty($blog_ids)) { ?>
<h3>Your Sites</h3>
<h2><?php _e('Your Sites', 'pmpro-network'); ?></h2>
<table id="pmpro_add_site" class="pmpro_checkout" width="100%" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th><?php _e('Name') ?></th>
<th><?php _e('Options') ?></th>
<th><?php _e('Name', 'pmpro-network'); ?></th>
<th><?php _e('Options', 'pmpro-network'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach($blog_ids as $blog_id) { ?>
<?php if( ! get_blog_details($blog_id)) continue; ?>
<tr<?php if(get_blog_status($blog_id, "deleted")) { ?> class="pmpro_disabled"<?php } ?>>
<tr<?php if(get_blog_status($blog_id, "deleted")) { ?> class="pmpro_grey"<?php } ?>>
<td>
<?php
if(get_blog_status($blog_id, "deleted"))
Expand All @@ -170,13 +147,13 @@ function pmpron_manage_sites_shortcode($atts, $content=null, $code="")
if(get_blog_status($blog_id, "deleted"))
{
?>
<?php _e('(deactivated)') ?>
<?php _e('(deactivated)', 'pmpro-network'); ?>
<?php
}
else
{
?>
<a href="<?php echo get_site_url($blog_id);?>/wp-admin/"><?php _e('Dashboard') ?></a>&nbsp;|&nbsp;<a href="<?php echo get_site_url($blog_id, "/wp-admin/post-new.php"); ?>"><?php _e('New Post') ?></a>&nbsp;|&nbsp;<a href="<?php echo get_site_url($blog_id, "/wp-admin/edit-comments.php"); ?>"><?php _e('Manage Comments') ?></a>&nbsp;|&nbsp;<a href="<?php echo get_site_url($blog_id);?>"><?php _e('Visit Site') ?></a>
<a href="<?php echo get_site_url($blog_id);?>"><?php _e('Visit', 'pmpro-network'); ?></a>&nbsp;|&nbsp;<a href="<?php echo get_site_url($blog_id);?>/wp-admin/"><?php _e('Dashboard', 'pmpro-network'); ?></a>
<?php
}
?>
Expand All @@ -191,5 +168,5 @@ function pmpron_manage_sites_shortcode($atts, $content=null, $code="")
ob_end_clean();
return $temp_content;
}
add_shortcode("pmpron_manage_sites", "pmpron_manage_sites_shortcode");
add_shortcode( 'pmpron_manage_sites', 'pmpron_manage_sites_shortcode');

0 comments on commit 42290ef

Please sign in to comment.