ap_ask_form( null $deprecated = null )
Description #
Output new/edit question form.
Parameters #
- $deprecatednull (Optional) Deprecated argument. Default value: null
Changelog #
Source #
File: includes/functions.php
function ap_ask_form( $deprecated = null ) { if ( ! is_null( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '4.1.0', 'Use $_GET[id] for currently editing question ID.' ); } $editing = false; $editing_id = ap_sanitize_unslash( 'id', 'r' ); // If post_id is empty then its not editing. if ( ! empty( $editing_id ) ) { $editing = true; } if ( $editing && ! ap_user_can_edit_question( $editing_id ) ) { echo '<p>' . esc_attr__( 'You cannot edit this question.', 'anspress-question-answer' ) . '</p>'; return; } if ( ! $editing && ! ap_user_can_ask() ) { echo '<p>' . esc_attr__( 'You do not have permission to ask a question.', 'anspress-question-answer' ) . '</p>'; return; } $args = array( 'hidden_fields' => array( array( 'name' => 'action', 'value' => 'ap_form_question', ), ), ); $values = array(); $session_values = anspress()->session->get( 'form_question' ); // Add value when editing post. if ( $editing ) { $question = ap_get_post( $editing_id ); $form['editing'] = true; $form['editing_id'] = $editing_id; $form['submit_label'] = __( 'Update Question', 'anspress-question-answer' ); $values['post_title'] = $question->post_title; $values['post_content'] = $question->post_content; $values['is_private'] = 'private_post' === $question->post_status ? true : false; if ( isset( $values['anonymous_name'] ) ) { $fields = ap_get_post_field( 'fields', $question ); $values['anonymous_name'] = ! empty( $fields['anonymous_name'] ) ? $fields['anonymous_name'] : ''; } } elseif ( ! empty( $session_values ) ) { // Set last session values if not editing. $values = $session_values; } // Generate form. anspress()->get_form( 'question' )->set_values( $values )->generate( $args ); }
Expand full source code Collapse full source code View on GitHub: includes/functions.php:2039
Add your comment