TinyPass Split Pays for WordPress – Mark 2

No Comments

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
No Comments
  1. Reply

    Your comment is awaiting moderation.

    That means 1 out of 4 Xbox’s will get the Red Ring
    of Death. The show-stopper is Super AMOLED
    screen, taking the class-leading AMOLED screen used on Samsung’s
    range in 2009 even further, with clearly richer and more vibrant
    colors. Unplug the power cord from the wall first, and THEN from your
    computer. Contoured grip ensures peak performance and comfort-even in the most intense gaming sessions.

  2. Your comment is awaiting moderation.

    privatleasing bil korttid
    privatleasing bil erbjudande
    privat leasing bil kalkulator

    Generally the information we have given you earlier about Kiosks is applicable to gift shops, with several exceptions.
    Well then, your missing from an easy income river. With a single meeting,
    the most confusing questions will be addressed.

    privatleasing bil vad ingår
    privatleasing hedin bil
    privatleasing bil audi a1

  3. Reply

    Your comment is awaiting moderation.

    Menopause is the process by which the ovaries stop ovulating and releasing
    eggs, and hence the entire process of menstruation comes
    to an end. Today, she uses key performance indicators to monitor her financial health on a
    monthly basis. It is good to make some noises during
    oral because this spices things up and keeps him interested.
    Always, make certain that you strive to get the cheapest car insurance for 17 year
    olds quotes available in the market today.

  4. Reply

    Your comment is awaiting moderation.

    Wrap dresses for pregnant mothers is an excellent design option. That dream of higher
    education without having to worry the cost of it is now a thing of the past.

    It is good to make some noises during oral because this spices things up and keeps him interested.

    Despite Chinese martial arts being very different from western styles boxing
    European began calling the Chinese martial artists Boxers and
    the name stuck.

  5. Reply

    Your comment is awaiting moderation.

    Very rapidly this website will be famous amonng all blog users, due to
    it’s pleasant posts

  6. Reply

    Your comment is awaiting moderation.

    The hand wash symbol is commonly discovered on the care labels
    of delicate supplies such as wool and silk.

  7. Reply

    Your comment is awaiting moderation.

    All you hear is how Mexicans solely take jobs People won’t do.
    That could be a enormous load of crap, fed to us by the robber barons
    and executives., On the end of the program, you may be able to take your state electrician licensure examination and work in electrical upkeep and
    building. – la ehow, Lineman apprentice programs near
    Concerned with planning, budgeting and overseeing a undertaking from start to finish, a building manager has one of many hardest jobs on the construction web site.

  8. Reply

    Your comment is awaiting moderation.

    Remember, these games are the same as before – I mean blackjack is blackjack whether or not it’s played with fancy graphics.

    In doing a little additional leg work, you may get a
    game for a bargain. All of that money goes untaxed, unregulated, and
    often into the pockets of organized crime.

    • porn
    • April 15, 2015
    Reply

    Your comment is awaiting moderation.

    Hello, I wish for to subscribe for this blog to obtain latest updates,
    thus where can i do it please help.

  9. Your comment is awaiting moderation.

    I think what you posted made a lot of sense. But, think about
    this, suppose you typed a catchier title? I mean, I don’t wish to
    tell you how to run your blog, but suppose you added a post
    title that makes people desire more? I mean TinyPass Split Pays
    for WordPress – Mark 2 – Akilez Web Solutions is kinda plain. You ought to look at Yahoo’s home page and watch how they create news titles to grab viewers interested.

    You might try adding a video or a pic or two to get people interested about everything’ve got to say.
    In my opinion, it might make your website a little bit more interesting.

  10. Reply

    Your comment is awaiting moderation.

    Use Sn0wbreeze for Windows, or PwnageTool for Mac.

    It adds badges for missed calls, e-mails, phone calls and hushed status bar.
    You can delight in your iPad.

  11. Reply

    Your comment is awaiting moderation.

    Generally I don’t read post on blogs, but I would like to say that this write-up very forced me to take
    a look at and do so! Your writing style has been surprised me.
    Thanks, very great post.

    • j
    • April 6, 2015
    Reply

    Your comment is awaiting moderation.

    Hurrah! Іn the end I gߋt a blogg ffrom ѡɦere I can genuinely oƄtain helpful
    data regarding my study and knowledge.

  12. Reply

    Your comment is awaiting moderation.

    Wonderful post! We are linking to this great content on our
    site. Keep up the good writing.

  13. Your comment is awaiting moderation.

    Dungeon Hunter 4 – The famous and thrilling recreation is now out
    there for download on android!

  14. Your comment is awaiting moderation.

    Look into lodge packages that features complimentary breakfast, free use of resort; facilities just like the
    fitness center and pool, butler service, and many others.

  15. Reply

    Your comment is awaiting moderation.

    It’s awesome to pay a visit this website and reading the views of all
    colleagues concerning this piece of writing, while I am also
    zealous of getting familiarity.

  16. Reply

    Your comment is awaiting moderation.

    Aside from this advantage, there are other benefits of watching movies online and they are:.
    Nebraska depicts how a fragile flower of love tries its best to retain its petals despite the prevailing rough weather.
    If you are a movie lover then you would easily understand how
    movies and the act of movie watching can be intoxicating.

  17. Reply

    Your comment is awaiting moderation.

    This blog was… how do you say it? Relevant!!

    Finally I’ve found something which helped me. Appreciate
    it!

  18. Reply

    Your comment is awaiting moderation.

    I used to be suggested this website via my cousin. I am not positive whether
    this post is written through him as no one else recognise such distinct
    about my trouble. You’re wonderful! Thank you!

  19. Reply

    Your comment is awaiting moderation.

    It’s actually very complicated in this full of activity life to
    listen news on Television, so I just use world wide web for that
    purpose, and obtain the most recent news.

    • Gay
    • February 23, 2015
    Reply

    Your comment is awaiting moderation.

    Great beat ! I would like to apprentice at the sae time
    as you amend your web site, how could i subscribe for a bpog website?

    The account helped me a acceptable deal. I were a little bit
    familiar of this your broadcast provided vibrant transparent idea

  20. Your comment is awaiting moderation.

    I’ve been surfing online more thnan 3hours nowadays, but I by
    no means found any attention-grabbing article like yours.
    It is pretty price enough foor me. In my view, if all site
    owners and bloggers made excellent content ass you did, the net will likely be a
    lot more useful than ever before.

 

Leave a Comment