Skip to content

Commit

Permalink
Fixed warnings, fixed notice for empty data
Browse files Browse the repository at this point in the history
  • Loading branch information
jcssamoylov committed Jul 22, 2015
1 parent f7b03cf commit 0665089
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 47 deletions.
8 changes: 6 additions & 2 deletions assets/just_custom_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ function modalWindow(content){
*/
function initSettings(){
var jcf_read_settings_active = jQuery('#jcform_settings').find('input[name="jcf_read_settings"]:checked').attr('id');
jQuery('#jcform_settings input[name="jcf_read_settings"]').change(function(){
jQuery('#jcform_settings input[name="jcf_read_settings"]').live('change', function(){
var data = {
'action' : 'jcf_check_file',
'jcf_multisite_setting' : jQuery('#jcform_settings').find('input[name="jcf_multisite_setting"]:checked').val(),
Expand Down Expand Up @@ -427,7 +427,11 @@ function initSettings(){
}
else{
jQuery('input[type="radio"]#jcf_read_file_global, label[for="jcf_read_file_global"]').hide();
jQuery('input[type="radio"]#jcf_read_file').attr({'checked':!jQuery('input[type="radio"]#jcf_read_file_global').is(':checked')});
if(jcf_read_settings_active == 'jcf_read_file_global'){
jQuery('#jcform_settings').find('input[name="jcf_read_settings"]#jcf_read_file').attr({'checked':'checked'});
}else{
jQuery('#jcform_settings').find('input[name="jcf_read_settings"]#'+jcf_read_settings_active).attr({'checked':'checked'});
}
}
});
}
22 changes: 16 additions & 6 deletions inc/functions.fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,23 @@ function jcf_fieldsets_get_option_name(){
}

function jcf_fieldsets_count($post_type){
$fieldsets = get_option('jcf_fieldsets-'.$post_type, array());
$count['fieldsets'] = count($fieldsets);
$count['fields'] = 0;
foreach($fieldsets as $fieldset){
if(!empty($fieldset['fields'])){
$count['fields'] += count($fieldset['fields']);
$jcf_read_settings = jcf_get_read_settings();
if( !empty($jcf_read_settings) && ($jcf_read_settings == 'theme' OR $jcf_read_settings == 'global') ){
$jcf_settings = jcf_get_all_settings_from_file();
$fieldsets = $jcf_settings['fieldsets'][$post_type];
} else {
$fieldsets = jcf_get_options('jcf_fieldsets-'.$post_type);
}
if(!empty($fieldsets)){
$count['fieldsets'] = count($fieldsets);
$count['fields'] = 0;
foreach($fieldsets as $fieldset){
if(!empty($fieldset['fields'])){
$count['fields'] += count($fieldset['fields']);
}
}
}else{
$count = array('fieldsets' => 0, 'fields' => 0);
}
return $count;
}
Expand Down
47 changes: 24 additions & 23 deletions inc/functions.post.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,35 @@ function jcf_post_load_custom_fields( $post_type = '' ){
} else {
$fieldsets = jcf_fieldsets_get();
}

// remove fieldsets without fields
foreach($fieldsets as $f_id => $fieldset){
// check $enabled; add custom js/css for components
foreach($fieldset['fields'] as $field_id => $enabled){
if( !$enabled ){
unset($fieldset['fields'][$field_id]);
continue;
if(!empty($fieldsets)){
// remove fieldsets without fields
foreach($fieldsets as $f_id => $fieldset){
// check $enabled; add custom js/css for components
foreach($fieldset['fields'] as $field_id => $enabled){
if( !$enabled ){
unset($fieldset['fields'][$field_id]);
continue;
}
$field_obj = jcf_init_field_object($field_id, $fieldset['id']);
$field_obj->do_add_js();
$field_obj->do_add_css();
}
// if all fields disabled -> remove fieldset
if( empty($fieldset['fields']) ){
unset($fieldsets[$f_id]);
}
$field_obj = jcf_init_field_object($field_id, $fieldset['id']);
$field_obj->do_add_js();
$field_obj->do_add_css();
}
// if all fields disabled -> remove fieldset
if( empty($fieldset['fields']) ){
unset($fieldsets[$f_id]);
}
}
if(!empty($field_obj)) unset($field_obj);
if(!empty($field_obj)) unset($field_obj);

if( empty($fieldsets) ) return false;
if( empty($fieldsets) ) return false;

// add custom styles and scripts
add_action('admin_print_styles', 'jcf_edit_post_styles');
add_action('admin_print_scripts', 'jcf_edit_post_scripts');
// add custom styles and scripts
add_action('admin_print_styles', 'jcf_edit_post_styles');
add_action('admin_print_scripts', 'jcf_edit_post_scripts');

foreach($fieldsets as $f_id => $fieldset){
add_meta_box('jcf_fieldset-'.$f_id, $fieldset['title'], 'jcf_post_show_custom_fields', $post_type, 'advanced', 'default', array($fieldset) );
foreach($fieldsets as $f_id => $fieldset){
add_meta_box('jcf_fieldset-'.$f_id, $fieldset['title'], 'jcf_post_show_custom_fields', $post_type, 'advanced', 'default', array($fieldset) );
}
}
}

Expand Down
38 changes: 22 additions & 16 deletions just-custom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,32 @@ function jcf_admin_fields_page( $post_type ){
function jcf_admin_keep_settings($dir, $read_settings){
$jcf_settings = jcf_get_all_settings_from_db();
$home_dir = get_home_path();
if( is_writable($home_dir) ){
if( !file_exists($dir) ){
if( wp_mkdir_p($dir) ){
if( is_writable($dir) ){
$save = jcf_admin_save_all_settings_in_file($jcf_settings, $read_settings);
$notice = $save ? array('notice' => '<strong>Config file</strong> has saved') : array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . get_template_directory() . ' directory');
}else{
$notice = array('error' => 'Error! Check the writable rules for ' . $dir . ' directory ');
$theme_dir = get_template_directory();
if( !file_exists($dir) ){
if( wp_mkdir_p($dir) ){
if( is_writable($dir) ){
$save = jcf_admin_save_all_settings_in_file($jcf_settings, $read_settings);
if($read_settings == 'theme'){
$notice = $save ? array('notice' => '<strong>Config file</strong> has saved') : array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . $theme_dir . ' directory');
}
} else {
$notice = array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . get_template_directory() . ' directory');
else{
$notice = $save ? array('notice' => '<strong>Config file</strong> has saved') : array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . $home_dir . 'wp-content/ directory');
}

}else{
$notice = array('error' => 'Error! Check the writable rules for ' . $dir . ' directory ');
}
} else {
if($read_settings == 'theme'){
$notice = array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . $theme_dir . ' directory');
}
else{
$notice = array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . $home_dir . 'wp-content/ directory');
}
}else{
$save = jcf_admin_save_all_settings_in_file($jcf_settings, $read_settings);
$notice = $save ? array('notice' => '<strong>Config file</strong> has saved') : array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . get_template_directory() . ' directory');
}
}else{
$notice = array('error' => 'Error! <strong>Config File</strong> has not created. Check the writable rules for ' . $home_dir . ' directory ');
$save = jcf_admin_save_all_settings_in_file($jcf_settings, $read_settings);
$notice = $save ? array('notice' => '<strong>Config file</strong> has saved') : array('error' => 'Error! <strong>Config file</strong> has not saved. Check the writable rules for ' . $theme_dir . ' directory');
}
do_action('admin_notices', $notice);
return $save;
Expand Down Expand Up @@ -288,8 +296,6 @@ function jcf_get_all_settings_from_file(){
if (file_exists($filename)) {
return jcf_get_settings_from_file($filename);
}else{
$notice = array('error' => 'The file of settings is not found');
do_action('admin_notices', $notice);
return false;
}
}
Expand Down

0 comments on commit 0665089

Please # to comment.