Make WordPress Core

Ticket #20618: 20618.2.patch

File 20618.2.patch, 4.7 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/includes/class-wp-plugin-install-list-table.php

     
    203203                                                break;
    204204                                        case 'latest_installed':
    205205                                        case 'newer_installed':
    206                                                 $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . __( 'Installed' ) . '</span>';
     206                                                $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>';
    207207                                                break;
    208208                                }
    209209                        }
  • wp-admin/includes/class-wp-theme-install-list-table.php

     
    198198                        'action' => 'install-theme',
    199199                        'theme'  => $theme->slug,
    200200                ), self_admin_url( 'update.php' ) );
    201                 $actions[] = '<a class="install-now" href="' . wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
    202201
     202                $update_url = add_query_arg( array(
     203                        'action' => 'upgrade-theme',
     204                        'theme'  => $theme->slug,
     205                ), self_admin_url( 'update.php' ) );
     206
     207                $status = $this->_get_theme_status( $theme );
     208
     209                switch ( $status ) {
     210                        default:
     211                        case 'install':
     212                                $actions[] = '<a class="install-now" href="' . wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
     213                                break;
     214                        case 'update_available':
     215                                $actions[] = '<a class="install-now" href="' . wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
     216                                break;
     217                        case 'newer_installed':
     218                        case 'latest_installed':
     219                                $actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
     220                                break;
     221                }
     222
    203223                $actions[] = '<a class="install-theme-preview" href="#" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>';
    204224
    205225                $actions = apply_filters( 'theme_install_actions', $actions, $theme );
     
    290310                        'theme'  => $theme->slug,
    291311                ), self_admin_url( 'update.php' ) );
    292312
     313                $update_url = add_query_arg( array(
     314                        'action' => 'upgrade-theme',
     315                        'theme'  => $theme->slug,
     316                ), self_admin_url( 'update.php' ) );
     317
     318                $status = $this->_get_theme_status( $theme );
     319
    293320                ?>
    294                 <div class="install-theme-info">
    295                         <a class="theme-install button-primary" href="<?php echo wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ); ?>"><?php _e( 'Install' ); ?></a>
     321                <div class="install-theme-info"><?php
     322                        switch ( $status ) {
     323                                default:
     324                                case 'install':
     325                                        echo '<a class="theme-install button-primary" href="' . wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) . '">' . __( 'Install' ) . '</a>';
     326                                        break;
     327                                case 'update_available':
     328                                        echo '<a class="theme-install button-primary" href="' . wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
     329                                        break;
     330                                case 'newer_installed':
     331                                case 'latest_installed':
     332                                        echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
     333                                        break;
     334                        } ?>
    296335                        <h3 class="theme-name"><?php echo $name; ?></h3>
    297336                        <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span>
    298337                        <?php if ( isset( $theme->screenshot_url ) ): ?>
     
    328367                global $tab, $type;
    329368                parent::_js_vars( compact( 'tab', 'type' ) );
    330369        }
     370
     371        /**
     372         * Check to see if the theme is already installed.
     373         *
     374         * @since 3.4
     375         * @access private
     376         *
     377         * @param object $theme - A WordPress.org Theme API object.
     378         * @return string Theme status.
     379         */
     380        function _get_theme_status( $theme ) {
     381                $status = 'install';
     382
     383                $installed_theme = wp_get_theme( $theme->slug );
     384                if ( $installed_theme->exists() ) {
     385                        if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) )
     386                                $status = 'latest_installed';
     387                        elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) )
     388                                $status = 'newer_installed';
     389                        else
     390                                $status = 'update_available';
     391                }
     392
     393                return $status;
     394        }
    331395}