WordPress.org

Make WordPress Core

Changes between Version 2 and Version 3 of Ticket #49025, comment 6


Ignore:
Timestamp:
04/30/2020 11:45:56 AM (18 months ago)
Author:
raQai
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #49025, comment 6

    v2 v3  
    2929{{{
    3030function anchor_nav_menu_items($menu){
    31         // contains # and does not start with it
    32         if (strpos($menu->url,'#')) {
    33       // check if this is a relative url
    34       // FIXME this condition needs some additional work because it relys on using the host properly
    35       //       www.domain.com/foo/bar would probably not match https://domain.com/foo/bar
    36                 if (strpos(get_site_url(), $menu->url) === false) {
    37                         $menu_site_url = get_site_url(null, $menu->url);
    38          $menu_site_id = url_to_postid($menu_site_url);
    39          // check if the current site is referenced in the menu item
    40                         if ($menu_site_id === get_the_id()) {
    41                                 $menu_site_url_explode = explode('#', $menu->url);
    42                                 $menu->url = '#' . end($menu_site_url_explode);
    43                         }
    44                 }
    45         }
    46 
    47         return $menu;
     31  // contains # and does not start with it
     32  if (strpos($menu->url,'#')) {
     33    // check if this is a relative url
     34    // FIXME this condition needs some additional work because it relys on using the host properly
     35    //       www.domain.com/foo/bar would probably not match https://domain.com/foo/bar
     36    if (strpos(get_site_url(), $menu->url) === false) {
     37      $menu_site_url = get_site_url(null, $menu->url);
     38      $menu_site_id = url_to_postid($menu_site_url);
     39      // check if the current site is referenced in the menu item
     40      if ($menu_site_id === get_the_id()) {
     41        $menu_site_url_explode = explode('#', $menu->url);
     42        $menu->url = '#' . end($menu_site_url_explode);
     43      }
     44    }
     45  }
     46  return $menu;
    4847}
    4948
     
    53523. Using the above changes, some functions in the JavaScript can be simplified/removed (see attached index.js.diff and index.js)
    5453
    55 I would create a PR for this, but I do not know where to actually put the php code since I am only used to hooks and filters, not the WordPress core libraries. This is certainly not a final solution, but imo it goes into the right direction.
     54I would create a PR for this, but I do not know where to actually put the php code since I am only used to hooks and filters, not the WordPress core libraries.
    5655
    5756You can see a working example on https://foos.bogdan-iws.de/
    5857Relevant Navigation: "Angebot" -> all sub elements are anchors.
     58
     59This is certainly not a final solution, but imo it goes into the right direction. I put fixmes on every line which would need further investigation.