Changeset 3237295
- Timestamp:
- 02/09/2025 11:37:54 AM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
confetti-fall-animation/trunk/confetti-fall-animation.php
r3201072 r3237295 3 3 /** 4 4 * @package confetti-fall-animation 5 * @version 1.3. 05 * @version 1.3.1 6 6 **/ 7 7 8 8 /* 9 9 Plugin Name: Confetti Fall Animation 10 Plugin URI: https:// rtoluxurycars.com11 Description: Add a delightful falling confetti animation to your website. Welcome your visitors on special occasions such as new year, birthdays, festivals, promotions, or any other special events.10 Plugin URI: https://wpdeveloperr.com/ 11 Description: Add a delightful falling confetti animation to your website. Welcome your visitors on special occasions such as new year, birthdays, festivals, promotions, or any other special events. 12 12 Author: WPDeveloperr 13 Author URI: https:// rtoluxurycars.com/14 Version: 1.3. 013 Author URI: https://wpdeveloperr.com/ 14 Version: 1.3.1 15 15 License: GPLv2 or later 16 16 Text Domain: confetti-fall-animation 17 */17 */ 18 18 19 19 defined('ABSPATH') or die('Hey, You can\'t access this directly.'); 20 20 21 /* --- */22 21 if (!function_exists("add_action")) { 23 22 exit; 24 23 } 25 /* --- */26 24 27 define(" cfa_dir_url", plugin_dir_url(__FILE__));28 define(" cfa_dir_path", plugin_dir_path(__FILE__));29 require_once cfa_dir_path. 'inc/popupBackgroundImage.php';30 require_once cfa_dir_path. 'inc/confetti_settings.php';25 define("CFA_DIR_URL", plugin_dir_url(__FILE__)); 26 define("CFA_DIR_PATH", plugin_dir_path(__FILE__)); 27 require_once CFA_DIR_PATH . 'inc/popupBackgroundImage.php'; 28 require_once CFA_DIR_PATH . 'inc/confetti_settings.php'; 31 29 32 /* --- */ 33 34 35 function cfa_enqueue_scripts(){ 36 30 function cfa_enqueue_scripts() { 37 31 wp_enqueue_script("jquery"); 38 wp_enqueue_script("confetti-js",cfa_dir_url . "assets/js/confetti.min.js"); 39 wp_enqueue_script("confetti-fall-animation",cfa_dir_url . "assets/js/confetti-fall-animation.js",array("jquery", "confetti-js")); 40 41 wp_enqueue_script('confetti-popup-script', cfa_dir_url . 'assets/js/popup-plugin.js', array('jquery'), '1.0', true); 42 // Define JavaScript variable 43 $delayInSeconds = get_option('confetti-popup-delay', 5); // Get delay time from WordPress settings 44 wp_localize_script('confetti-popup-script', 'delayPopupSettings', array( 45 'delayInSeconds' => $delayInSeconds 46 )); 47 wp_enqueue_style('custom-popup-style', cfa_dir_url . 'assets/css/popup-plugin.css', array(), '1.0'); 32 wp_enqueue_script("confetti-js", CFA_DIR_URL . "assets/js/confetti.min.js", array(), null, true); 33 wp_enqueue_script("confetti-fall-animation", CFA_DIR_URL . "assets/js/confetti-fall-animation.js", array("jquery", "confetti-js"), null, true); 34 35 wp_enqueue_script('confetti-popup-script', CFA_DIR_URL . 'assets/js/popup-plugin.js', array('jquery'), '1.0', true); 36 $delayInSeconds = intval(get_option('confetti-popup-delay', 5)); 37 wp_localize_script('confetti-popup-script', 'delayPopupSettings', array('delayInSeconds' => $delayInSeconds)); 38 39 wp_enqueue_style('custom-popup-style', CFA_DIR_URL . 'assets/css/popup-plugin.css', array(), '1.0'); 48 40 } 49 41 add_action("wp_enqueue_scripts", "cfa_enqueue_scripts"); 50 42 51 /* --- */ 52 function confetti_backend_scripts(){ 53 wp_register_style( 'confetti-style', cfa_dir_url . 'assets/css/popup-plugin.css', array(), '1.0', 'all' ); 54 wp_enqueue_style('confetti-style'); 55 43 function confetti_backend_scripts() { 44 wp_enqueue_style('confetti-style', CFA_DIR_URL . 'assets/css/popup-plugin.css', array(), '1.0', 'all'); 56 45 } 57 46 add_action('admin_enqueue_scripts', 'confetti_backend_scripts'); 58 47 59 /* --- */60 61 // Activation and deactivation hooks62 48 register_activation_hook(__FILE__, 'confetti_popup_activate'); 63 49 register_deactivation_hook(__FILE__, 'confetti_popup_deactivate'); 64 50 65 51 function confetti_popup_activate() { 66 // Set an option to indicate that the welcome message has not been shown67 52 add_option('confetti_welcome_shown', false); 68 53 } 69 54 70 function confetti_popup_deactivate() { 71 // Deactivation code here 55 function confetti_popup_deactivate() {} 56 57 add_action('admin_menu', 'confetti_menu_func'); 58 function confetti_menu_func() { 59 add_menu_page('CF Animation', 'CF Animation', 'manage_options', 'confetti-animation', 'confetti_animation_page', 'dashicons-buddicons-community', 50); 60 add_submenu_page('confetti-animation', 'Popup Settings', 'Popup Settings', 'manage_options', 'popup-settings', 'render_plugin_background_settings_page'); 72 61 } 73 62 74 75 // Add a menu item for the plugin settings 76 add_action('admin_menu', 'confetti_menu_func'); 77 78 function confetti_menu_func() { 79 $parent_url = 'confetti-animation'; 80 $icon_url = 'dashicons-buddicons-community'; 81 add_menu_page('CF Animation','CF Animation','manage_options', $parent_url,'confetti_animation_page', $icon_url, 50); 82 add_submenu_page( $parent_url, 'Popup Settings', 'Popup Settings', 'manage_options', 'popup-settings', 'render_plugin_background_settings_page'); 83 63 function confetti_animation_page() { 64 $confetti_settings = new Confetti_Settings(); 65 $confetti_settings->confetti_settings_page(); 84 66 } 85 67 86 // Define Setting for Confetti Animation 87 function confetti_animation_page(){ 88 $confetti_settings = new Confetti_Settings(); 89 $confetti_settings->confetti_settings_page(); 90 91 } 92 93 94 // Create settings fields and sections 68 add_action('admin_init', 'confetti_popup_settings'); 95 69 function confetti_popup_settings() { 96 // Add a section 97 add_settings_section('confetti-popup-general','General Settings','confetti_popup_general_section_callback','confetti-animation'); 98 // Add a field for the popup content 99 add_settings_field('confetti-popup-content','Add Popup Content','confetti_popup_content_callback','confetti-animation','confetti-popup-general'); 100 // Add a field for selecting pages 101 add_settings_field('confetti-popup-pages','Select Page to Display Popup','confetti_popup_pages_callback','confetti-animation','confetti-popup-general'); 102 // Add a field for setting the popup display time 103 add_settings_field('confetti-popup-delay','Popup Display Time (in seconds)','confetti_popup_delay_callback','confetti-animation','confetti-popup-general'); 104 // Register the setting for popup display time 70 add_settings_section('confetti-popup-general', 'General Settings', 'confetti_popup_general_section_callback', 'confetti-animation'); 71 add_settings_field('confetti-popup-content', 'Add Popup Content', 'confetti_popup_content_callback', 'confetti-animation', 'confetti-popup-general'); 72 add_settings_field('confetti-popup-pages', 'Select Page to Display Popup', 'confetti_popup_pages_callback', 'confetti-animation', 'confetti-popup-general'); 73 add_settings_field('confetti-popup-delay', 'Popup Display Time (in seconds)', 'confetti_popup_delay_callback', 'confetti-animation', 'confetti-popup-general'); 74 105 75 register_setting('confetti-animation', 'confetti-popup-delay'); 106 76 register_setting('confetti-animation', 'confetti-popup-content'); 107 77 register_setting('confetti-animation', 'confetti-popup-pages'); 108 78 } 109 // Create settings fields and sections110 add_action('admin_init', 'confetti_popup_settings');111 79 112 // Callback functions for settings fields113 80 function confetti_popup_general_section_callback() { 114 echo 'Configure the confetti popup settings.';81 echo esc_html__('Configure the confetti popup settings.', 'confetti-fall-animation'); 115 82 } 116 83 117 84 function confetti_popup_content_callback() { 118 85 $content = get_option('confetti-popup-content', ''); 119 $value = !empty($content) ? $content : '<h2>Welcome to Confetti Animation</h2>'; 120 echo '<textarea name="confetti-popup-content" rows="5" cols="50">' . esc_textarea($value) . '</textarea>'; 121 echo '<br><small>You can use html tags as well</small>'; 86 echo '<textarea name="confetti-popup-content" rows="5" cols="50">' . esc_textarea($content) . '</textarea>'; 122 87 } 123 88 124 function confetti_popup_pages_callback() {125 $pages = get_option('confetti-popup-pages', []);126 $all_pages = get_pages();127 128 echo '<select name="confetti-popup-pages[]">';129 echo '<option value="none"> None </option>';130 foreach ($all_pages as $page) {131 echo '<option value="' . esc_attr($page->ID) . '" ' . (in_array($page->ID, $pages) ? 'selected' : '') . '>' . esc_html($page->post_title) . '</option>';132 }133 echo '</select>';134 }135 89 function confetti_popup_display() { 136 90 $content = get_option('confetti-popup-content', ''); 137 $pages = get_option('confetti-popup-pages', []);91 $pages = array_map('intval', (array) get_option('confetti-popup-pages', [])); 138 92 139 93 if (in_array(get_the_ID(), $pages)) { 140 // Display the popup content here 141 ?> 142 <div id="confetti-popup" style="display: none;"> <?php echo wp_kses_post($content); ?> <a id="confetti-popup-close"> <i class="fa fa-close"></i>Close</a></div> 143 <?php 94 echo '<div id="confetti-popup" style="display: none;">' . esc_html($content) . ' <a id="confetti-popup-close"> <i class="fa fa-close"></i>Close</a></div>'; 144 95 } 145 96 } 146 147 97 add_action('wp_footer', 'confetti_popup_display'); 148 98 149 // Callback function for the delay field150 99 function confetti_popup_delay_callback() { 151 $delay = get_option('confetti-popup-delay', 5); // Default delay of 5 seconds100 $delay = intval(get_option('confetti-popup-delay', 5)); 152 101 echo '<input type="number" name="confetti-popup-delay" value="' . esc_attr($delay) . '" min="1" />'; 153 102 } 154 103 155 156 // Function to display the welcome message157 104 function confetti_welcome_message() { 158 // Check if the welcome message has already been shown 159 $welcome= get_option('confetti_welcome_shown', false); 160 161 if ($welcome) { 162 return true; 105 if (get_option('confetti_welcome_shown', false)) { 106 return; 163 107 } 164 else{ 165 ?> 166 <div class="notice notice-success is-dismissible"> 167 <p>Welcome to Confetti Fall Animation Plugin! Thank you for installing and activating our plugin.</p> 168 <p>Now you can enjoy the confetti animation on your website with one click away.</p> 169 </div> 170 <?php 171 172 // Set the flag to indicate that the welcome message has been shown 173 update_option('confetti_welcome_shown', true); 174 } 108 echo '<div class="notice notice-success is-dismissible">'; 109 echo '<p>' . esc_html__('Welcome to Confetti Fall Animation Plugin! Thank you for installing and activating our plugin.', 'confetti-fall-animation') . '</p>'; 110 echo '</div>'; 111 update_option('confetti_welcome_shown', true); 175 112 } 176 177 // Hook to display the welcome message178 113 add_action('admin_notices', 'confetti_welcome_message'); 179 114 180 181 182 // Add a meta box with a button to the page/post editor183 function add_shortcode_button_meta_box() {184 add_meta_box(185 'shortcode_button_meta_box', // Meta box ID186 'Add CFA Shortcode', // Title of the meta box187 'shortcode_button_meta_box_content', // Callback function to display content188 'page', // Post type(s) where the meta box should appear (you can add more post types if needed)189 'side', // Context: 'normal', 'advanced', or 'side'190 'high' // Priority: 'high', 'core', 'default', or 'low'191 );192 }193 add_action('add_meta_boxes', 'add_shortcode_button_meta_box');194 // Callback function to display content inside the meta box195 function shortcode_button_meta_box_content($post) {196 // Output HTML for the button197 echo '<button id="add-shortcode-button" class="button">Add CF Animation Shortcode</button>';198 }199 200 // JavaScript to handle button click and insert shortcode201 function add_shortcode_button_script() {202 ?>203 <script>204 jQuery(document).ready(function($) {205 $('#add-shortcode-button').on('click', function(e) {206 e.preventDefault();207 // Modify this line to insert your shortcode into the editor208 var shortcode = '[confetti-fall-animation delay="1" time="25"]';209 wp.media.editor.insert(shortcode);210 });211 });212 </script>213 <?php214 }215 add_action('admin_footer', 'add_shortcode_button_script');216 217 218 219 220 // Add confetti to homepage based on the option221 115 add_action('wp', 'add_confetti_to_homepage'); 222 116 function add_confetti_to_homepage() { 223 $confetti_active = get_option('confetti_active'); 224 225 if (is_front_page() && $confetti_active) { 117 if (is_front_page() && get_option('confetti_active')) { 226 118 echo do_shortcode('[confetti-fall-animation delay="1" time="25"]'); 227 119 } … … 229 121 230 122 add_shortcode("confetti-fall-animation", "cfa_html_view_pages"); 231 function cfa_html_view_pages($props) 232 { 233 if ($props) { 234 $props = shortcode_atts( 235 array( 236 "delay" => "", 237 "time" => "", 238 ), $props 239 ); 240 $delay = $props["delay"]; 241 $time = $props["time"]; 242 return "<div class=\"confetti-fall-animation\" data-delay=\"" . $delay . "\" data-time=\"" . $time . "\"></div>"; 243 } 123 function cfa_html_view_pages($props) { 124 $props = shortcode_atts([ 125 "delay" => "1", 126 "time" => "25" 127 ], $props); 128 129 return '<div class="confetti-fall-animation" data-delay="' . esc_attr($props["delay"]) . '" data-time="' . esc_attr($props["time"]) . '"></div>'; 244 130 }
Note: See TracChangeset
for help on using the changeset viewer.