WordPress.org

Support

Support » How-To and Troubleshooting » Require an external class in to functions

Require an external class in to functions

  • 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • gabrielcastillo
    Member

    @gabrielcastillo

    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.

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Require an external class in to functions’ is closed to new replies.