PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.2
4.9.2 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 All 200 releases
← All changes | includes/Editors/Editor.php +92 -71 3.5.04.9.2 View file →
@@ -2,9 +2,9 @@
2 2
3 3 namespace WPDeveloper\BetterDocs\Editors;
4 4
5 5 if ( ! defined( 'ABSPATH' ) ) {
6 - exit; // Exit if accessed directly
6 + exit; // Exit if accessed directly
7 7 }
8 8
9 9 use Exception;
10 10 use WPDeveloper\BetterDocs\Utils\Base;
@@ -11,93 +11,114 @@
11 11 use WPDeveloper\BetterDocs\Utils\Enqueue;
12 12 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
13 13
14 14 class Editor extends Base {
15 - /**
16 - * Container
17 - * @var Container
18 - */
19 - private $container;
15 + /**
16 + * Container
17 + * @var Container
18 + */
19 + private $container;
20 20
21 - /**
22 - * List of editors we support. i.e: Elementor, Block Editor (WordPress Default)
23 - * @var array
24 - */
25 - private $editors = [];
21 + /**
22 + * List of editors we support. i.e: Elementor, Block Editor (WordPress Default)
23 + * @var array
24 + */
25 + private $editors = [];
26 26
27 - /**
28 - * Assets Manager
29 - * @var Enqueue
30 - */
31 - private $assets = [];
27 + /**
28 + * Assets Manager
29 + * @var Enqueue
30 + */
31 + private $assets = [];
32 32
33 - public function __construct( Container $container, $editors = [] ) {
34 - $this->container = $container;
35 - $this->editors = $editors;
36 - $this->assets = $this->container->get( Enqueue::class );
33 + public function __construct( Container $container, $editors = [] ) {
34 + $this->container = $container;
35 + $this->editors = $editors;
36 + $this->assets = $this->container->get( Enqueue::class );
37 37
38 - // add_action( 'admin_enqueue_scripts', [$this, 'admin_enqueue'] );
39 - // add_action( 'wp_enqueue_scripts', [$this, 'public_enqueue'] );
40 - }
38 + // add_action( 'admin_enqueue_scripts', [$this, 'admin_enqueue'] );
39 + // add_action( 'wp_enqueue_scripts', [$this, 'public_enqueue'] );
41 40
42 - public function admin_enqueue( $hook ) {
43 - $this->register_vendor_assets();
44 - }
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 + }
45 44
46 - public function public_enqueue() {
47 - $this->register_vendor_assets();
48 - }
45 + public function admin_enqueue( $hook ) {
46 + $this->register_vendor_assets();
47 + }
49 48
50 - public function register_vendor_assets() {
51 - $this->assets->register( 'betterdocs-fontawesome', 'vendor/css/font-awesome5.css' );
52 - }
49 + public function public_enqueue() {
50 + $this->register_vendor_assets();
51 + }
53 52
54 - public function init() {
55 - if ( empty( $this->editors ) ) {
56 - return;
57 - }
53 + public function register_vendor_assets() {
54 + $this->assets->register( 'betterdocs-fontawesome', 'vendor/css/font-awesome5.css' );
55 + }
58 56
59 - foreach ( $this->editors as $editor ) {
60 - $this->container->get( $editor )->init();
61 - }
62 - }
57 + public function init() {
58 + if ( empty( $this->editors ) ) {
59 + return;
60 + }
63 61
64 - public function admin_init() {
65 - if ( empty( $this->editors ) ) {
66 - return;
67 - }
62 + foreach ( $this->editors as $editor ) {
63 + $this->container->get( $editor )->init();
64 + }
65 + }
68 66
69 - foreach ( $this->editors as $editor ) {
70 - $_editor = $this->container->get( $editor );
71 - if ( method_exists( $_editor, 'admin_init' ) ) {
72 - $_editor->admin_init();
73 - }
74 - }
75 - }
67 + public function admin_init() {
68 + if ( empty( $this->editors ) ) {
69 + return;
70 + }
76 71
77 - public function get( $editor_id = 'elementor' ) {
78 - if ( empty( $this->editors[$editor_id] ) ) {
79 - throw new Exception( sprintf( __( 'Editor: %s not exists.', 'betterdocs' ), $editor_id ) );
80 - }
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 + }
81 79
82 - return ( $this->container->get( $this->editors[$editor_id] ) );
83 - }
80 + public function get( $editor_id = 'elementor' ) {
81 + if ( empty( $this->editors[ $editor_id ] ) ) {
82 + // Translators: %s is the editor ID that does not exist.
83 + throw new Exception( esc_textarea( sprintf( __( 'Editor: %s does not exist.', 'betterdocs' ), $editor_id ) ) ); //to escape anything into strings
84 + }
84 85
85 - public function get_post_count( $term_count, $term_id, $nested_subcategory = false ) {
86 - if ( $nested_subcategory == false ) {
87 - return $term_count;
88 - }
86 + return ( $this->container->get( $this->editors[ $editor_id ] ) );
87 + }
89 88
90 - $taxonomy = 'doc_category';
91 - $args = [ 'child_of' => $term_id ];
92 89
93 - $tax_terms = get_terms( $taxonomy, $args );
90 + public function get_post_count( $term_count, $term_id, $nested_subcategory = false ) {
91 + if ( $nested_subcategory == false ) {
92 + return $term_count;
93 + }
94 94
95 - if ( $tax_terms ) {
96 - $term_count = array_reduce( $tax_terms, function( $carry, $term ){
97 - return $carry + $term->count;
98 - }, $term_count );
99 - }
95 + $taxonomy = 'doc_category';
96 + $args = [
97 + 'taxonomy' => $taxonomy,
98 + 'child_of' => $term_id,
99 + ];
100 100
101 - return $term_count;
102 - }
101 + $tax_terms = get_terms( $args );
102 +
103 + if ( $tax_terms ) {
104 + $term_count = array_reduce(
105 + $tax_terms,
106 + function ( $carry, $term ) {
107 + return $carry + $term->count;
108 + },
109 + $term_count
110 + );
111 + }
112 +
113 + return $term_count;
114 + }
115 +
116 + public function replace_all_parts_betterdocs_urls( $data ) {
117 + if ( isset( $data['type'] ) && $data['type'] == 'docs' ) {
118 + $data['placeholderUrl'] = 'https://demo.betterdocs.co/wp-content/uploads/2024/09/Single-doc.svg';
119 + } elseif ( isset( $data['type'] ) && $data['type'] == 'doc-archive' ) {
120 + $data['placeholderUrl'] = 'https://demo.betterdocs.co/wp-content/uploads/2024/09/Docs-Archive.svg';
121 + }
122 + return $data;
123 + }
103 124 }