. * * @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 extends ReduxFramework { /** * 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 ) { //parent::__construct( $parent->sections, $parent->args ); $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'); 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 '
'; echo ''; echo ''; echo ''; echo '
'; //Upload controls DIV echo '
'; //If the user has WP3.5+ show upload/remove button echo '' . __( 'Upload', 'redux-framework' ) . ''; $hide = ''; if( empty( $this->value['url'] ) || $this->value['url'] == '' ) $hide =' hide'; echo '' . __( 'Remove', 'redux-framework' ) . ''; echo '
'; } /** * * Functions to pass data from the PHP to the JS at render time. * * @return array Params to be saved as a javascript object accessable to the UI. * * @since Redux_Framework 3.1.1 * */ function localize($field, $value = "") { $params = array(); if ( !isset( $field['mode'] ) ) { $field['mode'] = "image"; } $params['mode'] = $field['mode']; if ( empty( $value ) ) { $value = $this->value; } $params['val'] = $value; return $params; } /** * Enqueue Function. * * If this field requires any scripts, or css define this function and register/enqueue the scripts/css * * @since 1.0.0 * @access public * @return void */ public function enqueue() { wp_enqueue_script( 'redux-field-media-js', ReduxFramework::$_url . 'inc/fields/media/field_media.js', array( 'jquery', 'wp-color-picker' ), time(), true ); wp_enqueue_style( 'redux-field-media-css', ReduxFramework::$_url . 'inc/fields/media/field_media.css', time(), true ); } } }