Skip to content

Commit

Permalink
Improve template arguments customization
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-mendonca committed Oct 1, 2024
1 parent 1a47298 commit ebcba3c
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions includes/class-toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,14 @@ public static function register_plugin_scripts( $template, &$args, $dependencies
$script_id,
'gpToolbox',
array(
'admin' => self::current_user_is_glotpress_admin(), // GlotPress Admin with manage options capability.
'gp_url' => gp_url(), // GlotPress base URL. Defaults to /glotpress/.
'gp_url_project' => gp_url_project(), // GlotPress projects base URL. Defaults to /glotpress/projects/.
'nonce' => wp_create_nonce( 'wp_rest' ), // Authenticate in the Rest API.
'args' => ! is_null( $args ) ? self::{'template_args_' . $template}( $args ) : null, // Template arguments.
'supported_statuses' => self::supported_translation_statuses(), // Supported translation statuses.
'user_locale' => GP_locales::by_field( 'wp_locale', get_user_locale() ), // Current user Locale.
'user_login' => wp_get_current_user()->user_login, // Current user login (username).
'admin' => self::current_user_is_glotpress_admin(), // GlotPress Admin with manage options capability.
'gp_url' => gp_url(), // GlotPress base URL. Defaults to /glotpress/.
'gp_url_project' => gp_url_project(), // GlotPress projects base URL. Defaults to /glotpress/projects/.
'nonce' => wp_create_nonce( 'wp_rest' ), // Authenticate in the Rest API.
'args' => ! is_null( $args ) ? self::template_args( $template, $args ) : null, // Template arguments.
'supported_statuses' => self::supported_translation_statuses(), // Supported translation statuses.
'user_locale' => GP_locales::by_field( 'wp_locale', get_user_locale() ), // Current user Locale.
'user_login' => wp_get_current_user()->user_login, // Current user login (username).
/**
* Filters wether to color highlight or not the translation stats counts of the translation sets on the project page.
*
Expand All @@ -509,44 +509,52 @@ public static function register_plugin_scripts( $template, &$args, $dependencies


/**
* Project template arguments.
* Get template arguments.
*
* @since 1.0.0
* @since 1.0.6
*
* @param array<string, mixed> $args GlotPress template arguments.
* @param string $template The template name.
* @param array<string, mixed> $args GlotPress template arguments.
*
* @return array<string, mixed> Array of template arguments.
*/
public static function template_args_project( array $args ) {

$result = array();
public static function template_args( $template, array $args ) {

$result['project'] = $args['project'];
switch ( $template ) {
// Project template.
case 'project':
// Customize template arguments for Project.
return self::template_args_project( $args );

if ( is_array( $args['translation_sets'] ) ) {
foreach ( $args['translation_sets'] as $translation_set ) {
$result['translation_sets'][ $translation_set->locale ] = $translation_set;
}
default:
// Return the arguments unchanged.
return $args;
}

// Return Project and Translation Sets.
return $result;
}


/**
* Tools template arguments.
* Project template arguments.
*
* @since 1.0.0
*
* @param array<string, mixed> $args GlotPress template arguments.
*
* @return array<string, mixed> Array of template arguments.
*/
public static function template_args_tools( array $args ) {
public static function template_args_project( array $args ) {

$result = $args;
$result = array();

$result['project'] = $args['project'];

if ( is_array( $args['translation_sets'] ) ) {
foreach ( $args['translation_sets'] as $translation_set ) {
$result['translation_sets'][ $translation_set->locale ] = $translation_set;
}
}

// Return Project and Translation Sets.
return $result;
}

Expand Down

0 comments on commit ebcba3c

Please sign in to comment.