| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: weDocs |
| 4 |
Plugin URI: https://wedocs.co/ |
| 5 |
Description: A documentation plugin for WordPress |
| 6 |
Version: 2.2.5 |
| 7 |
Author: weDevs |
| 8 |
Author URI: https://wedocs.co/?utm_source=wporg&utm_medium=banner&utm_campaign=author-uri |
| 9 |
License: GPL2 |
| 10 |
Text Domain: wedocs |
| 11 |
Domain Path: /languages |
| 12 |
*/ |
| 13 |
|
| 14 |
/* |
| 15 |
* Copyright (c) 2021 Tareq Hasan (email: tareq@wedevs.com). All rights reserved. |
| 16 |
* |
| 17 |
* Released under the GPL license |
| 18 |
* http://www.opensource.org/licenses/gpl-license.php |
| 19 |
* |
| 20 |
* This is an add-on for WordPress |
| 21 |
* http://wordpress.org/ |
| 22 |
* |
| 23 |
* ********************************************************************** |
| 24 |
* This program is free software; you can redistribute it and/or modify |
| 25 |
* it under the terms of the GNU General Public License as published by |
| 26 |
* the Free Software Foundation; either version 2 of the License, or |
| 27 |
* (at your option) any later version. |
| 28 |
* |
| 29 |
* This program is distributed in the hope that it will be useful, |
| 30 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 |
* GNU General Public License for more details. |
| 33 |
* |
| 34 |
* You should have received a copy of the GNU General Public License |
| 35 |
* along with this program; if not, write to the Free Software |
| 36 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 37 |
* ********************************************************************** |
| 38 |
*/ |
| 39 |
|
| 40 |
// don't call the file directly |
| 41 |
use Appsero\Client; |
| 42 |
use WeDevs\WeDocs\Capability; |
| 43 |
|
| 44 |
if ( ! defined( 'ABSPATH' ) ) { |
| 45 |
exit; |
| 46 |
} |
| 47 |
|
| 48 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 49 |
require_once plugin_dir_path(__FILE__) . 'assets/build/blocks/helpers/block-styles.php'; |
| 50 |
// require_once __DIR__ . '/includes/captcha-config.php'; // todo add later |
| 51 |
|
| 52 |
/** |
| 53 |
* WeDocs class. |
| 54 |
* |
| 55 |
* @class WeDocs The class that holds the entire WeDocs plugin |
| 56 |
*/ |
| 57 |
final class WeDocs { |
| 58 |
/** |
| 59 |
* Plugin version. |
| 60 |
* |
| 61 |
* @var string |
| 62 |
*/ |
| 63 |
const VERSION = '2.2.5'; |
| 64 |
|
| 65 |
/** |
| 66 |
* The plugin url. |
| 67 |
* |
| 68 |
* @var string |
| 69 |
*/ |
| 70 |
public $plugin_url; |
| 71 |
|
| 72 |
/** |
| 73 |
* The plugin path. |
| 74 |
* |
| 75 |
* @var string |
| 76 |
*/ |
| 77 |
public $plugin_path; |
| 78 |
|
| 79 |
/** |
| 80 |
* The theme directory path. |
| 81 |
* |
| 82 |
* @var string |
| 83 |
*/ |
| 84 |
public $theme_dir_path; |
| 85 |
|
| 86 |
/** |
| 87 |
* The post type name. |
| 88 |
* |
| 89 |
* @var string |
| 90 |
*/ |
| 91 |
private $post_type = 'docs'; |
| 92 |
|
| 93 |
/** |
| 94 |
* Holds various class instances |
| 95 |
* |
| 96 |
* @var array |
| 97 |
*/ |
| 98 |
private $container = []; |
| 99 |
|
| 100 |
/** |
| 101 |
* Class constructor. |
| 102 |
*/ |
| 103 |
private function __construct() { |
| 104 |
$this->define_constants(); |
| 105 |
$this->init_actions(); |
| 106 |
|
| 107 |
register_activation_hook( __FILE__, [ $this, 'activate' ] ); |
| 108 |
|
| 109 |
add_action( 'after_setup_theme', [ $this, 'init_classes' ] ); |
| 110 |
|
| 111 |
$this->init_action_scheduler(); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Initializes the WeDocs() class. |
| 116 |
* |
| 117 |
* Checks for an existing WeDocs() instance |
| 118 |
* and if it doesn't find one, creates it. |
| 119 |
*/ |
| 120 |
public static function init() { |
| 121 |
static $instance = false; |
| 122 |
|
| 123 |
if ( ! $instance ) { |
| 124 |
$instance = new WeDocs(); |
| 125 |
} |
| 126 |
|
| 127 |
return $instance; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Define the required plugin constants |
| 132 |
* |
| 133 |
* @return void |
| 134 |
*/ |
| 135 |
public function define_constants() { |
| 136 |
define( 'WEDOCS_VERSION', self::VERSION ); |
| 137 |
define( 'WEDOCS_FILE', __FILE__ ); |
| 138 |
define( 'WEDOCS_PATH', __DIR__ ); |
| 139 |
define( 'WEDOCS_URL', plugins_url( '', WEDOCS_FILE ) ); |
| 140 |
define( 'WEDOCS_ASSETS', WEDOCS_URL . '/assets' ); |
| 141 |
define( 'WEDOCS_PROMO_KEY', 'wedocs_promo_notices' ); |
| 142 |
define( 'WEDOCS_PROMO_URL', 'https://raw.githubusercontent.com/weDevsOfficial/wedocs-util/refs/heads/master/promotion.json' ); |
| 143 |
define( 'WEDOCS_LOGO_URL', WEDOCS_URL . '/assets/img/wedocs-icon-128x128.png' ); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Magic getter to bypass referencing plugin. |
| 148 |
* |
| 149 |
* @param $prop |
| 150 |
* |
| 151 |
* @return mixed |
| 152 |
*/ |
| 153 |
public function __get( $prop ) { |
| 154 |
if ( array_key_exists( $prop, $this->container ) ) { |
| 155 |
return $this->container[ $prop ]; |
| 156 |
} |
| 157 |
|
| 158 |
return $this->{$prop}; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Initialize the plugin. |
| 163 |
* |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
public function init_actions() { |
| 167 |
$this->theme_dir_path = apply_filters( 'wedocs_theme_dir_path', 'wedocs/' ); |
| 168 |
|
| 169 |
// Localize our plugin |
| 170 |
add_action( 'init', [ $this, 'localization_setup' ] ); |
| 171 |
add_action( 'init', [ $this, 'register_blocks' ] ); |
| 172 |
// add_action('init', [$this, 'register_blocks']); |
| 173 |
add_filter('block_categories_all', [$this, 'register_block_category']); |
| 174 |
add_filter( 'render_block', [ $this, 'gate_pro_blocks' ], 10, 2 ); |
| 175 |
|
| 176 |
// registeer our widget |
| 177 |
add_action( 'widgets_init', [ $this, 'register_widget' ] ); |
| 178 |
} |
| 179 |
|
| 180 |
public function register_blocks() { |
| 181 |
// Enqueue admin script early to make weDocsAdminScriptVars available for blocks |
| 182 |
wp_enqueue_script( 'wedocs-admin-script' ); |
| 183 |
|
| 184 |
// Modern WordPress block registration using block.json files |
| 185 |
$block_directories = [ |
| 186 |
// Free blocks |
| 187 |
'assets/build/blocks/DocsGrid', |
| 188 |
'assets/build/blocks/Breadcrumb', |
| 189 |
'assets/build/blocks/HelpfulFeedback', |
| 190 |
'assets/build/blocks/QuickSearch', |
| 191 |
'assets/build/blocks/PrintButton', |
| 192 |
'assets/build/blocks/DocNavigation', |
| 193 |
'assets/build/blocks/Sidebar', |
| 194 |
'assets/build/blocks/Search', |
| 195 |
'assets/build/blocks/HelpfulModal', |
| 196 |
'assets/build/blocks/LastUpdated', |
| 197 |
// Pro blocks — always registered so they appear in the inserter; |
| 198 |
// JS handles the pro gate and shows the PRO badge when pro is inactive. |
| 199 |
'assets/build/blocks/TableOfContents', |
| 200 |
// 'assets/build/blocks/AdvanceContributors', |
| 201 |
'assets/build/blocks/Contributors', |
| 202 |
'assets/build/blocks/SocialShare', |
| 203 |
'assets/build/blocks/AISummary', |
| 204 |
'assets/build/blocks/DocActions', |
| 205 |
'assets/build/blocks/ReadingProgress', |
| 206 |
'assets/build/blocks/FontSizeSwitcher', |
| 207 |
]; |
| 208 |
|
| 209 |
|
| 210 |
foreach ( $block_directories as $block_dir ) { |
| 211 |
$block_path = plugin_dir_path(__FILE__) . $block_dir; |
| 212 |
|
| 213 |
if ( file_exists( $block_path . '/block.json' ) ) { |
| 214 |
|
| 215 |
// Register block using block.json (modern approach - render callback is handled by block.json) |
| 216 |
register_block_type( $block_path ); |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
/** |
| 222 |
* Prevent pro-only blocks from rendering on the frontend when weDocs Pro is inactive. |
| 223 |
* Covers blocks that use a save() function (static HTML stored in DB). |
| 224 |
* |
| 225 |
* @param string $block_content Rendered block HTML. |
| 226 |
* @param array $block Block data. |
| 227 |
* @return string |
| 228 |
*/ |
| 229 |
public function gate_pro_blocks( $block_content, $block ) { |
| 230 |
static $pro_active = null; |
| 231 |
if ( $pro_active === null ) { |
| 232 |
$pro_active = function_exists( 'wedocs_is_pro_active' ) && wedocs_is_pro_active(); |
| 233 |
} |
| 234 |
|
| 235 |
if ( $pro_active ) { |
| 236 |
return $block_content; |
| 237 |
} |
| 238 |
|
| 239 |
$pro_blocks = [ |
| 240 |
'wedocs/reading-progress', |
| 241 |
'wedocs/ai-summary', |
| 242 |
'wedocs/doc-actions', |
| 243 |
'wedocs/font-size-switcher', |
| 244 |
]; |
| 245 |
|
| 246 |
if ( isset( $block['blockName'] ) && in_array( $block['blockName'], $pro_blocks, true ) ) { |
| 247 |
return ''; |
| 248 |
} |
| 249 |
|
| 250 |
return $block_content; |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Register the weDocs block category. |
| 255 |
* |
| 256 |
* @param array $categories Existing block categories. |
| 257 |
* @return array Modified block categories. |
| 258 |
*/ |
| 259 |
public function register_block_category($categories) { |
| 260 |
// Check if weDocs category already exists |
| 261 |
foreach ($categories as $category) { |
| 262 |
if ($category['slug'] === 'wedocs') { |
| 263 |
return $categories; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
// Add weDocs category at the beginning |
| 268 |
return array_merge( |
| 269 |
[ |
| 270 |
[ |
| 271 |
'slug' => 'wedocs', |
| 272 |
'title' => __('weDocs', 'wedocs'), |
| 273 |
'icon' => null |
| 274 |
] |
| 275 |
], |
| 276 |
$categories |
| 277 |
); |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* The plugin activation function. |
| 282 |
* |
| 283 |
* @since 1.3 |
| 284 |
* |
| 285 |
* @return void |
| 286 |
*/ |
| 287 |
public function activate() { |
| 288 |
$installer = new WeDevs\WeDocs\Installer(); |
| 289 |
$installer->run(); |
| 290 |
|
| 291 |
// Set the redirect option to true when the plugin is activated. |
| 292 |
update_option( 'wedocs_activation_redirect', true ); |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Initialize the classes. |
| 297 |
* |
| 298 |
* @since 1.4 |
| 299 |
* |
| 300 |
* @return void |
| 301 |
*/ |
| 302 |
public function init_classes() { |
| 303 |
$this->container['post_type'] = new WeDevs\WeDocs\Post_Types(); |
| 304 |
|
| 305 |
if ( is_admin() ) { |
| 306 |
$this->container['admin'] = new WeDevs\WeDocs\Admin(); |
| 307 |
} else { |
| 308 |
$this->container['frontend'] = new WeDevs\WeDocs\Frontend(); |
| 309 |
} |
| 310 |
|
| 311 |
if ( wp_doing_ajax() ) { |
| 312 |
$this->container['ajax'] = new WeDevs\WeDocs\Ajax(); |
| 313 |
} |
| 314 |
|
| 315 |
$this->container['api'] = new WeDevs\WeDocs\API(); |
| 316 |
$this->container['assets'] = new WeDevs\WeDocs\Assets(); |
| 317 |
$this->container['migrate'] = new WeDevs\WeDocs\Admin\Migrate(); |
| 318 |
$this->container['upgrader'] = new WeDevs\WeDocs\Upgrader\Upgrader(); |
| 319 |
$this->container['capability'] = new Capability(); |
| 320 |
$this->container['templates'] = new WeDevs\WeDocs\Templates\TemplateManager(); |
| 321 |
|
| 322 |
// Initialize Elementor integration if Elementor is active |
| 323 |
if ( did_action( 'elementor/loaded' ) ) { |
| 324 |
$this->container['elementor'] = new WeDevs\WeDocs\Elementor(); |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
/** |
| 329 |
* Initialize plugin for localization. |
| 330 |
* |
| 331 |
* @uses load_plugin_textdomain() |
| 332 |
*/ |
| 333 |
public function localization_setup() { |
| 334 |
load_plugin_textdomain( 'wedocs', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 335 |
} |
| 336 |
|
| 337 |
/** |
| 338 |
* Register the search widget. |
| 339 |
* |
| 340 |
* @return void |
| 341 |
*/ |
| 342 |
public function register_widget() { |
| 343 |
register_widget( 'WeDevs\WeDocs\Widget' ); |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Get the plugin url. |
| 348 |
* |
| 349 |
* @return string |
| 350 |
*/ |
| 351 |
public function plugin_url() { |
| 352 |
if ( $this->plugin_url ) { |
| 353 |
return $this->plugin_url; |
| 354 |
} |
| 355 |
|
| 356 |
return $this->plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) ); |
| 357 |
} |
| 358 |
|
| 359 |
/** |
| 360 |
* Get the plugin path. |
| 361 |
* |
| 362 |
* @return string |
| 363 |
*/ |
| 364 |
public function plugin_path() { |
| 365 |
if ( $this->plugin_path ) { |
| 366 |
return $this->plugin_path; |
| 367 |
} |
| 368 |
|
| 369 |
return $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ); |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Initialize action scheduler. |
| 374 |
* |
| 375 |
* @since 2.0.0 |
| 376 |
* |
| 377 |
* @return void |
| 378 |
*/ |
| 379 |
public function init_action_scheduler() { |
| 380 |
require_once( __DIR__ . '/vendor/woocommerce/action-scheduler/action-scheduler.php' ); |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Get the template path. |
| 385 |
* |
| 386 |
* @return string |
| 387 |
*/ |
| 388 |
public function template_path() { |
| 389 |
return $this->plugin_path() . '/templates/'; |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Get the theme directory path. |
| 394 |
* |
| 395 |
* @return string |
| 396 |
*/ |
| 397 |
public function theme_dir_path() { |
| 398 |
return $this->theme_dir_path; |
| 399 |
} |
| 400 |
} // WeDocs |
| 401 |
|
| 402 |
/** |
| 403 |
* Initialize the plugin. |
| 404 |
* |
| 405 |
* @return \WeDocs |
| 406 |
*/ |
| 407 |
function wedocs() { |
| 408 |
return WeDocs::init(); |
| 409 |
} |
| 410 |
|
| 411 |
// kick it off |
| 412 |
wedocs(); |
| 413 |
|
| 414 |
|
| 415 |
/** |
| 416 |
* Dequeue wedocs-pro-frontend-css on non-docs post types |
| 417 |
*/ |
| 418 |
function dequeue_wedocs_pro_frontend_css() { |
| 419 |
// Check if we're not on a docs post type |
| 420 |
if ( ! is_singular( 'docs' ) && ! is_post_type_archive( 'docs' ) && ! is_tax( array( 'doc_category', 'doc_tag' ) ) ) { |
| 421 |
wp_dequeue_style( 'wedocs-pro-frontend-css' ); |
| 422 |
wp_deregister_style( 'wedocs-pro-frontend-css' ); |
| 423 |
} |
| 424 |
} |
| 425 |
add_action( 'wp_enqueue_scripts', 'dequeue_wedocs_pro_frontend_css', 20 ); |
| 426 |
|
| 427 |
|
| 428 |
|