grok / wordpress-plugin-scalable-vector-graphics

Scalable Vector Graphics are two-dimensional vector graphics, that can be both static and dynamic. This plugin allows your to easily use them on your site.
http://sterlinghamilton.com/scalable-vector-graphics-plugin
GNU General Public License v2.0
15 stars 5 forks source link

Doesn't work with WP_Customize_Image_Control #4

Closed littlefyr closed 10 years ago

littlefyr commented 10 years ago

This plugin is awesome sauce. I'm going to be using it everywhere.

One thing I noticed, however, is that this does not work with my theme customization. Which is to say that when I add a theme setting for "Logo" I can't upload an SVG logo to that.

I'm hoping to share this theme via WP so I'm not going to bake all this logic into my theme, but I want to let others who may want to use SVG are able to without having to jump through hoops to get there.

grok commented 10 years ago

Could you point me to the code you are using for the logo?

littlefyr commented 10 years ago

Its been a little while since I worked on this part (life and all that) but I think this is it:

In the customize_register action I have this code:

        $wp_customize->add_setting($this->setting_name('logo'), array(
            'transport' => 'postMessage',
            'default'   => ''
            ));

        $wp_customize->add_control(
            new LF_Customize_Image_Control(
                $wp_customize,
                $this->setting_name('logo'),
                array(
                    'label'      => __( 'Upload a logo', 'theme_name' ),
                    'section'    => 'title_tagline',
                    'settings'   => $this->setting_name('logo')
                    )
                )
            );

And that custom image control simply wraps the default to more nicely handle the file upload:

<?php 
//Sourced from https://gist.github.com/eduardozulian/4739075/
class LF_Customize_Image_Control extends WP_Customize_Image_Control {
    /**
     * Constructor.
     *
     * @since 3.4.0
     * @uses WP_Customize_Image_Control::__construct()
     *
     * @param WP_Customize_Manager $manager
     */
    public function __construct( $manager, $id, $args = array() ) {
        parent::__construct( $manager, $id, $args );
    }

    /**
     * Search for images within the defined context
     */
    public function tab_uploaded() {
        $my_context_uploads = get_posts( array(
            'post_type'  => 'attachment',
            'meta_key'   => '_wp_attachment_context',
            'meta_value' => $this->context,
            'orderby'    => 'post_date',
            'nopaging'   => true,
        ) );
        ?>

        <div class="uploaded-target"></div>

        <?php
        if ( empty( $my_context_uploads ) )
            return;

        foreach ( (array) $my_context_uploads as $my_context_upload ) {
            $this->print_tab_image( esc_url_raw( $my_context_upload->guid ) );
        }
    }
} 
grok commented 10 years ago

Is there custom upload functionality? I don't see where it actually uploads the image. Code looks like it configures some settings, and retrieves some posts.

I need to see what the data looks like as it's going in and hopefully an output of what the image object looks like.

littlefyr commented 10 years ago

This is just the Theme customization api http://codex.wordpress.org/Class_Reference%5CWP_Customize_Manager%5Cadd_control

grok commented 10 years ago

Oh duh - ok yeah I'll mess with this in a few hours

On Sep 4, 2014, at 11:10 PM, Adam van den Hoven notifications@github.com wrote:

This is just the Theme customization api http://codex.wordpress.org/Class_Reference%5CWP_Customize_Manager%5Cadd_control

— Reply to this email directly or view it on GitHub.

Scrupulosis commented 10 years ago

There seems to be part of an answer here

grok commented 10 years ago

Nice. I'll give that a try. I think that's enough to get it done.

grok commented 10 years ago

@Scrupulosis is correct. This is the proper approach.

Here's my test.

  1. I created a blank Theme.
  2. I created a blank style.css, index.php and functions.php file.
  3. In the functions file I added the following code:

https://gist.github.com/grok/52343cb93cca482c0796

Prior to adding $this->extensions = array('jpg', 'jpeg', 'gif', 'png', 'svg'); I was unable to upload SVG files. After adding that I was able to.

littlefyr commented 10 years ago

Ok. That's great. Thanks.