Version Description
- If the option is set to true, the same image obtained to the og:image will be added to the RSS feed on the "enclosure" and "media:content" tags so that apps like RSS Graffiti and twitterfeed post them correctly.
Download this release
Release Info
Developer | wonderm00n |
Plugin | Open Graph for Facebook, Google+ and Twitter Card Tags |
Version | 0.2 |
Comparing to | |
See all releases |
Code changes from version 0.1.9.5 to 0.2
- includes/settings-page.php +12 -8
- readme.txt +7 -2
- wonderm00n-open-graph.php +108 -91
includes/settings-page.php
CHANGED
@@ -32,6 +32,7 @@
|
|
32 |
$fb_desc_homepage_customtext = get_option('wonderm00n_open_graph_fb_desc_homepage_customtext');
|
33 |
$fb_image_show=get_option('wonderm00n_open_graph_fb_image_show');
|
34 |
$fb_image=get_option('wonderm00n_open_graph_fb_image');
|
|
|
35 |
$fb_image_use_featured=get_option('wonderm00n_open_graph_fb_image_use_featured');
|
36 |
$fb_image_use_content=get_option('wonderm00n_open_graph_fb_image_use_content');
|
37 |
$fb_image_use_media=get_option('wonderm00n_open_graph_fb_image_use_media');
|
@@ -172,12 +173,8 @@
|
|
172 |
<tr class="fb_url_options">
|
173 |
<th scope="row" nowrap="nowrap">Add trailing slash at the end:</th>
|
174 |
<td>
|
175 |
-
<
|
176 |
-
|
177 |
-
<option value="1"<?php if (intval($fb_url_add_trailing)==1) echo ' selected="selected"'; ?>>Yes </option>
|
178 |
-
</select>
|
179 |
-
<br/>
|
180 |
-
On the homepage will be: <i><?php echo get_option('siteurl'); ?><span id="fb_url_add_trailing_example">/</span></i>
|
181 |
</td>
|
182 |
</tr>
|
183 |
<tr>
|
@@ -188,7 +185,7 @@
|
|
188 |
<th scope="row" nowrap="nowrap">Include Type (og:type) tag?</th>
|
189 |
<td>
|
190 |
<input type="checkbox" name="fb_type_show" id="fb_type_show" value="1" <?php echo (intval($fb_type_show)==1 ? ' checked="checked"' : ''); ?> onclick="showTypeOptions();"/>
|
191 |
-
(will be
|
192 |
</td>
|
193 |
</tr>
|
194 |
<tr class="fb_type_options">
|
@@ -249,6 +246,13 @@
|
|
249 |
Full URL with http://
|
250 |
</td>
|
251 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
<tr class="fb_image_options">
|
253 |
<th scope="row" nowrap="nowrap">On posts/pages:</th>
|
254 |
<td>
|
@@ -400,7 +404,7 @@
|
|
400 |
}
|
401 |
}
|
402 |
function showUrlTrail() {
|
403 |
-
if (jQuery('#fb_url_add_trailing').
|
404 |
jQuery('#fb_url_add_trailing_example').show();
|
405 |
} else {
|
406 |
jQuery('#fb_url_add_trailing_example').hide();
|
32 |
$fb_desc_homepage_customtext = get_option('wonderm00n_open_graph_fb_desc_homepage_customtext');
|
33 |
$fb_image_show=get_option('wonderm00n_open_graph_fb_image_show');
|
34 |
$fb_image=get_option('wonderm00n_open_graph_fb_image');
|
35 |
+
$fb_image_rss=get_option('wonderm00n_open_graph_fb_image_rss');
|
36 |
$fb_image_use_featured=get_option('wonderm00n_open_graph_fb_image_use_featured');
|
37 |
$fb_image_use_content=get_option('wonderm00n_open_graph_fb_image_use_content');
|
38 |
$fb_image_use_media=get_option('wonderm00n_open_graph_fb_image_use_media');
|
173 |
<tr class="fb_url_options">
|
174 |
<th scope="row" nowrap="nowrap">Add trailing slash at the end:</th>
|
175 |
<td>
|
176 |
+
<input type="checkbox" name="fb_url_add_trailing" id="fb_url_add_trailing" value="1" <?php echo (intval($fb_url_add_trailing)==1 ? ' checked="checked"' : ''); ?> onclick="showUrlTrail();"/>
|
177 |
+
(on the homepage will be: <i><?php echo get_option('siteurl'); ?><span id="fb_url_add_trailing_example">/</span></i>)
|
|
|
|
|
|
|
|
|
178 |
</td>
|
179 |
</tr>
|
180 |
<tr>
|
185 |
<th scope="row" nowrap="nowrap">Include Type (og:type) tag?</th>
|
186 |
<td>
|
187 |
<input type="checkbox" name="fb_type_show" id="fb_type_show" value="1" <?php echo (intval($fb_type_show)==1 ? ' checked="checked"' : ''); ?> onclick="showTypeOptions();"/>
|
188 |
+
(will be "article" for posts and pages and "website" or "blog" for the homepage)
|
189 |
</td>
|
190 |
</tr>
|
191 |
<tr class="fb_type_options">
|
246 |
Full URL with http://
|
247 |
</td>
|
248 |
</tr>
|
249 |
+
<tr class="fb_image_options">
|
250 |
+
<th scope="row" nowrap="nowrap">Also add image to RSS/RSS2 feeds?</th>
|
251 |
+
<td>
|
252 |
+
<input type="checkbox" name="fb_image_rss" id="fb_image_rss" value="1" <?php echo (intval($fb_image_rss)==1 ? ' checked="checked"' : ''); ?> onclick="showImageOptions();"/>
|
253 |
+
(for auto-posting apps like RSS Graffiti, twitterfeed, ...)
|
254 |
+
</td>
|
255 |
+
</tr>
|
256 |
<tr class="fb_image_options">
|
257 |
<th scope="row" nowrap="nowrap">On posts/pages:</th>
|
258 |
<td>
|
404 |
}
|
405 |
}
|
406 |
function showUrlTrail() {
|
407 |
+
if (jQuery('#fb_url_add_trailing').is(':checked')) {
|
408 |
jQuery('#fb_url_add_trailing_example').show();
|
409 |
} else {
|
410 |
jQuery('#fb_url_add_trailing_example').hide();
|
readme.txt
CHANGED
@@ -4,13 +4,14 @@ Donate link: http://blog.wonderm00n.com/2011/10/14/wordpress-plugin-simple-faceb
|
|
4 |
Tags: facebook, open graph, seo, share, social, meta
|
5 |
Requires at least: 3
|
6 |
Tested up to: 3.2.1
|
7 |
-
Stable tag: 0.
|
8 |
|
9 |
This plugin inserts Facebook Open Graph Tags into your WordPress Blog/Website for more effective Facebook sharing results.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
This plugin inserts Facebook Open Graph Tags into your WordPress Blog/Website for more effective Facebook sharing results.
|
|
|
14 |
|
15 |
It allows the user to choose which tags are, or not, included and also the default image if the post/page doesn't have one.
|
16 |
|
@@ -24,7 +25,7 @@ The tags that this plugin inserts are:
|
|
24 |
* **og:url** : From the post/page permalink.
|
25 |
* **og:type** : "website" or "blog" for the homepage and "article" for all the others.
|
26 |
* **og:description** : From post/page excerpt if it exist, or from post/page content. From category/tag description on it's pages, if it exist. From tagline, or custom text, on all the others.
|
27 |
-
* **og:image** : From post/page featured/thumbnail image, or if it doesn't exist from the first image in the post content, or if it doesn't exist from the first image on the post media gallery, or if it doesn't exist from the default image defined on the options menu.
|
28 |
|
29 |
== Installation ==
|
30 |
|
@@ -34,6 +35,10 @@ The tags that this plugin inserts are:
|
|
34 |
|
35 |
== Changelog ==
|
36 |
|
|
|
|
|
|
|
|
|
37 |
= 0.1.9.5 =
|
38 |
|
39 |
* It's now possible to choose how the post/page og:image tag is set. It means that if the user doesn't want to use the featured/thumbnail image, or the first image in the post content, or the first image on the media gallery, or even the default image, he can choose not to.
|
4 |
Tags: facebook, open graph, seo, share, social, meta
|
5 |
Requires at least: 3
|
6 |
Tested up to: 3.2.1
|
7 |
+
Stable tag: 0.2
|
8 |
|
9 |
This plugin inserts Facebook Open Graph Tags into your WordPress Blog/Website for more effective Facebook sharing results.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
This plugin inserts Facebook Open Graph Tags into your WordPress Blog/Website for more effective Facebook sharing results.
|
14 |
+
It also allows to insert the "enclosure" and "media:content" tags to the RSS feeds, so that apps like RSS Graffiti and twitterfeed post the image to Facebook correctly.
|
15 |
|
16 |
It allows the user to choose which tags are, or not, included and also the default image if the post/page doesn't have one.
|
17 |
|
25 |
* **og:url** : From the post/page permalink.
|
26 |
* **og:type** : "website" or "blog" for the homepage and "article" for all the others.
|
27 |
* **og:description** : From post/page excerpt if it exist, or from post/page content. From category/tag description on it's pages, if it exist. From tagline, or custom text, on all the others.
|
28 |
+
* **og:image** : From post/page featured/thumbnail image, or if it doesn't exist from the first image in the post content, or if it doesn't exist from the first image on the post media gallery, or if it doesn't exist from the default image defined on the options menu. The same image chosen here will be used and enclosure/media:content on the RSS feed.
|
29 |
|
30 |
== Installation ==
|
31 |
|
35 |
|
36 |
== Changelog ==
|
37 |
|
38 |
+
= 0.2 =
|
39 |
+
|
40 |
+
* If the option is set to true, the same image obtained to the og:image will be added to the RSS feed on the "enclosure" and "media:content" tags so that apps like RSS Graffiti and twitterfeed post them correctly.
|
41 |
+
|
42 |
= 0.1.9.5 =
|
43 |
|
44 |
* It's now possible to choose how the post/page og:image tag is set. It means that if the user doesn't want to use the featured/thumbnail image, or the first image in the post content, or the first image on the media gallery, or even the default image, he can choose not to.
|
wonderm00n-open-graph.php
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* @package Wonderm00n's Simple Facebook Open Graph Meta Tags
|
4 |
-
* @version 0.
|
5 |
*/
|
6 |
/*
|
7 |
Plugin Name: Wonderm00n's Simple Facebook Open Graph Meta Tags
|
8 |
Plugin URI: http://blog.wonderm00n.com/2011/10/14/wordpress-plugin-simple-facebook-open-graph-tags/
|
9 |
Description: This plugin inserts Facebook Open Graph Tags into your Wordpress Blog/Website for better Facebook sharing
|
10 |
Author: Marco Almeida (Wonderm00n)
|
11 |
-
Version: 0.
|
12 |
Author URI: http://wonderm00n.com
|
13 |
*/
|
14 |
|
@@ -53,96 +53,8 @@ function wonderm00n_open_graph() {
|
|
53 |
}
|
54 |
$fb_desc=(intval($fb_desc_chars)>0 ? substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))),0,$fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))));
|
55 |
if (intval($fb_image_show)==1) {
|
56 |
-
$
|
57 |
-
//Featured image
|
58 |
-
if (function_exists('get_post_thumbnail_id')) {
|
59 |
-
if (intval($fb_image_use_featured)==1) {
|
60 |
-
if ($id_attachment=get_post_thumbnail_id($post->ID)) {
|
61 |
-
//There's a featured/thumbnail image for this post
|
62 |
-
$fb_image=wp_get_attachment_url($id_attachment, false);
|
63 |
-
$thumbdone=true;
|
64 |
-
}
|
65 |
-
}
|
66 |
-
}
|
67 |
-
//From post/page content
|
68 |
-
if (!$thumbdone) {
|
69 |
-
if (intval($fb_image_use_content)==1) {
|
70 |
-
$imgreg = '/<img .*src=["\']([^ ^"^\']*)["\']/';
|
71 |
-
preg_match_all($imgreg, trim($post->post_content), $matches);
|
72 |
-
$image=$matches[1][0];
|
73 |
-
if ($image) {
|
74 |
-
//There's an image on the content
|
75 |
-
$pos = strpos($image, site_url());
|
76 |
-
if ($pos === false) {
|
77 |
-
$fb_image=$_SERVER['HTTP_HOST'].$image;
|
78 |
-
} else {
|
79 |
-
$fb_image=$image;
|
80 |
-
}
|
81 |
-
$thumbdone=true;
|
82 |
-
}
|
83 |
-
}
|
84 |
-
}
|
85 |
-
//From media gallery
|
86 |
-
if (!$thumbdone) {
|
87 |
-
if (intval($fb_image_use_media)==1) {
|
88 |
-
$images = get_posts(array('post_type' => 'attachment','numberposts' => 1,'post_status' => null,'order' => 'ASC','orderby' => 'menu_order','post_mime_type' => 'image','post_parent' => $post->ID));
|
89 |
-
if ($images) {
|
90 |
-
$fb_image=wp_get_attachment_url($images[0]->ID, false);
|
91 |
-
$thumbdone=true;
|
92 |
-
}
|
93 |
-
}
|
94 |
-
}
|
95 |
-
//From default
|
96 |
-
if (!$thumbdone) {
|
97 |
-
if (intval($fb_image_use_default)==1) {
|
98 |
-
//Well... We sure did try. We'll just keep the default one!
|
99 |
-
//$fb_image is already set
|
100 |
-
} else {
|
101 |
-
//User chose not to use default on pages/posts
|
102 |
-
$fb_image='';
|
103 |
-
}
|
104 |
-
}
|
105 |
-
}
|
106 |
-
|
107 |
-
|
108 |
-
/*$thumbok=false;
|
109 |
-
if (function_exists('get_post_thumbnail_id')) {
|
110 |
-
$thumbok=true;
|
111 |
}
|
112 |
-
//From post/page featured/image
|
113 |
-
if ($thumbok) {
|
114 |
-
if ($id_attachment=get_post_thumbnail_id($post->ID)) {
|
115 |
-
//There's a featured/thumbnail image for this post
|
116 |
-
$fb_image=wp_get_attachment_url($id_attachment, false);
|
117 |
-
} else {
|
118 |
-
$thumbok=false;
|
119 |
-
}
|
120 |
-
}
|
121 |
-
if (!$thumbok) {
|
122 |
-
//If not, we'll try to get the first image on the post content
|
123 |
-
$imgreg = '/<img .*src=["\']([^ ^"^\']*)["\']/';
|
124 |
-
preg_match_all($imgreg, trim($post->post_content), $matches);
|
125 |
-
$image=$matches[1][0];
|
126 |
-
if ($image) {
|
127 |
-
//There's an image on the content
|
128 |
-
$pos = strpos($image, site_url());
|
129 |
-
if ($pos === false) {
|
130 |
-
$fb_image=$_SERVER['HTTP_HOST'].$image;
|
131 |
-
} else {
|
132 |
-
$fb_image=$image;
|
133 |
-
}
|
134 |
-
} else {
|
135 |
-
//If not, we'll try to get the first image associated to the post, even if not used on the content
|
136 |
-
$images = get_posts(array('post_type' => 'attachment','numberposts' => 1,'post_status' => null,'order' => 'ASC','orderby' => 'menu_order','post_mime_type' => 'image','post_parent' => $post->ID));
|
137 |
-
if ($images) {
|
138 |
-
$fb_image=wp_get_attachment_url($images[0]->ID, false);
|
139 |
-
} else {
|
140 |
-
//Well... We sure did try. We'll just keep the default one :-(
|
141 |
-
}
|
142 |
-
}
|
143 |
-
}*/
|
144 |
-
|
145 |
-
|
146 |
} else {
|
147 |
global $wp_query;
|
148 |
//Other pages - Defaults
|
@@ -259,6 +171,109 @@ function wonderm00n_open_graph_add_opengraph_namespace( $output ) {
|
|
259 |
//We want to be last to add the namespace because some other plugin may already added it ;-)
|
260 |
add_filter('language_attributes', 'wonderm00n_open_graph_add_opengraph_namespace',9999);
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
//Admin
|
263 |
if ( is_admin() ) {
|
264 |
add_action('admin_menu', 'wonderm00n_open_graph_add_options');
|
@@ -283,6 +298,7 @@ if ( is_admin() ) {
|
|
283 |
update_option("wonderm00n_open_graph_fb_desc_show", 1);
|
284 |
update_option("wonderm00n_open_graph_fb_desc_chars", 300);
|
285 |
update_option("wonderm00n_open_graph_fb_image_show", 1);
|
|
|
286 |
update_option("wonderm00n_open_graph_fb_image_use_featured", 1);
|
287 |
update_option("wonderm00n_open_graph_fb_image_use_content", 1);
|
288 |
update_option("wonderm00n_open_graph_fb_image_use_media", 1);
|
@@ -334,6 +350,7 @@ if ( is_admin() ) {
|
|
334 |
update_option('wonderm00n_open_graph_fb_desc_homepage_customtext', trim($_POST['fb_desc_homepage_customtext']));
|
335 |
update_option('wonderm00n_open_graph_fb_image_show', intval($_POST['fb_image_show']));
|
336 |
update_option('wonderm00n_open_graph_fb_image', trim($_POST['fb_image']));
|
|
|
337 |
update_option('wonderm00n_open_graph_fb_image_use_featured', intval($_POST['fb_image_use_featured']));
|
338 |
update_option('wonderm00n_open_graph_fb_image_use_content', intval($_POST['fb_image_use_content']));
|
339 |
update_option('wonderm00n_open_graph_fb_image_use_media', intval($_POST['fb_image_use_media']));
|
1 |
<?php
|
2 |
/**
|
3 |
* @package Wonderm00n's Simple Facebook Open Graph Meta Tags
|
4 |
+
* @version 0.2
|
5 |
*/
|
6 |
/*
|
7 |
Plugin Name: Wonderm00n's Simple Facebook Open Graph Meta Tags
|
8 |
Plugin URI: http://blog.wonderm00n.com/2011/10/14/wordpress-plugin-simple-facebook-open-graph-tags/
|
9 |
Description: This plugin inserts Facebook Open Graph Tags into your Wordpress Blog/Website for better Facebook sharing
|
10 |
Author: Marco Almeida (Wonderm00n)
|
11 |
+
Version: 0.2
|
12 |
Author URI: http://wonderm00n.com
|
13 |
*/
|
14 |
|
53 |
}
|
54 |
$fb_desc=(intval($fb_desc_chars)>0 ? substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))),0,$fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))));
|
55 |
if (intval($fb_image_show)==1) {
|
56 |
+
$fb_image=wonderm00n_open_graph_post_image($fb_image_use_featured, $fb_image_use_content, $fb_image_use_media, $fb_image_use_default, $fb_image);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
} else {
|
59 |
global $wp_query;
|
60 |
//Other pages - Defaults
|
171 |
//We want to be last to add the namespace because some other plugin may already added it ;-)
|
172 |
add_filter('language_attributes', 'wonderm00n_open_graph_add_opengraph_namespace',9999);
|
173 |
|
174 |
+
//Add images also to RSS feed. Most code from WP RSS Images by Alain Gonzalez
|
175 |
+
function wonderm00n_open_graph_images_on_feed($comments) {
|
176 |
+
$fb_image_rss=get_option('wonderm00n_open_graph_fb_image_rss');
|
177 |
+
if (intval($fb_image_rss)==1) {
|
178 |
+
if (!$comments) {
|
179 |
+
add_action('rss2_ns', 'wonderm00n_open_graph_images_on_feed_yahoo_media_tag');
|
180 |
+
add_action('rss_item', 'wonderm00n_open_graph_images_on_feed_image');
|
181 |
+
add_action('rss2_item', 'wonderm00n_open_graph_images_on_feed_image');
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
function wonderm00n_open_graph_images_on_feed_yahoo_media_tag() {
|
186 |
+
echo 'xmlns:media="http://search.yahoo.com/mrss/"';
|
187 |
+
}
|
188 |
+
function wonderm00n_open_graph_images_on_feed_image() {
|
189 |
+
$fb_image=get_option('wonderm00n_open_graph_fb_image');
|
190 |
+
$fb_image_use_featured=get_option('wonderm00n_open_graph_fb_image_use_featured');
|
191 |
+
$fb_image_use_content=get_option('wonderm00n_open_graph_fb_image_use_content');
|
192 |
+
$fb_image_use_media=get_option('wonderm00n_open_graph_fb_image_use_media');
|
193 |
+
$fb_image_use_default=get_option('wonderm00n_open_graph_fb_image_use_default');
|
194 |
+
$fb_image = wonderm00n_open_graph_post_image($fb_image_use_featured, $fb_image_use_content, $fb_image_use_media, $fb_image_use_default, $fb_image);
|
195 |
+
if ($fb_image!='') {
|
196 |
+
$uploads = wp_upload_dir();
|
197 |
+
$url = parse_url($fb_image);
|
198 |
+
$path = $uploads['basedir'] . preg_replace( '/.*uploads(.*)/', '${1}', $url['path'] );
|
199 |
+
//echo $path;
|
200 |
+
if (file_exists($path)) {
|
201 |
+
$filesize=filesize($path);
|
202 |
+
$url=$path;
|
203 |
+
} else {
|
204 |
+
$header=get_headers($fb_image, 1);
|
205 |
+
$filesize=$header['Content-Length'];
|
206 |
+
$url=$fb_image;
|
207 |
+
}
|
208 |
+
list($width, $height, $type, $attr) = getimagesize($url);
|
209 |
+
echo '<enclosure url="' . $fb_image . '" length="' . $filesize . '" type="'.image_type_to_mime_type($type).'" />';
|
210 |
+
echo '<media:content url="'.$fb_image.'" width="'.$width.'" height="'.$height.'" medium="image" type="'.image_type_to_mime_type($type).'" />';
|
211 |
+
}
|
212 |
+
}
|
213 |
+
add_action("do_feed_rss","wonderm00n_open_graph_images_on_feed",5,1);
|
214 |
+
add_action("do_feed_rss2","wonderm00n_open_graph_images_on_feed",5,1);
|
215 |
+
|
216 |
+
//Post image
|
217 |
+
function wonderm00n_open_graph_post_image($fb_image_use_featured=1, $fb_image_use_content=1, $fb_image_use_media=1, $fb_image_use_default=1, $default_image='') {
|
218 |
+
global $post;
|
219 |
+
$thumbdone=false;
|
220 |
+
$fb_image='';
|
221 |
+
//Featured image
|
222 |
+
if (function_exists('get_post_thumbnail_id')) {
|
223 |
+
if (intval($fb_image_use_featured)==1) {
|
224 |
+
if ($id_attachment=get_post_thumbnail_id($post->ID)) {
|
225 |
+
//There's a featured/thumbnail image for this post
|
226 |
+
$fb_image=wp_get_attachment_url($id_attachment, false);
|
227 |
+
$thumbdone=true;
|
228 |
+
//echo 'IMG FEAT';
|
229 |
+
}
|
230 |
+
}
|
231 |
+
}
|
232 |
+
//From post/page content
|
233 |
+
if (!$thumbdone) {
|
234 |
+
if (intval($fb_image_use_content)==1) {
|
235 |
+
$imgreg = '/<img .*src=["\']([^ ^"^\']*)["\']/';
|
236 |
+
preg_match_all($imgreg, trim($post->post_content), $matches);
|
237 |
+
$image=$matches[1][0];
|
238 |
+
if ($image) {
|
239 |
+
//There's an image on the content
|
240 |
+
$pos = strpos($image, site_url());
|
241 |
+
if ($pos === false) {
|
242 |
+
$fb_image=$_SERVER['HTTP_HOST'].$image;
|
243 |
+
} else {
|
244 |
+
$fb_image=$image;
|
245 |
+
}
|
246 |
+
$thumbdone=true;
|
247 |
+
//echo 'IMG CONTENT';
|
248 |
+
}
|
249 |
+
}
|
250 |
+
}
|
251 |
+
//From media gallery
|
252 |
+
if (!$thumbdone) {
|
253 |
+
if (intval($fb_image_use_media)==1) {
|
254 |
+
$images = get_posts(array('post_type' => 'attachment','numberposts' => 1,'post_status' => null,'order' => 'ASC','orderby' => 'menu_order','post_mime_type' => 'image','post_parent' => $post->ID));
|
255 |
+
if ($images) {
|
256 |
+
$fb_image=wp_get_attachment_url($images[0]->ID, false);
|
257 |
+
$thumbdone=true;
|
258 |
+
//echo 'IMG MEDIA';
|
259 |
+
}
|
260 |
+
}
|
261 |
+
}
|
262 |
+
//From default
|
263 |
+
if (!$thumbdone) {
|
264 |
+
if (intval($fb_image_use_default)==1) {
|
265 |
+
//Well... We sure did try. We'll just keep the default one!
|
266 |
+
$fb_image=$default_image;
|
267 |
+
//echo 'IMG DEFAULT';
|
268 |
+
} else {
|
269 |
+
//User chose not to use default on pages/posts
|
270 |
+
$fb_image='';
|
271 |
+
//echo 'IMG NO IMG';
|
272 |
+
}
|
273 |
+
}
|
274 |
+
return $fb_image;
|
275 |
+
}
|
276 |
+
|
277 |
//Admin
|
278 |
if ( is_admin() ) {
|
279 |
add_action('admin_menu', 'wonderm00n_open_graph_add_options');
|
298 |
update_option("wonderm00n_open_graph_fb_desc_show", 1);
|
299 |
update_option("wonderm00n_open_graph_fb_desc_chars", 300);
|
300 |
update_option("wonderm00n_open_graph_fb_image_show", 1);
|
301 |
+
update_option("wonderm00n_open_graph_fb_image_rss", 0);
|
302 |
update_option("wonderm00n_open_graph_fb_image_use_featured", 1);
|
303 |
update_option("wonderm00n_open_graph_fb_image_use_content", 1);
|
304 |
update_option("wonderm00n_open_graph_fb_image_use_media", 1);
|
350 |
update_option('wonderm00n_open_graph_fb_desc_homepage_customtext', trim($_POST['fb_desc_homepage_customtext']));
|
351 |
update_option('wonderm00n_open_graph_fb_image_show', intval($_POST['fb_image_show']));
|
352 |
update_option('wonderm00n_open_graph_fb_image', trim($_POST['fb_image']));
|
353 |
+
update_option('wonderm00n_open_graph_fb_image_rss', intval($_POST['fb_image_rss']));
|
354 |
update_option('wonderm00n_open_graph_fb_image_use_featured', intval($_POST['fb_image_use_featured']));
|
355 |
update_option('wonderm00n_open_graph_fb_image_use_content', intval($_POST['fb_image_use_content']));
|
356 |
update_option('wonderm00n_open_graph_fb_image_use_media', intval($_POST['fb_image_use_media']));
|