-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-edd-changelog.php
142 lines (124 loc) · 3.17 KB
/
simple-edd-changelog.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
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Easy Digital Downloads - Changelog
*
* Plugin Name: Easy Digital Downloads - Changelog
* Plugin URI: https://themesgrove.com/
* Description: Display changlog for EDD download.
* Tags: edd, edd-changelog, changelog
* Version: 0.1
* Author: ThemesGrove
* Author URI: https://themesgrove.com/
* Text Domain: simple-edd-changelog
*
* Requires PHP: 5.6
* Requires at least: 4.9
* Tested up to: 5.4
*/
// Exit if accessed directly.
if (!defined('ABSPATH')) exit;
final class EDDChangelog
{
/**
* The single instance of this class
*/
private static $instance = null;
/**
* Construct EDDChangelog class.
*
* @since 0.1
* @access private
*/
private function __construct()
{
// Define constants.
$this->define_constants();
// Initialize actions.
$this->init_actions();
}
/**
* Main EDDChangelog Instance.
*
* Ensures that only one instance of EDDChangelog exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 0.1
* @return object | \EDDChangelog
* @access public
*/
public static function instance()
{
if (!isset(self::$instance) && !(self::$instance instanceof EDDChangelog)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Define the necessary constants.
*
* @since 0.1
* @access private
* @return void
*/
private function define_constants()
{
// Set plugin version.
if (!defined('SIMPLE_EDD_CHANGELOG_VERSION')) {
define('SIMPLE_EDD_CHANGELOG_VERSION', '0.1');
}
}
/**
* Initialize actions.
*
* @since 0.1
* @access private
* @return void
*/
private function init_actions()
{
register_activation_hook(__FILE__, [$this, 'activate']);
// Add shortcode
add_shortcode('edd_changelog', [$this, 'changelog_shortcode']);
}
/**
* Activate plugin.
*
* @since 0.1
* @access public
* @return void
*/
public function activate()
{
$installed = get_option('simple_edd_changelog_installed');
if (!$installed) {
update_option('simple_edd_changelog_installed', time());
}
update_option('simple_edd_changelog_version', SIMPLE_EDD_CHANGELOG_VERSION);
}
/**
* The [edd_changelog] shortcode.
*
* @access public
* @since 1.0
* @return string
*/
public static function changelog_shortcode($atts)
{
if (!isset($atts['id'])) {
return;
}
$changelog = get_post_meta($atts['id'], '_edd_sl_changelog', TRUE);
// Sanitize the HTML from the change log field data.
$changelog = balanceTags(wp_kses_post($changelog), TRUE);
if (!empty($changelog)) {
$html = sprintf(
'<div class="edd-changelog"><h2>%1$s</h2>%2$s</div>',
$atts['title'] ?? 'Changelog',
$changelog
);
}
return $html;
}
}
// Load main class
EDDChangelog::instance();