Plugin Directory

Changeset 3237295


Ignore:
Timestamp:
02/09/2025 11:37:54 AM (14 months ago)
Author:
shakeelu
Message:

code updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • confetti-fall-animation/trunk/confetti-fall-animation.php

    r3201072 r3237295  
    33/**
    44 * @package confetti-fall-animation
    5  * @version 1.3.0
     5 * @version 1.3.1
    66 **/
    77
    88/*
    99Plugin Name: Confetti Fall Animation
    10 Plugin URI: https://rtoluxurycars.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.
     10Plugin URI: https://wpdeveloperr.com/
     11Description: 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.
    1212Author: WPDeveloperr
    13 Author URI: https://rtoluxurycars.com/
    14 Version: 1.3.0
     13Author URI: https://wpdeveloperr.com/
     14Version: 1.3.1
    1515License: GPLv2 or later
    1616Text Domain: confetti-fall-animation
    17  */
     17*/
    1818
    1919defined('ABSPATH') or die('Hey, You can\'t access this directly.');
    2020
    21 /* --- */
    2221if (!function_exists("add_action")) {
    2322    exit;
    2423}
    25 /* --- */
    2624
    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';
     25define("CFA_DIR_URL", plugin_dir_url(__FILE__));
     26define("CFA_DIR_PATH", plugin_dir_path(__FILE__));
     27require_once CFA_DIR_PATH . 'inc/popupBackgroundImage.php';
     28require_once CFA_DIR_PATH . 'inc/confetti_settings.php';
    3129
    32 /* --- */
    33 
    34 
    35 function cfa_enqueue_scripts(){
    36 
     30function cfa_enqueue_scripts() {
    3731    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');
    4840}
    4941add_action("wp_enqueue_scripts", "cfa_enqueue_scripts");
    5042
    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 
     43function confetti_backend_scripts() {
     44    wp_enqueue_style('confetti-style', CFA_DIR_URL . 'assets/css/popup-plugin.css', array(), '1.0', 'all');
    5645}
    5746add_action('admin_enqueue_scripts', 'confetti_backend_scripts');
    5847
    59 /* --- */
    60 
    61 // Activation and deactivation hooks
    6248register_activation_hook(__FILE__, 'confetti_popup_activate');
    6349register_deactivation_hook(__FILE__, 'confetti_popup_deactivate');
    6450
    6551function confetti_popup_activate() {
    66     // Set an option to indicate that the welcome message has not been shown
    6752    add_option('confetti_welcome_shown', false);
    6853}
    6954
    70 function confetti_popup_deactivate() {
    71     // Deactivation code here
     55function confetti_popup_deactivate() {}
     56
     57add_action('admin_menu', 'confetti_menu_func');
     58function 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');
    7261}
    7362
    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 
     63function confetti_animation_page() {
     64    $confetti_settings = new Confetti_Settings();
     65    $confetti_settings->confetti_settings_page();
    8466}
    8567
    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
     68add_action('admin_init', 'confetti_popup_settings');
    9569function 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   
    10575    register_setting('confetti-animation', 'confetti-popup-delay');
    10676    register_setting('confetti-animation', 'confetti-popup-content');
    10777    register_setting('confetti-animation', 'confetti-popup-pages');
    10878}
    109 // Create settings fields and sections
    110 add_action('admin_init', 'confetti_popup_settings');
    11179
    112 // Callback functions for settings fields
    11380function confetti_popup_general_section_callback() {
    114     echo 'Configure the confetti popup settings.';
     81    echo esc_html__('Configure the confetti popup settings.', 'confetti-fall-animation');
    11582}
    11683
    11784function confetti_popup_content_callback() {
    11885    $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>';
    12287}
    12388
    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 }
    13589function confetti_popup_display() {
    13690    $content = get_option('confetti-popup-content', '');
    137     $pages = get_option('confetti-popup-pages', []);
     91    $pages = array_map('intval', (array) get_option('confetti-popup-pages', []));
    13892
    13993    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>';
    14495    }
    14596}
    146 
    14797add_action('wp_footer', 'confetti_popup_display');
    14898
    149 // Callback function for the delay field
    15099function confetti_popup_delay_callback() {
    151     $delay = get_option('confetti-popup-delay', 5); // Default delay of 5 seconds
     100    $delay = intval(get_option('confetti-popup-delay', 5));
    152101    echo '<input type="number" name="confetti-popup-delay" value="' . esc_attr($delay) . '" min="1" />';
    153102}
    154103
    155 
    156 // Function to display the welcome message
    157104function 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;
    163107    }
    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);
    175112}
    176 
    177 // Hook to display the welcome message
    178113add_action('admin_notices', 'confetti_welcome_message');
    179114
    180 
    181 
    182 // Add a meta box with a button to the page/post editor
    183 function add_shortcode_button_meta_box() {
    184     add_meta_box(
    185         'shortcode_button_meta_box', // Meta box ID
    186         'Add CFA Shortcode', // Title of the meta box
    187         'shortcode_button_meta_box_content', // Callback function to display content
    188         '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 box
    195 function shortcode_button_meta_box_content($post) {
    196     // Output HTML for the button
    197     echo '<button id="add-shortcode-button" class="button">Add CF Animation Shortcode</button>';
    198 }
    199 
    200 // JavaScript to handle button click and insert shortcode
    201 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 editor
    208                 var shortcode = '[confetti-fall-animation delay="1" time="25"]';
    209                 wp.media.editor.insert(shortcode);
    210             });
    211         });
    212     </script>
    213     <?php
    214 }
    215 add_action('admin_footer', 'add_shortcode_button_script');
    216 
    217 
    218 
    219 
    220 // Add confetti to homepage based on the option
    221115add_action('wp', 'add_confetti_to_homepage');
    222116function 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')) {
    226118        echo do_shortcode('[confetti-fall-animation delay="1" time="25"]');
    227119    }
     
    229121
    230122add_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     }
     123function 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>';
    244130}
Note: See TracChangeset for help on using the changeset viewer.