diff --git a/includes/main.php b/includes/main.php index 5907a6d..7eceb94 100644 --- a/includes/main.php +++ b/includes/main.php @@ -76,7 +76,16 @@ function wzkb_knowledge( $args = array() ) { $output = '
'; // Are we trying to display a category? - $category = absint( $args['category'] ); + $category = intval( $args['category'] ); + + // if $category = -1, then get the current term object and set the category to the term ID. + if ( -1 === $category ) { + $term = get_queried_object(); + if ( isset( $term->term_id ) ) { + $category = $term->term_id; + } + } + $level = ( 0 < $category ) ? 1 : 0; $term_id = ( 0 < $category ) ? $category : 0; $nested_wrapper = ( isset( $args['nested_wrapper'] ) ) ? $args['nested_wrapper'] : true; diff --git a/includes/public/class-template-handler.php b/includes/public/class-template-handler.php new file mode 100644 index 0000000..f44e50b --- /dev/null +++ b/includes/public/class-template-handler.php @@ -0,0 +1,218 @@ + 'add_custom_archive_template', + 'index' => 'add_custom_index_template', + 'single' => 'add_custom_single_template', + 'taxonomy' => 'add_custom_taxonomy_template', + 'search' => 'add_custom_search_template', + ); + + foreach ( $template_types as $type => $callback ) { + add_filter( "{$type}_template_hierarchy", array( $this, $callback ) ); + } + } + + /** + * Add custom template for the wz_knowledgebase custom post type and wzkb_category taxonomy. + * + * @param array $templates Array of found templates. + * @param string $type Type of template (archive, single, taxonomy). + * @param string $post_type Post type or taxonomy name. + * @param string $template_name Template name to add. + * @return array Updated array of found templates. + */ + private function add_custom_template( $templates, $type, $post_type, $template_name ) { + if ( ( in_array( $type, array( 'archive', 'index', 'search' ), true ) ) || + ( 'single' === $type && is_singular( $post_type ) ) ) { + array_unshift( $templates, $template_name ); + } + return $templates; + } + + /** + * Add custom archive template for the wz_knowledgebase custom post type. + * + * @param array $templates Array of found templates. + * @return array Updated array of found templates. + */ + public function add_custom_archive_template( $templates ) { + if ( is_tax( 'wzkb_category' ) ) { + return $this->add_custom_template( $templates, 'archive', 'wzkb_category', 'taxonomy-wzkb_category' ); + } + if ( is_singular( 'wz_knowledgebase' ) ) { + return $this->add_custom_template( $templates, 'single', 'wz_knowledgebase', 'single-wz_knowledgebase' ); + } + if ( is_search() ) { + return $this->add_custom_template( $templates, 'search', 'wz_knowledgebase', 'wzkb-search' ); + } + return $this->add_custom_template( $templates, 'archive', 'wz_knowledgebase', 'archive-wz_knowledgebase' ); + } + + /** + * Add custom archive template for the wz_knowledgebase custom post type. + * + * @param array $templates Array of found templates. + * @return array Updated array of found templates. + */ + public function add_custom_index_template( $templates ) { + return $this->add_custom_archive_template( $templates ); + } + + /** + * Add custom single template for the wz_knowledgebase custom post type. + * + * @param array $templates Array of found templates. + * @return array Updated array of found templates. + */ + public function add_custom_single_template( $templates ) { + return $this->add_custom_template( $templates, 'single', 'wz_knowledgebase', 'single-wz_knowledgebase' ); + } + + /** + * Add custom taxonomy template for the wzkb_category taxonomy. + * + * @param array $templates Array of found templates. + * @return array Updated array of found templates. + */ + public function add_custom_taxonomy_template( $templates ) { + return $this->add_custom_template( $templates, 'archive', 'wzkb_category', 'taxonomy-wzkb_category' ); + } + + /** + * Add custom search template for the wz_knowledgebase custom post type. + * + * @param array $templates Array of found templates. + * @return array Updated array of found templates. + */ + public function add_custom_search_template( $templates ) { + return $this->add_custom_template( $templates, 'search', 'wz_knowledgebase', 'wzkb-search' ); + } + + /** + * Manage block templates for the wz_knowledgebase custom post type. + * + * @param array $query_result Array of found block templates. + * @param array $query Arguments to retrieve templates. + * @param string $template_type $template_type wp_template or wp_template_part. + * @return array Updated array of found block templates. + */ + public function manage_block_templates( $query_result, $query, $template_type ) { + if ( 'wp_template' !== $template_type ) { + return $query_result; + } + + global $post; + if ( ( empty( $post ) && ! is_admin() ) || ( ! empty( $post ) && 'wz_knowledgebase' !== $post->post_type ) ) { + return $query_result; + } + + $theme = wp_get_theme(); + $block_source = 'plugin'; + + $template_name = null; + + if ( is_singular( 'wz_knowledgebase' ) ) { + $template_name = 'single-wz_knowledgebase'; + } elseif ( is_post_type_archive( 'wz_knowledgebase' ) ) { + $template_name = is_search() ? 'wzkb-search' : 'archive-wz_knowledgebase'; + } elseif ( is_tax( 'wzkb_category' ) && ! is_search() ) { + $template_name = 'taxonomy-wzkb_category'; + } + + if ( $template_name ) { + $template_file_path = $theme->get_template_directory() . '/templates/' . $template_name . '.html'; + if ( file_exists( $template_file_path ) ) { + $block_source = 'theme'; + } else { + $template_file_path = __DIR__ . '/templates/' . $template_name . '.html'; + } + + $template_contents = self::get_template_content( $template_file_path ); + $template_contents = self::replace_placeholders_with_shortcodes( $template_contents ); + + $new_block = new \WP_Block_Template(); + $new_block->type = 'wp_template'; + $new_block->theme = $theme->stylesheet; + $new_block->slug = $template_name; + $new_block->id = 'wzkb//' . $template_name; + $new_block->title = 'Knowledge Base Template - ' . $template_name; + $new_block->description = ''; + $new_block->source = $block_source; + $new_block->status = 'publish'; + $new_block->has_theme_file = true; + $new_block->is_custom = true; + $new_block->content = $template_contents; + $new_block->post_types = array( 'wz_knowledgebase' ); + + $query_result[] = $new_block; + } + + return $query_result; + } + + /** + * Replaces placeholders with corresponding shortcode output. + * + * @param string $template_contents The template content containing placeholders. + * @return string The updated template with shortcodes replaced by their output. + */ + public static function replace_placeholders_with_shortcodes( $template_contents ) { + // Regular expression to match placeholders like {{shortcode param="value"}}. + $pattern = '/\{\{([a-zA-Z_]+)(.*?)\}\}/'; + + // Callback function to process each match. + $callback = function ( $matches ) { + $shortcode = trim( $matches[1] ); // Extract the shortcode name. + $params = trim( $matches[2] ); // Extract any parameters. + + // Construct the shortcode with the parameters. + if ( ! empty( $params ) ) { + $shortcode_output = '[' . $shortcode . ' ' . $params . ']'; + } else { + $shortcode_output = '[' . $shortcode . ']'; + } + + // Run the shortcode and return the output. + return do_shortcode( $shortcode_output ); + }; + + // Run the preg_replace_callback to find and replace all placeholders. + return preg_replace_callback( $pattern, $callback, $template_contents ); + } + + /** + * Get the content of a template file. + * + * @param string $template The template file to include. + * @return string The content of the template file. + */ + public static function get_template_content( $template ) { + ob_start(); + include $template; + return ob_get_clean(); + } +} + +new Template_Handler(); diff --git a/includes/public/css/wzkb-styles-rtl.css b/includes/public/css/wzkb-styles-rtl.css index be8217d..66db175 100644 --- a/includes/public/css/wzkb-styles-rtl.css +++ b/includes/public/css/wzkb-styles-rtl.css @@ -25,6 +25,7 @@ padding: 5px 1px; background-color: ghostwhite; margin-top: 30px; + margin-bottom: 0; } .wzkb h3.wzkb-section-name-level-0, .wzkb h3.wzkb-section-name-level-1 { diff --git a/includes/public/css/wzkb-styles-rtl.min.css b/includes/public/css/wzkb-styles-rtl.min.css index 9087bef..f4a4f1c 100644 --- a/includes/public/css/wzkb-styles-rtl.min.css +++ b/includes/public/css/wzkb-styles-rtl.min.css @@ -1 +1 @@ -.wzkb{width:100%;margin:10px 0;}.wzkb:after,.wzkb_master_section:after{content:"";display:table;clear:both;}.wzkb h3 a,.wzkb h4 a,.wzkb h3 a:visited,.wzkb h4 a:visited{color:#333;text-decoration:none;border:0;}.wzkb h3.wzkb_section_name{font-size:20px;}.wzkb-section-name-level-1{border-bottom:1px black dotted;border-top:1px black dotted;padding:5px 1px;background-color:ghostwhite;margin-top:30px;}.wzkb h3.wzkb-section-name-level-0,.wzkb h3.wzkb-section-name-level-1{font-size:28px;}.wzkb h3.wzkb-section-name-level-2{border-bottom:1px solid #666;font-size:24px;}.wzkb-articles-list{margin:0!important;padding:0!important;}.wzkb-articles-list li{margin:5px 0;list-style-type:none!important;}.wzkb-articles-list li:before{content:"\f123";display:inline-block;width:20px;height:20px;font-size:20px;line-height:1;font-family:dashicons;text-decoration:inherit;font-weight:400;font-style:normal;vertical-align:top;text-align:center;-webkit-transition:color .1s ease-in 0;transition:color .1s ease-in 0;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;margin-left:10px;word-wrap:break-word;color:#666;}.wzkb_section_count{display:block;float:left;margin:0;padding:2px;border:0;background:orange;border-radius:45%;text-align:center;font-size:70%;min-width:36px;}.section{clear:both;padding:0;margin:0;}.col{display:block;float:right;margin:1% 1.6% 1% 0;}.col:first-child{margin-right:0;}.group:before,.group:after{content:"";display:table;}.group:after{clear:both;}.group{zoom:1;}.wzkb_section.span_2_of_2{width:100%;}.wzkb_section.span_1_of_2{width:49.2%;}.wzkb_section.span_1_of_2:nth-child(2n+1){clear:right;margin-right:0;}.wzkb_section.span_3_of_3{width:100%;}.wzkb_section.span_2_of_3{width:66.13%;}.wzkb_section.span_1_of_3{width:32.26%;}.wzkb_section.span_1_of_3:nth-child(3n+1){clear:right;margin-right:0;}.wzkb_section.span_4_of_4{width:100%;}.wzkb_section.span_3_of_4{width:74.6%;}.wzkb_section.span_2_of_4{width:49.2%;}.wzkb_section.span_1_of_4{width:23.8%;}.wzkb_section.span_1_of_4:nth-child(4n+1){clear:right;margin-right:0;}.wzkb_section.span_5_of_5{width:100%;}.wzkb_section.span_4_of_5{width:79.68%;}.wzkb_section.span_3_of_5{width:59.36%;}.wzkb_section.span_2_of_5{width:39.04%;}.wzkb_section.span_1_of_5{width:18.72%;}.wzkb_section.span_1_of_5:nth-child(5n+1){clear:right;margin-right:0;}@media only screen and (max-width:480px){.col{margin:1% 0}.span_2_of_2,.span_1_of_2,.span_1_of_3,.span_2_of_3,.span_3_of_3,.span_1_of_4,.span_2_of_4,.span_3_of_4,.span_4_of_4,.span_1_of_5,.span_2_of_5,.span_3_of_5,.span_4_of_5,.span_5_of_5{width:100%}}#wzkb-content-primary{margin:0 auto;max-width:1366px;display:block;}#wzkb-sidebar-primary{float:left;margin-right:-100%;max-width:413px;position:relative;}@media only screen and (max-width:480px){#wzkb-sidebar-primary,#wzkb-content-primary{float:none!important;width:98%!important;margin-right:0}}#wzkb-sidebar-primary .widget{padding:20px;margin-top:10px;}#wzkb-sidebar-primary .widget ul{margin-right:10px;}#wzkb-sidebar-primary .widget ul li{margin-right:10px;list-style-type:disc;}.nav-previous{float:right;}.nav-next{float:left;}.wzkb-search-form{border:#ddd 1px solid;padding-right:10px;position:relative;padding-left:12px;margin:20px 0;font-size:1.3em;width:95%;}.wzkb-search-form label{width:100%;}input[type="search"].wzkb-search-field{border:none;color:#555;font-family:'Open Sans',sans-serif;font-size:1em;padding:10px 45px 10px 6px;width:100%;background:url(../images/search-icon.png) no-repeat 100% 5px;outline:none;}input[type="submit"].wzkb-search-submit{display:none;}.wzkb-search-form .screen-reader-text{position:absolute;clip:rect(0 0 0 0);}nav.pagination{width:100%;margin:15px 0;padding:15px 0;border-top:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;}.wzkb-alert{position:relative;padding:.75rem 1.25rem;margin-bottom:1rem;border:1px solid transparent;border-radius:.25rem;}.wzkb-alert-heading{color:inherit;}.wzkb-alert-link{font-weight:700;}.wzkb-alert-dismissible{padding-left:4rem;}.wzkb-alert-dismissible .close{position:absolute;top:0;left:0;padding:.75rem 1.25rem;color:inherit;}.wzkb-alert-primary{color:#004085;background-color:#cce5ff;border-color:#b8daff;}.wzkb-alert-primary hr{border-top-color:#9fcdff;}.wzkb-alert-primary .wzkb-alert-link{color:#002752;}.wzkb-alert-secondary{color:#383d41;background-color:#e2e3e5;border-color:#d6d8db;}.wzkb-alert-secondary hr{border-top-color:#c8cbcf;}.wzkb-alert-secondary .wzkb-alert-link{color:#202326;}.wzkb-alert-success{color:#155724;background-color:#d4edda;border-color:#c3e6cb;}.wzkb-alert-success hr{border-top-color:#b1dfbb;}.wzkb-alert-success .wzkb-alert-link{color:#0b2e13;}.wzkb-alert-info{color:#0c5460;background-color:#d1ecf1;border-color:#bee5eb;}.wzkb-alert-info hr{border-top-color:#abdde5;}.wzkb-alert-info .wzkb-alert-link{color:#062c33;}.wzkb-alert-warning{color:#856404;background-color:#fff3cd;border-color:#ffeeba;}.wzkb-alert-warning hr{border-top-color:#ffe8a1;}.wzkb-alert-warning .wzkb-alert-link{color:#533f03;}.wzkb-alert-danger{color:#721c24;background-color:#f8d7da;border-color:#f5c6cb;}.wzkb-alert-danger hr{border-top-color:#f1b0b7;}.wzkb-alert-danger .wzkb-alert-link{color:#491217;}.wzkb-alert-light{color:#818182;background-color:#fefefe;border-color:#fdfdfe;}.wzkb-alert-light hr{border-top-color:#ececf6;}.wzkb-alert-light .wzkb-alert-link{color:#686868;}.wzkb-alert-dark{color:#1b1e21;background-color:#d6d8d9;border-color:#c6c8ca;}.wzkb-alert-dark hr{border-top-color:#b9bbbe;}.wzkb-alert-dark .wzkb-alert-link{color:#040505;}.wzkb-related-articles{clear:both;}.wzkb-related-articles ul{list-style-type:none;margin:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));grid-column-gap:25px;column-gap:25px;}.wzkb-related-articles ul li{width:auto;}.wzkb-related-articles img,.wzkb-related-articles a{display:block;} \ No newline at end of file +.wzkb{width:100%;margin:10px 0;}.wzkb:after,.wzkb_master_section:after{content:"";display:table;clear:both;}.wzkb h3 a,.wzkb h4 a,.wzkb h3 a:visited,.wzkb h4 a:visited{color:#333;text-decoration:none;border:0;}.wzkb h3.wzkb_section_name{font-size:20px;}.wzkb-section-name-level-1{border-bottom:1px black dotted;border-top:1px black dotted;padding:5px 1px;background-color:ghostwhite;margin-top:30px;margin-bottom:0;}.wzkb h3.wzkb-section-name-level-0,.wzkb h3.wzkb-section-name-level-1{font-size:28px;}.wzkb h3.wzkb-section-name-level-2{border-bottom:1px solid #666;font-size:24px;}.wzkb-articles-list{margin:0!important;padding:0!important;}.wzkb-articles-list li{margin:5px 0;list-style-type:none!important;}.wzkb-articles-list li:before{content:"\f123";display:inline-block;width:20px;height:20px;font-size:20px;line-height:1;font-family:dashicons;text-decoration:inherit;font-weight:400;font-style:normal;vertical-align:top;text-align:center;-webkit-transition:color .1s ease-in 0;transition:color .1s ease-in 0;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;margin-left:10px;word-wrap:break-word;color:#666;}.wzkb_section_count{display:block;float:left;margin:0;padding:2px;border:0;background:orange;border-radius:45%;text-align:center;font-size:70%;min-width:36px;}.section{clear:both;padding:0;margin:0;}.col{display:block;float:right;margin:1% 1.6% 1% 0;}.col:first-child{margin-right:0;}.group:before,.group:after{content:"";display:table;}.group:after{clear:both;}.group{zoom:1;}.wzkb_section.span_2_of_2{width:100%;}.wzkb_section.span_1_of_2{width:49.2%;}.wzkb_section.span_1_of_2:nth-child(2n+1){clear:right;margin-right:0;}.wzkb_section.span_3_of_3{width:100%;}.wzkb_section.span_2_of_3{width:66.13%;}.wzkb_section.span_1_of_3{width:32.26%;}.wzkb_section.span_1_of_3:nth-child(3n+1){clear:right;margin-right:0;}.wzkb_section.span_4_of_4{width:100%;}.wzkb_section.span_3_of_4{width:74.6%;}.wzkb_section.span_2_of_4{width:49.2%;}.wzkb_section.span_1_of_4{width:23.8%;}.wzkb_section.span_1_of_4:nth-child(4n+1){clear:right;margin-right:0;}.wzkb_section.span_5_of_5{width:100%;}.wzkb_section.span_4_of_5{width:79.68%;}.wzkb_section.span_3_of_5{width:59.36%;}.wzkb_section.span_2_of_5{width:39.04%;}.wzkb_section.span_1_of_5{width:18.72%;}.wzkb_section.span_1_of_5:nth-child(5n+1){clear:right;margin-right:0;}@media only screen and (max-width:480px){.col{margin:1% 0}.span_2_of_2,.span_1_of_2,.span_1_of_3,.span_2_of_3,.span_3_of_3,.span_1_of_4,.span_2_of_4,.span_3_of_4,.span_4_of_4,.span_1_of_5,.span_2_of_5,.span_3_of_5,.span_4_of_5,.span_5_of_5{width:100%}}#wzkb-content-primary{margin:0 auto;max-width:1366px;display:block;}#wzkb-sidebar-primary{float:left;margin-right:-100%;max-width:413px;position:relative;}@media only screen and (max-width:480px){#wzkb-sidebar-primary,#wzkb-content-primary{float:none!important;width:98%!important;margin-right:0}}#wzkb-sidebar-primary .widget{padding:20px;margin-top:10px;}#wzkb-sidebar-primary .widget ul{margin-right:10px;}#wzkb-sidebar-primary .widget ul li{margin-right:10px;list-style-type:disc;}.nav-previous{float:right;}.nav-next{float:left;}.wzkb-search-form{border:#ddd 1px solid;padding-right:10px;position:relative;padding-left:12px;margin:20px 0;font-size:1.3em;width:95%;}.wzkb-search-form label{width:100%;}input[type="search"].wzkb-search-field{border:none;color:#555;font-family:'Open Sans',sans-serif;font-size:1em;padding:10px 45px 10px 6px;width:100%;background:url(../images/search-icon.png) no-repeat 100% 5px;outline:none;}input[type="submit"].wzkb-search-submit{display:none;}.wzkb-search-form .screen-reader-text{position:absolute;clip:rect(0 0 0 0);}nav.pagination{width:100%;margin:15px 0;padding:15px 0;border-top:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;}.wzkb-alert{position:relative;padding:.75rem 1.25rem;margin-bottom:1rem;border:1px solid transparent;border-radius:.25rem;}.wzkb-alert-heading{color:inherit;}.wzkb-alert-link{font-weight:700;}.wzkb-alert-dismissible{padding-left:4rem;}.wzkb-alert-dismissible .close{position:absolute;top:0;left:0;padding:.75rem 1.25rem;color:inherit;}.wzkb-alert-primary{color:#004085;background-color:#cce5ff;border-color:#b8daff;}.wzkb-alert-primary hr{border-top-color:#9fcdff;}.wzkb-alert-primary .wzkb-alert-link{color:#002752;}.wzkb-alert-secondary{color:#383d41;background-color:#e2e3e5;border-color:#d6d8db;}.wzkb-alert-secondary hr{border-top-color:#c8cbcf;}.wzkb-alert-secondary .wzkb-alert-link{color:#202326;}.wzkb-alert-success{color:#155724;background-color:#d4edda;border-color:#c3e6cb;}.wzkb-alert-success hr{border-top-color:#b1dfbb;}.wzkb-alert-success .wzkb-alert-link{color:#0b2e13;}.wzkb-alert-info{color:#0c5460;background-color:#d1ecf1;border-color:#bee5eb;}.wzkb-alert-info hr{border-top-color:#abdde5;}.wzkb-alert-info .wzkb-alert-link{color:#062c33;}.wzkb-alert-warning{color:#856404;background-color:#fff3cd;border-color:#ffeeba;}.wzkb-alert-warning hr{border-top-color:#ffe8a1;}.wzkb-alert-warning .wzkb-alert-link{color:#533f03;}.wzkb-alert-danger{color:#721c24;background-color:#f8d7da;border-color:#f5c6cb;}.wzkb-alert-danger hr{border-top-color:#f1b0b7;}.wzkb-alert-danger .wzkb-alert-link{color:#491217;}.wzkb-alert-light{color:#818182;background-color:#fefefe;border-color:#fdfdfe;}.wzkb-alert-light hr{border-top-color:#ececf6;}.wzkb-alert-light .wzkb-alert-link{color:#686868;}.wzkb-alert-dark{color:#1b1e21;background-color:#d6d8d9;border-color:#c6c8ca;}.wzkb-alert-dark hr{border-top-color:#b9bbbe;}.wzkb-alert-dark .wzkb-alert-link{color:#040505;}.wzkb-related-articles{clear:both;}.wzkb-related-articles ul{list-style-type:none;margin:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));grid-column-gap:25px;column-gap:25px;}.wzkb-related-articles ul li{width:auto;}.wzkb-related-articles img,.wzkb-related-articles a{display:block;} \ No newline at end of file diff --git a/includes/public/css/wzkb-styles.css b/includes/public/css/wzkb-styles.css index 94bef93..39ce399 100644 --- a/includes/public/css/wzkb-styles.css +++ b/includes/public/css/wzkb-styles.css @@ -25,6 +25,7 @@ padding: 5px 1px; background-color: ghostwhite; margin-top: 30px; + margin-bottom: 0; } .wzkb h3.wzkb-section-name-level-0, .wzkb h3.wzkb-section-name-level-1 { diff --git a/includes/public/css/wzkb-styles.min.css b/includes/public/css/wzkb-styles.min.css index cd4b0af..46c1d49 100644 --- a/includes/public/css/wzkb-styles.min.css +++ b/includes/public/css/wzkb-styles.min.css @@ -1 +1 @@ -.wzkb{width:100%;margin:10px 0;}.wzkb:after,.wzkb_master_section:after{content:"";display:table;clear:both;}.wzkb h3 a,.wzkb h4 a,.wzkb h3 a:visited,.wzkb h4 a:visited{color:#333;text-decoration:none;border:0;}.wzkb h3.wzkb_section_name{font-size:20px;}.wzkb-section-name-level-1{border-bottom:1px black dotted;border-top:1px black dotted;padding:5px 1px;background-color:ghostwhite;margin-top:30px;}.wzkb h3.wzkb-section-name-level-0,.wzkb h3.wzkb-section-name-level-1{font-size:28px;}.wzkb h3.wzkb-section-name-level-2{border-bottom:1px solid #666;font-size:24px;}.wzkb-articles-list{margin:0!important;padding:0!important;}.wzkb-articles-list li{margin:5px 0;list-style-type:none!important;}.wzkb-articles-list li:before{content:"\f123";display:inline-block;width:20px;height:20px;font-size:20px;line-height:1;font-family:dashicons;text-decoration:inherit;font-weight:400;font-style:normal;vertical-align:top;text-align:center;-webkit-transition:color .1s ease-in 0;transition:color .1s ease-in 0;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;margin-right:10px;word-wrap:break-word;color:#666;}.wzkb_section_count{display:block;float:right;margin:0;padding:2px;border:0;background:orange;border-radius:45%;text-align:center;font-size:70%;min-width:36px;}.section{clear:both;padding:0;margin:0;}.col{display:block;float:left;margin:1% 0 1% 1.6%;}.col:first-child{margin-left:0;}.group:before,.group:after{content:"";display:table;}.group:after{clear:both;}.group{zoom:1;}.wzkb_section.span_2_of_2{width:100%;}.wzkb_section.span_1_of_2{width:49.2%;}.wzkb_section.span_1_of_2:nth-child(2n+1){clear:left;margin-left:0;}.wzkb_section.span_3_of_3{width:100%;}.wzkb_section.span_2_of_3{width:66.13%;}.wzkb_section.span_1_of_3{width:32.26%;}.wzkb_section.span_1_of_3:nth-child(3n+1){clear:left;margin-left:0;}.wzkb_section.span_4_of_4{width:100%;}.wzkb_section.span_3_of_4{width:74.6%;}.wzkb_section.span_2_of_4{width:49.2%;}.wzkb_section.span_1_of_4{width:23.8%;}.wzkb_section.span_1_of_4:nth-child(4n+1){clear:left;margin-left:0;}.wzkb_section.span_5_of_5{width:100%;}.wzkb_section.span_4_of_5{width:79.68%;}.wzkb_section.span_3_of_5{width:59.36%;}.wzkb_section.span_2_of_5{width:39.04%;}.wzkb_section.span_1_of_5{width:18.72%;}.wzkb_section.span_1_of_5:nth-child(5n+1){clear:left;margin-left:0;}@media only screen and (max-width:480px){.col{margin:1% 0}.span_2_of_2,.span_1_of_2,.span_1_of_3,.span_2_of_3,.span_3_of_3,.span_1_of_4,.span_2_of_4,.span_3_of_4,.span_4_of_4,.span_1_of_5,.span_2_of_5,.span_3_of_5,.span_4_of_5,.span_5_of_5{width:100%}}#wzkb-content-primary{margin:0 auto;max-width:1366px;display:block;}#wzkb-sidebar-primary{float:right;margin-left:-100%;max-width:413px;position:relative;}@media only screen and (max-width:480px){#wzkb-sidebar-primary,#wzkb-content-primary{float:none!important;width:98%!important;margin-left:0}}#wzkb-sidebar-primary .widget{padding:20px;margin-top:10px;}#wzkb-sidebar-primary .widget ul{margin-left:10px;}#wzkb-sidebar-primary .widget ul li{margin-left:10px;list-style-type:disc;}.nav-previous{float:left;}.nav-next{float:right;}.wzkb-search-form{border:#ddd 1px solid;padding-left:10px;position:relative;padding-right:12px;margin:20px 0;font-size:1.3em;width:95%;}.wzkb-search-form label{width:100%;}input[type="search"].wzkb-search-field{border:none;color:#555;font-family:'Open Sans',sans-serif;font-size:1em;padding:10px 6px 10px 45px;width:100%;background:url(../images/search-icon.png) no-repeat 0 5px;outline:none;}input[type="submit"].wzkb-search-submit{display:none;}.wzkb-search-form .screen-reader-text{position:absolute;clip:rect(0 0 0 0);}nav.pagination{width:100%;margin:15px 0;padding:15px 0;border-top:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;}.wzkb-alert{position:relative;padding:.75rem 1.25rem;margin-bottom:1rem;border:1px solid transparent;border-radius:.25rem;}.wzkb-alert-heading{color:inherit;}.wzkb-alert-link{font-weight:700;}.wzkb-alert-dismissible{padding-right:4rem;}.wzkb-alert-dismissible .close{position:absolute;top:0;right:0;padding:.75rem 1.25rem;color:inherit;}.wzkb-alert-primary{color:#004085;background-color:#cce5ff;border-color:#b8daff;}.wzkb-alert-primary hr{border-top-color:#9fcdff;}.wzkb-alert-primary .wzkb-alert-link{color:#002752;}.wzkb-alert-secondary{color:#383d41;background-color:#e2e3e5;border-color:#d6d8db;}.wzkb-alert-secondary hr{border-top-color:#c8cbcf;}.wzkb-alert-secondary .wzkb-alert-link{color:#202326;}.wzkb-alert-success{color:#155724;background-color:#d4edda;border-color:#c3e6cb;}.wzkb-alert-success hr{border-top-color:#b1dfbb;}.wzkb-alert-success .wzkb-alert-link{color:#0b2e13;}.wzkb-alert-info{color:#0c5460;background-color:#d1ecf1;border-color:#bee5eb;}.wzkb-alert-info hr{border-top-color:#abdde5;}.wzkb-alert-info .wzkb-alert-link{color:#062c33;}.wzkb-alert-warning{color:#856404;background-color:#fff3cd;border-color:#ffeeba;}.wzkb-alert-warning hr{border-top-color:#ffe8a1;}.wzkb-alert-warning .wzkb-alert-link{color:#533f03;}.wzkb-alert-danger{color:#721c24;background-color:#f8d7da;border-color:#f5c6cb;}.wzkb-alert-danger hr{border-top-color:#f1b0b7;}.wzkb-alert-danger .wzkb-alert-link{color:#491217;}.wzkb-alert-light{color:#818182;background-color:#fefefe;border-color:#fdfdfe;}.wzkb-alert-light hr{border-top-color:#ececf6;}.wzkb-alert-light .wzkb-alert-link{color:#686868;}.wzkb-alert-dark{color:#1b1e21;background-color:#d6d8d9;border-color:#c6c8ca;}.wzkb-alert-dark hr{border-top-color:#b9bbbe;}.wzkb-alert-dark .wzkb-alert-link{color:#040505;}.wzkb-related-articles{clear:both;}.wzkb-related-articles ul{list-style-type:none;margin:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));grid-column-gap:25px;column-gap:25px;}.wzkb-related-articles ul li{width:auto;}.wzkb-related-articles img,.wzkb-related-articles a{display:block;} \ No newline at end of file +.wzkb{width:100%;margin:10px 0;}.wzkb:after,.wzkb_master_section:after{content:"";display:table;clear:both;}.wzkb h3 a,.wzkb h4 a,.wzkb h3 a:visited,.wzkb h4 a:visited{color:#333;text-decoration:none;border:0;}.wzkb h3.wzkb_section_name{font-size:20px;}.wzkb-section-name-level-1{border-bottom:1px black dotted;border-top:1px black dotted;padding:5px 1px;background-color:ghostwhite;margin-top:30px;margin-bottom:0;}.wzkb h3.wzkb-section-name-level-0,.wzkb h3.wzkb-section-name-level-1{font-size:28px;}.wzkb h3.wzkb-section-name-level-2{border-bottom:1px solid #666;font-size:24px;}.wzkb-articles-list{margin:0!important;padding:0!important;}.wzkb-articles-list li{margin:5px 0;list-style-type:none!important;}.wzkb-articles-list li:before{content:"\f123";display:inline-block;width:20px;height:20px;font-size:20px;line-height:1;font-family:dashicons;text-decoration:inherit;font-weight:400;font-style:normal;vertical-align:top;text-align:center;-webkit-transition:color .1s ease-in 0;transition:color .1s ease-in 0;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;margin-right:10px;word-wrap:break-word;color:#666;}.wzkb_section_count{display:block;float:right;margin:0;padding:2px;border:0;background:orange;border-radius:45%;text-align:center;font-size:70%;min-width:36px;}.section{clear:both;padding:0;margin:0;}.col{display:block;float:left;margin:1% 0 1% 1.6%;}.col:first-child{margin-left:0;}.group:before,.group:after{content:"";display:table;}.group:after{clear:both;}.group{zoom:1;}.wzkb_section.span_2_of_2{width:100%;}.wzkb_section.span_1_of_2{width:49.2%;}.wzkb_section.span_1_of_2:nth-child(2n+1){clear:left;margin-left:0;}.wzkb_section.span_3_of_3{width:100%;}.wzkb_section.span_2_of_3{width:66.13%;}.wzkb_section.span_1_of_3{width:32.26%;}.wzkb_section.span_1_of_3:nth-child(3n+1){clear:left;margin-left:0;}.wzkb_section.span_4_of_4{width:100%;}.wzkb_section.span_3_of_4{width:74.6%;}.wzkb_section.span_2_of_4{width:49.2%;}.wzkb_section.span_1_of_4{width:23.8%;}.wzkb_section.span_1_of_4:nth-child(4n+1){clear:left;margin-left:0;}.wzkb_section.span_5_of_5{width:100%;}.wzkb_section.span_4_of_5{width:79.68%;}.wzkb_section.span_3_of_5{width:59.36%;}.wzkb_section.span_2_of_5{width:39.04%;}.wzkb_section.span_1_of_5{width:18.72%;}.wzkb_section.span_1_of_5:nth-child(5n+1){clear:left;margin-left:0;}@media only screen and (max-width:480px){.col{margin:1% 0}.span_2_of_2,.span_1_of_2,.span_1_of_3,.span_2_of_3,.span_3_of_3,.span_1_of_4,.span_2_of_4,.span_3_of_4,.span_4_of_4,.span_1_of_5,.span_2_of_5,.span_3_of_5,.span_4_of_5,.span_5_of_5{width:100%}}#wzkb-content-primary{margin:0 auto;max-width:1366px;display:block;}#wzkb-sidebar-primary{float:right;margin-left:-100%;max-width:413px;position:relative;}@media only screen and (max-width:480px){#wzkb-sidebar-primary,#wzkb-content-primary{float:none!important;width:98%!important;margin-left:0}}#wzkb-sidebar-primary .widget{padding:20px;margin-top:10px;}#wzkb-sidebar-primary .widget ul{margin-left:10px;}#wzkb-sidebar-primary .widget ul li{margin-left:10px;list-style-type:disc;}.nav-previous{float:left;}.nav-next{float:right;}.wzkb-search-form{border:#ddd 1px solid;padding-left:10px;position:relative;padding-right:12px;margin:20px 0;font-size:1.3em;width:95%;}.wzkb-search-form label{width:100%;}input[type="search"].wzkb-search-field{border:none;color:#555;font-family:'Open Sans',sans-serif;font-size:1em;padding:10px 6px 10px 45px;width:100%;background:url(../images/search-icon.png) no-repeat 0 5px;outline:none;}input[type="submit"].wzkb-search-submit{display:none;}.wzkb-search-form .screen-reader-text{position:absolute;clip:rect(0 0 0 0);}nav.pagination{width:100%;margin:15px 0;padding:15px 0;border-top:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;}.wzkb-alert{position:relative;padding:.75rem 1.25rem;margin-bottom:1rem;border:1px solid transparent;border-radius:.25rem;}.wzkb-alert-heading{color:inherit;}.wzkb-alert-link{font-weight:700;}.wzkb-alert-dismissible{padding-right:4rem;}.wzkb-alert-dismissible .close{position:absolute;top:0;right:0;padding:.75rem 1.25rem;color:inherit;}.wzkb-alert-primary{color:#004085;background-color:#cce5ff;border-color:#b8daff;}.wzkb-alert-primary hr{border-top-color:#9fcdff;}.wzkb-alert-primary .wzkb-alert-link{color:#002752;}.wzkb-alert-secondary{color:#383d41;background-color:#e2e3e5;border-color:#d6d8db;}.wzkb-alert-secondary hr{border-top-color:#c8cbcf;}.wzkb-alert-secondary .wzkb-alert-link{color:#202326;}.wzkb-alert-success{color:#155724;background-color:#d4edda;border-color:#c3e6cb;}.wzkb-alert-success hr{border-top-color:#b1dfbb;}.wzkb-alert-success .wzkb-alert-link{color:#0b2e13;}.wzkb-alert-info{color:#0c5460;background-color:#d1ecf1;border-color:#bee5eb;}.wzkb-alert-info hr{border-top-color:#abdde5;}.wzkb-alert-info .wzkb-alert-link{color:#062c33;}.wzkb-alert-warning{color:#856404;background-color:#fff3cd;border-color:#ffeeba;}.wzkb-alert-warning hr{border-top-color:#ffe8a1;}.wzkb-alert-warning .wzkb-alert-link{color:#533f03;}.wzkb-alert-danger{color:#721c24;background-color:#f8d7da;border-color:#f5c6cb;}.wzkb-alert-danger hr{border-top-color:#f1b0b7;}.wzkb-alert-danger .wzkb-alert-link{color:#491217;}.wzkb-alert-light{color:#818182;background-color:#fefefe;border-color:#fdfdfe;}.wzkb-alert-light hr{border-top-color:#ececf6;}.wzkb-alert-light .wzkb-alert-link{color:#686868;}.wzkb-alert-dark{color:#1b1e21;background-color:#d6d8d9;border-color:#c6c8ca;}.wzkb-alert-dark hr{border-top-color:#b9bbbe;}.wzkb-alert-dark .wzkb-alert-link{color:#040505;}.wzkb-related-articles{clear:both;}.wzkb-related-articles ul{list-style-type:none;margin:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));grid-column-gap:25px;column-gap:25px;}.wzkb-related-articles ul li{width:auto;}.wzkb-related-articles img,.wzkb-related-articles a{display:block;} \ No newline at end of file diff --git a/includes/public/public.php b/includes/public/public.php index e44487e..d8f7290 100644 --- a/includes/public/public.php +++ b/includes/public/public.php @@ -49,9 +49,24 @@ function wpkb_enqueue_styles() { wp_enqueue_style( 'wzkb_styles' ); } } + if ( wzkb_get_option( 'include_styles' ) ) { + if ( is_singular( 'wz_knowledgebase' ) || is_post_type_archive( 'wz_knowledgebase' ) || ( is_tax( 'wzkb_category' ) && ! is_search() ) ) { + wp_enqueue_style( 'wzkb_styles' ); + } + } wp_add_inline_style( 'wzkb_styles', esc_html( wzkb_get_option( 'custom_css' ) ) ); + // Add custom styles for taxonomy archives. + if ( is_tax( 'wzkb_category' ) ) { + $custom_css = ' + .wzkb-section-name-level-1 { + display: none; + } + '; + wp_add_inline_style( 'wzkb_styles', $custom_css ); + } + if ( wzkb_get_option( 'show_sidebar' ) ) { $extra_styles = '#wzkb-sidebar-primary{width:25%;}#wzkb-content-primary{width:75%;float:left;}'; wp_add_inline_style( 'wzkb_styles', $extra_styles ); @@ -74,6 +89,10 @@ function wpkb_enqueue_styles() { * @return string Modified Archive Template location */ function wzkb_archive_template( $template ) { + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { + return $template; + } + $template_name = null; if ( is_singular( 'wz_knowledgebase' ) ) { @@ -105,18 +124,58 @@ function wzkb_archive_template( $template ) { add_filter( 'template_include', 'wzkb_archive_template' ); +/** + * Helper function to build a WP_Block_Template object. + * + * @param string $theme The source of the template (plugin name in this case). + * @param string $template_slug Template slug for the block template. + * @param string $template_file Path to the template file. + * @param string $template_type Template type (either 'wp_template' or 'wp_template_part'). + * + * @return WP_Block_Template|WP_Error The block template object or WP_Error on failure. + */ +function wzkb_build_block_template_result( $theme, $template_slug, $template_file, $template_type ) { + // Use wp_remote_get to retrieve the content of the template file. + $response = wp_remote_get( $template_file ); + + // Check for errors in the response. + if ( is_wp_error( $response ) ) { + return $response; // Return the error if there's an issue. + } + + $content = wp_remote_retrieve_body( $response ); // Get the body content of the response. + + // Create a new WP_Block_Template object. + $template = new WP_Block_Template(); + $template->id = $theme . '//' . $template_slug; + $template->theme = $theme; + $template->content = $content; + $template->slug = $template_slug; + $template->source = 'plugin'; + $template->type = $template_type; + $template->title = ucfirst( str_replace( '-', ' ', $template_slug ) ); + $template->status = 'publish'; + $template->has_theme_file = true; + $template->is_custom = true; + $template->modified = null; // Adjust as necessary. + + return $template; +} + + /** * For knowledge base search results, set posts_per_page 10. * * @since 1.1.0 * - * @param object $query The search query object. - * @return object $query Updated search query object + * @param \WP_Query $query The search query object. + * @return \WP_Query $query Updated search query object */ function wzkb_posts_per_search_page( $query ) { if ( ! is_admin() && $query->is_search() && isset( $query->query_vars['post_type'] ) && 'wz_knowledgebase' === $query->query_vars['post_type'] ) { - $query->query_vars['posts_per_page'] = 10; + $query->set( 'posts_per_page', 12 ); + $query->set( 'post_type', 'wz_knowledgebase' ); } return $query; diff --git a/includes/public/templates/archive-wz_knowledgebase.html b/includes/public/templates/archive-wz_knowledgebase.html new file mode 100644 index 0000000..46fe006 --- /dev/null +++ b/includes/public/templates/archive-wz_knowledgebase.html @@ -0,0 +1,20 @@ + + + +
+ +
+ + {{kbsearch}} + + + {{kbbreadcrumb}} + + + {{knowledgebase}} +
+ +
+ + + diff --git a/includes/public/templates/single-wz_knowledgebase.html b/includes/public/templates/single-wz_knowledgebase.html new file mode 100644 index 0000000..29e2853 --- /dev/null +++ b/includes/public/templates/single-wz_knowledgebase.html @@ -0,0 +1,100 @@ + + + +
+ +
+ + +
+ + {{kbsearch}} + + + {{kbbreadcrumb}} + + + + + +
+ +
+ + + +
+ + +
+ + + +
+ + + +
+

Comments

+ + + + + + +
+ +
+ + +
+ + +
+ +
+ + + + + +
+ + +
+ +
+ + + + + + + + + + +
+ + + + + + +
+ + +
+ +
+ + + \ No newline at end of file diff --git a/includes/public/templates/taxonomy-wzkb_category.html b/includes/public/templates/taxonomy-wzkb_category.html new file mode 100644 index 0000000..533164c --- /dev/null +++ b/includes/public/templates/taxonomy-wzkb_category.html @@ -0,0 +1,20 @@ + + + +
+ +
+ + {{kbsearch}} + + + {{kbbreadcrumb}} + + + {{knowledgebase category="-1"}} +
+ +
+ + + diff --git a/includes/public/templates/wzkb-search.html b/includes/public/templates/wzkb-search.html new file mode 100644 index 0000000..63276b5 --- /dev/null +++ b/includes/public/templates/wzkb-search.html @@ -0,0 +1,57 @@ + + + +
+ + + +
+ + {{kbsearch}} +
+ + + +
+ +

No posts were found.

+ + + + +
+ + + + +
+ + + + + + + +
+ + + + + + + + + + + + +
+ +
+ +
+ + + \ No newline at end of file diff --git a/includes/search.php b/includes/search.php index 791f56f..b71809d 100644 --- a/includes/search.php +++ b/includes/search.php @@ -25,16 +25,14 @@ */ function wzkb_get_search_form( $echo_output = true ) { - $form = ' - - '; + $form = ''; /** * Filter the HTML output of the search form. @@ -50,8 +48,8 @@ function wzkb_get_search_form( $echo_output = true ) { } if ( $echo_output ) { - echo $result; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo trim( $result ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } else { - return $result; + return trim( $result ); } } diff --git a/includes/shortcode.php b/includes/shortcode.php index f644bbf..2dd3bb4 100644 --- a/includes/shortcode.php +++ b/includes/shortcode.php @@ -163,3 +163,49 @@ function wzkb_shortcode_alert( $atts, $content = null ) { return apply_filters( 'wzkb_shortcode_alert', $output, $atts, $content ); } add_shortcode( 'kbalert', 'wzkb_shortcode_alert' ); + + +/** + * Create the shortcode to display alerts using [kbalert]. + * + * @since 2.2.2 + * + * @param array $atts Shortcode attributes array. + * @param string $content Content to wrap in the Shortcode. + * @return string $output Formatted shortcode output + */ +function wzkb_shortcode_related_articles( $atts, $content = null ) { + + if ( wzkb_get_option( 'include_styles' ) ) { + wp_enqueue_style( 'wzkb_styles' ); + } + + $atts = shortcode_atts( + array( + 'numberposts' => 5, + 'echo' => false, + 'post' => get_post(), + 'exclude' => array(), + 'show_thumb' => true, + 'show_date' => true, + 'title' => '

' . __( 'Related Articles', 'knowledgebase' ) . '

', + 'thumb_size' => 'thumbnail', + ), + $atts, + 'kb_related_articles' + ); + + $output = wzkb_related_articles( $atts ); + + /** + * Filters knowledge base breadcrumb shortcode. + * + * @since 2.2.2 + * + * @param string $output Formatted shortcode output + * @param array $att Shortcode attributes array + * @param string $content Content to wrap in the Shortcode + */ + return apply_filters( 'wzkb_shortcode_related_articles', $output, $atts, $content ); +} +add_shortcode( 'kb_related_articles', 'wzkb_shortcode_related_articles' ); diff --git a/knowledgebase.php b/knowledgebase.php index 78a52f1..af1c01d 100644 --- a/knowledgebase.php +++ b/knowledgebase.php @@ -15,7 +15,7 @@ * Plugin Name: WebberZone Knowledge Base * Plugin URI: https://github.com/WebberZone/knowledgebase * Description: Fastest way to create a highly-flexible multi-product knowledge base. - * Version: 2.2.1 + * Version: 2.2.2-RC1 * Author: WebberZone * Author URI: https://webberzone.com * License: GPL-2.0+ @@ -73,6 +73,7 @@ require_once WZKB_PLUGIN_DIR . 'includes/admin/settings/class-knowledgebase-settings.php'; require_once WZKB_PLUGIN_DIR . 'includes/admin/settings/options-api.php'; require_once WZKB_PLUGIN_DIR . 'includes/public/public.php'; + require_once WZKB_PLUGIN_DIR . 'includes/public/class-template-handler.php'; require_once WZKB_PLUGIN_DIR . 'includes/public/related.php'; require_once WZKB_PLUGIN_DIR . 'includes/activate-deactivate.php'; require_once WZKB_PLUGIN_DIR . 'includes/custom-post-type.php';