Plugin Directory

Changeset 3814646


Ignore:
Timestamp:
11/21/2026 12:18:35 AM (less than one hour ago)
Author:
davidlilja
Message:

v2.0.1 - Dismissible review request on the plugin's own pages

Location:
del-embed-for-bandcamp
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • del-embed-for-bandcamp/tags/2.0.1/assets/admin.css

    r3814642 r3814646  
    891891        transition: opacity 0.15s;
    892892}
     893
     894/* Review request (2.0.1) */
     895.bcwp-review {
     896        border-left-color: #dba617;
     897}
  • del-embed-for-bandcamp/tags/2.0.1/del-embed-for-bandcamp.php

    r3814642 r3814646  
    33 * Plugin Name: DEL Embed for Bandcamp
    44 * Description: Display your Bandcamp releases on WordPress with embedded players and customizable layouts.
    5  * Version:     2.0.0
     5 * Version:     2.0.1
    66 * Author:      David Elfström Lilja
    77 * Author URI:  https://davidlilja.se/
    … …  
    1414}
    1515
    16 define( 'BCWP_VERSION', '2.0.0' );
     16define( 'BCWP_VERSION', '2.0.1' );
    1717define( 'BCWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    1818define( 'BCWP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    … …  
    6666require_once BCWP_PLUGIN_DIR . 'includes/stats.php';
    6767
     68// On a new install or an update: remember when the plugin was installed.
     69if ( $bcwp_prev !== BCWP_VERSION ) {
     70        bcwp_note_install( $bcwp_prev );
     71}
     72
    6873// Stop the automatic import schedule when the plugin is deactivated.
    6974register_deactivation_hook( __FILE__, function () {
  • del-embed-for-bandcamp/tags/2.0.1/includes/notice.php

    r3812128 r3814646  
    11<?php
    22/**
    3  * Thank-you notice. Shown once on the plugin's own admin pages after an
    4  * install or update, until the user closes it.
     3 * Notices on the plugin's own admin pages.
     4 *
     5 * Thank-you notice: shown once after an install or update, until the user
     6 * closes it.
     7 *
     8 * Review request (2.0.1): asks for a review on WordPress.org once the plugin
     9 * has been in use for a while. It can be closed for good or postponed, is
     10 * never shown together with the thank-you notice, and offers nothing in
     11 * return for a review.
    512 */
    613
    … …  
    8592        <?php
    8693}
     94
     95define( 'BCWP_REVIEW_URL', 'https://wordpress.org/support/plugin/del-embed-for-bandcamp/reviews/#new-post' );
     96
     97add_action( 'admin_post_bcwp_review', 'bcwp_review_action' );
     98add_action( 'wp_ajax_bcwp_review', 'bcwp_review_action' );
     99
     100/**
     101 * Remember when the plugin was installed. Called when the version changes.
     102 *
     103 * A new install stores the time. A site that already had the plugin before
     104 * this was tracked stores 0, which means "has used it for a while".
     105 *
     106 * @param string $previous_version Version before this one, or '' for a new install.
     107 */
     108function bcwp_note_install( $previous_version ) {
     109        if ( false === get_option( 'bcwp_installed' ) ) {
     110                add_option( 'bcwp_installed', '' === $previous_version ? time() : 0, '', false );
     111        }
     112}
     113
     114/**
     115 * Whether the current user should see the review request.
     116 */
     117function bcwp_show_review() {
     118        if ( ! current_user_can( 'manage_options' ) || bcwp_show_thanks() ) {
     119                return false;
     120        }
     121
     122        // "done" = closed for good, a number = hidden until that time.
     123        $state = get_user_meta( get_current_user_id(), 'bcwp_review', true );
     124        if ( 'done' === $state || ( is_numeric( $state ) && time() < (int) $state ) ) {
     125                return false;
     126        }
     127
     128        $installed = get_option( 'bcwp_installed' );
     129        if ( false === $installed ) {
     130                return false;
     131        }
     132        $releases = count( bcwp_get_items() );
     133
     134        // Sites that had the plugin before 2.0.1: ask as soon as it is in use.
     135        if ( 0 === (int) $installed ) {
     136                return $releases >= 1;
     137        }
     138
     139        // New installs: after two weeks and a few releases.
     140        return (int) $installed <= time() - 14 * DAY_IN_SECONDS && $releases >= 3;
     141}
     142
     143/**
     144 * Close or postpone the review request for the current user. Works with and
     145 * without JavaScript.
     146 */
     147function bcwp_review_action() {
     148        check_admin_referer( 'bcwp_review' );
     149
     150        $do = isset( $_REQUEST['do'] ) ? sanitize_key( wp_unslash( $_REQUEST['do'] ) ) : '';
     151
     152        if ( current_user_can( 'manage_options' ) ) {
     153                if ( 'later' === $do ) {
     154                        update_user_meta( get_current_user_id(), 'bcwp_review', time() + 30 * DAY_IN_SECONDS );
     155                } elseif ( 'done' === $do ) {
     156                        update_user_meta( get_current_user_id(), 'bcwp_review', 'done' );
     157                }
     158        }
     159
     160        if ( wp_doing_ajax() ) {
     161                wp_send_json_success();
     162        }
     163
     164        wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'admin.php?page=bandcamp-releases' ) );
     165        exit;
     166}
     167
     168/**
     169 * Print the review request. Called from the shared page header.
     170 */
     171function bcwp_render_review() {
     172        if ( ! bcwp_show_review() ) {
     173                return;
     174        }
     175
     176        $base      = wp_nonce_url( admin_url( 'admin-post.php?action=bcwp_review' ), 'bcwp_review' );
     177        $done_url  = add_query_arg( 'do', 'done', $base );
     178        $later_url = add_query_arg( 'do', 'later', $base );
     179        ?>
     180        <div class="bcwp-thanks bcwp-review" id="bcwp-review" role="region" aria-label="<?php esc_attr_e( 'Review', 'del-embed-for-bandcamp' ); ?>">
     181                <a href="<?php echo esc_url( $done_url ); ?>" class="bcwp-thanks-close" data-do="done" aria-label="<?php esc_attr_e( 'Close', 'del-embed-for-bandcamp' ); ?>">&times;</a>
     182                <p class="bcwp-thanks-title"><?php esc_html_e( 'Enjoying DEL Embed for Bandcamp?', 'del-embed-for-bandcamp' ); ?> &#11088;</p>
     183                <p><?php esc_html_e( 'You\'ve been using the plugin for a while now. If it\'s useful to you, a short review on WordPress.org would mean a lot. Reviews help other musicians and labels find the plugin, and they keep me going.', 'del-embed-for-bandcamp' ); ?></p>
     184                <p class="bcwp-thanks-actions">
     185                        <a href="<?php echo esc_url( BCWP_REVIEW_URL ); ?>" target="_blank" rel="noopener" class="button button-primary bcwp-review-go" data-do="done">&#11088; <?php esc_html_e( 'Leave a review', 'del-embed-for-bandcamp' ); ?></a>
     186                        <a href="<?php echo esc_url( $later_url ); ?>" class="button" data-do="later"><?php esc_html_e( 'Maybe later', 'del-embed-for-bandcamp' ); ?></a>
     187                        <a href="<?php echo esc_url( $done_url ); ?>" class="bcwp-thanks-dismiss" data-do="done"><?php esc_html_e( 'No thanks', 'del-embed-for-bandcamp' ); ?></a>
     188                </p>
     189        </div>
     190        <script>
     191        ( function () {
     192                var box = document.getElementById( 'bcwp-review' );
     193                if ( ! box || ! window.fetch ) {
     194                        return;
     195                }
     196                box.addEventListener( 'click', function ( e ) {
     197                        var link = e.target.closest( '[data-do]' );
     198                        if ( ! link ) {
     199                                return;
     200                        }
     201                        // The review button opens WordPress.org in a new tab; the others stay here.
     202                        if ( ! link.classList.contains( 'bcwp-review-go' ) ) {
     203                                e.preventDefault();
     204                        }
     205                        box.parentNode.removeChild( box );
     206                        var body = new URLSearchParams( {
     207                                action: 'bcwp_review',
     208                                'do': link.getAttribute( 'data-do' ),
     209                                _wpnonce: <?php echo wp_json_encode( wp_create_nonce( 'bcwp_review' ) ); ?>
     210                        } );
     211                        fetch( <?php echo wp_json_encode( admin_url( 'admin-ajax.php' ) ); ?>, { method: 'POST', credentials: 'same-origin', body: body, keepalive: true } );
     212                } );
     213        } )();
     214        </script>
     215        <?php
     216}
  • del-embed-for-bandcamp/tags/2.0.1/includes/settings.php

    r3814642 r3814646  
    395395        <?php
    396396        bcwp_render_thanks();
     397        bcwp_render_review();
    397398}
    398399
  • del-embed-for-bandcamp/tags/2.0.1/readme.txt

    r3814642 r3814646  
    44Requires at least: 5.0
    55Tested up to: 7.1
    6 Stable tag: 2.0.0
     6Stable tag: 2.0.1
    77Requires PHP: 7.4
    88License: GPLv2 or later
    … …  
    162162== Changelog ==
    163163
     164= 2.0.1 =
     165* New: A small note on the plugin's own pages asks for a review once you have used the plugin for a while. You can close it for good or postpone it.
     166
    164167= 2.0.0 =
    165168Everything new is optional and off until you turn it on. Existing shortcodes and blocks work as before.
    … …  
    263266== Upgrade Notice ==
    264267
     268= 2.0.1 =
     269Adds a small, dismissible review request on the plugin's own pages. No other changes.
     270
    265271= 2.0.0 =
    266272Big update: vinyl record effect, latest release spotlight, player bar, format labels, filter buttons, shareable links and statistics. All optional. Existing shortcodes work as before.
  • del-embed-for-bandcamp/trunk/assets/admin.css

    r3814642 r3814646  
    891891        transition: opacity 0.15s;
    892892}
     893
     894/* Review request (2.0.1) */
     895.bcwp-review {
     896        border-left-color: #dba617;
     897}
  • del-embed-for-bandcamp/trunk/del-embed-for-bandcamp.php

    r3814642 r3814646  
    33 * Plugin Name: DEL Embed for Bandcamp
    44 * Description: Display your Bandcamp releases on WordPress with embedded players and customizable layouts.
    5  * Version:     2.0.0
     5 * Version:     2.0.1
    66 * Author:      David Elfström Lilja
    77 * Author URI:  https://davidlilja.se/
    … …  
    1414}
    1515
    16 define( 'BCWP_VERSION', '2.0.0' );
     16define( 'BCWP_VERSION', '2.0.1' );
    1717define( 'BCWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    1818define( 'BCWP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    … …  
    6666require_once BCWP_PLUGIN_DIR . 'includes/stats.php';
    6767
     68// On a new install or an update: remember when the plugin was installed.
     69if ( $bcwp_prev !== BCWP_VERSION ) {
     70        bcwp_note_install( $bcwp_prev );
     71}
     72
    6873// Stop the automatic import schedule when the plugin is deactivated.
    6974register_deactivation_hook( __FILE__, function () {
  • del-embed-for-bandcamp/trunk/includes/notice.php

    r3812128 r3814646  
    11<?php
    22/**
    3  * Thank-you notice. Shown once on the plugin's own admin pages after an
    4  * install or update, until the user closes it.
     3 * Notices on the plugin's own admin pages.
     4 *
     5 * Thank-you notice: shown once after an install or update, until the user
     6 * closes it.
     7 *
     8 * Review request (2.0.1): asks for a review on WordPress.org once the plugin
     9 * has been in use for a while. It can be closed for good or postponed, is
     10 * never shown together with the thank-you notice, and offers nothing in
     11 * return for a review.
    512 */
    613
    … …  
    8592        <?php
    8693}
     94
     95define( 'BCWP_REVIEW_URL', 'https://wordpress.org/support/plugin/del-embed-for-bandcamp/reviews/#new-post' );
     96
     97add_action( 'admin_post_bcwp_review', 'bcwp_review_action' );
     98add_action( 'wp_ajax_bcwp_review', 'bcwp_review_action' );
     99
     100/**
     101 * Remember when the plugin was installed. Called when the version changes.
     102 *
     103 * A new install stores the time. A site that already had the plugin before
     104 * this was tracked stores 0, which means "has used it for a while".
     105 *
     106 * @param string $previous_version Version before this one, or '' for a new install.
     107 */
     108function bcwp_note_install( $previous_version ) {
     109        if ( false === get_option( 'bcwp_installed' ) ) {
     110                add_option( 'bcwp_installed', '' === $previous_version ? time() : 0, '', false );
     111        }
     112}
     113
     114/**
     115 * Whether the current user should see the review request.
     116 */
     117function bcwp_show_review() {
     118        if ( ! current_user_can( 'manage_options' ) || bcwp_show_thanks() ) {
     119                return false;
     120        }
     121
     122        // "done" = closed for good, a number = hidden until that time.
     123        $state = get_user_meta( get_current_user_id(), 'bcwp_review', true );
     124        if ( 'done' === $state || ( is_numeric( $state ) && time() < (int) $state ) ) {
     125                return false;
     126        }
     127
     128        $installed = get_option( 'bcwp_installed' );
     129        if ( false === $installed ) {
     130                return false;
     131        }
     132        $releases = count( bcwp_get_items() );
     133
     134        // Sites that had the plugin before 2.0.1: ask as soon as it is in use.
     135        if ( 0 === (int) $installed ) {
     136                return $releases >= 1;
     137        }
     138
     139        // New installs: after two weeks and a few releases.
     140        return (int) $installed <= time() - 14 * DAY_IN_SECONDS && $releases >= 3;
     141}
     142
     143/**
     144 * Close or postpone the review request for the current user. Works with and
     145 * without JavaScript.
     146 */
     147function bcwp_review_action() {
     148        check_admin_referer( 'bcwp_review' );
     149
     150        $do = isset( $_REQUEST['do'] ) ? sanitize_key( wp_unslash( $_REQUEST['do'] ) ) : '';
     151
     152        if ( current_user_can( 'manage_options' ) ) {
     153                if ( 'later' === $do ) {
     154                        update_user_meta( get_current_user_id(), 'bcwp_review', time() + 30 * DAY_IN_SECONDS );
     155                } elseif ( 'done' === $do ) {
     156                        update_user_meta( get_current_user_id(), 'bcwp_review', 'done' );
     157                }
     158        }
     159
     160        if ( wp_doing_ajax() ) {
     161                wp_send_json_success();
     162        }
     163
     164        wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'admin.php?page=bandcamp-releases' ) );
     165        exit;
     166}
     167
     168/**
     169 * Print the review request. Called from the shared page header.
     170 */
     171function bcwp_render_review() {
     172        if ( ! bcwp_show_review() ) {
     173                return;
     174        }
     175
     176        $base      = wp_nonce_url( admin_url( 'admin-post.php?action=bcwp_review' ), 'bcwp_review' );
     177        $done_url  = add_query_arg( 'do', 'done', $base );
     178        $later_url = add_query_arg( 'do', 'later', $base );
     179        ?>
     180        <div class="bcwp-thanks bcwp-review" id="bcwp-review" role="region" aria-label="<?php esc_attr_e( 'Review', 'del-embed-for-bandcamp' ); ?>">
     181                <a href="<?php echo esc_url( $done_url ); ?>" class="bcwp-thanks-close" data-do="done" aria-label="<?php esc_attr_e( 'Close', 'del-embed-for-bandcamp' ); ?>">&times;</a>
     182                <p class="bcwp-thanks-title"><?php esc_html_e( 'Enjoying DEL Embed for Bandcamp?', 'del-embed-for-bandcamp' ); ?> &#11088;</p>
     183                <p><?php esc_html_e( 'You\'ve been using the plugin for a while now. If it\'s useful to you, a short review on WordPress.org would mean a lot. Reviews help other musicians and labels find the plugin, and they keep me going.', 'del-embed-for-bandcamp' ); ?></p>
     184                <p class="bcwp-thanks-actions">
     185                        <a href="<?php echo esc_url( BCWP_REVIEW_URL ); ?>" target="_blank" rel="noopener" class="button button-primary bcwp-review-go" data-do="done">&#11088; <?php esc_html_e( 'Leave a review', 'del-embed-for-bandcamp' ); ?></a>
     186                        <a href="<?php echo esc_url( $later_url ); ?>" class="button" data-do="later"><?php esc_html_e( 'Maybe later', 'del-embed-for-bandcamp' ); ?></a>
     187                        <a href="<?php echo esc_url( $done_url ); ?>" class="bcwp-thanks-dismiss" data-do="done"><?php esc_html_e( 'No thanks', 'del-embed-for-bandcamp' ); ?></a>
     188                </p>
     189        </div>
     190        <script>
     191        ( function () {
     192                var box = document.getElementById( 'bcwp-review' );
     193                if ( ! box || ! window.fetch ) {
     194                        return;
     195                }
     196                box.addEventListener( 'click', function ( e ) {
     197                        var link = e.target.closest( '[data-do]' );
     198                        if ( ! link ) {
     199                                return;
     200                        }
     201                        // The review button opens WordPress.org in a new tab; the others stay here.
     202                        if ( ! link.classList.contains( 'bcwp-review-go' ) ) {
     203                                e.preventDefault();
     204                        }
     205                        box.parentNode.removeChild( box );
     206                        var body = new URLSearchParams( {
     207                                action: 'bcwp_review',
     208                                'do': link.getAttribute( 'data-do' ),
     209                                _wpnonce: <?php echo wp_json_encode( wp_create_nonce( 'bcwp_review' ) ); ?>
     210                        } );
     211                        fetch( <?php echo wp_json_encode( admin_url( 'admin-ajax.php' ) ); ?>, { method: 'POST', credentials: 'same-origin', body: body, keepalive: true } );
     212                } );
     213        } )();
     214        </script>
     215        <?php
     216}
  • del-embed-for-bandcamp/trunk/includes/settings.php

    r3814642 r3814646  
    395395        <?php
    396396        bcwp_render_thanks();
     397        bcwp_render_review();
    397398}
    398399
  • del-embed-for-bandcamp/trunk/readme.txt

    r3814642 r3814646  
    44Requires at least: 5.0
    55Tested up to: 7.1
    6 Stable tag: 2.0.0
     6Stable tag: 2.0.1
    77Requires PHP: 7.4
    88License: GPLv2 or later
    … …  
    162162== Changelog ==
    163163
     164= 2.0.1 =
     165* New: A small note on the plugin's own pages asks for a review once you have used the plugin for a while. You can close it for good or postpone it.
     166
    164167= 2.0.0 =
    165168Everything new is optional and off until you turn it on. Existing shortcodes and blocks work as before.
    … …  
    263266== Upgrade Notice ==
    264267
     268= 2.0.1 =
     269Adds a small, dismissible review request on the plugin's own pages. No other changes.
     270
    265271= 2.0.0 =
    266272Big update: vinyl record effect, latest release spotlight, player bar, format labels, filter buttons, shareable links and statistics. All optional. Existing shortcodes work as before.
Note: See TracChangeset for help on using the changeset viewer.