-
Notifications
You must be signed in to change notification settings - Fork 0
/
atg-plugin-boilerplate.php
184 lines (159 loc) · 5.85 KB
/
atg-plugin-boilerplate.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/*
Plugin Name: ATG Plugin Boilerplate
Plugin URI: http://www.github.com/afgarcia86/atg-plugin-boilerplate/
Description: This is a basic boilerplate plugin for faster plugin development
Version: 1.0.0
Author: AndresTheGiant
Author URI: http://www.andresthegiant.com/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Domain Path: /languages
Text Domain: atgpb
*/
//------------------------------------------------------------------------------------------------------------------
//---------- ATG License Key ---------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
//If you hardcode a ATG License Key here, it will automatically populate on activation.
$atg_license_key = '';
//-- OR ---//
//You can also add the ATG Plugin Boilerplate license key to your wp-config.php file to automatically populate on activation
//Add the code in the comment below to your wp-config.php to do so:
//define('GF_LICENSE_KEY','YOUR_KEY_GOES_HERE');
//------------------------------------------------------------------------------------------------------------------
if ( ! defined( 'ABSPATH' ) ) {
die();
}
/**
* Defines the current page.
* @var string ATG_CURRENT_PAGE The current page
*/
if ( ! defined( 'ATG_CURRENT_PAGE' ) ) {
define( 'ATG_CURRENT_PAGE', basename( $_SERVER['PHP_SELF'] ) );
}
/**
* Checks if an admin page is being viewed
* @var boolean IS_ADMIN True if admin page. False otherwise.
*/
if ( ! defined( 'IS_ADMIN' ) ) {
define( 'IS_ADMIN', is_admin() );
}
require_once( plugin_dir_path( __FILE__ ) . 'common.php' );
require_once( plugin_dir_path( __FILE__ ) . 'settings.php' );
require_once( plugin_dir_path( __FILE__ ) . 'help.php' );
require_once( plugin_dir_path( __FILE__ ) . 'tinymce-shortcode.php' );
add_action( 'init', array( 'ATGPB', 'init' ) );
/**
* Class ATGPB
*
* Handles the loading of ATG Plugin Boilerplate and other core functionality
*/
class ATGPB {
/**
* Defines this version of ATG Plugin Boilerplate
*
* @access public
* @static
* @var string $version The version number
*/
public static $version = '1.0.0';
/**
* Initializes ATG Plugin Boilerplate
*
* @access public
* @static
*/
public static function init() {
self::register_scripts();
add_action( 'wp_enqueue_scripts', array( 'ATGPB', 'enqueue_scripts' ) );
add_action( 'admin_menu', array( 'ATGPB', 'create_menu' ) );
add_action( 'admin_init', array( 'ATGPBSettings', 'register_settings_fields' ) );
add_shortcode('insert_button', array('ATGPBShortcode', 'insert_button_func'));
if ( ATGPB::page_supports_insert_button() ) {
// /*** Start Wisiwig Button ***/
// add_filter('mce_external_plugins', array('ATGPBShortcode', 'enqueue_plugin_scripts'));
// add_filter('mce_buttons', array('ATGPBShortcode', 'register_buttons_editor'));
// /*** End Wisiwig Button ***/
/*** Start Media Button ***/
add_action( 'media_buttons', array( 'ATGPBShortcode', 'insert_button' ), 20 );
add_action( 'admin_print_footer_scripts', array( 'ATGPBShortcode', 'insert_shortcode' ) );
/*** End Media Button ***/
}
}
/* Registers ATG Plugin Boilerplate scripts
*
* If SCRIPT_DEBUG constant is set, uses the un-minified version.
*
* @access public
* @static
*/
public static function register_scripts() {
$base_url = ATGPBCommon::get_base_url();
$version = ATGPB::$version;
wp_register_script('atgbp_admin', $base_url . '/js/admin.js', array('jquery'), $version);
wp_register_style('atgbp_admin', $base_url . '/css/admin.css', array(), $version);
}
/**
* Enqueues registered ATG Plugin Boilerplate scripts
*
* @access public
* @static
*
* @param null $hook Not used
*/
public static function enqueue_scripts( $hook ) {
$scripts = array();
if(IS_ADMIN) {
wp_enqueue_script('atgbp_admin');
wp_enqueue_style('atgbp_admin');
}
}
/**
* Creates the "Bootstrap Button" left nav.
*
* @access public
* @static
*
*/
public static function create_menu() {
$capability = current_user_can( 'manage_options' );
$menu_slug = 'atgbp_settings';
/*** Add Settings Page ***/
// add_options_page( __( 'Bootstrap Button', 'atgbp' ), __( 'Bootstrap Button', 'atgbp' ), $capability, $menu_slug, array( 'ATGPBSettings', 'settings_page' ));
/*** End Settigns Page ***/
/*** Add Custom Menu ***/
$admin_icon = self::get_admin_icon_b64();
add_menu_page( __( 'Bootstrap Button', 'atgbp' ), __( 'Bootstrap Button', 'atgbp' ), $capability, $menu_slug, array( 'ATGPBSettings', 'settings_page' ), $admin_icon, 80 );
// Adding submenu pages
add_submenu_page( $menu_slug, __( 'Help', 'atgpb' ), __( 'Help', 'atgpb' ), $capability, 'atgbp_help', array( 'ATGPBHelp', 'help_page' ) );
/*** End Custom Menu ***/
}
/**
* Gets the admin icon for the Forms menu item
*
* @access public
* @static
*
* @param bool|string $color The hex color if changing the color of the icon. Defualts to false.
*
* @return string Base64 encoded icon string.
*/
public static function get_admin_icon_b64() {
$base_url = ATGPBCommon::get_base_url();
$svg = base64_encode(file_get_contents($base_url.'/images/dashicon.svg'));
$icon = 'data:image/svg+xml;base64,' . $svg;
return $icon;
}
/**
* Determines if the "Add Form" button should be added to the page.
*
* @access public
* @static
*
* @return boolean $display_add_form_button True if the page is supported. False otherwise.
*/
public static function page_supports_insert_button() {
$is_post_edit_page = in_array( ATG_CURRENT_PAGE, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php', 'customize.php' ) );
return $is_post_edit_page;
}
}