投稿日:2017/12/26
プラグイン Quick Chat の仕組み
https://netaone.com/wp/quick-chat/
・wp_quick_chat_users のテーブルが作られる。
jsのajaxでアクションフックを動かしている模様。
https://netaone.com/wp/quick-chat/
DB
・wp_quick_chat_messages・wp_quick_chat_users のテーブルが作られる。
wordpress
wp_ajax_{action} で独自のアクションフック(複数)があり、jsのajaxでアクションフックを動かしている模様。
js
jQuery.post(
quick_chat.ajaxurl,{
action: 'quick-chat-ajax-new-message',
sys_mes: sys_mes,
message: message_text,
room: room_name
},
function(data) {
if(quick_chat.no_participation == 0 && data.no_participation == 1)
location.reload(true);
});
php
public function new_message_ajax_handler(){
global $wpdb;
$quick_chat_messages_table_name = $wpdb->prefix . 'quick_chat_messages';
if($this->user_status != 0)
$_POST['message'] = wp_kses(trim(stripslashes(substr($_POST['message'], 0, $this->options['message_maximum_number_chars']))),'');
else
$_POST['message'] = wp_kses(trim(stripslashes($_POST['message'])),'');
if($this->no_participation == 0 && $_POST['message'] != ''){
if($this->user_status != 0){
$_POST['message'] = $this->filter($_POST['message'], (isset($this->options['replace_inside_bad_words'])? true:false));
}
if(isset($this->options['hyperlinks'])){
$_POST['message'] = links_add_target(make_clickable($_POST['message']));
}
$wpdb->query('INSERT INTO '.$quick_chat_messages_table_name.' (wpid, room, timestamp, alias, status, ip, message) VALUES ( "'.$this->user_id.'", "'.esc_sql($_POST['room']).'", NOW(), "'.(($_POST['sys_mes'] == 'true') ? 'quick_chat': esc_sql($this->user_name)).'", '.$this->user_status.', "'.$this->user_ip.'", "'.esc_sql($_POST['message']).'");');
}
$response = json_encode(array('no_participation' => $this->no_participation));
header( "Content-Type: application/json" );
echo $response;
exit;
}
add_action( 'wp_ajax_quick-chat-ajax-new-message', array($this, 'new_message_ajax_handler'));
wordpressの初期設定をしているときの動作と同じ感じの模様。