-1

I'm trying to fetch language packs for multiple themes in bulk using the following WordPress Themes API endpoint:

https://api.wordpress.org/themes/info/1.1/?action=query_themes&request[fields][language_packs]=1

However, this does not return the language_packs field as expected.

Interestingly, the same structure works perfectly for plugins using the WordPress Plugins API:

https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[fields][language_packs]=1

I am aware that the following endpoint can fetch translations for a single theme:

https://api.wordpress.org/translations/themes/1.0/?slug={slug}&version={theme-version}

However, I need to fetch language packs for multiple themes in bulk, and the above URL only supports a single theme per request.

I checked the WordPress code and found the language_packs parameter is explicitly available for plugins but couldn't find a similar parameter for themes.

Question:

Is there a way to retrieve language_packs for multiple themes in bulk via the WordPress API? Or am I missing some parameter or method to get this data for themes, similar to how it works for plugins?

1 Answer 1

0

There is no way to do that, but as an alternative, you can call that api in loop along with theme parameter as per your need. Here is the sample code for your reference.

$themes = json_decode( file_get_contents( 'https://api.wordpress.org/themes/info/1.1/?action=query_themes' ), true );

$language_packs = [];
foreach ( $themes['themes'] as $theme ) {
    $slug            = $theme['slug'];
    $version         = $theme['version'];     
   $translation_info = json_decode( file_get_contents( "https://api.wordpress.org/translations/themes/1.0/?slug={$slug}&version={$version}" ), true );
    
    if ( isset( $translation_info['translations'] ) ) {
        $language_packs[$slug] = $translation_info[ 'translations' ];
    }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.