Tuesday, March 15, 2016

Using the WordPress Theme Customizer Media Controls

With recent WordPress updates, its API has changed. Some functions and classes have been added, others have been deprecated.

In this article, I will discuss the Theme Customizer Media Controls. In the previous versions, these controls were available, but only in the WP_Customize_Upload_Control class. Now we find a new class to manage media WP_Customize_Media_Control.

First, I'll cover how to use this new class to manage media controls in the Theme Customizer. Then we will cover a concrete example of a class that extends WP_Customize_Media_Control to allow the control of cropped images.

The New Base Class to Manage a Media Control

Why Introduce a New Class?

Before version 4.3, WordPress provided us WP_Customize_Upload_Control, a class to manage the upload of a media file in the Theme Customizer. However, this class didn’t save the ID of the uploaded media but only its URL. As the ID is a more common way to retrieve information about a media file, the decision was taken to provide a new class, WP_Customize_Media_Control.

If you have the habit of using WP_Customize_Upload_Control, you can still use it without any problems, as it now extends the WP_Customize_Media_Control class so compatibility is ensured. However, it surely is a better idea to update your code and use WP_Customize_Media_Control.

Continue reading %Using the WordPress Theme Customizer Media Controls%


by Jérémy Heleine via SitePoint

No comments:

Post a Comment