Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Dave Davis
Dave Davis
1,837 Points

Wordpress plugin to add a playlist after content not working at all...

I've used Pluginception to create a plugin to append a playlist containing attached music to a the_content of the current post by default. I'm struggling with making Easy Digital Downloads Frontend Submissions forms work for me, and this is a solution for the 80/20 issue (the 20% of features needed that require custom work!). ;)

Starting from a script from Pippin @Pippinsplugin - https://pippinsplugins.com/playing-nice-with-the-content-filter/ I wound up with the code below, but unfortunately it doesn't seem to work when run. It doesn't blow anything up either, which is good I suppose...

It's a relatively small, simple plug to do a simple task. But it doesn't work. :(

function download_show_playlist( $content ) { global $post; if( is_singular() && is_main_query() && $post->post_type === 'download' ) { $download = new EDD_Download( $post->ID ); $files = $download->get_files( ); $submission_attachment_ids = ''; if ( is_array( $files ) ){ $first = true; foreach ( $files as $key => $value ) { if ( !isset( $value[ 'attachment_id' ] ) ){ continue; } if ( $first ){ $submission_attachment_ids .= $value[ 'attachment_id' ]; $first = false; } else { $submission_attachment_ids .= ',' . $value[ 'attachment_id' ]; } } } else { return $content; // no files attached to the download }

        if ( !$submission_attachment_ids || strlen( $submission_attachment_ids ) < 1 ) {
            return $content; // no files attached to the download
        }

        $new_content = '[playlist ids="' . $submission_attachment_ids . '"]';
        $content .= $new_content;
    }   
    return $content;
}
add_filter( 'the_content', 'download_show_playlist' );