-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwitterPlugin.php
35 lines (28 loc) · 1.19 KB
/
TwitterPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace Antanova\Wordpress;
class TwitterPlugin
{
protected $factory;
protected $config;
public function __construct($config)
{
$this->config = $config;
// set up our endpoint
add_action('wp_ajax_anta_tweets', array($this, 'ajax_request'));
add_action('wp_ajax_nopriv_anta_tweets', array($this, 'ajax_request'));
// enqueue scripts when the theme is ready
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
}
public function ajax_request()
{
$this->factory = new TwitterTokenFactory($this->config['api_key'], $this->config['api_secret']);
$tweets = new Tweets($this->factory, new TwitterClient());
$tweets->getTweets($this->config['screen_name'], 3);
}
public function enqueue_scripts()
{
wp_enqueue_script('twitter', plugins_url('/js/ajax-twitter.js', __FILE__), array('jquery'), null, true);
//wp_enqueue_script('twittertxt', plugins_url('/node_modules/twitter-text/twitter-text.js', __FILE__), array('jquery'), null, true);
//wp_enqueue_script('twitter', plugins_url('/js/tweets.js', __FILE__), array('jquery'), null, true);
}
}