Вот код плагина который пишу для wordpress
<?php
/**
* Plugin Name:
* Description:
* Version: 1.0
* Author:
*/
// Add shortcode for displaying Twitter timeline
function twitter_timeline_shortcode() {
// Your Twitter API credentials
$consumer_key = '00000';
$consumer_secret = '00000';
$oauth_access_token = '000000';
$oauth_access_token_secret = '000000';
// User whose tweets you want to display
$twitter_username = '@elonmusk';
// Include TwitterAPIExchange library
require_once plugin_dir_path(__FILE__) . 'TwitterAPIExchange.php';
// Set up API request parameters
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$request_method = 'GET';
$get_field = '?screen_name=' . $twitter_username;
// Make API request using TwitterAPIExchange
$twitter = new TwitterAPIExchange(array(
'oauth_access_token' => $oauth_access_token,
'oauth_access_token_secret' => $oauth_access_token_secret,
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret
));
$twitter_timeline = $twitter->setGetfield($get_field)
->buildOauth($url, $request_method)
->performRequest();
// Decode JSON response into an array
$twitter_timeline = json_decode($twitter_timeline);
// Output tweets as HTML
$output = '<div class="twitter-timeline">';
foreach ($twitter_timeline as $tweet) {
$output .= '<div class="twitter-tweet">';
$output .= '<p>' . $tweet->text . '</p>';
$output .= '<p class="twitter-date">' . date('F j, Y, g:i a', strtotime($tweet->created_at)) . '</p>';
var_dump($tweet);
$output .= '</div>';
}
$output .= '</div>';
return $output;
}
add_shortcode('twitter-feed', 'twitter_timeline_shortcode');
?>
но на сайте при добавлении шорткода [twitter-feed] выдаёт ошибку
"Warning: Attempt to read property "text" on array in C:\OpenServer\domains\myuniversitywork.ua\wp-content\plugins\TwittMe\TwittMe.php on line 46
Warning: Attempt to read property "created_at" on array in C:\OpenServer\domains\myuniversitywork.ua\wp-content\plugins\TwittMe\TwittMe.php on line 47"