extend wordpress core class in functions.php

I am trying to extend a wordpress core class inside my theme’s functions.php, & the class I am trying to extend is WP_Customize_Image_Control from class wp-customize-control.php in wp-includes.

It already extends “WP_Customize_Upload_Control”.

Read More

I would like to allow the .svg mime-type to be uploaded within the theme customizer.

in my theme’s functions.php I am adding these lines:

class WP_Customize_Image_Control_SVG extends WP_Customize_Image_Control {
      public $extensions = array( 'jpg', 'jpeg', 'gif', 'png', 'svg' );
};

but sadly this breaks everything.

Any help, hints or tips appreciated.

Related posts

Leave a Reply

1 comment

  1. You are close.

    /* Extend the Image Control */
    
    class WP_Customize_Image_Control_SVG extends WP_Customize_Image_Control
    {
            public function __construct( $manager, $id, $args = array() )
           {
                    parent::__construct( $manager, $id, $args );
                    $this->remove_tab('uploaded');
                    $this->extensions = array( 'jpg', 'jpeg', 'gif', 'png', 'svg' );
            }
    }
    

    This goes inside your “customize_register” action

    Just make sure you’re registering this one instead of the normal image control.