[resolved] get_allowed_themes() (3 posts)

  1. pescadito01
    Posted 6 years ago #


    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

  2. David Sader
    Posted 6 years ago #

    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.

    $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>';
    echo '</pre>';
  3. pescadito01
    Posted 6 years ago #

    Thanks, It works very well!

    You can close the ticket.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.