Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin that I use on all my new sites to set up site defaults (deletes the "hello world" post, the "about" page, the "Mr WordPress" comment, etc...)

I'd like to add a routine that removes all the default links under "Blogroll". I'm not sure what function to call. Any ideas?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Haven't tested this yet, but it should do the trick in 3x:

// Get all the existing links
$arr_args = array( 'hide_invisible' => 0 );
$arr_links = get_bookmarks( $arr_args );

// Run through the list and delete 'em
foreach($arr_links as $obj_link) {
    wp_delete_link($obj_link->link_id);
}

Of course, you'd only want to do this once, and only on a fresh install as it deletes all links. Alternately, you could hardcode an array of default link slugs/ids and loop through that instead. Depends where and when you're running this thing.

share|improve this answer
    
@TheDeadMedic, @Denis > Thanks! –  Scott B Dec 7 '10 at 15:15

Just "truncate wp_links" using wpdb. :-)

share|improve this answer
    
+1 - but don't forget about the term relationships first (and possibly even deleting the term 'blogroll' too?) –  TheDeadMedic Dec 6 '10 at 22:09
1  
Denis, sounds interesting, can you elaborate a bit on how you would do this taking TheDeadMedic's comment into account? –  Scott B Dec 6 '10 at 22:41
1  
Why would you mess with all this manually when Wordpress has a native function for deleting links? The function wp_delete_link() deletes a link and its relationships for you. It also cleans out the bookmark cache. –  MathSmath Dec 6 '10 at 23:38
1  
@MathSmath It was only that a raw query does everything in one swoop - but in hindsight, you're right. I'd combine the two solutions, wp_delete_link() to clear out the cache and term relations, then TRUNCATE to reset the table index :) –  TheDeadMedic Dec 6 '10 at 23:52
    
@TheDeadMedic Digital high five. –  MathSmath Dec 7 '10 at 1:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.