Open Graph for Facebook, Google+ and Twitter Card Tags - Version 0.1.9.5

Version Description

  • 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.
Download this release

Release Info

Developer wonderm00n
Plugin Icon Open Graph for Facebook, Google+ and Twitter Card Tags
Version 0.1.9.5
Comparing to
See all releases

Code changes from version 0.1.9 to 0.1.9.5

includes/settings-page.php CHANGED
@@ -32,6 +32,10 @@
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
 
36
  ?>
37
  <div class="wrap">
@@ -245,6 +249,26 @@
245
  Full URL with http://
246
  </td>
247
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  </table>
249
  <p class="submit">
250
  <input type="hidden" name="action" value="save"/>
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');
38
+ $fb_image_use_default=get_option('wonderm00n_open_graph_fb_image_use_default');
39
 
40
  ?>
41
  <div class="wrap">
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>
255
+ <div>
256
+ 1) <input type="checkbox" name="fb_image_use_featured" id="fb_image_use_featured" value="1" <?php echo (intval($fb_image_use_featured)==1 ? ' checked="checked"' : ''); ?>/>
257
+ Image will be fetched from post/page featured/thumbnail picture.</div>
258
+ <div>
259
+ 2) <input type="checkbox" name="fb_image_use_content" id="fb_image_use_content" value="1" <?php echo (intval($fb_image_use_content)==1 ? ' checked="checked"' : ''); ?>/>
260
+ If it doesn't exist, use the first image from the post/page content.
261
+ </div>
262
+ <div>
263
+ 3) <input type="checkbox" name="fb_image_use_media" id="fb_image_use_media" value="1" <?php echo (intval($fb_image_use_media)==1 ? ' checked="checked"' : ''); ?>/>
264
+ If it doesn't exist, use first image from the post/page media gallery.
265
+ </div>
266
+ <div>
267
+ 4) <input type="checkbox" name="fb_image_use_default" id="fb_image_use_default" value="1" <?php echo (intval($fb_image_use_default)==1 ? ' checked="checked"' : ''); ?>/>
268
+ If it doesn't exist, use the default image above.
269
+ </div>
270
+ </td>
271
+ </tr>
272
  </table>
273
  <p class="submit">
274
  <input type="hidden" name="action" value="save"/>
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.1.9
8
 
9
  This plugin inserts Facebook Open Graph Tags into your WordPress Blog/Website for more effective Facebook sharing results.
10
 
@@ -34,6 +34,10 @@ The tags that this plugin inserts are:
34
 
35
  == Changelog ==
36
 
 
 
 
 
37
  = 0.1.9 =
38
 
39
  * Added the og:locale tag. This will be the Wordpress locale by default, but can be chosen by the user also.
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.1.9.5
8
 
9
  This plugin inserts Facebook Open Graph Tags into your WordPress Blog/Website for more effective Facebook sharing results.
10
 
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.
40
+
41
  = 0.1.9 =
42
 
43
  * Added the og:locale tag. This will be the Wordpress locale by default, but can be chosen by the user also.
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.1.9
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.1.9
12
  Author URI: http://wonderm00n.com
13
  */
14
 
@@ -33,6 +33,10 @@ function wonderm00n_open_graph() {
33
  $fb_desc_homepage_customtext = get_option('wonderm00n_open_graph_fb_desc_homepage_customtext');
34
  $fb_image_show=get_option('wonderm00n_open_graph_fb_image_show');
35
  $fb_image=get_option('wonderm00n_open_graph_fb_image');
 
 
 
 
36
 
37
  $fb_type='article';
38
  if (is_singular()) {
@@ -48,10 +52,64 @@ function wonderm00n_open_graph() {
48
  $fb_desc=trim($post->post_content);
49
  }
50
  $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)))));
51
- $thumbok=false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  if (function_exists('get_post_thumbnail_id')) {
53
  $thumbok=true;
54
  }
 
55
  if ($thumbok) {
56
  if ($id_attachment=get_post_thumbnail_id($post->ID)) {
57
  //There's a featured/thumbnail image for this post
@@ -82,7 +140,9 @@ function wonderm00n_open_graph() {
82
  //Well... We sure did try. We'll just keep the default one :-(
83
  }
84
  }
85
- }
 
 
86
  } else {
87
  global $wp_query;
88
  //Other pages - Defaults
@@ -223,6 +283,10 @@ if ( is_admin() ) {
223
  update_option("wonderm00n_open_graph_fb_desc_show", 1);
224
  update_option("wonderm00n_open_graph_fb_desc_chars", 300);
225
  update_option("wonderm00n_open_graph_fb_image_show", 1);
 
 
 
 
226
  }
227
 
228
  function wonderm00n_open_graph_settings_link( $links, $file ) {
@@ -270,7 +334,35 @@ if ( is_admin() ) {
270
  update_option('wonderm00n_open_graph_fb_desc_homepage_customtext', trim($_POST['fb_desc_homepage_customtext']));
271
  update_option('wonderm00n_open_graph_fb_image_show', intval($_POST['fb_image_show']));
272
  update_option('wonderm00n_open_graph_fb_image', trim($_POST['fb_image']));
 
 
 
 
273
  }
274
  }
275
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  ?>
1
  <?php
2
  /**
3
  * @package Wonderm00n's Simple Facebook Open Graph Meta Tags
4
+ * @version 0.1.9.5
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.1.9.5
12
  Author URI: http://wonderm00n.com
13
  */
14
 
33
  $fb_desc_homepage_customtext = get_option('wonderm00n_open_graph_fb_desc_homepage_customtext');
34
  $fb_image_show=get_option('wonderm00n_open_graph_fb_image_show');
35
  $fb_image=get_option('wonderm00n_open_graph_fb_image');
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');
39
+ $fb_image_use_default=get_option('wonderm00n_open_graph_fb_image_use_default');
40
 
41
  $fb_type='article';
42
  if (is_singular()) {
52
  $fb_desc=trim($post->post_content);
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
+ $thumbdone=false;
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
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
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);
289
+ update_option("wonderm00n_open_graph_fb_image_use_default", 1);
290
  }
291
 
292
  function wonderm00n_open_graph_settings_link( $links, $file ) {
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']));
340
+ update_option('wonderm00n_open_graph_fb_image_use_default', intval($_POST['fb_image_use_default']));
341
  }
342
  }
343
  }
344
+
345
+
346
+
347
+
348
+ //Upgrade 2012-01-02 (locale)
349
+ if (trim(get_option('wonderm00n_open_graph_fb_locale_show'))=='') {
350
+ update_option("wonderm00n_open_graph_fb_locale_show", 1);
351
+ }
352
+ //Upgrade 2012-01-02 (images)
353
+ if (
354
+ trim(get_option('wonderm00n_open_graph_fb_image_use_featured'))==''
355
+ ||
356
+ trim(get_option('wonderm00n_open_graph_fb_image_use_content'))==''
357
+ ||
358
+ trim(get_option('wonderm00n_open_graph_fb_image_use_media'))==''
359
+ ||
360
+ trim(get_option('wonderm00n_open_graph_fb_image_use_default'))==''
361
+ ) {
362
+ update_option("wonderm00n_open_graph_fb_image_use_featured", 1);
363
+ update_option("wonderm00n_open_graph_fb_image_use_content", 1);
364
+ update_option("wonderm00n_open_graph_fb_image_use_media", 1);
365
+ update_option("wonderm00n_open_graph_fb_image_use_default", 1);
366
+ }
367
+
368
  ?>