@@ -55,6 +55,68 @@ public function init() {
5555 add_filter ( 'plugin_row_meta ' , array ( $ this , 'plugin_row_meta ' ), 10 , 2 );
5656
5757 add_filter ( 'string_locator_search_sources_markup ' , array ( $ this , 'add_search_options ' ), 10 , 2 );
58+ add_action ( 'wp_ajax_string_locator_notice_dismiss ' , array ( $ this , 'dismiss_notice ' ) );
59+
60+ add_action ( 'admin_notices ' , array ( $ this , 'show_sponsorship_notice ' ) );
61+ }
62+
63+ public function dismiss_notice () {
64+ // Only users who can use the plugin should be able to dismiss the notice.
65+ if ( ! current_user_can ( 'update_core ' ) || ! wp_verify_nonce ( $ _POST ['_nonce ' ], 'string-locator-notice-dismiss ' ) ) {
66+ return ;
67+ }
68+
69+ update_option ( 'string-locator-sponsorship-notice-dismissed ' , array ( 'is_dismissed ' => true ) );
70+ }
71+
72+ public function show_sponsorship_notice () {
73+ $ screen = get_current_screen ();
74+
75+ // Only show the notice on the plugins search page.
76+ if ( 'tools_page_string-locator ' !== $ screen ->id || isset ( $ _GET ['edit-file ' ] ) ) {
77+ return ;
78+ }
79+
80+ // Do not show the notice to users who have dismissed it.
81+ $ option = get_option ( 'string-locator-sponsorship-notice-dismissed ' , array ( 'is_dismissed ' => false ) );
82+ if ( true === $ option ['is_dismissed ' ] ) {
83+ return ;
84+ }
85+
86+ ?>
87+
88+ <div class="notice notice-info is-dismissible" id="string-locator-sponsorship-notice">
89+ <p>
90+ <?php esc_html_e ( 'Thank you for trying out the String Locator plugin! ' , 'string-locator ' ); ?>
91+ </p>
92+
93+ <p>
94+ <?php esc_html_e ( 'If you like the plugin, please consider making a donation to support the plugin development. ' , 'string-locator ' ); ?>
95+ </p>
96+
97+ <p>
98+ <a href="https://github.com/sponsors/Clorith/" target="_blank" class="button button-primary">
99+ <?php esc_html_e ( 'Donate via GitHub ' , 'string-locator ' ); ?>
100+ </a>
101+
102+ <a href="https://paypal.me/clorith" target="_blank" class="button">
103+ <?php esc_html_e ( 'Donate via PayPal ' , 'string-locator ' ); ?>
104+ </a>
105+ </p>
106+
107+ <script>
108+ jQuery( document ).ready( function( $ ) {
109+ $( '#string-locator-sponsorship-notice' ).on( 'click', '.notice-dismiss', function() {
110+ $.post( ajaxurl, {
111+ action: 'string_locator_notice_dismiss',
112+ _nonce: '<?php echo wp_create_nonce ( 'string-locator-notice-dismiss ' ); ?> '
113+ } );
114+ } );
115+ } );
116+ </script>
117+ </div>
118+
119+ <?php
58120 }
59121
60122 public function add_search_options ( $ searchers , $ search_location ) {
0 commit comments