1
+ <?php
2
+
3
+ class Custom_Featured_Image_Metabox_Settings {
4
+
5
+ /**
6
+ * Unique identifier for your plugin.
7
+ *
8
+ *
9
+ * Call $plugin_slug from public plugin class later.
10
+ *
11
+ * @since 0.5.0
12
+ *
13
+ * @var string
14
+ */
15
+ protected $ plugin_slug = null ;
16
+
17
+ /**
18
+ * Instance of this class.
19
+ *
20
+ * @since 0.5.0
21
+ *
22
+ * @var object
23
+ */
24
+ protected static $ instance = null ;
25
+
26
+ /**
27
+ * Initialize the plugin by setting localization and loading public scripts
28
+ * and styles.
29
+ *
30
+ * @since 0.5.0
31
+ */
32
+ private function __construct () {
33
+
34
+ $ plugin = Custom_Featured_Image_Metabox::get_instance ();
35
+ $ this ->plugin_slug = $ plugin ->get_plugin_slug ();
36
+
37
+ add_action ( 'admin_init ' , array ( $ this , 'admin_init ' ) );
38
+
39
+ }
40
+
41
+ /**
42
+ * Return an instance of this class.
43
+ *
44
+ * @since 0.5.0
45
+ *
46
+ * @return object A single instance of this class.
47
+ */
48
+ public static function get_instance () {
49
+
50
+ // If the single instance hasn't been set, set it now.
51
+ if ( null == self ::$ instance ) {
52
+ self ::$ instance = new self ;
53
+ }
54
+
55
+ return self ::$ instance ;
56
+ }
57
+
58
+ /**
59
+ * Registering the Sections, Fields, and Settings.
60
+ *
61
+ * This function is registered with the 'admin_init' hook.
62
+ */
63
+ public function admin_init () {
64
+
65
+ if ( false == get_option ( $ this ->plugin_slug ) ) {
66
+ add_option ( $ this ->plugin_slug , $ this ->default_settings () );
67
+ } // end if
68
+
69
+ add_settings_section (
70
+ 'general ' ,
71
+ __ ( 'General ' , $ this ->plugin_slug ),
72
+ '' ,
73
+ $ this ->plugin_slug
74
+ );
75
+
76
+ add_settings_field (
77
+ 'title ' ,
78
+ __ ( 'Title Text ' , $ this ->plugin_slug ),
79
+ array ( $ this , 'title_callback ' ),
80
+ $ this ->plugin_slug ,
81
+ 'general '
82
+ );
83
+
84
+ add_settings_field (
85
+ 'instruction ' ,
86
+ __ ( 'Instruction ' , $ this ->plugin_slug ),
87
+ array ( $ this , 'instruction_callback ' ),
88
+ $ this ->plugin_slug ,
89
+ 'general '
90
+ );
91
+
92
+ add_settings_field (
93
+ 'link_text ' ,
94
+ __ ( 'Link Text ' , $ this ->plugin_slug ),
95
+ array ( $ this , 'link_text_callback ' ),
96
+ $ this ->plugin_slug ,
97
+ 'general '
98
+ );
99
+
100
+ add_settings_field (
101
+ 'button_text ' ,
102
+ __ ( 'Button Text ' , $ this ->plugin_slug ),
103
+ array ( $ this , 'button_text_callback ' ),
104
+ $ this ->plugin_slug ,
105
+ 'general '
106
+ );
107
+
108
+ register_setting (
109
+ $ this ->plugin_slug ,
110
+ $ this ->plugin_slug
111
+ );
112
+
113
+ } // end admin_init
114
+
115
+ /**
116
+ * Provides default values for the plugin settings.
117
+ *
118
+ * @return array<string> Default settings
119
+ */
120
+ public function default_settings () {
121
+
122
+ $ defaults = array (
123
+ 'title ' => 'Post Featured Image ' ,
124
+ 'instruction ' => '' ,
125
+ 'link_text ' => '' ,
126
+ 'button_text ' => '' ,
127
+ );
128
+
129
+ return apply_filters ( 'default_settings ' , $ defaults );
130
+
131
+ } // end default_settings
132
+
133
+ public function title_callback () {
134
+
135
+ $ options = get_option ( $ this ->plugin_slug );
136
+ $ value = isset ( $ options ['title ' ] ) ? $ options ['title ' ] : '' ;
137
+
138
+ $ html = '<input type"text" id="title" name=" ' . $ this ->plugin_slug . '[title]" value=" ' . $ value . '" class="regular-text" /> ' ;
139
+ $ html .= '<p class="description"> ' . __ ( 'Enter your custom title for Featured Image Metabox. ' , $ this ->plugin_slug ) . '</p> ' ;
140
+
141
+ echo $ html ;
142
+
143
+ } // end title_callback
144
+
145
+ public function instruction_callback () {
146
+
147
+ $ options = get_option ( $ this ->plugin_slug );
148
+ $ value = isset ( $ options ['instruction ' ] ) ? $ options ['instruction ' ] : '' ;
149
+
150
+ $ html = '<input type"text" id="instruction" name=" ' . $ this ->plugin_slug . '[instruction]" value=" ' . $ value . '" class="regular-text" /> ' ;
151
+ $ html .= '<p class="description"> ' . __ ( 'Enter the instruction for Featured Image, like the image dimensions. ' , $ this ->plugin_slug ) . '</p> ' ;
152
+
153
+ echo $ html ;
154
+
155
+ } // end instruction_callback
156
+
157
+ public function link_text_callback () {
158
+
159
+ $ options = get_option ( $ this ->plugin_slug );
160
+ $ value = isset ( $ options ['link_text ' ] ) ? $ options ['link_text ' ] : '' ;
161
+
162
+ $ html = '<input type"text" id="link_text" name=" ' . $ this ->plugin_slug . '[link_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
163
+ $ html .= '<p class="description"> ' . sprintf ( __ ( 'Enter the custom link text to replace the "%s". ' , $ this ->plugin_slug ), __ ( 'Set featured image ' ) ) . '</p> ' ;
164
+
165
+ echo $ html ;
166
+
167
+ } // end link_text_callback
168
+
169
+ public function button_text_callback () {
170
+
171
+ $ options = get_option ( $ this ->plugin_slug );
172
+ $ value = isset ( $ options ['button_text ' ] ) ? $ options ['button_text ' ] : '' ;
173
+
174
+ $ html = '<input type"text" id="button_text" name=" ' . $ this ->plugin_slug . '[button_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
175
+ $ html .= '<p class="description"> ' . sprintf ( __ ( 'Enter the custom button text to replace the "%s". ' , $ this ->plugin_slug ), __ ( 'Set featured image ' ) ) . '</p> ' ;
176
+
177
+ echo $ html ;
178
+
179
+ } // end button_text_callback
180
+ }
181
+
182
+ Custom_Featured_Image_Metabox_Settings::get_instance ();
183
+ ?>
0 commit comments