WordPress.org

Making WordPress.org

Changeset 5249


Ignore:
Timestamp:
04/05/2017 05:13:26 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Add a previous versions download link.
This is currently badly styled, but is a POC to see how it works. The <select> uses Javascript to change the <a> button's href.
A <a> is used rather than a <button> or form submit to allow copy-paste to work.

See #2365

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-advanced.php

    r5248 r5249  
    2626        <tbody></tbody>
    2727    </table>
     28
     29    <?php
     30
     31        $tags = (array) get_post_meta( $post->ID, 'tagged_versions', true );
     32        // Sort the versions by version
     33        usort( $tags, 'version_compare' );
     34        // We'll want to add a Development Version if it exists
     35        $tags[] = 'trunk';
     36
     37        // Remove the current version, this may be trunk.
     38        $tags = array_diff( $tags, array( get_post_meta( $post->ID, 'stable_tag', true ) ) );
     39
     40        // List Trunk, followed by the most recent non-stable release.
     41        $tags = array_reverse( $tags );
     42
     43        if ( $tags ) {
     44            echo '<h5>' . __( 'Previous Versions', 'wporg-plugins' ) . '</h5>';
     45
     46            echo '<select id="prevous-versions" onchange="getElementById(\'download-previous-link\').href=this.value;">';
     47            foreach ( $tags as $version ) {
     48                $text = ( 'trunk' == $version ? __( 'Development Version', 'wporg-plugins' ) : $version );
     49                printf( '<option value="%s">%s</option>', esc_attr( Template::download_link( $post, $version ) ), esc_html( $text ) );
     50            }
     51            echo '</select> ';
     52
     53            printf(
     54                '<a href="%s" id="download-previous-link" class="button">%s</a>',
     55                esc_url( Template::download_link( $post, reset( $tags ) ) ),
     56                __( 'Download', 'wporg-plugins' )
     57            );
     58        }
     59
     60    ?>
    2861</div>
Note: See TracChangeset for help on using the changeset viewer.