function wpinventory_process_reserve($data) { $to_email = wpinventory_get_config('reserve_email'); if (!$to_email) { $to_email = get_option('admin_email'); } $subject = WPIMCore::__('An item has been reserved from') . ' ' . get_bloginfo('site_name'); $message = ''; $fields = array('inventory_number', 'inventory_serial', 'inventory_name'); $fields = apply_filters('wpim_reserve_item_fields', $fields); $item_title = WPIMCore::__('Item Details'); $item_title = apply_filters('wpim_reserve_title_item_details', $item_title); $message .= PHP_EOL . $item_title; $inventory_display = wpinventory_get_display_settings('detail'); if (!empty($data['inventory_id'])) { $loop = new WPIMLoop(array('inventory_id' => $data['inventory_id'])); while ($loop->have_items()) { $loop->the_item(); foreach ($inventory_display as $field) { $message .= PHP_EOL . $loop->get_label($field) . ': ' . $loop->get_field($field); } } } $reservation_title = WPIMCore::__('Reservation Details'); $reservation_title = apply_filters('wpim_reserve_title_reservation_details', $reservation_title); $message .= PHP_EOL . PHP_EOL . $reservation_title; $exclude = array('inventory_id'); $exclude = apply_filters('wpim_reserve_exclude_form_fields', $exclude); $args = wpinventory_get_reserve_config(); foreach ($data as $field => $d) { if (!in_array($field, $exclude) && $args['display_' . $field]) { $message .= PHP_EOL . $d['label'] . ': ' . $d['value']; } } $subject = apply_filters('wpim_reserve_email_subject', $subject); $message = apply_filters('wpim_reserve_email_message', $message); $status = FALSE; $test_mode = FALSE; if ($test_mode) { echo '<br>== E-Mail output (in test mode) ==<br>'; echo '<pre>'; echo 'To: ' . $to_email . PHP_EOL; echo 'Subject: ' . $subject . PHP_EOL; echo 'Message:' . PHP_EOL; echo $message; echo '</pre>'; } $success = wp_mail($to_email, $subject, $message); if (!$success) { return WPIMCore::__('There was an issue sending your e-mail. Please try again later.'); } else { if (wpinventory_get_config('reserve_decrement')) { $wpim_item = new WPIMItem(); $wpim_item->save_reserve($data['inventory_id'], $data['quantity']['value']); do_action('wpim_reserve_sent', $data['inventory_id'], $data, $subject, $message); $status = TRUE; } } $send_confirmation = wpinventory_get_config('reserve_confirmation'); if ($send_confirmation) { // Grab e-mail from the form $confirm_email = $data['email']['value']; // If the user is logged in, use that e-mail if (is_user_logged_in()) { $current_user = wp_get_current_user(); $confirm_email = $current_user->user_email; } $subject = apply_filters('wpim_reserve_confirmation_email_subject', $subject); $message = apply_filters('wpim_reserve_confirmation_email_message', $message); if ($test_mode) { echo '<br>== E-Mail Confirmation output (in test mode) ==<br>'; echo '<pre>'; echo 'To: ' . $confirm_email . PHP_EOL; echo 'Subject: ' . $subject . PHP_EOL; echo 'Message:' . PHP_EOL; echo $message; echo '</pre>'; } $success = wp_mail($confirm_email, $subject, $message); if (!$success) { return WPIMCore::__('There was an issue sending the confirmation e-mail. Please try again later.'); } else { do_action('wpim_reserve_confirmation_sent', $data['inventory_id'], $data, $subject, $message); $status = TRUE; } } return $status; }
public static function activate($data, $key) { // data to send in our API request if (!$data) { $item_name = self::REG_ITEM_NAME; $item_key = 'core'; } else { $item_name = $data->item_name; $item_key = $data->key; } $api_params = array('edd_action' => 'activate_license', 'license' => $key, 'item_name' => urlencode($item_name), 'url' => home_url()); $response = wp_remote_post(self::API_URL, array('timeout' => 15, 'sslverify' => FALSE, 'body' => $api_params)); if (is_wp_error($response)) { // Try again with post $response = wp_remote_get(add_query_arg($api_params, self::API_URL), array('timeout' => 15, 'sslverify' => FALSE)); if (is_wp_error($response)) { echo '<div class="error"><p>' . WPIMCore::__('When attempting to activate license, could not reach license site.') . '</p></div>'; return FALSE; } } if (!$response) { echo '<div class="error"><p>' . WPIMCore::__('When attempting to activate license, no response was received.') . '</p></div>'; } else { if (wp_remote_retrieve_response_code($response) != 200) { echo '<div class="error"><p>' . sprintf(WPIMCore::__('When attempting to activate license, a response code of %d was returned.'), wp_remote_retrieve_response_code($response)) . '</p>'; echo '<p><strong>Debugging Information: Please provide the information below to support.</strong></p>'; var_dump($response); echo '</div>'; } else { $response = json_decode(wp_remote_retrieve_body($response)); if ($response->license != 'valid') { echo '<div class="error"><p>' . sprintf(WPIMCore::__('The license entered for %s is invalid.'), $item_name) . '</p></div>'; $key = array('key' => '', 'expires' => NULL, 'valid' => FALSE); } else { echo '<div class="updated"><p>' . sprintf(WPIMCore::__('Congratulations! The %s license entered is valid.'), $item_name); if ($item_key != 'core') { echo ' <a href="' . admin_url('admin.php?page=manage_settings') . '">' . sprintf(WPIMCore::__('(Click to refresh if %s is not visible.)'), $item_name) . '</a>'; } echo '</p></div>'; $key = array('key' => $key, 'expires' => strtotime($response->expires), 'valid' => TRUE); } } $all_reg_info = WPIMCore::get_reg_info(); $all_reg_info[$item_key] = $key; update_option('wpim_license', $all_reg_info); } }
function form($instance) { $default = array('title' => WPIMCore::__('Latest Items'), 'page_id' => '', 'category_id' => '', 'number' => '4'); $instance = wp_parse_args((array) $instance, $default); $WPIMCategories = new WPIMCategory(); $categories = $WPIMCategories->get_all(array('order' => 'sort_order')); $categories_array = array('' => WPIMCore::__('Show All')); foreach ($categories as $cat) { $categories_array[$cat->category_id] = $cat->category_name; } $category_select = WPIMCore::dropdown_array($this->get_field_name('category_id'), $instance['category_id'], $categories_array); echo '<p><label for="' . $this->get_field_name('title') . '">' . WPIMCore::__('Widget Title') . '</label> <input type="text" class="widefat" name="' . $this->get_field_name('title') . '" value="' . $instance['title'] . '" /></p>'; echo '<p><label for="' . $this->get_field_name('number') . '">' . WPIMCore::__('Number of Items') . '</label> <input type="text" class="small-text" name="' . $this->get_field_name('number') . '" value="' . $instance['number'] . '" /></p>'; echo '<p><label for="' . $this->get_field_name('page_id') . '">' . WPIMCore::__('Links to Page') . '</label> ' . wp_dropdown_pages('echo=0&name=' . $this->get_field_name('page_id') . '&selected=' . $instance['page_id'] . '&show_option_none=' . WPIMCore::__('Select...')) . '</p>'; echo '<p><label for="' . $this->get_field_name('category_id') . '">' . WPIMCore::__('Category') . '</label> ' . $category_select . '</p>'; }