• I’ve taken some custom SiteOrigin Page Builder widgets out of a theme and placed them in a new custom plugin.

    In the main plugin file, I have:

    require plugin_dir_url( __FILE__ ) . 'hdr003.php';
    require plugin_dir_url( __FILE__ ) . 'hme006.php';
    require plugin_dir_url( __FILE__ ) . 'hme007.php';
    
    function purity_register_widgets(){
        register_widget('ICD_HDR003_Widget');
        register_widget('ICD_HME006_Widget');
        register_widget('ICD_HME007_Widget');
    }
    add_action( 'widgets_init', 'purity_register_widgets');

    In, for example, hdr003.php, I have:

    class ICD_HDR003_Widget extends WP_Widget {

    However, I receive:

    Fatal error: Class ‘WP_Widget’ not found

    Hence, I’m trying to include in hdr003.php:

    require_once(get_home_path(). 'wp-includes/class-wp-widget.php');

    but this produces an error:

    Fatal error: Uncaught Error: Call to undefined function get_home_path()

    The function is a valid function.

    If I replace that line with:

    require_once(ABSPATH . 'wp-includes/class-wp-widget.php');

    I receive:

    include_once(ABSPATH/wp-includes/class-wp-widget.php): failed to open stream: No such file or directory

    The file /wp-includes/class-wp-widget.php exists.

    I’ve replaced /wp-admin & /wp-includes with newly downloaded copies.

    Help appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The code in your plugin file that is not in a function is run when plugins are loaded. This is pretty early in the loading of WordPress. It might not be the right answer, but can you try moving your require to inside the function but use a path to plugin dir instead of a URI.

    Thread Starter insightdes

    (@insightdes)

    Thanks Joy.

    I moved the require_once call out of the widget files, and into the main plugin file.

    However, my site currently breaks, and debug.log has:

    [15-Mar-2019 04:30:44 UTC] PHP Warning: require(http://www.example.local/wp-content/plugins/icd_siteorigin_widgets/hme006.php): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
    in /Applications/AMPPS/www/example.local/wp-content/plugins/icd_siteorigin_widgets/icd_siteorigin_widgets.php on line 19

    [15-Mar-2019 04:30:44 UTC] PHP Fatal error: require(): Failed opening required ‘http://www.example.local/wp-content/plugins/icd_siteorigin_widgets/hme006.php’ (include_path=’.:’) in /Applications/AMPPS/www/example.local/wp-content/plugins/icd_siteorigin_widgets/icd_siteorigin_widgets.php on line 19

    The file http://www.example.local/wp-content/plugins/icd_siteorigin_widgets/hme006.php exists.

    Help appreciated.

    Thread Starter insightdes

    (@insightdes)

    curl is enabled in php.ini

    You have to use the path, not the url.

    Thread Starter insightdes

    (@insightdes)

    Thanks Joy,

    Can you help me on how to do that please?

    Cheers.

    Thread Starter insightdes

    (@insightdes)

    I used the full path to the file as a workaround, and then I received an error when trying to activate the plugin:

    Fatal error: Cannot declare class WP_Widget, because the name is already in use in /full/path/to/wp-includes/class-wp-widget.php on line 20

    This is the top of one of the files required by the main plugin file:

    class ICD_HDR003_Widget extends WP_Widget {

    Help appreciated.

    • This reply was modified 7 years, 1 month ago by insightdes.
    Thread Starter insightdes

    (@insightdes)

    Can you help me please Joy?

    I can’t see your code, and it’s better for you if you learn how to diagnose problems. You can read the PHP manual if you don’t understand require.
    http://www.php.net/manual/en/

    You should also look at the order of the WordPress execution. Themes and plugins are loaded at different times.
    https://codex.wordpress.org/Plugin_API/Hooks

    Here is the Plugin Handbook: https://developer.wordpress.org/plugins/

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Fatal error: Uncaught Error: Call to undefined function get_home_path()’ is closed to new replies.