Skip to content

Commit

Permalink
Merge branch 'issue/339' into feature/gutenberg-donation-form-block
Browse files Browse the repository at this point in the history
* issue/339:
  Add clarity to docs
  Version bumped
  Apply posts_where clause on payment sql query
  Add __rename_meta_table_name reusable fn
  Use $meta_type to generate table name
  Fix #2683
  Fix broken unit test.
  Added icon and updated text for per form email tab - Fixes #2680
  Resolved issue with untranslatable string and incorrect variable name
  Packagist license validation
  Removed "Built with Gulp" badge since we're building with webpack now...
  Stop emailing me...
  Fixing packagist complaining about license value
  Reduce the max limit of posts_per_page for windows OS.
  Fix #2678
  Remove error.log code
  Fix upgrades
  Fix broken update
  • Loading branch information
DevinWalker committed Jan 22, 2018
2 parents 024f021 + 9d39c01 commit f7674e6
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,6 +1,6 @@
# [GiveWP](https://givewp.com "Give - Democratizing Generosity") #

![WordPress version](https://img.shields.io/wordpress/plugin/v/give.svg) ![WordPress Rating](https://img.shields.io/wordpress/plugin/r/give.svg) ![WordPress Downloads](https://img.shields.io/wordpress/plugin/dt/give.svg) [![Build Status](https://travis-ci.org/WordImpress/Give.svg?branch=master)](https://travis-ci.org/WordImpress/Give) [![Code Coverage](https://scrutinizer-ci.com/g/WordImpress/Give/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/WordImpress/Give/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/WordImpress/Give/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/WordImpress/Give/?branch=master) [![License](https://img.shields.io/badge/license-GPL--2.0%2B-green.svg)](https://github.com/WordImpress/Give/blob/master/license.txt) [![built with gulp](https://camo.githubusercontent.com/2a01d8fcbdfc09eb24d02c6655c897f0ab9ca69a/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6275696c74253230776974682d67756c702e6a732d7265642e737667)](http://gulpjs.com/)
![WordPress version](https://img.shields.io/wordpress/plugin/v/give.svg) ![WordPress Rating](https://img.shields.io/wordpress/plugin/r/give.svg) ![WordPress Downloads](https://img.shields.io/wordpress/plugin/dt/give.svg) [![Build Status](https://travis-ci.org/WordImpress/Give.svg?branch=master)](https://travis-ci.org/WordImpress/Give) [![Code Coverage](https://scrutinizer-ci.com/g/WordImpress/Give/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/WordImpress/Give/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/WordImpress/Give/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/WordImpress/Give/?branch=master) [![License](https://img.shields.io/badge/license-GPL--2.0%2B-green.svg)](https://github.com/WordImpress/Give/blob/master/license.txt)

Welcome to the GiveWP GitHub repository. This is the code source and the center of active development. Here you can browse the source, look at open issues, and contribute to the project. We recommend all developers follow the GiveWP development blog to stay up to date on the latest features and changes.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "wordimpress/give",
"type": "wordpress-plugin",
"license": "GPL-2.0+",
"license": "GPL-2.0-or-later",
"description": "Give - a WordPress Donation Plugin and Fundraising Platform",
"homepage": "https://givewp.com/",
"require": {
Expand Down
4 changes: 2 additions & 2 deletions give.php
Expand Up @@ -5,7 +5,7 @@
* Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
* Author: WordImpress
* Author URI: https://wordimpress.com
* Version: 2.0.0
* Version: 2.0.1
* Text Domain: give
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/WordImpress/Give
Expand Down Expand Up @@ -373,7 +373,7 @@ private function setup_constants() {

// Plugin version
if ( ! defined( 'GIVE_VERSION' ) ) {
define( 'GIVE_VERSION', '2.0.0' );
define( 'GIVE_VERSION', '2.0.1' );
}

// Plugin Root File
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/donors/class-donor-table.php
Expand Up @@ -119,7 +119,7 @@ public function column_default( $donor, $column_name ) {
case 'num_donations' :
$value = sprintf(
'<a href="%s">%s</a>',
admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor['id'] ) ),
admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&status=publish&donor=' . absint( $donor['id'] ) ),
esc_html( $donor['num_donations'] )
);
break;
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/donors/donors.php
Expand Up @@ -459,7 +459,7 @@ class="button info-item editable donor-edit-link"><?php _e( 'Edit Donor', 'give'
<div id="donor-stats-wrapper" class="donor-section postbox clear">
<ul>
<li>
<a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor->id ) ); ?>">
<a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&status=publish&donor=' . absint( $donor->id ) ); ?>">
<span class="dashicons dashicons-heart"></span>
<?php
// Completed Donations.
Expand Down
3 changes: 2 additions & 1 deletion includes/admin/emails/class-email-notifications.php
Expand Up @@ -118,7 +118,8 @@ public function add_metabox_setting_fields( $settings, $post_id ) {
// Email notification setting.
$settings['email_notification_options'] = array(
'id' => 'email_notification_options',
'title' => __( 'Email Notification', 'give' ),
'title' => __( 'Email Notifications', 'give' ),
'icon-html' => '<span class="dashicons dashicons-email-alt"></span>',
'fields' => array(
array(
'name' => __( 'Email Options', 'give' ),
Expand Down
12 changes: 6 additions & 6 deletions includes/admin/settings/class-settings-general.php
Expand Up @@ -117,8 +117,8 @@ public function get_settings() {
break;

case 'currency-settings' :
$current_position_before = __( 'Before - %s&#x200e;10', 'give' );
$current_position_after = __( 'After - 10%s&#x200f;', 'give' );
$currency_position_before = __( 'Before - %s&#x200e;10', 'give' );
$currency_position_after = __( 'After - 10%s&#x200f;', 'give' );

$settings = array(
// Section 2: Currency
Expand Down Expand Up @@ -148,14 +148,14 @@ public function get_settings() {
'type' => 'select',
'options' => array(
/* translators: %s: currency symbol */
'before' => sprintf( $current_position_before, give_currency_symbol( give_get_currency() ) ),
'before' => sprintf( $currency_position_before, give_currency_symbol( give_get_currency() ) ),
/* translators: %s: currency symbol */
'after' => sprintf( __( $current_position_after, 'give' ), give_currency_symbol( give_get_currency() ) ),
'after' => sprintf( $currency_position_after, give_currency_symbol( give_get_currency() ) ),
),
'default' => 'before',
'attributes' => array(
'data-before-template' => sprintf( $current_position_before, '{currency_pos}' ),
'data-after-template' => sprintf( $current_position_after, '{currency_pos}' ),
'data-before-template' => sprintf( $currency_position_before, '{currency_pos}' ),
'data-after-template' => sprintf( $currency_position_after, '{currency_pos}' ),
),
),
array(
Expand Down
Expand Up @@ -347,20 +347,20 @@ public function render_upload_html() {
<tr valign="top">
<th colspan="2">
<h2 id="give-import-title"><?php esc_html_e( 'Import Core Settings from a JSON file', 'give' ) ?></h2>
<p class="give-field-description"><?php esc_html_e( 'This tool allows you to merge or replace settings data to your give settings via a JSON file.', 'give' ) ?></p>
<p class="give-field-description"><?php esc_html_e( 'This tool allows you to import Give settings from another Give installation. Settings imported contain data from Give core as well as any of our Premium Add-ons.', 'give' ) ?></p>
</th>
</tr>

<tr valign="top">
<th scope="row" class="titledesc">
<label for="json">Choose a json file:</label>
<label for="json"><?php esc_html_e( 'Choose a JSON file:', 'give' ) ?></label>
</th>
<td class="give-forminp">
<div class="give-field-wrap">
<label for="json">
<input type="file" name="json" class="give-upload-json-file" value="<?php echo $json; ?>"
accept=".json">
<p class="give-field-description">The file must be a JSON file type only.</p>
<p class="give-field-description"><?php esc_html_e( 'The file type must be JSON.', 'give' )?></p>
</label>
</div>
</td>
Expand All @@ -370,7 +370,7 @@ public function render_upload_html() {
array(
'id' => 'type',
'name' => __( 'Merge Type:', 'give' ),
'description' => __( 'Import the Setting from the JSON and then merge or replace with the current settings', 'give' ),
'description' => __( 'Select "Merge" to retain existing settings, or "Replace" to overwrite with the settings from the JSON file', 'give' ),
'default' => $type,
'type' => 'radio_inline',
'options' => array(
Expand Down
5 changes: 5 additions & 0 deletions includes/admin/tools/views/html-admin-page-system-info.php
Expand Up @@ -136,6 +136,11 @@
<td><?php echo 0 !== $blog_page_id ? esc_html( get_the_title( $blog_page_id ) . ' (#' . $blog_page_id . ')' ) : __( 'Unset', 'give' ); ?></td>
</tr>
<?php endif;?>
<tr>
<td data-export-label="Table Prefix Length"><?php _e( 'Table Prefix', 'give' ); ?>:</td>
<td class="help"><?php echo Give()->tooltips->render_help( __( 'The table prefix used in your WordPress database.', 'give' ) ); ?></td>
<td><?php echo esc_html( $wpdb->prefix ); ?></td>
</tr>
<tr>
<td data-export-label="Table Prefix Length"><?php _e( 'Table Prefix Length', 'give' ); ?>:</td>
<td class="help"><?php echo Give()->tooltips->render_help( __( 'The length of the table prefix used in your WordPress database.', 'give' ) ); ?></td>
Expand Down
21 changes: 11 additions & 10 deletions includes/admin/upgrades/class-give-updates.php
Expand Up @@ -23,7 +23,7 @@ class Give_Updates {
* @access static
* @var Give_Background_Updater
*/
static private $background_updater;
static public $background_updater;

/**
* Updates
Expand Down Expand Up @@ -583,6 +583,7 @@ public function is_parent_updates_completed( $update ) {

// Check if dependency is valid or not.
if ( ! $this->has_valid_dependency( $update ) ) {
error_log( print_r( 'exit 2', true ) . "\n", 3, WP_CONTENT_DIR . '/debug_new.log' );
return null;
}

Expand Down Expand Up @@ -623,15 +624,15 @@ public function is_doing_updates() {
*/
public function has_valid_dependency( $update ) {
$is_valid_dependency = true;
$update_ids = wp_list_pluck( $this->get_updates( 'database' ), 'id' );

foreach ( $update['depend'] as $depend ) {
// Check if dependency is valid or not.
if ( ! in_array( $depend, $update_ids ) ) {
$is_valid_dependency = false;
break;
}
}
// $update_ids = wp_list_pluck( $this->get_updates( 'database', 'all' ), 'id' );
//
// foreach ( $update['depend'] as $depend ) {
// // Check if dependency is valid or not.
// if ( ! in_array( $depend, $update_ids ) ) {
// $is_valid_dependency = false;
// break;
// }
// }

return $is_valid_dependency;
}
Expand Down
45 changes: 44 additions & 1 deletion includes/class-give-background-updater.php
Expand Up @@ -35,6 +35,18 @@ public function dispatch() {
parent::dispatch();
}


/**
* Get all batches.
*
* @since 2.0
* @access public
* @return stdClass
*/
public function get_all_batch() {
return parent::get_batch();
}

/**
* Handle cron healthcheck
*
Expand Down Expand Up @@ -99,10 +111,40 @@ protected function task( $update ) {
);

// Continuously skip update if previous update does not complete yet.
if(
if (
$resume_update['update_info']['id'] !== $update['id'] &&
! give_has_upgrade_completed( $resume_update['update_info']['id'] )
) {
$batch = Give_Updates::$background_updater->get_all_batch();
$batch_data_count = count( $batch->data );

if ( ! empty( $batch ) && 1 === $batch_data_count ) {
if ( ! empty( $update['depend'] ) ) {

$give_updates = Give_Updates::get_instance();
$all_updates = $give_updates->get_updates( 'database', 'all' );
$all_update_ids = wp_list_pluck( $all_updates, 'id' );

foreach ( $update['depend'] as $depend ) {
if ( give_has_upgrade_completed( $depend ) ) {
continue;
}

if ( in_array( $depend, $all_update_ids ) ) {
array_unshift( $batch->data, $all_updates[ array_search( $depend, $all_update_ids ) ] );
}
}

if( $batch_data_count !== count( $batch->data ) ) {
update_option( $batch->key, $batch->data );
$this->dispatch();

wp_die();
}
}
}


return $update;
}

Expand All @@ -112,6 +154,7 @@ protected function task( $update ) {
$give_updates->update = absint( $resume_update['update'] );
$is_parent_update_completed = $give_updates->is_parent_updates_completed( $update );


// Skip update if dependency update does not complete yet.
if ( empty( $is_parent_update_completed ) ) {
// @todo: set error when you have only one update with invalid dependency
Expand Down
2 changes: 1 addition & 1 deletion includes/class-give-db-logs.php
Expand Up @@ -289,7 +289,7 @@ public function get_sql( $args = array() ) {
$this->validate_params( $args );

if ( $args['number'] < 1 ) {
$args['number'] = 999999999999;
$args['number'] = 99999999999;
}

// Where clause for primary table.
Expand Down
63 changes: 39 additions & 24 deletions includes/class-give-db-meta.php
Expand Up @@ -265,42 +265,57 @@ public function delete_meta( $id = 0, $meta_key = '', $meta_value = '', $delete_
* @return string
*/
public function __rename_meta_table_name_in_query( $clause, $wp_query ) {
global $wpdb;

// Add new table to sql query.
if ( $this->is_post_type_query( $wp_query ) && ! empty( $wp_query->meta_query->queries ) ) {
$clause = str_replace( "{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause );
$clause = str_replace( $wpdb->postmeta, $this->table_name, $clause );
$clause = $this->__rename_meta_table_name( $clause, current_filter() );
}

switch( current_filter() ) {
case 'posts_join':
$joins = array( 'INNER JOIN', 'LEFT JOIN' );
return $clause;
}


/**
* Rename query clauses for new meta table
*
* @param $clause
* @param $filter
*
* @return mixed
*/
public function __rename_meta_table_name( $clause, $filter ){
global $wpdb;

foreach ( $joins as $join ) {
if( false !== strpos( $clause, $join ) ) {
$clause = explode( $join, $clause );
$clause = str_replace( "{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause );
$clause = str_replace( $wpdb->postmeta, $this->table_name, $clause );

foreach ( $clause as $key => $clause_part ) {
if( empty( $clause_part ) ) {
continue;
}
switch( $filter ) {
case 'posts_join':
$joins = array( 'INNER JOIN', 'LEFT JOIN' );

preg_match( '/' . $wpdb->prefix . 'give_paymentmeta AS (.*) ON/', $clause_part, $alias_table_name );
foreach ( $joins as $join ) {
if( false !== strpos( $clause, $join ) ) {
$clause = explode( $join, $clause );

if( isset( $alias_table_name[1] ) ) {
$clause[$key] = str_replace( "{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part );
}
foreach ( $clause as $key => $clause_part ) {
if( empty( $clause_part ) ) {
continue;
}

$clause = implode( "{$join} ", $clause );
preg_match( '/' . $wpdb->prefix . 'give_' . $this->meta_type . 'meta AS (.*) ON/', $clause_part, $alias_table_name );

if( isset( $alias_table_name[1] ) ) {
$clause[$key] = str_replace( "{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part );
}
}

$clause = implode( "{$join} ", $clause );
}
break;
}
break;

case 'posts_where':
$clause = str_replace( array( 'mt2.post_id', 'mt1.post_id' ), array( "mt2.{$this->meta_type}_id", "mt1.{$this->meta_type}_id" ), $clause );
break;
}
case 'posts_where':
$clause = str_replace( array( 'mt2.post_id', 'mt1.post_id' ), array( "mt2.{$this->meta_type}_id", "mt1.{$this->meta_type}_id" ), $clause );
break;
}

return $clause;
Expand Down
2 changes: 1 addition & 1 deletion includes/donors/class-give-donors-query.php
Expand Up @@ -189,7 +189,7 @@ public function get_sql() {
global $wpdb;

if ( $this->args['number'] < 1 ) {
$this->args['number'] = 999999999999;
$this->args['number'] = 99999999999;
}

$where = $this->get_where_query();
Expand Down
9 changes: 7 additions & 2 deletions includes/payments/class-give-payment.php
Expand Up @@ -734,10 +734,15 @@ private function insert_payment() {
*
* @since 2.0.1
*/
$custom_payment_meta = array_diff( $this->payment_meta, $payment_data );
$custom_payment_meta = array_diff(
array_map( 'maybe_serialize', $this->payment_meta ),
array_map( 'maybe_serialize', $payment_data )
);

if( ! empty( $custom_payment_meta ) ) {
give_doing_it_wrong( '_give_payment_meta', __( 'This custom meta key deprecated. We are not using this meta key for storing payment meta but your custom meta data will be store because we added backward compatibility. Please change your logic because in future we can remove it.', 'give' ), '2.0.0' );
$this->update_meta( '_give_payment_meta', $custom_payment_meta );

$this->update_meta( '_give_payment_meta', array_map( 'maybe_unserialize', $custom_payment_meta ) );
}

$this->new = true;
Expand Down
3 changes: 2 additions & 1 deletion includes/payments/class-payments-query.php
Expand Up @@ -838,13 +838,14 @@ private function get_sql() {
if ( ! empty( $this->args['meta_query'] ) ) {
$meta_query_obj = new WP_Meta_Query( $this->args['meta_query'] );
$where = implode( ' ', $meta_query_obj->get_sql( 'post', $wpdb->posts, 'ID' ) ) . " {$where}";
$where = Give()->payment_meta->__rename_meta_table_name( $where, 'posts_where' );
}

// Set sql query.
$sql = $wpdb->prepare(
"SELECT {$fields} FROM {$wpdb->posts} LIMIT %d,%d;",
absint( $this->args['offset'] ),
( empty( $this->args['nopaging'] ) ? absint( $this->args['posts_per_page'] ) : 999999999999999 )
( empty( $this->args['nopaging'] ) ? absint( $this->args['posts_per_page'] ) : 99999999999 )
);

// $where, $orderby and order already prepared query they can generate notice if you re prepare them in above.
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Expand Up @@ -5,7 +5,7 @@ Tags: donation, donations, donation plugin, wordpress donation plugin, wp donati
Requires at least: 4.8
Tested up to: 4.9
Requires PHP: 5.3
Stable tag: 2.0.0
Stable tag: 2.0.1
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down

0 comments on commit f7674e6

Please sign in to comment.