Skip to content

Commit

Permalink
Don't use ap_ajax action for question, answer and comment form.
Browse files Browse the repository at this point in the history
  • Loading branch information
rahularyan committed Nov 29, 2017
1 parent 2aa99ac commit 2a67d90
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 30 deletions.
4 changes: 2 additions & 2 deletions anspress-question-answer.php
Expand Up @@ -221,11 +221,11 @@ public static function instance() {
*/
do_action( 'anspress_loaded' );

self::$instance->setup_hooks();

if ( class_exists( 'WP_CLI' ) ) {
WP_CLI::add_command( 'anspress', 'AnsPress_Cli' );
}

self::$instance->setup_hooks();
} // End if().

return self::$instance;
Expand Down
9 changes: 6 additions & 3 deletions includes/ajax-hooks.php
Expand Up @@ -57,9 +57,12 @@ public static function init() {
anspress()->add_action( 'ap_ajax_subscribe', __CLASS__, 'subscribe_to_question' );
anspress()->add_action( 'ap_ajax_get_repeatable_field', __CLASS__, 'get_repeatable_field' );

anspress()->add_action( 'ap_ajax_form_question', 'AP_Form_Hooks', 'submit_question_form', 11 );
anspress()->add_action( 'ap_ajax_form_answer', 'AP_Form_Hooks', 'submit_answer_form', 11 );
anspress()->add_action( 'ap_ajax_form_comment', 'AP_Form_Hooks', 'submit_comment_form', 11 );
anspress()->add_action( 'wp_ajax_ap_form_question', 'AP_Form_Hooks', 'submit_question_form', 11, 0 );
anspress()->add_action( 'wp_ajax_nopriv_ap_form_question', 'AP_Form_Hooks', 'submit_question_form', 11, 0 );
anspress()->add_action( 'wp_ajax_ap_form_answer', 'AP_Form_Hooks', 'submit_answer_form', 11, 0 );
anspress()->add_action( 'wp_ajax_nopriv_ap_form_answer', 'AP_Form_Hooks', 'submit_answer_form', 11, 0 );
anspress()->add_action( 'wp_ajax_ap_form_comment', 'AP_Form_Hooks', 'submit_comment_form', 11, 0 );
anspress()->add_action( 'wp_ajax_nopriv_ap_form_comment', 'AP_Form_Hooks', 'submit_comment_form', 11, 0 );

}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-form-hooks.php
Expand Up @@ -317,7 +317,7 @@ public static function submit_question_form( $manual = false ) {
$_post = ap_get_post( $question_args['ID'] );

// Check if valid post type and user can edit.
if ( false === $manual && ( 'question' !== $_post->post_type || ! ap_user_can_edit_question( $_post ) ) ) {
if ( false !== $manual && ( 'question' !== $_post->post_type || ! ap_user_can_edit_question( $_post ) ) ) {
ap_ajax_json( 'something_wrong' );
}
}
Expand Down
21 changes: 6 additions & 15 deletions includes/functions.php
Expand Up @@ -1882,6 +1882,7 @@ function ap_set_in_array( &$arr, $path, $val ) {
*
* @since unknown
* @since 4.1.0 Moved from includes\ask-form.php. Deprecated first argument. Using new form class.
* @since 4.1.5 Don't use ap_ajax as action.
*/
function ap_ask_form( $deprecated = null ) {
if ( ! is_null( $deprecated ) ) {
Expand Down Expand Up @@ -1910,11 +1911,7 @@ function ap_ask_form( $deprecated = null ) {
'hidden_fields' => array(
array(
'name' => 'action',
'value' => 'ap_ajax',
),
array(
'name' => 'ap_ajax_action',
'value' => 'form_question',
'value' => 'ap_form_question',
),
),
);
Expand Down Expand Up @@ -2010,6 +2007,7 @@ function ap_answer_post_ajax_response( $question_id, $answer_id ) {
* @return void
* @since unknown
* @since 4.1.0 Moved from includes\answer-form.php. Using new Form class.
* @since 4.1.5 Don't use ap_ajax as action.
*/
function ap_answer_form( $question_id, $editing = false ) {
if ( ! ap_user_can_answer( $question_id ) ) {
Expand All @@ -2020,11 +2018,7 @@ function ap_answer_form( $question_id, $editing = false ) {
'hidden_fields' => array(
array(
'name' => 'action',
'value' => 'ap_ajax',
),
array(
'name' => 'ap_ajax_action',
'value' => 'form_answer',
'value' => 'ap_form_answer',
),
),
);
Expand All @@ -2040,6 +2034,7 @@ function ap_answer_form( $question_id, $editing = false ) {
* @return void
*
* @since 4.1.0
* @since 4.1.5 Don't use ap_ajax.
*/
function ap_comment_form( $post_id = false, $_comment = false ) {
if ( false === $post_id ) {
Expand All @@ -2058,11 +2053,7 @@ function ap_comment_form( $post_id = false, $_comment = false ) {
),
array(
'name' => 'action',
'value' => 'ap_ajax',
),
array(
'name' => 'ap_ajax_action',
'value' => 'form_comment',
'value' => 'ap_form_comment',
),
),
);
Expand Down
5 changes: 0 additions & 5 deletions includes/hooks.php
Expand Up @@ -618,11 +618,6 @@ public static function save_question_hooks( $post_id, $post, $updated ) {
$qameta = array(
'last_updated' => current_time( 'mysql' ),
'answers' => ap_count_published_answers( $post_id ),
'activities' => array(
'type' => $activity_type,
'user_id' => $post->post_author,
'date' => current_time( 'mysql' ),
),
);

// Check if anonymous post and have name.
Expand Down
2 changes: 1 addition & 1 deletion templates/css/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion templates/css/main.css.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions templates/scss/question.scss
Expand Up @@ -77,8 +77,7 @@
.ap-question-meta {
margin-bottom: 25px;
>.ap-display-meta-item {
display: table;
float: left;
display: inline-block;
margin-right: 20px;
&:last-child {
margin-right: 0;
Expand Down
3 changes: 3 additions & 0 deletions templates/scss/reset.scss
Expand Up @@ -363,3 +363,6 @@ ul{
background: #ffeeba;
}
}
.text-center {
text-align: center;
}

0 comments on commit 2a67d90

Please sign in to comment.