Plugin Directory

Changeset 2309465

Timestamp:
05/21/2020 12:30:05 PM (4 years ago)
Author:
wolly
Message:

Released version 2.0, code rewritten and added new styles

Location:
wpit-funny-name-generator
Files:
22 added
5 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • wpit-funny-name-generator/trunk/assets/css/funny_name.css

    r2308926 r2309465  
     1
     2
     3
     4
     5
     6
    17.submit-name{
    28   
    39    margin-top: 25px;
    4 }
    5 .row.month{
    6    
    7     margin-top: 1em;
    810}
    911
     
    5759  flex-wrap: wrap;
    5860  width: 100%;
     61
    5962}
    6063
  • wpit-funny-name-generator/trunk/readme.txt

    r2308929 r2309465  
    55Requires at least: 4.0
    66Tested up to: 5.4
    7 Stable tag: 1.2
     7Stable tag:
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3737
    3838== Installation ==
    39 Upload Wpit Funny Name Generator folder to the /wp-content/plugins/ directory
    40 Activate the plugin through the \'Plugins\' menu in WordPress
    41 Insert the right shortcode in a page or post.
     39Install Wpit Funny Name Generator via the plugin directory, or upload the files manually to your server, then activate it.
    4240
    4341
     
    6058In order to generate Unicorn name use [unicorn_calc] shortcode
    6159
     60
     61
     62
     63
     64
     65
     66
    6267= Do the plugin store data= =
    6368No data will be stored.
     
    7075
    7176== Changelog ==
     77
     78
     79
     80
     81
    7282= 1.2 =
    7383
     
    8393
    8494* First release
     95
     96
  • wpit-funny-name-generator/trunk/wpit-funny-name-generator.php

    r2308926 r2309465  
    33 * @package wpit funny name generator
    44 * @author Paolo Valenti
    5  * @version 1.2 added unicorn generator
     5 * @version
    66 */
    77/*
     
    1010Description: This plugin generate Jedi, Mad Max, Ninja names and unicorn name
    1111Author: Wolly
    12 Version: 1.2
     12Version:
    1313Author URI: https://paolovalenti.info
    1414Text Domain: wpit-funny-name-generator
     
    3333*/
    3434
    35 define ( 'WPIT_WPITFNG_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
    36 define ( 'WPIT_WPITFNG_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    37 define ( 'WPIT_WPITFNG_PLUGIN_SLUG', basename( dirname( __FILE__ ) ) );
    38 define ( 'WPIT_WPITFNG_PLUGIN_VERSION', '1.2' );
    39 define ( 'WPIT_WPITFNG_PLUGIN_VERSION_NAME', 'wpit-wpitfng-version' );
    40 
    41 
     35// Exit if accessed directly
     36if ( ! defined( 'ABSPATH' ) ) {
     37    exit;
     38}   
    4239
    4340// Create text domain for localization purpose, po files must be in languages directory
     
    5148add_action('plugins_loaded', 'wpit_funny_name_generator_text_domain');
    5249
    53 include_once 'inc/class-wpit-jedi.php';
    54 include_once 'inc/class-wpit-mad-max.php';
    55 include_once 'inc/class-wpit-ninja.php';
    56 include_once 'inc/class-wpit-unicorn.php';
    57 
    58 include_once 'inc/class-wpit-funny-opiton-panel.php';
    59 
    60 
    61 class Wpit_Funny_Name_Generator {
    62 
    63     //A static member variable representing the class instance
    64     private static $_instance = null;
    65 
    66 
    67 
    68     /**
    69      * Wpit_Funny_Name_Generator::__construct()
    70      * Locked down the constructor, therefore the class cannot be externally instantiated
    71      *
    72      * @param array $args various params some overidden by default
    73      *
    74      * @return
    75      */
    76 
    77     private function __construct() {
    78 
    79         //check for plugin update (put in construct)
    80         add_action( 'init', array( $this, 'update_check' ) );
    81         add_action(
    82                 'wp_enqueue_scripts',
    83                 array(
    84                     $this,
    85                     'enqueue_styles',
    86                 )
     50if ( ! class_exists( 'Wpit_Funny_Name_Generator' ) ){
     51   
     52    class Wpit_Funny_Name_Generator {
     53   
     54        //A static member variable representing the class instance
     55        private static $instance;
     56   
     57        /**
     58         * The version number of Wol_Iab.
     59         *
     60         * @access private
     61         * @since  1.0
     62         * @var    $version
     63         */
     64        private $version = '2.0';
     65       
     66        /**
     67         * option
     68         *
     69         * @var mixed
     70         * @access public
     71         */
     72        public $option;
     73       
     74        /**
     75         * jedi
     76         *
     77         * @var mixed
     78         * @access public
     79         */
     80        public $jedi;
     81       
     82        /**
     83         * mad_max
     84         *
     85         * @var mixed
     86         * @access public
     87         */
     88        public $mad_max;
     89       
     90        /**
     91         * ninja
     92         *
     93         * @var mixed
     94         * @access public
     95         */
     96        public $ninja;
     97       
     98        /**
     99         * unicorn
     100         *
     101         * @var mixed
     102         * @access public
     103         */
     104        public $unicorn;
     105       
     106        public $utility;
     107   
     108       
     109        public static function instance() {
     110            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Wpit_Funny_Name_Generator ) ) {
     111                self::$instance = new Wpit_Funny_Name_Generator();
     112
     113                if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
     114
     115                    add_action(
     116                        'admin_notices',
     117                        array(
     118                            'Wol_Iab',
     119                            'below_php_version_notice',
     120                        )
     121                    );
     122
     123                    return self::$instance;
     124                }
     125
     126                self::$instance->setup_constants();
     127
     128                self::$instance->includes();
     129               
     130                add_action(
     131                    'plugins_loaded',
     132                    array(
     133                        self::$instance,
     134                        'setup_objects',
     135                    ),
     136                    - 1
     137                );
     138
     139                add_action(
     140                    'init',
     141                    array(
     142                        self::$instance,
     143                        'init_settings',
     144                    )
     145                );
     146
     147            }
     148
     149            return self::$instance;
     150        }   
     151       
     152        /**
     153         * Throw error on object clone
     154         *
     155         * The whole idea of the singleton design pattern is that there is a single
     156         * object therefore, we don't want the object to be cloned.
     157         *
     158         * @return void
     159         * @since  1.0
     160         * @access protected
     161         */
     162        public function __clone() {
     163            // Cloning instances of the class is forbidden
     164            _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'Wol_Iab' ), '1.0' );
     165        }
     166
     167        /**
     168         * Disable unserializing of the class
     169         *
     170         * @return void
     171         * @since  1.0
     172         * @access protected
     173         */
     174        public function __wakeup() {
     175            // Unserializing instances of the class is forbidden
     176            _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'Wol_Iab' ), '1.0' );
     177        }
     178
     179        /**
     180         * Show a warning to sites running PHP < 5.6
     181         *
     182         * @static
     183         * @access private
     184         * @return void
     185         * @since  1.0
     186         */
     187        public static function below_php_version_notice() {
     188            echo '<div class="error"><p>' . esc_html__( 'Your version of PHP is below the minimum version of PHP required by Wol_Iab. Please contact your host and request that your version be upgraded to 5.6 or later.', 'Wol_Iab' ) . '</p></div>';
     189        }
     190
     191        /**
     192         * Setup plugin constants
     193         *
     194         * @access private
     195         * @return void
     196         * @since  1.0
     197         */
     198        private function setup_constants() {
     199           
     200            if ( ! defined( 'WPIT_WPITFNG_PLUGIN_VERSION' ) ) {
     201                define( 'WPIT_WPITFNG_PLUGIN_VERSION', $this->version );
     202            }
     203           
     204            if ( ! defined( 'WPIT_WPITFNG_PLUGIN_VERSION_NAME' ) ) {
     205                define ( 'WPIT_WPITFNG_PLUGIN_VERSION_NAME', 'wpit-wpitfng-version' );
     206            }
     207
     208           
     209            // Plugin Folder Path
     210            if ( ! defined( 'WPIT_WPITFNG_PLUGIN_PATH' ) ) {
     211                define( 'WPIT_WPITFNG_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
     212            }
     213
     214            // Plugin Folder URL
     215            if ( ! defined( 'WPIT_WPITFNG_PLUGIN_URL' ) ) {
     216                define( 'WPIT_WPITFNG_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
     217            }
     218           
     219            // Plugin Folder URL
     220            if ( ! defined( 'WPIT_WPITFNG_PLUGIN_SLUG' ) ) {
     221                define ( 'WPIT_WPITFNG_PLUGIN_SLUG', basename( dirname( __FILE__ ) ) );
     222            }
     223
     224        }
     225       
     226        /**
     227         * includes function.
     228         *
     229         * @access private
     230         * @return void
     231         */
     232        private function includes() {
     233           
     234            if ( is_admin(  ) ){
     235               
     236                require_once WPIT_WPITFNG_PLUGIN_PATH . 'class-funny-option-panel.php';
     237               
     238            } else {
     239                require_once WPIT_WPITFNG_PLUGIN_PATH . 'wol-wrapper-functions.php';
     240                require_once WPIT_WPITFNG_PLUGIN_PATH . 'inc/class-jedi.php';
     241                require_once WPIT_WPITFNG_PLUGIN_PATH . 'inc/class-jedi.php';
     242                require_once WPIT_WPITFNG_PLUGIN_PATH . 'inc/class-mad-max.php';
     243                require_once WPIT_WPITFNG_PLUGIN_PATH . 'inc/class-ninja.php';
     244                require_once WPIT_WPITFNG_PLUGIN_PATH . 'inc/class-unicorn.php';
     245                require_once WPIT_WPITFNG_PLUGIN_PATH . 'inc/class-utility.php';
     246               
     247            }
     248        }
     249       
     250        /**
     251         * Setup all objects
     252         *
     253         * @access public
     254         * @return void
     255         * @since  1.6.2
     256         */
     257        public function setup_objects() {
     258           
     259            // Instantiate in admin only
     260            if ( is_admin() ) {
     261
     262                self::$instance->option     = new Wol_Funny_Name_Options_Page();               
     263
     264            } else {
     265
     266                // Frontend only used class
     267                self::$instance->jedi       = new Wol_Jedy();
     268                self::$instance->mad_max    = new Wol_Mad_Max();
     269                self::$instance->ninja      = new Wol_Ninja();
     270                self::$instance->unicorn    = new WOl_Unicorn();
     271                self::$instance->utility    = new Wol_Fng_Utility();
     272               
     273               
     274
     275            }
     276           
     277            self::$instance->update_check();
     278           
     279            add_action(
     280                    'wp_enqueue_scripts',
     281                    array(
     282                        $this,
     283                        'enqueue_styles',
     284                    )
     285                );
     286        }
     287       
     288        public function init_settings() {
     289            wp_cache_add_non_persistent_groups( array( 'funny-name-session' ) );
     290        }
     291
     292        /**
     293        * update_UTILITY_check function.
     294        *
     295        * @access public
     296        * @return void
     297        */
     298        public function update_check() {
     299        // Do checks only in backend
     300           if ( is_admin() ) {
     301   
     302   
     303               if ( version_compare( get_site_option( WPIT_WPITFNG_PLUGIN_VERSION_NAME ), WPIT_WPITFNG_PLUGIN_VERSION , "<" ) ) {
     304   
     305                self::$instance->do_update();
     306   
     307                }
     308   
     309            } //end if only in the admin
     310        }
     311   
     312        /**
     313        * do_update function.
     314        *
     315        * @access private
     316        *
     317        */
     318        public function do_update(){
     319   
     320           //DO NOTHING, BY NOW, MAYBE IN THE FUTURE
     321   
     322           //Update option
     323   
     324           update_option( WPIT_WPITFNG_PLUGIN_VERSION_NAME , WPIT_WPITFNG_PLUGIN_VERSION );
     325        }
     326       
     327        public function enqueue_styles(){
     328           
     329            wp_register_style(
     330                    'wol_funny_name_css',
     331                    WPIT_WPITFNG_PLUGIN_URL . 'assets/css/funny_name.css',
     332                    array(),
     333                    '1.0.0'
     334                );
     335            wp_enqueue_style( 'wol_funny_name_css' );
     336           
     337           
     338            wp_register_script(
     339                'font-awesome-5',
     340                'https://kit.fontawesome.com/dc9cba53cf.js',
     341                array(),
     342                '1.0.0',
     343                true
    87344            );
    88 
    89 
    90 
    91 
    92     }
    93 
    94     /**
    95      * Wpit_Funny_Name_Generator::__clone()
    96      * Prevent any object or instance of that class to be cloned
    97      *
    98      * @return
    99      */
    100     public function __clone() {
    101         trigger_error( "Cannot clone instance of Singleton pattern ...", E_USER_ERROR );
    102     }
    103 
    104     /**
    105      * Wpit_Funny_Name_Generator::__wakeup()
    106      * Prevent any object or instance to be deserialized
    107      *
    108      * @return
    109      */
    110     public function __wakeup() {
    111         trigger_error( 'Cannot deserialize instance of Singleton pattern ...', E_USER_ERROR );
    112     }
    113 
    114     /**
    115      * Wpit_Funny_Name_Generator::getInstance()
    116      * Have a single globally accessible static method
    117      *
    118      * @param mixed $args
    119      *
    120      * @return
    121      */
    122     public static function getInstance( $args = array() ) {
    123         if ( ! is_object( self::$_instance ) )
    124             self::$_instance = new self( $args );
    125 
    126         return self::$_instance;
    127 
    128 
    129     }
    130 
    131 
    132 
    133 
    134 
    135     /**
    136     * update_UTILITY_check function.
    137     *
    138     * @access public
    139     * @return void
    140     */
    141     public function update_check() {
    142     // Do checks only in backend
    143        if ( is_admin() ) {
    144 
    145 
    146            if ( version_compare( get_site_option( WPIT_WPITFNG_PLUGIN_VERSION_NAME ), WPIT_WPITFNG_PLUGIN_VERSION , "<" ) ) {
    147 
    148             $this->do_update();
    149 
    150             }
    151 
    152         } //end if only in the admin
    153     }
    154 
    155     /**
    156     * do_update function.
    157     *
    158     * @access private
    159     *
    160     */
    161     public function do_update(){
    162 
    163        //DO NOTHING, BY NOW, MAYBE IN THE FUTURE
    164 
    165        //Update option
    166 
    167        update_option( WPIT_WPITFNG_PLUGIN_VERSION_NAME , WPIT_WPITFNG_PLUGIN_VERSION );
    168     }
    169    
    170     public function enqueue_styles(){
    171        
    172         wp_register_style(
    173                 'wol_funny_name_css',
    174                 WPIT_WPITFNG_PLUGIN_URL . 'assets/css/funny_name.css',
    175                 array(),
    176                 '1.0.0'
    177             );
    178             wp_enqueue_style( 'wol_funny_name_css' );
    179 
    180     }
    181 
    182 
    183 }// chiudo la classe
    184 
    185 //istanzio la classe
    186 
    187 $wpit_funny_name_generator = Wpit_Funny_Name_Generator::getInstance();
     345            wp_enqueue_script( 'font-awesome-5' );
     346           
     347           
     348   
     349        }
     350   
     351   
     352    }// chiudo la classe
     353
     354} // ! class exists
     355
     356
     357/**
     358 * The main function responsible for returning the one true Wol_Iab
     359 * Instance to functions everywhere.
     360 *
     361 * Use this function like you would a global variable, except without needing
     362 * to declare the global.
     363 *
     364 * Example: <?php $Wol_Iab = Wol_Iab(); ?>
     365 *
     366 * @return Wol_Iab The one true Wol_Iab Instance
     367 * @since 1.0
     368 */
     369function funnyname() {
     370    return Wpit_Funny_Name_Generator::instance();
     371}
     372
     373funnyname();
Note: See TracChangeset for help on using the changeset viewer.