| @@ -26,355 +26,318 @@ | ||
| 26 | 26 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Feedback; |
| 27 | 27 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\FAQ; |
| 28 | 28 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Reactions; |
| 29 | 29 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Navigation; |
| 30 | -use WPDeveloper\BetterDocs\Editors\Elementor\Widget\CodeSnippet; | |
| 31 | -use WPDeveloper\BetterDocs\Editors\Elementor\Widget\CodeSnippetTab; | |
| 32 | 30 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ArchiveList; |
| 33 | 31 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\PrintButton; |
| 34 | 32 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Breadcrumbs; |
| 35 | 33 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ReadingTime; |
| 36 | -use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ArticleSummary; | |
| 37 | 34 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\SearchForm; |
| 38 | 35 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\CategoryBox; |
| 39 | 36 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\CategoryGrid; |
| 40 | -use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\CategorySlateLayout; | |
| 41 | 37 | use WPDeveloper\BetterDocs\Editors\Elementor\Conditions\ArchiveCondition; |
| 42 | 38 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Tags; |
| 39 | +// use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\BetterdocsEncyclopedia; | |
| 43 | 40 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\CategoryArchiveHeader; |
| 44 | 41 | |
| 45 | 42 | class Elementor extends BaseEditor { |
| 46 | - protected $is_elementor_active = false; | |
| 47 | - protected $is_elementor_pro_active = false; | |
| 48 | - protected static $is_templates_added = false; | |
| 43 | + protected $is_elementor_active = false; | |
| 44 | + protected $is_elementor_pro_active = false; | |
| 45 | + protected static $is_templates_added = false; | |
| 49 | 46 | |
| 50 | - /** | |
| 51 | - * Elementor plugin class | |
| 52 | - * @var ElementorPlugin | |
| 53 | - */ | |
| 54 | - protected $elementor; | |
| 47 | + /** | |
| 48 | + * Elementor plugin class | |
| 49 | + * @var ElementorPlugin | |
| 50 | + */ | |
| 51 | + protected $elementor; | |
| 55 | 52 | |
| 56 | - /** | |
| 57 | - * Elementor Helper class | |
| 58 | - * @var Helper | |
| 59 | - */ | |
| 60 | - protected $helper; | |
| 53 | + /** | |
| 54 | + * Elementor Helper class | |
| 55 | + * @var Helper | |
| 56 | + */ | |
| 57 | + protected $helper; | |
| 61 | 58 | |
| 62 | - public function __construct( Settings $settings, Enqueue $enqueue, Helper $helper ) { | |
| 63 | - parent::__construct( $settings, $enqueue ); | |
| 59 | + public function __construct( Settings $settings, Enqueue $enqueue, Helper $helper ) { | |
| 60 | + parent::__construct( $settings, $enqueue ); | |
| 64 | 61 | |
| 65 | - $this->helper = $helper; | |
| 66 | - $this->is_elementor_active = betterdocs()->helper->is_plugin_active( 'elementor/elementor.php' ); | |
| 67 | - $this->is_elementor_pro_active = betterdocs()->helper->is_plugin_active( 'elementor-pro/elementor-pro.php' ); | |
| 62 | + $this->helper = $helper; | |
| 63 | + $this->is_elementor_active = betterdocs()->helper->is_plugin_active( 'elementor/elementor.php' ); | |
| 64 | + $this->is_elementor_pro_active = betterdocs()->helper->is_plugin_active( 'elementor-pro/elementor-pro.php' ); | |
| 68 | 65 | |
| 69 | - if ( ! $this->is_elementor_active || ! class_exists( ElementorPlugin::class ) ) { | |
| 70 | - return; | |
| 71 | - } | |
| 66 | + if ( ! $this->is_elementor_active || ! class_exists( ElementorPlugin::class ) ) { | |
| 67 | + return; | |
| 68 | + } | |
| 72 | 69 | |
| 73 | - $this->elementor = ElementorPlugin::instance(); | |
| 74 | - } | |
| 70 | + $this->elementor = ElementorPlugin::instance(); | |
| 71 | + } | |
| 75 | 72 | |
| 76 | - public function init() { | |
| 77 | - if ( ! $this->is_elementor_active || $this->elementor == null ) { | |
| 78 | - return; | |
| 79 | - } | |
| 73 | + public function init() { | |
| 74 | + if ( ! $this->is_elementor_active || $this->elementor == null ) { | |
| 75 | + return; | |
| 76 | + } | |
| 80 | 77 | |
| 81 | - add_action( 'wp_enqueue_scripts', [$this, 'enqueue_scripts'] ); | |
| 78 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); | |
| 82 | 79 | |
| 83 | - add_action( 'elementor/elements/categories_registered', [$this, 'register_widget_category'] ); | |
| 84 | - add_action( 'elementor/widgets/register', [$this, 'register_basic_widgets'] ); | |
| 80 | + add_action( 'elementor/elements/categories_registered', [ $this, 'register_widget_category' ] ); | |
| 81 | + add_action( 'elementor/widgets/register', [ $this, 'register_basic_widgets' ] ); | |
| 85 | 82 | |
| 86 | - add_action( 'elementor/editor/before_enqueue_scripts', [$this, 'editor_enqueue_scripts'] ); | |
| 87 | - add_filter( 'elementor/editor/localize_settings', [$this, 'promote_pro_elements'] ); | |
| 83 | + add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_enqueue_scripts' ] ); | |
| 84 | + add_filter( 'elementor/editor/localize_settings', [ $this, 'promote_pro_elements' ] ); | |
| 88 | 85 | |
| 89 | - add_filter( 'elementor/theme/need_override_location', [$this, 'override_location'], 10, 2 ); | |
| 90 | - add_action( 'betterdocs/elementor/widgets/query', [$this, 'betterdocs_query'], 10, 2 ); | |
| 91 | - add_filter( 'betterdocs_base_terms_args', [$this, 'handle_editor_mode_terms_args'], 10, 1 ); | |
| 86 | + add_filter( 'elementor/theme/need_override_location', [ $this, 'override_location' ], 10, 2 ); | |
| 87 | + add_action( 'betterdocs/elementor/widgets/query', [ $this, 'betterdocs_query' ], 10, 2 ); | |
| 92 | 88 | |
| 93 | - if ( $this->is_elementor_pro_active ) { | |
| 94 | - add_action( 'elementor/dynamic_tags/register', [$this, 'register_basic_tags'] ); | |
| 95 | - add_action( 'elementor/widgets/register', [$this, 'register_theme_builder_widgets'] ); | |
| 96 | - add_action( 'elementor/theme/register_conditions', [$this, 'register_conditions'] ); | |
| 89 | + if ( $this->is_elementor_pro_active ) { | |
| 90 | + add_action( 'elementor/dynamic_tags/register', [ $this, 'register_basic_tags' ] ); | |
| 91 | + add_action( 'elementor/widgets/register', [ $this, 'register_theme_builder_widgets' ] ); | |
| 92 | + add_action( 'elementor/theme/register_conditions', [ $this, 'register_conditions' ] ); | |
| 97 | 93 | |
| 98 | - //(Conflict Fix)Solves the issue with plugin - Sticky Header Effects for Elementor(Plugin) | |
| 99 | - if ( ! did_action( 'elementor/documents/register' ) ) { | |
| 100 | - add_action( 'elementor/documents/register', [$this, 'register_documents'] ); | |
| 101 | - } else { | |
| 102 | - $this->elementor->documents->register_document_type( 'docs', SingleDocs::get_class_full_name() ); | |
| 103 | - $this->elementor->documents->register_document_type( 'doc-archive', DocsArchive::get_class_full_name() ); | |
| 104 | - } | |
| 105 | - } | |
| 94 | + //(Conflict Fix)Solves the issue with plugin - Sticky Header Effects for Elementor(Plugin) | |
| 95 | + if ( ! did_action( 'elementor/documents/register' ) ) { | |
| 96 | + add_action( 'elementor/documents/register', [ $this, 'register_documents' ] ); | |
| 97 | + } else { | |
| 98 | + $this->elementor->documents->register_document_type( 'docs', SingleDocs::get_class_full_name() ); | |
| 99 | + $this->elementor->documents->register_document_type( 'doc-archive', DocsArchive::get_class_full_name() ); | |
| 100 | + } | |
| 101 | + } | |
| 106 | 102 | |
| 107 | - $this->betterdocs_init(); | |
| 108 | - } | |
| 103 | + $this->betterdocs_init(); | |
| 104 | + } | |
| 109 | 105 | |
| 110 | - public function editor_enqueue_scripts() { | |
| 111 | - betterdocs()->assets->enqueue( 'betterdocs-el-icon', 'elementor/css/betterdocs-el-icon.css' ); | |
| 112 | - } | |
| 106 | + public function editor_enqueue_scripts() { | |
| 107 | + betterdocs()->assets->enqueue( 'betterdocs-el-icon', 'elementor/css/betterdocs-el-icon.css' ); | |
| 108 | + } | |
| 113 | 109 | |
| 114 | - public function register_documents( $documents_manager ) { | |
| 115 | - $documents_manager->register_document_type( 'docs', SingleDocs::get_class_full_name() ); | |
| 116 | - $documents_manager->register_document_type( 'doc-archive', DocsArchive::get_class_full_name() ); | |
| 117 | - } | |
| 110 | + public function register_documents( $documents_manager ) { | |
| 111 | + $documents_manager->register_document_type( 'docs', SingleDocs::get_class_full_name() ); | |
| 112 | + $documents_manager->register_document_type( 'doc-archive', DocsArchive::get_class_full_name() ); | |
| 113 | + } | |
| 118 | 114 | |
| 119 | - public function override_location( $need_override_location, $location ) { | |
| 120 | - if ( is_singular( ['docs'] ) && 'single' === $location ) { | |
| 121 | - $need_override_location = true; | |
| 122 | - } | |
| 115 | + public function override_location( $need_override_location, $location ) { | |
| 116 | + if ( is_singular( [ 'docs' ] ) && 'single' === $location ) { | |
| 117 | + $need_override_location = true; | |
| 118 | + } | |
| 123 | 119 | |
| 124 | - return $need_override_location; | |
| 125 | - } | |
| 120 | + return $need_override_location; | |
| 121 | + } | |
| 126 | 122 | |
| 127 | - /** | |
| 128 | - * Query Controls | |
| 129 | - * | |
| 130 | - */ | |
| 131 | - public function betterdocs_query( $wb, $taxonomy ) { | |
| 132 | - $wb->start_controls_section( | |
| 133 | - 'eael_section_post__filters', | |
| 134 | - [ | |
| 135 | - 'label' => __( 'Query', 'betterdocs' ) | |
| 136 | - ] | |
| 137 | - ); | |
| 123 | + /** | |
| 124 | + * Query Controls | |
| 125 | + * | |
| 126 | + */ | |
| 127 | + public function betterdocs_query( $wb, $taxonomy ) { | |
| 128 | + $wb->start_controls_section( | |
| 129 | + 'eael_section_post__filters', | |
| 130 | + [ | |
| 131 | + 'label' => __( 'Query', 'betterdocs' ) | |
| 132 | + ] | |
| 133 | + ); | |
| 138 | 134 | |
| 139 | - $default_multiple_kb = $this->multiple_kb_status(); | |
| 135 | + $default_multiple_kb = $this->multiple_kb_status(); | |
| 140 | 136 | |
| 141 | - if ( $default_multiple_kb && $taxonomy != 'knowledge_base' ) { | |
| 142 | - $multiple_kb_terms = $this->get_kb_terms( true, false ); | |
| 143 | - $default_slug = count( $multiple_kb_terms ) > 0 ? array_keys( $multiple_kb_terms )[0] : ''; | |
| 137 | + if ( $default_multiple_kb && $taxonomy != 'knowledge_base' ) { | |
| 138 | + $multiple_kb_terms = $this->get_kb_terms( true, false ); | |
| 139 | + $default_slug = count( $multiple_kb_terms ) > 0 ? array_keys( $multiple_kb_terms )[0] : ''; | |
| 144 | 140 | |
| 145 | - $wb->add_control( | |
| 146 | - 'selected_knowledge_base', | |
| 147 | - [ | |
| 148 | - 'label' => __( 'Knowledge Bases', 'betterdocs' ), | |
| 149 | - 'label_block' => true, | |
| 150 | - 'type' => Controls_Manager::SELECT2, | |
| 151 | - 'options' => $multiple_kb_terms, | |
| 152 | - 'multiple' => false, | |
| 153 | - 'default' => '', | |
| 154 | - 'select2options' => [ | |
| 155 | - 'placeholder' => __( 'All Knowledge Base', 'betterdocs' ), | |
| 156 | - 'allowClear' => true | |
| 157 | - ] | |
| 158 | - ] | |
| 159 | - ); | |
| 160 | - } | |
| 141 | + $wb->add_control( | |
| 142 | + 'selected_knowledge_base', | |
| 143 | + [ | |
| 144 | + 'label' => __( 'Knowledge Bases', 'betterdocs' ), | |
| 145 | + 'label_block' => true, | |
| 146 | + 'type' => Controls_Manager::SELECT2, | |
| 147 | + 'options' => $multiple_kb_terms, | |
| 148 | + 'multiple' => false, | |
| 149 | + 'default' => '', | |
| 150 | + 'select2options' => [ | |
| 151 | + 'placeholder' => __( 'All Knowledge Base', 'betterdocs' ), | |
| 152 | + 'allowClear' => true | |
| 153 | + ] | |
| 154 | + ] | |
| 155 | + ); | |
| 156 | + } | |
| 161 | 157 | |
| 162 | - if ( $wb->get_name() === 'betterdocs-category-grid' ) { | |
| 163 | - $wb->add_control( | |
| 164 | - 'grid_query_heading', | |
| 165 | - [ | |
| 166 | - 'label' => __( 'Category Grid', 'betterdocs' ), | |
| 167 | - 'type' => Controls_Manager::HEADING | |
| 168 | - ] | |
| 169 | - ); | |
| 170 | - } | |
| 158 | + if ( $wb->get_name() === 'betterdocs-category-grid' ) { | |
| 159 | + $wb->add_control( | |
| 160 | + 'grid_query_heading', | |
| 161 | + [ | |
| 162 | + 'label' => __( 'Category Grid', 'betterdocs' ), | |
| 163 | + 'type' => Controls_Manager::HEADING | |
| 164 | + ] | |
| 165 | + ); | |
| 166 | + } | |
| 171 | 167 | |
| 172 | - $wb->add_control( | |
| 173 | - 'include', | |
| 174 | - [ | |
| 175 | - 'label' => __( 'Include', 'betterdocs' ), | |
| 176 | - 'label_block' => true, | |
| 177 | - 'type' => Controls_Manager::SELECT2, | |
| 178 | - 'options' => $this->helper->get_terms( $taxonomy, 'term_id' ), | |
| 179 | - 'multiple' => true, | |
| 180 | - 'default' => [] | |
| 181 | - ] | |
| 182 | - ); | |
| 168 | + $wb->add_control( | |
| 169 | + 'include', | |
| 170 | + [ | |
| 171 | + 'label' => __( 'Include', 'betterdocs' ), | |
| 172 | + 'label_block' => true, | |
| 173 | + 'type' => Controls_Manager::SELECT2, | |
| 174 | + 'options' => $this->helper->get_terms( $taxonomy, 'term_id' ), | |
| 175 | + 'multiple' => true, | |
| 176 | + 'default' => [] | |
| 177 | + ] | |
| 178 | + ); | |
| 183 | 179 | |
| 184 | - $wb->add_control( | |
| 185 | - 'exclude', | |
| 186 | - [ | |
| 187 | - 'label' => __( 'Exclude', 'betterdocs' ), | |
| 188 | - 'type' => Controls_Manager::SELECT2, | |
| 189 | - 'options' => $this->helper->get_terms( $taxonomy, 'term_id' ), | |
| 190 | - 'label_block' => true, | |
| 191 | - 'post_type' => '', | |
| 192 | - 'multiple' => true | |
| 193 | - ] | |
| 194 | - ); | |
| 180 | + $wb->add_control( | |
| 181 | + 'exclude', | |
| 182 | + [ | |
| 183 | + 'label' => __( 'Exclude', 'betterdocs' ), | |
| 184 | + 'type' => Controls_Manager::SELECT2, | |
| 185 | + 'options' => $this->helper->get_terms( $taxonomy, 'term_id' ), | |
| 186 | + 'label_block' => true, | |
| 187 | + 'post_type' => '', | |
| 188 | + 'multiple' => true | |
| 189 | + ] | |
| 190 | + ); | |
| 195 | 191 | |
| 196 | - if ( $wb->get_name() === 'betterdocs-category-grid' ) { | |
| 197 | - $wb->add_control( | |
| 198 | - 'grid_per_page', | |
| 199 | - [ | |
| 200 | - 'label' => __( 'Grid Per Page', 'betterdocs' ), | |
| 201 | - 'type' => Controls_Manager::NUMBER, | |
| 202 | - 'default' => '8' | |
| 203 | - ] | |
| 204 | - ); | |
| 205 | - } else if ( $wb->get_name() !== 'betterdocs-sidebar' ) { | |
| 206 | - $wb->add_control( | |
| 207 | - 'box_per_page', | |
| 208 | - [ | |
| 209 | - 'label' => $wb->get_name() == 'betterdocs-tab-view-list' | |
| 210 | - ? __( 'Tabs Per Page', 'betterdocs' ) | |
| 211 | - : __( 'Box Per Page', 'betterdocs' ), | |
| 212 | - 'type' => Controls_Manager::NUMBER, | |
| 213 | - 'default' => '8' | |
| 214 | - ] | |
| 215 | - ); | |
| 216 | - } | |
| 192 | + if ( $wb->get_name() === 'betterdocs-category-grid' ) { | |
| 193 | + $wb->add_control( | |
| 194 | + 'grid_per_page', | |
| 195 | + [ | |
| 196 | + 'label' => __( 'Grid Per Page', 'betterdocs' ), | |
| 197 | + 'type' => Controls_Manager::NUMBER, | |
| 198 | + 'default' => '8' | |
| 199 | + ] | |
| 200 | + ); | |
| 201 | + } elseif ( $wb->get_name() !== 'betterdocs-sidebar' ) { | |
| 202 | + $wb->add_control( | |
| 203 | + 'box_per_page', | |
| 204 | + [ | |
| 205 | + 'label' => $wb->get_name() == 'betterdocs-tab-view-list' ? __( 'Tabs Per Page', 'betterdocs' ) : __( 'Box Per Page', 'betterdocs' ), | |
| 206 | + 'type' => Controls_Manager::NUMBER, | |
| 207 | + 'default' => '8' | |
| 208 | + ] | |
| 209 | + ); | |
| 210 | + } | |
| 217 | 211 | |
| 218 | - $wb->add_control( | |
| 219 | - 'offset', | |
| 220 | - [ | |
| 221 | - 'label' => __( 'Offset', 'betterdocs' ), | |
| 222 | - 'type' => Controls_Manager::NUMBER, | |
| 223 | - 'default' => '0' | |
| 224 | - ] | |
| 225 | - ); | |
| 212 | + $wb->add_control( | |
| 213 | + 'offset', | |
| 214 | + [ | |
| 215 | + 'label' => __( 'Offset', 'betterdocs' ), | |
| 216 | + 'type' => Controls_Manager::NUMBER, | |
| 217 | + 'default' => '0' | |
| 218 | + ] | |
| 219 | + ); | |
| 226 | 220 | |
| 227 | - // difference between betterdocs-sidebar and betterdocs-category-grid is the default order | |
| 228 | - if ( $wb->get_name() === 'betterdocs-sidebar' ) { | |
| 229 | - $wb->add_control( | |
| 230 | - 'orderby', | |
| 231 | - [ | |
| 232 | - 'label' => __( 'Terms Order By', 'betterdocs' ), | |
| 233 | - 'type' => Controls_Manager::SELECT, | |
| 234 | - 'options' => [ | |
| 235 | - 'none' => __( 'No order', 'betterdocs' ), | |
| 236 | - 'name' => __( 'Name', 'betterdocs' ), | |
| 237 | - 'slug' => __( 'Slug', 'betterdocs' ), | |
| 238 | - 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 239 | - 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 240 | - 'id' => __( 'ID', 'betterdocs' ), | |
| 241 | - 'description' => __( 'Description', 'betterdocs' ), | |
| 242 | - 'parent' => __( 'Parent', 'betterdocs' ), | |
| 243 | - 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 244 | - ], | |
| 245 | - 'default' => $this->settings->get( 'terms_orderby', 'betterdocs_order' ) | |
| 246 | - ] | |
| 247 | - ); | |
| 221 | + // difference between betterdocs-sidebar and betterdocs-category-grid is the default order | |
| 222 | + if ( $wb->get_name() === 'betterdocs-sidebar' ) { | |
| 223 | + $wb->add_control( | |
| 224 | + 'orderby', | |
| 225 | + [ | |
| 226 | + 'label' => __( 'Order By', 'betterdocs' ), | |
| 227 | + 'type' => Controls_Manager::SELECT, | |
| 228 | + 'options' => [ | |
| 229 | + 'none' => __( 'No order', 'betterdocs' ), | |
| 230 | + 'name' => __( 'Name', 'betterdocs' ), | |
| 231 | + 'slug' => __( 'Slug', 'betterdocs' ), | |
| 232 | + 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 233 | + 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 234 | + 'id' => __( 'ID', 'betterdocs' ), | |
| 235 | + 'description' => __( 'Description', 'betterdocs' ), | |
| 236 | + 'parent' => __( 'Parent', 'betterdocs' ), | |
| 237 | + 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 238 | + ], | |
| 239 | + 'default' => $this->settings->get( 'terms_orderby', 'betterdocs_order' ) | |
| 240 | + ] | |
| 241 | + ); | |
| 248 | 242 | |
| 249 | - $wb->add_control( | |
| 250 | - 'order', | |
| 251 | - [ | |
| 252 | - 'label' => __( 'Terms Order', 'betterdocs' ), | |
| 253 | - 'type' => Controls_Manager::SELECT, | |
| 254 | - 'options' => [ | |
| 255 | - 'ASC' => 'Ascending', | |
| 256 | - 'DESC' => 'Descending' | |
| 257 | - ], | |
| 258 | - 'default' => $this->settings->get( 'terms_order', 'ASC' ), | |
| 259 | - 'condition' => [ | |
| 260 | - 'orderby!' => 'betterdocs_order' | |
| 261 | - ] | |
| 243 | + $wb->add_control( | |
| 244 | + 'order', | |
| 245 | + [ | |
| 246 | + 'label' => __( 'Order', 'betterdocs' ), | |
| 247 | + 'type' => Controls_Manager::SELECT, | |
| 248 | + 'options' => [ | |
| 249 | + 'ASC' => 'Ascending', | |
| 250 | + 'DESC' => 'Descending' | |
| 251 | + ], | |
| 252 | + 'default' => $this->settings->get( 'terms_order', 'ASC' ), | |
| 253 | + 'condition' => [ | |
| 254 | + 'orderby!' => 'betterdocs_order' | |
| 255 | + ] | |
| 262 | 256 | |
| 263 | - ] | |
| 264 | - ); | |
| 257 | + ] | |
| 258 | + ); | |
| 259 | + } else { | |
| 260 | + $wb->add_control( | |
| 261 | + 'orderby', | |
| 262 | + [ | |
| 263 | + 'label' => __( 'Order By', 'betterdocs' ), | |
| 264 | + 'type' => Controls_Manager::SELECT, | |
| 265 | + 'options' => [ | |
| 266 | + 'none' => __( 'No order', 'betterdocs' ), | |
| 267 | + 'name' => __( 'Name', 'betterdocs' ), | |
| 268 | + 'slug' => __( 'Slug', 'betterdocs' ), | |
| 269 | + 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 270 | + 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 271 | + 'id' => __( 'ID', 'betterdocs' ), | |
| 272 | + 'description' => __( 'Description', 'betterdocs' ), | |
| 273 | + 'parent' => __( 'Parent', 'betterdocs' ), | |
| 274 | + 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 275 | + ], | |
| 276 | + 'default' => 'name' | |
| 277 | + ] | |
| 278 | + ); | |
| 265 | 279 | |
| 266 | - $wb->add_control( | |
| 267 | - 'post_orderby', | |
| 268 | - [ | |
| 269 | - 'label' => __( 'Docs Order By', 'betterdocs' ), | |
| 270 | - 'type' => Controls_Manager::SELECT, | |
| 271 | - 'options' => $this->helper->orderby_options(), | |
| 272 | - 'default' => 'date' | |
| 273 | - ] | |
| 274 | - ); | |
| 280 | + $wb->add_control( | |
| 281 | + 'order', | |
| 282 | + [ | |
| 283 | + 'label' => __( 'Order', 'betterdocs' ), | |
| 284 | + 'type' => Controls_Manager::SELECT, | |
| 285 | + 'options' => [ | |
| 286 | + 'ASC' => 'Ascending', | |
| 287 | + 'DESC' => 'Descending' | |
| 288 | + ], | |
| 289 | + 'default' => 'asc', | |
| 290 | + 'condition' => [ | |
| 291 | + 'orderby!' => 'betterdocs_order' | |
| 292 | + ] | |
| 275 | 293 | |
| 276 | - $wb->add_control( | |
| 277 | - 'post_order', | |
| 278 | - [ | |
| 279 | - 'label' => __( 'Docs Order', 'betterdocs' ), | |
| 280 | - 'type' => Controls_Manager::SELECT, | |
| 281 | - 'options' => [ | |
| 282 | - 'asc' => 'Ascending', | |
| 283 | - 'desc' => 'Descending' | |
| 284 | - ], | |
| 285 | - 'default' => 'asc', | |
| 286 | - 'condition' => [ | |
| 287 | - 'post_orderby!' => 'betterdocs_order' | |
| 288 | - ] | |
| 289 | - ] | |
| 290 | - ); | |
| 291 | - } else { | |
| 292 | - $wb->add_control( | |
| 293 | - 'orderby', | |
| 294 | - [ | |
| 295 | - 'label' => __( 'Order By', 'betterdocs' ), | |
| 296 | - 'type' => Controls_Manager::SELECT, | |
| 297 | - 'options' => [ | |
| 298 | - 'none' => __( 'No order', 'betterdocs' ), | |
| 299 | - 'name' => __( 'Name', 'betterdocs' ), | |
| 300 | - 'slug' => __( 'Slug', 'betterdocs' ), | |
| 301 | - 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 302 | - 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 303 | - 'id' => __( 'ID', 'betterdocs' ), | |
| 304 | - 'description' => __( 'Description', 'betterdocs' ), | |
| 305 | - 'parent' => __( 'Parent', 'betterdocs' ), | |
| 306 | - 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 307 | - ], | |
| 308 | - 'default' => 'name' | |
| 309 | - ] | |
| 310 | - ); | |
| 294 | + ] | |
| 295 | + ); | |
| 296 | + } | |
| 311 | 297 | |
| 312 | - $wb->add_control( | |
| 313 | - 'order', | |
| 314 | - [ | |
| 315 | - 'label' => __( 'Order', 'betterdocs' ), | |
| 316 | - 'type' => Controls_Manager::SELECT, | |
| 317 | - 'options' => [ | |
| 318 | - 'ASC' => 'Ascending', | |
| 319 | - 'DESC' => 'Descending' | |
| 320 | - ], | |
| 321 | - 'default' => 'ASC', | |
| 322 | - 'condition' => [ | |
| 323 | - 'orderby!' => 'betterdocs_order' | |
| 324 | - ] | |
| 298 | + if ( $wb->get_name() === 'betterdocs-category-grid' ) { | |
| 299 | + $wb->add_control( | |
| 300 | + 'grid_posts_query_heading', | |
| 301 | + [ | |
| 302 | + 'label' => __( 'Grid List Posts', 'betterdocs' ), | |
| 303 | + 'type' => Controls_Manager::HEADING, | |
| 304 | + 'separator' => 'before' | |
| 305 | + ] | |
| 306 | + ); | |
| 325 | 307 | |
| 326 | - ] | |
| 327 | - ); | |
| 328 | - } | |
| 308 | + $wb->add_control( | |
| 309 | + 'post_per_page', | |
| 310 | + [ | |
| 311 | + 'label' => __( 'Post Per Page', 'betterdocs' ), | |
| 312 | + 'type' => Controls_Manager::NUMBER, | |
| 313 | + 'default' => '6' | |
| 314 | + ] | |
| 315 | + ); | |
| 329 | 316 | |
| 330 | - if ( $wb->get_name() === 'betterdocs-category-grid' || $wb->get_name() === 'betterdocs-category-slate-layout' ) { | |
| 331 | - $wb->add_control( | |
| 332 | - 'grid_posts_query_heading', | |
| 333 | - [ | |
| 334 | - 'label' => __( 'Grid List Posts', 'betterdocs' ), | |
| 335 | - 'type' => Controls_Manager::HEADING, | |
| 336 | - 'separator' => 'before' | |
| 337 | - ] | |
| 338 | - ); | |
| 317 | + $wb->add_control( | |
| 318 | + 'post_orderby', | |
| 319 | + [ | |
| 320 | + 'label' => __( 'Order By', 'betterdocs' ), | |
| 321 | + 'type' => Controls_Manager::SELECT, | |
| 322 | + 'options' => $this->helper->orderby_options(), | |
| 323 | + 'default' => 'date' | |
| 324 | + ] | |
| 325 | + ); | |
| 339 | 326 | |
| 340 | - $wb->add_control( | |
| 341 | - 'post_per_page', | |
| 342 | - [ | |
| 343 | - 'label' => __( 'Post Per Page', 'betterdocs' ), | |
| 344 | - 'type' => Controls_Manager::NUMBER, | |
| 345 | - 'default' => '6' | |
| 346 | - ] | |
| 347 | - ); | |
| 327 | + $wb->add_control( | |
| 328 | + 'post_order', | |
| 329 | + [ | |
| 330 | + 'label' => __( 'Order', 'betterdocs' ), | |
| 331 | + 'type' => Controls_Manager::SELECT, | |
| 332 | + 'options' => [ | |
| 333 | + 'asc' => 'Ascending', | |
| 334 | + 'desc' => 'Descending' | |
| 335 | + ], | |
| 336 | + 'default' => 'desc' | |
| 337 | + ] | |
| 338 | + ); | |
| 348 | 339 | |
| 349 | - $wb->add_control( | |
| 350 | - 'post_orderby', | |
| 351 | - [ | |
| 352 | - 'label' => __( 'Order By', 'betterdocs' ), | |
| 353 | - 'type' => Controls_Manager::SELECT, | |
| 354 | - 'options' => $this->helper->orderby_options(), | |
| 355 | - 'default' => 'betterdocs_order' | |
| 356 | - ] | |
| 357 | - ); | |
| 358 | - | |
| 359 | - $wb->add_control( | |
| 360 | - 'post_order', | |
| 361 | - [ | |
| 362 | - 'label' => __( 'Order', 'betterdocs' ), | |
| 363 | - 'type' => Controls_Manager::SELECT, | |
| 364 | - 'options' => [ | |
| 365 | - 'asc' => 'Ascending', | |
| 366 | - 'desc' => 'Descending' | |
| 367 | - ], | |
| 368 | - 'default' => 'asc', | |
| 369 | - 'condition' => [ | |
| 370 | - 'post_orderby!' => 'betterdocs_order' | |
| 371 | - ] | |
| 372 | - ] | |
| 373 | - ); | |
| 374 | - } | |
| 375 | - | |
| 376 | - if ( $wb->get_name() === 'betterdocs-category-grid' ) { | |
| 377 | 340 | $wb->add_control( |
| 378 | 341 | 'nested_subcategory', |
| 379 | 342 | [ |
| 380 | 343 | 'label' => __( 'Enable Nested Subcategory', 'betterdocs' ), |
| @@ -408,627 +371,531 @@ | ||
| 408 | 371 | 'nested_subcategory' => 'true' |
| 409 | 372 | ] |
| 410 | 373 | ] |
| 411 | 374 | ); |
| 375 | + } | |
| 412 | 376 | |
| 377 | + if ( $wb->get_name() === 'betterdocs-category-box' ) { | |
| 413 | 378 | $wb->add_control( |
| 414 | - 'lazy_load', | |
| 379 | + 'nested_subcategory', | |
| 415 | 380 | [ |
| 416 | - 'label' => __( 'Lazy Load Docs & Subcategories', 'betterdocs' ), | |
| 417 | - 'description' => __( 'Render only the active category upfront; fetch the rest on click. Recommended for large knowledge bases when this widget is used as a sidebar.', 'betterdocs' ), | |
| 381 | + 'label' => __( 'Nested Subcategory', 'betterdocs' ), | |
| 418 | 382 | 'type' => Controls_Manager::SWITCHER, |
| 419 | 383 | 'label_on' => __( 'Yes', 'betterdocs' ), |
| 420 | 384 | 'label_off' => __( 'No', 'betterdocs' ), |
| 421 | 385 | 'return_value' => 'true', |
| 422 | - 'default' => '' | |
| 386 | + 'default' => false | |
| 423 | 387 | ] |
| 424 | 388 | ); |
| 425 | 389 | } |
| 426 | 390 | |
| 427 | - if ( $wb->get_name() === 'betterdocs-category-box' ) { | |
| 428 | - $wb->add_control( | |
| 429 | - 'nested_subcategory', | |
| 430 | - [ | |
| 431 | - 'label' => __( 'Nested Subcategory', 'betterdocs' ), | |
| 432 | - 'type' => Controls_Manager::SWITCHER, | |
| 433 | - 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 434 | - 'label_off' => __( 'No', 'betterdocs' ), | |
| 435 | - 'return_value' => 'true', | |
| 436 | - 'default' => 'true', | |
| 437 | - ] | |
| 438 | - ); | |
| 391 | + if ( $wb->get_name() === 'betterdocs-sidebar' ) { | |
| 392 | + $wb->add_control( | |
| 393 | + 'nested_subcategory', | |
| 394 | + [ | |
| 395 | + 'label' => __( 'Nested Subcategory', 'betterdocs' ), | |
| 396 | + 'type' => Controls_Manager::SWITCHER, | |
| 397 | + 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 398 | + 'label_off' => __( 'No', 'betterdocs' ), | |
| 399 | + 'return_value' => 'true', | |
| 400 | + 'default' => ( $this->settings->get( 'archive_nested_subcategory' ) == 1 ) ? 'true' : '' | |
| 401 | + ] | |
| 402 | + ); | |
| 403 | + } | |
| 439 | 404 | |
| 405 | + if ( $wb->get_name() === 'betterdocs-tab-view-list' ) { | |
| 440 | 406 | $wb->add_control( |
| 441 | - 'show_dynamic_categories_in_doc_category_template', | |
| 442 | - [ | |
| 443 | - 'label' => __( 'Show Categories Dynamically', 'betterdocs' ), | |
| 444 | - 'type' => Controls_Manager::SWITCHER, | |
| 445 | - 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 446 | - 'label_off' => __( 'No', 'betterdocs' ), | |
| 447 | - 'return_value' => 'true', | |
| 448 | - 'default' => 'true', | |
| 449 | - ] | |
| 450 | - ); | |
| 407 | + 'tab_posts_query_heading', | |
| 408 | + [ | |
| 409 | + 'label' => __( 'Tab List Posts', 'betterdocs' ), | |
| 410 | + 'type' => Controls_Manager::HEADING, | |
| 411 | + 'separator' => 'before' | |
| 412 | + ] | |
| 413 | + ); | |
| 451 | 414 | |
| 452 | 415 | $wb->add_control( |
| 453 | - 'show_dynamic_categories_in_doc_category_template_description', | |
| 416 | + 'tab_box_per_tabs', | |
| 454 | 417 | [ |
| 455 | - 'type' => Controls_Manager::RAW_HTML, | |
| 456 | - 'raw' => __( "Note: This option is only applicable for BetterDocs Category Archive page. If enabled, this will show the Categories dynamically in your BetterDocs Category Archive page.", 'betterdocs' ), | |
| 457 | - 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info' | |
| 418 | + 'label' => __( 'Box Per Tabs', 'betterdocs' ), | |
| 419 | + 'type' => Controls_Manager::NUMBER, | |
| 420 | + 'default' => '10' | |
| 458 | 421 | ] |
| 459 | 422 | ); |
| 460 | - } | |
| 461 | 423 | |
| 462 | - if ( $wb->get_name() === 'betterdocs-sidebar' ) { | |
| 463 | - $wb->add_control( | |
| 464 | - 'nested_subcategory', | |
| 465 | - [ | |
| 466 | - 'label' => __( 'Nested Subcategory', 'betterdocs' ), | |
| 467 | - 'type' => Controls_Manager::SWITCHER, | |
| 468 | - 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 469 | - 'label_off' => __( 'No', 'betterdocs' ), | |
| 470 | - 'return_value' => 'true', | |
| 471 | - 'default' => ( $this->settings->get( 'archive_nested_subcategory' ) == 1 ) ? 'true' : '' | |
| 472 | - ] | |
| 473 | - ); | |
| 424 | + $wb->add_control( | |
| 425 | + 'post_per_tab', | |
| 426 | + [ | |
| 427 | + 'label' => __( 'Posts Per Tab', 'betterdocs' ), | |
| 428 | + 'type' => Controls_Manager::NUMBER, | |
| 429 | + 'default' => '10' | |
| 430 | + ] | |
| 431 | + ); | |
| 474 | 432 | |
| 475 | - $wb->add_control( | |
| 476 | - 'lazy_load', | |
| 477 | - [ | |
| 478 | - 'label' => __( 'Lazy Load Docs & Subcategories', 'betterdocs' ), | |
| 479 | - 'description' => __( 'Render only the active category upfront; fetch the rest on click (or on scroll for the Memphis sidebar layout).', 'betterdocs' ), | |
| 480 | - 'type' => Controls_Manager::SWITCHER, | |
| 481 | - 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 482 | - 'label_off' => __( 'No', 'betterdocs' ), | |
| 483 | - 'return_value' => 'true', | |
| 484 | - 'default' => ( $this->settings->get( 'archive_lazy_load_descendants' ) == 1 ) ? 'true' : '' | |
| 485 | - ] | |
| 486 | - ); | |
| 487 | - } | |
| 433 | + $wb->add_control( | |
| 434 | + 'tab_list_posts_orderby', | |
| 435 | + [ | |
| 436 | + 'label' => __( 'Posts Order By', 'betterdocs' ), | |
| 437 | + 'type' => Controls_Manager::SELECT, | |
| 438 | + 'options' => [ | |
| 439 | + 'name' => __( 'Name', 'betterdocs' ), | |
| 440 | + 'slug' => __( 'Slug', 'betterdocs' ), | |
| 441 | + 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 442 | + 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 443 | + 'id' => __( 'ID', 'betterdocs' ), | |
| 444 | + 'description' => __( 'Description', 'betterdocs' ), | |
| 445 | + 'parent' => __( 'Parent', 'betterdocs' ), | |
| 446 | + 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 447 | + ], | |
| 448 | + 'default' => 'name' | |
| 449 | + ] | |
| 450 | + ); | |
| 488 | 451 | |
| 489 | - if ( $wb->get_name() === 'betterdocs-tab-view-list' ) { | |
| 490 | - $wb->add_control( | |
| 491 | - 'tab_posts_query_heading', | |
| 492 | - [ | |
| 493 | - 'label' => __( 'Tab List Posts', 'betterdocs' ), | |
| 494 | - 'type' => Controls_Manager::HEADING, | |
| 495 | - 'separator' => 'before' | |
| 496 | - ] | |
| 497 | - ); | |
| 452 | + $wb->add_control( | |
| 453 | + 'tab_list_order', | |
| 454 | + [ | |
| 455 | + 'label' => __( 'Order', 'betterdocs' ), | |
| 456 | + 'type' => Controls_Manager::SELECT, | |
| 457 | + 'options' => [ | |
| 458 | + 'ASC' => 'Ascending', | |
| 459 | + 'DESC' => 'Descending' | |
| 460 | + ], | |
| 461 | + 'default' => 'ASC' | |
| 498 | 462 | |
| 499 | - $wb->add_control( | |
| 500 | - 'tab_box_per_tabs', | |
| 501 | - [ | |
| 502 | - 'label' => __( 'Box Per Tabs', 'betterdocs' ), | |
| 503 | - 'type' => Controls_Manager::NUMBER, | |
| 504 | - 'default' => '10' | |
| 505 | - ] | |
| 506 | - ); | |
| 463 | + ] | |
| 464 | + ); | |
| 507 | 465 | |
| 508 | - $wb->add_control( | |
| 509 | - 'post_per_tab', | |
| 510 | - [ | |
| 511 | - 'label' => __( 'Posts Per Tab', 'betterdocs' ), | |
| 512 | - 'type' => Controls_Manager::NUMBER, | |
| 513 | - 'default' => '10' | |
| 514 | - ] | |
| 515 | - ); | |
| 466 | + $wb->add_control( | |
| 467 | + 'nested_subcategory_tab_list', | |
| 468 | + [ | |
| 469 | + 'label' => __( 'Nested Subcategory', 'betterdocs' ), | |
| 470 | + 'type' => Controls_Manager::SWITCHER, | |
| 471 | + 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 472 | + 'label_off' => __( 'No', 'betterdocs' ), | |
| 473 | + 'return_value' => 'true', | |
| 474 | + 'default' => 'true' | |
| 475 | + ] | |
| 476 | + ); | |
| 516 | 477 | |
| 517 | - $wb->add_control( | |
| 518 | - 'tab_list_posts_orderby', | |
| 519 | - [ | |
| 520 | - 'label' => __( 'Posts Order By', 'betterdocs' ), | |
| 521 | - 'type' => Controls_Manager::SELECT, | |
| 522 | - 'options' => [ | |
| 523 | - 'name' => __( 'Name', 'betterdocs' ), | |
| 524 | - 'slug' => __( 'Slug', 'betterdocs' ), | |
| 525 | - 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 526 | - 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 527 | - 'id' => __( 'ID', 'betterdocs' ), | |
| 528 | - 'description' => __( 'Description', 'betterdocs' ), | |
| 529 | - 'parent' => __( 'Parent', 'betterdocs' ), | |
| 530 | - 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 531 | - ], | |
| 532 | - 'default' => 'name' | |
| 533 | - ] | |
| 534 | - ); | |
| 478 | + $wb->add_control( | |
| 479 | + 'nested_posts_per_page', | |
| 480 | + [ | |
| 481 | + 'label' => __( 'Posts Per Page', 'betterdocs' ), | |
| 482 | + 'type' => Controls_Manager::NUMBER, | |
| 483 | + 'default' => '-1', | |
| 484 | + 'condition' => [ | |
| 485 | + 'nested_subcategory_tab_list' => 'true' | |
| 486 | + ] | |
| 487 | + ] | |
| 488 | + ); | |
| 535 | 489 | |
| 536 | - $wb->add_control( | |
| 537 | - 'tab_list_order', | |
| 538 | - [ | |
| 539 | - 'label' => __( 'Order', 'betterdocs' ), | |
| 540 | - 'type' => Controls_Manager::SELECT, | |
| 541 | - 'options' => [ | |
| 542 | - 'ASC' => 'Ascending', | |
| 543 | - 'DESC' => 'Descending' | |
| 544 | - ], | |
| 545 | - 'default' => 'ASC' | |
| 490 | + $wb->add_control( | |
| 491 | + 'nested_sub_cat_order', | |
| 492 | + [ | |
| 493 | + 'label' => __( 'Nested Subcategory Order', 'betterdocs' ), | |
| 494 | + 'type' => Controls_Manager::SELECT, | |
| 495 | + 'options' => [ | |
| 496 | + 'ASC' => 'Ascending', | |
| 497 | + 'DESC' => 'Descending' | |
| 498 | + ], | |
| 499 | + 'default' => 'ASC', | |
| 500 | + 'condition' => [ | |
| 501 | + 'nested_subcategory_tab_list' => 'true' | |
| 502 | + ] | |
| 503 | + ] | |
| 504 | + ); | |
| 546 | 505 | |
| 547 | - ] | |
| 548 | - ); | |
| 506 | + $wb->add_control( | |
| 507 | + 'nested_sub_cat_orderby', | |
| 508 | + [ | |
| 509 | + 'label' => __( 'Nested Subcategory Order By', 'betterdocs' ), | |
| 510 | + 'type' => Controls_Manager::SELECT, | |
| 511 | + 'options' => [ | |
| 512 | + 'none' => __( 'No order', 'betterdocs' ), | |
| 513 | + 'name' => __( 'Name', 'betterdocs' ), | |
| 514 | + 'slug' => __( 'Slug', 'betterdocs' ), | |
| 515 | + 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 516 | + 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 517 | + 'id' => __( 'ID', 'betterdocs' ), | |
| 518 | + 'description' => __( 'Description', 'betterdocs' ), | |
| 519 | + 'parent' => __( 'Parent', 'betterdocs' ), | |
| 520 | + 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 521 | + ], | |
| 522 | + 'default' => 'name', | |
| 523 | + 'condition' => [ | |
| 524 | + 'nested_subcategory_tab_list' => 'true' | |
| 525 | + ] | |
| 526 | + ] | |
| 527 | + ); | |
| 528 | + } | |
| 549 | 529 | |
| 550 | - $wb->add_control( | |
| 551 | - 'nested_subcategory_tab_list', | |
| 552 | - [ | |
| 553 | - 'label' => __( 'Nested Subcategory', 'betterdocs' ), | |
| 554 | - 'type' => Controls_Manager::SWITCHER, | |
| 555 | - 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 556 | - 'label_off' => __( 'No', 'betterdocs' ), | |
| 557 | - 'return_value' => 'true', | |
| 558 | - 'default' => 'true' | |
| 559 | - ] | |
| 560 | - ); | |
| 530 | + $wb->end_controls_section(); | |
| 531 | + } | |
| 561 | 532 | |
| 562 | - $wb->add_control( | |
| 563 | - 'nested_posts_per_page', | |
| 564 | - [ | |
| 565 | - 'label' => __( 'Posts Per Page', 'betterdocs' ), | |
| 566 | - 'type' => Controls_Manager::NUMBER, | |
| 567 | - 'default' => '-1', | |
| 568 | - 'condition' => [ | |
| 569 | - 'nested_subcategory_tab_list' => 'true' | |
| 570 | - ] | |
| 571 | - ] | |
| 572 | - ); | |
| 533 | + public function multiple_kb_status() { | |
| 534 | + if ( $this->settings->get( 'multiple_kb' ) == 1 ) { | |
| 535 | + return 'true'; | |
| 536 | + } | |
| 573 | 537 | |
| 574 | - $wb->add_control( | |
| 575 | - 'nested_sub_cat_order', | |
| 576 | - [ | |
| 577 | - 'label' => __( 'Nested Subcategory Order', 'betterdocs' ), | |
| 578 | - 'type' => Controls_Manager::SELECT, | |
| 579 | - 'options' => [ | |
| 580 | - 'ASC' => 'Ascending', | |
| 581 | - 'DESC' => 'Descending' | |
| 582 | - ], | |
| 583 | - 'default' => 'ASC', | |
| 584 | - 'condition' => [ | |
| 585 | - 'nested_subcategory_tab_list' => 'true' | |
| 586 | - ] | |
| 587 | - ] | |
| 588 | - ); | |
| 538 | + return ''; | |
| 539 | + } | |
| 589 | 540 | |
| 590 | - $wb->add_control( | |
| 591 | - 'nested_sub_cat_orderby', | |
| 592 | - [ | |
| 593 | - 'label' => __( 'Nested Subcategory Order By', 'betterdocs' ), | |
| 594 | - 'type' => Controls_Manager::SELECT, | |
| 595 | - 'options' => [ | |
| 596 | - 'none' => __( 'No order', 'betterdocs' ), | |
| 597 | - 'name' => __( 'Name', 'betterdocs' ), | |
| 598 | - 'slug' => __( 'Slug', 'betterdocs' ), | |
| 599 | - 'term_group' => __( 'Term Group', 'betterdocs' ), | |
| 600 | - 'term_id' => __( 'Term ID', 'betterdocs' ), | |
| 601 | - 'id' => __( 'ID', 'betterdocs' ), | |
| 602 | - 'description' => __( 'Description', 'betterdocs' ), | |
| 603 | - 'parent' => __( 'Parent', 'betterdocs' ), | |
| 604 | - 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' ) | |
| 605 | - ], | |
| 606 | - 'default' => 'name', | |
| 607 | - 'condition' => [ | |
| 608 | - 'nested_subcategory_tab_list' => 'true' | |
| 609 | - ] | |
| 610 | - ] | |
| 611 | - ); | |
| 612 | - } | |
| 541 | + public function get_kb_terms( $prettify = false, $term_id = true ) { | |
| 542 | + $args = [ | |
| 543 | + 'taxonomy' => 'knowledge_base', | |
| 544 | + 'hide_empty' => true, | |
| 545 | + 'parent' => 0 | |
| 546 | + ]; | |
| 613 | 547 | |
| 614 | - $wb->end_controls_section(); | |
| 615 | - } | |
| 548 | + $terms = get_terms( $args ); | |
| 616 | 549 | |
| 617 | - public function multiple_kb_status() { | |
| 618 | - if ( $this->settings->get( 'multiple_kb' ) == 1 ) { | |
| 619 | - return 'true'; | |
| 620 | - } | |
| 550 | + if ( is_wp_error( $terms ) ) { | |
| 551 | + return []; | |
| 552 | + } | |
| 621 | 553 | |
| 622 | - return ''; | |
| 623 | - } | |
| 554 | + if ( $prettify ) { | |
| 555 | + $pretty_taxonomies = []; | |
| 624 | 556 | |
| 625 | - public function get_kb_terms( $prettify = false, $term_id = true ) { | |
| 626 | - // This list populates the widget "Knowledge Bases" selector — an admin-side | |
| 627 | - // config picker, not a front-end listing. It must show EVERY KB regardless of | |
| 628 | - // whether it currently has content or is access-restricted for the editing | |
| 629 | - // user's role. Previously it ran through terms_query()/get_terms(), so on a | |
| 630 | - // regular page the Pro access-control terms_clauses filter + hide_empty pruned | |
| 631 | - // the list to a subset, while the theme-builder context showed them all. | |
| 632 | - // hide_empty:false keeps empty KBs; suppress_filters:true signals AccessControl | |
| 633 | - // (get_terms_args) to skip its role-based terms_clauses filter, so the picker is | |
| 634 | - // consistent everywhere. | |
| 635 | - $terms = get_terms( [ | |
| 636 | - 'taxonomy' => 'knowledge_base', | |
| 637 | - 'hide_empty' => false, | |
| 638 | - 'parent' => 0, | |
| 639 | - 'orderby' => 'name', | |
| 640 | - 'suppress_filters' => true, | |
| 641 | - ] ); | |
| 557 | + foreach ( $terms as $term ) { | |
| 558 | + $pretty_taxonomies[ $term_id ? $term->term_id : $term->slug ] = $term->name; | |
| 559 | + } | |
| 642 | 560 | |
| 643 | - if ( is_wp_error( $terms ) ) { | |
| 644 | - return []; | |
| 645 | - } | |
| 561 | + return $pretty_taxonomies; | |
| 562 | + } | |
| 646 | 563 | |
| 647 | - if ( $prettify ) { | |
| 648 | - $pretty_taxonomies = []; | |
| 564 | + return $terms; | |
| 565 | + } | |
| 649 | 566 | |
| 650 | - foreach ( $terms as $term ) { | |
| 651 | - // Decode HTML entities (e.g. "&" → "&") so the select2 control | |
| 652 | - // shows the real KB name instead of the escaped entity. | |
| 653 | - $pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = wp_specialchars_decode( $term->name, ENT_QUOTES ); | |
| 654 | - } | |
| 567 | + public function register_basic_tags( $module ) { | |
| 568 | + $module->register( new TitleTag() ); | |
| 569 | + } | |
| 655 | 570 | |
| 656 | - return $pretty_taxonomies; | |
| 657 | - } | |
| 571 | + public function register_basic_widgets( $widgets_manager ) { | |
| 572 | + foreach ( $this->basic_widget_lists() as $value ) { | |
| 573 | + $widgets_manager->register( new $value() ); | |
| 574 | + } | |
| 575 | + } | |
| 658 | 576 | |
| 659 | - return $terms; | |
| 660 | - } | |
| 577 | + /** | |
| 578 | + * | |
| 579 | + * Mange all widget for single docs | |
| 580 | + * | |
| 581 | + * @return string[] | |
| 582 | + * @since 1.3.0 | |
| 583 | + */ | |
| 584 | + private function basic_widget_lists() { | |
| 585 | + $widget_arr = [ | |
| 586 | + 'betterdocs-elementor-search-form' => SearchForm::class, | |
| 587 | + 'betterdocs-elementor-category-grid' => CategoryGrid::class, | |
| 588 | + 'betterdocs-elementor-category-box' => CategoryBox::class, | |
| 589 | + 'betterdocs-faq-widget' => FAQ::class | |
| 590 | + // 'betterdocs-encyclopedia-widget' => BetterdocsEncyclopedia::class | |
| 591 | + ]; | |
| 661 | 592 | |
| 662 | - public function register_basic_tags( $module ) { | |
| 663 | - $module->register( new TitleTag ); | |
| 664 | - } | |
| 593 | + return $widget_arr; | |
| 594 | + } | |
| 665 | 595 | |
| 666 | - /** | |
| 667 | - * Handle editor mode for terms query args | |
| 668 | - * | |
| 669 | - * @param array $args Terms query arguments | |
| 670 | - * @return array Modified arguments | |
| 671 | - */ | |
| 672 | - public function handle_editor_mode_terms_args( $args ) { | |
| 673 | - // Only modify if we're in Elementor editor mode | |
| 674 | - if ( $this->elementor && $this->elementor->editor->is_edit_mode() ) { | |
| 675 | - // Show empty categories in editor mode for better preview | |
| 676 | - $args['hide_empty'] = false; | |
| 677 | - } | |
| 596 | + public function register_widget_category( $elements_manager ) { | |
| 597 | + $elements_manager->add_category( | |
| 598 | + 'betterdocs-elements', | |
| 599 | + [ | |
| 600 | + 'title' => __( 'BetterDocs', 'betterdocs' ), | |
| 601 | + 'icon' => 'font' | |
| 602 | + ], | |
| 603 | + 1 | |
| 604 | + ); | |
| 605 | + } | |
| 678 | 606 | |
| 679 | - return $args; | |
| 680 | - } | |
| 607 | + public function promote_pro_elements( $config ) { | |
| 608 | + if ( $this->is_pro_active ) { | |
| 609 | + return $config; | |
| 610 | + } | |
| 681 | 611 | |
| 682 | - public function register_basic_widgets( $widgets_manager ) { | |
| 683 | - foreach ( $this->basic_widget_lists() as $value ) { | |
| 684 | - $widgets_manager->register( new $value ); | |
| 685 | - } | |
| 686 | - } | |
| 612 | + $promotion_widgets = []; | |
| 687 | 613 | |
| 688 | - /** | |
| 689 | - * | |
| 690 | - * Mange all widget for single docs | |
| 691 | - * | |
| 692 | - * @return string[] | |
| 693 | - * @since 1.3.0 | |
| 694 | - */ | |
| 695 | - private function basic_widget_lists() { | |
| 696 | - $widget_arr = [ | |
| 697 | - 'betterdocs-elementor-search-form' => SearchForm::class, | |
| 698 | - 'betterdocs-elementor-category-grid' => CategoryGrid::class, | |
| 699 | - 'betterdocs-elementor-category-box' => CategoryBox::class, | |
| 700 | - 'betterdocs-elementor-category-slate' => CategorySlateLayout::class, | |
| 701 | - 'betterdocs-faq-widget' => FAQ::class, | |
| 702 | - 'betterdocs-code-snippet' => CodeSnippet::class, | |
| 703 | - 'betterdocs-code-snippet-tab' => CodeSnippetTab::class | |
| 704 | - ]; | |
| 614 | + if ( isset( $config['promotionWidgets'] ) ) { | |
| 615 | + $promotion_widgets = $config['promotionWidgets']; | |
| 616 | + } | |
| 705 | 617 | |
| 706 | - return $widget_arr; | |
| 707 | - } | |
| 618 | + $combine_array = array_merge( | |
| 619 | + $promotion_widgets, | |
| 620 | + [ | |
| 621 | + [ | |
| 622 | + 'name' => 'betterdocs-multiple-kb', | |
| 623 | + 'title' => __( 'BetterDocs Multiple KB', 'betterdocs' ), | |
| 624 | + 'icon' => 'betterdocs-icon-category-box', | |
| 625 | + 'categories' => '["docs-archive"]' | |
| 626 | + ] | |
| 627 | + ] | |
| 628 | + ); | |
| 708 | 629 | |
| 709 | - public function register_widget_category( $elements_manager ) { | |
| 710 | - $elements_manager->add_category( 'betterdocs-elements', [ | |
| 711 | - 'title' => __( 'BetterDocs', 'betterdocs' ), | |
| 712 | - 'icon' => 'font' | |
| 713 | - ], 1 ); | |
| 714 | - } | |
| 630 | + $config['promotionWidgets'] = $combine_array; | |
| 715 | 631 | |
| 716 | - public function promote_pro_elements( $config ) { | |
| 717 | - if ( $this->is_pro_active ) { | |
| 718 | - return $config; | |
| 719 | - } | |
| 632 | + return $config; | |
| 633 | + } | |
| 720 | 634 | |
| 721 | - $promotion_widgets = []; | |
| 635 | + public function is_templates() { | |
| 636 | + if ( $this->is_elementor_active && $this->is_elementor_pro_active ) { | |
| 637 | + $post_id = get_the_ID(); | |
| 638 | + if ( $this->elementor->editor->is_edit_mode() || ( | |
| 639 | + get_post_meta( $post_id, '_elementor_template_type', true ) | |
| 640 | + && $this->elementor->documents->get( $post_id )->is_built_with_elementor() | |
| 641 | + ) ) { | |
| 642 | + return true; | |
| 643 | + } | |
| 644 | + } | |
| 722 | 645 | |
| 723 | - if ( isset( $config['promotionWidgets'] ) ) { | |
| 724 | - $promotion_widgets = $config['promotionWidgets']; | |
| 725 | - } | |
| 646 | + return null; | |
| 647 | + } | |
| 726 | 648 | |
| 727 | - $combine_array = array_merge( $promotion_widgets, [ | |
| 728 | - [ | |
| 729 | - 'name' => 'betterdocs-multiple-kb', | |
| 730 | - 'title' => __( 'BetterDocs Multiple KB', 'betterdocs' ), | |
| 731 | - 'icon' => 'betterdocs-icon-category-box', | |
| 732 | - 'categories' => '["docs-archive"]' | |
| 733 | - ] | |
| 734 | - ] ); | |
| 649 | + public function enqueue_scripts() { | |
| 650 | + $assets = betterdocs()->assets; | |
| 735 | 651 | |
| 736 | - $config['promotionWidgets'] = $combine_array; | |
| 652 | + /** | |
| 653 | + * Widget's CSS | |
| 654 | + */ | |
| 655 | + $assets->register( 'betterdocs-el-category-grid', 'elementor/css/category-grid.css' ); | |
| 656 | + $assets->register( 'betterdocs-el-category-box', 'elementor/css/category-box.css' ); | |
| 657 | + $assets->register( 'betterdocs-el-articles-list', 'elementor/css/articles-list.css' ); | |
| 658 | + $assets->register( 'betterdocs-el-navigation', 'elementor/css/navigation.css' ); | |
| 737 | 659 | |
| 738 | - return $config; | |
| 739 | - } | |
| 660 | + /** | |
| 661 | + * Widget's JS | |
| 662 | + */ | |
| 663 | + $assets->register( 'betterdocs-el-category-grid', 'elementor/js/category-grid.js', [ 'jquery', 'betterdocs-category-toggler' ] ); | |
| 740 | 664 | |
| 741 | - public function is_templates() { | |
| 742 | - if ( $this->is_elementor_active && $this->is_elementor_pro_active ) { | |
| 743 | - $post_id = get_the_ID(); | |
| 744 | - if ( $this->elementor->editor->is_edit_mode() || ( | |
| 745 | - get_post_meta( $post_id, '_elementor_template_type', true ) | |
| 746 | - && $this->elementor->documents->get( $post_id )->is_built_with_elementor() | |
| 747 | - ) ) { | |
| 748 | - return true; | |
| 749 | - } | |
| 750 | - } | |
| 665 | + /** | |
| 666 | + * Localize This In Order To Know If This Block Is Arriving From Betterdocs Templates Or Not | |
| 667 | + */ | |
| 668 | + betterdocs()->assets->localize( | |
| 669 | + 'betterdocs-el-category-grid', | |
| 670 | + 'betterdocsCategoryGridConfig', | |
| 671 | + [ | |
| 672 | + 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false | |
| 673 | + ] | |
| 674 | + ); | |
| 751 | 675 | |
| 752 | - return null; | |
| 753 | - } | |
| 676 | + if ( betterdocs()->helper->is_el_templates() == true ) { | |
| 677 | + $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/css/betterdocs-el-edit.css' ); | |
| 754 | 678 | |
| 755 | - public function enqueue_scripts() { | |
| 756 | - $assets = betterdocs()->assets; | |
| 679 | + if ( ! $this->is_pro_active ) { | |
| 680 | + $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/js/editor.js', [ 'jquery' ] ); | |
| 681 | + } | |
| 682 | + } | |
| 757 | 683 | |
| 758 | - /** | |
| 759 | - * Widget's CSS | |
| 760 | - */ | |
| 761 | - $assets->register( 'betterdocs-el-category-grid', 'elementor/css/category-grid.css' ); | |
| 762 | - $assets->register( 'betterdocs-el-category-box', 'elementor/css/category-box.css' ); | |
| 763 | - $assets->register( 'betterdocs-el-articles-list', 'elementor/css/articles-list.css' ); | |
| 764 | - $assets->register( 'betterdocs-el-navigation', 'elementor/css/navigation.css' ); | |
| 765 | - $assets->register( 'betterdocs-code-snippet', 'public/css/code-snippet.css' ); | |
| 766 | - $assets->register( 'betterdocs-code-snippet-tab', 'public/css/code-snippet-tab.css' ); | |
| 684 | + do_action( 'betterdocs_elementor_enqueue_scripts', $this ); | |
| 685 | + } | |
| 767 | 686 | |
| 768 | - /** | |
| 769 | - * Widget's JS | |
| 770 | - */ | |
| 771 | - $assets->register( 'betterdocs-el-category-grid', 'elementor/js/category-grid.js', ['jquery', 'betterdocs-category-toggler'] ); | |
| 772 | - $assets->register( 'betterdocs-code-snippet', 'public/js/code-snippet.js', ['jquery'] ); | |
| 773 | - $assets->register( 'betterdocs-code-snippet-tab', 'public/js/code-snippet-tab.js', ['jquery'] ); | |
| 687 | + public function register_theme_builder_widgets( $widgets_manager ) { | |
| 688 | + foreach ( $this->builder_widget_list() as $value ) { | |
| 689 | + if ( class_exists( $value ) ) { | |
| 690 | + $widgets_manager->register( new $value() ); | |
| 691 | + } | |
| 692 | + } | |
| 693 | + } | |
| 774 | 694 | |
| 775 | - /** | |
| 776 | - * Localize This In Order To Know If This Block Is Arriving From Betterdocs Templates Or Not | |
| 777 | - */ | |
| 778 | - betterdocs()->assets->localize( 'betterdocs-el-category-grid', 'betterdocsCategoryGridConfig', [ | |
| 779 | - 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false | |
| 780 | - ] ); | |
| 695 | + /** | |
| 696 | + * Mange all widget for single docs | |
| 697 | + * | |
| 698 | + * @return array<string> | |
| 699 | + * @since 1.3.0 | |
| 700 | + */ | |
| 701 | + public function builder_widget_list() { | |
| 702 | + return apply_filters( | |
| 703 | + 'betterdocs_elementor_pro_widgets', | |
| 704 | + [ | |
| 705 | + 'betterdocs-elementor-toc' => ToC::class, | |
| 706 | + 'betterdocs-elementor-title' => Title::class, | |
| 707 | + 'betterdocs-elementor-sidebar' => Sidebar::class, | |
| 708 | + 'betterdocs-elementor-content' => Content::class, | |
| 709 | + 'betterdocs-elementor-doc-date' => DocDate::class, | |
| 710 | + 'betterdocs-elementor-doc-share' => DocShare::class, | |
| 711 | + 'betterdocs-elementor-feedback' => Feedback::class, | |
| 712 | + 'betterdocs-elementor-reactions' => Reactions::class, | |
| 713 | + 'betterdocs-elementor-navigation' => Navigation::class, | |
| 714 | + 'betterdocs-elementor-breadcrumbs' => Breadcrumbs::class, | |
| 715 | + 'betterdocs-elementor-category-archive-list' => ArchiveList::class, | |
| 716 | + 'betteredocs-elementor-reading-time' => ReadingTime::class, | |
| 717 | + 'betterdocs-print-button' => PrintButton::class, | |
| 718 | + 'betterdocs-elementor-doc-author' => DocAuthor::class, | |
| 719 | + 'betteredocs-elementor-doc-category-archive-header' => CategoryArchiveHeader::class, | |
| 720 | + 'betterdocs-elementor-tags' => Tags::class | |
| 721 | + ] | |
| 722 | + ); | |
| 723 | + } | |
| 781 | 724 | |
| 782 | - if ( betterdocs()->helper->is_el_templates() == true ) { | |
| 783 | - $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/css/betterdocs-el-edit.css' ); | |
| 725 | + /** | |
| 726 | + * @param \ElementorPro\Modules\ThemeBuilder\Classes\Conditions_Manager $conditions_manager | |
| 727 | + */ | |
| 728 | + public function register_conditions( $conditions_manager ) { | |
| 729 | + $betterdocs_condition = betterdocs()->container->get( ArchiveCondition::class ); | |
| 730 | + $conditions_manager->get_condition( 'general' )->register_sub_condition( $betterdocs_condition ); | |
| 731 | + } | |
| 784 | 732 | |
| 785 | - if ( ! $this->is_pro_active ) { | |
| 786 | - $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/js/editor.js', ['jquery'] ); | |
| 787 | - } | |
| 788 | - } | |
| 733 | + public function betterdocs_init() { | |
| 734 | + add_action( 'elementor/init', [ $this, 'register_template_instance' ], 20 ); | |
| 789 | 735 | |
| 790 | - do_action( 'betterdocs_elementor_enqueue_scripts', $this ); | |
| 791 | - } | |
| 736 | + static $is_done = false; | |
| 737 | + if ( defined( 'Elementor\Api::LIBRARY_OPTION_KEY' ) && ! $is_done ) { | |
| 738 | + $is_done = true; | |
| 739 | + add_filter( 'option_' . ElementorAPI::LIBRARY_OPTION_KEY, [ $this, 'prepend_categories' ] ); | |
| 740 | + } | |
| 792 | 741 | |
| 793 | - public function register_theme_builder_widgets( $widgets_manager ) { | |
| 794 | - foreach ( $this->builder_widget_list() as $value ) { | |
| 795 | - if ( class_exists( $value ) ) { | |
| 796 | - $widgets_manager->register( new $value ); | |
| 797 | - } | |
| 798 | - } | |
| 799 | - } | |
| 742 | + add_action( 'elementor/ajax/register_actions', [ $this, 'modified_ajax_action' ], 20 ); | |
| 800 | 743 | |
| 801 | - /** | |
| 802 | - * Mange all widget for single docs | |
| 803 | - * | |
| 804 | - * @return array<string> | |
| 805 | - * @since 1.3.0 | |
| 806 | - */ | |
| 807 | - public function builder_widget_list() { | |
| 808 | - return apply_filters( 'betterdocs_elementor_pro_widgets', [ | |
| 809 | - 'betterdocs-elementor-toc' => ToC::class, | |
| 810 | - 'betterdocs-elementor-title' => Title::class, | |
| 811 | - 'betterdocs-elementor-sidebar' => Sidebar::class, | |
| 812 | - 'betterdocs-elementor-content' => Content::class, | |
| 813 | - 'betterdocs-elementor-doc-date' => DocDate::class, | |
| 814 | - 'betterdocs-elementor-doc-share' => DocShare::class, | |
| 815 | - 'betterdocs-elementor-feedback' => Feedback::class, | |
| 816 | - 'betterdocs-elementor-reactions' => Reactions::class, | |
| 817 | - 'betterdocs-article-summary' => ArticleSummary::class, | |
| 818 | - 'betterdocs-elementor-navigation' => Navigation::class, | |
| 819 | - 'betterdocs-elementor-breadcrumbs' => Breadcrumbs::class, | |
| 820 | - 'betterdocs-elementor-category-archive-list' => ArchiveList::class, | |
| 821 | - 'betteredocs-elementor-reading-time' => ReadingTime::class, | |
| 822 | - 'betterdocs-print-button' => PrintButton::class, | |
| 823 | - 'betterdocs-elementor-doc-author' => DocAuthor::class, | |
| 824 | - 'betteredocs-elementor-doc-category-archive-header' => CategoryArchiveHeader::class, | |
| 825 | - 'betterdocs-elementor-tags' => Tags::class | |
| 826 | - ] ); | |
| 827 | - } | |
| 744 | + if ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.10.0', '>=' ) && ! self::$is_templates_added ) { | |
| 745 | + self::$is_templates_added = true; | |
| 746 | + add_filter( 'http_response', [ $this, 'http_response_modify_for_bd_template' ], 10, 3 ); | |
| 747 | + } elseif ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) && ! self::$is_templates_added ) { | |
| 748 | + self::$is_templates_added = true; | |
| 749 | + add_filter( 'option_' . ElementorAPI::LIBRARY_OPTION_KEY, [ $this, 'added_bd_template' ] ); | |
| 750 | + } | |
| 751 | + } | |
| 828 | 752 | |
| 829 | - /** | |
| 830 | - * @param \ElementorPro\Modules\ThemeBuilder\Classes\Conditions_Manager $conditions_manager | |
| 831 | - */ | |
| 832 | - public function register_conditions( $conditions_manager ) { | |
| 833 | - $betterdocs_condition = betterdocs()->container->get( ArchiveCondition::class ); | |
| 834 | - $conditions_manager->get_condition( 'general' )->register_sub_condition( $betterdocs_condition ); | |
| 835 | - } | |
| 753 | + /** | |
| 754 | + * Added BetterDocs template with Elementor core templates list | |
| 755 | + * | |
| 756 | + * @param $response | |
| 757 | + * @param $parsed_args | |
| 758 | + * @param $url | |
| 759 | + * | |
| 760 | + * @return mixed | |
| 761 | + * @since 2.3.5 | |
| 762 | + */ | |
| 763 | + public function http_response_modify_for_bd_template( $response, $parsed_args, $url ) { | |
| 764 | + if ( $url === \Elementor\TemplateLibrary\Source_Remote::API_TEMPLATES_URL ) { | |
| 765 | + $templates_list = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 766 | + $bd_templates = $this->get_templates(); | |
| 836 | 767 | |
| 837 | - public function betterdocs_init() { | |
| 838 | - add_action( 'elementor/init', [$this, 'register_template_instance'], 20 ); | |
| 768 | + if ( ! empty( $bd_templates ) ) { | |
| 769 | + $templates_list = array_merge( (array) $templates_list, (array) $bd_templates ); | |
| 770 | + } | |
| 839 | 771 | |
| 840 | - static $is_done = false; | |
| 841 | - if ( defined( 'Elementor\Api::LIBRARY_OPTION_KEY' ) && ! $is_done ) { | |
| 842 | - $is_done = true; | |
| 843 | - add_filter( 'option_' . ElementorAPI::LIBRARY_OPTION_KEY, [$this, 'prepend_categories'] ); | |
| 844 | - } | |
| 772 | + $response['body'] = json_encode( $templates_list ); | |
| 773 | + } | |
| 845 | 774 | |
| 846 | - add_action( 'elementor/ajax/register_actions', [$this, 'modified_ajax_action'], 20 ); | |
| 775 | + return $response; | |
| 776 | + } | |
| 847 | 777 | |
| 848 | - if ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.10.0', '>=' ) && ! self::$is_templates_added ) { | |
| 849 | - self::$is_templates_added = true; | |
| 850 | - add_filter( 'http_response', [$this, 'http_response_modify_for_bd_template'], 10, 3 ); | |
| 851 | - } elseif ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) && ! self::$is_templates_added ) { | |
| 852 | - self::$is_templates_added = true; | |
| 853 | - add_filter( 'option_' . ElementorAPI::LIBRARY_OPTION_KEY, [$this, 'added_bd_template'] ); | |
| 854 | - } | |
| 855 | - } | |
| 778 | + public function register_template_instance() { | |
| 779 | + $this->elementor->templates_manager->register_source( TemplateSource::class ); | |
| 780 | + } | |
| 856 | 781 | |
| 857 | - /** | |
| 858 | - * Added BetterDocs template with Elementor core templates list | |
| 859 | - * | |
| 860 | - * @param $response | |
| 861 | - * @param $parsed_args | |
| 862 | - * @param $url | |
| 863 | - * | |
| 864 | - * @return mixed | |
| 865 | - * @since 2.3.5 | |
| 866 | - */ | |
| 867 | - public function http_response_modify_for_bd_template( $response, $parsed_args, $url ) { | |
| 868 | - if ( $url === \Elementor\TemplateLibrary\Source_Remote::API_TEMPLATES_URL ) { | |
| 869 | - $templates_list = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 870 | - $bd_templates = $this->get_templates(); | |
| 782 | + public function prepend_categories( $library_data ) { | |
| 783 | + $categories = $this->template_categories(); | |
| 784 | + if ( ! empty( $categories ) ) { | |
| 785 | + $library_data['types_data']['block']['categories'] = array_merge( | |
| 786 | + $categories, | |
| 787 | + $library_data['types_data']['block']['categories'] | |
| 788 | + ); | |
| 789 | + } | |
| 790 | + return $library_data; | |
| 791 | + } | |
| 871 | 792 | |
| 872 | - if ( ! empty( $bd_templates ) ) { | |
| 873 | - $templates_list = array_merge( (array) $templates_list, (array) $bd_templates ); | |
| 874 | - } | |
| 793 | + public function template_categories() { | |
| 794 | + return [ | |
| 795 | + 'Single Docs', | |
| 796 | + 'Docs Archive' | |
| 797 | + ]; | |
| 798 | + } | |
| 875 | 799 | |
| 876 | - $response['body'] = json_encode( $templates_list ); | |
| 877 | - } | |
| 800 | + /** | |
| 801 | + * Added BetterDocs template with Elementor core templates list | |
| 802 | + * | |
| 803 | + * added_template | |
| 804 | + * | |
| 805 | + * @param $templates_list array elementor template list | |
| 806 | + * | |
| 807 | + * @return array | |
| 808 | + * @since 2.0.7 | |
| 809 | + * | |
| 810 | + */ | |
| 811 | + public function added_bd_template( array $templates_list ) { | |
| 812 | + $templates = $this->get_templates(); | |
| 878 | 813 | |
| 879 | - return $response; | |
| 880 | - } | |
| 814 | + if ( ! empty( $templates ) ) { | |
| 815 | + $templates_list['templates'] = array_merge( $templates_list['templates'], $templates ); | |
| 816 | + } | |
| 881 | 817 | |
| 882 | - public function register_template_instance() { | |
| 883 | - $this->elementor->templates_manager->register_source( TemplateSource::class ); | |
| 884 | - } | |
| 818 | + return $templates_list; | |
| 819 | + } | |
| 885 | 820 | |
| 886 | - public function prepend_categories( $library_data ) { | |
| 887 | - $categories = $this->template_categories(); | |
| 888 | - if ( ! empty( $categories ) ) { | |
| 889 | - $library_data['types_data']['block']['categories'] = array_merge( | |
| 890 | - $categories, | |
| 891 | - isset( $library_data['types_data']['block']['categories'] ) ? $library_data['types_data']['block']['categories'] : [] | |
| 892 | - ); | |
| 893 | - } | |
| 894 | - return $library_data; | |
| 895 | - } | |
| 821 | + /** | |
| 822 | + * get_templates | |
| 823 | + * | |
| 824 | + * Get Better docs template list and cache this list | |
| 825 | + * | |
| 826 | + * @return array|mixed | |
| 827 | + * @since 2.0.0 | |
| 828 | + */ | |
| 829 | + public function get_templates() { | |
| 830 | + $_cache_key = 'betterdocs_template_library_' . betterdocs()->version; | |
| 831 | + $templates = get_transient( $_cache_key ); | |
| 896 | 832 | |
| 897 | - public function template_categories() { | |
| 898 | - return [ | |
| 899 | - 'Single Docs', | |
| 900 | - 'Docs Archive' | |
| 901 | - ]; | |
| 902 | - } | |
| 833 | + if ( ! $templates ) { | |
| 834 | + $source = new TemplateSource(); | |
| 835 | + $templates = $source->get_items(); | |
| 903 | 836 | |
| 904 | - /** | |
| 905 | - * Added BetterDocs template with Elementor core templates list | |
| 906 | - * | |
| 907 | - * added_template | |
| 908 | - * | |
| 909 | - * @param $templates_list array elementor template list | |
| 910 | - * | |
| 911 | - * @return array | |
| 912 | - * @since 2.0.7 | |
| 913 | - * | |
| 914 | - */ | |
| 915 | - public function added_bd_template( array $templates_list ) { | |
| 916 | - $templates = $this->get_templates(); | |
| 837 | + if ( ! empty( $templates ) ) { | |
| 838 | + $templates = array_map( | |
| 839 | + function ( $template ) { | |
| 840 | + $template['id'] = $template['template_id']; | |
| 841 | + $template['tmpl_created'] = $template['date']; | |
| 842 | + $template['tags'] = json_encode( $template['tags'] ); | |
| 843 | + $template['is_pro'] = $template['isPro']; | |
| 844 | + $template['access_level'] = $template['accessLevel']; | |
| 845 | + $template['popularity_index'] = $template['popularityIndex']; | |
| 846 | + $template['trend_index'] = $template['trendIndex']; | |
| 847 | + $template['has_page_settings'] = $template['hasPageSettings']; | |
| 917 | 848 | |
| 918 | - if ( ! empty( $templates ) ) { | |
| 919 | - $templates_list['templates'] = array_merge( $templates_list['templates'], $templates ); | |
| 920 | - } | |
| 849 | + return $template; | |
| 850 | + }, | |
| 851 | + $templates | |
| 852 | + ); | |
| 921 | 853 | |
| 922 | - return $templates_list; | |
| 923 | - } | |
| 854 | + set_transient( $_cache_key, $templates, WEEK_IN_SECONDS ); | |
| 855 | + } else { | |
| 856 | + $templates = []; | |
| 857 | + } | |
| 858 | + } | |
| 924 | 859 | |
| 925 | - /** | |
| 926 | - * get_templates | |
| 927 | - * | |
| 928 | - * Get Better docs template list and cache this list | |
| 929 | - * | |
| 930 | - * @return array|mixed | |
| 931 | - * @since 2.0.0 | |
| 932 | - */ | |
| 933 | - public function get_templates() { | |
| 934 | - $_cache_key = 'betterdocs_template_library_' . betterdocs()->version; | |
| 935 | - $source = new TemplateSource; | |
| 936 | - $local_ids = array_column( $source->get_local_templates(), 'template_id' ); | |
| 937 | - $templates = get_transient( $_cache_key ); | |
| 860 | + return $templates; | |
| 861 | + } | |
| 938 | 862 | |
| 939 | - if ( ! $templates ) { | |
| 940 | - // Only cache remote templates — local templates are always appended fresh below | |
| 941 | - $all_templates = $source->get_items(); | |
| 942 | - $remote_only = array_values( array_filter( $all_templates, function ( $t ) use ( $local_ids ) { | |
| 943 | - return ! in_array( $t['template_id'], $local_ids, true ); | |
| 944 | - } ) ); | |
| 863 | + public function modified_ajax_action( $ajax ) { | |
| 864 | + if ( ! isset( $_REQUEST['actions'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 865 | + return; | |
| 866 | + } | |
| 945 | 867 | |
| 946 | - if ( ! empty( $remote_only ) ) { | |
| 947 | - $remote_only = array_map( function ( $template ) { | |
| 948 | - $template['id'] = $template['template_id']; | |
| 949 | - $template['tmpl_created'] = $template['date']; | |
| 950 | - $template['tags'] = json_encode( $template['tags'] ); | |
| 951 | - $template['is_pro'] = $template['isPro']; | |
| 952 | - $template['access_level'] = $template['accessLevel']; | |
| 953 | - $template['popularity_index'] = $template['popularityIndex']; | |
| 954 | - $template['trend_index'] = $template['trendIndex']; | |
| 955 | - $template['has_page_settings'] = $template['hasPageSettings']; | |
| 868 | + $actions = json_decode( stripslashes( $_REQUEST['actions'] ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 869 | + $data = false; | |
| 956 | 870 | |
| 957 | - return $template; | |
| 958 | - }, $remote_only ); | |
| 871 | + foreach ( $actions as $id => $action_data ) { | |
| 872 | + if ( ! isset( $action_data['get_template_data'] ) ) { | |
| 873 | + $data = $action_data; | |
| 874 | + } | |
| 875 | + } | |
| 959 | 876 | |
| 960 | - set_transient( $_cache_key, $remote_only, WEEK_IN_SECONDS ); | |
| 961 | - $templates = $remote_only; | |
| 962 | - } else { | |
| 963 | - $templates = []; | |
| 964 | - } | |
| 965 | - } else { | |
| 966 | - // Strip any local templates that may have been cached in a previous version | |
| 967 | - $templates = array_values( array_filter( $templates, function ( $t ) use ( $local_ids ) { | |
| 968 | - $id = isset( $t['template_id'] ) ? $t['template_id'] : ( isset( $t['id'] ) ? $t['id'] : '' ); | |
| 969 | - return ! in_array( $id, $local_ids, true ); | |
| 970 | - } ) ); | |
| 971 | - } | |
| 877 | + if ( ! $data ) { | |
| 878 | + return; | |
| 879 | + } | |
| 972 | 880 | |
| 973 | - // Always append local templates fresh so they are never stale-cached | |
| 974 | - $local_templates = array_map( function ( $template ) { | |
| 975 | - $template['id'] = $template['template_id']; | |
| 976 | - $template['tmpl_created'] = $template['date']; | |
| 977 | - $template['tags'] = json_encode( $template['tags'] ); | |
| 978 | - $template['is_pro'] = $template['isPro']; | |
| 979 | - $template['access_level'] = $template['accessLevel']; | |
| 980 | - $template['popularity_index'] = $template['popularityIndex']; | |
| 981 | - $template['trend_index'] = $template['trendIndex']; | |
| 982 | - $template['has_page_settings'] = $template['hasPageSettings']; | |
| 881 | + if ( ! isset( $data['data'] ) ) { | |
| 882 | + return; | |
| 883 | + } | |
| 983 | 884 | |
| 984 | - return $template; | |
| 985 | - }, $source->get_local_templates() ); | |
| 885 | + $data = $data['data']; | |
| 986 | 886 | |
| 987 | - return array_merge( $templates, $local_templates ); | |
| 988 | - } | |
| 887 | + if ( empty( $data['template_id'] ) ) { | |
| 888 | + return; | |
| 889 | + } | |
| 989 | 890 | |
| 990 | - public function modified_ajax_action( $ajax ) { | |
| 991 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Elementor's own ajax handler verifies nonce upstream. | |
| 992 | - if ( ! isset( $_REQUEST['actions'] ) ) { | |
| 993 | - return; | |
| 994 | - } | |
| 891 | + if ( false === strpos( $data['template_id'], 'betterdocs_' ) ) { | |
| 892 | + return; | |
| 893 | + } | |
| 894 | + $ajax->register_ajax_action( 'get_template_data', [ $this, 'get_template_data' ] ); | |
| 895 | + } | |
| 995 | 896 | |
| 996 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Elementor's ajax handler verifies nonce; raw JSON is structure-validated below. | |
| 997 | - $raw_actions = wp_unslash( $_REQUEST['actions'] ); | |
| 998 | - $actions = json_decode( $raw_actions, true ); | |
| 999 | - if ( ! is_array( $actions ) ) { | |
| 1000 | - return; | |
| 1001 | - } | |
| 1002 | - $data = false; | |
| 1003 | - | |
| 1004 | - foreach ( $actions as $id => $action_data ) { | |
| 1005 | - if ( ! isset( $action_data['get_template_data'] ) ) { | |
| 1006 | - $data = $action_data; | |
| 1007 | - } | |
| 1008 | - } | |
| 1009 | - | |
| 1010 | - if ( ! $data ) { | |
| 1011 | - return; | |
| 1012 | - } | |
| 1013 | - | |
| 1014 | - if ( ! isset( $data['data'] ) ) { | |
| 1015 | - return; | |
| 1016 | - } | |
| 1017 | - | |
| 1018 | - $data = $data['data']; | |
| 1019 | - | |
| 1020 | - if ( empty( $data['template_id'] ) ) { | |
| 1021 | - return; | |
| 1022 | - } | |
| 1023 | - | |
| 1024 | - if ( false === strpos( $data['template_id'], 'betterdocs_' ) ) { | |
| 1025 | - return; | |
| 1026 | - } | |
| 1027 | - $ajax->register_ajax_action( 'get_template_data', [$this, 'get_template_data'] ); | |
| 1028 | - } | |
| 1029 | - | |
| 1030 | - public function get_template_data( $args ) { | |
| 1031 | - $source = new TemplateSource; | |
| 1032 | - return $source->get_data( $args ); | |
| 1033 | - } | |
| 897 | + public function get_template_data( $args ) { | |
| 898 | + $source = new TemplateSource(); | |
| 899 | + return $source->get_data( $args ); | |
| 900 | + } | |
| 1034 | 901 | } |