WordPress.org

Making WordPress.org

Changeset 9438


Ignore:
Timestamp:
01/30/2020 02:15:05 AM (4 weeks ago)
Author:
SergeyBiryukov
Message:

Support Theme: Prevent standalone <li> tags from breaking the theme layout.

If a <li> tag is not preceded by <ul> or <ol>, prepend it with <ul> and let force_balance_tags() do the rest.

Fixes #20. See #bb2357.

File:
1 edited

Legend:

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

    r9277 r9438  
    591591add_filter( 'bbp_get_topic_edit_url', 'wporg_support_fix_pending_posts_reply_url', 10, 2 );
    592592add_filter( 'bbp_get_reply_edit_url', 'wporg_support_fix_pending_posts_reply_url', 10, 2 );
     593
     594/**
     595 * Prevent standalone <li> tags from breaking the theme layout.
     596 *
     597 * If a <li> tag is not preceded by <ul> or <ol>, prepend it with <ul>
     598 * and let force_balance_tags() do the rest.
     599 *
     600 * @see https://meta.trac.wordpress.org/ticket/20
     601 * @see https://bbpress.trac.wordpress.org/ticket/2357
     602 *
     603 * @param string $content Topic or reply content.
     604 * @return string Filtered content.
     605 */
     606function wporg_support_wrap_standalone_li_tags_in_ul( $content ) {
     607    if ( false !== strpos( $content, '<li>' ) ) {
     608        $content = preg_replace( '#(?<!<ul>\s|<ol>\s)<li>#', '<ul><li>', $content );
     609        $content = force_balance_tags( $content );
     610    }
     611
     612    return $content;
     613}
     614add_filter( 'bbp_get_topic_content', 'wporg_support_wrap_standalone_li_tags_in_ul', 50 );
     615add_filter( 'bbp_get_reply_content', 'wporg_support_wrap_standalone_li_tags_in_ul', 50 );
    593616
    594617/**
Note: See TracChangeset for help on using the changeset viewer.