Skip to content

Commit

Permalink
Merge pull request #1173 from laterpay/develop
Browse files Browse the repository at this point in the history
Tag 2.5.3
  • Loading branch information
thrijith authored May 7, 2019
2 parents d04a43f + 9f8bc08 commit 8aa37c8
Show file tree
Hide file tree
Showing 24 changed files with 255 additions and 176 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ The plugin is available on http://wordpress.org/plugins/laterpay

1. Fork it ( https://github.com/laterpay/laterpay-wordpress-plugin/fork )
2. Run `composer install` to install all the dependencies.
3. Create your feature branch (`git checkout -b feature/my_new_feature`)
3. Create your feature branch (`git checkout -b feature/my_new_feature develop`)
4. Add your changes, verify coding standards and language compatibility ( [Check #development-notes](#development-notes) )
5. Run `gulp build` for `js` and / or `css` changes. Please check [gulpfile](gulpfile.js) for more tasks.
6. Commit your changes (`git commit -am 'Added some feature'`)
7. Push to the branch (`git push origin feature/my_new_feature`)
8. Create a new Pull Request to develop.

Note: Source code of the plugin resides in [laterpay](./laterpay) directory, you should copy / rsync files from this directory to your test site, in order to see the changes done.

⚠️ Warning: Code from this repo is only to be used for development purposes. Always use the latest version available at http://wordpress.org/plugins/laterpay for production sites.

## Development Notes

##### Please run following commands from the root directory.

1. Please verfiy your code is in compliance to the Coding Standards used in this Project.
1. Please verify your code is in compliance to the Coding Standards used in this Project.
2. Run `composer phpcs filename` or `composer phpcs laterpay` to check for PHPCS errors/warnings.
3. Run `composer phpcompat` to check if the code is compatible for PHP 5.6 and above

Expand All @@ -54,4 +58,4 @@ The LaterPay WordPress plugin uses [Semantic Versioning 2.0.0](http://semver.org

## Copyright

Copyright 2018 LaterPay GmbH – Released under MIT License
Copyright 2019 LaterPay GmbH – Released under MIT License
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "laterpay/laterpay-wordpress-plugin",
"description": "This is the official LaterPay plugin for selling digital content with WordPress",
"license": "MIT",
"version": "2.5.2",
"version": "2.5.3",
"config": {
"vendor-dir": "laterpay/vendor",
"secure-http": true
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var gulp = require('gulp'),
// OPTIONS -------------------------------------------------------------------------------------------------------------
var gulpKnownOptions = {
string: 'version',
default: { version: '2.5.2' }
default: { version: '2.5.3' }
};
var gulpOptions = minimist(process.argv.slice(2), gulpKnownOptions);
gulpOptions.svn = {};
Expand Down
18 changes: 14 additions & 4 deletions laterpay/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Contributors: laterpay, dominik-rodler, mihail-turalenka, avahura, ahryb
Donate link: https://laterpay.net
Tags: laterpay, accept micropayments, accept payments, access control, billing, buy now pay later, content monetization, creditcard, debitcard, free to read, laterpay for wordpress, laterpay payment, laterpay plugin, micropayments, monetize, paid content, pay button, pay per use, payments, paywall, PPU, sell digital content, sell digital goods, single sale, wordpress laterpay, Payments, Content Monetization, Paywall, Paid Content, Publisher, Blogger
Requires at least: 4.6
Tested up to: 5.1.1
Stable tag: 2.5.2
Tested up to: 5.2
Stable tag: 2.5.3
Author URI: https://laterpay.net
Plugin URI: https://github.com/laterpay/laterpay-wordpress-plugin
License: MIT
Expand Down Expand Up @@ -45,7 +45,9 @@ The LaterPay WordPress plugin is easy to implement and offers a user interface t
* Data sharing

= What it costs you: =

LaterPay is performance-based and works on a revenue sharing basis - for a limited time we’re charging a rate of 15% of actual revenue generated with LaterPay, ALL-INCLUSIVE.

* No payment processing fees
* No chargeback fees
* No payout fees
Expand All @@ -68,7 +70,9 @@ when you need it. Contextual help for the current page is available via the ‘H
You can find further information about LaterPay and the LaterPay WordPress plugin in the [LaterPay Knowledge Base](https://www.laterpay.net/academy).

= Is this plugin crawler friendly? =

Yes!

* *Social media:* The plugin supports Facebook, Twitter, and Google+ crawlers, so it won’t hurt your social media reach.
* *Google and Google News:* The plugin also supports Google and Google News crawlers.
* Crawlers will never have access to the full content but only to your teaser content.
Expand All @@ -84,6 +88,12 @@ Yes!
6. The plugin provides a variety of advanced settings to customize the LaterPay plugin and adjust it to your needs.

== Changelog ==
= 2.5.3 ( May 7, 2019 ) =
* Optimize code and use internal cache, to reduce queries.
* Add warning for subscription with invalid price.
* Lower Subscription Minimum value to $1.99 and 1.49€ for US and EU region respectively.
* Remove Hyperlinks from Obfuscated text.

= 2.5.2 ( April 2, 2019 ) =
* Add Advanced Tab, to inform about all advanced feature.
* Add disclaimer for Subscription voucher.
Expand Down Expand Up @@ -618,8 +628,8 @@ KNOWN BUGS:

== Upgrade notice ==

= 2.5.2 ( April 2, 2019 ) =
A new "Advanced" Tab containing information of advanced feature, updated plugin mode toggle behaviour and improvements with LaterPay functionality.
= 2.5.3 ( May 7, 2019 ) =
Code optimizations for reducing DB calls, reduced Subscription minimum value for both regions and minor improvements with LaterPay functionality.

== Arbitrary section ==

Expand Down
6 changes: 4 additions & 2 deletions laterpay/application/Controller/Admin/Pricing.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ protected function subscription_form_save( LaterPay_Core_Event $event ) {
$event->set_result(
array(
'success' => true,
'region' => get_option( 'laterpay_region', 'us' ),
'data' => $data,
'vouchers' => $vouchers,
'html' => $this->render_subscription( $hmtl_data ),
Expand Down Expand Up @@ -864,8 +865,9 @@ protected function subscription_delete( LaterPay_Core_Event $event ) {

$event->set_result(
array(
'success' => true,
'message' => esc_html__( 'Subscription deleted.', 'laterpay' ),
'success' => true,
'message' => esc_html__( 'Subscription deleted.', 'laterpay' ),
'region' => get_option( 'laterpay_region', 'us' ),
)
);
} else {
Expand Down
4 changes: 4 additions & 0 deletions laterpay/application/Controller/Frontend/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ public function prefetch_post_access( LaterPay_Core_Event $event ) {
return;
}

if ( 1 === count( $posts ) && ! LaterPay_Helper_Post::is_enabled_type( $posts[0]->ID ) ) {
return;
}

$post_ids = array();
// as posts can also be loaded by widgets (e.g. recent posts and popular posts), we loop through all posts
// and bundle them in one API request to LaterPay, to avoid the overhead of multiple API requests
Expand Down
44 changes: 0 additions & 44 deletions laterpay/application/Controller/Frontend/PreviewMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,6 @@ public static function get_subscribed_events() {
);
}

/**
* Check requirements for logging and rendering the post statistic pane via Ajax callback.
*
* @param WP_Post $post
*
* @return bool
*/
protected function check_requirements( $post = null ) {

if ( empty( $post ) ) {
// check, if we're on a singular page
if ( ! is_singular() ) {
return false;
}

// check, if we have a post
$post = get_post();
if ( $post === null ) {
return false;
}
}

// don't collect statistics data, if the current post is not published
if ( $post->post_status !== LaterPay_Helper_Pricing::STATUS_POST_PUBLISHED ) {
return false;
}

// don't collect statistics data, if the current post_type is not an allowed post_type
$allowed_post_types = $this->config->get( 'content.enabled_post_types' );
if ( ! in_array( $post->post_type, $allowed_post_types, true ) ) {
return false;
}

// don't collect statistics data, if the current post is not purchasable
if ( ! LaterPay_Helper_Pricing::is_purchasable( $post->ID ) ) {
return false;
}

return true;
}

/**
* Callback to add the statistics placeholder to the footer.
*
Expand All @@ -82,9 +41,6 @@ protected function check_requirements( $post = null ) {
* @return void
*/
public function modify_footer( LaterPay_Core_Event $event ) {
if ( ! $this->check_requirements() ) {
return;
}

// don't add the preview pane placeholder to the footer, if the user is not logged in
if ( ! LaterPay_Helper_User::can( 'laterpay_has_full_access_to_content', get_the_ID() ) ) {
Expand Down
4 changes: 2 additions & 2 deletions laterpay/application/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LaterPay_Helper_Config {
'ppu_min' => 0.05,
'ppu_only_limit' => 1.48,
'ppu_max' => 5.00,
'sis_min' => 3.99,
'sis_min' => 1.49,
'sis_only_limit' => 5.01,
'sis_max' => 149.99,
'sis_min_limit' => 1.50,
Expand Down Expand Up @@ -73,7 +73,7 @@ class LaterPay_Helper_Config {
'ppu_min' => 0.05,
'ppu_only_limit' => 1.98,
'ppu_max' => 5.00,
'sis_min' => 3.99,
'sis_min' => 1.99,
'sis_only_limit' => 5.01,
'sis_max' => 149.99,
'sis_min_limit' => 2.00,
Expand Down
17 changes: 17 additions & 0 deletions laterpay/application/Helper/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,21 @@ public static function is_content_purchasable( $post_id ) {
return true;
}
}

/**
* Check if post_type is salable.
*
* @param int $post_id Post ID.
*
* @return bool
*/
public static function is_enabled_type( $post_id ) {
$enabled_types = (array) get_option( 'laterpay_enabled_post_types' );

if ( ! empty( $enabled_types ) && in_array( get_post_type( $post_id ), $enabled_types, true ) ) {
return true;
}

return false;
}
}
24 changes: 22 additions & 2 deletions laterpay/application/Helper/Pricing.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class LaterPay_Helper_Pricing
const STATUS_POST_PUBLISHED = 'publish';
const META_KEY = 'laterpay_post_prices';

/**
* Internal cache for storing posts with their prices.
*
* @var array Internal cache of posts with their prices.
*
* @access private
*/
private static $purchasable_posts = [];

/**
* Check, if the current post or a given post is purchasable.
*
Expand All @@ -38,8 +47,14 @@ public static function is_purchasable( $post_id = null ) {
}
}

// check, if the current post price is not 0
$price = LaterPay_Helper_Pricing::get_post_price( $post_id, true );
// Check if price already exists.
if ( isset( self::$purchasable_posts[ $post_id ] ) ) {
$price = self::$purchasable_posts[ $post_id ];
} else {
// check, if the current post price is not 0
$price = LaterPay_Helper_Pricing::get_post_price( $post_id, true );
self::$purchasable_posts[ $post_id ] = $price;
}

// Get current post price behaviour.
$post_price_behaviour = self::get_post_price_behaviour();
Expand Down Expand Up @@ -204,6 +219,11 @@ public static function recalculate_post_price( $post_id, $category_id, $post_pri
* @return float $price
*/
public static function get_post_price( $post_id, $recalculate = false ) {

if ( ! LaterPay_Helper_Post::is_enabled_type( $post_id ) ) {
return (float) 0;
}

$global_default_price = get_option( 'laterpay_global_price' );

$cache_key = 'laterpay_post_price_' . $post_id;
Expand Down
4 changes: 4 additions & 0 deletions laterpay/application/Helper/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public static function get_scrambled_text( $content ) {
foreach ( $words as $key => $value ) {
$tag = ( ! empty( $tags[ $key ] ) ) ? $tags[ $key ] : '';

if ( ! empty( $tag[1] ) && 'a' === $tag[1] ) {
$tag = preg_replace( '/<a(.*)href="([^"]*)"(.*)>/', '<a$1href="#"$3>', $tag );
}

if ( ! in_array( trim( $tag, '<>/' ), $allowed_tags, true ) ) {
// Scramble the string before appending to final content.
$final_content .= self::scramble_text( $value ) . $tag;
Expand Down
50 changes: 28 additions & 22 deletions laterpay/application/Model/SubscriptionWP.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,8 @@ public function get_subscription( $id, $ignore_deleted = false ) {
'fields' => 'ids',
);

// Create a hash from the query args.
$args_hash = md5( wp_json_encode( $query_args ) );

// Check if data already exists for requested query args.
if ( isset( self::$subscription_data_store[ $args_hash ] ) ) {

// Get data from internal cache for already requested query.
$current_posts = self::$subscription_data_store[ $args_hash ];

} else {

$query = new WP_Query( $query_args );

// Get posts for requested args.
$current_posts = $query->posts;

self::$subscription_data_store[ $args_hash ] = $current_posts;

}
// Get data from data store.
$current_posts = self::get_subscription_from_data_store( $query_args );

$id = ( isset( $current_posts[0] ) ) ? $current_posts[0] : '';

Expand All @@ -122,9 +105,8 @@ public function get_subscription( $id, $ignore_deleted = false ) {
$query_args['post_status'] = 'publish';
}

$get_subscription_query = new WP_Query( $query_args );

$posts = $get_subscription_query->get_posts();
// Get data from data store.
$posts = self::get_subscription_from_data_store( $query_args );

if ( isset( $posts[0] ) ) {
$subscription = $this->transform_post_to_subscription( $posts[0] );
Expand Down Expand Up @@ -572,4 +554,28 @@ private function ensure_post_meta_present( $post_meta ) {

return $post_meta_new;
}

/**
* Get subscription data from internal cache.
*
* @param array $query_args Query args to be passed to WP_Query.
*
* @return array
*/
private function get_subscription_from_data_store( $query_args ) {

// Create a hash from the query args.
$args_hash = md5( wp_json_encode( $query_args ) );

// Check if data exists for requested query args, if not, add it to internal cache.
if ( ! isset( self::$subscription_data_store[ $args_hash ] ) ) {

$query = new WP_Query( $query_args );

// Get posts for requested args.
self::$subscription_data_store[ $args_hash ] = $query->posts;
}

return self::$subscription_data_store[ $args_hash ];
}
}
Loading

0 comments on commit 8aa37c8

Please sign in to comment.