diff --git a/assets/css/paywall-styles.css b/assets/css/paywall-styles.css index 2d3ebcc..49b3152 100644 --- a/assets/css/paywall-styles.css +++ b/assets/css/paywall-styles.css @@ -18,4 +18,14 @@ .unlocked-indicator span { padding: 0 1rem; /* Space between text and lines */ +} + +/* Show Unlock Count on Front-end */ +.pb-frontend-unlock-count { + color: var(--pb-frontend-unlock-color, #0074C2); + margin-bottom: 1em; + text-align: center; + font-family: inherit; + font-size: 1.2em; + font-style: italic; } \ No newline at end of file diff --git a/assets/js/paybutton-admin.js b/assets/js/paybutton-admin.js index 8fc62a9..a6f8f70 100644 --- a/assets/js/paybutton-admin.js +++ b/assets/js/paybutton-admin.js @@ -16,4 +16,21 @@ jQuery(document).ready(function($) { toggleColorFields(); // On checkbox change unlockedCheckbox.on('change', toggleColorFields); + + //NEW: Toggle the “Unlock Count Color” row visibility + var enableUnlockCountCheckbox = $('#paybutton_enable_frontend_unlock_count'); + var frontendUnlockColorRow = $('#paybutton_frontend_unlock_color_row'); + + function toggleFrontendUnlockColorRow() { + if ( enableUnlockCountCheckbox.is(':checked') ) { + frontendUnlockColorRow.show(); + } else { + frontendUnlockColorRow.hide(); + } + } + + // On page load + toggleFrontendUnlockColorRow(); + // On checkbox change + enableUnlockCountCheckbox.on('change', toggleFrontendUnlockColorRow); }); \ No newline at end of file diff --git a/includes/class-paybutton-admin.php b/includes/class-paybutton-admin.php index 80f858b..b8de464 100644 --- a/includes/class-paybutton-admin.php +++ b/includes/class-paybutton-admin.php @@ -295,7 +295,17 @@ private function save_settings() { if ( isset( $_POST['paybutton_public_key'] ) ) { $public_key = sanitize_text_field( $_POST['paybutton_public_key'] ); update_option( 'paybutton_public_key', $public_key ); - } + } + + //Front‐end unlock count toggle + $enable_frontend_unlock_count = isset( $_POST['paybutton_enable_frontend_unlock_count'] ) ? '1' : '0'; + update_option( 'paybutton_enable_frontend_unlock_count', $enable_frontend_unlock_count ); + + //Front‐end unlock count text color + $frontend_unlock_color = isset( $_POST['paybutton_frontend_unlock_color'] ) + ? sanitize_hex_color( wp_unslash( $_POST['paybutton_frontend_unlock_color'] ) ) + : '#0074C2'; + update_option( 'paybutton_frontend_unlock_color', $frontend_unlock_color ); } /** diff --git a/includes/class-paybutton-public.php b/includes/class-paybutton-public.php index 4fef79f..63ac003 100644 --- a/includes/class-paybutton-public.php +++ b/includes/class-paybutton-public.php @@ -45,6 +45,9 @@ public function enqueue_public_assets() { // Read the admin-chosen color for the unlocked content indicator from options $pb_indicator_color = get_option('paybutton_unlocked_indicator_color', '#000000'); + // Read the admin-chosen color for the frontend unlock label + $frontend_label_color = esc_attr( get_option( 'paybutton_frontend_unlock_color', '#0074C2' ) ); + // Add inline CSS variables. $custom_css = " :root { @@ -55,6 +58,7 @@ public function enqueue_public_assets() { --logout-button-bg-color: " . esc_attr( get_option('paybutton_logout_button_bg_color', '#d9534f') ) . "; --logout-button-text-color: " . esc_attr( get_option('paybutton_logout_button_text_color', '#fff') ) . "; --pb-unlocked-indicator-color: {$pb_indicator_color}; + --pb-frontend-unlock-color: {$frontend_label_color}; } "; wp_add_inline_style( 'paybutton-sticky-header', esc_attr( $custom_css ) ); @@ -222,8 +226,41 @@ public function paybutton_paywall_shortcode( $atts, $content = null ) { ), 'opReturn' => (string) $post_id //This is a hack to give the PB server the post ID to send it back to WP's DB ); + + //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. + $unlock_label_html = ''; + + if ( '1' === get_option( 'paybutton_enable_frontend_unlock_count', '0' ) ) { + global $wpdb; + $unlock_table_name = $wpdb->prefix . 'paybutton_paywall_unlocked'; + + $unlock_count = (int) $wpdb->get_var( $wpdb->prepare( + "SELECT COUNT(*) FROM {$unlock_table_name} WHERE post_id = %d", + $post_id + ) ); + + if ( $unlock_count < 1 ) { + $unlock_text = '🔓 Be the first to unlock this content!'; + } elseif ( $unlock_count === 1 ) { + $unlock_text = '🔥 1 unlock and counting...'; + } else { + $unlock_text = "🔥 {$unlock_count} unlocks and counting..."; + } + + // Build the

into a variable, but do not echo yet: + $unlock_label_html = '

' + . esc_html( $unlock_text ) + . '

'; + } + ob_start(); //When ob_start() is called, PHP begins buffering all subsequent output instead of printing it to the browser. ?> + + +
+ + + Show Unlock Count on Front‐end + + + + + + + + + + + + + +

+ Pick the hex color for the unlock count label. +

+ +

Sticky Header Settings