-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.php
129 lines (115 loc) · 4.23 KB
/
Core.php
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
<?php
/**
* Plugin Name: sample OOP Plugin
* Plugin URI: https://github.com/sadeq-yaqobi/
* Description: A simple WordPress plugin demonstrating Object-Oriented Programming principles.
* Author: Sadeq Yaqobi
* Version: 1.0.0
* License: GPLv2 or later
* Author URI: https://github.com/sadeq-yaqobi/
*/
defined('ABSPATH') || exit();
/**
* Class Core
*
* Main class for the OOP Plugin functionality.
*/
class Core
{
/**
* Constructor for the class.
*
* Initializes the plugin by setting up constants and calling the initialization method.
*/
public function __construct()
{
$this->define_constants();
$this->init();
}
/**
* Define plugin-related constants.
*/
public function define_constants()
{
define('OOP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('OOP_PLUGIN_URL', plugin_dir_url(__FILE__));
}
/**
* Initialize the plugin.
*
* This method handles the setup of the plugin, including activation, deactivation, and asset registration.
*/
public function init()
{
// Include the Autoload class for automatic loading of other classes
include_once 'AutoLoad.php';
// Register activation and deactivation hooks
register_activation_hook(__FILE__, [$this, 'activation']);
register_deactivation_hook(__FILE__, [$this, 'deactivation']);
// Register asset registration actions for both admin and front-end
add_action('admin_enqueue_scripts', [$this, 'register_assets']); // Register assets on the admin side
add_action('wp_enqueue_scripts', [$this, 'register_assets']); // Register assets on the front side
// Load entities (assuming it's a method responsible for loading plugin entities)
$this->load_entities();
}
/**
* Actions to perform on plugin activation.
*
* You can add any necessary tasks here, such as creating database tables.
*/
public function activation()
{
// Add activation tasks here
}
/**
* Actions to perform on plugin deactivation.
*/
public function deactivation()
{
// Add deactivation tasks here
}
/**
* Register and enqueue assets (CSS and JS).
*/
public function register_assets()
{
// Register and enqueue CSS
if (is_admin()) {
// Admin styles
wp_register_style('bootstrap-5', 'https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.rtl.min.css', '', '5.0.2');
wp_register_style('fontawesome-icon', 'https://use.fontawesome.com/releases/v5.15.4/css/all.css', '', '5.15.4');
wp_register_style('dashboard-style', plugins_url('oop-plugin/assets/css/admin.css'), '', '1.0.0');
wp_enqueue_style('bootstrap-5');
wp_enqueue_style('fontawesome-icon');
wp_enqueue_style('dashboard-style');
} else {
// Frontend styles
wp_register_style('front-style', plugins_url('oop-plugin/assets/css/front.css'), '', '1.0.0');
wp_enqueue_style('front-style');
}
// Register and enqueue JS
if (is_admin()) {
// Admin scripts
wp_register_script('sweet-alert-js', 'https://cdn.jsdelivr.net/npm/sweetalert2@11', '', '2.11.0', ['strategy' => 'async', 'in_footer' => true]);
wp_register_script('dashboard-js', OOP_PLUGIN_URL . 'assets/js/admin.js', ['jquery'], '1.0.0', ['strategy' => 'defer', 'in_footer' => false]);
wp_enqueue_script('sweet-alert-js');
wp_enqueue_script('dashboard-js');
} else {
// Frontend scripts
wp_register_script('front-js', OOP_PLUGIN_URL . 'assets/js/front.js', ['jquery'], '1.0.0', ['strategy' => 'defer', 'in_footer' => false]);
wp_enqueue_script('front-js');
}
}
public function load_entities()
{
// Load plugin entities, such as the UserEntity entity by new objects.
new Menu_ExampleUser();
new MetaBox_ExampleVideoUrl();
new PostType_ExampleBook();
new Taxonomy_ExampleWriter();
new Widget_ExampleInfo();
new Setting_ExampleGatePay();
}
}
// Instantiate the Core class to initialize the plugin
$core = new Core();