Deprecated
This function has been deprecated. This function is replaced by a new method @see AP_Form_Hooks::submit_question_form() instead.
ap_save_question( array $args, bool $wp_error = false )
Description #
Insert and update question.
Parameters #
- $argsarray (Required) Question arguments.
- $wp_errorbool (Optional) Return wp error. Default value: false
Source #
File: includes/deprecated.php
function ap_save_question( $args, $wp_error = false ) {
_deprecated_function( __FUNCTION__, '4.1.0', 'AP_Form_Hooks::submit_question_form()' );
if ( isset( $args['is_private'] ) && $args['is_private'] ) {
$args['post_status'] = 'private_post';
}
$args = wp_parse_args(
$args, array(
'post_author' => -1,
'post_status' => 'publish',
'post_name' => '',
'comment_status' => 'open',
)
);
// Check if question title is empty.
if ( empty( $args['post_title'] ) ) {
if ( true === $wp_error ) {
return new WP_Error( 'question_title_empty', __( 'Question title cannot be blank', 'anspress-question-answer' ) );
}
return false;
}
/** This filter is documented in includes\class-form-hooks.php */
$args['post_content'] = apply_filters( 'ap_form_contents_filter', $args['post_content'] );
$args['post_name'] = ap_remove_stop_words_post_name( $args['post_name'] );
$args['post_type'] = 'question';
if ( isset( $args['ID'] ) ) {
/** This filter is documented in includes\class-form-hooks.php */
$args = apply_filters( 'ap_pre_update_question', $args );
} else {
/** This filter is documented in includes\class-form-hooks.php */
$args = apply_filters( 'ap_pre_insert_question', $args );
}
$post_id = wp_insert_post( $args, true );
if ( true === $wp_error && is_wp_error( $post_id ) ) {
return $post_id;
}
if ( $post_id ) {
$qameta_args = [ 'last_updated' => current_time( 'mysql' ) ];
if ( isset( $args['anonymous_name'] ) && ap_opt( 'allow_anonymous' ) ) {
$qameta_args['fields'] = [ 'anonymous_name' => $args['anonymous_name'] ];
}
ap_insert_qameta( $post_id, $qameta_args );
$activity_type = isset( $args['ID'] ) ? 'edit_question' : 'new_question';
// Add question activity meta.
ap_update_post_activity_meta( $post_id, $activity_type, get_current_user_id() );
if ( ap_isset_post_value( 'ap-medias' ) ) {
$ids = ap_sanitize_unslash( 'ap-medias', 'r' );
ap_set_media_post_parent( $ids, $post_id );
}
}
return $post_id;
}
Expand full source code Collapse full source code View on GitHub: includes/deprecated.php:149
Add your comment