PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.7
GiveWP – Donation Plugin and Fundraising Platform v2.0.7
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / class-addon-activation-banner.php
give / includes / admin Last commit date
donors 7 years ago emails 7 years ago forms 7 years ago payments 7 years ago reports 7 years ago settings 7 years ago shortcodes 7 years ago tools 7 years ago upgrades 7 years ago views 7 years ago EDD_SL_Plugin_Updater.php 7 years ago abstract-admin-settings-page.php 7 years ago add-ons.php 7 years ago admin-actions.php 7 years ago admin-filters.php 7 years ago admin-footer.php 7 years ago admin-pages.php 7 years ago class-addon-activation-banner.php 7 years ago class-admin-settings.php 7 years ago class-api-keys-table.php 7 years ago class-blank-slate.php 7 years ago class-give-settings.php 7 years ago class-i18n-module.php 7 years ago dashboard-widgets.php 7 years ago give-metabox-functions.php 7 years ago plugins.php 7 years ago welcome.php 7 years ago
class-addon-activation-banner.php
373 lines
1 <?php
2 /**
3 * Give Activation Banner
4 *
5 * @author WordImpress
6 * @version 1.0
7 * https://github.com/WordImpress/plugin-activation-banner-demo
8 */
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class Give_Addon_Activation_Banner
17 */
18 class Give_Addon_Activation_Banner {
19
20 /**
21 * Class constructor.
22 *
23 * @since 1.0
24 * @access public
25 *
26 * @param array $_banner_details {
27 * 'file' => __FILE__, // (required) Directory path to the main plugin file
28 * 'name' => __( 'Authorize.net Gateway', 'give-authorize' ), // (required) Name of the Add-on
29 * 'version' => GIVE_AUTHORIZE_VERSION, // (required)The most current version
30 * 'documentation_url' => 'http://docs.givewp.com/addon-authorize',// (required)
31 * 'support_url' => 'https://givewp.com/support/', // (required)Location of Add-on settings page, leave blank to hide
32 * 'testing' => false, // (required) Never leave as "true" in production!!!
33 * }
34 */
35 function __construct( $_banner_details ) {
36 $current_user = wp_get_current_user();
37
38 $this->plugin_activate_by = 0;
39 $this->banner_details = $_banner_details;
40 $this->test_mode = ( $this->banner_details['testing'] == 'true' ) ? true : false;
41 $this->nag_meta_key = 'give_addon_activation_ignore_' . sanitize_title( $this->banner_details['name'] );
42 $this->activate_by_meta_key = 'give_addon_' . sanitize_title( $this->banner_details['name'] ) . '_active_by_user';
43
44 //Get current user
45 $this->user_id = $current_user->ID;
46
47 // Set up hooks.
48 $this->init();
49
50 // Store user id who activate plugin.
51 $this->add_addon_activate_meta();
52 }
53
54 /**
55 * Set up WordPress filters to hook into WP's update process.
56 *
57 * @since 1.0
58 * @access public
59 *
60 * @return void
61 */
62 public function init() {
63
64 //Testing?
65 if ( $this->test_mode ) {
66 delete_user_meta( $this->user_id, $this->nag_meta_key );
67 }
68
69 //Get the current page to add the notice to
70 add_action( 'current_screen', array( $this, 'give_addon_notice_ignore' ) );
71 add_action( 'admin_notices', array( $this, 'give_addon_activation_admin_notice' ) );
72
73 // File path of addon must be included in banner detail other addon activate meta will not delete.
74 $file_name = $this->get_plugin_file_name();
75
76 if ( ! empty( $file_name ) ) {
77 add_action( 'deactivate_' . $file_name, array( $this, 'remove_addon_activate_meta' ) );
78 }
79 }
80
81
82 /**
83 * Check if current page is plugin page or not.
84 *
85 * @since 1.8
86 * @access private
87 * @return bool
88 */
89 private function is_plugin_page() {
90 $screen = get_current_screen();
91
92 return ( $screen->parent_file === 'plugins.php' );
93 }
94
95
96 /**
97 * Give Addon Activation Banner
98 *
99 * @since 1.0
100 * @access public
101 */
102 public function give_addon_activation_admin_notice() {
103
104 // Bailout.
105 if ( ! $this->is_plugin_page() || $this->user_id !== $this->plugin_activate_by ) {
106 return;
107 }
108
109 // If the user hasn't already dismissed the alert, output activation banner.
110 if ( ! get_user_meta( $this->user_id, $this->nag_meta_key ) ) {
111
112 $this->print_css();
113
114 // Output inline styles here because there's no reason
115 // to enqueued them after the alert is dismissed.
116
117 ob_start();
118 ?>
119
120 <div class="updated give-addon-alert give-notice" style="display: none">
121
122 <img src="<?php echo GIVE_PLUGIN_URL; ?>assets/images/svg/give-icon-full-circle.svg" class="give-logo"/>
123
124 <div class="give-alert-message">
125 <h3><?php
126 printf(
127 /* translators: %s: Add-on name */
128 esc_html__( "Thank you for installing Give's %s Add-on!", 'give' ),
129 '<span>' . $this->banner_details['name'] . '</span>'
130 );
131 ?></h3>
132
133 <a href="<?php
134 //The Dismiss Button.
135 $nag_admin_dismiss_url = 'plugins.php?' . $this->nag_meta_key . '=0';
136 echo admin_url( $nag_admin_dismiss_url ); ?>" class="dismiss"><span
137 class="dashicons dashicons-dismiss"></span></a>
138
139 <div class="alert-actions">
140
141 <?php //Point them to your settings page.
142 if ( isset( $this->banner_details['settings_url'] ) ) { ?>
143 <a href="<?php echo $this->banner_details['settings_url']; ?>">
144 <span class="dashicons dashicons-admin-settings"></span><?php esc_html_e( 'Go to Settings', 'give' ); ?>
145 </a>
146 <?php } ?>
147
148 <?php
149 // Show them how to configure the Addon.
150 if ( isset( $this->banner_details['documentation_url'] ) ) { ?>
151 <a href="<?php echo $this->banner_details['documentation_url'] ?>" target="_blank">
152 <span class="dashicons dashicons-media-text"></span><?php
153 printf(
154 /* translators: %s: Add-on name */
155 esc_html__( 'Documentation: %s Add-on', 'give' ),
156 $this->banner_details['name']
157 );
158 ?></a>
159 <?php } ?>
160 <?php
161 //Let them signup for plugin updates
162 if ( isset( $this->banner_details['support_url'] ) ) { ?>
163
164 <a href="<?php echo $this->banner_details['support_url'] ?>" target="_blank">
165 <span class="dashicons dashicons-sos"></span><?php esc_html_e( 'Get Support', 'give' ); ?>
166 </a>
167
168 <?php } ?>
169
170 </div>
171 </div>
172 </div>
173 <?php
174
175 $notice_html = ob_get_clean();
176
177
178 // Register notice.
179 Give()->notices->register_notice( array(
180 'id' => 'give_' . sanitize_title( $this->banner_details['name'] ) . '_notice',
181 'type' => 'updated',
182 'description_html' => $notice_html,
183 'show' => true,
184 ) );
185 }
186 }
187
188
189 /**
190 * Add activation banner css.
191 *
192 * @since 1.8.16
193 * @access private
194 */
195 private function print_css(){
196 ?>
197 <style>
198 div.give-addon-alert.updated {
199 padding: 20px;
200 position: relative;
201 border-color: #66BB6A;
202 }
203
204 div.give-alert-message {
205 margin-left: 70px;
206 }
207
208 div.give-addon-alert img.give-logo {
209 max-width: 50px;
210 float: left;
211 }
212
213 div.give-addon-alert h3 {
214 margin: -5px 0 10px;
215 font-size: 22px;
216 font-weight: 300;
217 line-height: 30px;
218 }
219
220 div.give-addon-alert h3 span {
221 font-weight: 700;
222 color: #66BB6A;
223 }
224
225 div.give-addon-alert .alert-actions {
226 }
227
228 div.give-addon-alert a {
229 color: #66BB6A;
230 }
231
232 div.give-addon-alert .alert-actions a {
233 margin-right: 2em;
234 }
235
236 div.give-addon-alert .alert-actions a {
237 text-decoration: underline;
238 }
239
240 div.give-addon-alert .alert-actions a:hover {
241 color: #555555;
242 }
243
244 div.give-addon-alert .alert-actions a span {
245 text-decoration: none;
246 margin-right: 5px;
247 }
248
249 div.give-addon-alert .dismiss {
250 position: absolute;
251 right: 20px;
252 height: 100%;
253 top: 50%;
254 margin-top: -10px;
255 outline: none;
256 box-shadow: none;
257 text-decoration: none;
258 color: #AAA;
259 }
260
261 div.give-addon-alert .dismiss:hover {
262 color: #333;
263 }
264 </style>
265 <?php
266 }
267
268
269 /**
270 * Ignore Nag.
271 *
272 * This is the action that allows the user to dismiss the banner it basically sets a tag to their user meta data
273 *
274 * @since 1.0
275 * @access public
276 */
277 public function give_addon_notice_ignore() {
278
279 /**
280 * If user clicks to ignore the notice, add that to their user meta the banner then checks whether this tag exists already or not.
281 * See here: http://codex.wordpress.org/Function_Reference/add_user_meta
282 */
283 if ( isset( $_GET[ $this->nag_meta_key ] ) && '0' == $_GET[ $this->nag_meta_key ] ) {
284
285 //Get the global user
286 $current_user = wp_get_current_user();
287 $user_id = $current_user->ID;
288
289 add_user_meta( $user_id, $this->nag_meta_key, 'true', true );
290 }
291 }
292
293 /**
294 * Setup user id to option
295 *
296 * @since 1.8
297 * @access private
298 */
299 private function add_addon_activate_meta() {
300 $user_id = get_option( $this->activate_by_meta_key );
301 $this->plugin_activate_by = (int) $user_id;
302
303 if ( ! $user_id ) {
304 add_option( $this->activate_by_meta_key, $this->user_id, '', 'no' );
305 $this->plugin_activate_by = (int) $this->user_id;
306 }
307 }
308
309
310 /**
311 * Delete user id from option if plugin deactivated.
312 *
313 * @since 1.8
314 * @access public
315 */
316 public function remove_addon_activate_meta() {
317 $user_id = get_option( $this->activate_by_meta_key );
318
319 if ( $user_id ) {
320 delete_option( $this->activate_by_meta_key );
321 }
322 }
323
324
325 /**
326 * Get plugin file name.
327 *
328 * @since 1.8
329 * @access private
330 * @return mixed
331 */
332 private function get_plugin_file_name() {
333 $active_plugins = get_option( 'active_plugins' );
334 $file_name = '';
335
336 try {
337
338 // Check addon file path.
339 if ( ! empty( $this->banner_details['file'] ) ) {
340 $file_name = '';
341 if ( $file_path = explode( '/plugins/', $this->banner_details['file'] ) ) {
342 $file_path = array_pop( $file_path );
343 $file_name = current( explode( '/', $file_path ) );
344 }
345
346 if ( empty( $file_name ) ) {
347 return false;
348 }
349
350 foreach ( $active_plugins as $plugin ) {
351 if ( false !== strpos( $plugin, $file_name ) ) {
352 $file_name = $plugin;
353 break;
354 }
355 }
356 } elseif ( WP_DEBUG ) {
357 throw new Exception( __( "File path must be added within the {$this->banner_details['name']} add-on in the banner details.", 'give' ) );
358 }
359
360 // Check plugin path calculated by addon file path.
361 if ( empty( $file_name ) && WP_DEBUG ) {
362 throw new Exception( __( "Empty add-on plugin path for {$this->banner_details['name']} add-on.", 'give' ) );
363 }
364
365 } catch ( Exception $e ) {
366 echo $e->getMessage();
367 }
368
369 return $file_name;
370 }
371
372 }
373