| 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 ReduxFramework |
| 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( 'ReduxFramework_info' ) ) { |
| 29 |
|
| 30 |
/** |
| 31 |
* Main ReduxFramework_info class |
| 32 |
* |
| 33 |
* @since 1.0.0 |
| 34 |
*/ |
| 35 |
class ReduxFramework_info { |
| 36 |
|
| 37 |
/** |
| 38 |
* Field Constructor. |
| 39 |
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function |
| 40 |
* |
| 41 |
* @since 1.0.0 |
| 42 |
* @access public |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
function __construct( $field = array(), $value = '', $parent ) { |
| 46 |
$this->parent = $parent; |
| 47 |
$this->field = $field; |
| 48 |
$this->value = $value; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Field Render Function. |
| 53 |
* Takes the vars and outputs the HTML for the field in the settings |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
* @access public |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
public function render() { |
| 60 |
|
| 61 |
$defaults = array( |
| 62 |
'title' => '', |
| 63 |
'desc' => '', |
| 64 |
'notice' => true, |
| 65 |
'style' => '', |
| 66 |
'color' => '', |
| 67 |
); |
| 68 |
|
| 69 |
$this->field = wp_parse_args( $this->field, $defaults ); |
| 70 |
|
| 71 |
$styles = array( |
| 72 |
'normal', |
| 73 |
'info', |
| 74 |
'warning', |
| 75 |
'success', |
| 76 |
'critical', |
| 77 |
'custom' |
| 78 |
); |
| 79 |
|
| 80 |
if (!in_array($this->field['style'], $styles)) { |
| 81 |
$this->field['style'] = 'normal'; |
| 82 |
} |
| 83 |
if ($this->field['style'] == "custom") { |
| 84 |
if (!empty($this->field['color']) ) { |
| 85 |
$this->field['color'] = "border-color:".$this->field['color'].';'; |
| 86 |
} else { |
| 87 |
$this->field['style'] = 'normal'; |
| 88 |
$this->field['color'] = ""; |
| 89 |
} |
| 90 |
} else { |
| 91 |
$this->field['color'] = ""; |
| 92 |
} |
| 93 |
|
| 94 |
if ( empty( $this->field['desc'] ) && ! empty( $this->field['default'] ) ) { |
| 95 |
$this->field['desc'] = $this->field['default']; |
| 96 |
unset( $this->field['default'] ); |
| 97 |
} |
| 98 |
|
| 99 |
if ( empty( $this->field['desc'] ) && ! empty( $this->field['subtitle'] ) ) { |
| 100 |
$this->field['desc'] = $this->field['subtitle']; |
| 101 |
unset( $this->field['subtitle'] ); |
| 102 |
} |
| 103 |
|
| 104 |
if ( empty( $this->field['desc'] ) ) { |
| 105 |
$this->field['desc'] = ""; |
| 106 |
} |
| 107 |
|
| 108 |
if ( empty( $this->field['raw_html'] ) ) { |
| 109 |
if ( $this->field['notice'] == true ) { |
| 110 |
$this->field['class'] .= ' redux-notice-field'; |
| 111 |
} else { |
| 112 |
$this->field['class'] .= ' redux-info-field'; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
$this->field['style'] = 'redux-' . $this->field['style'] . ' '; |
| 118 |
} |
| 119 |
|
| 120 |
$indent = ( isset( $this->field['sectionIndent'] ) && $this->field['sectionIndent'] ) ? ' form-table-section-indented' : ''; |
| 121 |
|
| 122 |
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']) . '"' : '' ) . '>'; |
| 123 |
|
| 124 |
if ( ! empty( $this->field['raw_html'] ) && $this->field['raw_html'] ) { |
| 125 |
echo wp_kses_post($this->field['desc']); |
| 126 |
} else { |
| 127 |
if ( isset( $this->field['title'] ) && ! empty( $this->field['title'] ) ) { |
| 128 |
$this->field['title'] = '<b>' . wp_kses_post($this->field['title']) . '</b><br/>'; |
| 129 |
} |
| 130 |
|
| 131 |
if ( isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && $this->field['icon'] !== true ) { |
| 132 |
echo '<p class="redux-info-icon"><i class="' . esc_attr($this->field['icon']) . ' icon-large"></i></p>'; |
| 133 |
} |
| 134 |
|
| 135 |
if ( isset( $this->field['raw'] ) && ! empty( $this->field['raw'] ) ) { |
| 136 |
echo wp_kses_post($this->field['raw']); |
| 137 |
} |
| 138 |
|
| 139 |
if ( ! empty( $this->field['title'] ) || ! empty( $this->field['desc'] ) ) { |
| 140 |
echo '<p class="redux-info-desc">' . wp_kses_post($this->field['title']) . wp_kses_post($this->field['desc']) . '</p>'; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
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;">'; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Enqueue Function. |
| 149 |
* If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
| 150 |
* |
| 151 |
* @since 1.0.0 |
| 152 |
* @access public |
| 153 |
* @return void |
| 154 |
*/ |
| 155 |
public function enqueue() { |
| 156 |
if ($this->parent->args['dev_mode']) { |
| 157 |
wp_enqueue_style( |
| 158 |
'redux-field-info-css', |
| 159 |
ReduxFramework::$_url . 'inc/fields/info/field_info.css', |
| 160 |
array(), |
| 161 |
time(), |
| 162 |
'all' |
| 163 |
); |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
} |