0

Hope you someone help me out here a bit. I'm trying to include a WOT Wrapper (https://github.com/lukaswhite/weboftrust) into a WordPress plugin. However I have no experience whatsoever with PHP namespaces. I'm calling the class from within my plugin file, let's call it plugin.php:

function verify_site_content() {
    // Create a client
    $client = \Lukaswhite\Weboftrust\WeboftrustClient::factory();


// IMPORTANT - set the API key
$client->setApiKey('xdddxx');

// Call the API, passing in an array of URLs
$response = $client->lookup(array('www.domain.com'));

$website = $response['www.domain.com'];

if ($website->isTrustworthy()) {
// it sure is, do something...
    echo "YES TRUSTWORTHY";


} else {
    // Uh-oh, perhaps we should be wary of this site.
        echo "NO NOT TRUSTWORTHY";
}



//$url = get_site_url();
$url = "http://www.domain.com";

return true;


}

The files are located at:

PLUGINFOLDER

PLUGINFOLDER/plugin.php

PLUGINFOLDER/Lukaswhite/Weboftrust/WeboftrustClient.php etc.

Hope this makes sense. I don't seem to understand why I don't have to include the php files etc. but believe this has to do with namespaces.

Here's the error I'm getting:

Fatal error: Uncaught Error: Class 'Lukaswhite\Weboftrust\WeboftrustClient' not found in /Applications/MAMP/htdocs/abpa11.dev/wp-content/plugins/pluginfolder/plugin.php:137 Stack trace: #0 /Applications/MAMP/htdocs/abpa11.dev/wp-content/plugins/pluginfolder/plugin.php(68): verify_site_content()

Hope one can shed some light...

  • you need to explicitly include the main file of the wrapper – Mark Kaplun Oct 9 '16 at 6:09
  • This is meant to be installed per Composer. If you do that, you get an autoloader, and your files will be available when you need them, without separate include statements. – fuxia Oct 9 '16 at 11:42
  • I see thanks! I guess the author could have mentioned that somewhere, but I had the feeling when I saw all the use statements in the src files. – Daniel Klose Oct 10 '16 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.