Support Forum
I'm working on upgrading from 4.5 to 5.1.3.
It looks like links that were auto shortened and now formatted like this...
<a href="http://www.theglobeandmail.com/globe-investor/personal-finance/problem-with-post-edit-buttonigher-fees-borrowing-costs-welcome-to-booming-big-six-banking/article4521956/" rel="nofollow" target="_blank">http://www.theglobeandmail.com.....le4521956/</a>
... are not properly shortened anymore. They instead show up as just the part before the periods and thus the actual link is broken. Would installing a forum plugin (such as the TinyMCE one) fix the issue or is it an inherent issue with new auto-shortening logic?
In fact, the above post is a perfect illustration of the issue, as is the test below
Testing by editing the HTML source: http://www.theglobeandmail.com.....le4521956/
It seems somewhere between 4.5.1 and 5.x, we made a change in the url shortening... earlier, it incorrectly was saving shortened urls in the database vs shortening them on display... we corrected that in 5.0 but does have some knock off on earlier shortenings due to a bug in wp where the make clickabled function chokes on a dot/period in a url anchor text and thus dorks it up... We are trying to find another make clickable function besides that wp one that works properly, but have not found one yet that does not mess up elsewhere... a catch 22 situation at the moment...
but new posts wont have this problem...
Visit Cruise Talk Central and Mr Papa's World
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?).
/*
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/suppo.....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 '+';
}
?>
hey Peter, welcome back!
wow, going to have to take a closer look at that when I get a chance... might be something we want to including in the upgrade script from 4.5...
sorry, what do you mean by content elements? the display template functions? have you checked out the codex? http://codex.simple-press.com
its far from complete but we continue to populate it with more data as we go... sorry, just a limit to what the 3 of us can do!
Visit Cruise Talk Central and Mr Papa's World
Regarding "manipulating various content elements", I mean code like:
sp_update_post( $postID, $postContent );
... so that we don't have to directly write SQL.
I think there was code like that in 4.5. It might be obvious in 5.1.3, although I don't see it in the codex. Then again, I might just need to get familiar with the "new" version
As Steve said above we are trying hard to get the Codex API pages documented but it is a time thing with such a small team. In the meantime we suggest to users that if they need some API clarification on any point, they ask here and we will endeavour to give detailed explanations, advice and pointers and help walk them through things.
There just are not enough hours in a day!
YELLOW
SWORDFISH
|
1 Guest(s)