Skip to content

Commit ea4df59

Browse files
committed
Improve plugin structure
1 parent e82be49 commit ea4df59

File tree

3 files changed

+171
-42
lines changed

3 files changed

+171
-42
lines changed

README.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== Gravity Forms - Phone Extension ===
22
Contributors: joehana
3-
Donate link: http://paypal.me/joehana
3+
Donate link: http://paypal.me/anex
44
Tags: forms, phone, input
55
Requires at least: 4.5.0
66
Tested up to: 4.7
7-
Stable tag: 1.0.1
7+
Stable tag: 1.1.0
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

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

2626
== Changelog ==
2727

28+
= 1.1.0 =
29+
* Improve Plugin Structure
30+
* Update intlTelInput to 11.0.11
31+
2832
= 1.0.1 =
2933
* FIX: Remove 'http:' from $.get function in init.js to prevent issues on SSL Sites
3034

gravityforms-phone-extension.php

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: Gravity Forms - Phone Extension
55
* Plugin URI: https://github.com/ANEX-Agency/Gravityforms-Phone-Extension
66
* Description: Extends the Phone Field with a Country Code Selectbox
7-
* Version: 1.0.1
7+
* Version: 1.1.0
88
* Author: ANEX
99
* Author URI: http://anex.at
1010
* License: GPL-2.0+
@@ -13,53 +13,25 @@
1313
* Domain Path: /languages
1414
*/
1515

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

21-
/**
22-
* Create Gravity Forms Phone Extension
23-
* plugin class
24-
*
25-
* @since 1.0.0
26-
*/
27-
28-
class GravityForms_Phone_Extension {
21+
define( 'GF_PHONE_EXTENSION_VERSION', '1.1.0' );
2922

30-
/**
31-
* Initializes the plugin
32-
*/
33-
function __construct() {
34-
35-
// Register site styles
36-
add_action( 'wp_enqueue_scripts', array( $this, 'assets' ) );
37-
38-
}
23+
add_action( 'gform_loaded', array( 'GF_Phone_Extension_Bootstrap', 'load' ), 5 );
3924

25+
class GF_Phone_Extension_Bootstrap {
4026

41-
/**
42-
* Register and enqueue plugin-specific assets.
43-
*/
44-
public function assets() {
45-
46-
// register & enqueue styles
47-
wp_enqueue_style( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/css/intlTelInput.css', __FILE__ ), array(), '9.2.4' );
48-
wp_enqueue_style( 'gravityforms-phone-extension', plugins_url( 'assets/css/style.css', __FILE__ ), array(), '1.0.1' );
27+
public static function load(){
4928

50-
// register & enqueue scripts
51-
wp_enqueue_script( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/js/intlTelInput.min.js', __FILE__ ), array( 'jquery' ), '9.2.4', true );
52-
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 );
53-
wp_enqueue_script( 'gravityforms-phone-extension', plugins_url( 'assets/js/init.js', __FILE__ ), array( 'jquery' ), '1.0.1', true );
29+
require_once( 'includes/class-gf-phone-extension.php' );
5430

31+
GFAddOn::register( 'GF_Phone_Extension' );
5532
}
56-
5733
}
5834

59-
/**
60-
* Call class
61-
*
62-
* @since 1.0.0
63-
*/
64-
if( ! is_admin() )
65-
$GravityForms_Phone_Extension= new GravityForms_Phone_Extension();
35+
function gf_phone_extension(){
36+
return GF_Phone_Extension::get_instance();
37+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
3+
/**
4+
* Create Gravity Forms Phone Extension
5+
* plugin class
6+
*
7+
* @since 1.0.0
8+
*/
9+
10+
class GF_Phone_Extension {
11+
12+
/**
13+
* Contains an instance of this class, if available.
14+
*
15+
* @since 1.0.0
16+
* @access private
17+
* @var object $_instance If available, contains an instance of this class.
18+
*/
19+
private static $_instance = null;
20+
21+
/**
22+
* Defines the version of the Propstack Add-On.
23+
*
24+
* @since 1.0.0
25+
* @access protected
26+
* @var string $_version Contains the version, defined from gravityforms-propstack.php
27+
*/
28+
protected $_version = GF_PHONE_EXTENSION_VERSION;
29+
30+
/**
31+
* Defines the minimum Gravity Forms version required.
32+
*
33+
* @since 1.0.0
34+
* @access protected
35+
* @var string $_min_gravityforms_version The minimum version required.
36+
*/
37+
protected $_min_gravityforms_version = '2.2';
38+
39+
/**
40+
* Defines the plugin slug.
41+
*
42+
* @since 1.0.0
43+
* @access protected
44+
* @var string $_slug The slug used for this plugin.
45+
*/
46+
protected $_slug = 'gravityforms-phone-extension';
47+
48+
/**
49+
* Defines the main plugin file.
50+
*
51+
* @since 1.0.0
52+
* @access protected
53+
* @var string $_path The path to the main plugin file, relative to the plugins folder.
54+
*/
55+
protected $_path = 'gravityforms-phone-extension/gravityforms-phone-extension.php';
56+
57+
/**
58+
* Defines the full path to this class file.
59+
*
60+
* @since 1.0.0
61+
* @access protected
62+
* @var string $_full_path The full path.
63+
*/
64+
protected $_full_path = __FILE__;
65+
66+
/**
67+
* Defines the URL where this Add-On can be found.
68+
*
69+
* @since 1.0.0
70+
* @access protected
71+
* @var string The URL of the Add-On.
72+
*/
73+
protected $_url = 'http://www.anex.at';
74+
75+
/**
76+
* Defines the title of this Add-On.
77+
*
78+
* @since 1.0.0
79+
* @access protected
80+
* @var string $_title The title of the Add-On.
81+
*/
82+
protected $_title = 'Gravity Forms Phone Extension Add-On';
83+
84+
/**
85+
* Defines the short title of the Add-On.
86+
*
87+
* @since 1.0.0
88+
* @access protected
89+
* @var string $_short_title The short title.
90+
*/
91+
protected $_short_title = 'Phone Extension';
92+
93+
/**
94+
* Defines if Add-On should use Gravity Forms servers for update data.
95+
*
96+
* @since 1.0.0
97+
* @access protected
98+
* @var bool
99+
*/
100+
protected $_enable_rg_autoupgrade = false;
101+
102+
/**
103+
* Get an instance of this class.
104+
*
105+
* @since 1.0.0
106+
* @access public
107+
*
108+
* @return GF_Phone_Extension
109+
*/
110+
public static function get_instance() {
111+
112+
if ( null === self::$_instance ) {
113+
self::$_instance = new self;
114+
}
115+
116+
return self::$_instance;
117+
118+
}
119+
120+
/**
121+
* Initializes the plugin
122+
*
123+
* @since 1.0.0
124+
* @access public
125+
*/
126+
public function __construct() {
127+
128+
// Register site styles
129+
add_action( 'wp_enqueue_scripts', array( $this, 'assets' ) );
130+
131+
}
132+
133+
134+
/**
135+
* Register and enqueue plugin-specific assets
136+
*
137+
* @since 1.0.0
138+
* @access public
139+
*/
140+
public function assets() {
141+
142+
// register & enqueue styles
143+
wp_enqueue_style( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/css/intlTelInput.css', dirname( __FILE__ ) ), array(), '11.0.11' );
144+
wp_enqueue_style( 'gravityforms-phone-extension', plugins_url( 'assets/css/style.css', dirname( __FILE__ ) ), array(), $this->_version );
145+
146+
// register & enqueue scripts
147+
wp_enqueue_script( 'intl-tel-input', plugins_url( 'vendor/intl-tel-input/js/intlTelInput.min.js', dirname( __FILE__ ) ), array( 'jquery' ), '11.0.11', true );
148+
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 );
149+
wp_enqueue_script( 'gravityforms-phone-extension', plugins_url( 'assets/js/init.js', dirname( __FILE__ ) ), array( 'jquery', 'intl-tel-input' ), $this->_version, true );
150+
151+
}
152+
153+
}

0 commit comments

Comments
 (0)