0

i need to make some change on file that is save on inc/classes on my template.

The file is

<?php

class TheWorld_Tabs_Widget extends WP_Widget {

    function __construct() {
        // Set up the widget options.
        $widget_options = array(
            'classname'   => 'widget-theworld-tabs tabs-widget',
            'description' => __( 'Display popular posts, recent posts and tags in tabs.', 'theworld' )
        );
        // Create the widget.
        parent::__construct(
            'theworld-tabs',                  // $this->id_base
            __( '&raquo; Tabs', 'theworld' ), // $this->name
            $widget_options                   // $this->widget_options
        );
    }

    function widget( $args, $instance ) {
        extract( $args );
        // Output the theme's $before_widget wrapper.
        echo $before_widget;
        ?>
        <ul class="tabs-nav">
            <li class="active"><a href="#tab1" title="Popular"><i class="fa fa-thumbs-up"></i></a></li>
            <li><a href="#tab2" title="Latest"><i class="fa fa-clock-o"></i></a></li>
            <li><a href="#tab3" title="Comments"><i class="fa fa-comment"></i></a></li>        
            <li><a href="#tab4" title="Tags"><i class="fa fa-tag"></i></a></li>
        </ul>
        <div class="tabs-container">
            <div class="tab-content" id="tab1">
                <?php the_widget( 'TheWorld_Popular_Widget', 'title=0&show_date=1&limit=5' ); ?>
            </div>
            <div class="tab-content" id="tab2">
                <?php the_widget( 'TheWorld_Recent_Widget', 'title=0&show_date=1&limit=5' ); ?>
            </div>
            <div class="tab-content" id="tab3">
                <?php the_widget( 'WP_Widget_Recent_Comments' ); ?>
            </div>
            <div class="tab-content" id="tab4">
                <?php the_widget( 'WP_Widget_Tag_Cloud' ); ?>
            </div>
        </div>
        <?php
        // Close the theme's widget wrapper.
        echo $after_widget;
    }
    /**
     * Displays the widget control options in the Widgets admin screen.
     *
     * @since 1.0.0
     */
    function form( $instance ) {
    ?>
        <p><?php _e( 'No need to setting anything for this widget.', 'theworld' ); ?></p>
    <?php
    }
}

And i need to change to

<?php

class TheWorld_Tabs_Widget extends WP_Widget {

    function __construct() {
        // Set up the widget options.
        $widget_options = array(
            'classname'   => 'widget-theworld-tabs tabs-widget',
            'description' => __( 'Display popular posts, recent posts and tags in tabs.', 'theworld' )
        );
        // Create the widget.
        parent::__construct(
            'theworld-tabs',                  // $this->id_base
            __( '&raquo; Tabs', 'theworld' ), // $this->name
            $widget_options                   // $this->widget_options
        );
    }

    function widget( $args, $instance ) {
        extract( $args );
        // Output the theme's $before_widget wrapper.
        echo $before_widget;
        ?>
        <ul class="tabs-nav">
            <li class="active"><a href="#tab1" title="Popular"><i class="fa fa-thumbs-up"></i></a></li>
            <li><a href="#tab2" title="Latest"><i class="fa fa-clock-o"></i></a></li>      
            <li><a href="#tab4" title="Tags"><i class="fa fa-tag"></i></a></li>
        </ul>
        <div class="tabs-container">
            <div class="tab-content" id="tab1">
                <?php the_widget( 'TheWorld_Popular_Widget', 'title=0&show_date=1&limit=5' ); ?>
            </div>
            <div class="tab-content" id="tab2">
                <?php the_widget( 'TheWorld_Recent_Widget', 'title=0&show_date=1&limit=5' ); ?>
            </div>
            <div class="tab-content" id="tab4">
                <?php the_widget( 'WP_Widget_Tag_Cloud' ); ?>
            </div>
        </div>
        <?php
        // Close the theme's widget wrapper.
        echo $after_widget;
    }

    function form( $instance ) {
    ?>
        <p><?php _e( 'No need to setting anything for this widget.', 'theworld' ); ?></p>
    <?php
    }
}

I've put this on my child functions.php

require get_stylesheet_directory() . '/inc/classes/widget-tabs.php'; 

And then save on child-theme/inc/classes/widget-tabs.php my edit file but i have error

Fatal error: Cannot redeclare class TheWorld_Tabs_Widget in /home/mysite/public_html/wp-content/themes/world/inc/classes/widget-tabs.php on line 0

1 Answer 1

1

Although it is a bit old post, there are some possible solutions:

  1. For your specific problem, since the only difference I see from the original widget is that you do not need the "tab3" regarding the recent comments and since each div has its own id, you can easily put in your css something like:

    #tab3 {display:none;}
    
  2. Now, regarding the override of the widget.

    • If you have access to the parent theme, you can wrap the widget in an if statement like:

      if(!class_exists('TheWorld_Tabs_Widget')) { 
         class TheWorld_Tabs_Widget extends WP_Widget {...
         ...
      }
      

      then, your widget will override the parent one and no error will be thrown.

      • If you do not have access to the parent theme, you can make a small change to your version of the widget by changing the name to something else (e.g.: TheWorld_Tabs_Widget_Child), and then use this to your theme.

      OR

      • try to unregister the parent widget first, by using the unregister_widget() function, in your child theme functions file. This assumes that the widget in the parent theme is registered at the widget_init. like:

        function some_widget_unregister() {
            unregister_widget( 'TheWorld_Tabs_Widget' );
        }
        add_action( 'widgets_init', 'some_widget_unregister', 99 );
        

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.