forked from miya0001/oembed-instagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oembed-instagram.php
65 lines (53 loc) · 1.63 KB
/
oembed-instagram.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
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
<?php
/*
Plugin Name: oEmbed Instagram
Plugin URI: https://github.com/miya0001/oembed-instagram
Description: Embed image and video from instagram.
Author: Takayuki Miyauchi
Version: 1.5.2
Author URI: http://wpist.me/
*/
$oembed_instagram = new oEmbedInstagram();
$oembed_instagram->register();
class oEmbedInstagram {
function register()
{
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
add_action( 'wp_head', array( $this, 'wp_head' ) );
}
public function wp_head( )
{
$css = '<style type="text/css">';
$css .= '.oembed-instagram{box-shadow: 1px 1px 3px #eeeeee; background-color: #ffffff; border: 1px solid #dedede; margin: 1em 5px;}';
$css .= '.oembed-instagram iframe{display: block; margin: 0 auto; max-width: 100%; box-sizing: border-box;}';
$css .= '</style>'."\n";
echo apply_filters( 'oembed_instagram_style', $css);
}
public function wp_enqueue_scripts()
{
wp_enqueue_script(
'oembed-instagram',
plugins_url( 'oembed-instagram.js', __FILE__ ),
array( 'jquery' ),
'1.5.1',
true
);
}
public function plugins_loaded()
{
wp_embed_register_handler(
'instagram',
'#http://instagram.com/.*/?$#i',
array( $this, 'oembed_handler' )
);
}
public function oembed_handler( $m, $attr, $url, $rattr )
{
$html = '<div class="oembed-instagram"><iframe src="%s/embed" width="612" height="710" frameborder="0" scrolling="no" allowtransparency="true"></iframe></div>';
$res = parse_url( $m[0] );
$uri = untrailingslashit( '//'.$res['host'].$res['path'] );
return sprintf( $html, $uri );
}
}
// EOF