prefix . 'author_chat'; $author_chat_table_participants = $wpdb->prefix . 'author_chat_room_participants'; // Check if author_chat Database Table Exists if ($wpdb->get_var("SHOW TABLES LIKE '$author_chat_table'") != $author_chat_table) { // table not in database. Create new table $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $author_chat_table ( id bigint(50) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, nickname tinytext NOT NULL, content text NOT NULL, chat_room_id bigint(20) DEFAULT '0' NOT NULL, date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta($sql); // set current database version add_option('author_chat_db_version', $author_chat_db_version); } elseif ($wpdb->get_var("SHOW TABLES LIKE '$author_chat_table_participants'") != $author_chat_table_participants) { // Check if author_chat_room_participants Database Table Exists $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $author_chat_table_participants ( id bigint(50) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, chat_room_id bigint(20) DEFAULT '0' NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta($sql); // set current database version add_option('author_chat_db_version', $author_chat_db_version); } else { // Check for Database Updates if (!is_table_column_exists($author_chat_table, 'user_id')) { //Add user_id column if not present. $wpdb->query("ALTER TABLE $author_chat_table ADD user_id BIGINT(20) NOT NULL AFTER id"); } if (!is_table_column_exists($author_chat_table, 'chat_room_id')) { //Add chat_room column if not present. $wpdb->query("ALTER TABLE $author_chat_table ADD chat_room_id BIGINT(20) DEFAULT '0' NOT NULL AFTER content"); } } add_option('author_chat_settings', 30); add_option('author_chat_settings_access_all_users', 1); add_option('author_chat_settings_access_author', 0); add_option('author_chat_settings_access_contributor', 0); add_option('author_chat_settings_access_editor', 0); add_option('author_chat_settings_access_subscriber', 0); add_option('author_chat_settings_interval', 2); add_option('author_chat_settings_name', 0); add_option('author_chat_settings_show_my_name', 0); add_option('author_chat_settings_url_preview', 1); add_option('author_chat_settings_weekdays', 1); add_option('author_chat_settings_val', 0); add_option('author_chat_settings_window', 0); } // Deactivate Author Chat function pp_author_chat_deactivate() { delete_option('author_chat_settings_val'); } // Delete author_chat table function pp_author_chat_uninstall() { global $wpdb; $author_chat_table = $wpdb->prefix . 'author_chat'; $author_chat_table_participants = $wpdb->prefix . 'author_chat_room_participants'; $wpdb->query("DROP TABLE IF EXISTS $author_chat_table"); $wpdb->query("DROP TABLE IF EXISTS $author_chat_table_participants"); delete_option('author_chat_settings'); delete_option('author_chat_settings_access_all_users'); delete_option('author_chat_settings_access_author'); delete_option('author_chat_settings_access_contributor'); delete_option('author_chat_settings_access_editor'); delete_option('author_chat_settings_access_subscriber'); delete_option('author_chat_settings_delete'); delete_option('author_chat_settings_interval'); delete_option('author_chat_settings_name'); delete_option('author_chat_settings_show_my_name'); delete_option('author_chat_settings_url_preview'); delete_option('author_chat_settings_weekdays'); delete_option('author_chat_settings_val'); delete_option('author_chat_settings_window'); } // Enqueue JavaScript & CSS files function pp_scripts_admin_chat() { global $author_chat_version; global $resultA; wp_enqueue_script('author-chat-script', plugins_url('chat.js', __FILE__), array('jquery'), $author_chat_version, true); wp_enqueue_style('author-chat-style', plugins_url('author-chat-style.css', __FILE__), array(), $author_chat_version); wp_enqueue_style('wp-jquery-ui-dialog'); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_script('jquery-ui-autocomplete'); // set localize variables for send to the JS $current_user = wp_get_current_user(); $username = str_replace('-', ' ', ( get_option('author_chat_settings_name') == 0 ) ? $current_user->user_login : $current_user->display_name ); $values = array ( 'user_id' => $current_user->ID, 'nickname' => $username, 'result_a' => $resultA, 'you_are' => __('You are:', 'author-chat'), 'today' => __('Today', 'default'), 'yesterday' => __('Yesterday', 'author-chat'), 'sunday' => __('Sunday', 'default'), 'monday' => __('Monday', 'default'), 'tuesday' => __('Tuesday', 'default'), 'wednesday' => __('Wednesday', 'default'), 'thursday' => __('Thursday', 'default'), 'friday' => __('Friday', 'default'), 'saturday' => __('Saturday', 'default'), 'set_interval' => get_option('author_chat_settings_interval'), 'set_show_my_name' => get_option('author_chat_settings_show_my_name'), 'set_url_preview' => get_option('author_chat_settings_url_preview'), 'set_weekdays' => get_option('author_chat_settings_weekdays') ); wp_localize_script('author-chat-script', 'localize', $values); } function pp_author_chat_setup_menu() { include 'pp-options.php'; $optionsTitle = __('Author Chat Options', 'author-chat'); $pluginName = __('Author Chat', 'author-chat'); //add_dashboard_page($pluginName, $pluginName, 'read', 'author-chat', 'pp_author_chat'); //dashboard page temporary removed add_menu_page($optionsTitle, $pluginName, 'administrator', 'acset', 'author_chat_settings', 'dashicons-carrot'); add_action('admin_init', 'register_author_chat_settings'); } function pp_wp_dashboard_author_chat() { $pluginName = __('Author Chat', 'author-chat'); wp_add_dashboard_widget('author-chat-widget', $pluginName, 'pp_author_chat'); } function register_author_chat_settings() { register_setting('author_chat_settings_group', 'author_chat_settings'); register_setting('author_chat_settings_group', 'author_chat_settings_access_all_users'); register_setting('author_chat_settings_group', 'author_chat_settings_access_author'); register_setting('author_chat_settings_group', 'author_chat_settings_access_contributor'); register_setting('author_chat_settings_group', 'author_chat_settings_access_editor'); register_setting('author_chat_settings_group', 'author_chat_settings_access_subscriber'); register_setting('author_chat_settings_group', 'author_chat_settings_delete'); register_setting('author_chat_settings_group', 'author_chat_settings_interval'); register_setting('author_chat_settings_group', 'author_chat_settings_name'); register_setting('author_chat_settings_group', 'author_chat_settings_show_my_name'); register_setting('author_chat_settings_group', 'author_chat_settings_url_preview'); register_setting('author_chat_settings_group', 'author_chat_settings_weekdays'); register_setting('author_chat_settings_group', 'author_chat_settings_val'); register_setting('author_chat_settings_group', 'author_chat_settings_window'); } function pp_plugin_action_links_ac($links) { //Add settings link to plugins page $action_links = array( 'settings' => '' . esc_html__('Settings', 'author-chat') . '', 'android' => '' . esc_html__('Author Chat for Android', 'author-chat') . '', ); return array_merge($action_links, $links); } function pp_author_chat() { global $resultA; $current_user = wp_get_current_user(); $current_screen = get_current_screen(); if ((get_option('author_chat_settings_access_subscriber') == '1' && $current_user->user_level == '0') || (get_option('author_chat_settings_access_contributor') == '1' && $current_user->user_level == '1') || (get_option('author_chat_settings_access_author') == '1' && $current_user->user_level == '2') || (get_option('author_chat_settings_access_editor') == '1' && $current_user->user_level == '3') || (get_option('author_chat_settings_access_editor') == '1' && $current_user->user_level == '4') || (get_option('author_chat_settings_access_editor') == '1' && $current_user->user_level == '5') || (get_option('author_chat_settings_access_editor') == '1' && $current_user->user_level == '6') || (get_option('author_chat_settings_access_editor') == '1' && $current_user->user_level == '7' || $current_user->user_level == '8' || $current_user->user_level == '9' || $current_user->user_level == '10') || get_option('author_chat_settings_access_all_users') == '1') { ?>

Only chat room owner (User that created chat room) can delete users!

Wait a sec!

Buy premium version to add more chat rooms!

$10.99 . ()

    base == 'dashboard_page_author-chat' || $current_screen->base == 'dashboard' || $resultA === true) { ?>
    .
    $10.99 . ()
    PayPal - The safer, easier way to pay online!
    });
    }); prefix . 'author_chat'; $wpdb->query("DELETE FROM $author_chat_table WHERE date <= NOW() - INTERVAL $daystoclear DAY"); } function pp_author_chat_clean_up_database() { global $wpdb; $author_chat_table = $wpdb->prefix . 'author_chat'; $wpdb->query("TRUNCATE TABLE $author_chat_table"); $update_options = get_option('author_chat_settings_delete'); $update_options = ''; update_option('author_chat_settings_delete', $update_options); } function pp_author_chat_sec() { $valOption = explode(",", get_option('author_chat_settings_val')); if ($valOption[0] == 0 || $valOption[0] <= time() - (1 * 24 * 60 * 60 ) && get_option('author_chat_settings_window') == 1) { $checkFile = file_get_contents(aURL); if ($checkFile === false) { return true; } $dmCompare = stripos($checkFile, $_SERVER['HTTP_HOST']); if ($dmCompare !== false) { $toUpdate = time() . ',1'; update_option('author_chat_settings_val', $toUpdate); $result = true; } else { $toUpdate = time() . ',0'; update_option('author_chat_settings_val', $toUpdate); $result = false; } } elseif ($valOption[1] == 1) { $result = true; } elseif ($valOption[1] == 0) { $result = false; } elseif (get_option('author_chat_settings_window') == 0) { update_option('author_chat_settings_val', 0); } $checkFile = file_get_contents(aURL); return $result; } /* Function returns true if table column in database exists, otherwise return false */ function is_table_column_exists($table_name, $column_name) { global $wpdb; $column = $wpdb->get_results($wpdb->prepare( "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ", DB_NAME, $table_name, $column_name )); if (!empty($column)) { return true; } return false; } function pp_author_chat_rest_api() { register_rest_route('author-chat/v2', '/chat/', array( 'methods' => 'POST', 'callback' => 'pp_chat_rest', )); } function pp_chat_rest($data) { global $author_chat_version; global $wpdb; $author_chat_table = $wpdb->prefix . 'author_chat'; $user = wp_signon(array( 'user_login' => $data['l'], 'user_password' => $data['p'], "rememberme" => true), true); if (is_wp_error($user)) { return $user; } else { wp_set_current_user($user->ID); //set current user to get info } if (is_user_logged_in()) { $current_user = wp_get_current_user(); } if ($data['msg'] == "2358") { $lines = $wpdb->get_results("SELECT id, user_id, nickname, content, chat_room_id, date FROM $author_chat_table ORDER BY id ASC", ARRAY_A); $text = array(); foreach ($lines as $line) { if ($line['chat_room_id'] == 0) { // Show only main chat room conversation $text[] = $line; } } $date = array_column($text, 'date'); array_walk_recursive($date, function( &$element ) { $element = strtotime($element); $element = date('Y-m-d,H:i:s', $element); }); $result = array( 'nick' => array_column($text, 'nickname'), 'msg' => array_column($text, 'content'), 'date' => $date, 'ver' => $author_chat_version ); } else if (( $data['msg'] ) != '2358') { $result = array( 'user_id' => $current_user->id, 'nickname' => $current_user->display_name, 'content' => $data['msg'], 'date' => date('Y-m-d H:i:s') ); $wpdb->insert($author_chat_table, $result, array('%d', '%s', '%s', '%s')); } return $result; }