Пример #1
0
function weaver_admin_page_process_options()
{
    /* Process all options - called upon entry to options forms */
    // echo("WEAVER-SETTINGS:"); var_dump($weaver_main_settings);
    // echo "POST-weaver-settings:" ; var_dump($_POST['weaver_main_settings']);
    // echo "POST-FULL:" ; var_dump($_POST);
    settings_errors();
    // display results from SAPI save settings
    /* ================ Weaver Upgrade 2020 Weaver buttons ================== */
    if (weaver_submitted('hide_import_old_weaver')) {
        weaver_setopt('wvr_hide_if_are_oldWeaver_opts', true);
        weaver_save_msg(__('Hide 2010 Weaver Notice', WEAVER_TRANSADMIN));
    }
    if (weaver_submitted('import_old_weaver')) {
        weaver_import_2010_weaver();
        weaver_save_msg(__("Previously existing settngs imported.", WEAVER_TRANSADMIN));
    }
    /* ================ Weaver Themes Tab ================== */
    if (weaver_submitted('setsubtheme') || weaver_submitted('setsubtheme2')) {
        /* seems like Mozilla doesn't like 2 sets of select inputs on same page, so we make up 2 ids/names to use */
        if (isset($_POST['setsubtheme'])) {
            $pID = 'ttw_subtheme';
        } else {
            $pID = 'ttw_subtheme2';
        }
        $cur_subtheme = weaver_filter_textarea($_POST[$pID]);
        /* must have been set to get here */
        if ($cur_subtheme == '') {
            $cur_subtheme = 'Wheat';
        }
        /* but just in case */
        /* now, I set all values for theme */
        weaver_activate_subtheme($cur_subtheme);
        $t = weaver_getopt('ttw_subtheme');
        if ($t == '') {
            $t = 'Wheat';
        }
        /* did we save a theme? */
        weaver_save_msg(__("Weaver current sub-theme set to: ", WEAVER_TRANSADMIN) . $t);
    }
    /* ================ Weaver FTP File Access ================== */
    if (weaver_submitted('ftp_save_form')) {
        if (isset($_POST['ftp_hostnamex'])) {
            weaver_setopt('ftp_hostname', trim(weaver_filter_textarea($_POST['ftp_hostnamex'])));
        }
        if (isset($_POST['ftp_usernamex'])) {
            weaver_setopt('ftp_username', trim(weaver_filter_textarea($_POST['ftp_usernamex'])));
        }
        if (isset($_POST['ftp_passwordx'])) {
            weaver_setopt('ftp_password', weaver_encrypt(trim($_POST['ftp_passwordx'])));
        }
        if (isset($_POST['ftp_hide_check_messagex'])) {
            weaver_setopt('ftp_hide_check_message', true);
        } else {
            weaver_setopt('ftp_hide_check_message', false);
        }
        weaver_save_msg(__('FTP File Access Form Settings Saved.', WEAVER_TRANSADMIN));
    }
    /* ================ Weaver Main Options Tab ================== */
    /* Weaver Main and Advanced Options processed in validation callbacks */
    /* ================ Weaver Advanced Options Tab ================== */
    /* SAPI settings are handled in the Main Options Tab section above */
    if (weaver_submitted('reset_weaver')) {
        // delete everything!
        weaver_save_msg(__('All Weaver settings have been reset to the defaults.', WEAVER_TRANS));
        delete_option('weaver_main_settings');
        delete_option('weaver_advanced_settings');
        weaver_load_cache();
        // be sure cache has something valid in it
        weaver_init_opts('reset_weaver');
    }
    /* ================ Weaver Save/Restore Themes Tab ================== */
    /* this tab has the most individual forms and submit commands */
    if (weaver_submitted('changethemename')) {
        if (isset($_POST['newthemename'])) {
            $new_name = sanitize_user($_POST['newthemename']);
            weaver_setopt('ttw_themename', $new_name);
            echo '<div id="message" class="updated fade"><p><strong>Theme name changed to ' . $new_name . '</strong></p></div>';
        }
        global $weaver_dev;
        if ($weaver_dev) {
            // used to save a theme for distribution/inclusion in dynamic theme db
            if (isset($_POST['newthemeimage'])) {
                weaver_setopt('ttw_theme_image', $_POST['newthemeimage']);
            }
            if (isset($_POST['newthemedesc'])) {
                weaver_setopt('ttw_theme_description', $_POST['newthemedesc']);
            }
        }
    }
    if (weaver_submitted('savemytheme')) {
        if (weaver_savemytheme()) {
            weaver_save_msg(__('All current main and advanced options backed up in <em>My Saved Theme</em>.', WEAVER_TRANSADMIN));
        } else {
            weaver_save_msg(__('ERROR: Saving <em>My Saved Theme</em> failed.', WEAVER_TRANSADMIN));
        }
    }
    if (weaver_submitted('backup_settings')) {
        $name = weaver_savebackup();
        if ($name !== false) {
            weaver_save_msg(__('All current main and advanced options backed up in:', WEAVER_TRANSADMIN) . ' "' . $name . '.wvb"');
        } else {
            weaver_save_msg(__('ERROR: Saving backup failed.', WEAVER_TRANSADMIN));
        }
    }
    if (weaver_submitted('filesavetheme')) {
        $base = strtolower(sanitize_file_name($_POST['savethemename']));
        $temp_url = weaver_write_current_theme($base);
        if ($temp_url == '') {
            weaver_save_msg(__('Invalid name supplied to save theme to file.', WEAVER_TRANSADMIN));
        } else {
            weaver_save_msg(__("All current main and advanced options saved in ", WEAVER_TRANSADMIN) . $temp_url);
        }
    }
    if (weaver_submitted('uploadtheme') && isset($_POST['uploadit']) && $_POST['uploadit'] == 'yes') {
        weaver_uploadit();
    }
    if (weaver_submitted('restoretheme')) {
        $base = $_POST['ttw_restorename'];
        $valid = validate_file($base);
        // make sure an ok file name
        $fn = weaver_f_uploads_base_dir() . 'weaver-subthemes/' . $base;
        if ($valid < 1 && weaver_upload_theme($fn)) {
            $t = weaver_getopt('ttw_subtheme');
            if ($t == '') {
                $t = 'Wheat';
            }
            /* did we save a theme? */
            weaver_save_msg(__("Weaver theme restored from file, saved as: ", WEAVER_TRANSADMIN) . $t);
        } else {
            weaver_save_msg('<em style="color:red;">' . __('INVALID FILE NAME PROVIDED - Try Again', WEAVER_TRANSADMIN) . "({$fn})" . '</em>');
        }
    }
    if (weaver_submitted('deletetheme')) {
        $myFile = $_POST['selectName'];
        $valid = validate_file($myFile);
        if ($valid < 1 && $myFile != "None") {
            weaver_f_delete(weaver_f_uploads_base_dir() . 'weaver-subthemes/' . $myFile);
            echo '<div style="background-color: rgb(255, 251, 204);" id="message" class="updated fade"><p>File: <strong>' . $myFile . '</strong> has been deleted.</p></div>';
        } else {
            echo '<div style="background-color: rgb(255, 251, 204);" id="message" class="updated fade"><p>File: <strong>' . $myFile . '</strong> invalid file name, not deleted.</p></div>';
        }
    }
    /* ====================================================== */
    if (weaver_submitted('wvrx_save_extension')) {
        /* for theme extensions */
        do_action('wvrx_save_extension');
    }
    if (weaver_submitted('wvrx_plus_save_plus')) {
        do_action('wvrx_plus_save_plus');
    }
    // All plus submit buttons...
    weaver_save_opts('Weaver Admin');
    /* FINALLY - SAVE ALL OPTIONS AND UPDATE CURRENT CSS FILE */
}
Пример #2
0
 /**
  * Sets up theme defaults and registers support for various WordPress features.
  *
  * Note that this function is hooked into the after_setup_theme hook, which runs
  * before the init hook. The init hook is too late for some features, such as indicating
  * support post thumbnails.
  *
  * To override weaver_setup() in a child theme, add your own weaver_setup to your child theme's
  * functions.php file.
  *
  * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  * @uses register_nav_menus() To add support for navigation menus.
  * @uses add_custom_background() To add support for a custom background.
  * @uses add_editor_style() To style the visual editor.
  * @uses load_theme_textdomain() For translation/localization support.
  * @uses add_custom_image_header() To add support for a custom header.
  * @uses register_default_headers() To register the default custom header images provided with the theme.
  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  *
  * @uses add_theme_support( 'custom-header', $weaverii_header ) for WP 3.4+ custom header
  */
 function weaver_setup()
 {
     // This theme styles the visual editor with editor-style.css to match the theme style.
     add_editor_style();
     // Post Format support.
     add_theme_support('post-formats', array('aside', 'gallery', 'link', 'quote', 'status'));
     // This theme uses post thumbnails
     add_theme_support('post-thumbnails');
     // Add default posts and comments RSS feed links to head
     add_theme_support('automatic-feed-links');
     // Make theme available for translation
     // Translations can be filed in the /languages/ directory
     load_theme_textdomain(WEAVER_TRANS, TEMPLATEPATH . '/languages');
     $locale = get_locale();
     $locale_file = TEMPLATEPATH . "/languages/{$locale}.php";
     if (is_readable($locale_file)) {
         require_once $locale_file;
     }
     // Weaver supports two nav menus
     register_nav_menus(array('primary' => __('Primary Navigation', WEAVER_TRANSADMIN), 'secondary' => __('Secondary Navigation', WEAVER_TRANSADMIN)));
     global $content_width;
     if (!isset($content_width)) {
         $content_width = 640;
     }
     // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
     register_default_headers(array('wheat' => array('url' => "%s/images/headers/wheat.jpg", 'thumbnail_url' => "%s/images/headers/wheat-thumbnail.jpg", 'description' => __('Wheat 940x198 Header', WEAVER_TRANSADMIN)), 'buds' => array('url' => '%s/images/headers/buds.jpg', 'thumbnail_url' => '%s/images/headers/buds-thumbnail.jpg', 'description' => __('Buds', WEAVER_TRANSADMIN)), 'grand-teton' => array('url' => '%s/images/headers/grand-teton.jpg', 'thumbnail_url' => '%s/images/headers/grand-teton-thumbnail.jpg', 'description' => __('Grand Tetons', WEAVER_TRANSADMIN)), 'moon' => array('url' => '%s/images/headers/moon.jpg', 'thumbnail_url' => '%s/images/headers/moon-thumbnail.jpg', 'description' => __('Moon', WEAVER_TRANSADMIN)), 'moss' => array('url' => '%s/images/headers/moss.jpg', 'thumbnail_url' => '%s/images/headers/moss-thumbnail.jpg', 'description' => __('Moss', WEAVER_TRANSADMIN)), 'mum' => array('url' => "%s/images/headers/mum.jpg", 'thumbnail_url' => "%s/images/headers/mum-thumbnail.jpg", 'description' => __('Mum 940x198 Header', WEAVER_TRANSADMIN)), 'ocean-birds' => array('url' => '%s/images/headers/ocean-birds.jpg', 'thumbnail_url' => '%s/images/headers/ocean-birds-thumbnail.jpg', 'description' => __('Ocean Birds', WEAVER_TRANSADMIN)), 'painted-desert' => array('url' => '%s/images/headers/painted-desert.jpg', 'thumbnail_url' => '%s/images/headers/painted-desert-thumbnail.jpg', 'description' => __('Painted Desert', WEAVER_TRANSADMIN)), 'path' => array('url' => '%s/images/headers/path.jpg', 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', 'description' => __('Path', WEAVER_TRANSADMIN)), 'sopris' => array('url' => "%s/images/headers/sopris.png", 'thumbnail_url' => "%s/images/headers/sopris-thumbnail.png", 'description' => __('Sopris 940x198 Header', WEAVER_TRANSADMIN)), 'sunset' => array('url' => '%s/images/headers/sunset.jpg', 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', 'description' => __('Sunset', WEAVER_TRANSADMIN)), 'wpweaver' => array('url' => "%s/images/headers/wpweaver.jpg", 'thumbnail_url' => "%s/images/headers/wpweaver-thumbnail.jpg", 'description' => __('WPWeaver 940x140 Header', WEAVER_TRANSADMIN)), 'yosemite' => array('url' => '%s/images/headers/yosemite.jpg', 'thumbnail_url' => '%s/images/headers/yosemite-thumbnail.jpg', 'description' => __('Yosemite', WEAVER_TRANSADMIN)), 'indieave' => array('url' => "%s/images/headers/indieave.png", 'thumbnail_url' => "%s/images/headers/indieave-thumbnail.png", 'description' => __('Indie Ave 940x180 Blank Header BG', WEAVER_TRANSADMIN)), 'ivorydrive' => array('url' => "%s/images/headers/ivorydrive.png", 'thumbnail_url' => "%s/images/headers/ivorydrive-thumbnail.png", 'description' => __('Ivory Drive 940x198 Blank Header BG', WEAVER_TRANSADMIN)), 'transparent' => array('url' => '%s/images/headers/transparent.png', 'thumbnail_url' => '%s/images/headers/transparent-thumbnail.png', 'description' => __('Transparent header image', WEAVER_TRANSADMIN)), 'black' => array('url' => '%s/images/headers/black.png', 'thumbnail_url' => '%s/images/headers/black-thumbnail.png', 'description' => __('Black', WEAVER_TRANSADMIN)), 'gray' => array('url' => '%s/images/headers/gray.png', 'thumbnail_url' => '%s/images/headers/gray-thumbnail.png', 'description' => __('Gray', WEAVER_TRANSADMIN)), 'silver' => array('url' => '%s/images/headers/silver.png', 'thumbnail_url' => '%s/images/headers/silver-thumbnail.png', 'description' => __('Silver', WEAVER_TRANSADMIN)), 'white' => array('url' => '%s/images/headers/white.png', 'thumbnail_url' => '%s/images/headers/white-thumbnail.png', 'description' => __('White', WEAVER_TRANSADMIN)), 'maroon' => array('url' => '%s/images/headers/maroon.png', 'thumbnail_url' => '%s/images/headers/maroon-thumbnail.png', 'description' => __('Maroon', WEAVER_TRANSADMIN)), 'red' => array('url' => '%s/images/headers/red.png', 'thumbnail_url' => '%s/images/headers/red-thumbnail.png', 'description' => __('Red', WEAVER_TRANSADMIN)), 'olive' => array('url' => '%s/images/headers/olive.png', 'thumbnail_url' => '%s/images/headers/olive-thumbnail.png', 'description' => __('Olive', WEAVER_TRANSADMIN)), 'yellow' => array('url' => '%s/images/headers/yellow.png', 'thumbnail_url' => '%s/images/headers/yellow-thumbnail.png', 'description' => __('Yellow', WEAVER_TRANSADMIN)), 'green' => array('url' => '%s/images/headers/green.png', 'thumbnail_url' => '%s/images/headers/green-thumbnail.png', 'description' => __('Green', WEAVER_TRANSADMIN)), 'lime' => array('url' => '%s/images/headers/lime.png', 'thumbnail_url' => '%s/images/headers/lime-thumbnail.png', 'description' => __('Lime', WEAVER_TRANSADMIN)), 'teal' => array('url' => '%s/images/headers/teal.png', 'thumbnail_url' => '%s/images/headers/teal-thumbnail.png', 'description' => __('Teal', WEAVER_TRANSADMIN)), 'aqua' => array('url' => '%s/images/headers/aqua.png', 'thumbnail_url' => '%s/images/headers/aqua-thumbnail.png', 'description' => __('Aqua', WEAVER_TRANSADMIN)), 'navy' => array('url' => '%s/images/headers/navy.png', 'thumbnail_url' => '%s/images/headers/navy-thumbnail.png', 'description' => __('Navy', WEAVER_TRANSADMIN)), 'blue' => array('url' => '%s/images/headers/blue.png', 'thumbnail_url' => '%s/images/headers/blue-thumbnail.png', 'description' => __('Blue', WEAVER_TRANSADMIN)), 'purple' => array('url' => '%s/images/headers/purple.png', 'thumbnail_url' => '%s/images/headers/purple-thumbnail.png', 'description' => __('Purple', WEAVER_TRANSADMIN)), 'fuchsia' => array('url' => '%s/images/headers/fuchsia.png', 'thumbnail_url' => '%s/images/headers/fuchsia-thumbnail.png', 'description' => __('fuchsia', WEAVER_TRANSADMIN))));
     // now, need Weaver settings available for everything else
     $width = 0;
     $height = 0;
     if (weaver_load_cache()) {
         // settings will be there unless initial activation or theme preview
         $width = weaver_getopt('ttw_header_image_width');
         $height = weaver_getopt('ttw_header_image_height');
     }
     if ($width == 0 && $height == 0) {
         $width = 940;
         $height = 198;
     }
     global $weaverii_header;
     $weaverii_header = array('default-image' => '%s/images/headers/wheat.jpg', 'random-default' => true, 'width' => $width, 'height' => $height, 'flex-height' => true, 'flex-width' => true, 'default-text-color' => '', 'header-text' => false, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => 'weaver_admin_header_style', 'admin-preview-callback' => '');
     if (function_exists('get_custom_header')) {
         add_theme_support('custom-header', $weaverii_header);
         add_theme_support('custom-background');
     } else {
         // WordPress 3.3 backward compatibility here
         // Add support for custom backgrounds
         add_custom_background();
         // The default header text color
         define('NO_HEADER_TEXT', !$weaverii_header['header-text']);
         // don't include text info in the Headers admin
         define('HEADER_TEXTCOLOR', $weaverii_header['default-text-color']);
         // By leaving empty, we allow for random image rotation.
         // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
         define('HEADER_IMAGE', $weaverii_header['default-image']);
         define('HEADER_IMAGE_WIDTH', $weaverii_header['width']);
         define('HEADER_IMAGE_HEIGHT', $weaverii_header['height']);
         // Turn on random header image rotation by default.
         add_theme_support('custom-header');
         // Add a way for the custom header to be styled in the admin panel that controls
         // custom headers. See weaverii_admin_header_style(), below.
         add_custom_image_header('weaver_admin_header_style', 'weaver_admin_header_style');
     }
     // We'll be using post thumbnails for custom header images on posts and pages.
     // We want them to be 940 pixels wide by 198 pixels tall.
     // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
     set_post_thumbnail_size($weaverii_header['width'], $weaverii_header['height'], true);
     // ... and thus ends the changeable header business.
 }