PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.1
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Editors / Editor.php

Editor.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.8.1, at includes/Editors/Editor.php

116 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Editors;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly
7 }
8
9 use Exception;
10 use WPDeveloper\BetterDocs\Utils\Base;
11 use WPDeveloper\BetterDocs\Utils\Enqueue;
12 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
13
14 class Editor extends Base {
15 /**
16 * Container
17 * @var Container
18 */
19 private $container;
20
21 /**
22 * List of editors we support. i.e: Elementor, Block Editor (WordPress Default)
23 * @var array
24 */
25 private $editors = [];
26
27 /**
28 * Assets Manager
29 * @var Enqueue
30 */
31 private $assets = [];
32
33 public function __construct( Container $container, $editors = [] ) {
34 $this->container = $container;
35 $this->editors = $editors;
36 $this->assets = $this->container->get( Enqueue::class );
37
38 // add_action( 'admin_enqueue_scripts', [$this, 'admin_enqueue'] );
39 // add_action( 'wp_enqueue_scripts', [$this, 'public_enqueue'] );
40
41 //Add placeholder image for elementor theme builder (All Parts) Tab
42 add_filter('elementor-pro/site-editor/data/template', [$this, 'replace_all_parts_betterdocs_urls'], 10, 1);
43 }
44
45 public function admin_enqueue( $hook ) {
46 $this->register_vendor_assets();
47 }
48
49 public function public_enqueue() {
50 $this->register_vendor_assets();
51 }
52
53 public function register_vendor_assets() {
54 $this->assets->register( 'betterdocs-fontawesome', 'vendor/css/font-awesome5.css' );
55 }
56
57 public function init() {
58 if ( empty( $this->editors ) ) {
59 return;
60 }
61
62 foreach ( $this->editors as $editor ) {
63 $this->container->get( $editor )->init();
64 }
65 }
66
67 public function admin_init() {
68 if ( empty( $this->editors ) ) {
69 return;
70 }
71
72 foreach ( $this->editors as $editor ) {
73 $_editor = $this->container->get( $editor );
74 if ( method_exists( $_editor, 'admin_init' ) ) {
75 $_editor->admin_init();
76 }
77 }
78 }
79
80 public function get( $editor_id = 'elementor' ) {
81 if ( empty( $this->editors[$editor_id] ) ) {
82 throw new Exception( sprintf( __( 'Editor: %s not exists.', 'betterdocs' ), $editor_id ) );
83 }
84
85 return ( $this->container->get( $this->editors[$editor_id] ) );
86 }
87
88 public function get_post_count( $term_count, $term_id, $nested_subcategory = false ) {
89 if ( $nested_subcategory == false ) {
90 return $term_count;
91 }
92
93 $taxonomy = 'doc_category';
94 $args = [ 'child_of' => $term_id ];
95
96 $tax_terms = get_terms( $taxonomy, $args );
97
98 if ( $tax_terms ) {
99 $term_count = array_reduce( $tax_terms, function( $carry, $term ){
100 return $carry + $term->count;
101 }, $term_count );
102 }
103
104 return $term_count;
105 }
106
107 public function replace_all_parts_betterdocs_urls( $data ) {
108 if(isset( $data['type'] ) && $data['type'] == 'docs' ){
109 $data['placeholderUrl'] = 'https://demo.betterdocs.co/wp-content/uploads/2024/09/Single-doc.svg';
110 } else if(isset( $data['type'] ) && $data['type'] == 'doc-archive' ){
111 $data['placeholderUrl'] = 'https://demo.betterdocs.co/wp-content/uploads/2024/09/Docs-Archive.svg';
112 }
113 return $data;
114 }
115 }
116