Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggreagtion Enquires Welcome

Provide a Download Link For The Latest Version Of WordPress (With Shortcode or PHP)

If you're in the web business, it' likely you have something to do with WordPress. The shortcode function on this page serves to provide a download link to the current version of the package. It's not intended as an alternative to the WordPress website, or as an alternative to the inbuilt update features. We use it on our own reference page as a means to provide a quick reference for our own fresh installs.

We utilize the WordPress API as described on the WP Codex page. The result is cached locally for 12 hours to avoid repeated requests.

The Result

To display the download link only, use [bmwordpress]. The result:

Download Current Version [ Download ] (V5.7.2)

We would like access to the Australian locale so we use [bmwordpress locale="en_AU"]. The result:

Download Current Version [ Download ] (V5.7.2), Localised en_AU Version [ Download ] (V5.7.2)

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

1
<?php 
2
/*
3
 Provide a Download Link For The Latest Version Of WordPress (With Shortcode or PHP)
4
 http://www.beliefmedia.com/wordpress-download
5
*/
6
 
7
8
 
9
  $atts = shortcode_atts(array(
10
    'locale' => false,
11
    'cache_tmp' => 3600,
12
    'cache' => 3600 * 6
13
  ), $atts);
14
 
15
 $transient = 'wpdlk_' . md5(serialize($atts));
16
 $cachedresult =  get_transient($transient);
17
 if ($cachedresult !== false ) {
18
  return $cachedresult;
19
 
20
  } else {
21
 
22
  $url = 'https://api.wordpress.org/core/version-check/1.7/';
23
  $data = @file_get_contents($url);
24
  if ($data !== false) $data = json_decode($data, true);
25
 
26
  if ($data !== false) {
27
 
28
    $download = $data['offers']['0']['download'];
29
    $current = $data['offers']['0']['current'];
30
    $php_version = $data['offers']['0']['php_version'];
31
    $mysql_version = $data['offers']['0']['mysql_version'];
32
 
33
    /* Create links */
34
    $result = '<p>Download Current Version [ <a href=&quot;' . $download . '&quot;>Download</a> ] (V' . $current . ')';
35
    if ($atts['locale'] !== false) $result .= ', Localised ' . $atts['locale'] . ' Version [ <a href=&quot;https://' . strtolower($atts['locale']) . '.wordpress.org/wordpress-' . $current . '-' . $atts['locale'] . '.zip&quot;>Download</a> ] (V' . $current . ')';
36
    $result .= '</p>';
37
 
38
    set_transient($transient, $result, $atts['cache']);
39
    return $result;
40
 
41
  } else {
42
 
43
    $result = '<p>Temporarily Unavailable</p>';
44
    set_transient($transient, $result, $atts['cache_tmp']);
45
    return $result;
46
 
47
  }
48
 }
49
}
50
add_shortcode('bmwordpress', 'beliefmedia_wordpress_download_links');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

PHP Code

Used outside of WordPress, the following may be used. Usage requires Simple Cache.

1
<?php 
2
/*
3
 Provide a Download Link For The Latest Version Of WordPress (With Shortcode or PHP)
4
 http://www.beliefmedia.com/wordpress-download
5
*/
6
 
7
function beliefmedia_wordpress_download_links($locale = '', $cache = 43200) {
8
 
9
 $transient = 'wp_download_' . md5(serialize(func_get_args()));
10
 $cachedresult =  beliefmedia_get_transient($transient, $cache);
11
 
12
 if ($cachedresult !== false ) {
13
  return $cachedresult;
14
 
15
  } else {
16
 
17
  $url = 'https://api.wordpress.org/core/version-check/1.7/';
18
  $data = @file_get_contents($url);
19
  if ($data !== false) $data = json_decode($data, true);
20
 
21
  if ($data !== false) {
22
 
23
    $download = $data['offers']['0']['download'];
24
    $current = $data['offers']['0']['current'];
25
    $php_version = $data['offers']['0']['php_version'];
26
    $mysql_version = $data['offers']['0']['mysql_version'];
27
 
28
    $result = '<p>Download Current Version [ <a href=&quot;' . $download . '&quot;>Download</a> ] (V' . $current . ')';
29
    if ($locale != '') $result .= ', Localised ' . $atts['locale'] . ' Version [ <a href=&quot;' . $download . '?locale=' . $atts['locale'] . '&quot;>Download</a> ] (V' . $current . ')';
30
    $result .= '</p>';
31
 
32
    beliefmedia_set_transient($transient, $result);
33
    return $result;
34
 
35
    } else {
36
 
37
    $result = beliefmedia_get_transient_data($transient);
38
    set_transient($transient, $result);
39
    return $result;
40
 
41
  }
42
 }
43
}
44
 
45
/* Usage */
46
47
 
48
/* Usage, Australian locale */
49
echo beliefmedia_wordpress_download_links($locale = 'au_AU');

Considerations

  • If you use a locale, ensure you copy it in the correct format (en_AU).
  • Alter the text to return your desired text. We coded it to best suit our needs... and it may not be consistent with yours.
  • Include the required PHP and MySQL version into your text with $php_version and $mysql_version.
  • If you supply a locale, ensure it's correct. If invalid, the response will only return an error.

Download


Title: WordPress Current Download Link (WP Plugin)
Description: Provide a Download Link For The Latest Version Of WordPress (With Shortcode or PHP).
  Download • Version 0.1, 1.6K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (1.0K)    PHP Code & Snippets, (1.0K)    

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Connecticut)

  Want to have a chat?
 

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment

READY TO HAVE A CHAT? CALL US ANYTIME ON 1300 235 433