Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-mendonca committed Feb 24, 2020
2 parents 00dd933 + b52a987 commit 66bf2e0
Show file tree
Hide file tree
Showing 23 changed files with 225 additions and 70 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"phpcompatibility/phpcompatibility-wp": "^2.1.0",
"szepeviktor/phpstan-wordpress": "^0.6.0"
},
"config": {
"optimize-autoloader": true
},
"scripts": {
"test": [
"@lint",
Expand Down
5 changes: 4 additions & 1 deletion css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ table.wp-list-table.plugins td.column-translation-stats {

table.wp-list-table.plugins td.column-translation-stats .translation-stats-title {
display: block;
font-size: 14px;
white-space: nowrap;
}

table.wp-list-table.plugins td.column-translation-stats .translation-stats-title p {
margin-top: 0;
}

table.wp-list-table.plugins td.column-translation-stats .translation-stats-title .tstats-update-link {
float: right;
}
Expand Down
5 changes: 4 additions & 1 deletion css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ table.wp-list-table.plugins { // WordPress Installed Plugins table.

.translation-stats-title {
display: block;
font-size: 14px;
white-space: nowrap;

p {
margin-top: 0;
}

.tstats-update-link {
float: right;

Expand Down
32 changes: 26 additions & 6 deletions includes/class-tstats-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ public function __construct() {
* Add Translation Stats settings debug tab.
*
* @since 0.9.0
*
* @return void
*/
public function tstats_settings_tab__debug() {
if ( TSTATS_DEBUG ) {
if ( defined( 'TSTATS_DEBUG' ) && TSTATS_DEBUG ) {
?>
<a class="nav-tab" href="#debug"><span class="dashicons dashicons-info"></span> <?php esc_html_e( 'Debug', 'translation-stats' ); ?></a>
<?php
Expand All @@ -92,9 +94,11 @@ public function tstats_settings_tab__debug() {
* Add Translation Stats settings debug content.
*
* @since 0.9.0
*
* @return void
*/
public function tstats_settings_content__debug() {
if ( TSTATS_DEBUG ) {
if ( defined( 'TSTATS_DEBUG' ) && TSTATS_DEBUG ) {
?>
<div id="tab-debug" class="tab-content hidden">
<?php
Expand All @@ -111,10 +115,12 @@ public function tstats_settings_content__debug() {
* Register Settings Page sections Debug.
*
* @since 0.9.0
*
* @return void
*/
public function tstats_settings_section__debug() {

if ( TSTATS_DEBUG ) {
if ( defined( 'TSTATS_DEBUG' ) && TSTATS_DEBUG ) {

add_settings_section(
'tstats_settings_advanced_debug', // String for use in the 'id' attribute of tags.
Expand All @@ -132,6 +138,8 @@ public function tstats_settings_section__debug() {
* Callback function for section "Debug".
*
* @since 0.8.0
*
* @return void
*/
public function tstats_settings_advanced_debug_callback() {

Expand All @@ -153,9 +161,11 @@ public function tstats_settings_advanced_debug_callback() {
* Display debug formated message with plugin options.
*
* @since 0.8.0
*
* @return void
*/
public function tstats_debug_info() {
if ( TSTATS_DEBUG ) {
if ( defined( 'TSTATS_DEBUG' ) && TSTATS_DEBUG ) {
?>
<br>
<div class="tstats-debug-block notice notice-alt inline notice-info">
Expand All @@ -178,6 +188,8 @@ public function tstats_debug_info() {
* Show the server debug info.
*
* @since 0.8.0
*
* @return void
*/
public function tstats_debug_info__server() {
?>
Expand Down Expand Up @@ -223,6 +235,8 @@ public function tstats_debug_info__server() {
* Show the site settings debug info.
*
* @since 0.8.0
*
* @return void
*/
public function tstats_debug_info__settings() {
// Get plugin settings.
Expand Down Expand Up @@ -304,6 +318,8 @@ public function tstats_debug_info__settings() {
* Show the site transients debug info.
*
* @since 0.8.0
*
* @return void
*/
public function tstats_debug_info__transients() {
?>
Expand Down Expand Up @@ -351,9 +367,11 @@ public function tstats_debug_info__transients() {
* @param string $field_id Setting ID.
* @param string $value Setting Value.
* @param string $default Setting Default.
*
* @return void
*/
public function tstats_debug_setting_field_info( $field_id, $value, $default ) {
if ( TSTATS_DEBUG ) {
if ( defined( 'TSTATS_DEBUG' ) && TSTATS_DEBUG ) {
?>
<div class="tstats-debug-block notice notice-alt inline notice-info">
<p>
Expand Down Expand Up @@ -397,9 +415,11 @@ public function tstats_debug_setting_field_info( $field_id, $value, $default ) {
* @param string $project_slug Plugin Slug..
* @param string $plugin_on_wporg Plugin exist on WP.org: True or false.
* @param string $plugin_translation_on_wporg Plugin translation project exist on WP.org: True or false.
*
* @return void
*/
public function tstats_settings_plugin_widget__debug( $project_slug, $plugin_on_wporg, $plugin_translation_on_wporg ) {
if ( TSTATS_DEBUG ) {
if ( defined( 'TSTATS_DEBUG' ) && TSTATS_DEBUG ) {
?>
<div class="tstats-debug-block notice notice-alt inline notice-info">
<p>
Expand Down
5 changes: 4 additions & 1 deletion includes/class-tstats-globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ public function tstats_translation_language() {
*
* @since 0.9.5
*
* @return bool Return true if Translation Stats language is 'en_US'.
* @return bool True if Translation Stats language is 'en_US', false otherwise.
*/
public function tstats_language_is_english() {

// Get Translation Stats language.
$tstats_language = $this->tstats_translation_language();

// Check if user locale is 'en_US'.
if ( 'en_US' === $tstats_language ) {
return true;
}

return false;
}


Expand Down
14 changes: 12 additions & 2 deletions includes/class-tstats-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function tstats_action_links( $links ) {
* @since 0.8.0
*
* @param string $hook Hook.
*
* @return void
*/
public function tstats_register_plugin_styles( $hook ) {

Expand All @@ -82,7 +84,7 @@ public function tstats_register_plugin_styles( $hook ) {
wp_register_style(
'translation-stats',
TSTATS_DIR_URL . 'css/admin.css',
false,
array(),
TSTATS_VERSION
);

Expand All @@ -98,13 +100,15 @@ public function tstats_register_plugin_styles( $hook ) {
* Register and enqueue Dark Mode style sheet.
*
* @since 0.8.0
*
* @return void
*/
public function tstats_register_plugin_styles_dark_mode() {

wp_register_style(
'translation-stats-dark-mode',
TSTATS_DIR_URL . 'css/admin-dark-mode.css',
false,
array(),
TSTATS_VERSION
);

Expand All @@ -118,6 +122,8 @@ public function tstats_register_plugin_styles_dark_mode() {
* @since 0.8.0
*
* @param string $hook Hook.
*
* @return void
*/
public function tstats_register_plugin_scripts( $hook ) {

Expand Down Expand Up @@ -216,6 +222,8 @@ public function tstats_register_plugin_scripts( $hook ) {
* @since 0.9.3
*
* @param string $hook Hook.
*
* @return bool Return true if current page is allowed, false if isn't allowed.
*/
public function tstats_allowed_pages( $hook ) {

Expand All @@ -224,6 +232,8 @@ public function tstats_allowed_pages( $hook ) {
return true;
}

return false;

}

}
Expand Down
2 changes: 2 additions & 0 deletions includes/class-tstats-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function __construct() {
* @since 0.9.5 Array with all the notice data.
*
* @param array $args Array of message data.
*
* @return void
*/
public function tstats_notice_message( $args ) {

Expand Down
44 changes: 29 additions & 15 deletions includes/class-tstats-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public function tstats_add_translation_stats_column( $columns ) {
*
* @param string $column_name Column Slug ( e.g. 'translation-stats' ).
* @param string $plugin_file Plugin ID ( e.g. 'slug/plugin-name.php' ).
*
* @return void
*/
public function tstats_render_plugin_stats_column( $column_name, $plugin_file ) {

Expand Down Expand Up @@ -159,6 +161,8 @@ public function tstats_render_plugin_stats_column( $column_name, $plugin_file )
* @since 0.8.0
*
* @param string $project_slug Plugin Slug.
*
* @return void
*/
public function tstats_render_plugin_stats( $project_slug ) {

Expand All @@ -172,6 +176,7 @@ public function tstats_render_plugin_stats( $project_slug ) {
?>

<div class="translation-stats-title">
<p>

<?php
// Add Translation Stats plugin widget title.
Expand All @@ -181,6 +186,7 @@ public function tstats_render_plugin_stats( $project_slug ) {
do_action( 'tstats_stats_plugin_widget_title__actions', $project_slug, $locale );
?>

</p>
</div>

<?php
Expand Down Expand Up @@ -217,6 +223,8 @@ public function tstats_render_plugin_stats( $project_slug ) {
*
* @param string $project_slug Plugin Slug.
* @param array $locale Locale array.
*
* @return void
*/
public function tstats_stats_plugin_widget_title( $project_slug, $locale ) {

Expand All @@ -238,18 +246,18 @@ public function tstats_stats_plugin_widget_title( $project_slug, $locale ) {
* Load plugin widget title update button.
*
* @since 0.9.4
*
* @return void
*/
public function tstats_plugin_update_button() {
?>

<div class="tstats-update-link">
<span class="tstats-update-link">
<button class="handlediv button-link tstats-update-button" type="button" aria-expanded="true">
<span class="dashicons dashicons-update"></span>
<span class="screen-reader-text"><?php esc_html_e( 'Update', 'translation-stats' ); ?></span>
</button>
</div>

<br><br>
</span>

<?php
}
Expand All @@ -259,6 +267,8 @@ public function tstats_plugin_update_button() {
* Load plugin widget loading placeholder.
*
* @since 0.9.4
*
* @return void
*/
public function tstats_stats_plugin_widget_content() {

Expand All @@ -278,6 +288,8 @@ public function tstats_stats_plugin_widget_content() {
* Load plugin widget content.
*
* @since 0.9.4
*
* @return void
*/
public function tstats_stats_plugin_widget_content_load() {

Expand Down Expand Up @@ -328,7 +340,9 @@ public function tstats_stats_plugin_widget_content_load() {
*
* @param string $project_slug Plugin Slug.
* @param array $locale Locale array.
* @param string $force_update True: Force get new stats. False: Use transients.
* @param bool $force_update True: Force get new stats. False: Use transients.
*
* @return void
*/
public function tstats_stats_plugin_widget_content_stats( $project_slug, $locale, $force_update ) {

Expand Down Expand Up @@ -407,16 +421,16 @@ public function tstats_stats_plugin_widget_content_stats( $project_slug, $locale
* @param string $project_slug Plugin Slug.
* @param string $subproject Translation subproject (' Dev', 'Dev Readme', 'Stable', 'Stable Readme' ).
* @param string $subproject_slug Translation subproject Slug ( 'dev', 'dev-readme', 'stable', 'stable-readme' ).
* @param string $force_update True: Force get new stats. False: Use transients.
* @param bool $force_update True: Force get new stats. False: Use transients.
*
* @return array $stats_bar Subproject stats bar and error boolean.
* @return array|null $stats_bar Subproject stats bar and error boolean.
*/
public function tstats_render_stats_bar( $locale, $project_slug, $subproject, $subproject_slug, $force_update ) {

$options = get_option( TSTATS_WP_OPTION );
// Show bar only if subproject is enabled in plugin settings.
if ( empty( $options[ $project_slug ][ $subproject_slug ] ) ) {
return;
return null;
}

$stats_bar_link = 'https://translate.wordpress.org/projects/wp-plugins/' . $project_slug . '/' . $subproject_slug . '/' . $locale['slug']['locale'] . '/' . $locale['slug']['variant'];
Expand All @@ -425,7 +439,7 @@ public function tstats_render_stats_bar( $locale, $project_slug, $subproject, $s
$translation_stats = $this->tstats_plugin_subproject_stats( $locale, $project_slug, $subproject_slug, $force_update );

// Initializing variable.
$percent_translated = '';
$percent_translated = 0;

// If translation stats are not an object, project not found.
if ( ! is_object( $translation_stats ) ) {
Expand Down Expand Up @@ -507,16 +521,16 @@ public function tstats_render_stats_bar( $locale, $project_slug, $subproject, $s


/**
* Render plugin subproject stat bar.
* Render plugin subproject stats bar.
*
* @since 0.8.0
*
* @param array $locale Locale array.
* @param string $project_slug Plugin Slug.
* @param string $subproject_slug Translation subproject Slug ( 'dev', 'dev-readme', 'stable', 'stable-readme' ).
* @param string $force_update True: Force get new stats. False: Use transients.
* @param array $locale Locale array.
* @param string $project_slug Plugin Slug.
* @param string $subproject_slug Translation subproject Slug ( 'dev', 'dev-readme', 'stable', 'stable-readme' ).
* @param bool $force_update True: Force get new stats. False: Use transients.
*
* @return string $translation_stats Plugin stats.
* @return object|bool Project stats if exist, otherwise returns 'false'.
*/
public function tstats_plugin_subproject_stats( $locale, $project_slug, $subproject_slug, $force_update ) {

Expand Down
Loading

0 comments on commit 66bf2e0

Please sign in to comment.