/** * Shortcode for zeen101's Leaky Paywall * Prints out the zeen101's Leaky Paywall * * @since CHANGEME */ function do_leaky_paywall_profile($atts) { $settings = get_leaky_paywall_settings(); $mode = 'off' === $settings['test_mode'] ? 'live' : 'test'; $defaults = array(); // Merge defaults with passed atts // Extract (make each array element its own PHP var $args = shortcode_atts($defaults, $atts); extract($args); $results = ''; if (is_user_logged_in()) { $sites = array(''); global $blog_id; if (is_multisite_premium()) { if (!is_main_site($blog_id)) { $sites = array('_all', '_' . $blog_id); } else { $sites = array('_all', '_' . $blog_id, ''); } } $user = wp_get_current_user(); $results .= sprintf(__('<p>Welcome %s, you are currently logged in. <a href="%s">Click here to log out.</a></p>', 'issuem-leaky-paywall'), $user->user_login, wp_logout_url(get_page_link($settings['page_for_login']))); //Your Subscription $results .= '<h2>' . __('Your Subscription', 'issuem-leaky-paywall') . '</h2>'; $results .= apply_filters('leaky_paywall_profile_your_subscription_start', ''); $results .= '<table>'; $results .= '<thead>'; $results .= '<tr>'; $results .= ' <th>' . __('Status', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Type', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Payment Method', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Expiration', 'issuem-leaky-paywall') . '</th>'; $results .= ' <th>' . __('Cancel?', 'issuem-leaky-paywall') . '</th>'; $results .= '</tr>'; $results .= '</thead>'; foreach ($sites as $site) { $status = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true); $level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); $level_id = apply_filters('get_leaky_paywall_users_level_id', $level_id, $user, $mode, $site); $level_id = apply_filters('get_leaky_paywall_subscription_level_level_id', $level_id); if (false === $level_id || empty($settings['levels'][$level_id]['label'])) { $level_name = __('Undefined', 'issuem-leaky-paywall'); } else { $level_name = stripcslashes($settings['levels'][$level_id]['label']); } $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); $expires = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true); $expires = apply_filters('do_leaky_paywall_profile_shortcode_expiration_column', $expires, $user, $mode, $site, $level_id); if (empty($expires) || '0000-00-00 00:00:00' === $expires) { $expires = __('Never', 'issuem-leaky-paywall'); } else { $date_format = get_option('date_format'); $expires = mysql2date($date_format, $expires); } $plan = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_plan' . $site, true); if (!empty($plan) && 'Canceled' !== $plan && 'Never' !== $expires) { $expires = sprintf(__('Recurs on %s', 'issuem-leaky-paywall'), $expires); } $paid = leaky_paywall_has_user_paid($user->user_email, $site); if ('subscription' === $paid) { $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); $cancel = sprintf(__('<a href="%s">cancel</a>', 'issuem-leaky-paywall'), '?cancel&payment_gateway=' . $payment_gateway . '&subscriber_id=' . $subscriber_id); } else { $cancel = ' '; } if (!empty($status) && !empty($level_name) && !empty($payment_gateway) && !empty($expires)) { $results .= '<tbody>'; $results .= ' <td>' . ucfirst($status) . '</td>'; $results .= ' <td>' . $level_name . '</td>'; $results .= ' <td>' . leaky_paywall_translate_payment_gateway_slug_to_name($payment_gateway) . '</td>'; $results .= ' <td>' . $expires . '</td>'; $results .= ' <td>' . $cancel . '</td>'; $results .= '</tbody>'; } } $results .= '</table>'; $results .= apply_filters('leaky_paywall_profile_your_subscription_end', ''); //Your Mobile Devices include_once ABSPATH . 'wp-admin/includes/plugin.php'; if (is_plugin_active('unipress-api/unipress-api.php')) { global $unipress_api; $results .= '<h2>' . __('Your Mobile Devices', 'issuem-leaky-paywall') . '</h2>'; $results .= '<p>' . __('To generate a token for the mobile app, click the "Add New Mobile Device" button below.', 'issuem-leaky-paywall') . '</p>'; $results .= apply_filters('leaky_paywall_profile_your_mobile_devices_start', ''); $results .= $unipress_api->leaky_paywall_subscriber_info_paid_subscriber_end(''); $results .= apply_filters('leaky_paywall_profile_your_mobile_devices_end', ''); } //Your Profile $results .= '<h2>' . __('Your Profile', 'issuem-leaky-paywall') . '</h2>'; if (!empty($_POST['leaky-paywall-profile-nonce'])) { if (wp_verify_nonce($_POST['leaky-paywall-profile-nonce'], 'leaky-paywall-profile')) { try { $userdata = get_userdata($user->ID); $args = array('ID' => $user->ID, 'user_login' => $userdata->user_login, 'display_name' => $userdata->display_name, 'user_email' => $userdata->user_email); if (!empty($_POST['username'])) { $args['user_login'] = $_POST['username']; } if (!empty($_POST['displayname'])) { $args['display_name'] = $_POST['displayname']; } if (!empty($_POST['email'])) { if (is_email($_POST['email'])) { $args['user_email'] = $_POST['email']; } else { throw new Exception(__('Invalid email address.', 'issuem-leaky-paywall')); } } if (!empty($_POST['password1']) && !empty($_POST['password2'])) { if ($_POST['password1'] === $_POST['password2']) { wp_set_password($_POST['password1'], $user->ID); } else { throw new Exception(__('Passwords do not match.', 'issuem-leaky-paywall')); } } $user_id = wp_update_user($args); if (is_wp_error($user_id)) { throw new Exception($user_id->get_error_message()); } else { $user = get_userdata($user_id); //Refresh the user object $results .= '<p class="save">' . __('Profile Changes Saved.', 'issuem-leaky-paywall') . '</p>'; } } catch (Exception $e) { $results .= '<p class="error">' . $e->getMessage() . '</p>'; } } } $results .= apply_filters('leaky_paywall_profile_your_profile_start', ''); $results .= '<form id="leaky-paywall-profile" action="" method="post">'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-username">' . __('Username', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-username" name="username" value="' . $user->user_login . '" disabled="disabled" readonly="readonly" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-display-name">' . __('Display Name', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-display-name" name="displayname" value="' . $user->display_name . '" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-email">' . __('Email', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-email" name="email" value="' . $user->user_email . '" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-password1">' . __('New Password', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="password" class="issuem-leaky-paywall-field-input" id="leaky-paywall-password1" name="password1" value="" />'; $results .= '</p>'; $results .= '<p>'; $results .= '<label class="leaky-paywall-field-label" for="leaky-paywall-gift-subscription-password2">' . __('New Password (again)', 'issuem-leaky-paywall') . '</label>'; $results .= '<input type="password" class="issuem-leaky-paywall-field-input" id="leaky-paywall-gift-subscription-password2" name="password2" value="" />'; $results .= '</p>'; $results .= wp_nonce_field('leaky-paywall-profile', 'leaky-paywall-profile-nonce', true, false); $results .= '<p class="submit"><input type="submit" id="submit" class="button button-primary" value="' . __('Update Profile Information', 'issuem-leaky-paywall') . '" /></p>'; $results .= '</form>'; $results .= apply_filters('leaky_paywall_profile_your_profile_end', ''); $results .= '<div class="issuem-leaky-paywall-subscriber-info">'; if (false !== ($expires = leaky_paywall_has_user_paid())) { //Your Payment Information if (!empty($_POST['leaky-paywall-profile-stripe-cc-update-nonce'])) { if (wp_verify_nonce($_POST['leaky-paywall-profile-stripe-cc-update-nonce'], 'leaky-paywall-profile-stripe-cc-update')) { try { $secret_key = 'test' === $mode ? $settings['test_secret_key'] : $settings['live_secret_key']; foreach ($sites as $site) { $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); if (!empty($subscriber_id)) { break; } } $cu = Stripe_Customer::retrieve($subscriber_id); if (!empty($cu)) { if (true === $cu->deleted) { throw new Exception(__('Unable to find valid Stripe customer ID to unsubscribe. Please contact support', 'issuem-leaky-paywall')); } } if (empty($_POST['stripe-cc-number'])) { throw new Exception(__('Credit Card Number Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-exp-month'])) { throw new Exception(__('Credit Card Expiration Month Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-exp-year'])) { throw new Exception(__('Credit Card Expiration Year Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-cvc'])) { throw new Exception(__('Credit Card Security Code (CVC) Required', 'issuem-leaky-paywall')); } if (empty($_POST['stripe-cc-name'])) { throw new Exception(__("Credit Card Cardholder's Name Required", 'issuem-leaky-paywall')); } $subscriptions = $cu->subscriptions->all('limit=1'); foreach ($subscriptions->data as $susbcription) { $sub = $cu->subscriptions->retrieve($susbcription->id); $sub->card = array('number' => $_POST['stripe-cc-number'], 'exp_month' => $_POST['stripe-cc-exp-month'], 'exp_year' => $_POST['stripe-cc-exp-year'], 'cvc' => $_POST['stripe-cc-cvc'], 'name' => $_POST['stripe-cc-name']); $sub->save(); } $results .= '<p>' . __('Your credit card has been successfully updated.', 'issuem-leaky-paywall') . '</p>'; } catch (Exception $e) { $results = '<h1>' . sprintf(__('Error updating Credit Card information: %s', 'issuem-leaky-paywall'), $e->getMessage()) . '</h1>'; } } } $results .= apply_filters('leaky_paywall_profile_your_payment_info_start', ''); $results .= apply_filters('leaky_paywall_subscriber_info_paid_subscriber_start', ''); foreach ($sites as $site) { $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); $expires = leaky_paywall_has_user_paid($user->user_email, $site); if ('subscription' === $expires) { $payment_form = ''; switch ($payment_gateway) { case 'stripe': $payment_form .= '<h3>' . __('Update Credit Card', 'issuem-leaky-paywall') . '</h3>'; $payment_form .= '<form id="leaky-paywall-update-credit-card" action="" method="post">'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-number">' . __('Card Number', 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-number" name="stripe-cc-number" value="" placeholder="4242 4242 4242 4242" />'; $payment_form .= '</p>'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-expiration">' . __('Expiration Date', 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-exp-month" name="stripe-cc-exp-month" value="" placeholder="' . date_i18n('m', strtotime('+1 Month')) . '" />'; $payment_form .= ' / '; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-exp-year" name="stripe-cc-exp-year" value="" placeholder="' . date_i18n('Y', strtotime('+1 Year')) . '" />'; $payment_form .= '</p>'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-cvc">' . __('Security Code (CVC)', 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-cvc" name="stripe-cc-cvc" value="" placeholder="777" />'; $payment_form .= '</p>'; $payment_form .= '<p>'; $payment_form .= '<label class="lp-field-label" for="leaky-paywall-cc-name">' . __("Cardholder's Name", 'issuem-leaky-paywall') . '</label>'; $payment_form .= '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-cc-name" name="stripe-cc-name" value="" placeholder="John Doe" />'; $payment_form .= '</p>'; $payment_form .= wp_nonce_field('leaky-paywall-profile-stripe-cc-update', 'leaky-paywall-profile-stripe-cc-update-nonce', true, false); $payment_form .= '<p class="submit"><input type="submit" id="submit" class="button button-primary" value="' . __('Update Credit Card Information', 'issuem-leaky-paywall') . '" /></p>'; $payment_form .= '</form>'; break; case 'paypal-standard': case 'paypal_standard': $paypal_url = 'test' === $mode ? 'https://www.sandbox.paypal.com/' : 'https://www.paypal.com/'; $paypal_email = 'test' === $mode ? $settings['paypal_sand_email'] : $settings['paypal_live_email']; $payment_form .= '<p>' . __("You can update your payment details through PayPal's website.", 'issuem-leaky-paywall') . '</p>'; $payment_form .= '<p><a href="' . $paypal_url . '"><img src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_pponly_142x27.png" border="0"></a></p>'; break; } $results .= '<h2>' . __('Your Payment Information', 'issuem-leaky-paywall') . '</h2>'; $results .= $payment_form; break; //We only want the first match } } } else { $results .= '<h2>' . __('Your Account is Not Currently Active', 'issuem-leaky-paywall') . '</h2>'; $results .= '<p>' . sprintf(__('To reactivate your account, please visit our <a href="%s">Subscription page</a>.', 'issuem-leaky-paywall'), get_page_link($settings['page_for_subscription'])) . '</p>'; } $results .= '</div>'; $results .= apply_filters('leaky_paywall_profile_your_payment_info_end', ''); } else { $results .= do_leaky_paywall_login(array()); } return $results; }
function display_rows() { global $current_site, $blog_id; $settings = get_leaky_paywall_settings(); if (is_multisite_premium()) { global $blog_id; if (!is_main_site($blog_id)) { $sites = array('_all', '_' . $blog_id); } else { $sites = array('_all', '_' . $blog_id, ''); } } else { // create a generic array so that single site installs will iterate through the sites loop below $sites = array('_all'); } $alt = ''; foreach ($this->items as $user) { $user = get_user_by('email', $user->user_email); $mode = 'off' === $settings['test_mode'] ? 'live' : 'test'; foreach ($sites as $site) { $alt = 'alternate' == $alt ? '' : 'alternate'; if (is_multisite_premium()) { $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); } else { $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway', true); } if (empty($payment_gateway)) { continue; } ?> <tr class="<?php echo $alt; ?> "> <?php list($columns, $hidden) = $this->get_column_info(); foreach ($columns as $column_name => $column_display_name) { $class = "class='{$column_name} column-{$column_name}'"; $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } $attributes = "{$class}{$style}"; switch ($column_name) { case 'wp_user_login': echo "<td {$attributes}>"; ?> <strong><?php echo $user->user_login; ?> </strong> </td> <?php break; case 'email': $avatar = get_avatar($user->user_email, 32); $edit_link = esc_url(add_query_arg('edit', urlencode($user->user_email))); echo "<td {$attributes}>"; ?> <?php echo $avatar; ?> <strong><a href="<?php echo $edit_link; ?> " class="edit"><?php echo $user->user_email; ?> </a></strong> </td> <?php break; case 'level_id': if (is_multisite_premium()) { $level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); } else { $level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id', true); } $level_id = apply_filters('get_leaky_paywall_users_level_id', $level_id, $user, $mode, $site); $level_id = apply_filters('get_leaky_paywall_subscription_level_level_id', $level_id); if (false === $level_id || empty($settings['levels'][$level_id]['label'])) { $level_name = __('Undefined', 'issuem-leaky-paywall'); } else { $level_name = stripcslashes($settings['levels'][$level_id]['label']); } echo "<td {$attributes}>" . $level_name . '</td>'; break; case 'susbcriber_id': if (is_multisite_premium()) { echo "<td {$attributes}>" . get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true) . '</td>'; } else { echo "<td {$attributes}>" . get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id', true) . '</td>'; } break; case 'price': if (is_multisite_premium()) { echo "<td {$attributes}>" . number_format((double) get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_price' . $site, true), '2') . '</td>'; } else { echo "<td {$attributes}>" . number_format((double) get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_price', true), '2') . '</td>'; } break; case 'plan': if (is_multisite_premium()) { $plan = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_plan' . $site, true); } else { $plan = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_plan', true); } if (empty($plan)) { $plan = __('Non-Recurring', 'issuem-leaky-paywall'); } else { if ('paypal_standard' === $payment_gateway || 'paypal-standard' === $payment_gateway) { $plan = sprintf(__('Recurring every %s', 'issuem-leaky-paywall'), str_replace(array('D', 'W', 'M', 'Y'), array('Days', 'Weeks', 'Months', 'Years'), $plan)); } } echo "<td {$attributes}>" . $plan . '</td>'; break; case 'created': if (is_multisite_premium()) { $created = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_created' . $site, true); } else { $created = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_created', true); } $created = apply_filters('do_leaky_paywall_profile_shortcode_created_column', $created, $user, $mode, $site, $level_id); $date_format = get_option('date_format'); $created = mysql2date($date_format, $created); echo "<td {$attributes}>" . $created . '</td>'; break; case 'expires': if (is_multisite_premium()) { $expires = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true); } else { $expires = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires', true); } $expires = apply_filters('do_leaky_paywall_profile_shortcode_expiration_column', $expires, $user, $mode, $site, $level_id); if (empty($expires) || '0000-00-00 00:00:00' === $expires || 'Never' === $expires) { $expires = __('Never', 'issuem-leaky-paywall'); } else { $date_format = get_option('date_format'); $expires = mysql2date($date_format, $expires); } echo "<td {$attributes}>" . $expires . '</td>'; break; case 'gateway': echo "<td {$attributes}>" . leaky_paywall_translate_payment_gateway_slug_to_name($payment_gateway) . '</td>'; break; case 'status': if (is_multisite_premium()) { echo "<td {$attributes}>" . get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true) . '</td>'; } else { echo "<td {$attributes}>" . get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status', true) . '</td>'; } break; default: echo "<td {$attributes}>" . apply_filters('manage_leaky_paywall_subscribers_custom_column', ' ', $column_name, $user->ID) . '</td>'; break; } } } ?> </tr> <?php } }