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/plugins/plugin-directory/class-template.php

    r12931 r12933  
    794794            array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
    795795            home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-transfer' )
     796        );
     797    }
     798
     799    /**
     800     * Generates a link to toggle the Live Preview button.
     801     *
     802     * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     803     * @return string URL to toggle status.
     804     */
     805    public static function get_self_toggle_preview_link( $post = null ) {
     806        $post = get_post( $post );
     807
     808        return add_query_arg(
     809            array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
     810            home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-toggle-preview' )
    796811        );
    797812    }
Note: See TracChangeset for help on using the changeset viewer.