Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Checkout page v3.1 compat #34

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 98 additions & 95 deletions pmpro-network.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ function pmpron_init() {
}
add_action('init', 'pmpron_init');

/*
First we need to add some fields to the checkout page.
*/
//add the fields to the form
function pmpron_pmpro_checkout_boxes()
{
/**
* Add site credits fields to the checkout page.
*
* @since TBD
* @return void
*/
function pmpron_pmpro_checkout_boxes() {
global $current_user, $wpdb, $pmpro_network_non_site_levels;

$level_id = null;
Expand All @@ -80,104 +81,106 @@ function pmpron_pmpro_checkout_boxes()
$level_id = intval( $level->id );
}

// Return if requested level is in non site levels array
if ( !empty($level_id) && !empty($pmpro_network_non_site_levels) && in_array( $level_id, $pmpro_network_non_site_levels ) )
return;
// Bail if requested level is in non site levels array
if ( !empty( $level_id ) && !empty( $pmpro_network_non_site_levels )
&& in_array( $level_id, $pmpro_network_non_site_levels ) ) {
return;
}

// Return if site credits for this level is < 1
$site_credits = pmpron_getSiteCredits($level_id);
if(intval($site_credits) < 1)
// Bail if site credits for this level is < 1
if( intval( pmpron_getSiteCredits( $level_id ) ) < 1 ) {
return;
}

if(!empty($_REQUEST['sitename']))
{
$sitename = '';
$sitetitle = '';
if( !empty( $_REQUEST['sitename'] ) ) {
$sitename = $_REQUEST['sitename'];
$sitetitle = $_REQUEST['sitetitle'];
}
elseif(!empty($_SESSION['sitename']))
{
$sitename = $_SESSION['sitename'];
$sitetitle = $_SESSION['sitetitle'];
}
else {
$sitename = '';
$sitetitle = '';
}
?>
<div id="pmpro_site_fields" class="pmpro_checkout">
<hr />
<h2>
<span class="pmpro_checkout-h2-name"><?php esc_html_e( 'Site Information', 'pmpro-network'); ?></span>
<span class="pmpro_checkout-h2-msg"><?php echo sprintf( __( 'Sites Included: <strong>%s</strong>', 'pmpro-network' ), pmpron_getSiteCredits($level_id), 'pmpro-network'); ?></span>
</h2>
<div class="pmpro_checkout-fields">
<?php
//check if the user already has a blog
if($current_user->ID)
{
$all_blog_ids = pmpron_getBlogsForUser($current_user->ID);
$blog_id = get_user_meta($current_user->ID, "pmpron_blog_id", true);
if(count($all_blog_ids) > 1)
{
$blogname = "many";
}
elseif($blog_id)
{
$user_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE blog_id = '" . $blog_id . "' LIMIT 1");
$blogname = get_blog_option($blog_id, "blogname");
}
}
if(!empty($blogname)) {
if($blogname == "many")
{
?>
<div class="pmpro_checkout-field">
<p><?php esc_html_e( 'You will be reclaiming your previous sites.', 'pmpro-network' ); ?></p>
<input type="hidden" name="blog_id" value="<?php echo esc_attr( $blog_id ); ?>" />

</div>
<?php
}
else
{
?>
<div class="pmpro_checkout-field">
<p><?php echo sprintf( __( 'You will be reclaiming your site <strong>%s</strong>.', 'pmpro-network' ), $blogname ); ?></p>
<input type="hidden" name="blog_id" value="<?php echo esc_attr( $blog_id ); ?>" />

</div>
<?php
}
}
else
{
?>
<div class="pmpro_checkout-field pmpro_checkout-field-sitename">
<label for="sitename"><?php esc_html_e( 'Site Name', 'pmpro-network' ); ?></label>
<input id="sitename" name="sitename" type="text" class="input" size="30" value="<?php echo esc_attr(stripslashes($sitename)); ?>" /><span class="pmpro_asterisk"> <abbr title="Required Field">*</abbr></span>
<?php
global $current_site;
$site_domain = preg_replace( '|^www\.|', '', $current_site->domain );

if ( !is_subdomain_install() )
$site = $current_site->domain . $current_site->path . __( 'sitename' );
else
$site = __( '{site name}' ) . '.' . $site_domain . $current_site->path;

echo '<p><strong>' . esc_html( sprintf( __( 'Your address will be %s', 'pmpro-network' ), $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.', 'pmpro-network' ) . '</p>';
?>
<fieldset id="pmpro_site_fields" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fieldset', 'pmpro_payment_information_fields' ) ); ?>">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<legend class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_legend' ) ); ?>">
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_heading pmpro_font-large' ) ); ?>">
<span class="pmpro_checkout-h2-name"><?php esc_html_e( 'Site Information', 'pmpro-network'); ?></span>
</h2>
</legend>
<span>
<?php echo sprintf( __( 'Sites Included: <strong>%s</strong>', 'pmpro-network' ), pmpron_getSiteCredits($level_id), 'pmpro-network'); ?></span>
</span>
<div class="pmpro_checkout-fields">
<?php
//check if the user already has a blog
if( $current_user->ID ) {
$all_blog_ids = pmpron_getBlogsForUser( $current_user->ID );
$blog_id = get_user_meta( $current_user->ID, "pmpron_blog_id", true );
if( count( $all_blog_ids ) > 1 ) {
$blogname = "many";
} elseif( $blog_id ) {
$user_blog = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE blog_id = '" . $blog_id . "' LIMIT 1" );
$blogname = get_blog_option( $blog_id, "blogname" );
}
}

if( !empty( $blogname ) ) {
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_checkout-field' ) ); ?>">
<p>
<?php if( $blogname == "many" ) { ?>
<?php esc_html_e( 'You will be reclaiming your previous sites.', 'pmpro-network' ); ?>
<?php } else { ?>
<?php echo sprintf( __( 'You will be reclaiming your site <strong>%s</strong>.', 'pmpro-network' ), $blogname ); ?>
</p>
<input type="hidden" name="blog_id" value="<?php echo esc_attr( $blog_id ); ?>" />

</div>
<?php
}
} else {
?>
</div> <!-- end pmpro_checkout-field-sitename -->
<div class="pmpro_checkout-field pmpro_checkout-field-sitetitle">
<label for="sitetitle"><?php esc_html_e( 'Site Title', 'pmpro-network' ); ?></label>
<input id="sitetitle" name="sitetitle" type="text" class="input" size="30" value="<?php echo esc_attr(stripslashes($sitetitle)); ?>" /><span class="pmpro_asterisk"> <abbr title="<?php esc_attr_e( 'Required Field', 'pmpro-network' ); ?>">*</abbr></span>

</div> <!-- end pmpro_checkout-field-sitetitle -->
<?php
}
?>
</div> <!-- end pmpro_checkout-fields -->
</div> <!-- end pmpro_site_fields -->
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_checkout-field pmpro_checkout-field-sitename' ) ); ?>">
<label for="sitename" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ) ?>">
<?php esc_html_e( 'Site Name', 'pmpro-network' ); ?>
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_asterisk' ) ); ?>">
<abbr title="<?php esc_attr_e( 'Required Field', 'pmpro-network' ); ?>">*</abbr>
</label>
<input id="sitename" name="sitename" type="text" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-text') ) ?>" size="30" value="<?php echo esc_attr( stripslashes( $sitename ) ); ?>" />
<?php
global $current_site;
$site_domain = preg_replace( '|^www\.|', '', $current_site->domain );

if ( !is_subdomain_install() ) {
$site = $current_site->domain . $current_site->path . __( 'sitename' );
} else {
$site = __( '{site name}' ) . '.' . $site_domain . $current_site->path;
}
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_hint' ) ) ?>">
<p>
<?php echo esc_html( sprintf( __( 'Your address will be %s', 'pmpro-network' ), $site ) ); ?>
</p>
<p>
<?php echo __( '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.', 'pmpro-network' ) ?>
</p>
</div>
</div> <!-- end pmpro_checkout-field-sitename -->
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_checkout-field pmpro_checkout-field-sitetitle' ) ); ?>">
<label for="sitetitle" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ) ?>" >
<?php esc_html_e( 'Site Title', 'pmpro-network' ); ?>
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_asterisk' ) ); ?>">
<abbr title="<?php esc_attr_e( 'Required Field', 'pmpro-network' ); ?>">*</abbr>
</label>
<input id="sitetitle" name="sitetitle" type="text" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-text') ) ?>" size="30" value="<?php echo esc_attr( stripslashes( $sitename ) ); ?>" size="30" value="<?php echo esc_attr(stripslashes($sitetitle)); ?>" />
</div> <!-- end pmpro_checkout-field-sitetitle -->
<?php
}
?>
</div> <!-- end pmpro_checkout-fields -->
</div> <!-- end pmpro_card_content -->
</div> <!-- end pmpro_card -->
<?php
}
add_action('pmpro_checkout_boxes', 'pmpron_pmpro_checkout_boxes');
Expand Down