Here’s a quick script to clean up old style links! It could probably use Simple:Press API functions for fetching and updating posts (speaking of which, is there documentation for manipulating the various content elemenest?).
<?php
/*
For migrating from Simple:Press (WordPress forum plugin) 4.5 to 5.1.3 and cleaning up link shortening
In 4.5, links were shortened on save
In 5.1.3, links are shortened on display
Run this script in the root of your WordPress directory: php clean_up_links.php
Source: https://simple-press.com/support-forum/sp5-general-topics/link-formatting-when-upgrading-4-5-to-5-1-3
*/
include ‘wp-load.php’;
$postCount = $wpdb->get_var( ‘SELECT COUNT(*) FROM wp_sfposts’ );
$limit = 100;
print “n Total post count: $postCount”;
print “n Looping through $limit at a time”;
print “n”;
for( $offset = 0; $offset < $postCount; $offset += $limit )
{
$posts = $wpdb->get_results( “SELECT post_id, post_content FROM wp_sfposts LIMIT $limit, $offset ORDER BY post_id ASC” );
foreach( $posts as $post )
{
/*
Matches would be:
0 = The entire string
1 = The link in the <a> tag
2 = The rest of the parameters in the <a> tag (nofollow, target, etc.)
3 = The part after the 5 periods
So then we want to replace 0 with 1 for each result
We are assuming that the links have 5 consecutive periods
*/
$postContent = $post->post_content;
$postID = $post->post_id;
preg_match_all( “/<a href=”(.*?)”(.*?)…..(.*?)</a>/is”, $postContent, $linkMatches );
if( !empty( $linkMatches[0] ) )
{
foreach( $linkMatches[0] as $index => $stringMatch )
{
$postContent = str_replace( $stringMatch, $linkMatches[1][$index], $postContent );
$wpdb->query( $wpdb->prepare( “UPDATE wp_sfposts SET post_content = %s WHERE post_id = %d LIMIT 1;”, $postContent, $postID ) );
}
}
}
// Basic feedback to the user
print ‘+’;
}
?>