@@ -45,6 +45,9 @@ public function enqueue_public_assets() {
4545 // Read the admin-chosen color for the unlocked content indicator from options
4646 $ pb_indicator_color = get_option ('paybutton_unlocked_indicator_color ' , '#000000 ' );
4747
48+ // Read the admin-chosen color for the frontend unlock label
49+ $ frontend_label_color = esc_attr ( get_option ( 'paybutton_frontend_unlock_color ' , '#0074C2 ' ) );
50+
4851 // Add inline CSS variables.
4952 $ custom_css = "
5053 :root {
@@ -55,6 +58,7 @@ public function enqueue_public_assets() {
5558 --logout-button-bg-color: " . esc_attr ( get_option ('paybutton_logout_button_bg_color ' , '#d9534f ' ) ) . ";
5659 --logout-button-text-color: " . esc_attr ( get_option ('paybutton_logout_button_text_color ' , '#fff ' ) ) . ";
5760 --pb-unlocked-indicator-color: {$ pb_indicator_color };
61+ --pb-frontend-unlock-color: {$ frontend_label_color };
5862 }
5963 " ;
6064 wp_add_inline_style ( 'paybutton-sticky-header ' , esc_attr ( $ custom_css ) );
@@ -222,8 +226,41 @@ public function paybutton_paywall_shortcode( $atts, $content = null ) {
222226 ),
223227 'opReturn ' => (string ) $ post_id //This is a hack to give the PB server the post ID to send it back to WP's DB
224228 );
229+
230+ //NEW: If the admin enabled “Show Unlock Count on Front‐end,” and this post is NOT yet unlocked then display unlock count on the front end.
231+ $ unlock_label_html = '' ;
232+
233+ if ( '1 ' === get_option ( 'paybutton_enable_frontend_unlock_count ' , '0 ' ) ) {
234+ global $ wpdb ;
235+ $ unlock_table_name = $ wpdb ->prefix . 'paybutton_paywall_unlocked ' ;
236+
237+ $ unlock_count = (int ) $ wpdb ->get_var ( $ wpdb ->prepare (
238+ "SELECT COUNT(*) FROM {$ unlock_table_name } WHERE post_id = %d " ,
239+ $ post_id
240+ ) );
241+
242+ if ( $ unlock_count < 1 ) {
243+ $ unlock_text = '🔓 Be the first to unlock this content! ' ;
244+ } elseif ( $ unlock_count === 1 ) {
245+ $ unlock_text = '🔥 1 unlock and counting... ' ;
246+ } else {
247+ $ unlock_text = "🔥 {$ unlock_count } unlocks and counting... " ;
248+ }
249+
250+ // Build the <p> into a variable, but do not echo yet:
251+ $ unlock_label_html = '<p class="pb-frontend-unlock-count"> '
252+ . esc_html ( $ unlock_text )
253+ . '</p> ' ;
254+ }
255+
225256 ob_start (); //When ob_start() is called, PHP begins buffering all subsequent output instead of printing it to the browser.
226257 ?>
258+
259+ <?php
260+ //Print the unlock‐count HTML (if enabled) before the PayButton container.
261+ echo $ unlock_label_html ;
262+ ?>
263+
227264 <div id="paybutton-container-<?php echo esc_attr ( $ post_id ); ?> " class="paybutton-container" data-config="<?php echo esc_attr ( json_encode ( $ config ) ); ?> " style="text-align: center;"></div>
228265 <?php
229266 return ob_get_clean (); // ob_get_clean() Returns the HTML string to WordPress so it is inserted properly.
0 commit comments