// Enqueue script for parent theme stylesheet function example_enqueue_styles() { wp_enqueue_style('parent-theme', get_template_directory_uri() . '/style.css'); wp_enqueue_style('child-theme', get_stylesheet_directory_uri() . '/style.css', array('parent-theme')); } add_action('wp_enqueue_scripts', 'example_enqueue_styles'); // Register AJAX actions for saving chat messages add_action('wp_ajax_save_chat_message', 'save_chat_message_to_db'); add_action('wp_ajax_nopriv_save_chat_message', 'save_chat_message_to_db'); function save_chat_message_to_db() { global $wpdb; // Get data from the AJAX request $name = sanitize_text_field($_POST['name']); $message = sanitize_textarea_field($_POST['message']); $image = $_FILES['image'] ?? null; // Adjusted to handle file upload $image_url = ''; // Process image upload if there is one if (!empty($image) && $image['error'] === UPLOAD_ERR_OK) { $upload_dir = wp_upload_dir(); // Get WordPress upload directory $image_path = $upload_dir['path'] . '/' . basename($image['name']); if (move_uploaded_file($image['tmp_name'], $image_path)) { // Save the URL instead of the image binary data $image_url = $upload_dir['url'] . '/' . basename($image['name']); } } // Save data into the custom table $table_name = $wpdb->prefix . 'chat_messages'; $result = $wpdb->insert( $table_name, [ 'name' => $name, 'message' => $message, 'image' => $image_url, // Store image URL 'timestamp' => current_time('mysql'), ] ); // Send a response if ($result) { wp_send_json_success('Message saved successfully'); } else { wp_send_json_error('Failed to save message'); } wp_die(); // Always terminate AJAX functions properly } // Register AJAX actions for retrieving chat messages add_action('wp_ajax_get_chat_messages', 'get_chat_messages'); add_action('wp_ajax_nopriv_get_chat_messages', 'get_chat_messages'); function get_chat_messages() { global $wpdb; $table_name = $wpdb->prefix . 'chat_messages'; // Fetch messages from the database, ordered by timestamp $messages = $wpdb->get_results("SELECT * FROM $table_name ORDER BY timestamp ASC"); // Send the messages as a JSON response wp_send_json_success($messages); wp_die(); } // Create the database table for storing chat messages function create_chat_messages_table() { global $wpdb; $table_name = $wpdb->prefix . 'chat_messages'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, name varchar(100) NOT NULL, message text NOT NULL, image text DEFAULT NULL, // Store image as a URL timestamp datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } add_action('after_setup_theme', 'create_chat_messages_table'); {"id":17,"date":"2024-11-26T23:43:24","date_gmt":"2024-11-26T23:43:24","guid":{"rendered":"https:\/\/zse.bcg.mybluehost.me\/?page_id=17"},"modified":"2024-11-27T03:19:34","modified_gmt":"2024-11-27T03:19:34","slug":"homepage","status":"publish","type":"page","link":"https:\/\/moneyfund.com\/","title":{"rendered":"Homepage"},"content":{"rendered":"","protected":false},"excerpt":{"rendered":"

[…]<\/p>\n

Read More…<\/a><\/p>\n","protected":false},"author":3,"featured_media":27,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"page-templates\/homepage.php","meta":{"nf_dc_page":"","footnotes":""},"class_list":["post-17","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/pages\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":2,"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/pages\/17\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/pages\/17\/revisions\/102"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/media\/27"}],"wp:attachment":[{"href":"https:\/\/moneyfund.com\/wp-json\/wp\/v2\/media?parent=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}