Last active
April 4, 2020 11:20
-
-
Save swissspidy/e2d1cde667fa4da4db66 to your computer and use it in GitHub Desktop.
Display a table with available translation updates on the WordPress update screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Translation Updates Table | |
* | |
* @author Pascal Birchler <[email protected]> | |
* @license GPL2+ | |
*/ | |
/** | |
* Displays a table with available translation updates. | |
*/ | |
function required_language_updates_table() { | |
$translation_updates = wp_get_translation_updates(); | |
if ( empty( $translation_updates ) ) { | |
return; | |
} | |
require_once( ABSPATH . '/wp-admin/includes/translation-install.php' ); | |
$available_translations = wp_get_available_translations(); | |
$all_plugins = get_plugins(); | |
?> | |
<form method="post" action="<?php echo esc_url( 'update-core.php?action=do-translation-upgrade' ); ?>" name="upgrade-translations" class="upgrade"> | |
<table class="widefat" id="update-translations-table"> | |
<thead> | |
<tr> | |
<th scope="col" class="manage-column"><?php _e( 'Type' ); ?></th> | |
<th scope="col" class="manage-column"><?php _e( 'Translation' ); ?></th> | |
</tr> | |
</thead> | |
<tbody class="translations"> | |
<?php foreach ( $translation_updates as $available_update ) : ?> | |
<?php | |
$type = $available_update->type; | |
$language = $available_update->language; | |
$slug = $available_update->slug; | |
if ( isset( $available_translations[ $language ] ) ) { | |
$language = $available_translations[ $language ]['native_name']; | |
} | |
$name = ''; | |
if ( 'plugin' === $type ) { | |
foreach ( $all_plugins as $plugin ) { | |
if ( $slug === $plugin['TextDomain'] ) { | |
$name = $plugin['Title']; | |
break; | |
} | |
} | |
} else if ( 'theme' === $type ) { | |
$name = wp_get_theme( $slug )->get( 'Name' ); | |
} | |
?> | |
<tr> | |
<td><p><?php echo esc_html( ucfirst( $type ) ); ?></p></td> | |
<td> | |
<p> | |
<strong><?php echo esc_html( $language ); ?></strong> | |
<?php if ( ! empty( $name ) ) : ?> | |
<br> | |
<?php echo esc_html( $name ); ?> | |
<?php endif; ?> | |
</p> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
</tbody> | |
</table> | |
<p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade"/> | |
</p> | |
</form> | |
<?php | |
} | |
add_action( 'core_upgrade_preamble', 'required_language_updates_table' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment