Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ai
noblogs-wp
Commits
15cc7b5d
Commit
15cc7b5d
authored
Jul 25, 2015
by
ale
Committed by
lucha
Oct 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[auto] Plugin: oembed-provider 2.1.0
parent
217890fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
38 deletions
+61
-38
wp-content/plugins/oembed-provider/oembed-provider.php
wp-content/plugins/oembed-provider/oembed-provider.php
+55
-36
wp-content/plugins/oembed-provider/readme.txt
wp-content/plugins/oembed-provider/readme.txt
+6
-2
No files found.
wp-content/plugins/oembed-provider/oembed-provider.php
View file @
15cc7b5d
...
...
@@ -3,18 +3,34 @@
Plugin Name: oEmbed Provider
Plugin URI: http://wordpress.org/extend/plugins/oembed-provider/
Description: An oEmbed provider for Wordpress
Version: 2.
0.1
Version: 2.
1.0
Author: pfefferle, candrews
Author URI: https://github.com/pfefferle/oEmbedProvider/
*/
add_action
(
'init'
,
array
(
'OembedProviderPlugin'
,
'init'
));
/**
* oEmbed Provider for WordPress
*
* @author Matthias Pfefferle
* @author Craig Andrews
*/
class
OembedProvider
{
class
OembedProviderPlugin
{
/**
* initialize plugin
*/
public
static
function
init
()
{
add_action
(
'wp_head'
,
array
(
'OembedProviderPlugin'
,
'add_oembed_links'
));
add_action
(
'parse_query'
,
array
(
'OembedProviderPlugin'
,
'parse_query'
));
add_filter
(
'query_vars'
,
array
(
'OembedProviderPlugin'
,
'query_vars'
));
add_filter
(
'oembed_provider_data'
,
array
(
'OembedProviderPlugin'
,
'generate_default_content'
),
90
,
3
);
add_filter
(
'oembed_provider_data_attachment'
,
array
(
'OembedProviderPlugin'
,
'generate_attachment_content'
),
91
,
2
);
add_filter
(
'oembed_provider_data_post'
,
array
(
'OembedProviderPlugin'
,
'generate_post_content'
),
91
,
2
);
add_filter
(
'oembed_provider_data_page'
,
array
(
'OembedProviderPlugin'
,
'generate_post_content'
),
91
,
2
);
add_action
(
'oembed_provider_render_json'
,
array
(
'OembedProviderPlugin'
,
'render_json'
),
99
,
2
);
add_action
(
'oembed_provider_render_xml'
,
array
(
'OembedProviderPlugin'
,
'render_xml'
),
99
);
}
/**
* auto discovery links
...
...
@@ -34,6 +50,8 @@ class OembedProvider {
$query_vars
[]
=
'format'
;
$query_vars
[]
=
'url'
;
$query_vars
[]
=
'callback'
;
$query_vars
[]
=
'maxwidth'
;
$query_vars
[]
=
'maxheight'
;
return
$query_vars
;
}
...
...
@@ -47,11 +65,11 @@ class OembedProvider {
return
;
}
$post_ID
=
url_to_postid
(
$wp
->
query_vars
[
'url'
]);
$post_ID
=
url_to_postid
(
apply_filters
(
'oembed_url'
,
$wp
->
query_vars
[
'url'
])
)
;
$post
=
get_post
(
$post_ID
);
if
(
!
$post
)
{
header
(
'Status:
404
'
);
if
(
!
$post
)
{
status_
header
(
404
);
wp_die
(
"Not found"
);
}
...
...
@@ -91,6 +109,31 @@ class OembedProvider {
$oembed_provider_data
[
'author_url'
]
=
get_author_posts_url
(
$author
->
ID
,
$author
->
nicename
);
$oembed_provider_data
[
'title'
]
=
$post
->
post_title
;
// check content
if
(
!
empty
(
$post
->
post_content
))
{
$oembed_provider_data
[
'html'
]
=
$post
->
post_content
;
$oembed_provider_data
[
'type'
]
=
'rich'
;
}
else
{
$oembed_provider_data
[
'type'
]
=
'link'
;
}
return
$oembed_provider_data
;
}
/**
* adds post/page specific content
*
* @param array $oembed_provider_data
* @param Object $post
*/
public
static
function
generate_post_content
(
$oembed_provider_data
,
$post
)
{
if
(
function_exists
(
'has_post_thumbnail'
)
&&
has_post_thumbnail
(
$post
->
ID
))
{
$image
=
wp_get_attachment_image_src
(
get_post_thumbnail_id
(
$post
->
ID
));
$oembed_provider_data
[
'thumbnail_url'
]
=
$image
[
0
];
$oembed_provider_data
[
'thumbnail_width'
]
=
$image
[
1
];
$oembed_provider_data
[
'thumbnail_height'
]
=
$image
[
2
];
}
return
$oembed_provider_data
;
}
...
...
@@ -101,7 +144,7 @@ class OembedProvider {
* @param Object $post
*/
public
static
function
generate_attachment_content
(
$oembed_provider_data
,
$post
)
{
if
(
substr
(
$post
->
post_mime_type
,
0
,
strlen
(
'image/'
))
==
'image/'
)
{
if
(
wp_attachment_is_image
(
$post
->
ID
)
)
{
$oembed_provider_data
[
'type'
]
=
'photo'
;
}
else
{
$oembed_provider_data
[
'type'
]
=
'link'
;
...
...
@@ -111,27 +154,13 @@ class OembedProvider {
$metadata
=
wp_get_attachment_metadata
(
$post
->
ID
);
$oembed_provider_data
[
'width'
]
=
$metadata
[
'width'
];
$oembed_provider_data
[
'height'
]
=
$metadata
[
'height'
];
return
$oembed_provider_data
;
}
if
(
isset
(
$metadata
[
'width'
]))
{
$oembed_provider_data
[
'width'
]
=
$metadata
[
'width'
];
}
/**
* adds post/page specific content
*
* @param array $oembed_provider_data
* @param Object $post
*/
public
static
function
generate_post_content
(
$oembed_provider_data
,
$post
)
{
if
(
function_exists
(
'has_post_thumbnail'
)
&&
has_post_thumbnail
(
$post
->
ID
))
{
$image
=
wp_get_attachment_image_src
(
get_post_thumbnail_id
(
$post
->
ID
));
$oembed_provider_data
[
'thumbnail_url'
]
=
$image
[
0
];
$oembed_provider_data
[
'thumbnail_width'
]
=
$image
[
1
];
$oembed_provider_data
[
'thumbnail_height'
]
=
$image
[
2
];
if
(
isset
(
$metadata
[
'height'
]))
{
$oembed_provider_data
[
'height'
]
=
$metadata
[
'height'
];
}
$oembed_provider_data
[
'type'
]
=
'rich'
;
$oembed_provider_data
[
'html'
]
=
$post
->
post_content
;
return
$oembed_provider_data
;
}
...
...
@@ -167,20 +196,10 @@ class OembedProvider {
// render xml-output
echo
'<?xml version="1.0" encoding="'
.
get_bloginfo
(
'charset'
)
.
'" ?>'
;
echo
'<oembed>'
;
foreach
(
array_keys
(
$oembed_provider_data
)
as
$element
){
foreach
(
array_keys
(
$oembed_provider_data
)
as
$element
)
{
echo
'<'
.
$element
.
'>'
.
esc_html
(
$oembed_provider_data
[
$element
])
.
'</'
.
$element
.
'>'
;
}
echo
'</oembed>'
;
exit
;
}
}
add_action
(
'wp_head'
,
array
(
'OembedProvider'
,
'add_oembed_links'
));
add_action
(
'parse_query'
,
array
(
'OembedProvider'
,
'parse_query'
));
add_filter
(
'query_vars'
,
array
(
'OembedProvider'
,
'query_vars'
));
add_filter
(
'oembed_provider_data'
,
array
(
'OembedProvider'
,
'generate_default_content'
),
90
,
3
);
add_filter
(
'oembed_provider_data_attachment'
,
array
(
'OembedProvider'
,
'generate_attachment_content'
),
91
,
2
);
add_filter
(
'oembed_provider_data_post'
,
array
(
'OembedProvider'
,
'generate_post_content'
),
91
,
2
);
add_filter
(
'oembed_provider_data_page'
,
array
(
'OembedProvider'
,
'generate_post_content'
),
91
,
2
);
add_action
(
'oembed_provider_render_json'
,
array
(
'OembedProvider'
,
'render_json'
),
99
,
2
);
add_action
(
'oembed_provider_render_xml'
,
array
(
'OembedProvider'
,
'render_xml'
),
99
);
wp-content/plugins/oembed-provider/readme.txt
View file @
15cc7b5d
...
...
@@ -2,8 +2,8 @@
Contributors: pfefferle, candrews
Tags: oembed, links
Requires at least: 3.0
Tested up to:
3.7
.1
Stable tag: 2.
0.1
Tested up to:
4.0
.1
Stable tag: 2.
1.0
An oEmbed provider for Wordpress.
...
...
@@ -27,6 +27,10 @@ Yes!
== Changelog ==
= 2.1.0 =
* added `oembed_url` filter: https://github.com/pfefferle/wordpress-oembed-provider/pull/2
* better `custom_post_type` support
= 2.0.1 =
* type 'rich' now returns the full html
* take use of more WordPress functions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment