-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmart-client-intake.php
More file actions
162 lines (143 loc) · 5 KB
/
Copy pathsmart-client-intake.php
File metadata and controls
162 lines (143 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Plugin Name: Smart Client Intake System
* Plugin URI: https://github.com/sharanvijaydev/smart-client-intake
* Description: A client submission and case management plugin with custom post type, admin dashboard, filterable list table, CSV export, email notifications, REST API, and frontend intake form with spam protection.
* Version: 1.0.0
* Author: R Saravanan
* Author URI: https://www.linkedin.com/in/sharanvijay/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: smart-client-intake
* Requires at least: 6.0
* Requires PHP: 7.4
*/
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Plugin constants.
define( 'SCI_VERSION', '1.0.0' );
define( 'SCI_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'SCI_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'SCI_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
// Load all include files.
require_once SCI_PLUGIN_DIR . 'includes/class-cpt-submission.php';
require_once SCI_PLUGIN_DIR . 'includes/class-meta-boxes.php';
require_once SCI_PLUGIN_DIR . 'includes/class-list-table.php';
require_once SCI_PLUGIN_DIR . 'includes/class-admin-page.php';
require_once SCI_PLUGIN_DIR . 'includes/class-form-handler.php';
require_once SCI_PLUGIN_DIR . 'includes/class-email-notification.php';
require_once SCI_PLUGIN_DIR . 'includes/class-csv-export.php';
require_once SCI_PLUGIN_DIR . 'includes/class-rest-api.php';
/**
* Main Plugin Class — Singleton Pattern.
*
* Bootstraps all components: CPT, meta boxes, admin pages,
* form handling, email notifications, CSV export, and REST API.
*/
final class Smart_Client_Intake {
/**
* Single instance.
*
* @var Smart_Client_Intake|null
*/
private static $instance = null;
/**
* Get the singleton instance.
*
* @return Smart_Client_Intake
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor — initialize all components.
*/
private function __construct() {
// Core components.
new SCI_CPT_Submission();
new SCI_Meta_Boxes();
new SCI_Admin_Page();
new SCI_Form_Handler();
new SCI_Email_Notification();
new SCI_CSV_Export();
new SCI_REST_API();
// Enqueue assets.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) );
// Settings link on plugins page.
add_filter( 'plugin_action_links_' . SCI_PLUGIN_BASENAME, array( $this, 'add_plugin_links' ) );
}
/**
* Enqueue admin CSS on relevant pages only.
*
* @param string $hook Current admin page hook.
*/
public function enqueue_admin_assets( $hook ) {
$screen = get_current_screen();
// Load only on our admin page and submission edit screens.
$allowed_screens = array(
'toplevel_page_sci-dashboard',
'sci_submission',
);
if ( $screen && ( in_array( $screen->id, $allowed_screens, true ) || 'sci_submission' === $screen->post_type ) ) {
wp_enqueue_style(
'sci-admin',
SCI_PLUGIN_URL . 'assets/css/admin.css',
array(),
SCI_VERSION
);
}
}
/**
* Enqueue frontend CSS and JS on pages containing our shortcode.
*/
public function enqueue_frontend_assets() {
global $post;
if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'client_intake_form' ) ) {
wp_enqueue_style(
'sci-frontend',
SCI_PLUGIN_URL . 'assets/css/frontend.css',
array(),
SCI_VERSION
);
wp_enqueue_script(
'sci-form-validation',
SCI_PLUGIN_URL . 'assets/js/form-validation.js',
array(),
SCI_VERSION,
true
);
}
}
/**
* Add quick links on the Plugins page.
*
* @param array $links Existing plugin links.
* @return array Modified links.
*/
public function add_plugin_links( $links ) {
$dashboard_link = '<a href="' . esc_url( admin_url( 'admin.php?page=sci-dashboard' ) ) . '">'
. esc_html__( 'Dashboard', 'smart-client-intake' ) . '</a>';
array_unshift( $links, $dashboard_link );
return $links;
}
}
// Activation hook — flush rewrite rules so CPT permalinks work.
register_activation_hook( __FILE__, function () {
$cpt = new SCI_CPT_Submission();
$cpt->register_post_type();
flush_rewrite_rules();
} );
// Deactivation hook — clean up rewrite rules.
register_deactivation_hook( __FILE__, function () {
flush_rewrite_rules();
} );
// Boot the plugin.
add_action( 'plugins_loaded', function () {
Smart_Client_Intake::get_instance();
} );