Making WordPress.org


Ignore:
Timestamp:
02/13/2020 11:40:22 PM (4 years ago)
Author:
coffee2code
Message:

Developer theme: Allow preview link for explanations to preview the explanation being edited within the context of its associated function/hook/method/class.

Props valentinbora.
Fixes #5018.

File:
1 edited

Legend:

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

    r9325 r9503  
    16821682
    16831683        // Get explanation's raw post content.
    1684         $content = get_explanation_field( 'post_content', $_post );
     1684        $content = '';
     1685        if (
     1686            ! empty( $_GET['wporg_explanations_preview_nonce'] )
     1687        &&
     1688            false !== wp_verify_nonce( $_GET['wporg_explanations_preview_nonce'], 'post_preview_' . $post->ID )
     1689        ) {
     1690            $preview = wp_get_post_autosave( $post->ID );
     1691
     1692            if ( is_object( $preview ) ) {
     1693                $post = $preview;
     1694                $content = get_post_field( 'post_content', $preview, 'display' );
     1695            }
     1696        } else {
     1697            $content = get_explanation_field( 'post_content', $_post );
     1698        }
    16851699
    16861700        // Pass the content through expected content filters.
Note: See TracChangeset for help on using the changeset viewer.