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 protected]';
$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 );
?>
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 protected]';
$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 );
?>
Share
Improve this question
edited Apr 23, 2019 at 18:11
Fayaz
9,0172 gold badges33 silver badges51 bronze badges
asked Apr 23, 2019 at 17:53
Ron BonomoRon Bonomo
212 bronze badges
2 Answers
Reset to default 1It 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!
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