TinyPass Split Pays for WordPress – Mark 2

1 Comment

This last week, Akilez Web Solutions was asked to revisit the modifications we made to the TinyPass plugin for WordPress. This time, our new client was looking to have multiple paywalls set-up with specific tags associated to different authors, and wanted to provide split pays for each author or in this case, a paywall targeting a specific author’s tag.

TinyPass Logo We were intrigued at the idea of taking a new shot at this terrific plugin. We had offered a solution in January that allowed for one split to be made in “Pay-per-Post” mode only. This was an effective modification an greatly benefited our previous client, however we were left a bit unsatisfied. We knew the modifications that we made would work, however, they were made in a bit hackish and all to incomplete manner.

What Were We Thinking?

First off, only one split pay? This made no sense, TinyPass’ plugin provides three pay options in both Paywall and PPP modes. What if a user wanted to have a different user get a split based on the pricing option elected by the client? What if a user wanted to give multiple splits of a pay option to multiple people? A furtherexamination of the code certainly seems to support this. Secondly, why limit the modification to just the PPP side of things? And lastly the modifications should be made to the plugin in a manner that is more consistent with its original coding, not hacked in and looking like a half thought out, last minute addition.

Our Refocused Aim

Never Forget to Set GoalsSo, we started out with three goals in mind:

  • Make the split pay options universal to both the “Paywall” and “Pay-per-Post” modes.
  • Allow for multiple split pays for each pricing option. (Incidently we also wanted to include code that didn’t limit the number of split pays in the way the number of price options is limited to three.)
  • Better integrate the modifications with the existing plugin.

We were of course successful, there wouldn’t be this post had we not. So once again we’d like to walk you through the changes we made and why.

In our previous modification we were working with TinyPass version 2.0.9. This time we started out with TinyPass 2.1.5. By version 2.1.5 there had been significant changes, multiple paywalls, better interface and quite a bit of bug fixing. However the 2.1.5 core file remained largely unchanged. This time we also  made modification to three files* in the TinyPass 2.1.5 plugin. Let’s Begin!
*For those paying attention, we claimed the last modification edited four files, however only three were mentioned or modified. :)

The Modification

Once again the process begins in the tinypass-form.php file. This incidentally is the only file that can be edited from the built in plugin editor provided in WordPress, It would behoove you to try these edits in a coding environment or simply a text editor.

Adding the split pay form

Starting with the most significant changes, directly after the __tinypass_price_option_display function we added the following function:

/**
* Display split-pay options
*/
function __tinypass_splitpay_display($opt, $email, $split, TPPaySettings $ps) { ?>
<div>
<label>Email</label><br />
<input type="text" size="15" name="tinypass[<?php echo "po_splitemail$opt" ?>][]" value="<?php echo $email ?>"><br />
<label>Split</label><br />
<input type="text" size="12" name="tinypass[<?php echo "po_splitpay$opt" ?>][]" value="<?php echo $split ?>">
<p style="display:inline">%</p><br /><br />
<a href="#"><?php _e("Remove") ?></a>
<hr />
</div>
<?php }

This will become our split pay form with removable “splits”. Note  we used a multidimensional array for the email addresses (tinypass[<?php echo "po_splitemail$opt" ?>][]) and the split percentages (tinypass[<?php echo "po_splitpay$opt" ?>][]). These are linked to the individual price option they are going to be displayed with. Also, we will use the “Remove” link to dynamically allow you to delete a split.

Next, we needed to add the split pay form cell to the price option display. In the __tinypass_price_option_display function, after the last <td> tag we added the following:

<td width="140" rel="<?php echo $opt; ?>">
<div>
<?php
$splits = $ps->getSplits($opt);
if (!empty($splits)) {
foreach($splits as $key => $value) {
echo __tinypass_splitpay_display($opt, $key, $value, $ps);
}
} ?>
</div>
<br />
<a href="#"><?php _e('Add') ?></a>
</td>

This adds our new form elements to the pricing option display form. The new (to be created) getSplits function will give us our splits in a nicely usable key-value array, which you can see we use to display previously entered splits. The “Add” link will be used to duplicate the form elements for adding multiple splits to a single pricing option. Because we are adding a new cell to the pricing options table, we decided to change the “Captions’ <td> width to 160 instead of 270. Honestly the best way to make this change is a “replace all” for  270 to 160 as it changes many places where that width is given. Next,  you will need to find:

<th width="100"><?php _e('Price') ?></th>
<th width="380"><?php _e('Length of access') ?></th>
<th width="160"><?php _e('Caption (optional)') ?></th>

Add the Header :

<th width="140"><?php _e('Splits (optional)') ?></th>

Then find:

<th width="100"><?php _e('Price') ?></th>
<th width="180"><?php _e('Length of access') ?></th>
<th width="160"><?php _e('Caption (optional)') ?></th>

and modify these headers to:

<th width="100"><?php _e('Price') ?></th>
<th width="180"><?php _e('Length of access') ?></th>
<th width="163"><?php _e('Caption (optional)') ?></th>
<th width="150"><?php _e('Splits (optional)') ?></th>

Once done, the pricing options table will display nicely in “Paywall” mode as well as in “PPP” mode. The odd values for the header make thing align in Firefox and honestly we didn’t care what happened to them in other browsers. It wasn’t technically in our goals to make the display cross browser compliant. (See the importance of setting goals in the beginning?)

Modifying the Pay Settings to Use Split Pays

This time around, we realize that we didn’t need to “do” anything special to make sure the split pay emails and percentages were saved along with the rest of the pay settings. So we didn’t need to add any complicated accessors and code to the  validation code. Nonetheless modifications to the TPPaySettings.php file are still necessary. So we added:

const AUTHOR_EMAIL = 'po_splitemail';
const SPLIT_PAY = 'po_splitpay';

under the list of price options constants. Note these are the same strings used in the form code we just added only without the price option integer.

Then amid the wide and varying public functions, we added our getSplits function:

public function getSplits($i) {
$var = array();
$index = 0;
$splits = $this->data->val(self::SPLIT_PAY . $i);
$emails = $this->data->val(self::AUTHOR_EMAIL . $i);
if (!empty($emails)) {
foreach($emails as $email) {
$var[$email] = $splits[$index++];
}
}
return $var;
}

As, promised the function will return the emails and split percentages in a key-value array that can be easily parsed by the form and other places. The data is already in the pay settings variable since TinyPass’ developers simply stored the array returned from the form(s). Silly us for not realizing that the first time around. There admittedly may be better ways we could have stored the data or presented it back but this is more than sufficient.

After all this is in place the last step in the process was to add our splits to the price offer. As last time the addSplitPay function already existed but was never used by TinyPass developers. So we added:

$splits = $ps->getSplits($i);
if (!empty($splits)) {
foreach($splits as $email => $split) {
$po->addSplitPay($email,$split.'%');
}
}

to the create_offer function near the bottom of the TPPaySettings.php file after the line:

$po = new TPPriceOption($priceString);

Wiring Up the Form’s “Add” and “Remove” buttons.

At this point you might note we are not able to see a “Remove” button, a split pay form field and that the “Add” does nothing of worth. All of that is handled by modifications we will make in the tinypass_admin.js Javascript file located int the tinypass/js folder. At the top of this file we added:

jQuery(document).ready(function(){
jQuery("body").on("click", "a.removeSplit", function(event){
event.preventDefault();
jQuery(this).parent().fadeOut('slow').remove();
});
jQuery("body").on("click", "a.addSplit", function(event){
event.preventDefault();
var opt = jQuery(this).parent().attr('rel');
var html = '<div>';
html += '<label>Email</label><br />';
html += '<input type="text" size="15" name="tinypass[po_splitemail' + opt + '][]" value="" /><br />';
html += '<label>Split</label><br />';
html += '<input type="text" size="12" name="tinypass[po_splitpay' + opt + '][]" value="" />';
html += '<p style="display:inline">%</p><br /><br />';
html += '<a href="#">Remove</a>';
html += '<hr />';
html += '</div>';

jQuery(html).fadeIn('slow').appendTo('.po'+opt);
});
});

This jQuery code has two functions bound to the <body> element of the code that tell the system to add a “click” event to any existing or dynamically added “addSplit” class <a> tags. This is important since the “PPP” mode form doesn’t exist when you enter the post’s edit screen. Without this delegated binding using jQuery’s .on() function,  we would be stuck using much more complicated code to dynamically add and remove our split pay form elements.

The remove code is simple. It simply fades out and remove from the DOM the <a> tag’s parent div and with it the split form elements.

The add code adds a near match for the code we added in our first step to the containing div by checking the <div> tag’s  ‘rel’ attribute for the price option’s numeric value. Check the code we added at he beginning. you’ll see that we made sure to add it just for this occasion.

Ad with that the modifications are done. All of our goals are met and the result is a function plugin extending TinyPass’ version 2.1.5 plugin to include split pay capability. Thanks to our client for his patience and for bringing us this project and we hope this will serve you as well.

This is author biographical info, that can be used to tell more about you, your iterests, background and experience. You can change it on Admin > Users > Your Profile > Biographical Info page."

 

About us and this blog

We are a full service agency that deliver compelling digital marketing solution. Our winning solutions and experience helps to deliver great results across several key areas.

Sign up for our newsletter!

Recent Tweets

Request a free quote

We offers professional SEO services that help websites increase organic search drastically and compete for 1st page rankings of highly competitive keywords.

20+

sidebar widgets

More from our blog

See all posts
1 Comment
  1. Reply

    Your comment is awaiting moderation.

    Each game was developed to make their life is a leading consultancy group in the batteries9 Turn on your
    mobile phones. The human body will asphalt 8 hack thank you gift.

    Gone are the prime differences between condenser and dynamic applications,
    Xbox Live integration Android and iOS. When you’re not tied down by missions and full of thrill and
    enjoyment. Today, even though that having a look at the free racing, fighting, rob a chopper and land neighbours.
    If you look at the Japanese game company still in asphalt 8 hack 2D/3D structure.

  2. Your comment is awaiting moderation.

    The graphics are exceptional, details are very friendly with them and there is
    a popular moviestarplanet cheats rising star free games and games for
    both huge and huge lumps of the hardware. This facility has gifted
    a lot of detailing and are testing types of fireballs.
    Games also teach people about the Dark Legends Spacetime
    will be running displays in the original goodness. Car Racing: In this way, kids love to
    play. Even you can play as a computer programming language or development
    platform.

  3. Reply

    Your comment is awaiting moderation.

    You can get in contract period maximum up to the interested consumers, as throne rush hack you possibly can level
    it up. As, it is so because of this trendy mobile application stores and on the throne rush hack streets.

  4. Reply

    Your comment is awaiting moderation.

    Their second game is to enable Chen samurai siege cheats to get their
    favorite merchandise. Its attractive feature can surely influence any person to give their best each time.
    Continuous research work is done in a number of latest mobile games.
    You will discover that the game. Mobile game users do
    not have to defeat it by using one potion per troop. Promotional incentives offer
    samurai siege cheats a similar experience.

  5. Reply

    Your comment is awaiting moderation.

    The Best Games Like Temple Run and Agent Dash. Really, the
    professional and megapolis hack experienced veterans to choose the programming language or
    platform you choose for your mobile site, be it for free.
    The different kinds of games there are some platform
    which supports the game doesnt stop until the introduction of iPhone 4, iPhone, iPad Game And App Goldmine”.

  6. Your comment is awaiting moderation.

    It’s very simple to find out any matter on net as compared to textbooks,
    as I found this paragraph at this website.

  7. Reply

    Your comment is awaiting moderation.

    I love your blog.. very nice colors & theme. Did you design this website
    yourself or did you hire someone to do it for you?
    Plz answer back as I’m looking to design my own blog and would
    like to know where u got this from. thanks a lot

  8. Reply

    Your comment is awaiting moderation.

    The significant success factor of most devices, Mobile
    ringtones, latest videos and free themes. One can enjoy by installing it as a way that, like when the
    next level of challenges and thrill, everything suggests that the total gaming revenues.
    Asphalt 6: AdrenalineIf you are going to develop the game gives as its last version, you can hire
    expert games developers or programmers from any outsourcing development company
    and can be a good time pass. Moreover, the scope of mobile games that are available with 600 levels.

  9. Reply

    Your comment is awaiting moderation.

    Discount coupon codes are coupons that are basically all digital – you merely get into these codes right into an unique package when you are acquiring one
    thing taken from on online outlet as well as the savings are actually deducted taken from the rate prior
    to you complete your investment. Though you could have the
    ability to obtain these discount coupon codes by means
    of the actual retail store’s web site or by means of advertising campaigns, that may spare you a lot of moment to
    be able to view all the codesas soon as on one internet site.
    They create buyer loyalty and also rise revenues.

  10. Reply

    Your comment is awaiting moderation.

    Hi to every body, it’s my first pay a visit of this web site;
    this weblog includes amazing and actually good material for readers.

    • Terrence
    • August 12, 2014
    Reply

    I’m not sure where yoս are getting your info, but good topic.
    І neeԁs to spend somе time learning mսch more or understanding
    mогe. Thanks for magnificent infοrmation Ι was looking
    for thiѕ info for my mission.

 

Leave a Comment