| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Editors; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly |
| 7 |
} |
| 8 |
|
| 9 |
use Elementor\Controls_Manager; |
| 10 |
use Elementor\Api as ElementorAPI; |
| 11 |
use Elementor\Plugin as ElementorPlugin; |
| 12 |
use WPDeveloper\BetterDocs\Core\Settings; |
| 13 |
use WPDeveloper\BetterDocs\Utils\Enqueue; |
| 14 |
use WPDeveloper\BetterDocs\Editors\Elementor\Helper; |
| 15 |
use WPDeveloper\BetterDocs\Editors\Elementor\SingleDocs; |
| 16 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ToC; |
| 17 |
use WPDeveloper\BetterDocs\Editors\Elementor\DocsArchive; |
| 18 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Title; |
| 19 |
use WPDeveloper\BetterDocs\Editors\Elementor\Tags\TitleTag; |
| 20 |
use WPDeveloper\BetterDocs\Editors\Elementor\TemplateSource; |
| 21 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Content; |
| 22 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\DocDate; |
| 23 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Sidebar; |
| 24 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\DocShare; |
| 25 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Feedback; |
| 26 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\FAQ; |
| 27 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Reactions; |
| 28 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Navigation; |
| 29 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ArchiveList; |
| 30 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Breadcrumbs; |
| 31 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\SearchForm; |
| 32 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\CategoryBox; |
| 33 |
use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\CategoryGrid; |
| 34 |
use WPDeveloper\BetterDocs\Editors\Elementor\Conditions\ArchiveCondition; |
| 35 |
|
| 36 |
class Elementor extends BaseEditor { |
| 37 |
protected $is_elementor_active = false; |
| 38 |
protected $is_elementor_pro_active = false; |
| 39 |
protected static $is_templates_added = false; |
| 40 |
|
| 41 |
/** |
| 42 |
* Elementor plugin class |
| 43 |
* @var ElementorPlugin |
| 44 |
*/ |
| 45 |
protected $elementor; |
| 46 |
|
| 47 |
/** |
| 48 |
* Elementor Helper class |
| 49 |
* @var Helper |
| 50 |
*/ |
| 51 |
protected $helper; |
| 52 |
|
| 53 |
public function __construct( Settings $settings, Enqueue $enqueue, Helper $helper ) { |
| 54 |
parent::__construct( $settings, $enqueue ); |
| 55 |
|
| 56 |
$this->helper = $helper; |
| 57 |
$this->is_elementor_active = betterdocs()->helper->is_plugin_active( 'elementor/elementor.php' ); |
| 58 |
$this->is_elementor_pro_active = betterdocs()->helper->is_plugin_active( 'elementor-pro/elementor-pro.php' ); |
| 59 |
|
| 60 |
if ( ! $this->is_elementor_active || ! class_exists( ElementorPlugin::class ) ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$this->elementor = ElementorPlugin::instance(); |
| 65 |
} |
| 66 |
|
| 67 |
public function init() { |
| 68 |
if ( ! $this->is_elementor_active || $this->elementor == null ) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
add_action( 'wp_enqueue_scripts', [$this, 'enqueue_scripts'] ); |
| 73 |
|
| 74 |
add_action( 'elementor/elements/categories_registered', [$this, 'register_widget_category'] ); |
| 75 |
add_action( 'elementor/widgets/register', [$this, 'register_basic_widgets'] ); |
| 76 |
|
| 77 |
add_action( 'elementor/editor/before_enqueue_scripts', [$this, 'editor_enqueue_scripts'] ); |
| 78 |
add_filter( 'elementor/editor/localize_settings', [$this, 'promote_pro_elements'] ); |
| 79 |
|
| 80 |
add_filter( 'elementor/theme/need_override_location', [$this, 'override_location'], 10, 2 ); |
| 81 |
add_action( 'betterdocs/elementor/widgets/query', [$this, 'betterdocs_query'], 10, 2 ); |
| 82 |
|
| 83 |
if ( $this->is_elementor_pro_active ) { |
| 84 |
add_action( 'elementor/dynamic_tags/register', [$this, 'register_basic_tags'] ); |
| 85 |
add_action( 'elementor/widgets/register', [$this, 'register_theme_builder_widgets'] ); |
| 86 |
add_action( 'elementor/theme/register_conditions', [$this, 'register_conditions'] ); |
| 87 |
|
| 88 |
//(Conflict Fix)Solves the issue with plugin - Sticky Header Effects for Elementor(Plugin) |
| 89 |
if ( ! did_action( 'elementor/documents/register' ) ) { |
| 90 |
add_action( 'elementor/documents/register', [$this, 'register_documents'] ); |
| 91 |
} else { |
| 92 |
$this->elementor->documents->register_document_type( 'docs', SingleDocs::get_class_full_name() ); |
| 93 |
$this->elementor->documents->register_document_type( 'doc-archive', DocsArchive::get_class_full_name() ); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
$this->betterdocs_init(); |
| 98 |
} |
| 99 |
|
| 100 |
public function editor_enqueue_scripts() { |
| 101 |
betterdocs()->assets->enqueue( 'betterdocs-el-icon', 'elementor/css/betterdocs-el-icon.css' ); |
| 102 |
} |
| 103 |
|
| 104 |
public function register_documents( $documents_manager ) { |
| 105 |
$documents_manager->register_document_type( 'docs', SingleDocs::get_class_full_name() ); |
| 106 |
$documents_manager->register_document_type( 'doc-archive', DocsArchive::get_class_full_name() ); |
| 107 |
} |
| 108 |
|
| 109 |
public function override_location( $need_override_location, $location ) { |
| 110 |
if ( is_singular( ['docs'] ) && 'single' === $location ) { |
| 111 |
$need_override_location = true; |
| 112 |
} |
| 113 |
|
| 114 |
return $need_override_location; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Query Controls |
| 119 |
* |
| 120 |
*/ |
| 121 |
public function betterdocs_query( $wb, $taxonomy ) { |
| 122 |
$wb->start_controls_section( |
| 123 |
'eael_section_post__filters', |
| 124 |
[ |
| 125 |
'label' => __( 'Query', 'betterdocs' ) |
| 126 |
] |
| 127 |
); |
| 128 |
|
| 129 |
$default_multiple_kb = $this->multiple_kb_status(); |
| 130 |
|
| 131 |
if ( $default_multiple_kb && $taxonomy != 'knowledge_base' ) { |
| 132 |
$multiple_kb_terms = $this->get_kb_terms( true, false ); |
| 133 |
$default_slug = count( $multiple_kb_terms ) > 0 ? array_keys( $multiple_kb_terms )[0] : ''; |
| 134 |
|
| 135 |
$wb->add_control( |
| 136 |
'selected_knowledge_base', |
| 137 |
[ |
| 138 |
'label' => __( 'Knowledge Bases', 'betterdocs' ), |
| 139 |
'label_block' => true, |
| 140 |
'type' => Controls_Manager::SELECT2, |
| 141 |
'options' => $multiple_kb_terms, |
| 142 |
'multiple' => false, |
| 143 |
'default' => '', |
| 144 |
'select2options' => [ |
| 145 |
'placeholder' => __( 'All Knowledge Base', 'betterdocs' ), |
| 146 |
'allowClear' => true |
| 147 |
] |
| 148 |
] |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
if ( $wb->get_name() === 'betterdocs-category-grid' ) { |
| 153 |
$wb->add_control( |
| 154 |
'grid_query_heading', |
| 155 |
[ |
| 156 |
'label' => __( 'Category Grid', 'betterdocs' ), |
| 157 |
'type' => Controls_Manager::HEADING |
| 158 |
] |
| 159 |
); |
| 160 |
} |
| 161 |
|
| 162 |
$wb->add_control( |
| 163 |
'include', |
| 164 |
[ |
| 165 |
'label' => __( 'Include', 'betterdocs' ), |
| 166 |
'label_block' => true, |
| 167 |
'type' => Controls_Manager::SELECT2, |
| 168 |
'options' => $this->helper->get_terms( $taxonomy, 'term_id' ), |
| 169 |
'multiple' => true, |
| 170 |
'default' => [] |
| 171 |
] |
| 172 |
); |
| 173 |
|
| 174 |
$wb->add_control( |
| 175 |
'exclude', |
| 176 |
[ |
| 177 |
'label' => __( 'Exclude', 'betterdocs' ), |
| 178 |
'type' => Controls_Manager::SELECT2, |
| 179 |
'options' => $this->helper->get_terms( $taxonomy, 'term_id' ), |
| 180 |
'label_block' => true, |
| 181 |
'post_type' => '', |
| 182 |
'multiple' => true |
| 183 |
] |
| 184 |
); |
| 185 |
|
| 186 |
if ( $wb->get_name() === 'betterdocs-category-grid' ) { |
| 187 |
$wb->add_control( |
| 188 |
'grid_per_page', |
| 189 |
[ |
| 190 |
'label' => __( 'Grid Per Page', 'betterdocs' ), |
| 191 |
'type' => Controls_Manager::NUMBER, |
| 192 |
'default' => '8' |
| 193 |
] |
| 194 |
); |
| 195 |
} else if ( $wb->get_name() !== 'betterdocs-sidebar' ) { |
| 196 |
$wb->add_control( |
| 197 |
'box_per_page', |
| 198 |
[ |
| 199 |
'label' => __( 'Box Per Page', 'betterdocs' ), |
| 200 |
'type' => Controls_Manager::NUMBER, |
| 201 |
'default' => '8' |
| 202 |
] |
| 203 |
); |
| 204 |
} |
| 205 |
|
| 206 |
$wb->add_control( |
| 207 |
'offset', |
| 208 |
[ |
| 209 |
'label' => __( 'Offset', 'betterdocs' ), |
| 210 |
'type' => Controls_Manager::NUMBER, |
| 211 |
'default' => '0' |
| 212 |
] |
| 213 |
); |
| 214 |
|
| 215 |
// difference between betterdocs-sidebar and betterdocs-category-grid is the default order |
| 216 |
if ( $wb->get_name() === 'betterdocs-sidebar' ) { |
| 217 |
$wb->add_control( |
| 218 |
'orderby', |
| 219 |
[ |
| 220 |
'label' => __( 'Order By', 'betterdocs' ), |
| 221 |
'type' => Controls_Manager::SELECT, |
| 222 |
'options' => [ |
| 223 |
'none' => __( 'No order', 'betterdocs' ), |
| 224 |
'name' => __( 'Name', 'betterdocs' ), |
| 225 |
'slug' => __( 'Slug', 'betterdocs' ), |
| 226 |
'term_group' => __( 'Term Group', 'betterdocs' ), |
| 227 |
'term_id' => __( 'Term ID', 'betterdocs' ), |
| 228 |
'id' => __( 'ID', 'betterdocs' ), |
| 229 |
'description' => __( 'Description', 'betterdocs' ), |
| 230 |
'parent' => __( 'Parent', 'betterdocs' ), |
| 231 |
'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) |
| 232 |
], |
| 233 |
'default' => $this->settings->get( 'terms_orderby', 'betterdocs_order' ) |
| 234 |
] |
| 235 |
); |
| 236 |
|
| 237 |
$wb->add_control( |
| 238 |
'order', |
| 239 |
[ |
| 240 |
'label' => __( 'Order', 'betterdocs' ), |
| 241 |
'type' => Controls_Manager::SELECT, |
| 242 |
'options' => [ |
| 243 |
'ASC' => 'Ascending', |
| 244 |
'DESC' => 'Descending' |
| 245 |
], |
| 246 |
'default' => $this->settings->get( 'terms_order', 'ASC' ), |
| 247 |
'condition' => [ |
| 248 |
'orderby!' => 'betterdocs_order' |
| 249 |
] |
| 250 |
|
| 251 |
] |
| 252 |
); |
| 253 |
} else { |
| 254 |
$wb->add_control( |
| 255 |
'orderby', |
| 256 |
[ |
| 257 |
'label' => __( 'Order By', 'betterdocs' ), |
| 258 |
'type' => Controls_Manager::SELECT, |
| 259 |
'options' => [ |
| 260 |
'none' => __( 'No order', 'betterdocs' ), |
| 261 |
'name' => __( 'Name', 'betterdocs' ), |
| 262 |
'slug' => __( 'Slug', 'betterdocs' ), |
| 263 |
'term_group' => __( 'Term Group', 'betterdocs' ), |
| 264 |
'term_id' => __( 'Term ID', 'betterdocs' ), |
| 265 |
'id' => __( 'ID', 'betterdocs' ), |
| 266 |
'description' => __( 'Description', 'betterdocs' ), |
| 267 |
'parent' => __( 'Parent', 'betterdocs' ), |
| 268 |
'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) |
| 269 |
], |
| 270 |
'default' => 'name' |
| 271 |
] |
| 272 |
); |
| 273 |
|
| 274 |
$wb->add_control( |
| 275 |
'order', |
| 276 |
[ |
| 277 |
'label' => __( 'Order', 'betterdocs' ), |
| 278 |
'type' => Controls_Manager::SELECT, |
| 279 |
'options' => [ |
| 280 |
'ASC' => 'Ascending', |
| 281 |
'DESC' => 'Descending' |
| 282 |
], |
| 283 |
'default' => 'asc', |
| 284 |
'condition' => [ |
| 285 |
'orderby!' => 'betterdocs_order' |
| 286 |
] |
| 287 |
|
| 288 |
] |
| 289 |
); |
| 290 |
} |
| 291 |
|
| 292 |
if ( $wb->get_name() === 'betterdocs-category-grid' ) { |
| 293 |
$wb->add_control( |
| 294 |
'grid_posts_query_heading', |
| 295 |
[ |
| 296 |
'label' => __( 'Grid List Posts', 'betterdocs' ), |
| 297 |
'type' => Controls_Manager::HEADING, |
| 298 |
'separator' => 'before' |
| 299 |
] |
| 300 |
); |
| 301 |
|
| 302 |
$wb->add_control( |
| 303 |
'post_per_page', |
| 304 |
[ |
| 305 |
'label' => __( 'Post Per Page', 'betterdocs' ), |
| 306 |
'type' => Controls_Manager::NUMBER, |
| 307 |
'default' => '6' |
| 308 |
] |
| 309 |
); |
| 310 |
|
| 311 |
$wb->add_control( |
| 312 |
'post_orderby', |
| 313 |
[ |
| 314 |
'label' => __( 'Order By', 'betterdocs' ), |
| 315 |
'type' => Controls_Manager::SELECT, |
| 316 |
'options' => $this->helper->orderby_options(), |
| 317 |
'default' => 'date' |
| 318 |
] |
| 319 |
); |
| 320 |
|
| 321 |
$wb->add_control( |
| 322 |
'post_order', |
| 323 |
[ |
| 324 |
'label' => __( 'Order', 'betterdocs' ), |
| 325 |
'type' => Controls_Manager::SELECT, |
| 326 |
'options' => [ |
| 327 |
'asc' => 'Ascending', |
| 328 |
'desc' => 'Descending' |
| 329 |
], |
| 330 |
'default' => 'desc' |
| 331 |
] |
| 332 |
); |
| 333 |
|
| 334 |
$wb->add_control( |
| 335 |
'nested_subcategory', |
| 336 |
[ |
| 337 |
'label' => __( 'Enable Nested Subcategory', 'betterdocs' ), |
| 338 |
'type' => Controls_Manager::SWITCHER, |
| 339 |
'label_on' => __( 'Yes', 'betterdocs' ), |
| 340 |
'label_off' => __( 'No', 'betterdocs' ), |
| 341 |
'return_value' => 'true', |
| 342 |
'default' => false |
| 343 |
] |
| 344 |
); |
| 345 |
|
| 346 |
$wb->add_control( |
| 347 |
'post_per_subcat', |
| 348 |
[ |
| 349 |
'label' => __( 'Post Per Subcategory', 'betterdocs' ), |
| 350 |
'type' => Controls_Manager::NUMBER, |
| 351 |
'default' => '6', |
| 352 |
'condition' => [ |
| 353 |
'nested_subcategory' => 'true' |
| 354 |
] |
| 355 |
] |
| 356 |
); |
| 357 |
} |
| 358 |
|
| 359 |
if ( $wb->get_name() === 'betterdocs-category-box' ) { |
| 360 |
$wb->add_control( |
| 361 |
'nested_subcategory', |
| 362 |
[ |
| 363 |
'label' => __( 'Nested Subcategory', 'betterdocs' ), |
| 364 |
'type' => Controls_Manager::SWITCHER, |
| 365 |
'label_on' => __( 'Yes', 'betterdocs' ), |
| 366 |
'label_off' => __( 'No', 'betterdocs' ), |
| 367 |
'return_value' => 'true', |
| 368 |
'default' => false |
| 369 |
] |
| 370 |
); |
| 371 |
} |
| 372 |
|
| 373 |
if ( $wb->get_name() === 'betterdocs-sidebar' ) { |
| 374 |
$wb->add_control( |
| 375 |
'nested_subcategory', |
| 376 |
[ |
| 377 |
'label' => __( 'Nested Subcategory', 'betterdocs' ), |
| 378 |
'type' => Controls_Manager::SWITCHER, |
| 379 |
'label_on' => __( 'Yes', 'betterdocs' ), |
| 380 |
'label_off' => __( 'No', 'betterdocs' ), |
| 381 |
'return_value' => 'true', |
| 382 |
'default' => ( $this->settings->get( 'archive_nested_subcategory' ) == 1 ) ? 'true' : '' |
| 383 |
] |
| 384 |
); |
| 385 |
} |
| 386 |
|
| 387 |
if ( $wb->get_name() === 'betterdocs-tab-view-list' ) { |
| 388 |
$wb->add_control( |
| 389 |
'tab_posts_query_heading', |
| 390 |
[ |
| 391 |
'label' => __( 'Tab List Posts', 'betterdocs' ), |
| 392 |
'type' => Controls_Manager::HEADING, |
| 393 |
'separator' => 'before' |
| 394 |
] |
| 395 |
); |
| 396 |
|
| 397 |
$wb->add_control( |
| 398 |
'post_per_tab', |
| 399 |
[ |
| 400 |
'label' => __( 'Posts Per Tab', 'betterdocs' ), |
| 401 |
'type' => Controls_Manager::NUMBER, |
| 402 |
'default' => '10' |
| 403 |
] |
| 404 |
); |
| 405 |
|
| 406 |
$wb->add_control( |
| 407 |
'tab_list_posts_orderby', |
| 408 |
[ |
| 409 |
'label' => __( 'Posts Order By', 'betterdocs' ), |
| 410 |
'type' => Controls_Manager::SELECT, |
| 411 |
'options' => [ |
| 412 |
'name' => __( 'Name', 'betterdocs' ), |
| 413 |
'slug' => __( 'Slug', 'betterdocs' ), |
| 414 |
'term_group' => __( 'Term Group', 'betterdocs' ), |
| 415 |
'term_id' => __( 'Term ID', 'betterdocs' ), |
| 416 |
'id' => __( 'ID', 'betterdocs' ), |
| 417 |
'description' => __( 'Description', 'betterdocs' ), |
| 418 |
'parent' => __( 'Parent', 'betterdocs' ), |
| 419 |
'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) |
| 420 |
], |
| 421 |
'default' => 'name' |
| 422 |
] |
| 423 |
); |
| 424 |
|
| 425 |
$wb->add_control( |
| 426 |
'tab_list_order', |
| 427 |
[ |
| 428 |
'label' => __( 'Order', 'betterdocs' ), |
| 429 |
'type' => Controls_Manager::SELECT, |
| 430 |
'options' => [ |
| 431 |
'ASC' => 'Ascending', |
| 432 |
'DESC' => 'Descending' |
| 433 |
], |
| 434 |
'default' => 'ASC' |
| 435 |
|
| 436 |
] |
| 437 |
); |
| 438 |
|
| 439 |
$wb->add_control( |
| 440 |
'nested_subcategory_tab_list', |
| 441 |
[ |
| 442 |
'label' => __( 'Nested Subcategory', 'betterdocs' ), |
| 443 |
'type' => Controls_Manager::SWITCHER, |
| 444 |
'label_on' => __( 'Yes', 'betterdocs' ), |
| 445 |
'label_off' => __( 'No', 'betterdocs' ), |
| 446 |
'return_value' => 'true', |
| 447 |
'default' => 'true' |
| 448 |
] |
| 449 |
); |
| 450 |
|
| 451 |
$wb->add_control( |
| 452 |
'nested_posts_per_page', |
| 453 |
[ |
| 454 |
'label' => __( 'Posts Per Page', 'betterdocs' ), |
| 455 |
'type' => Controls_Manager::NUMBER, |
| 456 |
'default' => '-1', |
| 457 |
'condition' => [ |
| 458 |
'nested_subcategory_tab_list' => 'true' |
| 459 |
] |
| 460 |
] |
| 461 |
); |
| 462 |
|
| 463 |
$wb->add_control( |
| 464 |
'nested_sub_cat_order', |
| 465 |
[ |
| 466 |
'label' => __( 'Nested Subcategory Order', 'betterdocs' ), |
| 467 |
'type' => Controls_Manager::SELECT, |
| 468 |
'options' => [ |
| 469 |
'ASC' => 'Ascending', |
| 470 |
'DESC' => 'Descending' |
| 471 |
], |
| 472 |
'default' => 'ASC', |
| 473 |
'condition' => [ |
| 474 |
'nested_subcategory_tab_list' => 'true' |
| 475 |
] |
| 476 |
] |
| 477 |
); |
| 478 |
|
| 479 |
$wb->add_control( |
| 480 |
'nested_sub_cat_orderby', |
| 481 |
[ |
| 482 |
'label' => __( 'Nested Subcategory Order By', 'betterdocs' ), |
| 483 |
'type' => Controls_Manager::SELECT, |
| 484 |
'options' => [ |
| 485 |
'none' => __( 'No order', 'betterdocs' ), |
| 486 |
'name' => __( 'Name', 'betterdocs' ), |
| 487 |
'slug' => __( 'Slug', 'betterdocs' ), |
| 488 |
'term_group' => __( 'Term Group', 'betterdocs' ), |
| 489 |
'term_id' => __( 'Term ID', 'betterdocs' ), |
| 490 |
'id' => __( 'ID', 'betterdocs' ), |
| 491 |
'description' => __( 'Description', 'betterdocs' ), |
| 492 |
'parent' => __( 'Parent', 'betterdocs' ), |
| 493 |
'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) |
| 494 |
], |
| 495 |
'default' => 'name', |
| 496 |
'condition' => [ |
| 497 |
'nested_subcategory_tab_list' => 'true' |
| 498 |
] |
| 499 |
] |
| 500 |
); |
| 501 |
} |
| 502 |
|
| 503 |
$wb->end_controls_section(); |
| 504 |
} |
| 505 |
|
| 506 |
public function multiple_kb_status() { |
| 507 |
if ( $this->settings->get( 'multiple_kb' ) == 1 ) { |
| 508 |
return 'true'; |
| 509 |
} |
| 510 |
|
| 511 |
return ''; |
| 512 |
} |
| 513 |
|
| 514 |
public function get_kb_terms( $prettify = false, $term_id = true ) { |
| 515 |
$args = [ |
| 516 |
'taxonomy' => 'knowledge_base', |
| 517 |
'hide_empty' => true, |
| 518 |
'parent' => 0 |
| 519 |
]; |
| 520 |
|
| 521 |
$terms = get_terms( $args ); |
| 522 |
|
| 523 |
if ( is_wp_error( $terms ) ) { |
| 524 |
return []; |
| 525 |
} |
| 526 |
|
| 527 |
if ( $prettify ) { |
| 528 |
$pretty_taxonomies = []; |
| 529 |
|
| 530 |
foreach ( $terms as $term ) { |
| 531 |
$pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = $term->name; |
| 532 |
} |
| 533 |
|
| 534 |
return $pretty_taxonomies; |
| 535 |
} |
| 536 |
|
| 537 |
return $terms; |
| 538 |
} |
| 539 |
|
| 540 |
public function register_basic_tags( $module ) { |
| 541 |
$module->register( new TitleTag ); |
| 542 |
} |
| 543 |
|
| 544 |
public function register_basic_widgets( $widgets_manager ) { |
| 545 |
foreach ( $this->basic_widget_lists() as $value ) { |
| 546 |
$widgets_manager->register( new $value ); |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
/** |
| 551 |
* |
| 552 |
* Mange all widget for single docs |
| 553 |
* |
| 554 |
* @return string[] |
| 555 |
* @since 1.3.0 |
| 556 |
*/ |
| 557 |
private function basic_widget_lists() { |
| 558 |
$widget_arr = [ |
| 559 |
'betterdocs-elementor-search-form' => SearchForm::class, |
| 560 |
'betterdocs-elementor-category-grid' => CategoryGrid::class, |
| 561 |
'betterdocs-elementor-category-box' => CategoryBox::class, |
| 562 |
'betterdocs-faq-widget' => FAQ::class |
| 563 |
]; |
| 564 |
|
| 565 |
return $widget_arr; |
| 566 |
} |
| 567 |
|
| 568 |
public function register_widget_category( $elements_manager ) { |
| 569 |
$elements_manager->add_category( 'betterdocs-elements', [ |
| 570 |
'title' => __( 'BetterDocs', 'betterdocs' ), |
| 571 |
'icon' => 'font' |
| 572 |
], 1 ); |
| 573 |
} |
| 574 |
|
| 575 |
public function promote_pro_elements( $config ) { |
| 576 |
if ( $this->is_pro_active ) { |
| 577 |
return $config; |
| 578 |
} |
| 579 |
|
| 580 |
$promotion_widgets = []; |
| 581 |
|
| 582 |
if ( isset( $config['promotionWidgets'] ) ) { |
| 583 |
$promotion_widgets = $config['promotionWidgets']; |
| 584 |
} |
| 585 |
|
| 586 |
$combine_array = array_merge( $promotion_widgets, [ |
| 587 |
[ |
| 588 |
'name' => 'betterdocs-multiple-kb', |
| 589 |
'title' => __( 'BetterDocs Multiple KB', 'betterdocs' ), |
| 590 |
'icon' => 'betterdocs-icon-category-box', |
| 591 |
'categories' => '["docs-archive"]' |
| 592 |
] |
| 593 |
] ); |
| 594 |
|
| 595 |
$config['promotionWidgets'] = $combine_array; |
| 596 |
|
| 597 |
return $config; |
| 598 |
} |
| 599 |
|
| 600 |
public function is_templates() { |
| 601 |
if ( $this->is_elementor_active && $this->is_elementor_pro_active ) { |
| 602 |
$post_id = get_the_ID(); |
| 603 |
if ( $this->elementor->editor->is_edit_mode() || ( |
| 604 |
get_post_meta( $post_id, '_elementor_template_type', true ) |
| 605 |
&& $this->elementor->documents->get( $post_id )->is_built_with_elementor() |
| 606 |
) ) { |
| 607 |
return true; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
return null; |
| 612 |
} |
| 613 |
|
| 614 |
public function enqueue_scripts() { |
| 615 |
$assets = betterdocs()->assets; |
| 616 |
|
| 617 |
/** |
| 618 |
* Widget's CSS |
| 619 |
*/ |
| 620 |
$assets->register( 'betterdocs-el-category-grid', 'elementor/css/category-grid.css' ); |
| 621 |
$assets->register( 'betterdocs-el-category-box', 'elementor/css/category-box.css' ); |
| 622 |
$assets->register( 'betterdocs-el-articles-list', 'elementor/css/articles-list.css' ); |
| 623 |
$assets->register( 'betterdocs-el-navigation', 'elementor/css/navigation.css' ); |
| 624 |
|
| 625 |
/** |
| 626 |
* Widget's JS |
| 627 |
*/ |
| 628 |
$assets->register( 'betterdocs-el-category-grid', 'elementor/js/category-grid.js', ['jquery', 'betterdocs-category-toggler'] ); |
| 629 |
|
| 630 |
if ( betterdocs()->helper->is_el_templates() == true ) { |
| 631 |
$assets->enqueue( 'betterdocs-elementor-editor', 'elementor/css/betterdocs-el-edit.css' ); |
| 632 |
|
| 633 |
if ( ! $this->is_pro_active ) { |
| 634 |
$assets->enqueue( 'betterdocs-elementor-editor', 'elementor/js/editor.js', ['jquery'] ); |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
do_action( 'betterdocs_elementor_enqueue_scripts', $this ); |
| 639 |
} |
| 640 |
|
| 641 |
public function register_theme_builder_widgets( $widgets_manager ) { |
| 642 |
foreach ( $this->builder_widget_list() as $value ) { |
| 643 |
if ( class_exists( $value ) ) { |
| 644 |
$widgets_manager->register( new $value ); |
| 645 |
} |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
/** |
| 650 |
* Mange all widget for single docs |
| 651 |
* |
| 652 |
* @return array<string> |
| 653 |
* @since 1.3.0 |
| 654 |
*/ |
| 655 |
public function builder_widget_list() { |
| 656 |
return apply_filters( 'betterdocs_elementor_pro_widgets', [ |
| 657 |
'betterdocs-elementor-toc' => ToC::class, |
| 658 |
'betterdocs-elementor-title' => Title::class, |
| 659 |
'betterdocs-elementor-sidebar' => Sidebar::class, |
| 660 |
'betterdocs-elementor-content' => Content::class, |
| 661 |
'betterdocs-elementor-doc-date' => DocDate::class, |
| 662 |
'betterdocs-elementor-doc-share' => DocShare::class, |
| 663 |
'betterdocs-elementor-feedback' => Feedback::class, |
| 664 |
'betterdocs-elementor-reactions' => Reactions::class, |
| 665 |
'betterdocs-elementor-navigation' => Navigation::class, |
| 666 |
'betterdocs-elementor-breadcrumbs' => Breadcrumbs::class, |
| 667 |
'betterdocs-elementor-category-archive-list' => ArchiveList::class |
| 668 |
] ); |
| 669 |
} |
| 670 |
|
| 671 |
/** |
| 672 |
* @param \ElementorPro\Modules\ThemeBuilder\Classes\Conditions_Manager $conditions_manager |
| 673 |
*/ |
| 674 |
public function register_conditions( $conditions_manager ) { |
| 675 |
$betterdocs_condition = betterdocs()->container->get( ArchiveCondition::class ); |
| 676 |
$conditions_manager->get_condition( 'general' )->register_sub_condition( $betterdocs_condition ); |
| 677 |
} |
| 678 |
|
| 679 |
public function betterdocs_init() { |
| 680 |
add_action( 'elementor/init', [$this, 'register_template_instance'], 20 ); |
| 681 |
|
| 682 |
static $is_done = false; |
| 683 |
if ( defined( 'Elementor\Api::LIBRARY_OPTION_KEY' ) && ! $is_done ) { |
| 684 |
$is_done = true; |
| 685 |
add_filter( 'option_' . ElementorAPI::LIBRARY_OPTION_KEY, [$this, 'prepend_categories'] ); |
| 686 |
} |
| 687 |
|
| 688 |
add_action( 'elementor/ajax/register_actions', [$this, 'modified_ajax_action'], 20 ); |
| 689 |
|
| 690 |
if ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.10.0', '>=' ) && ! self::$is_templates_added ) { |
| 691 |
self::$is_templates_added = true; |
| 692 |
add_filter( 'http_response', [$this, 'http_response_modify_for_bd_template'], 10, 3 ); |
| 693 |
} elseif ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) && ! self::$is_templates_added ) { |
| 694 |
self::$is_templates_added = true; |
| 695 |
add_filter( 'option_' . ElementorAPI::LIBRARY_OPTION_KEY, [$this, 'added_bd_template'] ); |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
/** |
| 700 |
* Added BetterDocs template with Elementor core templates list |
| 701 |
* |
| 702 |
* @param $response |
| 703 |
* @param $parsed_args |
| 704 |
* @param $url |
| 705 |
* |
| 706 |
* @return mixed |
| 707 |
* @since 2.3.5 |
| 708 |
*/ |
| 709 |
public function http_response_modify_for_bd_template( $response, $parsed_args, $url ) { |
| 710 |
if ( $url === \Elementor\TemplateLibrary\Source_Remote::API_TEMPLATES_URL ) { |
| 711 |
$templates_list = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 712 |
$bd_templates = $this->get_templates(); |
| 713 |
|
| 714 |
if ( ! empty( $bd_templates ) ) { |
| 715 |
$templates_list = array_merge( (array) $templates_list, (array) $bd_templates ); |
| 716 |
} |
| 717 |
|
| 718 |
$response['body'] = json_encode( $templates_list ); |
| 719 |
} |
| 720 |
|
| 721 |
return $response; |
| 722 |
} |
| 723 |
|
| 724 |
public function register_template_instance() { |
| 725 |
$this->elementor->templates_manager->register_source( TemplateSource::class ); |
| 726 |
} |
| 727 |
|
| 728 |
public function prepend_categories( $library_data ) { |
| 729 |
$categories = $this->template_categories(); |
| 730 |
if ( ! empty( $categories ) ) { |
| 731 |
$library_data['types_data']['block']['categories'] = array_merge( |
| 732 |
$categories, |
| 733 |
$library_data['types_data']['block']['categories'] |
| 734 |
); |
| 735 |
} |
| 736 |
return $library_data; |
| 737 |
} |
| 738 |
|
| 739 |
public function template_categories() { |
| 740 |
return [ |
| 741 |
'Single Docs', |
| 742 |
'Docs Archive' |
| 743 |
]; |
| 744 |
} |
| 745 |
|
| 746 |
/** |
| 747 |
* Added BetterDocs template with Elementor core templates list |
| 748 |
* |
| 749 |
* added_template |
| 750 |
* |
| 751 |
* @param $templates_list array elementor template list |
| 752 |
* |
| 753 |
* @return array |
| 754 |
* @since 2.0.7 |
| 755 |
* |
| 756 |
*/ |
| 757 |
public function added_bd_template( array $templates_list ) { |
| 758 |
$templates = $this->get_templates(); |
| 759 |
|
| 760 |
if ( ! empty( $templates ) ) { |
| 761 |
$templates_list['templates'] = array_merge( $templates_list['templates'], $templates ); |
| 762 |
} |
| 763 |
|
| 764 |
return $templates_list; |
| 765 |
} |
| 766 |
|
| 767 |
/** |
| 768 |
* get_templates |
| 769 |
* |
| 770 |
* Get Better docs template list and cache this list |
| 771 |
* |
| 772 |
* @return array|mixed |
| 773 |
* @since 2.0.0 |
| 774 |
*/ |
| 775 |
public function get_templates() { |
| 776 |
$_cache_key = 'betterdocs_template_library_' . betterdocs()->version; |
| 777 |
$templates = get_transient( $_cache_key ); |
| 778 |
|
| 779 |
if ( ! $templates ) { |
| 780 |
$source = new TemplateSource; |
| 781 |
$templates = $source->get_items(); |
| 782 |
|
| 783 |
if ( ! empty( $templates ) ) { |
| 784 |
$templates = array_map( function ( $template ) { |
| 785 |
$template['id'] = $template['template_id']; |
| 786 |
$template['tmpl_created'] = $template['date']; |
| 787 |
$template['tags'] = json_encode( $template['tags'] ); |
| 788 |
$template['is_pro'] = $template['isPro']; |
| 789 |
$template['access_level'] = $template['accessLevel']; |
| 790 |
$template['popularity_index'] = $template['popularityIndex']; |
| 791 |
$template['trend_index'] = $template['trendIndex']; |
| 792 |
$template['has_page_settings'] = $template['hasPageSettings']; |
| 793 |
|
| 794 |
return $template; |
| 795 |
}, $templates ); |
| 796 |
|
| 797 |
set_transient( $_cache_key, $templates, WEEK_IN_SECONDS ); |
| 798 |
} else { |
| 799 |
$templates = []; |
| 800 |
} |
| 801 |
} |
| 802 |
|
| 803 |
return $templates; |
| 804 |
} |
| 805 |
|
| 806 |
public function modified_ajax_action( $ajax ) { |
| 807 |
if ( ! isset( $_REQUEST['actions'] ) ) { |
| 808 |
return; |
| 809 |
} |
| 810 |
|
| 811 |
$actions = json_decode( stripslashes( $_REQUEST['actions'] ), true ); |
| 812 |
$data = false; |
| 813 |
|
| 814 |
foreach ( $actions as $id => $action_data ) { |
| 815 |
if ( ! isset( $action_data['get_template_data'] ) ) { |
| 816 |
$data = $action_data; |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
if ( ! $data ) { |
| 821 |
return; |
| 822 |
} |
| 823 |
|
| 824 |
if ( ! isset( $data['data'] ) ) { |
| 825 |
return; |
| 826 |
} |
| 827 |
|
| 828 |
$data = $data['data']; |
| 829 |
|
| 830 |
if ( empty( $data['template_id'] ) ) { |
| 831 |
return; |
| 832 |
} |
| 833 |
|
| 834 |
if ( false === strpos( $data['template_id'], 'betterdocs_' ) ) { |
| 835 |
return; |
| 836 |
} |
| 837 |
$ajax->register_ajax_action( 'get_template_data', [$this, 'get_template_data'] ); |
| 838 |
} |
| 839 |
|
| 840 |
public function get_template_data( $args ) { |
| 841 |
$source = new TemplateSource; |
| 842 |
return $source->get_data( $args ); |
| 843 |
} |
| 844 |
} |
| 845 |
|