Skip to content

Commit 83fb6ad

Browse files
authored
Bug fix
1 parent 77e02a4 commit 83fb6ad

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

admin/class-smarty-fs-admin.php

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -271,30 +271,37 @@ public function fs_admin_notice() {
271271
* @return void
272272
*/
273273
public function register_submission_type() {
274-
register_post_type('submission',
275-
array(
276-
'labels' => array(
277-
'name' => __('Submissions', 'smarty-form-submissions'),
278-
'singular_name' => __('Submission', 'smarty-form-submissions'),
279-
'add_new' => __('Add New Submission', 'smarty-form-submissions'),
280-
'add_new_item' => __('Add New Submission', 'smarty-form-submissions'),
281-
'edit_item' => __('Edit Submission', 'smarty-form-submissions'),
282-
'view_item' => __('View Submission', 'smarty-form-submissions'),
283-
'all_items' => __('All Submissions', 'smarty-form-submissions'),
284-
'search_items' => __('Search Submissions', 'smarty-form-submissions'),
285-
),
286-
'public' => true,
287-
'publicly_queryable' => false,
288-
'exclude_from_search' => true,
289-
'has_archive' => false,
290-
'rewrite' => array(
291-
'slug' => 'submissions'
292-
),
293-
'taxonomies' => array('subject'),
294-
'menu_icon' => 'dashicons-buddicons-pm',
295-
'supports' => array('custom-fields'),
296-
)
297-
);
274+
// Check if the license is valid
275+
$license_options = get_option('smarty_fs_settings_license');
276+
$api_key = $license_options['api_key'] ?? '';
277+
278+
// Only register the post type if the license is active
279+
if ($this->license->fs_is_valid_api_key($api_key)) {
280+
register_post_type('submission',
281+
array(
282+
'labels' => array(
283+
'name' => __('Submissions', 'smarty-form-submissions'),
284+
'singular_name' => __('Submission', 'smarty-form-submissions'),
285+
'add_new' => __('Add New Submission', 'smarty-form-submissions'),
286+
'add_new_item' => __('Add New Submission', 'smarty-form-submissions'),
287+
'edit_item' => __('Edit Submission', 'smarty-form-submissions'),
288+
'view_item' => __('View Submission', 'smarty-form-submissions'),
289+
'all_items' => __('All Submissions', 'smarty-form-submissions'),
290+
'search_items' => __('Search Submissions', 'smarty-form-submissions'),
291+
),
292+
'public' => true,
293+
'publicly_queryable' => false,
294+
'exclude_from_search' => true,
295+
'has_archive' => false,
296+
'rewrite' => array(
297+
'slug' => 'submissions'
298+
),
299+
'taxonomies' => array('subject'),
300+
'menu_icon' => 'dashicons-buddicons-pm',
301+
'supports' => array('custom-fields'),
302+
)
303+
);
304+
}
298305
}
299306

300307
/**
@@ -346,11 +353,17 @@ public function remove_add_new_submenu() {
346353
* @since 1.0.0
347354
*/
348355
public function register_submission_routes() {
349-
register_rest_route('smarty/v1', '/submit-form/', array(
350-
'methods' => WP_REST_Server::CREATABLE,
351-
'callback' => array($this, 'handle_form_submission'), // Corrected callback reference
352-
'permission_callback' => '__return_true',
353-
));
356+
// Check if the license is valid
357+
$license_options = get_option('smarty_fs_settings_license');
358+
$api_key = $license_options['api_key'] ?? '';
359+
360+
if ($this->license->fs_is_valid_api_key($api_key)) {
361+
register_rest_route('smarty/v1', '/submit-form/', array(
362+
'methods' => WP_REST_Server::CREATABLE,
363+
'callback' => array($this, 'handle_form_submission'), // Corrected callback reference
364+
'permission_callback' => '__return_true',
365+
));
366+
}
354367
}
355368

356369
/**
@@ -435,7 +448,7 @@ public function add_submission_meta_boxes() {
435448

436449
add_meta_box(
437450
'submission_admin_comments', // Unique ID
438-
__('Comments', 'smarty-form-submissions'), // Box title
451+
__('Comments', 'smarty-form-submissions'), // Box title
439452
array($this, 'admin_comments_meta_box_html'), // Callback function
440453
'submission' // Post type
441454
);

0 commit comments

Comments
 (0)