1313class WPSAC_Page extends Plugin {
1414
1515 private $ settings_api ;
16+ private $ section_id = 'options ' ;
1617
1718 function __construct () {
1819
1920 $ this ->settings_api = new \WeDevs_Settings_API ();
2021 $ this ->settings_fields = array ();
2122
23+ // Process saved options on submit
24+ if ( isset ( $ _POST ['option_page ' ] ) && $ _POST ['option_page ' ] == $ this ->prefix ( $ this ->section_id ) ) $ this ->options_container_saved ();
25+
2226 // Create a settings page using wordpress-settings-api-class (Settings > Settings API)
2327 add_action ( 'admin_init ' , array ( $ this , 'wpsac_admin_init ' ) );
2428 add_action ( 'admin_menu ' , array ( $ this , 'wpsac_admin_menu ' ) );
@@ -31,6 +35,10 @@ function __construct() {
3135 * @since 0.3.0
3236 */
3337 public function wpsac_admin_init () {
38+
39+ // Flush cache when settings saved
40+ if ( isset ( $ _POST ['option_page ' ] ) && $ _POST ['option_page ' ] == $ this ->prefix ( $ this ->section_id ) ) self ::$ cache ->flush ();
41+
3442 $ this ->settings_api ->set_sections ( $ this ->get_settings_sections () );
3543 $ this ->settings_api ->set_fields ( $ this ->get_settings_fields () );
3644 $ this ->settings_api ->admin_init ();
@@ -55,7 +63,7 @@ public function get_settings_sections() {
5563 $ sections = array (
5664
5765 array (
58- 'id ' => $ this ->prefix ( ' general ' ),
66+ 'id ' => $ this ->prefix ( $ this -> section_id ),
5967 'title ' => self ::$ config ->get ( 'short_name ' ) . ' ' . __ ( 'Settings ' , self ::$ textdomain ) . ' (WPSAC) '
6068 )
6169 );
@@ -72,7 +80,7 @@ public function get_settings_sections() {
7280 public function get_settings_fields () {
7381
7482 $ settings_fields = array (
75- $ this ->prefix ( ' general ' ) => array (
83+ $ this ->prefix ( $ this -> section_id ) => array (
7684 array (
7785 'name ' => $ this ->prefix ( 'blog_name ' ),
7886 'label ' => __ ( 'Blog Name ' , self ::$ textdomain ),
@@ -125,4 +133,17 @@ public function create_wpsac_settings_page() {
125133
126134 }
127135
136+ /**
137+ * When settings saved, run optional code to process. This is not elegant,
138+ * but WPSAC doesn't have an options saved hook.
139+ *
140+ * @since 0.3.2
141+ */
142+ private function options_container_saved () {
143+
144+ // Example - If we wanted to saved the "blog_name" field as an MD5 hash:
145+ //$_POST[ $this->prefix( $this->section_id ) ][ $this->prefix( 'blog_name' ) ] = md5( $this->prefix( 'blog_name' ) );
146+
147+ }
148+
128149}
0 commit comments