Coder Social home page Coder Social logo

jchristopher / attachments Goto Github PK

View Code? Open in Web Editor NEW
241.0 241.0 78.0 3.51 MB

[WordPress Plugin] Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types

Home Page: wordpress.org/extend/plugins/attachments/

License: GNU General Public License v2.0

PHP 72.34% CSS 4.20% JavaScript 23.46%

attachments's People

Contributors

bessl avatar bluefish6 avatar builtbylane avatar cpommiss avatar dhunink avatar eniefac avatar hasinhayder avatar jchristopher avatar joostdekeijzer avatar jrtashjian avatar kasparsj avatar kokareff avatar mleczakm avatar ore4444 avatar studioanino avatar stuk88 avatar tcoukoulis avatar wunc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

attachments's Issues

Changing 'Delete' to 'Remove'

I wanted to propose that you change 'Delete' to 'Remove' since the file itself is not actually deleted from the media library. I understand that the meta-data will be deleted, but I still think 'Remove' would be more accurate. Thanks for the plugin

Attachment recognized but output breaks theme page

Hi,

I've registered a new instance named "my_attachments" and inside my theme, inside The Loop, i've placed this code:

                    <li class="project">
            <div class="project-content">
                <h2><?php the_title(); ?></h2>
                <?php the_content(); ?>
            </div>
            <div class="project-imgs">
                <?php 
                $project_attachments = new Attachments( 'my_attachments' ); 
                if( $project_attachments->exist() ) {
                    while( $attachment = $project_attachments->get() ) {
                        echo $attachment->url();
                    }
                }
                ?>
            </div>
        </li>

Not only it does not give any output the whole page stops after this. I've tried echoing all the attachment's data. The only thing that works is the print_r( $attachment ). If I just echo something like 'inside while loop' it works as well.

Any idea about what can be happening?

Thanks a lot

Only Show Attachment Fields for Certain Page(s)?

I was wondering if it was possible to get attachment fields to only show up on certain pages in the backend. For example, if I had a page called "Music" and I wanted an mp3 attachment field to appear for that page, but on no other page.

Thanks in advance.

Suggestion: in function search, if $query is null, make the attachment $valid (don't do a search)

Hello again,

I'm using the Plugin to attach Resources to each Post. Then, I have a page called Resources, where I want to list all the resources from all the posts. So basically this could be a function called get_all, or also a search with $query = null.

I changed your code into this later option. I'll show my changes, if you agree I hope they can be commited.

In class.attachments.php, function search, where it says (in 2 places):

if( strpos( strtolower( $potential_attachments[$i]->fields->$field ), strtolower( $query ) ) !== false ) // does the value match?

I changed by adding !$query || inside the condition:

if( !$query || strpos( strtolower( $potential_attachments[$i]->fields->$field ), strtolower( $query ) ) !== false ) // does the value match?

Cheers,
Leo

Can't figure out how to migrate?

Maybe I'm missing something... I have a WP site making extensive use of the old 2.4.8.2 version of code. I installed the new Attachments upgrade and have updated all of the old template code. Nowhere do I get any options for migrating over old content (nothing under Settings, nowhere). Since I have a LOT of assets associated with the old version, I really don't want to have to manually move these over. Is there some kind of naming convention with defining the new attachments setup in the functions.php file that maps this to old data? Any suggestions? Thanks!

Paged attachments

Hi,
I created custom post template (single-album.php) where I display all attachment's images.
How can I limit images display number and create navigation?

thank you

Wordpress support thread has fix for

Check out http://wordpress.org/support/topic/class-attachments-not-found?replies=19#post-3551177

I found a bug and suggested a fix for class.attachments.php (line 970-ish).

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;
            }
        }

Invalid argument supplied for foreach() in query.php

Hi,
I get a warning message when I activate attachments:

Invalid argument supplied for foreach() in <b>/www/htdocs/w0002c/wp-includes/query.php</b> on line <b>1702</b>

I did some troubleshooting and the error is caused by the $this->check_for_legacy_data() function in attachments\classes\class.attachments.php.

I think the problem is caused by the $post_types array (which is empty) and the query:

$legacy         = new WP_Query( $args );

triggers the error. Maybe you can add a "return" before the query starts if the $post_types is empty?

Migration documentation - mention legacy version is included in newer version

Hi there,

I was trying to figure out when upgrading to Wordpress 3.5.1 from 3.4.X the best way to go about updating the Attachments plugin as we're still using the older 1.6.2.1 version.

In the readme.md under Upgrade Notice, it wasn't clear to me that the older version was actually bundled with the newer version. Could you update the documentation to mention that fact?

eg. something like:

"Version 1.x of Attachments has been fully deprecated but is still available and included in the current Attachments 3 plugin. If you would like to continue to use the (no longer supported) 1.x version you may activate it by adding the following to your wp-config.php"

Also, the description toward the top of the readme could be updated as well:

"If you are not running WordPress 3.5, the legacy version 1.6.2.1 bundled with the Attachments 3 plugin will be used in older installs until you upgrade to WordPress 3.5."

Thanks for the great plugin!

attachments->get() wont work on custom post type

Untitled-1
Untitled-2

I'm inside the loop and the_title(), the_content() and everything works fine.
I've added this to functions to get the options when I edit my custom post.

// all post types to utilize (string|array)
'post_type' => array( 'post', 'job_seeker' ),

My pure php code on single.php

get() ) : ?>
                     <?php echo $attachments->url(); ?>"><?php echo $attachments->field( 'title' ); ?> (<?php echo $attachments->type(); ?>, <?php echo $attachments->filesize(); ?>)
                    <?php endwhile; ?>

Attachments error

My entire wordpress website wont show anymore.
I installed attachments, i followed the instruction on how to revert it back to the v1 by adding define attachments legacy, true. in my wp-config..

I made a backup of my config file before changing it, and now my entire website won't show?? Even when i re-upload the backup file, nothing.

I've spent the past 3 weeks building this website, can somebody please help me?

filter by type()

Jonathan,

I see you have a userhelp tag so I hope its ok to post support requests here. Im trying complete a function to return attachment X of an explicit type but have found that type is returning empty:

function tr_postThumb(){
     $id = get_the_ID();
        $attachments = new Attachments( 'attachments', $id );
        if( $attachments->exist() ){
            if ( $attachment = $attachments->get() ){
                if($attachments->type()==""){ // image - but type() returns empty.
                        echo "<pre>";
                        //print_r($attachments);
                        echo $attachments->type(). "<br />";
                        echo $attachments->id(). "<br />";
                        echo $attachments->subtype(). "<br />";
                        echo $attachments->url(). "<br />";
                        echo "</pre>";
                        $tr_post_thumb = $attachments->image( 'thumbnail' );
                }
            }
    }
}

What am I doing wrong here? I would ultimately like to implement get_single and specify it as well, but need to reduce the results to a particular mime type first.

Thanks for all the hard work you've put into this, it really shows.

Captions are missing on website but present in wp-admin

I have a very simple custom theme that uses the attachments plugin to attach a number of images to custom posts. I used to have the website hidden on a develop domain, now i put it online on a new hosting and domain name but the captions seem to be missing. The website is: http://wouterleduc.com/?wp_photoproject=two-crows
the captions should be below the popupped images.
Untitled-2

Let me know whatever information you need, i'll be glad to provide them.

Thanks for the help,
RAoul

PO file name and path for translating the Attachments plugin

Hi Jonathan.

I'm trying to translate to spanish your plugin, but I don't know which name must have the PO file nor where to place it. I've tried creating it as .../wp-content/plugins/attachments/languages/attachments-es_ES.po and .../wp-content/plugins/attachments/languages/default-es_ES.po , but nothing happened. I can't find the load_plugin_textdomain call in your not deprecated plugin version.

Can you help me? I'll send you my translation when it's done, of course!

Plugin conflict - Custom Field Suite

I was working on a site that hadn't got updated for a while and after updating there is a conflict between Attachments and Custom Field Suite (http://wordpress.org/extend/plugins/custom-field-suite/). Previously the site was using Attachments 1 and an earlier version of CFS - but since the update skipped a number of versions, I don't know quite when the conflict started.

The conflict is described here http://uproot.us/forums/questions/1239/possible-plugin-conflict/ - and I'm not really sure if it's Attachments tripping up or CFS, but I thought I'd post about it here, in case anyone else has come across an issue with these two plugins.

Allow searching within Attachments

I'm not sure if this is an Attachments feature or a seperate plugin that could sit between the WP Media Framework and all other plugins that deal with Media.

Would be great for WP to read a file when uploaded (PDFs, DOCs etc) and store a plain text index of what's in the file so that if people use Wordpress search, these attachments appear in the results.

Not sure if this is even possible...

Attaching something on a custom post type.

I am using WordPress 3.5 MU install

I use a MU install for test sites I am working on before I push them live, Attachments was not showing up on the portfolio custom post type. So I follow the following steps.

I disable the default instance by adding the recommended line to my wp-config.php.

Then I added the listed function to my functions.php

It now shows up fine in my custom post type, but when I click on Attach Files and then select an item and click Attach. it will close the window but not show up in the Attachments meta. Tried to update the post and refresh still doesn't show up. I would be more then happy to offer any of my resources to try and figure out the issue.

Can't edit the meta fields in firefox

Hello,

I'm having a weird problem, when I'm working on my Windows 7 desktop I can't edit the meta fields of the attachement when I'm using the latest version of Mozilla Firefox but I can edit them when I'm using Google Chrome. Is this a known issue?

Regards Niels.

Ability to get a single attachment

Would be nice to be able to get a single attachment. Currently, can get the first attachment using $attachment->get() but would like to get individual attachments. To work with the existing class code, the ability to set attachments_ref would probably work.

Something like the following might work…

function get($reference = null)
{
    if (is_numeric($reference)) {
        if( !count( $this->attachments ) || empty($this->attachments[$reference]) )
            return false;

        return $this->attachments[$reference];
    }
    else {
        $this->attachments_ref++;

        if( !count( $this->attachments ) || $this->attachments_ref >= count( $this->attachments ) )
            return false;

        return $this->attachments[$this->attachments_ref];
    }
}

WP Media manager shows uploads via 'Attachments' but not the other way around.

Two in one day - I know, sorry!

I was surprised to see media uploaded via the 'Attachments' plugin, turn up in the WP interface, and also returned by get_children() –– was that always the case? I'd been working on the assumption that these were separate entities.

Other then having to re-jig the way im handeling attachments, it becomes a client training issue. If the systems were reciprocal then it would be relatively easy to explain, other wise you have to really stress the differences between the two systems. I can and probably will ultimately make the 'Add Media' button disappear of course, but WP's new system has its merits.

I feel there would be some merit to making the relationship reciprocal, ie attachments to the post appear in both systems regardless of how it was attached -- or keep them as separate data sets -- or have some control over how that line is drawn.

Many thanks --

README.md typo?

Think I've caught a small typo

line 209 in README.md reads:

$fields => array(

should be:

$fields = array(

I'd do a pull request but Im just not confident with git yet.

Suggestion: add possibility to filter / search by mime_type

Hello once again :)

In that page Resources I have listing all resources (attachments) from all posts, I want to filter by file type (video, audio, application, image, etc). I think it makes sense to add this in the search.

I added some changes, again if you agree I hope they can be committed.

  • added 'filetypes' in $defaults in search():
$defaults = array(
        'attachment_id' => null,            // not searching for a single attachment ID
        'instance'      => 'attachments',   // default instance
        'post_type'     => null,            // search 'any' post type
        'post_id'       => null,            // searching all posts
        'post_status'   => 'publish',       // search only published posts
        'fields'        => null,            // search all fields
        'filetypes'     => null             // Added filetypes support
    );
  • convert to array
if( is_string( $params['filetypes'] ) )
    $params['filetypes']       = array( $params['filetypes'] );   // we always want an array
  • added new function get_mime_type($id): code copied from function type()
function get_mime_type($id)
{
    $attachment_mime = explode( '/', get_post_mime_type( $id ) );
    return isset( $attachment_mime[0] ) ? $attachment_mime[0] : false;
}  
  • changed from (2 places):
if( strpos( strtolower( $potential_attachments[$i]->fields->$field ),
            strtolower( $query ) ) !== false ) // does the value match?
    $valid = true;

to:

if( strpos( strtolower( $potential_attachments[$i]->fields->$field ),
            strtolower( $query ) ) !== false ) // does the value match?
    if( !$params['filetypes'] || in_array($this->get_mime_type( $potential_attachments[$i]->id ), $params['filetypes']) )
        $valid = true;
  • and finally, reuse function get_mime_type inside type():
function type( $index = null )
{
    $index = is_null( $index ) ? $this->attachments_ref : intval( $index );

    if( !isset( $this->attachments[$index]->id ) )
        return false;

    return $this->get_mime_type($this->attachments[$index]->id);
//            $attachment_mime = explode( '/', get_post_mime_type( $this->attachments[$index]->id ) );
//            return isset( $attachment_mime[0] ) ? $attachment_mime[0] : false;
}

After all this changes, it is possible to perform this search:

$search_args = array(
    'instance'      => 'attachments',
    'filetypes'     => array('audio', 'video')
);

and it filters by audio and video

Cheers,
Leo

Why base64 encode the attachments options in the postmeta table?

I'm having an issue with base64 encoding the serialized options in postmeta table.
This way it's impossible to do an easy match on Media Library items and connected Posts ( via the Attachments plugin ) by a single SQL query.

I understand that it's something that was done on the 1.x version, and removed from 3.x.
But can't an config option be added when using the 3.x version in 1.x mode on an old WP install that the base64 encode/decode is disabled?
Plugin newly added to the installation and no other attachments are available...
The WP Install can't be updated at this point for the client.

Enhancement: Provide search mechanism for attachments and meta

It would be great to have an API for searching all of the attachments in a given instance, with or without knowing a post ID. Ideally, it would search all of an attachment's meta as well, so entries from titles, captions, and other added fields would be included.

For instance, I could call: $myInstance->search('some text'); to search everything.

Or, I could limit it to a specific field: $myInstance->search('some text', array('title', 'custom_field'));

Attachments auto-populate from last set

Good day --

Overall, I love the plugin, and am thrilled it's being actively developed :)

However, I have noticed a major issue...but maybe (hopefully) it's just me. Whenever I create a new post, or edit an existing, whatever attachments I added last appear in the Attachments field. This appears to be a superficial bug, in that the shown attachments are not connected to the post until it is saved. For example, editing an existing post will show the wrong attachments, but if I leave the editor without saving, the original attachments are intact. Saving, however, overwrites them.

This occurs on an out-of-the-box WP 3.5.1 installation, using a custom theme I'm developing. While I do have other plugins running, this occurs regardless of whether or not they are active. I have not created a custom instance of Attachments.

Thanks,
Nate P.

Bug with using 'attachment' instead of $this->meta_key

Hello, thanks for the plugin, it is awesome! I found a bug: right now it always searches under meta_key 'attachments', I changed this value to something else but it is not working.

I found it is because, in class.attachments.php, function search, where it says:

array(
    'key'       => 'attachments',
    'value'     => $query,
    'compare'   => 'LIKE'
)

it should be:

array(
    'key'       => $this->meta_key,
    'value'     => $query,
    'compare'   => 'LIKE'
)

Cheers
Leo

[minor issue] Does not work if plugin added as MUplugin (Must Use Plugin)

If we need to add this plugin as a must use plugin in SiteRoot/wp-content/mu-plugins/ and activate it using a loader, everything seems to work but we get Failed to load resource: the server responded with a status of 404 (Not Found) http://example.com/wp-content/plugins/attachments/js/attachments.js?ver=3.4.2.1 as the new folder would be http://example.com/wp-content/mu-plugins/attachments/js/attachments.js

Not quite sure if wordpress plugins are supposed to support mu-plugins tough, I just started to play with these lately.

Quick fix is to simply locate where the plugin url is called and change it to WPMU_PLUGIN_URL

Line 42 of index.php would become something like this:
define( 'ATTACHMENTS_URL', WPMU_PLUGIN_URL . '/attachments/' );

Uncaught TypeError: Cannot read property 'url' of undefined

i get that error trying to attach a image.
wordpress and attachments are both newest versions.

Chrome error:
Uncaught TypeError: Cannot read property 'url' of undefined post-new.php:579
(anonymous function) post-new.php:579
T.each.T.forEach load-scripts.php:394
r.(anonymous function) load-scripts.php:420
(anonymous function) post-new.php:569
g.Events.trigger load-scripts.php:404
f.extend._onModelEvent load-scripts.php:419
g.Events.trigger load-scripts.php:404
f.view.Toolbar.Select.f.view.Toolbar.extend.clickSelect load-scripts.php:437
f.view.Button.f.View.extend.click load-scripts.php:437
v.event.dispatch load-scripts.php:2
o.handle.u

Notice: Undefined property: stdClass::$fields

Hello, thank you for very awesome plugin of yours! I have a minor issue with it.

In PHP debugging mode, it throws a notice: Undefined property: stdClass::$fields in [...]/wp-content/plugins/attachments/classes/class.attachments.php on line 1579. Any idea why?

An attachment shows just fine, so if there's no quick way how to fix the notice, it's just fine. :)

My theme code

"174" is a post_ID of my page.


<?php
    $attachments = new Attachments( 'my_attachments_home', 174);
?>
<aside><?php if( $attachments->exist() ) { 
    $my_index = 0; 
    if( $attachment = $attachments->get_single( $my_index ) ) { 
        echo $attachments->image( 'thumbnail',$my_index); 
    }
} ?>

Setting up custom Attachments box


< ?php function my_attachments( $attachments ) {
    $args = array(
        // title of the meta box (string)
        'label' => 'Galerie',
        // all post types to utilize (string|array)
        'post_type' => array( 'post', 'vystavy'),
        // allowed file type(s) (array) (image|video|text|audio|application)
        'filetype' => null, // no filetype limit
        // include a note within the meta box (string)
        'note' => 'Přiložit obrázky',
        // text for 'Attach' button in meta box (string)
        'button_text' => __( 'Přiložit obrázky', 'attachments' ),
        // text for modal 'Attach' button (string)
        'modal_text' => __( 'Přiložit', 'attachments' ),
        'fields' => array(
            array(
                        'name' => 'title', // unique field name
                        'type' => 'text', // registered field type
                        'label' => __( 'Title', 'attachments' ), // label to display
                ), 
            ),
        );
        $args_home = array(
                // title of the meta box (string)
                'label' => 'Profilový obrázek',
                // all post types to utilize (string|array)
                'post_type' => array( 'page'),
                // allowed file type(s) (array) (image|video|text|audio|application)
                'filetype' => null, // no filetype limit
                // include a note within the meta box (string)
                'note' => 'Velikost na stránce 120x120px - Tvůj obrázek by tedy měl být spíš ikonka (ideálně výřez obličeje).',
                // text for 'Attach' button in meta box (string)
                'button_text' => __( 'Vložit profilový obrázek', 'attachments' ),
                // text for modal 'Attach' button (string)
                'modal_text' => __( 'Vložit profilový obrázek', 'attachments' ),
                'fields' => array(),
        );
        $attachments->register( 'my_attachments', $args ); // unique instance name
        $attachments->register( 'my_attachments_home', $args_home ); // unique instance name
}
add_action( 'attachments_register', 'my_attachments' ); ?>

Any idea what am I doing wrong? Thank you!

Add ability to set location rules for instances

Very often an instance only makes sense on a single Page, or a select few Pages. Location rules should be added to facilitate showing an instance only when certain location criteria (post ID, post parent ID, category, etc.) are met.

Fieldtype textarea: Won't save linebreaks

Example before save:

"In unserem neu entstehenden Fitness- und Gesundheitsstudio
im Thermen Resort Rilchingen bieten wir Ihnen auf über
1.400 m² ein Angebot der Spitzenklasse."

Example after save:

"In unserem neu entstehenden Fitness- und Gesundheitsstudiornim Thermen Resort Rilchingen bieten wir Ihnen auf überrn1.400 m² ein Angebot der Spitzenklasse."

Recognize that the lines breaks are replaced by "rn".

Problem lies prolly in line 994 of class.attachments.php

$attachment['fields'][$key] = htmlentities( stripslashes( $field_value ), ENT_QUOTES, 'UTF-8' );

Special characters (ěščřžýáíé)

Hi,
I've small issue with using this amazing plugin.
My language use these special characters, but if I try to use them in a title of an attachment, I will get this: u011bšu010du0159u017eýáíé

Can you please tell me, where I can fix it? I need UTF-8.

Thank you

phantom attachments

Hello -
I've run across a minor issue that crops up we 'delete permanently' via the WP media interface, files added using the 'Attachments' plugin interface. Residual information still appears in the 'Attachments' interface, even with a post update and page refresh. What we basically see is the field information but no thumbnail (screenshot).

Screen Shot 2013-04-07 at 23 11 41

Adding pagination to the search

Hi Jonathan,

I'm adding a new issue here to discuss the addition of pagination to the results of the search. I think this would be a wonderful thing to have.

As I explained in my previous 3 issues, I use Attachments to upload Resources to the post, like presentations, word files, or even youtube embeds (through plugin jwp6). Then, I have a page called Resources, where I select all the Resources from all the posts and display them all together. I attach an image of this page.

attachments

I would need to have pagination in function search(). However I was exploring the code, and I think it is not possible right now efficiently, because first you select the posts, and then from the metadata under metakey 'attachments' you select / filter the attachments. So let's say you want to paginate 20 results at a time, then you'd need to process all results, and then from the list just return 20.

The best way would be to already get the results, paginated, using WP_Query, so that the query wil alreadyl return the 20 values.

So I was thinking this strategy: In addition of what Attachments already does, saving the info under the post metadata under key 'attachments', also do the following:

  • save the attachment metadata not only under the post meta, but also under the attachment meta (add redundant data)
  • then in function search(), instead of querying for posts and then selecting and filtering its attached files, query directly for the attachments, like this:
$attachment_args = array(
    'post_type' => 'attachment', 
    'post_mime_type' => $filetype, 
    'post_status' => 'inherit', 
    'posts_per_page' => 20,
    'meta_query' => array(
        array(
            'key' => 'attachment_post_id',
            'value' => $post_id,
            'compare' => 'IN',
        )
    )    
);
$attachments = new WP_Query( $attachment_args );

As you can see, then you can also filter by post_mime_type already, and you can bring all results by not providing the $post_id

Also, you can add the id / title / caption / etc fields as a metadata field each and then also filter by them, for instance:

$attachment_args = array(
    'post_type' => 'attachment', 
    'post_mime_type' => $filetype, 
    'post_status' => 'inherit', 
    'posts_per_page' => 20,
    'meta_query' => array(
        array(
            'key' => 'attachment_post_id',
            'value' => $post_id,
            'compare' => 'IN',
        ),  
        array(
            'key' => 'attachment_title',
            'value' => $query,
            'compare' => 'LIKE',
        ),
        array(
            'key' => 'attachment_caption',
            'value' => $query,
            'compare' => 'LIKE',
        )
   )
);
$attachments = new WP_Query( $attachment_args );

So what do you think?

Cheers,
Leo

Misleading instance name on usage tutorial

You suggest in users function.php to insert a function my_attachments(), at the end of that function you wrote: $attachments->register( 'my_attachments', $args ); // unique instance name

However you suggest on your example to use on a page:

Instead, it should be: $attachments = new Attachments( 'my_attachments' );

This wrong information, makes Attachments not working on CPTs

add_image_size and attachments

Hi,

I dont think this is a issue its more of a question and i wasnt quite sure of the best place to put it if im totally honest.

Does the plugin when uploading a image create multiple versions of the image according to the add_image_size that i have added in my functions.php file or does it simply upload a single copy un modified?

The reason i ask is because im using it on one site ive uploaded a large image 2000px wide and was expecting it to get resized and when i call the image using the correct name for that image size the image being displayed is still the 2000px one just sized down in the html code with a height and a width, this wouldnt usually be a bother but because the user has uploaded a large file its slow rendering as its over 1.8mb. Ideally it would be great if when a image was uploaded the add_image_size sizes would be added to it and multiple copies created (Thats of course if I have it incorrect and in fact the plugin already does this?)

thanks

Dan

Pre-populating title and caption from media library

Borrowed from http://wordpress.org/support/topic/pre-populating-title-and-caption-from-media-library


Is there a way to have the plugin use the title and caption for an item in the media library to pre-populate the title and caption fields in the attachments metabox?

To rephrase: when I use the attachments plugin to attach an item from my media library to a post, is there a way to have the title and caption fields pre-populated with the same data from the item?

I'd like to avoid having to re-enter all of this info when I use the attachments plugin to attach existing media library items to my posts.

Theme code not working for me.

I'm having a hard time displaying the attachments in my post. Here is my instance declaration:

function projects_attachments( $attachments )
{
$fields         = array(
array(
  'name'      => 'title',                         // unique field name
  'type'      => 'text',                          // registered field type
  'label'     => __( 'Title', 'attachments' ),    // label to display
  'default'   => 'title',                         // default value upon selection
),
array(
    'name'      => 'type',                         // unique field name
    'type'      => 'select',                          // registered field type
    'label'     => __( 'Type', 'attachments' ),    // label to display
    'meta'      => array(                               // field-specific meta as defined by field      class
                'allow_null'    => false,            // allow null value? (adds 'empty' <option>)
                'multiple'      => false,            // multiple <select>?
                'options'       => array(           // the <option>s to use
                      '1'     => 'Screenshot',
                      '2'     => 'Flash Banner',
                  )
              ),
),
array(
  'name'      => 'swf',                       // unique field name
  'type'      => 'text',                      // registered field type
  'label'     => __( 'SWF URL', 'attachments' ),  // label to display
  'default'   => '',                       // default value upon selection
),
);

$args = array(

// title of the meta box (string)
'label'         => 'Project Attachments',

// all post types to utilize (string|array)
'post_type'     => array( 'projects' ),

// meta box position (string) (normal, side or advanced)
'position'      => 'normal',

// meta box priority (string) (high, default, low, core)
'priority'      => 'default',

// allowed file type(s) (array) (image|video|text|audio|application)
'filetype'      => null,  // no filetype limit

// include a note within the meta box (string)
'note'          => 'Attach all project related files here.',

// by default new Attachments will be appended to the list
// but you can have then prepend if you set this to false
'append'        => true,

// text for 'Attach' button in meta box (string)
'button_text'   => __( 'Attach Files', 'attachments' ),

// text for modal 'Attach' button (string)
'modal_text'    => __( 'Attach', 'attachments' ),

// which tab should be the default in the modal (string) (browse|upload)
'router'        => 'browse',

// fields array
'fields'        => $fields,

);

$attachments->register( 'projects_attachments', $args ); // unique instance name
 }

 add_action( 'attachments_register', 'projects_attachments' );

And here's the code I have in my theme:

<?php $attachments = new Attachments( 'projects_attachments' ); 
      if($attachments->exist()) :
?>
<div id="project-attachments">
<ul class="clearfix">
<?php
    while( $attachment = $attachments->get() ) {
        switch($attachment->field( 'type' )) {
            case "1": 
                ?>
                <li><a href="<?php echo $attachment->src( 'full' ); ?>" rel="thumbs"><img src="<?php echo $attachment->image( 'thumbnail' ); ?>" alt="<?php echo $attachment->field( 'title' ); ?>" /></a></li>
                <?php
                break;
            case "2": 
                ?>
                <li><a href="<?php echo $attachment->src( 'full' ); ?>" rel="thumbs"><img src="<?php echo $attachment->image( 'thumbnail' ); ?>" alt="<?php echo $attachment->field( 'title' ); ?>" /></a></li>
                <?php
                break;
        }
    } ?>
</ul>
</div>
<?php endif; ?>

Do you have any idea why it'd error out when trying to get $attachment->src( 'full' )? Also, when I print_r($attachment) it only shows the attachment ID, fields, and post ID. So for some reason it seems the object isn't being populated with everything as needed.

Traversable

Hi,

Currently, usage of get() only allows one loop on attachments.

You should consider to implements Iterator interface.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.