当在自定义WordPress页面上放置短代码时,输出始终显示在页面内容的顶部。WP短代码输出始终在页面顶部
我发现,这个问题可以通过使用回报,而不是回声是固定的,或者by using output buffering:(ob_start()/ob_get_contents())
不幸的是我的编码技能不是我想他们是..我不知道确切地在哪里实施这些修复。
有人可以帮我吗?插件开发人员没有回复我的邮件,我需要让这个工作a.s.a.p.
我认为这需要在故障插件的函数文件中实现,所以我在下面添加了它。
<?php
/**
* Woocommerce Category Accordion Functions
*
* @author \t \t TechieResource
* @category \t Shortcode
* @package \t woocommerce-category-accordion/inc
* @version \t 1.2.1
*/
/**
/* Clean variables
*
* @param string $var
* @return string
*/
if (! defined('ABSPATH')) {
\t exit;
} // Exit if accessed directly
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
\t
class trwca_wc_category_accordion{
\t
\t \t /**
\t \t * Constructor
\t \t */
\t private $shortcode_tag = "WC-Category-Accordion";
\t \t
\t \t public function __construct() {
\t \t
\t \t add_action('woocommerce_category_accordion', array($this, 'woocommerce_category_accordion_func'), 10, 2);
\t \t add_shortcode($this->shortcode_tag, array($this, 'wc_category_accordion_sc'));
\t \t
\t \t \t if (is_admin()){
\t \t \t \t add_action('admin_head', array($this, 'admin_head'));
\t \t \t \t add_action('admin_enqueue_scripts', array($this , 'admin_enqueue_scripts'));
\t \t \t }
\t \t }
\t \t /**
\t \t * Display the Woocommerce Category Accordion.
\t \t * @since 1.2.1
\t \t * @param array $instance Arguments.
\t \t * @param bool $echo Whether to display or return the output.
\t \t * @return string
\t \t */
\t \t public function woocommerce_category_accordion_func($instance, $echo = true) {
\t \t \t extract($instance, EXTR_SKIP);
\t \t \t global $wp_query; \t \t
\t \t
\t \t \t global $post, $product; \t
\t
\t \t \t $exclude_tree = esc_attr($exclude_tree); \t \t
\t \t
\t \t \t $hide_empty = esc_attr($hide_empty);
\t \t \t
\t \t \t $show_count = esc_attr($show_count);
\t \t \t
\t \t \t $open_cat = esc_attr($open_cat); \t \t
\t \t \t
\t \t \t $ac_speed = esc_attr($ac_speed);
\t \t \t
\t \t \t $ac_type = esc_attr($ac_type);
\t \t \t
\t \t \t $event_type = esc_attr($event_type);
\t \t \t
\t \t \t $ac_icon = esc_attr($ac_icon);
\t \t \t
\t \t \t $sortby = esc_attr($sortby);
\t \t \t
\t \t \t $ac_theme = esc_attr($ac_theme);
\t \t \t
\t \t \t $order = esc_attr($order);
\t \t \t
\t \t \t $level = esc_attr($level);
\t \t \t
\t \t \t $cats_id = esc_attr($ac_opencat);
\t \t \t
\t \t \t $disable_parent = esc_attr($disable_parent);
\t \t \t
\t \t \t $disable_aclink = esc_attr($disable_aclink);
\t \t \t \t \t
\t \t \t if(!empty($instance['id'])){
\t \t \t \t
\t \t \t \t $widgetid= $instance['id'];
\t \t \t }
\t \t \t else{
\t \t \t \t if($sh_id!=""){
\t \t \t \t \t $widgetid= "wc_category_accordion-".$sh_id; \t
\t \t \t \t }
\t \t \t \t else{
\t \t \t \t \t $widgetid= "wc_category_accordion-".$this->trwca_generate_random_code(3);
\t \t \t \t }
\t \t \t }
\t \t
\t \t \t $instance_categories = get_terms('product_cat', '&parent=0&exclude='.$exclude_tree.''); \t \t
\t \t \t \t
\t \t \t if (is_array($instance_categories)) {
\t
\t \t \t \t foreach($instance_categories as $categories) {
\t
\t \t \t \t \t $term_id[] = $categories->term_id;
\t
\t \t \t \t \t $term_name = $categories->name;
\t \t \t \t }
\t \t \t }
\t
\t \t \t if(!empty($post->ID)){
\t \t \t \t
\t \t \t \t $terms =get_the_terms($post->ID, 'product_cat');
\t \t \t }
\t \t \t else {
\t \t \t
\t \t \t \t $terms="";
\t \t \t }
\t \t \t
\t \t \t if (is_array($terms)) {
\t
\t \t \t \t foreach ($terms as $term) {
\t
\t \t \t \t \t $_cat=$term->term_id;
\t
\t \t \t \t \t break;
\t
\t \t \t \t }
\t \t \t }
\t \t
\t \t /* For current category highlight */
\t \t \t if(is_product()){
\t \t \t
\t \t \t $current_cat= array();
\t \t \t
\t \t \t $cat = $wp_query->get_queried_object(); \t \t
\t \t \t \t
\t \t \t if (!empty($cat->term_id))
\t
\t \t \t {
\t \t \t \t $current_cat = $cat->term_id;
\t
\t \t \t }
\t \t \t else{
\t \t \t \t $_cat_id="1";
\t
\t \t \t \t if (isset($term->term_id))
\t
\t \t \t \t \t {
\t \t \t \t \t $_cat=$term->term_id;
\t
\t \t \t \t \t $_cat_id = !empty($_cat) ? $_cat_id=$_cat : $_cat_id=1 ;
\t \t \t \t \t
\t \t \t \t \t }
\t \t \t \t \t if (is_shop())
\t
\t \t \t \t \t {
\t \t \t \t \t \t $_cat_id="1";
\t \t \t \t \t }
\t \t \t \t \t if (!is_shop()){
\t \t \t \t \t \t
\t \t \t \t \t \t if (is_array($terms)) { \t \t \t \t \t
\t \t \t \t \t
\t \t \t \t \t \t \t foreach($terms as $term){
\t \t \t \t \t \t \t \t $myterms[]= $term->term_id;
\t \t \t \t \t \t \t }
\t \t \t \t \t \t \t $cats_id=end($myterms);
?>
\t <script type="text/javascript">
\t
\t var cats_id= <?php return end($myterms); ?>;
\t
\t </script>
\t <style type="text/css">
<?php foreach((get_the_terms($post->ID, 'product_cat')) as $term) {
\t \t \t $myterms= $term->term_id;
\t \t \t return 'ul.'.$widgetid.' li.cat-item-'.$myterms.' > a{font-weight:bold;}';
\t \t }
\t \t \t \t \t }
\t \t \t }
?>
\t </style>
<?php
\t }
\t \t \t }
\t $cat = $wp_query->get_queried_object();
\t \t \t \t \t
\t \t if (!empty($cat->term_id) && !is_product()){
\t \t \t
\t \t \t $cats_id = $cat->term_id;
\t \t \t return '<script type="text/javascript">
\t \t \t
\t \t \t var cats_id= '.$cats_id.';
\t \t \t
\t \t \t </script>';
\t \t }
\t \t else if(!is_product_category() && !is_product()){
\t
\t $cats_id=$ac_opencat;
\t \t }
\t $ac_type = $ac_type=="toggle" ? $ac_type= "true" : $ac_type= "false";
\t
\t $open_cat = $open_cat== true || $open_cat =='on' ? $open_cat=true : $open_cat=false;
\t \t \t \t \t
\t \t \t
/* Icon Selection */
\t switch ($ac_icon) {
\t \t \t case 'angle' : \t \t \t \t \t
\t \t \t \t $open_icon="angle-down"; \t \t \t \t
\t \t \t \t $close_icon="angle-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'doubleangle' :
\t \t \t \t $open_icon="angle-double-down";
\t \t \t \t $close_icon="angle-double-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'arrow-circle1' :
\t \t \t \t $open_icon="arrow-circle-down";
\t \t \t \t $close_icon="arrow-circle-right";
\t \t \t \t break;
\t \t \t \t \t
\t \t \t case 'arrow-circle2' : \t \t \t \t \t
\t \t \t \t $open_icon="arrow-circle-o-down"; \t \t \t \t
\t \t \t \t $close_icon="arrow-circle-o-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'arrow-right' :
\t \t \t \t $open_icon="arrow-down";
\t \t \t \t $close_icon="arrow-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'caret' :
\t \t \t \t $open_icon="caret-down";
\t \t \t \t $close_icon="caret-right";
\t \t \t \t break;
\t \t \t
\t \t \t case 'caret-square' : \t \t \t \t \t
\t \t \t \t $open_icon="caret-square-o-down"; \t \t \t \t
\t \t \t \t $close_icon="caret-square-o-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'chevron' :
\t \t \t \t $open_icon="chevron-down";
\t \t \t \t $close_icon="chevron-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'chevron-circle' :
\t \t \t \t $open_icon="chevron-circle-down";
\t \t \t \t $close_icon="chevron-circle-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'hand' :
\t \t \t \t $open_icon="hand-o-down";
\t \t \t \t $close_icon="hand-o-right";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'plus' :
\t \t \t \t $open_icon="minus";
\t \t \t \t $close_icon="plus";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'plus-circle' :
\t \t \t \t $open_icon="minus-circle";
\t \t \t \t $close_icon="plus-circle";
\t \t \t \t break;
\t \t \t
\t \t \t case 'plus-square1' :
\t \t \t \t $open_icon="minus-square";
\t \t \t \t $close_icon="plus-square";
\t \t \t \t break;
\t \t \t \t
\t \t \t case 'plus-square2' :
\t \t \t \t $open_icon="minus-square-o";
\t \t \t \t $close_icon="plus-square-o";
\t \t \t \t break; \t \t \t \t \t \t
\t }
\t
\t
\t if($disable_aclink==true){
\t \t
\t \t $disable_aclink='true';
\t }
\t else if($disable_aclink==""){
\t
\t \t $disable_aclink= 'false';
\t }
\t if($disable_parent==true){
\t \t
\t \t $disable_parent='true';
\t }
\t else if($disable_parent==""){
\t
\t \t $disable_parent='false';
\t
\t }
\t $cats_id= empty($cats_id) ? 1 : $cats_id;
?>
<script type="text/javascript">
var $=jQuery.noConflict();
$(document).ready(function($){ \t
$('.<?php echo $widgetid; ?>').trwcAccordion({
\t \t \t classParent \t : 'trwca-parent',
\t \t \t classActive \t : 'active',
\t \t \t classArrow \t : 'trwca-icon',
\t \t \t classCount \t : 'trwca-count',
\t \t \t classExpand \t : 'trwca-current-parent',
\t \t \t eventType \t : '<?php echo $event_type; ?>',
\t \t \t hoverDelay \t : 100,
\t \t \t menuClose : true,
\t \t \t cats_id: <?php echo $cats_id; ?>,
\t \t \t ac_type : <?php echo $ac_type; ?>,
\t \t \t autoExpand \t : true,
\t \t \t speed : '<?php echo $ac_speed ?>',
\t \t \t saveState \t : '<?php echo $open_cat; ?>',
\t \t \t disableLink \t : <?php echo $disable_aclink; ?>,
\t \t \t disableparentLink : <?php echo $disable_parent; ?>,
\t \t \t auto_open: 1,
\t \t \t showCount : true,
\t \t \t widget_id : "<?php echo $widgetid; ?>",
\t \t \t openIcon \t : '<?php echo $open_icon; ?>',
\t \t \t closeIcon \t : '<?php echo $close_icon; ?>',
});
});
</script>
<div class="block-content trwca-actheme <?php echo $ac_theme; ?>">
<div class="trwca-loader"></div>
<ul class="<?php echo $widgetid; ?> accordion" id="outer_ul">
<?php
$subcat_args = array(
\t \t \t \t 'taxonomy' => 'product_cat',
\t \t \t \t 'title_li' => '',
\t \t \t \t 'orderby' => $sortby,
\t \t \t \t 'order' => $order,
\t \t \t \t 'depth' => $level,
\t \t \t \t 'show_count' => $show_count,
\t \t \t \t 'hide_empty' => $hide_empty,
\t \t \t \t 'use_desc_for_title' => 1,
\t \t \t \t 'echo' => false,
\t \t \t \t 'exclude' => $exclude_tree,
\t \t \t \t 'hierarchical' => true ,
\t \t \t \t 'show_option_none' => __('No Categories Found','trwca'),
\t \t \t \t 'link_after' => '',
\t \t \t \t 'walker'=> new trwca_walker
\t \t \t );
\t \t \t \t \t \t
?>
<?php $subcategories = wp_list_categories($subcat_args);
\t $subcategories=preg_replace_callback(
'/<\/a> \(([0-9]+)\)/',
function ($matches) {
return ' <span class="count">('.($matches[1]).')</span></a>';
},$subcategories
);
\t \t
?>
<?php if ($subcategories) {
\t \t \t echo $subcategories;
}
?>
</ul>
</div>
<?php
\t \t }
\t \t public function trwca_generate_random_code($length=3) {
\t \t $string = '';
\t \t
\t \t $characters = "123456789";
\t \t for ($p = 0; $p < $length; $p++) {
\t \t $string .= $characters[mt_rand(0, strlen($characters)-1)];
\t \t \t }
\t \t return $string;
\t \t }
\t \t /**
\t \t * admin_head
\t \t * calls your functions into the correct filters
\t \t * @return void
\t \t */
\t \t function admin_head() {
\t \t \t // check user permissions
\t \t \t if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
\t \t \t \t return;
\t \t \t }
\t \t \t
\t \t \t // check if WYSIWYG is enabled
\t \t \t if ('true' == get_user_option('rich_editing')) {
\t \t \t \t add_filter('mce_external_plugins', array($this ,'mce_external_plugins'));
\t \t \t \t add_filter('mce_buttons', array($this, 'mce_buttons'));
\t \t \t }
\t \t }
\t
\t \t /**
\t \t * mce_external_plugins
\t \t * Adds our tinymce plugin
\t \t * @param array $plugin_array
\t \t * @return array
\t \t */
\t \t function mce_external_plugins($plugin_array) {
\t \t \t
\t \t \t $plugin_array['WC_Category_Accordion'] = plugins_url('admin/js/mce-button.js' , __FILE__);
\t \t \t return $plugin_array;
\t \t }
\t
\t \t /**
\t \t * mce_buttons
\t \t * Adds our tinymce button
\t \t * @param array $buttons
\t \t * @return array
\t \t */
\t \t function mce_buttons($buttons) {
\t \t \t array_push($buttons, 'WC_Category_Accordion');
\t \t \t return $buttons;
\t \t }
\t
\t \t /**
\t \t * admin_enqueue_scripts
\t \t * Used to enqueue custom styles
\t \t * @return void
\t \t */
\t \t function admin_enqueue_scripts(){
\t \t \t wp_enqueue_style('WC-Category-Accordion-sh', plugins_url('admin/css/mce-button.css' , __FILE__));
\t \t }
\t \t public function wc_category_accordion_sc($atts, $content = null) {
\t \t \t \t
\t \t \t \t $defaults = array(
\t \t \t \t \t \t \t 'show_count' => 0,
\t \t \t \t \t \t \t 'ac_speed' => 'fast',
\t \t \t \t \t \t \t 'exclude_tree' =>'',
\t \t \t \t \t \t \t 'hide_empty' => 0,
\t \t \t \t \t \t \t 'sortby' =>'name',
\t \t \t \t \t \t \t 'order' =>'ASC',
\t \t \t \t \t \t \t 'level' => 0,
\t \t \t \t \t \t \t 'event_type' => 'click',
\t \t \t \t \t \t \t 'ac_type' => 'toggle',
\t \t \t \t \t \t \t 'open_cat' => 0,
\t \t \t \t \t \t \t 'ac_opencat' => 1,
\t \t \t \t \t \t \t 'ac_icon' =>'plus',
\t \t \t \t \t \t \t 'disable_parent' => 0,
\t \t \t \t \t \t \t 'disable_aclink' => 0,
\t \t \t \t \t \t \t 'ac_theme' => '',
\t \t \t \t \t \t \t 'sh_id'=> '');
\t \t \t \t $settings = shortcode_atts($defaults, $atts);
\t \t \t \t return $this->woocommerce_category_accordion_func($settings, false);
\t \t }
}
new trwca_wc_category_accordion();
\t function trwca_clean($var) {
\t \t return sanitize_text_field($var);
\t }
}
?>
谢谢你们!
我的答案是否解决了问题Affi? – admcfajn