From 73c551ebe6ddb65ccc710436c94ece51bcbc588b Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 19 Apr 2016 01:01:37 +0700 Subject: [PATCH 01/17] Track the develop branch on Scrutinizer --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae7c55c..e80cfbb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # WP Review Me -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/?branch=master) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/?branch=develop) Are you distributing WordPress themes or plugins on WordPress.org? Then you know how important reviews are. From 5688afde4edd035bf54a5874e5e09cefeecff476 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Wed, 20 Apr 2016 08:37:23 +0700 Subject: [PATCH 02/17] Remove integrations - closes #3 closes #2 --- includes/integrations/class-edd.php | 243 ----------------- includes/integrations/class-wordpress.php | 47 ---- review.php | 16 +- samples/plugin-edd.php | 301 ---------------------- 4 files changed, 10 insertions(+), 597 deletions(-) delete mode 100644 includes/integrations/class-edd.php delete mode 100644 includes/integrations/class-wordpress.php delete mode 100644 samples/plugin-edd.php diff --git a/includes/integrations/class-edd.php b/includes/integrations/class-edd.php deleted file mode 100644 index f29e2eb..0000000 --- a/includes/integrations/class-edd.php +++ /dev/null @@ -1,243 +0,0 @@ - - * @version 1.0 - * @license GPL-2.0+ - * @link https://julienliabeuf.com - * @copyright 2016 Julien Liabeuf - */ - -// If this file is called directly, abort. -if ( ! defined( 'WPINC' ) ) { - die; -} - -class WRM_EDD extends WP_Review_Me { - - /** - * URL of the EDD shop - * - * @since 1.0 - * @var string - */ - protected $edd_url; - - /** - * The discount code settings - * - * @since 1.0 - * @var array - */ - protected $discount; - - /** - * The discount code generated - * - * @since 1.0 - * @var string - */ - protected $code; - - /** - * The confirmation e-mail data - * - * @since 1.0 - * @var array - */ - protected $email; - - public function __construct( $args, $email = array() ) { - - $this->edd_url = isset( $args['edd_url'] ) ? esc_url( $args['edd_url'] ) : ''; - $this->discount = isset( $args['edd_discount'] ) && is_array( $args['edd_discount'] ) ? wp_parse_args( $args['edd_discount'], $this->discount_defaults() ) : $this->discount_defaults(); - $this->email = $email; - - // Call parent constructor - parent::__construct( $args ); - - // Register our discount action - add_action( 'wrm_after_notice_dismissed', array( $this, 'query_discount_ajax' ), 10, 2 ); - - } - - /** - * Get the EDD discount default options - * - * @since 1.0 - * @return array - */ - private function discount_defaults() { - - $defaults = array( - 'type' => 'percentage', - 'amount' => 20, - 'validity' => 30, // In days - ); - - return $defaults; - - } - - /** - * Trigger the EDD discount query via Ajax - * - * @since 1.0 - * - * @param string $link_id Unique ID of the link clicked to generate the discount - * - * @return void - */ - public function query_discount_ajax( $link_id ) { - - // Not this notice. Abort. - if ( $link_id !== $this->link_id ) { - echo 'not this instance job'; - - return; - } - - echo $this->query_discount(); - - } - - /** - * Send the HTTP query to the EDD shop - * - * @since 1.0 - * @return string|true - */ - protected function query_discount() { - - $endpoint = esc_url( add_query_arg( 'wrm_action', 'discount', $this->edd_url ) ); - $data = array( 'wrm_email' => get_bloginfo( 'admin_email' ), 'wrm_discount' => $this->discount ); // Wrap our vars to avoid post names issues - - $response = wp_remote_post( $endpoint, array( - 'method' => 'POST', - 'timeout' => 20, - 'redirection' => 5, - 'httpversion' => '1.1', - 'blocking' => true, - 'body' => $data, - 'user-agent' => 'WRM/' . $this->version . '; ' . get_bloginfo( 'url' ) - ) ); - - if ( is_wp_error( $response ) ) { - return $response->get_error_message(); - } - - if ( 200 != wp_remote_retrieve_response_code( $response ) ) { - return wp_remote_retrieve_response_message( $response ); - } - - $body = json_decode( wp_remote_retrieve_body( $response ) ); - - if ( false === $body ) { - return __( 'Unknown error', 'wp-review-me' ); - } - - if ( 'success' === $body->result ) { - $this->code = trim( $body->message ); - $this->email_code(); - return $this->code; - } - - return $body->message; - - } - - /** - * Get the e-mail data - * - * @since 1.0 - * @return array - */ - protected function get_email_data() { - - $body = '

Hi,

From our entire team, many thanks for your review.

While you just spent a few minutes writing it, your testimonial will be a big help to us.

Many users don\'t realize it but reviews are a key part of the promotion work for our product. This allows us to increase our user base, and thus get more support for improving our product.

As a thank you from us, please find hereafter your discount code for a {{amount}} discount valid until {{expiration}}:

Your discount code: {{code}}

Enjoy the product!

'; - - if ( isset( $this->email['body'] ) ) { - $body = $this->email['body']; - } - - $tags = array( 'code', 'amount', 'expiration' ); - - foreach ( $tags as $tag ) { - - $find = '{{' . $tag . '}}'; - - switch ( $tag ) { - - case 'code': - $body = str_replace( $find, $this->code, $body ); - break; - - case 'amount': - - $amount = $this->discount['amount']; - - if ( 'percentage' === $this->discount['type'] ) { - $amount = $amount . '%'; - } - - $body = str_replace( $find, $amount, $body ); - break; - - case 'expiration': - $expiration = date( get_option( 'date_format' ), time() + ( (int) $this->discount['validity'] * 86400 ) ); - $body = str_replace( $find, $expiration, $body ); - break; - - } - - } - - $email['body'] = $body; - $email['subject'] = isset( $this->email['subject'] ) ? sanitize_text_field( $this->email['subject'] ) : esc_html__( 'Your discount code', 'wp-review-me' ); - $email['from_name'] = isset( $this->email['from_name'] ) ? sanitize_text_field( $this->email['from_name'] ) : get_bloginfo( 'name' ); - $email['from_email'] = isset( $this->email['from_email'] ) ? sanitize_text_field( $this->email['from_email'] ) : get_bloginfo( 'admin_email' ); - - return apply_filters( 'wrm_edd_email', $email ); - - } - - /** - * E-mail the discount code to the reviewer - * - * @since 1.0 - * @return bool - */ - protected function email_code() { - - $email = $this->get_email_data(); - $from_name = $email['from_name']; - $from_email = $email['from_email']; - $headers = array( - "MIME-Version: 1.0", - "Content-type: text/html; charset=utf-8", - "From: $from_name <$from_email>", - ); - - return wp_mail( get_bloginfo( 'admin_email' ), $email['subject'], $email['body'], $headers ); - - } - - /** - * Get the review prompt message - * - * @since 1.0 - * @return string - */ - protected function get_message() { - - $message = $this->message; - $link = $this->get_review_link_tag(); - $message = $message . ' ' . $link; - - return wp_kses_post( $message ); - - } - -} \ No newline at end of file diff --git a/includes/integrations/class-wordpress.php b/includes/integrations/class-wordpress.php deleted file mode 100644 index 44fdeb7..0000000 --- a/includes/integrations/class-wordpress.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @version 1.0 - * @license GPL-2.0+ - * @link https://julienliabeuf.com - * @copyright 2016 Julien Liabeuf - */ - -// If this file is called directly, abort. -if ( ! defined( 'WPINC' ) ) { - die; -} - -class WRM_WordPress extends WP_Review_Me { - - /** - * WRM_WordPress constructor - * - * @since 1.0 - * - * @param array $args - */ - public function __construct( $args ) { - parent::__construct( $args ); - } - - /** - * Get the review prompt message - * - * @since 1.0 - * @return string - */ - protected function get_message() { - - $message = $this->message; - $link = $this->get_review_link_tag(); - $message = $message . ' ' . $link; - - return wp_kses_post( $message ); - - } - -} \ No newline at end of file diff --git a/review.php b/review.php index 568c65d..9eabba4 100644 --- a/review.php +++ b/review.php @@ -26,7 +26,7 @@ if ( ! defined( 'WPINC' ) ) { if ( ! class_exists( 'WP_Review_Me' ) ) { - abstract class WP_Review_Me { + class WP_Review_Me { /** * Library version @@ -411,12 +411,16 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { * @since 1.0 * @return string */ - abstract protected function get_message(); + protected function get_message() { + + $message = $this->message; + $link = $this->get_review_link_tag(); + $message = $message . ' ' . $link; + + return wp_kses_post( $message ); + + } } - // Load integrations - require_once( dirname( __FILE__ ) . '/includes/integrations/class-wordpress.php' ); - require_once( dirname( __FILE__ ) . '/includes/integrations/class-edd.php' ); - } \ No newline at end of file diff --git a/samples/plugin-edd.php b/samples/plugin-edd.php deleted file mode 100644 index 8d13931..0000000 --- a/samples/plugin-edd.php +++ /dev/null @@ -1,301 +0,0 @@ - - * - * @package WP Review Me EDD Bridge - * @author Julien Liabeuf - * @version 1.0 - * @license GPL-2.0+ - * @link https://julienliabeuf.com - * @copyright 2016 Julien Liabeuf - * - * Plugin Name: WP Review Me EDD Bridge - * Plugin URI: https://github.com/julien731/WP-Review-Me - * Description: Handles POST requests from a WP Review Me client - * Author: Julien Liabeuf - * Author URI: https://julienliabeuf.com - * Version: 1.0 - * Text Domain: wp-review-me - * Domain Path: languages - */ - -// If this file is called directly, abort. -if ( ! defined( 'WPINC' ) ) { - die; -} - -if ( ! class_exists( 'WRM_EDD_Bridge' ) ): - - /** - * Main WRM EDD class - * - * This class is the one and only instance of the plugin. It is used - * to load the core and all its components. - * - * @since 3.2.5 - */ - final class WRM_EDD_Bridge { - - /** - * Minimum version of WordPress required ot run the plugin - * - * @since 1.0 - * @var string - */ - public $wordpress_version_required = '3.8'; - - /** - * Required version of PHP. - * - * Follow WordPress latest requirements and require - * PHP version 5.2 at least. - * - * @since 1.0 - * @var string - */ - public $php_version_required = '5.2'; - - /** - * Email of the user - * - * @since 1.0 - * @var string - */ - protected $email; - - /** - * Discount code - * - * @since 1.0 - * @var string - */ - protected $code; - - /** - * Throw error on object clone - * - * The whole idea of the singleton design pattern is that there is a single - * object therefore, we don't want the object to be cloned. - * - * @since 3.2.5 - * @return void - */ - public function __clone() { - // Cloning instances of the class is forbidden - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'awesome-support' ), '3.2.5' ); - } - - /** - * Disable unserializing of the class - * - * @since 3.2.5 - * @return void - */ - public function __wakeup() { - // Unserializing instances of the class is forbidden - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'awesome-support' ), '3.2.5' ); - } - - public function __construct() { - add_action( 'init', array( $this, 'init' ) ); - } - - /** - * Initialize the bridge - * - * @since 1.0 - * @return bool|void - */ - public function init() { - - // Some work to do? - if ( ! empty( $_GET ) && isset( $_GET['wrm_action'] ) ) { - - switch ( $_GET['wrm_action'] ) { - - case 'discount': - $this->discount(); - break; - } - - } - - } - - /** - * Run some checks and generate the discount if it's all good - * - * @since 1.0 - * @return void - */ - protected function discount() { - - $result = array( 'result' => 'error' ); - - // Make sure the WordPress version is recent enough - if ( ! $this->is_version_compatible() ) { - $result['message'] = 'WordPress version incompatible'; - echo json_encode( $result ); - die(); - } - - // Make sure we have a version of PHP that's not too old - if ( ! $this->is_php_version_enough() ) { - $result['message'] = 'PHP version incompatible'; - echo json_encode( $result ); - die(); - } - - // Check if EDD is here - if ( ! function_exists( 'edd_store_discount' ) ) { - $result['message'] = 'EDD not active'; - echo json_encode( $result ); - die(); - } - - // Make sure we have an e-mail - if ( ! isset( $_POST['wrm_email'] ) ) { - $result['message'] = 'Email missing'; - echo json_encode( $result ); - die(); - } - - $this->email = $_POST['wrm_email']; - $this->code = md5( $this->email ); - - if ( ! $this->is_code_unique() ) { - $result['message'] = 'Code already claimed'; - echo json_encode( $result ); - die(); - } - - $message = $this->insert_discount(); - $result['result'] = $message ? 'success' : 'error'; - $result['message'] = $message ? $this->code : 'unknown error'; - - echo json_encode( $result ); - die(); - - } - - /** - * Check if the core version is compatible with this. - * - * @since 3.3 - * @return boolean - */ - private function is_version_compatible() { - - if ( empty( $this->wordpress_version_required ) ) { - return true; - } - - if ( version_compare( get_bloginfo( 'version' ), $this->wordpress_version_required, '<' ) ) { - return false; - } - - return true; - - } - - /** - * Check if the version of PHP is compatible with this addon. - * - * @since 3.3 - * @return boolean - */ - private function is_php_version_enough() { - - /** - * No version set, we assume everything is fine. - */ - if ( empty( $this->php_version_required ) ) { - return true; - } - - if ( version_compare( phpversion(), $this->php_version_required, '<' ) ) { - return false; - } - - return true; - - } - - protected function is_code_unique() { - return ! is_null( $this->code ) && edd_get_discount_by_code( $this->code ) ? false : true; - } - - /** - * Get the EDD discount default options - * - * @since 1.0 - * @return array - */ - private function discount_defaults() { - - $defaults = array( - 'type' => 'percentage', - 'amount' => 20, - 'validity' => 30, // In days - ); - - return $defaults; - - } - - /** - * Insert the discount code. - * - * @since 0.1.0 - * @return integer Discount ID - */ - protected function insert_discount() { - - $discount = isset( $_POST['wrm_discount'] ) ? wp_parse_args( $_POST['wrm_discount'], $this->discount_defaults() ) : $this->discount_defaults(); - - // Make sure the discount type exists - if ( ! in_array( $discount['type'], array( 'percent', 'flat' ) ) ) { - $discount['type'] = 'percent'; - } - - // Make sure the discount is not over 100% (for percentage discounts) - if ( 'percent' === $discount['type'] && (int) $discount['amount'] > 100 ) { - $discount['amount'] = 100; - } - - $details = array( - 'code' => $this->code, - 'name' => sprintf( 'Discount for a review %s', $this->email ), - 'status' => 'active', - 'uses' => 0, - 'max' => 1, - 'amount' => $discount['amount'], - 'start' => date( 'Y-m-d' ), - 'expiration' => date( 'Y-m-d', strtotime( date( 'Y-m-d' ) . "+ {$discount['validity']} days" ) ), - 'type' => $discount['type'], - 'min_price' => 0, - 'products' => array(), - 'product_condition' => 'any', - 'excluded_products' => array(), - 'not_global' => true, - 'use_once' => true, - ); - - return edd_store_discount( $details ); - - } - - } - -endif; - -new WRM_EDD_Bridge(); \ No newline at end of file From ca9d11a37962c6873fa1c7a09dd465f90f77d487 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Wed, 20 Apr 2016 08:39:28 +0700 Subject: [PATCH 03/17] Update instructions in readme.md --- README.md | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e80cfbb..9cbe61c 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,9 @@ composer require julien731/wp-review-me Creating a new review prompt would look like that: ``` -new WRM_WordPress( array( 'days_after' => 10, 'type' => 'plugin', 'slug' => 'my-plugin' ) ); +new WP_Review_Me( array( 'days_after' => 10, 'type' => 'plugin', 'slug' => 'my-plugin' ) ); ``` This is the simplest way of creating a review prompt. If you want to customize it further, a few advanced parameters are available. -You can see the documentation on the wiki page: https://github.com/julien731/WP-Review-Me/wiki - -## Integrations - -Because users sometimes won't take the time to leave a review without an incentive, there are a couple of integrations made just for that. - -### Easy Digital Downloads - -With the EDD integration, you can automatically generate a discount code for the user in exchange for a review. See the [documentation for the EDD integration](https://github.com/julien731/WP-Review-Me/wiki/Integration:-EDD). \ No newline at end of file +You can see the documentation on the wiki page: https://github.com/julien731/WP-Review-Me/wiki \ No newline at end of file From db6090587dcf025ef525abc147b96756fba0d85b Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Wed, 20 Apr 2016 19:35:18 +0700 Subject: [PATCH 04/17] Add info note about dropping integrations --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9cbe61c..fd11a7e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/?branch=develop) +*In order to comply with the WordPress.org guidelines, the EDD integration has been removed and the WooCommerce integration has been dropped.* + Are you distributing WordPress themes or plugins on WordPress.org? Then you know how important reviews are. The bad thing with reviews is that, while unhappy users love to let the world know, happy users tend to forget reviewing your product. From 1f454a7629183536cb660d57779e6de40453d3c3 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 19 Apr 2016 01:01:37 +0700 Subject: [PATCH 05/17] Track the develop branch on Scrutinizer --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae7c55c..e80cfbb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # WP Review Me -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/?branch=master) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/?branch=develop) Are you distributing WordPress themes or plugins on WordPress.org? Then you know how important reviews are. From 9930e7085b406c9b4d792736e02fef1c84ba5d74 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Wed, 20 Apr 2016 08:37:23 +0700 Subject: [PATCH 06/17] Remove integrations - closes #3 closes #2 --- includes/integrations/class-edd.php | 243 ----------------- includes/integrations/class-wordpress.php | 47 ---- review.php | 16 +- samples/plugin-edd.php | 301 ---------------------- 4 files changed, 10 insertions(+), 597 deletions(-) delete mode 100644 includes/integrations/class-edd.php delete mode 100644 includes/integrations/class-wordpress.php delete mode 100644 samples/plugin-edd.php diff --git a/includes/integrations/class-edd.php b/includes/integrations/class-edd.php deleted file mode 100644 index f29e2eb..0000000 --- a/includes/integrations/class-edd.php +++ /dev/null @@ -1,243 +0,0 @@ - - * @version 1.0 - * @license GPL-2.0+ - * @link https://julienliabeuf.com - * @copyright 2016 Julien Liabeuf - */ - -// If this file is called directly, abort. -if ( ! defined( 'WPINC' ) ) { - die; -} - -class WRM_EDD extends WP_Review_Me { - - /** - * URL of the EDD shop - * - * @since 1.0 - * @var string - */ - protected $edd_url; - - /** - * The discount code settings - * - * @since 1.0 - * @var array - */ - protected $discount; - - /** - * The discount code generated - * - * @since 1.0 - * @var string - */ - protected $code; - - /** - * The confirmation e-mail data - * - * @since 1.0 - * @var array - */ - protected $email; - - public function __construct( $args, $email = array() ) { - - $this->edd_url = isset( $args['edd_url'] ) ? esc_url( $args['edd_url'] ) : ''; - $this->discount = isset( $args['edd_discount'] ) && is_array( $args['edd_discount'] ) ? wp_parse_args( $args['edd_discount'], $this->discount_defaults() ) : $this->discount_defaults(); - $this->email = $email; - - // Call parent constructor - parent::__construct( $args ); - - // Register our discount action - add_action( 'wrm_after_notice_dismissed', array( $this, 'query_discount_ajax' ), 10, 2 ); - - } - - /** - * Get the EDD discount default options - * - * @since 1.0 - * @return array - */ - private function discount_defaults() { - - $defaults = array( - 'type' => 'percentage', - 'amount' => 20, - 'validity' => 30, // In days - ); - - return $defaults; - - } - - /** - * Trigger the EDD discount query via Ajax - * - * @since 1.0 - * - * @param string $link_id Unique ID of the link clicked to generate the discount - * - * @return void - */ - public function query_discount_ajax( $link_id ) { - - // Not this notice. Abort. - if ( $link_id !== $this->link_id ) { - echo 'not this instance job'; - - return; - } - - echo $this->query_discount(); - - } - - /** - * Send the HTTP query to the EDD shop - * - * @since 1.0 - * @return string|true - */ - protected function query_discount() { - - $endpoint = esc_url( add_query_arg( 'wrm_action', 'discount', $this->edd_url ) ); - $data = array( 'wrm_email' => get_bloginfo( 'admin_email' ), 'wrm_discount' => $this->discount ); // Wrap our vars to avoid post names issues - - $response = wp_remote_post( $endpoint, array( - 'method' => 'POST', - 'timeout' => 20, - 'redirection' => 5, - 'httpversion' => '1.1', - 'blocking' => true, - 'body' => $data, - 'user-agent' => 'WRM/' . $this->version . '; ' . get_bloginfo( 'url' ) - ) ); - - if ( is_wp_error( $response ) ) { - return $response->get_error_message(); - } - - if ( 200 != wp_remote_retrieve_response_code( $response ) ) { - return wp_remote_retrieve_response_message( $response ); - } - - $body = json_decode( wp_remote_retrieve_body( $response ) ); - - if ( false === $body ) { - return __( 'Unknown error', 'wp-review-me' ); - } - - if ( 'success' === $body->result ) { - $this->code = trim( $body->message ); - $this->email_code(); - return $this->code; - } - - return $body->message; - - } - - /** - * Get the e-mail data - * - * @since 1.0 - * @return array - */ - protected function get_email_data() { - - $body = '

Hi,

From our entire team, many thanks for your review.

While you just spent a few minutes writing it, your testimonial will be a big help to us.

Many users don\'t realize it but reviews are a key part of the promotion work for our product. This allows us to increase our user base, and thus get more support for improving our product.

As a thank you from us, please find hereafter your discount code for a {{amount}} discount valid until {{expiration}}:

Your discount code: {{code}}

Enjoy the product!

'; - - if ( isset( $this->email['body'] ) ) { - $body = $this->email['body']; - } - - $tags = array( 'code', 'amount', 'expiration' ); - - foreach ( $tags as $tag ) { - - $find = '{{' . $tag . '}}'; - - switch ( $tag ) { - - case 'code': - $body = str_replace( $find, $this->code, $body ); - break; - - case 'amount': - - $amount = $this->discount['amount']; - - if ( 'percentage' === $this->discount['type'] ) { - $amount = $amount . '%'; - } - - $body = str_replace( $find, $amount, $body ); - break; - - case 'expiration': - $expiration = date( get_option( 'date_format' ), time() + ( (int) $this->discount['validity'] * 86400 ) ); - $body = str_replace( $find, $expiration, $body ); - break; - - } - - } - - $email['body'] = $body; - $email['subject'] = isset( $this->email['subject'] ) ? sanitize_text_field( $this->email['subject'] ) : esc_html__( 'Your discount code', 'wp-review-me' ); - $email['from_name'] = isset( $this->email['from_name'] ) ? sanitize_text_field( $this->email['from_name'] ) : get_bloginfo( 'name' ); - $email['from_email'] = isset( $this->email['from_email'] ) ? sanitize_text_field( $this->email['from_email'] ) : get_bloginfo( 'admin_email' ); - - return apply_filters( 'wrm_edd_email', $email ); - - } - - /** - * E-mail the discount code to the reviewer - * - * @since 1.0 - * @return bool - */ - protected function email_code() { - - $email = $this->get_email_data(); - $from_name = $email['from_name']; - $from_email = $email['from_email']; - $headers = array( - "MIME-Version: 1.0", - "Content-type: text/html; charset=utf-8", - "From: $from_name <$from_email>", - ); - - return wp_mail( get_bloginfo( 'admin_email' ), $email['subject'], $email['body'], $headers ); - - } - - /** - * Get the review prompt message - * - * @since 1.0 - * @return string - */ - protected function get_message() { - - $message = $this->message; - $link = $this->get_review_link_tag(); - $message = $message . ' ' . $link; - - return wp_kses_post( $message ); - - } - -} \ No newline at end of file diff --git a/includes/integrations/class-wordpress.php b/includes/integrations/class-wordpress.php deleted file mode 100644 index 44fdeb7..0000000 --- a/includes/integrations/class-wordpress.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @version 1.0 - * @license GPL-2.0+ - * @link https://julienliabeuf.com - * @copyright 2016 Julien Liabeuf - */ - -// If this file is called directly, abort. -if ( ! defined( 'WPINC' ) ) { - die; -} - -class WRM_WordPress extends WP_Review_Me { - - /** - * WRM_WordPress constructor - * - * @since 1.0 - * - * @param array $args - */ - public function __construct( $args ) { - parent::__construct( $args ); - } - - /** - * Get the review prompt message - * - * @since 1.0 - * @return string - */ - protected function get_message() { - - $message = $this->message; - $link = $this->get_review_link_tag(); - $message = $message . ' ' . $link; - - return wp_kses_post( $message ); - - } - -} \ No newline at end of file diff --git a/review.php b/review.php index 568c65d..9eabba4 100644 --- a/review.php +++ b/review.php @@ -26,7 +26,7 @@ if ( ! defined( 'WPINC' ) ) { if ( ! class_exists( 'WP_Review_Me' ) ) { - abstract class WP_Review_Me { + class WP_Review_Me { /** * Library version @@ -411,12 +411,16 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { * @since 1.0 * @return string */ - abstract protected function get_message(); + protected function get_message() { + + $message = $this->message; + $link = $this->get_review_link_tag(); + $message = $message . ' ' . $link; + + return wp_kses_post( $message ); + + } } - // Load integrations - require_once( dirname( __FILE__ ) . '/includes/integrations/class-wordpress.php' ); - require_once( dirname( __FILE__ ) . '/includes/integrations/class-edd.php' ); - } \ No newline at end of file diff --git a/samples/plugin-edd.php b/samples/plugin-edd.php deleted file mode 100644 index 8d13931..0000000 --- a/samples/plugin-edd.php +++ /dev/null @@ -1,301 +0,0 @@ - - * - * @package WP Review Me EDD Bridge - * @author Julien Liabeuf - * @version 1.0 - * @license GPL-2.0+ - * @link https://julienliabeuf.com - * @copyright 2016 Julien Liabeuf - * - * Plugin Name: WP Review Me EDD Bridge - * Plugin URI: https://github.com/julien731/WP-Review-Me - * Description: Handles POST requests from a WP Review Me client - * Author: Julien Liabeuf - * Author URI: https://julienliabeuf.com - * Version: 1.0 - * Text Domain: wp-review-me - * Domain Path: languages - */ - -// If this file is called directly, abort. -if ( ! defined( 'WPINC' ) ) { - die; -} - -if ( ! class_exists( 'WRM_EDD_Bridge' ) ): - - /** - * Main WRM EDD class - * - * This class is the one and only instance of the plugin. It is used - * to load the core and all its components. - * - * @since 3.2.5 - */ - final class WRM_EDD_Bridge { - - /** - * Minimum version of WordPress required ot run the plugin - * - * @since 1.0 - * @var string - */ - public $wordpress_version_required = '3.8'; - - /** - * Required version of PHP. - * - * Follow WordPress latest requirements and require - * PHP version 5.2 at least. - * - * @since 1.0 - * @var string - */ - public $php_version_required = '5.2'; - - /** - * Email of the user - * - * @since 1.0 - * @var string - */ - protected $email; - - /** - * Discount code - * - * @since 1.0 - * @var string - */ - protected $code; - - /** - * Throw error on object clone - * - * The whole idea of the singleton design pattern is that there is a single - * object therefore, we don't want the object to be cloned. - * - * @since 3.2.5 - * @return void - */ - public function __clone() { - // Cloning instances of the class is forbidden - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'awesome-support' ), '3.2.5' ); - } - - /** - * Disable unserializing of the class - * - * @since 3.2.5 - * @return void - */ - public function __wakeup() { - // Unserializing instances of the class is forbidden - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'awesome-support' ), '3.2.5' ); - } - - public function __construct() { - add_action( 'init', array( $this, 'init' ) ); - } - - /** - * Initialize the bridge - * - * @since 1.0 - * @return bool|void - */ - public function init() { - - // Some work to do? - if ( ! empty( $_GET ) && isset( $_GET['wrm_action'] ) ) { - - switch ( $_GET['wrm_action'] ) { - - case 'discount': - $this->discount(); - break; - } - - } - - } - - /** - * Run some checks and generate the discount if it's all good - * - * @since 1.0 - * @return void - */ - protected function discount() { - - $result = array( 'result' => 'error' ); - - // Make sure the WordPress version is recent enough - if ( ! $this->is_version_compatible() ) { - $result['message'] = 'WordPress version incompatible'; - echo json_encode( $result ); - die(); - } - - // Make sure we have a version of PHP that's not too old - if ( ! $this->is_php_version_enough() ) { - $result['message'] = 'PHP version incompatible'; - echo json_encode( $result ); - die(); - } - - // Check if EDD is here - if ( ! function_exists( 'edd_store_discount' ) ) { - $result['message'] = 'EDD not active'; - echo json_encode( $result ); - die(); - } - - // Make sure we have an e-mail - if ( ! isset( $_POST['wrm_email'] ) ) { - $result['message'] = 'Email missing'; - echo json_encode( $result ); - die(); - } - - $this->email = $_POST['wrm_email']; - $this->code = md5( $this->email ); - - if ( ! $this->is_code_unique() ) { - $result['message'] = 'Code already claimed'; - echo json_encode( $result ); - die(); - } - - $message = $this->insert_discount(); - $result['result'] = $message ? 'success' : 'error'; - $result['message'] = $message ? $this->code : 'unknown error'; - - echo json_encode( $result ); - die(); - - } - - /** - * Check if the core version is compatible with this. - * - * @since 3.3 - * @return boolean - */ - private function is_version_compatible() { - - if ( empty( $this->wordpress_version_required ) ) { - return true; - } - - if ( version_compare( get_bloginfo( 'version' ), $this->wordpress_version_required, '<' ) ) { - return false; - } - - return true; - - } - - /** - * Check if the version of PHP is compatible with this addon. - * - * @since 3.3 - * @return boolean - */ - private function is_php_version_enough() { - - /** - * No version set, we assume everything is fine. - */ - if ( empty( $this->php_version_required ) ) { - return true; - } - - if ( version_compare( phpversion(), $this->php_version_required, '<' ) ) { - return false; - } - - return true; - - } - - protected function is_code_unique() { - return ! is_null( $this->code ) && edd_get_discount_by_code( $this->code ) ? false : true; - } - - /** - * Get the EDD discount default options - * - * @since 1.0 - * @return array - */ - private function discount_defaults() { - - $defaults = array( - 'type' => 'percentage', - 'amount' => 20, - 'validity' => 30, // In days - ); - - return $defaults; - - } - - /** - * Insert the discount code. - * - * @since 0.1.0 - * @return integer Discount ID - */ - protected function insert_discount() { - - $discount = isset( $_POST['wrm_discount'] ) ? wp_parse_args( $_POST['wrm_discount'], $this->discount_defaults() ) : $this->discount_defaults(); - - // Make sure the discount type exists - if ( ! in_array( $discount['type'], array( 'percent', 'flat' ) ) ) { - $discount['type'] = 'percent'; - } - - // Make sure the discount is not over 100% (for percentage discounts) - if ( 'percent' === $discount['type'] && (int) $discount['amount'] > 100 ) { - $discount['amount'] = 100; - } - - $details = array( - 'code' => $this->code, - 'name' => sprintf( 'Discount for a review %s', $this->email ), - 'status' => 'active', - 'uses' => 0, - 'max' => 1, - 'amount' => $discount['amount'], - 'start' => date( 'Y-m-d' ), - 'expiration' => date( 'Y-m-d', strtotime( date( 'Y-m-d' ) . "+ {$discount['validity']} days" ) ), - 'type' => $discount['type'], - 'min_price' => 0, - 'products' => array(), - 'product_condition' => 'any', - 'excluded_products' => array(), - 'not_global' => true, - 'use_once' => true, - ); - - return edd_store_discount( $details ); - - } - - } - -endif; - -new WRM_EDD_Bridge(); \ No newline at end of file From e7ea9ad376b94dd0c8bf001cbf1329dd41ac772d Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Wed, 20 Apr 2016 08:39:28 +0700 Subject: [PATCH 07/17] Update instructions in readme.md --- README.md | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e80cfbb..9cbe61c 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,9 @@ composer require julien731/wp-review-me Creating a new review prompt would look like that: ``` -new WRM_WordPress( array( 'days_after' => 10, 'type' => 'plugin', 'slug' => 'my-plugin' ) ); +new WP_Review_Me( array( 'days_after' => 10, 'type' => 'plugin', 'slug' => 'my-plugin' ) ); ``` This is the simplest way of creating a review prompt. If you want to customize it further, a few advanced parameters are available. -You can see the documentation on the wiki page: https://github.com/julien731/WP-Review-Me/wiki - -## Integrations - -Because users sometimes won't take the time to leave a review without an incentive, there are a couple of integrations made just for that. - -### Easy Digital Downloads - -With the EDD integration, you can automatically generate a discount code for the user in exchange for a review. See the [documentation for the EDD integration](https://github.com/julien731/WP-Review-Me/wiki/Integration:-EDD). \ No newline at end of file +You can see the documentation on the wiki page: https://github.com/julien731/WP-Review-Me/wiki \ No newline at end of file From f55e83a0e5a95a0ab7798f4d7791ab3af83e99a3 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Wed, 20 Apr 2016 19:35:18 +0700 Subject: [PATCH 08/17] Add info note about dropping integrations --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9cbe61c..fd11a7e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/julien731/WP-Review-Me/?branch=develop) +*In order to comply with the WordPress.org guidelines, the EDD integration has been removed and the WooCommerce integration has been dropped.* + Are you distributing WordPress themes or plugins on WordPress.org? Then you know how important reviews are. The bad thing with reviews is that, while unhappy users love to let the world know, happy users tend to forget reviewing your product. From 1e24fa8a8f8a7a62e770df603048fc8bd8353bac Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Sun, 3 Jul 2016 21:31:46 +0700 Subject: [PATCH 09/17] Update image src --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd11a7e..65656bb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The bad thing with reviews is that, while unhappy users love to let the world kn How can you get more good reviews? Simply ask your users. -![WP Review Me](http://i.imgur.com/iZk4Bgu.png) +![WP Review Me](http://i.imgur.com/9oNGvm2.png) ## How It Works @@ -38,4 +38,4 @@ new WP_Review_Me( array( 'days_after' => 10, 'type' => 'plugin', 'slug' => 'my-p This is the simplest way of creating a review prompt. If you want to customize it further, a few advanced parameters are available. -You can see the documentation on the wiki page: https://github.com/julien731/WP-Review-Me/wiki \ No newline at end of file +You can see the documentation on the wiki page: https://github.com/julien731/WP-Review-Me/wiki From 66baf1dbd939f3cb97723a01449f6d54dee9a970 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 27 Sep 2016 11:01:06 +0700 Subject: [PATCH 10/17] Typecast var --- review.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/review.php b/review.php index 9eabba4..74fd900 100644 --- a/review.php +++ b/review.php @@ -238,7 +238,7 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { */ public function is_time() { - $installed = get_option( $this->key, false ); + $installed = (int) get_option( $this->key, false ); if ( false === $installed ) { $this->setup_date(); From 4f9d9633a1b3cbcaf098cca6415185dceac7f2b5 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 27 Sep 2016 11:01:36 +0700 Subject: [PATCH 11/17] Fix calculation error --- review.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/review.php b/review.php index 74fd900..449f14d 100644 --- a/review.php +++ b/review.php @@ -245,7 +245,7 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { $installed = time(); } - if ( $installed + ( $this->days + 86400 ) > time() ) { + if ( $installed + ( $this->days * 86400 ) > time() ) { return false; } From 973892a9a00797c7616d85548a0430873dc80baa Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 27 Sep 2016 11:02:12 +0700 Subject: [PATCH 12/17] Bump version number --- review.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/review.php b/review.php index 449f14d..b59487f 100644 --- a/review.php +++ b/review.php @@ -13,7 +13,7 @@ * * @package WP Review Me * @author Julien Liabeuf - * @version 1.0 + * @version 1.0.1 * @license GPL-2.0+ * @link https://julienliabeuf.com * @copyright 2016 Julien Liabeuf @@ -34,7 +34,7 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { * @since 1.0 * @var string */ - public $version = '1.0'; + public $version = '1.0.1'; /** * Required version of PHP. From 0f616f7eddc9c373441739f73f7041c2556c5911 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 27 Sep 2016 11:02:43 +0700 Subject: [PATCH 13/17] Update review URLs - fixes #4 --- review.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/review.php b/review.php index b59487f..df8211e 100644 --- a/review.php +++ b/review.php @@ -271,23 +271,23 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { */ protected function get_review_link() { - $link = 'https://wordpress.org/support/view/'; + $link = 'https://wordpress.org/support/'; switch ( $this->type ) { case 'theme': - $link .= 'theme-reviews/'; + $link .= 'theme/'; break; case 'plugin': - $link .= 'plugin-reviews/'; + $link .= 'plugin/'; break; } - $link .= $this->slug; + $link .= $this->slug . '/reviews'; $link = add_query_arg( 'rate', $this->rating, $link ); - $link = esc_url( $link . '#postform' ); + $link = esc_url( $link . '#new-post' ); return $link; From cb43e768e0dc1e2eb8e1a3a96ffa3dfd9f890602 Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 27 Sep 2016 11:04:50 +0700 Subject: [PATCH 14/17] Bump version number again. Actually forgot to do it when releasing 2.0. --- review.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/review.php b/review.php index df8211e..73e0427 100644 --- a/review.php +++ b/review.php @@ -13,7 +13,7 @@ * * @package WP Review Me * @author Julien Liabeuf - * @version 1.0.1 + * @version 2.0.1 * @license GPL-2.0+ * @link https://julienliabeuf.com * @copyright 2016 Julien Liabeuf @@ -34,7 +34,7 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { * @since 1.0 * @var string */ - public $version = '1.0.1'; + public $version = '2.0.1'; /** * Required version of PHP. From a47a0fc6fa9b36a6f7eac5077ec11f7329fbff0e Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 9 Apr 2017 17:34:56 -0400 Subject: [PATCH 15/17] Fix comparison within is_time() method Using false here is causing the check to ALWAYS evaluate as false since the value is being cast to an int. A check of `bool === int` can never be true, so updating this to comparing for 0 is the best solution. --- review.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/review.php b/review.php index 73e0427..e63f225 100644 --- a/review.php +++ b/review.php @@ -240,7 +240,7 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { $installed = (int) get_option( $this->key, false ); - if ( false === $installed ) { + if ( 0 === $installed ) { $this->setup_date(); $installed = time(); } @@ -423,4 +423,4 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { } -} \ No newline at end of file +} From a9efc4fb2d1076192ea8f5ea816f07c8ca1c9306 Mon Sep 17 00:00:00 2001 From: Daniele Scasciafratte Date: Mon, 13 Aug 2018 22:10:27 +0200 Subject: [PATCH 16/17] Update review.php --- review.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/review.php b/review.php index 73e0427..188e778 100644 --- a/review.php +++ b/review.php @@ -19,11 +19,6 @@ * @copyright 2016 Julien Liabeuf */ -// If this file is called directly, abort. -if ( ! defined( 'WPINC' ) ) { - die; -} - if ( ! class_exists( 'WP_Review_Me' ) ) { class WP_Review_Me { @@ -423,4 +418,4 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { } -} \ No newline at end of file +} From c9bae4c60fb89b961212485786579b7e00b35621 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 16 Nov 2018 17:49:38 -0500 Subject: [PATCH 17/17] Update review.php --- review.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/review.php b/review.php index e63f225..7c06f1e 100644 --- a/review.php +++ b/review.php @@ -238,7 +238,7 @@ if ( ! class_exists( 'WP_Review_Me' ) ) { */ public function is_time() { - $installed = (int) get_option( $this->key, false ); + $installed = (int) get_option( $this->key, 0 ); if ( 0 === $installed ) { $this->setup_date();