| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | +namespace WPDeveloper\BetterDocs\Shortcodes; | |
| 2 | 3 | |
| 3 | -namespace WPDeveloper\BetterDocs\Shortcodes; | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 4 | 7 | |
| 8 | + | |
| 5 | 9 | use WPDeveloper\BetterDocs\Core\Query; |
| 6 | 10 | use WPDeveloper\BetterDocs\Utils\Helper; |
| 7 | 11 | use WPDeveloper\BetterDocs\Core\Settings; |
| 8 | 12 | use WPDeveloper\BetterDocs\Core\Shortcode; |
| @@ -26,15 +30,19 @@ | ||
| 26 | 30 | return ['betterdocs']; |
| 27 | 31 | } |
| 28 | 32 | |
| 29 | 33 | public function submit() { |
| 34 | + if ( ! betterdocs()->settings->get( 'email_feedback' ) ) { | |
| 35 | + wp_send_json_error( __( 'Email feedback is disabled.', 'betterdocs' ) ); | |
| 36 | + } | |
| 37 | + | |
| 30 | 38 | check_ajax_referer( 'betterdocs_submit_data', 'security' ); |
| 31 | 39 | |
| 32 | - $postID = isset( $_POST['postID'] ) ? $_POST['postID'] : null; | |
| 40 | + $postID = isset( $_POST['postID'] ) ? absint( wp_unslash( $_POST['postID'] ) ) : 0; | |
| 33 | 41 | $article = get_the_title( $postID ); |
| 34 | - $name = isset( $_POST['message_name'] ) ? sanitize_text_field( stripslashes( $_POST['message_name'] ) ) : ''; | |
| 35 | - $email = isset( $_POST['message_email'] ) ? sanitize_email( stripslashes( $_POST['message_email'] ) ) : ''; | |
| 36 | - $message_text = isset( $_POST['message_text'] ) ? sanitize_textarea_field( stripslashes( $_POST['message_text'] ) ) : ''; | |
| 42 | + $name = isset( $_POST['message_name'] ) ? sanitize_text_field( wp_unslash( $_POST['message_name'] ) ) : ''; | |
| 43 | + $email = isset( $_POST['message_email'] ) ? sanitize_email( wp_unslash( $_POST['message_email'] ) ) : ''; | |
| 44 | + $message_text = isset( $_POST['message_text'] ) ? sanitize_textarea_field( wp_unslash( $_POST['message_text'] ) ) : ''; | |
| 37 | 45 | |
| 38 | 46 | $_errors = []; |
| 39 | 47 | |
| 40 | 48 | //validate presence of name |
| @@ -75,13 +83,16 @@ | ||
| 75 | 83 | 'success' => true |
| 76 | 84 | ]; |
| 77 | 85 | |
| 78 | 86 | ob_start(); |
| 79 | - betterdocs()->views->get( 'admin/email/feedback-email', [ | |
| 80 | - 'name' => $name, | |
| 81 | - 'article' => $article, | |
| 82 | - 'message_text' => $message_text | |
| 83 | - ] ); | |
| 87 | + betterdocs()->views->get( | |
| 88 | + 'admin/email/feedback-email', | |
| 89 | + [ | |
| 90 | + 'name' => $name, | |
| 91 | + 'article' => $article, | |
| 92 | + 'message_text' => $message_text | |
| 93 | + ] | |
| 94 | + ); | |
| 84 | 95 | $message = ob_get_clean(); |
| 85 | 96 | |
| 86 | 97 | // @todo: check strip tags: wp_mail( $to, $subject, strip_tags( $message ), $headers ) |
| 87 | 98 | |
| @@ -104,9 +115,12 @@ | ||
| 104 | 115 | * @return array |
| 105 | 116 | */ |
| 106 | 117 | public function default_attributes() { |
| 107 | 118 | return [ |
| 108 | - 'button_text' => __( 'Send', 'betterdocs' ) | |
| 119 | + 'button_text' => __( 'Send', 'betterdocs' ), | |
| 120 | + 'feedback_form_name_label_text' => __( 'Name:', 'betterdocs' ), | |
| 121 | + 'feedback_form_email_label_text' => __( 'Email:', 'betterdocs' ), | |
| 122 | + 'feedback_form_message_label_text' => __( 'Message:', 'betterdocs' ) | |
| 109 | 123 | ]; |
| 110 | 124 | } |
| 111 | 125 | |
| 112 | 126 | public function render( $atts, $content = null ) { |