-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.plugdigital.php
More file actions
230 lines (169 loc) · 5.98 KB
/
class.plugdigital.php
File metadata and controls
230 lines (169 loc) · 5.98 KB
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
<?php
/**
* pdmx - PlugDigital México
* Author: Manuel Padilla manuel@plugdigital.net
*/
class pdmx {
const NONCE = 'plugdigital';
private static $initiated = false;
public static function init() {
// Google Analytics ID?
if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-pdmx-google-analytics-id' ) {
self::enter_pdmx_google_analytics_id();
}
// Facebook Pixel ID?
if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-pdmx-facebook-pixel-id' ) {
self::enter_pdmx_facebook_pixel_id();
}
// Login Image?
if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-pdmx-login-image' ) {
self::enter_pdmx_login_image();
}
// DELETE Login Image?
if ( isset( $_POST['action'] ) && $_POST['action'] == 'delete-pdmx-login-image' ) {
self::delete_pdmx_login_image();
}
if ( ! self::$initiated ) {
self::init_hooks();
}
}
/**
* Initializes WordPress hooks
*/
private static function init_hooks() {
self::$initiated = true;
add_action( 'wp_before_admin_bar_render', array( 'pdmx', 'pdmx_add_our_link' ) );
add_action( 'login_footer', array( 'pdmx', 'pdmx_login_powered' ) );
add_action( 'admin_menu', array( 'pdmx', 'pdmx_settings_menu' ) );
add_action( 'wp_head', array( 'pdmx', 'pdmx_google_analytics_code' ) );
add_action( 'wp_head', array( 'pdmx', 'pdmx_facebook_pixel_code' ) );
add_action( 'admin_enqueue_scripts', array( 'pdmx', 'pdmx_admin_scripts' ) );
add_action( 'login_form', array( 'pdmx', 'pdmx_login_image_form' ) );
}
/**
* Enqueue Scripts
*/
public static function pdmx_admin_scripts() {
wp_register_style( 'pdmx-admin-styles', plugin_dir_url( __FILE__ ) . 'assets/css/plugdigital.admin.css', array(), '1.0.0', 'all' );
wp_enqueue_style( 'pdmx-admin-styles' );
wp_enqueue_media();
wp_register_script( 'pdmx-admin-script', plugin_dir_url( __FILE__ ) . 'assets/js/plugdigital.admin.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'pdmx-admin-script' );
}
/**
* Add Plug Digital link at top bar
*/
public static function pdmx_add_our_link() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'plugdigital-site',
'title' => 'Plug Digital',
'href' => 'https://www.plugdigital.net'
) );
}
/**
* Add Powered By Plug Digital at login form
*/
public static function pdmx_login_powered() {
pdmx::view('powered-by');
}
/**
* Show star page
*/
public static function pdmx_start_page() {
pdmx::view('start');
}
public static function view( $name, array $args = array() ) {
$args = apply_filters( 'pdmx_view_arguments', $args, $name );
foreach ( $args AS $key => $val ) {
$$key = $val;
}
load_plugin_textdomain( 'PlugDigital' );
$file = PLUGDIGITAL__PLUGIN_DIR . 'views/'. $name . '.php';
include( $file );
}
// Add options page
public static function pdmx_settings_menu() {
add_options_page( 'Optimización y Rendimiento', 'Optimización y Rendimiento', 'manage_options', 'pdmx-settings-menu', 'pdmx::pdmx_start_page' );
}
/**
* Google Analytics ID DB Save
*/
public static function enter_pdmx_google_analytics_id() {
if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
return false;
update_option( 'pdmx_google_analytics_id', $_POST['pdmx-google-analytics-id'] );
return true;
}
/**
* Facebook Pixel ID DB Save
*/
public static function enter_pdmx_facebook_pixel_id() {
if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
return false;
update_option( 'pdmx_facebook_pixel_id', $_POST['pdmx-facebook-pixel-id'] );
return true;
}
/**
* Login image DB Save
*/
public static function enter_pdmx_login_image() {
if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
return false;
update_option( 'pdmx_login_image', $_POST['pdmx-login-image'] );
return true;
}
/**
* DELETE Login image DB Save
*/
public static function delete_pdmx_login_image() {
if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
return false;
delete_option( 'pdmx_login_image' );
return true;
}
/**
* Add Google Analytics ID to the head
*/
public static function pdmx_google_analytics_code( ) {
if ( get_option( 'pdmx_google_analytics_id' ) ): ?>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '<?php echo get_option( 'pdmx_google_analytics_id' ); ?>', 'auto');
ga('send', 'pageview');
</script>
<!-- END Google Analytics -->
<?php endif;
}
/**
* Add Facebook Pixel to the head
*/
public static function pdmx_facebook_pixel_code( ) {
if ( get_option( 'pdmx_facebook_pixel_id' ) ): ?>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '<?php echo get_option( 'pdmx_facebook_pixel_id' ); ?>'); // Insert your pixel ID here.
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=<?php echo get_option( 'pdmx_facebook_pixel_id' ); ?>&ev=PageView&noscript=1" /></noscript>
<!-- END Facebook Pixel Code -->
<?php endif;
}
/**
* Add custom login form image
*/
public static function pdmx_login_image_form() { ?>
<style type="text/css">
.login h1 a{ background-image: none,url(<?php echo get_option( 'pdmx_login_image' ); ?>); background-repeat: no-repeat; background-size: contain; width: 100%}
</style>
<?php }
} // class pdmx end