@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | ) |
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - $categories_enabled = give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ); |
|
| 51 | - $tags_enabled = give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ); |
|
| 50 | + $categories_enabled = give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ); |
|
| 51 | + $tags_enabled = give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ); |
|
| 52 | 52 | |
| 53 | 53 | $pdf = new give_pdf(); |
| 54 | 54 | $pdf->AddPage( 'L', 'A4' ); |
@@ -80,15 +80,15 @@ discard block |
||
| 80 | 80 | $pdf->Cell( 70, 6, utf8_decode( __( 'Form Name', 'give' ) ), 1, 0, 'L', true ); |
| 81 | 81 | $pdf->Cell( 30, 6, utf8_decode( __( 'Price', 'give' ) ), 1, 0, 'L', true ); |
| 82 | 82 | |
| 83 | - // Display Categories Heading only, if user has opted for it. |
|
| 84 | - if ( $categories_enabled ) { |
|
| 83 | + // Display Categories Heading only, if user has opted for it. |
|
| 84 | + if ( $categories_enabled ) { |
|
| 85 | 85 | $pdf->Cell( 45, 6, utf8_decode( __( 'Categories', 'give' ) ), 1, 0, 'L', true ); |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // Display Tags Heading only, if user has opted for it. |
|
| 89 | - if ( $tags_enabled ) { |
|
| 88 | + // Display Tags Heading only, if user has opted for it. |
|
| 89 | + if ( $tags_enabled ) { |
|
| 90 | 90 | $pdf->Cell( 45, 6, utf8_decode( __( 'Tags', 'give' ) ), 1, 0, 'L', true ); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | $pdf->Cell( 45, 6, utf8_decode( __( 'Number of Donations', 'give' ) ), 1, 0, 'L', true ); |
| 94 | 94 | $pdf->Cell( 45, 6, utf8_decode( __( 'Income to Date', 'give' ) ), 1, 1, 'L', true ); |
@@ -125,17 +125,17 @@ discard block |
||
| 125 | 125 | $price = give_currency_filter( give_get_form_price( $form->ID ), '', true ); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - // Display Categories Data only, if user has opted for it. |
|
| 129 | - if ( $categories_enabled ) { |
|
| 130 | - $categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' ); |
|
| 131 | - $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : ''; |
|
| 132 | - } |
|
| 128 | + // Display Categories Data only, if user has opted for it. |
|
| 129 | + if ( $categories_enabled ) { |
|
| 130 | + $categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' ); |
|
| 131 | + $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : ''; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - // Display Tags Data only, if user has opted for it. |
|
| 135 | - if ( $tags_enabled ) { |
|
| 136 | - $tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' ); |
|
| 137 | - $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : ''; |
|
| 138 | - } |
|
| 134 | + // Display Tags Data only, if user has opted for it. |
|
| 135 | + if ( $tags_enabled ) { |
|
| 136 | + $tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' ); |
|
| 137 | + $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : ''; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | $sales = give_get_form_sales_stats( $form->ID ); |
| 141 | 141 | $link = get_permalink( $form->ID ); |
@@ -147,38 +147,38 @@ discard block |
||
| 147 | 147 | $earnings = iconv( 'UTF-8', 'windows-1252', utf8_encode( $earnings ) ); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - // This will help filter data before appending it to PDF Receipt. |
|
| 151 | - $prepare_pdf_data = array(); |
|
| 152 | - $prepare_pdf_data[] = $title; |
|
| 153 | - $prepare_pdf_data[] = $price; |
|
| 150 | + // This will help filter data before appending it to PDF Receipt. |
|
| 151 | + $prepare_pdf_data = array(); |
|
| 152 | + $prepare_pdf_data[] = $title; |
|
| 153 | + $prepare_pdf_data[] = $price; |
|
| 154 | 154 | |
| 155 | - // Append Categories Data only, if user has opted for it. |
|
| 156 | - if ( $categories_enabled ) { |
|
| 157 | - $prepare_pdf_data[] = $categories; |
|
| 158 | - } |
|
| 155 | + // Append Categories Data only, if user has opted for it. |
|
| 156 | + if ( $categories_enabled ) { |
|
| 157 | + $prepare_pdf_data[] = $categories; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - // Append Tags Data only, if user has opted for it. |
|
| 161 | - if ( $tags_enabled ) { |
|
| 162 | - $prepare_pdf_data[] = $tags; |
|
| 163 | - } |
|
| 160 | + // Append Tags Data only, if user has opted for it. |
|
| 161 | + if ( $tags_enabled ) { |
|
| 162 | + $prepare_pdf_data[] = $tags; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - $prepare_pdf_data[] = $sales; |
|
| 166 | - $prepare_pdf_data[] = $earnings; |
|
| 165 | + $prepare_pdf_data[] = $sales; |
|
| 166 | + $prepare_pdf_data[] = $earnings; |
|
| 167 | 167 | |
| 168 | 168 | $pdf->Row( $prepare_pdf_data ); |
| 169 | 169 | endforeach; |
| 170 | 170 | } else { |
| 171 | 171 | |
| 172 | - // Fix: Minor Styling Alignment Issue for PDF |
|
| 173 | - if( $categories_enabled && $tags_enabled ) { |
|
| 174 | - $pdf->SetWidths( array( 280 ) ); |
|
| 175 | - } elseif( $categories_enabled || $tags_enabled ) { |
|
| 176 | - $pdf->SetWidths( array( 235 ) ); |
|
| 177 | - } else { |
|
| 178 | - $pdf->SetWidths( array( 190 ) ); |
|
| 179 | - } |
|
| 172 | + // Fix: Minor Styling Alignment Issue for PDF |
|
| 173 | + if( $categories_enabled && $tags_enabled ) { |
|
| 174 | + $pdf->SetWidths( array( 280 ) ); |
|
| 175 | + } elseif( $categories_enabled || $tags_enabled ) { |
|
| 176 | + $pdf->SetWidths( array( 235 ) ); |
|
| 177 | + } else { |
|
| 178 | + $pdf->SetWidths( array( 190 ) ); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - $title = utf8_decode( __( 'No forms found.', 'give' ) ); |
|
| 181 | + $title = utf8_decode( __( 'No forms found.', 'give' ) ); |
|
| 182 | 182 | $pdf->Row( array( $title ) ); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly.. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -25,94 +25,94 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @uses give_pdf |
| 27 | 27 | */ |
| 28 | -function give_generate_pdf( $data ) { |
|
| 28 | +function give_generate_pdf($data) { |
|
| 29 | 29 | |
| 30 | - if ( ! current_user_can( 'view_give_reports' ) ) { |
|
| 31 | - wp_die( __( 'You do not have permission to generate PDF sales reports.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 30 | + if ( ! current_user_can('view_give_reports')) { |
|
| 31 | + wp_die(__('You do not have permission to generate PDF sales reports.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'give_generate_pdf' ) ) { |
|
| 35 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 34 | + if ( ! wp_verify_nonce($_GET['_wpnonce'], 'give_generate_pdf')) { |
|
| 35 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - require_once GIVE_PLUGIN_DIR . '/includes/libraries/fpdf/fpdf.php'; |
|
| 39 | - require_once GIVE_PLUGIN_DIR . '/includes/libraries/fpdf/give_pdf.php'; |
|
| 38 | + require_once GIVE_PLUGIN_DIR.'/includes/libraries/fpdf/fpdf.php'; |
|
| 39 | + require_once GIVE_PLUGIN_DIR.'/includes/libraries/fpdf/give_pdf.php'; |
|
| 40 | 40 | |
| 41 | 41 | $daterange = utf8_decode( |
| 42 | 42 | sprintf( |
| 43 | 43 | /* translators: 1: start date 2: end date */ |
| 44 | - __( '%1$s to %2$s', 'give' ), |
|
| 45 | - date_i18n( give_date_format(), mktime( 0, 0, 0, 1, 1, date( 'Y' ) ) ), |
|
| 46 | - date_i18n( give_date_format() ) |
|
| 44 | + __('%1$s to %2$s', 'give'), |
|
| 45 | + date_i18n(give_date_format(), mktime(0, 0, 0, 1, 1, date('Y'))), |
|
| 46 | + date_i18n(give_date_format()) |
|
| 47 | 47 | ) |
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - $categories_enabled = give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ); |
|
| 51 | - $tags_enabled = give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ); |
|
| 50 | + $categories_enabled = give_is_setting_enabled(give_get_option('categories', 'disabled')); |
|
| 51 | + $tags_enabled = give_is_setting_enabled(give_get_option('tags', 'disabled')); |
|
| 52 | 52 | |
| 53 | 53 | $pdf = new give_pdf(); |
| 54 | - $pdf->AddPage( 'L', 'A4' ); |
|
| 54 | + $pdf->AddPage('L', 'A4'); |
|
| 55 | 55 | |
| 56 | - $pdf->SetTitle( utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ) ); |
|
| 57 | - $pdf->SetAuthor( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) ); |
|
| 58 | - $pdf->SetCreator( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) ); |
|
| 56 | + $pdf->SetTitle(utf8_decode(__('Donation report for the current year for all forms', 'give'))); |
|
| 57 | + $pdf->SetAuthor(utf8_decode(__('Give - Democratizing Generosity', 'give'))); |
|
| 58 | + $pdf->SetCreator(utf8_decode(__('Give - Democratizing Generosity', 'give'))); |
|
| 59 | 59 | |
| 60 | - $pdf->Image( apply_filters( 'give_pdf_export_logo', GIVE_PLUGIN_URL . 'assets/images/give-logo-small.png' ), 247, 8 ); |
|
| 60 | + $pdf->Image(apply_filters('give_pdf_export_logo', GIVE_PLUGIN_URL.'assets/images/give-logo-small.png'), 247, 8); |
|
| 61 | 61 | |
| 62 | - $pdf->SetMargins( 8, 8, 8 ); |
|
| 63 | - $pdf->SetX( 8 ); |
|
| 62 | + $pdf->SetMargins(8, 8, 8); |
|
| 63 | + $pdf->SetX(8); |
|
| 64 | 64 | |
| 65 | - $pdf->SetFont( 'Helvetica', '', 16 ); |
|
| 66 | - $pdf->SetTextColor( 50, 50, 50 ); |
|
| 67 | - $pdf->Cell( 0, 3, utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ), 0, 2, 'L', false ); |
|
| 65 | + $pdf->SetFont('Helvetica', '', 16); |
|
| 66 | + $pdf->SetTextColor(50, 50, 50); |
|
| 67 | + $pdf->Cell(0, 3, utf8_decode(__('Donation report for the current year for all forms', 'give')), 0, 2, 'L', false); |
|
| 68 | 68 | |
| 69 | - $pdf->SetFont( 'Helvetica', '', 13 ); |
|
| 69 | + $pdf->SetFont('Helvetica', '', 13); |
|
| 70 | 70 | $pdf->Ln(); |
| 71 | - $pdf->SetTextColor( 150, 150, 150 ); |
|
| 72 | - $pdf->Cell( 0, 6, utf8_decode( __( 'Date Range: ', 'give' ) ) . $daterange, 0, 2, 'L', false ); |
|
| 71 | + $pdf->SetTextColor(150, 150, 150); |
|
| 72 | + $pdf->Cell(0, 6, utf8_decode(__('Date Range: ', 'give')).$daterange, 0, 2, 'L', false); |
|
| 73 | 73 | $pdf->Ln(); |
| 74 | - $pdf->SetTextColor( 50, 50, 50 ); |
|
| 75 | - $pdf->SetFont( 'Helvetica', '', 14 ); |
|
| 76 | - $pdf->Cell( 0, 10, utf8_decode( __( 'Table View', 'give' ) ), 0, 2, 'L', false ); |
|
| 77 | - $pdf->SetFont( 'Helvetica', '', 12 ); |
|
| 74 | + $pdf->SetTextColor(50, 50, 50); |
|
| 75 | + $pdf->SetFont('Helvetica', '', 14); |
|
| 76 | + $pdf->Cell(0, 10, utf8_decode(__('Table View', 'give')), 0, 2, 'L', false); |
|
| 77 | + $pdf->SetFont('Helvetica', '', 12); |
|
| 78 | 78 | |
| 79 | - $pdf->SetFillColor( 238, 238, 238 ); |
|
| 80 | - $pdf->Cell( 70, 6, utf8_decode( __( 'Form Name', 'give' ) ), 1, 0, 'L', true ); |
|
| 81 | - $pdf->Cell( 30, 6, utf8_decode( __( 'Price', 'give' ) ), 1, 0, 'L', true ); |
|
| 79 | + $pdf->SetFillColor(238, 238, 238); |
|
| 80 | + $pdf->Cell(70, 6, utf8_decode(__('Form Name', 'give')), 1, 0, 'L', true); |
|
| 81 | + $pdf->Cell(30, 6, utf8_decode(__('Price', 'give')), 1, 0, 'L', true); |
|
| 82 | 82 | |
| 83 | 83 | // Display Categories Heading only, if user has opted for it. |
| 84 | - if ( $categories_enabled ) { |
|
| 85 | - $pdf->Cell( 45, 6, utf8_decode( __( 'Categories', 'give' ) ), 1, 0, 'L', true ); |
|
| 84 | + if ($categories_enabled) { |
|
| 85 | + $pdf->Cell(45, 6, utf8_decode(__('Categories', 'give')), 1, 0, 'L', true); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Display Tags Heading only, if user has opted for it. |
| 89 | - if ( $tags_enabled ) { |
|
| 90 | - $pdf->Cell( 45, 6, utf8_decode( __( 'Tags', 'give' ) ), 1, 0, 'L', true ); |
|
| 89 | + if ($tags_enabled) { |
|
| 90 | + $pdf->Cell(45, 6, utf8_decode(__('Tags', 'give')), 1, 0, 'L', true); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $pdf->Cell( 45, 6, utf8_decode( __( 'Number of Donations', 'give' ) ), 1, 0, 'L', true ); |
|
| 94 | - $pdf->Cell( 45, 6, utf8_decode( __( 'Income to Date', 'give' ) ), 1, 1, 'L', true ); |
|
| 93 | + $pdf->Cell(45, 6, utf8_decode(__('Number of Donations', 'give')), 1, 0, 'L', true); |
|
| 94 | + $pdf->Cell(45, 6, utf8_decode(__('Income to Date', 'give')), 1, 1, 'L', true); |
|
| 95 | 95 | |
| 96 | - $year = date( 'Y' ); |
|
| 97 | - $give_forms = get_posts( array( 'post_type' => 'give_forms', 'year' => $year, 'posts_per_page' => - 1 ) ); |
|
| 96 | + $year = date('Y'); |
|
| 97 | + $give_forms = get_posts(array('post_type' => 'give_forms', 'year' => $year, 'posts_per_page' => -1)); |
|
| 98 | 98 | |
| 99 | - if ( $give_forms ) { |
|
| 100 | - $pdf->SetWidths( array( 70, 30, 45, 45, 45, 45 ) ); |
|
| 99 | + if ($give_forms) { |
|
| 100 | + $pdf->SetWidths(array(70, 30, 45, 45, 45, 45)); |
|
| 101 | 101 | |
| 102 | - foreach ( $give_forms as $form ): |
|
| 103 | - $pdf->SetFillColor( 255, 255, 255 ); |
|
| 102 | + foreach ($give_forms as $form): |
|
| 103 | + $pdf->SetFillColor(255, 255, 255); |
|
| 104 | 104 | |
| 105 | 105 | $title = $form->post_title; |
| 106 | 106 | |
| 107 | - if ( give_has_variable_prices( $form->ID ) ) { |
|
| 107 | + if (give_has_variable_prices($form->ID)) { |
|
| 108 | 108 | |
| 109 | - $prices = give_get_variable_prices( $form->ID ); |
|
| 109 | + $prices = give_get_variable_prices($form->ID); |
|
| 110 | 110 | |
| 111 | 111 | $first = $prices[0]['_give_amount']; |
| 112 | - $last = array_pop( $prices ); |
|
| 112 | + $last = array_pop($prices); |
|
| 113 | 113 | $last = $last['_give_amount']; |
| 114 | 114 | |
| 115 | - if ( $first < $last ) { |
|
| 115 | + if ($first < $last) { |
|
| 116 | 116 | $min = $first; |
| 117 | 117 | $max = $last; |
| 118 | 118 | } else { |
@@ -120,31 +120,31 @@ discard block |
||
| 120 | 120 | $max = $first; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $price = give_currency_filter( give_format_amount( $min, array( 'sanitize' => false ) ), '', true ) . ' - ' . give_currency_filter( give_format_amount( $max ), '', true ); |
|
| 123 | + $price = give_currency_filter(give_format_amount($min, array('sanitize' => false)), '', true).' - '.give_currency_filter(give_format_amount($max), '', true); |
|
| 124 | 124 | } else { |
| 125 | - $price = give_currency_filter( give_get_form_price( $form->ID ), '', true ); |
|
| 125 | + $price = give_currency_filter(give_get_form_price($form->ID), '', true); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Display Categories Data only, if user has opted for it. |
| 129 | - if ( $categories_enabled ) { |
|
| 130 | - $categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' ); |
|
| 131 | - $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : ''; |
|
| 129 | + if ($categories_enabled) { |
|
| 130 | + $categories = get_the_term_list($form->ID, 'give_forms_category', '', ', ', ''); |
|
| 131 | + $categories = ! is_wp_error($categories) ? strip_tags($categories) : ''; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // Display Tags Data only, if user has opted for it. |
| 135 | - if ( $tags_enabled ) { |
|
| 136 | - $tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' ); |
|
| 137 | - $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : ''; |
|
| 135 | + if ($tags_enabled) { |
|
| 136 | + $tags = get_the_term_list($form->ID, 'give_forms_tag', '', ', ', ''); |
|
| 137 | + $tags = ! is_wp_error($tags) ? strip_tags($tags) : ''; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $sales = give_get_form_sales_stats( $form->ID ); |
|
| 141 | - $link = get_permalink( $form->ID ); |
|
| 142 | - $earnings = give_currency_filter( give_get_form_earnings_stats( $form->ID ), '', true ); |
|
| 140 | + $sales = give_get_form_sales_stats($form->ID); |
|
| 141 | + $link = get_permalink($form->ID); |
|
| 142 | + $earnings = give_currency_filter(give_get_form_earnings_stats($form->ID), '', true); |
|
| 143 | 143 | |
| 144 | - if ( function_exists( 'iconv' ) ) { |
|
| 144 | + if (function_exists('iconv')) { |
|
| 145 | 145 | // Ensure characters like euro; are properly converted. |
| 146 | - $price = iconv( 'UTF-8', 'windows-1252', utf8_encode( $price ) ); |
|
| 147 | - $earnings = iconv( 'UTF-8', 'windows-1252', utf8_encode( $earnings ) ); |
|
| 146 | + $price = iconv('UTF-8', 'windows-1252', utf8_encode($price)); |
|
| 147 | + $earnings = iconv('UTF-8', 'windows-1252', utf8_encode($earnings)); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // This will help filter data before appending it to PDF Receipt. |
@@ -153,51 +153,51 @@ discard block |
||
| 153 | 153 | $prepare_pdf_data[] = $price; |
| 154 | 154 | |
| 155 | 155 | // Append Categories Data only, if user has opted for it. |
| 156 | - if ( $categories_enabled ) { |
|
| 156 | + if ($categories_enabled) { |
|
| 157 | 157 | $prepare_pdf_data[] = $categories; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Append Tags Data only, if user has opted for it. |
| 161 | - if ( $tags_enabled ) { |
|
| 161 | + if ($tags_enabled) { |
|
| 162 | 162 | $prepare_pdf_data[] = $tags; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $prepare_pdf_data[] = $sales; |
| 166 | 166 | $prepare_pdf_data[] = $earnings; |
| 167 | 167 | |
| 168 | - $pdf->Row( $prepare_pdf_data ); |
|
| 168 | + $pdf->Row($prepare_pdf_data); |
|
| 169 | 169 | endforeach; |
| 170 | 170 | } else { |
| 171 | 171 | |
| 172 | 172 | // Fix: Minor Styling Alignment Issue for PDF |
| 173 | - if( $categories_enabled && $tags_enabled ) { |
|
| 174 | - $pdf->SetWidths( array( 280 ) ); |
|
| 175 | - } elseif( $categories_enabled || $tags_enabled ) { |
|
| 176 | - $pdf->SetWidths( array( 235 ) ); |
|
| 173 | + if ($categories_enabled && $tags_enabled) { |
|
| 174 | + $pdf->SetWidths(array(280)); |
|
| 175 | + } elseif ($categories_enabled || $tags_enabled) { |
|
| 176 | + $pdf->SetWidths(array(235)); |
|
| 177 | 177 | } else { |
| 178 | - $pdf->SetWidths( array( 190 ) ); |
|
| 178 | + $pdf->SetWidths(array(190)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - $title = utf8_decode( __( 'No forms found.', 'give' ) ); |
|
| 182 | - $pdf->Row( array( $title ) ); |
|
| 181 | + $title = utf8_decode(__('No forms found.', 'give')); |
|
| 182 | + $pdf->Row(array($title)); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $pdf->Ln(); |
| 186 | - $pdf->SetTextColor( 50, 50, 50 ); |
|
| 187 | - $pdf->SetFont( 'Helvetica', '', 14 ); |
|
| 188 | - $pdf->Cell( 0, 10, utf8_decode( __( 'Graph View', 'give' ) ), 0, 2, 'L', false ); |
|
| 189 | - $pdf->SetFont( 'Helvetica', '', 12 ); |
|
| 190 | - |
|
| 191 | - $image = html_entity_decode( urldecode( give_draw_chart_image() ) ); |
|
| 192 | - $image = str_replace( ' ', '%20', $image ); |
|
| 193 | - |
|
| 194 | - $pdf->SetX( 25 ); |
|
| 195 | - $pdf->Image( $image . '&file=.png' ); |
|
| 196 | - $pdf->Ln( 7 ); |
|
| 197 | - $pdf->Output( apply_filters( 'give_sales_earnings_pdf_export_filename', 'give-report-' . date_i18n( 'Y-m-d' ) ) . '.pdf', 'D' ); |
|
| 186 | + $pdf->SetTextColor(50, 50, 50); |
|
| 187 | + $pdf->SetFont('Helvetica', '', 14); |
|
| 188 | + $pdf->Cell(0, 10, utf8_decode(__('Graph View', 'give')), 0, 2, 'L', false); |
|
| 189 | + $pdf->SetFont('Helvetica', '', 12); |
|
| 190 | + |
|
| 191 | + $image = html_entity_decode(urldecode(give_draw_chart_image())); |
|
| 192 | + $image = str_replace(' ', '%20', $image); |
|
| 193 | + |
|
| 194 | + $pdf->SetX(25); |
|
| 195 | + $pdf->Image($image.'&file=.png'); |
|
| 196 | + $pdf->Ln(7); |
|
| 197 | + $pdf->Output(apply_filters('give_sales_earnings_pdf_export_filename', 'give-report-'.date_i18n('Y-m-d')).'.pdf', 'D'); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | -add_action( 'give_generate_pdf', 'give_generate_pdf' ); |
|
| 200 | +add_action('give_generate_pdf', 'give_generate_pdf'); |
|
| 201 | 201 | |
| 202 | 202 | /** |
| 203 | 203 | * Draws Chart for PDF Report. |
@@ -214,38 +214,38 @@ discard block |
||
| 214 | 214 | * @return string $chart->getUrl() URL for the Google Chart |
| 215 | 215 | */ |
| 216 | 216 | function give_draw_chart_image() { |
| 217 | - require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/GoogleChart.php'; |
|
| 218 | - require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php'; |
|
| 219 | - require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php'; |
|
| 217 | + require_once GIVE_PLUGIN_DIR.'/includes/libraries/googlechartlib/GoogleChart.php'; |
|
| 218 | + require_once GIVE_PLUGIN_DIR.'/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php'; |
|
| 219 | + require_once GIVE_PLUGIN_DIR.'/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php'; |
|
| 220 | 220 | |
| 221 | - $chart = new GoogleChart( 'lc', 900, 330 ); |
|
| 221 | + $chart = new GoogleChart('lc', 900, 330); |
|
| 222 | 222 | |
| 223 | 223 | $i = 1; |
| 224 | 224 | $earnings = ""; |
| 225 | 225 | $sales = ""; |
| 226 | 226 | |
| 227 | - while ( $i <= 12 ) : |
|
| 228 | - $earnings .= give_get_earnings_by_date( null, $i, date( 'Y' ) ) . ","; |
|
| 229 | - $sales .= give_get_sales_by_date( null, $i, date( 'Y' ) ) . ","; |
|
| 230 | - $i ++; |
|
| 227 | + while ($i <= 12) : |
|
| 228 | + $earnings .= give_get_earnings_by_date(null, $i, date('Y')).","; |
|
| 229 | + $sales .= give_get_sales_by_date(null, $i, date('Y')).","; |
|
| 230 | + $i++; |
|
| 231 | 231 | endwhile; |
| 232 | 232 | |
| 233 | - $earnings_array = explode( ",", $earnings ); |
|
| 234 | - $sales_array = explode( ",", $sales ); |
|
| 233 | + $earnings_array = explode(",", $earnings); |
|
| 234 | + $sales_array = explode(",", $sales); |
|
| 235 | 235 | |
| 236 | 236 | $i = 0; |
| 237 | - while ( $i <= 11 ) { |
|
| 238 | - if ( empty( $sales_array[ $i ] ) ) { |
|
| 239 | - $sales_array[ $i ] = 0; |
|
| 237 | + while ($i <= 11) { |
|
| 238 | + if (empty($sales_array[$i])) { |
|
| 239 | + $sales_array[$i] = 0; |
|
| 240 | 240 | } |
| 241 | - $i ++; |
|
| 241 | + $i++; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | $min_earnings = 0; |
| 245 | - $max_earnings = max( $earnings_array ); |
|
| 246 | - $earnings_scale = round( $max_earnings, - 1 ); |
|
| 245 | + $max_earnings = max($earnings_array); |
|
| 246 | + $earnings_scale = round($max_earnings, - 1); |
|
| 247 | 247 | |
| 248 | - $data = new GoogleChartData( array( |
|
| 248 | + $data = new GoogleChartData(array( |
|
| 249 | 249 | $earnings_array[0], |
| 250 | 250 | $earnings_array[1], |
| 251 | 251 | $earnings_array[2], |
@@ -258,25 +258,25 @@ discard block |
||
| 258 | 258 | $earnings_array[9], |
| 259 | 259 | $earnings_array[10], |
| 260 | 260 | $earnings_array[11] |
| 261 | - ) ); |
|
| 261 | + )); |
|
| 262 | 262 | |
| 263 | - $data->setLegend( __( 'Income', 'give' ) ); |
|
| 264 | - $data->setColor( '1b58a3' ); |
|
| 265 | - $chart->addData( $data ); |
|
| 263 | + $data->setLegend(__('Income', 'give')); |
|
| 264 | + $data->setColor('1b58a3'); |
|
| 265 | + $chart->addData($data); |
|
| 266 | 266 | |
| 267 | - $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE ); |
|
| 268 | - $shape_marker->setColor( '000000' ); |
|
| 269 | - $shape_marker->setSize( 7 ); |
|
| 270 | - $shape_marker->setBorder( 2 ); |
|
| 271 | - $shape_marker->setData( $data ); |
|
| 272 | - $chart->addMarker( $shape_marker ); |
|
| 267 | + $shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE); |
|
| 268 | + $shape_marker->setColor('000000'); |
|
| 269 | + $shape_marker->setSize(7); |
|
| 270 | + $shape_marker->setBorder(2); |
|
| 271 | + $shape_marker->setData($data); |
|
| 272 | + $chart->addMarker($shape_marker); |
|
| 273 | 273 | |
| 274 | - $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE ); |
|
| 275 | - $value_marker->setColor( '000000' ); |
|
| 276 | - $value_marker->setData( $data ); |
|
| 277 | - $chart->addMarker( $value_marker ); |
|
| 274 | + $value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE); |
|
| 275 | + $value_marker->setColor('000000'); |
|
| 276 | + $value_marker->setData($data); |
|
| 277 | + $chart->addMarker($value_marker); |
|
| 278 | 278 | |
| 279 | - $data = new GoogleChartData( array( |
|
| 279 | + $data = new GoogleChartData(array( |
|
| 280 | 280 | $sales_array[0], |
| 281 | 281 | $sales_array[1], |
| 282 | 282 | $sales_array[2], |
@@ -289,46 +289,46 @@ discard block |
||
| 289 | 289 | $sales_array[9], |
| 290 | 290 | $sales_array[10], |
| 291 | 291 | $sales_array[11] |
| 292 | - ) ); |
|
| 293 | - $data->setLegend( __( 'Donations', 'give' ) ); |
|
| 294 | - $data->setColor( 'ff6c1c' ); |
|
| 295 | - $chart->addData( $data ); |
|
| 296 | - |
|
| 297 | - $chart->setTitle( __( 'Donations by Month for all Give Forms', 'give' ), '336699', 18 ); |
|
| 298 | - |
|
| 299 | - $chart->setScale( 0, $max_earnings ); |
|
| 300 | - |
|
| 301 | - $y_axis = new GoogleChartAxis( 'y' ); |
|
| 302 | - $y_axis->setDrawTickMarks( true )->setLabels( array( 0, $max_earnings ) ); |
|
| 303 | - $chart->addAxis( $y_axis ); |
|
| 304 | - |
|
| 305 | - $x_axis = new GoogleChartAxis( 'x' ); |
|
| 306 | - $x_axis->setTickMarks( 5 ); |
|
| 307 | - $x_axis->setLabels( array( |
|
| 308 | - __( 'Jan', 'give' ), |
|
| 309 | - __( 'Feb', 'give' ), |
|
| 310 | - __( 'Mar', 'give' ), |
|
| 311 | - __( 'Apr', 'give' ), |
|
| 312 | - __( 'May', 'give' ), |
|
| 313 | - __( 'June', 'give' ), |
|
| 314 | - __( 'July', 'give' ), |
|
| 315 | - __( 'Aug', 'give' ), |
|
| 316 | - __( 'Sept', 'give' ), |
|
| 317 | - __( 'Oct', 'give' ), |
|
| 318 | - __( 'Nov', 'give' ), |
|
| 319 | - __( 'Dec', 'give' ) |
|
| 320 | - ) ); |
|
| 321 | - $chart->addAxis( $x_axis ); |
|
| 322 | - |
|
| 323 | - $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE ); |
|
| 324 | - $shape_marker->setSize( 6 ); |
|
| 325 | - $shape_marker->setBorder( 2 ); |
|
| 326 | - $shape_marker->setData( $data ); |
|
| 327 | - $chart->addMarker( $shape_marker ); |
|
| 328 | - |
|
| 329 | - $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE ); |
|
| 330 | - $value_marker->setData( $data ); |
|
| 331 | - $chart->addMarker( $value_marker ); |
|
| 292 | + )); |
|
| 293 | + $data->setLegend(__('Donations', 'give')); |
|
| 294 | + $data->setColor('ff6c1c'); |
|
| 295 | + $chart->addData($data); |
|
| 296 | + |
|
| 297 | + $chart->setTitle(__('Donations by Month for all Give Forms', 'give'), '336699', 18); |
|
| 298 | + |
|
| 299 | + $chart->setScale(0, $max_earnings); |
|
| 300 | + |
|
| 301 | + $y_axis = new GoogleChartAxis('y'); |
|
| 302 | + $y_axis->setDrawTickMarks(true)->setLabels(array(0, $max_earnings)); |
|
| 303 | + $chart->addAxis($y_axis); |
|
| 304 | + |
|
| 305 | + $x_axis = new GoogleChartAxis('x'); |
|
| 306 | + $x_axis->setTickMarks(5); |
|
| 307 | + $x_axis->setLabels(array( |
|
| 308 | + __('Jan', 'give'), |
|
| 309 | + __('Feb', 'give'), |
|
| 310 | + __('Mar', 'give'), |
|
| 311 | + __('Apr', 'give'), |
|
| 312 | + __('May', 'give'), |
|
| 313 | + __('June', 'give'), |
|
| 314 | + __('July', 'give'), |
|
| 315 | + __('Aug', 'give'), |
|
| 316 | + __('Sept', 'give'), |
|
| 317 | + __('Oct', 'give'), |
|
| 318 | + __('Nov', 'give'), |
|
| 319 | + __('Dec', 'give') |
|
| 320 | + )); |
|
| 321 | + $chart->addAxis($x_axis); |
|
| 322 | + |
|
| 323 | + $shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE); |
|
| 324 | + $shape_marker->setSize(6); |
|
| 325 | + $shape_marker->setBorder(2); |
|
| 326 | + $shape_marker->setData($data); |
|
| 327 | + $chart->addMarker($shape_marker); |
|
| 328 | + |
|
| 329 | + $value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE); |
|
| 330 | + $value_marker->setData($data); |
|
| 331 | + $chart->addMarker($value_marker); |
|
| 332 | 332 | |
| 333 | 333 | return $chart->getUrl(); |
| 334 | 334 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly. |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -41,20 +41,20 @@ discard block |
||
| 41 | 41 | public function csv_cols() { |
| 42 | 42 | |
| 43 | 43 | $cols = array( |
| 44 | - 'ID' => __( 'ID', 'give' ), |
|
| 45 | - 'post_name' => __( 'Slug', 'give' ), |
|
| 46 | - 'post_title' => __( 'Name', 'give' ), |
|
| 47 | - 'post_date' => __( 'Date Created', 'give' ), |
|
| 48 | - 'post_author' => __( 'Author', 'give' ), |
|
| 49 | - 'post_content' => __( 'Description', 'give' ), |
|
| 50 | - 'post_excerpt' => __( 'Excerpt', 'give' ), |
|
| 51 | - 'post_status' => __( 'Status', 'give' ), |
|
| 52 | - 'categories' => __( 'Categories', 'give' ), |
|
| 53 | - 'tags' => __( 'Tags', 'give' ), |
|
| 54 | - 'give_price' => __( 'Price', 'give' ), |
|
| 55 | - '_thumbnail_id' => __( 'Featured Image', 'give' ), |
|
| 56 | - '_give_form_sales' => __( 'Donations', 'give' ), |
|
| 57 | - '_give_download_earnings' => __( 'Income', 'give' ), |
|
| 44 | + 'ID' => __('ID', 'give'), |
|
| 45 | + 'post_name' => __('Slug', 'give'), |
|
| 46 | + 'post_title' => __('Name', 'give'), |
|
| 47 | + 'post_date' => __('Date Created', 'give'), |
|
| 48 | + 'post_author' => __('Author', 'give'), |
|
| 49 | + 'post_content' => __('Description', 'give'), |
|
| 50 | + 'post_excerpt' => __('Excerpt', 'give'), |
|
| 51 | + 'post_status' => __('Status', 'give'), |
|
| 52 | + 'categories' => __('Categories', 'give'), |
|
| 53 | + 'tags' => __('Tags', 'give'), |
|
| 54 | + 'give_price' => __('Price', 'give'), |
|
| 55 | + '_thumbnail_id' => __('Featured Image', 'give'), |
|
| 56 | + '_give_form_sales' => __('Donations', 'give'), |
|
| 57 | + '_give_download_earnings' => __('Income', 'give'), |
|
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | return $cols; |
@@ -84,43 +84,43 @@ discard block |
||
| 84 | 84 | 'paged' => $this->step |
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | - $forms = new WP_Query( $args ); |
|
| 87 | + $forms = new WP_Query($args); |
|
| 88 | 88 | |
| 89 | - if ( $forms->posts ) { |
|
| 90 | - foreach ( $forms->posts as $form ) { |
|
| 89 | + if ($forms->posts) { |
|
| 90 | + foreach ($forms->posts as $form) { |
|
| 91 | 91 | |
| 92 | 92 | $row = []; |
| 93 | 93 | |
| 94 | - foreach ( $this->csv_cols() as $key => $value ) { |
|
| 94 | + foreach ($this->csv_cols() as $key => $value) { |
|
| 95 | 95 | |
| 96 | 96 | // Setup default value/ |
| 97 | - $row[ $key ] = ''; |
|
| 97 | + $row[$key] = ''; |
|
| 98 | 98 | |
| 99 | - if ( in_array( $key, $meta ) ) { |
|
| 99 | + if (in_array($key, $meta)) { |
|
| 100 | 100 | |
| 101 | - switch ( $key ) { |
|
| 101 | + switch ($key) { |
|
| 102 | 102 | |
| 103 | 103 | case '_thumbnail_id' : |
| 104 | 104 | |
| 105 | - $image_id = get_post_thumbnail_id( $form->ID ); |
|
| 106 | - $row[ $key ] = wp_get_attachment_url( $image_id ); |
|
| 105 | + $image_id = get_post_thumbnail_id($form->ID); |
|
| 106 | + $row[$key] = wp_get_attachment_url($image_id); |
|
| 107 | 107 | |
| 108 | 108 | break; |
| 109 | 109 | |
| 110 | 110 | case 'give_price' : |
| 111 | 111 | |
| 112 | - if ( give_has_variable_prices( $form->ID ) ) { |
|
| 112 | + if (give_has_variable_prices($form->ID)) { |
|
| 113 | 113 | |
| 114 | 114 | $prices = []; |
| 115 | - foreach ( give_get_variable_prices( $form->ID ) as $price ) { |
|
| 116 | - $prices[] = $price['name'] . ': ' . $price['amount']; |
|
| 115 | + foreach (give_get_variable_prices($form->ID) as $price) { |
|
| 116 | + $prices[] = $price['name'].': '.$price['amount']; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $row[ $key ] = implode( ' | ', $prices ); |
|
| 119 | + $row[$key] = implode(' | ', $prices); |
|
| 120 | 120 | |
| 121 | 121 | } else { |
| 122 | 122 | |
| 123 | - $row[ $key ] = give_get_form_price( $form->ID ); |
|
| 123 | + $row[$key] = give_get_form_price($form->ID); |
|
| 124 | 124 | |
| 125 | 125 | } |
| 126 | 126 | |
@@ -128,44 +128,44 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | default : |
| 130 | 130 | |
| 131 | - $row[ $key ] = give_get_meta( $form->ID, $key, TRUE ); |
|
| 131 | + $row[$key] = give_get_meta($form->ID, $key, TRUE); |
|
| 132 | 132 | |
| 133 | 133 | break; |
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - } elseif ( isset( $form->$key ) ) { |
|
| 137 | + } elseif (isset($form->$key)) { |
|
| 138 | 138 | |
| 139 | - switch ( $key ) { |
|
| 139 | + switch ($key) { |
|
| 140 | 140 | |
| 141 | 141 | case 'post_author' : |
| 142 | 142 | |
| 143 | - $row[ $key ] = get_the_author_meta( 'user_login', $form->post_author ); |
|
| 143 | + $row[$key] = get_the_author_meta('user_login', $form->post_author); |
|
| 144 | 144 | |
| 145 | 145 | break; |
| 146 | 146 | |
| 147 | 147 | default : |
| 148 | 148 | |
| 149 | - $row[ $key ] = $form->$key; |
|
| 149 | + $row[$key] = $form->$key; |
|
| 150 | 150 | |
| 151 | 151 | break; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - } elseif ( 'tags' == $key ) { |
|
| 154 | + } elseif ('tags' == $key) { |
|
| 155 | 155 | |
| 156 | - $terms = get_the_terms( $form->ID, 'form_tag' ); |
|
| 157 | - if ( $terms ) { |
|
| 158 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
| 159 | - $row[ $key ] = implode( ' | ', $terms ); |
|
| 156 | + $terms = get_the_terms($form->ID, 'form_tag'); |
|
| 157 | + if ($terms) { |
|
| 158 | + $terms = wp_list_pluck($terms, 'name'); |
|
| 159 | + $row[$key] = implode(' | ', $terms); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | |
| 163 | - } elseif ( 'categories' == $key ) { |
|
| 163 | + } elseif ('categories' == $key) { |
|
| 164 | 164 | |
| 165 | - $terms = get_the_terms( $form->ID, 'form_category' ); |
|
| 166 | - if ( $terms ) { |
|
| 167 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
| 168 | - $row[ $key ] = implode( ' | ', $terms ); |
|
| 165 | + $terms = get_the_terms($form->ID, 'form_category'); |
|
| 166 | + if ($terms) { |
|
| 167 | + $terms = wp_list_pluck($terms, 'name'); |
|
| 168 | + $row[$key] = implode(' | ', $terms); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | } |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
| 180 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
| 179 | + $data = apply_filters('give_export_get_data', $data); |
|
| 180 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
| 181 | 181 | |
| 182 | 182 | return $data; |
| 183 | 183 | |
@@ -197,20 +197,20 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | $args = array( |
| 199 | 199 | 'post_type' => 'give_forms', |
| 200 | - 'posts_per_page' => - 1, |
|
| 200 | + 'posts_per_page' => -1, |
|
| 201 | 201 | 'post_status' => 'any', |
| 202 | 202 | 'fields' => 'ids', |
| 203 | 203 | ); |
| 204 | 204 | |
| 205 | - $forms = new WP_Query( $args ); |
|
| 205 | + $forms = new WP_Query($args); |
|
| 206 | 206 | $total = (int) $forms->post_count; |
| 207 | 207 | $percentage = 100; |
| 208 | 208 | |
| 209 | - if ( $total > 0 ) { |
|
| 210 | - $percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
| 209 | + if ($total > 0) { |
|
| 210 | + $percentage = ((30 * $this->step) / $total) * 100; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( $percentage > 100 ) { |
|
| 213 | + if ($percentage > 100) { |
|
| 214 | 214 | $percentage = 100; |
| 215 | 215 | } |
| 216 | 216 | |
@@ -216,7 +216,6 @@ |
||
| 216 | 216 | /** |
| 217 | 217 | * Set Donation Amount for Multi Level Donation Forms |
| 218 | 218 | * |
| 219 | - * @param int $form_id |
|
| 220 | 219 | * @param object $form |
| 221 | 220 | * |
| 222 | 221 | * @since 1.8.9 |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -25,14 +25,14 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function give_get_actions() { |
| 27 | 27 | |
| 28 | - $_get_action = ! empty( $_GET['give_action'] ) ? $_GET['give_action'] : null; |
|
| 28 | + $_get_action = ! empty($_GET['give_action']) ? $_GET['give_action'] : null; |
|
| 29 | 29 | |
| 30 | 30 | // Add backward compatibility to give-action param ( $_GET ) |
| 31 | - if( empty( $_get_action ) ) { |
|
| 32 | - $_get_action = ! empty( $_GET['give-action'] ) ? $_GET['give-action'] : null; |
|
| 31 | + if (empty($_get_action)) { |
|
| 32 | + $_get_action = ! empty($_GET['give-action']) ? $_GET['give-action'] : null; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if ( isset( $_get_action ) ) { |
|
| 35 | + if (isset($_get_action)) { |
|
| 36 | 36 | /** |
| 37 | 37 | * Fires in WordPress init or admin init, when give_action is present in $_GET. |
| 38 | 38 | * |
@@ -40,12 +40,12 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param array $_GET Array of HTTP GET variables. |
| 42 | 42 | */ |
| 43 | - do_action( "give_{$_get_action}", $_GET ); |
|
| 43 | + do_action("give_{$_get_action}", $_GET); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | -add_action( 'init', 'give_get_actions' ); |
|
| 48 | +add_action('init', 'give_get_actions'); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Hooks Give actions, when present in the $_POST super global. Every give_action |
@@ -58,15 +58,15 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | function give_post_actions() { |
| 60 | 60 | |
| 61 | - $_post_action = ! empty( $_POST['give_action'] ) ? $_POST['give_action'] : null; |
|
| 61 | + $_post_action = ! empty($_POST['give_action']) ? $_POST['give_action'] : null; |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | // Add backward compatibility to give-action param ( $_POST ). |
| 65 | - if( empty( $_post_action ) ) { |
|
| 66 | - $_post_action = ! empty( $_POST['give-action'] ) ? $_POST['give-action'] : null; |
|
| 65 | + if (empty($_post_action)) { |
|
| 66 | + $_post_action = ! empty($_POST['give-action']) ? $_POST['give-action'] : null; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ( isset( $_post_action ) ) { |
|
| 69 | + if (isset($_post_action)) { |
|
| 70 | 70 | /** |
| 71 | 71 | * Fires in WordPress init or admin init, when give_action is present in $_POST. |
| 72 | 72 | * |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @param array $_POST Array of HTTP POST variables. |
| 76 | 76 | */ |
| 77 | - do_action( "give_{$_post_action}", $_POST ); |
|
| 77 | + do_action("give_{$_post_action}", $_POST); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | -add_action( 'init', 'give_post_actions' ); |
|
| 82 | +add_action('init', 'give_post_actions'); |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Connect WordPress user with Donor. |
@@ -89,28 +89,28 @@ discard block |
||
| 89 | 89 | * @param array $user_data User Data |
| 90 | 90 | * @return void |
| 91 | 91 | */ |
| 92 | -function give_connect_donor_to_wpuser( $user_id, $user_data ){ |
|
| 92 | +function give_connect_donor_to_wpuser($user_id, $user_data) { |
|
| 93 | 93 | /* @var Give_Donor $donor */ |
| 94 | - $donor = new Give_Donor( $user_data['user_email'] ); |
|
| 94 | + $donor = new Give_Donor($user_data['user_email']); |
|
| 95 | 95 | |
| 96 | 96 | // Validate donor id and check if do nor is already connect to wp user or not. |
| 97 | - if( $donor->id && ! $donor->user_id ) { |
|
| 97 | + if ($donor->id && ! $donor->user_id) { |
|
| 98 | 98 | |
| 99 | 99 | // Update donor user_id. |
| 100 | - if( $donor->update( array( 'user_id' => $user_id ) ) ) { |
|
| 101 | - $donor_note = sprintf( esc_html__( 'WordPress user #%d is connected to #%d', 'give' ), $user_id, $donor->id ); |
|
| 102 | - $donor->add_note( $donor_note ); |
|
| 100 | + if ($donor->update(array('user_id' => $user_id))) { |
|
| 101 | + $donor_note = sprintf(esc_html__('WordPress user #%d is connected to #%d', 'give'), $user_id, $donor->id); |
|
| 102 | + $donor->add_note($donor_note); |
|
| 103 | 103 | |
| 104 | 104 | // Update user_id meta in payments. |
| 105 | - if( ! empty( $donor->payment_ids ) && ( $donations = explode( ',', $donor->payment_ids ) ) ) { |
|
| 106 | - foreach ( $donations as $donation ) { |
|
| 107 | - give_update_meta( $donation, '_give_payment_user_id', $user_id ); |
|
| 105 | + if ( ! empty($donor->payment_ids) && ($donations = explode(',', $donor->payment_ids))) { |
|
| 106 | + foreach ($donations as $donation) { |
|
| 107 | + give_update_meta($donation, '_give_payment_user_id', $user_id); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | -add_action( 'give_insert_user', 'give_connect_donor_to_wpuser', 10, 2 ); |
|
| 113 | +add_action('give_insert_user', 'give_connect_donor_to_wpuser', 10, 2); |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -124,24 +124,24 @@ discard block |
||
| 124 | 124 | function give_validate_license_when_site_migrated() { |
| 125 | 125 | // Store current site address if not already stored. |
| 126 | 126 | $homeurl = home_url(); |
| 127 | - if( ! get_option( 'give_site_address_before_migrate' ) ) { |
|
| 127 | + if ( ! get_option('give_site_address_before_migrate')) { |
|
| 128 | 128 | // Update site address. |
| 129 | - update_option( 'give_site_address_before_migrate', $homeurl ); |
|
| 129 | + update_option('give_site_address_before_migrate', $homeurl); |
|
| 130 | 130 | |
| 131 | 131 | return; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if( $homeurl !== get_option( 'give_site_address_before_migrate' ) ) { |
|
| 134 | + if ($homeurl !== get_option('give_site_address_before_migrate')) { |
|
| 135 | 135 | // Immediately run cron. |
| 136 | - wp_schedule_single_event( time() , 'give_validate_license_when_site_migrated' ); |
|
| 136 | + wp_schedule_single_event(time(), 'give_validate_license_when_site_migrated'); |
|
| 137 | 137 | |
| 138 | 138 | // Update site address. |
| 139 | - update_option( 'give_site_address_before_migrate', home_url() ); |
|
| 139 | + update_option('give_site_address_before_migrate', home_url()); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | } |
| 143 | -add_action( 'init', 'give_validate_license_when_site_migrated' ); |
|
| 144 | -add_action( 'admin_init', 'give_validate_license_when_site_migrated' ); |
|
| 143 | +add_action('init', 'give_validate_license_when_site_migrated'); |
|
| 144 | +add_action('admin_init', 'give_validate_license_when_site_migrated'); |
|
| 145 | 145 | |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,18 +150,18 @@ discard block |
||
| 150 | 150 | * @since 1.8 |
| 151 | 151 | * @param $data |
| 152 | 152 | */ |
| 153 | -function give_donor_batch_export_complete( $data ) { |
|
| 153 | +function give_donor_batch_export_complete($data) { |
|
| 154 | 154 | // Remove donor ids cache. |
| 155 | - if( |
|
| 156 | - isset( $data['class'] ) |
|
| 155 | + if ( |
|
| 156 | + isset($data['class']) |
|
| 157 | 157 | && 'Give_Batch_Donors_Export' === $data['class'] |
| 158 | - && ! empty( $data['forms'] ) |
|
| 159 | - && isset( $data['give_export_option']['query_id'] ) |
|
| 158 | + && ! empty($data['forms']) |
|
| 159 | + && isset($data['give_export_option']['query_id']) |
|
| 160 | 160 | ) { |
| 161 | - Give_Cache::delete( Give_Cache::get_key( $data['give_export_option']['query_id'] ) ); |
|
| 161 | + Give_Cache::delete(Give_Cache::get_key($data['give_export_option']['query_id'])); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | -add_action('give_file_export_complete', 'give_donor_batch_export_complete' ); |
|
| 164 | +add_action('give_file_export_complete', 'give_donor_batch_export_complete'); |
|
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * Print css for wordpress setting pages. |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | /* @var WP_Screen $screen */ |
| 173 | 173 | $screen = get_current_screen(); |
| 174 | 174 | |
| 175 | - if( ! ( $screen instanceof WP_Screen ) ) { |
|
| 175 | + if ( ! ($screen instanceof WP_Screen)) { |
|
| 176 | 176 | return false; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - switch ( true ) { |
|
| 180 | - case ( 'plugins' === $screen->base || 'plugins-network' === $screen->base ): |
|
| 179 | + switch (true) { |
|
| 180 | + case ('plugins' === $screen->base || 'plugins-network' === $screen->base): |
|
| 181 | 181 | ?> |
| 182 | 182 | <style> |
| 183 | 183 | tr.active.update + tr.give-addon-notice-tr td{ |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | <?php |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | -add_action( 'admin_head', 'give_admin_quick_css' ); |
|
| 213 | +add_action('admin_head', 'give_admin_quick_css'); |
|
| 214 | 214 | |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -223,28 +223,28 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return void |
| 225 | 225 | */ |
| 226 | -function give_set_donation_levels_max_min_amount( $form_id ) { |
|
| 226 | +function give_set_donation_levels_max_min_amount($form_id) { |
|
| 227 | 227 | if ( |
| 228 | - ( 'set' === $_POST['_give_price_option'] ) || |
|
| 229 | - ( in_array( '_give_donation_levels', $_POST ) && count( $_POST['_give_donation_levels'] ) <= 0 ) || |
|
| 230 | - ! ( $donation_levels_amounts = wp_list_pluck( $_POST['_give_donation_levels'], '_give_amount' ) ) |
|
| 228 | + ('set' === $_POST['_give_price_option']) || |
|
| 229 | + (in_array('_give_donation_levels', $_POST) && count($_POST['_give_donation_levels']) <= 0) || |
|
| 230 | + ! ($donation_levels_amounts = wp_list_pluck($_POST['_give_donation_levels'], '_give_amount')) |
|
| 231 | 231 | ) { |
| 232 | 232 | // Delete old meta. |
| 233 | - give_delete_meta( $form_id, '_give_levels_minimum_amount' ); |
|
| 234 | - give_delete_meta( $form_id, '_give_levels_maximum_amount' ); |
|
| 233 | + give_delete_meta($form_id, '_give_levels_minimum_amount'); |
|
| 234 | + give_delete_meta($form_id, '_give_levels_maximum_amount'); |
|
| 235 | 235 | |
| 236 | 236 | return; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Sanitize donation level amounts. |
| 240 | - $donation_levels_amounts = array_map( 'give_maybe_sanitize_amount', $donation_levels_amounts ); |
|
| 240 | + $donation_levels_amounts = array_map('give_maybe_sanitize_amount', $donation_levels_amounts); |
|
| 241 | 241 | |
| 242 | - $min_amount = min( $donation_levels_amounts ); |
|
| 243 | - $max_amount = max( $donation_levels_amounts ); |
|
| 242 | + $min_amount = min($donation_levels_amounts); |
|
| 243 | + $max_amount = max($donation_levels_amounts); |
|
| 244 | 244 | |
| 245 | 245 | // Set Minimum and Maximum amount for Multi Level Donation Forms |
| 246 | - give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount_for_db( $min_amount ) : 0 ); |
|
| 247 | - give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount? give_sanitize_amount_for_db( $max_amount ) : 0 ); |
|
| 246 | + give_update_meta($form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount_for_db($min_amount) : 0); |
|
| 247 | + give_update_meta($form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount_for_db($max_amount) : 0); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | -add_action( 'give_pre_process_give_forms_meta', 'give_set_donation_levels_max_min_amount', 30 ); |
|
| 251 | 250 | \ No newline at end of file |
| 251 | +add_action('give_pre_process_give_forms_meta', 'give_set_donation_levels_max_min_amount', 30); |
|
| 252 | 252 | \ No newline at end of file |
@@ -253,7 +253,7 @@ |
||
| 253 | 253 | * |
| 254 | 254 | * @access public |
| 255 | 255 | * @since 1.0 |
| 256 | - * @return mixed string If search is present, false otherwise. |
|
| 256 | + * @return string|false string If search is present, false otherwise. |
|
| 257 | 257 | */ |
| 258 | 258 | public function get_search() { |
| 259 | 259 | return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
@@ -12,13 +12,13 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly. |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // Load WP_List_Table if not loaded |
| 20 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 21 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 20 | +if ( ! class_exists('WP_List_Table')) { |
|
| 21 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | public function __construct() { |
| 62 | 62 | |
| 63 | 63 | // Set parent defaults |
| 64 | - parent::__construct( array( |
|
| 65 | - 'singular' => __( 'Donor', 'give' ), // Singular name of the listed records. |
|
| 66 | - 'plural' => __( 'Donors', 'give' ), // Plural name of the listed records. |
|
| 67 | - 'ajax' => false,// Does this table support ajax?. |
|
| 68 | - ) ); |
|
| 64 | + parent::__construct(array( |
|
| 65 | + 'singular' => __('Donor', 'give'), // Singular name of the listed records. |
|
| 66 | + 'plural' => __('Donors', 'give'), // Plural name of the listed records. |
|
| 67 | + 'ajax' => false, // Does this table support ajax?. |
|
| 68 | + )); |
|
| 69 | 69 | |
| 70 | 70 | } |
| 71 | 71 | |
@@ -80,22 +80,22 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return void |
| 82 | 82 | */ |
| 83 | - public function search_box( $text, $input_id ) { |
|
| 84 | - $input_id = $input_id . '-search-input'; |
|
| 83 | + public function search_box($text, $input_id) { |
|
| 84 | + $input_id = $input_id.'-search-input'; |
|
| 85 | 85 | |
| 86 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 87 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 86 | + if ( ! empty($_REQUEST['orderby'])) { |
|
| 87 | + echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />'; |
|
| 88 | 88 | } |
| 89 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 90 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 89 | + if ( ! empty($_REQUEST['order'])) { |
|
| 90 | + echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />'; |
|
| 91 | 91 | } |
| 92 | 92 | ?> |
| 93 | 93 | <p class="search-box" role="search"> |
| 94 | 94 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
| 95 | 95 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/> |
| 96 | - <?php submit_button( $text, 'button', false, false, array( |
|
| 96 | + <?php submit_button($text, 'button', false, false, array( |
|
| 97 | 97 | 'ID' => 'search-submit', |
| 98 | - ) ); ?> |
|
| 98 | + )); ?> |
|
| 99 | 99 | </p> |
| 100 | 100 | <?php |
| 101 | 101 | } |
@@ -111,31 +111,31 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return string Column Name. |
| 113 | 113 | */ |
| 114 | - public function column_default( $donor, $column_name ) { |
|
| 115 | - switch ( $column_name ) { |
|
| 114 | + public function column_default($donor, $column_name) { |
|
| 115 | + switch ($column_name) { |
|
| 116 | 116 | |
| 117 | 117 | case 'num_donations' : |
| 118 | 118 | $value = sprintf( |
| 119 | 119 | '<a href="%s">%s</a>', |
| 120 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor['id'] ) ), |
|
| 121 | - esc_html( $donor['num_donations'] ) |
|
| 120 | + admin_url('edit.php?post_type=give_forms&page=give-payment-history&donor='.absint($donor['id'])), |
|
| 121 | + esc_html($donor['num_donations']) |
|
| 122 | 122 | ); |
| 123 | 123 | break; |
| 124 | 124 | |
| 125 | 125 | case 'amount_spent' : |
| 126 | - $value = give_currency_filter( give_format_amount( $donor[ $column_name ], array( 'sanitize' => false ) ) ); |
|
| 126 | + $value = give_currency_filter(give_format_amount($donor[$column_name], array('sanitize' => false))); |
|
| 127 | 127 | break; |
| 128 | 128 | |
| 129 | 129 | case 'date_created' : |
| 130 | - $value = date_i18n( give_date_format(), strtotime( $donor['date_created'] ) ); |
|
| 130 | + $value = date_i18n(give_date_format(), strtotime($donor['date_created'])); |
|
| 131 | 131 | break; |
| 132 | 132 | |
| 133 | 133 | default: |
| 134 | - $value = isset( $donor[ $column_name ] ) ? $donor[ $column_name ] : null; |
|
| 134 | + $value = isset($donor[$column_name]) ? $donor[$column_name] : null; |
|
| 135 | 135 | break; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - return apply_filters( "give_report_column_{$column_name}", $value, $donor['id'] ); |
|
| 138 | + return apply_filters("give_report_column_{$column_name}", $value, $donor['id']); |
|
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @return string |
| 148 | 148 | */ |
| 149 | - public function column_name( $donor ) { |
|
| 150 | - $name = '#' . $donor['id'] . ' '; |
|
| 151 | - $name .= ! empty( $donor['name'] ) ? $donor['name'] : '<em>' . esc_html__( 'Unnamed Donor', 'give' ) . '</em>'; |
|
| 152 | - $view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] ); |
|
| 153 | - $actions = $this->get_row_actions( $donor ); |
|
| 149 | + public function column_name($donor) { |
|
| 150 | + $name = '#'.$donor['id'].' '; |
|
| 151 | + $name .= ! empty($donor['name']) ? $donor['name'] : '<em>'.esc_html__('Unnamed Donor', 'give').'</em>'; |
|
| 152 | + $view_url = admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor['id']); |
|
| 153 | + $actions = $this->get_row_actions($donor); |
|
| 154 | 154 | |
| 155 | - return '<a href="' . esc_url( $view_url ) . '">' . $name . '</a>' . $this->row_actions( $actions ); |
|
| 155 | + return '<a href="'.esc_url($view_url).'">'.$name.'</a>'.$this->row_actions($actions); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -164,14 +164,14 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function get_columns() { |
| 166 | 166 | $columns = array( |
| 167 | - 'name' => __( 'Name', 'give' ), |
|
| 168 | - 'email' => __( 'Email', 'give' ), |
|
| 169 | - 'num_donations' => __( 'Donations', 'give' ), |
|
| 170 | - 'amount_spent' => __( 'Total Donated', 'give' ), |
|
| 171 | - 'date_created' => __( 'Date Created', 'give' ), |
|
| 167 | + 'name' => __('Name', 'give'), |
|
| 168 | + 'email' => __('Email', 'give'), |
|
| 169 | + 'num_donations' => __('Donations', 'give'), |
|
| 170 | + 'amount_spent' => __('Total Donated', 'give'), |
|
| 171 | + 'date_created' => __('Date Created', 'give'), |
|
| 172 | 172 | ); |
| 173 | 173 | |
| 174 | - return apply_filters( 'give_list_donors_columns', $columns ); |
|
| 174 | + return apply_filters('give_list_donors_columns', $columns); |
|
| 175 | 175 | |
| 176 | 176 | } |
| 177 | 177 | |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | public function get_sortable_columns() { |
| 186 | 186 | |
| 187 | 187 | $columns = array( |
| 188 | - 'date_created' => array( 'date_created', true ), |
|
| 189 | - 'name' => array( 'name', true ), |
|
| 190 | - 'num_donations' => array( 'purchase_count', false ), |
|
| 191 | - 'amount_spent' => array( 'purchase_value', false ), |
|
| 188 | + 'date_created' => array('date_created', true), |
|
| 189 | + 'name' => array('name', true), |
|
| 190 | + 'num_donations' => array('purchase_count', false), |
|
| 191 | + 'amount_spent' => array('purchase_value', false), |
|
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | - return apply_filters( 'give_list_donors_sortable_columns', $columns ); |
|
| 194 | + return apply_filters('give_list_donors_sortable_columns', $columns); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -204,19 +204,19 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return array An array of action links. |
| 206 | 206 | */ |
| 207 | - public function get_row_actions( $donor ) { |
|
| 207 | + public function get_row_actions($donor) { |
|
| 208 | 208 | |
| 209 | 209 | $actions = array( |
| 210 | 210 | |
| 211 | - 'view' => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] ), sprintf( esc_attr__( 'View "%s"', 'give' ), $donor['name'] ), __( 'View Donor', 'give' ) ), |
|
| 211 | + 'view' => sprintf('<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor['id']), sprintf(esc_attr__('View "%s"', 'give'), $donor['name']), __('View Donor', 'give')), |
|
| 212 | 212 | |
| 213 | - 'notes' => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=notes&id=' . $donor['id'] ), sprintf( esc_attr__( 'Notes for "%s"', 'give' ), $donor['name'] ), __( 'Notes', 'give' ) ), |
|
| 213 | + 'notes' => sprintf('<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url('edit.php?post_type=give_forms&page=give-donors&view=notes&id='.$donor['id']), sprintf(esc_attr__('Notes for "%s"', 'give'), $donor['name']), __('Notes', 'give')), |
|
| 214 | 214 | |
| 215 | - 'delete' => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $donor['id'] ), sprintf( esc_attr__( 'Delete "%s"', 'give' ), $donor['name'] ), __( 'Delete', 'give' ) ), |
|
| 215 | + 'delete' => sprintf('<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url('edit.php?post_type=give_forms&page=give-donors&view=delete&id='.$donor['id']), sprintf(esc_attr__('Delete "%s"', 'give'), $donor['name']), __('Delete', 'give')), |
|
| 216 | 216 | |
| 217 | 217 | ); |
| 218 | 218 | |
| 219 | - return apply_filters( 'give_donor_row_actions', $actions, $donor ); |
|
| 219 | + return apply_filters('give_donor_row_actions', $actions, $donor); |
|
| 220 | 220 | |
| 221 | 221 | } |
| 222 | 222 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * @since 1.0 |
| 231 | 231 | * @return void |
| 232 | 232 | */ |
| 233 | - public function bulk_actions( $which = '' ) { |
|
| 233 | + public function bulk_actions($which = '') { |
|
| 234 | 234 | // These aren't really bulk actions but this outputs the markup in the right place. |
| 235 | 235 | } |
| 236 | 236 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @return int Current page number. |
| 243 | 243 | */ |
| 244 | 244 | public function get_paged() { |
| 245 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 245 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | * @return mixed string If search is present, false otherwise. |
| 254 | 254 | */ |
| 255 | 255 | public function get_search() { |
| 256 | - return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
|
| 256 | + return ! empty($_GET['s']) ? urldecode(trim($_GET['s'])) : false; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -270,13 +270,13 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | // Get donor query. |
| 272 | 272 | $args = $this->get_donor_query(); |
| 273 | - $donors = Give()->donors->get_donors( $args ); |
|
| 273 | + $donors = Give()->donors->get_donors($args); |
|
| 274 | 274 | |
| 275 | - if ( $donors ) { |
|
| 275 | + if ($donors) { |
|
| 276 | 276 | |
| 277 | - foreach ( $donors as $donor ) { |
|
| 277 | + foreach ($donors as $donor) { |
|
| 278 | 278 | |
| 279 | - $user_id = ! empty( $donor->user_id ) ? intval( $donor->user_id ) : 0; |
|
| 279 | + $user_id = ! empty($donor->user_id) ? intval($donor->user_id) : 0; |
|
| 280 | 280 | |
| 281 | 281 | $data[] = array( |
| 282 | 282 | 'id' => $donor->id, |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - return apply_filters( 'give_donors_column_query_data', $data ); |
|
| 293 | + return apply_filters('give_donors_column_query_data', $data); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -305,9 +305,9 @@ discard block |
||
| 305 | 305 | |
| 306 | 306 | $_donor_query['number'] = - 1; |
| 307 | 307 | $_donor_query['offset'] = 0; |
| 308 | - $donors = Give()->donors->get_donors( $_donor_query ); |
|
| 308 | + $donors = Give()->donors->get_donors($_donor_query); |
|
| 309 | 309 | |
| 310 | - return count( $donors ); |
|
| 310 | + return count($donors); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
@@ -319,10 +319,10 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | public function get_donor_query() { |
| 321 | 321 | $paged = $this->get_paged(); |
| 322 | - $offset = $this->per_page * ( $paged - 1 ); |
|
| 322 | + $offset = $this->per_page * ($paged - 1); |
|
| 323 | 323 | $search = $this->get_search(); |
| 324 | - $order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC'; |
|
| 325 | - $orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id'; |
|
| 324 | + $order = isset($_GET['order']) ? sanitize_text_field($_GET['order']) : 'DESC'; |
|
| 325 | + $orderby = isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : 'id'; |
|
| 326 | 326 | |
| 327 | 327 | $args = array( |
| 328 | 328 | 'number' => $this->per_page, |
@@ -331,10 +331,10 @@ discard block |
||
| 331 | 331 | 'orderby' => $orderby, |
| 332 | 332 | ); |
| 333 | 333 | |
| 334 | - if ( $search ) { |
|
| 335 | - if ( is_email( $search ) ) { |
|
| 334 | + if ($search) { |
|
| 335 | + if (is_email($search)) { |
|
| 336 | 336 | $args['email'] = $search; |
| 337 | - } elseif ( is_numeric( $search ) ) { |
|
| 337 | + } elseif (is_numeric($search)) { |
|
| 338 | 338 | $args['id'] = $search; |
| 339 | 339 | } else { |
| 340 | 340 | $args['name'] = $search; |
@@ -357,16 +357,16 @@ discard block |
||
| 357 | 357 | $hidden = array(); // No hidden columns. |
| 358 | 358 | $sortable = $this->get_sortable_columns(); |
| 359 | 359 | |
| 360 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 360 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 361 | 361 | |
| 362 | 362 | $this->items = $this->donor_data(); |
| 363 | 363 | |
| 364 | 364 | $this->total = $this->get_donor_count(); |
| 365 | 365 | |
| 366 | - $this->set_pagination_args( array( |
|
| 366 | + $this->set_pagination_args(array( |
|
| 367 | 367 | 'total_items' => $this->total, |
| 368 | 368 | 'per_page' => $this->per_page, |
| 369 | - 'total_pages' => ceil( $this->total / $this->per_page ), |
|
| 370 | - ) ); |
|
| 369 | + 'total_pages' => ceil($this->total / $this->per_page), |
|
| 370 | + )); |
|
| 371 | 371 | } |
| 372 | 372 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @param array $args The $_POST array being passed. |
| 274 | 274 | * |
| 275 | - * @return int Whether it was a successful deletion. |
|
| 275 | + * @return false|null Whether it was a successful deletion. |
|
| 276 | 276 | */ |
| 277 | 277 | function give_donor_delete( $args ) { |
| 278 | 278 | |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | * Remove an email address to the donor from within the admin and log a donor note and redirect back to the donor interface for feedback. |
| 547 | 547 | * |
| 548 | 548 | * @since 1.7 |
| 549 | - * @return bool|null |
|
| 549 | + * @return false|null |
|
| 550 | 550 | */ |
| 551 | 551 | function give_remove_donor_email() { |
| 552 | 552 | if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * and redirect back to the donor interface for feedback |
| 590 | 590 | * |
| 591 | 591 | * @since 1.7 |
| 592 | - * @return bool|null |
|
| 592 | + * @return false|null |
|
| 593 | 593 | */ |
| 594 | 594 | function give_set_donor_primary_email() { |
| 595 | 595 | if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -23,17 +23,17 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @return array|bool $output Response messages |
| 25 | 25 | */ |
| 26 | -function give_edit_donor( $args ) { |
|
| 26 | +function give_edit_donor($args) { |
|
| 27 | 27 | |
| 28 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
| 28 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
| 29 | 29 | |
| 30 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
| 31 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array( |
|
| 30 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
| 31 | + wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array( |
|
| 32 | 32 | 'response' => 403, |
| 33 | - ) ); |
|
| 33 | + )); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if ( empty( $args ) ) { |
|
| 36 | + if (empty($args)) { |
|
| 37 | 37 | return false; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -41,15 +41,15 @@ discard block |
||
| 41 | 41 | $donor_id = (int) $args['customerinfo']['id']; |
| 42 | 42 | $nonce = $args['_wpnonce']; |
| 43 | 43 | |
| 44 | - if ( ! wp_verify_nonce( $nonce, 'edit-donor' ) ) { |
|
| 45 | - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array( |
|
| 44 | + if ( ! wp_verify_nonce($nonce, 'edit-donor')) { |
|
| 45 | + wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array( |
|
| 46 | 46 | 'response' => 400, |
| 47 | - ) ); |
|
| 47 | + )); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $donor = new Give_Donor( $donor_id ); |
|
| 50 | + $donor = new Give_Donor($donor_id); |
|
| 51 | 51 | |
| 52 | - if ( empty( $donor->id ) ) { |
|
| 52 | + if (empty($donor->id)) { |
|
| 53 | 53 | return false; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -58,70 +58,70 @@ discard block |
||
| 58 | 58 | 'user_id' => 0, |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - $donor_info = wp_parse_args( $donor_info, $defaults ); |
|
| 61 | + $donor_info = wp_parse_args($donor_info, $defaults); |
|
| 62 | 62 | |
| 63 | - if ( (int) $donor_info['user_id'] !== (int) $donor->user_id ) { |
|
| 63 | + if ((int) $donor_info['user_id'] !== (int) $donor->user_id) { |
|
| 64 | 64 | |
| 65 | 65 | // Make sure we don't already have this user attached to a donor. |
| 66 | - if ( ! empty( $donor_info['user_id'] ) && false !== Give()->donors->get_donor_by( 'user_id', $donor_info['user_id'] ) ) { |
|
| 67 | - give_set_error( 'give-invalid-donor-user_id', sprintf( __( 'The User ID #%d is already associated with a different donor.', 'give' ), $donor_info['user_id'] ) ); |
|
| 66 | + if ( ! empty($donor_info['user_id']) && false !== Give()->donors->get_donor_by('user_id', $donor_info['user_id'])) { |
|
| 67 | + give_set_error('give-invalid-donor-user_id', sprintf(__('The User ID #%d is already associated with a different donor.', 'give'), $donor_info['user_id'])); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Make sure it's actually a user. |
| 71 | - $user = get_user_by( 'id', $donor_info['user_id'] ); |
|
| 72 | - if ( ! empty( $donor_info['user_id'] ) && false === $user ) { |
|
| 73 | - give_set_error( 'give-invalid-user_id', sprintf( __( 'The User ID #%d does not exist. Please assign an existing user.', 'give' ), $donor_info['user_id'] ) ); |
|
| 71 | + $user = get_user_by('id', $donor_info['user_id']); |
|
| 72 | + if ( ! empty($donor_info['user_id']) && false === $user) { |
|
| 73 | + give_set_error('give-invalid-user_id', sprintf(__('The User ID #%d does not exist. Please assign an existing user.', 'give'), $donor_info['user_id'])); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // Record this for later. |
| 78 | 78 | $previous_user_id = $donor->user_id; |
| 79 | 79 | |
| 80 | - if ( give_get_errors() ) { |
|
| 80 | + if (give_get_errors()) { |
|
| 81 | 81 | return false; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Setup the donor address, if present. |
| 85 | 85 | $address = array(); |
| 86 | - if ( intval( $donor_info['user_id'] ) > 0 ) { |
|
| 86 | + if (intval($donor_info['user_id']) > 0) { |
|
| 87 | 87 | |
| 88 | - $current_address = get_user_meta( $donor_info['user_id'], '_give_user_address', true ); |
|
| 88 | + $current_address = get_user_meta($donor_info['user_id'], '_give_user_address', true); |
|
| 89 | 89 | |
| 90 | - if ( false === $current_address ) { |
|
| 91 | - $address['line1'] = isset( $donor_info['line1'] ) ? $donor_info['line1'] : ''; |
|
| 92 | - $address['line2'] = isset( $donor_info['line2'] ) ? $donor_info['line2'] : ''; |
|
| 93 | - $address['city'] = isset( $donor_info['city'] ) ? $donor_info['city'] : ''; |
|
| 94 | - $address['country'] = isset( $donor_info['country'] ) ? $donor_info['country'] : ''; |
|
| 95 | - $address['zip'] = isset( $donor_info['zip'] ) ? $donor_info['zip'] : ''; |
|
| 96 | - $address['state'] = isset( $donor_info['state'] ) ? $donor_info['state'] : ''; |
|
| 90 | + if (false === $current_address) { |
|
| 91 | + $address['line1'] = isset($donor_info['line1']) ? $donor_info['line1'] : ''; |
|
| 92 | + $address['line2'] = isset($donor_info['line2']) ? $donor_info['line2'] : ''; |
|
| 93 | + $address['city'] = isset($donor_info['city']) ? $donor_info['city'] : ''; |
|
| 94 | + $address['country'] = isset($donor_info['country']) ? $donor_info['country'] : ''; |
|
| 95 | + $address['zip'] = isset($donor_info['zip']) ? $donor_info['zip'] : ''; |
|
| 96 | + $address['state'] = isset($donor_info['state']) ? $donor_info['state'] : ''; |
|
| 97 | 97 | } else { |
| 98 | - $current_address = wp_parse_args( $current_address, array( |
|
| 98 | + $current_address = wp_parse_args($current_address, array( |
|
| 99 | 99 | 'line1', |
| 100 | 100 | 'line2', |
| 101 | 101 | 'city', |
| 102 | 102 | 'zip', |
| 103 | 103 | 'state', |
| 104 | 104 | 'country', |
| 105 | - ) ); |
|
| 106 | - $address['line1'] = isset( $donor_info['line1'] ) ? $donor_info['line1'] : $current_address['line1']; |
|
| 107 | - $address['line2'] = isset( $donor_info['line2'] ) ? $donor_info['line2'] : $current_address['line2']; |
|
| 108 | - $address['city'] = isset( $donor_info['city'] ) ? $donor_info['city'] : $current_address['city']; |
|
| 109 | - $address['country'] = isset( $donor_info['country'] ) ? $donor_info['country'] : $current_address['country']; |
|
| 110 | - $address['zip'] = isset( $donor_info['zip'] ) ? $donor_info['zip'] : $current_address['zip']; |
|
| 111 | - $address['state'] = isset( $donor_info['state'] ) ? $donor_info['state'] : $current_address['state']; |
|
| 105 | + )); |
|
| 106 | + $address['line1'] = isset($donor_info['line1']) ? $donor_info['line1'] : $current_address['line1']; |
|
| 107 | + $address['line2'] = isset($donor_info['line2']) ? $donor_info['line2'] : $current_address['line2']; |
|
| 108 | + $address['city'] = isset($donor_info['city']) ? $donor_info['city'] : $current_address['city']; |
|
| 109 | + $address['country'] = isset($donor_info['country']) ? $donor_info['country'] : $current_address['country']; |
|
| 110 | + $address['zip'] = isset($donor_info['zip']) ? $donor_info['zip'] : $current_address['zip']; |
|
| 111 | + $address['state'] = isset($donor_info['state']) ? $donor_info['state'] : $current_address['state']; |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Sanitize the inputs |
| 116 | 116 | $donor_data = array(); |
| 117 | - $donor_data['name'] = strip_tags( stripslashes( $donor_info['name'] ) ); |
|
| 117 | + $donor_data['name'] = strip_tags(stripslashes($donor_info['name'])); |
|
| 118 | 118 | $donor_data['user_id'] = $donor_info['user_id']; |
| 119 | 119 | |
| 120 | - $donor_data = apply_filters( 'give_edit_donor_info', $donor_data, $donor_id ); |
|
| 121 | - $address = apply_filters( 'give_edit_donor_address', $address, $donor_id ); |
|
| 120 | + $donor_data = apply_filters('give_edit_donor_info', $donor_data, $donor_id); |
|
| 121 | + $address = apply_filters('give_edit_donor_address', $address, $donor_id); |
|
| 122 | 122 | |
| 123 | - $donor_data = array_map( 'sanitize_text_field', $donor_data ); |
|
| 124 | - $address = array_map( 'sanitize_text_field', $address ); |
|
| 123 | + $donor_data = array_map('sanitize_text_field', $donor_data); |
|
| 124 | + $address = array_map('sanitize_text_field', $address); |
|
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * Fires before editing a donor. |
@@ -132,27 +132,27 @@ discard block |
||
| 132 | 132 | * @param array $donor_data The donor data. |
| 133 | 133 | * @param array $address The donor's address. |
| 134 | 134 | */ |
| 135 | - do_action( 'give_pre_edit_donor', $donor_id, $donor_data, $address ); |
|
| 135 | + do_action('give_pre_edit_donor', $donor_id, $donor_data, $address); |
|
| 136 | 136 | |
| 137 | 137 | $output = array(); |
| 138 | 138 | |
| 139 | - if ( $donor->update( $donor_data ) ) { |
|
| 139 | + if ($donor->update($donor_data)) { |
|
| 140 | 140 | |
| 141 | - if ( ! empty( $donor->user_id ) && $donor->user_id > 0 ) { |
|
| 142 | - update_user_meta( $donor->user_id, '_give_user_address', $address ); |
|
| 141 | + if ( ! empty($donor->user_id) && $donor->user_id > 0) { |
|
| 142 | + update_user_meta($donor->user_id, '_give_user_address', $address); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // Update some donation meta if we need to. |
| 146 | - $payments_array = explode( ',', $donor->payment_ids ); |
|
| 146 | + $payments_array = explode(',', $donor->payment_ids); |
|
| 147 | 147 | |
| 148 | - if ( $donor->user_id != $previous_user_id ) { |
|
| 149 | - foreach ( $payments_array as $payment_id ) { |
|
| 150 | - give_update_payment_meta( $payment_id, '_give_payment_user_id', $donor->user_id ); |
|
| 148 | + if ($donor->user_id != $previous_user_id) { |
|
| 149 | + foreach ($payments_array as $payment_id) { |
|
| 150 | + give_update_payment_meta($payment_id, '_give_payment_user_id', $donor->user_id); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | $output['success'] = true; |
| 155 | - $donor_data = array_merge( $donor_data, $address ); |
|
| 155 | + $donor_data = array_merge($donor_data, $address); |
|
| 156 | 156 | $output['customer_info'] = $donor_data; |
| 157 | 157 | |
| 158 | 158 | } else { |
@@ -169,11 +169,11 @@ discard block |
||
| 169 | 169 | * @param int $donor_id The ID of the donor. |
| 170 | 170 | * @param array $donor_data The donor data. |
| 171 | 171 | */ |
| 172 | - do_action( 'give_post_edit_donor', $donor_id, $donor_data ); |
|
| 172 | + do_action('give_post_edit_donor', $donor_id, $donor_data); |
|
| 173 | 173 | |
| 174 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 175 | - header( 'Content-Type: application/json' ); |
|
| 176 | - echo json_encode( $output ); |
|
| 174 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 175 | + header('Content-Type: application/json'); |
|
| 176 | + echo json_encode($output); |
|
| 177 | 177 | wp_die(); |
| 178 | 178 | } |
| 179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | -add_action( 'give_edit-donor', 'give_edit_donor', 10, 1 ); |
|
| 184 | +add_action('give_edit-donor', 'give_edit_donor', 10, 1); |
|
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | 187 | * Save a donor note. |
@@ -192,40 +192,40 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @return int The Note ID that was saved, or 0 if nothing was saved. |
| 194 | 194 | */ |
| 195 | -function give_donor_save_note( $args ) { |
|
| 195 | +function give_donor_save_note($args) { |
|
| 196 | 196 | |
| 197 | - $donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' ); |
|
| 197 | + $donor_view_role = apply_filters('give_view_donors_role', 'view_give_reports'); |
|
| 198 | 198 | |
| 199 | - if ( ! is_admin() || ! current_user_can( $donor_view_role ) ) { |
|
| 200 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array( |
|
| 199 | + if ( ! is_admin() || ! current_user_can($donor_view_role)) { |
|
| 200 | + wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array( |
|
| 201 | 201 | 'response' => 403, |
| 202 | - ) ); |
|
| 202 | + )); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if ( empty( $args ) ) { |
|
| 205 | + if (empty($args)) { |
|
| 206 | 206 | return false; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $donor_note = trim( sanitize_text_field( $args['donor_note'] ) ); |
|
| 209 | + $donor_note = trim(sanitize_text_field($args['donor_note'])); |
|
| 210 | 210 | $donor_id = (int) $args['customer_id']; |
| 211 | 211 | $nonce = $args['add_donor_note_nonce']; |
| 212 | 212 | |
| 213 | - if ( ! wp_verify_nonce( $nonce, 'add-donor-note' ) ) { |
|
| 214 | - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array( |
|
| 213 | + if ( ! wp_verify_nonce($nonce, 'add-donor-note')) { |
|
| 214 | + wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array( |
|
| 215 | 215 | 'response' => 400, |
| 216 | - ) ); |
|
| 216 | + )); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if ( empty( $donor_note ) ) { |
|
| 220 | - give_set_error( 'empty-donor-note', __( 'A note is required.', 'give' ) ); |
|
| 219 | + if (empty($donor_note)) { |
|
| 220 | + give_set_error('empty-donor-note', __('A note is required.', 'give')); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( give_get_errors() ) { |
|
| 223 | + if (give_get_errors()) { |
|
| 224 | 224 | return false; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $donor = new Give_Donor( $donor_id ); |
|
| 228 | - $new_note = $donor->add_note( $donor_note ); |
|
| 227 | + $donor = new Give_Donor($donor_id); |
|
| 228 | + $new_note = $donor->add_note($donor_note); |
|
| 229 | 229 | |
| 230 | 230 | /** |
| 231 | 231 | * Fires before inserting donor note. |
@@ -235,22 +235,22 @@ discard block |
||
| 235 | 235 | * @param int $donor_id The ID of the donor. |
| 236 | 236 | * @param string $new_note Note content. |
| 237 | 237 | */ |
| 238 | - do_action( 'give_pre_insert_donor_note', $donor_id, $new_note ); |
|
| 238 | + do_action('give_pre_insert_donor_note', $donor_id, $new_note); |
|
| 239 | 239 | |
| 240 | - if ( ! empty( $new_note ) && ! empty( $donor->id ) ) { |
|
| 240 | + if ( ! empty($new_note) && ! empty($donor->id)) { |
|
| 241 | 241 | |
| 242 | 242 | ob_start(); |
| 243 | 243 | ?> |
| 244 | 244 | <div class="donor-note-wrapper dashboard-comment-wrap comment-item"> |
| 245 | 245 | <span class="note-content-wrap"> |
| 246 | - <?php echo stripslashes( $new_note ); ?> |
|
| 246 | + <?php echo stripslashes($new_note); ?> |
|
| 247 | 247 | </span> |
| 248 | 248 | </div> |
| 249 | 249 | <?php |
| 250 | 250 | $output = ob_get_contents(); |
| 251 | 251 | ob_end_clean(); |
| 252 | 252 | |
| 253 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 253 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 254 | 254 | echo $output; |
| 255 | 255 | exit; |
| 256 | 256 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | -add_action( 'give_add-donor-note', 'give_donor_save_note', 10, 1 ); |
|
| 266 | +add_action('give_add-donor-note', 'give_donor_save_note', 10, 1); |
|
| 267 | 267 | |
| 268 | 268 | /** |
| 269 | 269 | * Delete a donor. |
@@ -274,41 +274,41 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return int Whether it was a successful deletion. |
| 276 | 276 | */ |
| 277 | -function give_donor_delete( $args ) { |
|
| 277 | +function give_donor_delete($args) { |
|
| 278 | 278 | |
| 279 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
| 279 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
| 280 | 280 | |
| 281 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
| 282 | - wp_die( __( 'You do not have permission to delete donors.', 'give' ), __( 'Error', 'give' ), array( |
|
| 281 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
| 282 | + wp_die(__('You do not have permission to delete donors.', 'give'), __('Error', 'give'), array( |
|
| 283 | 283 | 'response' => 403, |
| 284 | - ) ); |
|
| 284 | + )); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if ( empty( $args ) ) { |
|
| 287 | + if (empty($args)) { |
|
| 288 | 288 | return false; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | $donor_id = (int) $args['customer_id']; |
| 292 | - $confirm = ! empty( $args['give-donor-delete-confirm'] ) ? true : false; |
|
| 293 | - $remove_data = ! empty( $args['give-donor-delete-records'] ) ? true : false; |
|
| 292 | + $confirm = ! empty($args['give-donor-delete-confirm']) ? true : false; |
|
| 293 | + $remove_data = ! empty($args['give-donor-delete-records']) ? true : false; |
|
| 294 | 294 | $nonce = $args['_wpnonce']; |
| 295 | 295 | |
| 296 | - if ( ! wp_verify_nonce( $nonce, 'delete-donor' ) ) { |
|
| 297 | - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array( |
|
| 296 | + if ( ! wp_verify_nonce($nonce, 'delete-donor')) { |
|
| 297 | + wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array( |
|
| 298 | 298 | 'response' => 400, |
| 299 | - ) ); |
|
| 299 | + )); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if ( ! $confirm ) { |
|
| 303 | - give_set_error( 'donor-delete-no-confirm', __( 'Please confirm you want to delete this donor.', 'give' ) ); |
|
| 302 | + if ( ! $confirm) { |
|
| 303 | + give_set_error('donor-delete-no-confirm', __('Please confirm you want to delete this donor.', 'give')); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( give_get_errors() ) { |
|
| 307 | - wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id ) ); |
|
| 306 | + if (give_get_errors()) { |
|
| 307 | + wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor_id)); |
|
| 308 | 308 | exit; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $donor = new Give_Donor( $donor_id ); |
|
| 311 | + $donor = new Give_Donor($donor_id); |
|
| 312 | 312 | |
| 313 | 313 | /** |
| 314 | 314 | * Fires before deleting donor. |
@@ -319,50 +319,50 @@ discard block |
||
| 319 | 319 | * @param bool $confirm Delete confirmation. |
| 320 | 320 | * @param bool $remove_data Records delete confirmation. |
| 321 | 321 | */ |
| 322 | - do_action( 'give_pre_delete_donor', $donor_id, $confirm, $remove_data ); |
|
| 322 | + do_action('give_pre_delete_donor', $donor_id, $confirm, $remove_data); |
|
| 323 | 323 | |
| 324 | - if ( $donor->id > 0 ) { |
|
| 324 | + if ($donor->id > 0) { |
|
| 325 | 325 | |
| 326 | - $payments_array = explode( ',', $donor->payment_ids ); |
|
| 327 | - $success = Give()->donors->delete( $donor->id ); |
|
| 326 | + $payments_array = explode(',', $donor->payment_ids); |
|
| 327 | + $success = Give()->donors->delete($donor->id); |
|
| 328 | 328 | |
| 329 | - if ( $success ) { |
|
| 329 | + if ($success) { |
|
| 330 | 330 | |
| 331 | - if ( $remove_data ) { |
|
| 331 | + if ($remove_data) { |
|
| 332 | 332 | |
| 333 | 333 | // Remove all donations, logs, etc |
| 334 | - foreach ( $payments_array as $payment_id ) { |
|
| 335 | - give_delete_donation( $payment_id ); |
|
| 334 | + foreach ($payments_array as $payment_id) { |
|
| 335 | + give_delete_donation($payment_id); |
|
| 336 | 336 | } |
| 337 | 337 | } else { |
| 338 | 338 | |
| 339 | 339 | // Just set the donations to customer_id of 0 |
| 340 | - foreach ( $payments_array as $payment_id ) { |
|
| 341 | - give_update_payment_meta( $payment_id, '_give_payment_customer_id', 0 ); |
|
| 340 | + foreach ($payments_array as $payment_id) { |
|
| 341 | + give_update_payment_meta($payment_id, '_give_payment_customer_id', 0); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&give-message=donor-deleted' ); |
|
| 345 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&give-message=donor-deleted'); |
|
| 346 | 346 | |
| 347 | 347 | } else { |
| 348 | 348 | |
| 349 | - give_set_error( 'give-donor-delete-failed', esc_html__( 'Error deleting donor.', 'give' ) ); |
|
| 350 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $donor_id ); |
|
| 349 | + give_set_error('give-donor-delete-failed', esc_html__('Error deleting donor.', 'give')); |
|
| 350 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=delete&id='.$donor_id); |
|
| 351 | 351 | |
| 352 | 352 | } |
| 353 | 353 | } else { |
| 354 | 354 | |
| 355 | - give_set_error( 'give-donor-delete-invalid-id', esc_html__( 'Invalid Donor ID.', 'give' ) ); |
|
| 356 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors' ); |
|
| 355 | + give_set_error('give-donor-delete-invalid-id', esc_html__('Invalid Donor ID.', 'give')); |
|
| 356 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors'); |
|
| 357 | 357 | |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - wp_redirect( $redirect ); |
|
| 360 | + wp_redirect($redirect); |
|
| 361 | 361 | exit; |
| 362 | 362 | |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | -add_action( 'give_delete-donor', 'give_donor_delete', 10, 1 ); |
|
| 365 | +add_action('give_delete-donor', 'give_donor_delete', 10, 1); |
|
| 366 | 366 | |
| 367 | 367 | /** |
| 368 | 368 | * Disconnect a user ID from a donor |
@@ -373,17 +373,17 @@ discard block |
||
| 373 | 373 | * |
| 374 | 374 | * @return bool|array If the disconnect was successful. |
| 375 | 375 | */ |
| 376 | -function give_disconnect_donor_user_id( $args ) { |
|
| 376 | +function give_disconnect_donor_user_id($args) { |
|
| 377 | 377 | |
| 378 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
| 378 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
| 379 | 379 | |
| 380 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
| 381 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array( |
|
| 380 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
| 381 | + wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array( |
|
| 382 | 382 | 'response' => 403, |
| 383 | - ) ); |
|
| 383 | + )); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - if ( empty( $args ) ) { |
|
| 386 | + if (empty($args)) { |
|
| 387 | 387 | return false; |
| 388 | 388 | } |
| 389 | 389 | |
@@ -391,14 +391,14 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | $nonce = $args['_wpnonce']; |
| 393 | 393 | |
| 394 | - if ( ! wp_verify_nonce( $nonce, 'edit-donor' ) ) { |
|
| 395 | - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array( |
|
| 394 | + if ( ! wp_verify_nonce($nonce, 'edit-donor')) { |
|
| 395 | + wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array( |
|
| 396 | 396 | 'response' => 400, |
| 397 | - ) ); |
|
| 397 | + )); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - $donor = new Give_Donor( $donor_id ); |
|
| 401 | - if ( empty( $donor->id ) ) { |
|
| 400 | + $donor = new Give_Donor($donor_id); |
|
| 401 | + if (empty($donor->id)) { |
|
| 402 | 402 | return false; |
| 403 | 403 | } |
| 404 | 404 | |
@@ -412,18 +412,18 @@ discard block |
||
| 412 | 412 | * @param int $donor_id The ID of the donor. |
| 413 | 413 | * @param int $user_id The ID of the user. |
| 414 | 414 | */ |
| 415 | - do_action( 'give_pre_donor_disconnect_user_id', $donor_id, $user_id ); |
|
| 415 | + do_action('give_pre_donor_disconnect_user_id', $donor_id, $user_id); |
|
| 416 | 416 | |
| 417 | 417 | $output = array(); |
| 418 | 418 | $donor_args = array( |
| 419 | 419 | 'user_id' => 0, |
| 420 | 420 | ); |
| 421 | 421 | |
| 422 | - if ( $donor->update( $donor_args ) ) { |
|
| 422 | + if ($donor->update($donor_args)) { |
|
| 423 | 423 | global $wpdb; |
| 424 | 424 | |
| 425 | - if ( ! empty( $donor->payment_ids ) ) { |
|
| 426 | - $wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $donor->payment_ids )" ); |
|
| 425 | + if ( ! empty($donor->payment_ids)) { |
|
| 426 | + $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $donor->payment_ids )"); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | $output['success'] = true; |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | } else { |
| 432 | 432 | |
| 433 | 433 | $output['success'] = false; |
| 434 | - give_set_error( 'give-disconnect-user-fail', __( 'Failed to disconnect user from donor.', 'give' ) ); |
|
| 434 | + give_set_error('give-disconnect-user-fail', __('Failed to disconnect user from donor.', 'give')); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -441,11 +441,11 @@ discard block |
||
| 441 | 441 | * |
| 442 | 442 | * @param int $donor_id The ID of the donor. |
| 443 | 443 | */ |
| 444 | - do_action( 'give_post_donor_disconnect_user_id', $donor_id ); |
|
| 444 | + do_action('give_post_donor_disconnect_user_id', $donor_id); |
|
| 445 | 445 | |
| 446 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 447 | - header( 'Content-Type: application/json' ); |
|
| 448 | - echo json_encode( $output ); |
|
| 446 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 447 | + header('Content-Type: application/json'); |
|
| 448 | + echo json_encode($output); |
|
| 449 | 449 | wp_die(); |
| 450 | 450 | } |
| 451 | 451 | |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | -add_action( 'give_disconnect-userid', 'give_disconnect_donor_user_id', 10, 1 ); |
|
| 456 | +add_action('give_disconnect-userid', 'give_disconnect_donor_user_id', 10, 1); |
|
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | 459 | * Add an email address to the donor from within the admin and log a donor note. |
@@ -464,90 +464,90 @@ discard block |
||
| 464 | 464 | * |
| 465 | 465 | * @return mixed If DOING_AJAX echos out JSON, otherwise returns array of success (bool) and message (string). |
| 466 | 466 | */ |
| 467 | -function give_add_donor_email( $args ) { |
|
| 467 | +function give_add_donor_email($args) { |
|
| 468 | 468 | /** |
| 469 | 469 | * Define variable |
| 470 | 470 | * |
| 471 | 471 | * @since 1.8.14 |
| 472 | 472 | */ |
| 473 | 473 | $donor_id = ''; |
| 474 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
| 474 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
| 475 | 475 | |
| 476 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
| 477 | - wp_die( esc_html__( 'You do not have permission to edit this donor.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
| 476 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
| 477 | + wp_die(esc_html__('You do not have permission to edit this donor.', 'give'), esc_html__('Error', 'give'), array( |
|
| 478 | 478 | 'response' => 403, |
| 479 | - ) ); |
|
| 479 | + )); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | $output = array(); |
| 483 | - if ( empty( $args ) || empty( $args['email'] ) || empty( $args['customer_id'] ) ) { |
|
| 483 | + if (empty($args) || empty($args['email']) || empty($args['customer_id'])) { |
|
| 484 | 484 | $output['success'] = false; |
| 485 | - if ( empty( $args['email'] ) ) { |
|
| 486 | - $output['message'] = __( 'Email address is required.', 'give' ); |
|
| 487 | - } elseif ( empty( $args['customer_id'] ) ) { |
|
| 488 | - $output['message'] = __( 'Donor ID is required.', 'give' ); |
|
| 485 | + if (empty($args['email'])) { |
|
| 486 | + $output['message'] = __('Email address is required.', 'give'); |
|
| 487 | + } elseif (empty($args['customer_id'])) { |
|
| 488 | + $output['message'] = __('Donor ID is required.', 'give'); |
|
| 489 | 489 | } else { |
| 490 | - $output['message'] = __( 'An error has occurred. Please try again.', 'give' ); |
|
| 490 | + $output['message'] = __('An error has occurred. Please try again.', 'give'); |
|
| 491 | 491 | } |
| 492 | - } elseif ( ! wp_verify_nonce( $args['_wpnonce'], 'give_add_donor_email' ) ) { |
|
| 492 | + } elseif ( ! wp_verify_nonce($args['_wpnonce'], 'give_add_donor_email')) { |
|
| 493 | 493 | $output = array( |
| 494 | 494 | 'success' => false, |
| 495 | - 'message' => esc_html__( 'Nonce verification failed.', 'give' ), |
|
| 495 | + 'message' => esc_html__('Nonce verification failed.', 'give'), |
|
| 496 | 496 | ); |
| 497 | - } elseif ( ! is_email( $args['email'] ) ) { |
|
| 497 | + } elseif ( ! is_email($args['email'])) { |
|
| 498 | 498 | $output = array( |
| 499 | 499 | 'success' => false, |
| 500 | - 'message' => esc_html__( 'Invalid email.', 'give' ), |
|
| 500 | + 'message' => esc_html__('Invalid email.', 'give'), |
|
| 501 | 501 | ); |
| 502 | 502 | } else { |
| 503 | - $email = sanitize_email( $args['email'] ); |
|
| 503 | + $email = sanitize_email($args['email']); |
|
| 504 | 504 | $donor_id = (int) $args['customer_id']; |
| 505 | 505 | $primary = 'true' === $args['primary'] ? true : false; |
| 506 | - $donor = new Give_Donor( $donor_id ); |
|
| 507 | - if ( false === $donor->add_email( $email, $primary ) ) { |
|
| 508 | - if ( in_array( $email, $donor->emails ) ) { |
|
| 506 | + $donor = new Give_Donor($donor_id); |
|
| 507 | + if (false === $donor->add_email($email, $primary)) { |
|
| 508 | + if (in_array($email, $donor->emails)) { |
|
| 509 | 509 | $output = array( |
| 510 | 510 | 'success' => false, |
| 511 | - 'message' => __( 'Email already associated with this donor.', 'give' ), |
|
| 511 | + 'message' => __('Email already associated with this donor.', 'give'), |
|
| 512 | 512 | ); |
| 513 | 513 | } else { |
| 514 | 514 | $output = array( |
| 515 | 515 | 'success' => false, |
| 516 | - 'message' => __( 'Email address is already associated with another donor.', 'give' ), |
|
| 516 | + 'message' => __('Email address is already associated with another donor.', 'give'), |
|
| 517 | 517 | ); |
| 518 | 518 | } |
| 519 | 519 | } else { |
| 520 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id . '&give-message=email-added' ); |
|
| 520 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor_id.'&give-message=email-added'); |
|
| 521 | 521 | $output = array( |
| 522 | 522 | 'success' => true, |
| 523 | - 'message' => __( 'Email successfully added to donor.', 'give' ), |
|
| 523 | + 'message' => __('Email successfully added to donor.', 'give'), |
|
| 524 | 524 | 'redirect' => $redirect, |
| 525 | 525 | ); |
| 526 | 526 | |
| 527 | 527 | $user = wp_get_current_user(); |
| 528 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' ); |
|
| 529 | - $donor_note = sprintf( __( 'Email address %1$s added by %2$s', 'give' ), $email, $user_login ); |
|
| 530 | - $donor->add_note( $donor_note ); |
|
| 528 | + $user_login = ! empty($user->user_login) ? $user->user_login : __('System', 'give'); |
|
| 529 | + $donor_note = sprintf(__('Email address %1$s added by %2$s', 'give'), $email, $user_login); |
|
| 530 | + $donor->add_note($donor_note); |
|
| 531 | 531 | |
| 532 | - if ( $primary ) { |
|
| 533 | - $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $email, $user_login ); |
|
| 534 | - $donor->add_note( $donor_note ); |
|
| 532 | + if ($primary) { |
|
| 533 | + $donor_note = sprintf(__('Email address %1$s set as primary by %2$s', 'give'), $email, $user_login); |
|
| 534 | + $donor->add_note($donor_note); |
|
| 535 | 535 | } |
| 536 | 536 | } |
| 537 | 537 | }// End if(). |
| 538 | 538 | |
| 539 | - do_action( 'give_post_add_donor_email', $donor_id, $args ); |
|
| 539 | + do_action('give_post_add_donor_email', $donor_id, $args); |
|
| 540 | 540 | |
| 541 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 542 | - header( 'Content-Type: application/json' ); |
|
| 543 | - echo json_encode( $output ); |
|
| 541 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 542 | + header('Content-Type: application/json'); |
|
| 543 | + echo json_encode($output); |
|
| 544 | 544 | wp_die(); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | return $output; |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | -add_action( 'give_add_donor_email', 'give_add_donor_email', 10, 1 ); |
|
| 550 | +add_action('give_add_donor_email', 'give_add_donor_email', 10, 1); |
|
| 551 | 551 | |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -557,39 +557,39 @@ discard block |
||
| 557 | 557 | * @return bool|null |
| 558 | 558 | */ |
| 559 | 559 | function give_remove_donor_email() { |
| 560 | - if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 560 | + if (empty($_GET['id']) || ! is_numeric($_GET['id'])) { |
|
| 561 | 561 | return false; |
| 562 | 562 | } |
| 563 | - if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) { |
|
| 563 | + if (empty($_GET['email']) || ! is_email($_GET['email'])) { |
|
| 564 | 564 | return false; |
| 565 | 565 | } |
| 566 | - if ( empty( $_GET['_wpnonce'] ) ) { |
|
| 566 | + if (empty($_GET['_wpnonce'])) { |
|
| 567 | 567 | return false; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | $nonce = $_GET['_wpnonce']; |
| 571 | - if ( ! wp_verify_nonce( $nonce, 'give-remove-donor-email' ) ) { |
|
| 572 | - wp_die( esc_html__( 'Nonce verification failed', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
| 571 | + if ( ! wp_verify_nonce($nonce, 'give-remove-donor-email')) { |
|
| 572 | + wp_die(esc_html__('Nonce verification failed', 'give'), esc_html__('Error', 'give'), array( |
|
| 573 | 573 | 'response' => 403, |
| 574 | - ) ); |
|
| 574 | + )); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - $donor = new Give_Donor( $_GET['id'] ); |
|
| 578 | - if ( $donor->remove_email( $_GET['email'] ) ) { |
|
| 579 | - $url = add_query_arg( 'give-message', 'email-removed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
| 577 | + $donor = new Give_Donor($_GET['id']); |
|
| 578 | + if ($donor->remove_email($_GET['email'])) { |
|
| 579 | + $url = add_query_arg('give-message', 'email-removed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
| 580 | 580 | $user = wp_get_current_user(); |
| 581 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' ); |
|
| 582 | - $donor_note = sprintf( __( 'Email address %1$s removed by %2$s', 'give' ), $_GET['email'], $user_login ); |
|
| 583 | - $donor->add_note( $donor_note ); |
|
| 581 | + $user_login = ! empty($user->user_login) ? $user->user_login : __('System', 'give'); |
|
| 582 | + $donor_note = sprintf(__('Email address %1$s removed by %2$s', 'give'), $_GET['email'], $user_login); |
|
| 583 | + $donor->add_note($donor_note); |
|
| 584 | 584 | } else { |
| 585 | - $url = add_query_arg( 'give-message', 'email-remove-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
| 585 | + $url = add_query_arg('give-message', 'email-remove-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - wp_safe_redirect( $url ); |
|
| 588 | + wp_safe_redirect($url); |
|
| 589 | 589 | exit; |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | -add_action( 'give_remove_donor_email', 'give_remove_donor_email', 10 ); |
|
| 592 | +add_action('give_remove_donor_email', 'give_remove_donor_email', 10); |
|
| 593 | 593 | |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -600,41 +600,41 @@ discard block |
||
| 600 | 600 | * @return bool|null |
| 601 | 601 | */ |
| 602 | 602 | function give_set_donor_primary_email() { |
| 603 | - if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 603 | + if (empty($_GET['id']) || ! is_numeric($_GET['id'])) { |
|
| 604 | 604 | return false; |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) { |
|
| 607 | + if (empty($_GET['email']) || ! is_email($_GET['email'])) { |
|
| 608 | 608 | return false; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - if ( empty( $_GET['_wpnonce'] ) ) { |
|
| 611 | + if (empty($_GET['_wpnonce'])) { |
|
| 612 | 612 | return false; |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | $nonce = $_GET['_wpnonce']; |
| 616 | 616 | |
| 617 | - if ( ! wp_verify_nonce( $nonce, 'give-set-donor-primary-email' ) ) { |
|
| 618 | - wp_die( esc_html__( 'Nonce verification failed', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
| 617 | + if ( ! wp_verify_nonce($nonce, 'give-set-donor-primary-email')) { |
|
| 618 | + wp_die(esc_html__('Nonce verification failed', 'give'), esc_html__('Error', 'give'), array( |
|
| 619 | 619 | 'response' => 403, |
| 620 | - ) ); |
|
| 620 | + )); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - $donor = new Give_Donor( $_GET['id'] ); |
|
| 623 | + $donor = new Give_Donor($_GET['id']); |
|
| 624 | 624 | |
| 625 | - if ( $donor->set_primary_email( $_GET['email'] ) ) { |
|
| 626 | - $url = add_query_arg( 'give-message', 'primary-email-updated', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
| 625 | + if ($donor->set_primary_email($_GET['email'])) { |
|
| 626 | + $url = add_query_arg('give-message', 'primary-email-updated', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
| 627 | 627 | $user = wp_get_current_user(); |
| 628 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : esc_html__( 'System', 'give' ); |
|
| 629 | - $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $_GET['email'], $user_login ); |
|
| 628 | + $user_login = ! empty($user->user_login) ? $user->user_login : esc_html__('System', 'give'); |
|
| 629 | + $donor_note = sprintf(__('Email address %1$s set as primary by %2$s', 'give'), $_GET['email'], $user_login); |
|
| 630 | 630 | |
| 631 | - $donor->add_note( $donor_note ); |
|
| 631 | + $donor->add_note($donor_note); |
|
| 632 | 632 | } else { |
| 633 | - $url = add_query_arg( 'give-message', 'primary-email-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
| 633 | + $url = add_query_arg('give-message', 'primary-email-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | - wp_safe_redirect( $url ); |
|
| 636 | + wp_safe_redirect($url); |
|
| 637 | 637 | exit; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | -add_action( 'give_set_donor_primary_email', 'give_set_donor_primary_email', 10 ); |
|
| 640 | +add_action('give_set_donor_primary_email', 'give_set_donor_primary_email', 10); |
|
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | * @access public |
| 50 | 50 | * @since 1.5 |
| 51 | 51 | * |
| 52 | - * @return array $data The data for the CSV file |
|
| 52 | + * @return boolean $data The data for the CSV file |
|
| 53 | 53 | */ |
| 54 | 54 | public function get_data() { |
| 55 | 55 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -57,32 +57,32 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | $args = array( |
| 59 | 59 | 'number' => $this->per_step, |
| 60 | - 'offset' => $this->per_step * ( $this->step - 1 ), |
|
| 60 | + 'offset' => $this->per_step * ($this->step - 1), |
|
| 61 | 61 | 'orderby' => 'id', |
| 62 | 62 | 'order' => 'DESC', |
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | - $donors = Give()->donors->get_donors( $args ); |
|
| 65 | + $donors = Give()->donors->get_donors($args); |
|
| 66 | 66 | |
| 67 | - if ( $donors ) { |
|
| 67 | + if ($donors) { |
|
| 68 | 68 | |
| 69 | - $allowed_payment_status = apply_filters( 'give_recount_donors_donation_statuses', give_get_payment_status_keys() ); |
|
| 69 | + $allowed_payment_status = apply_filters('give_recount_donors_donation_statuses', give_get_payment_status_keys()); |
|
| 70 | 70 | |
| 71 | - foreach ( $donors as $donor ) { |
|
| 71 | + foreach ($donors as $donor) { |
|
| 72 | 72 | |
| 73 | - $attached_payment_ids = explode( ',', $donor->payment_ids ); |
|
| 73 | + $attached_payment_ids = explode(',', $donor->payment_ids); |
|
| 74 | 74 | |
| 75 | 75 | $attached_args = array( |
| 76 | 76 | 'post__in' => $attached_payment_ids, |
| 77 | - 'number' => - 1, |
|
| 77 | + 'number' => -1, |
|
| 78 | 78 | 'status' => $allowed_payment_status, |
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | - $attached_payments = (array) give_get_payments( $attached_args ); |
|
| 81 | + $attached_payments = (array) give_get_payments($attached_args); |
|
| 82 | 82 | |
| 83 | 83 | $unattached_args = array( |
| 84 | 84 | 'post__not_in' => $attached_payment_ids, |
| 85 | - 'number' => - 1, |
|
| 85 | + 'number' => -1, |
|
| 86 | 86 | 'status' => $allowed_payment_status, |
| 87 | 87 | 'meta_query' => array( |
| 88 | 88 | array( |
@@ -93,29 +93,29 @@ discard block |
||
| 93 | 93 | ), |
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | - $unattached_payments = give_get_payments( $unattached_args ); |
|
| 96 | + $unattached_payments = give_get_payments($unattached_args); |
|
| 97 | 97 | |
| 98 | - $payments = array_merge( $attached_payments, $unattached_payments ); |
|
| 98 | + $payments = array_merge($attached_payments, $unattached_payments); |
|
| 99 | 99 | |
| 100 | 100 | $purchase_value = 0.00; |
| 101 | 101 | $purchase_count = 0; |
| 102 | 102 | $payment_ids = array(); |
| 103 | 103 | |
| 104 | - if ( $payments ) { |
|
| 104 | + if ($payments) { |
|
| 105 | 105 | |
| 106 | - foreach ( $payments as $payment ) { |
|
| 106 | + foreach ($payments as $payment) { |
|
| 107 | 107 | |
| 108 | 108 | $should_process_payment = 'publish' == $payment->post_status ? true : false; |
| 109 | - $should_process_payment = apply_filters( 'give_donor_recount_should_process_donation', $should_process_payment, $payment ); |
|
| 109 | + $should_process_payment = apply_filters('give_donor_recount_should_process_donation', $should_process_payment, $payment); |
|
| 110 | 110 | |
| 111 | - if ( true === $should_process_payment ) { |
|
| 111 | + if (true === $should_process_payment) { |
|
| 112 | 112 | |
| 113 | - if ( apply_filters( 'give_donor_recount_should_increase_value', true, $payment ) ) { |
|
| 114 | - $purchase_value += give_get_payment_amount( $payment->ID ); |
|
| 113 | + if (apply_filters('give_donor_recount_should_increase_value', true, $payment)) { |
|
| 114 | + $purchase_value += give_get_payment_amount($payment->ID); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if ( apply_filters( 'give_donor_recount_should_increase_count', true, $payment ) ) { |
|
| 118 | - $purchase_count ++; |
|
| 117 | + if (apply_filters('give_donor_recount_should_increase_count', true, $payment)) { |
|
| 118 | + $purchase_count++; |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - $payment_ids = implode( ',', $payment_ids ); |
|
| 126 | + $payment_ids = implode(',', $payment_ids); |
|
| 127 | 127 | |
| 128 | 128 | $donor_update_data = array( |
| 129 | 129 | 'purchase_count' => $purchase_count, |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | 'payment_ids' => $payment_ids, |
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | - $donor_instance = new Give_Donor( $donor->id ); |
|
| 135 | - $donor_instance->update( $donor_update_data ); |
|
| 134 | + $donor_instance = new Give_Donor($donor->id); |
|
| 135 | + $donor_instance->update($donor_update_data); |
|
| 136 | 136 | |
| 137 | 137 | }// End foreach(). |
| 138 | 138 | |
@@ -152,21 +152,21 @@ discard block |
||
| 152 | 152 | public function get_percentage_complete() { |
| 153 | 153 | |
| 154 | 154 | $args = array( |
| 155 | - 'number' => - 1, |
|
| 155 | + 'number' => -1, |
|
| 156 | 156 | 'orderby' => 'id', |
| 157 | 157 | 'order' => 'DESC', |
| 158 | 158 | ); |
| 159 | 159 | |
| 160 | - $donors = Give()->donors->get_donors( $args ); |
|
| 161 | - $total = count( $donors ); |
|
| 160 | + $donors = Give()->donors->get_donors($args); |
|
| 161 | + $total = count($donors); |
|
| 162 | 162 | |
| 163 | 163 | $percentage = 100; |
| 164 | 164 | |
| 165 | - if ( $total > 0 ) { |
|
| 166 | - $percentage = ( ( $this->per_step * $this->step ) / $total ) * 100; |
|
| 165 | + if ($total > 0) { |
|
| 166 | + $percentage = (($this->per_step * $this->step) / $total) * 100; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ( $percentage > 100 ) { |
|
| 169 | + if ($percentage > 100) { |
|
| 170 | 170 | $percentage = 100; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @param array $request The Form Data passed into the batch processing |
| 182 | 182 | */ |
| 183 | - public function set_properties( $request ) { |
|
| 183 | + public function set_properties($request) { |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -191,21 +191,21 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function process_step() { |
| 193 | 193 | |
| 194 | - if ( ! $this->can_export() ) { |
|
| 195 | - wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
| 194 | + if ( ! $this->can_export()) { |
|
| 195 | + wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array( |
|
| 196 | 196 | 'response' => 403, |
| 197 | - ) ); |
|
| 197 | + )); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | $had_data = $this->get_data(); |
| 201 | 201 | |
| 202 | - if ( $had_data ) { |
|
| 202 | + if ($had_data) { |
|
| 203 | 203 | $this->done = false; |
| 204 | 204 | |
| 205 | 205 | return true; |
| 206 | 206 | } else { |
| 207 | 207 | $this->done = true; |
| 208 | - $this->message = esc_html__( 'Donor stats have been successfully recounted.', 'give' ); |
|
| 208 | + $this->message = esc_html__('Donor stats have been successfully recounted.', 'give'); |
|
| 209 | 209 | |
| 210 | 210 | return false; |
| 211 | 211 | } |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | * Headers |
| 216 | 216 | */ |
| 217 | 217 | public function headers() { |
| 218 | - ignore_user_abort( true ); |
|
| 218 | + ignore_user_abort(true); |
|
| 219 | 219 | |
| 220 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
| 221 | - set_time_limit( 0 ); |
|
| 220 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
| 221 | + set_time_limit(0); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * |
| 217 | 217 | * @access public |
| 218 | 218 | * @since 1.1 |
| 219 | - * @return array |
|
| 219 | + * @return string |
|
| 220 | 220 | */ |
| 221 | 221 | public function get_versions() { |
| 222 | 222 | return $this->versions; |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @uses Give_API::invalid_key() |
| 303 | 303 | * @uses Give_API::invalid_auth() |
| 304 | 304 | * @since 1.1 |
| 305 | - * @return bool |
|
| 305 | + * @return false|null |
|
| 306 | 306 | */ |
| 307 | 307 | private function validate_request() { |
| 308 | 308 | global $wp_query; |
@@ -694,7 +694,7 @@ discard block |
||
| 694 | 694 | * |
| 695 | 695 | * @param array $args Arguments to override defaults |
| 696 | 696 | * |
| 697 | - * @return array $dates |
|
| 697 | + * @return integer|null $dates |
|
| 698 | 698 | */ |
| 699 | 699 | public function get_dates( $args = array() ) { |
| 700 | 700 | $dates = array(); |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly. |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -141,27 +141,27 @@ discard block |
||
| 141 | 141 | 'v1' => 'GIVE_API_V1', |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - foreach ( $this->get_versions() as $version => $class ) { |
|
| 145 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
| 144 | + foreach ($this->get_versions() as $version => $class) { |
|
| 145 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
| 149 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
| 150 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
| 151 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
| 152 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
| 153 | - add_action( 'personal_options_update', array( $this, 'generate_api_key' ) ); |
|
| 154 | - add_action( 'edit_user_profile_update', array( $this, 'generate_api_key' ) ); |
|
| 155 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
| 148 | + add_action('init', array($this, 'add_endpoint')); |
|
| 149 | + add_action('wp', array($this, 'process_query'), - 1); |
|
| 150 | + add_filter('query_vars', array($this, 'query_vars')); |
|
| 151 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
| 152 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
| 153 | + add_action('personal_options_update', array($this, 'generate_api_key')); |
|
| 154 | + add_action('edit_user_profile_update', array($this, 'generate_api_key')); |
|
| 155 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
| 156 | 156 | |
| 157 | 157 | // Setup a backwards compatibility check for user API Keys |
| 158 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
| 158 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
| 159 | 159 | |
| 160 | 160 | // Determine if JSON_PRETTY_PRINT is available |
| 161 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
| 161 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
| 162 | 162 | |
| 163 | 163 | // Allow API request logging to be turned off |
| 164 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
| 164 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
| 165 | 165 | |
| 166 | 166 | // Setup Give_Payment_Stats instance |
| 167 | 167 | $this->stats = new Give_Payment_Stats(); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * @since 1.1 |
| 177 | 177 | */ |
| 178 | 178 | public function add_endpoint() { |
| 179 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
| 179 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @return string[] $vars New query vars |
| 191 | 191 | */ |
| 192 | - public function query_vars( $vars ) { |
|
| 192 | + public function query_vars($vars) { |
|
| 193 | 193 | |
| 194 | 194 | $vars[] = 'token'; |
| 195 | 195 | $vars[] = 'key'; |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function get_default_version() { |
| 242 | 242 | |
| 243 | - $version = get_option( 'give_default_api_version' ); |
|
| 243 | + $version = get_option('give_default_api_version'); |
|
| 244 | 244 | |
| 245 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
| 245 | + if (defined('GIVE_API_VERSION')) { |
|
| 246 | 246 | $version = GIVE_API_VERSION; |
| 247 | - } elseif ( ! $version ) { |
|
| 247 | + } elseif ( ! $version) { |
|
| 248 | 248 | $version = 'v1'; |
| 249 | 249 | } |
| 250 | 250 | |
@@ -265,14 +265,14 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | $version = $wp_query->query_vars['give-api']; |
| 267 | 267 | |
| 268 | - if ( strpos( $version, '/' ) ) { |
|
| 268 | + if (strpos($version, '/')) { |
|
| 269 | 269 | |
| 270 | - $version = explode( '/', $version ); |
|
| 271 | - $version = strtolower( $version[0] ); |
|
| 270 | + $version = explode('/', $version); |
|
| 271 | + $version = strtolower($version[0]); |
|
| 272 | 272 | |
| 273 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
| 273 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
| 274 | 274 | |
| 275 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
| 275 | + if (array_key_exists($version, $this->versions)) { |
|
| 276 | 276 | |
| 277 | 277 | $this->queried_version = $version; |
| 278 | 278 | |
@@ -308,16 +308,16 @@ discard block |
||
| 308 | 308 | $this->override = false; |
| 309 | 309 | |
| 310 | 310 | // Make sure we have both user and api key |
| 311 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] !== 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
| 311 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] !== 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
| 312 | 312 | |
| 313 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
| 313 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
| 314 | 314 | $this->missing_auth(); |
| 315 | 315 | |
| 316 | 316 | return false; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Retrieve the user by public API key and ensure they exist |
| 320 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
| 320 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
| 321 | 321 | |
| 322 | 322 | $this->invalid_key(); |
| 323 | 323 | |
@@ -325,11 +325,11 @@ discard block |
||
| 325 | 325 | |
| 326 | 326 | } else { |
| 327 | 327 | |
| 328 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
| 329 | - $secret = $this->get_user_secret_key( $user ); |
|
| 330 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
| 328 | + $token = urldecode($wp_query->query_vars['token']); |
|
| 329 | + $secret = $this->get_user_secret_key($user); |
|
| 330 | + $public = urldecode($wp_query->query_vars['key']); |
|
| 331 | 331 | |
| 332 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
| 332 | + if (hash_equals(md5($secret.$public), $token)) { |
|
| 333 | 333 | $this->is_valid_request = true; |
| 334 | 334 | } else { |
| 335 | 335 | $this->invalid_auth(); |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | } |
| 341 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] === 'forms' ) { |
|
| 341 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] === 'forms') { |
|
| 342 | 342 | $this->is_valid_request = true; |
| 343 | - $wp_query->set( 'key', 'public' ); |
|
| 343 | + $wp_query->set('key', 'public'); |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
@@ -356,25 +356,25 @@ discard block |
||
| 356 | 356 | * |
| 357 | 357 | * @return bool if user ID is found, false otherwise |
| 358 | 358 | */ |
| 359 | - public function get_user( $key = '' ) { |
|
| 359 | + public function get_user($key = '') { |
|
| 360 | 360 | global $wpdb, $wp_query; |
| 361 | 361 | |
| 362 | - if ( empty( $key ) ) { |
|
| 363 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
| 362 | + if (empty($key)) { |
|
| 363 | + $key = urldecode($wp_query->query_vars['key']); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - if ( empty( $key ) ) { |
|
| 366 | + if (empty($key)) { |
|
| 367 | 367 | return false; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $user = Give_Cache::get( md5( 'give_api_user_' . $key ), true ); |
|
| 370 | + $user = Give_Cache::get(md5('give_api_user_'.$key), true); |
|
| 371 | 371 | |
| 372 | - if ( false === $user ) { |
|
| 373 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
| 374 | - Give_Cache::set( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS, true ); |
|
| 372 | + if (false === $user) { |
|
| 373 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
| 374 | + Give_Cache::set(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS, true); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if ( $user != null ) { |
|
| 377 | + if ($user != null) { |
|
| 378 | 378 | $this->user_id = $user; |
| 379 | 379 | |
| 380 | 380 | return $user; |
@@ -390,19 +390,19 @@ discard block |
||
| 390 | 390 | * |
| 391 | 391 | * @return mixed|null|string |
| 392 | 392 | */ |
| 393 | - public function get_user_public_key( $user_id = 0 ) { |
|
| 393 | + public function get_user_public_key($user_id = 0) { |
|
| 394 | 394 | global $wpdb; |
| 395 | 395 | |
| 396 | - if ( empty( $user_id ) ) { |
|
| 396 | + if (empty($user_id)) { |
|
| 397 | 397 | return ''; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
| 401 | - $user_public_key = Give_Cache::get( $cache_key, true ); |
|
| 400 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
| 401 | + $user_public_key = Give_Cache::get($cache_key, true); |
|
| 402 | 402 | |
| 403 | - if ( empty( $user_public_key ) ) { |
|
| 404 | - $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) ); |
|
| 405 | - Give_Cache::set( $cache_key, $user_public_key, HOUR_IN_SECONDS, true ); |
|
| 403 | + if (empty($user_public_key)) { |
|
| 404 | + $user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id)); |
|
| 405 | + Give_Cache::set($cache_key, $user_public_key, HOUR_IN_SECONDS, true); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | return $user_public_key; |
@@ -415,19 +415,19 @@ discard block |
||
| 415 | 415 | * |
| 416 | 416 | * @return mixed|null|string |
| 417 | 417 | */ |
| 418 | - public function get_user_secret_key( $user_id = 0 ) { |
|
| 418 | + public function get_user_secret_key($user_id = 0) { |
|
| 419 | 419 | global $wpdb; |
| 420 | 420 | |
| 421 | - if ( empty( $user_id ) ) { |
|
| 421 | + if (empty($user_id)) { |
|
| 422 | 422 | return ''; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
| 426 | - $user_secret_key = Give_Cache::get( $cache_key, true ); |
|
| 425 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
| 426 | + $user_secret_key = Give_Cache::get($cache_key, true); |
|
| 427 | 427 | |
| 428 | - if ( empty( $user_secret_key ) ) { |
|
| 429 | - $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) ); |
|
| 430 | - Give_Cache::set( $cache_key, $user_secret_key, HOUR_IN_SECONDS, true ); |
|
| 428 | + if (empty($user_secret_key)) { |
|
| 429 | + $user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id)); |
|
| 430 | + Give_Cache::set($cache_key, $user_secret_key, HOUR_IN_SECONDS, true); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | return $user_secret_key; |
@@ -443,10 +443,10 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | private function missing_auth() { |
| 445 | 445 | $error = array(); |
| 446 | - $error['error'] = __( 'You must specify both a token and API key.', 'give' ); |
|
| 446 | + $error['error'] = __('You must specify both a token and API key.', 'give'); |
|
| 447 | 447 | |
| 448 | 448 | $this->data = $error; |
| 449 | - $this->output( 401 ); |
|
| 449 | + $this->output(401); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -460,10 +460,10 @@ discard block |
||
| 460 | 460 | */ |
| 461 | 461 | private function invalid_auth() { |
| 462 | 462 | $error = array(); |
| 463 | - $error['error'] = __( 'Your request could not be authenticated.', 'give' ); |
|
| 463 | + $error['error'] = __('Your request could not be authenticated.', 'give'); |
|
| 464 | 464 | |
| 465 | 465 | $this->data = $error; |
| 466 | - $this->output( 403 ); |
|
| 466 | + $this->output(403); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | */ |
| 478 | 478 | private function invalid_key() { |
| 479 | 479 | $error = array(); |
| 480 | - $error['error'] = __( 'Invalid API key.', 'give' ); |
|
| 480 | + $error['error'] = __('Invalid API key.', 'give'); |
|
| 481 | 481 | |
| 482 | 482 | $this->data = $error; |
| 483 | - $this->output( 403 ); |
|
| 483 | + $this->output(403); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -493,10 +493,10 @@ discard block |
||
| 493 | 493 | */ |
| 494 | 494 | private function invalid_version() { |
| 495 | 495 | $error = array(); |
| 496 | - $error['error'] = __( 'Invalid API version.', 'give' ); |
|
| 496 | + $error['error'] = __('Invalid API version.', 'give'); |
|
| 497 | 497 | |
| 498 | 498 | $this->data = $error; |
| 499 | - $this->output( 404 ); |
|
| 499 | + $this->output(404); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -512,10 +512,10 @@ discard block |
||
| 512 | 512 | global $wp_query; |
| 513 | 513 | |
| 514 | 514 | // Start logging how long the request takes for logging |
| 515 | - $before = microtime( true ); |
|
| 515 | + $before = microtime(true); |
|
| 516 | 516 | |
| 517 | 517 | // Check for give-api var. Get out if not present |
| 518 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
| 518 | + if (empty($wp_query->query_vars['give-api'])) { |
|
| 519 | 519 | return; |
| 520 | 520 | } |
| 521 | 521 | |
@@ -529,45 +529,45 @@ discard block |
||
| 529 | 529 | $this->validate_request(); |
| 530 | 530 | |
| 531 | 531 | // Only proceed if no errors have been noted |
| 532 | - if ( ! $this->is_valid_request ) { |
|
| 532 | + if ( ! $this->is_valid_request) { |
|
| 533 | 533 | return; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
| 537 | - define( 'GIVE_DOING_API', true ); |
|
| 536 | + if ( ! defined('GIVE_DOING_API')) { |
|
| 537 | + define('GIVE_DOING_API', true); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | $data = array(); |
| 541 | 541 | $this->routes = new $this->versions[$this->get_queried_version()]; |
| 542 | 542 | $this->routes->validate_request(); |
| 543 | 543 | |
| 544 | - switch ( $this->endpoint ) : |
|
| 544 | + switch ($this->endpoint) : |
|
| 545 | 545 | |
| 546 | 546 | case 'stats' : |
| 547 | 547 | |
| 548 | - $data = $this->routes->get_stats( array( |
|
| 549 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 550 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 551 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 552 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 553 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 554 | - ) ); |
|
| 548 | + $data = $this->routes->get_stats(array( |
|
| 549 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 550 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 551 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 552 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 553 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 554 | + )); |
|
| 555 | 555 | |
| 556 | 556 | break; |
| 557 | 557 | |
| 558 | 558 | case 'forms' : |
| 559 | 559 | |
| 560 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
| 560 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
| 561 | 561 | |
| 562 | - $data = $this->routes->get_forms( $form ); |
|
| 562 | + $data = $this->routes->get_forms($form); |
|
| 563 | 563 | |
| 564 | 564 | break; |
| 565 | 565 | |
| 566 | 566 | case 'donors' : |
| 567 | 567 | |
| 568 | - $donor = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
| 568 | + $donor = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
| 569 | 569 | |
| 570 | - $data = $this->routes->get_donors( $donor ); |
|
| 570 | + $data = $this->routes->get_donors($donor); |
|
| 571 | 571 | |
| 572 | 572 | break; |
| 573 | 573 | |
@@ -580,26 +580,26 @@ discard block |
||
| 580 | 580 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 581 | 581 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 582 | 582 | */ |
| 583 | - $data = $this->routes->get_recent_donations( array( |
|
| 584 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
| 585 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 586 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 587 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 588 | - ) ); |
|
| 583 | + $data = $this->routes->get_recent_donations(array( |
|
| 584 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
| 585 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 586 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 587 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 588 | + )); |
|
| 589 | 589 | |
| 590 | 590 | break; |
| 591 | 591 | |
| 592 | 592 | endswitch; |
| 593 | 593 | |
| 594 | 594 | // Allow extensions to setup their own return data |
| 595 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
| 595 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
| 596 | 596 | |
| 597 | - $after = microtime( true ); |
|
| 598 | - $request_time = ( $after - $before ); |
|
| 597 | + $after = microtime(true); |
|
| 598 | + $request_time = ($after - $before); |
|
| 599 | 599 | $this->data['request_speed'] = $request_time; |
| 600 | 600 | |
| 601 | 601 | // Log this API request, if enabled. We log it here because we have access to errors. |
| 602 | - $this->log_request( $this->data ); |
|
| 602 | + $this->log_request($this->data); |
|
| 603 | 603 | |
| 604 | 604 | // Send out data to the output function |
| 605 | 605 | $this->output(); |
@@ -629,25 +629,25 @@ discard block |
||
| 629 | 629 | global $wp_query; |
| 630 | 630 | |
| 631 | 631 | // Whitelist our query options |
| 632 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
| 632 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
| 633 | 633 | 'stats', |
| 634 | 634 | 'forms', |
| 635 | 635 | 'donors', |
| 636 | 636 | 'donations', |
| 637 | - ) ); |
|
| 637 | + )); |
|
| 638 | 638 | |
| 639 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
| 640 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
| 639 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
| 640 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
| 641 | 641 | |
| 642 | 642 | $error = array(); |
| 643 | 643 | |
| 644 | 644 | // Make sure our query is valid |
| 645 | - if ( ! in_array( $query, $accepted ) ) { |
|
| 646 | - $error['error'] = __( 'Invalid query.', 'give' ); |
|
| 645 | + if ( ! in_array($query, $accepted)) { |
|
| 646 | + $error['error'] = __('Invalid query.', 'give'); |
|
| 647 | 647 | |
| 648 | 648 | $this->data = $error; |
| 649 | 649 | // 400 is Bad Request |
| 650 | - $this->output( 400 ); |
|
| 650 | + $this->output(400); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | $this->endpoint = $query; |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | public function get_paged() { |
| 665 | 665 | global $wp_query; |
| 666 | 666 | |
| 667 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
| 667 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | |
@@ -679,13 +679,13 @@ discard block |
||
| 679 | 679 | public function per_page() { |
| 680 | 680 | global $wp_query; |
| 681 | 681 | |
| 682 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
| 682 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
| 683 | 683 | |
| 684 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
| 684 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
| 685 | 685 | $per_page = 99999999; |
| 686 | 686 | } // End if(). |
| 687 | 687 | |
| 688 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
| 688 | + return apply_filters('give_api_results_per_page', $per_page); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | * |
| 699 | 699 | * @return array $dates |
| 700 | 700 | */ |
| 701 | - public function get_dates( $args = array() ) { |
|
| 701 | + public function get_dates($args = array()) { |
|
| 702 | 702 | $dates = array(); |
| 703 | 703 | |
| 704 | 704 | $defaults = array( |
@@ -709,60 +709,60 @@ discard block |
||
| 709 | 709 | 'enddate' => null, |
| 710 | 710 | ); |
| 711 | 711 | |
| 712 | - $args = wp_parse_args( $args, $defaults ); |
|
| 712 | + $args = wp_parse_args($args, $defaults); |
|
| 713 | 713 | |
| 714 | - $current_time = current_time( 'timestamp' ); |
|
| 714 | + $current_time = current_time('timestamp'); |
|
| 715 | 715 | |
| 716 | - if ( 'range' === $args['date'] ) { |
|
| 717 | - $startdate = strtotime( $args['startdate'] ); |
|
| 718 | - $enddate = strtotime( $args['enddate'] ); |
|
| 719 | - $dates['day_start'] = date( 'd', $startdate ); |
|
| 720 | - $dates['day_end'] = date( 'd', $enddate ); |
|
| 721 | - $dates['m_start'] = date( 'n', $startdate ); |
|
| 722 | - $dates['m_end'] = date( 'n', $enddate ); |
|
| 723 | - $dates['year'] = date( 'Y', $startdate ); |
|
| 724 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
| 716 | + if ('range' === $args['date']) { |
|
| 717 | + $startdate = strtotime($args['startdate']); |
|
| 718 | + $enddate = strtotime($args['enddate']); |
|
| 719 | + $dates['day_start'] = date('d', $startdate); |
|
| 720 | + $dates['day_end'] = date('d', $enddate); |
|
| 721 | + $dates['m_start'] = date('n', $startdate); |
|
| 722 | + $dates['m_end'] = date('n', $enddate); |
|
| 723 | + $dates['year'] = date('Y', $startdate); |
|
| 724 | + $dates['year_end'] = date('Y', $enddate); |
|
| 725 | 725 | } else { |
| 726 | 726 | // Modify dates based on predefined ranges |
| 727 | - switch ( $args['date'] ) : |
|
| 727 | + switch ($args['date']) : |
|
| 728 | 728 | |
| 729 | 729 | case 'this_month' : |
| 730 | 730 | $dates['day'] = null; |
| 731 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 732 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 733 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 731 | + $dates['m_start'] = date('n', $current_time); |
|
| 732 | + $dates['m_end'] = date('n', $current_time); |
|
| 733 | + $dates['year'] = date('Y', $current_time); |
|
| 734 | 734 | break; |
| 735 | 735 | |
| 736 | 736 | case 'last_month' : |
| 737 | 737 | $dates['day'] = null; |
| 738 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
| 738 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
| 739 | 739 | $dates['m_end'] = $dates['m_start']; |
| 740 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
| 740 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
| 741 | 741 | break; |
| 742 | 742 | |
| 743 | 743 | case 'today' : |
| 744 | - $dates['day'] = date( 'd', $current_time ); |
|
| 745 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 746 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 747 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 744 | + $dates['day'] = date('d', $current_time); |
|
| 745 | + $dates['m_start'] = date('n', $current_time); |
|
| 746 | + $dates['m_end'] = date('n', $current_time); |
|
| 747 | + $dates['year'] = date('Y', $current_time); |
|
| 748 | 748 | break; |
| 749 | 749 | |
| 750 | 750 | case 'yesterday' : |
| 751 | 751 | |
| 752 | - $year = date( 'Y', $current_time ); |
|
| 753 | - $month = date( 'n', $current_time ); |
|
| 754 | - $day = date( 'd', $current_time ); |
|
| 752 | + $year = date('Y', $current_time); |
|
| 753 | + $month = date('n', $current_time); |
|
| 754 | + $day = date('d', $current_time); |
|
| 755 | 755 | |
| 756 | - if ( $month == 1 && $day == 1 ) { |
|
| 756 | + if ($month == 1 && $day == 1) { |
|
| 757 | 757 | |
| 758 | - $year -= 1; |
|
| 758 | + $year -= 1; |
|
| 759 | 759 | $month = 12; |
| 760 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 760 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 761 | 761 | |
| 762 | - } elseif ( $month > 1 && $day == 1 ) { |
|
| 762 | + } elseif ($month > 1 && $day == 1) { |
|
| 763 | 763 | |
| 764 | 764 | $month -= 1; |
| 765 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 765 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 766 | 766 | |
| 767 | 767 | } else { |
| 768 | 768 | |
@@ -778,65 +778,65 @@ discard block |
||
| 778 | 778 | break; |
| 779 | 779 | |
| 780 | 780 | case 'this_quarter' : |
| 781 | - $month_now = date( 'n', $current_time ); |
|
| 781 | + $month_now = date('n', $current_time); |
|
| 782 | 782 | |
| 783 | 783 | $dates['day'] = null; |
| 784 | 784 | |
| 785 | - if ( $month_now <= 3 ) { |
|
| 785 | + if ($month_now <= 3) { |
|
| 786 | 786 | |
| 787 | 787 | $dates['m_start'] = 1; |
| 788 | 788 | $dates['m_end'] = 3; |
| 789 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 789 | + $dates['year'] = date('Y', $current_time); |
|
| 790 | 790 | |
| 791 | - } elseif ( $month_now <= 6 ) { |
|
| 791 | + } elseif ($month_now <= 6) { |
|
| 792 | 792 | |
| 793 | 793 | $dates['m_start'] = 4; |
| 794 | 794 | $dates['m_end'] = 6; |
| 795 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 795 | + $dates['year'] = date('Y', $current_time); |
|
| 796 | 796 | |
| 797 | - } elseif ( $month_now <= 9 ) { |
|
| 797 | + } elseif ($month_now <= 9) { |
|
| 798 | 798 | |
| 799 | 799 | $dates['m_start'] = 7; |
| 800 | 800 | $dates['m_end'] = 9; |
| 801 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 801 | + $dates['year'] = date('Y', $current_time); |
|
| 802 | 802 | |
| 803 | 803 | } else { |
| 804 | 804 | |
| 805 | 805 | $dates['m_start'] = 10; |
| 806 | 806 | $dates['m_end'] = 12; |
| 807 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 807 | + $dates['year'] = date('Y', $current_time); |
|
| 808 | 808 | |
| 809 | 809 | } |
| 810 | 810 | break; |
| 811 | 811 | |
| 812 | 812 | case 'last_quarter' : |
| 813 | - $month_now = date( 'n', $current_time ); |
|
| 813 | + $month_now = date('n', $current_time); |
|
| 814 | 814 | |
| 815 | 815 | $dates['day'] = null; |
| 816 | 816 | |
| 817 | - if ( $month_now <= 3 ) { |
|
| 817 | + if ($month_now <= 3) { |
|
| 818 | 818 | |
| 819 | 819 | $dates['m_start'] = 10; |
| 820 | 820 | $dates['m_end'] = 12; |
| 821 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
| 821 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
| 822 | 822 | |
| 823 | - } elseif ( $month_now <= 6 ) { |
|
| 823 | + } elseif ($month_now <= 6) { |
|
| 824 | 824 | |
| 825 | 825 | $dates['m_start'] = 1; |
| 826 | 826 | $dates['m_end'] = 3; |
| 827 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 827 | + $dates['year'] = date('Y', $current_time); |
|
| 828 | 828 | |
| 829 | - } elseif ( $month_now <= 9 ) { |
|
| 829 | + } elseif ($month_now <= 9) { |
|
| 830 | 830 | |
| 831 | 831 | $dates['m_start'] = 4; |
| 832 | 832 | $dates['m_end'] = 6; |
| 833 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 833 | + $dates['year'] = date('Y', $current_time); |
|
| 834 | 834 | |
| 835 | 835 | } else { |
| 836 | 836 | |
| 837 | 837 | $dates['m_start'] = 7; |
| 838 | 838 | $dates['m_end'] = 9; |
| 839 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 839 | + $dates['year'] = date('Y', $current_time); |
|
| 840 | 840 | |
| 841 | 841 | } |
| 842 | 842 | break; |
@@ -845,14 +845,14 @@ discard block |
||
| 845 | 845 | $dates['day'] = null; |
| 846 | 846 | $dates['m_start'] = null; |
| 847 | 847 | $dates['m_end'] = null; |
| 848 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 848 | + $dates['year'] = date('Y', $current_time); |
|
| 849 | 849 | break; |
| 850 | 850 | |
| 851 | 851 | case 'last_year' : |
| 852 | 852 | $dates['day'] = null; |
| 853 | 853 | $dates['m_start'] = null; |
| 854 | 854 | $dates['m_end'] = null; |
| 855 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
| 855 | + $dates['year'] = date('Y', $current_time) - 1; |
|
| 856 | 856 | break; |
| 857 | 857 | |
| 858 | 858 | endswitch; |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | * |
| 866 | 866 | * @param array $dates The dates used for retrieving earnings. |
| 867 | 867 | */ |
| 868 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
| 868 | + return apply_filters('give_api_stat_dates', $dates); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -879,78 +879,78 @@ discard block |
||
| 879 | 879 | * |
| 880 | 880 | * @return array $donors Multidimensional array of the donors. |
| 881 | 881 | */ |
| 882 | - public function get_donors( $donor = null ) { |
|
| 882 | + public function get_donors($donor = null) { |
|
| 883 | 883 | |
| 884 | 884 | $donors = array(); |
| 885 | 885 | $error = array(); |
| 886 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
| 886 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
| 887 | 887 | return $donors; |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | $paged = $this->get_paged(); |
| 891 | 891 | $per_page = $this->per_page(); |
| 892 | - $offset = $per_page * ( $paged - 1 ); |
|
| 892 | + $offset = $per_page * ($paged - 1); |
|
| 893 | 893 | |
| 894 | - if ( is_numeric( $donor ) ) { |
|
| 894 | + if (is_numeric($donor)) { |
|
| 895 | 895 | $field = 'id'; |
| 896 | 896 | } else { |
| 897 | 897 | $field = 'email'; |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | - $donor_query = Give()->donors->get_donors( array( |
|
| 900 | + $donor_query = Give()->donors->get_donors(array( |
|
| 901 | 901 | 'number' => $per_page, |
| 902 | 902 | 'offset' => $offset, |
| 903 | 903 | $field => $donor, |
| 904 | - ) ); |
|
| 904 | + )); |
|
| 905 | 905 | $donor_count = 0; |
| 906 | 906 | |
| 907 | - if ( $donor_query ) { |
|
| 907 | + if ($donor_query) { |
|
| 908 | 908 | |
| 909 | - foreach ( $donor_query as $donor_obj ) { |
|
| 909 | + foreach ($donor_query as $donor_obj) { |
|
| 910 | 910 | |
| 911 | - $names = explode( ' ', $donor_obj->name ); |
|
| 912 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
| 911 | + $names = explode(' ', $donor_obj->name); |
|
| 912 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
| 913 | 913 | $last_name = ''; |
| 914 | - if ( ! empty( $names[1] ) ) { |
|
| 915 | - unset( $names[0] ); |
|
| 916 | - $last_name = implode( ' ', $names ); |
|
| 914 | + if ( ! empty($names[1])) { |
|
| 915 | + unset($names[0]); |
|
| 916 | + $last_name = implode(' ', $names); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | - $donors['donors'][ $donor_count ]['info']['user_id'] = ''; |
|
| 920 | - $donors['donors'][ $donor_count ]['info']['username'] = ''; |
|
| 921 | - $donors['donors'][ $donor_count ]['info']['display_name'] = ''; |
|
| 922 | - $donors['donors'][ $donor_count ]['info']['donor_id'] = $donor_obj->id; |
|
| 923 | - $donors['donors'][ $donor_count ]['info']['first_name'] = $first_name; |
|
| 924 | - $donors['donors'][ $donor_count ]['info']['last_name'] = $last_name; |
|
| 925 | - $donors['donors'][ $donor_count ]['info']['email'] = $donor_obj->email; |
|
| 919 | + $donors['donors'][$donor_count]['info']['user_id'] = ''; |
|
| 920 | + $donors['donors'][$donor_count]['info']['username'] = ''; |
|
| 921 | + $donors['donors'][$donor_count]['info']['display_name'] = ''; |
|
| 922 | + $donors['donors'][$donor_count]['info']['donor_id'] = $donor_obj->id; |
|
| 923 | + $donors['donors'][$donor_count]['info']['first_name'] = $first_name; |
|
| 924 | + $donors['donors'][$donor_count]['info']['last_name'] = $last_name; |
|
| 925 | + $donors['donors'][$donor_count]['info']['email'] = $donor_obj->email; |
|
| 926 | 926 | |
| 927 | - if ( ! empty( $donor_obj->user_id ) ) { |
|
| 927 | + if ( ! empty($donor_obj->user_id)) { |
|
| 928 | 928 | |
| 929 | - $user_data = get_userdata( $donor_obj->user_id ); |
|
| 929 | + $user_data = get_userdata($donor_obj->user_id); |
|
| 930 | 930 | |
| 931 | 931 | // Donor with registered account. |
| 932 | - $donors['donors'][ $donor_count ]['info']['user_id'] = $donor_obj->user_id; |
|
| 933 | - $donors['donors'][ $donor_count ]['info']['username'] = $user_data->user_login; |
|
| 934 | - $donors['donors'][ $donor_count ]['info']['display_name'] = $user_data->display_name; |
|
| 932 | + $donors['donors'][$donor_count]['info']['user_id'] = $donor_obj->user_id; |
|
| 933 | + $donors['donors'][$donor_count]['info']['username'] = $user_data->user_login; |
|
| 934 | + $donors['donors'][$donor_count]['info']['display_name'] = $user_data->display_name; |
|
| 935 | 935 | |
| 936 | 936 | } |
| 937 | 937 | |
| 938 | - $donors['donors'][ $donor_count ]['stats']['total_donations'] = $donor_obj->purchase_count; |
|
| 939 | - $donors['donors'][ $donor_count ]['stats']['total_spent'] = $donor_obj->purchase_value; |
|
| 938 | + $donors['donors'][$donor_count]['stats']['total_donations'] = $donor_obj->purchase_count; |
|
| 939 | + $donors['donors'][$donor_count]['stats']['total_spent'] = $donor_obj->purchase_value; |
|
| 940 | 940 | |
| 941 | - $donor_count ++; |
|
| 941 | + $donor_count++; |
|
| 942 | 942 | |
| 943 | 943 | } |
| 944 | - } elseif ( $donor ) { |
|
| 944 | + } elseif ($donor) { |
|
| 945 | 945 | |
| 946 | 946 | $error['error'] = sprintf( /* translators: %s: donor */ |
| 947 | - __( 'Donor %s not found.', 'give' ), $donor ); |
|
| 947 | + __('Donor %s not found.', 'give'), $donor ); |
|
| 948 | 948 | |
| 949 | 949 | return $error; |
| 950 | 950 | |
| 951 | 951 | } else { |
| 952 | 952 | |
| 953 | - $error['error'] = __( 'No donors found.', 'give' ); |
|
| 953 | + $error['error'] = __('No donors found.', 'give'); |
|
| 954 | 954 | |
| 955 | 955 | return $error; |
| 956 | 956 | |
@@ -969,37 +969,37 @@ discard block |
||
| 969 | 969 | * |
| 970 | 970 | * @return array $donors Multidimensional array of the forms. |
| 971 | 971 | */ |
| 972 | - public function get_forms( $form = null ) { |
|
| 972 | + public function get_forms($form = null) { |
|
| 973 | 973 | |
| 974 | 974 | $forms = array(); |
| 975 | 975 | $error = array(); |
| 976 | 976 | |
| 977 | - if ( $form == null ) { |
|
| 977 | + if ($form == null) { |
|
| 978 | 978 | $forms['forms'] = array(); |
| 979 | 979 | |
| 980 | - $form_list = get_posts( array( |
|
| 980 | + $form_list = get_posts(array( |
|
| 981 | 981 | 'post_type' => 'give_forms', |
| 982 | 982 | 'posts_per_page' => $this->per_page(), |
| 983 | 983 | 'suppress_filters' => true, |
| 984 | 984 | 'paged' => $this->get_paged(), |
| 985 | - ) ); |
|
| 985 | + )); |
|
| 986 | 986 | |
| 987 | - if ( $form_list ) { |
|
| 987 | + if ($form_list) { |
|
| 988 | 988 | $i = 0; |
| 989 | - foreach ( $form_list as $form_info ) { |
|
| 990 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
| 991 | - $i ++; |
|
| 989 | + foreach ($form_list as $form_info) { |
|
| 990 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
| 991 | + $i++; |
|
| 992 | 992 | } |
| 993 | 993 | } |
| 994 | 994 | } else { |
| 995 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
| 996 | - $form_info = get_post( $form ); |
|
| 995 | + if (get_post_type($form) == 'give_forms') { |
|
| 996 | + $form_info = get_post($form); |
|
| 997 | 997 | |
| 998 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
| 998 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
| 999 | 999 | |
| 1000 | 1000 | } else { |
| 1001 | 1001 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1002 | - __( 'Form %s not found.', 'give' ), $form ); |
|
| 1002 | + __('Form %s not found.', 'give'), $form ); |
|
| 1003 | 1003 | |
| 1004 | 1004 | return $error; |
| 1005 | 1005 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | * |
| 1018 | 1018 | * @return array Array of post data to return back in the API. |
| 1019 | 1019 | */ |
| 1020 | - private function get_form_data( $form_info ) { |
|
| 1020 | + private function get_form_data($form_info) { |
|
| 1021 | 1021 | |
| 1022 | 1022 | $form = array(); |
| 1023 | 1023 | |
@@ -1027,60 +1027,60 @@ discard block |
||
| 1027 | 1027 | $form['info']['create_date'] = $form_info->post_date; |
| 1028 | 1028 | $form['info']['modified_date'] = $form_info->post_modified; |
| 1029 | 1029 | $form['info']['status'] = $form_info->post_status; |
| 1030 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
| 1031 | - $form['info']['content'] = give_get_meta( $form_info->ID, '_give_form_content', true ); |
|
| 1032 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
| 1030 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
| 1031 | + $form['info']['content'] = give_get_meta($form_info->ID, '_give_form_content', true); |
|
| 1032 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
| 1033 | 1033 | |
| 1034 | - if ( give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) { |
|
| 1035 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
| 1036 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1034 | + if (give_is_setting_enabled(give_get_option('categories', 'disabled'))) { |
|
| 1035 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
| 1036 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1037 | 1037 | } |
| 1038 | - if ( give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) { |
|
| 1039 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1038 | + if (give_is_setting_enabled(give_get_option('tags', 'disabled'))) { |
|
| 1039 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | // Check whether any goal is to be achieved for the donation form. |
| 1043 | - $goal_option = give_get_meta( $form_info->ID, '_give_goal_option', true ); |
|
| 1044 | - $goal_amount = give_get_meta( $form_info->ID, '_give_set_goal', true ); |
|
| 1045 | - if ( give_is_setting_enabled( $goal_option ) && $goal_amount ) { |
|
| 1046 | - $total_income = give_get_form_earnings_stats( $form_info->ID ); |
|
| 1047 | - $goal_percentage_completed = ( $total_income < $goal_amount ) ? round( ( $total_income / $goal_amount ) * 100, 2 ) : 100; |
|
| 1048 | - $form['goal']['amount'] = isset( $goal_amount ) ? $goal_amount : ''; |
|
| 1049 | - $form['goal']['percentage_completed'] = isset( $goal_percentage_completed ) ? $goal_percentage_completed : ''; |
|
| 1043 | + $goal_option = give_get_meta($form_info->ID, '_give_goal_option', true); |
|
| 1044 | + $goal_amount = give_get_meta($form_info->ID, '_give_set_goal', true); |
|
| 1045 | + if (give_is_setting_enabled($goal_option) && $goal_amount) { |
|
| 1046 | + $total_income = give_get_form_earnings_stats($form_info->ID); |
|
| 1047 | + $goal_percentage_completed = ($total_income < $goal_amount) ? round(($total_income / $goal_amount) * 100, 2) : 100; |
|
| 1048 | + $form['goal']['amount'] = isset($goal_amount) ? $goal_amount : ''; |
|
| 1049 | + $form['goal']['percentage_completed'] = isset($goal_percentage_completed) ? $goal_percentage_completed : ''; |
|
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
| 1053 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
| 1054 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
| 1055 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
| 1056 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
| 1052 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
| 1053 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
| 1054 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
| 1055 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
| 1056 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | $counter = 0; |
| 1060 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
| 1061 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
| 1062 | - $counter ++; |
|
| 1060 | + if (give_has_variable_prices($form_info->ID)) { |
|
| 1061 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
| 1062 | + $counter++; |
|
| 1063 | 1063 | // multi-level item |
| 1064 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
| 1065 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
| 1064 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
| 1065 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
| 1066 | 1066 | |
| 1067 | 1067 | } |
| 1068 | 1068 | } else { |
| 1069 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
| 1069 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
| 1072 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
| 1073 | 1073 | |
| 1074 | 1074 | /** |
| 1075 | 1075 | * Fires when generating API sensitive data. |
| 1076 | 1076 | * |
| 1077 | 1077 | * @since 1.1 |
| 1078 | 1078 | */ |
| 1079 | - do_action( 'give_api_sensitive_data' ); |
|
| 1079 | + do_action('give_api_sensitive_data'); |
|
| 1080 | 1080 | |
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | - return apply_filters( 'give_api_forms_form', $form ); |
|
| 1083 | + return apply_filters('give_api_forms_form', $form); |
|
| 1084 | 1084 | |
| 1085 | 1085 | } |
| 1086 | 1086 | |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | * |
| 1096 | 1096 | * @return array |
| 1097 | 1097 | */ |
| 1098 | - public function get_stats( $args = array() ) { |
|
| 1098 | + public function get_stats($args = array()) { |
|
| 1099 | 1099 | $defaults = array( |
| 1100 | 1100 | 'type' => null, |
| 1101 | 1101 | 'form' => null, |
@@ -1104,9 +1104,9 @@ discard block |
||
| 1104 | 1104 | 'enddate' => null, |
| 1105 | 1105 | ); |
| 1106 | 1106 | |
| 1107 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1107 | + $args = wp_parse_args($args, $defaults); |
|
| 1108 | 1108 | |
| 1109 | - $dates = $this->get_dates( $args ); |
|
| 1109 | + $dates = $this->get_dates($args); |
|
| 1110 | 1110 | |
| 1111 | 1111 | $stats = array(); |
| 1112 | 1112 | $earnings = array( |
@@ -1117,40 +1117,40 @@ discard block |
||
| 1117 | 1117 | ); |
| 1118 | 1118 | $error = array(); |
| 1119 | 1119 | |
| 1120 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1120 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1121 | 1121 | return $stats; |
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | - if ( $args['type'] == 'donations' ) { |
|
| 1124 | + if ($args['type'] == 'donations') { |
|
| 1125 | 1125 | |
| 1126 | - if ( $args['form'] == null ) { |
|
| 1127 | - if ( $args['date'] == null ) { |
|
| 1126 | + if ($args['form'] == null) { |
|
| 1127 | + if ($args['date'] == null) { |
|
| 1128 | 1128 | $donations = $this->get_default_sales_stats(); |
| 1129 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1129 | + } elseif ($args['date'] === 'range') { |
|
| 1130 | 1130 | // Return donations for a date range. |
| 1131 | 1131 | // Ensure the end date is later than the start date. |
| 1132 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1133 | - $error['error'] = __( 'The end date must be later than the start date.', 'give' ); |
|
| 1132 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1133 | + $error['error'] = __('The end date must be later than the start date.', 'give'); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | // Ensure both the start and end date are specified |
| 1137 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1138 | - $error['error'] = __( 'Invalid or no date range specified.', 'give' ); |
|
| 1137 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1138 | + $error['error'] = __('Invalid or no date range specified.', 'give'); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | $total = 0; |
| 1142 | 1142 | |
| 1143 | 1143 | // Loop through the years |
| 1144 | 1144 | $y = $dates['year']; |
| 1145 | - while ( $y <= $dates['year_end'] ) : |
|
| 1145 | + while ($y <= $dates['year_end']) : |
|
| 1146 | 1146 | |
| 1147 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1147 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1148 | 1148 | $month_start = $dates['m_start']; |
| 1149 | 1149 | $month_end = $dates['m_end']; |
| 1150 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1150 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1151 | 1151 | $month_start = $dates['m_start']; |
| 1152 | 1152 | $month_end = 12; |
| 1153 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1153 | + } elseif ($y == $dates['year_end']) { |
|
| 1154 | 1154 | $month_start = 1; |
| 1155 | 1155 | $month_end = $dates['m_end']; |
| 1156 | 1156 | } else { |
@@ -1159,116 +1159,116 @@ discard block |
||
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | $i = $month_start; |
| 1162 | - while ( $i <= $month_end ) : |
|
| 1162 | + while ($i <= $month_end) : |
|
| 1163 | 1163 | |
| 1164 | - if ( $i == $dates['m_start'] ) { |
|
| 1164 | + if ($i == $dates['m_start']) { |
|
| 1165 | 1165 | $d = $dates['day_start']; |
| 1166 | 1166 | } else { |
| 1167 | 1167 | $d = 1; |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - if ( $i == $dates['m_end'] ) { |
|
| 1170 | + if ($i == $dates['m_end']) { |
|
| 1171 | 1171 | $num_of_days = $dates['day_end']; |
| 1172 | 1172 | } else { |
| 1173 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1173 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - while ( $d <= $num_of_days ) : |
|
| 1177 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
| 1178 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1179 | - if ( ! isset( $donations['sales'][ $date_key ] ) ) { |
|
| 1180 | - $donations['sales'][ $date_key ] = 0; |
|
| 1176 | + while ($d <= $num_of_days) : |
|
| 1177 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
| 1178 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1179 | + if ( ! isset($donations['sales'][$date_key])) { |
|
| 1180 | + $donations['sales'][$date_key] = 0; |
|
| 1181 | 1181 | } |
| 1182 | - $donations['sales'][ $date_key ] += $sale_count; |
|
| 1182 | + $donations['sales'][$date_key] += $sale_count; |
|
| 1183 | 1183 | $total += $sale_count; |
| 1184 | - $d ++; |
|
| 1184 | + $d++; |
|
| 1185 | 1185 | endwhile; |
| 1186 | - $i ++; |
|
| 1186 | + $i++; |
|
| 1187 | 1187 | endwhile; |
| 1188 | 1188 | |
| 1189 | - $y ++; |
|
| 1189 | + $y++; |
|
| 1190 | 1190 | endwhile; |
| 1191 | 1191 | |
| 1192 | 1192 | $donations['totals'] = $total; |
| 1193 | 1193 | } else { |
| 1194 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1194 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1195 | 1195 | $donations_count = 0; |
| 1196 | 1196 | |
| 1197 | 1197 | // Loop through the months |
| 1198 | 1198 | $month = $dates['m_start']; |
| 1199 | 1199 | |
| 1200 | - while ( $month <= $dates['m_end'] ) : |
|
| 1201 | - $donations_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
| 1202 | - $month ++; |
|
| 1200 | + while ($month <= $dates['m_end']) : |
|
| 1201 | + $donations_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
| 1202 | + $month++; |
|
| 1203 | 1203 | endwhile; |
| 1204 | 1204 | |
| 1205 | - $donations['donations'][ $args['date'] ] = $donations_count; |
|
| 1205 | + $donations['donations'][$args['date']] = $donations_count; |
|
| 1206 | 1206 | } else { |
| 1207 | - $donations['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1207 | + $donations['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | }// End if(). |
| 1210 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1211 | - $forms = get_posts( array( |
|
| 1210 | + } elseif ($args['form'] == 'all') { |
|
| 1211 | + $forms = get_posts(array( |
|
| 1212 | 1212 | 'post_type' => 'give_forms', |
| 1213 | 1213 | 'nopaging' => true, |
| 1214 | - ) ); |
|
| 1215 | - $i = 0; |
|
| 1216 | - foreach ( $forms as $form_info ) { |
|
| 1217 | - $donations['donations'][ $i ] = array( |
|
| 1218 | - $form_info->post_name => give_get_form_sales_stats( $form_info->ID ), |
|
| 1214 | + )); |
|
| 1215 | + $i = 0; |
|
| 1216 | + foreach ($forms as $form_info) { |
|
| 1217 | + $donations['donations'][$i] = array( |
|
| 1218 | + $form_info->post_name => give_get_form_sales_stats($form_info->ID), |
|
| 1219 | 1219 | ); |
| 1220 | - $i ++; |
|
| 1220 | + $i++; |
|
| 1221 | 1221 | } |
| 1222 | 1222 | } else { |
| 1223 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1224 | - $form_info = get_post( $args['form'] ); |
|
| 1223 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1224 | + $form_info = get_post($args['form']); |
|
| 1225 | 1225 | $donations['donations'][0] = array( |
| 1226 | - $form_info->post_name => give_get_form_sales_stats( $args['form'] ), |
|
| 1226 | + $form_info->post_name => give_get_form_sales_stats($args['form']), |
|
| 1227 | 1227 | ); |
| 1228 | 1228 | } else { |
| 1229 | 1229 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1230 | - __( 'Form %s not found.', 'give' ), $args['form'] ); |
|
| 1230 | + __('Form %s not found.', 'give'), $args['form'] ); |
|
| 1231 | 1231 | } |
| 1232 | 1232 | }// End if(). |
| 1233 | 1233 | |
| 1234 | - if ( ! empty( $error ) ) { |
|
| 1234 | + if ( ! empty($error)) { |
|
| 1235 | 1235 | return $error; |
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | return $donations; |
| 1239 | 1239 | |
| 1240 | - } elseif ( $args['type'] == 'earnings' ) { |
|
| 1241 | - if ( $args['form'] == null ) { |
|
| 1242 | - if ( $args['date'] == null ) { |
|
| 1240 | + } elseif ($args['type'] == 'earnings') { |
|
| 1241 | + if ($args['form'] == null) { |
|
| 1242 | + if ($args['date'] == null) { |
|
| 1243 | 1243 | $earnings = $this->get_default_earnings_stats(); |
| 1244 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1244 | + } elseif ($args['date'] === 'range') { |
|
| 1245 | 1245 | // Return sales for a date range |
| 1246 | 1246 | // Ensure the end date is later than the start date |
| 1247 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1248 | - $error['error'] = __( 'The end date must be later than the start date.', 'give' ); |
|
| 1247 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1248 | + $error['error'] = __('The end date must be later than the start date.', 'give'); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | // Ensure both the start and end date are specified |
| 1252 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1253 | - $error['error'] = __( 'Invalid or no date range specified.', 'give' ); |
|
| 1252 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1253 | + $error['error'] = __('Invalid or no date range specified.', 'give'); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | $total = (float) 0.00; |
| 1257 | 1257 | |
| 1258 | 1258 | // Loop through the years |
| 1259 | 1259 | $y = $dates['year']; |
| 1260 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
| 1260 | + if ( ! isset($earnings['earnings'])) { |
|
| 1261 | 1261 | $earnings['earnings'] = array(); |
| 1262 | 1262 | } |
| 1263 | - while ( $y <= $dates['year_end'] ) : |
|
| 1263 | + while ($y <= $dates['year_end']) : |
|
| 1264 | 1264 | |
| 1265 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1265 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1266 | 1266 | $month_start = $dates['m_start']; |
| 1267 | 1267 | $month_end = $dates['m_end']; |
| 1268 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1268 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1269 | 1269 | $month_start = $dates['m_start']; |
| 1270 | 1270 | $month_end = 12; |
| 1271 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1271 | + } elseif ($y == $dates['year_end']) { |
|
| 1272 | 1272 | $month_start = 1; |
| 1273 | 1273 | $month_end = $dates['m_end']; |
| 1274 | 1274 | } else { |
@@ -1277,94 +1277,94 @@ discard block |
||
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | 1279 | $i = $month_start; |
| 1280 | - while ( $i <= $month_end ) : |
|
| 1280 | + while ($i <= $month_end) : |
|
| 1281 | 1281 | |
| 1282 | - if ( $i == $dates['m_start'] ) { |
|
| 1282 | + if ($i == $dates['m_start']) { |
|
| 1283 | 1283 | $d = $dates['day_start']; |
| 1284 | 1284 | } else { |
| 1285 | 1285 | $d = 1; |
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | - if ( $i == $dates['m_end'] ) { |
|
| 1288 | + if ($i == $dates['m_end']) { |
|
| 1289 | 1289 | $num_of_days = $dates['day_end']; |
| 1290 | 1290 | } else { |
| 1291 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1291 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | - while ( $d <= $num_of_days ) : |
|
| 1295 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
| 1296 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1297 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
| 1298 | - $earnings['earnings'][ $date_key ] = 0; |
|
| 1294 | + while ($d <= $num_of_days) : |
|
| 1295 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
| 1296 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1297 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
| 1298 | + $earnings['earnings'][$date_key] = 0; |
|
| 1299 | 1299 | } |
| 1300 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
| 1300 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
| 1301 | 1301 | $total += $earnings_stat; |
| 1302 | - $d ++; |
|
| 1302 | + $d++; |
|
| 1303 | 1303 | endwhile; |
| 1304 | 1304 | |
| 1305 | - $i ++; |
|
| 1305 | + $i++; |
|
| 1306 | 1306 | endwhile; |
| 1307 | 1307 | |
| 1308 | - $y ++; |
|
| 1308 | + $y++; |
|
| 1309 | 1309 | endwhile; |
| 1310 | 1310 | |
| 1311 | 1311 | $earnings['totals'] = $total; |
| 1312 | 1312 | } else { |
| 1313 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1313 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1314 | 1314 | $earnings_count = (float) 0.00; |
| 1315 | 1315 | |
| 1316 | 1316 | // Loop through the months |
| 1317 | 1317 | $month = $dates['m_start']; |
| 1318 | 1318 | |
| 1319 | - while ( $month <= $dates['m_end'] ) : |
|
| 1320 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
| 1321 | - $month ++; |
|
| 1319 | + while ($month <= $dates['m_end']) : |
|
| 1320 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
| 1321 | + $month++; |
|
| 1322 | 1322 | endwhile; |
| 1323 | 1323 | |
| 1324 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
| 1324 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
| 1325 | 1325 | } else { |
| 1326 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1326 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1327 | 1327 | } |
| 1328 | 1328 | }// End if(). |
| 1329 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1330 | - $forms = get_posts( array( |
|
| 1329 | + } elseif ($args['form'] == 'all') { |
|
| 1330 | + $forms = get_posts(array( |
|
| 1331 | 1331 | 'post_type' => 'give_forms', |
| 1332 | 1332 | 'nopaging' => true, |
| 1333 | - ) ); |
|
| 1333 | + )); |
|
| 1334 | 1334 | |
| 1335 | 1335 | $i = 0; |
| 1336 | - foreach ( $forms as $form_info ) { |
|
| 1337 | - $earnings['earnings'][ $i ] = array( |
|
| 1338 | - $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ), |
|
| 1336 | + foreach ($forms as $form_info) { |
|
| 1337 | + $earnings['earnings'][$i] = array( |
|
| 1338 | + $form_info->post_name => give_get_form_earnings_stats($form_info->ID), |
|
| 1339 | 1339 | ); |
| 1340 | - $i ++; |
|
| 1340 | + $i++; |
|
| 1341 | 1341 | } |
| 1342 | 1342 | } else { |
| 1343 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1344 | - $form_info = get_post( $args['form'] ); |
|
| 1343 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1344 | + $form_info = get_post($args['form']); |
|
| 1345 | 1345 | $earnings['earnings'][0] = array( |
| 1346 | - $form_info->post_name => give_get_form_earnings_stats( $args['form'] ), |
|
| 1346 | + $form_info->post_name => give_get_form_earnings_stats($args['form']), |
|
| 1347 | 1347 | ); |
| 1348 | 1348 | } else { |
| 1349 | 1349 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1350 | - __( 'Form %s not found.', 'give' ), $args['form'] ); |
|
| 1350 | + __('Form %s not found.', 'give'), $args['form'] ); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | }// End if(). |
| 1353 | 1353 | |
| 1354 | - if ( ! empty( $error ) ) { |
|
| 1354 | + if ( ! empty($error)) { |
|
| 1355 | 1355 | return $error; |
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | return $earnings; |
| 1359 | - } elseif ( $args['type'] == 'donors' ) { |
|
| 1359 | + } elseif ($args['type'] == 'donors') { |
|
| 1360 | 1360 | $donors = new Give_DB_Donors(); |
| 1361 | 1361 | $stats['donations']['total_donors'] = $donors->count(); |
| 1362 | 1362 | |
| 1363 | 1363 | return $stats; |
| 1364 | 1364 | |
| 1365 | - } elseif ( empty( $args['type'] ) ) { |
|
| 1366 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
| 1367 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
| 1365 | + } elseif (empty($args['type'])) { |
|
| 1366 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
| 1367 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
| 1368 | 1368 | |
| 1369 | 1369 | return array( |
| 1370 | 1370 | 'stats' => $stats, |
@@ -1382,7 +1382,7 @@ discard block |
||
| 1382 | 1382 | * |
| 1383 | 1383 | * @return array |
| 1384 | 1384 | */ |
| 1385 | - public function get_recent_donations( $args = array() ) { |
|
| 1385 | + public function get_recent_donations($args = array()) { |
|
| 1386 | 1386 | global $wp_query; |
| 1387 | 1387 | |
| 1388 | 1388 | $defaults = array( |
@@ -1392,33 +1392,33 @@ discard block |
||
| 1392 | 1392 | 'enddate' => null, |
| 1393 | 1393 | ); |
| 1394 | 1394 | |
| 1395 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1395 | + $args = wp_parse_args($args, $defaults); |
|
| 1396 | 1396 | |
| 1397 | 1397 | $donations = array(); |
| 1398 | 1398 | |
| 1399 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1399 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1400 | 1400 | return $donations; |
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
| 1403 | + if (isset($wp_query->query_vars['id'])) { |
|
| 1404 | 1404 | $query = array(); |
| 1405 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
| 1406 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
| 1405 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
| 1406 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
| 1407 | 1407 | $query = array(); |
| 1408 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
| 1409 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
| 1410 | - $args = array( |
|
| 1408 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
| 1409 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
| 1410 | + $args = array( |
|
| 1411 | 1411 | 'fields' => 'ids', |
| 1412 | 1412 | 'meta_key' => '_give_payment_user_email', |
| 1413 | 1413 | 'meta_value' => $wp_query->query_vars['email'], |
| 1414 | 1414 | 'number' => $this->per_page(), |
| 1415 | 1415 | 'page' => $this->get_paged(), |
| 1416 | 1416 | ); |
| 1417 | - $query = give_get_payments( $args ); |
|
| 1418 | - } elseif ( isset( $wp_query->query_vars['date'] ) ) { |
|
| 1417 | + $query = give_get_payments($args); |
|
| 1418 | + } elseif (isset($wp_query->query_vars['date'])) { |
|
| 1419 | 1419 | |
| 1420 | - $current_time = current_time( 'timestamp' ); |
|
| 1421 | - $dates = $this->get_dates( $args ); |
|
| 1420 | + $current_time = current_time('timestamp'); |
|
| 1421 | + $dates = $this->get_dates($args); |
|
| 1422 | 1422 | $start_date = ''; |
| 1423 | 1423 | $end_date = ''; |
| 1424 | 1424 | |
@@ -1431,27 +1431,27 @@ discard block |
||
| 1431 | 1431 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 1432 | 1432 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 1433 | 1433 | */ |
| 1434 | - switch ( $wp_query->query_vars['date'] ) { |
|
| 1434 | + switch ($wp_query->query_vars['date']) { |
|
| 1435 | 1435 | |
| 1436 | 1436 | case 'today': |
| 1437 | 1437 | |
| 1438 | 1438 | // Set and Format Start and End Date to be date of today. |
| 1439 | - $start_date = $end_date = date( 'Y/m/d', $current_time ); |
|
| 1439 | + $start_date = $end_date = date('Y/m/d', $current_time); |
|
| 1440 | 1440 | |
| 1441 | 1441 | break; |
| 1442 | 1442 | |
| 1443 | 1443 | case 'yesterday': |
| 1444 | 1444 | |
| 1445 | 1445 | // Set and Format Start and End Date to be date of yesterday. |
| 1446 | - $start_date = $end_date = date( 'Y/m', $current_time ) . '/' . ( date( 'd', $current_time ) - 1 ); |
|
| 1446 | + $start_date = $end_date = date('Y/m', $current_time).'/'.(date('d', $current_time) - 1); |
|
| 1447 | 1447 | |
| 1448 | 1448 | break; |
| 1449 | 1449 | |
| 1450 | 1450 | case 'range': |
| 1451 | 1451 | |
| 1452 | 1452 | // Format Start Date and End Date for filtering payment based on date range. |
| 1453 | - $start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start']; |
|
| 1454 | - $end_date = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end']; |
|
| 1453 | + $start_date = $dates['year'].'/'.$dates['m_start'].'/'.$dates['day_start']; |
|
| 1454 | + $end_date = $dates['year_end'].'/'.$dates['m_end'].'/'.$dates['day_end']; |
|
| 1455 | 1455 | |
| 1456 | 1456 | break; |
| 1457 | 1457 | |
@@ -1465,22 +1465,22 @@ discard block |
||
| 1465 | 1465 | 'page' => $this->get_paged(), |
| 1466 | 1466 | ); |
| 1467 | 1467 | |
| 1468 | - $query = give_get_payments( $args ); |
|
| 1468 | + $query = give_get_payments($args); |
|
| 1469 | 1469 | } else { |
| 1470 | 1470 | $args = array( |
| 1471 | 1471 | 'fields' => 'ids', |
| 1472 | 1472 | 'number' => $this->per_page(), |
| 1473 | 1473 | 'page' => $this->get_paged(), |
| 1474 | 1474 | ); |
| 1475 | - $query = give_get_payments( $args ); |
|
| 1475 | + $query = give_get_payments($args); |
|
| 1476 | 1476 | }// End if(). |
| 1477 | 1477 | |
| 1478 | - if ( $query ) { |
|
| 1478 | + if ($query) { |
|
| 1479 | 1479 | $i = 0; |
| 1480 | - foreach ( $query as $payment ) { |
|
| 1480 | + foreach ($query as $payment) { |
|
| 1481 | 1481 | |
| 1482 | - if ( is_numeric( $payment ) ) { |
|
| 1483 | - $payment = new Give_Payment( $payment ); |
|
| 1482 | + if (is_numeric($payment)) { |
|
| 1483 | + $payment = new Give_Payment($payment); |
|
| 1484 | 1484 | $payment_meta = $payment->get_meta(); |
| 1485 | 1485 | $user_info = $payment->user_info; |
| 1486 | 1486 | } |
@@ -1488,41 +1488,41 @@ discard block |
||
| 1488 | 1488 | $payment_meta = $payment->get_meta(); |
| 1489 | 1489 | $user_info = $payment->user_info; |
| 1490 | 1490 | |
| 1491 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
| 1492 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
| 1493 | - |
|
| 1494 | - $donations['donations'][ $i ]['ID'] = $payment->number; |
|
| 1495 | - $donations['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
| 1496 | - $donations['donations'][ $i ]['key'] = $payment->key; |
|
| 1497 | - $donations['donations'][ $i ]['total'] = $payment->total; |
|
| 1498 | - $donations['donations'][ $i ]['status'] = give_get_payment_status( $payment, true ); |
|
| 1499 | - $donations['donations'][ $i ]['gateway'] = $payment->gateway; |
|
| 1500 | - $donations['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
| 1501 | - $donations['donations'][ $i ]['fname'] = $first_name; |
|
| 1502 | - $donations['donations'][ $i ]['lname'] = $last_name; |
|
| 1503 | - $donations['donations'][ $i ]['email'] = $payment->email; |
|
| 1504 | - $donations['donations'][ $i ]['date'] = $payment->date; |
|
| 1505 | - |
|
| 1506 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1507 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
| 1508 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
| 1509 | - |
|
| 1510 | - $donations['donations'][ $i ]['form']['id'] = $form_id; |
|
| 1511 | - $donations['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
| 1512 | - $donations['donations'][ $i ]['form']['price'] = $price; |
|
| 1513 | - |
|
| 1514 | - if ( give_has_variable_prices( $form_id ) ) { |
|
| 1515 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
| 1516 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
| 1517 | - $donations['donations'][ $i ]['form']['price_name'] = $price_name; |
|
| 1518 | - $donations['donations'][ $i ]['form']['price_id'] = $price_id; |
|
| 1519 | - $donations['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
| 1491 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
| 1492 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
| 1493 | + |
|
| 1494 | + $donations['donations'][$i]['ID'] = $payment->number; |
|
| 1495 | + $donations['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
| 1496 | + $donations['donations'][$i]['key'] = $payment->key; |
|
| 1497 | + $donations['donations'][$i]['total'] = $payment->total; |
|
| 1498 | + $donations['donations'][$i]['status'] = give_get_payment_status($payment, true); |
|
| 1499 | + $donations['donations'][$i]['gateway'] = $payment->gateway; |
|
| 1500 | + $donations['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
| 1501 | + $donations['donations'][$i]['fname'] = $first_name; |
|
| 1502 | + $donations['donations'][$i]['lname'] = $last_name; |
|
| 1503 | + $donations['donations'][$i]['email'] = $payment->email; |
|
| 1504 | + $donations['donations'][$i]['date'] = $payment->date; |
|
| 1505 | + |
|
| 1506 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1507 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
| 1508 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
| 1509 | + |
|
| 1510 | + $donations['donations'][$i]['form']['id'] = $form_id; |
|
| 1511 | + $donations['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
| 1512 | + $donations['donations'][$i]['form']['price'] = $price; |
|
| 1513 | + |
|
| 1514 | + if (give_has_variable_prices($form_id)) { |
|
| 1515 | + if (isset($payment_meta['price_id'])) { |
|
| 1516 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
| 1517 | + $donations['donations'][$i]['form']['price_name'] = $price_name; |
|
| 1518 | + $donations['donations'][$i]['form']['price_id'] = $price_id; |
|
| 1519 | + $donations['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
| 1520 | 1520 | |
| 1521 | 1521 | } |
| 1522 | 1522 | } |
| 1523 | 1523 | |
| 1524 | 1524 | // Add custom meta to API |
| 1525 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
| 1525 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
| 1526 | 1526 | |
| 1527 | 1527 | $exceptions = array( |
| 1528 | 1528 | 'form_title', |
@@ -1535,19 +1535,19 @@ discard block |
||
| 1535 | 1535 | ); |
| 1536 | 1536 | |
| 1537 | 1537 | // Don't clutter up results with dupes |
| 1538 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
| 1538 | + if (in_array($meta_key, $exceptions)) { |
|
| 1539 | 1539 | continue; |
| 1540 | 1540 | } |
| 1541 | 1541 | |
| 1542 | - $donations['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
| 1542 | + $donations['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
| 1543 | 1543 | |
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | - $i ++; |
|
| 1546 | + $i++; |
|
| 1547 | 1547 | }// End foreach(). |
| 1548 | 1548 | }// End if(). |
| 1549 | 1549 | |
| 1550 | - return apply_filters( 'give_api_donations_endpoint', $donations ); |
|
| 1550 | + return apply_filters('give_api_donations_endpoint', $donations); |
|
| 1551 | 1551 | } |
| 1552 | 1552 | |
| 1553 | 1553 | /** |
@@ -1563,9 +1563,9 @@ discard block |
||
| 1563 | 1563 | public function get_output_format() { |
| 1564 | 1564 | global $wp_query; |
| 1565 | 1565 | |
| 1566 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1566 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1567 | 1567 | |
| 1568 | - return apply_filters( 'give_api_output_format', $format ); |
|
| 1568 | + return apply_filters('give_api_output_format', $format); |
|
| 1569 | 1569 | } |
| 1570 | 1570 | |
| 1571 | 1571 | |
@@ -1582,8 +1582,8 @@ discard block |
||
| 1582 | 1582 | * |
| 1583 | 1583 | * @return void |
| 1584 | 1584 | */ |
| 1585 | - private function log_request( $data = array() ) { |
|
| 1586 | - if ( ! $this->log_requests ) { |
|
| 1585 | + private function log_request($data = array()) { |
|
| 1586 | + if ( ! $this->log_requests) { |
|
| 1587 | 1587 | return; |
| 1588 | 1588 | } |
| 1589 | 1589 | |
@@ -1599,36 +1599,36 @@ discard block |
||
| 1599 | 1599 | |
| 1600 | 1600 | $query = array( |
| 1601 | 1601 | 'give-api' => $wp_query->query_vars['give-api'], |
| 1602 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1603 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1604 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
| 1605 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 1606 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 1607 | - 'donor' => isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null, |
|
| 1608 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 1609 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 1610 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 1611 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
| 1612 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1613 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
| 1602 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1603 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1604 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
| 1605 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 1606 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 1607 | + 'donor' => isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null, |
|
| 1608 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 1609 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 1610 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 1611 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
| 1612 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1613 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
| 1614 | 1614 | ); |
| 1615 | 1615 | |
| 1616 | 1616 | $log_data = array( |
| 1617 | 1617 | 'log_type' => 'api_request', |
| 1618 | - 'post_excerpt' => http_build_query( $query ), |
|
| 1619 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
| 1618 | + 'post_excerpt' => http_build_query($query), |
|
| 1619 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
| 1620 | 1620 | ); |
| 1621 | 1621 | |
| 1622 | 1622 | $log_meta = array( |
| 1623 | 1623 | 'request_ip' => give_get_ip(), |
| 1624 | 1624 | 'user' => $this->user_id, |
| 1625 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1626 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1625 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1626 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1627 | 1627 | 'time' => $data['request_speed'], |
| 1628 | 1628 | 'version' => $this->get_queried_version(), |
| 1629 | 1629 | ); |
| 1630 | 1630 | |
| 1631 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
| 1631 | + $give_logs->insert_log($log_data, $log_meta); |
|
| 1632 | 1632 | } |
| 1633 | 1633 | |
| 1634 | 1634 | |
@@ -1652,11 +1652,11 @@ discard block |
||
| 1652 | 1652 | * |
| 1653 | 1653 | * @param int $status_code |
| 1654 | 1654 | */ |
| 1655 | - public function output( $status_code = 200 ) { |
|
| 1655 | + public function output($status_code = 200) { |
|
| 1656 | 1656 | |
| 1657 | 1657 | $format = $this->get_output_format(); |
| 1658 | 1658 | |
| 1659 | - status_header( $status_code ); |
|
| 1659 | + status_header($status_code); |
|
| 1660 | 1660 | |
| 1661 | 1661 | /** |
| 1662 | 1662 | * Fires before outputting the API. |
@@ -1667,25 +1667,25 @@ discard block |
||
| 1667 | 1667 | * @param Give_API $this The Give_API object. |
| 1668 | 1668 | * @param string $format Output format, XML or JSON. Default is JSON. |
| 1669 | 1669 | */ |
| 1670 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
| 1670 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
| 1671 | 1671 | |
| 1672 | - switch ( $format ) : |
|
| 1672 | + switch ($format) : |
|
| 1673 | 1673 | |
| 1674 | 1674 | case 'xml' : |
| 1675 | 1675 | |
| 1676 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
| 1677 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
| 1676 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
| 1677 | + $xml = Array2XML::createXML('give', $this->data); |
|
| 1678 | 1678 | echo $xml->saveXML(); |
| 1679 | 1679 | |
| 1680 | 1680 | break; |
| 1681 | 1681 | |
| 1682 | 1682 | case 'json' : |
| 1683 | 1683 | |
| 1684 | - header( 'Content-Type: application/json' ); |
|
| 1685 | - if ( ! empty( $this->pretty_print ) ) { |
|
| 1686 | - echo json_encode( $this->data, $this->pretty_print ); |
|
| 1684 | + header('Content-Type: application/json'); |
|
| 1685 | + if ( ! empty($this->pretty_print)) { |
|
| 1686 | + echo json_encode($this->data, $this->pretty_print); |
|
| 1687 | 1687 | } else { |
| 1688 | - echo json_encode( $this->data ); |
|
| 1688 | + echo json_encode($this->data); |
|
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | 1691 | break; |
@@ -1700,7 +1700,7 @@ discard block |
||
| 1700 | 1700 | * @param array $data Response data to return. |
| 1701 | 1701 | * @param Give_API $this The Give_API object. |
| 1702 | 1702 | */ |
| 1703 | - do_action( "give_api_output_{$format}", $this->data, $this ); |
|
| 1703 | + do_action("give_api_output_{$format}", $this->data, $this); |
|
| 1704 | 1704 | |
| 1705 | 1705 | break; |
| 1706 | 1706 | |
@@ -1715,7 +1715,7 @@ discard block |
||
| 1715 | 1715 | * @param Give_API $this The Give_API object. |
| 1716 | 1716 | * @param string $format Output format, XML or JSON. Default is JSON. |
| 1717 | 1717 | */ |
| 1718 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
| 1718 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
| 1719 | 1719 | |
| 1720 | 1720 | give_die(); |
| 1721 | 1721 | } |
@@ -1732,41 +1732,41 @@ discard block |
||
| 1732 | 1732 | * |
| 1733 | 1733 | * @return void |
| 1734 | 1734 | */ |
| 1735 | - function user_key_field( $user ) { |
|
| 1735 | + function user_key_field($user) { |
|
| 1736 | 1736 | |
| 1737 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
| 1737 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
| 1738 | 1738 | |
| 1739 | - $user = get_userdata( $user->ID ); |
|
| 1739 | + $user = get_userdata($user->ID); |
|
| 1740 | 1740 | ?> |
| 1741 | 1741 | <table class="form-table"> |
| 1742 | 1742 | <tbody> |
| 1743 | 1743 | <tr> |
| 1744 | 1744 | <th> |
| 1745 | - <?php _e( 'Give API Keys', 'give' ); ?> |
|
| 1745 | + <?php _e('Give API Keys', 'give'); ?> |
|
| 1746 | 1746 | </th> |
| 1747 | 1747 | <td> |
| 1748 | 1748 | <?php |
| 1749 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
| 1750 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
| 1749 | + $public_key = $this->get_user_public_key($user->ID); |
|
| 1750 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
| 1751 | 1751 | ?> |
| 1752 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
| 1752 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
| 1753 | 1753 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" /> |
| 1754 | - <span class="description"><?php _e( 'Generate API Key', 'give' ); ?></span> |
|
| 1754 | + <span class="description"><?php _e('Generate API Key', 'give'); ?></span> |
|
| 1755 | 1755 | <?php } else { ?> |
| 1756 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?> |
|
| 1756 | + <strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?> |
|
| 1757 | 1757 | </strong> |
| 1758 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>" /> |
|
| 1758 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>" /> |
|
| 1759 | 1759 | <br /> |
| 1760 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Secret key:', 'give' ); ?> |
|
| 1760 | + <strong style="display:inline-block; width: 125px;"><?php _e('Secret key:', 'give'); ?> |
|
| 1761 | 1761 | </strong> |
| 1762 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>" /> |
|
| 1762 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>" /> |
|
| 1763 | 1763 | <br /> |
| 1764 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Token:', 'give' ); ?> |
|
| 1764 | + <strong style="display:inline-block; width: 125px;"><?php _e('Token:', 'give'); ?> |
|
| 1765 | 1765 | </strong> |
| 1766 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>" /> |
|
| 1766 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>" /> |
|
| 1767 | 1767 | <br /> |
| 1768 | 1768 | <input name="give_revoke_api_key" type="checkbox" id="give_revoke_api_key" /> |
| 1769 | - <span class="description"><label for="give_revoke_api_key"><?php _e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
| 1769 | + <span class="description"><label for="give_revoke_api_key"><?php _e('Revoke API Keys', 'give'); ?></label></span> |
|
| 1770 | 1770 | <?php } ?> |
| 1771 | 1771 | </td> |
| 1772 | 1772 | </tr> |
@@ -1785,61 +1785,61 @@ discard block |
||
| 1785 | 1785 | * |
| 1786 | 1786 | * @return void |
| 1787 | 1787 | */ |
| 1788 | - public function process_api_key( $args ) { |
|
| 1788 | + public function process_api_key($args) { |
|
| 1789 | 1789 | |
| 1790 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
| 1791 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( |
|
| 1790 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
| 1791 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array( |
|
| 1792 | 1792 | 'response' => 403, |
| 1793 | - ) ); |
|
| 1793 | + )); |
|
| 1794 | 1794 | } |
| 1795 | 1795 | |
| 1796 | - if ( empty( $args['user_id'] ) ) { |
|
| 1797 | - wp_die( __( 'User ID Required.', 'give' ), __( 'Error', 'give' ), array( |
|
| 1796 | + if (empty($args['user_id'])) { |
|
| 1797 | + wp_die(__('User ID Required.', 'give'), __('Error', 'give'), array( |
|
| 1798 | 1798 | 'response' => 401, |
| 1799 | - ) ); |
|
| 1799 | + )); |
|
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | - if ( is_numeric( $args['user_id'] ) ) { |
|
| 1803 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
| 1802 | + if (is_numeric($args['user_id'])) { |
|
| 1803 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
| 1804 | 1804 | } else { |
| 1805 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
| 1805 | + $userdata = get_user_by('login', $args['user_id']); |
|
| 1806 | 1806 | $user_id = $userdata->ID; |
| 1807 | 1807 | } |
| 1808 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
| 1808 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
| 1809 | 1809 | |
| 1810 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1811 | - wp_die( sprintf( /* translators: %s: process */ |
|
| 1812 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( |
|
| 1810 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
| 1811 | + wp_die(sprintf( /* translators: %s: process */ |
|
| 1812 | + __('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array( |
|
| 1813 | 1813 | 'response' => 403, |
| 1814 | - ) ); |
|
| 1815 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1816 | - wp_die( sprintf( /* translators: %s: process */ |
|
| 1817 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( |
|
| 1814 | + )); |
|
| 1815 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
| 1816 | + wp_die(sprintf( /* translators: %s: process */ |
|
| 1817 | + __('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array( |
|
| 1818 | 1818 | 'response' => 403, |
| 1819 | - ) ); |
|
| 1819 | + )); |
|
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | - switch ( $process ) { |
|
| 1822 | + switch ($process) { |
|
| 1823 | 1823 | case 'generate': |
| 1824 | - if ( $this->generate_api_key( $user_id ) ) { |
|
| 1825 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
| 1826 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1824 | + if ($this->generate_api_key($user_id)) { |
|
| 1825 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
| 1826 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1827 | 1827 | exit(); |
| 1828 | 1828 | } else { |
| 1829 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1829 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1830 | 1830 | exit(); |
| 1831 | 1831 | } |
| 1832 | 1832 | break; |
| 1833 | 1833 | case 'regenerate': |
| 1834 | - $this->generate_api_key( $user_id, true ); |
|
| 1835 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
| 1836 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1834 | + $this->generate_api_key($user_id, true); |
|
| 1835 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
| 1836 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1837 | 1837 | exit(); |
| 1838 | 1838 | break; |
| 1839 | 1839 | case 'revoke': |
| 1840 | - $this->revoke_api_key( $user_id ); |
|
| 1841 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
| 1842 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1840 | + $this->revoke_api_key($user_id); |
|
| 1841 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
| 1842 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1843 | 1843 | exit(); |
| 1844 | 1844 | break; |
| 1845 | 1845 | default; |
@@ -1858,59 +1858,59 @@ discard block |
||
| 1858 | 1858 | * |
| 1859 | 1859 | * @return boolean True if (re)generated successfully, false otherwise. |
| 1860 | 1860 | */ |
| 1861 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
| 1861 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
| 1862 | 1862 | |
| 1863 | 1863 | // Bail out, if user doesn't exists. |
| 1864 | - if ( empty( $user_id ) ) { |
|
| 1864 | + if (empty($user_id)) { |
|
| 1865 | 1865 | return false; |
| 1866 | 1866 | } |
| 1867 | 1867 | |
| 1868 | - $user = get_userdata( $user_id ); |
|
| 1868 | + $user = get_userdata($user_id); |
|
| 1869 | 1869 | |
| 1870 | 1870 | // Bail Out, if user object doesn't exists. |
| 1871 | - if ( ! $user ) { |
|
| 1871 | + if ( ! $user) { |
|
| 1872 | 1872 | return false; |
| 1873 | 1873 | } |
| 1874 | 1874 | |
| 1875 | 1875 | $new_public_key = ''; |
| 1876 | 1876 | $new_secret_key = ''; |
| 1877 | 1877 | |
| 1878 | - if( ! empty( $_POST['from'] ) && 'profile' === $_POST['from'] ) { |
|
| 1878 | + if ( ! empty($_POST['from']) && 'profile' === $_POST['from']) { |
|
| 1879 | 1879 | // For User Profile Page. |
| 1880 | - if( ! empty( $_POST['give_set_api_key'] ) ) { |
|
| 1880 | + if ( ! empty($_POST['give_set_api_key'])) { |
|
| 1881 | 1881 | // Generate API Key from User Profile page. |
| 1882 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1883 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1884 | - } elseif ( ! empty( $_POST['give_revoke_api_key'] ) ) { |
|
| 1882 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1883 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1884 | + } elseif ( ! empty($_POST['give_revoke_api_key'])) { |
|
| 1885 | 1885 | // Revoke API Key from User Profile page. |
| 1886 | - $this->revoke_api_key( $user->ID ); |
|
| 1886 | + $this->revoke_api_key($user->ID); |
|
| 1887 | 1887 | } else { |
| 1888 | 1888 | return false; |
| 1889 | 1889 | } |
| 1890 | 1890 | } else { |
| 1891 | 1891 | // For Tools > API page. |
| 1892 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1892 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1893 | 1893 | |
| 1894 | - if ( empty( $public_key ) && ! $regenerate ) { |
|
| 1894 | + if (empty($public_key) && ! $regenerate) { |
|
| 1895 | 1895 | // Generating API for first time. |
| 1896 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1897 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1898 | - } elseif ( $public_key && $regenerate ) { |
|
| 1896 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1897 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1898 | + } elseif ($public_key && $regenerate) { |
|
| 1899 | 1899 | // API Key already exists and Regenerating API Key. |
| 1900 | - $this->revoke_api_key( $user->ID ); |
|
| 1901 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1902 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1903 | - } elseif ( ! empty( $public_key ) && ! $regenerate ) { |
|
| 1900 | + $this->revoke_api_key($user->ID); |
|
| 1901 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1902 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1903 | + } elseif ( ! empty($public_key) && ! $regenerate) { |
|
| 1904 | 1904 | // Doing nothing, when API Key exists but still try to generate again instead of regenerating. |
| 1905 | 1905 | return false; |
| 1906 | 1906 | } else { |
| 1907 | 1907 | // Revoke API Key. |
| 1908 | - $this->revoke_api_key( $user->ID ); |
|
| 1908 | + $this->revoke_api_key($user->ID); |
|
| 1909 | 1909 | } |
| 1910 | 1910 | } |
| 1911 | 1911 | |
| 1912 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
| 1913 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
| 1912 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
| 1913 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
| 1914 | 1914 | |
| 1915 | 1915 | return true; |
| 1916 | 1916 | } |
@@ -1925,26 +1925,26 @@ discard block |
||
| 1925 | 1925 | * |
| 1926 | 1926 | * @return bool |
| 1927 | 1927 | */ |
| 1928 | - public function revoke_api_key( $user_id = 0 ) { |
|
| 1928 | + public function revoke_api_key($user_id = 0) { |
|
| 1929 | 1929 | |
| 1930 | - if ( empty( $user_id ) ) { |
|
| 1930 | + if (empty($user_id)) { |
|
| 1931 | 1931 | return false; |
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | - $user = get_userdata( $user_id ); |
|
| 1934 | + $user = get_userdata($user_id); |
|
| 1935 | 1935 | |
| 1936 | - if ( ! $user ) { |
|
| 1936 | + if ( ! $user) { |
|
| 1937 | 1937 | return false; |
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1941 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 1942 | - if ( ! empty( $public_key ) ) { |
|
| 1943 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_' . $public_key ) ) ); |
|
| 1944 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_public_key' . $user_id ) ) ); |
|
| 1945 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_secret_key' . $user_id ) ) ); |
|
| 1946 | - delete_user_meta( $user_id, $public_key ); |
|
| 1947 | - delete_user_meta( $user_id, $secret_key ); |
|
| 1940 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1941 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 1942 | + if ( ! empty($public_key)) { |
|
| 1943 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_'.$public_key))); |
|
| 1944 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_public_key'.$user_id))); |
|
| 1945 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_secret_key'.$user_id))); |
|
| 1946 | + delete_user_meta($user_id, $public_key); |
|
| 1947 | + delete_user_meta($user_id, $secret_key); |
|
| 1948 | 1948 | } else { |
| 1949 | 1949 | return false; |
| 1950 | 1950 | } |
@@ -1966,9 +1966,9 @@ discard block |
||
| 1966 | 1966 | * |
| 1967 | 1967 | * @return string |
| 1968 | 1968 | */ |
| 1969 | - private function generate_public_key( $user_email = '' ) { |
|
| 1970 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 1971 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
| 1969 | + private function generate_public_key($user_email = '') { |
|
| 1970 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 1971 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
| 1972 | 1972 | |
| 1973 | 1973 | return $public; |
| 1974 | 1974 | } |
@@ -1983,9 +1983,9 @@ discard block |
||
| 1983 | 1983 | * |
| 1984 | 1984 | * @return string |
| 1985 | 1985 | */ |
| 1986 | - private function generate_private_key( $user_id = 0 ) { |
|
| 1987 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 1988 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
| 1986 | + private function generate_private_key($user_id = 0) { |
|
| 1987 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 1988 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
| 1989 | 1989 | |
| 1990 | 1990 | return $secret; |
| 1991 | 1991 | } |
@@ -2000,8 +2000,8 @@ discard block |
||
| 2000 | 2000 | * |
| 2001 | 2001 | * @return string |
| 2002 | 2002 | */ |
| 2003 | - public function get_token( $user_id = 0 ) { |
|
| 2004 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
| 2003 | + public function get_token($user_id = 0) { |
|
| 2004 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
| 2005 | 2005 | } |
| 2006 | 2006 | |
| 2007 | 2007 | /** |
@@ -2015,9 +2015,9 @@ discard block |
||
| 2015 | 2015 | |
| 2016 | 2016 | // Default sales return |
| 2017 | 2017 | $donations = array(); |
| 2018 | - $donations['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
| 2019 | - $donations['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
| 2020 | - $donations['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
| 2018 | + $donations['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
| 2019 | + $donations['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
| 2020 | + $donations['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
| 2021 | 2021 | $donations['donations']['totals'] = give_get_total_donations(); |
| 2022 | 2022 | |
| 2023 | 2023 | return $donations; |
@@ -2034,9 +2034,9 @@ discard block |
||
| 2034 | 2034 | |
| 2035 | 2035 | // Default earnings return |
| 2036 | 2036 | $earnings = array(); |
| 2037 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
| 2038 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
| 2039 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
| 2037 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
| 2038 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
| 2039 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
| 2040 | 2040 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
| 2041 | 2041 | |
| 2042 | 2042 | return $earnings; |
@@ -2056,25 +2056,25 @@ discard block |
||
| 2056 | 2056 | * |
| 2057 | 2057 | * @return string The API key/secret for the user supplied |
| 2058 | 2058 | */ |
| 2059 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
| 2059 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
| 2060 | 2060 | |
| 2061 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
| 2061 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
| 2062 | 2062 | return $check; |
| 2063 | 2063 | } |
| 2064 | 2064 | |
| 2065 | 2065 | $return = $check; |
| 2066 | 2066 | |
| 2067 | - switch ( $meta_key ) { |
|
| 2067 | + switch ($meta_key) { |
|
| 2068 | 2068 | case 'give_user_public_key': |
| 2069 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
| 2069 | + $return = Give()->api->get_user_public_key($object_id); |
|
| 2070 | 2070 | break; |
| 2071 | 2071 | case 'give_user_secret_key': |
| 2072 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
| 2072 | + $return = Give()->api->get_user_secret_key($object_id); |
|
| 2073 | 2073 | break; |
| 2074 | 2074 | } |
| 2075 | 2075 | |
| 2076 | - if ( ! $single ) { |
|
| 2077 | - $return = array( $return ); |
|
| 2076 | + if ( ! $single) { |
|
| 2077 | + $return = array($return); |
|
| 2078 | 2078 | } |
| 2079 | 2079 | |
| 2080 | 2080 | return $return; |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | * @access private |
| 704 | 704 | * @since 1.7 |
| 705 | 705 | * |
| 706 | - * @return bool |
|
| 706 | + * @return false|null |
|
| 707 | 707 | */ |
| 708 | 708 | private function __remove_license_key_from_subscriptions() { |
| 709 | 709 | $subscriptions = get_option( 'give_subscriptions', array() ); |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | * @param $plugin_data |
| 737 | 737 | * @param $status |
| 738 | 738 | * |
| 739 | - * @return bool |
|
| 739 | + * @return false|null |
|
| 740 | 740 | */ |
| 741 | 741 | public function plugin_page_notices( $plugin_file, $plugin_data, $status ) { |
| 742 | 742 | // Bailout. |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | * |
| 759 | 759 | * @since 1.8.7 |
| 760 | 760 | * @access public |
| 761 | - * @return array |
|
| 761 | + * @return string |
|
| 762 | 762 | */ |
| 763 | 763 | public function license_state_message() { |
| 764 | 764 | $message_data = array(); |
@@ -10,11 +10,11 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -if ( ! class_exists( 'Give_License' ) ) : |
|
| 17 | +if ( ! class_exists('Give_License')) : |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Give_License Class |
@@ -143,27 +143,27 @@ discard block |
||
| 143 | 143 | * @param string $_checkout_url |
| 144 | 144 | * @param string $_account_url |
| 145 | 145 | */ |
| 146 | - public function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null ) { |
|
| 146 | + public function __construct($_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null) { |
|
| 147 | 147 | |
| 148 | 148 | $give_options = give_get_settings(); |
| 149 | 149 | |
| 150 | 150 | $this->file = $_file; |
| 151 | 151 | $this->item_name = $_item_name; |
| 152 | - $this->item_shortname = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) ); |
|
| 152 | + $this->item_shortname = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($this->item_name))); |
|
| 153 | 153 | $this->version = $_version; |
| 154 | - $this->license = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : ''; |
|
| 155 | - $this->license_data = get_option( $this->item_shortname . '_license_active' ); |
|
| 154 | + $this->license = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : ''; |
|
| 155 | + $this->license_data = get_option($this->item_shortname.'_license_active'); |
|
| 156 | 156 | $this->author = $_author; |
| 157 | - $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url; |
|
| 158 | - $this->checkout_url = is_null( $_checkout_url ) ? $this->checkout_url : $_checkout_url; |
|
| 159 | - $this->account_url = is_null( $_account_url ) ? $this->account_url : $_account_url; |
|
| 157 | + $this->api_url = is_null($_api_url) ? $this->api_url : $_api_url; |
|
| 158 | + $this->checkout_url = is_null($_checkout_url) ? $this->checkout_url : $_checkout_url; |
|
| 159 | + $this->account_url = is_null($_account_url) ? $this->account_url : $_account_url; |
|
| 160 | 160 | $this->auto_updater_obj = null; |
| 161 | 161 | |
| 162 | 162 | // Add Setting for Give Add-on activation status. |
| 163 | - $is_addon_activated = get_option( 'give_is_addon_activated' ); |
|
| 164 | - if( ! $is_addon_activated && is_object( $this ) && sizeof( $this ) > 0 ) { |
|
| 165 | - update_option( 'give_is_addon_activated', true ); |
|
| 166 | - Give_Cache::set( 'give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS ); |
|
| 163 | + $is_addon_activated = get_option('give_is_addon_activated'); |
|
| 164 | + if ( ! $is_addon_activated && is_object($this) && sizeof($this) > 0) { |
|
| 165 | + update_option('give_is_addon_activated', true); |
|
| 166 | + Give_Cache::set('give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // Setup hooks |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | private function includes() { |
| 186 | 186 | |
| 187 | - if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
| 187 | + if ( ! class_exists('EDD_SL_Plugin_Updater')) { |
|
| 188 | 188 | require_once 'admin/EDD_SL_Plugin_Updater.php'; |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -202,30 +202,30 @@ discard block |
||
| 202 | 202 | private function hooks() { |
| 203 | 203 | |
| 204 | 204 | // Register settings. |
| 205 | - add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 ); |
|
| 205 | + add_filter('give_settings_licenses', array($this, 'settings'), 1); |
|
| 206 | 206 | |
| 207 | 207 | // Activate license key on settings save. |
| 208 | - add_action( 'admin_init', array( $this, 'activate_license' ) ); |
|
| 208 | + add_action('admin_init', array($this, 'activate_license')); |
|
| 209 | 209 | |
| 210 | 210 | // Deactivate license key. |
| 211 | - add_action( 'admin_init', array( $this, 'deactivate_license' ) ); |
|
| 211 | + add_action('admin_init', array($this, 'deactivate_license')); |
|
| 212 | 212 | |
| 213 | 213 | // Updater. |
| 214 | - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); |
|
| 215 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
| 214 | + add_action('admin_init', array($this, 'auto_updater'), 0); |
|
| 215 | + add_action('admin_notices', array($this, 'notices')); |
|
| 216 | 216 | |
| 217 | 217 | // Check license weekly. |
| 218 | - Give_Cron::add_weekly_event( array( $this, 'weekly_license_check' ) ); |
|
| 219 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_license_check' ) ); |
|
| 218 | + Give_Cron::add_weekly_event(array($this, 'weekly_license_check')); |
|
| 219 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_license_check')); |
|
| 220 | 220 | |
| 221 | 221 | // Check subscription weekly. |
| 222 | - Give_Cron::add_weekly_event( array( $this, 'weekly_subscription_check' ) ); |
|
| 223 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_subscription_check' ) ); |
|
| 222 | + Give_Cron::add_weekly_event(array($this, 'weekly_subscription_check')); |
|
| 223 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_subscription_check')); |
|
| 224 | 224 | |
| 225 | 225 | // Show addon notice on plugin page. |
| 226 | - $plugin_name = explode( 'plugins/', $this->file ); |
|
| 227 | - $plugin_name = end( $plugin_name ); |
|
| 228 | - add_action( "after_plugin_row_{$plugin_name}", array( $this, 'plugin_page_notices' ), 10, 3 ); |
|
| 226 | + $plugin_name = explode('plugins/', $this->file); |
|
| 227 | + $plugin_name = end($plugin_name); |
|
| 228 | + add_action("after_plugin_row_{$plugin_name}", array($this, 'plugin_page_notices'), 10, 3); |
|
| 229 | 229 | |
| 230 | 230 | } |
| 231 | 231 | |
@@ -265,16 +265,16 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @return array License settings. |
| 267 | 267 | */ |
| 268 | - public function settings( $settings ) { |
|
| 268 | + public function settings($settings) { |
|
| 269 | 269 | |
| 270 | 270 | $give_license_settings = array( |
| 271 | 271 | array( |
| 272 | 272 | 'name' => $this->item_name, |
| 273 | - 'id' => $this->item_shortname . '_license_key', |
|
| 273 | + 'id' => $this->item_shortname.'_license_key', |
|
| 274 | 274 | 'desc' => '', |
| 275 | 275 | 'type' => 'license_key', |
| 276 | 276 | 'options' => array( |
| 277 | - 'license' => get_option( $this->item_shortname . '_license_active' ), |
|
| 277 | + 'license' => get_option($this->item_shortname.'_license_active'), |
|
| 278 | 278 | 'shortname' => $this->item_shortname, |
| 279 | 279 | 'item_name' => $this->item_name, |
| 280 | 280 | 'api_url' => $this->api_url, |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | ), |
| 286 | 286 | ); |
| 287 | 287 | |
| 288 | - return array_merge( $settings, $give_license_settings ); |
|
| 288 | + return array_merge($settings, $give_license_settings); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -300,18 +300,18 @@ discard block |
||
| 300 | 300 | * |
| 301 | 301 | * @return array License settings content. |
| 302 | 302 | */ |
| 303 | - public function license_settings_content( $settings ) { |
|
| 303 | + public function license_settings_content($settings) { |
|
| 304 | 304 | |
| 305 | 305 | $give_license_settings = array( |
| 306 | 306 | array( |
| 307 | - 'name' => __( 'Add-on Licenses', 'give' ), |
|
| 307 | + 'name' => __('Add-on Licenses', 'give'), |
|
| 308 | 308 | 'desc' => '<hr>', |
| 309 | 309 | 'type' => 'give_title', |
| 310 | 310 | 'id' => 'give_title', |
| 311 | 311 | ), |
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | - return array_merge( $settings, $give_license_settings ); |
|
| 314 | + return array_merge($settings, $give_license_settings); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -326,56 +326,56 @@ discard block |
||
| 326 | 326 | */ |
| 327 | 327 | public function activate_license() { |
| 328 | 328 | // Bailout. |
| 329 | - if( ! $this->__is_user_can_edit_license() ) { |
|
| 329 | + if ( ! $this->__is_user_can_edit_license()) { |
|
| 330 | 330 | return; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // Allow third party addon developers to handle license activation. |
| 334 | - if ( $this->__is_third_party_addon() ) { |
|
| 335 | - do_action( 'give_activate_license', $this ); |
|
| 334 | + if ($this->__is_third_party_addon()) { |
|
| 335 | + do_action('give_activate_license', $this); |
|
| 336 | 336 | |
| 337 | 337 | return; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | // Delete previous license setting if a empty license key submitted. |
| 341 | - if ( empty( $_POST[ $this->item_shortname . '_license_key' ] ) ) { |
|
| 342 | - delete_option( $this->item_shortname . '_license_active' ); |
|
| 341 | + if (empty($_POST[$this->item_shortname.'_license_key'])) { |
|
| 342 | + delete_option($this->item_shortname.'_license_active'); |
|
| 343 | 343 | |
| 344 | 344 | return; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // Do not simultaneously activate add-ons if the user want to deactivate a specific add-on. |
| 348 | - foreach ( $_POST as $key => $value ) { |
|
| 349 | - if ( false !== strpos( $key, 'license_key_deactivate' ) ) { |
|
| 348 | + foreach ($_POST as $key => $value) { |
|
| 349 | + if (false !== strpos($key, 'license_key_deactivate')) { |
|
| 350 | 350 | // Don't activate a key when deactivating a different key |
| 351 | 351 | return; |
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | // Check if plugin previously installed. |
| 356 | - if ( $this->is_valid_license() ) { |
|
| 356 | + if ($this->is_valid_license()) { |
|
| 357 | 357 | return; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | // Get license key. |
| 361 | - $this->license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] ); |
|
| 361 | + $this->license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']); |
|
| 362 | 362 | |
| 363 | 363 | // Delete previous license key from subscription if previously added. |
| 364 | 364 | $this->__remove_license_key_from_subscriptions(); |
| 365 | 365 | |
| 366 | 366 | // Make sure there are no api errors. |
| 367 | - if ( ! ( $license_data = $this->get_license_info( 'activate_license' ) ) ) { |
|
| 367 | + if ( ! ($license_data = $this->get_license_info('activate_license'))) { |
|
| 368 | 368 | return; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Tell WordPress to look for updates. |
| 372 | - set_site_transient( 'update_plugins', null ); |
|
| 372 | + set_site_transient('update_plugins', null); |
|
| 373 | 373 | |
| 374 | 374 | // Add license data. |
| 375 | - update_option( $this->item_shortname . '_license_active', $license_data ); |
|
| 375 | + update_option($this->item_shortname.'_license_active', $license_data); |
|
| 376 | 376 | |
| 377 | 377 | // Add license key. |
| 378 | - give_update_option( "{$this->item_shortname}_license_key", $this->license ); |
|
| 378 | + give_update_option("{$this->item_shortname}_license_key", $this->license); |
|
| 379 | 379 | |
| 380 | 380 | // Check subscription for license key and store this to db (if any). |
| 381 | 381 | $this->__single_subscription_check(); |
@@ -393,33 +393,33 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public function deactivate_license() { |
| 395 | 395 | // Bailout. |
| 396 | - if( ! $this->__is_user_can_edit_license() ) { |
|
| 396 | + if ( ! $this->__is_user_can_edit_license()) { |
|
| 397 | 397 | return; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // Allow third party add-on developers to handle license deactivation. |
| 401 | - if ( $this->__is_third_party_addon() ) { |
|
| 402 | - do_action( 'give_deactivate_license', $this ); |
|
| 401 | + if ($this->__is_third_party_addon()) { |
|
| 402 | + do_action('give_deactivate_license', $this); |
|
| 403 | 403 | |
| 404 | 404 | return; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | // Run on deactivate button press. |
| 408 | - if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) { |
|
| 408 | + if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) { |
|
| 409 | 409 | |
| 410 | 410 | // Make sure there are no api errors. |
| 411 | - if ( ! ( $license_data = $this->get_license_info( 'deactivate_license' ) ) ) { |
|
| 411 | + if ( ! ($license_data = $this->get_license_info('deactivate_license'))) { |
|
| 412 | 412 | return; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // Ensure deactivated successfully. |
| 416 | - if ( isset( $license_data->success ) ) { |
|
| 416 | + if (isset($license_data->success)) { |
|
| 417 | 417 | |
| 418 | 418 | // Remove license data. |
| 419 | - delete_option( $this->item_shortname . '_license_active' ); |
|
| 419 | + delete_option($this->item_shortname.'_license_active'); |
|
| 420 | 420 | |
| 421 | 421 | // Delete licence data. |
| 422 | - give_delete_option( $this->item_shortname . '_license_key' ); |
|
| 422 | + give_delete_option($this->item_shortname.'_license_key'); |
|
| 423 | 423 | |
| 424 | 424 | // Remove license key from subscriptions if exist. |
| 425 | 425 | $this->__remove_license_key_from_subscriptions(); |
@@ -439,25 +439,25 @@ discard block |
||
| 439 | 439 | public function weekly_license_check() { |
| 440 | 440 | |
| 441 | 441 | if ( |
| 442 | - ! empty( $_POST['give_settings'] ) || |
|
| 443 | - empty( $this->license ) |
|
| 442 | + ! empty($_POST['give_settings']) || |
|
| 443 | + empty($this->license) |
|
| 444 | 444 | ) { |
| 445 | 445 | return; |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // Allow third party add-on developers to handle their license check. |
| 449 | - if ( $this->__is_third_party_addon() ) { |
|
| 450 | - do_action( 'give_weekly_license_check', $this ); |
|
| 449 | + if ($this->__is_third_party_addon()) { |
|
| 450 | + do_action('give_weekly_license_check', $this); |
|
| 451 | 451 | |
| 452 | 452 | return; |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | // Make sure there are no api errors. |
| 456 | - if ( ! ( $license_data = $this->get_license_info( 'check_license' ) ) ) { |
|
| 456 | + if ( ! ($license_data = $this->get_license_info('check_license'))) { |
|
| 457 | 457 | return; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - update_option( $this->item_shortname . '_license_active', $license_data ); |
|
| 460 | + update_option($this->item_shortname.'_license_active', $license_data); |
|
| 461 | 461 | |
| 462 | 462 | return; |
| 463 | 463 | } |
@@ -473,21 +473,21 @@ discard block |
||
| 473 | 473 | public function weekly_subscription_check() { |
| 474 | 474 | // Bailout. |
| 475 | 475 | if ( |
| 476 | - ! empty( $_POST['give_settings'] ) || |
|
| 477 | - empty( $this->license ) |
|
| 476 | + ! empty($_POST['give_settings']) || |
|
| 477 | + empty($this->license) |
|
| 478 | 478 | ) { |
| 479 | 479 | return; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // Remove old subscription data. |
| 483 | - if ( absint( get_option( '_give_subscriptions_edit_last', true ) ) < current_time( 'timestamp', 1 ) ) { |
|
| 484 | - delete_option( 'give_subscriptions' ); |
|
| 485 | - update_option( '_give_subscriptions_edit_last', strtotime( '+ 1 day', current_time( 'timestamp', 1 ) ) ); |
|
| 483 | + if (absint(get_option('_give_subscriptions_edit_last', true)) < current_time('timestamp', 1)) { |
|
| 484 | + delete_option('give_subscriptions'); |
|
| 485 | + update_option('_give_subscriptions_edit_last', strtotime('+ 1 day', current_time('timestamp', 1))); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | // Allow third party add-on developers to handle their subscription check. |
| 489 | - if ( $this->__is_third_party_addon() ) { |
|
| 490 | - do_action( 'give_weekly_subscription_check', $this ); |
|
| 489 | + if ($this->__is_third_party_addon()) { |
|
| 490 | + do_action('give_weekly_subscription_check', $this); |
|
| 491 | 491 | |
| 492 | 492 | return; |
| 493 | 493 | } |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | * @return void |
| 505 | 505 | */ |
| 506 | 506 | private function __single_subscription_check() { |
| 507 | - if ( empty( $this->license ) ) { |
|
| 507 | + if (empty($this->license)) { |
|
| 508 | 508 | return; |
| 509 | 509 | } |
| 510 | 510 | |
@@ -512,29 +512,29 @@ discard block |
||
| 512 | 512 | // Do not get confused with edd_action check_subscription. |
| 513 | 513 | // By default edd software licensing api does not have api to check subscription. |
| 514 | 514 | // This is a custom feature to check subscriptions. |
| 515 | - if ( ! ( $subscription_data = $this->get_license_info( 'check_subscription', true ) ) ) { |
|
| 515 | + if ( ! ($subscription_data = $this->get_license_info('check_subscription', true))) { |
|
| 516 | 516 | return; |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | |
| 520 | - if ( ! empty( $subscription_data['success'] ) && absint( $subscription_data['success'] ) ) { |
|
| 521 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
| 520 | + if ( ! empty($subscription_data['success']) && absint($subscription_data['success'])) { |
|
| 521 | + $subscriptions = get_option('give_subscriptions', array()); |
|
| 522 | 522 | |
| 523 | 523 | // Update subscription data only if subscription does not exist already. |
| 524 | - $subscriptions[ $subscription_data['id'] ] = $subscription_data; |
|
| 524 | + $subscriptions[$subscription_data['id']] = $subscription_data; |
|
| 525 | 525 | |
| 526 | 526 | |
| 527 | 527 | // Initiate default set of license for subscription. |
| 528 | - if( ! isset( $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
| 529 | - $subscriptions[ $subscription_data['id']]['licenses'] = array(); |
|
| 528 | + if ( ! isset($subscriptions[$subscription_data['id']]['licenses'])) { |
|
| 529 | + $subscriptions[$subscription_data['id']]['licenses'] = array(); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // Store licenses for subscription. |
| 533 | - if ( ! in_array( $this->license, $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
| 534 | - $subscriptions[ $subscription_data['id']]['licenses'][] = $this->license; |
|
| 533 | + if ( ! in_array($this->license, $subscriptions[$subscription_data['id']]['licenses'])) { |
|
| 534 | + $subscriptions[$subscription_data['id']]['licenses'][] = $this->license; |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - update_option( 'give_subscriptions', $subscriptions ); |
|
| 537 | + update_option('give_subscriptions', $subscriptions); |
|
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | |
@@ -548,12 +548,12 @@ discard block |
||
| 548 | 548 | */ |
| 549 | 549 | public function notices() { |
| 550 | 550 | |
| 551 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
| 551 | + if ( ! current_user_can('manage_give_settings')) { |
|
| 552 | 552 | return; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // Do not show licenses notices on license tab. |
| 556 | - if ( 'licenses' === give_get_current_setting_tab() ) { |
|
| 556 | + if ('licenses' === give_get_current_setting_tab()) { |
|
| 557 | 557 | return; |
| 558 | 558 | } |
| 559 | 559 | |
@@ -562,118 +562,118 @@ discard block |
||
| 562 | 562 | static $addon_license_key_in_subscriptions; |
| 563 | 563 | |
| 564 | 564 | // Set default value. |
| 565 | - $addon_license_key_in_subscriptions = ! empty( $addon_license_key_in_subscriptions ) ? $addon_license_key_in_subscriptions : array(); |
|
| 565 | + $addon_license_key_in_subscriptions = ! empty($addon_license_key_in_subscriptions) ? $addon_license_key_in_subscriptions : array(); |
|
| 566 | 566 | $messages = array(); |
| 567 | 567 | |
| 568 | 568 | // Check whether admin has Give Add-on activated since 24 hours? |
| 569 | - $is_license_notice_hidden = Give_Cache::get( 'give_cache_hide_license_notice_after_activation' ); |
|
| 569 | + $is_license_notice_hidden = Give_Cache::get('give_cache_hide_license_notice_after_activation'); |
|
| 570 | 570 | |
| 571 | 571 | // Display Invalid License notice, if its more than 24 hours since first Give Add-on activation. |
| 572 | 572 | if ( |
| 573 | - empty( $this->license ) |
|
| 574 | - && empty( $showed_invalid_message ) |
|
| 575 | - && ( false === $is_license_notice_hidden ) |
|
| 573 | + empty($this->license) |
|
| 574 | + && empty($showed_invalid_message) |
|
| 575 | + && (false === $is_license_notice_hidden) |
|
| 576 | 576 | ) { |
| 577 | 577 | |
| 578 | - Give()->notices->register_notice( array( |
|
| 578 | + Give()->notices->register_notice(array( |
|
| 579 | 579 | 'id' => 'give-invalid-license', |
| 580 | 580 | 'type' => 'error', |
| 581 | 581 | 'description' => sprintf( |
| 582 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
| 583 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
| 582 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
| 583 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
| 584 | 584 | ), |
| 585 | 585 | 'dismissible_type' => 'user', |
| 586 | 586 | 'dismiss_interval' => 'shortly', |
| 587 | - ) ); |
|
| 587 | + )); |
|
| 588 | 588 | |
| 589 | 589 | $showed_invalid_message = true; |
| 590 | 590 | |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | // Get subscriptions. |
| 594 | - $subscriptions = get_option( 'give_subscriptions' ); |
|
| 594 | + $subscriptions = get_option('give_subscriptions'); |
|
| 595 | 595 | |
| 596 | 596 | // Show subscription messages. |
| 597 | - if ( ! empty( $subscriptions ) && ! $showed_subscriptions_message ) { |
|
| 597 | + if ( ! empty($subscriptions) && ! $showed_subscriptions_message) { |
|
| 598 | 598 | |
| 599 | - foreach ( $subscriptions as $subscription ) { |
|
| 599 | + foreach ($subscriptions as $subscription) { |
|
| 600 | 600 | // Subscription expires timestamp. |
| 601 | - $subscription_expires = strtotime( $subscription['expires'] ); |
|
| 601 | + $subscription_expires = strtotime($subscription['expires']); |
|
| 602 | 602 | |
| 603 | 603 | // Start showing subscriptions message before one week of renewal date. |
| 604 | - if ( strtotime( '- 7 days', $subscription_expires ) > current_time( 'timestamp', 1 ) ) { |
|
| 604 | + if (strtotime('- 7 days', $subscription_expires) > current_time('timestamp', 1)) { |
|
| 605 | 605 | continue; |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | // Check if subscription message already exist in messages. |
| 609 | - if ( array_key_exists( $subscription['id'], $messages ) ) { |
|
| 609 | + if (array_key_exists($subscription['id'], $messages)) { |
|
| 610 | 610 | continue; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | // Check if license already expired. |
| 614 | - if ( strtotime( $subscription['expires'] ) < current_time( 'timestamp', 1 ) ) { |
|
| 615 | - Give()->notices->register_notice( array( |
|
| 614 | + if (strtotime($subscription['expires']) < current_time('timestamp', 1)) { |
|
| 615 | + Give()->notices->register_notice(array( |
|
| 616 | 616 | 'id' => "give-expired-subscription-{$subscription['id']}", |
| 617 | 617 | 'type' => 'error', |
| 618 | 618 | 'description' => sprintf( |
| 619 | - __( 'Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give' ), |
|
| 620 | - urldecode( $subscription['invoice_url'] ), |
|
| 619 | + __('Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give'), |
|
| 620 | + urldecode($subscription['invoice_url']), |
|
| 621 | 621 | $subscription['payment_id'], |
| 622 | 622 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
| 623 | 623 | Give()->notices->get_dismiss_link(array( |
| 624 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
| 624 | + 'title' => __('Click here if already renewed', 'give'), |
|
| 625 | 625 | 'dismissible_type' => 'user', |
| 626 | 626 | 'dismiss_interval' => 'permanent', |
| 627 | 627 | )) |
| 628 | 628 | ), |
| 629 | 629 | 'dismissible_type' => 'user', |
| 630 | 630 | 'dismiss_interval' => 'shortly', |
| 631 | - ) ); |
|
| 631 | + )); |
|
| 632 | 632 | } else { |
| 633 | - Give()->notices->register_notice( array( |
|
| 633 | + Give()->notices->register_notice(array( |
|
| 634 | 634 | 'id' => "give-expires-subscription-{$subscription['id']}", |
| 635 | 635 | 'type' => 'error', |
| 636 | 636 | 'description' => sprintf( |
| 637 | - __( 'Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give' ), |
|
| 638 | - human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscription['expires'] ) ), |
|
| 639 | - urldecode( $subscription['invoice_url'] ), |
|
| 637 | + __('Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give'), |
|
| 638 | + human_time_diff(current_time('timestamp', 1), strtotime($subscription['expires'])), |
|
| 639 | + urldecode($subscription['invoice_url']), |
|
| 640 | 640 | $subscription['payment_id'], |
| 641 | 641 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
| 642 | 642 | Give()->notices->get_dismiss_link(array( |
| 643 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
| 643 | + 'title' => __('Click here if already renewed', 'give'), |
|
| 644 | 644 | 'dismissible_type' => 'user', |
| 645 | 645 | 'dismiss_interval' => 'permanent', |
| 646 | 646 | )) |
| 647 | 647 | ), |
| 648 | 648 | 'dismissible_type' => 'user', |
| 649 | 649 | 'dismiss_interval' => 'shortly', |
| 650 | - ) ); |
|
| 650 | + )); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | // Stop validation for these license keys. |
| 654 | - $addon_license_key_in_subscriptions = array_merge( $addon_license_key_in_subscriptions, $subscription['licenses'] ); |
|
| 654 | + $addon_license_key_in_subscriptions = array_merge($addon_license_key_in_subscriptions, $subscription['licenses']); |
|
| 655 | 655 | }// End foreach(). |
| 656 | 656 | $showed_subscriptions_message = true; |
| 657 | 657 | }// End if(). |
| 658 | 658 | |
| 659 | 659 | // Show Non Subscription Give Add-on messages. |
| 660 | 660 | if ( |
| 661 | - ! in_array( $this->license, $addon_license_key_in_subscriptions ) |
|
| 662 | - && ! empty( $this->license ) |
|
| 663 | - && empty( $showed_invalid_message ) |
|
| 661 | + ! in_array($this->license, $addon_license_key_in_subscriptions) |
|
| 662 | + && ! empty($this->license) |
|
| 663 | + && empty($showed_invalid_message) |
|
| 664 | 664 | && ! $this->is_valid_license() |
| 665 | 665 | ) { |
| 666 | 666 | |
| 667 | - Give()->notices->register_notice( array( |
|
| 667 | + Give()->notices->register_notice(array( |
|
| 668 | 668 | 'id' => 'give-invalid-license', |
| 669 | 669 | 'type' => 'error', |
| 670 | 670 | 'description' => sprintf( |
| 671 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
| 672 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
| 671 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
| 672 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
| 673 | 673 | ), |
| 674 | 674 | 'dismissible_type' => 'user', |
| 675 | 675 | 'dismiss_interval' => 'shortly', |
| 676 | - ) ); |
|
| 676 | + )); |
|
| 677 | 677 | |
| 678 | 678 | $showed_invalid_message = true; |
| 679 | 679 | |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | * @return bool |
| 690 | 690 | */ |
| 691 | 691 | public function is_valid_license() { |
| 692 | - if ( apply_filters( 'give_is_valid_license', ( is_object( $this->license_data ) && ! empty( $this->license_data ) && property_exists( $this->license_data, 'license' ) && 'valid' === $this->license_data->license ) ) ) { |
|
| 692 | + if (apply_filters('give_is_valid_license', (is_object($this->license_data) && ! empty($this->license_data) && property_exists($this->license_data, 'license') && 'valid' === $this->license_data->license))) { |
|
| 693 | 693 | return true; |
| 694 | 694 | } |
| 695 | 695 | |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | * @return bool |
| 706 | 706 | */ |
| 707 | 707 | private function __is_third_party_addon() { |
| 708 | - return ( false === strpos( $this->api_url, 'givewp.com/' ) ); |
|
| 708 | + return (false === strpos($this->api_url, 'givewp.com/')); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -720,25 +720,25 @@ discard block |
||
| 720 | 720 | * @return bool |
| 721 | 721 | */ |
| 722 | 722 | private function __remove_license_key_from_subscriptions() { |
| 723 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
| 723 | + $subscriptions = get_option('give_subscriptions', array()); |
|
| 724 | 724 | |
| 725 | 725 | // Bailout. |
| 726 | - if ( empty( $this->license ) ) { |
|
| 726 | + if (empty($this->license)) { |
|
| 727 | 727 | return false; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - if ( ! empty( $subscriptions ) ) { |
|
| 731 | - foreach ( $subscriptions as $subscription_id => $subscription ) { |
|
| 732 | - $license_index = array_search( $this->license, $subscription['licenses'] ); |
|
| 733 | - if ( false !== $license_index ) { |
|
| 730 | + if ( ! empty($subscriptions)) { |
|
| 731 | + foreach ($subscriptions as $subscription_id => $subscription) { |
|
| 732 | + $license_index = array_search($this->license, $subscription['licenses']); |
|
| 733 | + if (false !== $license_index) { |
|
| 734 | 734 | // Remove license key. |
| 735 | - unset( $subscriptions[ $subscription_id ]['licenses'][ $license_index ] ); |
|
| 735 | + unset($subscriptions[$subscription_id]['licenses'][$license_index]); |
|
| 736 | 736 | |
| 737 | 737 | // Rearrange license keys. |
| 738 | - $subscriptions[ $subscription_id ]['licenses'] = array_values( $subscriptions[ $subscription_id ]['licenses'] ); |
|
| 738 | + $subscriptions[$subscription_id]['licenses'] = array_values($subscriptions[$subscription_id]['licenses']); |
|
| 739 | 739 | |
| 740 | 740 | // Update subscription information. |
| 741 | - update_option( 'give_subscriptions', $subscriptions ); |
|
| 741 | + update_option('give_subscriptions', $subscriptions); |
|
| 742 | 742 | break; |
| 743 | 743 | } |
| 744 | 744 | } |
@@ -752,17 +752,17 @@ discard block |
||
| 752 | 752 | * |
| 753 | 753 | * @return bool |
| 754 | 754 | */ |
| 755 | - public function plugin_page_notices( $plugin_file, $plugin_data, $status ) { |
|
| 755 | + public function plugin_page_notices($plugin_file, $plugin_data, $status) { |
|
| 756 | 756 | // Bailout. |
| 757 | - if ( $this->is_valid_license() ) { |
|
| 757 | + if ($this->is_valid_license()) { |
|
| 758 | 758 | return false; |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | $update_notice_wrap = '<tr class="give-addon-notice-tr active"><td colspan="3" class="colspanchange"><div class="notice inline notice-warning notice-alt give-invalid-license"><p><span class="dashicons dashicons-info"></span> %s</p></div></td></tr>'; |
| 762 | 762 | $message = $this->license_state_message(); |
| 763 | 763 | |
| 764 | - if ( ! empty( $message['message'] ) ) { |
|
| 765 | - echo sprintf( $update_notice_wrap, $message['message'] ); |
|
| 764 | + if ( ! empty($message['message'])) { |
|
| 765 | + echo sprintf($update_notice_wrap, $message['message']); |
|
| 766 | 766 | } |
| 767 | 767 | } |
| 768 | 768 | |
@@ -777,11 +777,11 @@ discard block |
||
| 777 | 777 | public function license_state_message() { |
| 778 | 778 | $message_data = array(); |
| 779 | 779 | |
| 780 | - if ( ! $this->is_valid_license() ) { |
|
| 780 | + if ( ! $this->is_valid_license()) { |
|
| 781 | 781 | |
| 782 | 782 | $message_data['message'] = sprintf( |
| 783 | 783 | 'Please <a href="%1$s">activate your license</a> to receive updates and support for the %2$s add-on.', |
| 784 | - esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) ), |
|
| 784 | + esc_url(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses')), |
|
| 785 | 785 | $this->item_name |
| 786 | 786 | ); |
| 787 | 787 | } |
@@ -796,18 +796,18 @@ discard block |
||
| 796 | 796 | * @since 1.8.9 |
| 797 | 797 | * @access private |
| 798 | 798 | */ |
| 799 | - private function __is_user_can_edit_license(){ |
|
| 799 | + private function __is_user_can_edit_license() { |
|
| 800 | 800 | // Bailout. |
| 801 | 801 | if ( |
| 802 | - empty( $_POST[ $this->item_shortname . '_license_key' ] ) || |
|
| 803 | - ! current_user_can( 'manage_give_settings' ) |
|
| 802 | + empty($_POST[$this->item_shortname.'_license_key']) || |
|
| 803 | + ! current_user_can('manage_give_settings') |
|
| 804 | 804 | ) { |
| 805 | 805 | return false; |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | // Security check. |
| 809 | - if ( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) ) { |
|
| 810 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 809 | + if ( ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')) { |
|
| 810 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | return true; |
@@ -825,8 +825,8 @@ discard block |
||
| 825 | 825 | * |
| 826 | 826 | * @return mixed |
| 827 | 827 | */ |
| 828 | - public function get_license_info( $edd_action = '', $response_in_array = false ) { |
|
| 829 | - if( empty( $edd_action ) ) { |
|
| 828 | + public function get_license_info($edd_action = '', $response_in_array = false) { |
|
| 829 | + if (empty($edd_action)) { |
|
| 830 | 830 | return false; |
| 831 | 831 | } |
| 832 | 832 | |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | $api_params = array( |
| 835 | 835 | 'edd_action' => $edd_action, // never change from "edd_" to "give_"! |
| 836 | 836 | 'license' => $this->license, |
| 837 | - 'item_name' => urlencode( $this->item_name ), |
|
| 837 | + 'item_name' => urlencode($this->item_name), |
|
| 838 | 838 | 'url' => home_url(), |
| 839 | 839 | ); |
| 840 | 840 | |
@@ -849,11 +849,11 @@ discard block |
||
| 849 | 849 | ); |
| 850 | 850 | |
| 851 | 851 | // Make sure there are no errors. |
| 852 | - if ( is_wp_error( $response ) ) { |
|
| 852 | + if (is_wp_error($response)) { |
|
| 853 | 853 | return false; |
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - return json_decode( wp_remote_retrieve_body( $response ), $response_in_array ); |
|
| 856 | + return json_decode(wp_remote_retrieve_body($response), $response_in_array); |
|
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param string $user_login Username |
| 175 | 175 | * @param string $user_pass Password |
| 176 | 176 | * |
| 177 | - * @return bool |
|
| 177 | + * @return false|null |
|
| 178 | 178 | */ |
| 179 | 179 | function give_log_user_in( $user_id, $user_login, $user_pass ) { |
| 180 | 180 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @param array $data Data sent from the register form |
| 217 | 217 | * |
| 218 | - * @return bool |
|
| 218 | + * @return false|null |
|
| 219 | 219 | */ |
| 220 | 220 | function give_process_register_form( $data ) { |
| 221 | 221 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -26,23 +26,23 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return string Login form |
| 28 | 28 | */ |
| 29 | -function give_login_form( $login_redirect = '', $logout_redirect = '' ) { |
|
| 30 | - if ( empty( $login_redirect ) ) { |
|
| 31 | - $login_redirect = add_query_arg( 'give-login-success', 'true', give_get_current_page_url() ); |
|
| 29 | +function give_login_form($login_redirect = '', $logout_redirect = '') { |
|
| 30 | + if (empty($login_redirect)) { |
|
| 31 | + $login_redirect = add_query_arg('give-login-success', 'true', give_get_current_page_url()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( empty( $logout_redirect ) ) { |
|
| 35 | - $logout_redirect = add_query_arg( 'give-logout-success', 'true', give_get_current_page_url() ); |
|
| 34 | + if (empty($logout_redirect)) { |
|
| 35 | + $logout_redirect = add_query_arg('give-logout-success', 'true', give_get_current_page_url()); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Add user_logout action to logout url. |
| 39 | 39 | $logout_redirect = add_query_arg( |
| 40 | 40 | array( |
| 41 | 41 | 'give_action' => 'user_logout', |
| 42 | - 'give_logout_nonce' => wp_create_nonce( 'give-logout-nonce' ), |
|
| 43 | - 'give_logout_redirect' => urlencode( $logout_redirect ), |
|
| 42 | + 'give_logout_nonce' => wp_create_nonce('give-logout-nonce'), |
|
| 43 | + 'give_logout_redirect' => urlencode($logout_redirect), |
|
| 44 | 44 | ), |
| 45 | - home_url( '/' ) |
|
| 45 | + home_url('/') |
|
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | ob_start(); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | ) |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - return apply_filters( 'give_login_form', ob_get_clean() ); |
|
| 58 | + return apply_filters('give_login_form', ob_get_clean()); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return string Register form |
| 70 | 70 | */ |
| 71 | -function give_register_form( $redirect = '' ) { |
|
| 72 | - if ( empty( $redirect ) ) { |
|
| 71 | +function give_register_form($redirect = '') { |
|
| 72 | + if (empty($redirect)) { |
|
| 73 | 73 | $redirect = give_get_current_page_url(); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | ob_start(); |
| 77 | 77 | |
| 78 | - if ( ! is_user_logged_in() ) { |
|
| 78 | + if ( ! is_user_logged_in()) { |
|
| 79 | 79 | give_get_template( |
| 80 | 80 | 'shortcode-register', |
| 81 | 81 | array( |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return apply_filters( 'give_register_form', ob_get_clean() ); |
|
| 87 | + return apply_filters('give_register_form', ob_get_clean()); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -96,34 +96,34 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @return void |
| 98 | 98 | */ |
| 99 | -function give_process_login_form( $data ) { |
|
| 100 | - if ( wp_verify_nonce( $data['give_login_nonce'], 'give-login-nonce' ) ) { |
|
| 101 | - $user_data = get_user_by( 'login', $data['give_user_login'] ); |
|
| 102 | - if ( ! $user_data ) { |
|
| 103 | - $user_data = get_user_by( 'email', $data['give_user_login'] ); |
|
| 99 | +function give_process_login_form($data) { |
|
| 100 | + if (wp_verify_nonce($data['give_login_nonce'], 'give-login-nonce')) { |
|
| 101 | + $user_data = get_user_by('login', $data['give_user_login']); |
|
| 102 | + if ( ! $user_data) { |
|
| 103 | + $user_data = get_user_by('email', $data['give_user_login']); |
|
| 104 | 104 | } |
| 105 | - if ( $user_data ) { |
|
| 105 | + if ($user_data) { |
|
| 106 | 106 | $user_ID = $user_data->ID; |
| 107 | 107 | $user_email = $user_data->user_email; |
| 108 | - if ( wp_check_password( $data['give_user_pass'], $user_data->user_pass, $user_ID ) ) { |
|
| 109 | - give_log_user_in( $user_data->ID, $data['give_user_login'], $data['give_user_pass'] ); |
|
| 108 | + if (wp_check_password($data['give_user_pass'], $user_data->user_pass, $user_ID)) { |
|
| 109 | + give_log_user_in($user_data->ID, $data['give_user_login'], $data['give_user_pass']); |
|
| 110 | 110 | } else { |
| 111 | - give_set_error( 'password_incorrect', __( 'The password you entered is incorrect.', 'give' ) ); |
|
| 111 | + give_set_error('password_incorrect', __('The password you entered is incorrect.', 'give')); |
|
| 112 | 112 | } |
| 113 | 113 | } else { |
| 114 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) ); |
|
| 114 | + give_set_error('username_incorrect', __('The username you entered does not exist.', 'give')); |
|
| 115 | 115 | } |
| 116 | 116 | // Check for errors and redirect if none present |
| 117 | 117 | $errors = give_get_errors(); |
| 118 | - if ( ! $errors ) { |
|
| 119 | - $redirect = apply_filters( 'give_login_redirect', $data['give_login_redirect'], $user_ID ); |
|
| 120 | - wp_redirect( $redirect ); |
|
| 118 | + if ( ! $errors) { |
|
| 119 | + $redirect = apply_filters('give_login_redirect', $data['give_login_redirect'], $user_ID); |
|
| 120 | + wp_redirect($redirect); |
|
| 121 | 121 | give_die(); |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | -add_action( 'give_user_login', 'give_process_login_form' ); |
|
| 126 | +add_action('give_user_login', 'give_process_login_form'); |
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -135,18 +135,18 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @return void |
| 137 | 137 | */ |
| 138 | -function give_process_user_logout( $data ) { |
|
| 139 | - if ( wp_verify_nonce( $data['give_logout_nonce'], 'give-logout-nonce' ) && is_user_logged_in() ) { |
|
| 138 | +function give_process_user_logout($data) { |
|
| 139 | + if (wp_verify_nonce($data['give_logout_nonce'], 'give-logout-nonce') && is_user_logged_in()) { |
|
| 140 | 140 | |
| 141 | 141 | // Prevent occurring of any custom action on wp_logout. |
| 142 | - remove_all_actions( 'wp_logout' ); |
|
| 142 | + remove_all_actions('wp_logout'); |
|
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | 145 | * Fires before processing user logout. |
| 146 | 146 | * |
| 147 | 147 | * @since 1.0 |
| 148 | 148 | */ |
| 149 | - do_action( 'give_before_user_logout' ); |
|
| 149 | + do_action('give_before_user_logout'); |
|
| 150 | 150 | |
| 151 | 151 | // Logout user. |
| 152 | 152 | wp_logout(); |
@@ -156,14 +156,14 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @since 1.0 |
| 158 | 158 | */ |
| 159 | - do_action( 'give_after_user_logout' ); |
|
| 159 | + do_action('give_after_user_logout'); |
|
| 160 | 160 | |
| 161 | - wp_redirect( $data['give_logout_redirect'] ); |
|
| 161 | + wp_redirect($data['give_logout_redirect']); |
|
| 162 | 162 | give_die(); |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | -add_action( 'give_user_logout', 'give_process_user_logout' ); |
|
| 166 | +add_action('give_user_logout', 'give_process_user_logout'); |
|
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | 169 | * Log User In |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return bool |
| 178 | 178 | */ |
| 179 | -function give_log_user_in( $user_id, $user_login, $user_pass ) { |
|
| 179 | +function give_log_user_in($user_id, $user_login, $user_pass) { |
|
| 180 | 180 | |
| 181 | - if ( $user_id < 1 ) { |
|
| 181 | + if ($user_id < 1) { |
|
| 182 | 182 | return false; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - wp_set_auth_cookie( $user_id ); |
|
| 186 | - wp_set_current_user( $user_id, $user_login ); |
|
| 185 | + wp_set_auth_cookie($user_id); |
|
| 186 | + wp_set_current_user($user_id, $user_login); |
|
| 187 | 187 | |
| 188 | 188 | /** |
| 189 | 189 | * Fires after the user has successfully logged in. |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @param string $user_login Username. |
| 194 | 194 | * @param WP_User $$user WP_User object of the logged-in user. |
| 195 | 195 | */ |
| 196 | - do_action( 'wp_login', $user_login, get_userdata( $user_id ) ); |
|
| 196 | + do_action('wp_login', $user_login, get_userdata($user_id)); |
|
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | 199 | * Fires after give user has successfully logged in. |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @param string $user_login Username. |
| 205 | 205 | * @param string $user_pass User password. |
| 206 | 206 | */ |
| 207 | - do_action( 'give_log_user_in', $user_id, $user_login, $user_pass ); |
|
| 207 | + do_action('give_log_user_in', $user_id, $user_login, $user_pass); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return bool |
| 219 | 219 | */ |
| 220 | -function give_process_register_form( $data ) { |
|
| 220 | +function give_process_register_form($data) { |
|
| 221 | 221 | |
| 222 | - if ( is_user_logged_in() ) { |
|
| 222 | + if (is_user_logged_in()) { |
|
| 223 | 223 | return false; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( empty( $_POST['give_register_submit'] ) ) { |
|
| 226 | + if (empty($_POST['give_register_submit'])) { |
|
| 227 | 227 | return false; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -232,38 +232,38 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @since 1.0 |
| 234 | 234 | */ |
| 235 | - do_action( 'give_pre_process_register_form' ); |
|
| 235 | + do_action('give_pre_process_register_form'); |
|
| 236 | 236 | |
| 237 | - if ( empty( $data['give_user_login'] ) ) { |
|
| 238 | - give_set_error( 'empty_username', esc_html__( 'Invalid username.', 'give' ) ); |
|
| 237 | + if (empty($data['give_user_login'])) { |
|
| 238 | + give_set_error('empty_username', esc_html__('Invalid username.', 'give')); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if ( username_exists( $data['give_user_login'] ) ) { |
|
| 242 | - give_set_error( 'username_unavailable', esc_html__( 'Username already taken.', 'give' ) ); |
|
| 241 | + if (username_exists($data['give_user_login'])) { |
|
| 242 | + give_set_error('username_unavailable', esc_html__('Username already taken.', 'give')); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if ( ! validate_username( $data['give_user_login'] ) ) { |
|
| 246 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username.', 'give' ) ); |
|
| 245 | + if ( ! validate_username($data['give_user_login'])) { |
|
| 246 | + give_set_error('username_invalid', esc_html__('Invalid username.', 'give')); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( email_exists( $data['give_user_email'] ) ) { |
|
| 250 | - give_set_error( 'email_unavailable', esc_html__( 'Email address already taken.', 'give' ) ); |
|
| 249 | + if (email_exists($data['give_user_email'])) { |
|
| 250 | + give_set_error('email_unavailable', esc_html__('Email address already taken.', 'give')); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( empty( $data['give_user_email'] ) || ! is_email( $data['give_user_email'] ) ) { |
|
| 254 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
| 253 | + if (empty($data['give_user_email']) || ! is_email($data['give_user_email'])) { |
|
| 254 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( ! empty( $data['give_payment_email'] ) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email( $data['give_payment_email'] ) ) { |
|
| 258 | - give_set_error( 'payment_email_invalid', esc_html__( 'Invalid payment email.', 'give' ) ); |
|
| 257 | + if ( ! empty($data['give_payment_email']) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email($data['give_payment_email'])) { |
|
| 258 | + give_set_error('payment_email_invalid', esc_html__('Invalid payment email.', 'give')); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ( empty( $_POST['give_user_pass'] ) ) { |
|
| 262 | - give_set_error( 'empty_password', esc_html__( 'Please enter a password.', 'give' ) ); |
|
| 261 | + if (empty($_POST['give_user_pass'])) { |
|
| 262 | + give_set_error('empty_password', esc_html__('Please enter a password.', 'give')); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( ( ! empty( $_POST['give_user_pass'] ) && empty( $_POST['give_user_pass2'] ) ) || ( $_POST['give_user_pass'] !== $_POST['give_user_pass2'] ) ) { |
|
| 266 | - give_set_error( 'password_mismatch', esc_html__( 'Passwords don\'t match.', 'give' ) ); |
|
| 265 | + if (( ! empty($_POST['give_user_pass']) && empty($_POST['give_user_pass2'])) || ($_POST['give_user_pass'] !== $_POST['give_user_pass2'])) { |
|
| 266 | + give_set_error('password_mismatch', esc_html__('Passwords don\'t match.', 'give')); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -271,26 +271,26 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | * @since 1.0 |
| 273 | 273 | */ |
| 274 | - do_action( 'give_process_register_form' ); |
|
| 274 | + do_action('give_process_register_form'); |
|
| 275 | 275 | |
| 276 | 276 | // Check for errors and redirect if none present |
| 277 | 277 | $errors = give_get_errors(); |
| 278 | 278 | |
| 279 | - if ( empty( $errors ) ) { |
|
| 279 | + if (empty($errors)) { |
|
| 280 | 280 | |
| 281 | - $redirect = apply_filters( 'give_register_redirect', $data['give_redirect'] ); |
|
| 281 | + $redirect = apply_filters('give_register_redirect', $data['give_redirect']); |
|
| 282 | 282 | |
| 283 | - give_register_and_login_new_user( array( |
|
| 283 | + give_register_and_login_new_user(array( |
|
| 284 | 284 | 'user_login' => $data['give_user_login'], |
| 285 | 285 | 'user_pass' => $data['give_user_pass'], |
| 286 | 286 | 'user_email' => $data['give_user_email'], |
| 287 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
| 288 | - 'role' => get_option( 'default_role' ), |
|
| 289 | - ) ); |
|
| 287 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
| 288 | + 'role' => get_option('default_role'), |
|
| 289 | + )); |
|
| 290 | 290 | |
| 291 | - wp_redirect( $redirect ); |
|
| 291 | + wp_redirect($redirect); |
|
| 292 | 292 | give_die(); |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | -add_action( 'give_user_register', 'give_process_register_form' ); |
|
| 296 | +add_action('give_user_register', 'give_process_register_form'); |
|