Ticket #2562: template_functions_bookmark_incl_excl.diff

File template_functions_bookmark_incl_excl.diff, 2.0 KB (added by MichaelH, 6 years ago)

adds exclusion/inclusion to get_bookmarks()

  • wp-includes/template-functions-bookmarks.php

     
    283283                parse_str($args, $r); 
    284284 
    285285        $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => -1, 
    286                 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0); 
     286                'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => ''); 
    287287        $r = array_merge($defaults, $r); 
    288288        extract($r); 
    289289 
     290        if ( !empty($include) ) {  
     291        $exclude = ''; 
     292        $category = -1; 
     293        $category_name = ''; 
     294        } 
     295 
    290296        $exclusions = ''; 
    291297        if ( !empty($exclude) ) { 
    292298                $exlinks = preg_split('/[\s,]+/',$r['exclude']); 
    293299                if ( count($exlinks) ) { 
    294300                        foreach ( $exlinks as $exlink ) { 
     301                                if (empty($exclusions)) 
     302                                        $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' '; 
     303                                else 
    295304                                $exclusions .= ' AND link_id <> ' . intval($exlink) . ' '; 
    296305                        } 
    297306                } 
    298307        } 
     308        if (!empty($exclusions))  
     309                $exclusions .= ')'; 
    299310 
     311        $inclusions = ''; 
     312        if ( !empty($include) ) { 
     313                $inclinks = preg_split('/[\s,]+/',$r['include']); 
     314                if ( count($inclinks) ) { 
     315                        foreach ( $inclinks as $inclink ) { 
     316                                if (empty($inclusions)) 
     317                                        $inclusions = ' AND ( link_id = ' . intval($inclink) . ' '; 
     318                                else 
     319                                        $inclusions .= ' OR link_id = ' . intval($inclink) . ' '; 
     320                        } 
     321                } 
     322        } 
     323        if (!empty($inclusions))  
     324                $inclusions .= ')'; 
     325                 
    300326        if ( ! empty($category_name) ) { 
    301327                if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") ) 
    302328                        $category = $cat_id; 
     
    341367                $visible = "AND link_visible = 'Y'"; 
    342368 
    343369        $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query"; 
     370        $query .= " $exclusions $inclusions"; 
    344371        $query .= " ORDER BY $orderby $order"; 
    345372        if ($limit != -1) 
    346373                $query .= " LIMIT $limit";