-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-plugin.php
More file actions
107 lines (94 loc) · 4.09 KB
/
custom-plugin.php
File metadata and controls
107 lines (94 loc) · 4.09 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
<?php
/**
* WP Admin Panel Framework
*
* A modern and professional framework for building WordPress admin panels with advanced features.
* Includes a powerful dashboard, data management system, and extensive API integration capabilities.
* Built with clean architecture and developer experience in mind.
*
* @package WPAdminPanelFramework
* @author Your Name
* @copyright 2024 Your Name or Company Name
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: WP Admin Panel Framework
* Plugin URI: https://github.com/username/wp-admin-panel-framework
* Description: A modern framework for creating professional WordPress admin panels with advanced data management, REST API integration, and a powerful dashboard. Features include CRUD operations, real-time statistics, custom fields, and extensive developer tools.
* Version: 1.0.0
* Requires at least: 5.8
* Requires PHP: 7.4
* Author: Your Name
* Author URI: https://yourwebsite.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-admin-panel-framework
* Domain Path: /languages
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
// Composer autoloader
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) {
require_once dirname(__FILE__) . '/vendor/autoload.php';
}
// Define plugin constants
define('CP_VERSION', '1.0.0');
define('CP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('CP_PLUGIN_URL', plugin_dir_url(__FILE__));
define('CP_PLUGIN_BASENAME', plugin_basename(__FILE__));
define('CP_ASSETS_URL', CP_PLUGIN_URL . 'assets/');
define('CP_TEMPLATES_DIR', CP_PLUGIN_DIR . 'templates/');
// Load environment variables
if (file_exists(CP_PLUGIN_DIR . '.env')) {
$dotenv = Dotenv\Dotenv::createImmutable(CP_PLUGIN_DIR);
$dotenv->load();
}
// Initialize the plugin
if (!function_exists('initialize_custom_plugin')):
function initialize_custom_plugin() {
try {
// Initialize error handler
$errorHandler = new CustomPlugin\Core\ErrorHandler();
set_error_handler([$errorHandler, 'handleError']);
set_exception_handler([$errorHandler, 'handleException']);
// Initialize logger
$logger = new CustomPlugin\Core\Logger();
// Initialize the plugin
$plugin = new CustomPlugin\Core\Plugin($logger);
// Register activation/deactivation hooks
register_activation_hook(__FILE__, [$plugin, 'activate']);
register_deactivation_hook(__FILE__, [$plugin, 'deactivate']);
// Initialize core components
$plugin->initializeCore();
// Initialize REST API
add_action('rest_api_init', [$plugin, 'initializeRestApi']);
// Initialize admin interface
if (is_admin()) {
$admin = new CustomPlugin\Admin\AdminInterface($plugin);
$admin->initialize();
}
} catch (\Exception $e) {
$logger->error('Plugin initialization failed: ' . $e->getMessage());
add_action('admin_notices', function() use ($e) {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__('Custom Plugin initialization failed: ' . $e->getMessage(), 'custom-plugin')
);
});
}
}
endif;
// Initialize the plugin after all plugins are loaded
add_action('plugins_loaded', 'initialize_custom_plugin');