Last active
April 6, 2017 05:24
-
-
Save maheshwaghmare/062ef98b5e2085703d7409f4e358d2b1 to your computer and use it in GitHub Desktop.
Get WordPress theme details which are hosted on wordpress.org though API call
This file contains hidden or 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 | |
| /** | |
| * Get wordpress.org Theme Details | |
| * | |
| * @see https://codex.wordpress.org/WordPress.org_API#Themes | |
| */ | |
| /** | |
| * Show Theme Details | |
| * | |
| * @param $theme_slug string Slug of the theme of wordpress.org | |
| * @return void | |
| */ | |
| function wp_theme_details( $theme_slug = 'twentyseventeen' ) { | |
| // Fire request. | |
| $request = wp_remote_get( 'https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=' . $theme_slug ); | |
| if( is_wp_error( $request ) ) { | |
| echo 'Error!'; | |
| } | |
| // Get body content. | |
| $body = wp_remote_retrieve_body( $request ); | |
| $theme_details = json_decode( $body ); | |
| // Print Details. | |
| echo '<pre>'; | |
| print_r( $theme_details ); | |
| echo '</pre>'; | |
| } | |
| // Function call. | |
| wp_theme_details( 'twentyseventeen' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment