| 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( 'ADMINIFY_Field_sorter' ) ) { |
| 11 |
class ADMINIFY_Field_sorter extends ADMINIFY_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 |
$args = wp_parse_args( |
| 19 |
$this->field, |
| 20 |
[ |
| 21 |
'disabled' => true, |
| 22 |
'enabled_title' => esc_html__( 'Enabled', 'adminify' ), |
| 23 |
'disabled_title' => esc_html__( 'Disabled', 'adminify' ), |
| 24 |
] |
| 25 |
); |
| 26 |
|
| 27 |
echo wp_kses_post( $this->field_before() ); |
| 28 |
|
| 29 |
$this->value = ( ! empty( $this->value ) ) ? $this->value : $this->field['default']; |
| 30 |
$enabled_options = ( ! empty( $this->value['enabled'] ) ) ? $this->value['enabled'] : []; |
| 31 |
$disabled_options = ( ! empty( $this->value['disabled'] ) ) ? $this->value['disabled'] : []; |
| 32 |
|
| 33 |
echo '<div class="adminify-sorter" data-depend-id="' . esc_attr( $this->field['id'] ) . '"></div>'; |
| 34 |
|
| 35 |
echo ( $args['disabled'] ) ? '<div class="adminify-modules">' : ''; |
| 36 |
|
| 37 |
echo ( ! empty( $args['enabled_title'] ) ) ? '<div class="adminify-sorter-title">' . esc_attr( $args['enabled_title'] ) . '</div>' : ''; |
| 38 |
echo '<ul class="adminify-enabled">'; |
| 39 |
if ( ! empty( $enabled_options ) ) { |
| 40 |
foreach ( $enabled_options as $key => $value ) { |
| 41 |
echo '<li><input type="hidden" name="' . esc_attr( $this->field_name( '[enabled][' . $key . ']' ) ) . '" value="' . esc_attr( $value ) . '"/><label>' . esc_attr( $value ) . '</label></li>'; |
| 42 |
} |
| 43 |
} |
| 44 |
echo '</ul>'; |
| 45 |
|
| 46 |
// Check for hide/show disabled section |
| 47 |
if ( $args['disabled'] ) { |
| 48 |
echo '</div>'; |
| 49 |
|
| 50 |
echo '<div class="adminify-modules">'; |
| 51 |
echo ( ! empty( $args['disabled_title'] ) ) ? '<div class="adminify-sorter-title">' . esc_attr( $args['disabled_title'] ) . '</div>' : ''; |
| 52 |
echo '<ul class="adminify-disabled">'; |
| 53 |
if ( ! empty( $disabled_options ) ) { |
| 54 |
foreach ( $disabled_options as $key => $value ) { |
| 55 |
echo '<li><input type="hidden" name="' . esc_attr( $this->field_name( '[disabled][' . $key . ']' ) ) . '" value="' . esc_attr( $value ) . '"/><label>' . esc_attr( $value ) . '</label></li>'; |
| 56 |
} |
| 57 |
} |
| 58 |
echo '</ul>'; |
| 59 |
echo '</div>'; |
| 60 |
} |
| 61 |
|
| 62 |
echo wp_kses_post( $this->field_after() ); |
| 63 |
} |
| 64 |
|
| 65 |
public function enqueue() { |
| 66 |
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) { |
| 67 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
} |
| 73 |
|