Exemplo n.º 1
0
 /**
  * Handles an ajax request to update a section's title
  *
  * @todo refactor to use exceptions and one json response vs pepper-style
  */
 public static function update_title_ajax()
 {
     Core\check_elevated_ajax_referer();
     $title = isset($_POST['title']) ? sanitize_text_field($_POST['title']) : false;
     if (!$title) {
         Core\send_json_error(['message' => __('Please enter a section name.', 'eight-day-week')]);
     }
     $post_id = isset($_POST['post_id']) ? sanitize_text_field($_POST['post_id']) : false;
     if (!$post_id) {
         Core\send_json_error(['message' => __('Whoops! This section appears to be invalid.', 'eight-day-week')]);
     }
     try {
         self::update_title($title, $post_id);
     } catch (\Exception $e) {
         Core\send_json_error(['message' => $e->getMessage()]);
     }
     Core\send_json_success();
 }
Exemplo n.º 2
0
/**
 * Handles a request to edit articles' status
 * @todo refactor into pattern so that json functions are higher up, and the handler throws exceptions insteads
 */
function bulk_edit_article_statuses_ajax()
{
    Core\check_elevated_ajax_referer();
    $term_id = absint($_POST['status']);
    $article_ids = $_POST['checked_articles'];
    //sanitize - only allow comma delimited integers
    if (!ctype_digit(str_replace(',', '', $article_ids))) {
        \Eight_Day_Week\Core\send_json_error(['message' => __('Invalid article IDs specified in the request.', 'eight-day-week')]);
    }
    $article_ids = explode(',', $article_ids);
    try {
        bulk_edit_article_statuses($term_id, $article_ids);
    } catch (\Exception $e) {
        \Eight_Day_Week\Core\send_json_error(['message' => $e->getMessage()]);
    }
    \Eight_Day_Week\Core\send_json_success();
}