| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Redux Framework is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 2 of the License, or |
| 7 |
* any later version. |
| 8 |
* Redux Framework is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* You should have received a copy of the GNU General Public License |
| 13 |
* along with Redux Framework. If not, see <http://www.gnu.org/licenses/>. |
| 14 |
* |
| 15 |
* @package ReduxFrameworkLegacy |
| 16 |
* @subpackage Field_Info |
| 17 |
* @author Daniel J Griffiths (Ghost1227) |
| 18 |
* @author Dovy Paukstys |
| 19 |
* @version 3.0.0 |
| 20 |
*/ |
| 21 |
|
| 22 |
// Exit if accessed directly |
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; |
| 25 |
} |
| 26 |
|
| 27 |
// Don't duplicate me! |
| 28 |
if ( ! class_exists( 'ReduxFrameworkLegacy_info' ) ) { |
| 29 |
|
| 30 |
/** |
| 31 |
* Main ReduxFrameworkLegacy_info class |
| 32 |
* |
| 33 |
* @since 1.0.0 |
| 34 |
*/ |
| 35 |
class ReduxFrameworkLegacy_info { |
| 36 |
|
| 37 |
public $parent; |
| 38 |
public $field; |
| 39 |
public $value; |
| 40 |
/** |
| 41 |
* Field Constructor. |
| 42 |
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function |
| 43 |
* |
| 44 |
* @since 1.0.0 |
| 45 |
* @access public |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
function __construct( $field = array(), $value = '', $parent = null ) { |
| 49 |
$this->parent = $parent; |
| 50 |
$this->field = $field; |
| 51 |
$this->value = $value; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Field Render Function. |
| 56 |
* Takes the vars and outputs the HTML for the field in the settings |
| 57 |
* |
| 58 |
* @since 1.0.0 |
| 59 |
* @access public |
| 60 |
* @return void |
| 61 |
*/ |
| 62 |
public function render() { |
| 63 |
|
| 64 |
$defaults = array( |
| 65 |
'title' => '', |
| 66 |
'desc' => '', |
| 67 |
'notice' => true, |
| 68 |
'style' => '', |
| 69 |
'color' => '', |
| 70 |
); |
| 71 |
|
| 72 |
$this->field = wp_parse_args( $this->field, $defaults ); |
| 73 |
|
| 74 |
$styles = array( |
| 75 |
'normal', |
| 76 |
'info', |
| 77 |
'warning', |
| 78 |
'success', |
| 79 |
'critical', |
| 80 |
'custom', |
| 81 |
); |
| 82 |
|
| 83 |
if ( ! in_array( $this->field['style'], $styles ) ) { |
| 84 |
$this->field['style'] = 'normal'; |
| 85 |
} |
| 86 |
if ( $this->field['style'] == 'custom' ) { |
| 87 |
if ( ! empty( $this->field['color'] ) ) { |
| 88 |
$this->field['color'] = 'border-color:' . $this->field['color'] . ';'; |
| 89 |
} else { |
| 90 |
$this->field['style'] = 'normal'; |
| 91 |
$this->field['color'] = ''; |
| 92 |
} |
| 93 |
} else { |
| 94 |
$this->field['color'] = ''; |
| 95 |
} |
| 96 |
|
| 97 |
if ( empty( $this->field['desc'] ) && ! empty( $this->field['default'] ) ) { |
| 98 |
$this->field['desc'] = $this->field['default']; |
| 99 |
unset( $this->field['default'] ); |
| 100 |
} |
| 101 |
|
| 102 |
if ( empty( $this->field['desc'] ) && ! empty( $this->field['subtitle'] ) ) { |
| 103 |
$this->field['desc'] = $this->field['subtitle']; |
| 104 |
unset( $this->field['subtitle'] ); |
| 105 |
} |
| 106 |
|
| 107 |
if ( empty( $this->field['desc'] ) ) { |
| 108 |
$this->field['desc'] = ''; |
| 109 |
} |
| 110 |
|
| 111 |
if ( empty( $this->field['raw_html'] ) ) { |
| 112 |
if ( $this->field['notice'] == true ) { |
| 113 |
$this->field['class'] .= ' redux-notice-field'; |
| 114 |
} else { |
| 115 |
$this->field['class'] .= ' redux-info-field'; |
| 116 |
} |
| 117 |
|
| 118 |
$this->field['style'] = 'redux-' . $this->field['style'] . ' '; |
| 119 |
} |
| 120 |
|
| 121 |
$indent = ( isset( $this->field['sectionIndent'] ) && $this->field['sectionIndent'] ) ? ' form-table-section-indented' : ''; |
| 122 |
|
| 123 |
echo '</td></tr></table><div id="info-' . esc_attr( $this->field['id'] ) . '" class="' . ( isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && $this->field['icon'] !== true ? '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'] ) . '"' : '' ) . '>'; |
| 124 |
|
| 125 |
if ( ! empty( $this->field['raw_html'] ) && $this->field['raw_html'] ) { |
| 126 |
echo wp_kses_post( $this->field['desc'] ); |
| 127 |
} else { |
| 128 |
if ( isset( $this->field['title'] ) && ! empty( $this->field['title'] ) ) { |
| 129 |
$this->field['title'] = '<b>' . wp_kses_post( $this->field['title'] ) . '</b><br/>'; |
| 130 |
} |
| 131 |
|
| 132 |
if ( isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && $this->field['icon'] !== true ) { |
| 133 |
echo '<p class="redux-info-icon"><i class="' . esc_attr( $this->field['icon'] ) . ' icon-large"></i></p>'; |
| 134 |
} |
| 135 |
|
| 136 |
if ( isset( $this->field['raw'] ) && ! empty( $this->field['raw'] ) ) { |
| 137 |
echo wp_kses_post( $this->field['raw'] ); |
| 138 |
} |
| 139 |
|
| 140 |
if ( ! empty( $this->field['title'] ) || ! empty( $this->field['desc'] ) ) { |
| 141 |
echo '<p class="redux-info-desc">' . wp_kses_post( $this->field['title'] ) . wp_kses_post( $this->field['desc'] ) . '</p>'; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
echo '</div><table class="form-table no-border" style="margin-top: 0;"><tbody><tr style="border-bottom:0; display:none;"><th style="padding-top:0;"></th><td style="padding-top:0;">'; |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Enqueue Function. |
| 150 |
* If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
| 151 |
* |
| 152 |
* @since 1.0.0 |
| 153 |
* @access public |
| 154 |
* @return void |
| 155 |
*/ |
| 156 |
public function enqueue() { |
| 157 |
if ( $this->parent->args['dev_mode'] ) { |
| 158 |
wp_enqueue_style( |
| 159 |
'redux-field-info-css', |
| 160 |
ReduxFrameworkLegacy::$_url . 'inc/fields/info/field_info.css', |
| 161 |
array(), |
| 162 |
time(), |
| 163 |
'all' |
| 164 |
); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|