class-fl-builder-user-templates-admin-settings.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Admin settings for user defined templates in the builder.
  4. *
  5. * @since 1.8
  6. */
  7. final class FLBuilderUserTemplatesAdminSettings {
  8. /**
  9. * Initialize hooks.
  10. *
  11. * @since 1.8
  12. * @return void
  13. */
  14. static public function init() {
  15. if ( is_admin() && isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], array( 'fl-builder-settings', 'fl-builder-multisite-settings' ) ) ) {
  16. add_filter( 'fl_builder_admin_settings_nav_items', __CLASS__ . '::admin_settings_nav_items' );
  17. add_action( 'fl_builder_admin_settings_render_forms', __CLASS__ . '::admin_settings_render_form' );
  18. add_action( 'fl_builder_admin_settings_save', __CLASS__ . '::save_settings' );
  19. }
  20. }
  21. /**
  22. * Adds the Templates nav item to the admin settings.
  23. *
  24. * @since 1.8
  25. * @param array $nav_items
  26. * @return array
  27. */
  28. static public function admin_settings_nav_items( $nav_items ) {
  29. $nav_items['templates'] = array(
  30. 'title' => __( 'Templates', 'vamtam-elements-b' ),
  31. 'show' => true,
  32. 'priority' => 450,
  33. );
  34. return $nav_items;
  35. }
  36. /**
  37. * Renders the admin settings templates form.
  38. *
  39. * @since 1.8
  40. * @return void
  41. */
  42. static public function admin_settings_render_form() {
  43. $enabled_templates = FLBuilderModel::get_enabled_templates();
  44. include VAMTAMEL_B_USER_TEMPLATES_DIR . 'includes/admin-settings-templates.php';
  45. }
  46. /**
  47. * Saves the template settings.
  48. *
  49. * @since 1.8
  50. * @return void
  51. */
  52. static public function save_settings() {
  53. if ( isset( $_POST['fl-templates-nonce'] ) && wp_verify_nonce( $_POST['fl-templates-nonce'], 'templates' ) ) {
  54. $enabled_templates = sanitize_text_field( $_POST['fl-template-settings'] );
  55. FLBuilderModel::update_admin_settings_option( '_fl_builder_enabled_templates', $enabled_templates, true );
  56. }
  57. }
  58. }
  59. FLBuilderUserTemplatesAdminSettings::init();