Making WordPress.org

Ticket #5018: 5018.diff

File 5018.diff, 3.5 KB (added by valentinbora, 5 years ago)
  • wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php

    diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php
    index 12b53083b..427dcbf9d 100644
    class WPORG_Explanations { 
    6060                // Output checkmark in explanations column if post has an explanation.
    6161                add_action( 'manage_posts_custom_column', array( $this, 'handle_column_data'  ), 10, 2 );
    6262
     63                add_filter( 'preview_post_link',           array ( $this, 'preview_post_link'     ), 10, 2 );
     64
    6365                // Permissions.
    6466                add_action( 'after_switch_theme',      array( $this, 'add_roles'              )        );
    6567                add_filter( 'user_has_cap',            array( $this, 'grant_caps'             )        );
    class WPORG_Explanations { 
    9294                                'not_found_in_trash'  => __( 'No Explanations found in trash', 'wporg' ),
    9395                        ),
    9496                        'public'            => false,
     97                        'publicly_queryable'=> true,
    9598                        'hierarchical'      => false,
    9699                        'show_ui'           => true,
    97100                        'show_in_menu'      => true,
    class WPORG_Explanations { 
    117120                }
    118121        }
    119122
     123        /**
     124         * Catch and complement preview post links from 'explanation' post types,
     125         * divert them to their parent Function/Hook/etc. post preview with extra
     126         * query parameters to override the respective section with the user's edits.
     127         *
     128         * @param string $preview_link The preview URL as generated by a previous internal call to get_preview_post_link
     129         * @param WP_Post $post Current post object.
     130         *
     131         * @see 'preview_post_link' filter
     132         * @access public
     133         * @return string
     134         **/
     135        public function preview_post_link( $preview_link, $post ) {
     136                if ( $this->exp_post_type != $post->post_type ) {
     137                        return $preview_link;
     138                }
     139
     140                if ( false !== strpos( $preview_link, 'preview_nonce=' ) ) {
     141                        $url = parse_url( $preview_link );
     142                        $url_query = array();
     143                        parse_str ( $url['query'], $url_query );
     144
     145                        return get_preview_post_link(
     146                                $post->post_parent,
     147                                array(
     148                                        'wporg_explanations_preview_id' => $url_query['preview_id'],
     149                                        'wporg_explanations_preview_nonce' => $url_query['preview_nonce'],
     150                                )
     151                        );
     152                }
     153
     154                return $preview_link;
     155        }
     156
    120157        /**
    121158         * Customizes admin menu.
    122159         *
  • wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
    index 559308ae2..c7b05c6e5 100644
    namespace DevHub { 
    16811681                $post = get_explanation( $_post );
    16821682
    16831683                // Get explanation's raw post content.
    1684                 $content = get_explanation_field( 'post_content', $_post );
     1684                if ( !empty( $_GET['wporg_explanations_preview_nonce'] )
     1685                        && false !== wp_verify_nonce( $_GET['wporg_explanations_preview_nonce'], 'post_preview_' . $post->ID )
     1686                ) {
     1687                        $preview = wp_get_post_autosave( $post->ID );
     1688
     1689                        if ( is_object( $preview ) ) {
     1690                                $post = $preview;
     1691                                $content = get_post_field( 'post_content', $preview, 'display' );
     1692                        }
     1693                } else {
     1694                        $content = get_explanation_field( 'post_content', $_post );
     1695                }
    16851696
    16861697                // Pass the content through expected content filters.
    16871698                $content = apply_filters( 'the_content', apply_filters( 'get_the_content', $content ) );