Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting title attribute from an uploaded image #51

Open
jackmahoney opened this issue Jul 31, 2012 · 2 comments
Open

Getting title attribute from an uploaded image #51

jackmahoney opened this issue Jul 31, 2012 · 2 comments

Comments

@jackmahoney
Copy link

Hi. Firstly LOVE your class - great work.

I need to get the title and alt attributes of an uploaded image using the MediaAccess class. However it only returns the url. I hacked it to return the title but it isn't such an elegant solution.

Any ideas how to make it better?

Here is my child class
https://gist.github.com/3214107

Here is the implementation in a metabox
https://gist.github.com/3214109

Thanks

@saddam-azad
Copy link

Currently MediaAccess can only get the URL of a given media. I wish it would also return all the associated information of the media along (attachment ID, title, alt, description, width, height, etc.).

Perhaps you could give it a shot by forking the project?

@jackmahoney
Copy link
Author

I extended your WPAlchemy_MediaAccess class and overrode line 329. Perhaps this is of some assistance?

                    send_to_editor = function(html)
                    {
                        clearInterval(interval);

                        if (wpalchemy_mediafield)
                        {
                            var src = html.match(/src=['|"](.*?)['|"] alt=/i);
                            src = (src && src[1]) ? src[1] : '' ;

                            var href = html.match(/href=['|"](.*?)['|"]/i);
                            href = (href && href[1]) ? href[1] : '' ;

                            var url = src ? src : href ;

                            //!important
                            var title = html.match(/title=['|"](.*?)['|"]/i);
                            title = (title && title[1]) ? title[1] : '' ;

                            wpalchemy_mediafield.val(url);
                            wpalchemy_mediafield_metafield.val(title);

                            // reset insert button label
                            setInsertButtonLabel(wpalchemy_insert_button_label);

                            wpalchemy_mediafield = null;
                        }
                        else
                        {
                            wpalchemy_send_to_editor_default(html);
                        }

                        tb_remove();
                    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants