/**
  * Form processor.
  *
  * @since 141111 First documented version.
  *
  * @param array $request_args Incoming action request args.
  *
  * @see   SubManageActions::subForm()
  */
 public static function process(array $request_args)
 {
     $plugin = plugin();
     // Needed below.
     $args = ['process_confirmation' => true, 'user_initiated' => true, 'ui_protected_data_keys_enable' => true, 'ui_protected_data_user' => wp_get_current_user()];
     static::$processing = true;
     // Flag as `TRUE`; along w/ other statics below.
     if (isset($request_args['key'])) {
         // Key sanitizer; for added security.
         $request_args['key'] = $sub_key = $plugin->utils_sub->sanitizeKey($request_args['key']);
     }
     if (isset($request_args['ID'])) {
         // Updating an existing subscription via ID?
         $sub_updater = new SubUpdater($request_args, $args);
         // Run updater.
         if ($sub_updater->hasErrors()) {
             // Updater has errors?
             static::$processing_errors = $sub_updater->errors();
             static::$processing_error_codes = $sub_updater->errorCodes();
             static::$processing_errors_html = $sub_updater->errorsHtml();
         } elseif ($sub_updater->didUpdate()) {
             // Updated?
             static::$processing_successes = $sub_updater->successes();
             static::$processing_success_codes = $sub_updater->successCodes();
             static::$processing_successes_html = $sub_updater->successesHtml();
             static::$processing_email_key_change = $sub_updater->emailKeyChanged();
         }
     } elseif ($plugin->options['enable'] && $plugin->options['new_subs_enable']) {
         // This check is for added security only. The form should not be available.
         $sub_inserter = new SubInserter($request_args, $args);
         // Run inserter.
         if ($sub_inserter->hasErrors()) {
             // Inserter has errors?
             static::$processing_errors = $sub_inserter->errors();
             static::$processing_error_codes = $sub_inserter->errorCodes();
             static::$processing_errors_html = $sub_inserter->errorsHtml();
         } elseif ($sub_inserter->didInsert()) {
             // Inserted?
             static::$processing_successes = $sub_inserter->successes();
             static::$processing_success_codes = $sub_inserter->successCodes();
             static::$processing_successes_html = $sub_inserter->successesHtml();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Form processor.
  *
  * @since 141111 First documented version.
  *
  * @param array $request_args Incoming action request args.
  *
  * @see   MenuPageActions::subForm()
  */
 public static function process(array $request_args)
 {
     $plugin = plugin();
     // Needed below.
     if (!current_user_can($plugin->manage_cap)) {
         if (!current_user_can($plugin->cap)) {
             return;
             // Unauthenticated; ignore.
         }
     }
     $reporting_errors = false;
     // Initialize.
     $process_confirmation = !empty($request_args['process_confirmation']);
     $args = compact('process_confirmation');
     if (isset($request_args['ID'])) {
         // Updating an existing subscription via ID?
         $sub_updater = new SubUpdater($request_args, $args);
         // Run updater.
         if ($sub_updater->didUpdate()) {
             // Updated successfully?
             $plugin->enqueueUserNotice(sprintf(__('Subscription ID #<code>%1$s</code> updated successfully.', 'comment-mail'), esc_html($request_args['ID'])), ['transient' => true, 'for_page' => $plugin->utils_env->currentMenuPage()]);
             $redirect_to = $plugin->utils_url->pageTableNavVarsOnly();
         } else {
             // There were errors; display those errors to the current user.
             $plugin->enqueueUserError(sprintf(__('Failed to update subscription ID #<code>%1$s</code>. Please review the following error(s):', 'comment-mail'), esc_html($request_args['ID'])) . '<ul class="pmp-list-items"><li>' . implode('</li><li>', $sub_updater->errorsHtml()) . '</li></ul>', ['transient' => true, 'for_page' => $plugin->utils_env->currentMenuPage()]);
         }
     } else {
         // We are doing a new insertion; i.e. a new subscription is being added here.
         $sub_inserter = new SubInserter($request_args, $args);
         // Run inserter.
         if ($sub_inserter->didInsert()) {
             // Inserted successfully?
             $plugin->enqueueUserNotice(sprintf(__('Subscription ID #<code>%1$s</code> created successfully.', 'comment-mail'), esc_html($sub_inserter->insertId())), ['transient' => true, 'for_page' => $plugin->utils_env->currentMenuPage()]);
             $redirect_to = $plugin->utils_url->pageTableNavVarsOnly();
         } else {
             // There were errors; display those errors to the current user.
             $plugin->enqueueUserError(__('Failed to create new subscription. Please review the following error(s):', 'comment-mail') . '<ul class="pmp-list-items"><li>' . implode('</li><li>', $sub_inserter->errorsHtml()) . '</li></ul>', ['transient' => true, 'for_page' => $plugin->utils_env->currentMenuPage()]);
         }
     }
     if (!empty($redirect_to)) {
         // If applicable.
         if (headers_sent()) {
             // Output started already?
             exit('      <script type="text/javascript">' . "         document.getElementsByTagName('body')[0].style.display = 'none';" . "         location.href = '" . $plugin->utils_string->escJsSq($redirect_to) . "';" . '      </script>' . '   </body>' . '</html>');
         }
         wp_redirect($redirect_to);
         exit;
     }
 }
Ejemplo n.º 3
0
 /**
  * Trash subscription.
  *
  * @since 141111 First documented version.
  *
  * @param int|string $sub_id_or_key Subscription ID.
  * @param array      $args          Any additional behavioral args.
  *
  * @return bool|null TRUE if subscription is trashed successfully.
  *                   Or, FALSE if unable to trash (e.g. already trashed).
  *                   Or, NULL on complete failure (e.g. invalid ID or key).
  */
 public function trash($sub_id_or_key, array $args = [])
 {
     if (!$sub_id_or_key) {
         return null;
         // Not possible.
     }
     if (!($sub = $this->get($sub_id_or_key))) {
         return null;
         // Not possible.
     }
     if ($sub->status === 'deleted') {
         return null;
         // Not possible.
     }
     if ($sub->status === 'trashed') {
         return false;
         // Trashed already.
     }
     $updater = new SubUpdater(['ID' => $sub->ID, 'status' => 'trashed'], $args);
     return $updater->didUpdate();
 }