This repository has been archived by the owner on May 23, 2021. It is now read-only.
forked from phankimi/doingitwrong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.php
89 lines (84 loc) · 2.51 KB
/
options.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
81
82
83
84
85
86
87
88
89
<?php
add_action( 'admin_menu', 'theme_options_menu' );
add_action( 'admin_init', 'settings_init' );
function settings_init(){
// Theme default settings/options
$defaults = array(
'typography' => array(
'body_text' => 16,
'title_text' => 36
),
'social' => array(
'facebook' => '#',
'twitter' => '#',
'blogger' => '#',
'youtube' => '#',
'pinterest' => '#',
'google' => '#',
'amazon' => '#',
'bitbucket' => '#',
'codepen' => '#',
'drupal' => '#',
'instagram' => '#',
'foursquare' => '#',
'delicious' => '#',
'linkedin' => '#',
'snapchat' => '#',
'steam' => '#',
'vimeo' => '#',
'wordpress' => '#',
'tumblr' => '#',
'yelp' => '#',
'reddit' => '#',
'lastfm' => '#',
'flickr' => '#',
)
);
// Get the options if they exists
$options = get_option( 'default_options' );
if( false === $options ){
add_option( 'default_options', $defaults );
}
$settings = wp_parse_args( $defaults, $options );
update_option( 'default_options', $settings );
register_setting( 'my_theme_options', 'default_options' );
}
function theme_options_menu(){
add_theme_page( 'Theme Options', 'Theme options', 'edit_theme_options', 'theme-options', 'options_page_render' );
}
function options_page_render(){ ?>
<div class="wrap">
<h2>Theme Options</h2>
<form action="options.php" method="post">
<?php settings_fields( 'my_theme_options' ); ?>
<?php $options = get_option( 'default_options' ); ?>
<section class="type">
<h3>Typography</h3>
<p>Set the font size for body text and title text</p>
<p>
<label for="body_text">Body Text</label>
<input id="default_options[typography][body_text]" name="default_options[typography][body_text]" type="text" value="<?php echo $options['typography']['body_text']; ?>">
</p>
<p>
<label for="title_text">Title Text</label>
<input id="default_options[typography][title_text]" name="default_options[typography][title_text]" type="text" value="<?php echo $options['typography']['title_text']; ?>">
</p>
</section>
<section class="social-sharing">
<h3>Social settings</h3>
<p>Use your social profile's link</p>
<?php
foreach( $options['social'] as $profile => $url){
echo '<p>';
echo '<label for="' . $profile . '">' . $profile . '</label><br/>';
echo '<input name="default_options[social][' . $profile . ']" type="text" value="' . $url .'" />';
echo '</p>';
} ?>
</section>
<?php submit_button(); ?>
</form>
<br><br>
Please visit our <a href="#">facebook page</a> or <a href="#">tweet us.</a>
</div>
<?php
}