This is an extension of Update Option Stored in Multi-Dimensional Array which was help getting draggable plugin options to save via ajax (which works), but unfortunately this is specific to the actual plugin settings saving to the database correctly. Ajax re-ordering works, but upon page-save (plugin settings save), the options are cleared from the database. Here is the settings page:
<?php
function mouldings_options_page() {
global $mouldings_options;
ob_start(); ?>
<div class="wrap">
<h2 style="margin: 0 0 5px;"><?php _e('Mouldings Options','roots'); ?></h2>
<form method="post" action="options.php" id="mouldings_options">
<?php settings_fields('mouldings_settings_group'); ?>
<div id="thumbnail-sizes" class="wp-box">
<div class="wp-box-half left">
<div class="inner">
<h2><?php _e('Thumbnail Sizes'); ?></h2>
<table class="widefat">
<thead>
<tr>
<th><?php _e('Post Type','roots'); ?></th>
<th><?php _e('Width (px)','roots'); ?></th>
<th><?php _e('Height (px)','roots'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><label class="description" for="mouldings_settings[idea_gallery_thumb_height]"><?php _e('Idea Gallery','roots'); ?></label></td>
<td><input id="mouldings_settings[idea_gallery_thumb_height]" name="mouldings_settings[idea_gallery_thumb_height]" type="text" value="<?php echo (isset($mouldings_options['idea_gallery_thumb_height'])) ? $mouldings_options['idea_gallery_thumb_height'] : ''; ?>"></td>
<td><input id="mouldings_settings[idea_gallery_thumb_width]" name="mouldings_settings[idea_gallery_thumb_width]" type="text" value="<?php echo (isset($mouldings_options['idea_gallery_thumb_width'])) ? $mouldings_options['idea_gallery_thumb_width'] : ''; ?>"></td>
</tr>
<tr>
<td><label class="description" for="mouldings_settings[collection_thumb_height]"><?php _e('Moulding Collection','roots'); ?></label></td>
<td><input id="mouldings_settings[collection_thumb_height]" name="mouldings_settings[collection_thumb_height]" type="text" value="<?php echo (isset($mouldings_options['collection_thumb_height'])) ? $mouldings_options['collection_thumb_height'] : ''; ?>"></td>
<td><input id="mouldings_settings[collection_thumb_width]" name="mouldings_settings[collection_thumb_width]" type="text" value="<?php echo (isset($mouldings_options['collection_thumb_width'])) ? $mouldings_options['collection_thumb_width'] : ''; ?>"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="wp-box-half right">
<div class="inner">
<?php echo '<h2>'.__('Information','roots').'</h2>';
_e('<p>Used to resize the various images that appear throughout the Mouldings plugin. If any values are left blank, they are assumed to be un-restricted.</p>','roots'); ?>
<?php
if(function_exists('RegenerateThumbnails')) {
echo '<div class="m-updated"><p><a href="'.admin_url('tools.php?page=regenerate-thumbnails').'">Regenerate Thumbnails</a> after altering these values</p></div>';
}
else {
echo '<div class="m-error"><p><strong>Notice:</strong> <a href="'.admin_url('plugin-install.php?tab=search&type=term&s=regenerate+thumbnails&plugin-search-input=Search+Plugins').'">Regenerate Thumbnails</a> is not installed. This is required so that you can regenerate thumbnails after changing any of these values.</p></div>';
}
?>
</div>
</div>
<div class="clear"></div>
</div>
<div id="profile-sidebar-order" class="wp-box">
<div class="wp-box-half left">
<div class="inner">
<h2><?php _e('Profile Sidebar Order'); ?></h2>
<table class="widefat psort-list">
<thead>
<tr>
<th><?php _e('Name', 'roots'); ?></th>
<th><?php _e('Order', 'roots'); ?></th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
foreach($mouldings_options['profile_element_order'] as $key => $item) :
echo '<tr id="list_items_' . $key . '" class="list_item">';
echo '<td>' . $item . '</td>';
echo '<td>' . $count . '</td>';
echo '</tr>';
$count++;
endforeach;
?>
</tbody>
</table>
</div>
</div>
<div class="wp-box-half right">
<div class="inner">
<?php echo '<h2>'.__('Information','roots').'</h2>';
_e('<p>Drag \'n drop the order of the elements that appear on the sidebar for both Profiles and Combinations.</p>','roots'); ?>
</div>
</div>
<div class="clear"></div>
</div>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Options','roots'); ?>">
</p>
</form>
</div>
<?php
echo ob_get_clean();
}
function mouldings_plugin_admin_styles() {
wp_enqueue_style('mouldings-admin-styles', MOULDINGS_BASE_URL . 'css/admin-global.css','','',$media = 'all');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('mouldings-admin-settings-scripts', MOULDINGS_BASE_URL . 'js/admin-settings.js', array('jquery'), '', true);
}
function mouldings_add_options_link() {
$mouldings_options_page = add_options_page(__('Mouldings Options','roots'),__('Mouldings','roots'),'manage_options','mouldings-options','mouldings_options_page');
add_action( 'admin_print_styles-' . $mouldings_options_page, 'mouldings_plugin_admin_styles' );
}
add_action('admin_menu','mouldings_add_options_link');
function mouldings_register_settings() {
register_setting('mouldings_settings_group','mouldings_settings');
}
add_action('admin_init','mouldings_register_settings');
?>
I'm thinking this may have something to do with "how" the profile_element_order
items are rendered? They are properly created on activation using this hook:
<?php
function mouldings_activate() {
global $wpdb, $mouldings_options;
if( false == get_option( 'mouldings_settings' ) ) {
$mouldings_options = array(
'img_base64_enable' => '1',
'moulding_combination_page' => '',
'moulding_collection_page' => '',
'idea_gallery_thumb_height' => '200',
'idea_gallery_thumb_width' => '200',
'collection_thumb_height' => '200',
'collection_thumb_width' => '200',
'profile_item_columns' => '4',
'idea_item_columns' => '2',
'collections_item_columns' => '2',
'combinations_item_columns' => '4',
'profile_element_order' => array(
'Option 1',
'Option 2',
'Option 3',
'Option 4',
'Option 5'
)
);
update_option( 'mouldings_settings', $mouldings_options );
}
}
register_activation_hook( MOULDINGS_PLUGIN_FILE, 'mouldings_activate' );
but are removed upon save. Thanks!