Sử dụng form wp_editor() để nhập dữ liệu songkhoe.vinmec.com (ok)

https://developer.wordpress.org/reference/functions/wp_editor/

Một ví dụ mới: C:\xampp\htdocs\billbusiness\wp-content\themes\gutener-child\buddypress\activity\post-form.php

<?php  
	$content = isset( $_GET['r'] )  ?  $_GET['r']  : "";
	$editor_id = "whats-new";
	$args = array(
    'tinymce'       => array(
        'toolbar1'      => 'bold,italic,underline,separator,alignleft,aligncenter,alignright,separator,link,unlink,undo,redo,styleselect,forecolor,outdent,indent,image',
    ),
    'media_buttons' => true
	);
	wp_editor( $content, $editor_id, $args );
?>

Kết quả:

<?php  
    $content   = (!empty($data) && !empty($data[0]->content_answer)) ? $data[0]->content_answer : "";
    $editor_id = 'comment-content';
    $settings  = array( 'media_buttons' => true);
    wp_editor( $content, $editor_id, $settings );
?>
let comment_content = tinyMCE.activeEditor.getContent();

C:\xampp\htdocs\oec\src\wp-content\themes\ecademy-child\edit-ask-question.php

<?php
/** Load WordPress Bootstrap */
if (empty($_REQUEST['movie']) || empty(get_wp_comments($_REQUEST['movie']))) {
    wp_die( 'Sorry, you are not allowed to access this page.' );
}
$data = get_comment_user(wp_unslash( $_REQUEST['movie'] ));
?>
<div>
    <?php if ($data[0]->comment_parent == 0) { ?>
        <form name="post" action="comment.php" method="post" id="post">
            <div class="wrap">
                <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
                <div id="poststuff">
                    <div id="post-body" class="metabox-holder columns-2">
                        <div id="post-body-content" class="edit-form-section edit-comment-section">
                            <div id="reply-content" class="stuffbox">
                                <div class="inside">
                                    <h2 class="edit-comment-author">Reply ask question</h2>
                                    <fieldset>
                                        <legend class="screen-reader-text">reply ask question</legend>
                                        <table class="form-table editcomment" role="presentation">
                                            <tbody>
                                            <tr>
                                                <td class="first" style="width: 10px; white-space: nowrap;"><label for="lecturers">Information lecturers</label></td>
                                                <td>
                                                    <select name="lecturers" class="lecturers" style="width: 24%">
                                                        <?php
                                                        $arg = array(
                                                            'role' => 'lp_teacher',
                                                            'meta_query' => array(
                                                                array(
                                                                    'key' => 'belong_to_vinmex',
                                                                    'value' => 1,
                                                                    'compare' => '=='
                                                                ),
                                                                array(
                                                                    'key' => 'instructor_questions',
                                                                    'value' => 1,
                                                                    'compare' => '=='
                                                                ),
                                                            )
                                                        );
                                                        foreach (get_users( $arg ) as $teacher) :
                                                            ?>
                                                            <option data-name="<?php echo $teacher->first_name; ?>" data-value="<?php echo $teacher->designation_name; ?>" value="<?php echo $teacher->id; ?>" <?php if (!empty($data) && $data[0]->doctor_id == $teacher->id) { echo 'selected'; }  ?>>
                                                                <?php echo $teacher->user_login; ?>
                                                            </option>
                                                        <?php
                                                        endforeach;
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width: 10%" class="first" style="width: 10px; white-space: nowrap;"><label for="lecturers">Content question</label></td>
                                                <td style="width: 50%">
                                                    <p><strong><?php echo $data[0]->content_question; ?></strong></p>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="first" style="width: 10px; white-space: nowrap;"><label for="comment_content">Content answer </label></td>
                                                <td>
                                                    
                                                    <?php  
                                                        $content   = (!empty($data) && !empty($data[0]->content_answer)) ? $data[0]->content_answer : "";
                                                        $editor_id = 'comment-content';
                                                        $settings  = array( 'media_buttons' => true);
                                                        wp_editor( $content, $editor_id, $settings );
                                                    ?>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </fieldset>
                                </div>
                            </div>

                            <input type="hidden" name="comment_id" value="<?php echo wp_unslash( $_REQUEST['movie'] ); ?>">
                            <input type="hidden" name="url" value="<?php menu_page_url( 'ask-question' ); ?>">
                            <input type="hidden" name="nonce" value="<?php echo wp_create_nonce("ask_question_nonce"); ?>">
                            <input type="hidden" name="customer_comment_id" value="<?php echo !empty($data) ? $data[0]->id : ''; ?>">
                            <input type="hidden" name="comment_edit_id" value="<?php echo (!empty($data) && !empty($data[0]->comment_edit_id)) ? $data[0]->comment_edit_id : ''; ?>">
                            <input type="hidden" name="content_question" value="<?php echo !empty($data) ? $data[0]->content_question : ''; ?>">
                            <input type="hidden" name="comments_user_id" value="<?php echo !empty($data) ? $data[0]->comments_user_id : ''; ?>">
                            <input type="hidden" name="customer_name" value="<?php echo !empty($data) ? $data[0]->comment_author : ''; ?>">
                            <input type="hidden" name="customer_email" value="<?php echo !empty($data) ? $data[0]->comment_author_email : ''; ?>">
                            <input type="hidden" name="lesson_name" value="<?php echo !empty($data) ? $data[0]->post_title : ''; ?>">
                            <?php $course_id = getCourseIdByLesson($data[0]->comment_post_ID)[0]->section_course_id;?>
                            <input type="hidden" name="course_name" value="<?php echo !empty($data) ? get_post_title($course_id)[0]->post_title : ''; ?>">
                            <input type="hidden" name="lesson_url" value="<?php echo get_permalink($course_id) . str_replace(home_url('/'), '', get_permalink($data[0]->comment_post_ID)); ?>">


                        </div><!-- /post-body-content -->
                        <div style="text-align: center">
                            <button style="height: 40px;line-height: 40px;padding-top: 0;padding-bottom: 0;text-transform: uppercase;border-radius: 8px;border: none;font-size: 14px;width: 180px;background-color: #337ab7;color: white;" class="btn-save-ask-question" type="button">Save</button>
                        </div>

                    </div><!-- /post-body -->
                </div>
            </div>
        </form>
    <?php } else { ?>
        <p>Đây không phải câu hỏi của người dùng.</p>
    <?php } ?>
</div>
<script>
    jQuery(document).on('click', '.btn-save-ask-question', function (e) {
        jQuery(this).attr("disabled", 'disabled');

        let comment_id = jQuery('input[name="comment_id"]').val();
        let customer_comment_id = jQuery('input[name="customer_comment_id"]').val();
        let comment_edit_id = jQuery('input[name="comment_edit_id"]').val();
        let lecturers = jQuery('select[name="lecturers"]').val();
        // let comment_content = jQuery('#comment-content').val();
        let comment_content = tinyMCE.activeEditor.getContent();
        let nonce = jQuery('input[name="nonce"]').val();
        let designation_name = jQuery('.lecturers option').attr('data-value');
        let full_name = jQuery('.lecturers option').attr('data-name');
        let content_question = jQuery('input[name="content_question"]').val();
        let customer_name = jQuery('input[name="customer_name"]').val();
        let customer_email = jQuery('input[name="customer_email"]').val();
        let lesson_name = jQuery('input[name="lesson_name"]').val();
        let course_name = jQuery('input[name="course_name"]').val();
        let lesson_url = jQuery('input[name="lesson_url"]').val();
        let comments_user_id = jQuery('input[name="comments_user_id"]').val();

        jQuery.ajax({
            url: ajaxurl,
            type: "post",
            data: {
                'action': 'ask_question',
                'nonce': nonce,
                'comment_id': comment_id,
                'customer_comment_id': customer_comment_id,
                'comment_edit_id': comment_edit_id,
                'lecturers': lecturers,
                'comment_content': comment_content,
                'content_question': content_question,
                'designation_name': designation_name,
                'full_name': full_name,
                'customer_name': customer_name,
                'customer_email': customer_email,
                'lesson_name': lesson_name,
                'course_name': course_name,
                'lesson_url': lesson_url,
                'comments_user_id': comments_user_id,
            },
            success: function (response) {
                if(response.data.result == 'success') {
                    window.location = jQuery('input[name="url"]').val();
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log('Error');
            }
        });
    });

</script>

Last updated