File manager - Edit - /home/monara/public_html/efm_web/wp-content/plugins/Radio chart request/Radio-chart-request-plugin.php
Back
<?php /* Plugin Name: Radio Chart Song Request Description: Allow users to request songs with styled design matching the radio chart. Version: 1.2 Author: Your Name */ // -------------------- // Create DB Table // -------------------- function rcr_create_table() { global $wpdb; $table_name = $wpdb->prefix . 'radio_requests'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, name varchar(100) NOT NULL, song varchar(200) NOT NULL, message text, created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } register_activation_hook(__FILE__, 'rcr_create_table'); // -------------------- // Shortcode Form // -------------------- function rcr_request_form() { ob_start(); ?> <div class="radio-chart-wrap"> <h2 class="radio-chart-title">🎵 Request a Song</h2> <form id="radioRequestForm" class="radio-chart-item"> <input type="text" name="name" placeholder="Your Name" required> <input type="text" name="song" placeholder="Song Title" required> <textarea name="message" placeholder="Your Message"></textarea> <button type="submit" class="radio-btn">Send Request</button> </form> <div id="requestResponse" class="radio-response"></div> </div> <style> .radio-chart-wrap { max-width: 700px; margin: 20px auto; padding: 20px; background: #d10015; border-radius: 15px; box-shadow: 0 3px 8px rgba(0,0,0,0.25); color: #fff; } .radio-chart-title { text-align: center; font-size: 1.5rem; margin-bottom: 15px; } #radioRequestForm { display: flex; flex-direction: column; gap: 10px; } #radioRequestForm input, #radioRequestForm textarea { padding: 10px; border: none; border-radius: 8px; font-size: 1rem; width: 100%; } #radioRequestForm button.radio-btn { background: #fff; color: #d10015; border: none; padding: 12px; font-weight: bold; cursor: pointer; border-radius: 8px; transition: 0.3s; } #radioRequestForm button.radio-btn:hover { background: #222; color: #fff; } .radio-response { margin-top: 15px; font-weight: bold; text-align: center; } </style> <script> jQuery(document).ready(function($){ $('#radioRequestForm').on('submit', function(e){ e.preventDefault(); var formData = $(this).serializeArray(); formData.push({ name: 'action', value: 'rcr_submit_request' }); $.post('<?php echo admin_url('admin-ajax.php'); ?>', formData, function(response){ if(response.success){ $('#requestResponse').html('<span style="color:lightgreen;">✅ ' + response.data + '</span>'); $('#radioRequestForm')[0].reset(); } else { $('#requestResponse').html('<span style="color:yellow;">⚠️ ' + response.data + '</span>'); } }); }); }); </script> <?php return ob_get_clean(); } add_shortcode('radio_request', 'rcr_request_form'); // -------------------- // AJAX Handler // -------------------- function rcr_submit_request() { global $wpdb; $table_name = $wpdb->prefix . 'radio_requests'; $name = sanitize_text_field($_POST['name'] ?? ''); $song = sanitize_text_field($_POST['song'] ?? ''); $message = sanitize_textarea_field($_POST['message'] ?? ''); if (empty($name) || empty($song)) { wp_send_json_error('Name and Song are required.'); } $inserted = $wpdb->insert($table_name, [ 'name' => $name, 'song' => $song, 'message' => $message, 'created_at' => current_time('mysql') ]); if ($inserted) { wp_send_json_success('Your request has been sent!'); } else { wp_send_json_error('Database error, please try again.'); } } add_action('wp_ajax_rcr_submit_request', 'rcr_submit_request'); add_action('wp_ajax_nopriv_rcr_submit_request', 'rcr_submit_request'); // -------------------- // Admin Page // -------------------- function rcr_admin_menu() { add_menu_page('Song Requests', 'Song Requests', 'manage_options', 'radio-requests', 'rcr_admin_page'); } add_action('admin_menu', 'rcr_admin_menu'); function rcr_admin_page() { global $wpdb; $table_name = $wpdb->prefix . 'radio_requests'; $results = $wpdb->get_results("SELECT * FROM $table_name ORDER BY created_at DESC"); echo '<div class="wrap"><h2>Song Requests</h2>'; if ($results) { echo '<table class="widefat"><thead><tr><th>Name</th><th>Song</th><th>Message</th><th>Date</th></tr></thead><tbody>'; foreach($results as $row){ echo "<tr><td>{$row->name}</td><td>{$row->song}</td><td>{$row->message}</td><td>{$row->created_at}</td></tr>"; } echo '</tbody></table>'; } else { echo '<p>No requests yet.</p>'; } echo '</div>'; }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings