PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.2
Defender Security – Malware Scanner, Login Security & Firewall v5.6.2
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / extra / wpmudev-black-friday / campaign.php

campaign.php in Defender Security – Malware Scanner, Login Security & Firewall 5.6.2, at extra/wpmudev-black-friday/campaign.php

183 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPMUDEV Black Friday common module
4 *
5 * Used by wordpress.org free plugins only to show Black Friday deal on admin dashboard.
6 *
7 * @since 1.0
8 * @author WPMUDEV
9 * @package WPMUDEV\BlackFriday
10 */
11
12 namespace WPMUDEV\Modules\BlackFriday;
13
14 // If this file is called directly, abort.
15 if ( ! defined( 'WPINC' ) ) {
16 die;
17 }
18
19 // Sub-module version.
20 if ( ! defined( 'WPMUDEV_MODULE_BLACK_FRIDAY_VERSION' ) ) {
21 define( 'WPMUDEV_MODULE_BLACK_FRIDAY_VERSION', '2.0.0' );
22 }
23
24 // Sub-module directory.
25 if ( ! defined( 'WPMUDEV_MODULE_BLACK_FRIDAY_DIR' ) ) {
26 define( 'WPMUDEV_MODULE_BLACK_FRIDAY_DIR', plugin_dir_path( __FILE__ ) );
27 }
28
29 // Sub-module url.
30 if ( ! defined( 'WPMUDEV_MODULE_BLACK_FRIDAY_URL' ) ) {
31 define( 'WPMUDEV_MODULE_BLACK_FRIDAY_URL', plugin_dir_url( __FILE__ ) );
32 }
33
34 // Sub-module Assets url.
35 if ( ! defined( 'WPMUDEV_MODULE_BLACK_FRIDAY_ASSETS_URL' ) ) {
36 define( 'WPMUDEV_MODULE_BLACK_FRIDAY_ASSETS_URL', untrailingslashit( WPMUDEV_MODULE_BLACK_FRIDAY_URL ) . '/build' );
37 }
38
39 if ( ! class_exists( __NAMESPACE__ . '\\Campaign' ) ) {
40 /**
41 * Class Load.
42 *
43 * @since 1.0
44 * @package WPMUDEV\BlackFriday\Campaign
45 */
46 class Campaign {
47 /**
48 * Start date of the campaign. Date format : dd-mm-yyyy.
49 *
50 * @var string
51 */
52 protected $campaign_start_date = '21-11-2025';
53
54 /**
55 * End date of the campaign. Date format : dd-mm-yyyy.
56 *
57 * @var string
58 */
59 protected $campaign_end_date = '03-12-2025';
60
61 /**
62 * Construct handler class.
63 *
64 * @since 1.0
65 *
66 * @param array $props Campaign props.
67 *
68 * @return void
69 */
70 public function __construct( array $props = array() ) {
71 $props['campaign_url'] = $props['campaign_url'] ?? 'https://wpmudev.com/black-friday/';
72 $props['utm_campaign'] = $props['utm_campaign'] ?? 'black-friday-2025';
73 $props['utm_medium'] = $props['utm_medium'] ?? 'plugin';
74 $props['priority'] = $props['priority'] ?? 10;
75
76 add_action( 'init', array( $this, 'add_textdomain' ) );
77
78 $this->load_modules( $props );
79 }
80
81 /**
82 * Load required modules.
83 *
84 * @since 2.0.0
85 *
86 * @param array $props Campaign props.
87 *
88 * @return void
89 */
90 public function load_modules( array $props = array() ) {
91 static $loaded = false;
92 if ( $loaded || ! $this->can_load() ) {
93 return;
94 }
95 $loaded = true;
96
97 // Load Utils so other classes can use it.
98 require_once plugin_dir_path( __FILE__ ) . 'includes/class-utils.php';
99
100 require_once 'includes/class-banner.php';
101
102 if ( class_exists( 'WPMUDEV\Modules\BlackFriday\Banner' ) ) {
103 new Banner( $props );
104 }
105
106 require_once 'includes/class-admin-menu.php';
107
108 if ( class_exists( 'WPMUDEV\Modules\BlackFriday\Admin_Menu' ) ) {
109 new Admin_Menu( $props );
110 }
111
112 require_once 'includes/class-action-links.php';
113 if ( class_exists( 'WPMUDEV\Modules\BlackFriday\Action_Links' ) ) {
114 new Action_Links( $props );
115 }
116 }
117
118 /**
119 * Checks if plugin's Black Friday deal can be loaded.
120 *
121 * @since 1.0
122 *
123 * @return boolean
124 */
125 public function can_load() {
126 if (
127 ! current_user_can( 'manage_options' ) ||
128 $this->event_expired() ||
129 $this->dashboard_plugin_installed()
130 ) {
131 return false;
132 }
133
134 return true;
135 }
136
137 /**
138 * Checks if offer has expired.
139 *
140 * @since 1.0
141 *
142 * @return boolean
143 */
144 public function event_expired() {
145 $current_date = apply_filters( 'wpmudev_blackfriday_current_date', 'd-m-Y' );
146 $start_date = apply_filters( 'wpmudev_blackfriday_start_date', $this->campaign_start_date );
147 $expire_date = apply_filters( 'wpmudev_blackfriday_expire_date', $this->campaign_end_date );
148
149 // Expires on 29 Nov 2025.
150 return (
151 date_create( date_i18n( $current_date ) )->getTimestamp() < date_create( date_i18n( $start_date ) )->getTimestamp() ||
152 date_create( date_i18n( $current_date ) )->getTimestamp() >= date_create( date_i18n( $expire_date ) )->getTimestamp()
153 );
154 }
155
156 /**
157 * Checks if Dashboard plugin is installed.
158 *
159 * @since 1.0
160 *
161 * @return boolean
162 */
163 public function dashboard_plugin_installed() {
164 return class_exists( 'WPMUDEV_Dashboard' );
165 }
166
167 /**
168 * Load sub-module textdomain.
169 *
170 * @since 2.0.0
171 *
172 * @return void
173 */
174 public function add_textdomain() {
175 load_plugin_textdomain(
176 'wpmudev-black-friday',
177 false,
178 dirname( plugin_basename( __FILE__ ) ) . '/languages/'
179 );
180 }
181 }
182 }
183