WordPress.org

Ready to get started?Download WordPress

Forums

Attachments
[resolved] Class 'Attachments' not found (21 posts)

  1. alex27
    Member
    Posted 1 year ago #

    Hello!

    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.

    http://wordpress.org/extend/plugins/attachments/

  2. illuminatus7
    Member
    Posted 1 year ago #

    Same problem here. Any thoughts!!

  3. Graham Stacey
    Member
    Posted 1 year ago #

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

  4. JR Tashjian
    Member
    Posted 1 year ago #

    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">
        <?php
        $attachments = attachments_get_attachments();
        $total_attachments = count( $attachments );
        if( $total_attachments > 0 ) : ?>
            <ol>
                <?php for( $i=0; $i < $total_attachments; $i++ ) : ?>
                    <li>
                        <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>
                    </li>
                <?php endfor; ?>
            </ol>
        <?php endif; ?>
    </div>

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

  5. Graham Stacey
    Member
    Posted 1 year ago #

    Thanks for a prompt reply

  6. alex27
    Member
    Posted 1 year ago #

    Thank you!

  7. mitchell360
    Member
    Posted 1 year ago #

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

  8. JR Tashjian
    Member
    Posted 1 year ago #

    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: https://github.com/jchristopher/attachments#upgrade-notice

  9. mitchell360
    Member
    Posted 1 year ago #

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

  10. JR Tashjian
    Member
    Posted 1 year ago #

    What error is it giving you? Do you have debugging enabled for PHP errors?
    http://codex.wordpress.org/Debugging_in_WordPress#WP_DEBUG

  11. mitchell360
    Member
    Posted 1 year ago #

    Just stepped through code. The plugin checks for

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

    Get rid of the equal sign...

  12. JR Tashjian
    Member
    Posted 1 year ago #

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

  13. mitchell360
    Member
    Posted 1 year ago #

    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.

  14. JR Tashjian
    Member
    Posted 1 year ago #

    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! :)

  15. mitchell360
    Member
    Posted 1 year ago #

    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

  16. mitchell360
    Member
    Posted 1 year ago #

    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.

  17. JR Tashjian
    Member
    Posted 1 year ago #

    Ok, it looks like the major issue is the code sync between Git and SVN. Download the latest from Github for now, it works: https://github.com/jchristopher/attachments

  18. mitchell360
    Member
    Posted 1 year ago #

    Edit works ... but getting the attachments was still broken. Seems to be a null check in the get_attachments function.

    Here is the fix (line 970-ish in class.attachments.php)

    function get_attachments( $instance = '', $post_id = null )
            {
                global $post;
    
    			if (is_null($post_id))
    			{
    				if( is_null( $post_id ) && is_object( $post ) && isset( $post->ID ) )
    				{
    					$post_id = $post->ID;
    				}
    				elseif( isset( $_GET['post'] ) )
    				{
    					$post_id = intval( $_GET['post'] );
    				}
    				else
    				{
    					// no post ID, nothing to do...
    					return;
    				}
    			}
  19. mitchell360
    Member
    Posted 1 year ago #

    I think that last fix will do the trick ... glad we got this resolved!

  20. JR Tashjian
    Member
    Posted 1 year ago #

    Attachments 3.0.1 was just pushed. Update the plugin and see if you still run into issues. You will most likely need to clear your browser's cache and cookies: http://support.wordpress.com/browser-issues/#clear-your-cache-and-cookies

  21. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Hey guys so sorry for these issues. JR helped me discover that I completely borked the sync from git to svn before committing. Everything should be ironed out in 3.0.1.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic