| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Loading a service? |
|---|
| 4 | */ |
|---|
| 5 | /* |
|---|
| 6 | Note: The applydiscountcode goes through the site_url() instead of admin-ajax to avoid HTTP/HTTPS issues. |
|---|
| 7 | */ |
|---|
| 8 | if(isset($_REQUEST['action']) && $_REQUEST['action'] == "applydiscountcode") |
|---|
| 9 | { |
|---|
| 10 | function pmpro_applydiscountcode_init() |
|---|
| 11 | { |
|---|
| 12 | require_once(dirname(__FILE__) . "/../services/applydiscountcode.php"); |
|---|
| 13 | exit; |
|---|
| 14 | } |
|---|
| 15 | add_action("init", "pmpro_applydiscountcode_init", 11); |
|---|
| 16 | } |
|---|
| 17 | function pmpro_wp_ajax_authnet_silent_post() |
|---|
| 18 | { |
|---|
| 19 | require_once(dirname(__FILE__) . "/../services/authnet-silent-post.php"); |
|---|
| 20 | exit; |
|---|
| 21 | } |
|---|
| 22 | add_action('wp_ajax_nopriv_authnet_silent_post', 'pmpro_wp_ajax_authnet_silent_post'); |
|---|
| 23 | add_action('wp_ajax_authnet_silent_post', 'pmpro_wp_ajax_authnet_silent_post'); |
|---|
| 24 | function pmpro_wp_ajax_getfile() |
|---|
| 25 | { |
|---|
| 26 | require_once(dirname(__FILE__) . "/../services/getfile.php"); |
|---|
| 27 | exit; |
|---|
| 28 | } |
|---|
| 29 | add_action('wp_ajax_nopriv_getfile', 'pmpro_wp_ajax_getfile'); |
|---|
| 30 | add_action('wp_ajax_getfile', 'pmpro_wp_ajax_getfile'); |
|---|
| 31 | function pmpro_wp_ajax_ipnhandler() |
|---|
| 32 | { |
|---|
| 33 | require_once(dirname(__FILE__) . "/../services/ipnhandler.php"); |
|---|
| 34 | exit; |
|---|
| 35 | } |
|---|
| 36 | add_action('wp_ajax_nopriv_ipnhandler', 'pmpro_wp_ajax_ipnhandler'); |
|---|
| 37 | add_action('wp_ajax_ipnhandler', 'pmpro_wp_ajax_ipnhandler'); |
|---|
| 38 | function pmpro_wp_ajax_stripe_webhook() |
|---|
| 39 | { |
|---|
| 40 | require_once(dirname(__FILE__) . "/../services/stripe-webhook.php"); |
|---|
| 41 | exit; |
|---|
| 42 | } |
|---|
| 43 | add_action('wp_ajax_nopriv_stripe_webhook', 'pmpro_wp_ajax_stripe_webhook'); |
|---|
| 44 | add_action('wp_ajax_stripe_webhook', 'pmpro_wp_ajax_stripe_webhook'); |
|---|
| 45 | function pmpro_wp_ajax_braintree_webhook() |
|---|
| 46 | { |
|---|
| 47 | require_once(dirname(__FILE__) . "/../services/braintree-webhook.php"); |
|---|
| 48 | exit; |
|---|
| 49 | } |
|---|
| 50 | add_action('wp_ajax_nopriv_braintree_webhook', 'pmpro_wp_ajax_braintree_webhook'); |
|---|
| 51 | add_action('wp_ajax_braintree_webhook', 'pmpro_wp_ajax_braintree_webhook'); |
|---|
| 52 | function pmpro_wp_ajax_twocheckout_ins() |
|---|
| 53 | { |
|---|
| 54 | require_once(dirname(__FILE__) . "/../services/twocheckout-ins.php"); |
|---|
| 55 | exit; |
|---|
| 56 | } |
|---|
| 57 | add_action('wp_ajax_nopriv_twocheckout-ins', 'pmpro_wp_ajax_twocheckout_ins'); |
|---|
| 58 | add_action('wp_ajax_twocheckout-ins', 'pmpro_wp_ajax_twocheckout_ins'); |
|---|
| 59 | function pmpro_wp_ajax_memberlist_csv() |
|---|
| 60 | { |
|---|
| 61 | require_once(dirname(__FILE__) . "/../adminpages/memberslist-csv.php"); |
|---|
| 62 | exit; |
|---|
| 63 | } |
|---|
| 64 | add_action('wp_ajax_memberslist_csv', 'pmpro_wp_ajax_memberlist_csv'); |
|---|
| 65 | function pmpro_wp_ajax_orders_csv() |
|---|
| 66 | { |
|---|
| 67 | require_once(dirname(__FILE__) . "/../adminpages/orders-csv.php"); |
|---|
| 68 | exit; |
|---|
| 69 | } |
|---|
| 70 | add_action('wp_ajax_orders_csv', 'pmpro_wp_ajax_orders_csv'); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * Handles the Visits, Views and Logins Export |
|---|
| 75 | */ |
|---|
| 76 | function pmpro_wp_ajax_login_report_csv() { |
|---|
| 77 | require_once(dirname(__FILE__) . "/../adminpages/login-csv.php"); |
|---|
| 78 | exit; |
|---|
| 79 | } |
|---|
| 80 | add_action('wp_ajax_login_report_csv', 'pmpro_wp_ajax_login_report_csv'); |
|---|
| 81 | |
|---|
| 82 | /** |
|---|
| 83 | * Handles the Sales Export |
|---|
| 84 | */ |
|---|
| 85 | function pmpro_wp_ajax_sales_report_csv() { |
|---|
| 86 | require_once(dirname(__FILE__) . "/../adminpages/sales-csv.php"); |
|---|
| 87 | exit; |
|---|
| 88 | } |
|---|
| 89 | add_action('wp_ajax_sales_report_csv', 'pmpro_wp_ajax_sales_report_csv'); |
|---|
| 90 | |
|---|
| 91 | /** |
|---|
| 92 | * Handles the Membership Stats Export |
|---|
| 93 | */ |
|---|
| 94 | function pmpro_wp_ajax_membership_stats_csv() { |
|---|
| 95 | require_once(dirname(__FILE__) . "/../adminpages/memberships-csv.php"); |
|---|
| 96 | exit; |
|---|
| 97 | } |
|---|
| 98 | add_action('wp_ajax_membership_stats_csv', 'pmpro_wp_ajax_membership_stats_csv'); |
|---|
| 99 | |
|---|
| 100 | /** |
|---|
| 101 | * Load the Orders print view. |
|---|
| 102 | * |
|---|
| 103 | * @since 1.8.6 |
|---|
| 104 | */ |
|---|
| 105 | function pmpro_orders_print_view() { |
|---|
| 106 | require_once(dirname(__FILE__) . "/../adminpages/orders-print.php"); |
|---|
| 107 | exit; |
|---|
| 108 | } |
|---|
| 109 | add_action('wp_ajax_pmpro_orders_print_view', 'pmpro_orders_print_view'); |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Get order JSON. |
|---|
| 113 | * |
|---|
| 114 | * @since 1.8.6 |
|---|
| 115 | * @since 2.9.10 - Only returns a subset of data. Only email is really used. |
|---|
| 116 | */ |
|---|
| 117 | function pmpro_get_order_json() { |
|---|
| 118 | // only admins can get this |
|---|
| 119 | if ( ! function_exists( 'current_user_can' ) || ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'pmpro_orders' ) ) ) { |
|---|
| 120 | die( esc_html__( 'You do not have permissions to perform this action.', 'paid-memberships-pro' ) ); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | $order_id = intval( $_REQUEST['order_id'] ); |
|---|
| 124 | $order = new MemberOrder($order_id); |
|---|
| 125 | $user = get_userdata($order->user_id); |
|---|
| 126 | |
|---|
| 127 | $r = array( |
|---|
| 128 | 'id' => (int)$order->id, |
|---|
| 129 | 'user_id' => (int)$order->user_id, |
|---|
| 130 | 'membership_id' => (int)$order->membership_id, |
|---|
| 131 | 'code' => esc_html( $order->code ), |
|---|
| 132 | 'Email' => sanitize_email( empty( $user->user_email ) ? '' : $user->user_email ), |
|---|
| 133 | ); |
|---|
| 134 | |
|---|
| 135 | echo wp_json_encode($r); |
|---|
| 136 | exit; |
|---|
| 137 | } |
|---|
| 138 | add_action('wp_ajax_pmpro_get_order_json', 'pmpro_get_order_json'); |
|---|
| 139 | |
|---|
| 140 | function pmpro_update_level_order() { |
|---|
| 141 | // only admins can get this |
|---|
| 142 | if ( ! function_exists( 'current_user_can' ) || ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'pmpro_membershiplevels' ) ) ) { |
|---|
| 143 | die( esc_html__( 'You do not have permissions to perform this action.', 'paid-memberships-pro' ) ); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | // Check the nonce. |
|---|
| 147 | if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'pmpro_update_level_order' ) ) { |
|---|
| 148 | die( esc_html__( 'You do not have permissions to perform this action.', 'paid-memberships-pro' ) ); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | $level_order = null; |
|---|
| 152 | |
|---|
| 153 | if ( isset( $_REQUEST['level_order'] ) && is_array( $_REQUEST['level_order'] ) ) { |
|---|
| 154 | $level_order = array_map( 'intval', $_REQUEST['level_order'] ); |
|---|
| 155 | $level_order = implode(',', $level_order ); |
|---|
| 156 | } else if ( isset( $_REQUEST['level_order'] ) ) { |
|---|
| 157 | $level_order = sanitize_text_field( $_REQUEST['level_order'] ); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | echo esc_html( update_option('pmpro_level_order', $level_order) ); |
|---|
| 161 | exit; |
|---|
| 162 | } |
|---|
| 163 | add_action('wp_ajax_pmpro_update_level_order', 'pmpro_update_level_order'); |
|---|
| 164 | |
|---|
| 165 | function pmpro_update_level_group_order() { |
|---|
| 166 | // only admins can get this |
|---|
| 167 | if ( ! function_exists( 'current_user_can' ) || ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'pmpro_membershiplevels' ) ) ) { |
|---|
| 168 | die( esc_html__( 'You do not have permissions to perform this action.', 'paid-memberships-pro' ) ); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | // Check the nonce. |
|---|
| 172 | if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'pmpro_update_level_group_order' ) ) { |
|---|
| 173 | die( esc_html__( 'You do not have permissions to perform this action.', 'paid-memberships-pro' ) ); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | $level_group_order = null; |
|---|
| 177 | |
|---|
| 178 | if ( isset( $_REQUEST['level_group_order'] ) && is_array( $_REQUEST['level_group_order'] ) ) { |
|---|
| 179 | $level_group_order = array_map( 'intval', $_REQUEST['level_group_order'] ); |
|---|
| 180 | } else if ( isset( $_REQUEST['level_group_order'] ) ) { |
|---|
| 181 | $level_group_order = explode(',', sanitize_text_field( $_REQUEST['level_group_order'] ) ); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | $count = 1; |
|---|
| 185 | foreach ( $level_group_order as $level_group_id ) { |
|---|
| 186 | $level_group = pmpro_get_level_group( $level_group_id ); |
|---|
| 187 | if ( ! empty( $level_group ) ) { |
|---|
| 188 | pmpro_edit_level_group( $level_group_id, $level_group->name, $level_group->allow_multiple_selections, $count ); |
|---|
| 189 | } |
|---|
| 190 | $count++; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | exit; |
|---|
| 194 | } |
|---|
| 195 | add_action('wp_ajax_pmpro_update_level_group_order', 'pmpro_update_level_group_order'); |
|---|
| 196 | |
|---|
| 197 | // User fields AJAX. |
|---|
| 198 | /** |
|---|
| 199 | * Callback to draw a field group. |
|---|
| 200 | */ |
|---|
| 201 | function pmpro_userfields_get_group_ajax() { |
|---|
| 202 | pmpro_get_field_group_html(); |
|---|
| 203 | exit; |
|---|
| 204 | } |
|---|
| 205 | add_action( 'wp_ajax_pmpro_userfields_get_group', 'pmpro_userfields_get_group_ajax' ); |
|---|
| 206 | |
|---|
| 207 | /** |
|---|
| 208 | * Callback to draw a field. |
|---|
| 209 | */ |
|---|
| 210 | function pmpro_userfields_get_field_ajax() { |
|---|
| 211 | pmpro_get_field_html(); |
|---|
| 212 | exit; |
|---|
| 213 | } |
|---|
| 214 | add_action( 'wp_ajax_pmpro_userfields_get_field', 'pmpro_userfields_get_field_ajax' ); |
|---|