Make WordPress Core


Ignore:
Timestamp:
10/16/2013 04:14:29 AM (13 years ago)
Author:
dd32
Message:

Language Packs: Many many fixes such as:

  • Add a "Update Translations" stand-alone button to the updates page
  • Shift Language feedback to before update process completion action links & limit the verbosity of output (name + success/errors)
  • Simplify/combine the language update descriptive string to only include a plugin/theme name
  • Properly handle cache clearing after language updates to prevent langs being repeditively updated
  • Display a "All items up to date" string when there's nothing to do
  • Reduce the 'Connection Information' from a <h2> to a <h3> to remove duplicate h2's and screen icons from update screens
  • Fix the Direct filesystem method not being used for Language updates because WP_LANG_DIR doesn't exist (check it's parent for writable instead)

See #18200, #22704

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r25801 r25806  
    308308                extract($options);
    309309
    310                 //Connect to the Filesystem first.
    311                 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
    312                 if ( ! $res ) //Mainly for non-connected filesystem.
    313                         return false;
    314 
    315310                if ( ! $is_multi ) // call $this->header separately if running multiple times
    316311                        $this->skin->header();
     312
     313                // Connect to the Filesystem first.
     314                $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
     315                // Mainly for non-connected filesystem.
     316                if ( ! $res ) {
     317                        if ( ! $is_multi )
     318                                $this->skin->footer();
     319                        return false;
     320                }
    317321
    318322                $this->skin->before();
     
    369373                $this->skin->after();
    370374
    371                 if ( ! $is_multi )
     375                if ( ! $is_multi ) {
     376                        do_action( 'upgrader_process_complete', $this, $hook_extra );
    372377                        $this->skin->footer();
     378                }
    373379
    374380                return $result;
     
    443449                        'clear_destination' => false, // Do not overwrite files.
    444450                        'clear_working' => true,
    445                         'hook_extra' => array()
     451                        'hook_extra' => array(
     452                                'type' => 'plugin',
     453                                'action' => 'install',
     454                        )
    446455                ) );
    447456
     
    453462                // Force refresh of plugin update information
    454463                wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
    455 
    456                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin' ), $package );
    457464
    458465                return true;
     
    491498                        'clear_working' => true,
    492499                        'hook_extra' => array(
    493                                 'plugin' => $plugin
     500                                'plugin' => $plugin,
     501                                'type' => 'plugin',
     502                                'action' => 'update',
    494503                        ),
    495504                ) );
     
    504513                // Force refresh of plugin update information
    505514                wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
    506 
    507                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin' ), $plugin );
    508515
    509516                return true;
     
    588595                $this->maintenance_mode(false);
    589596
     597                do_action( 'upgrader_process_complete', $this, array(
     598                        'action' => 'update',
     599                        'type' => 'plugin',
     600                        'bulk' => true,
     601                        'plugins' => $plugins,
     602                ) );
     603
    590604                $this->skin->bulk_footer();
    591605
     
    597611                // Force refresh of plugin update information
    598612                wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
    599 
    600                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true ), $plugins );
    601613
    602614                return $results;
     
    815827                        'destination' => get_theme_root(),
    816828                        'clear_destination' => false, //Do not overwrite files.
    817                         'clear_working' => true
     829                        'clear_working' => true,
     830                        'hook_extra' => array(
     831                                'type' => 'theme',
     832                                'action' => 'install',
     833                        ),
    818834                ) );
    819835
     
    826842                // Refresh the Theme Update information
    827843                wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
    828 
    829                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'theme' ), $package );
    830844
    831845                return true;
     
    864878                        'clear_working' => true,
    865879                        'hook_extra' => array(
    866                                 'theme' => $theme
     880                                'theme' => $theme,
     881                                'type' => 'theme',
     882                                'action' => 'update',
    867883                        ),
    868884                ) );
     
    876892
    877893                wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
    878 
    879                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), $theme );
    880894
    881895                return true;
     
    960974                $this->maintenance_mode(false);
    961975
     976                do_action( 'upgrader_process_complete', $this, array(
     977                        'action' => 'update',
     978                        'type' => 'plugin',
     979                        'bulk' => true,
     980                        'themes' => $themes,
     981                ) );
     982
    962983                $this->skin->bulk_footer();
    963984
     
    971992                // Refresh the Theme Update information
    972993                wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
    973 
    974                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme', 'bulk' => true ), $themes );
    975994
    976995                return $results;
     
    10741093}
    10751094
    1076 add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
     1095add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
    10771096class Language_Pack_Upgrader extends WP_Upgrader {
    10781097
     
    10801099        var $bulk = true;
    10811100
    1082         static function async_upgrade( $upgrader, $context, $package ) {
     1101        static function async_upgrade( $upgrader = false ) {
    10831102                // Avoid recursion.
    1084                 if ( $upgrader instanceof Language_Pack_Upgrader )
     1103                if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader )
    10851104                        return;
    10861105
    1087                 $lp_upgrader = new Language_Pack_Upgrader( new Headerless_Upgrader_Skin() );
     1106                // Nothing to do?
     1107                $language_updates = wp_get_translation_updates();
     1108                if ( ! $language_updates )
     1109                        return;
     1110
     1111                $skin = new Language_Pack_Upgrader_Skin( array(
     1112                        'skip_header_footer' => true,
     1113                ) );
     1114
     1115                $lp_upgrader = new Language_Pack_Upgrader( $skin );
    10881116                $lp_upgrader->upgrade();
    10891117        }
     
    10991127        }
    11001128
    1101         function upgrade( $update = false ) {
     1129        function upgrade( $update = false, $args = array() ) {
    11021130                if ( $update )
    11031131                        $update = array( $update );
    1104                 $results = $this->bulk_upgrade( $update );
     1132                $results = $this->bulk_upgrade( $update, $args );
    11051133                return $results[0];
    11061134        }
    11071135
    1108         function bulk_upgrade( $language_updates = array() ) {
     1136        function bulk_upgrade( $language_updates = array(), $args = array() ) {
    11091137                global $wp_filesystem;
     1138
     1139                $defaults = array(
     1140                        'clear_update_cache' => true,
     1141                );
     1142                $parsed_args = wp_parse_args( $args, $defaults );
    11101143
    11111144                $this->init();
     
    11151148                        $language_updates = wp_get_translation_updates();
    11161149
    1117                 if ( empty( $language_updates ) )
     1150                if ( empty( $language_updates ) ) {
     1151                        $this->skin->header();
     1152                        $this->skin->before();
     1153                        $this->skin->set_result( true );
     1154                        $this->skin->feedback( 'up_to_date' );
     1155                        $this->skin->after();
     1156                        $this->skin->bulk_footer();
     1157                        $this->skin->footer();
    11181158                        return true;
     1159                }
    11191160
    11201161                if ( 'upgrader_process_complete' == current_filter() )
     
    11451186
    11461187                foreach ( $language_updates as $language_update ) {
     1188
     1189                        $this->skin->language_update = $language_update;
    11471190
    11481191                        $destination = WP_LANG_DIR;
     
    11761219                }
    11771220
     1221                $this->skin->bulk_footer();
     1222
     1223                $this->skin->footer();
     1224
    11781225                // Clean up our hooks, in case something else does an upgrade on this connection.
    11791226                remove_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 2 );
     1227
     1228                if ( $parsed_args['clear_update_cache'] ) {
     1229                        wp_clean_themes_cache( true );
     1230                        wp_clean_plugins_cache( true );
     1231                        delete_site_transient( 'update_core' );
     1232                }
    11801233
    11811234                return $results;
     
    12051258
    12061259                return $source;
     1260        }
     1261
     1262        function get_name_for_update( $update ) {
     1263                switch ( $update->type ) {
     1264                        case 'core':
     1265                                return 'WordPress'; // Not translated
     1266                                break;
     1267                        case 'theme':
     1268                                $theme = wp_get_theme( $update->slug );
     1269                                if ( $theme->exists() )
     1270                                        return $theme->Get( 'Name' );
     1271                                break;
     1272                        case 'plugin':
     1273                                $plugin_data = get_plugins( '/' . $update->slug );
     1274                                $plugin_data = array_shift( $plugin_data );
     1275                                if ( $plugin_data )
     1276                                        return $plugin_data['Name'];
     1277                                break;
     1278                }
     1279                return '';
    12071280        }
    12081281
     
    13221395                }
    13231396
    1324                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ), $result );
    13251397                return $result;
    13261398        }
     
    16291701                                break;
    16301702                        case 'language':
    1631                                 if ( 'theme' == $item->type ) {
    1632                                         $theme = wp_get_theme( $item->slug );
    1633                                         $skin->feedback( sprintf(
    1634                                                 __( 'Updating the %1$s translation for the %2$s theme' ),
    1635                                                 $item->language,
    1636                                                 $theme->Get( 'Name' )
    1637                                         ) );
    1638                                         $item_name = sprintf(
    1639                                                 __( '%1$s translation for the %2$s theme' ),
    1640                                                 $item->language,
    1641                                                 $theme->Get( 'Name' )
    1642                                         );
    1643                                 } elseif ( 'plugin' == $item->type ) {
    1644                                         $plugin_data = get_plugins( '/' . $item->slug );
    1645                                         $plugin_data = array_shift( $plugin_data );
    1646                                         $skin->feedback( sprintf(
    1647                                                 __( 'Updating the %1$s translation for the %2$s plugin' ),
    1648                                                 $item->language,
    1649                                                 $plugin_data['Name']
    1650                                         ) );
    1651                                         $item_name = sprintf(
    1652                                                 __( '%1$s translation for the %2$s plugin' ),
    1653                                                 $item->language,
    1654                                                 $plugin_data['Name']
    1655                                         );
    1656                                 } else {
    1657                                         $skin->feedback( sprintf(
    1658                                                 __( 'Updating %s translation' ),
    1659                                                 $item->language
    1660                                         ) );
    1661                                         $item_name = sprintf(
    1662                                                 __( '%s translation' ),
    1663                                                 $item->language
    1664                                         );
    1665                                 }
    1666                                
     1703                                $name = $upgrader->get_name_for_update( $item );
     1704                                $skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)&#8230;' ), $name, $item->language ) );
    16671705                                break;
    16681706                }
     
    17121750
    17131751                // Don't automatically run these thins, as we'll handle it ourselves
    1714                 remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
     1752                remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
    17151753                remove_action( 'upgrader_process_complete', 'wp_version_check' );
    17161754                remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
Note: See TracChangeset for help on using the changeset viewer.