• Resolved pescadito01

    (@pescadito01)


    Hi

    in a multisite wp 30, i want to get the enabled themes of one blog but get_themes() push me all the installed themes.

    instead of this i tried to use get_allowed_themes() as defined in /wp-admin/themes.php but it return me Fatal error: Call to undefined function get_allowed_themes()

    what i need to properly call this functions inside my code?

    best regard, pescadito

Viewing 2 replies - 1 through 2 (of 2 total)
  • Unless you are on an admin page, those theme page admin functions(wp-admin/includes/theme.php) aren’t included.

    So filter your $themes array “manually” then. Something like the following example will/should echo out a list of blog allowed themes in a sidebar.php.

    <?php
    $themes = get_themes();
    
    $allowed_themes = apply_filters("allowed_themes", get_site_option( 'allowedthemes' ) );
    
    if( $allowed_themes == false )
    	$allowed_themes = array();
    
    $blog_allowed_themes = get_option( 'allowedthemes' );
    	if ( is_array( $blog_allowed_themes ) )
    		$allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
    reset( $themes );
    
    foreach( $themes as $key => $theme ) {
        if( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) {
    		unset( $themes[ $key ] );
        }
    }
    reset( $themes );
    
    // Do whatever you like with the $themes array
    
    echo '<pre>';
    print_r($themes);
    echo '</pre>';
    ?>
    Thread Starter pescadito01

    (@pescadito01)

    Thanks, It works very well!

    You can close the ticket.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_allowed_themes()’ is closed to new replies.