Modifying Tweetable plugin to work with PrettyLinkPro & Twitter Friendly Links

Modifying Tweetable (plugin) to work with PrettyLinkPro & Twitter Friendly Links

A little over a year ago I modified tweetable to shorten my auto published URLs with Now, I was using that for awhile but then turned to Twitter Friendly Links to use just the ID base with out the post or page query string (?p= ?page= ?attachment=).

After some time I started to play with Blair’s PrettyLink and PrettyLinkPro on a few other domain I’ve got. Well with the latest version of tweetable ( released this week I thought I check to see what was new and what I needed to modify in my pre-existing code. Turn’s out a new API was implemented, and that didn’t do much for me. I also recently just purchased and thought it would be great to auto shirk links with my new short dot me domain using PrettyLink and tweetable.

Just link before we are going to be editing two files: 1 mh_twitter_class.php and 2 admin_menus.php.

File number 1

Find line 388 and add global $post; after the public function. You’ll also want to change the $shortener default value, by removing it completely, leaving $shortener ONLY!

public function shorten_url($the_url, $shortener, $api_key='', $user='') {
    global $post;

Find line 427 and add this code (the parts in bold were added). Be sure to replace the deleted variable with the one provided in your pretty link tool page.

   } elseif ($shortener=="yourls" && isset($api_key) && isset($user)) {
        //Pass a string in the form of "[email protected]" as the username, and the password as the API key
        $yourls = explode('@', $user);
        $url = "http://{$yourls[1]}/yourls-api.php?username={$yourls[0]}&password={$api_key}&format=simple&action=shorturl&url={$the_url}";
        $response = $this->send_request($url, 'GET');
     * @ added by Austin Passy
     * @ link
    } elseif ($shortener=="self") {
        $url = url_to_postid( $the_url );
        $response = get_home_url( '/?=' ) . $url;

    } elseif ($shortener=="self") {
        $url = url_to_postid( $the_url );
        if ( 'post' == get_post_type() )
            $shortlink = wp_get_shortlink();
        elseif ( 'page' == get_post_type() )
            $shortlink = home_url( "?page_id={$url}" );
        elseif ( 'attachment' == $post->post_type )
            $shortlink = home_url( "?attachment_id={$url}" );
        $response = $shortlink;

    } elseif ($shortener=="twitterfriendlylinks" && function_exists( 'twitter_link' ) ) {
        $url = twitter_link();
        $response = $url;
    } elseif ($shortener=="prettylinkpro" && function_exists( 'prlipro_pretty_link' ) ) {
        global $prli_blogurl;
        $url = "{$prli_blogurl}/index.php?action=prli_endpoint_url&k=445e75096450c647eb707s7c45545a56&url={$the_url}";
        $response = $this->send_request($url, 'GET');
    // END
    } else {
        $url = "{$the_url}";
        $response = $this->send_request($url, 'GET');

File number 2

Find line 380 and add this code (the parts in bold were added):

   <option value="yourls" <?php if ($setting_url_shortener=='yourls') { echo 'selected="selected"'; } ?>>YOURLS</option>
     * @ added by Austin Passy
     * @ link
     */ ?>
    <option value="self" <?php if ($setting_url_shortener=='self') { echo 'selected="selected"'; } ?>>SELF (?p=ID)</option>
    <option value="twitterfriendlylinks" <?php if ($setting_url_shortener=='twitterfriendlylinks' ) { echo 'selected="selected"'; } ?>>Twitter Friendly Links</option>    
    <option value="prettylinkpro" <?php if ($setting_url_shortener=='prettylinkpro' ) { echo 'selected="selected"'; } ?>>Pretty Link Pro</option>
    <?php /**END */ ?>
    <?php $error_class = ' style="background:#F3898C;border:1px solid #F00;color:#222;padding:5px 10px;"'; ?>
    <?php if ($setting_url_shortener=='twitterfriendlylinks' && !function_exists( 'twitter_link' ) ) { ?>
    <span class="description"<?php echo $error_class; ?>>Requires <a href="">Twitter Friendly Links</a>. Please install or change settings</span>
    <?php } ?>
    <?php if ($setting_url_shortener=='prettylinkpro' && !function_exists( 'prlipro_pretty_link' )) { ?>
    <span class="description"<?php echo $error_class; ?>>Requires <a href="">Pretty Link Pro</a>. Please install or change settings</span>
    <?php } ?>
    <br />Specify which URL shortener should be used by Tweetable.

Now upload those two files, or if editing them inside of WordPress (by going to /wp-admin/plugin-editor.php/), and save them. Then apply the new changes in the Tweetable settings page and your done. Next time you post a entry the URL used will be your domain with the default ugly permalink, an ID or random number generated by Twitter Friendly Links or a shortlink with a possible different domain (like my domain) by PrettyLink!


πŸ’πŸ½β€β™‚οΈ Husband to Jeana.
⚾️ Dodgers & Brewers.
πŸ’» PHP Engineer.
πŸŒπŸΌβ€β™‚οΈGolfer; ~14 HDC.
🌱 Hydroponic Gardner.
🍿 Plex nerd.
πŸš™ '15 WRX, '22 Model 3 LR, & '66 Corvette C2.

Follow me on Twitter @TheFrosty & Instagram @TheFrosty.

Articles: 292