PluginProbe
LearnPress – bbPress Integration / 4.0.7
LearnPress – bbPress Integration v4.0.7
trunk 0.9.3 1.0 1.1 2.0 2.1.2 3.0.0 3.0.1 3.0.2 3.0.3 4.0.4 4.0.5 4.0.6 4.0.7
learnpress-bbpress / learnpress-bbpress.php

learnpress-bbpress.php in LearnPress – bbPress Integration 4.0.7, at learnpress-bbpress.php

159 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: LearnPress - bbPress Integration
4 * Plugin URI: http://thimpress.com/learnpress
5 * Description: Using the forum for courses provided by bbPress.
6 * Author: ThimPress
7 * Version: 4.0.7
8 * Author URI: http://thimpress.com
9 * Tags: learnpress, lms, add-on, bbpress
10 * Text Domain: learnpress-bbpress
11 * Domain Path: /languages/
12 * Require_LP_Version: 4.2.8
13 * Require_BBpress_Version: 2.0.0
14 * Requires at least: 6.0
15 * Requires PHP: 7.4
16 *
17 * @package LearnPress-bbPress-Integration
18 */
19
20 defined( 'ABSPATH' ) || exit;
21
22 const LP_ADDON_BBPRESS_FILE = __FILE__;
23
24 /**
25 * Class LP_Addon_BbPress_Preload
26 */
27 class LP_Addon_BbPress_Preload {
28 /**
29 * @var array|string[]
30 */
31 public static $addon_info = array();
32 /**
33 * @var LP_Addon_bbPress $addon
34 */
35 public static $addon;
36
37 /**
38 * LP_Addon_BbPress_Preload constructor.
39 */
40 public function __construct() {
41 // Set Base name plugin.
42 define( 'LP_ADDON_BBPRESS_BASENAME', plugin_basename( LP_ADDON_BBPRESS_FILE ) );
43
44 if ( ! function_exists( 'get_plugin_data' ) ) {
45 require_once ABSPATH . 'wp-admin/includes/plugin.php';
46 }
47
48 // Set version addon for LP check .
49 self::$addon_info = get_file_data(
50 LP_ADDON_BBPRESS_FILE,
51 array(
52 'Name' => 'Plugin Name',
53 'Require_LP_Version' => 'Require_LP_Version',
54 'Version' => 'Version',
55 'Require_BBpress_Version' => 'Require_BBpress_Version',
56 )
57 );
58
59 define( 'LP_ADDON_BBPRESS_VER', self::$addon_info['Version'] );
60 define( 'LP_ADDON_BBPRESS_REQUIRE_VER', self::$addon_info['Require_LP_Version'] );
61
62 // Check LP activated .
63 if ( ! is_plugin_active( 'learnpress/learnpress.php' ) ) {
64 add_action( 'admin_notices', array( $this, 'show_note_errors_require_lp' ) );
65
66 deactivate_plugins( LP_ADDON_BBPRESS_BASENAME );
67
68 if ( isset( $_GET['activate'] ) ) {
69 unset( $_GET['activate'] );
70 }
71
72 return;
73 }
74
75 // Check BBpress activated.
76 $bbpress_valid = true;
77 if ( ! is_plugin_active( 'bbpress/bbpress.php' ) ) {
78 $bbpress_valid = false;
79 } else {
80 $default_headers = array(
81 'Version' => 'Version',
82 'TextDomain' => 'Text Domain',
83 );
84 $bbpress_info = get_file_data( WP_PLUGIN_DIR . '/bbpress/bbpress.php', $default_headers, 'plugin' );
85
86 if ( version_compare( self::$addon_info['Require_BBpress_Version'], $bbpress_info['Version'], '>' ) ) {
87 $bbpress_valid = false;
88 }
89 }
90
91 if ( ! $bbpress_valid ) {
92 add_action( 'admin_notices', array( $this, 'show_notices_bbpress' ) );
93
94 deactivate_plugins( LP_ADDON_BBPRESS_BASENAME );
95
96 if ( isset( $_GET['activate'] ) ) {
97 unset( $_GET['activate'] );
98 }
99
100 return;
101 }
102
103 // Sure LP loaded.
104 add_action( 'learn-press/ready', array( $this, 'load' ) );
105 }
106
107 /**
108 * Load addon
109 */
110 public function load() {
111 include_once 'inc/load.php';
112 self::$addon = LP_Addon_bbPress::instance();
113 }
114
115 public function show_note_errors_require_lp() {
116 ?>
117 <div class="notice notice-error">
118 <p><?php echo( 'Please active <strong>LearnPress version ' . LP_ADDON_BBPRESS_REQUIRE_VER . ' or later</strong> before active <strong>' . self::$addon_info['Name'] . '</strong>' ); ?></p>
119 </div>
120 <?php
121 }
122
123 /**
124 * Show admin notice when inactive bbPress.
125 */
126 public function show_notices_bbpress() {
127 ?>
128 <div class="notice notice-error">
129 <p>
130 <?php
131 echo wp_kses(
132 sprintf(
133 __(
134 '<strong>BBPress</strong> addon for <strong>LearnPress</strong> requires %1$s version %2$s is <strong>activated</strong>.',
135 'learnpress-bbpress'
136 ),
137 sprintf(
138 '<a href="%s" target="_blank">bbPress</a>',
139 admin_url( 'plugin-install.php?tab=search&type=term&s=bbpress' )
140 ),
141 self::$addon_info['Require_BBpress_Version']
142 ),
143 array(
144 'a' => array(
145 'href' => array(),
146 'target' => array(),
147 ),
148 'strong' => array(),
149 )
150 );
151 ?>
152 </p>
153 </div>
154 <?php
155 }
156 }
157
158 new LP_Addon_BbPress_Preload();
159