コード例 #1
0
/**
* Function for loading and upgrading options
*
* Loads options on 'admin_menu' hook.
* Completely re-written - changed to "incremental" upgrading in v3.3.3
*
* Called by dfcg_add_page() which is hooked to 'admin_menu'
*
* In 2.3 - "imagepath" is deprecated, replaced by "imageurl" in 2.3
* In 2.3 - "defimagepath" is deprecated, replaced by "defimgmulti" and "defimgonecat"
* In 2.3 - 29 orig options + 30 new options added , total now is 59
*
* In RC2 - Change: "nourl" value of "image-url-type" is deprecated
*
* In RC3 - Added 2: "posts-column", "pages-column" added
* In RC3 - Total options is 59 + 2 = 61
*
* In RC4 - Added 13: "posts-desc-column", "pages-desc-column", "just-reset", "scripts", 9 jQuery options
* In RC4 - Change: "part" value of "image-url-type" is changed to "partial"
* In RC4 - Total options is 61 + 13 = 74
*
* In 3.1 - Added 7: "desc-method", "max-char", "more-text", "slide-p-a-color", "slide-p-ahover-color", "slide-p-a-weight", "slide-p-ahover-weight"
* In 3.1 - Total options = 74 + 7 = 81
*
* In 3.2 - Change: "desc-method" can now have three values - auto, manual, none
* In 3.2 - Added 2: 'pages-sort-column', 'pages-sort-control'
* In 3.2 - Total options = 81 + 2 = 83
*
* In 3.2.2 - Added 1: 'page-ids'
* In 3.2.2 - Change: new value 'page' added to 'limit-scripts' option
* In 3.2.2 - Total options = 83 + 1 = 84
*
* In 3.3 - Change: new value 'auto' added to 'image-url-type' option
* In 3.3 - Change: 'pages-selected' option renamed as 'ids-selected' (handles Post and Page IDs)
* In 3.3 - Change: 'defimgpages' option renamed as 'defimgid'
* In 3.3 - Change: 'pages-sort-control' option renamed as 'id-sort-control'
* In 3.3 - Change: 'pages' value of "populate-method" is changed to 'id-method'
* In 3.3 - Deleted 6: 'nav-theme', 'pause-on-hover', 'transition-speed', 'fade-panels', 'slide-overlay-position', 'gallery-background'
* In 3.3 - Added 5: 'thumb-type' 'defimgcustompost', 'custom-post-type', 'custom-post-type-number', 'custom-post-type-tax'
* In 3.3 - Change: 'custom-post' value added to 'populate-method' option
* In 3.3 - Total options = 84 - 6 + 5 = 83
*
* In 3.3.1 - Corrected '==' syntax to '=' for new options that should have been added in 3.3. What an idiot,eh?
*
* In 3.3.2 - Added 1: 'showArrows' for mootools and jQuery
* In 3.3.2 - Total options = 83 + 1 = 84
*
* In 3.3.3 - Total options = 84
*
* In 3.3.4 - Added 'slideInfoZoneStatic' options for fixed or sliding Slide Pane with jQuery
* In 3.3.4 - Added 'gallery-background' option - mootools and jquery
*
* In 3.4.4 - Total options = 84 + 2 = 86
*
* In 3.3.5 - No change. Total options = 86
*
* In 3.3.6 - No change. Total options = 86
*
* @uses dfcg_default_options()
* @since 3.2.2
* @updated 3.3.6
*/
function dfcg_set_gallery_options()
{
    // Get current version number (first introduced in 3.0 beta / 2.3)
    $existing_version = get_option('dfcg_version');
    // Existing version is same as this version - nothing to do here...
    if ($existing_version == DFCG_VER) {
        return;
    }
    /***** Ok, we need to do something - let's prepare some stuff *****/
    // Clean up version numbers, otherwise version_compare won't always work as expected
    if ($existing_version == '3.0 RC2') {
        $existing_version = '2.3.2';
    }
    if ($existing_version == '3.0 RC3') {
        $existing_version = '2.3.3';
    }
    if ($existing_version == '3.0 RC4') {
        $existing_version = '2.3.4';
    }
    $postmeta_upgrade = get_option('dfcg_plugin_postmeta_upgrade');
    $existing_opts = get_option('dfcg_plugin_settings');
    /***** Clean install - it's a wasteland here *****/
    if (empty($existing_version) && empty($postmeta_upgrade) && empty($existing_opts)) {
        $new_opts = dfcg_default_options();
        add_option('dfcg_plugin_settings', $new_opts);
        add_option('dfcg_version', DFCG_VER);
        $postmeta_upgrade = array();
        $postmeta_upgrade['upgraded'] = 'completed';
        add_option('dfcg_plugin_postmeta_upgrade', $postmeta_upgrade);
        return;
    }
    /***** Logic check in case $existing_version exists but there are no $existing_opts - eg bad uninstall *****/
    if ($existing_version && empty($existing_opts)) {
        $new_opts = dfcg_default_options();
        // Clean reinstall
        add_option('dfcg_plugin_settings', $new_opts);
        update_option('dfcg_version', DFCG_VER);
        // Check if postmeta was ever run
        if ($postmeta_upgrade['upgraded'] !== 'completed') {
            delete_option('dfcg_plugin_postmeta_upgrade');
            // Force postmeta to be re-run when Settings page is loaded
        }
        return;
    }
    /***** Logic check in case $existing_version doesn't exist but there are $existing_opts *****/
    if (empty($existing_version) && $existing_opts) {
        $existing_version = '2.2';
        // Force upgrades to be run
    }
    /***** Upgrade to 2.3 from 2.2 *****/
    if (version_compare($existing_version, '2.3', '<')) {
        // 29 options
        //$existing = get_option( 'dfcg_plugin_settings' );
        // Add 1 new option - Assign old imagepath to new imageurl
        $existing_opts['imageurl'] = $existing_opts['homeurl'] . $existing_opts['imagepath'];
        // Add 2 new options - Assign old defimagepath to defimgmulti and defimgonecat
        $existing_opts['defimgmulti'] = $existing_opts['homeurl'] . $existing_opts['defimagepath'];
        $existing_opts['defimgonecat'] = $existing_opts['homeurl'] . $existing_opts['defimagepath'];
        // Delete 2 options
        unset($existing_opts['imagepath']);
        unset($existing_opts['defimagepath']);
        // Add new 29 options
        $new_opts = array('populate-method' => 'multi-option', 'cat-display' => '1', 'posts-number' => '5', 'pages-selected' => '', 'image-url-type' => 'partial', 'defimgpages' => '', 'slide-h2-padtb' => '0', 'slide-h2-padlr' => '0', 'slide-p-padtb' => '0', 'slide-p-padlr' => '0', 'limit-scripts' => 'homepage', 'page-filename' => '', 'timed' => 'true', 'delay' => '9000', 'showCarousel' => 'true', 'showInfopane' => 'true', 'slideInfoZoneSlide' => 'true', 'slideInfoZoneOpacity' => '0.7', 'textShowCarousel' => 'Featured Articles', 'defaultTransition' => 'fade', 'cat06' => '1', 'cat07' => '1', 'cat08' => '1', 'cat09' => '1', 'off06' => '', 'off07' => '', 'off08' => '', 'off09' => '', 'errors' => 'true');
        // Total options = 29 + 1 + 2 - 2 + 29 = 59
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.0 RC2 (2.3.2) from 2.3 (aka 3.0 beta) *****/
    if (version_compare($existing_version, '2.3.2', '<')) {
        // 59 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Value 'nourl' is deprecated
        if ($existing_opts['image-url-type'] == 'nourl') {
            $existing_opts['image-url-type'] = 'part';
        }
        // Total options = 59
        update_option('dfcg_plugin_settings', $existing_opts);
    }
    /***** Upgrade to 3.0 RC3 (2.3.3) from 3.0 RC2 *****/
    if (version_compare($existing_version, '2.3.3', '<')) {
        // 59 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Add new 2 options
        $new_opts = array('posts-column' => 'true', 'pages-column' => 'true');
        // Total options = 59 + 2 = 61
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.0 RC4 (2.3.4) from 3.0 RC3 *****/
    if (version_compare($existing_version, '2.3.4', '<')) {
        // 61 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // 'part' changed to 'partial'
        if ($existing_opts['image-url-type'] == 'part') {
            $existing_opts['image-url-type'] = 'partial';
        }
        // Add new 13 options
        $new_opts = array('posts-desc-column' => 'true', 'pages-desc-column' => 'true', 'just-reset' => 'false', 'scripts' => 'mootools', 'slide-h2-weight' => 'bold', 'slide-p-line-height' => '14', 'slide-overlay-color' => '#000000', 'slide-overlay-position' => 'bottom', 'transition-speed' => '1500', 'nav-theme' => 'light', 'pause-on-hover' => 'true', 'fade-panels' => 'true', 'gallery-background' => '#000000');
        // Total options = 61 + 13 = 74
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.0 from 3.0 RC4 *****/
    if (version_compare($existing_version, '3.0', '<')) {
        // Nothing to do here...
    }
    /***** Upgrade to 3.1 from 3.0 *****/
    if (version_compare($existing_version, '3.1', '<')) {
        // 74 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Add new 7 options
        $new_opts = array('desc-method' => 'manual', 'max-char' => '100', 'more-text' => '[more]', 'slide-p-a-color' => '#FFFFFF', 'slide-p-ahover-color' => '#FFFFFF', 'slide-p-a-weight' => 'normal', 'slide-p-ahover-weight' => 'bold');
        // Total options = 74 + 7 = 81
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.2 from 3.1 *****/
    if (version_compare($existing_version, '3.2', '<')) {
        // 81 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Add new 2 options
        $new_opts = array('pages-sort-column' => 'true', 'pages-sort-control' => 'false');
        // Total options = 81 + 2 = 83
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.2.1 from 3.2 *****/
    if (version_compare($existing_version, '3.2.1', '<')) {
        // Nothing to do here...
    }
    /***** Upgrade to 3.2.2 from 3.2.1 *****/
    if (version_compare($existing_version, '3.2.2', '<')) {
        // 83 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Add new 1 option
        $new_opts = array('page-ids' => '');
        // Total options = 83 + 1 = 84
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.2.3 from 3.2.2 *****/
    if (version_compare($existing_version, '3.2.3', '<')) {
        // Nothing to do here...
    }
    /***** Upgrade to 3.3 from 3.2.3 *****/
    if (version_compare($existing_version, '3.3', '<')) {
        // 84 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Add new 3 options = renamed old options
        $existing_opts['ids-selected'] = $existing_opts['pages-selected'];
        $existing_opts['defimgid'] = $existing_opts['defimgpages'];
        $existing_opts['id-sort-control'] = $existing_opts['pages-sort-control'];
        // 'pages' changed to 'id-method'
        if ($existing_opts['populate-method'] == 'pages') {
            $existing_opts['populate-method'] = 'id-method';
        }
        // Delete 3 deprecated options (renamed in 3.3)
        unset($existing_opts['pages-selected']);
        unset($existing_opts['defimgpages']);
        unset($existing_opts['pages-sort-control']);
        // Delete 6 deprecated options
        unset($existing_opts['nav-theme']);
        unset($existing_opts['pause-on-hover']);
        unset($existing_opts['transition-speed']);
        unset($existing_opts['fade-panels']);
        unset($existing_opts['slide-overlay-position']);
        unset($existing_opts['gallery-background']);
        // Add new 5 options
        $new_opts = array('thumb-type' => 'legacy', 'custom-post-type' => '', 'custom-post-type-tax' => '', 'custom-post-type-number' => '5', 'defimgcustompost' => '');
        // Total options = 84 + 3 - 3 - 6 + 5 = 83
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.3.1 from 3.3 *****/
    if (version_compare($existing_version, '3.3.1', '<')) {
        // Nothing to do here...
    }
    /***** Upgrade to 3.3.2 from 3.3.1 *****/
    if (version_compare($existing_version, '3.3.2', '<')) {
        // 83 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Add new 1 options
        $new_opts = array('showArrows' => 'true');
        // Total options = 83 + 1 = 84
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.3.3 from 3.3.2 *****/
    if (version_compare($existing_version, '3.3.3', '<')) {
        // Nothing to do here...
    }
    /***** Upgrade to 3.3.4 from 3.3.3 *****/
    if (version_compare($existing_version, '3.3.4', '<')) {
        // 84 options
        $existing_opts = get_option('dfcg_plugin_settings');
        // Add new 1 option
        $new_opts = array('slideInfoZoneStatic' => 'false', 'gallery-background' => '#000000');
        // Total options = 84 + 2 = 85
        $updated = wp_parse_args($existing_opts, $new_opts);
        update_option('dfcg_plugin_settings', $updated);
    }
    /***** Upgrade to 3.3.5 from 3.3.4 *****/
    if (version_compare($existing_version, '3.3.5', '<')) {
        // Nothing to do here...
    }
    /***** Upgrade to 3.3.6 from 3.3.5 *****/
    if (version_compare($existing_version, '3.3.6', '<')) {
        // Nothing to do here...
    }
    // FINALLY, Update version no. in the db
    update_option('dfcg_version', DFCG_VER);
}
コード例 #2
0
/**
* Settings API callback function
*
* @param array $input $_POST input from form
* @global array $dfcg_options plugin options from db
* @return $input Sanitised form input ready for db
* @since 3.2.2
* @updated 3.3.4
*/
function dfcg_sanitise($input)
{
    global $dfcg_options;
    // Is the user allowed to do this? Probably not needed...
    if (function_exists('current_user_can') && !current_user_can('manage_options')) {
        die(__('Sorry. You do not have permission to do this.', DFCG_DOMAIN));
    }
    /* If RESET is checked, reset the options, and don't bother sanitising */
    if ($input['reset'] == "1") {
        // put back the defaults
        $input = dfcg_default_options();
        // we need this for use in add_action('admin_notices', 'dfcg_notice_reset')
        $input['just-reset'] = esc_attr('true');
        return $input;
    }
    /***** Some error messages for later *****/
    // Generic error message - triggered by wp_die
    $dfcg_sanitise_error = esc_attr__('An error has occurred. Go back and try again.', DFCG_DOMAIN);
    /***** Now correct certain options *****/
    // trim whitespace - all options
    foreach ($input as $key => $value) {
        $input[$key] = trim($value);
    }
    // deal with just-reset option, overwrite it in case it's 'true'
    $input['just-reset'] = '0';
    // deal with One Category Method "All" option to suppress WP_Class Error if category_description() is passed a '0'.
    // WP_Query will fail gracefully because cat='' is ignored
    // TODO: Probably not needed now due to sanitisation routines below
    if ($input['cat-display'] == 0) {
        $input['cat-display'] = '';
    }
    /***** Organise the options by type etc, into arrays, then sanitise / validate / format correct *****/
    //	Whitelist options													(10)	(10)
    //	Path and URL options												(6)		(1)
    //	On-off options														(1)
    //	Bool options														(15)
    //	String options - no XHTML allowed									(5)
    //	String options - some XHTML allowed									(1)
    //	String options - CSS hexcodes										(7)
    //	String options - numeric comma separated only 						(2)
    //	String options - filenames											(1)
    //	Integer options - positive - can be blank, can't be zero 			(9)
    //	Integer options - positive - can be blank, can't be zero 			(1)
    //	Integer options - positive - can't be blank, can't be zero 			(9)
    //	Integer options - positive integer - can't be blank, can be zero 	(18)
    //	Integer options - positive - large									(1)
    //	Total 																85
    /***** Whitelist options (10/10) *****/
    if (function_exists('wpmu_create_blog')) {
        // We're in WPMU
        $whitelist_opts = array('image-url-type', 'populate-method', 'defaultTransition', 'limit-scripts', 'scripts', 'slide-h2-weight', 'desc-method', 'slide-p-a-weight', 'slide-p-ahover-weight', 'thumb-type');
    } else {
        // We're in WP
        $whitelist_opts = array('image-url-type', 'populate-method', 'defaultTransition', 'limit-scripts', 'scripts', 'slide-h2-weight', 'desc-method', 'slide-p-a-weight', 'slide-p-ahover-weight', 'thumb-type');
    }
    // Define whitelist of known values
    $dfcg_whitelist = array('full', 'partial', 'multi-option', 'one-category', 'id-method', 'custom-post', 'fade', 'fadeslideleft', 'continuousvertical', 'continuoushorizontal', 'homepage', 'pagetemplate', 'other', 'mootools', 'jquery', 'bold', 'normal', 'manual', 'auto', 'none', 'page', 'post-thumbnails', 'legacy');
    // sanitise
    foreach ($whitelist_opts as $key) {
        // If option value is not in whitelist
        if (!in_array($input[$key], $dfcg_whitelist)) {
            //Used for testing: $input[$key] = 'dodgy';
            //var_dump($key, $input[$key]);
            wp_die("Dynamic Content Gallery Message #20: " . $dfcg_sanitise_error . "<br />Error with option: " . $key . "<br />Value: " . $input[$key]);
        }
    }
    /***** Path and URL options (6/1) *****/
    if (function_exists('wpmu_create_blog')) {
        // We're in WPMU
        $abs_url_opts = array('homeurl');
    } else {
        // We're in WP
        $abs_url_opts = array('imageurl', 'defimgmulti', 'defimgonecat', 'defimgid', 'defimgcustompost', 'homeurl');
    }
    // sanitise and add trailing slash
    foreach ($abs_url_opts as $key) {
        if (!empty($input[$key])) {
            if ($key == 'defimgid') {
                // Sanitise for db only
                $input[$key] = esc_url_raw($input[$key]);
            } else {
                // Trailingslashit if there is something to do it to
                $input[$key] = trailingslashit($input[$key]);
                // Sanitise for db
                $input[$key] = esc_url_raw($input[$key]);
            }
        }
    }
    /***** On-off options (1) *****/
    $onoff_opts = array('mootools');
    // sanitise, cast as 1 or 0, eg MOOTOOLS checkbox
    foreach ($onoff_opts as $key) {
        $input[$key] = $input[$key] ? '1' : '0';
    }
    /***** Bool options (15) *****/
    $bool_opts = array('reset', 'showCarousel', 'showInfopane', 'timed', 'slideInfoZoneSlide', 'errors', 'posts-column', 'pages-column', 'posts-desc-column', 'pages-desc-column', 'just-reset', 'pages-sort-column', 'id-sort-control', 'showArrows', 'slideInfoZoneStatic');
    // sanitise, eg RESET checkbox
    foreach ($bool_opts as $key) {
        $input[$key] = $input[$key] ? 'true' : 'false';
    }
    /***** String options - no XHTML allowed (5) *****/
    $str_opts_no_html = array('textShowCarousel', 'slideInfoZoneOpacity', 'more-text', 'custom-post-type', 'custom-post-type-tax');
    // sanitise
    foreach ($str_opts_no_html as $key) {
        // Extract first 50 characters (v3.2: increased from 25 chars to allow longer Featured Article text)
        $input[$key] = substr($input[$key], 0, 50);
        $input[$key] = wp_filter_nohtml_kses($input[$key]);
    }
    /***** String options - some XHTML allowed (1) *****/
    $str_opts_html = array('defimagedesc');
    // Note, form already includes stripslashes
    $allowed_html = array('a' => array('href' => array(), 'title' => array()), 'br' => array(), 'em' => array(), 'strong' => array());
    $allowed_protocols = array('http', 'https', 'mailto', 'feed');
    // sanitise
    foreach ($str_opts_html as $key) {
        $input[$key] = wp_kses($input[$key], $allowed_html, $allowed_protocols);
    }
    /***** String options - CSS hexcodes () *****/
    $str_opts_hexcode = array('gallery-border-colour', 'slide-h2-colour', 'slide-p-colour', 'slide-overlay-color', 'slide-p-a-color', 'slide-p-ahover-color', 'gallery-background');
    // TODO: This could be improved - regex doesn't validate whether a valid hex code.
    // deal with String options - CSS hexcodes
    foreach ($str_opts_hexcode as $key) {
        // Strip out any whitespace within list
        $input[$key] = str_replace(" ", "", $input[$key]);
        // If first character in string is not a #
        if (!substr($input[$key], 0, 1) == '#') {
            // Add one
            $input[$key] = substr_replace($input[$key], '#', 0, 0);
        }
        // Extract first 7 characters
        $input[$key] = substr($input[$key], 0, 7);
        // Make sure value contains only allowed numbers and characters
        if (!preg_match_all('/^[#A-Za-z0-9]+$/i', $input[$key], $result)) {
            // If not, revert to existing value
            $input[$key] = $dfcg_options[$key];
        }
    }
    /***** String options - numeric comma separated only (2) *****/
    $str_opts_csv_num = array('ids-selected', 'page-ids');
    // sanitise
    foreach ($str_opts_csv_num as $key) {
        if (!empty($input[$key])) {
            // Strip out any whitespace within list
            $input[$key] = str_replace(" ", "", $input[$key]);
            // If first character in string is a comma
            if (substr($input[$key], 0, 1) == ',') {
                // Remove the first comma in the list
                $input[$key] = substr($input[$key], 1);
            }
            // If last character in string is a comma
            if (substr($input[$key], -1) == ',') {
                // Remove the final comma in the list
                $input[$key] = substr($input[$key], 0, substr($input[$key], -1) - 1);
            }
            // Make sure list only contains numbers and commas
            if (!preg_match_all('/^[0-9,]+$/i', $input[$key], $result)) {
                // Resets the dodgy $input to the existing value. Better user-experience in case of failure.
                $input[$key] = $dfcg_options[$key];
            }
        }
    }
    /***** String options - filenames (1) *****/
    $str_opts_filename = array('page-filename');
    // This can be a comma separated list of page template filenames
    // sanitise
    foreach ($str_opts_filename as $key) {
        if (!empty($input[$key])) {
            // Convert filename list to array
            $filenames = explode(',', $input[$key]);
            foreach ($filenames as $filename) {
                // Strip out any whitespace within list
                $filename = str_replace(" ", "", $filename);
                // Make sure filename is alpha-num plus hypens and underscores with .php extension
                if (preg_match_all('/^([A-Za-z0-9_-]+(?=\\.(php))\\.\\2)$/i', $filename, $result)) {
                    // Add ok filename to temp array
                    $temp_array[] = $filename;
                }
            }
            // Convert array back to comma separated list
            $input[$key] = implode(',', $temp_array);
        }
    }
    /***** Integer options - positive - can be blank, can't be 0 (9) *****/
    $int_opts_can_be_blank = array('off01', 'off02', 'off03', 'off04', 'off05', 'off06', 'off07', 'off08', 'off09');
    // sanitise, but leave blank as empty, not 0
    foreach ($int_opts_can_be_blank as $key) {
        //
        if ($input[$key] == 0 || $input[$key] == '0') {
            $input[$key] = '';
        } else {
            // Strip out any whitespace within
            $input[$key] = str_replace(" ", "", $input[$key]);
            // Extract first 2 characters
            $input[$key] = substr($input[$key], 0, 2);
            // Cast as integer
            $input[$key] = absint($input[$key]);
        }
    }
    /***** Integer options - positive - can be blank, can't be 0 (1) *****/
    // Note: cat-display can be blank to avoid WP_Query error on first loading plugin
    $int_opts_can_be_blank_big = array('cat-display');
    // sanitise, but leave blank as empty, not 0
    foreach ($int_opts_can_be_blank_big as $key) {
        //
        if ($input[$key] == 0 || $input[$key] == '0') {
            $input[$key] = '';
        } else {
            // Strip out any whitespace within
            $input[$key] = str_replace(" ", "", $input[$key]);
            // Extract first 4 characters
            $input[$key] = substr($input[$key], 0, 4);
            // Cast as integer
            $input[$key] = absint($input[$key]);
        }
    }
    /***** Integer options - positive - can't be blank, can't be zero (9) *****/
    // Theoretically, this isn't needed, unless user turns off Select boxes in browser
    $int_opts_nonblank_nonzero = array('cat01', 'cat02', 'cat03', 'cat04', 'cat05', 'cat06', 'cat07', 'cat08', 'cat09');
    // sanitise, but leave blank and zero as 1
    foreach ($int_opts_nonblank_nonzero as $key) {
        //
        if (empty($input[$key])) {
            $input[$key] = 1;
        } else {
            // Extract first 6 characters - increased from 4 to allow for big cat ID numbers
            $input[$key] = substr($input[$key], 0, 6);
            // Cast as integer
            $input[$key] = absint($input[$key]);
        }
    }
    /***** Integer options - positive integer - can't be blank, can be zero (18) *****/
    $int_opts_nonblank = array('posts-number', 'gallery-width', 'gallery-height', 'gallery-border-thick', 'slide-height', 'slide-h2-size', 'slide-h2-padtb', 'slide-h2-padlr', 'slide-h2-marglr', 'slide-h2-margtb', 'slide-p-size', 'slide-p-padtb', 'slide-p-padlr', 'slide-p-marglr', 'slide-p-margtb', 'slide-p-line-height', 'max-char', 'custom-post-type-number');
    // sanitise, limit to 4 chars, convert blanks to 0
    foreach ($int_opts_nonblank as $key) {
        // Strip out any whitespace within
        $input[$key] = str_replace(" ", "", $input[$key]);
        // Extract first 4 characters
        $input[$key] = substr($input[$key], 0, 4);
        // Cast as integer
        $input[$key] = absint($input[$key]);
    }
    /***** Integer options - positive - large (1) *****/
    $int_opts_large = array('delay');
    // sanitise, limit to 5 chars, can't be blank, minimum value = 1000
    foreach ($int_opts_large as $key) {
        // Strip out any whitespace within
        $input[$key] = str_replace(" ", "", $input[$key]);
        // Extract first 5 characters
        $input[$key] = substr($input[$key], 0, 5);
        // Cast as integer
        $input[$key] = absint($input[$key]);
        // Minimum value = 1000 (otherwise gallery js script will go crazy)
        $min_value = 1000;
        if ($input[$key] < $min_value) {
            $input[$key] = 1000;
        }
    }
    /***** String options (2) *****/
    // Return sanitised options array ready for db
    return $input;
}