Add drag-and-drop template layout options

This commit is contained in:
Brian Miyaji
2016-04-02 18:39:17 +11:00
parent bd565b16bb
commit e611b00a92
10 changed files with 568 additions and 129 deletions

View File

@@ -19,7 +19,8 @@ class SP_Settings_Page {
protected $id = '';
protected $label = '';
protected $template = '';
public $templates = array();
/**
* Add this page to settings
*/
@@ -56,8 +57,69 @@ class SP_Settings_Page {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
if ( $current_section )
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section );
if ( $current_section )
do_action( 'sportspress_update_options_' . $this->template . '_' . $current_section );
if ( ! empty( $this->templates ) )
update_option( 'sportspress_' . $this->template . '_template_order', sp_array_value( $_POST, 'sportspress_' . $this->template . '_template_order', false ) );
if ( isset( $_POST['sportspress_template_visibility'] ) && is_array( $_POST['sportspress_template_visibility'] ) ) {
foreach ( $_POST['sportspress_template_visibility'] as $option => $toggled ) {
if ( $toggled ) {
update_option( $option, 'yes' );
} else {
update_option( $option, 'no' );
}
}
}
}
/**
* Layout settings
*
* @access public
* @return void
*/
public function layout_setting() {
$templates = apply_filters( 'sportspress_' . $this->template . '_templates', $this->templates );
$layout = get_option( 'sportspress_' . $this->template . '_template_order' );
if ( false === $layout ) {
$layout = array_keys( $templates );
}
$templates = array_merge( array_flip( $layout ), $templates );
?>
<tr valign="top">
<th>
<?php _e( 'Layout', 'sportspress' ); ?>
</th>
<td class="sp-sortable-list-container">
<p class="description"><?php _e( 'Drag each item into the order you prefer.', 'sportspress' ); ?></p>
<ul class="sp-layout sp-sortable-list ui-sortable">
<?php foreach ( $templates as $template => $details ) {
$option = sp_array_value( $details, 'option', 'sportspress_' . $this->template . '_show_' . $template );
$visibility = get_option( $option, sp_array_value( $details, 'default', 'yes' ) );
?>
<li>
<div class="sp-item-bar sp-layout-item-bar">
<div class="sp-item-handle sp-layout-item-handle ui-sortable-handle">
<span class="sp-item-title item-title"><?php echo sp_array_value( $details, 'title', ucfirst( $template ) ); ?></span>
<input type="hidden" name="sportspress_<?php echo $this->template; ?>_template_order[]" value="<?php echo $template; ?>">
</div>
<input type="hidden" name="sportspress_template_visibility[<?php echo $option; ?>]" value="0">
<input class="sp-toggle-switch" type="checkbox" name="sportspress_template_visibility[<?php echo $option; ?>]" id="<?php echo $option; ?>" value="1" <?php checked( $visibility, 'yes' ); ?>>
<label for="sportspress_<?php echo $this->template; ?>_show_<?php echo $template; ?>"></label>
</div>
</li>
<?php } ?>
</ul>
</td>
</tr>
<?php
}
}