admin-options.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Options Class
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Options' ) ) {
  11. class CSF_Options extends CSF_Abstract {
  12. // constans
  13. public $unique = '';
  14. public $notice = '';
  15. public $abstract = 'options';
  16. public $sections = array();
  17. public $options = array();
  18. public $errors = array();
  19. public $pre_tabs = array();
  20. public $pre_fields = array();
  21. public $pre_sections = array();
  22. public $args = array(
  23. // framework title
  24. 'framework_title' => '<img src="https://s.nmxc.ltd/sakurairo_vision/@2.6/series/login_logo.webp" style="width:50px;height:50px;transform:translateY(32%);margin-right: 13px;">iro 主题设置 <small> / Theme Options / テーマの設定</small>',
  25. 'framework_class' => '',
  26. // menu settings
  27. 'menu_title' => '',
  28. 'menu_slug' => '',
  29. 'menu_type' => 'menu',
  30. 'menu_capability' => 'manage_options',
  31. 'menu_icon' => null,
  32. 'menu_position' => null,
  33. 'menu_hidden' => false,
  34. 'menu_parent' => '',
  35. 'sub_menu_title' => '',
  36. // menu extras
  37. 'show_bar_menu' => true,
  38. 'show_sub_menu' => true,
  39. 'show_in_network' => true,
  40. 'show_in_customizer' => false,
  41. 'show_search' => true,
  42. 'show_reset_all' => true,
  43. 'show_reset_section' => true,
  44. 'show_footer' => true,
  45. 'show_all_options' => true,
  46. 'show_form_warning' => true,
  47. 'sticky_header' => true,
  48. 'save_defaults' => true,
  49. 'ajax_save' => true,
  50. 'form_action' => '',
  51. // admin bar menu settings
  52. 'admin_bar_menu_icon' => '',
  53. 'admin_bar_menu_priority' => 50,
  54. // footer
  55. 'footer_text' => 'Sakurairo 使用 Fuukei 定制的 <a href="https://github.com/Fuukei/Sakurairo_CSF" target="_blank">CSF</a> 设置框架,感谢你的使用 0v0',
  56. 'footer_after' => '',
  57. 'footer_credit' => '',
  58. // database model
  59. 'database' => '', // options, transient, theme_mod, network
  60. 'transient_time' => 0,
  61. // contextual help
  62. 'contextual_help' => array(),
  63. 'contextual_help_sidebar' => '',
  64. // typography options
  65. 'enqueue_webfont' => true,
  66. 'async_webfont' => false,
  67. // others
  68. 'output_css' => true,
  69. // theme
  70. 'nav' => 'normal',
  71. 'theme' => 'light',
  72. 'class' => '',
  73. // external default values
  74. 'defaults' => array(),
  75. );
  76. // run framework construct
  77. public function __construct( $key, $params = array() ) {
  78. $this->unique = $key;
  79. $this->args = apply_filters( "csf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
  80. $this->sections = apply_filters( "csf_{$this->unique}_sections", $params['sections'], $this );
  81. // run only is admin panel options, avoid performance loss
  82. $this->pre_tabs = $this->pre_tabs( $this->sections );
  83. $this->pre_fields = $this->pre_fields( $this->sections );
  84. $this->pre_sections = $this->pre_sections( $this->sections );
  85. $this->get_options();
  86. $this->set_options();
  87. $this->save_defaults();
  88. add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
  89. add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu' ), $this->args['admin_bar_menu_priority'] );
  90. add_action( 'wp_ajax_csf_'. $this->unique .'_ajax_save', array( $this, 'ajax_save' ) );
  91. if ( $this->args['database'] === 'network' && ! empty( $this->args['show_in_network'] ) ) {
  92. add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) );
  93. }
  94. // wp enqeueu for typography and output css
  95. parent::__construct();
  96. }
  97. // instance
  98. public static function instance( $key, $params = array() ) {
  99. return new self( $key, $params );
  100. }
  101. // add admin bar menu
  102. public function add_admin_bar_menu( $wp_admin_bar ) {
  103. if ( ! current_user_can( $this->args['menu_capability'] ) ) {
  104. return;
  105. }
  106. if ( is_network_admin() && ( $this->args['database'] !== 'network' || $this->args['show_in_network'] !== true ) ) {
  107. return;
  108. }
  109. if ( ! empty( $this->args['show_bar_menu'] ) && empty( $this->args['menu_hidden'] ) ) {
  110. global $submenu;
  111. $menu_slug = $this->args['menu_slug'];
  112. $menu_icon = ( ! empty( $this->args['admin_bar_menu_icon'] ) ) ? '<span class="csf-ab-icon ab-icon '. esc_attr( $this->args['admin_bar_menu_icon'] ) .'"></span>' : '';
  113. $wp_admin_bar->add_node( array(
  114. 'id' => $menu_slug,
  115. 'title' => $menu_icon . esc_attr( $this->args['menu_title'] ),
  116. 'href' => esc_url( ( is_network_admin() ) ? network_admin_url( 'admin.php?page='. $menu_slug ) : admin_url( 'admin.php?page='. $menu_slug ) ),
  117. ) );
  118. if ( ! empty( $submenu[$menu_slug] ) ) {
  119. foreach ( $submenu[$menu_slug] as $menu_key => $menu_value ) {
  120. $wp_admin_bar->add_node( array(
  121. 'parent' => $menu_slug,
  122. 'id' => $menu_slug .'-'. $menu_key,
  123. 'title' => $menu_value[0],
  124. 'href' => esc_url( ( is_network_admin() ) ? network_admin_url( 'admin.php?page='. $menu_value[2] ) : admin_url( 'admin.php?page='. $menu_value[2] ) ),
  125. ) );
  126. }
  127. }
  128. }
  129. }
  130. public function ajax_save() {
  131. $result = $this->set_options( true );
  132. if ( ! $result ) {
  133. wp_send_json_error( array( 'error' => esc_html__( 'Error while saving the changes.', 'sakurairo_csf' ) ) );
  134. } else {
  135. wp_send_json_success( array( 'notice' => $this->notice, 'errors' => $this->errors ) );
  136. }
  137. }
  138. // get default value
  139. public function get_default( $field ) {
  140. $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
  141. $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
  142. return $default;
  143. }
  144. // save defaults and set new fields value to main options
  145. public function save_defaults() {
  146. $tmp_options = $this->options;
  147. foreach ( $this->pre_fields as $field ) {
  148. if ( ! empty( $field['id'] ) ) {
  149. $this->options[$field['id']] = ( isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : $this->get_default( $field );
  150. }
  151. }
  152. if ( $this->args['save_defaults'] && empty( $tmp_options ) ) {
  153. $this->save_options( $this->options );
  154. }
  155. }
  156. // set options
  157. public function set_options( $ajax = false ) {
  158. // XSS ok.
  159. // No worries, This "POST" requests is sanitizing in the below foreach. see #L337 - #L341
  160. $response = ( $ajax && ! empty( $_POST['data'] ) ) ? json_decode( wp_unslash( trim( $_POST['data'] ) ), true ) : $_POST;
  161. // Set variables.
  162. $data = array();
  163. $noncekey = 'csf_options_nonce'. $this->unique;
  164. $nonce = ( ! empty( $response[$noncekey] ) ) ? $response[$noncekey] : '';
  165. $options = ( ! empty( $response[$this->unique] ) ) ? $response[$this->unique] : array();
  166. $transient = ( ! empty( $response['csf_transient'] ) ) ? $response['csf_transient'] : array();
  167. if ( wp_verify_nonce( $nonce, 'csf_options_nonce' ) ) {
  168. $importing = false;
  169. $section_id = ( ! empty( $transient['section'] ) ) ? $transient['section'] : '';
  170. if ( ! $ajax && ! empty( $response[ 'csf_import_data' ] ) ) {
  171. // XSS ok.
  172. // No worries, This "POST" requests is sanitizing in the below foreach. see #L337 - #L341
  173. $import_data = json_decode( wp_unslash( trim( $response[ 'csf_import_data' ] ) ), true );
  174. $options = ( is_array( $import_data ) && ! empty( $import_data ) ) ? $import_data : array();
  175. $importing = true;
  176. $this->notice = esc_html__( 'Settings successfully imported.', 'sakurairo_csf' );
  177. }
  178. if ( ! empty( $transient['reset'] ) ) {
  179. foreach ( $this->pre_fields as $field ) {
  180. if ( ! empty( $field['id'] ) ) {
  181. $data[$field['id']] = $this->get_default( $field );
  182. }
  183. }
  184. $this->notice = esc_html__( 'Default settings restored.', 'sakurairo_csf' );
  185. } else if ( ! empty( $transient['reset_section'] ) && ! empty( $section_id ) ) {
  186. if ( ! empty( $this->pre_sections[$section_id-1]['fields'] ) ) {
  187. foreach ( $this->pre_sections[$section_id-1]['fields'] as $field ) {
  188. if ( ! empty( $field['id'] ) ) {
  189. $data[$field['id']] = $this->get_default( $field );
  190. }
  191. }
  192. }
  193. $data = wp_parse_args( $data, $this->options );
  194. $this->notice = esc_html__( 'Default settings restored.', 'sakurairo_csf' );
  195. } else {
  196. // sanitize and validate
  197. foreach ( $this->pre_fields as $field ) {
  198. if ( ! empty( $field['id'] ) ) {
  199. $field_id = $field['id'];
  200. $field_value = isset( $options[$field_id] ) ? $options[$field_id] : '';
  201. // Ajax and Importing doing wp_unslash already.
  202. if ( ! $ajax && ! $importing ) {
  203. $field_value = wp_unslash( $field_value );
  204. }
  205. // Sanitize "post" request of field.
  206. if ( ! isset( $field['sanitize'] ) ) {
  207. if( is_array( $field_value ) ) {
  208. $data[$field_id] = wp_kses_post_deep( $field_value );
  209. } else {
  210. $data[$field_id] = wp_kses_post( $field_value );
  211. }
  212. } else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
  213. $data[$field_id] = call_user_func( $field['sanitize'], $field_value );
  214. } else {
  215. $data[$field_id] = $field_value;
  216. }
  217. // Validate "post" request of field.
  218. if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
  219. $has_validated = call_user_func( $field['validate'], $field_value );
  220. if ( ! empty( $has_validated ) ) {
  221. $data[$field_id] = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : '';
  222. $this->errors[$field_id] = $has_validated;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. $data = apply_filters( "csf_{$this->unique}_save", $data, $this );
  229. do_action( "csf_{$this->unique}_save_before", $data, $this );
  230. $this->options = $data;
  231. $this->save_options( $data );
  232. do_action( "csf_{$this->unique}_save_after", $data, $this );
  233. if ( empty( $this->notice ) ) {
  234. $this->notice = esc_html__( 'Settings saved.', 'sakurairo_csf' );
  235. }
  236. return true;
  237. }
  238. return false;
  239. }
  240. // save options database
  241. public function save_options( $data ) {
  242. if ( $this->args['database'] === 'transient' ) {
  243. set_transient( $this->unique, $data, $this->args['transient_time'] );
  244. } else if ( $this->args['database'] === 'theme_mod' ) {
  245. set_theme_mod( $this->unique, $data );
  246. } else if ( $this->args['database'] === 'network' ) {
  247. update_site_option( $this->unique, $data );
  248. } else {
  249. update_option( $this->unique, $data );
  250. }
  251. do_action( "csf_{$this->unique}_saved", $data, $this );
  252. }
  253. // get options from database
  254. public function get_options() {
  255. if ( $this->args['database'] === 'transient' ) {
  256. $this->options = get_transient( $this->unique );
  257. } else if ( $this->args['database'] === 'theme_mod' ) {
  258. $this->options = get_theme_mod( $this->unique );
  259. } else if ( $this->args['database'] === 'network' ) {
  260. $this->options = get_site_option( $this->unique );
  261. } else {
  262. $this->options = get_option( $this->unique );
  263. }
  264. if ( empty( $this->options ) ) {
  265. $this->options = array();
  266. }
  267. return $this->options;
  268. }
  269. // admin menu
  270. public function add_admin_menu() {
  271. extract( $this->args );
  272. if ( $menu_type === 'submenu' ) {
  273. $menu_page = call_user_func( 'add_submenu_page', $menu_parent, esc_attr( $menu_title ), esc_attr( $menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ) );
  274. } else {
  275. $menu_page = call_user_func( 'add_menu_page', esc_attr( $menu_title ), esc_attr( $menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ), $menu_icon, $menu_position );
  276. if ( ! empty( $sub_menu_title ) ) {
  277. call_user_func( 'add_submenu_page', $menu_slug, esc_attr( $sub_menu_title ), esc_attr( $sub_menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ) );
  278. }
  279. if ( ! empty( $this->args['show_sub_menu'] ) && count( $this->pre_tabs ) > 1 ) {
  280. // create submenus
  281. foreach ( $this->pre_tabs as $section ) {
  282. call_user_func( 'add_submenu_page', $menu_slug, esc_attr( $section['title'] ), esc_attr( $section['title'] ), $menu_capability, $menu_slug .'#tab='. sanitize_title( $section['title'] ), '__return_null' );
  283. }
  284. remove_submenu_page( $menu_slug, $menu_slug );
  285. }
  286. if ( ! empty( $menu_hidden ) ) {
  287. remove_menu_page( $menu_slug );
  288. }
  289. }
  290. add_action( 'load-'. $menu_page, array( $this, 'add_page_on_load' ) );
  291. }
  292. public function add_page_on_load() {
  293. if ( ! empty( $this->args['contextual_help'] ) ) {
  294. $screen = get_current_screen();
  295. foreach ( $this->args['contextual_help'] as $tab ) {
  296. $screen->add_help_tab( $tab );
  297. }
  298. if ( ! empty( $this->args['contextual_help_sidebar'] ) ) {
  299. $screen->set_help_sidebar( $this->args['contextual_help_sidebar'] );
  300. }
  301. }
  302. if ( ! empty( $this->args['footer_credit'] ) ) {
  303. add_filter( 'admin_footer_text', array( $this, 'add_admin_footer_text' ) );
  304. }
  305. }
  306. public function add_admin_footer_text() {
  307. echo wp_kses_post( $this->args['footer_credit'] );
  308. }
  309. public function error_check( $sections, $err = '' ) {
  310. if ( ! $this->args['ajax_save'] ) {
  311. if ( ! empty( $sections['fields'] ) ) {
  312. foreach ( $sections['fields'] as $field ) {
  313. if ( ! empty( $field['id'] ) ) {
  314. if ( array_key_exists( $field['id'], $this->errors ) ) {
  315. $err = '<span class="csf-label-error">!</span>';
  316. }
  317. }
  318. }
  319. }
  320. if ( ! empty( $sections['subs'] ) ) {
  321. foreach ( $sections['subs'] as $sub ) {
  322. $err = $this->error_check( $sub, $err );
  323. }
  324. }
  325. if ( ! empty( $sections['id'] ) && array_key_exists( $sections['id'], $this->errors ) ) {
  326. $err = $this->errors[$sections['id']];
  327. }
  328. }
  329. return $err;
  330. }
  331. // option page html output
  332. public function add_options_html() {
  333. $has_nav = ( count( $this->pre_tabs ) > 1 ) ? true : false;
  334. $show_all = ( ! $has_nav ) ? ' csf-show-all' : '';
  335. $ajax_class = ( $this->args['ajax_save'] ) ? ' csf-save-ajax' : '';
  336. $sticky_class = ( $this->args['sticky_header'] ) ? ' csf-sticky-header' : '';
  337. $wrapper_class = ( $this->args['framework_class'] ) ? ' '. $this->args['framework_class'] : '';
  338. $theme = ( $this->args['theme'] ) ? ' csf-theme-'. $this->args['theme'] : '';
  339. $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
  340. $nav_type = ( $this->args['nav'] === 'inline' ) ? 'inline' : 'normal';
  341. $form_action = ( $this->args['form_action'] ) ? $this->args['form_action'] : '';
  342. do_action( 'csf_options_before' );
  343. echo '<div class="csf csf-options'. esc_attr( $theme . $class . $wrapper_class ) .'" data-slug="'. esc_attr( $this->args['menu_slug'] ) .'" data-unique="'. esc_attr( $this->unique ) .'">';
  344. echo '<div class="csf-container">';
  345. echo '<form method="post" action="'. esc_attr( $form_action ) .'" enctype="multipart/form-data" id="csf-form" autocomplete="off" novalidate="novalidate">';
  346. echo '<input type="hidden" class="csf-section-id" name="csf_transient[section]" value="1">';
  347. wp_nonce_field( 'csf_options_nonce', 'csf_options_nonce'. $this->unique );
  348. echo '<div class="csf-header'. esc_attr( $sticky_class ) .'">';
  349. echo '<div class="csf-header-inner">';
  350. echo '<div class="csf-header-left">';
  351. echo '<h1>'. $this->args['framework_title'] .'</h1>';
  352. echo '</div>';
  353. echo '<div class="csf-header-right">';
  354. $notice_class = ( ! empty( $this->notice ) ) ? 'csf-form-show' : '';
  355. $notice_text = ( ! empty( $this->notice ) ) ? $this->notice : '';
  356. echo '<div class="csf-form-result csf-form-success '. esc_attr( $notice_class ) .'">'. $notice_text .'</div>';
  357. echo ( $this->args['show_form_warning'] ) ? '<div class="csf-form-result csf-form-warning">'. esc_html__( 'You have unsaved changes, save your changes!', 'sakurairo_csf' ) .'</div>' : '';
  358. echo ( $has_nav && $this->args['show_all_options'] ) ? '<div class="csf-expand-all" title="'. esc_html__( 'show all settings', 'sakurairo_csf' ) .'"><i class="fas fa-outdent"></i></div>' : '';
  359. echo ( $this->args['show_search'] ) ? '<div class="csf-search"><input type="text" name="csf-search" placeholder="'. esc_html__( 'Search...', 'sakurairo_csf' ) .'" autocomplete="off" /></div>' : '';
  360. echo '<div class="csf-buttons">';
  361. echo '<input type="submit" name="'. esc_attr( $this->unique ) .'[_nonce][save]" class="button button-primary csf-top-save csf-save'. esc_attr( $ajax_class ) .'" value="'. esc_html__( 'Save', 'sakurairo_csf' ) .'" data-save="'. esc_html__( 'Saving...', 'sakurairo_csf' ) .'">';
  362. echo ( $this->args['show_reset_section'] ) ? '<input type="submit" name="csf_transient[reset_section]" class="button button-secondary csf-reset-section csf-confirm" value="'. esc_html__( 'Reset Section', 'sakurairo_csf' ) .'" data-confirm="'. esc_html__( 'Are you sure to reset this section options?', 'sakurairo_csf' ) .'">' : '';
  363. echo ( $this->args['show_reset_all'] ) ? '<input type="submit" name="csf_transient[reset]" class="button csf-warning-primary csf-reset-all csf-confirm" value="'. ( ( $this->args['show_reset_section'] ) ? esc_html__( 'Reset All', 'sakurairo_csf' ) : esc_html__( 'Reset', 'sakurairo_csf' ) ) .'" data-confirm="'. esc_html__( 'Are you sure you want to reset all settings to default values?', 'sakurairo_csf' ) .'">' : '';
  364. echo '</div>';
  365. echo '</div>';
  366. echo '<div class="clear"></div>';
  367. echo '</div>';
  368. echo '</div>';
  369. echo '<div class="csf-wrapper'. esc_attr( $show_all ) .'">';
  370. if ( $has_nav ) {
  371. echo '<div class="csf-nav csf-nav-'. esc_attr( $nav_type ) .' csf-nav-options">';
  372. echo '<ul>';
  373. foreach ( $this->pre_tabs as $tab ) {
  374. $tab_id = sanitize_title( $tab['title'] );
  375. $tab_error = $this->error_check( $tab );
  376. $tab_icon = ( ! empty( $tab['icon'] ) ) ? '<i class="csf-tab-icon '. esc_attr( $tab['icon'] ) .'"></i>' : '';
  377. if ( ! empty( $tab['subs'] ) ) {
  378. echo '<li class="csf-tab-item">';
  379. echo '<a href="#tab='. esc_attr( $tab_id ) .'" data-tab-id="'. esc_attr( $tab_id ) .'" class="csf-arrow">'. $tab_icon . $tab['title'] . $tab_error .'</a>';
  380. echo '<ul>';
  381. foreach ( $tab['subs'] as $sub ) {
  382. $sub_id = $tab_id .'/'. sanitize_title( $sub['title'] );
  383. $sub_error = $this->error_check( $sub );
  384. $sub_icon = ( ! empty( $sub['icon'] ) ) ? '<i class="csf-tab-icon '. esc_attr( $sub['icon'] ) .'"></i>' : '';
  385. echo '<li><a href="#tab='. esc_attr( $sub_id ) .'" data-tab-id="'. esc_attr( $sub_id ) .'">'. $sub_icon . $sub['title'] . $sub_error .'</a></li>';
  386. }
  387. echo '</ul>';
  388. echo '</li>';
  389. } else {
  390. echo '<li class="csf-tab-item"><a href="#tab='. esc_attr( $tab_id ) .'" data-tab-id="'. esc_attr( $tab_id ) .'">'. $tab_icon . $tab['title'] . $tab_error .'</a></li>';
  391. }
  392. }
  393. echo '</ul>';
  394. echo '</div>';
  395. }
  396. echo '<div class="csf-content">';
  397. echo '<div class="csf-sections">';
  398. foreach ( $this->pre_sections as $section ) {
  399. $section_onload = ( ! $has_nav ) ? ' csf-onload' : '';
  400. $section_class = ( ! empty( $section['class'] ) ) ? ' '. $section['class'] : '';
  401. $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="csf-section-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
  402. $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
  403. $section_parent = ( ! empty( $section['ptitle'] ) ) ? sanitize_title( $section['ptitle'] ) .'/' : '';
  404. $section_slug = ( ! empty( $section['title'] ) ) ? sanitize_title( $section_title ) : '';
  405. echo '<div class="csf-section hidden'. esc_attr( $section_onload . $section_class ) .'" data-section-id="'. esc_attr( $section_parent . $section_slug ) .'">';
  406. echo ( $has_nav ) ? '<div class="csf-section-title"><h3>'. $section_icon . $section_title .'</h3></div>' : '';
  407. echo ( ! empty( $section['description'] ) ) ? '<div class="csf-field csf-section-description">'. $section['description'] .'</div>' : '';
  408. if ( ! empty( $section['fields'] ) ) {
  409. foreach ( $section['fields'] as $field ) {
  410. $is_field_error = $this->error_check( $field );
  411. if ( ! empty( $is_field_error ) ) {
  412. $field['_error'] = $is_field_error;
  413. }
  414. if ( ! empty( $field['id'] ) ) {
  415. $field['default'] = $this->get_default( $field );
  416. }
  417. $value = ( ! empty( $field['id'] ) && isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : '';
  418. Sakurairo_CSF::field( $field, $value, $this->unique, 'options' );
  419. }
  420. } else {
  421. echo '<div class="csf-no-option">'. esc_html__( 'No data available.', 'sakurairo_csf' ) .'</div>';
  422. }
  423. echo '</div>';
  424. }
  425. echo '</div>';
  426. echo '<div class="clear"></div>';
  427. echo '</div>';
  428. echo ( $has_nav && $nav_type === 'normal' ) ? '<div class="csf-nav-background"></div>' : '';
  429. echo '</div>';
  430. if ( ! empty( $this->args['show_footer'] ) ) {
  431. echo '<div class="csf-footer">';
  432. echo '<div class="csf-buttons">';
  433. echo '<input type="submit" name="csf_transient[save]" class="button button-primary csf-save'. esc_attr( $ajax_class ) .'" value="'. esc_html__( 'Save', 'sakurairo_csf' ) .'" data-save="'. esc_html__( 'Saving...', 'sakurairo_csf' ) .'">';
  434. echo ( $this->args['show_reset_section'] ) ? '<input type="submit" name="csf_transient[reset_section]" class="button button-secondary csf-reset-section csf-confirm" value="'. esc_html__( 'Reset Section', 'sakurairo_csf' ) .'" data-confirm="'. esc_html__( 'Are you sure to reset this section options?', 'sakurairo_csf' ) .'">' : '';
  435. echo ( $this->args['show_reset_all'] ) ? '<input type="submit" name="csf_transient[reset]" class="button csf-warning-primary csf-reset-all csf-confirm" value="'. ( ( $this->args['show_reset_section'] ) ? esc_html__( 'Reset All', 'sakurairo_csf' ) : esc_html__( 'Reset', 'sakurairo_csf' ) ) .'" data-confirm="'. esc_html__( 'Are you sure you want to reset all settings to default values?', 'sakurairo_csf' ) .'">' : '';
  436. echo '</div>';
  437. echo ( ! empty( $this->args['footer_text'] ) ) ? '<div class="csf-copyright">'. $this->args['footer_text'] .'</div>' : '';
  438. echo '<div class="clear"></div>';
  439. echo '</div>';
  440. }
  441. echo '</form>';
  442. echo '</div>';
  443. echo '<div class="clear"></div>';
  444. echo ( ! empty( $this->args['footer_after'] ) ) ? $this->args['footer_after'] : '';
  445. echo '</div>';
  446. do_action( 'csf_options_after' );
  447. }
  448. }
  449. }