| @@ -5,248 +5,315 @@ | ||
| 5 | 5 | use WPDeveloper\BetterDocs\Utils\Base; |
| 6 | 6 | use WPDeveloper\BetterDocs\Core\Settings; |
| 7 | 7 | use WPDeveloper\BetterDocs\Utils\Enqueue; |
| 8 | 8 | use WPDeveloper\BetterDocs\Utils\Database; |
| 9 | +use WPDeveloper\BetterDocs\Utils\Helper; | |
| 9 | 10 | use WPDeveloper\BetterDocs\Dependencies\DI\Container; |
| 10 | 11 | |
| 11 | 12 | class FrontEnd extends Base { |
| 12 | - private $container; | |
| 13 | - private $database; | |
| 14 | - /** | |
| 15 | - * Enqueue | |
| 16 | - * @var Enqueue | |
| 17 | - */ | |
| 18 | - private $assets; | |
| 19 | - /** | |
| 20 | - * Settings | |
| 21 | - * @var Settings | |
| 22 | - */ | |
| 23 | - private $settings; | |
| 24 | - private $widget_attributes = []; | |
| 25 | - private $widget_type = ''; | |
| 13 | + private $container; | |
| 14 | + private $database; | |
| 15 | + /** | |
| 16 | + * Enqueue | |
| 17 | + * @var Enqueue | |
| 18 | + */ | |
| 19 | + private $assets; | |
| 20 | + /** | |
| 21 | + * Settings | |
| 22 | + * @var Settings | |
| 23 | + */ | |
| 24 | + private $settings; | |
| 25 | + private $widget_attributes = []; | |
| 26 | + private $widget_type = ''; | |
| 26 | 27 | |
| 27 | - public function __construct( Container $container, Database $database, Settings $settings ) { | |
| 28 | - $this->container = $container; | |
| 29 | - $this->database = $database; | |
| 30 | - $this->settings = $settings; | |
| 28 | + public function __construct( Container $container, Database $database, Settings $settings ) { | |
| 29 | + $this->container = $container; | |
| 30 | + $this->database = $database; | |
| 31 | + $this->settings = $settings; | |
| 31 | 32 | |
| 32 | - $this->assets = $this->container->get( Enqueue::class ); | |
| 33 | + $this->assets = $this->container->get( Enqueue::class ); | |
| 33 | 34 | |
| 34 | - add_action( 'init', [$this, 'init'] ); | |
| 35 | - add_action( 'wp_enqueue_scripts', [$this, 'enqueue_scripts'] ); | |
| 35 | + add_action( 'init', [ $this, 'init' ] ); | |
| 36 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); | |
| 36 | 37 | |
| 37 | - add_filter( 'betterdocs_layout_filename', [$this, 'layout_filename'], 10, 2 ); | |
| 38 | + /** | |
| 39 | + * Update The 'Edit Site' Url In FSE Mode For Betterdocs Templates Only | |
| 40 | + */ | |
| 41 | + if ( Helper::is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && wp_is_block_theme() ) { | |
| 42 | + add_action( 'admin_bar_menu', [ $this, 'fse_url_update' ], 41, 1 ); | |
| 43 | + } | |
| 38 | 44 | |
| 39 | - add_action( 'betterdocs_docs_before_social', [$this, 'article_reactions'] ); | |
| 45 | + add_filter( 'betterdocs_layout_filename', [ $this, 'layout_filename' ], 10, 2 ); | |
| 40 | 46 | |
| 41 | - add_action( 'betterdocs_before_render', [$this, 'before_render'], 11, 2 ); | |
| 42 | - add_action( 'betterdocs_after_render', [$this, 'after_render'], 11, 2 ); | |
| 47 | + add_action( 'betterdocs_docs_before_social', [ $this, 'article_reactions' ] ); | |
| 43 | 48 | |
| 44 | - //Removes Divi Script On Betterdocs Single Doc #1130, issue title -> ( Bug Fix | With the DIVI theme copy #Url button doesn't seem to work ) | |
| 45 | - add_action( 'wp_enqueue_scripts', [$this, 'dequeue_divi_script'], 99999 ); | |
| 49 | + add_action( 'betterdocs_before_render', [ $this, 'before_render' ], 11, 2 ); | |
| 50 | + add_action( 'betterdocs_after_render', [ $this, 'after_render' ], 11, 2 ); | |
| 46 | 51 | |
| 47 | - //Remove Saliant Theme Script For (Delay Javascript Exection), which causes issue with betterdocs sidebar toggle, issue number (#1234) | |
| 48 | - add_action( 'nectar_hook_before_body_close', [$this, 'dequeue_saliant_theme_script'], 99999 ); | |
| 52 | + //Remove Saliant Theme Script For (Delay Javascript Exection), which causes issue with betterdocs sidebar toggle, issue number (#1234) | |
| 53 | + add_action( 'nectar_hook_before_body_close', [ $this, 'dequeue_saliant_theme_script' ], 99999 ); | |
| 49 | 54 | |
| 50 | - //Remove our search selector from from Searchanise plugin for woocommerce, conflicts with betterdocs search (Bug Fix Card -> https://trello.com/c/lXzrtv2f/1313-client-issue-betterdocs-is-conflicting-with-the-searchanise-plugin) | |
| 51 | - add_filter( 'se_load_search_widgets', [$this, 'exclude_betterdocs_search'], 10, 1 ); | |
| 52 | - } | |
| 55 | + //Remove our search selector from from Searchanise plugin for woocommerce, conflicts with betterdocs search (Bug Fix Card -> https://trello.com/c/lXzrtv2f/1313-client-issue-betterdocs-is-conflicting-with-the-searchanise-plugin) | |
| 56 | + add_filter( 'se_load_search_widgets', [ $this, 'exclude_betterdocs_search' ], 10, 1 ); | |
| 53 | 57 | |
| 54 | - public function exclude_betterdocs_search( $options ) { | |
| 55 | - $options['search_input'] = $options['search_input'].':not(.betterdocs-search-field)'; | |
| 56 | - return $options; | |
| 57 | - } | |
| 58 | - public function before_render( $widget, $widget_type ) { | |
| 59 | - $this->widget_attributes = isset( $widget->attributes ) ? $widget->attributes : []; | |
| 60 | - $this->widget_type = $widget_type; | |
| 58 | + //Fix Betterdocs Search Issue With HostCluster Theme | |
| 59 | + if ( function_exists( 'hostcluster_search_filter' ) ) { | |
| 60 | + remove_filter( 'pre_get_posts', 'hostcluster_search_filter' ); | |
| 61 | + } | |
| 62 | + } | |
| 61 | 63 | |
| 62 | - /** | |
| 63 | - * This line of code will run for reactions shortcode, elementor widget and blocks | |
| 64 | - */ | |
| 65 | - if ( strpos( $widget->get_name(), 'reactions' ) !== false ) { | |
| 66 | - $this->localize_reactions_data(); | |
| 67 | - } | |
| 64 | + public function fse_url_update( &$wp_admin_bar ) { | |
| 65 | + $site_edit_node = $wp_admin_bar->get_node( 'site-editor' ); | |
| 68 | 66 | |
| 69 | - /** | |
| 70 | - * This line of code will run for Feedback form Shortcode, Elementor widget and blocks | |
| 71 | - */ | |
| 72 | - if ( strpos( $widget->get_name(), 'feedback_form' ) ) { | |
| 73 | - $this->localize_feedback_form_data(); | |
| 74 | - } | |
| 67 | + if ( empty( $site_edit_node ) ) { | |
| 68 | + return; | |
| 69 | + } | |
| 75 | 70 | |
| 76 | - add_filter( 'betterdocs_nested_terms_args', [$this, 'terms_args'], 11, 1 ); | |
| 77 | - add_filter( 'betterdocs_nested_docs_args', [$this, 'docs_args'], 11, 1 ); | |
| 78 | - } | |
| 71 | + if ( is_post_type_archive( 'docs' ) || is_tax( 'knowledge_base' ) || is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) || is_singular( 'docs' ) ) { | |
| 72 | + $href = isset( $site_edit_node->href ) ? $site_edit_node->href : ''; | |
| 73 | + if ( ! empty( $href ) ) { | |
| 74 | + $href = $href . '&lang=' . ICL_LANGUAGE_CODE; | |
| 75 | + $site_edit_node->href = $href; | |
| 76 | + $wp_admin_bar->add_node( $site_edit_node ); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + } | |
| 79 | 80 | |
| 80 | - public function dequeue_divi_script() { | |
| 81 | - if ( is_singular( 'docs' ) ) { | |
| 82 | - wp_dequeue_script( 'divi-custom-script' ); | |
| 83 | - } | |
| 84 | - } | |
| 81 | + public function exclude_betterdocs_search( $options ) { | |
| 82 | + $options['search_input'] = $options['search_input'] . ':not(.betterdocs-search-field)'; | |
| 83 | + return $options; | |
| 84 | + } | |
| 85 | + public function before_render( $widget, $widget_type ) { | |
| 86 | + $this->widget_attributes = isset( $widget->attributes ) ? $widget->attributes : []; | |
| 87 | + $this->widget_type = $widget_type; | |
| 85 | 88 | |
| 86 | - public function dequeue_saliant_theme_script() { | |
| 87 | - if ( is_singular( 'docs' ) ) { | |
| 88 | - wp_dequeue_script( 'salient-delay-js' ); | |
| 89 | - } | |
| 90 | - if ( is_tax( 'doc_category' ) ) { | |
| 91 | - wp_dequeue_script( 'salient-delay-js' ); | |
| 92 | - } | |
| 93 | - if ( is_tax( 'doc_tag' ) ) { | |
| 94 | - wp_dequeue_script( 'salient-delay-js' ); | |
| 95 | - } | |
| 96 | - } | |
| 89 | + /** | |
| 90 | + * This line of code will run for reactions shortcode, elementor widget and blocks | |
| 91 | + */ | |
| 92 | + if ( strpos( $widget->get_name(), 'reactions' ) !== false ) { | |
| 93 | + $this->localize_reactions_data(); | |
| 94 | + } | |
| 97 | 95 | |
| 98 | - public function after_render( $widget, $widget_type ) { | |
| 99 | - remove_filter( 'betterdocs_nested_terms_args', [$this, 'terms_args'], 11 ); | |
| 100 | - remove_filter( 'betterdocs_nested_docs_args', [$this, 'docs_args'], 11 ); | |
| 96 | + /** | |
| 97 | + * This line of code will run for Feedback form Shortcode, Elementor widget and blocks | |
| 98 | + */ | |
| 99 | + if ( strpos( $widget->get_name(), 'feedback_form' ) ) { | |
| 100 | + $this->localize_feedback_form_data(); | |
| 101 | + } | |
| 101 | 102 | |
| 102 | - $this->widget_attributes = []; | |
| 103 | - $this->widget_type = ''; | |
| 104 | - } | |
| 103 | + add_filter( 'betterdocs_nested_terms_args', [ $this, 'terms_args' ], 11, 1 ); | |
| 104 | + add_filter( 'betterdocs_nested_docs_args', [ $this, 'docs_args' ], 11, 1 ); | |
| 105 | + } | |
| 105 | 106 | |
| 106 | - public function terms_args( $args ) { | |
| 107 | - switch ( $this->widget_type ) { | |
| 108 | - case 'shortcode': | |
| 109 | - if ( isset( $this->widget_attributes['terms_orderby'] ) ) { | |
| 110 | - $args['orderby'] = $this->widget_attributes['terms_orderby']; | |
| 111 | - } | |
| 107 | + public function dequeue_saliant_theme_script() { | |
| 108 | + if ( is_singular( 'docs' ) || is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) ) { | |
| 109 | + wp_dequeue_script( 'salient-delay-js' ); | |
| 110 | + } | |
| 111 | + } | |
| 112 | 112 | |
| 113 | - if ( isset( $this->widget_attributes['terms_order'] ) ) { | |
| 114 | - $args['order'] = $this->widget_attributes['terms_order']; | |
| 115 | - } | |
| 116 | - break; | |
| 117 | - case 'blocks': | |
| 118 | - if ( isset( $this->widget_attributes['orderBy'] ) ) { | |
| 119 | - if ( $this->widget_attributes['orderBy'] == 'doc_category_order' ) { | |
| 120 | - $args['orderby'] = 'meta_value_num'; | |
| 121 | - $args['meta_key'] = $this->widget_attributes['orderBy']; | |
| 122 | - } else { | |
| 123 | - $args['orderby'] = $this->widget_attributes['orderBy']; | |
| 124 | - } | |
| 125 | - } | |
| 126 | - if ( isset( $this->widget_attributes['order'] ) ) { | |
| 127 | - $args['order'] = $this->widget_attributes['order']; | |
| 128 | - } | |
| 129 | - break; | |
| 130 | - case 'elementor': | |
| 131 | - $args['orderby'] = $this->widget_attributes['orderby']; | |
| 132 | - $args['order'] = $this->widget_attributes['order']; | |
| 133 | - break; | |
| 134 | - } | |
| 113 | + public function after_render( $widget, $widget_type ) { | |
| 114 | + remove_filter( 'betterdocs_nested_terms_args', [ $this, 'terms_args' ], 11 ); | |
| 115 | + remove_filter( 'betterdocs_nested_docs_args', [ $this, 'docs_args' ], 11 ); | |
| 135 | 116 | |
| 136 | - return $args; | |
| 137 | - } | |
| 117 | + $this->widget_attributes = []; | |
| 118 | + $this->widget_type = ''; | |
| 119 | + } | |
| 138 | 120 | |
| 139 | - public function docs_args( $args ) { | |
| 140 | - switch ( $this->widget_type ) { | |
| 141 | - case 'shortcode': | |
| 142 | - if ( isset( $this->widget_attributes['orderby'] ) ) { | |
| 143 | - $args['orderby'] = $this->widget_attributes['orderby']; | |
| 144 | - } | |
| 121 | + public function terms_args( $args ) { | |
| 122 | + switch ( $this->widget_type ) { | |
| 123 | + case 'shortcode': | |
| 124 | + if ( isset( $this->widget_attributes['terms_orderby'] ) ) { | |
| 125 | + $args['orderby'] = $this->widget_attributes['terms_orderby']; | |
| 126 | + } | |
| 145 | 127 | |
| 146 | - if ( isset( $this->widget_attributes['order'] ) ) { | |
| 147 | - $args['order'] = $this->widget_attributes['order']; | |
| 148 | - } | |
| 149 | - break; | |
| 150 | - case 'blocks': | |
| 151 | - if ( isset( $this->widget_attributes['postsOrderBy'] ) ) { | |
| 152 | - $args['orderby'] = $this->widget_attributes['postsOrderBy']; | |
| 153 | - } | |
| 154 | - if ( isset( $this->widget_attributes['postsOrder'] ) ) { | |
| 155 | - $args['order'] = $this->widget_attributes['postsOrder']; | |
| 156 | - } | |
| 128 | + if ( isset( $this->widget_attributes['terms_order'] ) ) { | |
| 129 | + $args['order'] = $this->widget_attributes['terms_order']; | |
| 130 | + } | |
| 131 | + break; | |
| 132 | + case 'blocks': | |
| 133 | + if ( isset( $this->widget_attributes['orderBy'] ) ) { | |
| 134 | + if ( $this->widget_attributes['orderBy'] == 'doc_category_order' ) { | |
| 135 | + $args['orderby'] = 'meta_value_num'; | |
| 136 | + $args['meta_key'] = $this->widget_attributes['orderBy']; | |
| 137 | + } else { | |
| 138 | + $args['orderby'] = $this->widget_attributes['orderBy']; | |
| 139 | + } | |
| 140 | + } | |
| 141 | + if ( isset( $this->widget_attributes['order'] ) ) { | |
| 142 | + $args['order'] = $this->widget_attributes['order']; | |
| 143 | + } | |
| 144 | + break; | |
| 145 | + case 'elementor': | |
| 146 | + $args['orderby'] = $this->widget_attributes['orderby']; | |
| 147 | + $args['order'] = $this->widget_attributes['order']; | |
| 148 | + break; | |
| 149 | + } | |
| 157 | 150 | |
| 158 | - //This is for archive category block only | |
| 159 | - if ( isset( $this->widget_attributes['orderby'] ) ) { | |
| 160 | - $args['orderby'] = $this->widget_attributes['orderby']; | |
| 161 | - } | |
| 162 | - if ( isset( $this->widget_attributes['order'] ) ) { | |
| 163 | - $args['order'] = $this->widget_attributes['order']; | |
| 164 | - } | |
| 165 | - break; | |
| 166 | - case 'elementor': | |
| 167 | - $args['orderby'] = $this->widget_attributes['post_orderby']; | |
| 168 | - $args['order'] = $this->widget_attributes['post_order']; | |
| 169 | - break; | |
| 170 | - } | |
| 151 | + return $args; | |
| 152 | + } | |
| 171 | 153 | |
| 172 | - return $args; | |
| 173 | - } | |
| 154 | + public function docs_args( $args ) { | |
| 155 | + switch ( $this->widget_type ) { | |
| 156 | + case 'shortcode': | |
| 157 | + if ( isset( $this->widget_attributes['orderby'] ) ) { | |
| 158 | + $args['orderby'] = $this->widget_attributes['orderby']; | |
| 159 | + } | |
| 174 | 160 | |
| 175 | - public function article_reactions() { | |
| 176 | - if ( $this->database->get_theme_mod( 'betterdocs_post_reactions', true ) ) { | |
| 177 | - echo do_shortcode( '[betterdocs_article_reactions]' ); | |
| 178 | - } | |
| 179 | - } | |
| 161 | + if ( isset( $this->widget_attributes['order'] ) ) { | |
| 162 | + $args['order'] = $this->widget_attributes['order']; | |
| 163 | + } | |
| 164 | + break; | |
| 165 | + case 'blocks': | |
| 166 | + if ( isset( $this->widget_attributes['postsOrderBy'] ) ) { | |
| 167 | + $args['orderby'] = $this->widget_attributes['postsOrderBy']; | |
| 168 | + } | |
| 169 | + if ( isset( $this->widget_attributes['postsOrder'] ) ) { | |
| 170 | + $args['order'] = $this->widget_attributes['postsOrder']; | |
| 171 | + } | |
| 180 | 172 | |
| 181 | - public function enqueue_scripts() { | |
| 182 | - if ( is_singular( 'docs' ) ) { | |
| 183 | - wp_enqueue_style( 'betterdocs-single' ); | |
| 184 | - wp_enqueue_script( 'clipboard' ); | |
| 185 | - } | |
| 173 | + //This is for archive category block only | |
| 174 | + if ( isset( $this->widget_attributes['orderby'] ) ) { | |
| 175 | + $args['orderby'] = $this->widget_attributes['orderby']; | |
| 176 | + } | |
| 177 | + if ( isset( $this->widget_attributes['order'] ) ) { | |
| 178 | + $args['order'] = $this->widget_attributes['order']; | |
| 179 | + } | |
| 180 | + break; | |
| 181 | + case 'elementor': | |
| 182 | + $args['orderby'] = $this->widget_attributes['post_orderby']; | |
| 183 | + $args['order'] = $this->widget_attributes['post_order']; | |
| 184 | + break; | |
| 185 | + } | |
| 186 | 186 | |
| 187 | - if ( is_post_type_archive( 'docs' ) ) { | |
| 188 | - wp_enqueue_style( 'betterdocs-category-grid' ); //category grid shortcode is supposed to enqueue this style, but this is called again to fix flicking of UI on Docs Page | |
| 189 | - wp_enqueue_style( 'betterdocs-docs' ); | |
| 190 | - } | |
| 187 | + return $args; | |
| 188 | + } | |
| 191 | 189 | |
| 192 | - if ( is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) ) { | |
| 193 | - wp_enqueue_style( 'betterdocs-doc_category' ); | |
| 194 | - } | |
| 190 | + public function article_reactions() { | |
| 191 | + $args = []; | |
| 192 | + $single_layout = $this->database->get_theme_mod( 'betterdocs_single_layout_select', true ); | |
| 193 | + $reactions = $this->database->get_theme_mod( 'betterdocs_post_reactions', true ); | |
| 195 | 194 | |
| 196 | - if ( is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) || is_singular( 'docs' ) ) { | |
| 197 | - wp_enqueue_style( 'simplebar' ); | |
| 198 | - wp_enqueue_script( 'simplebar' ); | |
| 199 | - wp_enqueue_script( 'betterdocs-category-grid' ); | |
| 200 | - } | |
| 195 | + // Collect reaction values and icons | |
| 196 | + $reactions_data = [ | |
| 197 | + 'happy' => 'betterdocs_post_reactions_happy', | |
| 198 | + 'happy_icon' => 'betterdocs_post_reactions_happy_icon', | |
| 199 | + 'normal' => 'betterdocs_post_reactions_normal', | |
| 200 | + 'normal_icon' => 'betterdocs_post_reactions_normal_icon', | |
| 201 | + 'sad' => 'betterdocs_post_reactions_sad', | |
| 202 | + 'sad_icon' => 'betterdocs_post_reactions_sad_icon' | |
| 203 | + ]; | |
| 201 | 204 | |
| 202 | - if ( is_post_type_archive( 'docs' ) || is_singular( 'docs' ) || is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) || is_tax( 'knowledge_base' ) ) { | |
| 203 | - wp_enqueue_script( 'betterdocs' ); | |
| 204 | - } | |
| 205 | - } | |
| 205 | + foreach ( $reactions_data as $key => $theme_mod ) { | |
| 206 | + $value = $this->database->get_theme_mod( $theme_mod, true ); | |
| 207 | + if ( $value ) { | |
| 208 | + $args[ $key ] = $value; | |
| 209 | + } else { | |
| 210 | + $args[ $key ] = false; | |
| 211 | + } | |
| 212 | + } | |
| 206 | 213 | |
| 207 | - public function layout_filename( $filename, $origin_layout ) { | |
| 208 | - $filename = ( $origin_layout === 'layout-2' ) ? 'default' : $filename; | |
| 209 | - return $filename; | |
| 210 | - } | |
| 214 | + // Build the attribute string for the shortcode | |
| 215 | + $attr = ''; | |
| 216 | + foreach ( $args as $key => $value ) { | |
| 217 | + $attr .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( $value ) ); | |
| 218 | + } | |
| 211 | 219 | |
| 212 | - public function init() { | |
| 213 | - $this->container->get( TemplateLoader::class )->init(); | |
| 220 | + // Render the shortcode based on layout and reactions availability | |
| 221 | + if ( $single_layout == 'layout-8' && $reactions ) { | |
| 222 | + echo do_shortcode( '[betterdocs_article_reactions layout="layout-2"' . $attr . ']' ); | |
| 223 | + } elseif ( $single_layout == 'layout-9' && $reactions ) { | |
| 224 | + echo ''; | |
| 225 | + } elseif ( $reactions ) { | |
| 226 | + echo do_shortcode( '[betterdocs_article_reactions' . $attr . ']' ); | |
| 227 | + } | |
| 228 | + } | |
| 214 | 229 | |
| 215 | - add_filter( 'betterdocs_articles_args', [$this, 'article_args'], 11, 3 ); | |
| 216 | - } | |
| 217 | 230 | |
| 218 | - public function article_args( $args, $term_id, $_origin_args ) { | |
| 219 | - if ( null == $term_id || isset( $args['orderby'] ) ) { | |
| 220 | - return $args; | |
| 221 | - } | |
| 231 | + public function enqueue_scripts() { | |
| 232 | + if ( is_singular( 'docs' ) ) { | |
| 233 | + wp_enqueue_style( 'betterdocs-single' ); | |
| 234 | + wp_enqueue_style( 'betterdocs-encyclopedia' ); | |
| 235 | + wp_enqueue_style( 'betterdocs-glossaries' ); | |
| 236 | + wp_enqueue_script( 'clipboard' ); | |
| 237 | + wp_enqueue_script( 'betterdocs-glossaries' ); | |
| 238 | + } | |
| 222 | 239 | |
| 223 | - $post__in = betterdocs()->query->get_docs_order_by_terms( $term_id ); | |
| 240 | + if ( is_post_type_archive( 'docs' ) ) { | |
| 241 | + wp_enqueue_style( 'betterdocs-category-grid' ); //category grid shortcode is supposed to enqueue this style, but this is called again to fix flicking of UI on Docs Page | |
| 242 | + wp_enqueue_style( 'betterdocs-docs' ); | |
| 243 | + } | |
| 224 | 244 | |
| 225 | - if ( ! empty( $post__in ) ) { | |
| 226 | - $args['orderby'] = 'post__in'; | |
| 227 | - $args['post__in'] = $post__in; | |
| 228 | - } | |
| 245 | + if ( is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) ) { | |
| 246 | + wp_enqueue_style( 'betterdocs-doc_category' ); | |
| 247 | + } | |
| 229 | 248 | |
| 230 | - return $args; | |
| 231 | - } | |
| 249 | + if ( is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) || is_singular( 'docs' ) ) { | |
| 250 | + wp_enqueue_style( 'simplebar' ); | |
| 251 | + wp_enqueue_script( 'simplebar' ); | |
| 252 | + wp_enqueue_script( 'betterdocs-category-grid' ); | |
| 253 | + } | |
| 232 | 254 | |
| 233 | - public function localize_reactions_data() { | |
| 234 | - $this->assets->localize( 'betterdocs-reactions', 'betterdocsReactionsConfig', [ | |
| 235 | - 'post_id' => get_the_ID(), | |
| 236 | - 'FEEDBACK' => [ | |
| 237 | - 'DISPLAY' => true, | |
| 238 | - 'TEXT' => esc_html__( 'How did you feel?', 'betterdocs' ), | |
| 239 | - 'SUCCESS' => esc_html__( 'Thanks for your feedback', 'betterdocs' ), | |
| 240 | - 'URL' => get_rest_url( null, '/betterdocs/v1/feedback' ) | |
| 241 | - ] | |
| 242 | - ] ); | |
| 243 | - } | |
| 255 | + if ( is_post_type_archive( 'docs' ) || is_singular( 'docs' ) || is_tax( 'doc_category' ) || is_tax( 'doc_tag' ) || is_tax( 'knowledge_base' ) ) { | |
| 256 | + wp_enqueue_script( 'betterdocs' ); | |
| 257 | + } | |
| 244 | 258 | |
| 245 | - public function localize_feedback_form_data() { | |
| 246 | - $this->assets->localize( 'betterdocs', 'betterdocsSubmitFormConfig', [ | |
| 247 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 248 | - 'post_id' => get_the_ID(), | |
| 249 | - 'nonce' => wp_create_nonce( 'betterdocs_submit_data' ) | |
| 250 | - ] ); | |
| 251 | - } | |
| 259 | + if ( is_tax( 'glossaries' ) ) { | |
| 260 | + wp_enqueue_style( 'betterdocs-encyclopedia' ); | |
| 261 | + wp_enqueue_style( 'betterdocs-single' ); | |
| 262 | + wp_enqueue_style( 'betterdocs-glossaries' ); | |
| 263 | + } | |
| 264 | + } | |
| 265 | + | |
| 266 | + public function layout_filename( $filename, $origin_layout ) { | |
| 267 | + $filename = ( $origin_layout === 'layout-2' ) ? 'default' : $filename; | |
| 268 | + return $filename; | |
| 269 | + } | |
| 270 | + | |
| 271 | + public function init() { | |
| 272 | + $this->container->get( TemplateLoader::class )->init(); | |
| 273 | + | |
| 274 | + add_filter( 'betterdocs_articles_args', [ $this, 'article_args' ], 11, 3 ); | |
| 275 | + } | |
| 276 | + | |
| 277 | + public function article_args( $args, $term_id, $_origin_args ) { | |
| 278 | + if ( null == $term_id || isset( $args['orderby'] ) ) { | |
| 279 | + return $args; | |
| 280 | + } | |
| 281 | + | |
| 282 | + $post__in = betterdocs()->query->get_docs_order_by_terms( $term_id ); | |
| 283 | + | |
| 284 | + if ( ! empty( $post__in ) ) { | |
| 285 | + $args['orderby'] = 'post__in'; | |
| 286 | + $args['post__in'] = $post__in; | |
| 287 | + } | |
| 288 | + | |
| 289 | + return $args; | |
| 290 | + } | |
| 291 | + | |
| 292 | + public function localize_reactions_data() { | |
| 293 | + $this->assets->localize( | |
| 294 | + 'betterdocs-reactions', | |
| 295 | + 'betterdocsReactionsConfig', | |
| 296 | + [ | |
| 297 | + 'post_id' => get_the_ID(), | |
| 298 | + 'FEEDBACK' => [ | |
| 299 | + 'DISPLAY' => true, | |
| 300 | + 'TEXT' => esc_html__( 'How did you feel?', 'betterdocs' ), | |
| 301 | + 'SUCCESS' => betterdocs()->settings->get( 'reaction_feedback_text', __( 'Thanks for your feedback', 'betterdocs' ) ), | |
| 302 | + 'URL' => get_rest_url( null, '/betterdocs/v1/feedback' ) | |
| 303 | + ] | |
| 304 | + ] | |
| 305 | + ); | |
| 306 | + } | |
| 307 | + | |
| 308 | + public function localize_feedback_form_data() { | |
| 309 | + $this->assets->localize( | |
| 310 | + 'betterdocs', | |
| 311 | + 'betterdocsSubmitFormConfig', | |
| 312 | + [ | |
| 313 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 314 | + 'post_id' => get_the_ID(), | |
| 315 | + 'nonce' => wp_create_nonce( 'betterdocs_submit_data' ) | |
| 316 | + ] | |
| 317 | + ); | |
| 318 | + } | |
| 252 | 319 | } |