-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacebook-open-graph-scraper.php
More file actions
executable file
·67 lines (56 loc) · 1.53 KB
/
facebook-open-graph-scraper.php
File metadata and controls
executable file
·67 lines (56 loc) · 1.53 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Plugin Name: Facebook Open Graph Scraper
* Plugin URI: http://angrycreative.se
* Description: On save post, send post url to facebook and re scrape open graph information.
* Version: 1.2.1
* Author: viktorfroberg
* Author URI: http://angrycreative.se
* License: GPLv2
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
class AC_Facebook_Open_Graph_Scraper {
function __construct(){
add_action( 'save_post', array($this, 'post_scraper'), 90, 2);
}
/**
* Filter what post types should be re-scraped
* @since 1.0.0
* @param post_types array
*/
function get_post_types() {
return apply_filters( 'fogs_post_types', get_post_types());
}
/**
* On save post, update facebook post cache
*/
function post_scraper($post_id, $post) {
/**
* Filter what post types should be re-scraped
* @since 1.0.0
* @param post_types array
*/
$post_types = $this->get_post_types();
if(in_array($post->post_type, $post_types) || empty($post_types)){
$url = get_permalink($post_id);
$response = wp_remote_post( 'https://graph.facebook.com/', array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'blocking' => false,
'headers' => array(),
'body' => array( 'id' => $url, 'scrape' => 'true' )
)
);
}
}
}
add_action( 'plugins_loaded', 'load_ac_facebook_open_graph_scraper' );
function load_ac_facebook_open_graph_scraper() {
if ( is_admin() ) {
new AC_Facebook_Open_Graph_Scraper();
}
}