2

I am a game developer, not very familiar with web programming. I am trying to tie my website point system, MyCred, into my games. Mycred has code snippets for interacting with the points from another site. I use their snippet, but I keep getting this error:

Fatal error: require(): Failed opening required 'WP_DIRwp-blog-header.php' (include_path='.:/usr/lib/php7.2') in /homepages/24/d773619225/htdocs/clickandbuilds/SefronGames/Gameconnect/KC.php on line 2

I have searched the web and tried adding code to top to load the wp, but doesn't work. Still throws the error. Here is the php code I am having an issue with:

<?php
require WP_DIR.'wp-blog-header.php';
$secret_key = 'I took this off to protect info';
$remote_url = 'I took this off to protect info ';

$action     = 'CREDIT';
$account    = 'email@example.com';
$amount     = 10;
$ref        = 'reference';
$ref_id     = 0;
$entry      = 'Points for viewing video';
$data       = 'optional extra';
$point_type = 'Kanobia Credit';
$host       = get_bloginfo( 'url' );

$token      = md5( $host . $action . $amount . $secret_key );

$request    = array(
    'method' => 'POST',
    'body'   => array(
        'action'  => $action,
        'account' => $account,
        'amount'  => $amount,
        'ref'     => $ref,
        'ref_id'  => $ref_id,
        'type'    => $point_type,
        'entry'   => $entry,
        'data'    => $data,
        'token'   => $token,
        'host'    => $host
    )
);

$response = wp_remote_post( $remote_url, $request );
?>
1

It looks as though WP_DIR is being interpreted as a string. Is that constant defined anywhere before this code is being run?

My guess is that it is not as PHP will assume it's a string and that is why the location is WP_DIRwp-blog-header.php and not an actual file path.

Hope this helps!

0

No it isn't. I was reading other forums on the topic, were others had the error. And people posted to put that WP_DIR snippet at the top to get wordpress ability. That the error is because it needs stuff from wordpress that wasn't being recognized. with out that at the top my error is

Fatal error: Uncaught Error: Call to undefined function get_bloginfo() in /homepages/24/d773619225/htdocs/clickandbuilds/SefronGames/Gameconnect/KC.php:14 Stack trace:

0 {main}

thrown in /homepages/24/d773619225/htdocs/clickandbuilds/SefronGames/Gameconnect/KC.php on line 14
And other people said that putting the call to load wordpress stuff at the top fixed it for them. So I tried, but doesn't work for me

  • If you're trying to create an endpoint for your app to retrieve data from, this is not the way to do it in WordPress. You'll want to use the built-in REST API to do this. See this link for reference - developer.wordpress.org/rest-api/extending-the-rest-api/… – Welcher Apr 25 at 15:00
  • This link is very interesting, definitely going to study it. But it will take a min to study and "get" what it is saying. I am using code that mycred supplies so you can interact with the point system remotely. Using there code, I through that error. It is as if the code doesn't apply wp functions and all. So I believe I need to some how tell the script to use wp. – Ron Bonomo Apr 26 at 17:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.