balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-redux-info.php (4548B)


      1 <?php
      2 /**
      3  * Info Field.
      4  *
      5  * @package     ReduxFramework/Fields
      6  * @author      Dovy Paukstys & Kevin Provance (kprovance)
      7  * @version     4.0.0
      8  */
      9 
     10 defined( 'ABSPATH' ) || exit;
     11 
     12 // Don't duplicate me!
     13 if ( ! class_exists( 'Redux_Info', false ) ) {
     14 
     15 	/**
     16 	 * Main Redux_info class
     17 	 *
     18 	 * @since       1.0.0
     19 	 */
     20 	class Redux_Info extends Redux_Field {
     21 
     22 		/**
     23 		 * Set field and value defaults.
     24 		 */
     25 		public function set_defaults() {
     26 			$defaults = array(
     27 				'title'  => '',
     28 				'desc'   => '',
     29 				'indent' => false,
     30 				'notice' => true,
     31 				'style'  => '',
     32 				'color'  => '',
     33 			);
     34 
     35 			$this->field = wp_parse_args( $this->field, $defaults );
     36 		}
     37 
     38 		/**
     39 		 * Field Render Function.
     40 		 * Takes the vars and outputs the HTML for the field in the settings
     41 		 *
     42 		 * @since       1.0.0
     43 		 * @access      public
     44 		 * @return      void
     45 		 */
     46 		public function render() {
     47 			$styles = array(
     48 				'normal',
     49 				'info',
     50 				'warning',
     51 				'success',
     52 				'critical',
     53 				'custom',
     54 			);
     55 
     56 			if ( ! in_array( $this->field['style'], $styles, true ) ) {
     57 				$this->field['style'] = 'normal';
     58 			}
     59 
     60 			if ( 'custom' === $this->field['style'] ) {
     61 				if ( ! empty( $this->field['color'] ) ) {
     62 					$this->field['color'] = 'border-color:' . $this->field['color'] . ';';
     63 				} else {
     64 					$this->field['style'] = 'normal';
     65 					$this->field['color'] = '';
     66 				}
     67 			} else {
     68 				$this->field['color'] = '';
     69 			}
     70 
     71 			if ( empty( $this->field['desc'] ) && ! empty( $this->field['default'] ) ) {
     72 				$this->field['desc'] = $this->field['default'];
     73 				unset( $this->field['default'] );
     74 			}
     75 
     76 			if ( empty( $this->field['desc'] ) && ! empty( $this->field['subtitle'] ) ) {
     77 				$this->field['desc'] = $this->field['subtitle'];
     78 				unset( $this->field['subtitle'] );
     79 			}
     80 
     81 			if ( empty( $this->field['desc'] ) ) {
     82 				$this->field['desc'] = '';
     83 			}
     84 
     85 			if ( empty( $this->field['raw_html'] ) ) {
     86 				if ( true === $this->field['notice'] ) {
     87 					$this->field['class'] .= ' redux-notice-field';
     88 				} else {
     89 					$this->field['class'] .= ' redux-info-field';
     90 				}
     91 
     92 				$this->field['style'] = 'redux-' . $this->field['style'] . ' ';
     93 			}
     94 
     95 			// Old shim, deprecated arg.
     96 			if ( isset( $this->field['sectionIndent'] ) ) {
     97 				$this->field['indent'] = $this->field['sectionIndent'];
     98 			}
     99 			$indent = ( isset( $this->field['indent'] ) && $this->field['indent'] ) ? ' form-table-section-indented' : '';
    100 
    101 			echo '</td></tr></table>';
    102 			echo '<div
    103 					id="info-' . esc_attr( $this->field['id'] ) . '"
    104 					class="' . ( isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && true !== $this->field['icon'] ? 'hasIcon ' : '' ) . esc_attr( $this->field['style'] ) . ' ' . esc_attr( $this->field['class'] ) . ' redux-field-' . esc_attr( $this->field['type'] ) . esc_attr( $indent ) . '"' . ( ! empty( $this->field['color'] ) ? ' style="' . esc_attr( $this->field['color'] ) . '"' : '' ) . '>';
    105 
    106 			if ( ! empty( $this->field['raw_html'] ) && $this->field['raw_html'] ) {
    107 				echo wp_kses_post( $this->field['desc'] );
    108 			} else {
    109 				if ( isset( $this->field['title'] ) && ! empty( $this->field['title'] ) ) {
    110 					$this->field['title'] = '<b>' . wp_kses_post( $this->field['title'] ) . '</b><br/>';
    111 				}
    112 
    113 				if ( isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && true !== $this->field['icon'] ) {
    114 					echo '<p class="redux-info-icon"><i class="' . esc_attr( $this->field['icon'] ) . ' icon-large"></i></p>';
    115 				}
    116 
    117 				if ( isset( $this->field['raw'] ) && ! empty( $this->field['raw'] ) ) {
    118 					echo wp_kses_post( $this->field['raw'] );
    119 				}
    120 
    121 				if ( ! empty( $this->field['title'] ) || ! empty( $this->field['desc'] ) ) {
    122 					echo '<p class="redux-info-desc">' . wp_kses_post( $this->field['title'] ) . wp_kses_post( $this->field['desc'] ) . '</p>';
    123 				}
    124 			}
    125 
    126 			echo '</div>';
    127 			echo '<table class="form-table no-border" style="margin-top: 0;">';
    128 			echo '<tbody>';
    129 			echo '<tr style="border-bottom:0; display:none;">';
    130 			echo '<th style="padding-top:0;"></th>';
    131 			echo '<td style="padding-top:0;">';
    132 		}
    133 
    134 		/**
    135 		 * Enqueue Function.
    136 		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
    137 		 *
    138 		 * @since       1.0.0
    139 		 * @access      public
    140 		 * @return      void
    141 		 */
    142 		public function enqueue() {
    143 			if ( $this->parent->args['dev_mode'] ) {
    144 				wp_enqueue_style(
    145 					'redux-field-info-css',
    146 					Redux_Core::$url . 'inc/fields/info/redux-info.css',
    147 					array(),
    148 					$this->timestamp
    149 				);
    150 			}
    151 		}
    152 	}
    153 }
    154 
    155 class_alias( 'Redux_Info', 'ReduxFramework_Info' );