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