Suggestion for Pay To Blog

I found the sign up process for a new blog confusing when using pay-to-blog.

After signing up, the actual site is visible, and a user only sees the message and payment links when they try to login.

I feel like the payment option should happen as they signup and the site should not be there at all for a new blog when they first signup but have not paid yet.

I don't know if this would work for everyone's process, but it works for me.

Simply added a similar function as 'pay_to_blog_check' to the 'get_header' action hook. I tested different action hooks - init, etc. but needed to add it after the 'template_redirect' hook or else existing pages and 404 errors would send people to the live site (which I am trying to hide).

This way, any attempt to view the site when logged in will redirect to the payment page. Any attempt to view when not logged in, will redirect to the login page.

This is what I added:

add_action ('get_header', 'pay_to_blog_site_check',0);

function pay_to_blog_site_check() {
global $wpdb;
if ( $wpdb->blogid != 1 && !is_site_admin() ) {
if ( !strpos($_SERVER['REQUEST_URI'], 'wp-admin/blog.php') ) {
$blog_expire = get_option('blog_expire');
if ( empty( $blog_expire ) || $blog_expire == '0' ) {
$now = time();
$now = $now - 30;
$blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
$blog_expire = $blog_expire * 86400;
$blog_expire = $now + $blog_expire;
update_option('blog_expire', $blog_expire);
}
if ( time() > $blog_expire ) {
wp_redirect( get_option('wpurl') .'/wp-admin/blog.php');
}
}
}
}

  • 2Ps

    Hey Marty this sounds great . Problem for me is that I don't understand hooks other than from fishing and I only went fishing once in my life.

    Any chance you could share here the complete modified file, its name and location?

    That would be super helpfull and I concur with your observation and am facing the same challenge.

    Many thanks in advance,

    Ralf

    P.S. Is this code for WP 3 or older ?

  • 2Ps

    Hi again,

    does the code above go into pay-to-blog.php?

    I tried as below but I'm getting the following error:

    Parse error: syntax error, unexpected T_FUNCTION in /home/grandsun/public_html/wp-content/mu-plugins/pay-to-blog.php on line 45

    Here's what is did:

    //------------------------------------------------------------------------//
    //---Hook-----------------------------------------------------------------//
    //------------------------------------------------------------------------//
    add_action('admin_menu', 'pay_to_blog_plug_pages');
    add_filter('wpabar_menuitems', 'pay_to_blog_admin_bar');
    add_action('admin_head', 'pay_to_blog_blog_check');
    add_action('admin_menu', 'pay_to_blog_modify_menu_items',99);

    add_action ('get_header', 'pay_to_blog_site_check',0)

    //------------------------------------------------------------------------//
    //---Functions------------------------------------------------------------//
    //------------------------------------------------------------------------//
    function pay_to_blog_site_check() {
    global $wpdb;
    if ( $wpdb->blogid != 1 && !is_site_admin() ) {
    if ( !strpos($_SERVER['REQUEST_URI'], 'wp-admin/blog.php') ) {
    $blog_expire = get_option('blog_expire');
    if ( empty( $blog_expire ) || $blog_expire == '0' ) {
    $now = time();
    $now = $now - 30;
    $blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
    $blog_expire = $blog_expire * 86400;
    $blog_expire = $now + $blog_expire;
    update_option('blog_expire', $blog_expire);
    }
    if ( time() > $blog_expire ) {
    wp_redirect( get_option('wpurl') .'/wp-admin/blog.php');
    }
    }
    }
    }

    function pay_to_blog_modify_menu_items() {
    global $submenu, $menu, $wpdb;
    if ( $wpdb->blogid != 1 && !is_site_admin() ) {
    //if ( $wpdb->blogid != 1 ) {
    $blog_expire = get_option('blog_expire');
    if ( empty( $blog_expire ) || $blog_expire == '0' ) {
    $now = time();
    $now = $now - 30;
    $blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
    $blog_expire = $blog_expire * 86400;
    $blog_expire = $now + $blog_expire;
    update_option('blog_expire', $blog_expire);
    }
    if ( time() > $blog_expire ) {
    for ( $counter = 0; $counter <= 101; $counter += 1) {
    unset($menu[$counter]);
    }
    $menu[5] = array(__('Blog Account'), 'read', 'blog.php');
    }
    }
    }

    and so on...

    Many thanks for your support.

    Ralf

  • Marty Thornley

    Hey Raif,

    Everything you did looks fine, short one thing...

    add_action ('get_header', 'pay_to_blog_site_check',0)

    is missing a semi-colon at the end. It should be:

    add_action ('get_header', 'pay_to_blog_site_check',0);

    I actually added another file called 'pay_to_blog_custom.php' to my 'mu-plugins' folder, just to keep my additions separate from the actual plugin. But you can do what you did as well.

  • 2Ps

    Ok great.

    Thanks Marty,

    so now I did this:

    /mu-plugins/pay-to-blog-custom.php

    <?php
    /*
    Plugin Name: Pay To Blog Custom (must pay to view blog)

    Author: Marty Thornley
    Version: 1.0
    Author URI: http://martythornley.com/
    */

    add_action ('get_header', 'pay_to_blog_site_check',0);

    function pay_to_blog_site_check() {
    global $wpdb;
    if ( $wpdb->blogid != 1 && !is_site_admin() ) {
    if ( !strpos($_SERVER['REQUEST_URI'], 'wp-admin/blog.php') ) {
    $blog_expire = get_option('blog_expire');
    if ( empty( $blog_expire ) || $blog_expire == '0' ) {
    $now = time();
    $now = $now - 30;
    $blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
    $blog_expire = $blog_expire * 86400;
    $blog_expire = $now + $blog_expire;
    update_option('blog_expire', $blog_expire);
    }
    if ( time() > $blog_expire ) {
    wp_redirect( get_option('wpurl') .'/wp-admin/blog.php');
    }
    }
    }
    }
    ?>

    No errors!

    Hurray!

    I'll have a play with this and will report back. Very exciting stuff.

    Best,
    Ralf

  • Marty Thornley

    Awesome. No need for the formal plugin stuff or my info though. This was just a quick hack added onto the one they provide here.

    Plus unlike the plugins folder, you don't need to add the plugin info to the top. The 'mu-plugins' folder is great, it's like a giant functions.php - just throw functions in there and they work. That can make it dangerous too though. With no need to activate the plugins, they just do what they do when you go to the site.

  • 2Ps

    Thanks Marty,

    First part worked flawlessly, blog is redirecting to the login page when not paid up.

    I then tried to log in, but got this error message:

    Fatal error: Call to undefined function wp_get_current_user() in /home/grandsun/public_html/wp-includes/capabilities.php on line 1059

    Any ideas?

    Refreshing the log-in page did not repeat the error and I am now seeing the payment page.

    Nice!

    Thanks
    Ralf

  • Marty Thornley

    Thanks guys! Happy to help. Much more on its way :slight_smile:

    Actually found a few issues with this solution...

    Turns out, my little hack doesn't recognize sites set up for free. The way I did it, means any old site would end up having its 'blog_expires' option set to some value as soon as it is viewed (I think some combo using the demo period?) but that activates the rest of the plugin an the blog will expire soon.

    Had to make some fairly major changes to work around this, but its all good since I wanted to add the ability to make a site permanently free anyway. So added the option to make it permanently free, revert to a demo state, or revert to the paid state. Seems to be working pretty well.

    Made some other little tweaks to make it fit my needs as well.

    Tried attaching as .txt file but it said wrong mime?

    Copy and pasted here............

    /*
    Plugin Name: Pay To Blog
    Plugin URI:
    Description:
    Author: Andrew Billits (Incsub)
    Version: 1.5.3
    Author URI:
    */

    /*
    Copyright 2007-2009 Incsub (http://incsub.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    */

    //------------------------------------------------------------------------//
    //---Hook-----------------------------------------------------------------//
    //------------------------------------------------------------------------//

    // added this as a way to easily shut off the plugin for testing purposes. Just make the value of PAY_TO_BLOG_HOLD anything but '' and the plugin will be inactive.
    if ( !defined('PAY_TO_BLOG_HOLD') ) { define ('PAY_TO_BLOG_HOLD' , '' ); };

    add_action('admin_menu', 'pay_to_blog_plug_pages');

    if ( PAY_TO_BLOG_HOLD == '' ) {
    add_filter('wpabar_menuitems', 'pay_to_blog_admin_bar');
    add_action('admin_head', 'pay_to_blog_blog_check');
    add_action('admin_menu', 'pay_to_blog_modify_menu_items',99);
    };
    //------------------------------------------------------------------------//
    //---Functions------------------------------------------------------------//
    //------------------------------------------------------------------------//

    add_action ('get_header', 'pay_to_blog_site_check',0);

    function pay_to_blog_site_check() {
    global $wpdb;
    $blog_free = get_option('blog_free_time');

    if ( $wpdb->blogid != 1 && !is_site_admin() && $blog_free != 'forever' && PAY_TO_BLOG_HOLD == '' ) {
    if ( !strpos($_SERVER['REQUEST_URI'], 'wp-admin/blog.php') ) {
    $blog_expire = get_option('blog_expire');

    if ( empty( $blog_expire ) || $blog_expire == '0' ) {
    $now = time();
    $now = $now - 30;
    $blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
    $blog_expire = $blog_expire * 86400;
    $blog_expire = $now + $blog_expire;
    update_option('blog_expire', $blog_expire);
    }
    if ( time() > $blog_expire ) {
    wp_redirect( get_option('wpurl') .'/wp-admin/blog.php');
    }
    }
    }
    }

    function pay_to_blog_modify_menu_items() {
    global $submenu, $menu, $wpdb;
    if ( $wpdb->blogid != 1 && !is_site_admin() ) {
    //if ( $wpdb->blogid != 1 ) {
    $blog_expire = get_option('blog_expire');
    if ( empty( $blog_expire ) || $blog_expire == '0' ) {
    $now = time();
    $now = $now - 30;
    $blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
    $blog_expire = $blog_expire * 86400;
    $blog_expire = $now + $blog_expire;
    update_option('blog_expire', $blog_expire);
    }
    if ( time() > $blog_expire ) {
    for ( $counter = 0; $counter <= 101; $counter += 1) {
    unset($menu[$counter]);
    }
    $menu[5] = array(__('Blog Account'), 'read', 'blog.php');
    }
    }
    }

    function pay_to_blog_blog_check() {
    global $wpdb;
    if ( $wpdb->blogid != 1 && !is_site_admin() ) {
    if ( !strpos($_SERVER['REQUEST_URI'], 'blog') ) {
    $blog_expire = get_option('blog_expire');
    if ( empty( $blog_expire ) || $blog_expire == '0' ) {
    $now = time();
    $now = $now - 30;
    $blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
    $blog_expire = $blog_expire * 86400;
    $blog_expire = $now + $blog_expire;
    update_option('blog_expire', $blog_expire);
    }
    if ( time() > $blog_expire ) {
    echo "
    <SCRIPT LANGUAGE='JavaScript'>
    window.location='blog.php';
    </script>
    ";
    //wp_redirect('blog.php');
    }
    }
    }
    }

    function pay_to_blog_plug_pages() {
    global $wpdb, $wp_roles, $current_user;
    if ( is_site_admin() ) {
    add_submenu_page('ms-admin.php', 'Pay To Blog', 'Pay To Blog', 10, 'pay-to-blog', 'pay_to_blog_output');
    }
    if ( $wpdb->blogid != 1 ) {
    add_menu_page('Blog Account', 'Blog Account', 0, 'blog.php');
    }
    }

    function pay_to_blog_admin_bar( $menu ) {
    unset( $menu['blog.php'] );
    return $menu;
    }

    function pay_to_blog_extend($period, $blog_id) {
    switch_to_blog($blog_id);
    $now = time();
    if ( $period == '1' ) {
    $expires = $now + 2629744;
    } else if ( $period == '3' ) {
    $expires = $now + 7889231;
    } else if ( $period == '12' ) {
    $expires = $now + 31556926;
    }
    update_option( 'blog_expire', $expires );
    restore_current_blog();
    }

    //------------------------------------------------------------------------//
    //---Output Functions-----------------------------------------------------//
    //------------------------------------------------------------------------//

    function pay_to_blog_paypal_button_output($period) {
    global $wpdb, $current_site, $current_user;
    // Live URL: https://www.paypal.com/cgi-bin/webscr
    // Sandbox URL: https://www.sandbox.paypal.com/cgi-bin/webscr
    if (get_site_option( "pay_to_blog_paypal_status" ) == 'live'){
    $action = 'https://www.paypal.com/cgi-bin/webscr';
    } else {
    $action = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    }

    $blog_url = get_blogaddress_by_id($wpdb->blogid);
    if ( $period == '1' ) {
    $amount = get_site_option( "pay_to_blog_1_cost" );
    } else if ( $period == '3' ) {
    $amount = get_site_option( "pay_to_blog_3_cost" );
    } else if ( $period == '12' ) {
    $amount = get_site_option( "pay_to_blog_12_cost" );
    }
    if ( get_site_option( "pay_to_blog_paypal_payment_type" ) == 'single' ) {
    $button = '
    <form action="' . $action . '" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="' . get_site_option( "pay_to_blog_paypal_email" ) . '">
    <input type="hidden" name="item_name" value="' . $current_site->site_name . ' Blog Activation">
    <input type="hidden" name="item_number" value="' . $period . '">
    <input type="hidden" name="amount" value="' . $amount . '">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="return" value="' . $blog_url . 'wp-admin/blog.php?updated=true&updatedmsg=' . urlencode(__('Transaction Complete!')) . '">
    <input type="hidden" name="cancel_return" value="' . $blog_url . 'wp-admin/blog.php?updated=true&updatedmsg=' . urlencode(__('Transaction Canceled!')) . '">
    <input type="hidden" name="notify_url" value="' . $blog_url . 'pay-to-blog-paypal.php">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="' . get_site_option( "pay_to_blog_currency" ) . '">
    <input type="hidden" name="lc" value="' . get_site_option( "pay_to_blog_paypal_site" ) . '">
    <input type="hidden" name="custom" value="' . $period . '_' . get_site_option( "pay_to_blog_currency" ) . '_' . $wpdb->blogid . '">
    <input type="hidden" name="bn" value="PP-BuyNowBF">
    <p class="submit" style="border:none;padding-top:2px;">
    <input type="submit" name="Submit" value="PayPal">
    </p>
    </form>
    ';
    } else {
    /*
    a3 - amount to billed each recurrence
    p3 - number of time periods between each recurrence
    t3 - time period (D=days, W=weeks, M=months, Y=years)
    */
    $button = '
    <form action="' . $action . '" method="post">
    <input type="hidden" name="cmd" value="_xclick-subscriptions">
    <input type="hidden" name="business" value="' . get_site_option( "pay_to_blog_paypal_email" ) . '">
    <input type="hidden" name="item_name" value="' . $current_site->site_name . ' Blog Activation">
    <input type="hidden" name="item_number" value="' . $period . '">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="return" value="' . $blog_url . 'wp-admin/blog.php?updated=true&updatedmsg=' . urlencode(__('Transaction Complete!')) . '">
    <input type="hidden" name="cancel_return" value="' . $blog_url . 'wp-admin/blog.php?updated=true&updatedmsg=' . urlencode(__('Transaction Canceled!')) . '">
    <input type="hidden" name="notify_url" value="' . $blog_url . 'pay-to-blog-paypal.php">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="' . get_site_option( "pay_to_blog_currency" ) . '">
    <input type="hidden" name="lc" value="' . get_site_option( "pay_to_blog_paypal_site" ) . '">
    <input type="hidden" name="custom" value="' . $period . '_' . get_site_option( "pay_to_blog_currency" ) . '_' . $wpdb->blogid . '">
    <input type="hidden" name="a3" value="' . $amount . '">
    <input type="hidden" name="p3" value="' . $period . '">
    <input type="hidden" name="t3" value="M">
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="sra" value="1">
    <p class="submit" style="border:none;padding-top:2px;">
    <input type="submit" name="Submit" value="PayPal">
    </p>
    </form>
    ';
    }
    return $button;
    }

    //------------------------------------------------------------------------//
    //---Page Output Functions------------------------------------------------//
    //------------------------------------------------------------------------//

    function pay_to_blog_output() {
    global $wpdb, $wp_roles, $current_user, $current_site;

    if(!current_user_can('manage_options')) {
    echo "<p>" . __('Nice Try...') . "</p>"; //If accessed properly, this message doesn't appear.
    return;
    }
    if (isset($_GET['updated'])) {
    ?>
    <div id="message" class="updated fade"><p><?php _e('' . urldecode($_GET['updatedmsg']) . '') ?></p></div><?php
    }
    echo '<div class="wrap">';
    switch( $_GET[ 'action' ] ) {
    //---------------------------------------------------//
    default:
    ?>
    <h2><?php _e('Pay To Blog Settings') ?></h2>
    <form method="post" action="ms-admin.php?page=pay-to-blog&action=process">
    <table class="form-table">
    <tr valign="top">
    <th scope="row"><?php _e('Currency') ?></th>
    <td>
    <select name="pay_to_blog_currency">
    <?php
    $pay_to_blog_currency = get_site_option( "pay_to_blog_currency" );
    $sel_currency = empty($pay_to_blog_currency) ? 'USD' : $pay_to_blog_currency;
    $currencies = array(
    'AUD' => 'AUD - Australian Dollar',
    'CAD' => 'CAD - Canadian Dollar',
    'CHF' => 'CHF - Swiss Franc',
    'CZK' => 'CZK - Czech Koruna',
    'DKK' => 'DKK - Danish Krone',
    'EUR' => 'EUR - Euro',
    'GBP' => 'GBP - Pound Sterling',
    'HKD' => 'HKD - Hong Kong Dollar',
    'HUF' => 'HUF - Hungarian Forint',
    'JPY' => 'JPY - Japanese Yen',
    'NOK' => 'NOK - Norwegian Krone',
    'NZD' => 'NZD - New Zealand Dollar',
    'PLN' => 'PLN - Polish Zloty',
    'SEK' => 'SEK - Swedish Krona',
    'SGD' => 'SGD - Singapore Dollar',
    'USD' => 'USD - U.S. Dollar'
    );

    foreach ($currencies as $k => $v) {
    echo ' <option value="' . $k . '"' . ($k == $sel_currency ? ' selected' : '') . '>' . wp_specialchars($v, true) . '</option>' . "\n";
    }
    ?>
    </select>

    <?php //_e('') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('PayPal Email') ?></th>
    <td>
    <input type="text" name="pay_to_blog_paypal_email" value="<?php echo get_site_option( "pay_to_blog_paypal_email" ); ?>" />

    <?php //_e('Format: 00.00 - Ex: 1.25') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('PayPal Site') ?></th>
    <td>
    <select name="pay_to_blog_paypal_site">
    <?php
    $pay_to_blog_paypal_site = get_site_option( "pay_to_blog_paypal_site" );
    $sel_locale = empty($pay_to_blog_paypal_site) ? 'US' : $pay_to_blog_paypal_site;
    $locales = array(
    'AU' => 'Australia',
    'AT' => 'Austria',
    'BE' => 'Belgium',
    'CA' => 'Canada',
    'CN' => 'China',
    'FR' => 'France',
    'DE' => 'Germany',
    'IT' => 'Italy',
    'NL' => 'Netherlands',
    'PL' => 'Poland',
    'ES' => 'Spain',
    'CH' => 'Switzerland',
    'GB' => 'United Kingdom',
    'US' => 'United States'
    );

    foreach ($locales as $k => $v) {
    echo ' <option value="' . $k . '"' . ($k == $sel_locale ? ' selected' : '') . '>' . wp_specialchars($v, true) . '</option>' . "\n";
    }
    ?>
    </select>

    <?php //_e('Format: 00.00 - Ex: 1.25') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('PayPal Mode') ?></th>
    <td>
    <select name="pay_to_blog_paypal_status">
    <option value="live" <?php if (get_site_option( "pay_to_blog_paypal_status" ) == 'live') echo 'selected="selected"'; ?>><?php _e('Live Site') ?></option>
    <option value="test" <?php if (get_site_option( "pay_to_blog_paypal_status" ) == 'test') echo 'selected="selected"'; ?>><?php _e('Test Mode (Sandbox)') ?></option>
    </select>

    <?php //_e('Format: 00.00 - Ex: 1.25') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('PayPal Payment Type') ?></th>
    <td>
    <select name="pay_to_blog_paypal_payment_type">
    <option value="single" <?php if (get_site_option( "pay_to_blog_paypal_payment_type" ) == 'single') echo 'selected="selected"'; ?>><?php _e('Single') ?></option>
    <option value="recurring" <?php if (get_site_option( "pay_to_blog_paypal_payment_type" ) == 'recurring') echo 'selected="selected"'; ?>><?php _e('Recurring') ?></option>
    </select>

    <?php _e('Recurring = PayPal Subscription') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('1 Month') ?></th>
    <td>
    <select name="pay_to_blog_1_cost">
    <?php
    $pay_to_blog_1_cost = get_site_option( "pay_to_blog_1_cost" );
    $counter = 0;
    for ( $counter = 1; $counter <= 300; $counter += 1) {
    echo '<option value="' . $counter . '"' . ($counter == $pay_to_blog_1_cost ? ' selected' : '') . '>' . $counter . '</option>' . "\n";
    }
    ?>
    </select>

    <?php _e('Cost for one month in the currency selected above.'); ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('3 Months') ?></th>
    <td>
    <select name="pay_to_blog_3_cost">
    <?php
    $pay_to_blog_3_cost = get_site_option( "pay_to_blog_3_cost" );
    $counter = 0;
    for ( $counter = 1; $counter <= 300; $counter += 1) {
    echo '<option value="' . $counter . '"' . ($counter == $pay_to_blog_3_cost ? ' selected' : '') . '>' . $counter . '</option>' . "\n";
    }
    ?>
    </select>

    <?php _e('Cost for three months in the currency selected above.'); ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('12 Months') ?></th>
    <td>
    <select name="pay_to_blog_12_cost">
    <?php
    $pay_to_blog_12_cost = get_site_option( "pay_to_blog_12_cost" );
    $counter = 0;
    for ( $counter = 1; $counter <= 300; $counter += 1) {
    echo '<option value="' . $counter . '"' . ($counter == $pay_to_blog_12_cost ? ' selected' : '') . '>' . $counter . '</option>' . "\n";
    }
    ?>
    </select>

    <?php _e('Cost for one year in the currency selected above.'); ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('Demo Period') ?></th>
    <td>
    <select name="demo_period_days">
    <?php
    $demo_period_days = get_site_option( "demo_period_days" );
    if ($demo_period_days == '' || $demo_period_days == '0' ) { $demo_period_days = 0; };
    $counter = 0;
    for ( $counter = 0; $counter <= 101; $counter += 1) {
    echo '<option value="' . $counter . '"' . ($counter == $demo_period_days ? ' selected' : '') . '>' . $counter . '</option>' . "\n";
    }
    ?>
    </select>

    <?php _e('Period (in days) before users have to pay to use their blog'); ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('Message') ?></th>
    <td>
    <textarea name="pay_to_blog_message" type="text" rows="5" wrap="soft" id="pay_to_blog_message" style="width: 95%"/><?php echo stripslashes( get_site_option('pay_to_blog_message') ) ?>
    </textarea>

    <?php _e('This message is displayed at the top of the "Blog" page.') ?>
    </td>
    </tr>
    </table>
    <p class="submit">
    <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
    </p>
    </form>
    <h3><?php _e('Extend Blog') ?></h3>
    <form method="post" action="ms-admin.php?page=pay-to-blog&action=extend">
    <?php
    $expires = get_option('blog_expire');
    $blog_free = get_option('blog_free_time');
    $now = time();
    $time_left = $expires - $now;
    if ($free == 'forever') :
    _e('This blog is currently free forever');
    elseif ($free == 'demo') :
    _e('This blog is in a free demo and expires in ' . round( $time_left / 86400 ) . ' days');
    else :
    _e('This blog expires in ' . round( $time_left / 86400 ) . 'days');
    endif;
    ?>

    <table class="form-table">
    <tr valign="top">
    <th scope="row"><?php _e('Blog ID') ?></th>
    <td>
    <input type="text" name="bid" value="<?php echo $wpdb->blogid; ?>" />

    <?php //_e('Format: 00.00 - Ex: 1.25') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('Period') ?></th>
    <td>
    <select name="extend_period">
    <?php
    $counter = 0;
    for ( $counter = 1; $counter <= 365; $counter += 1) {
    echo '<option value="' . $counter . '">' . $counter . '</option>' . "\n";
    }
    ?>
    </select>

    <?php _e('Period (in days) you wish to extend the blog.'); ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('Make this Blog Free?') ?></th>
    <td>
    <input type="radio" name="free_blog" value="forever"><?php _e('Forever'); ?></input>

    <input type="radio" name="free_blog" value="demo"><?php _e('For Standard demo period of '); echo get_site_option( "demo_period_days" ); _e(' Days'); ?></input>

    <input type="radio" name="free_blog" value="paid"><?php _e('No. Return to paid blog.'); ?></input>

    </td>
    </tr> </table>
    <p class="submit">
    <input type="submit" name="Submit" value="<?php _e('Continue') ?>" />
    </p>
    </form>
    <?php
    break;
    //---------------------------------------------------//
    case "process":
    update_site_option( "pay_to_blog_currency", $_POST[ 'pay_to_blog_currency' ] );
    update_site_option( "pay_to_blog_paypal_email", $_POST[ 'pay_to_blog_paypal_email' ] );
    update_site_option( "pay_to_blog_paypal_site", $_POST[ 'pay_to_blog_paypal_site' ] );
    update_site_option( "pay_to_blog_message", addslashes( $_POST[ 'pay_to_blog_message' ] ) );
    update_site_option( "pay_to_blog_paypal_status", $_POST[ 'pay_to_blog_paypal_status' ] );
    update_site_option( "pay_to_blog_paypal_payment_type", $_POST[ 'pay_to_blog_paypal_payment_type' ] );
    update_site_option( "pay_to_blog_1_cost", $_POST[ 'pay_to_blog_1_cost' ] );
    update_site_option( "pay_to_blog_3_cost", $_POST[ 'pay_to_blog_3_cost' ] );
    update_site_option( "pay_to_blog_12_cost", $_POST[ 'pay_to_blog_12_cost' ] );
    update_site_option( "demo_period_days", $_POST[ 'demo_period_days' ] );
    echo "
    <SCRIPT LANGUAGE='JavaScript'>
    window.location='ms-admin.php?page=pay-to-blog&updated=true&updatedmsg=" . urlencode(__('Changes saved.')) . "';
    </script>
    ";
    break;
    //---------------------------------------------------//
    case "extend":
    if ( isset($_POST['Cancel']) ) {
    echo "
    <SCRIPT LANGUAGE='JavaScript'>
    window.location='ms-admin.php?page=pay-to-blog';
    </script>
    ";
    } else {
    $blog_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "blogs WHERE blog_id = '" . $_POST[ 'bid' ] . "'");

    if ( $blog_count > 0 ) {
    switch_to_blog($_POST[ 'bid' ]);

    if ( isset($_POST['free_blog']) ) {
    $blog_free = $_POST['free_blog'];
    if ( $blog_free == 'forever' || $blog_free == 'demo' ) :
    update_option('blog_expire', $blog_free);
    update_option('blog_free_time', $blog_free);
    elseif ( $blog_free == 'paid' ) :
    update_option('blog_free_time', $blog_free);
    endif;

    }

    $blog_expire = get_option('blog_expire');
    $demo_period_days = get_site_option( "demo_period_days" );

    $now = time();
    if ($blog_expire == 'forever') {
    $expires == 'forever';
    }
    elseif ($blog_expire == 'demo' || $blog_free == 'paid' ) {
    $expires = $demo_period_days * 86400;
    $expires = $now + $expires;
    }
    elseif ( $blog_expire > $now ) {
    $expires= $_POST[ 'extend_period' ];
    $expires = $expires * 86400;
    $expires = $blog_expire + $expires;
    } else {
    $expires = $_POST[ 'extend_period' ];
    $expires = $expires * 86400;
    $expires = $now + $expires;
    }
    update_option( 'blog_expire', $expires );
    restore_current_blog();
    echo "
    <SCRIPT LANGUAGE='JavaScript'>
    window.location='ms-admin.php?page=pay-to-blog&updated=true&updatedmsg=" . urlencode(__('Blog extended.')) . "';
    </script>
    ";
    } else {
    ?>
    <h2><?php _e('Extend Blog') ?></h2>
    <p><?php _e('Invalid blog ID. Please try again.') ?></p>
    <form method="post" action="ms-admin.php?page=pay-to-blog&action=extend">
    <table class="form-table">
    <tr valign="top">
    <th scope="row"><?php _e('Blog ID') ?></th>
    <td>
    <input type="text" name="bid" value="" />

    <?php //_e('Format: 00.00 - Ex: 1.25') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('Period') ?></th>
    <td>
    <select name="extend_period">
    <?php
    $counter = 0;
    for ( $counter = 1; $counter <= 365; $counter += 1) {
    echo '<option value="' . $counter . '">' . $counter . '</option>' . "\n";
    }
    ?>
    </select>

    <?php _e('Period (in days) you wish to extend the blog.'); ?>
    </td>
    </tr>
    </table>
    <p class="submit">
    <input type="submit" name="Cancel" value="<?php _e('Cancel') ?>" />
    <input type="submit" name="Submit" value="<?php _e('Continue') ?>" />
    </p>
    </form>
    <?php
    }
    }
    break;
    //---------------------------------------------------//
    case "temp":
    break;
    //---------------------------------------------------//
    }
    echo '</div>';
    }

    function pay_to_blog_account_output() {
    global $wpdb, $wp_roles, $current_user;

    if(!current_user_can('manage_options')) {
    echo "<p>" . __('Nice Try...') . "</p>"; //If accessed properly, this message doesn't appear.
    return;
    }
    if (isset($_GET['updated'])) {
    ?>
    <div id="message" class="updated fade"><p><?php _e('' . urldecode($_GET['updatedmsg']) . '') ?></p></div><?php
    }
    echo '<div class="wrap">';
    switch( $_GET[ 'action' ] ) {
    //---------------------------------------------------//
    default:
    $blog_expire = get_option('blog_expire');
    if ( empty( $blog_expire ) || $blog_expire == '0' ) {
    $now = time();
    $now = $now - 30;
    $blog_expire = $demo_period_days = get_site_option( "demo_period_days" );
    $blog_expire = $blog_expire * 86400;
    $blog_expire = $now + $blog_expire;
    update_option('blog_expire', $blog_expire);
    }
    if ( time() > $blog_expire ) {
    $blog = 'inactive';
    } else {
    $blog = 'active';
    }
    ?>
    <h2><?php _e('Blog') ?>: <?php _e( ucfirst( $blog ) ); ?></h2>
    <p><?php echo stripslashes( get_site_option('pay_to_blog_message') ) ?></p>
    <?php
    if ( $blog == 'active' ) {
    echo __('Expires') . ': ' . date(get_option('date_format'), get_option('blog_expire', 0));
    } else {
    echo '<p>' . __('Note: Depending on your payment method it may take just a few minutes (Credit Card or PayPal funds) or it may take several days (eCheck) for your account to be activated.') . '</p>';
    echo '<p class="submit" style="padding-top:2px;">';
    echo '' . __('Activate blog for one month') . ' (' . __('for') . ' ' . get_site_option( "pay_to_blog_1_cost" ) . ' ' . get_site_option( "pay_to_blog_currency" ) . '):
    ';
    echo pay_to_blog_paypal_button_output(1);
    echo '</p>';
    echo '<p class="submit" style="padding-top:2px;">';
    echo '' . __('Activate blog for three months') . ' (' . __('for') . ' ' . get_site_option( "pay_to_blog_3_cost" ) . ' ' . get_site_option( "pay_to_blog_currency" ) . '):
    ';
    echo pay_to_blog_paypal_button_output(3);
    echo '</p>';
    echo '<p class="submit" style="padding-top:2px;">';
    echo '' . __('Activate blog for one year') . ' (' . __('for') . ' ' . get_site_option( "pay_to_blog_12_cost" ) . ' ' . get_site_option( "pay_to_blog_currency" ) . '):
    ';
    echo pay_to_blog_paypal_button_output(12);
    echo '</p>';
    }
    break;
    //---------------------------------------------------//
    case "process":
    break;
    //---------------------------------------------------//
    case "temp":
    break;
    //---------------------------------------------------//
    }
    echo '</div>';
    }

  • 2Ps

    Hi Marty,

    Just tried your modded pay-to-blog.php above and got this error:

    Parse error: syntax error, unexpected '}' in /home/grandsun/public_html/wp-content/mu-plugins/pay-to-blog.php on line 239

    this is what it looks like in the code:

    237 <div id="message" class="updated fade"><p><?php _e('' . urldecode($_GET['updatedmsg']) . '') ?></p></div><?php
    238 }
    239 echo '<div class="wrap">';
    240 switch( $_GET[ 'action' ] ) {

    Ralf

  • 2Ps

    Hi Marty,

    Just tried your modded pay-to-blog.php above and got this error:

    Parse error: syntax error, unexpected '}' in /home/grandsun/public_html/wp-content/mu-plugins/pay-to-blog.php on line 239

    this is what it looks like in the code:

    237 <div id="message" class="updated fade"><p><?php _e('' . urldecode($_GET['updatedmsg']) . '') ?></p></div><?php
    238 }
    239 echo '<div class="wrap">';
    240 switch( $_GET[ 'action' ] ) {

    I suspect copy and pasting code into the forum for re-use creates odd line breaks and such. Perhaps you could zip up the file and attach it?

    all the best,
    Ralf

  • 2Ps

    Hi Marty,

    Working on all that... Basically have ended up building my own plugin with not only choose your own price but the ability to create arbitrary custom price packages. Will be a bit of a delay (a few days) before its done and ready for testing but will update here.

    excellent!

    As for the errors...

    Did you wrap everything in php? with the '<?php' to start and '?>' at the end?

    No I did not. But now that I have it looks good.

    Thank you Marty

    best,
    Ralf

  • 2Ps

    Marty,

    been testing your custom pay-to-blog.php

    1)

    Newly created blog, unpaid, not logged in, shows login form, (works as expected)

    logged in, shows pay to blog page (wp-admin/blog.php) - (works as expected)

    2)

    superadmin extending site by one day works too, blog is showing and wp-admin/blog.php is showing the correct date

    3)

    I've not been able to test using the paypal sandbox as I keep getting a error saying that the merchant is using an incorrect link.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.