| @@ -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 Elementor\Controls_Manager; |
| 10 | 10 | use Elementor\Api as ElementorAPI; |
| @@ -13,8 +13,9 @@ | ||
| 13 | 13 | use WPDeveloper\BetterDocs\Utils\Enqueue; |
| 14 | 14 | use WPDeveloper\BetterDocs\Editors\Elementor\Helper; |
| 15 | 15 | use WPDeveloper\BetterDocs\Editors\Elementor\SingleDocs; |
| 16 | 16 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ToC; |
| 17 | +use WPDeveloper\BetterDocs\Editors\Elementor\Widget\DocAuthor; | |
| 17 | 18 | use WPDeveloper\BetterDocs\Editors\Elementor\DocsArchive; |
| 18 | 19 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Title; |
| 19 | 20 | use WPDeveloper\BetterDocs\Editors\Elementor\Tags\TitleTag; |
| 20 | 21 | use WPDeveloper\BetterDocs\Editors\Elementor\TemplateSource; |
| @@ -26,819 +27,875 @@ | ||
| 26 | 27 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\FAQ; |
| 27 | 28 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Reactions; |
| 28 | 29 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Navigation; |
| 29 | 30 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ArchiveList; |
| 31 | +use WPDeveloper\BetterDocs\Editors\Elementor\Widget\PrintButton; | |
| 30 | 32 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Breadcrumbs; |
| 33 | +use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ReadingTime; | |
| 31 | 34 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\SearchForm; |
| 32 | 35 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\CategoryBox; |
| 33 | 36 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\CategoryGrid; |
| 34 | 37 | use WPDeveloper\BetterDocs\Editors\Elementor\Conditions\ArchiveCondition; |
| 38 | +use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Tags; | |
| 39 | +// use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\BetterdocsEncyclopedia; | |
| 40 | +use WPDeveloper\BetterDocs\Editors\Elementor\Widget\CategoryArchiveHeader; | |
| 35 | 41 | |
| 36 | 42 | class Elementor extends BaseEditor { |
| 37 | - protected $is_elementor_active = false; | |
| 38 | - protected $is_elementor_pro_active = false; | |
| 39 | - 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; | |
| 40 | 46 | |
| 41 | - /** | |
| 42 | - * Elementor plugin class | |
| 43 | - * @var ElementorPlugin | |
| 44 | - */ | |
| 45 | - protected $elementor; | |
| 47 | + /** | |
| 48 | + * Elementor plugin class | |
| 49 | + * @var ElementorPlugin | |
| 50 | + */ | |
| 51 | + protected $elementor; | |
| 46 | 52 | |
| 47 | - /** | |
| 48 | - * Elementor Helper class | |
| 49 | - * @var Helper | |
| 50 | - */ | |
| 51 | - protected $helper; | |
| 53 | + /** | |
| 54 | + * Elementor Helper class | |
| 55 | + * @var Helper | |
| 56 | + */ | |
| 57 | + protected $helper; | |
| 52 | 58 | |
| 53 | - public function __construct( Settings $settings, Enqueue $enqueue, Helper $helper ) { | |
| 54 | - parent::__construct( $settings, $enqueue ); | |
| 59 | + public function __construct( Settings $settings, Enqueue $enqueue, Helper $helper ) { | |
| 60 | + parent::__construct( $settings, $enqueue ); | |
| 55 | 61 | |
| 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' ); | |
| 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' ); | |
| 59 | 65 | |
| 60 | - if ( ! $this->is_elementor_active || ! class_exists( ElementorPlugin::class ) ) { | |
| 61 | - return; | |
| 62 | - } | |
| 66 | + if ( ! $this->is_elementor_active || ! class_exists( ElementorPlugin::class ) ) { | |
| 67 | + return; | |
| 68 | + } | |
| 63 | 69 | |
| 64 | - $this->elementor = ElementorPlugin::instance(); | |
| 65 | - } | |
| 70 | + $this->elementor = ElementorPlugin::instance(); | |
| 71 | + } | |
| 66 | 72 | |
| 67 | - public function init() { | |
| 68 | - if ( ! $this->is_elementor_active || $this->elementor == null ) { | |
| 69 | - return; | |
| 70 | - } | |
| 73 | + public function init() { | |
| 74 | + if ( ! $this->is_elementor_active || $this->elementor == null ) { | |
| 75 | + return; | |
| 76 | + } | |
| 71 | 77 | |
| 72 | - add_action( 'wp_enqueue_scripts', [$this, 'enqueue_scripts'] ); | |
| 78 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); | |
| 73 | 79 | |
| 74 | - add_action( 'elementor/elements/categories_registered', [$this, 'register_widget_category'] ); | |
| 75 | - 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' ] ); | |
| 76 | 82 | |
| 77 | - add_action( 'elementor/editor/before_enqueue_scripts', [$this, 'editor_enqueue_scripts'] ); | |
| 78 | - 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' ] ); | |
| 79 | 85 | |
| 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 ); | |
| 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 ); | |
| 82 | 88 | |
| 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'] ); | |
| 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' ] ); | |
| 87 | 93 | |
| 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 | - } | |
| 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 | + } | |
| 96 | 102 | |
| 97 | - $this->betterdocs_init(); | |
| 98 | - } | |
| 103 | + $this->betterdocs_init(); | |
| 104 | + } | |
| 99 | 105 | |
| 100 | - public function editor_enqueue_scripts() { | |
| 101 | - betterdocs()->assets->enqueue( 'betterdocs-el-icon', 'elementor/css/betterdocs-el-icon.css' ); | |
| 102 | - } | |
| 106 | + public function editor_enqueue_scripts() { | |
| 107 | + betterdocs()->assets->enqueue( 'betterdocs-el-icon', 'elementor/css/betterdocs-el-icon.css' ); | |
| 108 | + } | |
| 103 | 109 | |
| 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 | - } | |
| 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 | + } | |
| 108 | 114 | |
| 109 | - public function override_location( $need_override_location, $location ) { | |
| 110 | - if ( is_singular( ['docs'] ) && 'single' === $location ) { | |
| 111 | - $need_override_location = true; | |
| 112 | - } | |
| 115 | + public function override_location( $need_override_location, $location ) { | |
| 116 | + if ( is_singular( [ 'docs' ] ) && 'single' === $location ) { | |
| 117 | + $need_override_location = true; | |
| 118 | + } | |
| 113 | 119 | |
| 114 | - return $need_override_location; | |
| 115 | - } | |
| 120 | + return $need_override_location; | |
| 121 | + } | |
| 116 | 122 | |
| 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 | - ); | |
| 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 | + ); | |
| 128 | 134 | |
| 129 | - $default_multiple_kb = $this->multiple_kb_status(); | |
| 135 | + $default_multiple_kb = $this->multiple_kb_status(); | |
| 130 | 136 | |
| 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] : ''; | |
| 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] : ''; | |
| 134 | 140 | |
| 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 | - } | |
| 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 | + } | |
| 151 | 157 | |
| 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 | - } | |
| 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 | + } | |
| 161 | 167 | |
| 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 | - ); | |
| 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 | + ); | |
| 173 | 179 | |
| 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 | - ); | |
| 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 | + ); | |
| 185 | 191 | |
| 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 | - } | |
| 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 | + } | |
| 205 | 211 | |
| 206 | - $wb->add_control( | |
| 207 | - 'offset', | |
| 208 | - [ | |
| 209 | - 'label' => __( 'Offset', 'betterdocs' ), | |
| 210 | - 'type' => Controls_Manager::NUMBER, | |
| 211 | - 'default' => '0' | |
| 212 | - ] | |
| 213 | - ); | |
| 212 | + $wb->add_control( | |
| 213 | + 'offset', | |
| 214 | + [ | |
| 215 | + 'label' => __( 'Offset', 'betterdocs' ), | |
| 216 | + 'type' => Controls_Manager::NUMBER, | |
| 217 | + 'default' => '0' | |
| 218 | + ] | |
| 219 | + ); | |
| 214 | 220 | |
| 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 | - ); | |
| 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 | + ); | |
| 236 | 242 | |
| 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 | - ] | |
| 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 | + ] | |
| 250 | 256 | |
| 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 | - ); | |
| 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 | + ); | |
| 273 | 279 | |
| 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 | - ] | |
| 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 | + ] | |
| 287 | 293 | |
| 288 | - ] | |
| 289 | - ); | |
| 290 | - } | |
| 294 | + ] | |
| 295 | + ); | |
| 296 | + } | |
| 291 | 297 | |
| 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 | - ); | |
| 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 | + ); | |
| 301 | 307 | |
| 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 | - ); | |
| 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 | + ); | |
| 310 | 316 | |
| 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 | - ); | |
| 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 | + ); | |
| 320 | 326 | |
| 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 | - ); | |
| 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 | + ); | |
| 333 | 339 | |
| 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 | - ); | |
| 340 | + $wb->add_control( | |
| 341 | + 'nested_subcategory', | |
| 342 | + [ | |
| 343 | + 'label' => __( 'Enable Nested Subcategory', 'betterdocs' ), | |
| 344 | + 'type' => Controls_Manager::SWITCHER, | |
| 345 | + 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 346 | + 'label_off' => __( 'No', 'betterdocs' ), | |
| 347 | + 'return_value' => 'true', | |
| 348 | + 'default' => false | |
| 349 | + ] | |
| 350 | + ); | |
| 345 | 351 | |
| 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 | - } | |
| 352 | + $wb->add_control( | |
| 353 | + 'subcategory_per_grid', | |
| 354 | + [ | |
| 355 | + 'label' => __( 'Subcategory Per Grid', 'betterdocs' ), | |
| 356 | + 'type' => Controls_Manager::NUMBER, | |
| 357 | + 'default' => '2', | |
| 358 | + 'condition' => [ | |
| 359 | + 'nested_subcategory' => 'true' | |
| 360 | + ] | |
| 361 | + ] | |
| 362 | + ); | |
| 358 | 363 | |
| 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 | - } | |
| 364 | + $wb->add_control( | |
| 365 | + 'post_per_subcat', | |
| 366 | + [ | |
| 367 | + 'label' => __( 'Post Per Subcategory', 'betterdocs' ), | |
| 368 | + 'type' => Controls_Manager::NUMBER, | |
| 369 | + 'default' => '6', | |
| 370 | + 'condition' => [ | |
| 371 | + 'nested_subcategory' => 'true' | |
| 372 | + ] | |
| 373 | + ] | |
| 374 | + ); | |
| 375 | + } | |
| 372 | 376 | |
| 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 | - } | |
| 377 | + if ( $wb->get_name() === 'betterdocs-category-box' ) { | |
| 378 | + $wb->add_control( | |
| 379 | + 'nested_subcategory', | |
| 380 | + [ | |
| 381 | + 'label' => __( 'Nested Subcategory', 'betterdocs' ), | |
| 382 | + 'type' => Controls_Manager::SWITCHER, | |
| 383 | + 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 384 | + 'label_off' => __( 'No', 'betterdocs' ), | |
| 385 | + 'return_value' => 'true', | |
| 386 | + 'default' => false | |
| 387 | + ] | |
| 388 | + ); | |
| 389 | + } | |
| 386 | 390 | |
| 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 | - ); | |
| 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 | + } | |
| 396 | 404 | |
| 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 | + if ( $wb->get_name() === 'betterdocs-tab-view-list' ) { | |
| 406 | + $wb->add_control( | |
| 407 | + 'tab_posts_query_heading', | |
| 408 | + [ | |
| 409 | + 'label' => __( 'Tab List Posts', 'betterdocs' ), | |
| 410 | + 'type' => Controls_Manager::HEADING, | |
| 411 | + 'separator' => 'before' | |
| 412 | + ] | |
| 413 | + ); | |
| 405 | 414 | |
| 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 | - ); | |
| 415 | + $wb->add_control( | |
| 416 | + 'tab_box_per_tabs', | |
| 417 | + [ | |
| 418 | + 'label' => __( 'Box Per Tabs', 'betterdocs' ), | |
| 419 | + 'type' => Controls_Manager::NUMBER, | |
| 420 | + 'default' => '10' | |
| 421 | + ] | |
| 422 | + ); | |
| 424 | 423 | |
| 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' | |
| 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 | + ); | |
| 435 | 432 | |
| 436 | - ] | |
| 437 | - ); | |
| 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 | + ); | |
| 438 | 451 | |
| 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 | - ); | |
| 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' | |
| 450 | 462 | |
| 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 | - ); | |
| 463 | + ] | |
| 464 | + ); | |
| 462 | 465 | |
| 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 | - ); | |
| 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 | + ); | |
| 478 | 477 | |
| 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 | - } | |
| 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 | + ); | |
| 502 | 489 | |
| 503 | - $wb->end_controls_section(); | |
| 504 | - } | |
| 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 | + ); | |
| 505 | 505 | |
| 506 | - public function multiple_kb_status() { | |
| 507 | - if ( $this->settings->get( 'multiple_kb' ) == 1 ) { | |
| 508 | - return 'true'; | |
| 509 | - } | |
| 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 | + } | |
| 510 | 529 | |
| 511 | - return ''; | |
| 512 | - } | |
| 530 | + $wb->end_controls_section(); | |
| 531 | + } | |
| 513 | 532 | |
| 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 | - ]; | |
| 533 | + public function multiple_kb_status() { | |
| 534 | + if ( $this->settings->get( 'multiple_kb' ) == 1 ) { | |
| 535 | + return 'true'; | |
| 536 | + } | |
| 520 | 537 | |
| 521 | - $terms = get_terms( $args ); | |
| 538 | + return ''; | |
| 539 | + } | |
| 522 | 540 | |
| 523 | - if ( is_wp_error( $terms ) ) { | |
| 524 | - return []; | |
| 525 | - } | |
| 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 | + ]; | |
| 526 | 547 | |
| 527 | - if ( $prettify ) { | |
| 528 | - $pretty_taxonomies = []; | |
| 548 | + $terms = get_terms( $args ); | |
| 529 | 549 | |
| 530 | - foreach ( $terms as $term ) { | |
| 531 | - $pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = $term->name; | |
| 532 | - } | |
| 550 | + if ( is_wp_error( $terms ) ) { | |
| 551 | + return []; | |
| 552 | + } | |
| 533 | 553 | |
| 534 | - return $pretty_taxonomies; | |
| 535 | - } | |
| 554 | + if ( $prettify ) { | |
| 555 | + $pretty_taxonomies = []; | |
| 536 | 556 | |
| 537 | - return $terms; | |
| 538 | - } | |
| 557 | + foreach ( $terms as $term ) { | |
| 558 | + $pretty_taxonomies[ $term_id ? $term->term_id : $term->slug ] = $term->name; | |
| 559 | + } | |
| 539 | 560 | |
| 540 | - public function register_basic_tags( $module ) { | |
| 541 | - $module->register( new TitleTag ); | |
| 542 | - } | |
| 561 | + return $pretty_taxonomies; | |
| 562 | + } | |
| 543 | 563 | |
| 544 | - public function register_basic_widgets( $widgets_manager ) { | |
| 545 | - foreach ( $this->basic_widget_lists() as $value ) { | |
| 546 | - $widgets_manager->register( new $value ); | |
| 547 | - } | |
| 548 | - } | |
| 564 | + return $terms; | |
| 565 | + } | |
| 549 | 566 | |
| 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 | - ]; | |
| 567 | + public function register_basic_tags( $module ) { | |
| 568 | + $module->register( new TitleTag() ); | |
| 569 | + } | |
| 564 | 570 | |
| 565 | - return $widget_arr; | |
| 566 | - } | |
| 571 | + public function register_basic_widgets( $widgets_manager ) { | |
| 572 | + foreach ( $this->basic_widget_lists() as $value ) { | |
| 573 | + $widgets_manager->register( new $value() ); | |
| 574 | + } | |
| 575 | + } | |
| 567 | 576 | |
| 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 | - } | |
| 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 | + ]; | |
| 574 | 592 | |
| 575 | - public function promote_pro_elements( $config ) { | |
| 576 | - if ( $this->is_pro_active ) { | |
| 577 | - return $config; | |
| 578 | - } | |
| 593 | + return $widget_arr; | |
| 594 | + } | |
| 579 | 595 | |
| 580 | - $promotion_widgets = []; | |
| 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 | + } | |
| 581 | 606 | |
| 582 | - if ( isset( $config['promotionWidgets'] ) ) { | |
| 583 | - $promotion_widgets = $config['promotionWidgets']; | |
| 584 | - } | |
| 607 | + public function promote_pro_elements( $config ) { | |
| 608 | + if ( $this->is_pro_active ) { | |
| 609 | + return $config; | |
| 610 | + } | |
| 585 | 611 | |
| 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 | - ] ); | |
| 612 | + $promotion_widgets = []; | |
| 594 | 613 | |
| 595 | - $config['promotionWidgets'] = $combine_array; | |
| 614 | + if ( isset( $config['promotionWidgets'] ) ) { | |
| 615 | + $promotion_widgets = $config['promotionWidgets']; | |
| 616 | + } | |
| 596 | 617 | |
| 597 | - return $config; | |
| 598 | - } | |
| 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 | + ); | |
| 599 | 629 | |
| 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 | - } | |
| 630 | + $config['promotionWidgets'] = $combine_array; | |
| 610 | 631 | |
| 611 | - return null; | |
| 612 | - } | |
| 632 | + return $config; | |
| 633 | + } | |
| 613 | 634 | |
| 614 | - public function enqueue_scripts() { | |
| 615 | - $assets = betterdocs()->assets; | |
| 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 | + } | |
| 616 | 645 | |
| 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' ); | |
| 646 | + return null; | |
| 647 | + } | |
| 624 | 648 | |
| 625 | - /** | |
| 626 | - * Widget's JS | |
| 627 | - */ | |
| 628 | - $assets->register( 'betterdocs-el-category-grid', 'elementor/js/category-grid.js', ['jquery', 'betterdocs-category-toggler'] ); | |
| 649 | + public function enqueue_scripts() { | |
| 650 | + $assets = betterdocs()->assets; | |
| 629 | 651 | |
| 630 | - if ( betterdocs()->helper->is_el_templates() == true ) { | |
| 631 | - $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/css/betterdocs-el-edit.css' ); | |
| 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' ); | |
| 632 | 659 | |
| 633 | - if ( ! $this->is_pro_active ) { | |
| 634 | - $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/js/editor.js', ['jquery'] ); | |
| 635 | - } | |
| 636 | - } | |
| 660 | + /** | |
| 661 | + * Widget's JS | |
| 662 | + */ | |
| 663 | + $assets->register( 'betterdocs-el-category-grid', 'elementor/js/category-grid.js', [ 'jquery', 'betterdocs-category-toggler' ] ); | |
| 637 | 664 | |
| 638 | - do_action( 'betterdocs_elementor_enqueue_scripts', $this ); | |
| 639 | - } | |
| 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 | + ); | |
| 640 | 675 | |
| 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 | - } | |
| 676 | + if ( betterdocs()->helper->is_el_templates() == true ) { | |
| 677 | + $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/css/betterdocs-el-edit.css' ); | |
| 648 | 678 | |
| 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 | - } | |
| 679 | + if ( ! $this->is_pro_active ) { | |
| 680 | + $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/js/editor.js', [ 'jquery' ] ); | |
| 681 | + } | |
| 682 | + } | |
| 670 | 683 | |
| 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 | - } | |
| 684 | + do_action( 'betterdocs_elementor_enqueue_scripts', $this ); | |
| 685 | + } | |
| 678 | 686 | |
| 679 | - public function betterdocs_init() { | |
| 680 | - add_action( 'elementor/init', [$this, 'register_template_instance'], 20 ); | |
| 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 | + } | |
| 681 | 694 | |
| 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 | - } | |
| 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 | + } | |
| 687 | 724 | |
| 688 | - add_action( 'elementor/ajax/register_actions', [$this, 'modified_ajax_action'], 20 ); | |
| 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 | + } | |
| 689 | 732 | |
| 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 | - } | |
| 733 | + public function betterdocs_init() { | |
| 734 | + add_action( 'elementor/init', [ $this, 'register_template_instance' ], 20 ); | |
| 698 | 735 | |
| 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(); | |
| 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 | + } | |
| 713 | 741 | |
| 714 | - if ( ! empty( $bd_templates ) ) { | |
| 715 | - $templates_list = array_merge( (array) $templates_list, (array) $bd_templates ); | |
| 716 | - } | |
| 742 | + add_action( 'elementor/ajax/register_actions', [ $this, 'modified_ajax_action' ], 20 ); | |
| 717 | 743 | |
| 718 | - $response['body'] = json_encode( $templates_list ); | |
| 719 | - } | |
| 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 | + } | |
| 720 | 752 | |
| 721 | - return $response; | |
| 722 | - } | |
| 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(); | |
| 723 | 767 | |
| 724 | - public function register_template_instance() { | |
| 725 | - $this->elementor->templates_manager->register_source( TemplateSource::class ); | |
| 726 | - } | |
| 768 | + if ( ! empty( $bd_templates ) ) { | |
| 769 | + $templates_list = array_merge( (array) $templates_list, (array) $bd_templates ); | |
| 770 | + } | |
| 727 | 771 | |
| 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 | - } | |
| 772 | + $response['body'] = json_encode( $templates_list ); | |
| 773 | + } | |
| 738 | 774 | |
| 739 | - public function template_categories() { | |
| 740 | - return [ | |
| 741 | - 'Single Docs', | |
| 742 | - 'Docs Archive' | |
| 743 | - ]; | |
| 744 | - } | |
| 775 | + return $response; | |
| 776 | + } | |
| 745 | 777 | |
| 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(); | |
| 778 | + public function register_template_instance() { | |
| 779 | + $this->elementor->templates_manager->register_source( TemplateSource::class ); | |
| 780 | + } | |
| 759 | 781 | |
| 760 | - if ( ! empty( $templates ) ) { | |
| 761 | - $templates_list['templates'] = array_merge( $templates_list['templates'], $templates ); | |
| 762 | - } | |
| 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 | + } | |
| 763 | 792 | |
| 764 | - return $templates_list; | |
| 765 | - } | |
| 793 | + public function template_categories() { | |
| 794 | + return [ | |
| 795 | + 'Single Docs', | |
| 796 | + 'Docs Archive' | |
| 797 | + ]; | |
| 798 | + } | |
| 766 | 799 | |
| 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 ); | |
| 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(); | |
| 778 | 813 | |
| 779 | - if ( ! $templates ) { | |
| 780 | - $source = new TemplateSource; | |
| 781 | - $templates = $source->get_items(); | |
| 814 | + if ( ! empty( $templates ) ) { | |
| 815 | + $templates_list['templates'] = array_merge( $templates_list['templates'], $templates ); | |
| 816 | + } | |
| 782 | 817 | |
| 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']; | |
| 818 | + return $templates_list; | |
| 819 | + } | |
| 793 | 820 | |
| 794 | - return $template; | |
| 795 | - }, $templates ); | |
| 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 ); | |
| 796 | 832 | |
| 797 | - set_transient( $_cache_key, $templates, WEEK_IN_SECONDS ); | |
| 798 | - } else { | |
| 799 | - $templates = []; | |
| 800 | - } | |
| 801 | - } | |
| 833 | + if ( ! $templates ) { | |
| 834 | + $source = new TemplateSource(); | |
| 835 | + $templates = $source->get_items(); | |
| 802 | 836 | |
| 803 | - return $templates; | |
| 804 | - } | |
| 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']; | |
| 805 | 848 | |
| 806 | - public function modified_ajax_action( $ajax ) { | |
| 807 | - if ( ! isset( $_REQUEST['actions'] ) ) { | |
| 808 | - return; | |
| 809 | - } | |
| 849 | + return $template; | |
| 850 | + }, | |
| 851 | + $templates | |
| 852 | + ); | |
| 810 | 853 | |
| 811 | - $actions = json_decode( stripslashes( $_REQUEST['actions'] ), true ); | |
| 812 | - $data = false; | |
| 854 | + set_transient( $_cache_key, $templates, WEEK_IN_SECONDS ); | |
| 855 | + } else { | |
| 856 | + $templates = []; | |
| 857 | + } | |
| 858 | + } | |
| 813 | 859 | |
| 814 | - foreach ( $actions as $id => $action_data ) { | |
| 815 | - if ( ! isset( $action_data['get_template_data'] ) ) { | |
| 816 | - $data = $action_data; | |
| 817 | - } | |
| 818 | - } | |
| 860 | + return $templates; | |
| 861 | + } | |
| 819 | 862 | |
| 820 | - if ( ! $data ) { | |
| 821 | - return; | |
| 822 | - } | |
| 863 | + public function modified_ajax_action( $ajax ) { | |
| 864 | + if ( ! isset( $_REQUEST['actions'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 865 | + return; | |
| 866 | + } | |
| 823 | 867 | |
| 824 | - if ( ! isset( $data['data'] ) ) { | |
| 825 | - return; | |
| 826 | - } | |
| 868 | + $actions = json_decode( stripslashes( $_REQUEST['actions'] ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 869 | + $data = false; | |
| 827 | 870 | |
| 828 | - $data = $data['data']; | |
| 871 | + foreach ( $actions as $id => $action_data ) { | |
| 872 | + if ( ! isset( $action_data['get_template_data'] ) ) { | |
| 873 | + $data = $action_data; | |
| 874 | + } | |
| 875 | + } | |
| 829 | 876 | |
| 830 | - if ( empty( $data['template_id'] ) ) { | |
| 831 | - return; | |
| 832 | - } | |
| 877 | + if ( ! $data ) { | |
| 878 | + return; | |
| 879 | + } | |
| 833 | 880 | |
| 834 | - if ( false === strpos( $data['template_id'], 'betterdocs_' ) ) { | |
| 835 | - return; | |
| 836 | - } | |
| 837 | - $ajax->register_ajax_action( 'get_template_data', [$this, 'get_template_data'] ); | |
| 838 | - } | |
| 881 | + if ( ! isset( $data['data'] ) ) { | |
| 882 | + return; | |
| 883 | + } | |
| 839 | 884 | |
| 840 | - public function get_template_data( $args ) { | |
| 841 | - $source = new TemplateSource; | |
| 842 | - return $source->get_data( $args ); | |
| 843 | - } | |
| 885 | + $data = $data['data']; | |
| 886 | + | |
| 887 | + if ( empty( $data['template_id'] ) ) { | |
| 888 | + return; | |
| 889 | + } | |
| 890 | + | |
| 891 | + if ( false === strpos( $data['template_id'], 'betterdocs_' ) ) { | |
| 892 | + return; | |
| 893 | + } | |
| 894 | + $ajax->register_ajax_action( 'get_template_data', [ $this, 'get_template_data' ] ); | |
| 895 | + } | |
| 896 | + | |
| 897 | + public function get_template_data( $args ) { | |
| 898 | + $source = new TemplateSource(); | |
| 899 | + return $source->get_data( $args ); | |
| 900 | + } | |
| 844 | 901 | } |