Salesforce 到 Wordpress:WP 选项 Table 未填充来自 SF 的 json
Salesforce-to-Wordpress: WP Options Table not populating with json from SF
我正在尝试使用来自 Salesforce 的数据填充 WordPress 站点。有点类似于 this question maybe except I'm going in the opposite direction. I am basing my code quite a bit on this example,当我自己尝试它时,它对我来说效果很好,但一旦我用 Wordpress 尝试它,它就没有那么好用了。
从示例中,我只用下面的代码替换了 demo_rest.php,将 oauth_callback.php 中的最后一行更改为 return 到我在 WordPress 中的选项页面,进行了适当的更改config.php,并替换了 index.html。当我这样做时,我在 Salesforce 中看到我确实从我的插件登录,但没有任何东西从那里返回到 WordPress。它没有显示在我想要的 window 中,也没有用应该产生的 json 更新 mysql 数据库。我做错了什么?
我的代码。
<?php
/*Assign global variables*/
$plugin_url = WP_PLUGIN_URL . '/my-plugin';
$options = array();
// adds plugin settings page in wordpress admin menu
function salesforce_menu(){
add_options_page( // wordpres helper function to add a settings page
'Salesforce to WordPress Integrator',
'Salesforce Integration',
'manage_options',
'salesforce-integrator',
'salesforce_options_page'
);
}
add_action('admin_menu','salesforce_menu');
function salesforce_options_page(){
if ( !current_user_can('manage_options')){
wp_die ('You do not have sifficient permissions to access this page.');
}
global $plugin_url;
global $options;
if( $access_token != '') {
$response = get_stories($instance_url, $access_token);//This is where I'm probably getting messed up. I'm trying to call the get_stories function (defined later)
$options['response'] = $response;
$options['last_updated'] =time();
update_option ('storybank_approved', $options); //wp helper function to update the options table, hopefully with the results of my call to the API.
}
$options = get_option('storybank_approved');
if ($options !=''){
$response = $options['response'];
}
var_dump ($response); //I want this to show me the json on my settings page just to ensure that I have a response, but it looks like I don't
require('includes/options-page-wrapper.php');
}
//get salesforce records
function get_stories($instance_url, $access_token) {
$query = "SELECT Id, Name from salesforce_Object__c LIMIT 100";
$url = "$instance_url/services/data/v20.0/query?q=" . urlencode($query) ;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Authorization: OAuth $access_token"));
$json_response = curl_exec($curl);
curl_close($curl);
$response =json_decode($json_response,true);
$total_size = $response['totalSize'];
echo "$total_size record(s) returned<br/><br/>";
foreach ((array) $response['records'] as $record) {
echo $record['Id'] . ", " . $record['Name']. "<br/>";
}
echo "<br/>";
}
?>
getStories 函数未return获取值。
$响应 = get_stories($instance_url, $access_token); // 必须 return 东西。
//例如,为了简单起见,我删除了其余代码。
function get_stories($instance_url, $access_token) {
$response =json_decode($json_response,true);
return $response;
}
我正在尝试使用来自 Salesforce 的数据填充 WordPress 站点。有点类似于 this question maybe except I'm going in the opposite direction. I am basing my code quite a bit on this example,当我自己尝试它时,它对我来说效果很好,但一旦我用 Wordpress 尝试它,它就没有那么好用了。
从示例中,我只用下面的代码替换了 demo_rest.php,将 oauth_callback.php 中的最后一行更改为 return 到我在 WordPress 中的选项页面,进行了适当的更改config.php,并替换了 index.html。当我这样做时,我在 Salesforce 中看到我确实从我的插件登录,但没有任何东西从那里返回到 WordPress。它没有显示在我想要的 window 中,也没有用应该产生的 json 更新 mysql 数据库。我做错了什么?
我的代码。
<?php
/*Assign global variables*/
$plugin_url = WP_PLUGIN_URL . '/my-plugin';
$options = array();
// adds plugin settings page in wordpress admin menu
function salesforce_menu(){
add_options_page( // wordpres helper function to add a settings page
'Salesforce to WordPress Integrator',
'Salesforce Integration',
'manage_options',
'salesforce-integrator',
'salesforce_options_page'
);
}
add_action('admin_menu','salesforce_menu');
function salesforce_options_page(){
if ( !current_user_can('manage_options')){
wp_die ('You do not have sifficient permissions to access this page.');
}
global $plugin_url;
global $options;
if( $access_token != '') {
$response = get_stories($instance_url, $access_token);//This is where I'm probably getting messed up. I'm trying to call the get_stories function (defined later)
$options['response'] = $response;
$options['last_updated'] =time();
update_option ('storybank_approved', $options); //wp helper function to update the options table, hopefully with the results of my call to the API.
}
$options = get_option('storybank_approved');
if ($options !=''){
$response = $options['response'];
}
var_dump ($response); //I want this to show me the json on my settings page just to ensure that I have a response, but it looks like I don't
require('includes/options-page-wrapper.php');
}
//get salesforce records
function get_stories($instance_url, $access_token) {
$query = "SELECT Id, Name from salesforce_Object__c LIMIT 100";
$url = "$instance_url/services/data/v20.0/query?q=" . urlencode($query) ;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Authorization: OAuth $access_token"));
$json_response = curl_exec($curl);
curl_close($curl);
$response =json_decode($json_response,true);
$total_size = $response['totalSize'];
echo "$total_size record(s) returned<br/><br/>";
foreach ((array) $response['records'] as $record) {
echo $record['Id'] . ", " . $record['Name']. "<br/>";
}
echo "<br/>";
}
?>
getStories 函数未return获取值。 $响应 = get_stories($instance_url, $access_token); // 必须 return 东西。
//例如,为了简单起见,我删除了其余代码。
function get_stories($instance_url, $access_token) {
$response =json_decode($json_response,true);
return $response;
}