-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenesis-footer-builder.php
283 lines (180 loc) · 10.8 KB
/
genesis-footer-builder.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
/**
*
* Plugin Name: Genesis Footer Builder
* Plugin URI: https://www.converticacommerce.com/?p=17056
* Description: Helps build a custom footer for Genesis or Genesis child-themes.
* Version: 1.3.5
* Author: Shivanand Sharma
* Author URI: https://www.converticacommerce.com
* License: GPL-2.0+
* License URI: http://www.opensource.org/licenses/gpl-license.php
* Text Domain: genesis-footer-builder
* Donate Link: https://www.converticacommerce.com?item_name=Donation%20for%20Genesis%20Footer%20Builder&cmd=_xclick¤cy_code=USD&[email protected]
*
*/
define( 'GFB_SETTINGS_FIELD','genesis-footer-builder' );
define( 'GFB_PLUGIN_URL', plugin_dir_url(__FILE__) );
define( 'GFB_PLUGIN_PATH', plugin_dir_path(__FILE__) );
define( 'GFB_PLUGIN_DOMAIN', 'genesis-footer-builder' );
define( 'GFB_PLUGIN_NAME', 'Genesis Footer Builder' );
define( 'GFB_SETTINGS_VER', '1.0' );
register_activation_hook( __FILE__, 'gfb_activation' );
/**
* Checks if any theme from Binary Turf is present / active
* Helper function to check if any theme from Binary Turf is installed or active on site
*
* @author Shivanand Sharma
* @return bool true | false
* @since 1.3.1
*/
function gfb_is_bt_theme() {
$theme = wp_get_theme();
$bt_themes_td = array( 'lander-core', 'captivate', 'femme-flora' );
$current_theme_td = $theme->get( 'TextDomain' );
if( in_array( $current_theme_td, $bt_themes_td ) )
return true;
return false;
}
function gfb_activation() {
if ( 'genesis' != basename( get_template_directory() ) && ! gfb_is_bt_theme() ) {
gfb_deactivate_template_err();
}
if( !defined( 'PARENT_THEME_VERSION' ) || !version_compare( PARENT_THEME_VERSION, '2.1.0', '>=' ) )
gfb_deactivate_version_err( '2.1.0', '3.9.2' );
}
/**
* Deactivate the plugin if Genesis is not 'active'
* Useful when users switch themes
*/
add_action( 'admin_init', 'gfb_deactivate_self_no_genesis' );
function gfb_deactivate_self_no_genesis() {
if ( !function_exists( 'genesis_constants' ) && !gfb_is_bt_theme() ) {
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate plugin
gfb_deactivate_genesis_inactive();
}
}
/**
* Check if the parent theme Genesis is installed and activated, else deactivate
*/
function gfb_deactivate_template_err() {
deactivate_plugins( plugin_basename( __FILE__ ) );
$notice = sprintf( __( '%s requires %sGenesis Framework%s to be installed and activated. Please install Genesis as the parent theme to use Genesis Footer Builder.%sIf Genesis Framework / Genesis child theme is already installed, go to %sThemes page%s and activate it.%s← Return to Plugins page%sGo to Themes page →%s', 'genesis-footer-builder' ), '<p>' . GFB_PLUGIN_NAME, '<a title="Genesis Framework" href="http://www.binaryturf.com/genesis">', '</a>', '</p><p>', '<a title="Go to Themes page" href="' . self_admin_url('themes.php') . '">', '</a>', '</p><p><a href="' . self_admin_url( 'plugins.php' ) . '" style="background-color: #f2f2f2; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); display: inline-block; margin: 0 auto; padding: 10px 12px; float: left;" target="_parent">', '</a><a href="' . self_admin_url( 'themes.php' ) . '" style="background-color: #f2f2f2; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); display: inline-block; margin: 0 auto; padding: 10px 12px; float: right;">','</a><span style="display: block; clear: both;"></span></p>' );
wp_die( $notice );
}
/**
* Check the WordPress and Genesis version
* WordPress to be 3.9.2 and Genesis to be 2.1.0 to use the plugin, else deactivate
*/
function gfb_deactivate_version_err( $genesis_version = '2.1.0', $wp_version = '3.9.2' ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
$notice = sprintf( __( '%s requires WordPress version %s and Genesis version %s or greater. Please update to the latest version and try again.%s← Return to Plugins page%sGo to Themes page →%s', 'genesis-footer-builder' ), '<p>' . GFB_PLUGIN_NAME, '<strong>' . $wp_version . '</strong>', '<strong>' . $genesis_version . '</strong>', '</p><p><a href="' . self_admin_url( 'plugins.php' ) . '" style="background-color: #f2f2f2; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); display: inline-block; margin: 0 auto; padding: 10px 12px; float: left;" target="_parent">', '</a><a href="' . self_admin_url( 'themes.php' ) . '" style="background-color: #f2f2f2; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); display: inline-block; margin: 0 auto; padding: 10px 12px; float: right;">','</a><span style="display: block; clear: both;"></span></p>' );
wp_die( $notice );
}
/**
* Check the active theme to be Genesis
* Deactivate the plugin, if Genesis not active
*/
function gfb_deactivate_genesis_inactive() {
deactivate_plugins( plugin_basename( __FILE__ ) );
$notice = sprintf( __( '%s plugin requires %sGenesis Framework%s to be installed and activated. Please install Genesis as the parent theme to use %s.%sThe plugin will now be deactivated.%s← Return to Plugins page%sGo to Themes page →%s', 'genesis-footer-builder' ), '<p>' . GFB_PLUGIN_NAME, '<a href="http://www.binaryturf.com/genesis">', '</a>', GFB_PLUGIN_NAME, '</p><p>', '</p><p><a href="' . self_admin_url( 'plugins.php' ) . '" style="background-color: #f2f2f2; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); display: inline-block; margin: 0 auto; padding: 10px 12px; float: left;" target="_parent">', '</a><a href="' . self_admin_url( 'themes.php' ) . '" style="background-color: #f2f2f2; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); display: inline-block; margin: 0 auto; padding: 10px 12px; float: right;">','</a><span style="display: block; clear: both;"></span></p>' );
wp_die( $notice );
}
/*
* Safe load plugin textdomain, during init for translations
* @refer http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
*/
add_action( 'init', 'gfb_load_textdomain' );
/**
* Makes the plugin translation ready
* Let's make the plugin also look in the WordPress languages directory for translations
* Translation files should follow the syntax: genesis-footer-builder-{your-domain}
*
* Example: To set the plugin language to German(de_DE), you can drop in your translation files named as: genesis-footer-builder-de_DE.mo / genesis-footer-builder-de_DE.po
*/
function gfb_load_textdomain() {
$domain = 'genesis-footer-builder';
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
/* Users can create a directory 'genesis-footer-builder' under '../wp-content/languages/' and drop in translation files with the similar filename syntax as described above */
load_textdomain( $domain, WP_LANG_DIR . '/genesis-footer-builder/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, false, dirname( plugin_basename( __FILE__ ) ) .'/languages/' );
}
/**
* Adding the Support and Author links to the plugin in the admin area on the plugins page
*/
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'gfb_add_action_links' );
function gfb_add_action_links ( $links ) {
$link = array(
'<a href="'. admin_url( 'admin.php?page=genesis-footer-builder' ) .'">Settings</a>',
'<a href="https://wordpress.org/support/plugin/genesis-footer-builder" target="_blank">Support</a>'
);
return array_merge( $links, $link );
}
/**
* Include the plugin file which declares the constructor class and the plugin functions file
* Registering the menu location for the footer menu. The footer menu option is enabled by default.
* Declaring the function that the plugin uses to filter the footer output
*/
add_action( 'genesis_init', 'gfb_loader', 20 );
function gfb_loader() {
/** Call the upgrade routine to update the plugin and plugin settings **/
require_once( GFB_PLUGIN_PATH . 'admin/gfb-update.php' );
if ( is_admin() ) {
require_once( GFB_PLUGIN_PATH . 'admin/gfb-admin.php' );
add_filter( 'admin_body_class', 'gb_admin_page_class' );
add_filter( 'genesis_export_options', 'gfb_add_export_settings' );
}
require_once( GFB_PLUGIN_PATH . 'admin/gfb-functions.php' );
/** Check if the footer menu is enabled in the plugin settings page and register the menu location **/
$gfb_menu_enabled = gfb_get_option( 'gfb_footer_menu' );
if( $gfb_menu_enabled ){
$gfb_menu = register_nav_menu( 'gfb_footer_menu', 'Genesis Footer Builder Menu' );
}
/** Hook the footer output filter used by the plugin, possibly last in the queue **/
add_filter( 'genesis_footer_output', 'gfb_customized_footer', 12, 3 );
}
add_action( 'genesis_admin_menu', 'gfb_admin_menu' );
function gfb_admin_menu() {
$gfb_admin = new Gfb_Admin;
}
/*
* Setting up the default options for the plugin
* A filter is made available to filter the defaults for the plugin
*/
function gfb_defaults() {
$defaults = array(
'gfb_settings_version' => GFB_SETTINGS_VER,
'gfb_current_date' => 1, // Current year for Copyrights, 0 if unchecked
'gfb_date_format' => 0,
'gfb_date' => date( 'Y' ), // Custom year single
'gfb_date_start' => date( 'Y' ), // Custom year duration start, current year by default
'gfb_date_end' => date( 'Y', strtotime( '+1 year' ) ), // Custom year duration end, next year to the current by default
'gfb_brand' => '', // Brand name
'gfb_privacy' => 0, // Privacy page id, 0 for none
'gfb_disclaimer' => 0, // Disclaimer page id, 0 for none
'gfb_footer_menu' => 1, // Footer menu checkbox
'gfb_output' => '<p>Copyright © [gfb-date] — [gfb-brand] • All rights reserved. • [gfb-privacy-policy] • [gfb-disclaimer]</p><p>[gfb-affiliate-link] • [footer_wordpress_link] • [footer_loginout]</p>', // Output
'gfb_affiliate_link' => 'http://my.studiopress.com/themes/genesis',
);
return apply_filters( 'gfb_defaults', $defaults );
}
/*
* Creating a function to retrieve the plugin settings from the database
*/
function gfb_get_option( $key ) {
return genesis_get_option( $key, GFB_SETTINGS_FIELD );
}
/*
* Adding the date format option toggle to the available genesis toggles
*/
add_filter( 'genesis_toggles', 'gfb_toggles' );
function gfb_toggles( $toggles ) {
$gfb_toggle = array(
'gfb_current_date' => array( '#genesis-footer-builder\\[gfb_current_date\\]', '#gfb-custom-date', '_unchecked' ),
'gfb_date' => array( '#genesis-footer-builder\\[gfb_date_format\\]', '#gfb-date-format-unset', '_unchecked' ),
'gfb_date_start' => array( '#genesis-footer-builder\\[gfb_date_format\\]', '#gfb-date-format-set', '_checked' ),
'gfb_date_end' => array( '#genesis-footer-builder\\[gfb_date_format\\]', '#gfb-date-format-set', '_checked' ),
);
$toggles = array_merge( $toggles, $gfb_toggle );
return $toggles;
}