• Varun Sridharan's avatar
    WooCommerce Quick Donation 1.3.x Beta Version · 9c660c91
    Varun Sridharan authored
    Redeveloping The Plugin.
    Created Custom Post Type
    Created Custom Taxonomy {Category & Tags}
    Created Short code
    Project Output Like Select , Radio [Single or grouped]
    Price Box Output
    Customization Template
    
    [admin/class-admin-init.php]
    
    Added woocommerce_screen_ids
    Removed Admin Notice Handler Class Init
    Added Plugins Settings Page ID To WC Screen ID
    
    [admin/class-admin-settings.php & admin/class-donation-settings.php]
    
    Working To Get A Prefect Settings Page
    
    [admin/includes/class-admin-functions.php]
    
    Changed WC_QD()->donation_id to WC_QD_ID
    
    [includes/class-quick-donation-process.php]
    
    Created Class To Process Front End Donation Form
    
    [includes/class-shortcode-handler.php]
    
    Created 2 Actions
    wc_quick_donation_before_donation_form
    wc_quick_donation_after_donation_form
    
    [woocommerce-quick-donation.php]
    
    Changed $donation_id from dynimic to static
    Added WC_QD_ID defined variable
    
    Rearranged Few Loading Files
    
    Added Donation Processing Email
    Added Prefect Settings Framework
    Added Seperate Page For Listing Donations
    9c660c91
class-admin-notice.php 4.13 KB
<?php

/*
Name:        Admin Notice Helper
URI:         https://github.com/iandunn/admin-notice-helper
Version:     0.2
Author:      Ian Dunn
Author URI:  http://iandunn.name
License:     GPLv2
*/

/*  
 * Copyright 2014 Ian Dunn (email : ian@iandunn.name)
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as 
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

if ( ! defined( 'ABSPATH' ) ) {
	die( 'Access denied.' );
}

if ( ! class_exists( 'Admin_Notice_Helper' ) ) {

	class Admin_Notice_Helper {
		// Declare variables and constants
		protected static $instance;
		protected $notices, $notices_were_updated;

		/**
		 * Constructor
		 */
		protected function __construct() {
            $this->init();
			//add_action( 'init',          array( $this, 'init' ));         // needs to run before other plugin's init callbacks so that they can enqueue messages in their init callbacks
			add_action( 'admin_notices', array( $this, 'print_notices' ) );
			add_action( 'shutdown',      array( $this, 'shutdown' ) );
		}

		/**
		 * Provides access to a single instances of the class using the singleton pattern
		 *
		 * @mvc    Controller
		 * @author Ian Dunn <ian@iandunn.name>
		 * @return object
		 */
		public static function get_singleton() {
			if ( ! isset( self::$instance ) ) {
				self::$instance = new Admin_Notice_Helper();
			}

			return self::$instance;
		}

		/**
		 * Initializes variables
		 */
		public function init() {
			$default_notices             = array( 'update' => array(), 'error' => array() );
            
			$this->notices               = array_merge( $default_notices, get_option( 'anh_notices', array() ) );
			$this->notices_were_updated  = false;
		}

		/**
		 * Queues up a message to be displayed to the user
		 *
		 * @param string $message The text to show the user
		 * @param string $type    'update' for a success or notification message, or 'error' for an error message
		 */
		public function enqueue( $message, $type = 'update' ) {

            if(!empty($this->notices)){
                if(isset( $this->notices[ $type ])){
                    if ( in_array( $message, array_values( $this->notices[ $type ] ) ) ) {
                        return;
                    }
                }
            }

			$this->notices[ $type ][]   = (string) apply_filters( 'anh_enqueue_message', $message );
			$this->notices_were_updated = true;
		}

		/**
		 * Displays updates and errors
		 */
		public function print_notices() {
            
			foreach ( array( 'update', 'error' ) as $type ) {
                
				if ( count( $this->notices[ $type ] ) ) {
					$class = 'update' == $type ? 'updated' : 'error';

					?>

                    <div class="anh_message <?php esc_attr_e( $class ); ?>">
                        <?php foreach ( $this->notices[ $type ] as $notice ) : ?>
                            <p><?php echo wp_kses( $notice, wp_kses_allowed_html( 'post' ) ); ?></p>
                        <?php endforeach; ?>
                    </div>

                    <?php
                    

					$this->notices[ $type ]      = array();
					$this->notices_were_updated  = true;
				}
			}
		}

		/**
		 * Writes notices to the database
		 */
		public function shutdown() {
			if ( $this->notices_were_updated ) {
				update_option( 'anh_notices', $this->notices );
			}
		}
	} // end Admin_Notice_Helper

	Admin_Notice_Helper::get_singleton(); // Create the instance immediately to make sure hook callbacks are registered in time

	if ( ! function_exists( 'wc_qd_notice' ) ) {
		function wc_qd_notice( $message, $type = 'update' ) {
			Admin_Notice_Helper::get_singleton()->enqueue( $message, $type );
		}
	}
}

?>