Making WordPress.org


Ignore:
Timestamp:
10/06/2023 02:09:21 AM (7 months ago)
Author:
tellyworth
Message:

Plugins: add opt-out toggle for Live Preview button

This allows plugin committers to disable the Live Preview button for specific plugins. It adds a button to the Danger Zone section on the Advanced view of the plugin page.

See #7251

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php

    r12816 r12933  
    520520        // Output the self close button.
    521521        the_plugin_self_close_button();
     522
     523        // Output the toggle preview button.
     524        the_plugin_self_toggle_preview_button();
    522525    }
    523526
     
    554557        // Translators: %s is the plugin name, as defined by the plugin itself.
    555558        echo '<p><input class="button" type="submit" value="' . esc_attr( sprintf( __( 'I understand, please close %s.', 'wporg-plugins' ), get_the_title() ) ) . '" /></p>';
     559        echo '</form>';
     560    }
     561}
     562
     563/**
     564 * Displays a form for plugin committers to toggle the Live Preview button.
     565 */
     566function the_plugin_self_toggle_preview_button() {
     567    $post            = get_post();
     568    $toggle_link     = Template::get_self_toggle_preview_link( $post );
     569
     570    if ( ! current_user_can( 'plugin_self_close', $post ) ) {
     571        return;
     572    }
     573
     574    echo '<h4>' . esc_html__( 'Toggle Live Preview', 'wporg-plugins' ) . '</h4>';
     575    $preview_status = get_post_meta( $post->ID, '_no_preview', true ) ? 'disabled' : 'enabled';
     576    if ( 'enabled' === $preview_status ) {
     577        echo '<p>' . esc_html__( 'The Live Preview link to Playground is currently enabled. Use the toggle button to disable it.', 'wporg-plugins' ) . '</p>';
     578    } else {
     579        echo '<p>' . esc_html__( 'The Live Preview link to Playground is currently disabled. Use the toggle button to enable it.', 'wporg-plugins' ) . '</p>';
     580    }
     581
     582    echo '<div class="plugin-notice notice notice-warning notice-alt"><p>';
     583    _e( '<strong>Note:</strong> This only affects the availability of the Live Preview button on the plugin page. It does not prevent a plugin from running in the Playground.', 'wporg-plugins' );
     584    echo '</p></div>';
     585
     586    if ( $toggle_link ) {
     587        echo '<form method="POST" action="' . esc_url( $toggle_link ) . '" onsubmit="return confirm( jQuery(this).prev(\'.notice\').text() );">';
     588        // Translators: %s is the plugin name, as defined by the plugin itself.
     589        echo '<p><input class="button" type="submit" value="' . esc_attr( sprintf( __( 'Please toggle the Live Preview link for %s', 'wporg-plugins' ), get_the_title() ) ) . '" /></p>';
    556590        echo '</form>';
    557591    }
Note: See TracChangeset for help on using the changeset viewer.