Support » Plugin: Attachments » Class 'Attachments' not found

  • Resolved alex27



    I have the following problem – I installed Attachements plugin, attached file to post and added your code snippet to content-single.php (theme Twentyeleven). But when I go to see this post, I get the following error message:
    Fatal error: Class 'Attachments' not found in ...\wp-content\themes\twentyeleven\content-single.php on line 24

    What am I doing wrong? Should I modify something in your code snippet, or should it work out of the box.

Viewing 15 replies - 1 through 15 (of 20 total)
  • Same problem here. Any thoughts!!

    Same problem
    Thanks for the work on the update / upgrade btw

    If you are using Attachments 3.0 on a version of WordPress before 3.5 (scheduled to be released soon), then you will need to use the old syntax for pulling attachments into your templates. Doesn’t look like the docs were added for that but I’ll submit a patch. Here is the old syntax for you to use:

    <div id="attachments">
        $attachments = attachments_get_attachments();
        $total_attachments = count( $attachments );
        if( $total_attachments > 0 ) : ?>
                <?php for( $i=0; $i < $total_attachments; $i++ ) : ?>
                        <h3><?php echo $attachments[ $i ]['title']; ?></h3>
                        <p><?php echo $attachments[ $i ]['caption']; ?></p>
                        <p><small>Attachment ID: <?php echo $attachments[ $i ]['id']; ?></small></p>
                        <p><code><?php echo $attachments[ $i ]['location']; ?></code></p>
                        <p><?php echo $attachments[ $i ]['mime']; ?></p>
                <?php endfor; ?>
        <?php endif; ?>

    When WordPress 3.5 comes out, you will be able to use the new syntax.

    Thanks for a prompt reply

    Thank you!

    I upgraded to 3.5m but the new Attachments (‘attachments’) does not work. is there an include that we should do?

    Did you integrate Attachments to your site pre-Attachments 3.0 and pre-WordPress 3.5? You will most likely need to migrate your data to the new format but it looks like that may not be available yet.

    You can enable “legacy mode” for now until you can migrate. Check out how to enable “legacy mode” here:

    No. Just found and installed this awesome plugin a few minutes ago (Post 3.5 upgrade and post Attachments 3.0)

    What error is it giving you? Do you have debugging enabled for PHP errors?

    Just stepped through code. The plugin checks for

    version_compare( $wp_version, '3.5', '<=' )

    Get rid of the equal sign…

    I just submitted a pull request to the plugin author. Thanks for the heads up!

    There may be some other issues. I’m getting some odd results using the Attachments class vs. using the legacy code.

    Legacy code works fine.

    new Attachments does not.

    Hmm, I’m actually seeing some issues as well. I’ll see if I can solve any of these issues and submit a pull request. If you feel so inclined to do the same, go ahead! 🙂

    I think that I will stick with legacy mode for now. Once you get rid of the equals sign, and thus enter “modern” mode, there are other issues.

    For example, the “attach” section of the post edit form does not seem to actually attach anything to the post.

    Video Showing the Bug

    Indeed. I am stepping through the code as well. Hopefully we can zero in on it tonight…though my remote xdebug absolutely HATES working with PHP classes.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Class 'Attachments' not found’ is closed to new replies.