• Resolved devecity

    (@devecity)


    hello there, i’m developed a plugin for corona virus statics. but i’m facing a problems into my code. i’m using this below functions:

    function coronastatics_widgetreg()
    {
        register_widget('corona_bd_widget');
        register_widget('corona_bd_widget_world');
    }
    add_action('widgets_init', 'coronastatics_widgetreg');

    and i’m calling this functions as __construct. below is the code:

    <?php
    
    class corona_bd_widget extends WP_Widget{
        public function __construct()
        {
            $widget_ops = array(
                'classname' => 'corona_bd_widget',
                'description' => 'Display Bangladesh Live CoronaVirus (Covid-19) Real-Time Data'
            );
            parent::__construct('corona_bd_widget', 'CoronaStatics Bangladesh', $widget_ops);
        }
        
        // output the widget content on the front-end
        public function widget($args, $instance)
        {
            echo $args['before_widget'];
            if (!empty($instance['title'])) {
                echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
            }
                $data = json_decode(coronastatics_bangladeshapi());
    ?>

    the codes are working good. but now i want to change the “corona_bd_widget” to “coronastatics_bangladeshwidget”, but while i’m changing this “corona_bd_widget” to “coronastatics_bangladeshwidget” it’s not showing anything into the widget area of my website. can you please explain what is the issue?

    thanks.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • WebsiteGuider

    (@websiteguiderteam1618)

    Hi,
    Did you tried to change the name inside register_widget('corona_bd_widget'); with register_widget('coronastatics_bangladeshwidget');? You have to change id inside class constructer.
    Thanks

    • This reply was modified 3 years, 10 months ago by WebsiteGuider.
    • This reply was modified 3 years, 10 months ago by WebsiteGuider.
    Thread Starter devecity

    (@devecity)

    yes i want to change “corona_bd_widget” to “coronastatics_bangladeshwidget”. but while i’m changing this, the plugin doesn’t working. automatically hiding the widget from the website. below i’m post the functions and class constructor that is working.

    function coronastatics_widgetreg()
    {
        register_widget('corona_bd_widget');
        register_widget('corona_bd_widget_world');
    }
    add_action('widgets_init', 'coronastatics_widgetreg');
    <?php
    
    class corona_bd_widget extends WP_Widget{
        public function __construct()
        {
            $widget_ops = array(
                'classname' => 'corona_bd_widget',
                'description' => 'Display Bangladesh Live CoronaVirus (Covid-19) Real-Time Data'
            );
            parent::__construct('corona_bd_widget', 'CoronaStatics Bangladesh', $widget_ops);
        }
        
        // output the widget content on the front-end
        public function widget($args, $instance)
        {
            echo $args['before_widget'];
            if (!empty($instance['title'])) {
                echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
            }
                $data = json_decode(coronastatics_bangladeshapi());
    ?>

    the above code is working fine. but while i’m changing

    “corona_bd_widget”

    to

    “coronastatics_bangladeshwidget”

    it’s showing nothing and not working. can you explain how i can solve this?

    thanks.

    Moderator bcworkz

    (@bcworkz)

    If you’ve changed all occurrences of “corona_bd_widget” everywhere in your code as described, there’s no reason the widget would not appear. Are you sure you’ve uploaded the revised file to the correct location, replacing the “corona_bd_widget” version? Don’t ask why I think that can happen 🙂

    Caching could be at play. Flush any server side caching as well as your browser cache.

    You may have accidentally introduced a typo such that your code is ignored. Check your error log for any indication of syntax errors.

    If you still have trouble, post the code that is not working somewhere like pastebin.com or gist.github.com and provide the link here. Then someone could test your code for themselves and advise further.

    Thread Starter devecity

    (@devecity)

    hello there,
    solved this issue. problems was widget removing while changing the function name.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘register_widget(”); not working’ is closed to new replies.