. * * @package ReduxFramework * @subpackage Field_Media * @author Daniel J Griffiths (Ghost1227) * @author Dovy Paukstys * @version 3.0.0 */ // Exit if accessed directly if (!defined('ABSPATH')) { exit; } // Don't duplicate me! if (!class_exists('ReduxFramework_media')) { /** * Main ReduxFramework_media class * * @since 1.0.0 */ class ReduxFramework_media { /** * Field Constructor. * * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function * * @since 1.0.0 * @access public * @return void */ function __construct($field = array(), $value = '', $parent) { $this->parent = $parent; $this->field = $field; $this->value = $value; } /** * Field Render Function. * * Takes the vars and outputs the HTML for the field in the settings * * @since 1.0.0 * @access public * @return void */ public function render() { // No errors please $defaults = array( 'id' => '', 'url' => '', 'width' => '', 'height' => '', 'thumbnail' => '', ); $this->value = wp_parse_args($this->value, $defaults); if (!isset($this->field['mode'])) { $this->field['mode'] = "image"; } if (empty($this->value) && !empty($this->field['default'])) { // If there are standard values and value is empty if (is_array($this->field['default'])) { if (!empty($this->field['default']['id'])) { $this->value['id'] = $this->field['default']['id']; } if (!empty($this->field['default']['url'])) { $this->value['url'] = $this->field['default']['url']; } } else { if (is_numeric($this->field['default'])) { // Check if it's an attachment ID $this->value['id'] = $this->field['default']; } else { // Must be a URL $this->value['url'] = $this->field['default']; } } } if (empty($this->value['url']) && !empty($this->value['id'])) { $img = wp_get_attachment_image_src($this->value['id'], 'full'); $this->value['url'] = $img[0]; $this->value['width'] = $img[1]; $this->value['height'] = $img[2]; } $hide = 'hide '; if ((isset($this->field['preview']) && $this->field['preview'] === false)) { $this->field['class'] .= " noPreview"; } if ((!empty($this->field['url']) && $this->field['url'] === true ) || isset($this->field['preview']) && $this->field['preview'] === false) { $hide = ''; } $placeholder = isset($this->field['placeholder']) ? $this->field['placeholder'] : __('No media selected', 'redux-framework'); $readOnly = ' readonly="readonly"'; if (isset($this->field['readonly']) && $this->field['readonly'] === false) { $readOnly = ''; } echo ''; echo ''; echo ''; echo ''; echo ''; //Preview $hide = ''; if ((isset($this->field['preview']) && $this->field['preview'] === false) || empty($this->value['url'])) { $hide = 'hide '; } if (empty($this->value['thumbnail']) && !empty($this->value['url'])) { // Just in case if (!empty($this->value['id'])) { $image = wp_get_attachment_image_src($this->value['id'], array(150, 150)); $this->value['thumbnail'] = $image[0]; } else { $this->value['thumbnail'] = $this->value['url']; } } echo '