| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
/** |
| 4 |
* |
| 5 |
* Field: sorter |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'DARKIFY_Field_sorter' ) ) { |
| 11 |
class DARKIFY_Field_sorter extends DARKIFY_Fields { |
| 12 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
|
| 19 |
$args = wp_parse_args( |
| 20 |
$this->field, |
| 21 |
array( |
| 22 |
'disabled' => true, |
| 23 |
'enabled_title' => esc_html__( 'Enabled', 'darkify' ), |
| 24 |
'disabled_title' => esc_html__( 'Disabled', 'darkify' ), |
| 25 |
) |
| 26 |
); |
| 27 |
|
| 28 |
echo wp_kses_post( $this->field_before() ); |
| 29 |
|
| 30 |
$this->value = ( ! empty( $this->value ) ) ? $this->value : $this->field['default']; |
| 31 |
$enabled_options = ( ! empty( $this->value['enabled'] ) ) ? $this->value['enabled'] : array(); |
| 32 |
$disabled_options = ( ! empty( $this->value['disabled'] ) ) ? $this->value['disabled'] : array(); |
| 33 |
|
| 34 |
echo '<div class="darkify-sorter" data-depend-id="' . esc_attr( $this->field['id'] ) . '"></div>'; |
| 35 |
|
| 36 |
echo ( $args['disabled'] ) ? '<div class="darkify-modules">' : ''; |
| 37 |
|
| 38 |
echo ( ! empty( $args['enabled_title'] ) ) ? '<div class="darkify-sorter-title">' . esc_attr( $args['enabled_title'] ) . '</div>' : ''; |
| 39 |
echo '<ul class="darkify-enabled">'; |
| 40 |
if ( ! empty( $enabled_options ) ) { |
| 41 |
foreach ( $enabled_options as $key => $value ) { |
| 42 |
echo '<li><input type="hidden" name="' . esc_attr( $this->field_name( '[enabled][' . $key . ']' ) ) . '" value="' . esc_attr( $value ) . '"/><label>' . esc_attr( $value ) . '</label></li>'; |
| 43 |
} |
| 44 |
} |
| 45 |
echo '</ul>'; |
| 46 |
|
| 47 |
// Check for hide/show disabled section |
| 48 |
if ( $args['disabled'] ) { |
| 49 |
|
| 50 |
echo '</div>'; |
| 51 |
|
| 52 |
echo '<div class="darkify-modules">'; |
| 53 |
echo ( ! empty( $args['disabled_title'] ) ) ? '<div class="darkify-sorter-title">' . esc_attr( $args['disabled_title'] ) . '</div>' : ''; |
| 54 |
echo '<ul class="darkify-disabled">'; |
| 55 |
if ( ! empty( $disabled_options ) ) { |
| 56 |
foreach ( $disabled_options as $key => $value ) { |
| 57 |
echo '<li><input type="hidden" name="' . esc_attr( $this->field_name( '[disabled][' . $key . ']' ) ) . '" value="' . esc_attr( $value ) . '"/><label>' . esc_attr( $value ) . '</label></li>'; |
| 58 |
} |
| 59 |
} |
| 60 |
echo '</ul>'; |
| 61 |
echo '</div>'; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
echo wp_kses_post( $this->field_after() ); |
| 66 |
} |
| 67 |
|
| 68 |
public function enqueue() { |
| 69 |
|
| 70 |
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) { |
| 71 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|