diff --git a/just-variables.admin.php b/just-variables.admin.php index 250ccca..e410c82 100644 --- a/just-variables.admin.php +++ b/just-variables.admin.php @@ -39,10 +39,13 @@ function jv_get_language_strings(){ * show variables settings page */ function jv_admin_settings_page(){ - + //$post_types = jv_get_post_types( 'object' ); + $jv_read_settings = jv_get_read_settings(); + $jv_multisite_settings = jv_get_multisite_settings(); + $jv_tabs = !isset($_GET['tab']) ? 'fields' : $_GET['tab']; // Form submit processing if( !empty($_POST['submitted']) && !empty($_POST['jv_settings']) ){ - + $post = array_map( 'stripslashes_deep', $_POST['jv_settings']); // update database with new values $variables = array(); @@ -55,13 +58,13 @@ function jv_admin_settings_page(){ 'slug' => $post['slug'][$key], 'name' => $post['title'][$key], 'default' => $post['default'][$key], - 'placeholder' => $post['placeholder'][$key], ); + } //pa($variables,1); - + // update DB - update_option('jv_variables', $variables); + jv_update_options('jv_variables', $variables); // check if we have variables - if no - delete all values if( empty($variables) ){ @@ -69,12 +72,71 @@ function jv_admin_settings_page(){ } } } - - $variables = get_option('jv_variables', array()); + if( !empty($_POST['jv_update_settings']) ) { + if( MULTISITE ){ + $jv_multisite_settings = jv_save_multisite_settings( $_POST['jv_multisite_setting'] ); + } + $jv_read_settings = jv_update_read_settings(); + } + $variables = jv_get_options('jv_variables', array()); // load template include( JV_ROOT . '/templates/settings_page.tpl.php' ); } +/** + * Save miltisite settings from the form + * @param string $settings Multisite settings in present time + * @return string New multisite settings + */ +function jv_save_multisite_settings( $new_value ){ + $current_value = jv_get_multisite_settings(); + $new_value = trim($new_value); + if( $current_value ){ + $saved = update_site_option( 'jv_multisite_setting', $new_value ); + } + else{ + $saved = add_site_option( 'jv_multisite_setting', $new_value ); + } + + if( $saved ){ + jv_add_admin_notice('notice', __('MultiSite settings has been updated.', JV_TEXTDOMAIN)); + } + + return $new_value; +} + +/** + * Get multisite settings + * @return string Return multisite settings + */ +function jv_get_multisite_settings(){ + if( MULTISITE && $multisite_setting = get_site_option('jv_multisite_setting') ) + { + return $multisite_setting; + } + return JV_CONF_MS_SITE; +} + +/** + * Get options with wp-options + * @param string $key Option name + * @return array Options with $key + */ +function jv_get_options($key){ + $jv_multisite_settings = jv_get_multisite_settings(); + return $jv_multisite_settings == 'network' ? get_site_option($key, array()) : get_option($key, array()); +} +/** + * Update options with wp-options + * @param string $key Option name + * @param array $value Values with option name + * @return bollean + */ +function jv_update_options($key, $value){ + $jv_multisite_settings = jv_get_multisite_settings(); + $jv_multisite_settings == 'network' ? update_site_option($key, $value) : update_option($key, $value); + return true; +} ?> \ No newline at end of file diff --git a/just-variables.php b/just-variables.php index f2cf017..ef15b4a 100644 --- a/just-variables.php +++ b/just-variables.php @@ -6,12 +6,14 @@ Tags: theme, variables, template, text data Author: Alexander Prokopenko Author URI: http://justcoded.com/ -Version: 1.2.1 +Version: 1.1 Donate link: http://justcoded.com/just-labs/just-wordpress-theme-variables-plugin/#donate */ define('JV_ROOT', dirname(__FILE__)); define('JV_TEXTDOMAIN', 'just-wp-variables'); +define('JV_CONF_MS_SITE', 'site'); +define('JV_CONF_MS_NETWORK', 'network'); if(!function_exists('pa')){ function pa($mixed, $stop = false) { @@ -90,6 +92,38 @@ function just_variable_shortcode( $atts ){ } add_shortcode('justvar', 'just_variable_shortcode'); +/** + * add message to be printed with admin notice + * @param string $type notice|error + * @param string $message message to be printed + */ +function jv_add_admin_notice( $type, $message ){ + global $jv_notices; + if( !$jv_notices ) + $jv_notices = array(); + + $jv_notices[] = array($type, $message); +} + +/** + * Function for update saving method + * @return string Return read method from file or database + */ +function jv_update_read_settings(){ + $current_value = jv_get_read_settings(); + $new_value = $_POST['jv_read_settings']; + if( MULTISITE && ($_POST['jv_multisite_setting'] != JV_CONF_MS_NETWORK && $new_value == JV_CONF_SOURCE_FS_GLOBAL) ){ + jv_add_admin_notice('error', __('Settings storage update FAILED!. Your MultiSite Settings do not allow to set global storage in FileSystem', JCF_TEXTDOMAIN)); + return $current_value; + } +} +/** + * Get read sttings + * @return string Return read method from file or database + */ +function jv_get_read_settings(){ + return get_site_option('jv_read_settings'); +} ?> \ No newline at end of file diff --git a/just-variables.theme.php b/just-variables.theme.php index eb47b2e..bbe54fe 100644 --- a/just-variables.theme.php +++ b/just-variables.theme.php @@ -49,11 +49,11 @@ function jv_theme_vars_admin_page(){ settings_fields( 'jv_theme_vars' ); do_settings_sections( 'jv_theme_vars' ); - $theme_variables = get_option('jv_variables'); + $theme_variables = get_site_option('jv_variables'); $values = get_option('jv_values'); ?>
-<?php just_variable( "code for variable" ); ?>
Get variable value (no print): <?php just_variable( "code for variable", FALSE ); ?>
Shortcode example: [justvar code="code for variable"]
', JV_TEXTDOMAIN ); ?>
<?php just_variable( "code for variable" ); ?>
Shortcode example: [justvar code="code for variable"]
', JV_TEXTDOMAIN ); ?>