2
votes

I have included wp-load.php file in a plugin. It worked fine in the local WordPress environment. When I submitted the plugin for review they have asked to call the core files as a function. Below message they have sent in mail.

Calling core loading files directly

Including wp-config.php, wp-blog-header.php, wp-load.php, or pretty much any other WordPress core file that you have to call directly via an include is not permitted.

These calls are prone to failure as not all WordPress installs have the exact same file structure. In addition it opens your plugin to security issues, as WordPress can be easily tricked into running code in an unauthenticated manner.

Your code should always exist in functions and be called by action hooks. This is true even if you need code to exist outside of WordPress. Code should only be accessible to people who are logged in and authorized, if it needs that kind of access. Your plugin's pages should be called via the dashboard like all the other settings panels, and in that way, they'll always have access to WordPress functions.

If you need to have a ‘page’ accessed directly by an external service, you should use query_vars and/or rewrite rules to create a virtual page which calls a function.

I think below code i used may be the problem.

require_once('../../../wp-load.php'); 
$apikey = sanitize_text_field( $_POST['apikey'] );
$appid = sanitize_text_field( $_POST['appid'] );
$ulr = esc_url_raw( $_POST['ulr'] );

global $wpdb;
$wpdb->update( 
    'wp_table', 
    array( 
        'apikey' => $apikey,        // string
        'appid' => $appid,
        'ulr' => $ulr   
    ), 
    array( 'id' => '1' ), 
    array( 
        '%s',       // value1
        '%s',
        '%s'    
    ), 
    array( '%d' ) 
);

Why it is needed to load wp-load.php as a function but not as the method i have used??? What change I need to do now to get approved???

1

1 Answers

0
votes

Once you register your plugin and it is activated, it can use all WP core functions, so no need to load wp-load.php

loading this file generally used when you want to have a stand-alone file that you can go directly by calling/visiting its URL (not as a plugin)