1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Admin Menus |
4
|
|
|
* |
5
|
|
|
* @package SimpleCalendar\Admin |
6
|
|
|
*/ |
7
|
|
|
namespace SimpleCalendar\Admin; |
8
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Admin Menus. |
15
|
|
|
* |
16
|
|
|
* Handles the plugin admin dashboard menus. |
17
|
|
|
* |
18
|
|
|
* @since 3.0.0 |
19
|
|
|
*/ |
20
|
|
|
class Menus { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The main menu screen hook. |
24
|
|
|
* |
25
|
|
|
* @access public |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public static $main_menu = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Plugin basename. |
32
|
|
|
* |
33
|
|
|
* @access private |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private static $plugin = ''; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Set properties. |
40
|
|
|
* |
41
|
|
|
* @since 3.0.0 |
42
|
|
|
*/ |
43
|
|
|
public function __construct() { |
44
|
|
|
|
45
|
|
|
self::$main_menu = 'edit.php?post_type=calendar'; |
46
|
|
|
|
47
|
|
|
add_action( 'admin_menu', array( __CLASS__, 'add_menu_items' ) ); |
48
|
|
|
|
49
|
|
|
self::$plugin = plugin_basename( SIMPLE_CALENDAR_MAIN_FILE ); |
50
|
|
|
|
51
|
|
|
new Welcome(); |
52
|
|
|
|
53
|
|
|
// Links and meta content in plugins page. |
54
|
|
|
add_filter( 'plugin_action_links_' . self::$plugin, array( __CLASS__, 'plugin_action_links' ), 10, 5 ); |
55
|
|
|
add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 ); |
56
|
|
|
// Custom text in admin footer. |
57
|
|
|
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Add menu items. |
62
|
|
|
* |
63
|
|
|
* @since 3.0.0 |
64
|
|
|
*/ |
65
|
|
|
public static function add_menu_items() { |
66
|
|
|
|
67
|
|
|
add_submenu_page( |
68
|
|
|
self::$main_menu, |
69
|
|
|
__( 'Settings', 'google-calendar-events' ), |
70
|
|
|
__( 'Settings', 'google-calendar-events' ), |
71
|
|
|
'manage_options', |
72
|
|
|
'simple-calendar_settings', |
73
|
|
|
function () { |
74
|
|
|
$page = new Pages( 'settings' ); |
75
|
|
|
$page->html(); |
76
|
|
|
} |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
add_submenu_page( |
80
|
|
|
self::$main_menu, |
81
|
|
|
__( 'Add-ons', 'google-calendar-events' ), |
82
|
|
|
__( 'Add-ons', 'google-calendar-events' ), |
83
|
|
|
'manage_options', |
84
|
|
|
'simple-calendar_add_ons', |
85
|
|
|
function() { |
86
|
|
|
$page = new Pages( 'add-ons' ); |
87
|
|
|
$page->html(); |
88
|
|
|
} |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
add_submenu_page( |
92
|
|
|
self::$main_menu, |
93
|
|
|
__( 'Tools', 'google-calendar-events' ), |
94
|
|
|
__( 'Tools', 'google-calendar-events' ), |
95
|
|
|
'manage_options', |
96
|
|
|
'simple-calendar_tools', |
97
|
|
|
function () { |
98
|
|
|
$page = new Pages( 'tools' ); |
99
|
|
|
$page->html(); |
100
|
|
|
} |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
do_action( 'simcal_admin_add_menu_items' ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Action links in plugins page. |
108
|
|
|
* |
109
|
|
|
* @since 3.0.0 |
110
|
|
|
* |
111
|
|
|
* @param array $action_links |
112
|
|
|
* @param string $file |
113
|
|
|
* |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public static function plugin_action_links( $action_links, $file ) { |
117
|
|
|
|
118
|
|
|
if ( self::$plugin == $file ) { |
119
|
|
|
|
120
|
|
|
$links = array(); |
121
|
|
|
$links['settings'] = '<a href="' . admin_url( 'edit.php?post_type=calendar&page=simple-calendar_settings' ) . '">' . __( 'Settings', 'google-calendar-events' ) . '</a>'; |
122
|
|
|
$links['feeds'] = '<a href="' . admin_url( 'edit.php?post_type=calendar' ) . '">' . __( 'Calendars', 'google-calendar-events' ) . '</a>'; |
123
|
|
|
|
124
|
|
|
return apply_filters( 'simcal_plugin_action_links', array_merge( $links, $action_links ) ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $action_links; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Links in plugin meta in plugins page. |
132
|
|
|
* |
133
|
|
|
* @since 3.0.0 |
134
|
|
|
* |
135
|
|
|
* @param array $meta_links |
136
|
|
|
* @param string $file |
137
|
|
|
* |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
public static function plugin_row_meta( $meta_links, $file ) { |
141
|
|
|
|
142
|
|
|
if ( self::$plugin == $file ) { |
143
|
|
|
|
144
|
|
|
$links = array(); |
145
|
|
|
$links['add-ons'] = '<a href="' . simcal_ga_campaign_url( simcal_get_url( 'addons' ), 'core-plugin', 'plugin-listing' ) . '" target="_blank" >' . |
146
|
|
|
__( 'Add-ons', 'google-calendar-events' ) . '</a>'; |
147
|
|
|
|
148
|
|
|
return apply_filters( 'simcal_plugin_action_links', array_merge( $meta_links, $links ) ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $meta_links; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Admin footer text filter callback. |
156
|
|
|
* |
157
|
|
|
* Change this plugin screens admin footer text. |
158
|
|
|
* |
159
|
|
|
* @since 3.0.0 |
160
|
|
|
* |
161
|
|
|
* @param $footer_text |
162
|
|
|
* |
163
|
|
|
* @return string|void |
164
|
|
|
*/ |
165
|
|
|
public function admin_footer_text( $footer_text ) { |
166
|
|
|
|
167
|
|
|
// Check to make sure we're on a SimpleCal admin page |
168
|
|
|
$screen = simcal_is_admin_screen(); |
169
|
|
|
if ( $screen !== false ) { |
170
|
|
|
|
171
|
|
|
if ( 'calendar' == $screen ) { |
|
|
|
|
172
|
|
|
|
173
|
|
|
// Add Drip promo signup form (@see Newsletter meta box). |
174
|
|
|
// Removed 9/26/16. |
|
|
|
|
175
|
|
|
|
176
|
|
|
/* |
177
|
|
|
$drip_form_id = '5368192'; |
178
|
|
|
|
179
|
|
|
?> |
180
|
|
|
<form id="simcal-drip-form" |
181
|
|
|
method="post" |
182
|
|
|
target="_blank" |
183
|
|
|
action="https://www.getdrip.com/forms/<?php echo $drip_form_id; ?>/submissions/" |
184
|
|
|
data-drip-embedded-form="<?php echo $drip_form_id; ?>"> |
185
|
|
|
<input type="hidden" |
186
|
|
|
id="simcal-drip-real-field-first_name" |
187
|
|
|
name="fields[first_name]" |
188
|
|
|
value="" /> |
189
|
|
|
<input type="hidden" |
190
|
|
|
id="simcal-drip-real-field-email" |
191
|
|
|
name="fields[email]" |
192
|
|
|
value="" /> |
193
|
|
|
<input type="submit" |
194
|
|
|
class="hidden"/> |
195
|
|
|
</form> |
196
|
|
|
<?php |
197
|
|
|
*/ |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
// Change the footer text |
201
|
|
|
if ( ! get_option( 'simple-calendar_admin_footer_text_rated' ) ) { |
202
|
|
|
|
203
|
|
|
$footer_text = sprintf( |
204
|
|
|
__( 'If you like <strong>Simple Calendar</strong> please leave us a %s★★★★★ rating on WordPress.org%s. A huge thank you in advance!', 'google-calendar-events' ), |
205
|
|
|
'<a href="https://wordpress.org/support/view/plugin-reviews/google-calendar-events?filter=5#postform" target="_blank" class="simcal-rating-link" data-rated="' . esc_attr__( 'Thanks :)', 'google-calendar-events' ) . '">', '</a>' |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$footer_text .= '<script type="text/javascript">'; |
209
|
|
|
$footer_text .= "jQuery( 'a.simcal-rating-link' ).click( function() { |
210
|
|
|
jQuery.post( '" . \SimpleCalendar\plugin()->ajax_url() . "', { action: 'simcal_rated' } ); |
211
|
|
|
jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) ); |
212
|
|
|
});"; |
213
|
|
|
$footer_text .= '</script>'; |
214
|
|
|
|
215
|
|
|
} else { |
216
|
|
|
|
217
|
|
|
$footer_text = __( 'Thanks for using Simple Calendar!', 'google-calendar-events' ); |
218
|
|
|
|
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
return $footer_text; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
} |
227
|
|
|
|
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.