Esempio n. 1
0
/**
 * Saves settings.
 * 
 * @param type $form 
 */
function wpcf_admin_image_settings_form_submit($form)
{
    if (isset($_POST['clear-cache-images']) || isset($_POST['clear-cache-images-outdated'])) {
        require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/image.php';
        $cache_dir = wpcf_fields_image_get_cache_directory(true);
        if (is_wp_error($cache_dir)) {
            wpcf_admin_message_store($cache_dir->get_error_message());
        } else {
            if (isset($_POST['clear-cache-images'])) {
                wpcf_fields_image_clear_cache($cache_dir, 'all');
            } else {
                wpcf_fields_image_clear_cache($cache_dir);
            }
            wpcf_admin_message_store(__('Images cache cleared', 'wpcf'));
        }
        return true;
    }
    $settings = wpcf_get_settings();
    $data = $_POST['wpcf_settings'];
    foreach (array('add_resized_images_to_library', 'images_remote', 'images_remote_cache_time') as $setting) {
        if (!isset($data[$setting])) {
            $settings[$setting] = 0;
        } else {
            $settings[$setting] = $data[$setting];
        }
    }
    update_option('wpcf_settings', $settings);
    wpcf_admin_message_store(__('Settings saved', 'wpcf'));
}
Esempio n. 2
0
/**
 * Saves settings.
 *
 * @param type $form
 */
function wpcf_admin_general_settings_form_submit($form)
{
    if (isset($_POST['clear-cache-images']) || isset($_POST['clear-cache-images-outdated'])) {
        require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/image.php';
        $cache_dir = wpcf_fields_image_get_cache_directory(true);
        if (is_wp_error($cache_dir)) {
            wpcf_admin_message_store($cache_dir->get_error_message());
        } else {
            if (isset($_POST['clear-cache-images'])) {
                wpcf_fields_image_clear_cache($cache_dir, 'all');
            } else {
                wpcf_fields_image_clear_cache($cache_dir);
            }
            wpcf_admin_message_store(__('Images cache cleared', 'wpcf'));
        }
        return true;
    }
    $settings = wpcf_get_settings();
    $data = $_POST['wpcf_settings'];
    $keys = array('add_resized_images_to_library' => 'esc_html', 'help_box' => 'esc_html', 'hide_standard_custom_fields_metabox' => 'esc_html', 'images_remote' => 'intval', 'images_remote_cache_time' => 'intval', 'register_translations_on_import' => 'esc_html', 'toolset_messages' => 'intval', 'postmeta_unfiltered_html' => 'on-off', 'usermeta_unfiltered_html' => 'on-off');
    foreach ($keys as $key => $validation) {
        if (!isset($data[$key])) {
            $settings[$key] = 0;
        } else {
            switch ($validation) {
                case 'intval':
                    $settings[$key] = intval($data[$key]);
                    break;
                case 'on-off':
                    if (preg_match('/^(on|off)$/', $data[$key])) {
                        $settings[$key] = $data[$key];
                    } else {
                        $settings[$key] = 'off';
                    }
                    break;
                case 'esc_html':
                default:
                    $settings[$key] = esc_html($data[$key]);
                    break;
            }
        }
    }
    /**
     * validate hide_standard_custom_fields_metabox
     */
    if (!preg_match('/^(show|hide)$/', $settings['hide_standard_custom_fields_metabox'])) {
        $settings['hide_standard_custom_fields_metabox'] = 'show';
    }
    /**
     * update_option
     */
    update_option('wpcf_settings', $settings);
    wpcf_admin_message_store(__('Settings saved.', 'wpcf'));
}
Esempio n. 3
0
function wpcf_settings_clear_cache_images()
{
    if (!current_user_can('manage_options')) {
        $data = array('type' => 'capability', 'message' => __('You do not have permissions for that.', 'wpcf'));
        wp_send_json_error($data);
    }
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'wpcf_settings_nonce')) {
        $data = array('type' => 'nonce', 'message' => __('Your security credentials have expired. Please reload the page to get new ones.', 'wpcf'));
        wp_send_json_error($data);
    }
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/image.php';
    $cache_dir = wpcf_fields_image_get_cache_directory(true);
    if (is_wp_error($cache_dir)) {
        $data = array('type' => 'error', 'message' => $cache_dir->get_error_message());
        wp_send_json_error($data);
    }
    $posted_settings = isset($_POST['settings']) ? sanitize_text_field($_POST['settings']) : '';
    if (!in_array($posted_settings, array('all', 'outdated'))) {
        $data = array('type' => 'error', 'message' => __('Missing data', 'wpcf'));
        wp_send_json_error($data);
    }
    switch ($posted_settings) {
        case 'all':
            wpcf_fields_image_clear_cache($cache_dir, 'all');
            break;
        case 'outdated':
            wpcf_fields_image_clear_cache($cache_dir);
            break;
    }
    wp_send_json_success();
}