-
Notifications
You must be signed in to change notification settings - Fork 17
/
gravity-tooltips.php
162 lines (137 loc) · 4.14 KB
/
gravity-tooltips.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Plugin Name: Gravity Forms Tooltips
* Plugin URI: https://github.com/norcross/gravity-tooltips
* Description: Add custom tooltips in Gravity Forms.
* Author: Andrew Norcross
* Author URI: http://andrewnorcross.com/
* Version: 2.0.5
* Text Domain: gravity-tooltips
* Requires WP: 4.0
* Domain Path: languages
* GitHub Plugin URI: https://github.com/norcross/gravity-tooltips
*/
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Andrew Norcross
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// Define our base if we haven't already.
if ( ! defined( 'GFT_BASE' ) ) {
define( 'GFT_BASE', plugin_basename(__FILE__) );
}
// Define our version if we haven't already.
if ( ! defined( 'GFT_VER' ) ) {
define( 'GFT_VER', '2.0.5' );
}
/**
* Core class.
*
* Contains the loading functionality and sets our default options.
*/
class GF_Tooltips
{
/**
* Static property to hold our singleton instance.
*
* @var instance
*/
static $instance = false;
/**
* This is our constructor. there are many like it, but this one is mine.
*
* @return GF_Tooltips
*/
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
add_action( 'plugins_loaded', array( $this, 'load_files' ) );
// Activation hook.
register_activation_hook( __FILE__, array( $this, 'set_options' ) );
}
/**
* If an instance exists, this returns it. If not, it creates one and
* retuns it.
*
* @return $instance
*/
public static function getInstance() {
// Check for an instance of the class before loading.
if ( ! self::$instance ) {
self::$instance = new self;
}
// Return the instance.
return self::$instance;
}
/**
* Load our textdomain.
*
* @return string load_plugin_textdomain
*/
public function textdomain() {
load_plugin_textdomain( 'gravity-tooltips', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Load our files.
*
* @return void
*/
public function load_files() {
// Confirm we have our actual Gravity Forms class first.
if ( ! class_exists( 'RGForms' ) ) {
return;
}
// Load our admin setup.
if ( is_admin() ) {
require_once( 'lib/admin.php' );
}
// Load our front end setup.
if ( ! is_admin() ) {
require_once( 'lib/front.php' );
}
// Load our helper.
require_once( 'lib/helper.php' );
}
/**
* Set our options on activation.
*/
public function set_options() {
// Check for data first.
$exist = get_option( 'gf-tooltips' );
// We have it. leave it alone.
if ( ! empty( $exist ) ) {
return;
}
// Set a data array.
$data = array(
'type' => 'icon',
'icon' => 'question',
'design' => 'light',
'target' => 'right',
);
// Filter them.
apply_filters( 'gf_tooltips_default_settings', $data );
// Add the option.
update_option( 'gf-tooltips', $data, 'no' );
}
// End our class.
}
// Instantiate our class
$GF_Tooltips = GF_Tooltips::getInstance();