From 4defeadba37d68d0937a0ee99793ec1a0b4f59cb Mon Sep 17 00:00:00 2001 From: Siddharth Date: Tue, 27 Mar 2018 20:34:09 +0530 Subject: [PATCH 01/48] fix(shortcode): Use AJAX to render donation form Earlier every grid item had form hidden using CSS, now the hidden form is instead fetched using AJAX. --- assets/src/css/frontend/donation-grid.scss | 126 ++++++++++++++++++++- assets/src/js/frontend/give-misc.js | 40 +++++-- includes/ajax-functions.php | 19 ++++ templates/shortcode-form-grid.php | 14 +-- 4 files changed, 174 insertions(+), 25 deletions(-) diff --git a/assets/src/css/frontend/donation-grid.scss b/assets/src/css/frontend/donation-grid.scss index 1538770768..5222bcd074 100644 --- a/assets/src/css/frontend/donation-grid.scss +++ b/assets/src/css/frontend/donation-grid.scss @@ -153,10 +153,6 @@ .give-btn-modal { display: none !important; } - - .mfp-close:hover { - background-color: rgba(0, 0, 0, 0); - } } // .progress { @@ -263,3 +259,125 @@ .my-mfp-slide-bottom.mfp-removing.mfp-bg { opacity: 0; } + +.white-popup { + position: relative; + background: #fff; + font-size: 16px; + width: auto; + max-width: 600px; + margin: 20px auto; + padding: 1rem 2rem; + margin-top: 60px; + border-top: 5px solid rgba(0, 0, 0, 0); + line-height: 1.5; + box-shadow: 0px 15px 10px -5px rgba(0, 0, 0, .15); + max-height: 80vh; + overflow: auto; +} + + +.my-mfp-zoom-in .zoom-animation { + opacity: 0; + + -webkit-transition: all 0.2s ease-in-out; + -moz-transition: all 0.2s ease-in-out; + -o-transition: all 0.2s ease-in-out; + transition: all 0.2s ease-in-out; + -webkit-transform: scale(0.8); + -moz-transform: scale(0.8); + -ms-transform: scale(0.8); + -o-transform: scale(0.8); + transform: scale(0.8); +} + +.my-mfp-zoom-in.mfp-ready .zoom-animation { + opacity: 1; + + -webkit-transform: scale(1); + -moz-transform: scale(1); + -ms-transform: scale(1); + -o-transform: scale(1); + transform: scale(1); +} + +.my-mfp-zoom-in.mfp-removing .zoom-animation { + -webkit-transform: scale(0.8); + -moz-transform: scale(0.8); + -ms-transform: scale(0.8); + -o-transform: scale(0.8); + transform: scale(0.8); + opacity: 0; +} + +.my-mfp-zoom-in.mfp-bg { + opacity: 0; + -webkit-transition: opacity 0.3s ease-out; + -moz-transition: opacity 0.3s ease-out; + -o-transition: opacity 0.3s ease-out; + transition: opacity 0.3s ease-out; +} + +.my-mfp-zoom-in.mfp-ready.mfp-bg { + opacity: 0.8; +} + +.my-mfp-zoom-in.mfp-removing.mfp-bg { + opacity: 0; +} + +/** + * Fade-move animation for second dialog + */ +.popup-fade-slide .zoom-animation { + opacity: 0; + -webkit-transition: all 0.2s ease-out; + -moz-transition: all 0.2s ease-out; + -o-transition: all 0.2s ease-out; + transition: all 0.2s ease-out; + + -webkit-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + -moz-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + -ms-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + -o-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + +} + +.popup-fade-slide.mfp-ready .zoom-animation { + opacity: 1; + -webkit-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + -moz-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + -ms-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + -o-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + transform: translateY(0) perspective( 600px ) rotateX( 0 ); +} + +.popup-fade-slide.mfp-removing .zoom-animation { + opacity: 0; + -webkit-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + -moz-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + -ms-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + -o-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); +} + +.popup-fade-slide.mfp-bg { + opacity: 0; + -webkit-transition: opacity 0.3s ease-out; + -moz-transition: opacity 0.3s ease-out; + -o-transition: opacity 0.3s ease-out; + transition: opacity 0.3s ease-out; +} + +.popup-fade-slide.mfp-ready.mfp-bg { + opacity: 0.8; +} + +.popup-fade-slide.mfp-removing.mfp-bg { + opacity: 0; +} + +.mfp-close:hover { + background-color: rgba(0, 0, 0, 0); +} \ No newline at end of file diff --git a/assets/src/js/frontend/give-misc.js b/assets/src/js/frontend/give-misc.js index b437842d74..d34082f615 100644 --- a/assets/src/js/frontend/give-misc.js +++ b/assets/src/js/frontend/give-misc.js @@ -10,15 +10,37 @@ jQuery( function( $ ) { // Set custom validation message. give_change_html5_form_field_validation_message(); - // Donation grid shortcode popup. - $( '.js-give-grid-modal-launcher' ).magnificPopup( { - type: 'inline', - fixedContentPos: true, - fixedBgPos: true, - closeBtnInside: true, - midClick: true, - removalDelay: 300, - mainClass: 'my-mfp-slide-bottom', + // Get donation form HTML and popup using Magnific popup for [give_form_grid] shortcode. + doc.on( 'click', '.give-grid__item', function( e ) { + let ajax_popup = $( this ).data( 'ajax-popup' ); + + if ( ! ajax_popup ) { + return; + } + + e.preventDefault(); + + let form_id = $( this ).data( 'form-id' ); + + $.ajax({ + url: give_global_vars.ajaxurl, + type: 'POST', + data: { + action: 'get_modal_form_html', + form_id: form_id, + } + }).done( function( response ) { + var html = JSON.parse( response ); + + $.magnificPopup.open({ + mainClass: 'popup-fade-slide', + removalDelay: 300, + items: { + src: `
${ html.modal_html }
`, + type: 'inline', + } + }); + }); }); // Disable button if it have give-disabled class init. diff --git a/includes/ajax-functions.php b/includes/ajax-functions.php index c1505bef5f..7b91ad6ffb 100644 --- a/includes/ajax-functions.php +++ b/includes/ajax-functions.php @@ -623,3 +623,22 @@ function give_ajax_pages_search() { } add_action( 'wp_ajax_give_pages_search', 'give_ajax_pages_search' ); + +/** + * Sends the HTML rendered by give_get_donation_form() as JSON. + */ +function give_ajax_get_modal_form_html() { + + $form_id = give_clean( $_POST['form_id'] ); + $rendered_output = array(); + + ob_start(); + give_get_donation_form( array( 'id' => intval( $form_id ) ) ); + $rendered_output[ 'modal_html' ] = ob_get_clean(); + echo wp_json_encode( $rendered_output ); + + give_die(); +} + +add_action( 'wp_ajax_no_priv_get_modal_form_html', 'give_ajax_get_modal_form_html' ); +add_action( 'wp_ajax_get_modal_form_html', 'give_ajax_get_modal_form_html' ); \ No newline at end of file diff --git a/templates/shortcode-form-grid.php b/templates/shortcode-form-grid.php index 23fbd09031..9e2fe1873e 100644 --- a/templates/shortcode-form-grid.php +++ b/templates/shortcode-form-grid.php @@ -14,9 +14,10 @@ $raw_content = ''; // Raw form content. $stripped_content = ''; // Form content stripped of HTML tags and shortcodes. $excerpt = ''; // Trimmed form excerpt ready for display. +$form_id_modal = ( 'modal' === $atts['display_style'] ) ? 'data-ajax-popup="enabled" data-form-id=' . $form_id : ''; ?> -
+
> - ', - $form_id - ); - give_get_donation_form( $form_id ); - echo '
'; - } - ?>
From 37403b9e1258c15645b0485185c03a2ddac43330 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Thu, 29 Mar 2018 01:02:06 +0530 Subject: [PATCH 02/48] fix(shortcode): Add event delegation to load proper gateway --- assets/src/js/frontend/give-ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/src/js/frontend/give-ajax.js b/assets/src/js/frontend/give-ajax.js index 9a014f73f7..7f67c8d145 100644 --- a/assets/src/js/frontend/give-ajax.js +++ b/assets/src/js/frontend/give-ajax.js @@ -114,7 +114,7 @@ jQuery( document ).ready( function( $ ) { } ); //Switch the gateway on gateway selection field change - $( 'select#give-gateway, input.give-gateway' ).on( 'change', function( e ) { + $( document ).on( 'change', 'select#give-gateway, input.give-gateway', function( e ) { e.preventDefault(); From 214a31df8a1a143eaf3ecb3de7783ca0747d1c5a Mon Sep 17 00:00:00 2001 From: Siddharth Date: Thu, 29 Mar 2018 13:22:06 +0530 Subject: [PATCH 03/48] fix(shortcode): Move css to modal.scss file --- assets/src/css/frontend/donation-grid.scss | 181 -------------------- assets/src/css/frontend/modal.scss | 183 +++++++++++++++++++++ 2 files changed, 183 insertions(+), 181 deletions(-) diff --git a/assets/src/css/frontend/donation-grid.scss b/assets/src/css/frontend/donation-grid.scss index 5222bcd074..2b5b3007ee 100644 --- a/assets/src/css/frontend/donation-grid.scss +++ b/assets/src/css/frontend/donation-grid.scss @@ -200,184 +200,3 @@ // background-position: 40px 0; // } // } - -.mfp-hide { - display: none; -} - -.my-mfp-zoom-in .zoom-anim-dialog { - opacity: 0; - transition: all 0.2s ease-in-out; -} - -.my-mfp-zoom-in.mfp-ready .zoom-anim-dialog { - opacity: 1; -} - -.my-mfp-zoom-in.mfp-removing .zoom-anim-dialog { - opacity: 0; -} - -.my-mfp-zoom-in.mfp-bg { - opacity: 0; - transition: opacity 0.25s ease-out; -} - -.my-mfp-zoom-in.mfp-ready.mfp-bg { - opacity: 0.8; -} - -.my-mfp-zoom-in.mfp-removing.mfp-bg { - opacity: 0; -} - -.my-mfp-slide-bottom .zoom-anim-dialog { - opacity: 0; - transform: translateY(-200px); - transition: all 0.25s ease-out; -} - -.my-mfp-slide-bottom.mfp-ready .zoom-anim-dialog { - opacity: 1; - transform: translateY(0); -} - -.my-mfp-slide-bottom.mfp-removing .zoom-anim-dialog { - opacity: 0; - transform: translateY(-200px); -} - -.my-mfp-slide-bottom.mfp-bg { - opacity: 0; - transition: opacity 0.25s ease-out; -} - -.my-mfp-slide-bottom.mfp-ready.mfp-bg { - opacity: 0.8; -} - -.my-mfp-slide-bottom.mfp-removing.mfp-bg { - opacity: 0; -} - -.white-popup { - position: relative; - background: #fff; - font-size: 16px; - width: auto; - max-width: 600px; - margin: 20px auto; - padding: 1rem 2rem; - margin-top: 60px; - border-top: 5px solid rgba(0, 0, 0, 0); - line-height: 1.5; - box-shadow: 0px 15px 10px -5px rgba(0, 0, 0, .15); - max-height: 80vh; - overflow: auto; -} - - -.my-mfp-zoom-in .zoom-animation { - opacity: 0; - - -webkit-transition: all 0.2s ease-in-out; - -moz-transition: all 0.2s ease-in-out; - -o-transition: all 0.2s ease-in-out; - transition: all 0.2s ease-in-out; - -webkit-transform: scale(0.8); - -moz-transform: scale(0.8); - -ms-transform: scale(0.8); - -o-transform: scale(0.8); - transform: scale(0.8); -} - -.my-mfp-zoom-in.mfp-ready .zoom-animation { - opacity: 1; - - -webkit-transform: scale(1); - -moz-transform: scale(1); - -ms-transform: scale(1); - -o-transform: scale(1); - transform: scale(1); -} - -.my-mfp-zoom-in.mfp-removing .zoom-animation { - -webkit-transform: scale(0.8); - -moz-transform: scale(0.8); - -ms-transform: scale(0.8); - -o-transform: scale(0.8); - transform: scale(0.8); - opacity: 0; -} - -.my-mfp-zoom-in.mfp-bg { - opacity: 0; - -webkit-transition: opacity 0.3s ease-out; - -moz-transition: opacity 0.3s ease-out; - -o-transition: opacity 0.3s ease-out; - transition: opacity 0.3s ease-out; -} - -.my-mfp-zoom-in.mfp-ready.mfp-bg { - opacity: 0.8; -} - -.my-mfp-zoom-in.mfp-removing.mfp-bg { - opacity: 0; -} - -/** - * Fade-move animation for second dialog - */ -.popup-fade-slide .zoom-animation { - opacity: 0; - -webkit-transition: all 0.2s ease-out; - -moz-transition: all 0.2s ease-out; - -o-transition: all 0.2s ease-out; - transition: all 0.2s ease-out; - - -webkit-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - -moz-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - -ms-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - -o-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - -} - -.popup-fade-slide.mfp-ready .zoom-animation { - opacity: 1; - -webkit-transform: translateY(0) perspective( 600px ) rotateX( 0 ); - -moz-transform: translateY(0) perspective( 600px ) rotateX( 0 ); - -ms-transform: translateY(0) perspective( 600px ) rotateX( 0 ); - -o-transform: translateY(0) perspective( 600px ) rotateX( 0 ); - transform: translateY(0) perspective( 600px ) rotateX( 0 ); -} - -.popup-fade-slide.mfp-removing .zoom-animation { - opacity: 0; - -webkit-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - -moz-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - -ms-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - -o-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); -} - -.popup-fade-slide.mfp-bg { - opacity: 0; - -webkit-transition: opacity 0.3s ease-out; - -moz-transition: opacity 0.3s ease-out; - -o-transition: opacity 0.3s ease-out; - transition: opacity 0.3s ease-out; -} - -.popup-fade-slide.mfp-ready.mfp-bg { - opacity: 0.8; -} - -.popup-fade-slide.mfp-removing.mfp-bg { - opacity: 0; -} - -.mfp-close:hover { - background-color: rgba(0, 0, 0, 0); -} \ No newline at end of file diff --git a/assets/src/css/frontend/modal.scss b/assets/src/css/frontend/modal.scss index 51165df6fc..fea989922e 100644 --- a/assets/src/css/frontend/modal.scss +++ b/assets/src/css/frontend/modal.scss @@ -113,3 +113,186 @@ } } + +/** + * Give Modal & Magnific Popup CSS + */ +.mfp-hide { + display: none; +} + +.my-mfp-zoom-in .zoom-anim-dialog { + opacity: 0; + transition: all 0.2s ease-in-out; +} + +.my-mfp-zoom-in.mfp-ready .zoom-anim-dialog { + opacity: 1; +} + +.my-mfp-zoom-in.mfp-removing .zoom-anim-dialog { + opacity: 0; +} + +.my-mfp-zoom-in.mfp-bg { + opacity: 0; + transition: opacity 0.25s ease-out; +} + +.my-mfp-zoom-in.mfp-ready.mfp-bg { + opacity: 0.8; +} + +.my-mfp-zoom-in.mfp-removing.mfp-bg { + opacity: 0; +} + +.my-mfp-slide-bottom .zoom-anim-dialog { + opacity: 0; + transform: translateY(-200px); + transition: all 0.25s ease-out; +} + +.my-mfp-slide-bottom.mfp-ready .zoom-anim-dialog { + opacity: 1; + transform: translateY(0); +} + +.my-mfp-slide-bottom.mfp-removing .zoom-anim-dialog { + opacity: 0; + transform: translateY(-200px); +} + +.my-mfp-slide-bottom.mfp-bg { + opacity: 0; + transition: opacity 0.25s ease-out; +} + +.my-mfp-slide-bottom.mfp-ready.mfp-bg { + opacity: 0.8; +} + +.my-mfp-slide-bottom.mfp-removing.mfp-bg { + opacity: 0; +} + +.white-popup { + position: relative; + background: #fff; + font-size: 16px; + width: auto; + max-width: 600px; + margin: 20px auto; + padding: 1rem 2rem; + margin-top: 60px; + border-top: 5px solid rgba(0, 0, 0, 0); + line-height: 1.5; + box-shadow: 0px 15px 10px -5px rgba(0, 0, 0, .15); + max-height: 80vh; + overflow: auto; +} + +.my-mfp-zoom-in .zoom-animation { + opacity: 0; + + -webkit-transition: all 0.2s ease-in-out; + -moz-transition: all 0.2s ease-in-out; + -o-transition: all 0.2s ease-in-out; + transition: all 0.2s ease-in-out; + -webkit-transform: scale(0.8); + -moz-transform: scale(0.8); + -ms-transform: scale(0.8); + -o-transform: scale(0.8); + transform: scale(0.8); +} + +.my-mfp-zoom-in.mfp-ready .zoom-animation { + opacity: 1; + + -webkit-transform: scale(1); + -moz-transform: scale(1); + -ms-transform: scale(1); + -o-transform: scale(1); + transform: scale(1); +} + +.my-mfp-zoom-in.mfp-removing .zoom-animation { + -webkit-transform: scale(0.8); + -moz-transform: scale(0.8); + -ms-transform: scale(0.8); + -o-transform: scale(0.8); + transform: scale(0.8); + opacity: 0; +} + +.my-mfp-zoom-in.mfp-bg { + opacity: 0; + -webkit-transition: opacity 0.3s ease-out; + -moz-transition: opacity 0.3s ease-out; + -o-transition: opacity 0.3s ease-out; + transition: opacity 0.3s ease-out; +} + +.my-mfp-zoom-in.mfp-ready.mfp-bg { + opacity: 0.8; +} + +.my-mfp-zoom-in.mfp-removing.mfp-bg { + opacity: 0; +} + +/** + * Fade-move animation for second dialog + */ +.popup-fade-slide .zoom-animation { + opacity: 0; + -webkit-transition: all 0.2s ease-out; + -moz-transition: all 0.2s ease-out; + -o-transition: all 0.2s ease-out; + transition: all 0.2s ease-out; + + -webkit-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + -moz-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + -ms-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + -o-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); + +} + +.popup-fade-slide.mfp-ready .zoom-animation { + opacity: 1; + -webkit-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + -moz-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + -ms-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + -o-transform: translateY(0) perspective( 600px ) rotateX( 0 ); + transform: translateY(0) perspective( 600px ) rotateX( 0 ); +} + +.popup-fade-slide.mfp-removing .zoom-animation { + opacity: 0; + -webkit-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + -moz-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + -ms-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + -o-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); +} + +.popup-fade-slide.mfp-bg { + opacity: 0; + -webkit-transition: opacity 0.3s ease-out; + -moz-transition: opacity 0.3s ease-out; + -o-transition: opacity 0.3s ease-out; + transition: opacity 0.3s ease-out; +} + +.popup-fade-slide.mfp-ready.mfp-bg { + opacity: 0.8; +} + +.popup-fade-slide.mfp-removing.mfp-bg { + opacity: 0; +} + +.mfp-close:hover { + background-color: rgba(0, 0, 0, 0); +} \ No newline at end of file From 170cb210aca39de471d3b6711db9de0c8737d4b9 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Thu, 5 Apr 2018 15:22:26 +0530 Subject: [PATCH 04/48] fix(shortcode): Remove form load by AJAX This is a revert commit. The forms are shown/hidden instead of using AJAX to load the form. --- assets/src/js/frontend/give-misc.js | 40 +++++++---------------------- includes/ajax-functions.php | 19 -------------- includes/shortcodes.php | 2 +- templates/shortcode-form-grid.php | 14 ++++++++-- 4 files changed, 22 insertions(+), 53 deletions(-) diff --git a/assets/src/js/frontend/give-misc.js b/assets/src/js/frontend/give-misc.js index d34082f615..b437842d74 100644 --- a/assets/src/js/frontend/give-misc.js +++ b/assets/src/js/frontend/give-misc.js @@ -10,37 +10,15 @@ jQuery( function( $ ) { // Set custom validation message. give_change_html5_form_field_validation_message(); - // Get donation form HTML and popup using Magnific popup for [give_form_grid] shortcode. - doc.on( 'click', '.give-grid__item', function( e ) { - let ajax_popup = $( this ).data( 'ajax-popup' ); - - if ( ! ajax_popup ) { - return; - } - - e.preventDefault(); - - let form_id = $( this ).data( 'form-id' ); - - $.ajax({ - url: give_global_vars.ajaxurl, - type: 'POST', - data: { - action: 'get_modal_form_html', - form_id: form_id, - } - }).done( function( response ) { - var html = JSON.parse( response ); - - $.magnificPopup.open({ - mainClass: 'popup-fade-slide', - removalDelay: 300, - items: { - src: `
${ html.modal_html }
`, - type: 'inline', - } - }); - }); + // Donation grid shortcode popup. + $( '.js-give-grid-modal-launcher' ).magnificPopup( { + type: 'inline', + fixedContentPos: true, + fixedBgPos: true, + closeBtnInside: true, + midClick: true, + removalDelay: 300, + mainClass: 'my-mfp-slide-bottom', }); // Disable button if it have give-disabled class init. diff --git a/includes/ajax-functions.php b/includes/ajax-functions.php index d3e39f1577..e48258770f 100644 --- a/includes/ajax-functions.php +++ b/includes/ajax-functions.php @@ -622,22 +622,3 @@ function give_ajax_pages_search() { } add_action( 'wp_ajax_give_pages_search', 'give_ajax_pages_search' ); - -/** - * Sends the HTML rendered by give_get_donation_form() as JSON. - */ -function give_ajax_get_modal_form_html() { - - $form_id = give_clean( $_POST['form_id'] ); - $rendered_output = array(); - - ob_start(); - give_get_donation_form( array( 'id' => intval( $form_id ) ) ); - $rendered_output[ 'modal_html' ] = ob_get_clean(); - echo wp_json_encode( $rendered_output ); - - give_die(); -} - -add_action( 'wp_ajax_no_priv_get_modal_form_html', 'give_ajax_get_modal_form_html' ); -add_action( 'wp_ajax_get_modal_form_html', 'give_ajax_get_modal_form_html' ); \ No newline at end of file diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 8a07b56025..f1a15b5694 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -743,7 +743,7 @@ function give_form_grid_shortcode( $atts ) { 'image_size' => 'medium', 'image_height' => 'auto', 'excerpt_length' => 16, - 'display_style' => 'redirect', + 'display_style' => 'modal', ), $atts ); // Validate integer attributes. diff --git a/templates/shortcode-form-grid.php b/templates/shortcode-form-grid.php index 9e2fe1873e..23fbd09031 100644 --- a/templates/shortcode-form-grid.php +++ b/templates/shortcode-form-grid.php @@ -14,10 +14,9 @@ $raw_content = ''; // Raw form content. $stripped_content = ''; // Form content stripped of HTML tags and shortcodes. $excerpt = ''; // Trimmed form excerpt ready for display. -$form_id_modal = ( 'modal' === $atts['display_style'] ) ? 'data-ajax-popup="enabled" data-form-id=' . $form_id : ''; ?> -
> +
+ ', + $form_id + ); + give_get_donation_form( $form_id ); + echo '
'; + } + ?>
From 11e311f3abbf5fed6f76a41e41f93295d68cc5cb Mon Sep 17 00:00:00 2001 From: Siddharth Date: Thu, 5 Apr 2018 15:39:14 +0530 Subject: [PATCH 05/48] fix(shortcode): rename display style display_style "modal" is changed to "modal_reveal" --- includes/shortcodes.php | 2 +- templates/shortcode-form-grid.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/shortcodes.php b/includes/shortcodes.php index f1a15b5694..0128e27ffe 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -743,7 +743,7 @@ function give_form_grid_shortcode( $atts ) { 'image_size' => 'medium', 'image_height' => 'auto', 'excerpt_length' => 16, - 'display_style' => 'modal', + 'display_style' => 'modal_reveal', ), $atts ); // Validate integer attributes. diff --git a/templates/shortcode-form-grid.php b/templates/shortcode-form-grid.php index 23fbd09031..30fbbaaa9f 100644 --- a/templates/shortcode-form-grid.php +++ b/templates/shortcode-form-grid.php @@ -25,7 +25,7 @@ esc_attr( $form_id ), esc_attr( get_the_permalink() ) ); - } elseif ( 'modal' === $atts['display_style'] ) { + } elseif ( 'modal_reveal' === $atts['display_style'] ) { printf( '', esc_attr( $form_id ) @@ -110,7 +110,7 @@ ', $form_id From 3407cc8b59dffa117fa2ed16c7c44109be62672b Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 16:49:19 +0530 Subject: [PATCH 06/48] fix(shortcode): undo js chnage for modal --- assets/src/js/frontend/give-ajax.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/src/js/frontend/give-ajax.js b/assets/src/js/frontend/give-ajax.js index 7f67c8d145..c1a6fddb6b 100644 --- a/assets/src/js/frontend/give-ajax.js +++ b/assets/src/js/frontend/give-ajax.js @@ -114,8 +114,7 @@ jQuery( document ).ready( function( $ ) { } ); //Switch the gateway on gateway selection field change - $( document ).on( 'change', 'select#give-gateway, input.give-gateway', function( e ) { - + $( 'select#give-gateway, input.give-gateway' ).on( 'change', function( e ) { e.preventDefault(); //Which payment gateway to load? From 11324d4afd6a86e1112fdab45fe50fbafc035822 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Wed, 11 Apr 2018 17:28:52 +0530 Subject: [PATCH 07/48] perf(shortcode): Restructure SCSS and remove redundant code --- assets/src/css/frontend/donation-grid.scss | 202 --------------------- assets/src/css/frontend/give-frontend.scss | 2 +- assets/src/css/frontend/modal.scss | 176 +++--------------- assets/src/js/frontend/give-misc.js | 2 +- templates/shortcode-form-grid.php | 2 +- 5 files changed, 28 insertions(+), 356 deletions(-) delete mode 100644 assets/src/css/frontend/donation-grid.scss diff --git a/assets/src/css/frontend/donation-grid.scss b/assets/src/css/frontend/donation-grid.scss deleted file mode 100644 index 2b5b3007ee..0000000000 --- a/assets/src/css/frontend/donation-grid.scss +++ /dev/null @@ -1,202 +0,0 @@ -// @mixin mobile { -// @media screen and ( max-width: 480px ) { -// @content; -// } -// } - -// @mixin tablet { -// @media screen and ( max-width: 786px ) { -// @content; -// } -// } - -// @mixin tabel-to-desktop { -// @media screen and ( min-width: 787px ) and ( max-width: 1024px ) { -// @content; -// } -// } - -// .give-donation-grid-container { -// display: flex; -// flex-flow: row wrap; - -// .give-donation-grid-item { -// display: flex; -// margin-bottom: .5rem; -// padding: 0 .25rem; - -// .box { -// display: flex; -// flex-flow: column; -// padding: 1rem; -// width: 100%; -// box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.12); -// border-radius: 2px; -// overflow: hidden; -// transition: box-shadow .15s ease; - -// &:hover { -// box-shadow: 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12), 0 5px 5px -3px rgba(0, 0, 0, .2); - -// .progress.active .bar { -// animation: progress-bar-stripes 2s linear infinite; -// } -// } - -// img { -// height: 200px; -// object-fit: cover; -// } -// } - -// .donation-grid-featured-image { -// margin: -1rem -1rem 0 -1rem; -// padding: .5rem; -// } - -// .donation-grid-title { -// margin: 1rem 0 .25rem 0; -// font-size: 1.15rem; -// font-weight: bold; -// } - -// .give-goal-progress .give-progress-bar { -// height: 12px; -// } - -// .raised { -// margin-bottom: 4px; -// font-size: 0.8rem; -// color: #999; -// } - -// .donor-grid-excerpt { -// margin-bottom: 1.5rem; -// font-size: .90rem; -// } - -// .grid-donate-now { -// margin: auto 0 0 0; -// padding: .5rem; -// background-color: #68bb6c; -// color: #fff; -// font-weight: bold; -// text-align: center; -// text-decoration: none; -// text-transform: uppercase; -// border-radius: 2px; -// transition: background-color .15s ease; -// cursor: pointer; - -// &:hover { -// background-color: #429446; -// } -// } -// } - -// .give-grid-col-1 { -// width: 100%; -// } - -// .give-grid-col-2 { -// width: 50%; - -// @include mobile { -// width: 100%; -// } -// } - -// .give-grid-col-3 { -// width: calc( 100% / 3 ); - -// @include tablet { -// width: 50%; -// } - -// @include mobile { -// width: 100%; -// } -// } - -// .give-grid-col-4 { -// width: 25%; - -// @include tabel-to-desktop { -// width: calc( 100% / 3 ); -// } - -// @include tablet { -// width: 50%; -// } - -// @include mobile { -// width: 100%; -// } -// } -// } - -.give-donation-grid-item-form { - position: relative; - margin: 0 auto; - max-width: 550px; - background-color: #fff; - padding: 1rem; - height: 85vh; - overflow-y: auto; - - #give-payment-mode-select, - #give_purchase_form_wrap { - display: block !important; - } - - .give-btn-reveal, - .give-btn-modal { - display: none !important; - } -} - -// .progress { -// overflow: hidden; -// background-image: linear-gradient(top, #f5f5f5, #f9f9f9); -// background-repeat: repeat-x; -// filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f5f5f5', endColorstr='#f9f9f9', GradientType=0); -// box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); - -// .bar { -// background-image: linear-gradient(top, #149bdf, #0480be); -// background-repeat: repeat-x; -// filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#149bdf', endColorstr='#0480be', GradientType=0); -// box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); -// box-sizing: border-box; -// transition: width 0.6s ease; -// } -// } - -// .progress-striped .bar { -// background-color: #89949B; -// background-image: linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); -// background-size: 40px 40px; -// } - -// .progress-danger .bar { -// background-color: #89949B; -// background-image: linear-gradient(top, #89949B, #c43c35); -// background-repeat: repeat-x; -// filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ee5f5b', endColorstr='#c43c35', GradientType=0); -// } - -// .progress-danger.progress-striped .bar { -// background-color: #1ABC9C; -// background-image: linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); -// } - - -// @keyframes progress-bar-stripes { -// from { -// background-position: 0 0; -// } - -// to { -// background-position: 40px 0; -// } -// } diff --git a/assets/src/css/frontend/give-frontend.scss b/assets/src/css/frontend/give-frontend.scss index 503d180755..7747eb7281 100644 --- a/assets/src/css/frontend/give-frontend.scss +++ b/assets/src/css/frontend/give-frontend.scss @@ -22,7 +22,7 @@ @import 'tables'; @import 'theme-compatibility'; @import 'donation-history'; -@import 'donation-grid'; +@import 'modal'; // Wrapper increases specificity for defensive styling against themes. .give-wrap { diff --git a/assets/src/css/frontend/modal.scss b/assets/src/css/frontend/modal.scss index fea989922e..48b40342c6 100644 --- a/assets/src/css/frontend/modal.scss +++ b/assets/src/css/frontend/modal.scss @@ -114,182 +114,56 @@ } + /** - * Give Modal & Magnific Popup CSS + * Form Grid Magnific Popup CSS */ -.mfp-hide { - display: none; -} - -.my-mfp-zoom-in .zoom-anim-dialog { - opacity: 0; - transition: all 0.2s ease-in-out; -} - -.my-mfp-zoom-in.mfp-ready .zoom-anim-dialog { - opacity: 1; -} - -.my-mfp-zoom-in.mfp-removing .zoom-anim-dialog { - opacity: 0; -} - -.my-mfp-zoom-in.mfp-bg { - opacity: 0; - transition: opacity 0.25s ease-out; -} - -.my-mfp-zoom-in.mfp-ready.mfp-bg { - opacity: 0.8; -} - -.my-mfp-zoom-in.mfp-removing.mfp-bg { - opacity: 0; -} - -.my-mfp-slide-bottom .zoom-anim-dialog { - opacity: 0; - transform: translateY(-200px); - transition: all 0.25s ease-out; -} - -.my-mfp-slide-bottom.mfp-ready .zoom-anim-dialog { - opacity: 1; - transform: translateY(0); -} - -.my-mfp-slide-bottom.mfp-removing .zoom-anim-dialog { - opacity: 0; - transform: translateY(-200px); -} - -.my-mfp-slide-bottom.mfp-bg { - opacity: 0; - transition: opacity 0.25s ease-out; -} - -.my-mfp-slide-bottom.mfp-ready.mfp-bg { - opacity: 0.8; -} - -.my-mfp-slide-bottom.mfp-removing.mfp-bg { - opacity: 0; -} - -.white-popup { +.give-donation-grid-item-form { position: relative; - background: #fff; - font-size: 16px; - width: auto; + margin: 0 auto; max-width: 600px; - margin: 20px auto; - padding: 1rem 2rem; - margin-top: 60px; - border-top: 5px solid rgba(0, 0, 0, 0); - line-height: 1.5; - box-shadow: 0px 15px 10px -5px rgba(0, 0, 0, .15); - max-height: 80vh; - overflow: auto; -} - -.my-mfp-zoom-in .zoom-animation { - opacity: 0; - - -webkit-transition: all 0.2s ease-in-out; - -moz-transition: all 0.2s ease-in-out; - -o-transition: all 0.2s ease-in-out; - transition: all 0.2s ease-in-out; - -webkit-transform: scale(0.8); - -moz-transform: scale(0.8); - -ms-transform: scale(0.8); - -o-transform: scale(0.8); - transform: scale(0.8); -} - -.my-mfp-zoom-in.mfp-ready .zoom-animation { - opacity: 1; - - -webkit-transform: scale(1); - -moz-transform: scale(1); - -ms-transform: scale(1); - -o-transform: scale(1); - transform: scale(1); -} - -.my-mfp-zoom-in.mfp-removing .zoom-animation { - -webkit-transform: scale(0.8); - -moz-transform: scale(0.8); - -ms-transform: scale(0.8); - -o-transform: scale(0.8); - transform: scale(0.8); - opacity: 0; -} - -.my-mfp-zoom-in.mfp-bg { - opacity: 0; - -webkit-transition: opacity 0.3s ease-out; - -moz-transition: opacity 0.3s ease-out; - -o-transition: opacity 0.3s ease-out; - transition: opacity 0.3s ease-out; -} - -.my-mfp-zoom-in.mfp-ready.mfp-bg { - opacity: 0.8; -} + background-color: #fff; + padding: 1rem 1.5rem; + height: 85vh; + overflow-y: auto; + + #give-payment-mode-select, + #give_purchase_form_wrap { + display: block !important; + } -.my-mfp-zoom-in.mfp-removing.mfp-bg { - opacity: 0; + .give-btn-reveal, + .give-btn-modal { + display: none !important; + } } -/** - * Fade-move animation for second dialog - */ -.popup-fade-slide .zoom-animation { +.modal-fade-slide .give-modal--slide { opacity: 0; - -webkit-transition: all 0.2s ease-out; - -moz-transition: all 0.2s ease-out; - -o-transition: all 0.2s ease-out; transition: all 0.2s ease-out; - - -webkit-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - -moz-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - -ms-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - -o-transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - transform: translateY(-20px) perspective( 600px ) rotateX( 10deg ); - + transform: translateY(-20px) perspective( 600px ) rotateX( 0 ); } -.popup-fade-slide.mfp-ready .zoom-animation { +.modal-fade-slide.mfp-ready .give-modal--slide { opacity: 1; - -webkit-transform: translateY(0) perspective( 600px ) rotateX( 0 ); - -moz-transform: translateY(0) perspective( 600px ) rotateX( 0 ); - -ms-transform: translateY(0) perspective( 600px ) rotateX( 0 ); - -o-transform: translateY(0) perspective( 600px ) rotateX( 0 ); transform: translateY(0) perspective( 600px ) rotateX( 0 ); } -.popup-fade-slide.mfp-removing .zoom-animation { +.modal-fade-slide.mfp-removing .give-modal--slide { opacity: 0; - -webkit-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - -moz-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - -ms-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - -o-transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); - transform: translateY(-10px) perspective( 600px ) rotateX( 10deg ); + transform: translateY(-10px) perspective( 600px ) rotateX( 0 ); } -.popup-fade-slide.mfp-bg { +.modal-fade-slide.mfp-bg { opacity: 0; - -webkit-transition: opacity 0.3s ease-out; - -moz-transition: opacity 0.3s ease-out; - -o-transition: opacity 0.3s ease-out; transition: opacity 0.3s ease-out; } -.popup-fade-slide.mfp-ready.mfp-bg { +.modal-fade-slide.mfp-ready.mfp-bg { opacity: 0.8; } -.popup-fade-slide.mfp-removing.mfp-bg { +.modal-fade-slide.mfp-removing.mfp-bg { opacity: 0; } diff --git a/assets/src/js/frontend/give-misc.js b/assets/src/js/frontend/give-misc.js index b437842d74..c0e3a29359 100644 --- a/assets/src/js/frontend/give-misc.js +++ b/assets/src/js/frontend/give-misc.js @@ -18,7 +18,7 @@ jQuery( function( $ ) { closeBtnInside: true, midClick: true, removalDelay: 300, - mainClass: 'my-mfp-slide-bottom', + mainClass: 'modal-fade-slide', }); // Disable button if it have give-disabled class init. diff --git a/templates/shortcode-form-grid.php b/templates/shortcode-form-grid.php index 30fbbaaa9f..8875fa6fca 100644 --- a/templates/shortcode-form-grid.php +++ b/templates/shortcode-form-grid.php @@ -112,7 +112,7 @@ // If modal, print form in hidden container until it is time to be revealed. if ( 'modal_reveal' === $atts['display_style'] ) { printf( - '
', + '
', $form_id ); give_get_donation_form( $form_id ); From 52267631dfb4c4dc39c8bf683d2ab4a7cd5db1cc Mon Sep 17 00:00:00 2001 From: Siddharth Date: Fri, 13 Apr 2018 12:50:18 +0530 Subject: [PATCH 08/48] fix(modal): Add popup for display type button If you visit a URL directly with query parameters 'form-id' and 'payment-mode' for a form with display type 'button', the popup will pop up. --- assets/src/js/frontend/give-donations.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/src/js/frontend/give-donations.js b/assets/src/js/frontend/give-donations.js index 7e4ac7659c..660b381c6f 100644 --- a/assets/src/js/frontend/give-donations.js +++ b/assets/src/js/frontend/give-donations.js @@ -732,6 +732,7 @@ Give.form = { var $form_wrapper = jQuery( 'body' ).find( '#give-form-' + form_id + '-wrap' ), $form = $form_wrapper.find( 'form.give-form' ), display_modal = $form_wrapper.hasClass( 'give-display-modal' ), + display_button = $form_wrapper.hasClass( 'give-display-button' ), display_reveal = $form_wrapper.hasClass( 'give-display-reveal' ); // Update payment mode radio so it's correctly checked. @@ -752,7 +753,7 @@ Give.form = { } // This form is modal display so show the modal. - if ( display_modal ) { + if ( display_modal || display_button ) { give_open_form_modal( $form_wrapper, $form ); } else if ( display_reveal ) { // This is a reveal form, show it. From ee6bbc1062d770b1e9bdc76667026fca191a95b5 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 29 Mar 2018 17:59:17 +0530 Subject: [PATCH 09/48] perf(code): stop using Give_Payment in helper fns --- includes/payments/functions.php | 174 ++++++++++++++++++-------------- 1 file changed, 98 insertions(+), 76 deletions(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 98e6cb0ec7..5da4c62bc3 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -466,7 +466,7 @@ function give_check_for_existing_payment( $payment_id ) { /** * Get Payment Status * - * @param WP_Post|Give_Payment|int $payment Payment object or payment ID. + * @param WP_Post|Give_Payment|int $payment_id Payment object or payment ID. * @param bool $return_label Whether to return the translated status label instead of status value. * Default false. * @@ -474,38 +474,38 @@ function give_check_for_existing_payment( $payment_id ) { * * @return bool|mixed True if payment status exists, false otherwise. */ -function give_get_payment_status( $payment, $return_label = false ) { +function give_get_payment_status( $payment_id, $return_label = false ) { - if ( is_numeric( $payment ) ) { - - $payment = new Give_Payment( $payment ); - - if ( ! $payment->ID > 0 ) { - return false; + if ( ! is_numeric( $payment_id ) ) { + if( + $payment_id instanceof Give_Payment + || $payment_id instanceof WP_Post + ) { + $payment_id = $payment_id->ID; } } - if ( ! is_object( $payment ) || ! isset( $payment->post_status ) ) { + if ( ! $payment_id > 0 ) { return false; } + $payment_status = get_post_status( $payment_id ); + $statuses = give_get_payment_statuses(); - if ( ! is_array( $statuses ) || empty( $statuses ) ) { + if ( empty( $payment_status ) || ! is_array( $statuses ) || empty( $statuses ) ) { return false; } - // Get payment object if not already given. - $payment = $payment instanceof Give_Payment ? $payment : new Give_Payment( $payment->ID ); - if ( array_key_exists( $payment->status, $statuses ) ) { + if ( array_key_exists( $payment_status, $statuses ) ) { if ( true === $return_label ) { // Return translated status label. - return $statuses[ $payment->status ]; + return $statuses[ $payment_status ]; } else { // Account that our 'publish' status is labeled 'Complete' - $post_status = 'publish' === $payment->status ? 'Complete' : $payment->post_status; + $post_status = 'publish' === $payment_status ? 'Complete' : $payment_status; // Make sure we're matching cases, since they matter return array_search( strtolower( $post_status ), array_map( 'strtolower', $statuses ) ); @@ -703,18 +703,18 @@ function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $ * @return bool $ret True if complete, false otherwise. */ function give_is_payment_complete( $payment_id ) { - $payment = new Give_Payment( $payment_id ); - $ret = false; + $payment_status = ''; - if ( $payment->ID > 0 ) { + if ( $payment_id > 0 && 'give_payment' === get_post_type( $payment_id )) { + $payment_status = get_post_status( $payment_id ); - if ( (int) $payment_id === (int) $payment->ID && 'publish' == $payment->status ) { + if ( 'publish' === $payment_status ) { $ret = true; } } - return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment->post_status ); + return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment_status ); } /** @@ -835,9 +835,7 @@ function give_decrease_total_earnings( $amount = 0 ) { * @return mixed $meta Payment Meta. */ function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->get_meta( $meta_key, $single ); + return give_get_meta( $payment_id, $meta_key, $single ); } /** @@ -866,9 +864,29 @@ function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value * @return array $user_info User Info Meta Values. */ function give_get_payment_meta_user_info( $payment_id ) { - $payment = new Give_Payment( $payment_id ); + $donor_id = 0; + $donor_info = array( + 'first_name' => give_get_meta( $payment_id, '_give_donor_billing_first_name', true ), + 'last_name' => give_get_meta( $payment_id, '_give_donor_billing_last_name', true ), + 'email' => give_get_meta( $payment_id, '_give_donor_billing_donor_email', true ), + ); - return $payment->user_info; + if ( empty( $donor_info['first_name'] ) ) { + $donor_id = give_get_payment_donor_id( $payment_id ); + $donor_info['first_name'] = Give()->donor_meta->get_meta( $donor_id, '_give_donor_first_name', true ); + } + + if ( empty( $donor_info['last_name'] ) ) { + $donor_id = $donor_id ? $donor_id : give_get_payment_donor_id( $payment_id ); + $donor_info['first_name'] = Give()->donor_meta->get_meta( $donor_id, '_give_donor_last_name', true ); + } + + if ( empty( $donor_info['email'] ) ) { + $donor_id = $donor_id ? $donor_id : give_get_payment_donor_id( $payment_id ); + $donor_info['first_name'] = Give()->donors->get_column_by( 'email', 'id', $donor_id ); + } + + return $donor_info; } /** @@ -883,9 +901,7 @@ function give_get_payment_meta_user_info( $payment_id ) { * @return int $form_id Form ID. */ function give_get_payment_form_id( $payment_id ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->form_id; + return (int) give_get_meta( $payment_id, '_give_payment_form_id', true ); } /** @@ -898,9 +914,7 @@ function give_get_payment_form_id( $payment_id ) { * @return string $email User email. */ function give_get_payment_user_email( $payment_id ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->email; + return give_get_meta( $payment_id, '_give_payment_donor_email', true ); } /** @@ -929,9 +943,25 @@ function give_is_guest_payment( $payment_id ) { * @return int $user_id User ID. */ function give_get_payment_user_id( $payment_id ) { - $payment = new Give_Payment( $payment_id ); + global $wpdb; + $paymentmeta_table = Give()->payment_meta->table_name; - return $payment->user_id; + return (int) $wpdb->get_var( + $wpdb->prepare( + " + SELECT user_id + FROM $wpdb->donors + WHERE id=( + SELECT meta_value + FROM $paymentmeta_table + WHERE payment_id=%s + AND meta_key=%s + ) + ", + $payment_id, + '_give_payment_donor_id' + ) + ); } /** @@ -944,9 +974,7 @@ function give_get_payment_user_id( $payment_id ) { * @return int $payment->customer_id Donor ID. */ function give_get_payment_donor_id( $payment_id ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->customer_id; + return give_get_meta( $payment_id, '_give_payment_donor_id' , true ); } /** @@ -959,9 +987,7 @@ function give_get_payment_donor_id( $payment_id ) { * @return string $ip User IP. */ function give_get_payment_user_ip( $payment_id ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->ip; + return give_get_meta( $payment_id, '_give_payment_donor_ip', true ); } /** @@ -974,9 +1000,7 @@ function give_get_payment_user_ip( $payment_id ) { * @return string $date The date the payment was completed. */ function give_get_payment_completed_date( $payment_id = 0 ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->completed_date; + return give_get_meta( $payment_id, '_give_completed_date', true ); } /** @@ -989,9 +1013,7 @@ function give_get_payment_completed_date( $payment_id = 0 ) { * @return string $gateway Gateway. */ function give_get_payment_gateway( $payment_id ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->gateway; + return give_get_meta( $payment_id, '_give_payment_gateway', true ); } /** @@ -1004,9 +1026,7 @@ function give_get_payment_gateway( $payment_id ) { * @return string $currency The currency code. */ function give_get_payment_currency_code( $payment_id = 0 ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->currency; + return give_get_meta( $payment_id, '_give_payment_currency', true ); } /** @@ -1034,9 +1054,7 @@ function give_get_payment_currency( $payment_id = 0 ) { * @return string $key Donation key. */ function give_get_payment_key( $payment_id = 0 ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->key; + return give_get_meta( $payment_id, '_give_payment_purchase_key', true ); } /** @@ -1051,9 +1069,7 @@ function give_get_payment_key( $payment_id = 0 ) { * @return string $number Payment order number. */ function give_get_payment_number( $payment_id = 0 ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->number; + return Give()->seq_donation_number->get_serial_code( $payment_id ); } @@ -1063,7 +1079,7 @@ function give_get_payment_number( $payment_id = 0 ) { * Get the fully formatted or unformatted donation amount which is sent through give_currency_filter() * and give_format_amount() to format the amount correctly in case of formatted amount. * - * @param int|Give_Payment $donation Donation ID or Donation Object. + * @param int|Give_Payment $donation_id Donation ID or Donation Object. * @param bool|array $format_args Currency Formatting Arguments. * * @since 1.0 @@ -1071,14 +1087,15 @@ function give_get_payment_number( $payment_id = 0 ) { * * @return string $amount Fully formatted donation amount. */ -function give_donation_amount( $donation, $format_args = array() ) { - /* @var Give_Payment $donation */ - if ( ! ( $donation instanceof Give_Payment ) ) { - $donation = new Give_Payment( absint( $donation ) ); +function give_donation_amount( $donation_id, $format_args = array() ) { + if ( ! $donation_id ) { + return ''; + } elseif ( ! is_numeric( $donation_id ) && ( $donation_id instanceof Give_Payment ) ) { + $donation_id = $donation_id->ID; } - $amount = $donation->total; - $formatted_amount = $amount; + $amount = $formatted_amount = give_get_meta( $donation_id, '_give_payment_total', true ); + $currency_code = give_get_payment_currency_code( $donation_id ); if ( is_bool( $format_args ) ) { $format_args = array( @@ -1112,7 +1129,7 @@ function give_donation_amount( $donation, $format_args = array() ) { ! is_array( $format_args['amount'] ) ? array( 'sanitize' => false, - 'currency' => $donation->currency, + 'currency' => $currency_code, ) : $format_args['amount'] ); @@ -1122,7 +1139,7 @@ function give_donation_amount( $donation, $format_args = array() ) { $formatted_amount = give_currency_filter( $formatted_amount, ! is_array( $format_args['currency'] ) ? - array( 'currency_code' => $donation->currency ) : + array( 'currency_code' => $currency_code ) : $format_args['currency'] ); } @@ -1138,7 +1155,7 @@ function give_donation_amount( $donation, $format_args = array() ) { * @param int $donation_id Donation ID. * @param string $type Donation amount type. */ - return apply_filters( 'give_donation_amount', (string) $formatted_amount, $amount, $donation, $format_args ); + return apply_filters( 'give_donation_amount', (string) $formatted_amount, $amount, $donation_id, $format_args ); } /** @@ -1188,9 +1205,14 @@ function give_get_payment_subtotal( $payment_id = 0 ) { * @return string The donation ID. */ function give_get_payment_transaction_id( $payment_id = 0 ) { - $payment = new Give_Payment( $payment_id ); + $transaction_id = give_get_meta( $payment_id, '_give_payment_transaction_id', true ); + + if ( empty( $transaction_id ) ) { + $gateway = $this->gateway; + $transaction_id = apply_filters( "give_get_payment_transaction_id-{$gateway}", $this->ID ); + } - return $payment->transaction_id; + return $transaction_id; } /** @@ -1605,7 +1627,7 @@ function give_filter_where_older_than_week( $where = '' ) { * * Retrieves the form title and appends the level name if present. * - * @param int|Give_Payment $donation Donation Data Object. + * @param int|Give_Payment $donation_id Donation Data Object. * @param array $args a. only_level = If set to true will only return the level name if multi-level enabled. * b. separator = The separator between the Form Title and the Donation Level. * @@ -1613,13 +1635,13 @@ function give_filter_where_older_than_week( $where = '' ) { * * @return string $form_title Returns the full title if $only_level is false, otherwise returns the levels title. */ -function give_get_donation_form_title( $donation, $args = array() ) { +function give_get_donation_form_title( $donation_id, $args = array() ) { - if ( ! $donation instanceof Give_Payment ) { - $donation = new Give_Payment( $donation ); + if ( ! is_numeric( $donation_id ) && $donation_id instanceof Give_Payment ) { + $donation_id = $donation_id->ID; } - if( ! $donation->ID ) { + if( ! $donation_id ) { return ''; } @@ -1630,9 +1652,9 @@ function give_get_donation_form_title( $donation, $args = array() ) { $args = wp_parse_args( $args, $defaults ); - $form_id = $donation->form_id; - $price_id = $donation->price_id; - $form_title = $donation->form_title; + $form_id = give_get_payment_form_id( $donation_id ); + $price_id = give_get_meta( $donation_id, '_give_payment_price_id', true ); + $form_title = give_get_meta( $donation_id, '_give_payment_form_title', true ); $only_level = $args['only_level']; $separator = $args['separator']; $level_label = ''; @@ -1669,7 +1691,7 @@ function give_get_donation_form_title( $donation, $args = array() ) { } } elseif ( give_has_variable_prices( $form_id ) ) { - $level_label = give_get_price_option_name( $form_id, $price_id, $donation->ID, false ); + $level_label = give_get_price_option_name( $form_id, $price_id, $donation_id, false ); } // Only add separator if there is a form title. @@ -1689,7 +1711,7 @@ function give_get_donation_form_title( $donation, $args = array() ) { * * @since 1.0 */ - return apply_filters( 'give_get_donation_form_title', $form_title_html, $donation->payment_meta, $donation ); + return apply_filters( 'give_get_donation_form_title', $form_title_html, array(), $donation_id ); } /** From 3cc5581650246496f8fb8427e7417e1d262114f0 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 29 Mar 2018 21:27:02 +0530 Subject: [PATCH 10/48] feat(donations): add helper function to get donation total --- includes/payments/functions.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 5da4c62bc3..9d83367a94 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1871,3 +1871,20 @@ function give_get_payment_meta_price_id( $payment_meta ) { return apply_filters( 'give_get_payment_meta_price_id', $price_id, $payment_meta ); } + + +/** + * Get payment total amount + * + * @since 2.1.0 + * + * @param int $payment_id + * + * @return float + */ +function give_get_payment_total( $payment_id = 0 ) { + return round( + floatval( give_get_meta( $payment_id, '_give_payment_total', true ) ), + give_get_price_decimals( $payment_id ) + ); +} From 8648a7e4e3fd94a831fbff2b84112e0a1a9c4345 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 29 Mar 2018 21:27:23 +0530 Subject: [PATCH 11/48] fix(donations): use helper fn to get donation total --- includes/payments/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 9d83367a94..047d6197af 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1094,7 +1094,7 @@ function give_donation_amount( $donation_id, $format_args = array() ) { $donation_id = $donation_id->ID; } - $amount = $formatted_amount = give_get_meta( $donation_id, '_give_payment_total', true ); + $amount = $formatted_amount = give_get_payment_total( $donation_id ); $currency_code = give_get_payment_currency_code( $donation_id ); if ( is_bool( $format_args ) ) { From 5ac9736f91d4d6f641b4107cf9f6a2b0f4e9271d Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 3 Apr 2018 18:01:04 +0530 Subject: [PATCH 12/48] fix(donations): use direct sql query to get earnings --- includes/payments/class-payment-stats.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/payments/class-payment-stats.php b/includes/payments/class-payment-stats.php index 0931113637..ebeb0fb0dd 100644 --- a/includes/payments/class-payment-stats.php +++ b/includes/payments/class-payment-stats.php @@ -86,6 +86,7 @@ public function get_sales( $form_id = 0, $start_date = false, $end_date = false, * @return float|int Total amount of donations based on the passed arguments. */ public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { + global $wpdb; $this->setup_dates( $start_date, $end_date ); // Make sure start date is valid @@ -105,6 +106,7 @@ public function get_earnings( $form_id = 0, $start_date = false, $end_date = fal 'end_date' => $this->end_date, 'fields' => 'ids', 'number' => - 1, + 'output' => '', ); @@ -142,9 +144,13 @@ public function get_earnings( $form_id = 0, $start_date = false, $end_date = fal $earnings = 0; if ( ! empty( $payments ) ) { - foreach ( $payments as $payment ) { - $earnings += (float) give_donation_amount( $payment->ID, array( 'type' => 'stats' ) ); - } + $query = "SELECT SUM(meta_value) + FROM {$wpdb->paymentmeta} + WHERE meta_key='_give_payment_total' + AND payment_id IN ('". implode( '\',\'', $payments ) ."')"; + + // @todo check compatibility with currency switcher. + $earnings = $wpdb->get_var($query); } From e1b6f9fcef8a1d19c1429a99c38307d21aa540be Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 18:23:48 +0530 Subject: [PATCH 13/48] fix(donation): filter donation amount before calculate amount --- includes/payments/class-payment-stats.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/includes/payments/class-payment-stats.php b/includes/payments/class-payment-stats.php index ebeb0fb0dd..cc976f61fa 100644 --- a/includes/payments/class-payment-stats.php +++ b/includes/payments/class-payment-stats.php @@ -144,13 +144,30 @@ public function get_earnings( $form_id = 0, $start_date = false, $end_date = fal $earnings = 0; if ( ! empty( $payments ) ) { - $query = "SELECT SUM(meta_value) + $query = "SELECT payment_id as id, meta_value as total FROM {$wpdb->paymentmeta} WHERE meta_key='_give_payment_total' AND payment_id IN ('". implode( '\',\'', $payments ) ."')"; - // @todo check compatibility with currency switcher. - $earnings = $wpdb->get_var($query); + $payments = $wpdb->get_results($query, ARRAY_A); + + if( ! empty( $payments ) ) { + foreach ( $payments as $payment ) { + $earnings += (float) apply_filters( + /** + * Filter the donation amount + * Note: this filter documented in payments/functions.php:give_donation_amount() + * + * @since 2.1 + */ + 'give_donation_amount', + give_format_amount( $payment['total'], array( 'donation_id' => $payment['id'] ) ), + $payment['total'], + $payment['id'], + array( 'type' => 'stats' ) + ); + } + } } From 8cd94f73f90efe2366cacdb863956efb87c0e9e7 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 21:30:56 +0530 Subject: [PATCH 14/48] refactor(donation): get_earnings helper function --- includes/payments/class-payment-stats.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/payments/class-payment-stats.php b/includes/payments/class-payment-stats.php index cc976f61fa..dc431cd51c 100644 --- a/includes/payments/class-payment-stats.php +++ b/includes/payments/class-payment-stats.php @@ -153,19 +153,21 @@ public function get_earnings( $form_id = 0, $start_date = false, $end_date = fal if( ! empty( $payments ) ) { foreach ( $payments as $payment ) { - $earnings += (float) apply_filters( - /** - * Filter the donation amount - * Note: this filter documented in payments/functions.php:give_donation_amount() - * - * @since 2.1 - */ + /** + * Filter the donation amount + * Note: this filter documented in payments/functions.php:give_donation_amount() + * + * @since 2.1 + */ + $formatted_amount = apply_filters( 'give_donation_amount', give_format_amount( $payment['total'], array( 'donation_id' => $payment['id'] ) ), $payment['total'], $payment['id'], array( 'type' => 'stats' ) ); + + $earnings += (float) give_maybe_sanitize_amount( $formatted_amount ); } } From 77af4c79a58c604c758791650c14f4f98c2e0183 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 21:50:10 +0530 Subject: [PATCH 15/48] style(code):add filter doc --- includes/payments/functions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 047d6197af..dd877aa0df 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -714,6 +714,11 @@ function give_is_payment_complete( $payment_id ) { } } + /** + * Filter the flag + * + * @since 1.0 + */ return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment_status ); } From 18a3f0eb7f5a47d2583d7fa80f8c388bad27eec0 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 21:50:43 +0530 Subject: [PATCH 16/48] fix(donation): deprecated give_get_donation_form_title params --- includes/payments/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index dd877aa0df..7209f8c505 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1716,7 +1716,7 @@ function give_get_donation_form_title( $donation_id, $args = array() ) { * * @since 1.0 */ - return apply_filters( 'give_get_donation_form_title', $form_title_html, array(), $donation_id ); + return apply_filters( 'give_get_donation_form_title', $form_title_html, $donation_id ); } /** From 07081e4ef9a6cab61536096094bda51cb5471b83 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 22:12:45 +0530 Subject: [PATCH 17/48] fix(donation): get donor id from donation instead helper fn --- includes/payments/functions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 7209f8c505..5de2832c47 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -304,8 +304,7 @@ function give_delete_donation( $payment_id = 0, $update_donor = true ) { $amount = give_donation_amount( $payment_id ); $status = $payment->post_status; - $donor_id = give_get_payment_donor_id( $payment_id ); - $donor = new Give_Donor( $donor_id ); + $donor = new Give_Donor( $payment->donor_id); // Only undo donations that aren't these statuses. $dont_undo_statuses = apply_filters( 'give_undo_donation_statuses', array( From de1ad007d67d2fa56d71fd0ea5c463d15d42b27a Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 22:15:52 +0530 Subject: [PATCH 18/48] fix(donation): do not need to setup Give_Payment when update meta --- includes/payments/functions.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 5de2832c47..632ffde93e 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -853,9 +853,7 @@ function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta * @return mixed Meta ID if successful, false if unsuccessful. */ function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { - $payment = new Give_Payment( $payment_id ); - - return $payment->update_meta( $meta_key, $meta_value, $prev_value ); + return give_update_meta( $payment_id, $meta_key, $meta_value ); } /** From 324822f0e2b6e6ab2b7b5f5960b784dcb177188c Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 22:23:48 +0530 Subject: [PATCH 19/48] fix(donation): remove Give_Payment usage from give_get_donor_name_by fn --- includes/user-functions.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/includes/user-functions.php b/includes/user-functions.php index 584472639c..beba990daf 100644 --- a/includes/user-functions.php +++ b/includes/user-functions.php @@ -578,18 +578,15 @@ function give_get_donor_name_by( $id = 0, $from = 'donation' ) { switch ( $from ) { case 'donation': - $donation_info = new Give_Payment( $id ); - $first_name = $donation_info->get_meta( '_give_donor_billing_first_name', true ); - $last_name = $donation_info->get_meta( '_give_donor_billing_last_name', true ); + $first_name = give_get_meta( $id, '_give_donor_billing_first_name', true ); + $last_name = give_get_meta( $id, '_give_donor_billing_last_name', true ); $name = trim( "{$first_name} {$last_name}" ); break; case 'donor': - - $donor = new Give_Donor( $id ); - $name = $donor->name; + $name = Give()->donors->get_column( 'name', $id ); break; From c1c7e9192b1643d59bd299ed495b4a9cfa235b6e Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 22:38:11 +0530 Subject: [PATCH 20/48] fix(donation): add helper function to get donation address new fn give_get_donation_address --- includes/payments/functions.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 632ffde93e..a040323b5f 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1890,3 +1890,23 @@ function give_get_payment_total( $payment_id = 0 ) { give_get_price_decimals( $payment_id ) ); } + +/** + * Get donation address + * + * since 2.1.0 + * + * @param int $donation_id + * + * @return array + */ +function give_get_donation_address( $donation_id ){ + $address['line1'] = give_get_meta( $donation_id, '_give_donor_billing_address1', true, '' ); + $address['line2'] = give_get_meta( $donation_id, '_give_donor_billing_address2', true, '' ); + $address['city'] = give_get_meta( $donation_id, '_give_donor_billing_city', true, '' ); + $address['state'] = give_get_meta( $donation_id, '_give_donor_billing_state', true, '' ); + $address['zip'] = give_get_meta( $donation_id, '_give_donor_billing_zip', true, '' ); + $address['country'] = give_get_meta( $donation_id, '_give_donor_billing_country', true, '' ); + + return $address; +} From 2e135f92b9b87573e2a9ddc1f1351159a309ac5f Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 22:39:20 +0530 Subject: [PATCH 21/48] fix(donation): remove Give_Payment usage from _give_save_donor_billing_address fn --- includes/actions.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/includes/actions.php b/includes/actions.php index d8bad22ae0..b611c65a78 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -287,20 +287,19 @@ function give_set_donation_levels_max_min_amount( $form_id ) { * @param int $payment_id */ function _give_save_donor_billing_address( $payment_id ) { - /* @var Give_Payment $donation */ - $donation = new Give_Payment( $payment_id ); + $donor_id = absint( give_get_payment_donor_id( $payment_id )); // Bailout - if ( ! $donation->customer_id ) { + if ( ! $donor_id ) { return; } /* @var Give_Donor $donor */ - $donor = new Give_Donor( $donation->customer_id ); + $donor = new Give_Donor( $donor_id ); // Save address. - $donor->add_address( 'billing[]', $donation->address ); + $donor->add_address( 'billing[]', give_get_donation_address( $payment_id ) ); } add_action( 'give_complete_donation', '_give_save_donor_billing_address', 9999 ); From 1af099d373d9b65268a6466ee397b038fd156a70 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 5 Apr 2018 22:43:54 +0530 Subject: [PATCH 22/48] fix(donation): remove Give_Payment usage from give_email_donation_receipt fn --- includes/emails/functions.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/emails/functions.php b/includes/emails/functions.php index 6586ee2ab6..78f93b626b 100644 --- a/includes/emails/functions.php +++ b/includes/emails/functions.php @@ -27,8 +27,6 @@ * @return void */ function give_email_donation_receipt( $payment_id, $admin_notice = true ) { - $payment = new Give_Payment( $payment_id ); - /** * Fire the action */ @@ -46,7 +44,7 @@ function give_email_donation_receipt( $payment_id, $admin_notice = true ) { * @param int $payment_id Payment id. * @param mixed $payment_data Payment meta data. */ - do_action( 'give_new-donation_email_notification', $payment_id, $payment->payment_meta ); + do_action( 'give_new-donation_email_notification', $payment_id, give_get_payment_meta( $payment_id ) ); } } From 7b96575ff506109e81d4e672764bdf90f7fcb49a Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 09:18:13 +0530 Subject: [PATCH 23/48] feat(donation): add helper fn to check if donation completed or not --- includes/payments/functions.php | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index a040323b5f..4b1e01b726 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1910,3 +1910,44 @@ function give_get_donation_address( $donation_id ){ return $address; } + + +/** + * Check if donation completed or not + * + * @since 2.1.0 + * + * @param int $donation_id + * + * @return bool + */ +function give_is_donation_completed( $donation_id ){ + global $wpdb; + + /** + * Filter the flag + * + * @since 2.1.0 + * + * @param bool + * @param int $donation_id + */ + return apply_filters( 'give_is_donation_completed', (bool) $wpdb->get_var( + $wpdb->prepare( + " + SELECT meta_value + FROM {$wpdb->paymentmeta} + WHERE EXISTS ( + SELECT ID + FROM {$wpdb->posts} + WHERE post_status=%s + AND ID=%d + ) + AND {$wpdb->paymentmeta}.meta_key=%s + ", + 'publish', + $donation_id, + '_give_completed_date' + ) + ), $donation_id); +} From 631e89aab3d47a946c436f8c917990c887da1ee8 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 09:18:41 +0530 Subject: [PATCH 24/48] feat(donation): add helper fn to check if donation process by given gateway or not --- includes/payments/functions.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 4b1e01b726..11c61e1565 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1018,6 +1018,24 @@ function give_get_payment_gateway( $payment_id ) { return give_get_meta( $payment_id, '_give_payment_gateway', true ); } +/** + * Check if donation have specific gateway or not + * + * @since 2.1.0 + * + * @param int|Give_Payment $donation_id Donation ID + * @param string $gateway_id Gateway ID + * + * @return bool + */ +function give_has_payment_gateway( $donation_id, $gateway_id ) { + $donation_gateway = $donation_id instanceof Give_Payment ? + $donation_id->gateway : + give_get_payment_gateway( $donation_id ); + + return $gateway_id === $donation_gateway; +} + /** * Get the currency code a payment was made in * From f4dc85b71ce277f87fb12cbc6e4e3f1b7831866c Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 10:04:36 +0530 Subject: [PATCH 25/48] fix(donation): add helper function to get donor email new fn give_get_donation_donor_email --- includes/payments/functions.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 11c61e1565..4a755d8a4b 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -979,6 +979,19 @@ function give_get_payment_donor_id( $payment_id ) { return give_get_meta( $payment_id, '_give_payment_donor_id' , true ); } +/** + * Get the donor email associated with a donation. + * + * @param int $payment_id Payment ID. + * + * @since 2.1.0 + * + * @return string + */ +function give_get_donation_donor_email( $payment_id ) { + return give_get_meta( $payment_id, '_give_payment_donor_email' , true ); +} + /** * Get the IP address used to make a donation * From 1a8907697ea152286c525d193fdc72de66db95e6 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 10:17:01 +0530 Subject: [PATCH 26/48] fix(donation): refactor email tag code Stop using Give_Payment and Give_Donor to improve performance on frontend --- includes/emails/class-give-email-tags.php | 135 +++++++++------------- 1 file changed, 55 insertions(+), 80 deletions(-) diff --git a/includes/emails/class-give-email-tags.php b/includes/emails/class-give-email-tags.php index 606bdcc4d7..025b21d930 100644 --- a/includes/emails/class-give-email-tags.php +++ b/includes/emails/class-give-email-tags.php @@ -480,18 +480,17 @@ function give_email_tag_first_name( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); + $donor_info = give_get_payment_meta_user_info( $tag_args['payment_id'] ); + $email_names = give_get_email_names( $donor_info ); + $firstname = $email_names['name']; - // Get firstname. - if ( ! empty( $payment->user_info ) ) { - $email_names = give_get_email_names( $payment->user_info ); - $firstname = $email_names['name']; - } break; case give_check_variable( $tag_args, 'isset', 0, 'user_id' ): - $donor = new Give_Donor( $tag_args['user_id'], true ); - $firstname = $donor->get_first_name(); + $firstname = Give()->donor_meta->get_meta( + Give()->donors->get_column_by( 'id', 'user_id', $tag_args['user_id'] ), + '_give_donor_first_name' + ); break; /** @@ -500,8 +499,7 @@ function give_email_tag_first_name( $tag_args ) { * @since 2.0 */ case give_check_variable( $tag_args, 'isset', 0, 'donor_id' ): - $donor = new Give_Donor( $tag_args['donor_id'] ); - $firstname = $donor->get_first_name(); + $firstname = Give()->donor_meta->get_meta( $tag_args['donor_id'], '_give_donor_first_name' ); break; } @@ -535,18 +533,13 @@ function give_email_tag_fullname( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - - // Get fullname. - if ( ! empty( $payment->user_info ) ) { - $email_names = give_get_email_names( $payment->user_info ); - $fullname = $email_names['fullname']; - } + $donor_info = give_get_payment_meta_user_info( $tag_args['payment_id'] ); + $email_names = give_get_email_names( $donor_info ); + $fullname = $email_names['fullname']; break; case give_check_variable( $tag_args, 'isset', 0, 'user_id' ): - $donor = new Give_Donor( $tag_args['user_id'], true ); - $fullname = trim( "{$donor->get_first_name()} {$donor->get_last_name()}" ); + $fullname = Give()->donors->get_column_by( 'name', 'user_id', $tag_args['user_id'] ); break; /** @@ -555,8 +548,7 @@ function give_email_tag_fullname( $tag_args ) { * @since 2.0 */ case give_check_variable( $tag_args, 'isset', 0, 'donor_id' ): - $donor = new Give_Donor( $tag_args['donor_id'] ); - $fullname = $donor->name; + $fullname = Give()->donors->get_column( 'name', $tag_args['donor_id'] ); break; } @@ -590,13 +582,9 @@ function give_email_tag_username( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - - // Get username. - if ( ! empty( $payment->user_info ) ) { - $email_names = give_get_email_names( $payment->user_info ); - $username = $email_names['username']; - } + $donor_info = give_get_payment_meta_user_info( $tag_args['payment_id'] ); + $email_names = give_get_email_names( $donor_info ); + $username = $email_names['username']; break; case give_check_variable( $tag_args, 'isset', 0, 'user_id' ): @@ -610,9 +598,8 @@ function give_email_tag_username( $tag_args ) { * @since 2.0 */ case give_check_variable( $tag_args, 'isset', 0, 'donor_id' ): - $donor = new Give_Donor( $tag_args['donor_id'] ); - if ( ! empty( $donor->id ) && ! empty( $donor->user_id ) ) { - $user_info = get_user_by( 'id', $donor->user_id ); + if ( $user_id = Give()->donors->get_column( 'user_id', $tag_args['donor_id'] ) ) { + $user_info = get_user_by( 'id', $user_id ); $username = $user_info->user_login; } break; @@ -648,8 +635,7 @@ function give_email_tag_user_email( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $email = $payment->email; + $email = give_get_donation_donor_email( $tag_args['payment_id'] ); break; case give_check_variable( $tag_args, 'isset', 0, 'user_id' ): @@ -663,8 +649,7 @@ function give_email_tag_user_email( $tag_args ) { * @since 2.0 */ case give_check_variable( $tag_args, 'isset', 0, 'donor_id' ): - $donor = new Give_Donor( $tag_args['donor_id'] ); - $email = $donor->email; + $email = Give()->donors->get_column( 'email', $tag_args['donor_id'] ); break; } @@ -698,15 +683,15 @@ function give_email_tag_billing_address( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $donation = new Give_Payment( $tag_args['payment_id'] ); - $address = $donation->address['line1'] . "\n"; + $donation_address = give_get_donation_address( $tag_args['payment_id'] ); + $address = $donation_address['line1'] . "\n"; - if ( ! empty( $donation->address['line2'] ) ) { - $address .= $donation->address['line2'] . "\n"; + if ( ! empty( $donation_address['line2'] ) ) { + $address .= $donation_address['line2'] . "\n"; } - $address .= $donation->address['city'] . ' ' . $donation->address['zip'] . ' ' . $donation->address['state'] . "\n"; - $address .= $donation->address['country']; + $address .= $donation_address['city'] . ' ' . $donation_address['zip'] . ' ' . $donation_address['state'] . "\n"; + $address .= $donation_address['country']; break; } @@ -740,8 +725,7 @@ function give_email_tag_date( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $date = date_i18n( give_date_format(), strtotime( $payment->date ) ); + $date = date_i18n( give_date_format(), strtotime( get_the_date( $tag_args['payment_id'] ) ) ); break; } @@ -775,8 +759,7 @@ function give_email_tag_amount( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $give_amount = give_currency_filter( give_format_amount( $payment->total, array( 'sanitize' => false ) ), array( 'currency_code' => $payment->currency ) ); + $give_amount = give_donation_amount( $tag_args['payment_id'], array( 'sanitize' => false ) ); $amount = html_entity_decode( $give_amount, ENT_COMPAT, 'UTF-8' ); break; } @@ -824,8 +807,7 @@ function give_email_tag_payment_id( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $payment_id = $payment->number; + $payment_id = Give()->seq_donation_number->get_serial_code( $tag_args['payment_id'] ); break; } @@ -857,8 +839,7 @@ function give_email_tag_receipt_id( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $receipt_id = $payment->key; + $receipt_id = give_get_payment_key( $tag_args['payment_id'] ); break; } @@ -890,15 +871,18 @@ function give_email_tag_donation( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $level_title = give_has_variable_prices( $payment->form_id ); + $level_title = give_has_variable_prices( give_get_payment_form_id( $tag_args['payment_id'] ) ); $separator = $level_title ? '-' : ''; - $donation_form_title = strip_tags( give_check_variable( give_get_donation_form_title( - $payment, - array( - 'separator' => $separator, + $donation_form_title = strip_tags( + give_check_variable( + give_get_donation_form_title( + $tag_args['payment_id'], + array( 'separator' => $separator, ) + ), + 'empty', + '' ) - ), 'empty', '' ) ); + ); break; } @@ -934,9 +918,7 @@ function give_email_tag_form_title( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $payment_meta = $payment->payment_meta; - $donation_form_title = strip_tags( give_check_variable( $payment_meta, 'empty', '', 'form_title' ) ); + $donation_form_title = give_get_donation_form_title( $tag_args['payment_id'] ); break; } @@ -983,7 +965,7 @@ function give_email_tag_company_name( $tag_args ) { * @since 2.0.7 * * @param string $company_name - * @param array $tag_args + * @param array $tag_args */ return apply_filters( 'give_email_tag_company_name', @@ -1012,8 +994,7 @@ function give_email_tag_payment_method( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $payment_method = give_get_gateway_checkout_label( $payment->gateway ); + $payment_method = give_get_gateway_checkout_label( give_get_payment_gateway( $tag_args['payment_id'] ) ); break; } @@ -1052,8 +1033,7 @@ function give_email_tag_payment_total( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $payment_total = give_currency_filter( $payment->total ); + $payment_total = give_donation_amount( $tag_args['payment_id'] ); break; } @@ -1127,7 +1107,7 @@ function give_email_tag_receipt_link( $tag_args ) { 'payment_key' => give_get_payment_key( $tag_args['payment_id'] ), ), give_get_history_page_uri() ) ); - $formatted = sprintf( + $formatted = sprintf( '%2$s', $receipt_url, __( 'View it in your browser »', 'give' ) @@ -1343,8 +1323,7 @@ function give_email_tag_reset_password_link( $tag_args, $payment_id ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment = new Give_Payment( $tag_args['payment_id'] ); - $payment_id = $payment->number; + $payment_id = Give()->seq_donation_number->get_serial_code( $tag_args['payment_id'] ); break; case give_check_variable( $tag_args, 'isset', 0, 'user_id' ): @@ -1352,20 +1331,18 @@ function give_email_tag_reset_password_link( $tag_args, $payment_id ) { break; case give_check_variable( $tag_args, 'isset', 0, 'donor_id' ): - /* @var Give_Donor $donor */ - $donor = new Give_Donor( $tag_args['user_id'], true ); - $reset_password_url = give_get_reset_password_url( $donor->user_id ); + $reset_password_url = give_get_reset_password_url( Give()->donors->get_column( 'user_id', $tag_args['donor_id'] ) ); break; } - if( empty( $tag_args['email_content_type'] ) || 'text/html' === $tag_args['email_content_type'] ) { + if ( empty( $tag_args['email_content_type'] ) || 'text/html' === $tag_args['email_content_type'] ) { // Generate link, if Email content type is html. $reset_password_link = sprintf( '%2$s', esc_url( $reset_password_url ), __( 'Reset your password »', 'give' ) ); - } else{ + } else { $reset_password_link = sprintf( '%1$s: %2$s', __( 'Reset your password', 'give' ), @@ -1410,8 +1387,8 @@ function give_get_reset_password_url( $user_id ) { // Prepare Reset Password URL. $reset_password_url = esc_url( add_query_arg( array( 'action' => 'rp', - 'key' => get_password_reset_key( $user ), - 'login' => $user->user_login, + 'key' => get_password_reset_key( $user ), + 'login' => $user->user_login, ), wp_login_url() ) ); } @@ -1424,7 +1401,7 @@ function give_get_reset_password_url( $user_id ) { * Note: meta data email tag must be in given format {meta_*} * * @since 2.0.3 - * @see https://github.com/WordImpress/Give/issues/2801#issuecomment-365136602 + * @see https://github.com/WordImpress/Give/issues/2801#issuecomment-365136602 * * @param $content * @param $tag_args @@ -1494,16 +1471,14 @@ function __give_render_metadata_email_tag( $content, $tag_args ) { if ( isset( $tag_args['payment_id'] ) ) { $donor_id = give_get_payment_donor_id( $tag_args['payment_id'] ); } elseif ( isset( $tag_args['user_id'] ) ) { - $donor = new Give_Donor( $tag_args['user_id'], true ); - $donor_id = $donor->ID; + $donor_id = Give()->donors->get_column_by( 'id', 'user_id', $tag_args['user_id'] ); } } - $donor = new Give_Donor( $donor_id ); - $meta_data = $donor->get_meta( $meta_name ); + $meta_data = Give()->donor_meta->get_meta( $donor_id, $meta_name ); if ( ! isset( $meta_tag_arr[1] ) || ! is_array( $meta_data ) ) { $replace[] = $meta_data; - } elseif ( in_array( $meta_tag_arr[1], array_keys( $meta_data ) ) ) { + } elseif ( in_array( $meta_tag_arr[1], array_keys( $meta_data ) ) ) { $replace[] = $meta_data[ $meta_tag_arr[1] ]; } From 916a9cd45c842ea63c4eedeaf8215181c9a8bba8 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 11:06:39 +0530 Subject: [PATCH 27/48] fix(donation): refactor email tag code Stop using Give_Payment and Give_Donor to improve performance on frontend --- includes/emails/class-give-email-tags.php | 13 +++++++------ includes/payments/functions.php | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/emails/class-give-email-tags.php b/includes/emails/class-give-email-tags.php index 025b21d930..efbd935a54 100644 --- a/includes/emails/class-give-email-tags.php +++ b/includes/emails/class-give-email-tags.php @@ -489,7 +489,8 @@ function give_email_tag_first_name( $tag_args ) { case give_check_variable( $tag_args, 'isset', 0, 'user_id' ): $firstname = Give()->donor_meta->get_meta( Give()->donors->get_column_by( 'id', 'user_id', $tag_args['user_id'] ), - '_give_donor_first_name' + '_give_donor_first_name', + true ); break; @@ -499,7 +500,7 @@ function give_email_tag_first_name( $tag_args ) { * @since 2.0 */ case give_check_variable( $tag_args, 'isset', 0, 'donor_id' ): - $firstname = Give()->donor_meta->get_meta( $tag_args['donor_id'], '_give_donor_first_name' ); + $firstname = Give()->donor_meta->get_meta( $tag_args['donor_id'], '_give_donor_first_name', true ); break; } @@ -759,7 +760,7 @@ function give_email_tag_amount( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $give_amount = give_donation_amount( $tag_args['payment_id'], array( 'sanitize' => false ) ); + $give_amount = give_donation_amount( $tag_args['payment_id'], true ); $amount = html_entity_decode( $give_amount, ENT_COMPAT, 'UTF-8' ); break; } @@ -918,7 +919,7 @@ function give_email_tag_form_title( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $donation_form_title = give_get_donation_form_title( $tag_args['payment_id'] ); + $donation_form_title = give_get_payment_meta( $tag_args['payment_id'], '_give_payment_form_title' ); break; } @@ -1033,7 +1034,7 @@ function give_email_tag_payment_total( $tag_args ) { switch ( true ) { case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): - $payment_total = give_donation_amount( $tag_args['payment_id'] ); + $payment_total = give_currency_filter( give_get_payment_total( $tag_args['payment_id'] ) ); break; } @@ -1475,7 +1476,7 @@ function __give_render_metadata_email_tag( $content, $tag_args ) { } } - $meta_data = Give()->donor_meta->get_meta( $donor_id, $meta_name ); + $meta_data = Give()->donor_meta->get_meta( $donor_id, $meta_name, true ); if ( ! isset( $meta_tag_arr[1] ) || ! is_array( $meta_data ) ) { $replace[] = $meta_data; } elseif ( in_array( $meta_tag_arr[1], array_keys( $meta_data ) ) ) { diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 4a755d8a4b..ef8a17e663 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -888,6 +888,10 @@ function give_get_payment_meta_user_info( $payment_id ) { $donor_info['first_name'] = Give()->donors->get_column_by( 'email', 'id', $donor_id ); } + $donor_info['address'] = give_get_donation_address( $payment_id ); + $donor_info['id'] = give_get_payment_user_id( $payment_id ); + $donor_info['donor_id'] = give_get_payment_donor_id( $payment_id ); + return $donor_info; } From ee061a6e4ce0b40b555530ec3daa17b840f033ae Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 14:01:27 +0530 Subject: [PATCH 28/48] refactor(donation): remove payment meta query from receipt --- templates/shortcode-receipt.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/shortcode-receipt.php b/templates/shortcode-receipt.php index 86af5be45d..5bc7cdc5ad 100644 --- a/templates/shortcode-receipt.php +++ b/templates/shortcode-receipt.php @@ -20,7 +20,6 @@ $donation_id = $payment->ID; $donation_number = Give()->seq_donation_number->get_serial_code( $payment->ID ); $form_id = give_get_payment_meta( $donation_id, '_give_payment_form_id', true ); -$meta = give_get_payment_meta( $donation_id ); $donation = give_get_donation_form_title( $donation_id ); $user = give_get_payment_meta_user_info( $donation_id ); $email = give_get_payment_user_email( $donation_id ); @@ -59,7 +58,7 @@ $give_receipt_args['donation_receipt']['date'] = array( 'name' => __( 'Date', 'give' ), - 'value' => date_i18n( give_date_format(), strtotime( $meta['date'] ) ), + 'value' => date_i18n( give_date_format(), strtotime( give_get_payment_completed_date( $donation_id ) ) ), 'display' => $give_receipt_args['date'], ); From c221b50cc737a6c50018c02e75fb2918f1218c59 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 14:02:42 +0530 Subject: [PATCH 29/48] refactor(donation): remove fourth param from filter --- templates/shortcode-receipt.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/shortcode-receipt.php b/templates/shortcode-receipt.php index 5bc7cdc5ad..4436da86c6 100644 --- a/templates/shortcode-receipt.php +++ b/templates/shortcode-receipt.php @@ -209,9 +209,9 @@ * @param string $notice HTML markup for the default notice. * @param int $id Post ID where the notice is displayed. * @param string $status Payment status. - * @param array $meta Array of meta data related to the payment. + * @param int $donation_id Donation ID. */ - echo apply_filters( 'give_receipt_status_notice', Give()->notices->print_frontend_notice( $notice_message, false, $notice_type ), $id, $status, $meta ); + echo apply_filters( 'give_receipt_status_notice', Give()->notices->print_frontend_notice( $notice_message, false, $notice_type ), $id, $status, $donation_id ); } }// End if(). From 74059e197530dc47dcb375a8619377cc7951c7c2 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 14:07:07 +0530 Subject: [PATCH 30/48] fix(admin-settings): check if `fields` exist in array or not --- includes/admin/forms/class-metabox-form-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/forms/class-metabox-form-data.php b/includes/admin/forms/class-metabox-form-data.php index 36168bcf52..6b7f070364 100644 --- a/includes/admin/forms/class-metabox-form-data.php +++ b/includes/admin/forms/class-metabox-form-data.php @@ -1000,7 +1000,7 @@ private function get_field_id( $field ) { private function get_fields_id( $setting ) { $meta_keys = array(); - if ( ! empty( $setting ) ) { + if ( ! empty( $setting ) && array_key_exists( 'fields', $setting ) ) { foreach ( $setting['fields'] as $field ) { if ( $field_id = $this->get_field_id( $field ) ) { $meta_keys[] = $field_id; From 78323690b3c15255bd7e0125da5bdd72b3ed5e8b Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 14:11:34 +0530 Subject: [PATCH 31/48] refactor(donation): remove Give_Payment usage from give_check_for_existing_payment fn --- includes/payments/functions.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index ef8a17e663..047c146d59 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -452,14 +452,20 @@ function give_count_payments( $args = array() ) { * @return bool $exists True if payment exists, false otherwise. */ function give_check_for_existing_payment( $payment_id ) { - $exists = false; - $payment = new Give_Payment( $payment_id ); - - if ( $payment_id === $payment->ID && 'publish' === $payment->status ) { - $exists = true; - } + global $wpdb; - return $exists; + return (bool) $wpdb->get_var( + $wpdb->prepare( + " + SELECT ID + FROM {$wpdb->posts} + WHERE ID=%s + AND post_status=%s + ", + $payment_id, + 'publish' + ) + ); } /** From 7aa364fbeecdeda124ef8c70ed1b921e9427a735 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 15:03:22 +0530 Subject: [PATCH 32/48] fix(donation): remove $this from fn to prevent fatal error --- includes/payments/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 047c146d59..efa044c4ae 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1251,8 +1251,8 @@ function give_get_payment_transaction_id( $payment_id = 0 ) { $transaction_id = give_get_meta( $payment_id, '_give_payment_transaction_id', true ); if ( empty( $transaction_id ) ) { - $gateway = $this->gateway; - $transaction_id = apply_filters( "give_get_payment_transaction_id-{$gateway}", $this->ID ); + $gateway = give_get_payment_gateway( $payment_id ); + $transaction_id = apply_filters( "give_get_payment_transaction_id-{$gateway}", $payment_id ); } return $transaction_id; From 2090686a55cb87cbef39a8aedf9d03688feab6b9 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 15:24:03 +0530 Subject: [PATCH 33/48] fix(admin-settings): check if `fields` exist in array or not pass2 --- includes/admin/forms/class-metabox-form-data.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/admin/forms/class-metabox-form-data.php b/includes/admin/forms/class-metabox-form-data.php index 6b7f070364..c3f2c4d916 100644 --- a/includes/admin/forms/class-metabox-form-data.php +++ b/includes/admin/forms/class-metabox-form-data.php @@ -1000,7 +1000,11 @@ private function get_field_id( $field ) { private function get_fields_id( $setting ) { $meta_keys = array(); - if ( ! empty( $setting ) && array_key_exists( 'fields', $setting ) ) { + if ( + ! empty( $setting ) + && array_key_exists( 'fields', $setting ) + && ! empty( $setting['fields'] ) + ) { foreach ( $setting['fields'] as $field ) { if ( $field_id = $this->get_field_id( $field ) ) { $meta_keys[] = $field_id; From 91ba617d86007fa96c121f93f249b9681392b5de Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 6 Apr 2018 19:48:16 +0530 Subject: [PATCH 34/48] fix(donation): get donor email if donation email empty --- includes/payments/functions.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index efa044c4ae..c8b0f66114 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -926,7 +926,13 @@ function give_get_payment_form_id( $payment_id ) { * @return string $email User email. */ function give_get_payment_user_email( $payment_id ) { - return give_get_meta( $payment_id, '_give_payment_donor_email', true ); + $email = give_get_meta( $payment_id, '_give_payment_donor_email', true ); + + if ( empty( $email ) && ( $donor_id = give_get_payment_donor_id( $payment_id ) ) ) { + $email = Give()->donors->get_column( 'email', $donor_id ); + } + + return $email; } /** From d794398d0caac00f444531379090df84af6e2e75 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Wed, 11 Apr 2018 10:53:45 +0530 Subject: [PATCH 35/48] fix(donation): pass default deprecated param to prevent fatal error --- includes/payments/functions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index c8b0f66114..c1f247e09f 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1759,8 +1759,9 @@ function give_get_donation_form_title( $donation_id, $args = array() ) { * Filter form title with level html * * @since 1.0 + * @todo: remove third param after 2.1.0 */ - return apply_filters( 'give_get_donation_form_title', $form_title_html, $donation_id ); + return apply_filters( 'give_get_donation_form_title', $form_title_html, $donation_id, '' ); } /** From 9da8f3441734454f645ac7cb86bc207c3296e19a Mon Sep 17 00:00:00 2001 From: Govind Kumar Date: Fri, 13 Apr 2018 11:43:03 +0530 Subject: [PATCH 36/48] fix(translation): used html entities for currency symbol for admin labels. --- includes/currency-functions.php | 154 ++++++++++++++++---------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/includes/currency-functions.php b/includes/currency-functions.php index feefcb9eee..8f0d1642c8 100644 --- a/includes/currency-functions.php +++ b/includes/currency-functions.php @@ -67,7 +67,7 @@ function give_get_currency_position() { function give_get_currencies_list() { $currencies = array( 'USD' => array( - 'admin_label' => __( 'US Dollars ($)', 'give' ), + 'admin_label' => sprintf( __('US Dollars (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -77,7 +77,7 @@ function give_get_currencies_list() { ), ), 'EUR' => array( - 'admin_label' => __( 'Euros (€)', 'give' ), + 'admin_label' => sprintf( __('Euros (%1$s)', 'give'), '€'), 'symbol' => '€', 'setting' => array( 'currency_position' => 'before', @@ -87,7 +87,7 @@ function give_get_currencies_list() { ), ), 'GBP' => array( - 'admin_label' => __( 'Pounds Sterling (£)', 'give' ), + 'admin_label' => sprintf( __('Pounds Sterling (%1$s)', 'give'), '£'), 'symbol' => '£', 'setting' => array( 'currency_position' => 'before', @@ -97,7 +97,7 @@ function give_get_currencies_list() { ), ), 'AUD' => array( - 'admin_label' => __( 'Australian Dollars ($)', 'give' ), + 'admin_label' => sprintf( __('Australian Dollars (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -107,7 +107,7 @@ function give_get_currencies_list() { ), ), 'BRL' => array( - 'admin_label' => __( 'Brazilian Real (R$)', 'give' ), + 'admin_label' => sprintf( __('Brazilian Real (%1$s)', 'give'), 'R$'), 'symbol' => 'R$', 'setting' => array( 'currency_position' => 'before', @@ -117,7 +117,7 @@ function give_get_currencies_list() { ), ), 'CAD' => array( - 'admin_label' => __( 'Canadian Dollars ($)', 'give' ), + 'admin_label' => sprintf( __('Canadian Dollars (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -127,7 +127,7 @@ function give_get_currencies_list() { ), ), 'CZK' => array( - 'admin_label' => __( 'Czech Koruna (Kč)', 'give' ), + 'admin_label' => sprintf( __('Czech Koruna (%1$s)', 'give'), 'Kč'), 'symbol' => 'Kč', 'setting' => array( 'currency_position' => 'after', @@ -137,7 +137,7 @@ function give_get_currencies_list() { ), ), 'DKK' => array( - 'admin_label' => __( 'Danish Krone (kr.)', 'give' ), + 'admin_label' => sprintf( __('Danish Krone (%1$s)', 'give'), ' kr. '), 'symbol' => ' kr. ', 'setting' => array( 'currency_position' => 'before', @@ -147,7 +147,7 @@ function give_get_currencies_list() { ), ), 'HKD' => array( - 'admin_label' => __( 'Hong Kong Dollar ($)', 'give' ), + 'admin_label' => sprintf( __('Hong Kong Dollar (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -157,7 +157,7 @@ function give_get_currencies_list() { ), ), 'HUF' => array( - 'admin_label' => __( 'Hungarian Forint (Ft)', 'give' ), + 'admin_label' => sprintf( __('Hungarian Forint (%1$s)', 'give'), 'Ft'), 'symbol' => 'Ft', 'setting' => array( 'currency_position' => 'after', @@ -167,7 +167,7 @@ function give_get_currencies_list() { ), ), 'ILS' => array( - 'admin_label' => __( 'Israeli Shekel (₪)', 'give' ), + 'admin_label' => sprintf( __('Israeli Shekel (%1$s)', 'give'), '₪'), 'symbol' => '₪', 'setting' => array( 'currency_position' => 'after', @@ -177,7 +177,7 @@ function give_get_currencies_list() { ), ), 'JPY' => array( - 'admin_label' => __( 'Japanese Yen (¥)', 'give' ), + 'admin_label' => sprintf( __('Japanese Yen (%1$s)', 'give'), '¥'), 'symbol' => '¥', 'setting' => array( 'currency_position' => 'before', @@ -187,7 +187,7 @@ function give_get_currencies_list() { ), ), 'MYR' => array( - 'admin_label' => __( 'Malaysian Ringgits (RM)', 'give' ), + 'admin_label' => sprintf( __('Malaysian Ringgits (%1$s)', 'give'), 'RM'), 'symbol' => 'RM', 'setting' => array( 'currency_position' => 'before', @@ -197,7 +197,7 @@ function give_get_currencies_list() { ), ), 'MXN' => array( - 'admin_label' => __( 'Mexican Peso ($)', 'give' ), + 'admin_label' => sprintf( __('Mexican Peso (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -207,7 +207,7 @@ function give_get_currencies_list() { ), ), 'MAD' => array( - 'admin_label' => __( 'Moroccan Dirham (.د.م)', 'give' ), + 'admin_label' => sprintf( __('Moroccan Dirham (%1$s)', 'give'), '.د.م'), 'symbol' => '.د.م', 'setting' => array( 'currency_position' => 'before', @@ -217,7 +217,7 @@ function give_get_currencies_list() { ), ), 'NZD' => array( - 'admin_label' => __( 'New Zealand Dollar ($)', 'give' ), + 'admin_label' => sprintf( __('New Zealand Dollar (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -227,7 +227,7 @@ function give_get_currencies_list() { ), ), 'NOK' => array( - 'admin_label' => __( 'Norwegian Krone (Kr.)', 'give' ), + 'admin_label' => sprintf( __('Norwegian Krone (%1$s)', 'give'), 'kr.'), 'symbol' => 'kr.', 'setting' => array( 'currency_position' => 'before', @@ -237,7 +237,7 @@ function give_get_currencies_list() { ), ), 'PHP' => array( - 'admin_label' => __( 'Philippine Pesos (₱)', 'give' ), + 'admin_label' => sprintf( __('Philippine Pesos (%1$s)', 'give'), '₱'), 'symbol' => '₱', 'setting' => array( 'currency_position' => 'before', @@ -247,7 +247,7 @@ function give_get_currencies_list() { ), ), 'PLN' => array( - 'admin_label' => __( 'Polish Zloty (zł)', 'give' ), + 'admin_label' => sprintf( __('Polish Zloty (%1$s)', 'give'), 'zł'), 'symbol' => 'zł', 'setting' => array( 'currency_position' => 'after', @@ -257,7 +257,7 @@ function give_get_currencies_list() { ), ), 'SGD' => array( - 'admin_label' => __( 'Singapore Dollar ($)', 'give' ), + 'admin_label' => sprintf( __('Singapore Dollar (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -267,7 +267,7 @@ function give_get_currencies_list() { ), ), 'KRW' => array( - 'admin_label' => __( 'South Korean Won (₩)', 'give' ), + 'admin_label' => sprintf( __('South Korean Won (%1$s)', 'give'), '₩'), 'symbol' => '₩', 'setting' => array( 'currency_position' => 'before', @@ -277,7 +277,7 @@ function give_get_currencies_list() { ), ), 'ZAR' => array( - 'admin_label' => __( 'South African Rand (R)', 'give' ), + 'admin_label' => sprintf( __('South African Rand (%1$s)', 'give'), 'R'), 'symbol' => 'R', 'setting' => array( 'currency_position' => 'before', @@ -287,7 +287,7 @@ function give_get_currencies_list() { ), ), 'SEK' => array( - 'admin_label' => __( 'Swedish Krona (kr)', 'give' ), + 'admin_label' => sprintf( __('Swedish Krona (%1$s)', 'give'), ' kr. '), 'symbol' => ' kr. ', 'setting' => array( 'currency_position' => 'before', @@ -297,7 +297,7 @@ function give_get_currencies_list() { ), ), 'CHF' => array( - 'admin_label' => __( 'Swiss Franc (Fr)', 'give' ), + 'admin_label' => sprintf( __('Swiss Franc (%1$s)', 'give'), 'Fr'), 'symbol' => 'Fr', 'setting' => array( 'currency_position' => 'before', @@ -307,7 +307,7 @@ function give_get_currencies_list() { ), ), 'TWD' => array( - 'admin_label' => __( 'Taiwan New Dollars (NT$)', 'give' ), + 'admin_label' => sprintf( __('Taiwan New Dollars (%1$s)', 'give'), 'NT$'), 'symbol' => 'NT$', 'setting' => array( 'currency_position' => 'before', @@ -317,7 +317,7 @@ function give_get_currencies_list() { ), ), 'THB' => array( - 'admin_label' => __( 'Thai Baht (฿)', 'give' ), + 'admin_label' => sprintf( __('Thai Baht (%1$s)', 'give'), '฿'), 'symbol' => '฿', 'setting' => array( 'currency_position' => 'before', @@ -327,7 +327,7 @@ function give_get_currencies_list() { ), ), 'INR' => array( - 'admin_label' => __( 'Indian Rupee (₹)', 'give' ), + 'admin_label' => sprintf( __('Indian Rupee (%1$s)', 'give'), '₹'), 'symbol' => '₹', 'setting' => array( 'currency_position' => 'before', @@ -337,7 +337,7 @@ function give_get_currencies_list() { ), ), 'TRY' => array( - 'admin_label' => __( 'Turkish Lira (₺)', 'give' ), + 'admin_label' => sprintf( __('Turkish Lira (%1$s)', 'give'), '₺'), 'symbol' => '₺', 'setting' => array( 'currency_position' => 'after', @@ -347,7 +347,7 @@ function give_get_currencies_list() { ), ), 'IRR' => array( - 'admin_label' => __( 'Iranian Rial (﷼)', 'give' ), + 'admin_label' => sprintf( __('Iranian Rial (%1$s)', 'give'), '﷼'), 'symbol' => '﷼', 'setting' => array( 'currency_position' => 'after', @@ -357,7 +357,7 @@ function give_get_currencies_list() { ), ), 'RUB' => array( - 'admin_label' => __( 'Russian Rubles (руб)', 'give' ), + 'admin_label' => sprintf( __('Russian Rubles (%1$s)', 'give'), '₽'), 'symbol' => '₽', 'setting' => array( 'currency_position' => 'before', @@ -367,7 +367,7 @@ function give_get_currencies_list() { ), ), 'AED' => array( - 'admin_label' => __( 'United Arab Emirates dirham (د.إ)', 'give' ), + 'admin_label' => sprintf( __('United Arab Emirates dirham (%1$s)', 'give'), 'د.إ'), 'symbol' => 'د.إ', 'setting' => array( 'currency_position' => 'before', @@ -377,7 +377,7 @@ function give_get_currencies_list() { ), ), 'AMD' => array( - 'admin_label' => __( 'Armenian dram (AMD)', 'give' ), + 'admin_label' => sprintf( __('Armenian dram (%1$s)', 'give'), 'AMD'), 'symbol' => 'AMD', // Add backward compatibility. Using AMD in place of ֏ 'setting' => array( 'currency_position' => 'before', @@ -387,7 +387,7 @@ function give_get_currencies_list() { ), ), 'ANG' => array( - 'admin_label' => __( 'Netherlands Antillean guilder (ƒ)', 'give' ), + 'admin_label' => sprintf( __('Netherlands Antillean guilder (%1$s)', 'give'), 'ƒ'), 'symbol' => 'ƒ', 'setting' => array( 'currency_position' => 'before', @@ -397,7 +397,7 @@ function give_get_currencies_list() { ), ), 'ARS' => array( - 'admin_label' => __( 'Argentine peso ($)', 'give' ), + 'admin_label' => sprintf( __('Argentine peso (%1$s)', 'give'), '$'), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -407,7 +407,7 @@ function give_get_currencies_list() { ), ), 'AWG' => array( - 'admin_label' => __( 'Aruban florin (ƒ)', 'give' ), + 'admin_label' => sprintf( __( 'Aruban florin (%1$s)', 'give' ), 'ƒ' ), 'symbol' => 'ƒ', 'setting' => array( 'currency_position' => 'before', @@ -417,7 +417,7 @@ function give_get_currencies_list() { ), ), 'BAM' => array( - 'admin_label' => __( 'Bosnia and Herzegovina convertible mark (KM)', 'give' ), + 'admin_label' => sprintf( __( 'Bosnia and Herzegovina convertible mark (%1$s)', 'give' ), 'KM' ), 'symbol' => 'KM', 'setting' => array( 'currency_position' => 'before', @@ -427,7 +427,7 @@ function give_get_currencies_list() { ), ), 'BDT' => array( - 'admin_label' => __( 'Bangladeshi taka (৳)', 'give' ), + 'admin_label' => sprintf( __( 'Bangladeshi taka (%1$s)', 'give' ), '৳' ), 'symbol' => '৳', 'setting' => array( 'currency_position' => 'before', @@ -437,7 +437,7 @@ function give_get_currencies_list() { ), ), 'BHD' => array( - 'admin_label' => __( 'Bahraini dinar (.د.ب)', 'give' ), + 'admin_label' => sprintf( __( 'Bahraini dinar (%1$s)', 'give' ), '.د.ب' ), 'symbol' => '.د.ب', 'setting' => array( 'currency_position' => 'before', @@ -447,7 +447,7 @@ function give_get_currencies_list() { ), ), 'BMD' => array( - 'admin_label' => __( 'Bermudian dollar (BD$)', 'give' ), + 'admin_label' => sprintf( __( 'Bermudian dollar (%1$s)', 'give' ), 'BD$' ), 'symbol' => 'BD$', 'setting' => array( 'currency_position' => 'before', @@ -457,7 +457,7 @@ function give_get_currencies_list() { ), ), 'BND' => array( - 'admin_label' => __( 'Brunei dollar (B$)', 'give' ), + 'admin_label' => sprintf( __( 'Brunei dollar (%1$s)', 'give' ), 'B$' ), 'symbol' => 'B$', 'setting' => array( 'currency_position' => 'before', @@ -467,7 +467,7 @@ function give_get_currencies_list() { ), ), 'BOB' => array( - 'admin_label' => __( 'Bolivian boliviano (Bs.)', 'give' ), + 'admin_label' => sprintf( __( 'Bolivian boliviano (%1$s)', 'give' ), 'Bs.' ), 'symbol' => 'Bs.', 'setting' => array( 'currency_position' => 'before', @@ -477,7 +477,7 @@ function give_get_currencies_list() { ), ), 'BSD' => array( - 'admin_label' => __( 'Bahamian dollar (B$)', 'give' ), + 'admin_label' => sprintf( __( 'Bahamian dollar (%1$s)', 'give' ), 'B$' ), 'symbol' => 'B$', 'setting' => array( 'currency_position' => 'before', @@ -487,7 +487,7 @@ function give_get_currencies_list() { ), ), 'BWP' => array( - 'admin_label' => __( 'Botswana pula (P)', 'give' ), + 'admin_label' => sprintf( __( 'Botswana pula (%1$s)', 'give' ), 'P' ), 'symbol' => 'P', 'setting' => array( 'currency_position' => 'before', @@ -497,7 +497,7 @@ function give_get_currencies_list() { ), ), 'BZD' => array( - 'admin_label' => __( 'Belizean dollar (BZ$)', 'give' ), + 'admin_label' => sprintf( __( 'Belizean dollar (%1$s)', 'give' ), 'BZ$' ), 'symbol' => 'BZ$', 'setting' => array( 'currency_position' => 'before', @@ -507,7 +507,7 @@ function give_get_currencies_list() { ), ), 'CLP' => array( - 'admin_label' => __( 'Chilean peso ($)', 'give' ), + 'admin_label' => sprintf( __( 'Chilean peso (%1$s)', 'give' ), '$' ), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -517,7 +517,7 @@ function give_get_currencies_list() { ), ), 'CNY' => array( - 'admin_label' => __( 'Chinese yuan (¥)', 'give' ), + 'admin_label' => sprintf( __( 'Chinese yuan (%1$s)', 'give' ), '¥' ), 'symbol' => '¥', 'setting' => array( 'currency_position' => 'before', @@ -527,7 +527,7 @@ function give_get_currencies_list() { ), ), 'COP' => array( - 'admin_label' => __( 'Colombian peso ($)', 'give' ), + 'admin_label' => sprintf( __( 'Colombian peso (%1$s)', 'give' ), '$' ), 'symbol' => '$', 'setting' => array( 'currency_position' => 'before', @@ -537,7 +537,7 @@ function give_get_currencies_list() { ), ), 'CRC' => array( - 'admin_label' => __( 'Costa Rican colón (₡)', 'give' ), + 'admin_label' => sprintf( __( 'Costa Rican colón (%1$s)', 'give' ), '₡' ), 'symbol' => '₡', 'setting' => array( 'currency_position' => 'before', @@ -547,7 +547,7 @@ function give_get_currencies_list() { ), ), 'CUC' => array( - 'admin_label' => __( 'Cuban convertible peso (₱)', 'give' ), + 'admin_label' => sprintf( __( 'Cuban convertible peso (%1$s)', 'give' ), '₱' ), 'symbol' => '₱', 'setting' => array( 'currency_position' => 'before', @@ -557,7 +557,7 @@ function give_get_currencies_list() { ), ), 'CUP' => array( - 'admin_label' => __( 'Cuban convertible peso (₱)', 'give' ), + 'admin_label' => sprintf( __( 'Cuban convertible peso (%1$s)', 'give' ), '₱' ), 'symbol' => '₱', 'setting' => array( 'currency_position' => 'before', @@ -567,7 +567,7 @@ function give_get_currencies_list() { ), ), 'DOP' => array( - 'admin_label' => __( 'Dominican peso (RD$)', 'give' ), + 'admin_label' => sprintf( __( 'Dominican peso (%1$s)', 'give' ), 'RD$' ), 'symbol' => 'RD$', 'setting' => array( 'currency_position' => 'before', @@ -577,7 +577,7 @@ function give_get_currencies_list() { ), ), 'EGP' => array( - 'admin_label' => __( 'Egyptian pound (E£)', 'give' ), + 'admin_label' => sprintf( __( 'Egyptian pound (%1$s)', 'give' ), 'E£' ), 'symbol' => 'E£', 'setting' => array( 'currency_position' => 'before', @@ -587,7 +587,7 @@ function give_get_currencies_list() { ), ), 'GIP' => array( - 'admin_label' => __( 'Gibraltar pound (£)', 'give' ), + 'admin_label' => sprintf( __( 'Gibraltar pound (%1$s)', 'give' ), '£' ), 'symbol' => '£', 'setting' => array( 'currency_position' => 'before', @@ -597,7 +597,7 @@ function give_get_currencies_list() { ), ), 'GTQ' => array( - 'admin_label' => __( 'Guatemalan quetzal (Q)', 'give' ), + 'admin_label' => sprintf( __( 'Guatemalan quetzal (%1$s)', 'give' ), 'Q' ), 'symbol' => 'Q', 'setting' => array( 'currency_position' => 'before', @@ -607,7 +607,7 @@ function give_get_currencies_list() { ), ), 'HNL' => array( - 'admin_label' => __( 'Honduran lempira (L)', 'give' ), + 'admin_label' => sprintf( __( 'Honduran lempira (%1$s)', 'give' ), 'L' ), 'symbol' => 'L', 'setting' => array( 'currency_position' => 'before', @@ -617,7 +617,7 @@ function give_get_currencies_list() { ), ), 'HRK' => array( - 'admin_label' => __( 'Croatian kuna (kn)', 'give' ), + 'admin_label' => sprintf( __( 'Croatian kuna (%1$s)', 'give' ), 'kn' ), 'symbol' => 'kn', 'setting' => array( 'currency_position' => 'after', @@ -627,7 +627,7 @@ function give_get_currencies_list() { ), ), 'IDR' => array( - 'admin_label' => __( 'Indonesian rupiah (Rp)', 'give' ), + 'admin_label' => sprintf( __( 'Indonesian rupiah (%1$s)', 'give' ), 'Rp' ), 'symbol' => 'Rp', 'setting' => array( 'currency_position' => 'before', @@ -637,7 +637,7 @@ function give_get_currencies_list() { ), ), 'ISK' => array( - 'admin_label' => __( 'Icelandic króna (kr)', 'give' ), + 'admin_label' => sprintf( __( 'Icelandic króna (%1$s)', 'give' ), 'kr' ), 'symbol' => 'kr', 'setting' => array( 'currency_position' => 'after', @@ -647,7 +647,7 @@ function give_get_currencies_list() { ), ), 'JMD' => array( - 'admin_label' => __( 'Jamaican dollar (J$)', 'give' ), + 'admin_label' => sprintf( __( 'Jamaican dollar (%1$s)', 'give' ), 'j$' ), 'symbol' => 'j$', 'setting' => array( 'currency_position' => 'before', @@ -657,7 +657,7 @@ function give_get_currencies_list() { ), ), 'JOD' => array( - 'admin_label' => __( 'Jordanian dinar (د.ا)', 'give' ), + 'admin_label' => sprintf( __( 'Jordanian dinar (%1$s)', 'give' ), 'د.ا' ), 'symbol' => 'د.ا', 'setting' => array( 'currency_position' => 'before', @@ -667,7 +667,7 @@ function give_get_currencies_list() { ), ), 'KES' => array( - 'admin_label' => __( 'Kenyan shilling (KSh)', 'give' ), + 'admin_label' => sprintf( __( 'Kenyan shilling (%1$s)', 'give' ), 'KSh' ), 'symbol' => 'KSh', 'setting' => array( 'currency_position' => 'before', @@ -677,7 +677,7 @@ function give_get_currencies_list() { ), ), 'KWD' => array( - 'admin_label' => __( 'Kuwaiti dinar (د.ك)', 'give' ), + 'admin_label' => sprintf( __( 'Kuwaiti dinar (%1$s)', 'give' ), 'د.ك' ), 'symbol' => 'د.ك', 'setting' => array( 'currency_position' => 'before', @@ -687,7 +687,7 @@ function give_get_currencies_list() { ), ), 'KYD' => array( - 'admin_label' => __( 'Cayman Islands dollar (KY$)', 'give' ), + 'admin_label' => sprintf( __( 'Cayman Islands dollar (%1$s)', 'give' ), 'KY$' ), 'symbol' => 'KY$', 'setting' => array( 'currency_position' => 'before', @@ -697,7 +697,7 @@ function give_get_currencies_list() { ), ), 'MKD' => array( - 'admin_label' => __( 'Macedonian denar (ден)', 'give' ), + 'admin_label' => sprintf( __( 'Macedonian denar (%1$s)', 'give' ), 'ден' ), 'symbol' => 'ден', 'setting' => array( 'currency_position' => 'before', @@ -707,7 +707,7 @@ function give_get_currencies_list() { ), ), 'NPR' => array( - 'admin_label' => __( 'Nepalese rupee (NɌs)', 'give' ), + 'admin_label' => sprintf( __( 'Nepalese rupee (%1$s)', 'give' ), '₨' ), 'symbol' => '₨', 'setting' => array( 'currency_position' => 'before', @@ -717,7 +717,7 @@ function give_get_currencies_list() { ), ), 'OMR' => array( - 'admin_label' => __( 'Omani rial (ر.ع.)', 'give' ), + 'admin_label' => sprintf( __( 'Omani rial (%1$s)', 'give' ), 'ر.ع.' ), 'symbol' => 'ر.ع.', 'setting' => array( 'currency_position' => 'before', @@ -727,7 +727,7 @@ function give_get_currencies_list() { ), ), 'PEN' => array( - 'admin_label' => __( 'Peruvian nuevo sol (S/.)', 'give' ), + 'admin_label' => sprintf( __( 'Peruvian nuevo sol (%1$s)', 'give' ), 'S/.' ), 'symbol' => 'S/.', 'setting' => array( 'currency_position' => 'before', @@ -737,7 +737,7 @@ function give_get_currencies_list() { ), ), 'PKR' => array( - 'admin_label' => __( 'Pakistani rupee (Ɍs)', 'give' ), + 'admin_label' => sprintf( __( 'Pakistani rupee (%1$s)', 'give' ), '₨' ), 'symbol' => '₨', 'setting' => array( 'currency_position' => 'before', @@ -747,7 +747,7 @@ function give_get_currencies_list() { ), ), 'RON' => array( - 'admin_label' => __( 'Romanian leu (L)', 'give' ), + 'admin_label' => sprintf( __( 'Romanian leu (%1$s)', 'give' ), 'L' ), 'symbol' => 'L', 'setting' => array( 'currency_position' => 'after', @@ -757,7 +757,7 @@ function give_get_currencies_list() { ), ), 'SAR' => array( - 'admin_label' => __( 'Saudi riyal (ر.س)', 'give' ), + 'admin_label' => sprintf( __( 'Saudi riyal (%1$s)', 'give' ), 'ر.س' ), 'symbol' => 'ر.س', 'setting' => array( 'currency_position' => 'before', @@ -767,7 +767,7 @@ function give_get_currencies_list() { ), ), 'SZL' => array( - 'admin_label' => __( 'Swazi lilangeni (L)', 'give' ), + 'admin_label' => sprintf( __( 'Swazi lilangeni (%1$s)', 'give' ), 'L'), 'symbol' => 'L', 'setting' => array( 'currency_position' => 'before', @@ -777,7 +777,7 @@ function give_get_currencies_list() { ), ), 'TOP' => array( - 'admin_label' => __( 'Tongan paʻanga (T$)', 'give' ), + 'admin_label' => sprintf( __( 'Tongan paʻanga (%1$s)', 'give' ), 'T$'), 'symbol' => 'T$', 'setting' => array( 'currency_position' => 'before', @@ -787,7 +787,7 @@ function give_get_currencies_list() { ), ), 'TZS' => array( - 'admin_label' => __( 'Tanzanian shilling (TSh)', 'give' ), + 'admin_label' => sprintf( __( 'Tanzanian shilling (%1$s)', 'give' ), 'TSh'), 'symbol' => 'TSh', 'setting' => array( 'currency_position' => 'before', @@ -797,7 +797,7 @@ function give_get_currencies_list() { ), ), 'UAH' => array( - 'admin_label' => __( 'Ukrainian hryvnia (₴)', 'give' ), + 'admin_label' => sprintf( __( 'Ukrainian hryvnia (%1$s)', 'give' ), '₴'), 'symbol' => '₴', 'setting' => array( 'currency_position' => 'before', @@ -807,7 +807,7 @@ function give_get_currencies_list() { ), ), 'UYU' => array( - 'admin_label' => __( 'Uruguayan peso ($U)', 'give' ), + 'admin_label' => sprintf( __( 'Uruguayan peso (%1$s)', 'give' ), '$U'), 'symbol' => '$U', 'setting' => array( 'currency_position' => 'before', @@ -817,7 +817,7 @@ function give_get_currencies_list() { ), ), 'VEF' => array( - 'admin_label' => __( 'Venezuelan bolívar (Bs)', 'give' ), + 'admin_label' => sprintf( __( 'Venezuelan bolívar (%1$s)', 'give' ), 'Bs'), 'symbol' => 'Bs', 'setting' => array( 'currency_position' => 'before', @@ -827,7 +827,7 @@ function give_get_currencies_list() { ), ), 'XCD' => array( - 'admin_label' => __( 'East Caribbean dollar (EC$)', 'give' ), + 'admin_label' => sprintf( __( 'East Caribbean dollar (%1$s)', 'give' ), 'EC$'), 'symbol' => 'EC$', 'setting' => array( 'currency_position' => 'before', From 221bbf0de80a62b5390e73335642b4e61f1b25fe Mon Sep 17 00:00:00 2001 From: Govind Kumar Date: Fri, 13 Apr 2018 14:45:08 +0530 Subject: [PATCH 37/48] fix(donation-form): do not output formatted min max value . --- assets/src/js/frontend/give-donations.js | 3 ++- includes/forms/template.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/src/js/frontend/give-donations.js b/assets/src/js/frontend/give-donations.js index 660b381c6f..8c1372cf9a 100644 --- a/assets/src/js/frontend/give-donations.js +++ b/assets/src/js/frontend/give-donations.js @@ -870,7 +870,8 @@ Give.notice = { return null; } - var notice = notice_msg = formatted_amount = ''; + var notice, notice_msg, formatted_amount; + notice = notice_msg = formatted_amount = ''; if ( $form.length ) { switch ( error_code ) { diff --git a/includes/forms/template.php b/includes/forms/template.php index 958d02afea..6c2757f457 100644 --- a/includes/forms/template.php +++ b/includes/forms/template.php @@ -1946,11 +1946,11 @@ function __give_form_add_donation_hidden_field( $form_id, $args, $form ) { - + + value="" /> + value="" /> Date: Fri, 13 Apr 2018 17:10:11 +0530 Subject: [PATCH 38/48] fix(phpunit): remove extra space from input tag --- includes/forms/template.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/forms/template.php b/includes/forms/template.php index 6c2757f457..89df7ed87e 100644 --- a/includes/forms/template.php +++ b/includes/forms/template.php @@ -1946,11 +1946,11 @@ function __give_form_add_donation_hidden_field( $form_id, $args, $form ) { - + + value=""/> + value=""/> Date: Fri, 13 Apr 2018 18:10:15 +0530 Subject: [PATCH 39/48] fix(translation): improved error message for better translation. --- includes/class-give-translation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-give-translation.php b/includes/class-give-translation.php index 493a8e9ab0..85ce404f35 100644 --- a/includes/class-give-translation.php +++ b/includes/class-give-translation.php @@ -141,7 +141,7 @@ public static function add_text( $args = array() ) { array_key_exists( $args['id'], self::$text_configs ) ) { /* @var WP_Error $error */ - $error = new WP_Error( 'TEXT_ID_ALREADY_EXIST', __( 'Text ID without group already exist.', 'give' ), $args ); + $error = new WP_Error( 'TEXT_ID_ALREADY_EXIST', __( 'Text ID without a group already exists.', 'give' ), $args ); throw new Exception( $error->get_error_message( 'TEXT_ID_ALREADY_EXIST' ) ); } elseif ( @@ -150,7 +150,7 @@ public static function add_text( $args = array() ) { array_key_exists( $args['id'], self::$text_configs[ $args['group'] ] ) ) { /* @var WP_Error $error */ - $error = new WP_Error( 'TEXT_ID_WITHIN_GROUP_ALREADY_EXIST', __( 'Text ID with in group already exist.', 'give' ), $args ); + $error = new WP_Error( 'TEXT_ID_WITHIN_GROUP_ALREADY_EXIST', __( 'Text ID within a group already exists.', 'give' ), $args ); throw new Exception( $error->get_error_message( 'TEXT_ID_WITHIN_GROUP_ALREADY_EXIST' ) ); } From 28b36ddd3cba97f602ae682ce865e36bba58f20b Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 13 Apr 2018 21:14:12 +0530 Subject: [PATCH 40/48] fix(admin-update): make string more translatable --- includes/admin/upgrades/views/upgrades.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/admin/upgrades/views/upgrades.php b/includes/admin/upgrades/views/upgrades.php index 4c84087425..de33da5a0c 100644 --- a/includes/admin/upgrades/views/upgrades.php +++ b/includes/admin/upgrades/views/upgrades.php @@ -140,7 +140,20 @@

-

Update now', 'give' ), _n( 'is', 'are', $plugin_updates, 'give' ), $plugin_updates, _n( 'add-on', 'add-ons', $plugin_updates, 'give' ), _n( 'needs', 'need', $plugin_updates, 'give' ), $plugin_update_url ); ?>

+

+ Update now', + 'There are %1$d Give addons that need to be updated. Update now', + $plugin_updates, + 'give' + ), + $plugin_updates, + $plugin_update_url + ); + ?> +

From a7a67342022798199ca7510bedf5aed52a6d395a Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 13 Apr 2018 21:55:08 +0530 Subject: [PATCH 41/48] styles(code): update fn description --- includes/payments/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index c1f247e09f..253ce8356e 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -1676,7 +1676,7 @@ function give_filter_where_older_than_week( $where = '' ) { * * Retrieves the form title and appends the level name if present. * - * @param int|Give_Payment $donation_id Donation Data Object. + * @param int $donation_id Donation Data Object. * @param array $args a. only_level = If set to true will only return the level name if multi-level enabled. * b. separator = The separator between the Form Title and the Donation Level. * @@ -1685,7 +1685,7 @@ function give_filter_where_older_than_week( $where = '' ) { * @return string $form_title Returns the full title if $only_level is false, otherwise returns the levels title. */ function give_get_donation_form_title( $donation_id, $args = array() ) { - + // Backward compatibility. if ( ! is_numeric( $donation_id ) && $donation_id instanceof Give_Payment ) { $donation_id = $donation_id->ID; } From 0ef56ec766bda391b5979c19212b852dae5f509f Mon Sep 17 00:00:00 2001 From: raftaar1191 Date: Mon, 16 Apr 2018 06:30:40 +0530 Subject: [PATCH 42/48] fix(admin-tool): make import page as default #3015 --- includes/admin/admin-pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/admin-pages.php b/includes/admin/admin-pages.php index 248ada6d19..270ba85a7c 100644 --- a/includes/admin/admin-pages.php +++ b/includes/admin/admin-pages.php @@ -326,7 +326,7 @@ function give_tools_page_pages( $settings ) { * @return string */ function give_set_default_tab_form_tools_page( $default_tab ) { - return 'system-info'; + return 'export'; } add_filter( 'give_default_setting_tab_give-tools', 'give_set_default_tab_form_tools_page', 10, 1 ); From 24bfff31d68729f39c087876045b404d93d47ff6 Mon Sep 17 00:00:00 2001 From: raftaar1191 Date: Mon, 16 Apr 2018 06:31:48 +0530 Subject: [PATCH 43/48] fix(admin-tool): change tab order #3015 --- includes/admin/admin-pages.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/admin/admin-pages.php b/includes/admin/admin-pages.php index 270ba85a7c..05702a436d 100644 --- a/includes/admin/admin-pages.php +++ b/includes/admin/admin-pages.php @@ -293,9 +293,14 @@ function give_reports_page_pages( $settings ) { function give_tools_page_pages( $settings ) { include( 'abstract-admin-settings-page.php' ); + $settings = array( - // System Info. - include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-system-info.php' ), + + // Export. + include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-export.php' ), + + // Import + include_once( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-import.php' ), // Logs. include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-logs.php' ), @@ -306,11 +311,8 @@ function give_tools_page_pages( $settings ) { // Data. include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-data.php' ), - // Export. - include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-export.php' ), - - // Import - include_once( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-import.php' ), + // System Info. + include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-system-info.php' ), ); // Output. From 86b60e5b958d34617edccb1c3f85205deb73fa1b Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Mon, 16 Apr 2018 08:36:58 +0530 Subject: [PATCH 44/48] fix(admin-tool): remove php notice from system info page fix #2998 --- includes/admin/tools/views/html-admin-page-system-info.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/tools/views/html-admin-page-system-info.php b/includes/admin/tools/views/html-admin-page-system-info.php index ac9c574d4b..ce9e7da508 100644 --- a/includes/admin/tools/views/html-admin-page-system-info.php +++ b/includes/admin/tools/views/html-admin-page-system-info.php @@ -196,7 +196,7 @@ rating); + esc_html_e( property_exists( $tls_check, 'rating' ) ? $tls_check->rating : $tls_check->tls_version ); } ?> From 3a7bf9c60661963e521a61e9ac802e6c5500d234 Mon Sep 17 00:00:00 2001 From: mehul0810 Date: Mon, 16 Apr 2018 09:16:20 +0530 Subject: [PATCH 45/48] fix(admin-form): update field title for custom amount range --- includes/admin/forms/class-metabox-form-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/forms/class-metabox-form-data.php b/includes/admin/forms/class-metabox-form-data.php index c3f2c4d916..ef0c96ce04 100644 --- a/includes/admin/forms/class-metabox-form-data.php +++ b/includes/admin/forms/class-metabox-form-data.php @@ -151,7 +151,7 @@ function get_settings() { ), ), array( - 'name' => __( 'Max/Min. Amount', 'give' ), + 'name' => __( 'Min/Max. Amount', 'give' ), 'description' => __( 'Set minimum and maximum amount limit.', 'give' ), 'id' => $prefix . 'custom_amount_range', 'type' => 'range_slider', From 3920d24fe4f1084db5f7a7a6e94f6b89f52b06a3 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Mon, 16 Apr 2018 17:16:57 +0530 Subject: [PATCH 46/48] fix(modal): Fix modal content when display option=button --- assets/src/css/frontend/forms.scss | 4 ++-- assets/src/css/frontend/modal.scss | 17 +++++++++++++++++ includes/forms/template.php | 15 +++++++++++++++ includes/shortcodes.php | 1 + 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/assets/src/css/frontend/forms.scss b/assets/src/css/frontend/forms.scss index 4bea245dd6..c1475e10ad 100644 --- a/assets/src/css/frontend/forms.scss +++ b/assets/src/css/frontend/forms.scss @@ -383,11 +383,11 @@ form[id*='give-form'] { } .give-display-button-only > *:not(form) { - display: none !important; + display: none; } .give-display-button-only form > *:not(.give-btn-modal) { - display: none !important; + display: none; } /*--------------------------------- diff --git a/assets/src/css/frontend/modal.scss b/assets/src/css/frontend/modal.scss index 0927f16e15..86377d5d54 100644 --- a/assets/src/css/frontend/modal.scss +++ b/assets/src/css/frontend/modal.scss @@ -167,4 +167,21 @@ .mfp-close:hover { background-color: rgba(0, 0, 0, 0); +} + +/** + * Display Style Button + */ +.mfp-content { + .give-display-button-only .give-form-title { + display: none; + } + + .give-display-button-only > *:not(form) { + display: block; + } + + .give-display-button-only form > *:not(.give-btn-modal) { + display: block; + } } \ No newline at end of file diff --git a/includes/forms/template.php b/includes/forms/template.php index 89df7ed87e..f3f7701ca1 100644 --- a/includes/forms/template.php +++ b/includes/forms/template.php @@ -2040,3 +2040,18 @@ function add_give_goal_progress_bar_class( $class_bar ) { return $class_bar; } + +/** + * Add a class to the form wrap on the grid page. + * + * @param array $class Array of form wrapper classes. + * @param int $id ID of the form. + * @param array $args Additional args. + * + * @return array + */ +function add_class_for_form_grid( $class, $id, $args ) { + $class[] = 'give-form-grid-wrap'; + + return $class; +} diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 87ec39fb34..34bbf749b9 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -838,6 +838,7 @@ function give_form_grid_shortcode( $atts ) { add_filter( 'add_give_goal_progress_class', 'add_give_goal_progress_class', 10, 1 ); add_filter( 'add_give_goal_progress_bar_class', 'add_give_goal_progress_bar_class', 10, 1 ); + add_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10, 3 ); echo '
'; echo '
'; From 225116e0f42587951207ebe8a4000987264abaf4 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Mon, 16 Apr 2018 17:59:03 +0530 Subject: [PATCH 47/48] fix(modal): modal popup through URL parameters --- assets/src/js/frontend/give-donations.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/assets/src/js/frontend/give-donations.js b/assets/src/js/frontend/give-donations.js index 8c1372cf9a..ac853a28d1 100644 --- a/assets/src/js/frontend/give-donations.js +++ b/assets/src/js/frontend/give-donations.js @@ -752,6 +752,26 @@ Give.form = { this.autoSetMultiLevel( level_field ); } + let give_form_wrap = jQuery( '.give-form-wrap' ), + is_form_grid = give_form_wrap.hasClass( 'give-form-grid-wrap' ); + + if ( is_form_grid && 1 === jQuery( '#give-modal-form-' + form_id ).length ) { + jQuery.magnificPopup.open( { + items: { + type: 'inline', + src: '#give-modal-form-' + form_id, + }, + fixedContentPos: true, + fixedBgPos: true, + closeBtnInside: true, + midClick: true, + removalDelay: 300, + mainClass: 'modal-fade-slide', + }); + + return; + } + // This form is modal display so show the modal. if ( display_modal || display_button ) { give_open_form_modal( $form_wrapper, $form ); From 5311f01b583432d103c4ae2d9aaf3136b07b35c6 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Mon, 16 Apr 2018 21:01:40 +0530 Subject: [PATCH 48/48] fix(shortcode): Add proper redirection on failure --- includes/forms/template.php | 52 +++++++++++++++++++++++++++++++++++ includes/process-donation.php | 3 +- includes/shortcodes.php | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/includes/forms/template.php b/includes/forms/template.php index f3f7701ca1..f453e144c4 100644 --- a/includes/forms/template.php +++ b/includes/forms/template.php @@ -2048,6 +2048,8 @@ function add_give_goal_progress_bar_class( $class_bar ) { * @param int $id ID of the form. * @param array $args Additional args. * + * @since 2.1 + * * @return array */ function add_class_for_form_grid( $class, $id, $args ) { @@ -2055,3 +2057,53 @@ function add_class_for_form_grid( $class, $id, $args ) { return $class; } + +/** + * Add hidden field to Form Grid page + * + * @param int $form_id The form ID. + * @param array $args An array of form arguments. + * @param Give_Donate_Form $form Form object. + * + * @since 2.1 + */ +function give_is_form_grid_page_hidden_field( $id, $args, $form ) { + echo ''; +} + +/** + * Redirect to the same paginated URL on the Form Grid page + * and adds query parameters to open the popup again after + * redirection. + * + * @param string $redirect URL for redirection. + * @param array $args Array of additional args. + * + * @since 2.1 + * @return string + */ +function give_redirect_and_popup_form( $redirect, $args ) { + + // Check the page has Form Grid. + $is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : ''; + + if ( 'true' === $is_form_grid ) { + + $payment_mode = give_clean( $_POST['payment-mode'] ); + $form_id = $args['form-id']; + + // Get the URL without Query parameters. + $redirect = strtok( $redirect, '?' ); + + // Add query parameters 'form-id' and 'payment-mode'. + $redirect = add_query_arg( array( + 'form-id' => $form_id, + 'payment-mode' => $payment_mode, + ), $redirect ); + } + + // Return the modified URL. + return $redirect; +} + +add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 ); \ No newline at end of file diff --git a/includes/process-donation.php b/includes/process-donation.php index 15641958ff..6130354553 100644 --- a/includes/process-donation.php +++ b/includes/process-donation.php @@ -25,6 +25,7 @@ * @return mixed */ function give_process_donation_form() { + $is_ajax = isset( $_POST['give_ajax'] ); // Verify donation form nonce. @@ -1325,4 +1326,4 @@ function give_donation_form_validate_name_fields() { if ( $is_first_name || $is_last_name ) { give_set_error( 'invalid_name', esc_html__( ' cannot contain email address.', 'give' ) ); } -} \ No newline at end of file +} diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 34bbf749b9..a8958aa15a 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -839,6 +839,7 @@ function give_form_grid_shortcode( $atts ) { add_filter( 'add_give_goal_progress_class', 'add_give_goal_progress_class', 10, 1 ); add_filter( 'add_give_goal_progress_bar_class', 'add_give_goal_progress_bar_class', 10, 1 ); add_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10, 3 ); + add_action( 'give_donation_form_top', 'give_is_form_grid_page_hidden_field', 10, 3 ); echo '
'; echo '
';