-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.admin.php
More file actions
executable file
·147 lines (121 loc) · 3.98 KB
/
class.admin.php
File metadata and controls
executable file
·147 lines (121 loc) · 3.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
<?php
// Exit If Accessed Directly
if( ! defined( 'ABSPATH' ) ) { exit; }
// AJAX Load Script
add_action( 'admin_enqueue_scripts', function() {
wp_enqueue_script( 'bmew_admin', plugin_dir_url( __FILE__ ) . 'admin.js', [ 'jquery' ], null );
} );
// Plugin Action Links
add_filter(
'plugin_action_links_woo-benchmark-email/woo-benchmark-email.php',
function( $links ) {
$settings = [
'settings' => sprintf(
'<a href="%s">%s</a>',
admin_url( 'admin.php?page=wc-settings&tab=bmew' ),
__( 'Settings', 'woo-benchmark-email' )
),
];
return array_merge( $settings, $links );
} );
// Admin Dashboard Notifications
add_action( 'wp_dashboard_setup', function() {
// Ensure is_plugin_active() Exists
if( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$messages = [];
// Handle Sister Product Dismissal Request
if( ! empty( $_REQUEST['bmew_dismiss_sister'] ) && check_admin_referer( 'bmew_dismiss_sister' ) ) {
update_option( 'bmew_sister_dismissed', current_time( 'timestamp') );
}
// Check Sister Product
$bmew_sister_dismissed = get_option( 'bmew_sister_dismissed' );
if(
$bmew_sister_dismissed < current_time( 'timestamp') - 86400 * 90
&& ! is_plugin_active( 'benchmark-email-lite/benchmark-email-lite.php' )
&& current_user_can( 'activate_plugins' )
) {
// Plugin Installed But Not Activated
if( file_exists( WP_PLUGIN_DIR . '/benchmark-email-lite/benchmark-email-lite.php' ) ) {
$messages[] = sprintf(
'
%s <strong><a href="%s">%s</a></strong>
<a style="float:right;" href="%s">%s</a>
',
__( 'Activate our sister product Benchmark Email Lite to view campaign statistics.', 'woo-benchmark-email' ),
bmew_admin::get_sister_activate_link(),
__( 'Activate Now', 'woo-benchmark-email' ),
bmew_admin::get_sister_dismiss_link(),
__( 'dismiss for 90 days', 'woo-benchmark-email' )
);
// Plugin Not Installed
} else {
$messages[] = sprintf(
'
%s <strong><a href="%s">%s</a></strong>
<a style="float:right;" href="%s">%s</a>
',
__( 'Install our sister product Benchmark Email Lite to view campaign statistics.', 'woo-benchmark-email' ),
bmew_admin::get_sister_install_link(),
__( 'Install Now', 'woo-benchmark-email' ),
bmew_admin::get_sister_dismiss_link(),
__( 'dismiss for 90 days', 'woo-benchmark-email' )
);
}
}
// Message If Plugin Isn't Configured
if( empty( get_option( 'bmew_key' ) ) ) {
$messages[] = sprintf(
'%s <strong><a href="admin.php?page=wc-settings&tab=bmew">%s</a></strong>',
__( 'Please configure your API Key to use Woo Benchmark Email.', 'woo-benchmark-email' ),
__( 'Configure Now', 'woo-benchmark-email' )
);
}
// Output Message
if( $messages ) {
foreach( $messages as $message ) {
echo sprintf(
'<div class="notice notice-info is-dismissible"><p>%s</p></div>',
print_r( $message, true )
);
}
}
} );
// Load Settings API Class
add_filter( 'woocommerce_get_settings_pages', function( $settings ) {
$settings[] = include( 'class.wc-settings.php' );
return $settings;
} );
// Administrative Class
class bmew_admin {
// Sister Install Link
static function get_sister_install_link() {
$action = 'install-plugin';
$slug = 'benchmark-email-lite';
return wp_nonce_url(
add_query_arg(
[ 'action' => $action, 'plugin' => $slug ],
admin_url( 'update.php' )
),
$action . '_' . $slug
);
}
// Sister Activate Link
static function get_sister_activate_link( $action='activate' ) {
$plugin = 'benchmark-email-lite/benchmark-email-lite.php';
$_REQUEST['plugin'] = $plugin;
return wp_nonce_url(
add_query_arg(
[ 'action' => $action, 'plugin' => $plugin, 'plugin_status' => 'all', 'paged' => '1&s' ],
admin_url( 'plugins.php' )
),
$action . '-plugin_' . $plugin
);
}
// Sister Dismiss Notice Link
static function get_sister_dismiss_link() {
$url = wp_nonce_url( 'index.php?bmew_dismiss_sister=1', 'bmew_dismiss_sister' );
return $url;
}
}