Plugin Request: Theme Showcase w/ Supporter

0

I like the concept of the ThemeBrowser plugtin. It allows you to showcase the themes you offer on your site with thumbnails inserted via shortcode. Very cool.

This makes a lot of sense as someone thinking of signing up to blog would probably want to see their theme choices first.

But it doesn’t show “Supporter-Only” themes.

It would be great to be able to showcase on a page both the free and “supporter” themes.

  • Aaron
    • Ex Staff

    You just need to add to the available themes list in the same way supporter-themes.php does in the filter.

    Right after they populate a variable with themes $allowed_themes then you merge ours into the array:

    $supporter_allowed_themes = get_site_option( "supporter_themes" );
    if( is_array( $supporter_allowed_themes ) && is_supporter())
    $allowed_themes = array_merge( $allowed_themes, $supporter_allowed_themes );

  • dubya
    • The Incredible Code Injector

    Thanks Aaron.

    I’m just having one small problem with this… The supporter themes are being listed twice, once as a regular theme (although they are disabled as per the supporter plugin) and then once again with my added code. I suspect it is due to merging the arrays. Any advice?

    Here’s a snippet”

    function themebrowser_shortcode() {

    // get all themes

    $themes = get_themes();

    $allowed_themes = "";

    // get allowed themes for WPMU

    if ( function_exists( "get_site_option" ) ) {

    $allowed_themes = get_site_option( 'allowedthemes' );

    $supporter_allowed_themes = get_site_option( "supporter_themes" );

    if( is_array( $supporter_allowed_themes ) && is_supporter())

    $allowed_themes = array_merge( $allowed_themes, $supporter_allowed_themes );

    }

    // loop themes

    foreach( $themes as $theme ) {

    // check the themes is allowed, and it has a screenshot

    if ( $theme["Screenshot"] != "" && ( $allowed_themes == "" || isset( $allowed_themes[ wp_specialchars( $theme ) ] ) == true ) ) {

    // echo the details

    echo '

    <h3 style="clear:left;">' . $theme["Title"] . ' by ' . $theme["Author"] . '</h3>

    <p><img src="' . $theme["Theme Root URI"] . "/" . $theme["Template"] . "/" . $theme["Screenshot"] . '" alt="' . $theme["Title"] . '" style="float: left; margin: 0 1em 1em 0;" width="300px" /> ' . $theme["Description"] . '</p>

    ';

    }

    // check the themes is PREMIUM, and it has a screenshot

    if ( $theme["Screenshot"] != "" && ( $supporter_allowed_themes == "" || isset( $supporter_allowed_themes[ wp_specialchars( $theme ) ] ) == true ) ) {

    // echo the details

    echo '

    <h3 style="clear:left;">' . $theme["Title"] . ' by ' . $theme["Author"] . '
    ' . ' - This Premium Theme is available to SUPPORTERS ONLY' . '</h3>

    <p><img src="' . $theme["Theme Root URI"] . "/" . $theme["Template"] . "/" . $theme["Screenshot"] . '" alt="' . $theme["Title"] . '" style="float: left; margin: 0 1em 1em 0;" width="300px" /> ' . $theme["Description"] . '</p>

    ';

    }

    }

  • dubya
    • The Incredible Code Injector

    Haha!

    I got it all on my own, but when I came back here, you had already posted.

    I was mistakenly thinking that the 1st line in your post above was needed.

    Thanks for kicking me in the right direction. I’ve attached the end result for anyone that’s interested. Just rename the extension to .php and tweek the HTML output to your liking.

    Thanks again Aaron.

  • dubya
    • The Incredible Code Injector

    Well, it says I can upload a txt file. Guess not. Here’s the full code:

    <?php
    /*
    Plugin Name: Theme Browser
    Plugin URI: http://www.stillbreathing.co.uk/projects/themebrowser/
    Description: Shows the list of installed themes in your site
    Version: 0.2
    Author: Chris Taylor
    Author URI: http://www.stillbreathing.co.uk
    */

    require_once( "plugin-register.class.php" );
    $register = new Plugin_Register();
    $register->file = __FILE__;
    $register->slug = "themebrowser";
    $register->name = "Theme Browser";
    $register->version = "0.2";
    $register->developer = "Chris Taylor";
    $register->homepage = "http://www.stillbreathing.co.uk";

    // setup shortcodes
    // [themebrowser]
    add_shortcode( 'themebrowser', 'themebrowser_shortcode' );

    function themebrowser_shortcode() {
    // get all themes
    $themes = get_themes();
    $allowed_themes = "";
    // get allowed themes for WPMU
    if ( function_exists( "get_site_option" ) ) {
    $allowed_themes = get_site_option( 'allowedthemes' );
    $supporter_allowed_themes = get_site_option( "supporter_themes" );

    }
    // loop themes
    foreach( $themes as $theme ) {
    // check the themes is allowed, and it has a screenshot
    if ( $theme["Screenshot"] != "" && ( $allowed_themes == "" || isset( $allowed_themes[ wp_specialchars( $theme['Stylesheet'] ) ] ) == true ) ) {
    // echo the details
    echo '
    <h3 style="clear:left;">' . $theme["Title"] . ' by ' . $theme["Author"] . '</h3>
    <p><img src="' . $theme["Theme Root URI"] . "/" . $theme["Template"] . "/" . $theme["Screenshot"] . '" alt="' . $theme["Title"] . '" style="float: left; margin: 0 1em 1em 0;" width="300px" /> ' . $theme["Description"] . '</p>
    ';
    }
    // check the themes is PREMIUM, and it has a screenshot
    if ( $theme["Screenshot"] != "" && ( $supporter_allowed_themes == "" || isset( $supporter_allowed_themes[ wp_specialchars( $theme['Stylesheet'] ) ] ) == true ) ) {
    // echo the details
    echo '
    <h3 style="clear:left;">' . $theme["Title"] . ' by ' . $theme["Author"] . '<br />' . ' - This Premium Theme is available to SUPPORTERS ONLY' . '</h3>
    <p><img src="' . $theme["Theme Root URI"] . "/" . $theme["Template"] . "/" . $theme["Screenshot"] . '" alt="' . $theme["Title"] . '" style="float: left; margin: 0 1em 1em 0;" width="300px" /> ' . $theme["Description"] . '</p>
    ';
    }
    }
    }
    ?>