Skip to content

Commit

Permalink
Improve plugin structure
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeHana committed Apr 27, 2017
1 parent e82be49 commit ea4df59
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 42 deletions.
8 changes: 6 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== Gravity Forms - Phone Extension ===
Contributors: joehana
Donate link: http://paypal.me/joehana
Donate link: http://paypal.me/anex
Tags: forms, phone, input
Requires at least: 4.5.0
Tested up to: 4.7
Stable tag: 1.0.1
Stable tag: 1.1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -25,6 +25,10 @@ Extension for GravityForms (WordPress) which applies the International Phone Inp

== Changelog ==

= 1.1.0 =
* Improve Plugin Structure
* Update intlTelInput to 11.0.11

= 1.0.1 =
* FIX: Remove 'http:' from $.get function in init.js to prevent issues on SSL Sites

Expand Down
52 changes: 12 additions & 40 deletions gravityforms-phone-extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Gravity Forms - Phone Extension
* Plugin URI: https://github.com/ANEX-Agency/Gravityforms-Phone-Extension
* Description: Extends the Phone Field with a Country Code Selectbox
* Version: 1.0.1
* Version: 1.1.0
* Author: ANEX
* Author URI: http://anex.at
* License: GPL-2.0+
Expand All @@ -13,53 +13,25 @@
* Domain Path: /languages
*/

// If this file is called directly or Gravity Forms isn't loaded, abort.
if ( ! defined( 'WPINC' ) || ! class_exists( 'GFForms' ) ) {
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}

/**
* Create Gravity Forms Phone Extension
* plugin class
*
* @since 1.0.0
*/

class GravityForms_Phone_Extension {
define( 'GF_PHONE_EXTENSION_VERSION', '1.1.0' );

/**
* Initializes the plugin
*/
function __construct() {

// Register site styles
add_action( 'wp_enqueue_scripts', array( $this, 'assets' ) );

}
add_action( 'gform_loaded', array( 'GF_Phone_Extension_Bootstrap', 'load' ), 5 );

class GF_Phone_Extension_Bootstrap {

/**
* Register and enqueue plugin-specific assets.
*/
public function assets() {

// register & enqueue styles
wp_enqueue_style( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/css/intlTelInput.css', __FILE__ ), array(), '9.2.4' );
wp_enqueue_style( 'gravityforms-phone-extension', plugins_url( 'assets/css/style.css', __FILE__ ), array(), '1.0.1' );
public static function load(){

// register & enqueue scripts
wp_enqueue_script( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/js/intlTelInput.min.js', __FILE__ ), array( 'jquery' ), '9.2.4', true );
wp_enqueue_script( 'intl-tel-input-utils', plugins_url( 'vendor/intl-tel-input/js/utils.js', __FILE__ ), array( 'jquery', 'intl-tel-input' ), '9.2.4', true );
wp_enqueue_script( 'gravityforms-phone-extension', plugins_url( 'assets/js/init.js', __FILE__ ), array( 'jquery' ), '1.0.1', true );
require_once( 'includes/class-gf-phone-extension.php' );

GFAddOn::register( 'GF_Phone_Extension' );
}

}

/**
* Call class
*
* @since 1.0.0
*/
if( ! is_admin() )
$GravityForms_Phone_Extension= new GravityForms_Phone_Extension();
function gf_phone_extension(){
return GF_Phone_Extension::get_instance();
}
153 changes: 153 additions & 0 deletions includes/class-gf-phone-extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

/**
* Create Gravity Forms Phone Extension
* plugin class
*
* @since 1.0.0
*/

class GF_Phone_Extension {

/**
* Contains an instance of this class, if available.
*
* @since 1.0.0
* @access private
* @var object $_instance If available, contains an instance of this class.
*/
private static $_instance = null;

/**
* Defines the version of the Propstack Add-On.
*
* @since 1.0.0
* @access protected
* @var string $_version Contains the version, defined from gravityforms-propstack.php
*/
protected $_version = GF_PHONE_EXTENSION_VERSION;

/**
* Defines the minimum Gravity Forms version required.
*
* @since 1.0.0
* @access protected
* @var string $_min_gravityforms_version The minimum version required.
*/
protected $_min_gravityforms_version = '2.2';

/**
* Defines the plugin slug.
*
* @since 1.0.0
* @access protected
* @var string $_slug The slug used for this plugin.
*/
protected $_slug = 'gravityforms-phone-extension';

/**
* Defines the main plugin file.
*
* @since 1.0.0
* @access protected
* @var string $_path The path to the main plugin file, relative to the plugins folder.
*/
protected $_path = 'gravityforms-phone-extension/gravityforms-phone-extension.php';

/**
* Defines the full path to this class file.
*
* @since 1.0.0
* @access protected
* @var string $_full_path The full path.
*/
protected $_full_path = __FILE__;

/**
* Defines the URL where this Add-On can be found.
*
* @since 1.0.0
* @access protected
* @var string The URL of the Add-On.
*/
protected $_url = 'http://www.anex.at';

/**
* Defines the title of this Add-On.
*
* @since 1.0.0
* @access protected
* @var string $_title The title of the Add-On.
*/
protected $_title = 'Gravity Forms Phone Extension Add-On';

/**
* Defines the short title of the Add-On.
*
* @since 1.0.0
* @access protected
* @var string $_short_title The short title.
*/
protected $_short_title = 'Phone Extension';

/**
* Defines if Add-On should use Gravity Forms servers for update data.
*
* @since 1.0.0
* @access protected
* @var bool
*/
protected $_enable_rg_autoupgrade = false;

/**
* Get an instance of this class.
*
* @since 1.0.0
* @access public
*
* @return GF_Phone_Extension
*/
public static function get_instance() {

if ( null === self::$_instance ) {
self::$_instance = new self;
}

return self::$_instance;

}

/**
* Initializes the plugin
*
* @since 1.0.0
* @access public
*/
public function __construct() {

// Register site styles
add_action( 'wp_enqueue_scripts', array( $this, 'assets' ) );

}


/**
* Register and enqueue plugin-specific assets
*
* @since 1.0.0
* @access public
*/
public function assets() {

// register & enqueue styles
wp_enqueue_style( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/css/intlTelInput.css', dirname( __FILE__ ) ), array(), '11.0.11' );
wp_enqueue_style( 'gravityforms-phone-extension', plugins_url( 'assets/css/style.css', dirname( __FILE__ ) ), array(), $this->_version );

// register & enqueue scripts
wp_enqueue_script( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/js/intlTelInput.min.js', dirname( __FILE__ ) ), array( 'jquery' ), '11.0.11', true );
wp_enqueue_script( 'intl-tel-input-utils', plugins_url( 'vendor/intl-tel-input/js/utils.js', dirname( __FILE__ ) ), array( 'jquery', 'intl-tel-input' ), '11.0.11', true );
wp_enqueue_script( 'gravityforms-phone-extension', plugins_url( 'assets/js/init.js', dirname( __FILE__ ) ), array( 'jquery', 'intl-tel-input' ), $this->_version, true );

}

}

0 comments on commit ea4df59

Please sign in to comment.