// 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'); 1.0MoneyFund.comhttps://moneyfund.comMoneyFund.comhttps://moneyfund.com/author/moneyfund/Homepagerich600338<blockquote class="wp-embedded-content" data-secret="FhR4LPZhYD"><a href="https://moneyfund.com/">Homepage</a></blockquote><iframe sandbox="allow-scripts" security="restricted" src="https://moneyfund.com/embed/#?secret=FhR4LPZhYD" width="600" height="338" title="“Homepage” — MoneyFund.com" data-secret="FhR4LPZhYD" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe><script type="text/javascript"> /* <![CDATA[ */ /*! This file is auto-generated */ !function(d,l){"use strict";l.querySelector&&d.addEventListener&&"undefined"!=typeof URL&&(d.wp=d.wp||{},d.wp.receiveEmbedMessage||(d.wp.receiveEmbedMessage=function(e){var t=e.data;if((t||t.secret||t.message||t.value)&&!/[^a-zA-Z0-9]/.test(t.secret)){for(var s,r,n,a=l.querySelectorAll('iframe[data-secret="'+t.secret+'"]'),o=l.querySelectorAll('blockquote[data-secret="'+t.secret+'"]'),c=new RegExp("^https?:$","i"),i=0;i<o.length;i++)o[i].style.display="none";for(i=0;i<a.length;i++)s=a[i],e.source===s.contentWindow&&(s.removeAttribute("style"),"height"===t.message?(1e3<(r=parseInt(t.value,10))?r=1e3:~~r<200&&(r=200),s.height=r):"link"===t.message&&(r=new URL(s.getAttribute("src")),n=new URL(t.value),c.test(n.protocol))&&n.host===r.host&&l.activeElement===s&&(d.top.location.href=t.value))}},d.addEventListener("message",d.wp.receiveEmbedMessage,!1),l.addEventListener("DOMContentLoaded",function(){for(var e,t,s=l.querySelectorAll("iframe.wp-embedded-content"),r=0;r<s.length;r++)(t=(e=s[r]).getAttribute("data-secret"))||(t=Math.random().toString(36).substring(2,12),e.src+="#?secret="+t,e.setAttribute("data-secret",t)),e.contentWindow.postMessage({message:"ready",secret:t},"*")},!1)))}(window,document); /* ]]> */ </script> https://moneyfund.com/wp-content/uploads/moneyfund-xbanner.jpg600199