diff --git a/includes/class-toolbox.php b/includes/class-toolbox.php index 799027e..6648e40 100644 --- a/includes/class-toolbox.php +++ b/includes/class-toolbox.php @@ -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. * @@ -509,33 +509,32 @@ 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 $args GlotPress template arguments. + * @param string $template The template name. + * @param array $args GlotPress template arguments. * * @return array 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 * @@ -543,10 +542,19 @@ public static function template_args_project( array $args ) { * * @return array 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; }