1 | <?php |
||
2 | /** |
||
3 | * Contains the settings class for LSX |
||
4 | * |
||
5 | * @package lsx-projects |
||
6 | */ |
||
7 | |||
8 | namespace lsx\projects\classes\admin; |
||
9 | |||
10 | class Settings { |
||
0 ignored issues
–
show
Coding Style
Documentation
introduced
by
![]() |
|||
11 | |||
12 | /** |
||
13 | * Holds class instance |
||
14 | * |
||
15 | * @since 1.0.0 |
||
16 | * |
||
17 | * @var object \lsx_projects\classes\admin\Settings() |
||
18 | */ |
||
19 | protected static $instance = null; |
||
20 | |||
21 | /** |
||
22 | * Option key, and option page slug |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $screen_id = 'lsx_projects_settings'; |
||
27 | |||
28 | /** |
||
29 | * Contructor |
||
30 | */ |
||
31 | public function __construct() { |
||
0 ignored issues
–
show
|
|||
32 | add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) ); |
||
33 | add_action( 'lsx_projects_settings_page', array( $this, 'general_settings' ), 1, 1 ); |
||
34 | add_action( 'lsx_projects_settings_page', array( $this, 'contact_modal_settings' ), 1, 1 ); |
||
35 | } |
||
0 ignored issues
–
show
|
|||
36 | |||
37 | /** |
||
38 | * Return an instance of this class. |
||
39 | * |
||
40 | * @since 1.0.0 |
||
41 | * |
||
42 | * @return object Settings() A single instance of this class. |
||
43 | */ |
||
44 | public static function get_instance() { |
||
45 | // If the single instance hasn't been set, set it now. |
||
46 | if ( null === self::$instance ) { |
||
0 ignored issues
–
show
|
|||
47 | self::$instance = new self(); |
||
48 | } |
||
0 ignored issues
–
show
|
|||
49 | return self::$instance; |
||
50 | } |
||
0 ignored issues
–
show
|
|||
51 | |||
52 | /** |
||
53 | * Hook in and register a submenu options page for the Page post-type menu. |
||
54 | */ |
||
55 | public function register_settings_page() { |
||
56 | $cmb = new_cmb2_box( |
||
57 | array( |
||
58 | 'id' => $this->screen_id, |
||
59 | 'title' => esc_html__( 'Settings', 'lsx-projects' ), |
||
60 | 'object_types' => array( 'options-page' ), |
||
61 | 'option_key' => 'lsx_projects_options', // The option key and admin menu page slug. |
||
62 | 'parent_slug' => 'edit.php?post_type=project', // Make options page a submenu item of the themes menu. |
||
63 | 'capability' => 'manage_options', // Cap required to view options-page. |
||
64 | ) |
||
65 | ); |
||
66 | do_action( 'lsx_projects_settings_page', $cmb ); |
||
67 | } |
||
0 ignored issues
–
show
|
|||
68 | |||
69 | /** |
||
70 | * Registers the general settings. |
||
71 | * |
||
72 | * @param object $cmb new_cmb2_box(). |
||
73 | * @return void |
||
74 | */ |
||
75 | public function general_settings( $cmb ) { |
||
76 | $cmb->add_field( |
||
77 | array( |
||
78 | 'id' => 'settings_general_title', |
||
79 | 'type' => 'title', |
||
80 | 'name' => __( 'General', 'lsx-projects' ), |
||
81 | 'default' => __( 'General', 'lsx-projects' ), |
||
82 | ) |
||
83 | ); |
||
84 | $cmb->add_field( |
||
85 | array( |
||
86 | 'name' => __( 'Disable Single Posts', 'lsx-projects' ), |
||
87 | 'id' => 'projects_disable_single', |
||
88 | 'type' => 'checkbox', |
||
89 | 'value' => 1, |
||
90 | 'default' => 0, |
||
91 | 'description' => __( 'Disable Single Posts.', 'lsx-projects' ), |
||
92 | ) |
||
93 | ); |
||
94 | |||
95 | $cmb->add_field( |
||
96 | array( |
||
97 | 'name' => 'Placeholder', |
||
98 | 'desc' => __( 'Choose Image.', 'lsx-projects' ), |
||
99 | 'id' => 'projects_placeholder', |
||
100 | 'type' => 'file', |
||
101 | 'options' => array( |
||
102 | 'url' => false, // Hide the text input for the url. |
||
103 | ), |
||
104 | 'text' => array( |
||
105 | 'add_upload_file_text' => 'Choose Image', |
||
106 | ), |
||
107 | ) |
||
108 | ); |
||
109 | |||
110 | $cmb->add_field( |
||
111 | array( |
||
112 | 'id' => 'settings_general_closing', |
||
113 | 'type' => 'tab_closing', |
||
114 | ) |
||
115 | ); |
||
116 | } |
||
0 ignored issues
–
show
|
|||
117 | |||
118 | /** |
||
119 | * Registers the Contact modal settings. |
||
120 | * |
||
121 | * @param object $cmb new_cmb2_box(). |
||
122 | * @return void |
||
123 | */ |
||
124 | public function contact_modal_settings( $cmb ) { |
||
125 | $cmb->add_field( |
||
126 | array( |
||
127 | 'id' => 'settings_contact_modal_title', |
||
0 ignored issues
–
show
|
|||
128 | 'type' => 'title', |
||
0 ignored issues
–
show
|
|||
129 | 'name' => __( 'Contact modal', 'lsx-projects' ), |
||
0 ignored issues
–
show
|
|||
130 | 'description' => __( 'Displays contact modal on project single if there is a linked Caldera or WPform.', 'lsx-projects' ), |
||
131 | ) |
||
132 | ); |
||
133 | $cmb->add_field( |
||
134 | array( |
||
135 | 'name' => __( 'Enable contact modal', 'lsx-projects' ), |
||
136 | 'id' => 'projects_modal_enable', |
||
137 | 'type' => 'checkbox', |
||
138 | 'value' => 1, |
||
139 | 'default' => 0, |
||
140 | 'description' => __( 'Displays contact modal on project single.', 'lsx-projects' ), |
||
141 | ) |
||
142 | ); |
||
143 | |||
144 | $cmb->add_field( |
||
145 | array( |
||
146 | 'name' => __( 'Button label', 'lsx-projects' ), |
||
147 | 'id' => 'projects_modal_cta_label', |
||
148 | 'type' => 'text', |
||
149 | ) |
||
150 | ); |
||
151 | |||
152 | $cmb->add_field( |
||
153 | array( |
||
154 | 'name' => __( 'Caldera Form ID (if enabled)', 'lsx-projects' ), |
||
155 | 'id' => 'projects_modal_form_id', |
||
156 | 'type' => 'text', |
||
157 | ) |
||
158 | ); |
||
159 | |||
160 | $cmb->add_field( |
||
161 | array( |
||
162 | 'name' => __( 'WPForm ID (if enabled)', 'lsx-projects' ), |
||
163 | 'id' => 'projects_wpform_modal_form_id', |
||
164 | 'type' => 'text', |
||
165 | ) |
||
166 | ); |
||
167 | |||
168 | $cmb->add_field( |
||
169 | array( |
||
170 | 'id' => 'settings_contact_modal_closing', |
||
171 | 'type' => 'tab_closing', |
||
172 | ) |
||
173 | ); |
||
174 | } |
||
0 ignored issues
–
show
|
|||
175 | |||
176 | } |
||
177 |