@@ -37,7 +37,7 @@ |
||
| 37 | 37 | * |
| 38 | 38 | * Display admin bar when active |
| 39 | 39 | * |
| 40 | - * @return bool |
|
| 40 | + * @return false|null |
|
| 41 | 41 | */ |
| 42 | 42 | public function give_admin_bar_menu() { |
| 43 | 43 | global $wp_admin_bar; |
@@ -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 | |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | * @since 1.0 |
| 28 | 28 | */ |
| 29 | 29 | public function __construct() { |
| 30 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 31 | - add_action( 'give_dismiss_notices', array( $this, 'dismiss_notices' ) ); |
|
| 32 | - add_action( 'admin_bar_menu', array( $this, 'give_admin_bar_menu' ), 1000 ); |
|
| 30 | + add_action('admin_notices', array($this, 'show_notices')); |
|
| 31 | + add_action('give_dismiss_notices', array($this, 'dismiss_notices')); |
|
| 32 | + add_action('admin_bar_menu', array($this, 'give_admin_bar_menu'), 1000); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | public function give_admin_bar_menu() { |
| 43 | 43 | global $wp_admin_bar; |
| 44 | 44 | |
| 45 | - if ( ! give_is_test_mode() || ! current_user_can( 'view_give_reports' ) ) { |
|
| 45 | + if ( ! give_is_test_mode() || ! current_user_can('view_give_reports')) { |
|
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | //Add the main siteadmin menu item |
| 50 | - $wp_admin_bar->add_menu( array( |
|
| 50 | + $wp_admin_bar->add_menu(array( |
|
| 51 | 51 | 'id' => 'give-test-notice', |
| 52 | - 'href' => admin_url() . 'edit.php?post_type=give_forms&page=give-settings&tab=gateways', |
|
| 52 | + 'href' => admin_url().'edit.php?post_type=give_forms&page=give-settings&tab=gateways', |
|
| 53 | 53 | 'parent' => 'top-secondary', |
| 54 | - 'title' => esc_html( 'Give Test Mode Active', 'give' ), |
|
| 55 | - 'meta' => array( 'class' => 'give-test-mode-active' ), |
|
| 56 | - ) ); |
|
| 54 | + 'title' => esc_html('Give Test Mode Active', 'give'), |
|
| 55 | + 'meta' => array('class' => 'give-test-mode-active'), |
|
| 56 | + )); |
|
| 57 | 57 | |
| 58 | 58 | } |
| 59 | 59 | |
@@ -68,98 +68,98 @@ discard block |
||
| 68 | 68 | 'error' => array() |
| 69 | 69 | ); |
| 70 | 70 | |
| 71 | - if ( ! give_test_ajax_works() && ! get_user_meta( get_current_user_id(), '_give_admin_ajax_inaccessible_dismissed', true ) && current_user_can( 'manage_give_settings' ) ) { |
|
| 71 | + if ( ! give_test_ajax_works() && ! get_user_meta(get_current_user_id(), '_give_admin_ajax_inaccessible_dismissed', true) && current_user_can('manage_give_settings')) { |
|
| 72 | 72 | echo '<div class="error">'; |
| 73 | - echo '<p>' . esc_html( 'Your site appears to be blocking the WordPress ajax interface. This may cause issues with Give.', 'give' ) . '</p>'; |
|
| 73 | + echo '<p>'.esc_html('Your site appears to be blocking the WordPress ajax interface. This may cause issues with Give.', 'give').'</p>'; |
|
| 74 | 74 | /* translators: %s: https://givewp.com/documentation/core/troubleshooting/admin-ajax-blocked/ */ |
| 75 | - echo '<p>' . sprintf( __( 'Please see <a href="%s" target="_blank">this reference</a> for possible solutions.', 'give' ), esc_url( 'https://givewp.com/documentation/core/troubleshooting/admin-ajax-blocked/' ) ) . '</p>'; |
|
| 76 | - echo '<p><a href="' . add_query_arg( array( |
|
| 75 | + echo '<p>'.sprintf(__('Please see <a href="%s" target="_blank">this reference</a> for possible solutions.', 'give'), esc_url('https://givewp.com/documentation/core/troubleshooting/admin-ajax-blocked/')).'</p>'; |
|
| 76 | + echo '<p><a href="'.add_query_arg(array( |
|
| 77 | 77 | 'give_action' => 'dismiss_notices', |
| 78 | 78 | 'give_notice' => 'admin_ajax_inaccessible' |
| 79 | - ) ) . '">' . esc_html( 'Dismiss Notice', 'give' ) . '</a></p>'; |
|
| 79 | + )).'">'.esc_html('Dismiss Notice', 'give').'</a></p>'; |
|
| 80 | 80 | echo '</div>'; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
| 84 | - if ( isset( $_GET['give-message'] ) ) { |
|
| 84 | + if (isset($_GET['give-message'])) { |
|
| 85 | 85 | |
| 86 | 86 | // Donation reports errors |
| 87 | - if ( current_user_can( 'view_give_reports' ) ) { |
|
| 88 | - switch ( $_GET['give-message'] ) { |
|
| 87 | + if (current_user_can('view_give_reports')) { |
|
| 88 | + switch ($_GET['give-message']) { |
|
| 89 | 89 | case 'payment_deleted' : |
| 90 | - $notices['updated']['give-payment-deleted'] = esc_attr( 'The payment has been deleted.', 'give' ); |
|
| 90 | + $notices['updated']['give-payment-deleted'] = esc_attr('The payment has been deleted.', 'give'); |
|
| 91 | 91 | break; |
| 92 | 92 | case 'email_sent' : |
| 93 | - $notices['updated']['give-payment-sent'] = esc_attr( 'The donation receipt has been resent.', 'give' ); |
|
| 93 | + $notices['updated']['give-payment-sent'] = esc_attr('The donation receipt has been resent.', 'give'); |
|
| 94 | 94 | break; |
| 95 | 95 | case 'refreshed-reports' : |
| 96 | - $notices['updated']['give-refreshed-reports'] = esc_attr( 'The reports cache has been cleared.', 'give' ); |
|
| 96 | + $notices['updated']['give-refreshed-reports'] = esc_attr('The reports cache has been cleared.', 'give'); |
|
| 97 | 97 | break; |
| 98 | 98 | case 'payment-note-deleted' : |
| 99 | - $notices['updated']['give-payment-note-deleted'] = esc_attr( 'The payment note has been deleted.', 'give' ); |
|
| 99 | + $notices['updated']['give-payment-note-deleted'] = esc_attr('The payment note has been deleted.', 'give'); |
|
| 100 | 100 | break; |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // Give settings notices and errors |
| 105 | - if ( current_user_can( 'manage_give_settings' ) ) { |
|
| 106 | - switch ( $_GET['give-message'] ) { |
|
| 105 | + if (current_user_can('manage_give_settings')) { |
|
| 106 | + switch ($_GET['give-message']) { |
|
| 107 | 107 | case 'settings-imported' : |
| 108 | - $notices['updated']['give-settings-imported'] = esc_attr( 'The settings have been imported.', 'give' ); |
|
| 108 | + $notices['updated']['give-settings-imported'] = esc_attr('The settings have been imported.', 'give'); |
|
| 109 | 109 | break; |
| 110 | 110 | case 'api-key-generated' : |
| 111 | - $notices['updated']['give-api-key-generated'] = esc_attr( 'API keys successfully generated.', 'give' ); |
|
| 111 | + $notices['updated']['give-api-key-generated'] = esc_attr('API keys successfully generated.', 'give'); |
|
| 112 | 112 | break; |
| 113 | 113 | case 'api-key-exists' : |
| 114 | - $notices['error']['give-api-key-exists'] = esc_attr( 'The specified user already has API keys.', 'give' ); |
|
| 114 | + $notices['error']['give-api-key-exists'] = esc_attr('The specified user already has API keys.', 'give'); |
|
| 115 | 115 | break; |
| 116 | 116 | case 'api-key-regenerated' : |
| 117 | - $notices['updated']['give-api-key-regenerated'] = esc_attr( 'API keys successfully regenerated.', 'give' ); |
|
| 117 | + $notices['updated']['give-api-key-regenerated'] = esc_attr('API keys successfully regenerated.', 'give'); |
|
| 118 | 118 | break; |
| 119 | 119 | case 'api-key-revoked' : |
| 120 | - $notices['updated']['give-api-key-revoked'] = esc_attr( 'API keys successfully revoked.', 'give' ); |
|
| 120 | + $notices['updated']['give-api-key-revoked'] = esc_attr('API keys successfully revoked.', 'give'); |
|
| 121 | 121 | break; |
| 122 | 122 | case 'sent-test-email' : |
| 123 | - $notices['updated']['give-sent-test-email'] = esc_attr( 'The test email has been sent.', 'give' ); |
|
| 123 | + $notices['updated']['give-sent-test-email'] = esc_attr('The test email has been sent.', 'give'); |
|
| 124 | 124 | break; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | // Payments errors |
| 128 | - if ( current_user_can( 'edit_give_payments' ) ) { |
|
| 129 | - switch ( $_GET['give-message'] ) { |
|
| 128 | + if (current_user_can('edit_give_payments')) { |
|
| 129 | + switch ($_GET['give-message']) { |
|
| 130 | 130 | case 'note-added' : |
| 131 | - $notices['updated']['give-note-added'] = esc_attr( 'The payment note has been added successfully.', 'give' ); |
|
| 131 | + $notices['updated']['give-note-added'] = esc_attr('The payment note has been added successfully.', 'give'); |
|
| 132 | 132 | break; |
| 133 | 133 | case 'payment-updated' : |
| 134 | - $notices['updated']['give-payment-updated'] = esc_attr( 'The payment has been successfully updated.', 'give' ); |
|
| 134 | + $notices['updated']['give-payment-updated'] = esc_attr('The payment has been successfully updated.', 'give'); |
|
| 135 | 135 | break; |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Customer Notices |
| 140 | - if ( current_user_can( 'edit_give_payments' ) ) { |
|
| 141 | - switch ( $_GET['give-message'] ) { |
|
| 140 | + if (current_user_can('edit_give_payments')) { |
|
| 141 | + switch ($_GET['give-message']) { |
|
| 142 | 142 | case 'customer-deleted' : |
| 143 | - $notices['updated']['give-customer-deleted'] = esc_attr( 'Donor successfully deleted.', 'give' ); |
|
| 143 | + $notices['updated']['give-customer-deleted'] = esc_attr('Donor successfully deleted.', 'give'); |
|
| 144 | 144 | break; |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if ( count( $notices['updated'] ) > 0 ) { |
|
| 151 | - foreach ( $notices['updated'] as $notice => $message ) { |
|
| 152 | - add_settings_error( 'give-notices', $notice, $message, 'updated' ); |
|
| 150 | + if (count($notices['updated']) > 0) { |
|
| 151 | + foreach ($notices['updated'] as $notice => $message) { |
|
| 152 | + add_settings_error('give-notices', $notice, $message, 'updated'); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ( count( $notices['error'] ) > 0 ) { |
|
| 157 | - foreach ( $notices['error'] as $notice => $message ) { |
|
| 158 | - add_settings_error( 'give-notices', $notice, $message, 'error' ); |
|
| 156 | + if (count($notices['error']) > 0) { |
|
| 157 | + foreach ($notices['error'] as $notice => $message) { |
|
| 158 | + add_settings_error('give-notices', $notice, $message, 'error'); |
|
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - settings_errors( 'give-notices' ); |
|
| 162 | + settings_errors('give-notices'); |
|
| 163 | 163 | |
| 164 | 164 | } |
| 165 | 165 | |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | * @return void |
| 172 | 172 | */ |
| 173 | 173 | function give_admin_addons_notices() { |
| 174 | - add_settings_error( 'give-notices', 'give-addons-feed-error', esc_attr( 'There seems to be an issue with the server. Please try again in a few minutes.', 'give' ), 'error' ); |
|
| 175 | - settings_errors( 'give-notices' ); |
|
| 174 | + add_settings_error('give-notices', 'give-addons-feed-error', esc_attr('There seems to be an issue with the server. Please try again in a few minutes.', 'give'), 'error'); |
|
| 175 | + settings_errors('give-notices'); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -183,9 +183,9 @@ discard block |
||
| 183 | 183 | * @return void |
| 184 | 184 | */ |
| 185 | 185 | function dismiss_notices() { |
| 186 | - if ( isset( $_GET['give_notice'] ) ) { |
|
| 187 | - update_user_meta( get_current_user_id(), '_give_' . $_GET['give_notice'] . '_dismissed', 1 ); |
|
| 188 | - wp_redirect( remove_query_arg( array( 'give_action', 'give_notice' ) ) ); |
|
| 186 | + if (isset($_GET['give_notice'])) { |
|
| 187 | + update_user_meta(get_current_user_id(), '_give_'.$_GET['give_notice'].'_dismissed', 1); |
|
| 188 | + wp_redirect(remove_query_arg(array('give_action', 'give_notice'))); |
|
| 189 | 189 | exit; |
| 190 | 190 | } |
| 191 | 191 | } |
@@ -81,7 +81,6 @@ discard block |
||
| 81 | 81 | * @since 1.1 |
| 82 | 82 | * |
| 83 | 83 | * @param array $item Contains all the data of the keys |
| 84 | - * @param string $column_name The name of the column |
|
| 85 | 84 | * |
| 86 | 85 | * @return string Column Name |
| 87 | 86 | */ |
@@ -96,7 +95,6 @@ discard block |
||
| 96 | 95 | * @since 1.1 |
| 97 | 96 | * |
| 98 | 97 | * @param array $item Contains all the data of the keys |
| 99 | - * @param string $column_name The name of the column |
|
| 100 | 98 | * |
| 101 | 99 | * @return string Column Name |
| 102 | 100 | */ |
@@ -111,7 +109,6 @@ discard block |
||
| 111 | 109 | * @since 1.1 |
| 112 | 110 | * |
| 113 | 111 | * @param array $item Contains all the data of the keys |
| 114 | - * @param string $column_name The name of the column |
|
| 115 | 112 | * |
| 116 | 113 | * @return string Column Name |
| 117 | 114 | */ |
@@ -124,7 +121,7 @@ discard block |
||
| 124 | 121 | * |
| 125 | 122 | * @access public |
| 126 | 123 | * @since 1.1 |
| 127 | - * @return void |
|
| 124 | + * @return string |
|
| 128 | 125 | */ |
| 129 | 126 | public function column_user( $item ) { |
| 130 | 127 | |
@@ -10,13 +10,13 @@ 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 | 17 | // Load WP_List_Table if not loaded |
| 18 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 19 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 18 | +if ( ! class_exists('WP_List_Table')) { |
|
| 19 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | global $status, $page; |
| 51 | 51 | |
| 52 | 52 | // Set parent defaults |
| 53 | - parent::__construct( array( |
|
| 54 | - 'singular' => esc_html( 'API Key', 'give' ), // Singular name of the listed records |
|
| 55 | - 'plural' => esc_html( 'API Keys', 'give' ), // Plural name of the listed records |
|
| 53 | + parent::__construct(array( |
|
| 54 | + 'singular' => esc_html('API Key', 'give'), // Singular name of the listed records |
|
| 55 | + 'plural' => esc_html('API Keys', 'give'), // Plural name of the listed records |
|
| 56 | 56 | 'ajax' => false // Does this table support ajax? |
| 57 | - ) ); |
|
| 57 | + )); |
|
| 58 | 58 | |
| 59 | 59 | $this->query(); |
| 60 | 60 | } |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return string Column Name |
| 72 | 72 | */ |
| 73 | - public function column_default( $item, $column_name ) { |
|
| 74 | - return $item[ $column_name ]; |
|
| 73 | + public function column_default($item, $column_name) { |
|
| 74 | + return $item[$column_name]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @return string Column Name |
| 87 | 87 | */ |
| 88 | - public function column_key( $item ) { |
|
| 89 | - return '<input readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['key'] ) . '"/>'; |
|
| 88 | + public function column_key($item) { |
|
| 89 | + return '<input readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['key']).'"/>'; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @return string Column Name |
| 102 | 102 | */ |
| 103 | - public function column_token( $item ) { |
|
| 104 | - return '<input readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['token'] ) . '"/>'; |
|
| 103 | + public function column_token($item) { |
|
| 104 | + return '<input readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['token']).'"/>'; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @return string Column Name |
| 117 | 117 | */ |
| 118 | - public function column_secret( $item ) { |
|
| 119 | - return '<input readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['secret'] ) . '"/>'; |
|
| 118 | + public function column_secret($item) { |
|
| 119 | + return '<input readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['secret']).'"/>'; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,46 +126,46 @@ discard block |
||
| 126 | 126 | * @since 1.1 |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - public function column_user( $item ) { |
|
| 129 | + public function column_user($item) { |
|
| 130 | 130 | |
| 131 | 131 | $actions = array(); |
| 132 | 132 | |
| 133 | - if ( apply_filters( 'give_api_log_requests', true ) ) { |
|
| 133 | + if (apply_filters('give_api_log_requests', true)) { |
|
| 134 | 134 | $actions['view'] = sprintf( |
| 135 | 135 | '<a href="%s">%s</a>', |
| 136 | - esc_url( add_query_arg( array( |
|
| 136 | + esc_url(add_query_arg(array( |
|
| 137 | 137 | 'view' => 'api_requests', |
| 138 | 138 | 'post_type' => 'give_forms', |
| 139 | 139 | 'page' => 'give-reports', |
| 140 | 140 | 'tab' => 'logs', |
| 141 | 141 | 's' => $item['email'] |
| 142 | - ), 'edit.php' ) ), |
|
| 143 | - esc_html( 'View API Log', 'give' ) |
|
| 142 | + ), 'edit.php')), |
|
| 143 | + esc_html('View API Log', 'give') |
|
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $actions['reissue'] = sprintf( |
| 148 | 148 | '<a href="%s" class="give-regenerate-api-key">%s</a>', |
| 149 | - esc_url( wp_nonce_url( add_query_arg( array( |
|
| 149 | + esc_url(wp_nonce_url(add_query_arg(array( |
|
| 150 | 150 | 'user_id' => $item['id'], |
| 151 | 151 | 'give_action' => 'process_api_key', |
| 152 | 152 | 'give_api_process' => 'regenerate' |
| 153 | - ) ), 'give-api-nonce' ) ), |
|
| 154 | - esc_html( 'Reissue', 'give' ) |
|
| 153 | + )), 'give-api-nonce')), |
|
| 154 | + esc_html('Reissue', 'give') |
|
| 155 | 155 | ); |
| 156 | - $actions['revoke'] = sprintf( |
|
| 156 | + $actions['revoke'] = sprintf( |
|
| 157 | 157 | '<a href="%s" class="give-revoke-api-key give-delete">%s</a>', |
| 158 | - esc_url( wp_nonce_url( add_query_arg( array( |
|
| 158 | + esc_url(wp_nonce_url(add_query_arg(array( |
|
| 159 | 159 | 'user_id' => $item['id'], |
| 160 | 160 | 'give_action' => 'process_api_key', |
| 161 | 161 | 'give_api_process' => 'revoke' |
| 162 | - ) ), 'give-api-nonce' ) ), |
|
| 163 | - esc_html( 'Revoke', 'give' ) |
|
| 162 | + )), 'give-api-nonce')), |
|
| 163 | + esc_html('Revoke', 'give') |
|
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | - $actions = apply_filters( 'give_api_row_actions', array_filter( $actions ) ); |
|
| 166 | + $actions = apply_filters('give_api_row_actions', array_filter($actions)); |
|
| 167 | 167 | |
| 168 | - return sprintf( '%1$s %2$s', $item['user'], $this->row_actions( $actions ) ); |
|
| 168 | + return sprintf('%1$s %2$s', $item['user'], $this->row_actions($actions)); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | public function get_columns() { |
| 179 | 179 | $columns = array( |
| 180 | - 'user' => esc_html( 'Username', 'give' ), |
|
| 181 | - 'key' => esc_html( 'Public Key', 'give' ), |
|
| 182 | - 'token' => esc_html( 'Token', 'give' ), |
|
| 183 | - 'secret' => esc_html( 'Secret Key', 'give' ) |
|
| 180 | + 'user' => esc_html('Username', 'give'), |
|
| 181 | + 'key' => esc_html('Public Key', 'give'), |
|
| 182 | + 'token' => esc_html('Token', 'give'), |
|
| 183 | + 'secret' => esc_html('Secret Key', 'give') |
|
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | 186 | return $columns; |
@@ -193,19 +193,19 @@ discard block |
||
| 193 | 193 | * @since 1.1 |
| 194 | 194 | * @return void |
| 195 | 195 | */ |
| 196 | - function bulk_actions( $which = '' ) { |
|
| 196 | + function bulk_actions($which = '') { |
|
| 197 | 197 | // These aren't really bulk actions but this outputs the markup in the right place |
| 198 | 198 | static $give_api_is_bottom; |
| 199 | 199 | |
| 200 | - if ( $give_api_is_bottom ) { |
|
| 200 | + if ($give_api_is_bottom) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | ?> |
| 204 | 204 | <input type="hidden" name="give_action" value="process_api_key"/> |
| 205 | 205 | <input type="hidden" name="give_api_process" value="generate"/> |
| 206 | - <?php wp_nonce_field( 'give-api-nonce' ); ?> |
|
| 206 | + <?php wp_nonce_field('give-api-nonce'); ?> |
|
| 207 | 207 | <?php echo Give()->html->ajax_user_search(); ?> |
| 208 | - <?php submit_button( esc_html( 'Generate New API Keys', 'give' ), 'secondary', 'submit', false ); ?> |
|
| 208 | + <?php submit_button(esc_html('Generate New API Keys', 'give'), 'secondary', 'submit', false); ?> |
|
| 209 | 209 | <?php |
| 210 | 210 | $give_api_is_bottom = true; |
| 211 | 211 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @return int Current page number |
| 219 | 219 | */ |
| 220 | 220 | public function get_paged() { |
| 221 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 221 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -229,21 +229,21 @@ discard block |
||
| 229 | 229 | * @return array |
| 230 | 230 | */ |
| 231 | 231 | public function query() { |
| 232 | - $users = get_users( array( |
|
| 232 | + $users = get_users(array( |
|
| 233 | 233 | 'meta_value' => 'give_user_secret_key', |
| 234 | 234 | 'number' => $this->per_page, |
| 235 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ) |
|
| 236 | - ) ); |
|
| 237 | - $keys = array(); |
|
| 238 | - |
|
| 239 | - foreach ( $users as $user ) { |
|
| 240 | - $keys[ $user->ID ]['id'] = $user->ID; |
|
| 241 | - $keys[ $user->ID ]['email'] = $user->user_email; |
|
| 242 | - $keys[ $user->ID ]['user'] = '<a href="' . add_query_arg( 'user_id', $user->ID, 'user-edit.php' ) . '"><strong>' . $user->user_login . '</strong></a>'; |
|
| 243 | - |
|
| 244 | - $keys[ $user->ID ]['key'] = Give()->api->get_user_public_key( $user->ID ); |
|
| 245 | - $keys[ $user->ID ]['secret'] = Give()->api->get_user_secret_key( $user->ID ); |
|
| 246 | - $keys[ $user->ID ]['token'] = Give()->api->get_token( $user->ID ); |
|
| 235 | + 'offset' => $this->per_page * ($this->get_paged() - 1) |
|
| 236 | + )); |
|
| 237 | + $keys = array(); |
|
| 238 | + |
|
| 239 | + foreach ($users as $user) { |
|
| 240 | + $keys[$user->ID]['id'] = $user->ID; |
|
| 241 | + $keys[$user->ID]['email'] = $user->user_email; |
|
| 242 | + $keys[$user->ID]['user'] = '<a href="'.add_query_arg('user_id', $user->ID, 'user-edit.php').'"><strong>'.$user->user_login.'</strong></a>'; |
|
| 243 | + |
|
| 244 | + $keys[$user->ID]['key'] = Give()->api->get_user_public_key($user->ID); |
|
| 245 | + $keys[$user->ID]['secret'] = Give()->api->get_user_secret_key($user->ID); |
|
| 246 | + $keys[$user->ID]['token'] = Give()->api->get_token($user->ID); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | return $keys; |
@@ -260,13 +260,13 @@ discard block |
||
| 260 | 260 | public function total_items() { |
| 261 | 261 | global $wpdb; |
| 262 | 262 | |
| 263 | - if ( ! get_transient( 'give_total_api_keys' ) ) { |
|
| 264 | - $total_items = $wpdb->get_var( "SELECT count(user_id) FROM $wpdb->usermeta WHERE meta_value='give_user_secret_key'" ); |
|
| 263 | + if ( ! get_transient('give_total_api_keys')) { |
|
| 264 | + $total_items = $wpdb->get_var("SELECT count(user_id) FROM $wpdb->usermeta WHERE meta_value='give_user_secret_key'"); |
|
| 265 | 265 | |
| 266 | - set_transient( 'give_total_api_keys', $total_items, 60 * 60 ); |
|
| 266 | + set_transient('give_total_api_keys', $total_items, 60 * 60); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - return get_transient( 'give_total_api_keys' ); |
|
| 269 | + return get_transient('give_total_api_keys'); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | $hidden = array(); // No hidden columns |
| 283 | 283 | $sortable = array(); // Not sortable... for now |
| 284 | 284 | |
| 285 | - $this->_column_headers = array( $columns, $hidden, $sortable, 'id' ); |
|
| 285 | + $this->_column_headers = array($columns, $hidden, $sortable, 'id'); |
|
| 286 | 286 | |
| 287 | 287 | $data = $this->query(); |
| 288 | 288 | |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | $this->items = $data; |
| 292 | 292 | |
| 293 | - $this->set_pagination_args( array( |
|
| 293 | + $this->set_pagination_args(array( |
|
| 294 | 294 | 'total_items' => $total_items, |
| 295 | 295 | 'per_page' => $this->per_page, |
| 296 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 296 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
| 297 | 297 | ) |
| 298 | 298 | ); |
| 299 | 299 | } |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | * @uses api_request() |
| 68 | 68 | * |
| 69 | 69 | * @param array $_transient_data Update array build by WordPress. |
| 70 | - * @return array Modified update array with custom plugin data. |
|
| 70 | + * @return stdClass Modified update array with custom plugin data. |
|
| 71 | 71 | */ |
| 72 | 72 | function check_update( $_transient_data ) { |
| 73 | 73 | |
@@ -4,7 +4,9 @@ discard block |
||
| 4 | 4 | //set_site_transient( 'update_plugins', null ); |
| 5 | 5 | |
| 6 | 6 | // Exit if accessed directly |
| 7 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 7 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | + exit; |
|
| 9 | +} |
|
| 8 | 10 | |
| 9 | 11 | /** |
| 10 | 12 | * Allows plugins to use their own update API. |
@@ -273,11 +275,13 @@ discard block |
||
| 273 | 275 | |
| 274 | 276 | $data = array_merge( $this->api_data, $_data ); |
| 275 | 277 | |
| 276 | - if ( $data['slug'] != $this->slug ) |
|
| 277 | - return; |
|
| 278 | + if ( $data['slug'] != $this->slug ) { |
|
| 279 | + return; |
|
| 280 | + } |
|
| 278 | 281 | |
| 279 | - if ( empty( $data['license'] ) ) |
|
| 280 | - return; |
|
| 282 | + if ( empty( $data['license'] ) ) { |
|
| 283 | + return; |
|
| 284 | + } |
|
| 281 | 285 | |
| 282 | 286 | if( $this->api_url == home_url() ) { |
| 283 | 287 | return false; // Don't allow a plugin to ping itself |
@@ -13,330 +13,330 @@ |
||
| 13 | 13 | * @version 1.6 |
| 14 | 14 | */ |
| 15 | 15 | class EDD_SL_Plugin_Updater { |
| 16 | - private $api_url = ''; |
|
| 17 | - private $api_data = array(); |
|
| 18 | - private $name = ''; |
|
| 19 | - private $slug = ''; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Class constructor. |
|
| 23 | - * |
|
| 24 | - * @uses plugin_basename() |
|
| 25 | - * @uses hook() |
|
| 26 | - * |
|
| 27 | - * @param string $_api_url The URL pointing to the custom API endpoint. |
|
| 28 | - * @param string $_plugin_file Path to the plugin file. |
|
| 29 | - * @param array $_api_data Optional data to send with API calls. |
|
| 30 | - * @return void |
|
| 31 | - */ |
|
| 32 | - function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
| 33 | - $this->api_url = trailingslashit( $_api_url ); |
|
| 34 | - $this->api_data = $_api_data; |
|
| 35 | - $this->name = plugin_basename( $_plugin_file ); |
|
| 36 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
| 37 | - $this->version = $_api_data['version']; |
|
| 38 | - |
|
| 39 | - // Set up hooks. |
|
| 40 | - $this->init(); |
|
| 41 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Set up WordPress filters to hook into WP's update process. |
|
| 46 | - * |
|
| 47 | - * @uses add_filter() |
|
| 48 | - * |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - public function init() { |
|
| 16 | + private $api_url = ''; |
|
| 17 | + private $api_data = array(); |
|
| 18 | + private $name = ''; |
|
| 19 | + private $slug = ''; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Class constructor. |
|
| 23 | + * |
|
| 24 | + * @uses plugin_basename() |
|
| 25 | + * @uses hook() |
|
| 26 | + * |
|
| 27 | + * @param string $_api_url The URL pointing to the custom API endpoint. |
|
| 28 | + * @param string $_plugin_file Path to the plugin file. |
|
| 29 | + * @param array $_api_data Optional data to send with API calls. |
|
| 30 | + * @return void |
|
| 31 | + */ |
|
| 32 | + function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
| 33 | + $this->api_url = trailingslashit( $_api_url ); |
|
| 34 | + $this->api_data = $_api_data; |
|
| 35 | + $this->name = plugin_basename( $_plugin_file ); |
|
| 36 | + $this->slug = basename( $_plugin_file, '.php' ); |
|
| 37 | + $this->version = $_api_data['version']; |
|
| 38 | + |
|
| 39 | + // Set up hooks. |
|
| 40 | + $this->init(); |
|
| 41 | + add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Set up WordPress filters to hook into WP's update process. |
|
| 46 | + * |
|
| 47 | + * @uses add_filter() |
|
| 48 | + * |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + public function init() { |
|
| 52 | 52 | |
| 53 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 54 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
| 53 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 54 | + add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
| 55 | 55 | |
| 56 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
| 57 | - } |
|
| 56 | + add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Check for Updates at the defined API endpoint and modify the update array. |
|
| 61 | - * |
|
| 62 | - * This function dives into the update API just when WordPress creates its update array, |
|
| 63 | - * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
| 64 | - * It is reassembled from parts of the native WordPress plugin update code. |
|
| 65 | - * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
| 66 | - * |
|
| 67 | - * @uses api_request() |
|
| 68 | - * |
|
| 69 | - * @param array $_transient_data Update array build by WordPress. |
|
| 70 | - * @return array Modified update array with custom plugin data. |
|
| 71 | - */ |
|
| 72 | - function check_update( $_transient_data ) { |
|
| 59 | + /** |
|
| 60 | + * Check for Updates at the defined API endpoint and modify the update array. |
|
| 61 | + * |
|
| 62 | + * This function dives into the update API just when WordPress creates its update array, |
|
| 63 | + * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
| 64 | + * It is reassembled from parts of the native WordPress plugin update code. |
|
| 65 | + * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
| 66 | + * |
|
| 67 | + * @uses api_request() |
|
| 68 | + * |
|
| 69 | + * @param array $_transient_data Update array build by WordPress. |
|
| 70 | + * @return array Modified update array with custom plugin data. |
|
| 71 | + */ |
|
| 72 | + function check_update( $_transient_data ) { |
|
| 73 | 73 | |
| 74 | - global $pagenow; |
|
| 74 | + global $pagenow; |
|
| 75 | 75 | |
| 76 | - if( ! is_object( $_transient_data ) ) { |
|
| 77 | - $_transient_data = new stdClass; |
|
| 78 | - } |
|
| 76 | + if( ! is_object( $_transient_data ) ) { |
|
| 77 | + $_transient_data = new stdClass; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - if( 'plugins.php' == $pagenow && is_multisite() ) { |
|
| 81 | - return $_transient_data; |
|
| 82 | - } |
|
| 80 | + if( 'plugins.php' == $pagenow && is_multisite() ) { |
|
| 81 | + return $_transient_data; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
| 84 | + if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
| 85 | 85 | |
| 86 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 86 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 87 | 87 | |
| 88 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
| 88 | + if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
| 89 | 89 | |
| 90 | - $this->did_check = true; |
|
| 90 | + $this->did_check = true; |
|
| 91 | 91 | |
| 92 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 92 | + if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 93 | 93 | |
| 94 | - $_transient_data->response[ $this->name ] = $version_info; |
|
| 94 | + $_transient_data->response[ $this->name ] = $version_info; |
|
| 95 | 95 | |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $_transient_data->last_checked = time(); |
|
| 99 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
| 98 | + $_transient_data->last_checked = time(); |
|
| 99 | + $_transient_data->checked[ $this->name ] = $this->version; |
|
| 100 | 100 | |
| 101 | - } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $_transient_data; |
|
| 106 | - } |
|
| 105 | + return $_transient_data; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
|
| 110 | - * |
|
| 111 | - * @param string $file |
|
| 112 | - * @param array $plugin |
|
| 113 | - */ |
|
| 114 | - public function show_update_notification( $file, $plugin ) { |
|
| 108 | + /** |
|
| 109 | + * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
|
| 110 | + * |
|
| 111 | + * @param string $file |
|
| 112 | + * @param array $plugin |
|
| 113 | + */ |
|
| 114 | + public function show_update_notification( $file, $plugin ) { |
|
| 115 | 115 | |
| 116 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 117 | - return; |
|
| 118 | - } |
|
| 116 | + if( ! current_user_can( 'update_plugins' ) ) { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - if( ! is_multisite() ) { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 120 | + if( ! is_multisite() ) { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - if ( $this->name != $file ) { |
|
| 125 | - return; |
|
| 126 | - } |
|
| 124 | + if ( $this->name != $file ) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - // Remove our filter on the site transient |
|
| 129 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
| 128 | + // Remove our filter on the site transient |
|
| 129 | + remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
| 130 | 130 | |
| 131 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
| 131 | + $update_cache = get_site_transient( 'update_plugins' ); |
|
| 132 | 132 | |
| 133 | - if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
| 133 | + if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
| 134 | 134 | |
| 135 | - $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
| 136 | - $version_info = get_transient( $cache_key ); |
|
| 135 | + $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
| 136 | + $version_info = get_transient( $cache_key ); |
|
| 137 | 137 | |
| 138 | - if( false === $version_info ) { |
|
| 138 | + if( false === $version_info ) { |
|
| 139 | 139 | |
| 140 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 140 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 141 | 141 | |
| 142 | - set_transient( $cache_key, $version_info, 3600 ); |
|
| 143 | - } |
|
| 142 | + set_transient( $cache_key, $version_info, 3600 ); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | - if( ! is_object( $version_info ) ) { |
|
| 147 | - return; |
|
| 148 | - } |
|
| 146 | + if( ! is_object( $version_info ) ) { |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 150 | + if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 151 | 151 | |
| 152 | - $update_cache->response[ $this->name ] = $version_info; |
|
| 152 | + $update_cache->response[ $this->name ] = $version_info; |
|
| 153 | 153 | |
| 154 | - } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $update_cache->last_checked = time(); |
|
| 157 | - $update_cache->checked[ $this->name ] = $this->version; |
|
| 156 | + $update_cache->last_checked = time(); |
|
| 157 | + $update_cache->checked[ $this->name ] = $this->version; |
|
| 158 | 158 | |
| 159 | - set_site_transient( 'update_plugins', $update_cache ); |
|
| 159 | + set_site_transient( 'update_plugins', $update_cache ); |
|
| 160 | 160 | |
| 161 | - } else { |
|
| 161 | + } else { |
|
| 162 | 162 | |
| 163 | - $version_info = $update_cache->response[ $this->name ]; |
|
| 163 | + $version_info = $update_cache->response[ $this->name ]; |
|
| 164 | 164 | |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - // Restore our filter |
|
| 168 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 167 | + // Restore our filter |
|
| 168 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 169 | 169 | |
| 170 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 170 | + if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 171 | 171 | |
| 172 | - // build a plugin list row, with update notification |
|
| 173 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
| 174 | - echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 172 | + // build a plugin list row, with update notification |
|
| 173 | + $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
| 174 | + echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 175 | 175 | |
| 176 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
| 176 | + $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
| 177 | 177 | |
| 178 | - if ( empty( $version_info->download_link ) ) { |
|
| 179 | - printf( |
|
| 178 | + if ( empty( $version_info->download_link ) ) { |
|
| 179 | + printf( |
|
| 180 | 180 | /* translators: 1: name 2: changelog URL 3: version */ |
| 181 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'edd' ), |
|
| 182 | - esc_html( $version_info->name ), |
|
| 183 | - esc_url( $changelog_link ), |
|
| 184 | - esc_html( $version_info->new_version ) |
|
| 185 | - ); |
|
| 186 | - } else { |
|
| 187 | - printf( |
|
| 181 | + __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'edd' ), |
|
| 182 | + esc_html( $version_info->name ), |
|
| 183 | + esc_url( $changelog_link ), |
|
| 184 | + esc_html( $version_info->new_version ) |
|
| 185 | + ); |
|
| 186 | + } else { |
|
| 187 | + printf( |
|
| 188 | 188 | /* translators: 1: name 2: changelog URL 3: version 4: update URL */ |
| 189 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'edd' ), |
|
| 190 | - esc_html( $version_info->name ), |
|
| 191 | - esc_url( $changelog_link ), |
|
| 192 | - esc_html( $version_info->new_version ), |
|
| 193 | - esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
| 194 | - ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - echo '</div></td></tr>'; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Updates information on the "View version x.x details" page with custom data. |
|
| 204 | - * |
|
| 205 | - * @uses api_request() |
|
| 206 | - * |
|
| 207 | - * @param mixed $_data |
|
| 208 | - * @param string $_action |
|
| 209 | - * @param object $_args |
|
| 210 | - * @return object $_data |
|
| 211 | - */ |
|
| 212 | - function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - if ( $_action != 'plugin_information' ) { |
|
| 216 | - |
|
| 217 | - return $_data; |
|
| 218 | - |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
| 222 | - |
|
| 223 | - return $_data; |
|
| 224 | - |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $to_send = array( |
|
| 228 | - 'slug' => $this->slug, |
|
| 229 | - 'is_ssl' => is_ssl(), |
|
| 230 | - 'fields' => array( |
|
| 231 | - 'banners' => false, // These will be supported soon hopefully |
|
| 232 | - 'reviews' => false |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - |
|
| 236 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
| 237 | - |
|
| 238 | - if ( false !== $api_response ) { |
|
| 239 | - $_data = $api_response; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return $_data; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Disable SSL verification in order to prevent download update failures |
|
| 248 | - * |
|
| 249 | - * @param array $args |
|
| 250 | - * @param string $url |
|
| 251 | - * @return object $array |
|
| 252 | - */ |
|
| 253 | - function http_request_args( $args, $url ) { |
|
| 254 | - // If it is an https request and we are performing a package download, disable ssl verification |
|
| 255 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
| 256 | - $args['sslverify'] = false; |
|
| 257 | - } |
|
| 258 | - return $args; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Calls the API and, if successfull, returns the object delivered by the API. |
|
| 263 | - * |
|
| 264 | - * @uses get_bloginfo() |
|
| 265 | - * @uses wp_remote_post() |
|
| 266 | - * @uses is_wp_error() |
|
| 267 | - * |
|
| 268 | - * @param string $_action The requested action. |
|
| 269 | - * @param array $_data Parameters for the API action. |
|
| 270 | - * @return false||object |
|
| 271 | - */ |
|
| 272 | - private function api_request( $_action, $_data ) { |
|
| 273 | - |
|
| 274 | - global $wp_version; |
|
| 275 | - |
|
| 276 | - $data = array_merge( $this->api_data, $_data ); |
|
| 277 | - |
|
| 278 | - if ( $data['slug'] != $this->slug ) |
|
| 279 | - return; |
|
| 280 | - |
|
| 281 | - if ( empty( $data['license'] ) ) |
|
| 282 | - return; |
|
| 283 | - |
|
| 284 | - if( $this->api_url == home_url() ) { |
|
| 285 | - return false; // Don't allow a plugin to ping itself |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - $api_params = array( |
|
| 289 | - 'edd_action' => 'get_version', |
|
| 290 | - 'license' => $data['license'], |
|
| 291 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
| 292 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
| 293 | - 'slug' => $data['slug'], |
|
| 294 | - 'author' => $data['author'], |
|
| 295 | - 'url' => home_url() |
|
| 296 | - ); |
|
| 189 | + __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'edd' ), |
|
| 190 | + esc_html( $version_info->name ), |
|
| 191 | + esc_url( $changelog_link ), |
|
| 192 | + esc_html( $version_info->new_version ), |
|
| 193 | + esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + echo '</div></td></tr>'; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Updates information on the "View version x.x details" page with custom data. |
|
| 204 | + * |
|
| 205 | + * @uses api_request() |
|
| 206 | + * |
|
| 207 | + * @param mixed $_data |
|
| 208 | + * @param string $_action |
|
| 209 | + * @param object $_args |
|
| 210 | + * @return object $_data |
|
| 211 | + */ |
|
| 212 | + function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + if ( $_action != 'plugin_information' ) { |
|
| 216 | + |
|
| 217 | + return $_data; |
|
| 218 | + |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
| 222 | + |
|
| 223 | + return $_data; |
|
| 224 | + |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $to_send = array( |
|
| 228 | + 'slug' => $this->slug, |
|
| 229 | + 'is_ssl' => is_ssl(), |
|
| 230 | + 'fields' => array( |
|
| 231 | + 'banners' => false, // These will be supported soon hopefully |
|
| 232 | + 'reviews' => false |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + |
|
| 236 | + $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
| 237 | + |
|
| 238 | + if ( false !== $api_response ) { |
|
| 239 | + $_data = $api_response; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return $_data; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Disable SSL verification in order to prevent download update failures |
|
| 248 | + * |
|
| 249 | + * @param array $args |
|
| 250 | + * @param string $url |
|
| 251 | + * @return object $array |
|
| 252 | + */ |
|
| 253 | + function http_request_args( $args, $url ) { |
|
| 254 | + // If it is an https request and we are performing a package download, disable ssl verification |
|
| 255 | + if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
| 256 | + $args['sslverify'] = false; |
|
| 257 | + } |
|
| 258 | + return $args; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Calls the API and, if successfull, returns the object delivered by the API. |
|
| 263 | + * |
|
| 264 | + * @uses get_bloginfo() |
|
| 265 | + * @uses wp_remote_post() |
|
| 266 | + * @uses is_wp_error() |
|
| 267 | + * |
|
| 268 | + * @param string $_action The requested action. |
|
| 269 | + * @param array $_data Parameters for the API action. |
|
| 270 | + * @return false||object |
|
| 271 | + */ |
|
| 272 | + private function api_request( $_action, $_data ) { |
|
| 273 | + |
|
| 274 | + global $wp_version; |
|
| 275 | + |
|
| 276 | + $data = array_merge( $this->api_data, $_data ); |
|
| 277 | + |
|
| 278 | + if ( $data['slug'] != $this->slug ) |
|
| 279 | + return; |
|
| 280 | + |
|
| 281 | + if ( empty( $data['license'] ) ) |
|
| 282 | + return; |
|
| 283 | + |
|
| 284 | + if( $this->api_url == home_url() ) { |
|
| 285 | + return false; // Don't allow a plugin to ping itself |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + $api_params = array( |
|
| 289 | + 'edd_action' => 'get_version', |
|
| 290 | + 'license' => $data['license'], |
|
| 291 | + 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
| 292 | + 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
| 293 | + 'slug' => $data['slug'], |
|
| 294 | + 'author' => $data['author'], |
|
| 295 | + 'url' => home_url() |
|
| 296 | + ); |
|
| 297 | 297 | |
| 298 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
| 298 | + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
| 299 | 299 | |
| 300 | - if ( ! is_wp_error( $request ) ) { |
|
| 301 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
| 302 | - } |
|
| 300 | + if ( ! is_wp_error( $request ) ) { |
|
| 301 | + $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - if ( $request && isset( $request->sections ) ) { |
|
| 305 | - $request->sections = maybe_unserialize( $request->sections ); |
|
| 306 | - } else { |
|
| 307 | - $request = false; |
|
| 308 | - } |
|
| 304 | + if ( $request && isset( $request->sections ) ) { |
|
| 305 | + $request->sections = maybe_unserialize( $request->sections ); |
|
| 306 | + } else { |
|
| 307 | + $request = false; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - return $request; |
|
| 311 | - } |
|
| 310 | + return $request; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - public function show_changelog() { |
|
| 313 | + public function show_changelog() { |
|
| 314 | 314 | |
| 315 | 315 | |
| 316 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
| 317 | - return; |
|
| 318 | - } |
|
| 316 | + if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
| 317 | + return; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - if( empty( $_REQUEST['plugin'] ) ) { |
|
| 321 | - return; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - if( empty( $_REQUEST['slug'] ) ) { |
|
| 325 | - return; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 329 | - wp_die( esc_html( 'You do not have permission to install plugin updates.', 'edd' ), esc_html( 'Error', 'edd' ), array( 'response' => 403 ) ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
| 333 | - |
|
| 334 | - if( $response && isset( $response->sections['changelog'] ) ) { |
|
| 335 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - exit; |
|
| 340 | - } |
|
| 320 | + if( empty( $_REQUEST['plugin'] ) ) { |
|
| 321 | + return; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + if( empty( $_REQUEST['slug'] ) ) { |
|
| 325 | + return; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + if( ! current_user_can( 'update_plugins' ) ) { |
|
| 329 | + wp_die( esc_html( 'You do not have permission to install plugin updates.', 'edd' ), esc_html( 'Error', 'edd' ), array( 'response' => 403 ) ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
| 333 | + |
|
| 334 | + if( $response && isset( $response->sections['changelog'] ) ) { |
|
| 335 | + echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + exit; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | //set_site_transient( 'update_plugins', null ); |
| 5 | 5 | |
| 6 | 6 | // Exit if accessed directly |
| 7 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 7 | +if ( ! defined('ABSPATH')) exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Allows plugins to use their own update API. |
@@ -29,16 +29,16 @@ discard block |
||
| 29 | 29 | * @param array $_api_data Optional data to send with API calls. |
| 30 | 30 | * @return void |
| 31 | 31 | */ |
| 32 | - function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
| 33 | - $this->api_url = trailingslashit( $_api_url ); |
|
| 32 | + function __construct($_api_url, $_plugin_file, $_api_data = null) { |
|
| 33 | + $this->api_url = trailingslashit($_api_url); |
|
| 34 | 34 | $this->api_data = $_api_data; |
| 35 | - $this->name = plugin_basename( $_plugin_file ); |
|
| 36 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
| 35 | + $this->name = plugin_basename($_plugin_file); |
|
| 36 | + $this->slug = basename($_plugin_file, '.php'); |
|
| 37 | 37 | $this->version = $_api_data['version']; |
| 38 | 38 | |
| 39 | 39 | // Set up hooks. |
| 40 | 40 | $this->init(); |
| 41 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
| 41 | + add_action('admin_init', array($this, 'show_changelog')); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function init() { |
| 52 | 52 | |
| 53 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 54 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
| 53 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
| 54 | + add_filter('plugins_api', array($this, 'plugins_api_filter'), 10, 3); |
|
| 55 | 55 | |
| 56 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
| 56 | + add_action('after_plugin_row_'.$this->name, array($this, 'show_update_notification'), 10, 2); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -69,34 +69,34 @@ discard block |
||
| 69 | 69 | * @param array $_transient_data Update array build by WordPress. |
| 70 | 70 | * @return array Modified update array with custom plugin data. |
| 71 | 71 | */ |
| 72 | - function check_update( $_transient_data ) { |
|
| 72 | + function check_update($_transient_data) { |
|
| 73 | 73 | |
| 74 | 74 | global $pagenow; |
| 75 | 75 | |
| 76 | - if( ! is_object( $_transient_data ) ) { |
|
| 76 | + if ( ! is_object($_transient_data)) { |
|
| 77 | 77 | $_transient_data = new stdClass; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if( 'plugins.php' == $pagenow && is_multisite() ) { |
|
| 80 | + if ('plugins.php' == $pagenow && is_multisite()) { |
|
| 81 | 81 | return $_transient_data; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
| 84 | + if (empty($_transient_data->response) || empty($_transient_data->response[$this->name])) { |
|
| 85 | 85 | |
| 86 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 86 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
| 87 | 87 | |
| 88 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
| 88 | + if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) { |
|
| 89 | 89 | |
| 90 | 90 | $this->did_check = true; |
| 91 | 91 | |
| 92 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 92 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
| 93 | 93 | |
| 94 | - $_transient_data->response[ $this->name ] = $version_info; |
|
| 94 | + $_transient_data->response[$this->name] = $version_info; |
|
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $_transient_data->last_checked = time(); |
| 99 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
| 99 | + $_transient_data->checked[$this->name] = $this->version; |
|
| 100 | 100 | |
| 101 | 101 | } |
| 102 | 102 | |
@@ -111,86 +111,86 @@ discard block |
||
| 111 | 111 | * @param string $file |
| 112 | 112 | * @param array $plugin |
| 113 | 113 | */ |
| 114 | - public function show_update_notification( $file, $plugin ) { |
|
| 114 | + public function show_update_notification($file, $plugin) { |
|
| 115 | 115 | |
| 116 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 116 | + if ( ! current_user_can('update_plugins')) { |
|
| 117 | 117 | return; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if( ! is_multisite() ) { |
|
| 120 | + if ( ! is_multisite()) { |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if ( $this->name != $file ) { |
|
| 124 | + if ($this->name != $file) { |
|
| 125 | 125 | return; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Remove our filter on the site transient |
| 129 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
| 129 | + remove_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'), 10); |
|
| 130 | 130 | |
| 131 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
| 131 | + $update_cache = get_site_transient('update_plugins'); |
|
| 132 | 132 | |
| 133 | - if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
| 133 | + if ( ! is_object($update_cache) || empty($update_cache->response) || empty($update_cache->response[$this->name])) { |
|
| 134 | 134 | |
| 135 | - $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
| 136 | - $version_info = get_transient( $cache_key ); |
|
| 135 | + $cache_key = md5('edd_plugin_'.sanitize_key($this->name).'_version_info'); |
|
| 136 | + $version_info = get_transient($cache_key); |
|
| 137 | 137 | |
| 138 | - if( false === $version_info ) { |
|
| 138 | + if (false === $version_info) { |
|
| 139 | 139 | |
| 140 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 140 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
| 141 | 141 | |
| 142 | - set_transient( $cache_key, $version_info, 3600 ); |
|
| 142 | + set_transient($cache_key, $version_info, 3600); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
| 146 | - if( ! is_object( $version_info ) ) { |
|
| 146 | + if ( ! is_object($version_info)) { |
|
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 150 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
| 151 | 151 | |
| 152 | - $update_cache->response[ $this->name ] = $version_info; |
|
| 152 | + $update_cache->response[$this->name] = $version_info; |
|
| 153 | 153 | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $update_cache->last_checked = time(); |
| 157 | - $update_cache->checked[ $this->name ] = $this->version; |
|
| 157 | + $update_cache->checked[$this->name] = $this->version; |
|
| 158 | 158 | |
| 159 | - set_site_transient( 'update_plugins', $update_cache ); |
|
| 159 | + set_site_transient('update_plugins', $update_cache); |
|
| 160 | 160 | |
| 161 | 161 | } else { |
| 162 | 162 | |
| 163 | - $version_info = $update_cache->response[ $this->name ]; |
|
| 163 | + $version_info = $update_cache->response[$this->name]; |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Restore our filter |
| 168 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 168 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
| 169 | 169 | |
| 170 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 170 | + if ( ! empty($update_cache->response[$this->name]) && version_compare($this->version, $version_info->new_version, '<')) { |
|
| 171 | 171 | |
| 172 | 172 | // build a plugin list row, with update notification |
| 173 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
| 174 | - echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 173 | + $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
| 174 | + echo '<tr class="plugin-update-tr"><td colspan="'.$wp_list_table->get_column_count().'" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 175 | 175 | |
| 176 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
| 176 | + $changelog_link = self_admin_url('index.php?edd_sl_action=view_plugin_changelog&plugin='.$this->name.'&slug='.$this->slug.'&TB_iframe=true&width=772&height=911'); |
|
| 177 | 177 | |
| 178 | - if ( empty( $version_info->download_link ) ) { |
|
| 178 | + if (empty($version_info->download_link)) { |
|
| 179 | 179 | printf( |
| 180 | 180 | /* translators: 1: name 2: changelog URL 3: version */ |
| 181 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'edd' ), |
|
| 182 | - esc_html( $version_info->name ), |
|
| 183 | - esc_url( $changelog_link ), |
|
| 184 | - esc_html( $version_info->new_version ) |
|
| 181 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'edd'), |
|
| 182 | + esc_html($version_info->name), |
|
| 183 | + esc_url($changelog_link), |
|
| 184 | + esc_html($version_info->new_version) |
|
| 185 | 185 | ); |
| 186 | 186 | } else { |
| 187 | 187 | printf( |
| 188 | 188 | /* translators: 1: name 2: changelog URL 3: version 4: update URL */ |
| 189 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'edd' ), |
|
| 190 | - esc_html( $version_info->name ), |
|
| 191 | - esc_url( $changelog_link ), |
|
| 192 | - esc_html( $version_info->new_version ), |
|
| 193 | - esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
| 189 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'edd'), |
|
| 190 | + esc_html($version_info->name), |
|
| 191 | + esc_url($changelog_link), |
|
| 192 | + esc_html($version_info->new_version), |
|
| 193 | + esc_url(wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=').$this->name, 'upgrade-plugin_'.$this->name)) |
|
| 194 | 194 | ); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -209,16 +209,16 @@ discard block |
||
| 209 | 209 | * @param object $_args |
| 210 | 210 | * @return object $_data |
| 211 | 211 | */ |
| 212 | - function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
| 212 | + function plugins_api_filter($_data, $_action = '', $_args = null) { |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | - if ( $_action != 'plugin_information' ) { |
|
| 215 | + if ($_action != 'plugin_information') { |
|
| 216 | 216 | |
| 217 | 217 | return $_data; |
| 218 | 218 | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
| 221 | + if ( ! isset($_args->slug) || ($_args->slug != $this->slug)) { |
|
| 222 | 222 | |
| 223 | 223 | return $_data; |
| 224 | 224 | |
@@ -233,9 +233,9 @@ discard block |
||
| 233 | 233 | ) |
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
| 236 | + $api_response = $this->api_request('plugin_information', $to_send); |
|
| 237 | 237 | |
| 238 | - if ( false !== $api_response ) { |
|
| 238 | + if (false !== $api_response) { |
|
| 239 | 239 | $_data = $api_response; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | * @param string $url |
| 251 | 251 | * @return object $array |
| 252 | 252 | */ |
| 253 | - function http_request_args( $args, $url ) { |
|
| 253 | + function http_request_args($args, $url) { |
|
| 254 | 254 | // If it is an https request and we are performing a package download, disable ssl verification |
| 255 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
| 255 | + if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) { |
|
| 256 | 256 | $args['sslverify'] = false; |
| 257 | 257 | } |
| 258 | 258 | return $args; |
@@ -269,40 +269,40 @@ discard block |
||
| 269 | 269 | * @param array $_data Parameters for the API action. |
| 270 | 270 | * @return false||object |
| 271 | 271 | */ |
| 272 | - private function api_request( $_action, $_data ) { |
|
| 272 | + private function api_request($_action, $_data) { |
|
| 273 | 273 | |
| 274 | 274 | global $wp_version; |
| 275 | 275 | |
| 276 | - $data = array_merge( $this->api_data, $_data ); |
|
| 276 | + $data = array_merge($this->api_data, $_data); |
|
| 277 | 277 | |
| 278 | - if ( $data['slug'] != $this->slug ) |
|
| 278 | + if ($data['slug'] != $this->slug) |
|
| 279 | 279 | return; |
| 280 | 280 | |
| 281 | - if ( empty( $data['license'] ) ) |
|
| 281 | + if (empty($data['license'])) |
|
| 282 | 282 | return; |
| 283 | 283 | |
| 284 | - if( $this->api_url == home_url() ) { |
|
| 284 | + if ($this->api_url == home_url()) { |
|
| 285 | 285 | return false; // Don't allow a plugin to ping itself |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $api_params = array( |
| 289 | 289 | 'edd_action' => 'get_version', |
| 290 | 290 | 'license' => $data['license'], |
| 291 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
| 292 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
| 291 | + 'item_name' => isset($data['item_name']) ? $data['item_name'] : false, |
|
| 292 | + 'item_id' => isset($data['item_id']) ? $data['item_id'] : false, |
|
| 293 | 293 | 'slug' => $data['slug'], |
| 294 | 294 | 'author' => $data['author'], |
| 295 | 295 | 'url' => home_url() |
| 296 | 296 | ); |
| 297 | 297 | |
| 298 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
| 298 | + $request = wp_remote_post($this->api_url, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); |
|
| 299 | 299 | |
| 300 | - if ( ! is_wp_error( $request ) ) { |
|
| 301 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
| 300 | + if ( ! is_wp_error($request)) { |
|
| 301 | + $request = json_decode(wp_remote_retrieve_body($request)); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if ( $request && isset( $request->sections ) ) { |
|
| 305 | - $request->sections = maybe_unserialize( $request->sections ); |
|
| 304 | + if ($request && isset($request->sections)) { |
|
| 305 | + $request->sections = maybe_unserialize($request->sections); |
|
| 306 | 306 | } else { |
| 307 | 307 | $request = false; |
| 308 | 308 | } |
@@ -313,26 +313,26 @@ discard block |
||
| 313 | 313 | public function show_changelog() { |
| 314 | 314 | |
| 315 | 315 | |
| 316 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
| 316 | + if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action']) { |
|
| 317 | 317 | return; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if( empty( $_REQUEST['plugin'] ) ) { |
|
| 320 | + if (empty($_REQUEST['plugin'])) { |
|
| 321 | 321 | return; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if( empty( $_REQUEST['slug'] ) ) { |
|
| 324 | + if (empty($_REQUEST['slug'])) { |
|
| 325 | 325 | return; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 329 | - wp_die( esc_html( 'You do not have permission to install plugin updates.', 'edd' ), esc_html( 'Error', 'edd' ), array( 'response' => 403 ) ); |
|
| 328 | + if ( ! current_user_can('update_plugins')) { |
|
| 329 | + wp_die(esc_html('You do not have permission to install plugin updates.', 'edd'), esc_html('Error', 'edd'), array('response' => 403)); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
| 332 | + $response = $this->api_request('plugin_latest_version', array('slug' => $_REQUEST['slug'])); |
|
| 333 | 333 | |
| 334 | - if( $response && isset( $response->sections['changelog'] ) ) { |
|
| 335 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
| 334 | + if ($response && isset($response->sections['changelog'])) { |
|
| 335 | + echo '<div style="background:#fff;padding:10px;">'.$response->sections['changelog'].'</div>'; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | |
@@ -321,7 +321,7 @@ |
||
| 321 | 321 | * |
| 322 | 322 | * @param int $post_id Download (Post) ID |
| 323 | 323 | * |
| 324 | - * @return void |
|
| 324 | + * @return null|integer |
|
| 325 | 325 | */ |
| 326 | 326 | function give_price_save_quick_edit( $post_id ) { |
| 327 | 327 | if ( ! isset( $_POST['post_type'] ) || 'give_forms' !== $_POST['post_type'] ) { |
@@ -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 | |
@@ -27,34 +27,34 @@ discard block |
||
| 27 | 27 | * @return array $form_columns Updated array of forms columns |
| 28 | 28 | * Post Type List Table |
| 29 | 29 | */ |
| 30 | -function give_form_columns( $give_form_columns ) { |
|
| 30 | +function give_form_columns($give_form_columns) { |
|
| 31 | 31 | |
| 32 | 32 | //Standard columns |
| 33 | 33 | $give_form_columns = array( |
| 34 | 34 | 'cb' => '<input type="checkbox"/>', |
| 35 | - 'title' => esc_html( 'Name', 'give' ), |
|
| 36 | - 'form_category' => esc_html( 'Categories', 'give' ), |
|
| 37 | - 'form_tag' => esc_html( 'Tags', 'give' ), |
|
| 38 | - 'price' => esc_html( 'Price', 'give' ), |
|
| 39 | - 'goal' => esc_html( 'Goal', 'give' ), |
|
| 40 | - 'donations' => esc_html( 'Donations', 'give' ), |
|
| 41 | - 'earnings' => esc_html( 'Income', 'give' ), |
|
| 42 | - 'shortcode' => esc_html( 'Shortcode', 'give' ), |
|
| 43 | - 'date' => esc_html( 'Date', 'give' ) |
|
| 35 | + 'title' => esc_html('Name', 'give'), |
|
| 36 | + 'form_category' => esc_html('Categories', 'give'), |
|
| 37 | + 'form_tag' => esc_html('Tags', 'give'), |
|
| 38 | + 'price' => esc_html('Price', 'give'), |
|
| 39 | + 'goal' => esc_html('Goal', 'give'), |
|
| 40 | + 'donations' => esc_html('Donations', 'give'), |
|
| 41 | + 'earnings' => esc_html('Income', 'give'), |
|
| 42 | + 'shortcode' => esc_html('Shortcode', 'give'), |
|
| 43 | + 'date' => esc_html('Date', 'give') |
|
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | 46 | //Does the user want categories / tags? |
| 47 | - if ( give_get_option( 'enable_categories' ) !== 'on' ) { |
|
| 48 | - unset( $give_form_columns['form_category'] ); |
|
| 47 | + if (give_get_option('enable_categories') !== 'on') { |
|
| 48 | + unset($give_form_columns['form_category']); |
|
| 49 | 49 | } |
| 50 | - if ( give_get_option( 'enable_tags' ) !== 'on' ) { |
|
| 51 | - unset( $give_form_columns['form_tag'] ); |
|
| 50 | + if (give_get_option('enable_tags') !== 'on') { |
|
| 51 | + unset($give_form_columns['form_tag']); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - return apply_filters( 'give_forms_columns', $give_form_columns ); |
|
| 54 | + return apply_filters('give_forms_columns', $give_form_columns); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | -add_filter( 'manage_edit-give_forms_columns', 'give_form_columns' ); |
|
| 57 | +add_filter('manage_edit-give_forms_columns', 'give_form_columns'); |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Render Give Form Columns |
@@ -66,67 +66,67 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return void |
| 68 | 68 | */ |
| 69 | -function give_render_form_columns( $column_name, $post_id ) { |
|
| 70 | - if ( get_post_type( $post_id ) == 'give_forms' ) { |
|
| 69 | +function give_render_form_columns($column_name, $post_id) { |
|
| 70 | + if (get_post_type($post_id) == 'give_forms') { |
|
| 71 | 71 | global $give_options; |
| 72 | 72 | |
| 73 | - $style = isset( $give_options['button_style'] ) ? $give_options['button_style'] : 'button'; |
|
| 74 | - $color = isset( $give_options['checkout_color'] ) ? $give_options['checkout_color'] : 'blue'; |
|
| 75 | - $color = ( $color == 'inherit' ) ? '' : $color; |
|
| 73 | + $style = isset($give_options['button_style']) ? $give_options['button_style'] : 'button'; |
|
| 74 | + $color = isset($give_options['checkout_color']) ? $give_options['checkout_color'] : 'blue'; |
|
| 75 | + $color = ($color == 'inherit') ? '' : $color; |
|
| 76 | 76 | |
| 77 | - $purchase_text = ! empty( $give_options['add_to_cart_text'] ) ? $give_options['add_to_cart_text'] : esc_html( 'Purchase', 'give' ); |
|
| 77 | + $purchase_text = ! empty($give_options['add_to_cart_text']) ? $give_options['add_to_cart_text'] : esc_html('Purchase', 'give'); |
|
| 78 | 78 | |
| 79 | - switch ( $column_name ) { |
|
| 79 | + switch ($column_name) { |
|
| 80 | 80 | case 'form_category': |
| 81 | - echo get_the_term_list( $post_id, 'give_forms_category', '', ', ', '' ); |
|
| 81 | + echo get_the_term_list($post_id, 'give_forms_category', '', ', ', ''); |
|
| 82 | 82 | break; |
| 83 | 83 | case 'form_tag': |
| 84 | - echo get_the_term_list( $post_id, 'give_forms_tag', '', ', ', '' ); |
|
| 84 | + echo get_the_term_list($post_id, 'give_forms_tag', '', ', ', ''); |
|
| 85 | 85 | break; |
| 86 | 86 | case 'price': |
| 87 | - if ( give_has_variable_prices( $post_id ) ) { |
|
| 88 | - echo give_price_range( $post_id ); |
|
| 87 | + if (give_has_variable_prices($post_id)) { |
|
| 88 | + echo give_price_range($post_id); |
|
| 89 | 89 | } else { |
| 90 | - echo give_price( $post_id, false ); |
|
| 91 | - echo '<input type="hidden" class="formprice-' . $post_id . '" value="' . give_get_form_price( $post_id ) . '" />'; |
|
| 90 | + echo give_price($post_id, false); |
|
| 91 | + echo '<input type="hidden" class="formprice-'.$post_id.'" value="'.give_get_form_price($post_id).'" />'; |
|
| 92 | 92 | } |
| 93 | 93 | break; |
| 94 | 94 | case 'goal': |
| 95 | - $goal_option = get_post_meta( $post_id, '_give_goal_option', true ); |
|
| 96 | - if ( ! empty( $goal_option ) && $goal_option === 'yes' ) { |
|
| 97 | - echo give_goal( $post_id, false ); |
|
| 95 | + $goal_option = get_post_meta($post_id, '_give_goal_option', true); |
|
| 96 | + if ( ! empty($goal_option) && $goal_option === 'yes') { |
|
| 97 | + echo give_goal($post_id, false); |
|
| 98 | 98 | } else { |
| 99 | - esc_html_e( 'No Goal Set', 'give' ); |
|
| 99 | + esc_html_e('No Goal Set', 'give'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - echo '<input type="hidden" class="formgoal-' . $post_id . '" value="' . give_get_form_goal( $post_id ) . '" />'; |
|
| 102 | + echo '<input type="hidden" class="formgoal-'.$post_id.'" value="'.give_get_form_goal($post_id).'" />'; |
|
| 103 | 103 | break; |
| 104 | 104 | case 'donations': |
| 105 | - if ( current_user_can( 'view_give_forms_stats', $post_id ) ) { |
|
| 106 | - echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-reports&tab=logs&view=sales&form=' . $post_id ) ) . '">'; |
|
| 107 | - echo give_get_form_sales_stats( $post_id ); |
|
| 105 | + if (current_user_can('view_give_forms_stats', $post_id)) { |
|
| 106 | + echo '<a href="'.esc_url(admin_url('edit.php?post_type=give_forms&page=give-reports&tab=logs&view=sales&form='.$post_id)).'">'; |
|
| 107 | + echo give_get_form_sales_stats($post_id); |
|
| 108 | 108 | echo '</a>'; |
| 109 | 109 | } else { |
| 110 | 110 | echo '-'; |
| 111 | 111 | } |
| 112 | 112 | break; |
| 113 | 113 | case 'earnings': |
| 114 | - if ( current_user_can( 'view_give_forms_stats', $post_id ) ) { |
|
| 115 | - echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-reports&view=forms&form-id=' . $post_id ) ) . '">'; |
|
| 116 | - echo give_currency_filter( give_format_amount( give_get_form_earnings_stats( $post_id ) ) ); |
|
| 114 | + if (current_user_can('view_give_forms_stats', $post_id)) { |
|
| 115 | + echo '<a href="'.esc_url(admin_url('edit.php?post_type=give_forms&page=give-reports&view=forms&form-id='.$post_id)).'">'; |
|
| 116 | + echo give_currency_filter(give_format_amount(give_get_form_earnings_stats($post_id))); |
|
| 117 | 117 | echo '</a>'; |
| 118 | 118 | } else { |
| 119 | 119 | echo '-'; |
| 120 | 120 | } |
| 121 | 121 | break; |
| 122 | 122 | case 'shortcode': |
| 123 | - echo '<input onclick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly="" value="[give_form id="' . absint( $post_id ) . '"]">'; |
|
| 123 | + echo '<input onclick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly="" value="[give_form id="'.absint($post_id).'"]">'; |
|
| 124 | 124 | break; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | -add_action( 'manage_posts_custom_column', 'give_render_form_columns', 10, 2 ); |
|
| 129 | +add_action('manage_posts_custom_column', 'give_render_form_columns', 10, 2); |
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * Registers the sortable columns in the list table |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return array $columns Array of sortable columns |
| 139 | 139 | */ |
| 140 | -function give_sortable_form_columns( $columns ) { |
|
| 140 | +function give_sortable_form_columns($columns) { |
|
| 141 | 141 | $columns['price'] = 'price'; |
| 142 | 142 | $columns['sales'] = 'sales'; |
| 143 | 143 | $columns['earnings'] = 'earnings'; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | return $columns; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | -add_filter( 'manage_edit-give_forms_sortable_columns', 'give_sortable_form_columns' ); |
|
| 149 | +add_filter('manage_edit-give_forms_sortable_columns', 'give_sortable_form_columns'); |
|
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | * Sorts Columns in the Forms List Table |
@@ -157,11 +157,11 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return array $vars Array of all the sort variables |
| 159 | 159 | */ |
| 160 | -function give_sort_forms( $vars ) { |
|
| 160 | +function give_sort_forms($vars) { |
|
| 161 | 161 | // Check if we're viewing the "give_forms" post type |
| 162 | - if ( isset( $vars['post_type'] ) && 'give_forms' == $vars['post_type'] ) { |
|
| 162 | + if (isset($vars['post_type']) && 'give_forms' == $vars['post_type']) { |
|
| 163 | 163 | // Check if 'orderby' is set to "sales" |
| 164 | - if ( isset( $vars['orderby'] ) && 'sales' == $vars['orderby'] ) { |
|
| 164 | + if (isset($vars['orderby']) && 'sales' == $vars['orderby']) { |
|
| 165 | 165 | $vars = array_merge( |
| 166 | 166 | $vars, |
| 167 | 167 | array( |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Check if "orderby" is set to "earnings" |
| 175 | - if ( isset( $vars['orderby'] ) && 'earnings' == $vars['orderby'] ) { |
|
| 175 | + if (isset($vars['orderby']) && 'earnings' == $vars['orderby']) { |
|
| 176 | 176 | $vars = array_merge( |
| 177 | 177 | $vars, |
| 178 | 178 | array( |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // Check if "orderby" is set to "price" |
| 186 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
| 186 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
| 187 | 187 | $vars = array_merge( |
| 188 | 188 | $vars, |
| 189 | 189 | array( |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // Check if "orderby" is set to "goal" |
| 197 | - if ( isset( $vars['orderby'] ) && 'goal' == $vars['orderby'] ) { |
|
| 197 | + if (isset($vars['orderby']) && 'goal' == $vars['orderby']) { |
|
| 198 | 198 | $vars = array_merge( |
| 199 | 199 | $vars, |
| 200 | 200 | array( |
@@ -217,16 +217,16 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return array Array of all sort variables |
| 219 | 219 | */ |
| 220 | -function give_filter_forms( $vars ) { |
|
| 221 | - if ( isset( $vars['post_type'] ) && 'give_forms' == $vars['post_type'] ) { |
|
| 220 | +function give_filter_forms($vars) { |
|
| 221 | + if (isset($vars['post_type']) && 'give_forms' == $vars['post_type']) { |
|
| 222 | 222 | |
| 223 | 223 | // If an author ID was passed, use it |
| 224 | - if ( isset( $_REQUEST['author'] ) && ! current_user_can( 'view_give_reports' ) ) { |
|
| 224 | + if (isset($_REQUEST['author']) && ! current_user_can('view_give_reports')) { |
|
| 225 | 225 | |
| 226 | 226 | $author_id = $_REQUEST['author']; |
| 227 | - if ( (int) $author_id !== get_current_user_id() ) { |
|
| 227 | + if ((int) $author_id !== get_current_user_id()) { |
|
| 228 | 228 | // Tried to view the products of another person, sorry |
| 229 | - wp_die( esc_html( 'You do not have permission to view this data.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 229 | + wp_die(esc_html('You do not have permission to view this data.', 'give'), esc_html('Error', 'give'), array('response' => 403)); |
|
| 230 | 230 | } |
| 231 | 231 | $vars = array_merge( |
| 232 | 232 | $vars, |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @return void |
| 252 | 252 | */ |
| 253 | 253 | function give_forms_load() { |
| 254 | - add_filter( 'request', 'give_sort_forms' ); |
|
| 255 | - add_filter( 'request', 'give_filter_forms' ); |
|
| 254 | + add_filter('request', 'give_sort_forms'); |
|
| 255 | + add_filter('request', 'give_filter_forms'); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | -add_action( 'load-edit.php', 'give_forms_load', 9999 ); |
|
| 258 | +add_action('load-edit.php', 'give_forms_load', 9999); |
|
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * Remove Forms Month Filter |
@@ -269,17 +269,17 @@ discard block |
||
| 269 | 269 | * @global $typenow The post type we are viewing |
| 270 | 270 | * @return array Empty array disables the dropdown |
| 271 | 271 | */ |
| 272 | -function give_remove_month_filter( $dates ) { |
|
| 272 | +function give_remove_month_filter($dates) { |
|
| 273 | 273 | global $typenow; |
| 274 | 274 | |
| 275 | - if ( $typenow == 'give_forms' ) { |
|
| 275 | + if ($typenow == 'give_forms') { |
|
| 276 | 276 | $dates = array(); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | return $dates; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | -add_filter( 'months_dropdown_results', 'give_remove_month_filter', 99 ); |
|
| 282 | +add_filter('months_dropdown_results', 'give_remove_month_filter', 99); |
|
| 283 | 283 | |
| 284 | 284 | /** |
| 285 | 285 | * Adds price field to Quick Edit options |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | * |
| 292 | 292 | * @return void |
| 293 | 293 | */ |
| 294 | -function give_price_field_quick_edit( $column_name, $post_type ) { |
|
| 295 | - if ( $column_name != 'price' || $post_type != 'give_forms' ) { |
|
| 294 | +function give_price_field_quick_edit($column_name, $post_type) { |
|
| 295 | + if ($column_name != 'price' || $post_type != 'give_forms') { |
|
| 296 | 296 | return; |
| 297 | 297 | } |
| 298 | 298 | ?> |
@@ -301,12 +301,12 @@ discard block |
||
| 301 | 301 | <h4><?php |
| 302 | 302 | printf( |
| 303 | 303 | /* translators: %s: forms singular label */ |
| 304 | - esc_html( '%s Configuration', 'give' ), |
|
| 304 | + esc_html('%s Configuration', 'give'), |
|
| 305 | 305 | give_get_forms_label_singular() |
| 306 | 306 | ); |
| 307 | 307 | ?></h4> |
| 308 | 308 | <label> |
| 309 | - <span class="title"><?php esc_html_e( 'Price', 'give' ); ?></span> |
|
| 309 | + <span class="title"><?php esc_html_e('Price', 'give'); ?></span> |
|
| 310 | 310 | <span class="input-text-wrap"> |
| 311 | 311 | <input type="text" name="_give_regprice" class="text regprice" /> |
| 312 | 312 | </span> |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | <?php |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | -add_action( 'quick_edit_custom_box', 'give_price_field_quick_edit', 10, 2 ); |
|
| 321 | -add_action( 'bulk_edit_custom_box', 'give_price_field_quick_edit', 10, 2 ); |
|
| 320 | +add_action('quick_edit_custom_box', 'give_price_field_quick_edit', 10, 2); |
|
| 321 | +add_action('bulk_edit_custom_box', 'give_price_field_quick_edit', 10, 2); |
|
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | 324 | * Updates price when saving post |
@@ -329,23 +329,23 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @return void |
| 331 | 331 | */ |
| 332 | -function give_price_save_quick_edit( $post_id ) { |
|
| 333 | - if ( ! isset( $_POST['post_type'] ) || 'give_forms' !== $_POST['post_type'] ) { |
|
| 332 | +function give_price_save_quick_edit($post_id) { |
|
| 333 | + if ( ! isset($_POST['post_type']) || 'give_forms' !== $_POST['post_type']) { |
|
| 334 | 334 | return; |
| 335 | 335 | } |
| 336 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 336 | + if ( ! current_user_can('edit_post', $post_id)) { |
|
| 337 | 337 | return $post_id; |
| 338 | 338 | } |
| 339 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 339 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 340 | 340 | return $post_id; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if ( isset( $_REQUEST['_give_regprice'] ) ) { |
|
| 344 | - update_post_meta( $post_id, '_give_set_price', strip_tags( stripslashes( $_REQUEST['_give_regprice'] ) ) ); |
|
| 343 | + if (isset($_REQUEST['_give_regprice'])) { |
|
| 344 | + update_post_meta($post_id, '_give_set_price', strip_tags(stripslashes($_REQUEST['_give_regprice']))); |
|
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | -add_action( 'save_post', 'give_price_save_quick_edit' ); |
|
| 348 | +add_action('save_post', 'give_price_save_quick_edit'); |
|
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | 351 | * Process bulk edit actions via AJAX |
@@ -355,18 +355,18 @@ discard block |
||
| 355 | 355 | */ |
| 356 | 356 | function give_save_bulk_edit() { |
| 357 | 357 | |
| 358 | - $post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : array(); |
|
| 358 | + $post_ids = (isset($_POST['post_ids']) && ! empty($_POST['post_ids'])) ? $_POST['post_ids'] : array(); |
|
| 359 | 359 | |
| 360 | - if ( ! empty( $post_ids ) && is_array( $post_ids ) ) { |
|
| 361 | - $price = isset( $_POST['price'] ) ? strip_tags( stripslashes( $_POST['price'] ) ) : 0; |
|
| 362 | - foreach ( $post_ids as $post_id ) { |
|
| 360 | + if ( ! empty($post_ids) && is_array($post_ids)) { |
|
| 361 | + $price = isset($_POST['price']) ? strip_tags(stripslashes($_POST['price'])) : 0; |
|
| 362 | + foreach ($post_ids as $post_id) { |
|
| 363 | 363 | |
| 364 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 364 | + if ( ! current_user_can('edit_post', $post_id)) { |
|
| 365 | 365 | continue; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if ( ! empty( $price ) ) { |
|
| 369 | - update_post_meta( $post_id, '_give_set_price', give_sanitize_amount( $price ) ); |
|
| 368 | + if ( ! empty($price)) { |
|
| 369 | + update_post_meta($post_id, '_give_set_price', give_sanitize_amount($price)); |
|
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | } |
@@ -374,4 +374,4 @@ discard block |
||
| 374 | 374 | die(); |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | -add_action( 'wp_ajax_give_save_bulk_edit', 'give_save_bulk_edit' ); |
|
| 377 | +add_action('wp_ajax_give_save_bulk_edit', 'give_save_bulk_edit'); |
|
@@ -297,7 +297,6 @@ |
||
| 297 | 297 | * |
| 298 | 298 | * @since 1.0 |
| 299 | 299 | * |
| 300 | - * @param array $data Arguments passed |
|
| 301 | 300 | * |
| 302 | 301 | * @return void |
| 303 | 302 | */ |
@@ -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,106 +26,106 @@ discard block |
||
| 26 | 26 | * @return void |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | -function give_update_payment_details( $data ) { |
|
| 29 | +function give_update_payment_details($data) { |
|
| 30 | 30 | |
| 31 | - if ( ! current_user_can( 'edit_give_payments', $data['give_payment_id'] ) ) { |
|
| 32 | - wp_die( esc_html( 'You do not have permission to edit payment records.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 31 | + if ( ! current_user_can('edit_give_payments', $data['give_payment_id'])) { |
|
| 32 | + wp_die(esc_html('You do not have permission to edit payment records.', 'give'), esc_html('Error', 'give'), array('response' => 403)); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - check_admin_referer( 'give_update_payment_details_nonce' ); |
|
| 35 | + check_admin_referer('give_update_payment_details_nonce'); |
|
| 36 | 36 | |
| 37 | 37 | // Retrieve the payment ID |
| 38 | - $payment_id = absint( $data['give_payment_id'] ); |
|
| 39 | - $payment = new Give_Payment( $payment_id ); |
|
| 38 | + $payment_id = absint($data['give_payment_id']); |
|
| 39 | + $payment = new Give_Payment($payment_id); |
|
| 40 | 40 | |
| 41 | 41 | // Retrieve existing payment meta |
| 42 | 42 | $meta = $payment->get_meta(); |
| 43 | 43 | $user_info = $payment->user_info; |
| 44 | 44 | |
| 45 | 45 | $status = $data['give-payment-status']; |
| 46 | - $date = sanitize_text_field( $data['give-payment-date'] ); |
|
| 47 | - $hour = sanitize_text_field( $data['give-payment-time-hour'] ); |
|
| 46 | + $date = sanitize_text_field($data['give-payment-date']); |
|
| 47 | + $hour = sanitize_text_field($data['give-payment-time-hour']); |
|
| 48 | 48 | |
| 49 | 49 | // Restrict to our high and low |
| 50 | - if ( $hour > 23 ) { |
|
| 50 | + if ($hour > 23) { |
|
| 51 | 51 | $hour = 23; |
| 52 | - } elseif ( $hour < 0 ) { |
|
| 52 | + } elseif ($hour < 0) { |
|
| 53 | 53 | $hour = 00; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $minute = sanitize_text_field( $data['give-payment-time-min'] ); |
|
| 56 | + $minute = sanitize_text_field($data['give-payment-time-min']); |
|
| 57 | 57 | |
| 58 | 58 | // Restrict to our high and low |
| 59 | - if ( $minute > 59 ) { |
|
| 59 | + if ($minute > 59) { |
|
| 60 | 60 | $minute = 59; |
| 61 | - } elseif ( $minute < 0 ) { |
|
| 61 | + } elseif ($minute < 0) { |
|
| 62 | 62 | $minute = 00; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $address = array_map( 'trim', $data['give-payment-address'][0] ); |
|
| 65 | + $address = array_map('trim', $data['give-payment-address'][0]); |
|
| 66 | 66 | |
| 67 | - $curr_total = give_sanitize_amount( $payment->total ); |
|
| 68 | - $new_total = give_sanitize_amount( $_POST['give-payment-total'] ); |
|
| 69 | - $date = date( 'Y-m-d', strtotime( $date ) ) . ' ' . $hour . ':' . $minute . ':00'; |
|
| 67 | + $curr_total = give_sanitize_amount($payment->total); |
|
| 68 | + $new_total = give_sanitize_amount($_POST['give-payment-total']); |
|
| 69 | + $date = date('Y-m-d', strtotime($date)).' '.$hour.':'.$minute.':00'; |
|
| 70 | 70 | |
| 71 | - $curr_customer_id = sanitize_text_field( $data['give-current-customer'] ); |
|
| 72 | - $new_customer_id = sanitize_text_field( $data['customer-id'] ); |
|
| 71 | + $curr_customer_id = sanitize_text_field($data['give-current-customer']); |
|
| 72 | + $new_customer_id = sanitize_text_field($data['customer-id']); |
|
| 73 | 73 | |
| 74 | - do_action( 'give_update_edited_purchase', $payment_id ); |
|
| 74 | + do_action('give_update_edited_purchase', $payment_id); |
|
| 75 | 75 | |
| 76 | 76 | $payment->date = $date; |
| 77 | 77 | $updated = $payment->save(); |
| 78 | 78 | |
| 79 | - if ( 0 === $updated ) { |
|
| 80 | - wp_die( esc_html( 'Error Updating Payment.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
| 79 | + if (0 === $updated) { |
|
| 80 | + wp_die(esc_html('Error Updating Payment.', 'give'), esc_html('Error', 'give'), array('response' => 400)); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $customer_changed = false; |
| 84 | 84 | |
| 85 | - if ( isset( $data['give-new-customer'] ) && $data['give-new-customer'] == '1' ) { |
|
| 85 | + if (isset($data['give-new-customer']) && $data['give-new-customer'] == '1') { |
|
| 86 | 86 | |
| 87 | - $email = isset( $data['give-new-customer-email'] ) ? sanitize_text_field( $data['give-new-customer-email'] ) : ''; |
|
| 88 | - $names = isset( $data['give-new-customer-name'] ) ? sanitize_text_field( $data['give-new-customer-name'] ) : ''; |
|
| 87 | + $email = isset($data['give-new-customer-email']) ? sanitize_text_field($data['give-new-customer-email']) : ''; |
|
| 88 | + $names = isset($data['give-new-customer-name']) ? sanitize_text_field($data['give-new-customer-name']) : ''; |
|
| 89 | 89 | |
| 90 | - if ( empty( $email ) || empty( $names ) ) { |
|
| 91 | - wp_die( esc_html( 'New Customers require a name and email address.', 'give' ) ); |
|
| 90 | + if (empty($email) || empty($names)) { |
|
| 91 | + wp_die(esc_html('New Customers require a name and email address.', 'give')); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $customer = new Give_Customer( $email ); |
|
| 95 | - if ( empty( $customer->id ) ) { |
|
| 96 | - $customer_data = array( 'name' => $names, 'email' => $email ); |
|
| 97 | - $user_id = email_exists( $email ); |
|
| 98 | - if ( false !== $user_id ) { |
|
| 94 | + $customer = new Give_Customer($email); |
|
| 95 | + if (empty($customer->id)) { |
|
| 96 | + $customer_data = array('name' => $names, 'email' => $email); |
|
| 97 | + $user_id = email_exists($email); |
|
| 98 | + if (false !== $user_id) { |
|
| 99 | 99 | $customer_data['user_id'] = $user_id; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if ( ! $customer->create( $customer_data ) ) { |
|
| 102 | + if ( ! $customer->create($customer_data)) { |
|
| 103 | 103 | // Failed to crete the new donor, assume the previous donor |
| 104 | 104 | $customer_changed = false; |
| 105 | - $customer = new Give_Customer( $curr_customer_id ); |
|
| 106 | - give_set_error( 'give-payment-new-customer-fail', esc_html( 'Error creating new donor.', 'give' ) ); |
|
| 105 | + $customer = new Give_Customer($curr_customer_id); |
|
| 106 | + give_set_error('give-payment-new-customer-fail', esc_html('Error creating new donor.', 'give')); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $new_customer_id = $customer->id; |
| 111 | 111 | |
| 112 | - $previous_customer = new Give_Customer( $curr_customer_id ); |
|
| 112 | + $previous_customer = new Give_Customer($curr_customer_id); |
|
| 113 | 113 | |
| 114 | 114 | $customer_changed = true; |
| 115 | 115 | |
| 116 | - } elseif ( $curr_customer_id !== $new_customer_id ) { |
|
| 116 | + } elseif ($curr_customer_id !== $new_customer_id) { |
|
| 117 | 117 | |
| 118 | - $customer = new Give_Customer( $new_customer_id ); |
|
| 118 | + $customer = new Give_Customer($new_customer_id); |
|
| 119 | 119 | $email = $customer->email; |
| 120 | 120 | $names = $customer->name; |
| 121 | 121 | |
| 122 | - $previous_customer = new Give_Customer( $curr_customer_id ); |
|
| 122 | + $previous_customer = new Give_Customer($curr_customer_id); |
|
| 123 | 123 | |
| 124 | 124 | $customer_changed = true; |
| 125 | 125 | |
| 126 | 126 | } else { |
| 127 | 127 | |
| 128 | - $customer = new Give_Customer( $curr_customer_id ); |
|
| 128 | + $customer = new Give_Customer($curr_customer_id); |
|
| 129 | 129 | $email = $customer->email; |
| 130 | 130 | $names = $customer->name; |
| 131 | 131 | |
@@ -133,29 +133,29 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | |
| 135 | 135 | // Setup first and last name from input values |
| 136 | - $names = explode( ' ', $names ); |
|
| 137 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
| 136 | + $names = explode(' ', $names); |
|
| 137 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
| 138 | 138 | $last_name = ''; |
| 139 | - if ( ! empty( $names[1] ) ) { |
|
| 140 | - unset( $names[0] ); |
|
| 141 | - $last_name = implode( ' ', $names ); |
|
| 139 | + if ( ! empty($names[1])) { |
|
| 140 | + unset($names[0]); |
|
| 141 | + $last_name = implode(' ', $names); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
| 145 | - if ( $customer_changed ) { |
|
| 145 | + if ($customer_changed) { |
|
| 146 | 146 | |
| 147 | 147 | // Remove the stats and payment from the previous customer and attach it to the new customer |
| 148 | - $previous_customer->remove_payment( $payment_id, false ); |
|
| 149 | - $customer->attach_payment( $payment_id, false ); |
|
| 148 | + $previous_customer->remove_payment($payment_id, false); |
|
| 149 | + $customer->attach_payment($payment_id, false); |
|
| 150 | 150 | |
| 151 | 151 | // If purchase was completed and not ever refunded, adjust stats of customers |
| 152 | - if ( 'revoked' == $status || 'publish' == $status ) { |
|
| 152 | + if ('revoked' == $status || 'publish' == $status) { |
|
| 153 | 153 | |
| 154 | 154 | $previous_customer->decrease_purchase_count(); |
| 155 | - $previous_customer->decrease_value( $new_total ); |
|
| 155 | + $previous_customer->decrease_value($new_total); |
|
| 156 | 156 | |
| 157 | 157 | $customer->increase_purchase_count(); |
| 158 | - $customer->increase_value( $new_total ); |
|
| 158 | + $customer->increase_value($new_total); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | $payment->customer_id = $customer->id; |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | |
| 173 | 173 | // Check for payment notes |
| 174 | - if ( ! empty( $data['give-payment-note'] ) ) { |
|
| 174 | + if ( ! empty($data['give-payment-note'])) { |
|
| 175 | 175 | |
| 176 | - $note = wp_kses( $data['give-payment-note'], array() ); |
|
| 177 | - give_insert_payment_note( $payment_id, $note ); |
|
| 176 | + $note = wp_kses($data['give-payment-note'], array()); |
|
| 177 | + give_insert_payment_note($payment_id, $note); |
|
| 178 | 178 | |
| 179 | 179 | } |
| 180 | 180 | |
@@ -182,17 +182,17 @@ discard block |
||
| 182 | 182 | $payment->status = $status; |
| 183 | 183 | |
| 184 | 184 | // Adjust total store earnings if the payment total has been changed |
| 185 | - if ( $new_total !== $curr_total && ( 'publish' == $status || 'revoked' == $status ) ) { |
|
| 185 | + if ($new_total !== $curr_total && ('publish' == $status || 'revoked' == $status)) { |
|
| 186 | 186 | |
| 187 | - if ( $new_total > $curr_total ) { |
|
| 187 | + if ($new_total > $curr_total) { |
|
| 188 | 188 | // Increase if our new total is higher |
| 189 | 189 | $difference = $new_total - $curr_total; |
| 190 | - give_increase_total_earnings( $difference ); |
|
| 190 | + give_increase_total_earnings($difference); |
|
| 191 | 191 | |
| 192 | - } elseif ( $curr_total > $new_total ) { |
|
| 192 | + } elseif ($curr_total > $new_total) { |
|
| 193 | 193 | // Decrease if our new total is lower |
| 194 | 194 | $difference = $curr_total - $new_total; |
| 195 | - give_decrease_total_earnings( $difference ); |
|
| 195 | + give_decrease_total_earnings($difference); |
|
| 196 | 196 | |
| 197 | 197 | } |
| 198 | 198 | |
@@ -200,13 +200,13 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | $payment->save(); |
| 202 | 202 | |
| 203 | - do_action( 'give_updated_edited_purchase', $payment_id ); |
|
| 203 | + do_action('give_updated_edited_purchase', $payment_id); |
|
| 204 | 204 | |
| 205 | - wp_safe_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-updated&id=' . $payment_id ) ); |
|
| 205 | + wp_safe_redirect(admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-updated&id='.$payment_id)); |
|
| 206 | 206 | exit; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | -add_action( 'give_update_payment_details', 'give_update_payment_details' ); |
|
| 209 | +add_action('give_update_payment_details', 'give_update_payment_details'); |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * Trigger a Purchase Deletion |
@@ -217,48 +217,48 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return void |
| 219 | 219 | */ |
| 220 | -function give_trigger_purchase_delete( $data ) { |
|
| 221 | - if ( wp_verify_nonce( $data['_wpnonce'], 'give_payment_nonce' ) ) { |
|
| 220 | +function give_trigger_purchase_delete($data) { |
|
| 221 | + if (wp_verify_nonce($data['_wpnonce'], 'give_payment_nonce')) { |
|
| 222 | 222 | |
| 223 | - $payment_id = absint( $data['purchase_id'] ); |
|
| 223 | + $payment_id = absint($data['purchase_id']); |
|
| 224 | 224 | |
| 225 | - if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) { |
|
| 226 | - wp_die( esc_html( 'You do not have permission to edit payment records.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 225 | + if ( ! current_user_can('edit_give_payments', $payment_id)) { |
|
| 226 | + wp_die(esc_html('You do not have permission to edit payment records.', 'give'), esc_html('Error', 'give'), array('response' => 403)); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - give_delete_purchase( $payment_id ); |
|
| 230 | - wp_redirect( admin_url( '/edit.php?post_type=give_forms&page=give-payment-history&give-message=payment_deleted' ) ); |
|
| 229 | + give_delete_purchase($payment_id); |
|
| 230 | + wp_redirect(admin_url('/edit.php?post_type=give_forms&page=give-payment-history&give-message=payment_deleted')); |
|
| 231 | 231 | give_die(); |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | -add_action( 'give_delete_payment', 'give_trigger_purchase_delete' ); |
|
| 235 | +add_action('give_delete_payment', 'give_trigger_purchase_delete'); |
|
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * AJAX Store Payment Note |
| 239 | 239 | */ |
| 240 | 240 | function give_ajax_store_payment_note() { |
| 241 | 241 | |
| 242 | - $payment_id = absint( $_POST['payment_id'] ); |
|
| 243 | - $note = wp_kses( $_POST['note'], array() ); |
|
| 242 | + $payment_id = absint($_POST['payment_id']); |
|
| 243 | + $note = wp_kses($_POST['note'], array()); |
|
| 244 | 244 | |
| 245 | - if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) { |
|
| 246 | - wp_die( esc_html( 'You do not have permission to edit payment records.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 245 | + if ( ! current_user_can('edit_give_payments', $payment_id)) { |
|
| 246 | + wp_die(esc_html('You do not have permission to edit payment records.', 'give'), esc_html('Error', 'give'), array('response' => 403)); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( empty( $payment_id ) ) { |
|
| 250 | - die( '-1' ); |
|
| 249 | + if (empty($payment_id)) { |
|
| 250 | + die('-1'); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( empty( $note ) ) { |
|
| 254 | - die( '-1' ); |
|
| 253 | + if (empty($note)) { |
|
| 254 | + die('-1'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - $note_id = give_insert_payment_note( $payment_id, $note ); |
|
| 258 | - die( give_get_payment_note_html( $note_id ) ); |
|
| 257 | + $note_id = give_insert_payment_note($payment_id, $note); |
|
| 258 | + die(give_get_payment_note_html($note_id)); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | -add_action( 'wp_ajax_give_insert_payment_note', 'give_ajax_store_payment_note' ); |
|
| 261 | +add_action('wp_ajax_give_insert_payment_note', 'give_ajax_store_payment_note'); |
|
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | 264 | * Triggers a payment note deletion without ajax |
@@ -269,24 +269,24 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return void |
| 271 | 271 | */ |
| 272 | -function give_trigger_payment_note_deletion( $data ) { |
|
| 272 | +function give_trigger_payment_note_deletion($data) { |
|
| 273 | 273 | |
| 274 | - if ( ! wp_verify_nonce( $data['_wpnonce'], 'give_delete_payment_note_' . $data['note_id'] ) ) { |
|
| 274 | + if ( ! wp_verify_nonce($data['_wpnonce'], 'give_delete_payment_note_'.$data['note_id'])) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( ! current_user_can( 'edit_give_payments', $data['payment_id'] ) ) { |
|
| 279 | - wp_die( esc_html( 'You do not have permission to edit payment records.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 278 | + if ( ! current_user_can('edit_give_payments', $data['payment_id'])) { |
|
| 279 | + wp_die(esc_html('You do not have permission to edit payment records.', 'give'), esc_html('Error', 'give'), array('response' => 403)); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - $edit_order_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-note-deleted&id=' . absint( $data['payment_id'] ) ); |
|
| 282 | + $edit_order_url = admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-note-deleted&id='.absint($data['payment_id'])); |
|
| 283 | 283 | |
| 284 | - give_delete_payment_note( $data['note_id'], $data['payment_id'] ); |
|
| 284 | + give_delete_payment_note($data['note_id'], $data['payment_id']); |
|
| 285 | 285 | |
| 286 | - wp_redirect( $edit_order_url ); |
|
| 286 | + wp_redirect($edit_order_url); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | -add_action( 'give_delete_payment_note', 'give_trigger_payment_note_deletion' ); |
|
| 289 | +add_action('give_delete_payment_note', 'give_trigger_payment_note_deletion'); |
|
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | 292 | * Delete a payment note deletion with ajax |
@@ -299,16 +299,16 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function give_ajax_delete_payment_note() { |
| 301 | 301 | |
| 302 | - if ( ! current_user_can( 'edit_give_payments', $_POST['payment_id'] ) ) { |
|
| 303 | - wp_die( esc_html( 'You do not have permission to edit payment records.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 302 | + if ( ! current_user_can('edit_give_payments', $_POST['payment_id'])) { |
|
| 303 | + wp_die(esc_html('You do not have permission to edit payment records.', 'give'), esc_html('Error', 'give'), array('response' => 403)); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( give_delete_payment_note( $_POST['note_id'], $_POST['payment_id'] ) ) { |
|
| 307 | - die( '1' ); |
|
| 306 | + if (give_delete_payment_note($_POST['note_id'], $_POST['payment_id'])) { |
|
| 307 | + die('1'); |
|
| 308 | 308 | } else { |
| 309 | - die( '-1' ); |
|
| 309 | + die('-1'); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | -add_action( 'wp_ajax_give_delete_payment_note', 'give_ajax_delete_payment_note' ); |
|
| 315 | 314 | \ No newline at end of file |
| 315 | +add_action('wp_ajax_give_delete_payment_note', 'give_ajax_delete_payment_note'); |
|
| 316 | 316 | \ No newline at end of file |
@@ -157,7 +157,7 @@ |
||
| 157 | 157 | * |
| 158 | 158 | * @access public |
| 159 | 159 | * @since 1.0 |
| 160 | - * @return mixed String if search is present, false otherwise |
|
| 160 | + * @return string|false String if search is present, false otherwise |
|
| 161 | 161 | */ |
| 162 | 162 | public function get_search() { |
| 163 | 163 | return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
@@ -10,13 +10,13 @@ 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 | 17 | // Load WP_List_Table if not loaded |
| 18 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 19 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 18 | +if ( ! class_exists('WP_List_Table')) { |
|
| 19 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | global $status, $page; |
| 46 | 46 | |
| 47 | 47 | // Set parent defaults |
| 48 | - parent::__construct( array( |
|
| 49 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
| 50 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
| 48 | + parent::__construct(array( |
|
| 49 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
| 50 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
| 51 | 51 | 'ajax' => false // Does this table support ajax? |
| 52 | - ) ); |
|
| 52 | + )); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -63,20 +63,20 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - public function search_box( $text, $input_id ) { |
|
| 67 | - $input_id = $input_id . '-search-input'; |
|
| 66 | + public function search_box($text, $input_id) { |
|
| 67 | + $input_id = $input_id.'-search-input'; |
|
| 68 | 68 | |
| 69 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 70 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 69 | + if ( ! empty($_REQUEST['orderby'])) { |
|
| 70 | + echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />'; |
|
| 71 | 71 | } |
| 72 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 73 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 72 | + if ( ! empty($_REQUEST['order'])) { |
|
| 73 | + echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />'; |
|
| 74 | 74 | } |
| 75 | 75 | ?> |
| 76 | 76 | <p class="search-box"> |
| 77 | 77 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
| 78 | 78 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
| 79 | - <?php submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?> |
|
| 79 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?> |
|
| 80 | 80 | </p> |
| 81 | 81 | <?php |
| 82 | 82 | } |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function get_columns() { |
| 92 | 92 | $columns = array( |
| 93 | - 'ID' => esc_html( 'Log ID', 'give' ), |
|
| 94 | - 'details' => esc_html( 'Request Details', 'give' ), |
|
| 95 | - 'ip' => esc_html( 'Request IP', 'give' ), |
|
| 96 | - 'date' => esc_html( 'Date', 'give' ) |
|
| 93 | + 'ID' => esc_html('Log ID', 'give'), |
|
| 94 | + 'details' => esc_html('Request Details', 'give'), |
|
| 95 | + 'ip' => esc_html('Request IP', 'give'), |
|
| 96 | + 'date' => esc_html('Date', 'give') |
|
| 97 | 97 | ); |
| 98 | 98 | |
| 99 | 99 | return $columns; |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return string Column Name |
| 112 | 112 | */ |
| 113 | - public function column_default( $item, $column_name ) { |
|
| 114 | - switch ( $column_name ) { |
|
| 113 | + public function column_default($item, $column_name) { |
|
| 114 | + switch ($column_name) { |
|
| 115 | 115 | default: |
| 116 | - return $item[ $column_name ]; |
|
| 116 | + return $item[$column_name]; |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
@@ -127,26 +127,26 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return void |
| 129 | 129 | */ |
| 130 | - public function column_details( $item ) { |
|
| 130 | + public function column_details($item) { |
|
| 131 | 131 | ?> |
| 132 | - <a href="#TB_inline?width=640&inlineId=log-details-<?php echo $item['ID']; ?>" class="thickbox" title="<?php esc_attr_e( 'View Request Details', 'give' ); ?> "><?php esc_html_e( 'View Request', 'give' ); ?></a> |
|
| 132 | + <a href="#TB_inline?width=640&inlineId=log-details-<?php echo $item['ID']; ?>" class="thickbox" title="<?php esc_attr_e('View Request Details', 'give'); ?> "><?php esc_html_e('View Request', 'give'); ?></a> |
|
| 133 | 133 | <div id="log-details-<?php echo $item['ID']; ?>" style="display:none;"> |
| 134 | 134 | <?php |
| 135 | 135 | |
| 136 | - $request = get_post_field( 'post_excerpt', $item['ID'] ); |
|
| 137 | - $error = get_post_field( 'post_content', $item['ID'] ); |
|
| 138 | - echo '<p><strong>' . esc_html( 'API Request:', 'give' ) . '</strong></p>'; |
|
| 139 | - echo '<div>' . $request . '</div>'; |
|
| 140 | - if ( ! empty( $error ) ) { |
|
| 141 | - echo '<p><strong>' . esc_html( 'Error', 'give' ) . '</strong></p>'; |
|
| 142 | - echo '<div>' . esc_html( $error ) . '</div>'; |
|
| 136 | + $request = get_post_field('post_excerpt', $item['ID']); |
|
| 137 | + $error = get_post_field('post_content', $item['ID']); |
|
| 138 | + echo '<p><strong>'.esc_html('API Request:', 'give').'</strong></p>'; |
|
| 139 | + echo '<div>'.$request.'</div>'; |
|
| 140 | + if ( ! empty($error)) { |
|
| 141 | + echo '<p><strong>'.esc_html('Error', 'give').'</strong></p>'; |
|
| 142 | + echo '<div>'.esc_html($error).'</div>'; |
|
| 143 | 143 | } |
| 144 | - echo '<p><strong>' . esc_html( 'API User:', 'give' ) . '</strong></p>'; |
|
| 145 | - echo '<div>' . get_post_meta( $item['ID'], '_give_log_user', true ) . '</div>'; |
|
| 146 | - echo '<p><strong>' . esc_html( 'API Key:', 'give' ) . '</strong></p>'; |
|
| 147 | - echo '<div>' . get_post_meta( $item['ID'], '_give_log_key', true ) . '</div>'; |
|
| 148 | - echo '<p><strong>' . esc_html( 'Request Date:', 'give' ) . '</strong></p>'; |
|
| 149 | - echo '<div>' . get_post_field( 'post_date', $item['ID'] ) . '</div>'; |
|
| 144 | + echo '<p><strong>'.esc_html('API User:', 'give').'</strong></p>'; |
|
| 145 | + echo '<div>'.get_post_meta($item['ID'], '_give_log_user', true).'</div>'; |
|
| 146 | + echo '<p><strong>'.esc_html('API Key:', 'give').'</strong></p>'; |
|
| 147 | + echo '<div>'.get_post_meta($item['ID'], '_give_log_key', true).'</div>'; |
|
| 148 | + echo '<p><strong>'.esc_html('Request Date:', 'give').'</strong></p>'; |
|
| 149 | + echo '<div>'.get_post_field('post_date', $item['ID']).'</div>'; |
|
| 150 | 150 | ?> |
| 151 | 151 | </div> |
| 152 | 152 | <?php |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @return mixed String if search is present, false otherwise |
| 161 | 161 | */ |
| 162 | 162 | public function get_search() { |
| 163 | - return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
|
| 163 | + return ! empty($_GET['s']) ? urldecode(trim($_GET['s'])) : false; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | |
@@ -176,19 +176,19 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @param string $which |
| 178 | 178 | */ |
| 179 | - protected function display_tablenav( $which ) { |
|
| 180 | - if ( 'top' === $which ) { |
|
| 181 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
| 179 | + protected function display_tablenav($which) { |
|
| 180 | + if ('top' === $which) { |
|
| 181 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
| 182 | 182 | } |
| 183 | 183 | ?> |
| 184 | - <div class="tablenav <?php esc_attr_e( $which ); ?>"> |
|
| 184 | + <div class="tablenav <?php esc_attr_e($which); ?>"> |
|
| 185 | 185 | |
| 186 | 186 | <div class="alignleft actions bulkactions"> |
| 187 | - <?php $this->bulk_actions( $which ); ?> |
|
| 187 | + <?php $this->bulk_actions($which); ?> |
|
| 188 | 188 | </div> |
| 189 | 189 | <?php |
| 190 | - $this->extra_tablenav( $which ); |
|
| 191 | - $this->pagination( $which ); |
|
| 190 | + $this->extra_tablenav($which); |
|
| 191 | + $this->pagination($which); |
|
| 192 | 192 | ?> |
| 193 | 193 | |
| 194 | 194 | <br class="clear"/> |
@@ -210,31 +210,31 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $search = $this->get_search(); |
| 212 | 212 | |
| 213 | - if ( $search ) { |
|
| 214 | - if ( filter_var( $search, FILTER_VALIDATE_IP ) ) { |
|
| 213 | + if ($search) { |
|
| 214 | + if (filter_var($search, FILTER_VALIDATE_IP)) { |
|
| 215 | 215 | // This is an IP address search |
| 216 | 216 | $key = '_give_log_request_ip'; |
| 217 | - } else if ( is_email( $search ) ) { |
|
| 217 | + } else if (is_email($search)) { |
|
| 218 | 218 | // This is an email search |
| 219 | - $userdata = get_user_by( 'email', $search ); |
|
| 219 | + $userdata = get_user_by('email', $search); |
|
| 220 | 220 | |
| 221 | - if ( $userdata ) { |
|
| 221 | + if ($userdata) { |
|
| 222 | 222 | $search = $userdata->ID; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $key = '_give_log_user'; |
| 226 | - } elseif ( strlen( $search ) == 32 ) { |
|
| 226 | + } elseif (strlen($search) == 32) { |
|
| 227 | 227 | // Look for an API key |
| 228 | 228 | $key = '_give_log_key'; |
| 229 | - } elseif ( stristr( $search, 'token:' ) ) { |
|
| 229 | + } elseif (stristr($search, 'token:')) { |
|
| 230 | 230 | // Look for an API token |
| 231 | - $search = str_ireplace( 'token:', '', $search ); |
|
| 231 | + $search = str_ireplace('token:', '', $search); |
|
| 232 | 232 | $key = '_give_log_token'; |
| 233 | 233 | } else { |
| 234 | 234 | // This is (probably) a user ID search |
| 235 | - $userdata = get_userdata( $search ); |
|
| 235 | + $userdata = get_userdata($search); |
|
| 236 | 236 | |
| 237 | - if ( $userdata ) { |
|
| 237 | + if ($userdata) { |
|
| 238 | 238 | $search = $userdata->ID; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @return int Current page number |
| 261 | 261 | */ |
| 262 | 262 | public function get_paged() { |
| 263 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 263 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @since 1.0 |
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | - function bulk_actions( $which = '' ) { |
|
| 273 | + function bulk_actions($which = '') { |
|
| 274 | 274 | give_log_views(); |
| 275 | 275 | } |
| 276 | 276 | |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | 'meta_query' => $this->get_meta_query() |
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | - $logs = $give_logs->get_connected_logs( $log_query ); |
|
| 296 | + $logs = $give_logs->get_connected_logs($log_query); |
|
| 297 | 297 | |
| 298 | - if ( $logs ) { |
|
| 299 | - foreach ( $logs as $log ) { |
|
| 298 | + if ($logs) { |
|
| 299 | + foreach ($logs as $log) { |
|
| 300 | 300 | |
| 301 | 301 | $logs_data[] = array( |
| 302 | 302 | 'ID' => $log->ID, |
| 303 | - 'ip' => get_post_meta( $log->ID, '_give_log_request_ip', true ), |
|
| 303 | + 'ip' => get_post_meta($log->ID, '_give_log_request_ip', true), |
|
| 304 | 304 | 'date' => $log->post_date |
| 305 | 305 | ); |
| 306 | 306 | } |
@@ -328,14 +328,14 @@ discard block |
||
| 328 | 328 | $columns = $this->get_columns(); |
| 329 | 329 | $hidden = array(); // No hidden columns |
| 330 | 330 | $sortable = $this->get_sortable_columns(); |
| 331 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 331 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 332 | 332 | $this->items = $this->get_logs(); |
| 333 | - $total_items = $give_logs->get_log_count( 0, 'api_requests' ); |
|
| 333 | + $total_items = $give_logs->get_log_count(0, 'api_requests'); |
|
| 334 | 334 | |
| 335 | - $this->set_pagination_args( array( |
|
| 335 | + $this->set_pagination_args(array( |
|
| 336 | 336 | 'total_items' => $total_items, |
| 337 | 337 | 'per_page' => $this->per_page, |
| 338 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 338 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
| 339 | 339 | ) |
| 340 | 340 | ); |
| 341 | 341 | } |
@@ -143,7 +143,7 @@ |
||
| 143 | 143 | * |
| 144 | 144 | * @access public |
| 145 | 145 | * @since 1.0 |
| 146 | - * @return mixed string If search is present, false otherwise |
|
| 146 | + * @return string|false string If search is present, false otherwise |
|
| 147 | 147 | */ |
| 148 | 148 | public function get_search() { |
| 149 | 149 | return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
@@ -71,8 +71,8 @@ |
||
| 71 | 71 | |
| 72 | 72 | case 'user_id' : |
| 73 | 73 | return '<a href="' . |
| 74 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
| 75 | - '">' . $item['user_name'] . '</a>'; |
|
| 74 | + admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
| 75 | + '">' . $item['user_name'] . '</a>'; |
|
| 76 | 76 | |
| 77 | 77 | case 'amount' : |
| 78 | 78 | return give_currency_filter( give_format_amount( $item['amount'] ) ); |
@@ -9,13 +9,13 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | // Exit if accessed directly |
| 12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | +if ( ! defined('ABSPATH')) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // Load WP_List_Table if not loaded |
| 17 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 18 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 17 | +if ( ! class_exists('WP_List_Table')) { |
|
| 18 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | global $status, $page; |
| 45 | 45 | |
| 46 | 46 | // Set parent defaults |
| 47 | - parent::__construct( array( |
|
| 48 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
| 49 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
| 47 | + parent::__construct(array( |
|
| 48 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
| 49 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
| 50 | 50 | 'ajax' => false // Does this table support ajax? |
| 51 | - ) ); |
|
| 51 | + )); |
|
| 52 | 52 | |
| 53 | - add_action( 'give_log_view_actions', array( $this, 'give_forms_filter' ) ); |
|
| 53 | + add_action('give_log_view_actions', array($this, 'give_forms_filter')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -64,37 +64,37 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return string Column Name |
| 66 | 66 | */ |
| 67 | - public function column_default( $item, $column_name ) { |
|
| 67 | + public function column_default($item, $column_name) { |
|
| 68 | 68 | |
| 69 | - $payment = give_get_payment_by( 'id', $item['payment_id'] ); |
|
| 69 | + $payment = give_get_payment_by('id', $item['payment_id']); |
|
| 70 | 70 | |
| 71 | - switch ( $column_name ) { |
|
| 71 | + switch ($column_name) { |
|
| 72 | 72 | case 'form' : |
| 73 | - return '<a href="' . esc_url( add_query_arg( 'form', $item[ $column_name ] ) ) . '" >' . get_the_title( $item[ $column_name ] ) . '</a>'; |
|
| 73 | + return '<a href="'.esc_url(add_query_arg('form', $item[$column_name])).'" >'.get_the_title($item[$column_name]).'</a>'; |
|
| 74 | 74 | |
| 75 | 75 | case 'user_id' : |
| 76 | - return '<a href="' . |
|
| 77 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
| 78 | - '">' . $item['user_name'] . '</a>'; |
|
| 76 | + return '<a href="'. |
|
| 77 | + admin_url('edit.php?post_type=give_forms&page=give-payment-history&user='.( ! empty($item['user_id']) ? urlencode($item['user_id']) : give_get_payment_user_email($item['payment_id']))). |
|
| 78 | + '">'.$item['user_name'].'</a>'; |
|
| 79 | 79 | |
| 80 | 80 | case 'amount' : |
| 81 | - return give_currency_filter( give_format_amount( $item['amount'] ) ); |
|
| 81 | + return give_currency_filter(give_format_amount($item['amount'])); |
|
| 82 | 82 | |
| 83 | 83 | case 'status' : |
| 84 | 84 | |
| 85 | - $value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>'; |
|
| 85 | + $value = '<div class="give-donation-status status-'.sanitize_title(give_get_payment_status($payment, true)).'"><span class="give-donation-status-icon"></span> '.give_get_payment_status($payment, true).'</div>'; |
|
| 86 | 86 | |
| 87 | - if ( $payment->mode == 'test' ) { |
|
| 88 | - $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="' . esc_attr( 'This payment was made in test mode', 'give' ) . '">' . esc_html( 'Test', 'give' ) . '</span>'; |
|
| 87 | + if ($payment->mode == 'test') { |
|
| 88 | + $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="'.esc_attr('This payment was made in test mode', 'give').'">'.esc_html('Test', 'give').'</span>'; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | return $value; |
| 92 | 92 | |
| 93 | 93 | case 'payment_id' : |
| 94 | - return '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $item['payment_id'] ) . '">' . give_get_payment_number( $item['payment_id'] ) . '</a>'; |
|
| 94 | + return '<a href="'.admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id='.$item['payment_id']).'">'.give_get_payment_number($item['payment_id']).'</a>'; |
|
| 95 | 95 | |
| 96 | 96 | default: |
| 97 | - return $item[ $column_name ]; |
|
| 97 | + return $item[$column_name]; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function get_columns() { |
| 109 | 109 | $columns = array( |
| 110 | - 'ID' => esc_html( 'Log ID', 'give' ), |
|
| 111 | - 'user_id' => esc_html( 'Donor', 'give' ), |
|
| 110 | + 'ID' => esc_html('Log ID', 'give'), |
|
| 111 | + 'user_id' => esc_html('Donor', 'give'), |
|
| 112 | 112 | 'form' => give_get_forms_label_singular(), |
| 113 | - 'amount' => esc_html( 'Donation Amount', 'give' ), |
|
| 114 | - 'status' => esc_html( 'Status', 'give' ), |
|
| 115 | - 'payment_id' => esc_html( 'Transaction ID', 'give' ), |
|
| 116 | - 'date' => esc_html( 'Date', 'give' ) |
|
| 113 | + 'amount' => esc_html('Donation Amount', 'give'), |
|
| 114 | + 'status' => esc_html('Status', 'give'), |
|
| 115 | + 'payment_id' => esc_html('Transaction ID', 'give'), |
|
| 116 | + 'date' => esc_html('Date', 'give') |
|
| 117 | 117 | ); |
| 118 | 118 | |
| 119 | 119 | return $columns; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @return int Current page number |
| 128 | 128 | */ |
| 129 | 129 | public function get_paged() { |
| 130 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 130 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @return mixed int If User ID, string If Email/Login |
| 139 | 139 | */ |
| 140 | 140 | public function get_filtered_user() { |
| 141 | - return isset( $_GET['user'] ) ? absint( $_GET['user'] ) : false; |
|
| 141 | + return isset($_GET['user']) ? absint($_GET['user']) : false; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @return int Download ID |
| 150 | 150 | */ |
| 151 | 151 | public function get_filtered_give_form() { |
| 152 | - return ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : false; |
|
| 152 | + return ! empty($_GET['form']) ? absint($_GET['form']) : false; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @return mixed string If search is present, false otherwise |
| 161 | 161 | */ |
| 162 | 162 | public function get_search() { |
| 163 | - return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
|
| 163 | + return ! empty($_GET['s']) ? urldecode(trim($_GET['s'])) : false; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | |
@@ -176,20 +176,20 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @param string $which |
| 178 | 178 | */ |
| 179 | - protected function display_tablenav( $which ) { |
|
| 179 | + protected function display_tablenav($which) { |
|
| 180 | 180 | |
| 181 | - if ( 'top' === $which ) { |
|
| 182 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
| 181 | + if ('top' === $which) { |
|
| 182 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
| 183 | 183 | } |
| 184 | 184 | ?> |
| 185 | - <div class="tablenav <?php esc_attr_e( $which ); ?>"> |
|
| 185 | + <div class="tablenav <?php esc_attr_e($which); ?>"> |
|
| 186 | 186 | |
| 187 | 187 | <div class="alignleft actions bulkactions"> |
| 188 | - <?php $this->bulk_actions( $which ); ?> |
|
| 188 | + <?php $this->bulk_actions($which); ?> |
|
| 189 | 189 | </div> |
| 190 | 190 | <?php |
| 191 | - $this->extra_tablenav( $which ); |
|
| 192 | - $this->pagination( $which ); |
|
| 191 | + $this->extra_tablenav($which); |
|
| 192 | + $this->pagination($which); |
|
| 193 | 193 | ?> |
| 194 | 194 | |
| 195 | 195 | <br class="clear"/> |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $meta_query = array(); |
| 214 | 214 | |
| 215 | - if ( $user ) { |
|
| 215 | + if ($user) { |
|
| 216 | 216 | // Show only logs from a specific user |
| 217 | 217 | $meta_query[] = array( |
| 218 | 218 | 'key' => '_give_log_user_id', |
@@ -221,8 +221,8 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | $search = $this->get_search(); |
| 224 | - if ( $search ) { |
|
| 225 | - if ( is_email( $search ) ) { |
|
| 224 | + if ($search) { |
|
| 225 | + if (is_email($search)) { |
|
| 226 | 226 | // This is an email search. We use this to ensure it works for guest users and logged-in users |
| 227 | 227 | $key = '_give_log_user_info'; |
| 228 | 228 | $compare = 'LIKE'; |
@@ -231,32 +231,32 @@ discard block |
||
| 231 | 231 | $key = '_give_log_user_id'; |
| 232 | 232 | $compare = 'LIKE'; |
| 233 | 233 | |
| 234 | - if ( ! is_numeric( $search ) ) { |
|
| 234 | + if ( ! is_numeric($search)) { |
|
| 235 | 235 | // Searching for user by username |
| 236 | - $user = get_user_by( 'login', $search ); |
|
| 236 | + $user = get_user_by('login', $search); |
|
| 237 | 237 | |
| 238 | - if ( $user ) { |
|
| 238 | + if ($user) { |
|
| 239 | 239 | // Found one, set meta value to user's ID |
| 240 | 240 | $search = $user->ID; |
| 241 | 241 | } else { |
| 242 | 242 | // No user found so let's do a real search query |
| 243 | - $users = new WP_User_Query( array( |
|
| 243 | + $users = new WP_User_Query(array( |
|
| 244 | 244 | 'search' => $search, |
| 245 | - 'search_columns' => array( 'user_url', 'user_nicename' ), |
|
| 245 | + 'search_columns' => array('user_url', 'user_nicename'), |
|
| 246 | 246 | 'number' => 1, |
| 247 | 247 | 'fields' => 'ids' |
| 248 | - ) ); |
|
| 248 | + )); |
|
| 249 | 249 | |
| 250 | 250 | $found_user = $users->get_results(); |
| 251 | 251 | |
| 252 | - if ( $found_user ) { |
|
| 252 | + if ($found_user) { |
|
| 253 | 253 | $search = $found_user[0]; |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( ! $this->file_search ) { |
|
| 259 | + if ( ! $this->file_search) { |
|
| 260 | 260 | // Meta query only works for non file name searche |
| 261 | 261 | $meta_query[] = array( |
| 262 | 262 | 'key' => $key, |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | * @since 1.0 |
| 278 | 278 | * @return void |
| 279 | 279 | */ |
| 280 | - function bulk_actions( $which = '' ) { |
|
| 280 | + function bulk_actions($which = '') { |
|
| 281 | 281 | give_log_views(); |
| 282 | 282 | } |
| 283 | 283 | |
@@ -289,22 +289,22 @@ discard block |
||
| 289 | 289 | * @return void |
| 290 | 290 | */ |
| 291 | 291 | public function give_forms_filter() { |
| 292 | - $give_forms = get_posts( array( |
|
| 292 | + $give_forms = get_posts(array( |
|
| 293 | 293 | 'post_type' => 'give_forms', |
| 294 | 294 | 'post_status' => 'any', |
| 295 | - 'posts_per_page' => - 1, |
|
| 295 | + 'posts_per_page' => -1, |
|
| 296 | 296 | 'orderby' => 'title', |
| 297 | 297 | 'order' => 'ASC', |
| 298 | 298 | 'fields' => 'ids', |
| 299 | 299 | 'update_post_meta_cache' => false, |
| 300 | 300 | 'update_post_term_cache' => false |
| 301 | - ) ); |
|
| 301 | + )); |
|
| 302 | 302 | |
| 303 | - if ( $give_forms ) { |
|
| 303 | + if ($give_forms) { |
|
| 304 | 304 | echo '<select name="form" id="give-log-form-filter">'; |
| 305 | - echo '<option value="0">' . esc_html( 'All', 'give' ) . '</option>'; |
|
| 306 | - foreach ( $give_forms as $form ) { |
|
| 307 | - echo '<option value="' . $form . '"' . selected( $form, $this->get_filtered_give_form() ) . '>' . esc_html( get_the_title( $form ) ) . '</option>'; |
|
| 305 | + echo '<option value="0">'.esc_html('All', 'give').'</option>'; |
|
| 306 | + foreach ($give_forms as $form) { |
|
| 307 | + echo '<option value="'.$form.'"'.selected($form, $this->get_filtered_give_form()).'>'.esc_html(get_the_title($form)).'</option>'; |
|
| 308 | 308 | } |
| 309 | 309 | echo '</select>'; |
| 310 | 310 | } |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | global $give_logs; |
| 323 | 323 | |
| 324 | 324 | // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs |
| 325 | - wp_suspend_cache_addition( true ); |
|
| 325 | + wp_suspend_cache_addition(true); |
|
| 326 | 326 | |
| 327 | 327 | $logs_data = array(); |
| 328 | 328 | $paged = $this->get_paged(); |
| 329 | - $give_form = empty( $_GET['s'] ) ? $this->get_filtered_give_form() : null; |
|
| 329 | + $give_form = empty($_GET['s']) ? $this->get_filtered_give_form() : null; |
|
| 330 | 330 | $user = $this->get_filtered_user(); |
| 331 | 331 | |
| 332 | 332 | $log_query = array( |
@@ -336,26 +336,26 @@ discard block |
||
| 336 | 336 | 'meta_query' => $this->get_meta_query() |
| 337 | 337 | ); |
| 338 | 338 | |
| 339 | - $logs = $give_logs->get_connected_logs( $log_query ); |
|
| 339 | + $logs = $give_logs->get_connected_logs($log_query); |
|
| 340 | 340 | |
| 341 | - if ( $logs ) { |
|
| 342 | - foreach ( $logs as $log ) { |
|
| 343 | - $payment_id = get_post_meta( $log->ID, '_give_log_payment_id', true ); |
|
| 341 | + if ($logs) { |
|
| 342 | + foreach ($logs as $log) { |
|
| 343 | + $payment_id = get_post_meta($log->ID, '_give_log_payment_id', true); |
|
| 344 | 344 | |
| 345 | 345 | // Make sure this payment hasn't been deleted |
| 346 | - if ( get_post( $payment_id ) ) : |
|
| 347 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
| 348 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
| 349 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
| 346 | + if (get_post($payment_id)) : |
|
| 347 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
| 348 | + $payment_meta = give_get_payment_meta($payment_id); |
|
| 349 | + $payment_amount = give_get_payment_amount($payment_id); |
|
| 350 | 350 | |
| 351 | 351 | $logs_data[] = array( |
| 352 | - 'ID' => '<span class="give-item-label give-item-label-gray">' . $log->ID . '</span>', |
|
| 352 | + 'ID' => '<span class="give-item-label give-item-label-gray">'.$log->ID.'</span>', |
|
| 353 | 353 | 'payment_id' => $payment_id, |
| 354 | 354 | 'form' => $log->post_parent, |
| 355 | 355 | 'amount' => $payment_amount, |
| 356 | 356 | 'user_id' => $user_info['id'], |
| 357 | - 'user_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], |
|
| 358 | - 'date' => get_post_field( 'post_date', $payment_id ) |
|
| 357 | + 'user_name' => $user_info['first_name'].' '.$user_info['last_name'], |
|
| 358 | + 'date' => get_post_field('post_date', $payment_id) |
|
| 359 | 359 | ); |
| 360 | 360 | |
| 361 | 361 | endif; |
@@ -384,15 +384,15 @@ discard block |
||
| 384 | 384 | $columns = $this->get_columns(); |
| 385 | 385 | $hidden = array(); |
| 386 | 386 | $sortable = $this->get_sortable_columns(); |
| 387 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 387 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 388 | 388 | $current_page = $this->get_pagenum(); |
| 389 | 389 | $this->items = $this->get_logs(); |
| 390 | - $total_items = $give_logs->get_log_count( $this->get_filtered_give_form(), 'sale', $this->get_meta_query() ); |
|
| 390 | + $total_items = $give_logs->get_log_count($this->get_filtered_give_form(), 'sale', $this->get_meta_query()); |
|
| 391 | 391 | |
| 392 | - $this->set_pagination_args( array( |
|
| 392 | + $this->set_pagination_args(array( |
|
| 393 | 393 | 'total_items' => $total_items, |
| 394 | 394 | 'per_page' => $this->per_page, |
| 395 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 395 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
| 396 | 396 | ) |
| 397 | 397 | ); |
| 398 | 398 | } |
@@ -576,7 +576,7 @@ |
||
| 576 | 576 | * selected date-range (if any) |
| 577 | 577 | * |
| 578 | 578 | * @since 1.0 |
| 579 | - * @return array |
|
| 579 | + * @return integer|null |
|
| 580 | 580 | */ |
| 581 | 581 | function give_get_report_dates() { |
| 582 | 582 | $dates = array(); |
@@ -143,9 +143,11 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | endwhile; |
| 145 | 145 | |
| 146 | - else : |
|
| 146 | + else { |
|
| 147 | + : |
|
| 147 | 148 | |
| 148 | 149 | $sales = give_get_sales_by_date( null, $i, $y ); |
| 150 | + } |
|
| 149 | 151 | $sales_totals += $sales; |
| 150 | 152 | |
| 151 | 153 | $earnings = give_get_earnings_by_date( null, $i, $y ); |
@@ -393,9 +395,11 @@ discard block |
||
| 393 | 395 | |
| 394 | 396 | endwhile; |
| 395 | 397 | |
| 396 | - else : |
|
| 398 | + else { |
|
| 399 | + : |
|
| 397 | 400 | |
| 398 | 401 | $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
| 402 | + } |
|
| 399 | 403 | |
| 400 | 404 | $date = mktime( 0, 0, 0, $i, 1, $y ); |
| 401 | 405 | $end_date = mktime( 23, 59, 59, $i, $num_of_days, $y ); |
@@ -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,7 +25,7 @@ discard block |
||
| 25 | 25 | $dates = give_get_report_dates(); |
| 26 | 26 | |
| 27 | 27 | // Determine graph options |
| 28 | - switch ( $dates['range'] ) : |
|
| 28 | + switch ($dates['range']) : |
|
| 29 | 29 | case 'today' : |
| 30 | 30 | case 'yesterday' : |
| 31 | 31 | $day_by_day = true; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $day_by_day = false; |
| 38 | 38 | break; |
| 39 | 39 | case 'other' : |
| 40 | - if ( $dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year'] && ( $dates['m_start'] != '12' && $dates['m_end'] != '1' ) ) { |
|
| 40 | + if ($dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year'] && ($dates['m_start'] != '12' && $dates['m_end'] != '1')) { |
|
| 41 | 41 | $day_by_day = false; |
| 42 | 42 | } else { |
| 43 | 43 | $day_by_day = true; |
@@ -49,61 +49,61 @@ discard block |
||
| 49 | 49 | endswitch; |
| 50 | 50 | |
| 51 | 51 | $earnings_totals = 0.00; // Total earnings for time period shown |
| 52 | - $sales_totals = 0; // Total sales for time period shown |
|
| 52 | + $sales_totals = 0; // Total sales for time period shown |
|
| 53 | 53 | |
| 54 | 54 | $earnings_data = array(); |
| 55 | 55 | $sales_data = array(); |
| 56 | 56 | |
| 57 | - if ( $dates['range'] == 'today' || $dates['range'] == 'yesterday' ) { |
|
| 57 | + if ($dates['range'] == 'today' || $dates['range'] == 'yesterday') { |
|
| 58 | 58 | // Hour by hour |
| 59 | 59 | $hour = 1; |
| 60 | - $month = date( 'n', current_time( 'timestamp' ) ); |
|
| 61 | - while ( $hour <= 23 ) : |
|
| 60 | + $month = date('n', current_time('timestamp')); |
|
| 61 | + while ($hour <= 23) : |
|
| 62 | 62 | |
| 63 | - $sales = give_get_sales_by_date( $dates['day'], $month, $dates['year'], $hour ); |
|
| 64 | - $earnings = give_get_earnings_by_date( $dates['day'], $month, $dates['year'], $hour ); |
|
| 63 | + $sales = give_get_sales_by_date($dates['day'], $month, $dates['year'], $hour); |
|
| 64 | + $earnings = give_get_earnings_by_date($dates['day'], $month, $dates['year'], $hour); |
|
| 65 | 65 | |
| 66 | 66 | $sales_totals += $sales; |
| 67 | 67 | $earnings_totals += $earnings; |
| 68 | 68 | |
| 69 | - $date = mktime( $hour, 0, 0, $month, $dates['day'], $dates['year'] ) * 1000; |
|
| 70 | - $sales_data[] = array( $date, $sales ); |
|
| 71 | - $earnings_data[] = array( $date, $earnings ); |
|
| 69 | + $date = mktime($hour, 0, 0, $month, $dates['day'], $dates['year']) * 1000; |
|
| 70 | + $sales_data[] = array($date, $sales); |
|
| 71 | + $earnings_data[] = array($date, $earnings); |
|
| 72 | 72 | |
| 73 | - $hour ++; |
|
| 73 | + $hour++; |
|
| 74 | 74 | endwhile; |
| 75 | 75 | |
| 76 | - } elseif ( $dates['range'] == 'this_week' || $dates['range'] == 'last_week' ) { |
|
| 76 | + } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') { |
|
| 77 | 77 | |
| 78 | 78 | // Day by day |
| 79 | 79 | $day = $dates['day']; |
| 80 | 80 | $day_end = $dates['day_end']; |
| 81 | 81 | $month = $dates['m_start']; |
| 82 | - while ( $day <= $day_end ) : |
|
| 83 | - $sales = give_get_sales_by_date( $day, $month, $dates['year'] ); |
|
| 82 | + while ($day <= $day_end) : |
|
| 83 | + $sales = give_get_sales_by_date($day, $month, $dates['year']); |
|
| 84 | 84 | $sales_totals += $sales; |
| 85 | 85 | |
| 86 | - $earnings = give_get_earnings_by_date( $day, $month, $dates['year'] ); |
|
| 86 | + $earnings = give_get_earnings_by_date($day, $month, $dates['year']); |
|
| 87 | 87 | $earnings_totals += $earnings; |
| 88 | 88 | |
| 89 | - $date = mktime( 0, 0, 0, $month, $day, $dates['year'] ) * 1000; |
|
| 90 | - $sales_data[] = array( $date, $sales ); |
|
| 91 | - $earnings_data[] = array( $date, $earnings ); |
|
| 92 | - $day ++; |
|
| 89 | + $date = mktime(0, 0, 0, $month, $day, $dates['year']) * 1000; |
|
| 90 | + $sales_data[] = array($date, $sales); |
|
| 91 | + $earnings_data[] = array($date, $earnings); |
|
| 92 | + $day++; |
|
| 93 | 93 | endwhile; |
| 94 | 94 | |
| 95 | 95 | } else { |
| 96 | 96 | |
| 97 | 97 | $y = $dates['year']; |
| 98 | - while ( $y <= $dates['year_end'] ) : |
|
| 98 | + while ($y <= $dates['year_end']) : |
|
| 99 | 99 | |
| 100 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 100 | + if ($dates['year'] == $dates['year_end']) { |
|
| 101 | 101 | $month_start = $dates['m_start']; |
| 102 | 102 | $month_end = $dates['m_end']; |
| 103 | - } elseif ( $y == $dates['year'] ) { |
|
| 103 | + } elseif ($y == $dates['year']) { |
|
| 104 | 104 | $month_start = $dates['m_start']; |
| 105 | 105 | $month_end = 12; |
| 106 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 106 | + } elseif ($y == $dates['year_end']) { |
|
| 107 | 107 | $month_start = 1; |
| 108 | 108 | $month_end = $dates['m_end']; |
| 109 | 109 | } else { |
@@ -112,48 +112,48 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $i = $month_start; |
| 115 | - while ( $i <= $month_end ) : |
|
| 115 | + while ($i <= $month_end) : |
|
| 116 | 116 | |
| 117 | - if ( $day_by_day ) : |
|
| 117 | + if ($day_by_day) : |
|
| 118 | 118 | |
| 119 | - if ( $i == $month_end ) { |
|
| 119 | + if ($i == $month_end) { |
|
| 120 | 120 | |
| 121 | 121 | $num_of_days = $dates['day_end']; |
| 122 | 122 | |
| 123 | 123 | } else { |
| 124 | 124 | |
| 125 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 125 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $d = $dates['day']; |
| 130 | 130 | |
| 131 | - while ( $d <= $num_of_days ) : |
|
| 131 | + while ($d <= $num_of_days) : |
|
| 132 | 132 | |
| 133 | - $sales = give_get_sales_by_date( $d, $i, $y ); |
|
| 133 | + $sales = give_get_sales_by_date($d, $i, $y); |
|
| 134 | 134 | $sales_totals += $sales; |
| 135 | 135 | |
| 136 | - $earnings = give_get_earnings_by_date( $d, $i, $y ); |
|
| 136 | + $earnings = give_get_earnings_by_date($d, $i, $y); |
|
| 137 | 137 | $earnings_totals += $earnings; |
| 138 | 138 | |
| 139 | - $date = mktime( 0, 0, 0, $i, $d, $y ) * 1000; |
|
| 140 | - $sales_data[] = array( $date, $sales ); |
|
| 141 | - $earnings_data[] = array( $date, $earnings ); |
|
| 142 | - $d ++; |
|
| 139 | + $date = mktime(0, 0, 0, $i, $d, $y) * 1000; |
|
| 140 | + $sales_data[] = array($date, $sales); |
|
| 141 | + $earnings_data[] = array($date, $earnings); |
|
| 142 | + $d++; |
|
| 143 | 143 | |
| 144 | 144 | endwhile; |
| 145 | 145 | |
| 146 | 146 | else : |
| 147 | 147 | |
| 148 | - $sales = give_get_sales_by_date( null, $i, $y ); |
|
| 148 | + $sales = give_get_sales_by_date(null, $i, $y); |
|
| 149 | 149 | $sales_totals += $sales; |
| 150 | 150 | |
| 151 | - $earnings = give_get_earnings_by_date( null, $i, $y ); |
|
| 151 | + $earnings = give_get_earnings_by_date(null, $i, $y); |
|
| 152 | 152 | $earnings_totals += $earnings; |
| 153 | 153 | |
| 154 | - if ( $i == $month_end ) { |
|
| 154 | + if ($i == $month_end) { |
|
| 155 | 155 | |
| 156 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 156 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 157 | 157 | |
| 158 | 158 | } else { |
| 159 | 159 | |
@@ -161,24 +161,24 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $date = mktime( 0, 0, 0, $i, $num_of_days, $y ) * 1000; |
|
| 165 | - $sales_data[] = array( $date, $sales ); |
|
| 166 | - $earnings_data[] = array( $date, $earnings ); |
|
| 164 | + $date = mktime(0, 0, 0, $i, $num_of_days, $y) * 1000; |
|
| 165 | + $sales_data[] = array($date, $sales); |
|
| 166 | + $earnings_data[] = array($date, $earnings); |
|
| 167 | 167 | |
| 168 | 168 | endif; |
| 169 | 169 | |
| 170 | - $i ++; |
|
| 170 | + $i++; |
|
| 171 | 171 | |
| 172 | 172 | endwhile; |
| 173 | 173 | |
| 174 | - $y ++; |
|
| 174 | + $y++; |
|
| 175 | 175 | endwhile; |
| 176 | 176 | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | $data = array( |
| 180 | - esc_html( 'Income', 'give' ) => $earnings_data, |
|
| 181 | - esc_html( 'Donations', 'give' ) => $sales_data |
|
| 180 | + esc_html('Income', 'give') => $earnings_data, |
|
| 181 | + esc_html('Donations', 'give') => $sales_data |
|
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | 184 | // start our own output buffer |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | <div class="postbox"> |
| 191 | 191 | <div class="inside"> |
| 192 | 192 | <?php |
| 193 | - $graph = new Give_Graph( $data ); |
|
| 194 | - $graph->set( 'x_mode', 'time' ); |
|
| 195 | - $graph->set( 'multiple_y_axes', true ); |
|
| 193 | + $graph = new Give_Graph($data); |
|
| 194 | + $graph->set('x_mode', 'time'); |
|
| 195 | + $graph->set('multiple_y_axes', true); |
|
| 196 | 196 | $graph->display(); |
| 197 | 197 | |
| 198 | - if ( 'this_month' == $dates['range'] ) { |
|
| 198 | + if ('this_month' == $dates['range']) { |
|
| 199 | 199 | $estimated = give_estimated_monthly_stats(); |
| 200 | 200 | } |
| 201 | 201 | ?> |
@@ -206,32 +206,32 @@ discard block |
||
| 206 | 206 | <tbody> |
| 207 | 207 | <tr> |
| 208 | 208 | <td class="row-title"> |
| 209 | - <label for="tablecell"><?php esc_html_e( 'Total income for period: ', 'give' ); ?></label></td> |
|
| 210 | - <td><?php echo give_currency_filter( give_format_amount( $earnings_totals ) ); ?></td> |
|
| 209 | + <label for="tablecell"><?php esc_html_e('Total income for period: ', 'give'); ?></label></td> |
|
| 210 | + <td><?php echo give_currency_filter(give_format_amount($earnings_totals)); ?></td> |
|
| 211 | 211 | </tr> |
| 212 | 212 | <tr class="alternate"> |
| 213 | 213 | <td class="row-title"> |
| 214 | - <label for="tablecell"><?php esc_html_e( 'Total donations for period shown: ', 'give' ); ?></label> |
|
| 214 | + <label for="tablecell"><?php esc_html_e('Total donations for period shown: ', 'give'); ?></label> |
|
| 215 | 215 | </td> |
| 216 | - <td><?php echo give_format_amount( $sales_totals, false ); ?></td> |
|
| 216 | + <td><?php echo give_format_amount($sales_totals, false); ?></td> |
|
| 217 | 217 | </tr> |
| 218 | - <?php if ( 'this_month' == $dates['range'] ) : ?> |
|
| 218 | + <?php if ('this_month' == $dates['range']) : ?> |
|
| 219 | 219 | <tr> |
| 220 | 220 | <td class="row-title"> |
| 221 | - <label for="tablecell"><?php esc_html_e( 'Estimated monthly income: ', 'give' ); ?></label> |
|
| 221 | + <label for="tablecell"><?php esc_html_e('Estimated monthly income: ', 'give'); ?></label> |
|
| 222 | 222 | </td> |
| 223 | - <td><?php echo give_currency_filter( give_format_amount( $estimated['earnings'] ) ); ?></td> |
|
| 223 | + <td><?php echo give_currency_filter(give_format_amount($estimated['earnings'])); ?></td> |
|
| 224 | 224 | </tr> |
| 225 | 225 | <tr class="alternate"> |
| 226 | 226 | <td class="row-title"> |
| 227 | - <label for="tablecell"><?php esc_html_e( 'Estimated monthly donations: ', 'give' ); ?></label> |
|
| 227 | + <label for="tablecell"><?php esc_html_e('Estimated monthly donations: ', 'give'); ?></label> |
|
| 228 | 228 | </td> |
| 229 | - <td><?php echo give_format_amount( $estimated['sales'], false ); ?></td> |
|
| 229 | + <td><?php echo give_format_amount($estimated['sales'], false); ?></td> |
|
| 230 | 230 | </tr> |
| 231 | 231 | <?php endif; ?> |
| 232 | 232 | </table> |
| 233 | 233 | |
| 234 | - <?php do_action( 'give_reports_graph_additional_stats' ); ?> |
|
| 234 | + <?php do_action('give_reports_graph_additional_stats'); ?> |
|
| 235 | 235 | |
| 236 | 236 | </div> |
| 237 | 237 | </div> |
@@ -249,12 +249,12 @@ discard block |
||
| 249 | 249 | * @since 1.0 |
| 250 | 250 | * @return void |
| 251 | 251 | */ |
| 252 | -function give_reports_graph_of_form( $form_id = 0 ) { |
|
| 252 | +function give_reports_graph_of_form($form_id = 0) { |
|
| 253 | 253 | // Retrieve the queried dates |
| 254 | 254 | $dates = give_get_report_dates(); |
| 255 | 255 | |
| 256 | 256 | // Determine graph options |
| 257 | - switch ( $dates['range'] ) : |
|
| 257 | + switch ($dates['range']) : |
|
| 258 | 258 | case 'today' : |
| 259 | 259 | case 'yesterday' : |
| 260 | 260 | $day_by_day = true; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $day_by_day = false; |
| 273 | 273 | break; |
| 274 | 274 | case 'other' : |
| 275 | - if ( $dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year'] ) { |
|
| 275 | + if ($dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year']) { |
|
| 276 | 276 | $day_by_day = false; |
| 277 | 277 | } else { |
| 278 | 278 | $day_by_day = true; |
@@ -284,75 +284,75 @@ discard block |
||
| 284 | 284 | endswitch; |
| 285 | 285 | |
| 286 | 286 | $earnings_totals = (float) 0.00; // Total earnings for time period shown |
| 287 | - $sales_totals = 0; // Total sales for time period shown |
|
| 287 | + $sales_totals = 0; // Total sales for time period shown |
|
| 288 | 288 | |
| 289 | 289 | $earnings_data = array(); |
| 290 | 290 | $sales_data = array(); |
| 291 | 291 | $stats = new Give_Payment_Stats; |
| 292 | 292 | |
| 293 | - if ( $dates['range'] == 'today' || $dates['range'] == 'yesterday' ) { |
|
| 293 | + if ($dates['range'] == 'today' || $dates['range'] == 'yesterday') { |
|
| 294 | 294 | |
| 295 | 295 | // Hour by hour |
| 296 | 296 | $month = $dates['m_start']; |
| 297 | 297 | $hour = 1; |
| 298 | 298 | $minute = 0; |
| 299 | 299 | $second = 0; |
| 300 | - while ( $hour <= 23 ) : |
|
| 300 | + while ($hour <= 23) : |
|
| 301 | 301 | |
| 302 | - if ( $hour == 23 ) { |
|
| 302 | + if ($hour == 23) { |
|
| 303 | 303 | $minute = $second = 59; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - $date = mktime( $hour, $minute, $second, $month, $dates['day'], $dates['year'] ); |
|
| 307 | - $date_end = mktime( $hour + 1, $minute, $second, $month, $dates['day'], $dates['year'] ); |
|
| 306 | + $date = mktime($hour, $minute, $second, $month, $dates['day'], $dates['year']); |
|
| 307 | + $date_end = mktime($hour + 1, $minute, $second, $month, $dates['day'], $dates['year']); |
|
| 308 | 308 | |
| 309 | - $sales = $stats->get_sales( $form_id, $date, $date_end ); |
|
| 309 | + $sales = $stats->get_sales($form_id, $date, $date_end); |
|
| 310 | 310 | $sales_totals += $sales; |
| 311 | 311 | |
| 312 | - $earnings = $stats->get_earnings( $form_id, $date, $date_end ); |
|
| 312 | + $earnings = $stats->get_earnings($form_id, $date, $date_end); |
|
| 313 | 313 | $earnings_totals += $earnings; |
| 314 | 314 | |
| 315 | - $sales_data[] = array( $date * 1000, $sales ); |
|
| 316 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
| 315 | + $sales_data[] = array($date * 1000, $sales); |
|
| 316 | + $earnings_data[] = array($date * 1000, $earnings); |
|
| 317 | 317 | |
| 318 | - $hour ++; |
|
| 318 | + $hour++; |
|
| 319 | 319 | endwhile; |
| 320 | 320 | |
| 321 | - } elseif ( $dates['range'] == 'this_week' || $dates['range'] == 'last_week' ) { |
|
| 321 | + } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') { |
|
| 322 | 322 | |
| 323 | 323 | //Day by day |
| 324 | 324 | $day = $dates['day']; |
| 325 | 325 | $day_end = $dates['day_end']; |
| 326 | 326 | $month = $dates['m_start']; |
| 327 | - while ( $day <= $day_end ) : |
|
| 327 | + while ($day <= $day_end) : |
|
| 328 | 328 | |
| 329 | - $date = mktime( 0, 0, 0, $month, $day, $dates['year'] ); |
|
| 330 | - $date_end = mktime( 0, 0, 0, $month, $day + 1, $dates['year'] ); |
|
| 331 | - $sales = $stats->get_sales( $form_id, $date, $date_end ); |
|
| 329 | + $date = mktime(0, 0, 0, $month, $day, $dates['year']); |
|
| 330 | + $date_end = mktime(0, 0, 0, $month, $day + 1, $dates['year']); |
|
| 331 | + $sales = $stats->get_sales($form_id, $date, $date_end); |
|
| 332 | 332 | $sales_totals += $sales; |
| 333 | 333 | |
| 334 | - $earnings = $stats->get_earnings( $form_id, $date, $date_end ); |
|
| 334 | + $earnings = $stats->get_earnings($form_id, $date, $date_end); |
|
| 335 | 335 | $earnings_totals += $earnings; |
| 336 | 336 | |
| 337 | - $sales_data[] = array( $date * 1000, $sales ); |
|
| 338 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
| 337 | + $sales_data[] = array($date * 1000, $sales); |
|
| 338 | + $earnings_data[] = array($date * 1000, $earnings); |
|
| 339 | 339 | |
| 340 | - $day ++; |
|
| 340 | + $day++; |
|
| 341 | 341 | endwhile; |
| 342 | 342 | |
| 343 | 343 | } else { |
| 344 | 344 | |
| 345 | 345 | $y = $dates['year']; |
| 346 | 346 | |
| 347 | - while ( $y <= $dates['year_end'] ) : |
|
| 347 | + while ($y <= $dates['year_end']) : |
|
| 348 | 348 | |
| 349 | 349 | $last_year = false; |
| 350 | 350 | |
| 351 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 351 | + if ($dates['year'] == $dates['year_end']) { |
|
| 352 | 352 | $month_start = $dates['m_start']; |
| 353 | 353 | $month_end = $dates['m_end']; |
| 354 | 354 | $last_year = true; |
| 355 | - } elseif ( $y == $dates['year'] ) { |
|
| 355 | + } elseif ($y == $dates['year']) { |
|
| 356 | 356 | $month_start = $dates['m_start']; |
| 357 | 357 | $month_end = 12; |
| 358 | 358 | } else { |
@@ -361,75 +361,75 @@ discard block |
||
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $i = $month_start; |
| 364 | - while ( $i <= $month_end ) : |
|
| 364 | + while ($i <= $month_end) : |
|
| 365 | 365 | |
| 366 | - if ( $day_by_day ) : |
|
| 366 | + if ($day_by_day) : |
|
| 367 | 367 | |
| 368 | - if ( $i == $month_end && $last_year ) { |
|
| 368 | + if ($i == $month_end && $last_year) { |
|
| 369 | 369 | |
| 370 | 370 | $num_of_days = $dates['day_end']; |
| 371 | 371 | |
| 372 | 372 | } else { |
| 373 | 373 | |
| 374 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 374 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 375 | 375 | |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | $d = $dates['day']; |
| 379 | - while ( $d <= $num_of_days ) : |
|
| 379 | + while ($d <= $num_of_days) : |
|
| 380 | 380 | |
| 381 | - $date = mktime( 0, 0, 0, $i, $d, $y ); |
|
| 382 | - $end_date = mktime( 23, 59, 59, $i, $d, $y ); |
|
| 381 | + $date = mktime(0, 0, 0, $i, $d, $y); |
|
| 382 | + $end_date = mktime(23, 59, 59, $i, $d, $y); |
|
| 383 | 383 | |
| 384 | - $sales = $stats->get_sales( $form_id, $date, $end_date ); |
|
| 384 | + $sales = $stats->get_sales($form_id, $date, $end_date); |
|
| 385 | 385 | $sales_totals += $sales; |
| 386 | 386 | |
| 387 | - $earnings = $stats->get_earnings( $form_id, $date, $end_date ); |
|
| 387 | + $earnings = $stats->get_earnings($form_id, $date, $end_date); |
|
| 388 | 388 | $earnings_totals += $earnings; |
| 389 | 389 | |
| 390 | - $sales_data[] = array( $date * 1000, $sales ); |
|
| 391 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
| 392 | - $d ++; |
|
| 390 | + $sales_data[] = array($date * 1000, $sales); |
|
| 391 | + $earnings_data[] = array($date * 1000, $earnings); |
|
| 392 | + $d++; |
|
| 393 | 393 | |
| 394 | 394 | endwhile; |
| 395 | 395 | |
| 396 | 396 | else : |
| 397 | 397 | |
| 398 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 398 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 399 | 399 | |
| 400 | - $date = mktime( 0, 0, 0, $i, 1, $y ); |
|
| 401 | - $end_date = mktime( 23, 59, 59, $i, $num_of_days, $y ); |
|
| 400 | + $date = mktime(0, 0, 0, $i, 1, $y); |
|
| 401 | + $end_date = mktime(23, 59, 59, $i, $num_of_days, $y); |
|
| 402 | 402 | |
| 403 | - $sales = $stats->get_sales( $form_id, $date, $end_date ); |
|
| 403 | + $sales = $stats->get_sales($form_id, $date, $end_date); |
|
| 404 | 404 | $sales_totals += $sales; |
| 405 | 405 | |
| 406 | - $earnings = $stats->get_earnings( $form_id, $date, $end_date ); |
|
| 406 | + $earnings = $stats->get_earnings($form_id, $date, $end_date); |
|
| 407 | 407 | $earnings_totals += $earnings; |
| 408 | 408 | |
| 409 | - $sales_data[] = array( $date * 1000, $sales ); |
|
| 410 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
| 409 | + $sales_data[] = array($date * 1000, $sales); |
|
| 410 | + $earnings_data[] = array($date * 1000, $earnings); |
|
| 411 | 411 | endif; |
| 412 | 412 | |
| 413 | - $i ++; |
|
| 413 | + $i++; |
|
| 414 | 414 | |
| 415 | 415 | endwhile; |
| 416 | 416 | |
| 417 | - $y ++; |
|
| 417 | + $y++; |
|
| 418 | 418 | endwhile; |
| 419 | 419 | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | $data = array( |
| 423 | - esc_html( 'Income', 'give' ) => $earnings_data, |
|
| 424 | - esc_html( 'Donations', 'give' ) => $sales_data |
|
| 423 | + esc_html('Income', 'give') => $earnings_data, |
|
| 424 | + esc_html('Donations', 'give') => $sales_data |
|
| 425 | 425 | ); |
| 426 | 426 | |
| 427 | 427 | ?> |
| 428 | 428 | <h3><span><?php |
| 429 | 429 | printf( |
| 430 | 430 | /* translators: %s: form title */ |
| 431 | - esc_html( 'Income Over Time for %s', 'give' ), |
|
| 432 | - get_the_title( $form_id ) |
|
| 431 | + esc_html('Income Over Time for %s', 'give'), |
|
| 432 | + get_the_title($form_id) |
|
| 433 | 433 | ); |
| 434 | 434 | ?></span></h3> |
| 435 | 435 | |
@@ -437,9 +437,9 @@ discard block |
||
| 437 | 437 | <div class="postbox"> |
| 438 | 438 | <div class="inside"> |
| 439 | 439 | <?php |
| 440 | - $graph = new Give_Graph( $data ); |
|
| 441 | - $graph->set( 'x_mode', 'time' ); |
|
| 442 | - $graph->set( 'multiple_y_axes', true ); |
|
| 440 | + $graph = new Give_Graph($data); |
|
| 441 | + $graph->set('x_mode', 'time'); |
|
| 442 | + $graph->set('multiple_y_axes', true); |
|
| 443 | 443 | $graph->display(); |
| 444 | 444 | ?> |
| 445 | 445 | </div> |
@@ -449,26 +449,26 @@ discard block |
||
| 449 | 449 | <tbody> |
| 450 | 450 | <tr> |
| 451 | 451 | <td class="row-title"> |
| 452 | - <label for="tablecell"><?php esc_html_e( 'Total income for period: ', 'give' ); ?></label></td> |
|
| 453 | - <td><?php echo give_currency_filter( give_format_amount( $earnings_totals ) ); ?></td> |
|
| 452 | + <label for="tablecell"><?php esc_html_e('Total income for period: ', 'give'); ?></label></td> |
|
| 453 | + <td><?php echo give_currency_filter(give_format_amount($earnings_totals)); ?></td> |
|
| 454 | 454 | </tr> |
| 455 | 455 | <tr class="alternate"> |
| 456 | 456 | <td class="row-title"> |
| 457 | - <label for="tablecell"><?php esc_html_e( 'Total donations for period: ', 'give' ); ?></label> |
|
| 457 | + <label for="tablecell"><?php esc_html_e('Total donations for period: ', 'give'); ?></label> |
|
| 458 | 458 | </td> |
| 459 | 459 | <td><?php echo $sales_totals; ?></td> |
| 460 | 460 | </tr> |
| 461 | 461 | <tr> |
| 462 | 462 | <td class="row-title"> |
| 463 | - <label for="tablecell"><?php esc_html_e( 'Average monthly income: %s', 'give' ); ?></label> |
|
| 463 | + <label for="tablecell"><?php esc_html_e('Average monthly income: %s', 'give'); ?></label> |
|
| 464 | 464 | </td> |
| 465 | - <td><?php echo give_currency_filter( give_format_amount( give_get_average_monthly_form_earnings( $form_id ) ) ); ?></td> |
|
| 465 | + <td><?php echo give_currency_filter(give_format_amount(give_get_average_monthly_form_earnings($form_id))); ?></td> |
|
| 466 | 466 | </tr> |
| 467 | 467 | <tr class="alternate"> |
| 468 | 468 | <td class="row-title"> |
| 469 | - <label for="tablecell"><?php esc_html_e( 'Average monthly donations: %s', 'give' ); ?></label> |
|
| 469 | + <label for="tablecell"><?php esc_html_e('Average monthly donations: %s', 'give'); ?></label> |
|
| 470 | 470 | </td> |
| 471 | - <td><?php echo number_format( give_get_average_monthly_form_sales( $form_id ), 0 ); ?></td> |
|
| 471 | + <td><?php echo number_format(give_get_average_monthly_form_sales($form_id), 0); ?></td> |
|
| 472 | 472 | </tr> |
| 473 | 473 | </tbody> |
| 474 | 474 | </table> |
@@ -485,29 +485,29 @@ discard block |
||
| 485 | 485 | * @return void |
| 486 | 486 | */ |
| 487 | 487 | function give_reports_graph_controls() { |
| 488 | - $date_options = apply_filters( 'give_report_date_options', array( |
|
| 489 | - 'today' => esc_html( 'Today', 'give' ), |
|
| 490 | - 'yesterday' => esc_html( 'Yesterday', 'give' ), |
|
| 491 | - 'this_week' => esc_html( 'This Week', 'give' ), |
|
| 492 | - 'last_week' => esc_html( 'Last Week', 'give' ), |
|
| 493 | - 'this_month' => esc_html( 'This Month', 'give' ), |
|
| 494 | - 'last_month' => esc_html( 'Last Month', 'give' ), |
|
| 495 | - 'this_quarter' => esc_html( 'This Quarter', 'give' ), |
|
| 496 | - 'last_quarter' => esc_html( 'Last Quarter', 'give' ), |
|
| 497 | - 'this_year' => esc_html( 'This Year', 'give' ), |
|
| 498 | - 'last_year' => esc_html( 'Last Year', 'give' ), |
|
| 499 | - 'other' => esc_html( 'Custom', 'give' ) |
|
| 500 | - ) ); |
|
| 488 | + $date_options = apply_filters('give_report_date_options', array( |
|
| 489 | + 'today' => esc_html('Today', 'give'), |
|
| 490 | + 'yesterday' => esc_html('Yesterday', 'give'), |
|
| 491 | + 'this_week' => esc_html('This Week', 'give'), |
|
| 492 | + 'last_week' => esc_html('Last Week', 'give'), |
|
| 493 | + 'this_month' => esc_html('This Month', 'give'), |
|
| 494 | + 'last_month' => esc_html('Last Month', 'give'), |
|
| 495 | + 'this_quarter' => esc_html('This Quarter', 'give'), |
|
| 496 | + 'last_quarter' => esc_html('Last Quarter', 'give'), |
|
| 497 | + 'this_year' => esc_html('This Year', 'give'), |
|
| 498 | + 'last_year' => esc_html('Last Year', 'give'), |
|
| 499 | + 'other' => esc_html('Custom', 'give') |
|
| 500 | + )); |
|
| 501 | 501 | |
| 502 | 502 | $dates = give_get_report_dates(); |
| 503 | 503 | $display = $dates['range'] == 'other' ? '' : 'style="display:none;"'; |
| 504 | 504 | $view = give_get_reporting_view(); |
| 505 | 505 | |
| 506 | - if ( empty( $dates['day_end'] ) ) { |
|
| 507 | - $dates['day_end'] = cal_days_in_month( CAL_GREGORIAN, date( 'n' ), date( 'Y' ) ); |
|
| 506 | + if (empty($dates['day_end'])) { |
|
| 507 | + $dates['day_end'] = cal_days_in_month(CAL_GREGORIAN, date('n'), date('Y')); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - do_action( 'give_report_graph_controls_before' ); |
|
| 510 | + do_action('give_report_graph_controls_before'); |
|
| 511 | 511 | ?> |
| 512 | 512 | <form id="give-graphs-filter" method="get" class="alignright"> |
| 513 | 513 | <div class="tablenav top alignright"> |
@@ -515,53 +515,53 @@ discard block |
||
| 515 | 515 | |
| 516 | 516 | <input type="hidden" name="post_type" value="give_forms" /> |
| 517 | 517 | <input type="hidden" name="page" value="give-reports" /> |
| 518 | - <input type="hidden" name="view" value="<?php esc_attr_e( $view ); ?>" /> |
|
| 518 | + <input type="hidden" name="view" value="<?php esc_attr_e($view); ?>" /> |
|
| 519 | 519 | |
| 520 | - <?php if ( isset( $_GET['form-id'] ) ) : ?> |
|
| 521 | - <input type="hidden" name="form-id" value="<?php echo absint( $_GET['form-id'] ); ?>" /> |
|
| 520 | + <?php if (isset($_GET['form-id'])) : ?> |
|
| 521 | + <input type="hidden" name="form-id" value="<?php echo absint($_GET['form-id']); ?>" /> |
|
| 522 | 522 | <?php endif; ?> |
| 523 | 523 | |
| 524 | 524 | <div id="give-graphs-date-options-wrap" class="alignright"> |
| 525 | 525 | <select id="give-graphs-date-options" name="range"> |
| 526 | - <?php foreach ( $date_options as $key => $option ) : ?> |
|
| 527 | - <option value="<?php esc_attr_e( $key ); ?>"<?php selected( $key, $dates['range'] ); ?>><?php esc_html_e( $option ); ?></option> |
|
| 526 | + <?php foreach ($date_options as $key => $option) : ?> |
|
| 527 | + <option value="<?php esc_attr_e($key); ?>"<?php selected($key, $dates['range']); ?>><?php esc_html_e($option); ?></option> |
|
| 528 | 528 | <?php endforeach; ?> |
| 529 | 529 | </select> |
| 530 | 530 | |
| 531 | - <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Filter', 'give' ); ?>" /> |
|
| 531 | + <input type="submit" class="button-secondary" value="<?php esc_attr_e('Filter', 'give'); ?>" /> |
|
| 532 | 532 | </div> |
| 533 | 533 | |
| 534 | 534 | <div id="give-date-range-options" <?php echo $display; ?>> |
| 535 | - <span><?php esc_html_e( 'From', 'give' ); ?> </span> |
|
| 535 | + <span><?php esc_html_e('From', 'give'); ?> </span> |
|
| 536 | 536 | <select id="give-graphs-month-start" name="m_start"> |
| 537 | - <?php for ( $i = 1; $i <= 12; $i ++ ) : ?> |
|
| 538 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['m_start'] ); ?>><?php echo give_month_num_to_name( $i ); ?></option> |
|
| 537 | + <?php for ($i = 1; $i <= 12; $i++) : ?> |
|
| 538 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['m_start']); ?>><?php echo give_month_num_to_name($i); ?></option> |
|
| 539 | 539 | <?php endfor; ?> |
| 540 | 540 | </select> |
| 541 | 541 | <select id="give-graphs-day-start" name="day"> |
| 542 | - <?php for ( $i = 1; $i <= 31; $i ++ ) : ?> |
|
| 543 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['day'] ); ?>><?php echo $i; ?></option> |
|
| 542 | + <?php for ($i = 1; $i <= 31; $i++) : ?> |
|
| 543 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['day']); ?>><?php echo $i; ?></option> |
|
| 544 | 544 | <?php endfor; ?> |
| 545 | 545 | </select> |
| 546 | 546 | <select id="give-graphs-year-start" name="year"> |
| 547 | - <?php for ( $i = 2007; $i <= date( 'Y' ); $i ++ ) : ?> |
|
| 548 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['year'] ); ?>><?php echo $i; ?></option> |
|
| 547 | + <?php for ($i = 2007; $i <= date('Y'); $i++) : ?> |
|
| 548 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['year']); ?>><?php echo $i; ?></option> |
|
| 549 | 549 | <?php endfor; ?> |
| 550 | 550 | </select> |
| 551 | - <span><?php esc_html_e( 'To', 'give' ); ?> </span> |
|
| 551 | + <span><?php esc_html_e('To', 'give'); ?> </span> |
|
| 552 | 552 | <select id="give-graphs-month-end" name="m_end"> |
| 553 | - <?php for ( $i = 1; $i <= 12; $i ++ ) : ?> |
|
| 554 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['m_end'] ); ?>><?php echo give_month_num_to_name( $i ); ?></option> |
|
| 553 | + <?php for ($i = 1; $i <= 12; $i++) : ?> |
|
| 554 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['m_end']); ?>><?php echo give_month_num_to_name($i); ?></option> |
|
| 555 | 555 | <?php endfor; ?> |
| 556 | 556 | </select> |
| 557 | 557 | <select id="give-graphs-day-end" name="day_end"> |
| 558 | - <?php for ( $i = 1; $i <= 31; $i ++ ) : ?> |
|
| 559 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['day_end'] ); ?>><?php echo $i; ?></option> |
|
| 558 | + <?php for ($i = 1; $i <= 31; $i++) : ?> |
|
| 559 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['day_end']); ?>><?php echo $i; ?></option> |
|
| 560 | 560 | <?php endfor; ?> |
| 561 | 561 | </select> |
| 562 | 562 | <select id="give-graphs-year-end" name="year_end"> |
| 563 | - <?php for ( $i = 2007; $i <= date( 'Y' ); $i ++ ) : ?> |
|
| 564 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['year_end'] ); ?>><?php echo $i; ?></option> |
|
| 563 | + <?php for ($i = 2007; $i <= date('Y'); $i++) : ?> |
|
| 564 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['year_end']); ?>><?php echo $i; ?></option> |
|
| 565 | 565 | <?php endfor; ?> |
| 566 | 566 | </select> |
| 567 | 567 | </div> |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | </div> |
| 572 | 572 | </form> |
| 573 | 573 | <?php |
| 574 | - do_action( 'give_report_graph_controls_after' ); |
|
| 574 | + do_action('give_report_graph_controls_after'); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -586,65 +586,65 @@ discard block |
||
| 586 | 586 | function give_get_report_dates() { |
| 587 | 587 | $dates = array(); |
| 588 | 588 | |
| 589 | - $current_time = current_time( 'timestamp' ); |
|
| 589 | + $current_time = current_time('timestamp'); |
|
| 590 | 590 | |
| 591 | - $dates['range'] = isset( $_GET['range'] ) ? $_GET['range'] : 'this_month'; |
|
| 592 | - $dates['year'] = isset( $_GET['year'] ) ? $_GET['year'] : date( 'Y' ); |
|
| 593 | - $dates['year_end'] = isset( $_GET['year_end'] ) ? $_GET['year_end'] : date( 'Y' ); |
|
| 594 | - $dates['m_start'] = isset( $_GET['m_start'] ) ? $_GET['m_start'] : 1; |
|
| 595 | - $dates['m_end'] = isset( $_GET['m_end'] ) ? $_GET['m_end'] : 12; |
|
| 596 | - $dates['day'] = isset( $_GET['day'] ) ? $_GET['day'] : 1; |
|
| 597 | - $dates['day_end'] = isset( $_GET['day_end'] ) ? $_GET['day_end'] : cal_days_in_month( CAL_GREGORIAN, $dates['m_end'], $dates['year'] ); |
|
| 591 | + $dates['range'] = isset($_GET['range']) ? $_GET['range'] : 'this_month'; |
|
| 592 | + $dates['year'] = isset($_GET['year']) ? $_GET['year'] : date('Y'); |
|
| 593 | + $dates['year_end'] = isset($_GET['year_end']) ? $_GET['year_end'] : date('Y'); |
|
| 594 | + $dates['m_start'] = isset($_GET['m_start']) ? $_GET['m_start'] : 1; |
|
| 595 | + $dates['m_end'] = isset($_GET['m_end']) ? $_GET['m_end'] : 12; |
|
| 596 | + $dates['day'] = isset($_GET['day']) ? $_GET['day'] : 1; |
|
| 597 | + $dates['day_end'] = isset($_GET['day_end']) ? $_GET['day_end'] : cal_days_in_month(CAL_GREGORIAN, $dates['m_end'], $dates['year']); |
|
| 598 | 598 | |
| 599 | 599 | // Modify dates based on predefined ranges |
| 600 | - switch ( $dates['range'] ) : |
|
| 600 | + switch ($dates['range']) : |
|
| 601 | 601 | |
| 602 | 602 | case 'this_month' : |
| 603 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 604 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 603 | + $dates['m_start'] = date('n', $current_time); |
|
| 604 | + $dates['m_end'] = date('n', $current_time); |
|
| 605 | 605 | $dates['day'] = 1; |
| 606 | - $dates['day_end'] = cal_days_in_month( CAL_GREGORIAN, $dates['m_end'], $dates['year'] ); |
|
| 607 | - $dates['year'] = date( 'Y' ); |
|
| 608 | - $dates['year_end'] = date( 'Y' ); |
|
| 606 | + $dates['day_end'] = cal_days_in_month(CAL_GREGORIAN, $dates['m_end'], $dates['year']); |
|
| 607 | + $dates['year'] = date('Y'); |
|
| 608 | + $dates['year_end'] = date('Y'); |
|
| 609 | 609 | break; |
| 610 | 610 | |
| 611 | 611 | case 'last_month' : |
| 612 | - if ( date( 'n' ) == 1 ) { |
|
| 612 | + if (date('n') == 1) { |
|
| 613 | 613 | $dates['m_start'] = 12; |
| 614 | 614 | $dates['m_end'] = 12; |
| 615 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
| 616 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; |
|
| 615 | + $dates['year'] = date('Y', $current_time) - 1; |
|
| 616 | + $dates['year_end'] = date('Y', $current_time) - 1; |
|
| 617 | 617 | } else { |
| 618 | - $dates['m_start'] = date( 'n' ) - 1; |
|
| 619 | - $dates['m_end'] = date( 'n' ) - 1; |
|
| 618 | + $dates['m_start'] = date('n') - 1; |
|
| 619 | + $dates['m_end'] = date('n') - 1; |
|
| 620 | 620 | $dates['year_end'] = $dates['year']; |
| 621 | 621 | } |
| 622 | - $dates['day_end'] = cal_days_in_month( CAL_GREGORIAN, $dates['m_end'], $dates['year'] ); |
|
| 622 | + $dates['day_end'] = cal_days_in_month(CAL_GREGORIAN, $dates['m_end'], $dates['year']); |
|
| 623 | 623 | break; |
| 624 | 624 | |
| 625 | 625 | case 'today' : |
| 626 | - $dates['day'] = date( 'd', $current_time ); |
|
| 627 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 628 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 629 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 626 | + $dates['day'] = date('d', $current_time); |
|
| 627 | + $dates['m_start'] = date('n', $current_time); |
|
| 628 | + $dates['m_end'] = date('n', $current_time); |
|
| 629 | + $dates['year'] = date('Y', $current_time); |
|
| 630 | 630 | break; |
| 631 | 631 | |
| 632 | 632 | case 'yesterday' : |
| 633 | 633 | |
| 634 | - $year = date( 'Y', $current_time ); |
|
| 635 | - $month = date( 'n', $current_time ); |
|
| 636 | - $day = date( 'd', $current_time ); |
|
| 634 | + $year = date('Y', $current_time); |
|
| 635 | + $month = date('n', $current_time); |
|
| 636 | + $day = date('d', $current_time); |
|
| 637 | 637 | |
| 638 | - if ( $month == 1 && $day == 1 ) { |
|
| 638 | + if ($month == 1 && $day == 1) { |
|
| 639 | 639 | |
| 640 | 640 | $year -= 1; |
| 641 | 641 | $month = 12; |
| 642 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 642 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 643 | 643 | |
| 644 | - } elseif ( $month > 1 && $day == 1 ) { |
|
| 644 | + } elseif ($month > 1 && $day == 1) { |
|
| 645 | 645 | |
| 646 | 646 | $month -= 1; |
| 647 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 647 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 648 | 648 | |
| 649 | 649 | } else { |
| 650 | 650 | |
@@ -660,91 +660,91 @@ discard block |
||
| 660 | 660 | break; |
| 661 | 661 | |
| 662 | 662 | case 'this_week' : |
| 663 | - $dates['day'] = date( 'd', $current_time - ( date( 'w', $current_time ) - 1 ) * 60 * 60 * 24 ) - 1; |
|
| 664 | - $dates['day'] += get_option( 'start_of_week' ); |
|
| 663 | + $dates['day'] = date('d', $current_time - (date('w', $current_time) - 1) * 60 * 60 * 24) - 1; |
|
| 664 | + $dates['day'] += get_option('start_of_week'); |
|
| 665 | 665 | $dates['day_end'] = $dates['day'] + 6; |
| 666 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 667 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 668 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 666 | + $dates['m_start'] = date('n', $current_time); |
|
| 667 | + $dates['m_end'] = date('n', $current_time); |
|
| 668 | + $dates['year'] = date('Y', $current_time); |
|
| 669 | 669 | break; |
| 670 | 670 | |
| 671 | 671 | case 'last_week' : |
| 672 | - $dates['day'] = date( 'd', $current_time - ( date( 'w' ) - 1 ) * 60 * 60 * 24 ) - 8; |
|
| 673 | - $dates['day'] += get_option( 'start_of_week' ); |
|
| 672 | + $dates['day'] = date('d', $current_time - (date('w') - 1) * 60 * 60 * 24) - 8; |
|
| 673 | + $dates['day'] += get_option('start_of_week'); |
|
| 674 | 674 | $dates['day_end'] = $dates['day'] + 6; |
| 675 | - $dates['year'] = date( 'Y' ); |
|
| 676 | - |
|
| 677 | - if ( date( 'j', $current_time ) <= 7 ) { |
|
| 678 | - $dates['m_start'] = date( 'n', $current_time ) - 1; |
|
| 679 | - $dates['m_end'] = date( 'n', $current_time ) - 1; |
|
| 680 | - if ( $dates['m_start'] <= 1 ) { |
|
| 681 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
| 682 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; |
|
| 675 | + $dates['year'] = date('Y'); |
|
| 676 | + |
|
| 677 | + if (date('j', $current_time) <= 7) { |
|
| 678 | + $dates['m_start'] = date('n', $current_time) - 1; |
|
| 679 | + $dates['m_end'] = date('n', $current_time) - 1; |
|
| 680 | + if ($dates['m_start'] <= 1) { |
|
| 681 | + $dates['year'] = date('Y', $current_time) - 1; |
|
| 682 | + $dates['year_end'] = date('Y', $current_time) - 1; |
|
| 683 | 683 | } |
| 684 | 684 | } else { |
| 685 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 686 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 685 | + $dates['m_start'] = date('n', $current_time); |
|
| 686 | + $dates['m_end'] = date('n', $current_time); |
|
| 687 | 687 | } |
| 688 | 688 | break; |
| 689 | 689 | |
| 690 | 690 | case 'this_quarter' : |
| 691 | - $month_now = date( 'n', $current_time ); |
|
| 691 | + $month_now = date('n', $current_time); |
|
| 692 | 692 | |
| 693 | - if ( $month_now <= 3 ) { |
|
| 693 | + if ($month_now <= 3) { |
|
| 694 | 694 | |
| 695 | 695 | $dates['m_start'] = 1; |
| 696 | 696 | $dates['m_end'] = 4; |
| 697 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 697 | + $dates['year'] = date('Y', $current_time); |
|
| 698 | 698 | |
| 699 | - } else if ( $month_now <= 6 ) { |
|
| 699 | + } else if ($month_now <= 6) { |
|
| 700 | 700 | |
| 701 | 701 | $dates['m_start'] = 4; |
| 702 | 702 | $dates['m_end'] = 7; |
| 703 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 703 | + $dates['year'] = date('Y', $current_time); |
|
| 704 | 704 | |
| 705 | - } else if ( $month_now <= 9 ) { |
|
| 705 | + } else if ($month_now <= 9) { |
|
| 706 | 706 | |
| 707 | 707 | $dates['m_start'] = 7; |
| 708 | 708 | $dates['m_end'] = 10; |
| 709 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 709 | + $dates['year'] = date('Y', $current_time); |
|
| 710 | 710 | |
| 711 | 711 | } else { |
| 712 | 712 | |
| 713 | 713 | $dates['m_start'] = 10; |
| 714 | 714 | $dates['m_end'] = 1; |
| 715 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 716 | - $dates['year_end'] = date( 'Y', $current_time ) + 1; |
|
| 715 | + $dates['year'] = date('Y', $current_time); |
|
| 716 | + $dates['year_end'] = date('Y', $current_time) + 1; |
|
| 717 | 717 | |
| 718 | 718 | } |
| 719 | 719 | break; |
| 720 | 720 | |
| 721 | 721 | case 'last_quarter' : |
| 722 | - $month_now = date( 'n' ); |
|
| 722 | + $month_now = date('n'); |
|
| 723 | 723 | |
| 724 | - if ( $month_now <= 3 ) { |
|
| 724 | + if ($month_now <= 3) { |
|
| 725 | 725 | |
| 726 | 726 | $dates['m_start'] = 10; |
| 727 | 727 | $dates['m_end'] = 12; |
| 728 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
| 729 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; // Previous year |
|
| 728 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
| 729 | + $dates['year_end'] = date('Y', $current_time) - 1; // Previous year |
|
| 730 | 730 | |
| 731 | - } else if ( $month_now <= 6 ) { |
|
| 731 | + } else if ($month_now <= 6) { |
|
| 732 | 732 | |
| 733 | 733 | $dates['m_start'] = 1; |
| 734 | 734 | $dates['m_end'] = 3; |
| 735 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 735 | + $dates['year'] = date('Y', $current_time); |
|
| 736 | 736 | |
| 737 | - } else if ( $month_now <= 9 ) { |
|
| 737 | + } else if ($month_now <= 9) { |
|
| 738 | 738 | |
| 739 | 739 | $dates['m_start'] = 4; |
| 740 | 740 | $dates['m_end'] = 6; |
| 741 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 741 | + $dates['year'] = date('Y', $current_time); |
|
| 742 | 742 | |
| 743 | 743 | } else { |
| 744 | 744 | |
| 745 | 745 | $dates['m_start'] = 7; |
| 746 | 746 | $dates['m_end'] = 9; |
| 747 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 747 | + $dates['year'] = date('Y', $current_time); |
|
| 748 | 748 | |
| 749 | 749 | } |
| 750 | 750 | break; |
@@ -752,19 +752,19 @@ discard block |
||
| 752 | 752 | case 'this_year' : |
| 753 | 753 | $dates['m_start'] = 1; |
| 754 | 754 | $dates['m_end'] = 12; |
| 755 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 755 | + $dates['year'] = date('Y', $current_time); |
|
| 756 | 756 | break; |
| 757 | 757 | |
| 758 | 758 | case 'last_year' : |
| 759 | 759 | $dates['m_start'] = 1; |
| 760 | 760 | $dates['m_end'] = 12; |
| 761 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
| 762 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; |
|
| 761 | + $dates['year'] = date('Y', $current_time) - 1; |
|
| 762 | + $dates['year_end'] = date('Y', $current_time) - 1; |
|
| 763 | 763 | break; |
| 764 | 764 | |
| 765 | 765 | endswitch; |
| 766 | 766 | |
| 767 | - return apply_filters( 'give_report_dates', $dates ); |
|
| 767 | + return apply_filters('give_report_dates', $dates); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -774,17 +774,17 @@ discard block |
||
| 774 | 774 | * |
| 775 | 775 | * @param $data |
| 776 | 776 | */ |
| 777 | -function give_parse_report_dates( $data ) { |
|
| 777 | +function give_parse_report_dates($data) { |
|
| 778 | 778 | $dates = give_get_report_dates(); |
| 779 | 779 | |
| 780 | 780 | $view = give_get_reporting_view(); |
| 781 | - $id = isset( $_GET['form-id'] ) ? $_GET['form-id'] : null; |
|
| 781 | + $id = isset($_GET['form-id']) ? $_GET['form-id'] : null; |
|
| 782 | 782 | |
| 783 | - wp_redirect( add_query_arg( $dates, admin_url( 'edit.php?post_type=give_forms&page=give-reports&view=' . esc_attr( $view ) . '&form-id=' . absint( $id ) ) ) ); |
|
| 783 | + wp_redirect(add_query_arg($dates, admin_url('edit.php?post_type=give_forms&page=give-reports&view='.esc_attr($view).'&form-id='.absint($id)))); |
|
| 784 | 784 | give_die(); |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | -add_action( 'give_filter_reports', 'give_parse_report_dates' ); |
|
| 787 | +add_action('give_filter_reports', 'give_parse_report_dates'); |
|
| 788 | 788 | |
| 789 | 789 | |
| 790 | 790 | /** |
@@ -794,16 +794,16 @@ discard block |
||
| 794 | 794 | */ |
| 795 | 795 | function give_reports_refresh_button() { |
| 796 | 796 | |
| 797 | - $url = wp_nonce_url( add_query_arg( array( |
|
| 797 | + $url = wp_nonce_url(add_query_arg(array( |
|
| 798 | 798 | 'give_action' => 'refresh_reports_transients', |
| 799 | 799 | 'give-message' => 'refreshed-reports' |
| 800 | - ) ), 'give-refresh-reports' ); |
|
| 800 | + )), 'give-refresh-reports'); |
|
| 801 | 801 | |
| 802 | - echo '<a href="' . $url . '" data-tooltip="' . esc_attr( 'Clicking this will clear the reports cache.', 'give' ) . '" data-tooltip-my-position="right center" data-tooltip-target-position="left center" class="button alignright give-refresh-reports-button give-tooltip">' . esc_html( 'Refresh Reports', 'give' ) . '</a>'; |
|
| 802 | + echo '<a href="'.$url.'" data-tooltip="'.esc_attr('Clicking this will clear the reports cache.', 'give').'" data-tooltip-my-position="right center" data-tooltip-target-position="left center" class="button alignright give-refresh-reports-button give-tooltip">'.esc_html('Refresh Reports', 'give').'</a>'; |
|
| 803 | 803 | |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | -add_action( 'give_reports_graph_additional_stats', 'give_reports_refresh_button' ); |
|
| 806 | +add_action('give_reports_graph_additional_stats', 'give_reports_refresh_button'); |
|
| 807 | 807 | |
| 808 | 808 | /** |
| 809 | 809 | * Trigger the refresh of reports transients |
@@ -814,18 +814,18 @@ discard block |
||
| 814 | 814 | * |
| 815 | 815 | * @return void |
| 816 | 816 | */ |
| 817 | -function give_run_refresh_reports_transients( $data ) { |
|
| 817 | +function give_run_refresh_reports_transients($data) { |
|
| 818 | 818 | |
| 819 | - if ( ! wp_verify_nonce( $data['_wpnonce'], 'give-refresh-reports' ) ) { |
|
| 819 | + if ( ! wp_verify_nonce($data['_wpnonce'], 'give-refresh-reports')) { |
|
| 820 | 820 | return; |
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | //Delete transients |
| 824 | - delete_transient( 'give_estimated_monthly_stats' ); |
|
| 825 | - delete_transient( 'give_earnings_total' ); |
|
| 826 | - delete_transient( md5( 'give_earnings_this_monththis_month' ) ); |
|
| 827 | - delete_transient( md5( 'give_earnings_todaytoday' ) ); |
|
| 824 | + delete_transient('give_estimated_monthly_stats'); |
|
| 825 | + delete_transient('give_earnings_total'); |
|
| 826 | + delete_transient(md5('give_earnings_this_monththis_month')); |
|
| 827 | + delete_transient(md5('give_earnings_todaytoday')); |
|
| 828 | 828 | |
| 829 | 829 | } |
| 830 | 830 | |
| 831 | -add_action( 'give_refresh_reports_transients', 'give_run_refresh_reports_transients' ); |
|
| 832 | 831 | \ No newline at end of file |
| 832 | +add_action('give_refresh_reports_transients', 'give_run_refresh_reports_transients'); |
|
| 833 | 833 | \ No newline at end of file |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @access public |
| 213 | 213 | * @since 1.1 |
| 214 | - * @return array |
|
| 214 | + * @return string |
|
| 215 | 215 | */ |
| 216 | 216 | public function get_versions() { |
| 217 | 217 | return $this->versions; |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | * |
| 663 | 663 | * @param array $args Arguments to override defaults |
| 664 | 664 | * |
| 665 | - * @return array $dates |
|
| 665 | + * @return integer|null $dates |
|
| 666 | 666 | */ |
| 667 | 667 | public function get_dates( $args = array() ) { |
| 668 | 668 | $dates = array(); |
@@ -1712,7 +1712,7 @@ discard block |
||
| 1712 | 1712 | * |
| 1713 | 1713 | * @param int $user_id User ID of user to revoke key for |
| 1714 | 1714 | * |
| 1715 | - * @return string |
|
| 1715 | + * @return boolean |
|
| 1716 | 1716 | */ |
| 1717 | 1717 | public function revoke_api_key( $user_id = 0 ) { |
| 1718 | 1718 | |
@@ -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 | |
@@ -139,27 +139,27 @@ discard block |
||
| 139 | 139 | 'v1' => 'GIVE_API_V1', |
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | - foreach ( $this->get_versions() as $version => $class ) { |
|
| 143 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
| 142 | + foreach ($this->get_versions() as $version => $class) { |
|
| 143 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
| 147 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
| 148 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
| 149 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
| 150 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
| 151 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
| 152 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
| 153 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
| 146 | + add_action('init', array($this, 'add_endpoint')); |
|
| 147 | + add_action('wp', array($this, 'process_query'), - 1); |
|
| 148 | + add_filter('query_vars', array($this, 'query_vars')); |
|
| 149 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
| 150 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
| 151 | + add_action('personal_options_update', array($this, 'update_key')); |
|
| 152 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
| 153 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
| 154 | 154 | |
| 155 | 155 | // Setup a backwards compatibility check for user API Keys |
| 156 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
| 156 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
| 157 | 157 | |
| 158 | 158 | // Determine if JSON_PRETTY_PRINT is available |
| 159 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
| 159 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
| 160 | 160 | |
| 161 | 161 | // Allow API request logging to be turned off |
| 162 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
| 162 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
| 163 | 163 | |
| 164 | 164 | // Setup Give_Payment_Stats instance |
| 165 | 165 | $this->stats = new Give_Payment_Stats; |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @since 1.1 |
| 177 | 177 | */ |
| 178 | - public function add_endpoint( $rewrite_rules ) { |
|
| 179 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
| 178 | + public function add_endpoint($rewrite_rules) { |
|
| 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 | |
@@ -309,32 +309,32 @@ discard block |
||
| 309 | 309 | $this->override = false; |
| 310 | 310 | |
| 311 | 311 | // Make sure we have both user and api key |
| 312 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
| 312 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
| 313 | 313 | |
| 314 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
| 314 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
| 315 | 315 | $this->missing_auth(); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Retrieve the user by public API key and ensure they exist |
| 319 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
| 319 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
| 320 | 320 | |
| 321 | 321 | $this->invalid_key(); |
| 322 | 322 | |
| 323 | 323 | } else { |
| 324 | 324 | |
| 325 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
| 326 | - $secret = $this->get_user_secret_key( $user ); |
|
| 327 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
| 325 | + $token = urldecode($wp_query->query_vars['token']); |
|
| 326 | + $secret = $this->get_user_secret_key($user); |
|
| 327 | + $public = urldecode($wp_query->query_vars['key']); |
|
| 328 | 328 | |
| 329 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
| 329 | + if (hash_equals(md5($secret.$public), $token)) { |
|
| 330 | 330 | $this->is_valid_request = true; |
| 331 | 331 | } else { |
| 332 | 332 | $this->invalid_auth(); |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
| 335 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
| 336 | 336 | $this->is_valid_request = true; |
| 337 | - $wp_query->set( 'key', 'public' ); |
|
| 337 | + $wp_query->set('key', 'public'); |
|
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
@@ -350,25 +350,25 @@ discard block |
||
| 350 | 350 | * |
| 351 | 351 | * @return bool if user ID is found, false otherwise |
| 352 | 352 | */ |
| 353 | - public function get_user( $key = '' ) { |
|
| 353 | + public function get_user($key = '') { |
|
| 354 | 354 | global $wpdb, $wp_query; |
| 355 | 355 | |
| 356 | - if ( empty( $key ) ) { |
|
| 357 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
| 356 | + if (empty($key)) { |
|
| 357 | + $key = urldecode($wp_query->query_vars['key']); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( empty( $key ) ) { |
|
| 360 | + if (empty($key)) { |
|
| 361 | 361 | return false; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - $user = get_transient( md5( 'give_api_user_' . $key ) ); |
|
| 364 | + $user = get_transient(md5('give_api_user_'.$key)); |
|
| 365 | 365 | |
| 366 | - if ( false === $user ) { |
|
| 367 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
| 368 | - set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS ); |
|
| 366 | + if (false === $user) { |
|
| 367 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
| 368 | + set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - if ( $user != null ) { |
|
| 371 | + if ($user != null) { |
|
| 372 | 372 | $this->user_id = $user; |
| 373 | 373 | |
| 374 | 374 | return $user; |
@@ -377,37 +377,37 @@ discard block |
||
| 377 | 377 | return false; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - public function get_user_public_key( $user_id = 0 ) { |
|
| 380 | + public function get_user_public_key($user_id = 0) { |
|
| 381 | 381 | global $wpdb; |
| 382 | 382 | |
| 383 | - if ( empty( $user_id ) ) { |
|
| 383 | + if (empty($user_id)) { |
|
| 384 | 384 | return ''; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
| 388 | - $user_public_key = get_transient( $cache_key ); |
|
| 387 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
| 388 | + $user_public_key = get_transient($cache_key); |
|
| 389 | 389 | |
| 390 | - if ( empty( $user_public_key ) ) { |
|
| 391 | - $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 ) ); |
|
| 392 | - set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); |
|
| 390 | + if (empty($user_public_key)) { |
|
| 391 | + $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)); |
|
| 392 | + set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | return $user_public_key; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - public function get_user_secret_key( $user_id = 0 ) { |
|
| 398 | + public function get_user_secret_key($user_id = 0) { |
|
| 399 | 399 | global $wpdb; |
| 400 | 400 | |
| 401 | - if ( empty( $user_id ) ) { |
|
| 401 | + if (empty($user_id)) { |
|
| 402 | 402 | return ''; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
| 406 | - $user_secret_key = get_transient( $cache_key ); |
|
| 405 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
| 406 | + $user_secret_key = get_transient($cache_key); |
|
| 407 | 407 | |
| 408 | - if ( empty( $user_secret_key ) ) { |
|
| 409 | - $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 ) ); |
|
| 410 | - set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); |
|
| 408 | + if (empty($user_secret_key)) { |
|
| 409 | + $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)); |
|
| 410 | + set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | return $user_secret_key; |
@@ -423,10 +423,10 @@ discard block |
||
| 423 | 423 | */ |
| 424 | 424 | private function missing_auth() { |
| 425 | 425 | $error = array(); |
| 426 | - $error['error'] = esc_html( 'You must specify both a token and API key!', 'give' ); |
|
| 426 | + $error['error'] = esc_html('You must specify both a token and API key!', 'give'); |
|
| 427 | 427 | |
| 428 | 428 | $this->data = $error; |
| 429 | - $this->output( 401 ); |
|
| 429 | + $this->output(401); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -440,10 +440,10 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | private function invalid_auth() { |
| 442 | 442 | $error = array(); |
| 443 | - $error['error'] = esc_html( 'Your request could not be authenticated!', 'give' ); |
|
| 443 | + $error['error'] = esc_html('Your request could not be authenticated!', 'give'); |
|
| 444 | 444 | |
| 445 | 445 | $this->data = $error; |
| 446 | - $this->output( 403 ); |
|
| 446 | + $this->output(403); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -457,10 +457,10 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | private function invalid_key() { |
| 459 | 459 | $error = array(); |
| 460 | - $error['error'] = esc_html( 'Invalid API key!', 'give' ); |
|
| 460 | + $error['error'] = esc_html('Invalid API key!', 'give'); |
|
| 461 | 461 | |
| 462 | 462 | $this->data = $error; |
| 463 | - $this->output( 403 ); |
|
| 463 | + $this->output(403); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | private function invalid_version() { |
| 475 | 475 | $error = array(); |
| 476 | - $error['error'] = esc_html( 'Invalid API version!', 'give' ); |
|
| 476 | + $error['error'] = esc_html('Invalid API version!', 'give'); |
|
| 477 | 477 | |
| 478 | 478 | $this->data = $error; |
| 479 | - $this->output( 404 ); |
|
| 479 | + $this->output(404); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -492,10 +492,10 @@ discard block |
||
| 492 | 492 | global $wp_query; |
| 493 | 493 | |
| 494 | 494 | // Start logging how long the request takes for logging |
| 495 | - $before = microtime( true ); |
|
| 495 | + $before = microtime(true); |
|
| 496 | 496 | |
| 497 | 497 | // Check for give-api var. Get out if not present |
| 498 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
| 498 | + if (empty($wp_query->query_vars['give-api'])) { |
|
| 499 | 499 | return; |
| 500 | 500 | } |
| 501 | 501 | |
@@ -509,45 +509,45 @@ discard block |
||
| 509 | 509 | $this->validate_request(); |
| 510 | 510 | |
| 511 | 511 | // Only proceed if no errors have been noted |
| 512 | - if ( ! $this->is_valid_request ) { |
|
| 512 | + if ( ! $this->is_valid_request) { |
|
| 513 | 513 | return; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
| 517 | - define( 'GIVE_DOING_API', true ); |
|
| 516 | + if ( ! defined('GIVE_DOING_API')) { |
|
| 517 | + define('GIVE_DOING_API', true); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | $data = array(); |
| 521 | 521 | $this->routes = new $this->versions[$this->get_queried_version()]; |
| 522 | 522 | $this->routes->validate_request(); |
| 523 | 523 | |
| 524 | - switch ( $this->endpoint ) : |
|
| 524 | + switch ($this->endpoint) : |
|
| 525 | 525 | |
| 526 | 526 | case 'stats' : |
| 527 | 527 | |
| 528 | - $data = $this->routes->get_stats( array( |
|
| 529 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 530 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 531 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 532 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 533 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null |
|
| 534 | - ) ); |
|
| 528 | + $data = $this->routes->get_stats(array( |
|
| 529 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 530 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 531 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 532 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 533 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null |
|
| 534 | + )); |
|
| 535 | 535 | |
| 536 | 536 | break; |
| 537 | 537 | |
| 538 | 538 | case 'forms' : |
| 539 | 539 | |
| 540 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
| 540 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
| 541 | 541 | |
| 542 | - $data = $this->routes->get_forms( $form ); |
|
| 542 | + $data = $this->routes->get_forms($form); |
|
| 543 | 543 | |
| 544 | 544 | break; |
| 545 | 545 | |
| 546 | 546 | case 'donors' : |
| 547 | 547 | |
| 548 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
| 548 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
| 549 | 549 | |
| 550 | - $data = $this->routes->get_customers( $customer ); |
|
| 550 | + $data = $this->routes->get_customers($customer); |
|
| 551 | 551 | |
| 552 | 552 | break; |
| 553 | 553 | |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | endswitch; |
| 561 | 561 | |
| 562 | 562 | // Allow extensions to setup their own return data |
| 563 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
| 563 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
| 564 | 564 | |
| 565 | - $after = microtime( true ); |
|
| 566 | - $request_time = ( $after - $before ); |
|
| 565 | + $after = microtime(true); |
|
| 566 | + $request_time = ($after - $before); |
|
| 567 | 567 | $this->data['request_speed'] = $request_time; |
| 568 | 568 | |
| 569 | 569 | // Log this API request, if enabled. We log it here because we have access to errors. |
| 570 | - $this->log_request( $this->data ); |
|
| 570 | + $this->log_request($this->data); |
|
| 571 | 571 | |
| 572 | 572 | // Send out data to the output function |
| 573 | 573 | $this->output(); |
@@ -597,25 +597,25 @@ discard block |
||
| 597 | 597 | global $wp_query; |
| 598 | 598 | |
| 599 | 599 | // Whitelist our query options |
| 600 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
| 600 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
| 601 | 601 | 'stats', |
| 602 | 602 | 'forms', |
| 603 | 603 | 'donors', |
| 604 | 604 | 'donations' |
| 605 | - ) ); |
|
| 605 | + )); |
|
| 606 | 606 | |
| 607 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
| 608 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
| 607 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
| 608 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
| 609 | 609 | |
| 610 | 610 | $error = array(); |
| 611 | 611 | |
| 612 | 612 | // Make sure our query is valid |
| 613 | - if ( ! in_array( $query, $accepted ) ) { |
|
| 614 | - $error['error'] = esc_html( 'Invalid query!', 'give' ); |
|
| 613 | + if ( ! in_array($query, $accepted)) { |
|
| 614 | + $error['error'] = esc_html('Invalid query!', 'give'); |
|
| 615 | 615 | |
| 616 | 616 | $this->data = $error; |
| 617 | 617 | // 400 is Bad Request |
| 618 | - $this->output( 400 ); |
|
| 618 | + $this->output(400); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | $this->endpoint = $query; |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | public function get_paged() { |
| 633 | 633 | global $wp_query; |
| 634 | 634 | |
| 635 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
| 635 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | |
@@ -647,13 +647,13 @@ discard block |
||
| 647 | 647 | public function per_page() { |
| 648 | 648 | global $wp_query; |
| 649 | 649 | |
| 650 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
| 650 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
| 651 | 651 | |
| 652 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
| 652 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
| 653 | 653 | $per_page = 99999999; |
| 654 | 654 | } // Customers query doesn't support -1 |
| 655 | 655 | |
| 656 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
| 656 | + return apply_filters('give_api_results_per_page', $per_page); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | * |
| 667 | 667 | * @return array $dates |
| 668 | 668 | */ |
| 669 | - public function get_dates( $args = array() ) { |
|
| 669 | + public function get_dates($args = array()) { |
|
| 670 | 670 | $dates = array(); |
| 671 | 671 | |
| 672 | 672 | $defaults = array( |
@@ -677,60 +677,60 @@ discard block |
||
| 677 | 677 | 'enddate' => null |
| 678 | 678 | ); |
| 679 | 679 | |
| 680 | - $args = wp_parse_args( $args, $defaults ); |
|
| 680 | + $args = wp_parse_args($args, $defaults); |
|
| 681 | 681 | |
| 682 | - $current_time = current_time( 'timestamp' ); |
|
| 682 | + $current_time = current_time('timestamp'); |
|
| 683 | 683 | |
| 684 | - if ( 'range' === $args['date'] ) { |
|
| 685 | - $startdate = strtotime( $args['startdate'] ); |
|
| 686 | - $enddate = strtotime( $args['enddate'] ); |
|
| 687 | - $dates['day_start'] = date( 'd', $startdate ); |
|
| 688 | - $dates['day_end'] = date( 'd', $enddate ); |
|
| 689 | - $dates['m_start'] = date( 'n', $startdate ); |
|
| 690 | - $dates['m_end'] = date( 'n', $enddate ); |
|
| 691 | - $dates['year'] = date( 'Y', $startdate ); |
|
| 692 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
| 684 | + if ('range' === $args['date']) { |
|
| 685 | + $startdate = strtotime($args['startdate']); |
|
| 686 | + $enddate = strtotime($args['enddate']); |
|
| 687 | + $dates['day_start'] = date('d', $startdate); |
|
| 688 | + $dates['day_end'] = date('d', $enddate); |
|
| 689 | + $dates['m_start'] = date('n', $startdate); |
|
| 690 | + $dates['m_end'] = date('n', $enddate); |
|
| 691 | + $dates['year'] = date('Y', $startdate); |
|
| 692 | + $dates['year_end'] = date('Y', $enddate); |
|
| 693 | 693 | } else { |
| 694 | 694 | // Modify dates based on predefined ranges |
| 695 | - switch ( $args['date'] ) : |
|
| 695 | + switch ($args['date']) : |
|
| 696 | 696 | |
| 697 | 697 | case 'this_month' : |
| 698 | 698 | $dates['day'] = null; |
| 699 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 700 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 701 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 699 | + $dates['m_start'] = date('n', $current_time); |
|
| 700 | + $dates['m_end'] = date('n', $current_time); |
|
| 701 | + $dates['year'] = date('Y', $current_time); |
|
| 702 | 702 | break; |
| 703 | 703 | |
| 704 | 704 | case 'last_month' : |
| 705 | 705 | $dates['day'] = null; |
| 706 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
| 706 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
| 707 | 707 | $dates['m_end'] = $dates['m_start']; |
| 708 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
| 708 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
| 709 | 709 | break; |
| 710 | 710 | |
| 711 | 711 | case 'today' : |
| 712 | - $dates['day'] = date( 'd', $current_time ); |
|
| 713 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 714 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 715 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 712 | + $dates['day'] = date('d', $current_time); |
|
| 713 | + $dates['m_start'] = date('n', $current_time); |
|
| 714 | + $dates['m_end'] = date('n', $current_time); |
|
| 715 | + $dates['year'] = date('Y', $current_time); |
|
| 716 | 716 | break; |
| 717 | 717 | |
| 718 | 718 | case 'yesterday' : |
| 719 | 719 | |
| 720 | - $year = date( 'Y', $current_time ); |
|
| 721 | - $month = date( 'n', $current_time ); |
|
| 722 | - $day = date( 'd', $current_time ); |
|
| 720 | + $year = date('Y', $current_time); |
|
| 721 | + $month = date('n', $current_time); |
|
| 722 | + $day = date('d', $current_time); |
|
| 723 | 723 | |
| 724 | - if ( $month == 1 && $day == 1 ) { |
|
| 724 | + if ($month == 1 && $day == 1) { |
|
| 725 | 725 | |
| 726 | 726 | $year -= 1; |
| 727 | 727 | $month = 12; |
| 728 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 728 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 729 | 729 | |
| 730 | - } elseif ( $month > 1 && $day == 1 ) { |
|
| 730 | + } elseif ($month > 1 && $day == 1) { |
|
| 731 | 731 | |
| 732 | 732 | $month -= 1; |
| 733 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 733 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 734 | 734 | |
| 735 | 735 | } else { |
| 736 | 736 | |
@@ -746,65 +746,65 @@ discard block |
||
| 746 | 746 | break; |
| 747 | 747 | |
| 748 | 748 | case 'this_quarter' : |
| 749 | - $month_now = date( 'n', $current_time ); |
|
| 749 | + $month_now = date('n', $current_time); |
|
| 750 | 750 | |
| 751 | 751 | $dates['day'] = null; |
| 752 | 752 | |
| 753 | - if ( $month_now <= 3 ) { |
|
| 753 | + if ($month_now <= 3) { |
|
| 754 | 754 | |
| 755 | 755 | $dates['m_start'] = 1; |
| 756 | 756 | $dates['m_end'] = 3; |
| 757 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 757 | + $dates['year'] = date('Y', $current_time); |
|
| 758 | 758 | |
| 759 | - } else if ( $month_now <= 6 ) { |
|
| 759 | + } else if ($month_now <= 6) { |
|
| 760 | 760 | |
| 761 | 761 | $dates['m_start'] = 4; |
| 762 | 762 | $dates['m_end'] = 6; |
| 763 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 763 | + $dates['year'] = date('Y', $current_time); |
|
| 764 | 764 | |
| 765 | - } else if ( $month_now <= 9 ) { |
|
| 765 | + } else if ($month_now <= 9) { |
|
| 766 | 766 | |
| 767 | 767 | $dates['m_start'] = 7; |
| 768 | 768 | $dates['m_end'] = 9; |
| 769 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 769 | + $dates['year'] = date('Y', $current_time); |
|
| 770 | 770 | |
| 771 | 771 | } else { |
| 772 | 772 | |
| 773 | 773 | $dates['m_start'] = 10; |
| 774 | 774 | $dates['m_end'] = 12; |
| 775 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 775 | + $dates['year'] = date('Y', $current_time); |
|
| 776 | 776 | |
| 777 | 777 | } |
| 778 | 778 | break; |
| 779 | 779 | |
| 780 | 780 | case 'last_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'] = 10; |
| 788 | 788 | $dates['m_end'] = 12; |
| 789 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
| 789 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
| 790 | 790 | |
| 791 | - } else if ( $month_now <= 6 ) { |
|
| 791 | + } else if ($month_now <= 6) { |
|
| 792 | 792 | |
| 793 | 793 | $dates['m_start'] = 1; |
| 794 | 794 | $dates['m_end'] = 3; |
| 795 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 795 | + $dates['year'] = date('Y', $current_time); |
|
| 796 | 796 | |
| 797 | - } else if ( $month_now <= 9 ) { |
|
| 797 | + } else if ($month_now <= 9) { |
|
| 798 | 798 | |
| 799 | 799 | $dates['m_start'] = 4; |
| 800 | 800 | $dates['m_end'] = 6; |
| 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'] = 7; |
| 806 | 806 | $dates['m_end'] = 9; |
| 807 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 807 | + $dates['year'] = date('Y', $current_time); |
|
| 808 | 808 | |
| 809 | 809 | } |
| 810 | 810 | break; |
@@ -813,14 +813,14 @@ discard block |
||
| 813 | 813 | $dates['day'] = null; |
| 814 | 814 | $dates['m_start'] = null; |
| 815 | 815 | $dates['m_end'] = null; |
| 816 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 816 | + $dates['year'] = date('Y', $current_time); |
|
| 817 | 817 | break; |
| 818 | 818 | |
| 819 | 819 | case 'last_year' : |
| 820 | 820 | $dates['day'] = null; |
| 821 | 821 | $dates['m_start'] = null; |
| 822 | 822 | $dates['m_end'] = null; |
| 823 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
| 823 | + $dates['year'] = date('Y', $current_time) - 1; |
|
| 824 | 824 | break; |
| 825 | 825 | |
| 826 | 826 | endswitch; |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | * @param object $dates The dates used for retreiving earnings/donations |
| 835 | 835 | */ |
| 836 | 836 | |
| 837 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
| 837 | + return apply_filters('give_api_stat_dates', $dates); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
@@ -849,11 +849,11 @@ discard block |
||
| 849 | 849 | * |
| 850 | 850 | * @return array $customers Multidimensional array of the customers |
| 851 | 851 | */ |
| 852 | - public function get_customers( $customer = null ) { |
|
| 852 | + public function get_customers($customer = null) { |
|
| 853 | 853 | |
| 854 | 854 | $customers = array(); |
| 855 | 855 | $error = array(); |
| 856 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
| 856 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
| 857 | 857 | return $customers; |
| 858 | 858 | } |
| 859 | 859 | |
@@ -861,64 +861,64 @@ discard block |
||
| 861 | 861 | |
| 862 | 862 | $paged = $this->get_paged(); |
| 863 | 863 | $per_page = $this->per_page(); |
| 864 | - $offset = $per_page * ( $paged - 1 ); |
|
| 864 | + $offset = $per_page * ($paged - 1); |
|
| 865 | 865 | |
| 866 | - if ( is_numeric( $customer ) ) { |
|
| 866 | + if (is_numeric($customer)) { |
|
| 867 | 867 | $field = 'id'; |
| 868 | 868 | } else { |
| 869 | 869 | $field = 'email'; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - $customer_query = Give()->customers->get_customers( array( |
|
| 872 | + $customer_query = Give()->customers->get_customers(array( |
|
| 873 | 873 | 'number' => $per_page, |
| 874 | 874 | 'offset' => $offset, |
| 875 | 875 | $field => $customer |
| 876 | - ) ); |
|
| 876 | + )); |
|
| 877 | 877 | $customer_count = 0; |
| 878 | 878 | |
| 879 | - if ( $customer_query ) { |
|
| 879 | + if ($customer_query) { |
|
| 880 | 880 | |
| 881 | - foreach ( $customer_query as $customer_obj ) { |
|
| 881 | + foreach ($customer_query as $customer_obj) { |
|
| 882 | 882 | |
| 883 | - $names = explode( ' ', $customer_obj->name ); |
|
| 884 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
| 883 | + $names = explode(' ', $customer_obj->name); |
|
| 884 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
| 885 | 885 | $last_name = ''; |
| 886 | - if ( ! empty( $names[1] ) ) { |
|
| 887 | - unset( $names[0] ); |
|
| 888 | - $last_name = implode( ' ', $names ); |
|
| 886 | + if ( ! empty($names[1])) { |
|
| 887 | + unset($names[0]); |
|
| 888 | + $last_name = implode(' ', $names); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
| 892 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
| 893 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
| 894 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
| 895 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
| 896 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
| 897 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
| 891 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
| 892 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
| 893 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
| 894 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
| 895 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
| 896 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
| 897 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
| 898 | 898 | |
| 899 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
| 899 | + if ( ! empty($customer_obj->user_id)) { |
|
| 900 | 900 | |
| 901 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
| 901 | + $user_data = get_userdata($customer_obj->user_id); |
|
| 902 | 902 | |
| 903 | 903 | // Customer with registered account |
| 904 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
| 905 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
| 906 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
| 904 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
| 905 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
| 906 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
| 907 | 907 | |
| 908 | 908 | } |
| 909 | 909 | |
| 910 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
| 911 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
| 910 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
| 911 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
| 912 | 912 | |
| 913 | - $customer_count ++; |
|
| 913 | + $customer_count++; |
|
| 914 | 914 | |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | - } elseif ( $customer ) { |
|
| 917 | + } elseif ($customer) { |
|
| 918 | 918 | |
| 919 | 919 | $error['error'] = sprintf( |
| 920 | 920 | /* translators: %s: customer */ |
| 921 | - esc_html( 'Donor %s not found!', 'give' ), |
|
| 921 | + esc_html('Donor %s not found!', 'give'), |
|
| 922 | 922 | $customer |
| 923 | 923 | ); |
| 924 | 924 | |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | |
| 927 | 927 | } else { |
| 928 | 928 | |
| 929 | - $error['error'] = esc_html( 'No donors found!', 'give' ); |
|
| 929 | + $error['error'] = esc_html('No donors found!', 'give'); |
|
| 930 | 930 | |
| 931 | 931 | return $error; |
| 932 | 932 | |
@@ -945,38 +945,38 @@ discard block |
||
| 945 | 945 | * |
| 946 | 946 | * @return array $customers Multidimensional array of the forms |
| 947 | 947 | */ |
| 948 | - public function get_forms( $form = null ) { |
|
| 948 | + public function get_forms($form = null) { |
|
| 949 | 949 | |
| 950 | 950 | $forms = array(); |
| 951 | 951 | $error = array(); |
| 952 | 952 | |
| 953 | - if ( $form == null ) { |
|
| 953 | + if ($form == null) { |
|
| 954 | 954 | $forms['forms'] = array(); |
| 955 | 955 | |
| 956 | - $form_list = get_posts( array( |
|
| 956 | + $form_list = get_posts(array( |
|
| 957 | 957 | 'post_type' => 'give_forms', |
| 958 | 958 | 'posts_per_page' => $this->per_page(), |
| 959 | 959 | 'suppress_filters' => true, |
| 960 | 960 | 'paged' => $this->get_paged() |
| 961 | - ) ); |
|
| 961 | + )); |
|
| 962 | 962 | |
| 963 | - if ( $form_list ) { |
|
| 963 | + if ($form_list) { |
|
| 964 | 964 | $i = 0; |
| 965 | - foreach ( $form_list as $form_info ) { |
|
| 966 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
| 967 | - $i ++; |
|
| 965 | + foreach ($form_list as $form_info) { |
|
| 966 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
| 967 | + $i++; |
|
| 968 | 968 | } |
| 969 | 969 | } |
| 970 | 970 | } else { |
| 971 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
| 972 | - $form_info = get_post( $form ); |
|
| 971 | + if (get_post_type($form) == 'give_forms') { |
|
| 972 | + $form_info = get_post($form); |
|
| 973 | 973 | |
| 974 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
| 974 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
| 975 | 975 | |
| 976 | 976 | } else { |
| 977 | 977 | $error['error'] = sprintf( |
| 978 | 978 | /* translators: %s: form */ |
| 979 | - esc_html( 'Form %s not found!', 'give' ), |
|
| 979 | + esc_html('Form %s not found!', 'give'), |
|
| 980 | 980 | $form |
| 981 | 981 | ); |
| 982 | 982 | |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | * |
| 997 | 997 | * @return array Array of post data to return back in the API |
| 998 | 998 | */ |
| 999 | - private function get_form_data( $form_info ) { |
|
| 999 | + private function get_form_data($form_info) { |
|
| 1000 | 1000 | |
| 1001 | 1001 | $form = array(); |
| 1002 | 1002 | |
@@ -1006,46 +1006,46 @@ discard block |
||
| 1006 | 1006 | $form['info']['create_date'] = $form_info->post_date; |
| 1007 | 1007 | $form['info']['modified_date'] = $form_info->post_modified; |
| 1008 | 1008 | $form['info']['status'] = $form_info->post_status; |
| 1009 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
| 1010 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
| 1011 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
| 1009 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
| 1010 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
| 1011 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
| 1012 | 1012 | |
| 1013 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
| 1014 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
| 1015 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1013 | + if (give_get_option('enable_categories') == 'on') { |
|
| 1014 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
| 1015 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1016 | 1016 | } |
| 1017 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
| 1018 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1017 | + if (give_get_option('enable_tags') == 'on') { |
|
| 1018 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
| 1022 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
| 1023 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
| 1024 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
| 1025 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
| 1021 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
| 1022 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
| 1023 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
| 1024 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
| 1025 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | $counter = 0; |
| 1029 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
| 1030 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
| 1031 | - $counter ++; |
|
| 1029 | + if (give_has_variable_prices($form_info->ID)) { |
|
| 1030 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
| 1031 | + $counter++; |
|
| 1032 | 1032 | //muli-level item |
| 1033 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
| 1034 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
| 1033 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
| 1034 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
| 1035 | 1035 | |
| 1036 | 1036 | } |
| 1037 | 1037 | } else { |
| 1038 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
| 1038 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
| 1041 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
| 1042 | 1042 | |
| 1043 | 1043 | //Sensitive data here |
| 1044 | - do_action( 'give_api_sensitive_data' ); |
|
| 1044 | + do_action('give_api_sensitive_data'); |
|
| 1045 | 1045 | |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - return apply_filters( 'give_api_forms_form', $form ); |
|
| 1048 | + return apply_filters('give_api_forms_form', $form); |
|
| 1049 | 1049 | |
| 1050 | 1050 | } |
| 1051 | 1051 | |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | * |
| 1061 | 1061 | * @return array |
| 1062 | 1062 | */ |
| 1063 | - public function get_stats( $args = array() ) { |
|
| 1063 | + public function get_stats($args = array()) { |
|
| 1064 | 1064 | $defaults = array( |
| 1065 | 1065 | 'type' => null, |
| 1066 | 1066 | 'form' => null, |
@@ -1069,9 +1069,9 @@ discard block |
||
| 1069 | 1069 | 'enddate' => null |
| 1070 | 1070 | ); |
| 1071 | 1071 | |
| 1072 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1072 | + $args = wp_parse_args($args, $defaults); |
|
| 1073 | 1073 | |
| 1074 | - $dates = $this->get_dates( $args ); |
|
| 1074 | + $dates = $this->get_dates($args); |
|
| 1075 | 1075 | |
| 1076 | 1076 | $stats = array(); |
| 1077 | 1077 | $earnings = array( |
@@ -1082,41 +1082,41 @@ discard block |
||
| 1082 | 1082 | ); |
| 1083 | 1083 | $error = array(); |
| 1084 | 1084 | |
| 1085 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1085 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1086 | 1086 | return $stats; |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | - if ( $args['type'] == 'donations' ) { |
|
| 1089 | + if ($args['type'] == 'donations') { |
|
| 1090 | 1090 | |
| 1091 | - if ( $args['form'] == null ) { |
|
| 1092 | - if ( $args['date'] == null ) { |
|
| 1091 | + if ($args['form'] == null) { |
|
| 1092 | + if ($args['date'] == null) { |
|
| 1093 | 1093 | $sales = $this->get_default_sales_stats(); |
| 1094 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1094 | + } elseif ($args['date'] === 'range') { |
|
| 1095 | 1095 | // Return sales for a date range |
| 1096 | 1096 | |
| 1097 | 1097 | // Ensure the end date is later than the start date |
| 1098 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1099 | - $error['error'] = esc_html( 'The end date must be later than the start date!', 'give' ); |
|
| 1098 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1099 | + $error['error'] = esc_html('The end date must be later than the start date!', 'give'); |
|
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | 1102 | // Ensure both the start and end date are specified |
| 1103 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1104 | - $error['error'] = esc_html( 'Invalid or no date range specified!', 'give' ); |
|
| 1103 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1104 | + $error['error'] = esc_html('Invalid or no date range specified!', 'give'); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | $total = 0; |
| 1108 | 1108 | |
| 1109 | 1109 | // Loop through the years |
| 1110 | 1110 | $y = $dates['year']; |
| 1111 | - while ( $y <= $dates['year_end'] ) : |
|
| 1111 | + while ($y <= $dates['year_end']) : |
|
| 1112 | 1112 | |
| 1113 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1113 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1114 | 1114 | $month_start = $dates['m_start']; |
| 1115 | 1115 | $month_end = $dates['m_end']; |
| 1116 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1116 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1117 | 1117 | $month_start = $dates['m_start']; |
| 1118 | 1118 | $month_end = 12; |
| 1119 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1119 | + } elseif ($y == $dates['year_end']) { |
|
| 1120 | 1120 | $month_start = 1; |
| 1121 | 1121 | $month_end = $dates['m_end']; |
| 1122 | 1122 | } else { |
@@ -1125,113 +1125,113 @@ discard block |
||
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | 1127 | $i = $month_start; |
| 1128 | - while ( $i <= $month_end ) : |
|
| 1128 | + while ($i <= $month_end) : |
|
| 1129 | 1129 | |
| 1130 | - if ( $i == $dates['m_start'] ) { |
|
| 1130 | + if ($i == $dates['m_start']) { |
|
| 1131 | 1131 | $d = $dates['day_start']; |
| 1132 | 1132 | } else { |
| 1133 | 1133 | $d = 1; |
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | - if ( $i == $dates['m_end'] ) { |
|
| 1136 | + if ($i == $dates['m_end']) { |
|
| 1137 | 1137 | $num_of_days = $dates['day_end']; |
| 1138 | 1138 | } else { |
| 1139 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1139 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | - while ( $d <= $num_of_days ) : |
|
| 1143 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
| 1144 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1145 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
| 1146 | - $sales['sales'][ $date_key ] = 0; |
|
| 1142 | + while ($d <= $num_of_days) : |
|
| 1143 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
| 1144 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1145 | + if ( ! isset($sales['sales'][$date_key])) { |
|
| 1146 | + $sales['sales'][$date_key] = 0; |
|
| 1147 | 1147 | } |
| 1148 | - $sales['sales'][ $date_key ] += $sale_count; |
|
| 1148 | + $sales['sales'][$date_key] += $sale_count; |
|
| 1149 | 1149 | $total += $sale_count; |
| 1150 | - $d ++; |
|
| 1150 | + $d++; |
|
| 1151 | 1151 | endwhile; |
| 1152 | - $i ++; |
|
| 1152 | + $i++; |
|
| 1153 | 1153 | endwhile; |
| 1154 | 1154 | |
| 1155 | - $y ++; |
|
| 1155 | + $y++; |
|
| 1156 | 1156 | endwhile; |
| 1157 | 1157 | |
| 1158 | 1158 | $sales['totals'] = $total; |
| 1159 | 1159 | } else { |
| 1160 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1160 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1161 | 1161 | $sales_count = 0; |
| 1162 | 1162 | |
| 1163 | 1163 | // Loop through the months |
| 1164 | 1164 | $month = $dates['m_start']; |
| 1165 | 1165 | |
| 1166 | - while ( $month <= $dates['m_end'] ) : |
|
| 1167 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
| 1168 | - $month ++; |
|
| 1166 | + while ($month <= $dates['m_end']) : |
|
| 1167 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
| 1168 | + $month++; |
|
| 1169 | 1169 | endwhile; |
| 1170 | 1170 | |
| 1171 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
| 1171 | + $sales['donations'][$args['date']] = $sales_count; |
|
| 1172 | 1172 | } else { |
| 1173 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1173 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | } |
| 1176 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1177 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
| 1176 | + } elseif ($args['form'] == 'all') { |
|
| 1177 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
| 1178 | 1178 | $i = 0; |
| 1179 | - foreach ( $forms as $form_info ) { |
|
| 1180 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
| 1181 | - $i ++; |
|
| 1179 | + foreach ($forms as $form_info) { |
|
| 1180 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
| 1181 | + $i++; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | } else { |
| 1184 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1185 | - $form_info = get_post( $args['form'] ); |
|
| 1186 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
| 1184 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1185 | + $form_info = get_post($args['form']); |
|
| 1186 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
| 1187 | 1187 | } else { |
| 1188 | 1188 | $error['error'] = sprintf( |
| 1189 | 1189 | /* translators: %s: form */ |
| 1190 | - esc_html( 'Product %s not found!', 'give' ), |
|
| 1190 | + esc_html('Product %s not found!', 'give'), |
|
| 1191 | 1191 | $args['form'] |
| 1192 | 1192 | ); |
| 1193 | 1193 | } |
| 1194 | 1194 | } |
| 1195 | 1195 | |
| 1196 | - if ( ! empty( $error ) ) { |
|
| 1196 | + if ( ! empty($error)) { |
|
| 1197 | 1197 | return $error; |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | 1200 | return $sales; |
| 1201 | 1201 | |
| 1202 | - } elseif ( $args['type'] == 'earnings' ) { |
|
| 1203 | - if ( $args['form'] == null ) { |
|
| 1204 | - if ( $args['date'] == null ) { |
|
| 1202 | + } elseif ($args['type'] == 'earnings') { |
|
| 1203 | + if ($args['form'] == null) { |
|
| 1204 | + if ($args['date'] == null) { |
|
| 1205 | 1205 | $earnings = $this->get_default_earnings_stats(); |
| 1206 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1206 | + } elseif ($args['date'] === 'range') { |
|
| 1207 | 1207 | // Return sales for a date range |
| 1208 | 1208 | |
| 1209 | 1209 | // Ensure the end date is later than the start date |
| 1210 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1211 | - $error['error'] = esc_html( 'The end date must be later than the start date!', 'give' ); |
|
| 1210 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1211 | + $error['error'] = esc_html('The end date must be later than the start date!', 'give'); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | // Ensure both the start and end date are specified |
| 1215 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1216 | - $error['error'] = esc_html( 'Invalid or no date range specified!', 'give' ); |
|
| 1215 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1216 | + $error['error'] = esc_html('Invalid or no date range specified!', 'give'); |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | $total = (float) 0.00; |
| 1220 | 1220 | |
| 1221 | 1221 | // Loop through the years |
| 1222 | 1222 | $y = $dates['year']; |
| 1223 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
| 1223 | + if ( ! isset($earnings['earnings'])) { |
|
| 1224 | 1224 | $earnings['earnings'] = array(); |
| 1225 | 1225 | } |
| 1226 | - while ( $y <= $dates['year_end'] ) : |
|
| 1226 | + while ($y <= $dates['year_end']) : |
|
| 1227 | 1227 | |
| 1228 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1228 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1229 | 1229 | $month_start = $dates['m_start']; |
| 1230 | 1230 | $month_end = $dates['m_end']; |
| 1231 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1231 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1232 | 1232 | $month_start = $dates['m_start']; |
| 1233 | 1233 | $month_end = 12; |
| 1234 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1234 | + } elseif ($y == $dates['year_end']) { |
|
| 1235 | 1235 | $month_start = 1; |
| 1236 | 1236 | $month_end = $dates['m_end']; |
| 1237 | 1237 | } else { |
@@ -1240,92 +1240,92 @@ discard block |
||
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | $i = $month_start; |
| 1243 | - while ( $i <= $month_end ) : |
|
| 1243 | + while ($i <= $month_end) : |
|
| 1244 | 1244 | |
| 1245 | - if ( $i == $dates['m_start'] ) { |
|
| 1245 | + if ($i == $dates['m_start']) { |
|
| 1246 | 1246 | $d = $dates['day_start']; |
| 1247 | 1247 | } else { |
| 1248 | 1248 | $d = 1; |
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | - if ( $i == $dates['m_end'] ) { |
|
| 1251 | + if ($i == $dates['m_end']) { |
|
| 1252 | 1252 | $num_of_days = $dates['day_end']; |
| 1253 | 1253 | } else { |
| 1254 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1254 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | - while ( $d <= $num_of_days ) : |
|
| 1258 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
| 1259 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1260 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
| 1261 | - $earnings['earnings'][ $date_key ] = 0; |
|
| 1257 | + while ($d <= $num_of_days) : |
|
| 1258 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
| 1259 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1260 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
| 1261 | + $earnings['earnings'][$date_key] = 0; |
|
| 1262 | 1262 | } |
| 1263 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
| 1263 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
| 1264 | 1264 | $total += $earnings_stat; |
| 1265 | - $d ++; |
|
| 1265 | + $d++; |
|
| 1266 | 1266 | endwhile; |
| 1267 | 1267 | |
| 1268 | - $i ++; |
|
| 1268 | + $i++; |
|
| 1269 | 1269 | endwhile; |
| 1270 | 1270 | |
| 1271 | - $y ++; |
|
| 1271 | + $y++; |
|
| 1272 | 1272 | endwhile; |
| 1273 | 1273 | |
| 1274 | 1274 | $earnings['totals'] = $total; |
| 1275 | 1275 | } else { |
| 1276 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1276 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1277 | 1277 | $earnings_count = (float) 0.00; |
| 1278 | 1278 | |
| 1279 | 1279 | // Loop through the months |
| 1280 | 1280 | $month = $dates['m_start']; |
| 1281 | 1281 | |
| 1282 | - while ( $month <= $dates['m_end'] ) : |
|
| 1283 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
| 1284 | - $month ++; |
|
| 1282 | + while ($month <= $dates['m_end']) : |
|
| 1283 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
| 1284 | + $month++; |
|
| 1285 | 1285 | endwhile; |
| 1286 | 1286 | |
| 1287 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
| 1287 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
| 1288 | 1288 | } else { |
| 1289 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1289 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | } |
| 1292 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1293 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
| 1292 | + } elseif ($args['form'] == 'all') { |
|
| 1293 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
| 1294 | 1294 | |
| 1295 | 1295 | $i = 0; |
| 1296 | - foreach ( $forms as $form_info ) { |
|
| 1297 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
| 1298 | - $i ++; |
|
| 1296 | + foreach ($forms as $form_info) { |
|
| 1297 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
| 1298 | + $i++; |
|
| 1299 | 1299 | } |
| 1300 | 1300 | } else { |
| 1301 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1302 | - $form_info = get_post( $args['form'] ); |
|
| 1303 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
| 1301 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1302 | + $form_info = get_post($args['form']); |
|
| 1303 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
| 1304 | 1304 | } else { |
| 1305 | 1305 | $error['error'] = sprintf( |
| 1306 | 1306 | /* translators: %s: form */ |
| 1307 | - esc_html( 'Form %s not found!', 'give' ), |
|
| 1307 | + esc_html('Form %s not found!', 'give'), |
|
| 1308 | 1308 | $args['form'] |
| 1309 | 1309 | ); |
| 1310 | 1310 | } |
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | - if ( ! empty( $error ) ) { |
|
| 1313 | + if ( ! empty($error)) { |
|
| 1314 | 1314 | return $error; |
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | 1317 | return $earnings; |
| 1318 | - } elseif ( $args['type'] == 'donors' ) { |
|
| 1318 | + } elseif ($args['type'] == 'donors') { |
|
| 1319 | 1319 | $customers = new Give_DB_Customers(); |
| 1320 | 1320 | $stats['donations']['total_donors'] = $customers->count(); |
| 1321 | 1321 | |
| 1322 | 1322 | return $stats; |
| 1323 | 1323 | |
| 1324 | - } elseif ( empty( $args['type'] ) ) { |
|
| 1325 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
| 1326 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
| 1324 | + } elseif (empty($args['type'])) { |
|
| 1325 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
| 1326 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
| 1327 | 1327 | |
| 1328 | - return array( 'stats' => $stats ); |
|
| 1328 | + return array('stats' => $stats); |
|
| 1329 | 1329 | } |
| 1330 | 1330 | } |
| 1331 | 1331 | |
@@ -1341,18 +1341,18 @@ discard block |
||
| 1341 | 1341 | |
| 1342 | 1342 | $sales = array(); |
| 1343 | 1343 | |
| 1344 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1344 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1345 | 1345 | return $sales; |
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
| 1348 | + if (isset($wp_query->query_vars['id'])) { |
|
| 1349 | 1349 | $query = array(); |
| 1350 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
| 1351 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
| 1350 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
| 1351 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
| 1352 | 1352 | $query = array(); |
| 1353 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
| 1354 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
| 1355 | - $args = array( |
|
| 1353 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
| 1354 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
| 1355 | + $args = array( |
|
| 1356 | 1356 | 'fields' => 'ids', |
| 1357 | 1357 | 'meta_key' => '_give_payment_user_email', |
| 1358 | 1358 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1360,7 +1360,7 @@ discard block |
||
| 1360 | 1360 | 'page' => $this->get_paged(), |
| 1361 | 1361 | 'status' => 'publish' |
| 1362 | 1362 | ); |
| 1363 | - $query = give_get_payments( $args ); |
|
| 1363 | + $query = give_get_payments($args); |
|
| 1364 | 1364 | } else { |
| 1365 | 1365 | $args = array( |
| 1366 | 1366 | 'fields' => 'ids', |
@@ -1368,14 +1368,14 @@ discard block |
||
| 1368 | 1368 | 'page' => $this->get_paged(), |
| 1369 | 1369 | 'status' => 'publish' |
| 1370 | 1370 | ); |
| 1371 | - $query = give_get_payments( $args ); |
|
| 1371 | + $query = give_get_payments($args); |
|
| 1372 | 1372 | } |
| 1373 | - if ( $query ) { |
|
| 1373 | + if ($query) { |
|
| 1374 | 1374 | $i = 0; |
| 1375 | - foreach ( $query as $payment ) { |
|
| 1375 | + foreach ($query as $payment) { |
|
| 1376 | 1376 | |
| 1377 | - if ( is_numeric( $payment ) ) { |
|
| 1378 | - $payment = new Give_Payment( $payment ); |
|
| 1377 | + if (is_numeric($payment)) { |
|
| 1378 | + $payment = new Give_Payment($payment); |
|
| 1379 | 1379 | $payment_meta = $payment->get_meta(); |
| 1380 | 1380 | $user_info = $payment->user_info; |
| 1381 | 1381 | } else { |
@@ -1385,40 +1385,40 @@ discard block |
||
| 1385 | 1385 | $payment_meta = $payment->get_meta(); |
| 1386 | 1386 | $user_info = $payment->user_info; |
| 1387 | 1387 | |
| 1388 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
| 1389 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
| 1390 | - |
|
| 1391 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
| 1392 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
| 1393 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
| 1394 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
| 1395 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
| 1396 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
| 1397 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
| 1398 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
| 1399 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
| 1400 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
| 1401 | - |
|
| 1402 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1403 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
| 1404 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
| 1405 | - |
|
| 1406 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
| 1407 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
| 1408 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
| 1409 | - |
|
| 1410 | - if ( give_has_variable_prices( $form_id ) ) { |
|
| 1411 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
| 1412 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
| 1413 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
| 1414 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
| 1415 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
| 1388 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
| 1389 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
| 1390 | + |
|
| 1391 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
| 1392 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
| 1393 | + $sales['donations'][$i]['key'] = $payment->key; |
|
| 1394 | + $sales['donations'][$i]['total'] = $payment->total; |
|
| 1395 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
| 1396 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
| 1397 | + $sales['donations'][$i]['fname'] = $first_name; |
|
| 1398 | + $sales['donations'][$i]['lname'] = $last_name; |
|
| 1399 | + $sales['donations'][$i]['email'] = $payment->email; |
|
| 1400 | + $sales['donations'][$i]['date'] = $payment->date; |
|
| 1401 | + |
|
| 1402 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1403 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
| 1404 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
| 1405 | + |
|
| 1406 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
| 1407 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
| 1408 | + $sales['donations'][$i]['form']['price'] = $price; |
|
| 1409 | + |
|
| 1410 | + if (give_has_variable_prices($form_id)) { |
|
| 1411 | + if (isset($payment_meta['price_id'])) { |
|
| 1412 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
| 1413 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
| 1414 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
| 1415 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
| 1416 | 1416 | |
| 1417 | 1417 | } |
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | //Add custom meta to API |
| 1421 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
| 1421 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
| 1422 | 1422 | |
| 1423 | 1423 | $exceptions = array( |
| 1424 | 1424 | 'form_title', |
@@ -1431,19 +1431,19 @@ discard block |
||
| 1431 | 1431 | ); |
| 1432 | 1432 | |
| 1433 | 1433 | //Don't clutter up results with dupes |
| 1434 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
| 1434 | + if (in_array($meta_key, $exceptions)) { |
|
| 1435 | 1435 | continue; |
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
| 1438 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
| 1439 | 1439 | |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | - $i ++; |
|
| 1442 | + $i++; |
|
| 1443 | 1443 | } |
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
| 1446 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | /** |
@@ -1458,9 +1458,9 @@ discard block |
||
| 1458 | 1458 | public function get_output_format() { |
| 1459 | 1459 | global $wp_query; |
| 1460 | 1460 | |
| 1461 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1461 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1462 | 1462 | |
| 1463 | - return apply_filters( 'give_api_output_format', $format ); |
|
| 1463 | + return apply_filters('give_api_output_format', $format); |
|
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | |
@@ -1476,8 +1476,8 @@ discard block |
||
| 1476 | 1476 | * |
| 1477 | 1477 | * @return void |
| 1478 | 1478 | */ |
| 1479 | - private function log_request( $data = array() ) { |
|
| 1480 | - if ( ! $this->log_requests ) { |
|
| 1479 | + private function log_request($data = array()) { |
|
| 1480 | + if ( ! $this->log_requests) { |
|
| 1481 | 1481 | return; |
| 1482 | 1482 | } |
| 1483 | 1483 | |
@@ -1485,36 +1485,36 @@ discard block |
||
| 1485 | 1485 | |
| 1486 | 1486 | $query = array( |
| 1487 | 1487 | 'give-api' => $wp_query->query_vars['give-api'], |
| 1488 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1489 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1490 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
| 1491 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 1492 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 1493 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
| 1494 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 1495 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 1496 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 1497 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
| 1498 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1499 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
| 1488 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1489 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1490 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
| 1491 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 1492 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 1493 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
| 1494 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 1495 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 1496 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 1497 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
| 1498 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1499 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
| 1500 | 1500 | ); |
| 1501 | 1501 | |
| 1502 | 1502 | $log_data = array( |
| 1503 | 1503 | 'log_type' => 'api_request', |
| 1504 | - 'post_excerpt' => http_build_query( $query ), |
|
| 1505 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
| 1504 | + 'post_excerpt' => http_build_query($query), |
|
| 1505 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
| 1506 | 1506 | ); |
| 1507 | 1507 | |
| 1508 | 1508 | $log_meta = array( |
| 1509 | 1509 | 'request_ip' => give_get_ip(), |
| 1510 | 1510 | 'user' => $this->user_id, |
| 1511 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1512 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1511 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1512 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1513 | 1513 | 'time' => $data['request_speed'], |
| 1514 | 1514 | 'version' => $this->get_queried_version() |
| 1515 | 1515 | ); |
| 1516 | 1516 | |
| 1517 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
| 1517 | + $give_logs->insert_log($log_data, $log_meta); |
|
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | 1520 | |
@@ -1538,32 +1538,32 @@ discard block |
||
| 1538 | 1538 | * |
| 1539 | 1539 | * @param int $status_code |
| 1540 | 1540 | */ |
| 1541 | - public function output( $status_code = 200 ) { |
|
| 1541 | + public function output($status_code = 200) { |
|
| 1542 | 1542 | global $wp_query; |
| 1543 | 1543 | |
| 1544 | 1544 | $format = $this->get_output_format(); |
| 1545 | 1545 | |
| 1546 | - status_header( $status_code ); |
|
| 1546 | + status_header($status_code); |
|
| 1547 | 1547 | |
| 1548 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
| 1548 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
| 1549 | 1549 | |
| 1550 | - switch ( $format ) : |
|
| 1550 | + switch ($format) : |
|
| 1551 | 1551 | |
| 1552 | 1552 | case 'xml' : |
| 1553 | 1553 | |
| 1554 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
| 1555 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
| 1554 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
| 1555 | + $xml = Array2XML::createXML('give', $this->data); |
|
| 1556 | 1556 | echo $xml->saveXML(); |
| 1557 | 1557 | |
| 1558 | 1558 | break; |
| 1559 | 1559 | |
| 1560 | 1560 | case 'json' : |
| 1561 | 1561 | |
| 1562 | - header( 'Content-Type: application/json' ); |
|
| 1563 | - if ( ! empty( $this->pretty_print ) ) { |
|
| 1564 | - echo json_encode( $this->data, $this->pretty_print ); |
|
| 1562 | + header('Content-Type: application/json'); |
|
| 1563 | + if ( ! empty($this->pretty_print)) { |
|
| 1564 | + echo json_encode($this->data, $this->pretty_print); |
|
| 1565 | 1565 | } else { |
| 1566 | - echo json_encode( $this->data ); |
|
| 1566 | + echo json_encode($this->data); |
|
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | 1569 | break; |
@@ -1572,13 +1572,13 @@ discard block |
||
| 1572 | 1572 | default : |
| 1573 | 1573 | |
| 1574 | 1574 | // Allow other formats to be added via extensions |
| 1575 | - do_action( 'give_api_output_' . $format, $this->data, $this ); |
|
| 1575 | + do_action('give_api_output_'.$format, $this->data, $this); |
|
| 1576 | 1576 | |
| 1577 | 1577 | break; |
| 1578 | 1578 | |
| 1579 | 1579 | endswitch; |
| 1580 | 1580 | |
| 1581 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
| 1581 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
| 1582 | 1582 | |
| 1583 | 1583 | give_die(); |
| 1584 | 1584 | } |
@@ -1595,37 +1595,37 @@ discard block |
||
| 1595 | 1595 | * |
| 1596 | 1596 | * @return void |
| 1597 | 1597 | */ |
| 1598 | - function user_key_field( $user ) { |
|
| 1598 | + function user_key_field($user) { |
|
| 1599 | 1599 | |
| 1600 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
| 1601 | - $user = get_userdata( $user->ID ); |
|
| 1600 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
| 1601 | + $user = get_userdata($user->ID); |
|
| 1602 | 1602 | ?> |
| 1603 | 1603 | <table class="form-table"> |
| 1604 | 1604 | <tbody> |
| 1605 | 1605 | <tr> |
| 1606 | 1606 | <th> |
| 1607 | - <?php esc_html_e( 'Give API Keys', 'give' ); ?> |
|
| 1607 | + <?php esc_html_e('Give API Keys', 'give'); ?> |
|
| 1608 | 1608 | </th> |
| 1609 | 1609 | <td> |
| 1610 | 1610 | <?php |
| 1611 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
| 1612 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
| 1611 | + $public_key = $this->get_user_public_key($user->ID); |
|
| 1612 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
| 1613 | 1613 | ?> |
| 1614 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
| 1614 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
| 1615 | 1615 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
| 1616 | - <span class="description"><?php esc_html_e( 'Generate API Key', 'give' ); ?></span> |
|
| 1616 | + <span class="description"><?php esc_html_e('Generate API Key', 'give'); ?></span> |
|
| 1617 | 1617 | <?php } else { ?> |
| 1618 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'give' ); ?> </strong> |
|
| 1619 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php esc_attr_e( $public_key ); ?>"/> |
|
| 1618 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Public key:', 'give'); ?> </strong> |
|
| 1619 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php esc_attr_e($public_key); ?>"/> |
|
| 1620 | 1620 | <br/> |
| 1621 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'give' ); ?> </strong> |
|
| 1622 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php esc_attr_e( $secret_key ); ?>"/> |
|
| 1621 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Secret key:', 'give'); ?> </strong> |
|
| 1622 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php esc_attr_e($secret_key); ?>"/> |
|
| 1623 | 1623 | <br/> |
| 1624 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'give' ); ?> </strong> |
|
| 1625 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php esc_attr_e( $this->get_token( $user->ID ) ); ?>"/> |
|
| 1624 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Token:', 'give'); ?> </strong> |
|
| 1625 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php esc_attr_e($this->get_token($user->ID)); ?>"/> |
|
| 1626 | 1626 | <br/> |
| 1627 | 1627 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
| 1628 | - <span class="description"><label for="give_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
| 1628 | + <span class="description"><label for="give_set_api_key"><?php esc_html_e('Revoke API Keys', 'give'); ?></label></span> |
|
| 1629 | 1629 | <?php } ?> |
| 1630 | 1630 | </td> |
| 1631 | 1631 | </tr> |
@@ -1644,69 +1644,69 @@ discard block |
||
| 1644 | 1644 | * |
| 1645 | 1645 | * @return void |
| 1646 | 1646 | */ |
| 1647 | - public function process_api_key( $args ) { |
|
| 1647 | + public function process_api_key($args) { |
|
| 1648 | 1648 | |
| 1649 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
| 1649 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
| 1650 | 1650 | |
| 1651 | - wp_die( esc_html( 'Nonce verification failed.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 1651 | + wp_die(esc_html('Nonce verification failed.', 'give'), esc_html('Error', 'give'), array('response' => 403)); |
|
| 1652 | 1652 | |
| 1653 | 1653 | } |
| 1654 | 1654 | |
| 1655 | - if ( empty( $args['user_id'] ) ) { |
|
| 1656 | - wp_die( esc_html( 'User ID Required.', 'give' ), esc_html( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
| 1655 | + if (empty($args['user_id'])) { |
|
| 1656 | + wp_die(esc_html('User ID Required.', 'give'), esc_html('Error', 'give'), array('response' => 401)); |
|
| 1657 | 1657 | } |
| 1658 | 1658 | |
| 1659 | - if ( is_numeric( $args['user_id'] ) ) { |
|
| 1660 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
| 1659 | + if (is_numeric($args['user_id'])) { |
|
| 1660 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
| 1661 | 1661 | } else { |
| 1662 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
| 1662 | + $userdata = get_user_by('login', $args['user_id']); |
|
| 1663 | 1663 | $user_id = $userdata->ID; |
| 1664 | 1664 | } |
| 1665 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
| 1665 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
| 1666 | 1666 | |
| 1667 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1667 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
| 1668 | 1668 | wp_die( |
| 1669 | 1669 | sprintf( |
| 1670 | 1670 | /* translators: %s: process */ |
| 1671 | - esc_html( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
| 1671 | + esc_html('You do not have permission to %s API keys for this user.', 'give'), |
|
| 1672 | 1672 | $process |
| 1673 | 1673 | ), |
| 1674 | - esc_html( 'Error', 'give' ), |
|
| 1675 | - array( 'response' => 403 ) |
|
| 1674 | + esc_html('Error', 'give'), |
|
| 1675 | + array('response' => 403) |
|
| 1676 | 1676 | ); |
| 1677 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1677 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
| 1678 | 1678 | wp_die( |
| 1679 | 1679 | sprintf( |
| 1680 | 1680 | /* translators: %s: process */ |
| 1681 | - esc_html( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
| 1681 | + esc_html('You do not have permission to %s API keys for this user.', 'give'), |
|
| 1682 | 1682 | $process |
| 1683 | 1683 | ), |
| 1684 | - esc_html( 'Error', 'give' ), |
|
| 1685 | - array( 'response' => 403 ) |
|
| 1684 | + esc_html('Error', 'give'), |
|
| 1685 | + array('response' => 403) |
|
| 1686 | 1686 | ); |
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | - switch ( $process ) { |
|
| 1689 | + switch ($process) { |
|
| 1690 | 1690 | case 'generate': |
| 1691 | - if ( $this->generate_api_key( $user_id ) ) { |
|
| 1692 | - delete_transient( 'give-total-api-keys' ); |
|
| 1693 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1691 | + if ($this->generate_api_key($user_id)) { |
|
| 1692 | + delete_transient('give-total-api-keys'); |
|
| 1693 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1694 | 1694 | exit(); |
| 1695 | 1695 | } else { |
| 1696 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1696 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1697 | 1697 | exit(); |
| 1698 | 1698 | } |
| 1699 | 1699 | break; |
| 1700 | 1700 | case 'regenerate': |
| 1701 | - $this->generate_api_key( $user_id, true ); |
|
| 1702 | - delete_transient( 'give-total-api-keys' ); |
|
| 1703 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1701 | + $this->generate_api_key($user_id, true); |
|
| 1702 | + delete_transient('give-total-api-keys'); |
|
| 1703 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1704 | 1704 | exit(); |
| 1705 | 1705 | break; |
| 1706 | 1706 | case 'revoke': |
| 1707 | - $this->revoke_api_key( $user_id ); |
|
| 1708 | - delete_transient( 'give-total-api-keys' ); |
|
| 1709 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1707 | + $this->revoke_api_key($user_id); |
|
| 1708 | + delete_transient('give-total-api-keys'); |
|
| 1709 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1710 | 1710 | exit(); |
| 1711 | 1711 | break; |
| 1712 | 1712 | default; |
@@ -1725,34 +1725,34 @@ discard block |
||
| 1725 | 1725 | * |
| 1726 | 1726 | * @return boolean True if (re)generated succesfully, false otherwise. |
| 1727 | 1727 | */ |
| 1728 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
| 1728 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
| 1729 | 1729 | |
| 1730 | - if ( empty( $user_id ) ) { |
|
| 1730 | + if (empty($user_id)) { |
|
| 1731 | 1731 | return false; |
| 1732 | 1732 | } |
| 1733 | 1733 | |
| 1734 | - $user = get_userdata( $user_id ); |
|
| 1734 | + $user = get_userdata($user_id); |
|
| 1735 | 1735 | |
| 1736 | - if ( ! $user ) { |
|
| 1736 | + if ( ! $user) { |
|
| 1737 | 1737 | return false; |
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1741 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 1740 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1741 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 1742 | 1742 | |
| 1743 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
| 1744 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1745 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1743 | + if (empty($public_key) || $regenerate == true) { |
|
| 1744 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1745 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1746 | 1746 | } else { |
| 1747 | 1747 | return false; |
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | - if ( $regenerate == true ) { |
|
| 1751 | - $this->revoke_api_key( $user->ID ); |
|
| 1750 | + if ($regenerate == true) { |
|
| 1751 | + $this->revoke_api_key($user->ID); |
|
| 1752 | 1752 | } |
| 1753 | 1753 | |
| 1754 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
| 1755 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
| 1754 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
| 1755 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
| 1756 | 1756 | |
| 1757 | 1757 | return true; |
| 1758 | 1758 | } |
@@ -1767,26 +1767,26 @@ discard block |
||
| 1767 | 1767 | * |
| 1768 | 1768 | * @return string |
| 1769 | 1769 | */ |
| 1770 | - public function revoke_api_key( $user_id = 0 ) { |
|
| 1770 | + public function revoke_api_key($user_id = 0) { |
|
| 1771 | 1771 | |
| 1772 | - if ( empty( $user_id ) ) { |
|
| 1772 | + if (empty($user_id)) { |
|
| 1773 | 1773 | return false; |
| 1774 | 1774 | } |
| 1775 | 1775 | |
| 1776 | - $user = get_userdata( $user_id ); |
|
| 1776 | + $user = get_userdata($user_id); |
|
| 1777 | 1777 | |
| 1778 | - if ( ! $user ) { |
|
| 1778 | + if ( ! $user) { |
|
| 1779 | 1779 | return false; |
| 1780 | 1780 | } |
| 1781 | 1781 | |
| 1782 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1783 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 1784 | - if ( ! empty( $public_key ) ) { |
|
| 1785 | - delete_transient( md5( 'give_api_user_' . $public_key ) ); |
|
| 1786 | - delete_transient( md5( 'give_api_user_public_key' . $user_id ) ); |
|
| 1787 | - delete_transient( md5( 'give_api_user_secret_key' . $user_id ) ); |
|
| 1788 | - delete_user_meta( $user_id, $public_key ); |
|
| 1789 | - delete_user_meta( $user_id, $secret_key ); |
|
| 1782 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1783 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 1784 | + if ( ! empty($public_key)) { |
|
| 1785 | + delete_transient(md5('give_api_user_'.$public_key)); |
|
| 1786 | + delete_transient(md5('give_api_user_public_key'.$user_id)); |
|
| 1787 | + delete_transient(md5('give_api_user_secret_key'.$user_id)); |
|
| 1788 | + delete_user_meta($user_id, $public_key); |
|
| 1789 | + delete_user_meta($user_id, $secret_key); |
|
| 1790 | 1790 | } else { |
| 1791 | 1791 | return false; |
| 1792 | 1792 | } |
@@ -1811,22 +1811,22 @@ discard block |
||
| 1811 | 1811 | * |
| 1812 | 1812 | * @return void |
| 1813 | 1813 | */ |
| 1814 | - public function update_key( $user_id ) { |
|
| 1815 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
| 1814 | + public function update_key($user_id) { |
|
| 1815 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
| 1816 | 1816 | |
| 1817 | - $user = get_userdata( $user_id ); |
|
| 1817 | + $user = get_userdata($user_id); |
|
| 1818 | 1818 | |
| 1819 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1820 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 1819 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1820 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 1821 | 1821 | |
| 1822 | - if ( empty( $public_key ) ) { |
|
| 1823 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1824 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1822 | + if (empty($public_key)) { |
|
| 1823 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1824 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1825 | 1825 | |
| 1826 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
| 1827 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
| 1826 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
| 1827 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
| 1828 | 1828 | } else { |
| 1829 | - $this->revoke_api_key( $user_id ); |
|
| 1829 | + $this->revoke_api_key($user_id); |
|
| 1830 | 1830 | } |
| 1831 | 1831 | } |
| 1832 | 1832 | } |
@@ -1841,9 +1841,9 @@ discard block |
||
| 1841 | 1841 | * |
| 1842 | 1842 | * @return string |
| 1843 | 1843 | */ |
| 1844 | - private function generate_public_key( $user_email = '' ) { |
|
| 1845 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 1846 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
| 1844 | + private function generate_public_key($user_email = '') { |
|
| 1845 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 1846 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
| 1847 | 1847 | |
| 1848 | 1848 | return $public; |
| 1849 | 1849 | } |
@@ -1858,9 +1858,9 @@ discard block |
||
| 1858 | 1858 | * |
| 1859 | 1859 | * @return string |
| 1860 | 1860 | */ |
| 1861 | - private function generate_private_key( $user_id = 0 ) { |
|
| 1862 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 1863 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
| 1861 | + private function generate_private_key($user_id = 0) { |
|
| 1862 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 1863 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
| 1864 | 1864 | |
| 1865 | 1865 | return $secret; |
| 1866 | 1866 | } |
@@ -1875,8 +1875,8 @@ discard block |
||
| 1875 | 1875 | * |
| 1876 | 1876 | * @return string |
| 1877 | 1877 | */ |
| 1878 | - public function get_token( $user_id = 0 ) { |
|
| 1879 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
| 1878 | + public function get_token($user_id = 0) { |
|
| 1879 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
| 1880 | 1880 | } |
| 1881 | 1881 | |
| 1882 | 1882 | /** |
@@ -1890,9 +1890,9 @@ discard block |
||
| 1890 | 1890 | |
| 1891 | 1891 | // Default sales return |
| 1892 | 1892 | $sales = array(); |
| 1893 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
| 1894 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
| 1895 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
| 1893 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
| 1894 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
| 1895 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
| 1896 | 1896 | $sales['donations']['totals'] = give_get_total_sales(); |
| 1897 | 1897 | |
| 1898 | 1898 | return $sales; |
@@ -1909,9 +1909,9 @@ discard block |
||
| 1909 | 1909 | |
| 1910 | 1910 | // Default earnings return |
| 1911 | 1911 | $earnings = array(); |
| 1912 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
| 1913 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
| 1914 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
| 1912 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
| 1913 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
| 1914 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
| 1915 | 1915 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
| 1916 | 1916 | |
| 1917 | 1917 | return $earnings; |
@@ -1931,25 +1931,25 @@ discard block |
||
| 1931 | 1931 | * |
| 1932 | 1932 | * @return string The API key/secret for the user supplied |
| 1933 | 1933 | */ |
| 1934 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
| 1934 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
| 1935 | 1935 | |
| 1936 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
| 1936 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
| 1937 | 1937 | return $check; |
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | 1940 | $return = $check; |
| 1941 | 1941 | |
| 1942 | - switch ( $meta_key ) { |
|
| 1942 | + switch ($meta_key) { |
|
| 1943 | 1943 | case 'give_user_public_key': |
| 1944 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
| 1944 | + $return = Give()->api->get_user_public_key($object_id); |
|
| 1945 | 1945 | break; |
| 1946 | 1946 | case 'give_user_secret_key': |
| 1947 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
| 1947 | + $return = Give()->api->get_user_secret_key($object_id); |
|
| 1948 | 1948 | break; |
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | - if ( ! $single ) { |
|
| 1952 | - $return = array( $return ); |
|
| 1951 | + if ( ! $single) { |
|
| 1952 | + $return = array($return); |
|
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | 1955 | return $return; |