• I have been looking at code and searching through web sites and I think I am screwed as to what I want to do. I was looking for a way to add a filter that would inject category id’s into the query for the function get_bookmarks before it gets the list of links. I know I can add a filter to run after it gets the links, but I don’t want to do that.

    Here is what I am trying to do:

    I have a web site where people will only get to see links based on their user type. So “employees” will only see links in the “employees” category, and “managers” will only see links in the “managers” category. Links could be in both so both would see them.

    I can do this on the template side of it by adding a field to the wp_list_bookmarks tag, but I would rather write a plugin that would do this.

    Do you get what I mean? Am I grasping at air here – can I not add stuff to the query in get_bookmarks before it runs? For now I will do it in the template, but I would prefer it be a plugin.

    Thanks.

Viewing 1 replies (of 1 total)
  • you could use a preg_replace to inject the code.

    i wanted to use highslide to expand my links without leaving the website, so i added this:

    function make_hs_simple($content) {
    
        $pattern = "/<a(.*?)href=('|\")([A-Za-z0-9\/_\.\~\:-]*?)('|\")([^\>]*?)>/i";
        $replacement = '<a$1href=$2$3$4$5 onclick="return hs.htmlExpand(this, { objectType: \'iframe\',  allowHeightReduction: true, allowWidthReduction: true} )">';
        $content = preg_replace($pattern, $replacement, $content);
        return $content;
    }
    
    add_filter('wp_list_bookmarks', 'make_hs_simple');

    if you added global $post within the function, then replaced all the onlick like this:

    function make_hs_simple($content) {
    	global $post
    
    	$pattern = "/<a(.*?)href=('|\")([A-Za-z0-9\/_\.\~\:-]*?)('|\")([^\>]*?)>/i";
    	$replacement = '<a$1href=$2$3$4$5 '. $post->ID.'>';
    	$content = preg_replace($pattern, $replacement, $content);
    	return $content;
    }
    
    add_filter('wp_list_bookmarks', 'make_hs_simple');

    i dont know if thats exactly how you wanted it to work, but it did the trick for me, so it might be a start. although you also wrote that post 6 months ago, so you probably fixed it by now 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Adding a filter to ether get_bookmarks or wp_list_bookmarks’ is closed to new replies.