WordPress.org

Ready to get started?Download WordPress

Forums

Require an external class in to functions (3 posts)

  1. Davabuu
    Member
    Posted 1 year ago #

    I need some help to solve a problem

    I have created a widget with the following code

    class Widget extends WP_Widget {
    
    	function Widget() {
    		$widget_ops = array('classname' => 'widget', 'description' =>  __( 'desc', 'Shah_khor' ) );
        	$this->WP_Widget('widget', __( 'widget', 'Shah_khor' ), $widget_ops);
    	}
    
    	function widget( $args, $instance ) {
    		extract($args, EXTR_SKIP);
    		//Some Code
    	}
    
    	function update( $new_instance, $old_instance ) {
    		//Some Code
    	}
    
    	function form( $instance ) {
    		//Some Code
    	}
    }
    add_action( 'widgets_init', 'mywidgets' );
    function mywidgets() {
    	register_widget( 'Widget' );
    }

    It works perfect but I want to organize my functions file, so I decided to put this in a new file and then use require_once

    require_once ( get_stylesheet_directory() . '/lib/widget.php' );

    It works on the admin, but when I go to the frontend I get an empty page.
    Do you have any idea how can I solve this?
    Thanks advance

  2. gabrielcastillo
    Member
    Posted 1 year ago #

    Why not use: include(TEMPLATEPATH . '/lib/widget.php');

    You widget code is not outputting any information. The page will be blank until you output data from you widget.

  3. Davabuu
    Member
    Posted 1 year ago #

    I resume the code I know the fucntions are empty, I didn't want to paste all my code here.
    This code works perfect if I use it on functions.php but when I call it from a third file, it doesn't work. I guess is something about the class

Topic Closed

This topic has been closed to new replies.

About this Topic