@@ -10,79 +10,90 @@ class Settings extends Plugin {
1010 */
1111 function __construct () {
1212
13- // Clear the cache when settings are saved
13+ // Flush the cache when settings are saved
1414 add_action ('carbon_fields_theme_options_container_saved ' , array ( $ this , 'options_saved_hook ' ) );
1515
16+ // Create tabbed plugin options page (Settings > Plugin Name)
17+ $ this ->create_tabbed_options_page ();
18+
19+ }
20+
21+ /**
22+ * Create a tabbed options/settings page in WP Admin
23+ *
24+ * @see https://carbonfields.net/docs/containers-theme-options/ Carbon Fields Theme Options
25+ */
26+ private function create_tabbed_options_page () {
27+
1628 // Carbon Fields Docs: https://carbonfields.net/docs/containers-theme-options/
1729 Container::make ('theme_options ' , self ::$ settings ['data ' ]['Name ' ])
1830 ->set_page_parent ('options-general.php ' )
19- ->add_tab (__ ('General ' ), array (
20- Field::make ('checkbox ' , self :: $ prefix. 'remove_header_emojicons ' , 'Remove Emoji Code From Page Headers ' )
21- ->help_text ('Checking this box will remove the default Emoji code from page headers. ' ),
22- Field::make ( 'set ' , self :: $ prefix. 'enqueue_font_awesome ' , __ ( 'Load Font Awesome from CDN ' , self ::$ textdomain ))
23- ->help_text ('Load <a href="http://fontawesome.io/" target="_blank">Font Awesome</a> from <a href="https://www.bootstrapcdn.com/fontawesome/" target="_blank">CDN</a>. ' )
31+ ->add_tab ( __ ('General ' , self :: $ textdomain ), array (
32+ Field::make ('checkbox ' , $ this -> prefix ( 'remove_header_emojicons ' ), __ ( 'Remove Emoji Code From Page Headers ' , self :: $ textdomain ) )
33+ ->help_text ( __ ( 'Checking this box will remove the default Emoji code from page headers. ' , self :: $ textdomain ) ),
34+ Field::make ( 'set ' , $ this -> prefix ( 'enqueue_font_awesome ' ) , __ ('Load Font Awesome from CDN ' , self ::$ textdomain ) )
35+ ->help_text ( __ ( 'Load <a href="http://fontawesome.io/" target="_blank">Font Awesome</a> from <a href="https://www.bootstrapcdn.com/fontawesome/" target="_blank">CDN</a>. ' , self :: $ textdomain ) )
2436 ->add_options (array (
25- 'frontend ' => 'Frontend ' ,
26- 'backend ' => 'Backend '
37+ 'frontend ' => __ ( 'Frontend ' , self :: $ textdomain ) ,
38+ 'backend ' => __ ( 'Backend ' , self :: $ textdomain )
2739 ))
2840 ->set_default_value ('backend ' ),
29- Field::make ( 'separator ' , self :: $ prefix. 'general_separator_examples ' , __ ('Example Fields ' , self ::$ textdomain ) )
30- ->help_text ('These fields are just provided as examples and are not used by any logic in the plugin. ' ),
31- Field::make ('text ' , self :: $ prefix. 'blog_title ' , __ ('Blog Title ' , self ::$ textdomain )),
32- Field::make ('text ' , self :: $ prefix. 'email ' , 'Your E-mail Address ' )
41+ Field::make ( 'separator ' , $ this -> prefix ( 'general_separator_examples ' ) , __ ('Example Fields ' , self ::$ textdomain ) )
42+ ->help_text ( __ ( 'These fields are just provided as examples and are not used by any logic in the plugin. ' , self :: $ textdomain ) ),
43+ Field::make ('text ' , $ this -> prefix ( 'blog_title ' ) , __ ('Blog Title ' , self ::$ textdomain )),
44+ Field::make ('text ' , $ this -> prefix ( 'email ' ), __ ( 'Your E-mail Address ' , self :: $ textdomain ) )
3345 ->set_attribute ('type ' , 'email ' )
34- ->help_text ('This input field is an HTML5 <tt>email</tt> type. ' ),
35- Field::make ('text ' , self :: $ prefix. 'web_site_url ' , 'Web Site Address ' )
46+ ->help_text ( __ ( 'This input field is an HTML5 <tt>email</tt> type. ' , self :: $ textdomain ) ),
47+ Field::make ('text ' , $ this -> prefix ( 'web_site_url ' ), __ ( 'Web Site Address ' , self :: $ textdomain ) )
3648 ->set_attribute ('type ' , 'url ' )->set_attribute ( 'placeholder ' , site_url () )
37- ->help_text ('This input field is an HTML5 <tt>url</tt> type. ' ),
38- Field::make ('text ' , self :: $ prefix. 'phone ' , 'Phone Number ' )
49+ ->help_text ( __ ( 'This input field is an HTML5 <tt>url</tt> type. ' , self :: $ textdomain ) ),
50+ Field::make ('text ' , $ this -> prefix ( 'phone ' ), __ ( 'Phone Number ' , self :: $ textdomain ) )
3951 ->set_attribute ('type ' , 'tel ' ),
40- Field::make ('date_time ' , self :: $ prefix. 'date_time ' , 'Date & Time ' ),
41- Field::make ('radio ' , self :: $ prefix. ' radio ' , ' Subtitle Font Style ' )
52+ Field::make ('date_time ' , $ this -> prefix ( 'date_time ' ), __ ( 'Date & Time ' , self :: $ textdomain ) ),
53+ Field::make ('radio ' , $ this -> prefix ( ' radio_buttons ' ), __ ( ' Menu Position ' , self :: $ textdomain ) )
4254 ->add_options (array (
43- 'em ' => ' Italic ' ,
44- 'strong ' => ' Bold ' ,
45- 'del ' => ' Strike ' ,
46- )
47- ),
48- Field::make ('complex ' , self :: $ prefix. 'slides ' , self ::$ settings ['data ' ]['Name ' ] . ' ' . __ ('Slides ' , self ::$ textdomain ))->add_fields (array (
55+ 'none ' => __ ( ' Disabled ' , self :: $ textdomain ) ,
56+ 'top ' => __ ( ' Top (Default) ' , self :: $ textdomain ) ,
57+ 'left ' => __ ( ' Left ' , self :: $ textdomain )
58+ ))
59+ -> set_default_value ( ' top ' ),
60+ Field::make ('complex ' , $ this -> prefix ( 'slides ' ) , self ::$ settings ['data ' ]['Name ' ] . ' ' . __ ('Slides ' , self ::$ textdomain ))->add_fields (array (
4961 Field::make ('text ' , 'title ' ),
5062 Field::make ('image ' , 'photo ' ),
5163 )),
52- Field::make (" select " , self :: $ prefix. " select " , " Best Music " )
64+ Field::make (' select ' , $ this -> prefix ( ' select_dropdown ' ), __ ( ' Favorite Continent ' , self :: $ textdomain ) )
5365 ->add_options (array (
54- 'winning ' => 'Andy Grammer ' ,
55- 'losing ' => 'Nickelback ' ,
56- 'superstar ' => 'Anything Armin van Buuren spins '
66+ 'aria ' => __ ('Asia ' , self ::$ textdomain ),
67+ 'africa ' => __ ('Africa ' , self ::$ textdomain ),
68+ 'europe ' => __ ('Europe ' , self ::$ textdomain ),
69+ 'north-america ' => __ ('North America ' , self ::$ textdomain ),
70+ 'south-america ' => __ ('South America ' , self ::$ textdomain ),
71+ 'australia ' => __ ('Australia ' , self ::$ textdomain ),
72+ 'antarctica ' => __ ('Antarctica ' , self ::$ textdomain )
5773 ))
5874 )
5975 )
60- ->add_tab (__ ('Miscellaneous ' ), array (
61- Field::make ('color ' , self ::$ prefix .'font_color ' , 'Foreground Color ' ),
62- Field::make ('image ' , self ::$ prefix .'default_image ' , 'Default Image ' ),
63- Field::make ('file ' , self ::$ prefix .'file ' , 'File Upload ' )
64- )
65-
66- /*
67- // One page, no tabs (Example)
68- ->add_fields(array(
69- Field::make('color', self::$prefix.'background_color', 'Background Color'),
70- Field::make('image', self::$prefix.'background_image', 'Background Image')
76+ ->add_tab ( __ ('Miscellaneous ' , self ::$ textdomain ), array (
77+ Field::make ('color ' , $ this ->prefix ('font_color ' ), __ ('Foreground Color ' , self ::$ textdomain ) ),
78+ Field::make ('image ' , $ this ->prefix ('default_image ' ), __ ('Default Image ' , self ::$ textdomain ) ),
79+ Field::make ('file ' , $ this ->prefix ('file ' ), __ ('File Upload ' , self ::$ textdomain ) )
7180 )
72- */
7381 );
7482
75- // Add side metabox (Example)
76- /*
77- Container::make('post_meta', 'Custom Data')
78- ->show_on_post_type('post')
79- ->set_priority('default')
80- ->set_context('side')
83+ }
84+
85+ /**
86+ * Create a single options/settings page in WP Admin
87+ */
88+ private function create_single_options_page () {
89+
90+ Container::make ('theme_options ' , self ::$ settings ['data ' ]['Name ' ])
91+ ->set_page_parent ('options-general.php ' )
8192 ->add_fields (array (
82- Field::make('text', self::$prefix.'meta_test')
93+ Field::make ('text ' , $ this ->prefix ('your_name ' ), __ ('Your Name ' , self ::$ textdomain ) ),
94+ Field::make ('image ' , $ this ->prefix ('profile_pic ' ), __ ('Profile Pic ' , self ::$ textdomain ) )
8395 )
8496 );
85- */
8697
8798 }
8899
0 commit comments