| 1 |
<?php |
| 2 |
/** |
| 3 |
* UpStream_Options_Extensions |
| 4 |
* |
| 5 |
* @package UpStream |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! class_exists( 'UpStream_Options_Extensions' ) ) { |
| 14 |
|
| 15 |
/** |
| 16 |
* CMB2 Theme Options |
| 17 |
* |
| 18 |
* @version 0.1.0 |
| 19 |
*/ |
| 20 |
class UpStream_Options_Extensions { |
| 21 |
|
| 22 |
|
| 23 |
/** |
| 24 |
* Array of metaboxes/fields |
| 25 |
* |
| 26 |
* @var array |
| 27 |
*/ |
| 28 |
public $id = 'upstream_extensions'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Page title |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
protected $title = ''; |
| 36 |
|
| 37 |
/** |
| 38 |
* Menu Title |
| 39 |
* |
| 40 |
* @var string |
| 41 |
*/ |
| 42 |
protected $menu_title = ''; |
| 43 |
|
| 44 |
/** |
| 45 |
* Menu Title |
| 46 |
* |
| 47 |
* @var string |
| 48 |
*/ |
| 49 |
protected $description = ''; |
| 50 |
|
| 51 |
/** |
| 52 |
* Holds an instance of the object |
| 53 |
* |
| 54 |
* @var Myprefix_Admin |
| 55 |
**/ |
| 56 |
public static $instance = null; |
| 57 |
|
| 58 |
/** |
| 59 |
* Constructor |
| 60 |
* |
| 61 |
* @param Container $container Container. |
| 62 |
* |
| 63 |
* @since 0.1.0 |
| 64 |
*/ |
| 65 |
public function __construct( $container ) { |
| 66 |
|
| 67 |
/** |
| 68 |
* Add-ons page |
| 69 |
*/ |
| 70 |
do_action( 'allex_enable_module_addons' ); |
| 71 |
add_filter( 'allex_addons', array( 'UpStream_Options_Extensions', 'filter_allex_addons' ), 10, 2 ); |
| 72 |
|
| 73 |
/** |
| 74 |
* Upgrade link |
| 75 |
*/ |
| 76 |
do_action( 'allex_enable_module_upgrade', 'https://upstreamplugin.com/pricing/' ); |
| 77 |
|
| 78 |
// Set our title. |
| 79 |
$this->title = __( 'Extensions', 'upstream' ); |
| 80 |
$this->menu_title = $this->title; |
| 81 |
$this->description = __( |
| 82 |
'These extensions add extra functionality to the UpStream Project Management plugin.', |
| 83 |
'upstream' |
| 84 |
); |
| 85 |
|
| 86 |
add_action( |
| 87 |
'cmb2_render_upstream_extensions_wrapper', |
| 88 |
array( 'UpStream_Options_Extensions', 'render_extensions_wrapper' ), |
| 89 |
10, |
| 90 |
5 |
| 91 |
); |
| 92 |
|
| 93 |
add_filter( 'allex_upgrade_link', array( $this, 'filter_allex_upgrade_link' ), 10, 2 ); |
| 94 |
add_action( 'allex_addon_update_license', array( $this, 'action_allex_addon_update_license' ), 10, 4 ); |
| 95 |
add_filter( 'allex_addons_get_license_key', array( $this, 'filter_allex_addons_get_license_key' ), 10, 2 ); |
| 96 |
add_filter( 'allex_addons_get_license_status', array( $this, 'filter_allex_addons_get_license_status' ), 10, 2 ); |
| 97 |
|
| 98 |
do_action( 'allex_set_license_key_links', 'upstream', '/wp-admin/admin.php?page=upstream_extensions' ); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Returns true if there is one or more installed extension. |
| 103 |
* |
| 104 |
* @return bool |
| 105 |
*/ |
| 106 |
public static function there_are_installed_extensions() { |
| 107 |
$pool = apply_filters( 'allex_addons', array(), 'upstream' ); |
| 108 |
|
| 109 |
foreach ( $pool as $addon ) { |
| 110 |
if ( file_exists( ABSPATH . 'wp-content/plugins/' . $addon['slug'] . '/' . $addon['slug'] . '.php' ) ) { |
| 111 |
return true; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
return false; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
/** |
| 120 |
* Filter Allex Addons |
| 121 |
* |
| 122 |
* @param mixed $addons Addons. |
| 123 |
* @param mixed $plugin_name Plugin Name. |
| 124 |
* |
| 125 |
* @return array |
| 126 |
*/ |
| 127 |
public static function filter_allex_addons( $addons, $plugin_name ) { |
| 128 |
if ( 'upstream' === $plugin_name ) { |
| 129 |
$addons = self::get_addons_list(); |
| 130 |
} |
| 131 |
|
| 132 |
return $addons; |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Get Addons List |
| 137 |
* |
| 138 |
* @return array |
| 139 |
*/ |
| 140 |
protected static function get_addons_list() { |
| 141 |
$addons = array( |
| 142 |
'upstream-customizer' => array( |
| 143 |
'slug' => 'upstream-customizer', |
| 144 |
'title' => __( 'Customizer', 'upstream' ), |
| 145 |
'description' => __( |
| 146 |
'Adds controls to easily customize the appearance of your projects.', |
| 147 |
'upstream' |
| 148 |
), |
| 149 |
'icon_class' => 'fa fa-paint-brush', |
| 150 |
'edd_id' => 4051, |
| 151 |
), |
| 152 |
'upstream-email-notifications' => array( |
| 153 |
'slug' => 'upstream-email-notifications', |
| 154 |
'title' => __( 'Email Notifications', 'upstream' ), |
| 155 |
'description' => __( |
| 156 |
'Allows you to email project updates to people working on your projects.', |
| 157 |
'upstream' |
| 158 |
), |
| 159 |
'icon_class' => 'fa fa-envelope', |
| 160 |
'edd_id' => 4996, |
| 161 |
), |
| 162 |
'upstream-frontend-edit' => array( |
| 163 |
'slug' => 'upstream-frontend-edit', |
| 164 |
'title' => __( 'Frontend Edit', 'upstream' ), |
| 165 |
'description' => __( |
| 166 |
'Allow users to add and edit items on the frontend.', |
| 167 |
'upstream' |
| 168 |
), |
| 169 |
'icon_class' => 'fa fa-edit', |
| 170 |
'edd_id' => 3925, |
| 171 |
), |
| 172 |
'upstream-project-timeline' => array( |
| 173 |
'slug' => 'upstream-project-timeline', |
| 174 |
'title' => __( 'Project Timeline', 'upstream' ), |
| 175 |
'description' => __( |
| 176 |
'Add a Gantt style chart to visualize your projects.', |
| 177 |
'upstream' |
| 178 |
), |
| 179 |
'icon_class' => 'fa fa-align-left', |
| 180 |
'edd_id' => 3920, |
| 181 |
), |
| 182 |
'upstream-copy-project' => array( |
| 183 |
'slug' => 'upstream-copy-project', |
| 184 |
'title' => __( 'Copy Project', 'upstream' ), |
| 185 |
'description' => __( |
| 186 |
'Allows you to duplicate an UpStream project including all the content and options.', |
| 187 |
'upstream' |
| 188 |
), |
| 189 |
'icon_class' => 'fa fa-copy', |
| 190 |
'edd_id' => 5471, |
| 191 |
), |
| 192 |
'upstream-calendar-view' => array( |
| 193 |
'slug' => 'upstream-calendar-view', |
| 194 |
'title' => __( 'Calendar View', 'upstream' ), |
| 195 |
'description' => __( |
| 196 |
'This calendar display will allow you to easily see everything that’s happening in a project.', |
| 197 |
'upstream' |
| 198 |
), |
| 199 |
'icon_class' => 'fa fa-calendar', |
| 200 |
'edd_id' => 6798, |
| 201 |
), |
| 202 |
'upstream-custom-fields' => array( |
| 203 |
'slug' => 'upstream-custom-fields', |
| 204 |
'title' => __( 'Custom Fields', 'upstream' ), |
| 205 |
'description' => __( |
| 206 |
'This extension allows you to add more information to Project, Milestone, Tasks and Bugs.', |
| 207 |
'upstream' |
| 208 |
), |
| 209 |
'icon_class' => 'fa fa-reorder', |
| 210 |
'edd_id' => 8409, |
| 211 |
), |
| 212 |
|
| 213 |
'upstream-advanced-permissions' => array( |
| 214 |
'slug' => 'upstream-advanced-permissions', |
| 215 |
'title' => __( 'Advanced Permissions', 'upstream' ), |
| 216 |
'description' => __( |
| 217 |
'This extension allows you to set permissions by user or role for objects and individual fields.', |
| 218 |
'upstream' |
| 219 |
), |
| 220 |
'icon_class' => 'fa fa-lock', |
| 221 |
'edd_id' => 24749, |
| 222 |
), |
| 223 |
'upstream-time-tracking' => array( |
| 224 |
'slug' => 'upstream-time-tracking', |
| 225 |
'title' => __( 'Time Tracking', 'upstream' ), |
| 226 |
'description' => __( |
| 227 |
'This extension allows you track time spent on projects.', |
| 228 |
'upstream' |
| 229 |
), |
| 230 |
'icon_class' => 'fa fa-clock-o', |
| 231 |
'edd_id' => 27994, |
| 232 |
), |
| 233 |
'upstream-reporting' => array( |
| 234 |
'slug' => 'upstream-reporting', |
| 235 |
'title' => __( 'Reporting', 'upstream' ), |
| 236 |
'description' => __( |
| 237 |
'This extension provides reports and a report dashboard.', |
| 238 |
'upstream' |
| 239 |
), |
| 240 |
'icon_class' => 'fa fa-file-excel-o', |
| 241 |
'edd_id' => 16229, |
| 242 |
), |
| 243 |
'upstream-name-replacement' => array( |
| 244 |
'slug' => 'upstream-name-replacement', |
| 245 |
'title' => __( 'Naming', 'upstream' ), |
| 246 |
'description' => __( |
| 247 |
'This extension allows you to customize UpStream by replacing any names/text.', |
| 248 |
'upstream' |
| 249 |
), |
| 250 |
'icon_class' => 'fa fa-gear', |
| 251 |
'edd_id' => 27992, |
| 252 |
), |
| 253 |
'upstream-forms' => array( |
| 254 |
'slug' => 'upstream-forms', |
| 255 |
'title' => __( 'Forms', 'upstream' ), |
| 256 |
'description' => __( |
| 257 |
'This extension allows you to create/edit projects using popular forms tools.', |
| 258 |
'upstream' |
| 259 |
), |
| 260 |
'icon_class' => 'fa fa-book', |
| 261 |
'edd_id' => 26850, |
| 262 |
), |
| 263 |
'upstream-api' => array( |
| 264 |
'slug' => 'upstream-api', |
| 265 |
'title' => __( 'API', 'upstream' ), |
| 266 |
'description' => __( |
| 267 |
'This extension provides API functionality for UpStream.', |
| 268 |
'upstream' |
| 269 |
), |
| 270 |
'icon_class' => 'fa fa-desktop', |
| 271 |
'edd_id' => 30921, |
| 272 |
), |
| 273 |
); |
| 274 |
|
| 275 |
return $addons; |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Action Allex Addon Update License |
| 280 |
* |
| 281 |
* @param mixed $plugin_name Plugin Name. |
| 282 |
* @param mixed $addon_slug Addon Slug. |
| 283 |
* @param mixed $license_key License Key. |
| 284 |
* @param mixed $license_status License Status. |
| 285 |
*/ |
| 286 |
public function action_allex_addon_update_license( $plugin_name, $addon_slug, $license_key, $license_status ) { |
| 287 |
/** |
| 288 |
* Duplicate the license key for backward compatibility with add-ons. |
| 289 |
*/ |
| 290 |
$extensions = get_option( 'upstream:extensions' ); |
| 291 |
|
| 292 |
if ( ! is_array( $extensions ) ) { |
| 293 |
$extensions = array(); |
| 294 |
} |
| 295 |
|
| 296 |
$extensions[ $addon_slug ] = array( |
| 297 |
'key' => $license_key, |
| 298 |
'status' => $license_status, |
| 299 |
); |
| 300 |
|
| 301 |
update_option( 'upstream:extensions', $extensions ); |
| 302 |
} |
| 303 |
|
| 304 |
/** |
| 305 |
* Filter Allex Addons Get License Key |
| 306 |
* |
| 307 |
* @param mixed $license_key License Key. |
| 308 |
* @param mixed $addon_slug Addon Slug. |
| 309 |
* |
| 310 |
* @return string |
| 311 |
*/ |
| 312 |
public function filter_allex_addons_get_license_key( $license_key, $addon_slug ) { |
| 313 |
$extensions = get_option( 'upstream:extensions' ); |
| 314 |
|
| 315 |
if ( isset( $extensions[ $addon_slug ] ) && $extensions[ $addon_slug ]['key'] ) { |
| 316 |
return $extensions[ $addon_slug ]['key']; |
| 317 |
} |
| 318 |
|
| 319 |
return $license_key; |
| 320 |
} |
| 321 |
|
| 322 |
/** |
| 323 |
* Filter Allex Addons Get License Status |
| 324 |
* |
| 325 |
* @param mixed $license_status License Status. |
| 326 |
* @param mixed $addon_slug Addon Slug. |
| 327 |
* |
| 328 |
* @return string |
| 329 |
*/ |
| 330 |
public function filter_allex_addons_get_license_status( $license_status, $addon_slug ) { |
| 331 |
$extensions = get_option( 'upstream:extensions' ); |
| 332 |
|
| 333 |
if ( isset( $extensions[ $addon_slug ] ) && $extensions[ $addon_slug ]['status'] ) { |
| 334 |
return $extensions[ $addon_slug ]['status']; |
| 335 |
} |
| 336 |
|
| 337 |
return $license_status; |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* Renders all Extensions Page's HTML. |
| 342 |
* |
| 343 |
* @param \CMB2_Field $field The current CMB2_Field object. |
| 344 |
* @param string $value The field value passed through the escaping filter. |
| 345 |
* @param mixed $object_id The object id. |
| 346 |
* @param string $object_type The type of object being handled. |
| 347 |
* @param \CMB2_Types $field_type Instance of the correspondent CMB2_Types object. |
| 348 |
* |
| 349 |
* @since 1.11.0 |
| 350 |
* @static |
| 351 |
*/ |
| 352 |
public static function render_extensions_wrapper( $field, $value, $object_id, $object_type, $field_type ) { |
| 353 |
do_action( 'allex_echo_addons_page', 'https://upstreamplugin.com/pricing/', 'upstream' ); |
| 354 |
} |
| 355 |
|
| 356 |
/** |
| 357 |
* Filter Allex Upgrade Link |
| 358 |
* |
| 359 |
* @param string $ad_link Ad Link. |
| 360 |
* @param string $plugin_name Plugin Name. |
| 361 |
* |
| 362 |
* @return array |
| 363 |
*/ |
| 364 |
public function filter_allex_upgrade_link( $ad_link, $plugin_name ) { |
| 365 |
if ( 'upstream' === $plugin_name ) { |
| 366 |
$ad_link = 'https://upstreamplugin.com/welcome-coupon/'; |
| 367 |
} |
| 368 |
|
| 369 |
return $ad_link; |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Add the options metabox to the array of metaboxes. |
| 374 |
* |
| 375 |
* @return array |
| 376 |
* @since 0.1.0 |
| 377 |
*/ |
| 378 |
public function get_options() { |
| 379 |
$options = array( |
| 380 |
'id' => $this->id, |
| 381 |
'title' => $this->title, |
| 382 |
'menu_title' => $this->menu_title, |
| 383 |
'desc' => $this->description, |
| 384 |
'show_on' => array( |
| 385 |
'key' => 'options-page', |
| 386 |
'value' => array( $this->id ), |
| 387 |
), |
| 388 |
'fields' => array( |
| 389 |
array( |
| 390 |
'id' => 'upstream_extensions_wrapper', |
| 391 |
'type' => 'upstream_extensions_wrapper', |
| 392 |
), |
| 393 |
), |
| 394 |
); |
| 395 |
|
| 396 |
return $options; |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* Returns the running object |
| 401 |
* |
| 402 |
* @return Myprefix_Admin |
| 403 |
**/ |
| 404 |
public static function get_instance() { |
| 405 |
if ( is_null( self::$instance ) ) { |
| 406 |
self::$instance = new self(); |
| 407 |
} |
| 408 |
|
| 409 |
return self::$instance; |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
|