| 1 |
<?php |
| 2 |
|
| 3 |
use admin\Assets; |
| 4 |
|
| 5 |
/* |
| 6 |
Plugin Name: BBP Core |
| 7 |
Plugin URI: https://spider-themes.net/bbp-core |
| 8 |
Description: Expand bbPress powered forums with useful features like - private reply, solved topics ... |
| 9 |
Author: spider-themes |
| 10 |
Author URI: https://profiles.wordpress.org/spiderdevs/ |
| 11 |
Text Domain: bbp-core |
| 12 |
Version: 1.1.0 |
| 13 |
Requires at least: 5.0 |
| 14 |
Tested up to: 6.2 |
| 15 |
Requires PHP: 7.4 |
| 16 |
License: GPLv3 or later |
| 17 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html |
| 18 |
*/ |
| 19 |
|
| 20 |
defined( 'ABSPATH' ) || exit; |
| 21 |
|
| 22 |
|
| 23 |
if ( ! function_exists( 'bc_fs' ) ) { |
| 24 |
// Create a helper function for easy SDK access. |
| 25 |
function bc_fs() { |
| 26 |
global $bc_fs; |
| 27 |
|
| 28 |
if ( ! isset( $bc_fs ) ) { |
| 29 |
// Include Freemius SDK. |
| 30 |
require_once dirname( __FILE__ ) . '/includes/fs/start.php'; |
| 31 |
|
| 32 |
$bc_fs = fs_dynamic_init( array( |
| 33 |
'id' => '10864', |
| 34 |
'slug' => 'bbp-core', |
| 35 |
'type' => 'plugin', |
| 36 |
'public_key' => 'pk_41277ad11125f6e2a1b4e66f40164', |
| 37 |
'is_premium' => false, |
| 38 |
'is_premium_only' => false, |
| 39 |
'has_addons' => false, |
| 40 |
'has_paid_plans' => true, |
| 41 |
'trial' => array( |
| 42 |
'days' => 14, |
| 43 |
'is_require_payment' => true, |
| 44 |
), |
| 45 |
'menu' => array( |
| 46 |
'slug' => 'bbp-core', |
| 47 |
'contact' => false, |
| 48 |
'support' => false, |
| 49 |
'first-path' => 'admin.php?page=bbp-core', |
| 50 |
), |
| 51 |
) ); |
| 52 |
} |
| 53 |
|
| 54 |
return $bc_fs; |
| 55 |
} |
| 56 |
|
| 57 |
// Init Freemius. |
| 58 |
bc_fs()->add_filter( 'deactivate_on_activation', '__return_false' ); |
| 59 |
|
| 60 |
// Signal that SDK was initiated. |
| 61 |
do_action( 'bc_fs_loaded' ); |
| 62 |
} |
| 63 |
|
| 64 |
require_once __DIR__ . '/autoloader.php'; |
| 65 |
|
| 66 |
|
| 67 |
/** |
| 68 |
* Plugin's heart |
| 69 |
*/ |
| 70 |
final class BBP_Core { |
| 71 |
const VERSION = '1.1.0'; |
| 72 |
|
| 73 |
/** |
| 74 |
* Class constructor. |
| 75 |
*/ |
| 76 |
public function __construct() { |
| 77 |
$this->define_constants(); |
| 78 |
$this->core_includes(); |
| 79 |
|
| 80 |
register_activation_hook( __FILE__, [ $this, 'activate' ] ); |
| 81 |
add_action( 'wp_enqueue_scripts', [ $this, 'load_assets' ] ); |
| 82 |
add_action( 'admin_enqueue_scripts', [ $this, 'load_admin_scripts' ], 12 ); |
| 83 |
|
| 84 |
add_action( 'plugins_loaded', [ $this, 'init_plugin' ] ); |
| 85 |
|
| 86 |
$this->bbpc_hooks(); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Define Plugin Constants. |
| 91 |
* |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
public function define_constants() { |
| 95 |
define( 'BBPC_VERSION', self::VERSION ); |
| 96 |
define( 'BBPC_FILE', __FILE__ ); |
| 97 |
define( 'BBPC_DIR', __DIR__ . '/' ); |
| 98 |
define( 'BBPC_URL', plugins_url( '/', __FILE__ ) ); |
| 99 |
define( 'BBPC_ASSETS', BBPC_URL . 'assets/' ); |
| 100 |
define( 'BBPC_IMG', BBPC_ASSETS . 'img/' ); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* File includes. |
| 105 |
*/ |
| 106 |
public function core_includes() { |
| 107 |
require_once __DIR__ . '/includes/admin/menu/Approve_Topic.php'; |
| 108 |
require_once __DIR__ . '/includes/admin/menu/Create_Forum.php'; |
| 109 |
require_once __DIR__ . '/includes/admin/menu/Create_Topic.php'; |
| 110 |
require_once __DIR__ . '/includes/admin/menu/Delete_Forum.php'; |
| 111 |
require_once __DIR__ . '/includes/admin/menu/Delete_Topic.php'; |
| 112 |
require_once __DIR__ . '/includes/Elementor/BBP_Widgets.php'; |
| 113 |
require_once __DIR__ . '/includes/extra.php'; |
| 114 |
require_once __DIR__ . '/includes/ajax_actions.php'; |
| 115 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 116 |
require_once __DIR__ . '/includes/Frontend/Assets.php'; |
| 117 |
|
| 118 |
require_once __DIR__ . '/includes/admin/widgets/forum-info/widgets.php'; |
| 119 |
require_once __DIR__ . '/includes/Elementor/inc/forum-ajax.php'; |
| 120 |
|
| 121 |
// Core installer notice |
| 122 |
require_once __DIR__ . '/includes/admin/notices/notices.php'; |
| 123 |
require_once __DIR__ . '/includes/admin/notices/asking-for-review.php'; |
| 124 |
|
| 125 |
//Register Pro Widgets |
| 126 |
$theme = wp_get_theme(); |
| 127 |
|
| 128 |
if ( $theme != 'Ama' || ! bbpc_is_premium() ) { |
| 129 |
require_once __DIR__ . '/includes/admin/Pro_Widget_Map.php'; |
| 130 |
require_once __DIR__ . '/includes/admin/Pro_Widget_Service.php'; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Initializing Bbp_core class. |
| 136 |
* |
| 137 |
* @return \Bbp_core |
| 138 |
*/ |
| 139 |
static function init() { |
| 140 |
static $instance = false; |
| 141 |
|
| 142 |
if ( ! $instance ) { |
| 143 |
$instance = new self(); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Actions on plugin activation. |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
public function activate() { |
| 153 |
$installed = get_option( 'bbpc_installed' ); |
| 154 |
if ( ! $installed ) { |
| 155 |
update_option( 'bbpc_installed', time() ); |
| 156 |
} |
| 157 |
|
| 158 |
update_option( 'bbpc_version', BBPC_VERSION ); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Initialize the plugin functionality. |
| 163 |
* |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
public function init_plugin() { |
| 167 |
|
| 168 |
$this->load_features(); |
| 169 |
|
| 170 |
if ( is_admin() ) { |
| 171 |
new Admin(); |
| 172 |
new Assets(); |
| 173 |
} |
| 174 |
// If bbPress is not active, don't load assets and widgets. |
| 175 |
if ( ! class_exists( 'bbPress' ) ) { |
| 176 |
return; |
| 177 |
} |
| 178 |
if ( ! is_admin() ) { |
| 179 |
new Frontend\Assets(); |
| 180 |
} |
| 181 |
new admin\Elementor\BBP_Widgets(); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
/** |
| 186 |
* Load different features. |
| 187 |
* |
| 188 |
* @return void |
| 189 |
*/ |
| 190 |
public function load_features() { |
| 191 |
$opt = get_option( 'bbp_core_settings' ); |
| 192 |
define( 'BBPC_FEAT_PATH', plugin_dir_path( __FILE__ ) . 'includes/features/' ); |
| 193 |
|
| 194 |
if ( class_exists( 'bbPress' ) ) { |
| 195 |
if ( $opt['is_solved_topics'] ?? true ) { |
| 196 |
require BBPC_FEAT_PATH . 'bbp_solved_topic.php'; |
| 197 |
} |
| 198 |
|
| 199 |
if ( $opt['is_private_replies'] ?? true ) { |
| 200 |
require BBPC_FEAT_PATH . 'bbp-private-replies.php'; |
| 201 |
} |
| 202 |
|
| 203 |
if ( $opt['is_votes'] ?? true ) { |
| 204 |
new features\bbp_voting(); |
| 205 |
} |
| 206 |
|
| 207 |
if ( $opt['is_attachment'] ?? true ) { |
| 208 |
new features\bbp_attachments(); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Load Necessary assets for the plugin. |
| 215 |
* |
| 216 |
* @return void |
| 217 |
*/ |
| 218 |
public function load_assets() { |
| 219 |
wp_enqueue_style( 'bbpc', BBPC_ASSETS . 'css/bbpc.css' ); |
| 220 |
wp_enqueue_style( 'bbpc-voting', BBPC_ASSETS . 'css/bbpc-voting.css' ); |
| 221 |
|
| 222 |
// BBP Voting. |
| 223 |
if ( ! is_singular( 'topic' ) ) { |
| 224 |
return; |
| 225 |
} |
| 226 |
wp_enqueue_script( 'bbpc-voting', BBPC_ASSETS . 'js/bbpc-voting.js', [ 'jquery' ], BBPC_VERSION ); |
| 227 |
wp_localize_script( 'bbpc-voting', 'bbp_voting_ajax_object', [ 'ajax_url' => admin_url( 'admin-ajax.php' ) ] ); |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Load Admin Side styles and scripts. |
| 232 |
* |
| 233 |
* @return void |
| 234 |
*/ |
| 235 |
public function load_admin_scripts() { |
| 236 |
wp_enqueue_style( 'bbpc-admin', BBPC_ASSETS . 'css/bbpc-admin.css' ); |
| 237 |
wp_enqueue_style( 'bbpc-admin-global', BBPC_ASSETS . 'css/admin-global.css' ); |
| 238 |
|
| 239 |
$current_url = ! empty( $_GET['page'] ) ? admin_url( 'admin.php?page=' ) . sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; |
| 240 |
$bbp_core_url = admin_url( 'admin.php?page=bbp-core' ); |
| 241 |
$bbpc_settings_url = admin_url( 'admin.php?page=bbp-core-settings' ); |
| 242 |
|
| 243 |
if ( $bbp_core_url == $current_url ) { |
| 244 |
wp_enqueue_style( 'normalize', BBPC_ASSETS . 'css/normalize.css' ); |
| 245 |
wp_enqueue_style( 'nice-select', BBPC_ASSETS . 'css/nice-select.css' ); |
| 246 |
wp_enqueue_style( 'jquery-ui', BBPC_ASSETS . 'css/admin-ui-style.css' ); |
| 247 |
|
| 248 |
// Scripts. |
| 249 |
wp_enqueue_script( 'modernizr', BBPC_ASSETS . 'js/modernizr-3.11.2.min.js', [ 'jquery' ], '3.11.2', true ); |
| 250 |
wp_enqueue_script( 'jquery-ui', BBPC_ASSETS . 'js/jquery-ui.js', [ 'jquery' ], '1.12.1', true ); |
| 251 |
wp_enqueue_script( 'mixitup', BBPC_ASSETS . 'js/mixitup.min.js', [ 'jquery' ], '3.3.1', true ); |
| 252 |
wp_enqueue_script( 'mixitup-multifilter', BBPC_ASSETS . 'js/mixitup-multifilter.js', [ 'jquery' ], '3.3.1', true ); |
| 253 |
wp_enqueue_script( 'jquery-nice-select', BBPC_ASSETS . 'js/jquery.nice-select.min.js', [ 'jquery' ], '1.0', true ); |
| 254 |
wp_enqueue_script( 'tabby-polyfills', BBPC_ASSETS . 'js/tabby.polyfills.min.js', [ 'jquery' ], '1.0', true ); |
| 255 |
wp_enqueue_script( 'sortable', BBPC_ASSETS . 'js/Sortable.min.js', [ 'jquery' ], '1.0', true ); |
| 256 |
wp_enqueue_script( 'accordion', BBPC_ASSETS . 'js/accordion.min.js', [ 'jquery' ], '1.0', true ); |
| 257 |
wp_enqueue_script( 'bbpc-admin-main', BBPC_ASSETS . 'js/admin-main.js', [ 'jquery' ], '1.0', true ); |
| 258 |
wp_enqueue_script( 'sweetalert', BBPC_ASSETS . 'js/sweetalert.min.js', [ 'jquery' ], '1.0', true ); |
| 259 |
|
| 260 |
wp_localize_script( |
| 261 |
'jquery', |
| 262 |
'bbp_core_local_object', |
| 263 |
[ |
| 264 |
'create_forum_title' => esc_html__( 'Enter Forum Title', 'bbp-core' ), |
| 265 |
'create_topic_title' => esc_html__( 'Enter Topic Title', 'bbp-core' ), |
| 266 |
'forum_delete_title' => esc_html__( 'Are you sure to delete?', 'bbp-core' ), |
| 267 |
'forum_delete_desc' => esc_html__( "This forum will be deleted with all the topics and you won't be able to revert!", 'bbp-core' ), |
| 268 |
'topic_delete_desc' => esc_html__( "This topic will be deleted and you won't be able to revert!", 'bbp-core' ), |
| 269 |
'BBPC_ASSETS' => BBPC_ASSETS, |
| 270 |
] |
| 271 |
); |
| 272 |
} |
| 273 |
|
| 274 |
if ( $bbpc_settings_url == $current_url ) { |
| 275 |
wp_enqueue_style( 'sweetalert', BBPC_ASSETS . '/css/admin/sweetalert.css' ); |
| 276 |
wp_enqueue_script( 'sweetalert', BBPC_ASSETS . '/js/admin/sweetalert.min.js', [ 'jquery' ], true, true ); |
| 277 |
wp_enqueue_script( 'bbpc-admin-global', BBPC_ASSETS . 'js/admin-global.js', BBPC_VERSION ); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Actions and filter hooks in BBP Core plugin. |
| 283 |
* |
| 284 |
* @return void |
| 285 |
*/ |
| 286 |
public function bbpc_hooks() { |
| 287 |
require BBPC_DIR . 'includes/hooks/actions.php'; |
| 288 |
require BBPC_DIR . 'includes/hooks/image_sizes.php'; |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
/** |
| 293 |
* Initialize the bbp core plugin. |
| 294 |
* |
| 295 |
* @return \Bbp_core |
| 296 |
*/ |
| 297 |
function bbp_core() { |
| 298 |
return Bbp_core::init(); |
| 299 |
} |
| 300 |
|
| 301 |
bbp_core(); |