Skip to content

Instantly share code, notes, and snippets.

@N-Molham
Last active August 29, 2015 14:12
Show Gist options
  • Save N-Molham/c3765c35917b66de5f57 to your computer and use it in GitHub Desktop.
Save N-Molham/c3765c35917b66de5f57 to your computer and use it in GitHub Desktop.
Dashboard User Password Generator demo plugin main file
<?php
/*
Plugin Name: Dashboard User Password Generator
Plugin URI: http://nabeel.molham.me/blog/plugins/user-password-generator-demo
Description: Add a generator button next password field in the dashboard
Version: 1.0
Author: Nabeel Molham
Author URI: http://nabeel.molham.me/
Text Domain: user-password-generator-demo
Domain Path: /languages
License: GNU General Public License, version 2, http://www.gnu.org/licenses/gpl-2.0.html
*/
// Exit if accessed directly
// عشان لو حد نده على النلف مباشر يوقفه
if ( ! defined( 'ABSPATH' ) )
die();
/**
* Constants
* شوية حاجات بعرفها اساسية بتستخدم على طول
*/
// Plugin Matser file
define( 'UPGD_MAIN_FILE', __FILE__ );
// Physical path of the plugin on server hard drive
define( 'UPGD_DIR', plugin_dir_path( UPGD_MAIN_FILE ) );
// URL to the plugin directory
define( 'UPGD_URI', plugin_dir_url( UPGD_MAIN_FILE ) );
// Text domain unique name used for localizaion
define( 'UPGD_DOMAIN', 'user-password-generator-demo' );
// The plugin current version
define( 'UPGD_VERSION', '1.0' );
/**
* User Password Generator plugin Main
*
* @class User_Password_Generator_Demo
* @version 1.0
*/
class User_Password_Generator_Demo
{
/**
* Plugin Version
*
* @var string
*/
public $version = '1.0.0';
/**
* @var User_Password_Generator_Demo The single instance of the class
* @since 1.0
*/
protected static $_instance = null;
/**
* Constructor
*
* @since 1.0
*
* @return User_Password_Generator_Demo
*/
public function __construct()
{
// load language files
add_action( 'plugins_loaded', array( &$this, 'load_language' ) );
}
/**
* Language file loading
*
* @since 1.0
*
* @return void
*/
public function load_language()
{
// language files located in the "languages" directory in the plugin
// if the current language files not found it will use the default string written in the plugin
load_plugin_textdomain( UPGD_DOMAIN, false, UPGD_DIR . 'languages/' );
}
/**
* Main User_Password_Generator_Demo Instance
*
* Ensures only one instance of User_Password_Generator_Demo is loaded or can be loaded.
*
* @since 1.0
* @static
* @see UPGP()
*
* @return User_Password_Generator_Demo - Main instance
*/
public static function instance()
{
if ( is_null( self::$_instance ) )
self::$_instance = new self();
return self::$_instance;
}
}
/**
* Returns the main instance of the plugin to prevent the need to use globals.
*
* @since 1.0
*
* @return User_Password_Generator_Demo
*/
function UPGP()
{
return User_Password_Generator_Demo::instance();
}
// startup plugin
$GLOBALS['user_password_generator_demo'] = UPGP();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment