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
add_action('admin_init', function() {
  register_setting('elem_opts', 'elem_opts', 'elem_validate_opts');
  add_settings_section('elem_opts_social', 'Social Networks', 'elem_opts_social_cb', 'elem_opts');
  add_settings_field('elem_opts_social_fb', 'Facebook', 'elem_opts_social_fb_cb', 'elem_opts', 'elem_opts_social');
  add_settings_field('elem_opts_social_twitter', 'Twitter', 'elem_opts_social_twitter_cb', 'elem_opts', 'elem_opts_social');
  add_settings_field('elem_opts_social_tumblr', 'Tumblr', 'elem_opts_social_tumblr_cb', 'elem_opts', 'elem_opts_social');
});

function elem_opts_social_fb_cb() {
  $opts = get_option('elem_opts');
  $opts = wp_parse_args($opts, array(
    'facebook' => '', 
    'twitter' => '', 
    'tumblr' => ''
  ));
  ?>
  <input type="text" name="elem_opts[facebook]" value="<?php echo $opts['facebook']; ?>" /><br />
  <small><em>eg. http://facebook.com/username</em></small>
  <?php
}

function elem_opts_social_twitter_cb() {
  $opts = get_option('elem_opts');
  $opts = wp_parse_args($opts, array(
    'fb' => '', 
    'twitter' => '', 
    'tumblr' => ''
  ));
  ?>
  <input type="text" name="elem_opts[twitter]" value="<?php echo $opts['twitter']; ?>" /><br />
  <small><em>eg. http://twitter.com/username</em></small>
  <?php
}

function elem_opts_social_tumblr_cb() {
  $opts = get_option('elem_opts');
  $opts = wp_parse_args($opts, array(
    'fb' => '', 
    'twitter' => '', 
    'tumblr' => ''
  ));
  ?>
  <input type="text" name="elem_opts[tumblr]" value="<?php echo $opts['tumblr']; ?>" /><br />
  <small><em>eg. http://username.tumblr.com</em></small>
  <?php
}

add_action('admin_menu', function() {
    add_theme_page('Elements Options', 'Elements Options', 'manage_options', 'elem_opts', 'elem_opts_cb');
});

function elem_validate_opts($input) {
  return $input;
}

function elem_opts_social_cb() {
  ?>
  <p>Enable social network links, by entering your username of your social network profile</p>
  <?php
}

function elem_opts_cb() {
    ?>
    <div class="wrap">
        <h2>Elements Theme Options</h2>

        <form action="options.php" method="post">
            <?php 
            settings_fields('elem_opts'); 
            do_settings_sections('elem_opts');
            ?>
            <input type="submit" name="Submit" value="Save changes" />
        </form>
    </div>
    <?php
}