-
Notifications
You must be signed in to change notification settings - Fork 8
/
just-variables.admin.php
80 lines (65 loc) · 2.23 KB
/
just-variables.admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* init admin for just variables page
*/
function jv_admin_menu(){
add_options_page(__('Just Variables', JV_TEXTDOMAIN), __('Just Variables', JV_TEXTDOMAIN), 'manage_options', 'just_variables', 'jv_admin_settings_page');
}
/**
* Properly enqueue styles and scripts for our theme options page.
*/
add_action( 'admin_print_styles', 'jv_admin_styles' );
function jv_admin_styles( $hook_suffix ) {
wp_enqueue_style( 'just_variables', plugins_url( 'assets/styles.css' , __FILE__ ) );
}
add_action( 'admin_print_scripts', 'jv_admin_scripts' );
function jv_admin_scripts( $hook_suffix ) {
wp_enqueue_script( 'just_variables',
plugins_url( 'assets/settings_page.js' , __FILE__ ),
array( 'jquery', 'jquery-ui-sortable' ) );
// add text domain
wp_localize_script( 'just_variables', 'text_just_variables', jv_get_language_strings() );
}
/**
* translation strings for javascript
*/
function jv_get_language_strings(){
$strings = array(
'confirm_delete' => __('Are you sure you want to delete selected field?', JV_TEXTDOMAIN),
);
return $strings;
}
/**
* show variables settings page
*/
function jv_admin_settings_page(){
// 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();
if( !empty($post['slug']) ){
foreach($post['slug'] as $key => $slug){
if( $key == 0 ) continue; // 0 index is empty row for copy
$variables[ $slug ] = array(
'type' => $post['type'][$key],
'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);
// check if we have variables - if no - delete all values
if( empty($variables) ){
update_option('jv_values', array());
}
}
}
$variables = get_option('jv_variables', array());
// load template
include( JV_ROOT . '/templates/settings_page.tpl.php' );
}
?>