/
var
/
www
/
barefootlaw.org
/
wp-content
/
plugins
/
custom-file-downloader
/
Upload File
HOME
<?php function cfd_enqueue_scripts() { wp_enqueue_script('jquery'); // Make sure jQuery is loaded wp_enqueue_script('cfd-download-modal', plugin_dir_url(__FILE__) . 'js/download-modal.js', array('jquery'), '1.0', true); } add_action('wp_enqueue_scripts', 'cfd_enqueue_scripts'); function cfd_shortcode($atts) { // Shortcode attributes for file URL, etc. $atts = shortcode_atts( array( 'file_url' => '', // Default file URL ), $atts, 'custom_file_downloader' ); // Unique ID for multiple downloads on the same page $unique_id = uniqid('cfd_'); // Output the link and form ob_start(); ?> <a href="#" class="cfd_download_link" data-target="cfd_form_<?php echo $unique_id; ?>">Download File</a> <div id="cfd_form_<?php echo $unique_id; ?>" class="cfd_modal elementor-widget-wrap" style="display:none;"> <div class="cfd_modal_content elementor-element"> <div class="elementor-widget-container"> <form class="elementor-form" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post"> <input type="hidden" id="download_url" name="download_url" value="<?php echo $atts['file_url']; ?>"> <div class="elementor-field-type-text elementor-field-group elementor-column elementor-col-100"> <label for="cfd_name_<?php echo $unique_id; ?>">Name:</label> <input type="text" id="cfd_name_<?php echo $unique_id; ?>" name="cfd_name" required="required" class="elementor-field elementor-size-sm elementor-field-textual"> </div> <div class="elementor-field-type-select elementor-field-group elementor-column elementor-col-100"> <label for="cfd_gender_<?php echo $unique_id; ?>">Sex:</label> <select id="cfd_gender_<?php echo $unique_id; ?>" name="cfd_gender" required="required" class="elementor-field elementor-size-sm elementor-field-textual"> <option value="">Select Sex</option> <option value="female">Female</option> <option value="male">Male</option> </select> </div> <div class="elementor-field-group elementor-column elementor-col-100"> <button type="submit" class="elementor-button elementor-size-sm"> <span>Download</span> </button> </div> </form> </div> </div> </div> <style> .cfd_modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4); } .cfd_modal_content { background-color: #fefefe; margin: 15% auto; padding: 20px; border: 1px solid #888; width: 80%; } .cfd_close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .cfd_close:hover, .cfd_close:focus { color: black; text-decoration: none; cursor: pointer; } </style> <?php return ob_get_clean(); } add_action('init', 'custom_handle_form_submission'); function custom_handle_form_submission() { if ('POST' === $_SERVER['REQUEST_METHOD'] && !empty($_POST['cfd_name']) && !empty($_POST['cfd_gender'])) { // Process download $download_count = get_option('cfd_download_count', 0); update_option('cfd_download_count', ++$download_count); // Record submission (for your records, can be expanded) $submissions = get_option('cfd_submissions', array()); $submissions[] = array('name' => sanitize_text_field($_POST['cfd_name']), 'gender' => sanitize_text_field($_POST['cfd_gender']), 'date' => current_time('mysql')); update_option('cfd_submissions', $submissions); // Redirect to file URL wp_redirect($_POST['download_url']); exit; } } function cfd_register_admin_page() { add_menu_page( 'File Downloads', // Page title 'File Downloads', // Menu title 'manage_options', // Capability required 'cfd_file_downloads', // Menu slug 'cfd_display_admin_page', // Function to display the admin page 'dashicons-download', // Icon URL 6 // Position ); } add_action('admin_menu', 'cfd_register_admin_page'); function cfd_display_admin_page() { // Retrieve download data $submissions = get_option('cfd_submissions', array()); $download_count = get_option('cfd_download_count', 0); // Admin page layout echo '<div class="wrap">'; echo '<h1>File Download Submissions</h1>'; echo '<h2>Total Downloads: ' . esc_html($download_count) . '</h2>'; echo '<table class="wp-list-table widefat fixed striped">'; echo '<thead><tr><th>Name</th><th>Gender</th><th>Date</th></tr></thead>'; echo '<tbody>'; foreach ($submissions as $submission) { echo '<tr>'; echo '<td>' . esc_html($submission['name']) . '</td>'; echo '<td>' . esc_html($submission['gender']) . '</td>'; echo '<td>' . (isset($submission['date']) ? esc_html(date_i18n('F j, Y g:i a', strtotime($submission['date']))) : 'N/A') . '</td>'; echo '</tr>'; } echo '</tbody></table>'; echo '</div>'; } function my_custom_enqueue_styles() { wp_enqueue_style('my-custom-style', plugins_url('css/custom-style.css', __FILE__), array(), '1.0.0', 'all'); } add_action('wp_enqueue_scripts', 'my_custom_enqueue_styles');