/**
 * 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();
}
Beispiel #2
0
/**
 * Handler for an ajax request to get articles by title search
 */
function get_articles_ajax()
{
    $title = sanitize_text_field($_GET['title']);
    try {
        $articles = get_articles_autocomplete($title);
    } catch (\Exception $e) {
        \Eight_Day_Week\Core\send_json_error(['message' => $e->getMessage()]);
    }
    \Eight_Day_Week\Core\send_json_success(['articles' => $articles]);
}