-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
srpw.php
113 lines (92 loc) · 3.82 KB
/
srpw.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
<?php
/**
* Plugin Name: Smart Recent Posts Widget
* Plugin URI: https://wordpress.org/plugins/smart-recent-posts-widget/
* Description: Enables advanced widget that gives you total control over the output of your site’s most recent Posts.
* Version: 1.0.4
* Author: satrya
* Author URI: https://profiles.wordpress.org/satrya/
* Author Email: [email protected]
* Text Domain: smart-recent-posts-widget
* 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.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Exit if accessed directly
if (!defined('ABSPATH')) exit;
class SMART_RPW {
/**
* Constructor method.
*/
public function __construct() {
// Set the constants needed by the plugin.
add_action('plugins_loaded', array(&$this, 'constants'), 1);
// Internationalize the text strings used.
add_action('plugins_loaded', array(&$this, 'i18n'), 2);
// Load the functions files.
add_action('plugins_loaded', array(&$this, 'includes'), 3);
// Load the admin style and script.
add_action('admin_enqueue_scripts', array(&$this, 'admin_scripts'));
add_action('customize_controls_enqueue_scripts', array(&$this, 'admin_scripts'));
add_action('enqueue_block_editor_assets', array(&$this, 'admin_scripts'));
// Register widget.
add_action('widgets_init', array(&$this, 'register_widget'));
// Enqueue the front-end styles.
add_action('wp_enqueue_scripts', array(&$this, 'plugin_style'), 99);
add_action('enqueue_block_editor_assets', array(&$this, 'plugin_style'));
}
/**
* Defines constants used by the plugin.
*/
public function constants() {
// Set constant path to the plugin directory.
define('SRPW_DIR', trailingslashit(plugin_dir_path(__FILE__)));
// Set the constant path to the plugin directory URI.
define('SRPW_URI', trailingslashit(plugin_dir_url(__FILE__)));
// Set the constant path to the includes directory.
define('SRPW_INCLUDES', SRPW_DIR . trailingslashit('includes'));
// Set the constant path to the assets directory.
define('SRPW_ASSETS', SRPW_URI . trailingslashit('assets'));
}
/**
* Loads the translation files.
*/
public function i18n() {
load_plugin_textdomain('smart-recent-posts-widget', false, dirname(plugin_basename(__FILE__)) . '/languages/');
}
/**
* Loads the initial files needed by the plugin.
*/
public function includes() {
require_once(SRPW_INCLUDES . 'functions.php');
require_once(SRPW_INCLUDES . 'helpers.php');
require_once(SRPW_INCLUDES . 'widget.php');
}
/**
* Register custom style and script for the widget settings.
*/
public function admin_scripts() {
wp_enqueue_style('srpw-admin-style', trailingslashit(SRPW_ASSETS) . 'css/srpw-admin.css', null, null);
}
/**
* Register the widget.
*/
public function register_widget() {
register_widget('SMART_RECENT_POSTS_WIDGET');
}
/**
* Enqueue front-end style.
*/
public function plugin_style() {
wp_enqueue_style('srpw-style', trailingslashit(SRPW_ASSETS) . 'css/srpw-frontend.css');
}
}
new SMART_RPW;