Making WordPress.org


Ignore:
Timestamp:
09/05/2022 05:14:31 AM (4 years ago)
Author:
dufresnesteven
Message:

wporg-developer: Sync with ​https://github.com/WordPress/wporg-developer/commit/790d402933d2725374de0d19e6bf6a576c8b15d2

File:
1 edited

Legend:

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

    r11903 r12050  
    148148add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' );
    149149
     150/**
     151 * Set up the theme.
     152 */
    150153function init() {
    151154
    … …  
    165168
    166169        // Modify default breadcrumbs.
    167         add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_items_for_hooks', 10, 2 );
    168         add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_items_for_handbook_root', 10, 2 );
    169 
    170         add_filter( 'syntaxhighlighter_htmlresult', __NAMESPACE__ . '\\syntaxhighlighter_htmlresult' );
     170        add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_for_hooks', 10, 2 );
     171        add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_for_handbook_root', 10, 2 );
     172
     173        add_filter( 'mkaz_code_syntax_force_loading', '__return_true' );
     174        add_filter( 'mkaz_prism_css_path', __NAMESPACE__ . '\\update_prism_css_path' );
    171175}
    172176
    … …  
    178182 * be shown.
    179183 *
    180  * @param  array $items The breadcrumb trail items
    181  * @param  array $args  Original args
     184 * @param  array $items The breadcrumb trail items.
     185 * @param  array $args  Original args.
    182186 * @return array
    183187 */
    … …  
    186190
    187191        // Bail early when not the single archive for hook
    188         if ( ! is_singular() || $post_type !== get_post_type() || ! isset( $items[4] ) ) {
     192        if ( ! is_singular() || get_post_type() !== $post_type || ! isset( $items[4] ) ) {
    189193                return $items;
    190194        }
    … …  
    209213 * item is already the unlinked handbook name, which is sufficient.
    210214 *
    211  * @param  array $items The breadcrumb trail items
    212  * @param  array $args  Original args
     215 * @param  array $items The breadcrumb trail items.
     216 * @param  array $args  Original args.
    213217 * @return array
    214218 */
    … …  
    226230
    227231/**
    228  * widgets_init function.
     232 * Register widget areas.
    229233 *
    230234 * @access public
    … …  
    232236 */
    233237function widgets_init() {
    234         register_sidebar( array(
    235                 'name'          => __( 'Sidebar', 'wporg' ),
    236                 'id'            => 'sidebar-1',
    237                 'before_widget' => '<aside id="%1$s" class="box gray widget %2$s">',
    238                 'after_widget'  => '</div></aside>',
    239                 'before_title'  => '<h1 class="widget-title">',
    240                 'after_title'   => '</h1><div class="widget-content">',
    241         ) );
    242 
    243         register_sidebar( array(
    244                 'name'          => __( 'Landing Page Footer - Left', 'wporg' ),
    245                 'id'            => 'landing-footer-1',
    246                 'description'   => __( 'Appears in footer of the primary landing page', 'wporg' ),
    247                 'before_widget' => '<div id="%1$s" class="widget box %2$s">',
    248                 'after_widget'  => '</div>',
    249                 'before_title'  => '<h4 class="widget-title">',
    250                 'after_title'   => '</h4>',
    251         ) );
    252 
    253         register_sidebar( array(
    254                 'name'          => __( 'Landing Page Footer - Center', 'wporg' ),
    255                 'id'            => 'landing-footer-2',
    256                 'description'   => __( 'Appears in footer of the primary landing page', 'wporg' ),
    257                 'before_widget' => '<div id="%1$s" class="widget box %2$s">',
    258                 'after_widget'  => '</div>',
    259                 'before_title'  => '<h4 class="widget-title">',
    260                 'after_title'   => '</h4>',
    261         ) );
    262 
    263         register_sidebar( array(
    264                 'name'          => __( 'Landing Page Footer - Right', 'wporg' ),
    265                 'id'            => 'landing-footer-3',
    266                 'description'   => __( 'Appears in footer of the primary landing page', 'wporg' ),
    267                 'before_widget' => '<div id="%1$s" class="widget box %2$s">',
    268                 'after_widget'  => '</div>',
    269                 'before_title'  => '<h4 class="widget-title">',
    270                 'after_title'   => '</h4>',
    271         ) );
    272 }
    273 
    274 /**
     238        register_sidebar(
     239                array(
     240                        'name'          => __( 'Sidebar', 'wporg' ),
     241                        'id'            => 'sidebar-1',
     242                        'before_widget' => '<aside id="%1$s" class="box gray widget %2$s">',
     243                        'after_widget'  => '</div></aside>',
     244                        'before_title'  => '<h1 class="widget-title">',
     245                        'after_title'   => '</h1><div class="widget-content">',
     246                )
     247        );
     248
     249        register_sidebar(
     250                array(
     251                        'name'          => __( 'Landing Page Footer - Left', 'wporg' ),
     252                        'id'            => 'landing-footer-1',
     253                        'description'   => __( 'Appears in footer of the primary landing page', 'wporg' ),
     254                        'before_widget' => '<div id="%1$s" class="widget box %2$s">',
     255                        'after_widget'  => '</div>',
     256                        'before_title'  => '<h4 class="widget-title">',
     257                        'after_title'   => '</h4>',
     258                )
     259        );
     260
     261        register_sidebar(
     262                array(
     263                        'name'          => __( 'Landing Page Footer - Center', 'wporg' ),
     264                        'id'            => 'landing-footer-2',
     265                        'description'   => __( 'Appears in footer of the primary landing page', 'wporg' ),
     266                        'before_widget' => '<div id="%1$s" class="widget box %2$s">',
     267                        'after_widget'  => '</div>',
     268                        'before_title'  => '<h4 class="widget-title">',
     269                        'after_title'   => '</h4>',
     270                )
     271        );
     272
     273        register_sidebar(
     274                array(
     275                        'name'          => __( 'Landing Page Footer - Right', 'wporg' ),
     276                        'id'            => 'landing-footer-3',
     277                        'description'   => __( 'Appears in footer of the primary landing page', 'wporg' ),
     278                        'before_widget' => '<div id="%1$s" class="widget box %2$s">',
     279                        'after_widget'  => '</div>',
     280                        'before_title'  => '<h4 class="widget-title">',
     281                        'after_title'   => '</h4>',
     282                )
     283        );
     284}
     285
     286/**
     287 * Modify the default query.
     288 *
    275289 * @param \WP_Query $query
    276290 */
    … …  
    289303}
    290304
     305/**
     306 * Regiser navigation menu area.
     307 */
    291308function register_nav_menus() {
    292 
    293         \register_nav_menus( array(
    294                 'devhub-menu' => __( 'Developer Resources Menu', 'wporg' ),
    295                 'devhub-cli-menu' => __( 'WP-CLI Commands Menu', 'wporg' ),
    296                 'reference-home-api' => __( 'Reference API Menu', 'wporg' ),
    297         ) );
     309        \register_nav_menus(
     310                array(
     311                        'devhub-menu' => __( 'Developer Resources Menu', 'wporg' ),
     312                        'devhub-cli-menu' => __( 'WP-CLI Commands Menu', 'wporg' ),
     313                        'reference-home-api' => __( 'Reference API Menu', 'wporg' ),
     314                )
     315        );
    298316}
    299317
    … …  
    319337}
    320338
     339/**
     340 * Filer the permalink for a taxonomy.
     341 */
    321342function taxonomy_permalink( $link, $term, $taxonomy ) {
    322343        global $wp_rewrite;
    … …  
    326347        }
    327348
    328         if ( $taxonomy === 'wp-parser-source-file' ) {
     349        if ( 'wp-parser-source-file' === $taxonomy ) {
    329350                $slug = $term->slug;
    330351                if ( substr( $slug, -4 ) === '-php' ) {
    … …  
    333354                }
    334355                $link = home_url( user_trailingslashit( "reference/files/$slug" ) );
    335         } elseif ( $taxonomy === 'wp-parser-since' ) {
     356        } elseif ( 'wp-parser-since' === $taxonomy ) {
    336357                $link = str_replace( $term->slug, str_replace( '-', '.', $term->slug ), $link );
    337358        }
     359
    338360        return $link;
    339361}
    … …  
    354376}
    355377
     378/**
     379 * Register and enqueue the theme assets.
     380 */
    356381function theme_scripts_styles() {
    357382        wp_enqueue_style( 'dashicons' );
     383        // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
    358384        wp_enqueue_style( 'open-sans', '//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,400,300,600' );
    359         wp_enqueue_style( 'wporg-developer-style', get_stylesheet_uri(), array(), '4' );
     385        wp_enqueue_style( 'wporg-developer-style', get_stylesheet_uri(), array(), filemtime( __DIR__ . '/style.css' ) );
    360386        wp_enqueue_style(
    361387                'wp-dev-sass-compiled',
    … …  
    364390                filemtime( __DIR__ . '/stylesheets/main.css' )
    365391        );
    366         wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20181209', true );
    367         wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
    368         wp_enqueue_script( 'wporg-developer-search', get_template_directory_uri() . '/js/search.js', array(), '20150430', true );
    369         wp_enqueue_script( 'wporg-developer-chapters', get_template_directory_uri() . '/js/chapters.js', array( 'jquery' ), '20190603' );
    370         wp_enqueue_script( 'wporg-developer-menu', get_template_directory_uri() . '/js/menu.js', array( 'jquery' ), '20180201', true );
     392        wp_enqueue_script( 'wporg-developer-navigation', get_stylesheet_directory_uri() . '/js/navigation.js', array(), filemtime( __DIR__ . '/js/navigation.js' ), true );
     393        wp_enqueue_script( 'wporg-developer-chapters', get_stylesheet_directory_uri() . '/js/chapters.js', array( 'jquery' ), filemtime( __DIR__ . '/js/chapters.js' ) );
     394        wp_enqueue_script( 'wporg-developer-menu', get_stylesheet_directory_uri() . '/js/menu.js', array( 'jquery' ), filemtime( __DIR__ . '/js/menu.js' ), true );
    371395}
    372396
    … …  
    385409
    386410/**
    387  * If a syntax highlighted code block exceeds a given number of lines, wrap the
    388  * markup with other markup to trigger the code expansion/collapse JS handling
    389  * already implemented for the code reference.
    390  *
    391  * @param string  $text The pending result of the syntax highlighting.
     411 * Customize the syntax highlighter style.
     412 * See https://github.com/PrismJS/prism-themes.
     413 *
     414 * @param string $path Path to the file to override, relative to the theme.
    392415 * @return string
    393416 */
    394 function syntaxhighlighter_htmlresult( $text ) {
    395 
    396         // is_admin() is true in front end AJAX requests.
    397         if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    398                 return $text;
    399         }
    400 
    401         $new_text      = '';
    402         // Collapse is handled for >10 lines. But just go ahead and show the full
    403         // code if that is just barely being exceeded (no one wants to expand to
    404         // see one or two more lines).
    405         $lines_to_show = 12;
    406         $do_collapse   = ( substr_count( $text, "\n" ) - 1 ) > $lines_to_show;
    407 
    408         if ( $do_collapse )  {
    409                 $new_text .= '<section class="source-content">';
    410                 $new_text .= '<div class="source-code-container">';
    411         }
    412 
    413         $new_text .= $text;
    414 
    415         if ( $do_collapse ) {
    416                 $new_text .= '</div>';
    417                 $new_text .= '<p class="source-code-links"><span>';
    418                 $new_text .= '<a href="#" class="show-complete-source">' . __( 'Expand full source code', 'wporg' ) . '</a>';
    419                 $new_text .= '<a href="#" class="less-complete-source">' . __( 'Collapse full source code', 'wporg' ) . '</a>';
    420                 $new_text .= '</span></p>';
    421                 $new_text .= '</section>';
    422         }
    423 
    424         return $new_text;
    425 }
     417function update_prism_css_path( $path ) {
     418        return '/stylesheets/prism.css';
     419}
Note: See TracChangeset for help on using the changeset viewer.