Make WordPress Core

Ticket #14808: doc-override.diff

File doc-override.diff, 4.4 KB (added by dontfeedthecode, 5 months ago)

Refactored approach to handling the doc URL overriding for theme/plugin editing.

  • src/wp-admin/plugin-editor.php

    diff --git a/src/wp-admin/plugin-editor.php b/src/wp-admin/plugin-editor.php
    index 73017cae91..cb6caae0ea 100644
    a b if ( str_ends_with( $real_file, '.php' ) ) { 
    178178                $docs_select .= '<option value="">' . esc_html__( 'Function Name&hellip;' ) . '</option>';
    179179
    180180                foreach ( $functions as $function ) {
    181                         $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>';
     181
     182                        /**
     183                         * Allows the documentation URL to be filtered for the Plugin Editor.
     184                         *
     185                         * @since x
     186                         *
     187                         * @param string $function Name of the selected function.
     188                         * @param string $file     Path to the file being edited.
     189                         * @param string $plugin   Plugin file/directory name.
     190                         */
     191                        $option_value = apply_filters( 'plugin_editor_documentation_url', $function, $file, $plugin );
     192                       
     193                        $docs_select .= '<option value="' . esc_attr( $option_value ) . '">' . esc_html( $function ) . '()</option>';
    182194                }
    183195
    184196                $docs_select .= '</select>';
    endif; 
    295307                <div id="documentation" class="hide-if-no-js">
    296308                        <label for="docs-list"><?php _e( 'Documentation:' ); ?></label>
    297309                        <?php echo $docs_select; ?>
    298                         <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' !== jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ); ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&amp;redirect=true'); }" />
     310                        <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="(() => { const v = jQuery('#docs-list').val(); if (!v) return; let url; if (v.startsWith('http://') || v.startsWith('https://')) { url = v; } else { try { new URL(v); url = v; } catch { url = `https://api.wordpress.org/core/handbook/1.0/?function=${escape(v)}&locale=<?php echo urlencode(get_user_locale()); ?>&version=<?php echo urlencode(get_bloginfo('version')); ?>&redirect=true`; } } window.open(url); })()" />
    299311                </div>
    300312        <?php endif; ?>
    301313
  • src/wp-admin/theme-editor.php

    diff --git a/src/wp-admin/theme-editor.php b/src/wp-admin/theme-editor.php
    index bf869f4d8a..bcf96726e4 100644
    a b if ( ! empty( $posted_content ) ) { 
    172172                        $docs_select .= '<option value="">' . esc_html__( 'Function Name&hellip;' ) . '</option>';
    173173
    174174                        foreach ( $functions as $function ) {
    175                                 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>';
     175
     176                                /**
     177                                 * Allows the documentation URL to be filtered for the Theme Editor.
     178                                 *
     179                                 * @since x
     180                                 *
     181                                 * @param string $function Name of the selected function.
     182                                 * @param string $file     Path to the file being edited.
     183                                 * @param string $theme    Directory name of the theme being edited.
     184                                 */
     185                                $option_value = apply_filters( 'theme_editor_documentation_url', $function, $file, $theme->get_stylesheet() );
     186
     187                                $docs_select .= '<option value="' . esc_attr( $option_value ) . '">' . esc_html( $function ) . '()</option>';
    176188                        }
    177189
    178190                        $docs_select .= '</select>';
    else : 
    324336                        <div id="documentation" class="hide-if-no-js">
    325337                                <label for="docs-list"><?php _e( 'Documentation:' ); ?></label>
    326338                                <?php echo $docs_select; ?>
    327                                 <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' !== jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ); ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&amp;redirect=true'); }" />
     339                                <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="(() => { const v = jQuery('#docs-list').val(); if (!v) return; let url; if (v.startsWith('http://') || v.startsWith('https://')) { url = v; } else { try { new URL(v); url = v; } catch { url = `https://api.wordpress.org/core/handbook/1.0/?function=${escape(v)}&locale=<?php echo urlencode(get_user_locale()); ?>&version=<?php echo urlencode(get_bloginfo('version')); ?>&redirect=true`; } } window.open(url); })()" />
    328340                        </div>
    329341                <?php endif; ?>
    330342