ap_set_selected_answer( integer $question_id, integer $answer_id )

Description #

Set selected answer for a question

Parameters #

  • $question_id
    integer (Required) Question ID.
  • $answer_id
    integer (Required) Answer ID.

Changelog #

VersionDescription
4.1.8Close question after selecting an answer.
4.1.2Insert activity to log.
3.1.0Introduced.

Source #

File: includes/qameta.php

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
function ap_set_selected_answer( $question_id, $answer_id ) {
    // Log to activity table.
    ap_activity_add(
        array(
            'q_id'   => $question_id,
            'a_id'   => $answer_id,
            'action' => 'selected',
        )
    );
 
    ap_insert_qameta(
        $answer_id,
        array(
            'selected'     => 1,
            'last_updated' => current_time( 'mysql' ),
        )
    );
 
    $q_args = array(
        'selected_id'  => $answer_id,
        'last_updated' => current_time( 'mysql' ),
    );
 
    // Close question if enabled in option.
    if ( ap_opt( 'close_selected' ) ) {
        $q_args['closed'] = 1;
    }
 
    ap_insert_qameta( $question_id, $q_args );
    $ret = ap_update_answer_selected( $answer_id );
 
    $_post = ap_get_post( $answer_id );
 
    /**
     * Trigger right after selecting an answer.
     *
     * @param WP_Post $_post       WordPress post object.
     * @param object  $answer_id   Answer ID.
     *
     * @since 4.1.8 Moved from ajax-hooks.php.
     */
    do_action( 'ap_select_answer', $_post, $question_id );
 
    return $ret;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment