WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Does this php include look ok? (1 post)

  1. andym33
    Member
    Posted 3 months ago #

    I would like to add a dashboard widget and need to include/ require (whatever is better) a php file from my root. I combined a couple of things together that I found on different websites and it works, but I don't know php very well so just checking to see if there is a better way to write it especially if it causes problems with security/performance.

    function andym_dashboard_widget_1() {
    	wp_add_dashboard_widget(
                     'andym_dashboard_app_widget',         // Widget slug.
                     'Test Widget',                               // Title.
                     'andym_dashboard_widget_1_function'   // Display function.
        );
    }
    add_action( 'wp_dashboard_setup', 'andym_dashboard_widget_1' );
    function andym_dashboard_widget_1_function() {
     $path = $_SERVER['DOCUMENT_ROOT'];
       $path .= "/myfolder/myfile.php";
       include_once($path);
    }

    Thanks in advance

Reply

You must log in to post.

About this Topic