Pinterest "Pin It" Button - Version 1.3.0

Version Description

  • Added a Pin Count option (horizontal or vertical)
  • Added new button style where image is pre-selected (like official Pinterest button)
  • Added fields for specifying URL, image URL and description for new button style image pre-selected
  • Added float option for alignment (none, left or right) to widget and shortcode
  • Can now remove shortcode surrounding div tag wrapper
  • Can now remove widget surrounding div tag wrapper
  • Moved "Follow" button widget to separate plugin: Pinterest Follow Button Plugin
  • Both button styles now embed iframe (like official Pinterest button)
  • External JavaScript now loads in footer for better performance
  • Fixed bug where front page was still showing button even when Front Page was unchecked
  • Fixed bug where some settings weren't saved when upgrading the plugin
  • Fixed bug where tag, author, date and search archive pages were not displaying the button
Download this release

Release Info

Developer pderksen
Plugin Icon 128x128 Pinterest "Pin It" Button
Version 1.3.0
Comparing to
See all releases

Code changes from version 1.2.0 to 1.3.0

css/pinterest-pin-it-button-admin.css CHANGED
@@ -1,4 +1,4 @@
1
- /* Pinterest Pin It Button Admin CSS */
2
 
3
  .form-table {
4
  margin-bottom: 10px !important;
@@ -25,11 +25,6 @@
25
  margin: 10px 10px 0 0;
26
  }
27
 
28
- #other-links ul li {
29
- font-size: 15px;
30
- line-height: 1.2em;
31
- }
32
-
33
  .pib-settings {
34
  width: 70%;
35
  }
@@ -38,22 +33,29 @@
38
  width: 30%;
39
  }
40
 
41
- .hndle {
42
- color:#464646;
43
- background-color:#F1F1F1;
44
- font-size:15px;
45
- padding:7px 10px;
46
- display:block;
47
- margin-top:0px;
48
- font-weight:normal;
49
- cursor:default !important;
 
 
 
 
 
50
  }
51
 
52
- .wrap {
53
- background-position:fixed;
 
54
  }
55
 
56
- /* Mailchimp embedded form */
 
57
 
58
  #email-signup {
59
  /* background-color: #464646; */
@@ -89,8 +91,9 @@
89
  #mc_embed_signup .clear {clear:none; display:inline;}
90
  #mc_embed_signup input.email {display:block; padding:8px 0; margin:0 4% 10px 0; text-indent:5px; width:58%; min-width:130px;}
91
 
92
- /*
93
- SUPER CONVERSION BUTTON
 
94
 
95
  Conversion buttons made simple:
96
  http://www.performable.com/buttons/
@@ -149,3 +152,5 @@ a.awesome:active {
149
 
150
  .red.awesome,.red.awesome:visited{background-color:#CC1100 !important;}
151
  .red.awesome:hover{background-color:#991100 !important;}
 
 
1
+ /* Pinterest "Pin It" Button Admin CSS */
2
 
3
  .form-table {
4
  margin-bottom: 10px !important;
25
  margin: 10px 10px 0 0;
26
  }
27
 
 
 
 
 
 
28
  .pib-settings {
29
  width: 70%;
30
  }
33
  width: 30%;
34
  }
35
 
36
+ .postbox .pib-hndle {
37
+ cursor:pointer;
38
+ }
39
+
40
+ #pib-custom-css {
41
+ width: 100%;
42
+ }
43
+
44
+ .pib-full-width-textbox {
45
+ width: 100%;
46
+ }
47
+
48
+ td.pib-pad-cell-top {
49
+ padding-top: 7px;
50
  }
51
 
52
+ label.pib-plain-label {
53
+ margin: 0;
54
+ padding: 0;
55
  }
56
 
57
+
58
+ /* BEGIN Mailchimp Embedded Form CSS */
59
 
60
  #email-signup {
61
  /* background-color: #464646; */
91
  #mc_embed_signup .clear {clear:none; display:inline;}
92
  #mc_embed_signup input.email {display:block; padding:8px 0; margin:0 4% 10px 0; text-indent:5px; width:58%; min-width:130px;}
93
 
94
+ /* END Mailchimp Embedded Form CSS */
95
+
96
+ /* BEGIN Super Conversion Button CSS
97
 
98
  Conversion buttons made simple:
99
  http://www.performable.com/buttons/
152
 
153
  .red.awesome,.red.awesome:visited{background-color:#CC1100 !important;}
154
  .red.awesome:hover{background-color:#991100 !important;}
155
+
156
+ /* END Super Conversion Button CSS */
css/pinterest-pin-it-button.css CHANGED
@@ -2,35 +2,32 @@
2
 
3
  /* DIV surrounding button */
4
  .pin-it-btn-wrapper,
5
- .pin-it-btn-shortcode-wrapper {
6
- height: 30px;
7
- margin: 0;
8
- padding: 0;
9
  }
10
 
11
- /* From Pinterest official html */
12
- a.pin-it-btn {
13
- position: absolute;
14
- background: url(http://assets.pinterest.com/images/pinit6.png);
15
- font: 11px Arial, sans-serif;
16
- text-indent: -9999em;
17
- font-size: .01em;
18
- color: #CD1F1F;
19
- height: 20px;
20
- width: 43px;
21
- background-position: 0 -7px;
22
  }
23
 
24
- a.pin-it-btn:hover {
25
- background-position: 0 -28px;
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
- a.pin-it-btn:active {
29
- background-position: 0 -49px;
30
  }
31
 
32
- /* Widgets */
33
- .pib_widget_button,
34
- .pib_widget_follow_button {
35
- clear: both;
36
  }
2
 
3
  /* DIV surrounding button */
4
  .pin-it-btn-wrapper,
5
+ .pin-it-btn-wrapper-shortcode,
6
+ .pin-it-btn-wrapper-widget {
7
+
 
8
  }
9
 
10
+ .pin-it-btn-wrapper {
11
+ padding-bottom: 10px;
 
 
 
 
 
 
 
 
 
12
  }
13
 
14
+ /* Latest "clear fix" method: http://css-tricks.com/snippets/css/clear-fix/ */
15
+ .pib-clearfix:before,
16
+ .pib-clearfix:after {
17
+ content:"";
18
+ display:table;
19
+ }
20
+ .pib-clearfix:after {
21
+ clear:both;
22
+ }
23
+ .pib-clearfix {
24
+ zoom:1; /* For IE 6/7 (trigger hasLayout) */
25
  }
26
 
27
+ .pib-float-left {
28
+ float: left;
29
  }
30
 
31
+ .pib-float-right {
32
+ float: right;
 
 
33
  }
img/{pinit-button-icon-med.png → pinterest-button-icon-med.png} RENAMED
File without changes
img/{pinit-button-icon-small.png → pinterest-button-icon-small.png} RENAMED
File without changes
inc/admin-pin-it-button-iframe.html CHANGED
@@ -1,9 +1,8 @@
1
  <html>
2
  <body style="margin: 0; padding: 0;">
3
 
4
- <a href="http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fpinterestplugin.com&media=http%3A%2F%2Fpinterestplugin.com%2Fwp-content%2Fuploads%2F2012%2F02%2Fpinterest-pin-it-button-wordpress-plugin.jpg&description=Pinterest%20%22Pin%20It%22%20Button%20Plugin%20for%20WordPress"
5
- class="pin-it-button" count-layout="horizontal">Pin It</a>
6
- <script type="text/javascript" async src="//assets.pinterest.com/js/pinit.js"></script>
7
 
8
  </body>
9
  </html>
1
  <html>
2
  <body style="margin: 0; padding: 0;">
3
 
4
+ <a href="http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fpinterestplugin.com%2F&media=http%3A%2F%2Fpinterestplugin.com%2Fwp-content%2Fuploads%2F2012%2F02%2Fpinterest-pin-it-button-wordpress-plugin.jpg&description=Pinterest%20%22Pin%20It%22%20Button%20Plugin%20for%20WordPress%20--%20http%3A%2F%2Fpinterestplugin.com" class="pin-it-button" count-layout="horizontal">Pin It</a>
5
+ <script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
 
6
 
7
  </body>
8
  </html>
inc/pin-it-button-user-selects-image-iframe.html ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <style type="text/css">
5
+ /*
6
+ This is a modified version of http://d3io1k5o0zdpqr.cloudfront.net/pinit.html
7
+ To avoid conflict with official Pinterest button behavior, a "2"
8
+ has been appended to many DOM IDs and JS function names.
9
+ */
10
+
11
+ body {
12
+ margin: 0;
13
+ padding: 0;
14
+ }
15
+ #PinItButton2 {
16
+ position: absolute;
17
+ background: url(//d3io1k5o0zdpqr.cloudfront.net/images/pinit6.png);
18
+ font: 11px Arial, sans-serif;
19
+ text-indent: -9999em;
20
+ font-size: .01em;
21
+ color: #CD1F1F;
22
+ height: 20px;
23
+ width: 43px;
24
+ background-position: 0 -7px;
25
+ }
26
+ #PinItButton2:hover {
27
+ background-position: 0 -28px;
28
+ }
29
+ #PinItButton2:active {
30
+ background-position: 0 -49px;
31
+ }
32
+ #PinItButton2.pinned {
33
+ background-position: 0 -70px !important;
34
+ }
35
+ #CountPointer2 {
36
+ position: absolute;
37
+ z-index: 1;
38
+ background: url(//d3io1k5o0zdpqr.cloudfront.net/images/pinit6.png);
39
+ text-indent: -9999em;
40
+ font-size: .01em;
41
+ color: #FFF;
42
+ }
43
+ #CountBubble2 {
44
+ position: absolute;
45
+ border: 1px solid #C9C5C5;
46
+ color: #777;
47
+ background-color: #FCF9F9;
48
+ border-radius: 1px;
49
+ }
50
+ body.horizontal #CountPointer2 {
51
+ left: 43px;
52
+ height: 18px;
53
+ width: 4px;
54
+ background-position: -43px -8px;
55
+ }
56
+ body.horizontal #CountBubble2 {
57
+ top: 1px;
58
+ left: 46px;
59
+ height: 10px;
60
+ line-height: 10px;
61
+ padding: 2px 5px 4px 5px;
62
+ font: 10px Arial, Helvetica, sans-serif;
63
+ display: inline-block;
64
+ }
65
+ body.vertical #PinItButton2 {
66
+ top: 38px;
67
+ }
68
+ body.vertical #CountPointer2 {
69
+ top: 31px;
70
+ height: 7px;
71
+ width: 41px;
72
+ background-position: 0 0;
73
+ }
74
+ body.vertical #CountBubble2 {
75
+ left: 1px;
76
+ height: 21px;
77
+ width: 39px;
78
+ font: 12px Arial, Helvetica, sans-serif;
79
+ line-height: 12px;
80
+ padding: 9px 0 0;
81
+ text-align: center;
82
+ }
83
+ body.none #PinItCount2 {
84
+ display: none;
85
+ }
86
+ </style>
87
+
88
+ <script type="text/javascript">
89
+ var countLayout = 'horizontal';
90
+ var alwaysShowCount = false;
91
+
92
+ function pinIt2(pinItButton, pinUrl) {
93
+ return function(e) {
94
+
95
+ parent.execPinmarklet();
96
+
97
+ //Bookmarklet will open official create button popup after image selected,
98
+ //so this code not needed.
99
+
100
+ /*
101
+ var t;
102
+ if (e.target) t = e.target;
103
+ else t = e.srcElement;
104
+ if (t.id != pinItButton.id)
105
+ return false;
106
+
107
+ var modal = window.open(pinUrl, 'signin', 'width=665,height=300');
108
+ var wait = function() {
109
+ setTimeout(function() {
110
+ if (modal == null) {
111
+ failure();
112
+ return;
113
+ }
114
+ if (modal.closed)
115
+ pinItButton.setAttribute('class', 'pinned');
116
+ else
117
+ wait();
118
+ }, 25);
119
+ };
120
+
121
+ wait();
122
+ */
123
+
124
+ return false;
125
+ };
126
+ }
127
+
128
+ function receiveCount(data) {
129
+ if (data['error'])
130
+ return;
131
+
132
+ var targetUrl = data['url'];
133
+ var pinItCount = document.getElementById('PinItCount2');
134
+ var countBubble = document.getElementById('CountBubble2');
135
+
136
+ if (!alwaysShowCount && data['count'] < 1 && countLayout === 'horizontal')
137
+ return;
138
+
139
+ pinItCount.style.display = 'block';
140
+ var count = data['count'];
141
+ if (count > 999 && count <= 999999)
142
+ count = Math.floor(count / 1000) + "K+";
143
+ else if (count > 999999 && count <= 999999999)
144
+ count = Math.floor(count / 1000000) + "M+";
145
+ else if (count > 999999999)
146
+ count = "++";
147
+ countBubble.innerHTML = count;
148
+ }
149
+
150
+ window.onload = function() {
151
+ var pinItButton = document.getElementById('PinItButton2');
152
+ var pinItCount = document.getElementById('PinItCount2');
153
+
154
+ // Parse args
155
+ var vars = {}, url = window.location.href;
156
+ var pairs = url.slice(url.indexOf('?') + 1).split('&');
157
+ for (var i = 0; i < pairs.length; i++) {
158
+ var parts = pairs[i].split('=');
159
+ vars[parts[0]] = parts[1];
160
+ }
161
+
162
+ countLayout = vars['layout'] || countLayout;
163
+ alwaysShowCount = vars['count'] || alwaysShowCount;
164
+
165
+ // Apply count layout class
166
+ document.body.className = countLayout;
167
+
168
+ // Build pin URL
169
+ delete vars['layout'];
170
+ delete vars['count'];
171
+ var sep = '?', pinUrl = 'http://pinterest.com/pin/create/button/';
172
+ for (var i in vars) {
173
+ pinUrl += sep + i + '=' + vars[i];
174
+ sep = '&';
175
+ }
176
+
177
+ // Button click handler
178
+ if (document.addEventListener)
179
+ pinItButton.addEventListener('click', pinIt2(pinItButton, pinUrl), false);
180
+ else if (document.attachEvent)
181
+ pinItButton.attachEvent('onclick', pinIt2(pinItButton, pinUrl));
182
+
183
+ // Request count from API
184
+ if (countLayout != 'none' || alwaysShowCount) {
185
+ var targetUrl = vars['url'] || vars['media'];
186
+ var snode = document.createElement('script');
187
+ var hnode = document.getElementsByTagName('head')[0];
188
+ snode.setAttribute('async', 'true');
189
+ snode.setAttribute('src', '//api.pinterest.com/v1/urls/count.json?callback=receiveCount&url='+targetUrl);
190
+ hnode.appendChild(snode);
191
+ }
192
+ };
193
+ </script>
194
+ </head>
195
+
196
+ <body>
197
+ <a href="javascript:void(0)" id="PinItButton2" title="Pin it on Pinterest">Pin it</a>
198
+ <div id="PinItCount2" style="display:none;">
199
+ <div id="CountPointer2">&laquo;</div>
200
+ <div id="CountBubble2">0</div>
201
+ </div>
202
+ </body>
203
+ </html>
js/pin-it-button-user-selects-image-assets.js ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //Modified version of http://assets.pinterest.com/js/pinit.js
2
+ //Pinterest last updated 3/16/2012
3
+ //Added "always-show-count" attribute, updated style widths/heights
4
+ //Points to same iFrame html
5
+
6
+ (function(){
7
+ for(var e=[],c=document.getElementsByTagName("a"),b=0;b<c.length;b++)
8
+ e.push(c[b]);
9
+ for(;e.length>0;){
10
+ c=e.pop();
11
+
12
+ //if(!(!c.className||c.className.indexOf("pin-it-button")<0)){
13
+
14
+ //Changed class detection to avoid conflict with original pinit.js
15
+ if(!(!c.className||c.className.indexOf("pin-it-button2")<0)){
16
+
17
+ var d=c.getAttribute("href");
18
+ b={};
19
+ d=d.slice(d.indexOf("?")+1).split("&");
20
+ for(var a=0;a<d.length;a++){
21
+ var g=d[a].split("=");
22
+ b[g[0]]=g[1]
23
+ }
24
+ b.layout=c.getAttribute("count-layout");
25
+ b.count=c.getAttribute("always-show-count");
26
+ a="?";
27
+
28
+ //d=window.location.protocol+"//d3io1k5o0zdpqr.cloudfront.net/pinit.html";
29
+
30
+ //Point to local JS
31
+ d = iFrameBtnUrl;
32
+
33
+ for(var f in b)
34
+ if(b[f]){
35
+ d+=a+f+"="+b[f];
36
+ a="&"
37
+ }
38
+ a=document.createElement("iframe");
39
+ a.setAttribute("src",d);
40
+ a.setAttribute("scrolling","no");
41
+ a.allowTransparency=true;
42
+ a.frameBorder=0;
43
+ a.style.border="none";
44
+ if(b.layout=="none"){
45
+ a.style.width="43px";
46
+ a.style.height="20px"
47
+ }else if(b.layout=="vertical"){
48
+ a.style.width="43px";
49
+ a.style.height="58px"
50
+ }else{
51
+ a.style.width="90px";
52
+ a.style.height="20px"
53
+ }
54
+ c.parentNode.replaceChild(a,c)
55
+ }
56
+ }
57
+ })();
js/pin-it-button-user-selects-image.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ //Added function for firing off pinmarklet.js for "user selects image" button type
2
+
3
+ function execPinmarklet() {
4
+ var e=document.createElement('script');
5
+ e.setAttribute('type','text/javascript');
6
+ e.setAttribute('charset','UTF-8');
7
+ e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r=' + Math.random()*99999999);
8
+ document.body.appendChild(e);
9
+ }
js/pinterest-pin-it-button-admin.js CHANGED
@@ -2,24 +2,26 @@
2
  //jQuery doc ready
3
  //See http://digwp.com/2011/09/using-instead-of-jquery-in-wordpress/
4
  jQuery(document).ready(function($) {
5
- //Submit mailchimp form with link button
6
- $("#mc-embedded-subscribe-link").click(function(event) {
7
- event.preventDefault();
8
- $("#mc-embedded-subscribe-form").submit();
9
- });
10
-
11
  //Enable collapse/expand toggle of admin boxes (like WP dashboard)
12
- $(".inside").show();
13
-
14
- $(".hndle").toggle(function() {
15
- $(this).next(".inside").slideToggle("fast");
16
- }, function () {
17
- $(this).next(".inside").slideToggle("fast");
18
- });
19
 
20
- $(".handlediv").toggle(function() {
21
- $(this).next(".hndle").next(".inside").slideToggle("fast");
22
- }, function() {
23
- $(this).next(".hndle").next(".inside").slideToggle("fast");
24
- });
 
 
 
 
 
 
 
 
 
 
 
 
25
  });
2
  //jQuery doc ready
3
  //See http://digwp.com/2011/09/using-instead-of-jquery-in-wordpress/
4
  jQuery(document).ready(function($) {
5
+
 
 
 
 
 
6
  //Enable collapse/expand toggle of admin boxes (like WP dashboard)
7
+ //Don't use 'dashboard' and 'postbox' scripts built-into WP like WordPress SEO
8
+ //plugin as they conflict on other pages
 
 
 
 
 
9
 
10
+ $(".pib-hndle").toggle(function() {
11
+ $(this).next(".inside").slideToggle("fast");
12
+ }, function () {
13
+ $(this).next(".inside").slideToggle("fast");
14
+ });
15
+
16
+ $(".pib-handlediv").toggle(function() {
17
+ $(this).next(".pib-hndle").next(".inside").slideToggle("fast");
18
+ }, function() {
19
+ $(this).next(".pib-hndle").next(".inside").slideToggle("fast");
20
+ });
21
+
22
+ //Submit mailchimp form with link button
23
+ $("#mc-embedded-subscribe-link").click(function(event) {
24
+ event.preventDefault();
25
+ $("#mc-embedded-subscribe-form").submit();
26
+ });
27
  });
pinterest-pin-it-button.php CHANGED
@@ -1,38 +1,24 @@
1
  <?php
2
  /*
3
  Plugin Name: Pinterest "Pin It" Button
4
- Plugin URI: http://pinterestplugin.com/
5
- Description: Add a Pinterest "Pin It" button to your posts and pages.
6
- Version: 1.2.0
7
  Author: Phil Derksen
8
- Author URI: http://pinterestplugin.com/
 
 
 
9
  */
10
 
11
- /* Copyright 2012 Phil Derksen (phil@pinterestplugin.com)
12
-
13
- This program is free software; you can redistribute it and/or modify
14
- it under the terms of the GNU General Public License, version 2, as
15
- published by the Free Software Foundation.
16
-
17
- This program is distributed in the hope that it will be useful,
18
- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- GNU General Public License for more details.
21
-
22
- You should have received a copy of the GNU General Public License
23
- along with this program; if not, write to the Free Software
24
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
- */
26
 
27
  //Set global variables
28
 
29
  if ( ! defined( 'PIB_PLUGIN_BASENAME' ) )
30
  define( 'PIB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
31
-
32
- define( 'BASE_BTN_HTML', '<a href="javascript:void(0)" class="pin-it-btn" title="Pin It on Pinterest"></a>' );
33
-
34
- //Plugin install/activation
35
 
 
 
 
36
  function pib_install() {
37
 
38
  //Deactivate plugin if WP version too low
@@ -42,7 +28,6 @@ function pib_install() {
42
 
43
  //Setup default settings
44
  $pib_options = array(
45
- //'admin_activate_notice' => 0,
46
  'display_home_page' => 1,
47
  'display_front_page' => 0,
48
  'display_posts' => 1,
@@ -51,79 +36,106 @@ function pib_install() {
51
  'display_above_content' => 0,
52
  'display_below_content' => 1,
53
  'display_on_post_excerpts' => 0,
54
- 'remove_div' => 0,
55
- 'custom_css' => ''
 
 
 
56
  );
57
 
58
  //Save default option values
59
- update_option( 'pib_options', $pib_options );
60
-
61
- //Save default values for page/post meta boxes
62
- global $wpdb;
63
- $sql = "SELECT ID
64
- FROM $wpdb->posts
65
- WHERE post_type = 'post' || post_type = 'page'";
66
-
67
- $results = $wpdb->get_results( $sql, ARRAY_A );
68
-
69
- foreach( $results as $post_id )
70
- {
71
- $postid = $post_id['ID'];
72
- update_post_meta( $postid, 'pib_sharing_enabled', 1 );
73
- }
74
-
75
- $category_ids = get_all_category_ids();
76
- foreach($category_ids as $term_id) {
77
- $tag_extra_fields[$term_id]['checkbox'] = 1;
78
- update_option(PIB_CATEGORY_FIELDS, $tag_extra_fields);
79
- }
80
-
81
  }
82
 
83
  register_activation_hook( __FILE__, 'pib_install' );
84
 
85
- //Display admin notice only once, then set option to turn off
86
- //Using saved option instead of session which was causing errors for some
87
- //TODO Removed until further testing
88
-
89
- /*
90
- function pib_plugin_activate_notice() {
91
- $pib_options = get_option( 'pib_options' );
92
-
93
- if ( !$pib_options['admin_activate_notice'] ) {
94
- echo '<div class="updated"><p>' .
95
- '<strong>Your "Pin It" Button is activated!</strong> ' .
96
- sprintf( __( '<a href="%1$s" class="activate-notice-link">Customize Your Settings</a>' ),
97
- 'admin.php?page=' . PIB_PLUGIN_BASENAME ) .
98
- '</p></div>';
99
-
100
- $pib_options['admin_activate_notice'] = 1;
101
- update_option( 'pib_options', $pib_options );
102
- }
103
- }
104
-
105
- add_action('admin_notices', 'pib_plugin_activate_notice');
106
- */
107
 
108
  //Add settings page to admin menu
 
109
 
110
  function pib_create_menu() {
111
- add_menu_page( 'Pin It Button Settings', 'Pin It Button', 'manage_options', __FILE__, 'pib_create_settings_page',
112
- plugins_url( '/img/pinit-button-icon-small.png', __FILE__ ) );
 
 
113
  }
114
 
115
  add_action( 'admin_menu', 'pib_create_menu' );
116
 
 
117
  //Add Admin CSS/JS
118
 
119
  function pib_add_admin_css_js() {
120
  wp_enqueue_script( 'jquery' );
121
 
122
  wp_enqueue_style( 'pinterest-pin-it-button', plugins_url( '/css/pinterest-pin-it-button-admin.css' , __FILE__ ) );
123
- wp_enqueue_script( 'pinterest-pin-it-button', plugins_url( '/js/pinterest-pin-it-button-admin.js', __FILE__ ), array( 'jquery' ) );
 
 
 
 
 
 
 
 
 
124
  }
125
 
126
- add_action( 'admin_enqueue_scripts', 'pib_add_admin_css_js' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
 
129
  //Register settings
@@ -134,6 +146,7 @@ function pib_register_settings() {
134
 
135
  add_action( 'admin_init', 'pib_register_settings' );
136
 
 
137
  //Create settings page
138
 
139
  function pib_create_settings_page() {
@@ -144,8 +157,8 @@ function pib_create_settings_page() {
144
  ?>
145
  <div class="wrap">
146
 
147
- <a href="http://pinterestplugin.com/" target="_blank"><div id="pinit-button-icon-32" class="icon32"
148
- style="background: url(<?php echo plugins_url( '/img/pinit-button-icon-med.png', __FILE__ ); ?>) no-repeat;"><br /></div></a>
149
  <h2>Pinterest "Pin It" Button Settings</h2>
150
 
151
  <div class="metabox-holder">
@@ -154,12 +167,78 @@ function pib_create_settings_page() {
154
  <?php settings_errors(); //Display status messages after action ("settings saved", errors) ?>
155
 
156
  <form method="post" action="options.php">
157
- <?php settings_fields( 'pib-settings-group' ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  <div id="pib-options" class="postbox pib-postbox">
160
  <!--Collapsable-->
161
- <div class="handlediv" title="Click to toggle"><br /></div>
162
- <h3 class="hndle">What types of pages should the button appear on?</h3>
163
 
164
  <table class="form-table inside">
165
  <tr valign="top">
@@ -194,25 +273,26 @@ function pib_create_settings_page() {
194
  <td>
195
  <input id="display_archives" name="pib_options[display_archives]" type="checkbox"
196
  <?php if ( $pib_options['display_archives'] ) echo 'checked="checked"'; ?> />
197
- <label for="display_archives">Archives (includes Category, Tag, Author and time-based pages)</label>
198
  </td>
199
  </tr>
200
  <tr valign="top">
201
- <td>
202
- When editing a post, page or category, scroll down to find the option to hide the "Pin It" button for it.
 
203
  </td>
204
  </tr>
205
  <tr valign="top">
206
  <td>
207
- Go to <a href="<?php echo admin_url( 'widgets.php' ); ?>">Widgets</a> to add a "Pin It" button to the sidebar.
208
  </td>
209
  </tr>
210
  </table>
211
  </div>
212
 
213
  <div id="button-show" class="postbox pib-postbox">
214
- <div class="handlediv" title="Click to toggle"><br /></div>
215
- <h3 class="hndle">Where on each page should the button appear?</h3>
216
 
217
  <table class="form-table inside">
218
  <tr valign="top">
@@ -233,19 +313,16 @@ function pib_create_settings_page() {
233
  <label for="display_on_post_excerpts">On Post Excerpts</label>
234
  </td>
235
  </tr>
236
- <tr valign="top">
237
- <td>
238
- Use the shortcode <code>[pinit]</code> to display the button within content.<br/>
239
- Use the function <code><?php echo htmlentities('<?php echo do_shortcode(\'[pinit]\'); ?>'); ?></code>
240
- to display within template or theme files.
241
- </td>
242
- </tr>
243
  </table>
244
  </div>
 
 
 
 
245
 
246
  <div id="style-options" class="postbox pib-postbox">
247
- <div class="handlediv" title="Click to toggle"><br /></div>
248
- <h3 class="hndle">Additional layout and styling options</h3>
249
 
250
  <table class="form-table inside">
251
  <tr valign="top">
@@ -255,15 +332,22 @@ function pib_create_settings_page() {
255
  </tr>
256
  <tr valign="top">
257
  <td>
258
- <textarea name="pib_options[custom_css]" rows="6" cols="8"><?php echo $custom_css; ?></textarea>
259
  </td>
260
  </tr>
 
 
 
 
 
 
261
  <tr valign="top">
262
  <td>
263
- <input id="remove_div" name="pib_options[remove_div]" type="checkbox" <?php if ( $pib_options['remove_div'] ) echo 'checked="checked"'; ?> />
264
- <label for="remove_div">Remove surrounding <code><?php echo htmlentities('<div class="pin-it-btn-wrapper"></div>'); ?></code> tag</label>
265
  </td>
266
  </tr>
 
267
  <tr valign="top">
268
  <td>
269
  <a href="http://pinterestplugin.com/pin-it-button-custom-css/" target="_blank">See custom CSS examples</a> aligning the button
@@ -273,23 +357,52 @@ function pib_create_settings_page() {
273
  </table>
274
  </div>
275
 
276
- <table class="form-table inside">
277
- <tr valign="top">
278
- <td>
279
- <input name="Submit" type="submit" value="Save Changes" class="button-primary" />
280
- </td>
281
- </tr>
282
- </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  </form>
284
  </div>
285
  </div>
286
- <div class="pib-right-column postbox-container">
 
287
  <div class="meta-box-sortables ui-sortable">
288
  <div id="email-signup">
289
  <h4>Like This Plugin?</h4>
290
 
291
  <p class="large-text">
292
- Join the mailing list to be notified when new features are released.
293
  </p>
294
 
295
  <!-- Begin MailChimp Signup Form -->
@@ -312,11 +425,11 @@ function pib_create_settings_page() {
312
  </div>
313
 
314
  <div id="promo-buttons" class="postbox pib-postbox">
315
- <div class="handlediv" title="Click to toggle"><br /></div>
316
- <h3 class="hndle">Spread the Word!</h3>
317
 
318
  <div class="inside">
319
- <p>The more people using this plugin the more we can add to it for you. Just take a sec and share it!</p>
320
 
321
  <table>
322
  <tr>
@@ -331,30 +444,46 @@ function pib_create_settings_page() {
331
  <tr>
332
  <td><?php echo pib_share_pinterest(); ?></td>
333
  </tr>
 
 
 
334
  </table>
335
  </div>
336
  </div>
337
 
338
- <div id="other-links" class="postbox pib-postbox">
339
- <div class="handlediv" title="Click to toggle"><br /></div>
340
- <h3 class="hndle">Other Links</h3>
341
 
342
  <div class="inside">
343
  <ul>
344
- <li><a href="http://pinterestplugin.com/" target="_blank">Official Site - PinterestPlugin.com</a></li>
345
- <li><a href="https://pinterestplugin.uservoice.com/" target="_blank">User Support &amp; Feature Requests</a></li>
 
346
  </ul>
347
  </div>
348
  </div>
349
-
 
 
 
 
 
 
 
 
 
 
 
350
  <div id="news-links" class="postbox pib-postbox">
351
- <div class="handlediv" title="Click to toggle"><br /></div>
352
- <h3 class="hndle">News from PinterestPlugin.com</h3>
353
 
354
  <div class="inside">
355
- <? echo pib_rss_news(); ?>
356
  </div>
357
  </div>
 
358
  </div>
359
  </div>
360
 
@@ -363,8 +492,10 @@ function pib_create_settings_page() {
363
  <?php
364
  }
365
 
 
366
  //Render rss items from pinterestplugin.com
367
  //http://codex.wordpress.org/Function_Reference/fetch_feed
 
368
  function pib_rss_news() {
369
  // Get RSS Feed(s)
370
  include_once(ABSPATH . WPINC . '/feed.php');
@@ -398,6 +529,7 @@ function pib_rss_news() {
398
  <?php
399
  }
400
 
 
401
  //Render Facebook Share button
402
  //http://developers.facebook.com/docs/share/
403
  function pib_share_facebook() {
@@ -409,6 +541,7 @@ function pib_share_facebook() {
409
  <?php
410
  }
411
 
 
412
  //Render Twitter button
413
  //https://twitter.com/about/resources/buttons
414
  function pib_share_twitter() {
@@ -420,13 +553,14 @@ function pib_share_twitter() {
420
  <?php
421
  }
422
 
 
423
  //Render Google +1 button
424
  //http://www.google.com/intl/en/webmasters/+1/button/index.html
425
  function pib_share_google_plus() {
426
  ?>
427
 
428
  <!-- Place this tag where you want the +1 button to render -->
429
- <div class="g-plusone" data-size="small" data-annotation="inline" data-href="http://pinterestplugin.com/"></div>
430
 
431
  <!-- Place this render call where appropriate -->
432
  <script type="text/javascript">
@@ -440,11 +574,16 @@ function pib_share_google_plus() {
440
  <?php
441
  }
442
 
 
443
  //Render Pin It button
 
 
444
  function pib_share_pinterest() {
445
  ?>
446
- <iframe src='<?php echo plugins_url( '/inc/admin-pin-it-button-iframe.html' , __FILE__ ) ?>' scrolling="no" frameborder="0" allowtransparency="true"
447
- style="border:none; overflow:hidden; width:px; height:20px"></iframe>
 
 
448
  <?php
449
  }
450
 
@@ -468,7 +607,8 @@ function pib_like_facebook() {
468
  <?php
469
  }
470
 
471
- //Add a link to the settings page to the plugins list
 
472
 
473
  function pib_plugin_action_links( $links, $file ) {
474
  if ( $file != PIB_PLUGIN_BASENAME )
@@ -484,55 +624,108 @@ function pib_plugin_action_links( $links, $file ) {
484
 
485
  add_filter( 'plugin_action_links', 'pib_plugin_action_links', 10, 2 );
486
 
 
487
  //Adds a meta box to the main column on the Post and Page edit screens
488
 
489
  function pib_sharing_add_meta_box() {
490
- add_meta_box( 'pib_sharing_meta','"Pin It" Button Display', 'pib_sharing_meta_box_content', 'page', 'advanced', 'high' );
491
- add_meta_box( 'pib_sharing_meta','"Pin It" Button Display', 'pib_sharing_meta_box_content', 'post', 'advanced', 'high' );
492
  }
493
 
494
  add_action( 'admin_init', 'pib_sharing_add_meta_box' );
495
 
 
496
  //Renders the post/page meta box checkbox html
497
 
498
  function pib_sharing_meta_box_content( $post ) {
499
- $pib_sharing_checked = get_post_meta( $post->ID, 'pib_sharing_enabled', 1 );
 
500
 
501
- if ( $pib_sharing_checked || $pib_sharing_checked == true )
502
- $pib_sharing_checked = 'checked="checked"';
503
  else
504
- $pib_sharing_checked = '';
 
 
 
 
 
 
505
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
 
507
  <p>
508
  <input name="pib_enable_post_sharing" id="pib_enable_post_sharing" value="1" <?php echo $pib_sharing_checked; ?> type="checkbox" />
509
  <label for="pib_enable_post_sharing">Show "Pin It" button on this post/page.</label>
510
  <p class="description">
511
- <!-- <span style="font-size: 11px;"> -->
512
- If checked displays the button for this post/page if <strong>Individual Posts</strong> (for posts) or <strong>WordPress Static "Pages"</strong>
513
- (for pages) is also checked in <a href='<?php echo 'admin.php?page=' . PIB_PLUGIN_BASENAME ?>'>"Pin It" Button Settings</a>.
514
- If unchecked the button will always be hidden for this page or post.
515
  </p>
516
  <input type="hidden" name="pib_sharing_status_hidden" value="1" />
517
  </p>
518
 
519
- <?php
520
  }
521
 
 
522
  //Saves display option for individual post/page
523
 
524
  function pib_sharing_meta_box_save( $post_id ) {
525
  if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
526
  return $post_id;
527
 
528
- //Record sharing enable
529
  if ( isset( $_POST['post_type'] ) && ( 'post' == $_POST['post_type'] || 'page' == $_POST['post_type'] ) ) {
530
  if ( current_user_can( 'edit_post', $post_id ) ) {
531
  if ( isset( $_POST['pib_sharing_status_hidden'] ) ) {
532
- if ( isset( $_POST['pib_enable_post_sharing'] ) )
533
- update_post_meta( $post_id, 'pib_sharing_enabled', 1 );
534
- else
535
- delete_post_meta( $post_id, 'pib_sharing_enabled' );
 
 
 
 
 
 
 
 
 
 
 
 
 
536
  }
537
  }
538
  }
@@ -542,17 +735,40 @@ function pib_sharing_meta_box_save( $post_id ) {
542
 
543
  add_action( 'save_post', 'pib_sharing_meta_box_save' );
544
 
545
- //Add Public CSS/JS
 
546
 
547
  function pib_add_public_css_js() {
548
- wp_enqueue_script( 'jquery' );
549
-
550
- wp_enqueue_style( 'pinterest-pin-it-button', plugins_url( '/css/pinterest-pin-it-button.css' , __FILE__ ) );
551
- wp_enqueue_script( 'pinterest-pin-it-button', plugins_url( '/js/pinterest-pin-it-button.js', __FILE__ ), array( 'jquery' ) );
552
  }
553
 
554
  add_action( 'wp_enqueue_scripts', 'pib_add_public_css_js' );
555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
  //Add Custom CSS
557
 
558
  function pib_add_custom_css() {
@@ -566,91 +782,158 @@ function pib_add_custom_css() {
566
 
567
  add_action( 'wp_head', 'pib_add_custom_css' );
568
 
569
- //Button html to render
570
 
571
- function pib_button_html() {
 
 
 
572
  $pib_options = get_option( 'pib_options' );
 
 
 
 
 
573
 
574
- //Check that remove surrounding div checkbox is selected
575
- if ( $pib_options['remove_div'] ) {
576
- return BASE_BTN_HTML;
577
- } else {
578
- //Surround with div tag
579
- return '<div class="pin-it-btn-wrapper">' . BASE_BTN_HTML . '</div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  }
582
 
583
- //Register shortcode: [pinit]
584
 
585
- function pib_button_shortcode_html() {
586
- return '<div class="pin-it-btn-shortcode-wrapper">' . BASE_BTN_HTML . '</div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
587
  }
588
 
589
  add_shortcode( 'pinit', 'pib_button_shortcode_html' );
590
 
 
591
  //Render button on pages with regular content
592
 
593
  function pib_render_btn( $content ) {
594
  //Load options array
595
  $pib_options = get_option( 'pib_options' );
596
-
 
597
 
598
  //Determine if displayed on current page
599
  if (
600
  ( is_home() && ( $pib_options['display_home_page'] ) ) ||
601
- ( is_front_page() && ( $pib_options['display_front_page'] ) )
602
-
 
 
 
 
 
 
603
  ) {
604
  if ( $pib_options['display_above_content'] ) {
605
- $content = pib_button_html() . $content;
606
  }
607
-
608
  if ( $pib_options['display_below_content'] ) {
609
- $content .= pib_button_html();
610
- }
611
- }
612
-
613
- //Determine if displayed on individual post or page from meta value
614
- if( ( is_single() && ( $pib_options['display_posts'] ) ) ||
615
- ( is_page() && ( $pib_options['display_pages'] ) )) {
616
-
617
- global $wpdb;
618
- $sql = "SELECT post_id
619
- FROM $wpdb->postmeta
620
- WHERE meta_key = 'pib_sharing_enabled' AND meta_value = '1'";
621
-
622
- $results = $wpdb->get_results( $sql, ARRAY_A );
623
-
624
- foreach( $results as $postid ) {
625
- $postID = $postid['post_id'];
626
- if(is_single($postID) || is_page($postID)) {
627
- if ( $pib_options['display_above_content'] ) {
628
- $content = pib_button_html() . $content;
629
- }
630
-
631
- if ( $pib_options['display_below_content'] ) {
632
- $content .= pib_button_html();
633
- }
634
- }
635
  }
636
- }
637
 
638
  //Determine if displayed on Category on the base of category edit Screen Option
639
- if( is_archive() && ( $pib_options['display_archives'] ) ) {
640
-
641
  $tag_extra_fields = get_option(PIB_CATEGORY_FIELDS);
642
  $category_ids = get_all_category_ids();
643
  foreach($category_ids as $term_id) {
644
 
645
- if($tag_extra_fields[$term_id]['checkbox'] == 1) {
646
 
647
  if(is_category($term_id)) {
648
  if ( $pib_options['display_above_content'] ) {
649
- $content = pib_button_html() . $content;
650
  }
651
 
652
  if ( $pib_options['display_below_content'] ) {
653
- $content .= pib_button_html();
654
  }
655
  }
656
  }
@@ -668,7 +951,9 @@ add_filter( 'the_content', 'pib_render_btn' );
668
  function pib_render_btn_excerpt( $content ) {
669
  //Load options array
670
  $pib_options = get_option( 'pib_options' );
671
-
 
 
672
  if ( $pib_options['display_on_post_excerpts'] ) {
673
  if (
674
  ( is_home() && ( $pib_options['display_home_page'] ) ) ||
@@ -676,11 +961,10 @@ function pib_render_btn_excerpt( $content ) {
676
 
677
  ) {
678
  if ( $pib_options['display_above_content'] ) {
679
- $content = pib_button_html() . $content;
680
  }
681
-
682
  if ( $pib_options['display_below_content'] ) {
683
- $content .= pib_button_html();
684
  }
685
  }
686
 
@@ -692,20 +976,19 @@ function pib_render_btn_excerpt( $content ) {
692
  $category_ids = get_all_category_ids();
693
  foreach($category_ids as $term_id) {
694
 
695
- if($tag_extra_fields[$term_id]['checkbox'] == 1) {
696
 
697
 
698
  if(is_category($term_id)) {
699
  if ( $pib_options['display_above_content'] ) {
700
- $content = pib_button_html() . $content;
701
  }
702
 
703
  if ( $pib_options['display_below_content'] ) {
704
- $content .= pib_button_html();
705
  }
706
  }
707
  }
708
-
709
  }
710
  }
711
  }
@@ -714,21 +997,25 @@ function pib_render_btn_excerpt( $content ) {
714
 
715
  add_filter( 'the_excerpt', 'pib_render_btn_excerpt' );
716
 
 
717
  //Option name
 
718
  define('PIB_CATEGORY_FIELDS', 'pib_category_fields_option');
719
 
 
720
  //Add Checkbox to Category Edit Screen
 
721
  add_action('edit_category_form_fields', 'pib_category_fields');
722
 
723
  function pib_category_fields($tag) {
724
  $t_id = $tag->term_id;
725
  $tag_extra_fields = get_option(PIB_CATEGORY_FIELDS);
726
 
727
-
728
- if ( $tag_extra_fields[$t_id]['checkbox'] == 1)
729
- $pib_category_checked = 'checked="checked"';
730
- else
731
- $pib_category_checked = '';
732
  ?>
733
 
734
  <table class="form-table">
@@ -743,11 +1030,11 @@ function pib_category_fields($tag) {
743
  <label for="pib_category_field">Show "Pin It" Button</label>
744
  </th>
745
  <td>
746
- <input name="pib_category_field" id="pib_category_field" type="checkbox" value="1" <?php echo $pib_category_checked; ?>>
747
  <p class="description">
748
  If checked displays the button for this category (if <strong>Archives</strong> also checked in
749
  <a href='<?php echo 'admin.php?page=' . PIB_PLUGIN_BASENAME ?>'>"Pin It" Button Settings</a>).
750
- If unchecked the button will always be hidden for this category.
751
  </p>
752
  </td>
753
  </tr>
@@ -757,121 +1044,73 @@ function pib_category_fields($tag) {
757
  <?php
758
  }
759
 
 
760
  // when the form gets submitted, and the category gets updated (in your case the option will get updated with the values of your custom fields above
 
761
  add_action('edited_category', 'update_pib_category_fields');
762
 
763
  function update_pib_category_fields($term_id) {
764
- if($_POST['taxonomy'] == 'category'):
765
- $tag_extra_fields = get_option(PIB_CATEGORY_FIELDS);
766
- $tag_extra_fields[$term_id]['checkbox'] = strip_tags($_POST['pib_category_field']);
767
-
768
- update_option(PIB_CATEGORY_FIELDS, $tag_extra_fields);
769
- endif;
770
- }
771
-
772
- //Add Pinterest Pin It Button widget to sidebar
773
-
774
- class Pib_Widget extends WP_Widget {
775
 
776
- function __construct() {
777
- $widget_ops = array('classname' => 'pib_widget_button', 'description' => __( 'Add a "Pin It" button to your sidebar with this widget') );
778
- parent::__construct('pib_button', __('Pinterest - "Pin It" Button'), $widget_ops);
779
- }
780
-
781
- function widget( $args, $instance ) {
782
- extract($args);
783
-
784
- $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
785
-
786
- echo $before_widget;
787
- if ( $title )
788
- echo $before_title . $title . $after_title;
789
-
790
- echo '<div class="pin-it-btn-wrapper">' . BASE_BTN_HTML . '</div>';
791
- echo $after_widget;
792
- }
793
-
794
- function update( $new_instance, $old_instance ) {
795
- $instance = $old_instance;
796
- $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '') );
797
- $instance['title'] = strip_tags($new_instance['title']);
798
-
799
- return $instance;
800
- }
801
-
802
- function form( $instance ) {
803
- $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
804
- $title = strip_tags($instance['title']);
805
-
806
- ?>
807
-
808
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
809
- <p>
810
-
811
- <?php
812
- }
813
  }
814
 
815
- //Add function to the widgets_init hook.
816
- add_action( 'widgets_init', 'pib_load_widgets' );
817
 
818
- // Function that register Pin It Button widget.
819
- function pib_load_widgets() {
820
- register_widget( 'Pib_Widget' );
821
- }
822
-
823
- //Add Pinterest Follow Button Widget to sidebar
824
 
825
- class Pib_Follow_Button_Widget extends WP_Widget {
826
 
827
  function __construct() {
828
- $widget_ops = array('classname' => 'pib_widget_follow_button', 'description' => __( 'Add a Pinterest "Follow" button to your sidebar with this widget') );
829
- parent::__construct('pib_follow_button', __('Pinterest - "Follow" Button'), $widget_ops);
 
830
  }
831
 
832
  function widget( $args, $instance ) {
833
  extract($args);
834
 
835
- $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
836
- $pib_img_option = $instance['pib_follow_button_radio'];
837
- $pibusername = $instance['pibusername'];
838
- $newwindow = $instance['newwindow'] ? '1' : '0';
 
 
 
 
 
 
839
 
840
  echo $before_widget;
841
- if ( $title )
842
- echo $before_title . $title . $after_title;
843
-
844
- if($pib_img_option == 1){
845
- if($newwindow){
846
- echo '<a href="http://pinterest.com/'.$pibusername.'/" target="_blank"><img src="http://passets-cdn.pinterest.com/images/follow-on-pinterest-button.png" width="156" height="26" alt="Follow Me on Pinterest" /></a>';
847
- }
848
- else{
849
- echo '<a href="http://pinterest.com/'.$pibusername.'/"><img src="http://passets-cdn.pinterest.com/images/follow-on-pinterest-button.png" width="156" height="26" alt="Follow Me on Pinterest" /></a>';
850
- }
851
- }
852
- elseif($pib_img_option == 2){
853
- if($newwindow){
854
- echo'<a href="http://pinterest.com/'.$pibusername.'/" target="_blank"><img src="http://passets-cdn.pinterest.com/images/pinterest-button.png" width="78" height="26" alt="Follow Me on Pinterest" /></a>';
855
- }
856
- else {
857
- echo'<a href="http://pinterest.com/'.$pibusername.'/"><img src="http://passets-cdn.pinterest.com/images/pinterest-button.png" width="78" height="26" alt="Follow Me on Pinterest" /></a>';
858
- }
859
- }
860
- elseif($pib_img_option == 3){
861
- if($newwindow){
862
- echo'<a href="http://pinterest.com/'.$pibusername.'/" target="_blank"><img src="http://passets-cdn.pinterest.com/images/big-p-button.png" width="61" height="61" alt="Follow Me on Pinterest" /></a>';
863
- }
864
- else {
865
- echo'<a href="http://pinterest.com/'.$pibusername.'/"><img src="http://passets-cdn.pinterest.com/images/big-p-button.png" width="61" height="61" alt="Follow Me on Pinterest" /></a>';
866
- }
867
  }
868
- elseif($pib_img_option == 4){
869
- if($newwindow){
870
- echo'<a href="http://pinterest.com/'.$pibusername.'/" target="_blank"><img src="http://passets-cdn.pinterest.com/images/small-p-button.png" width="16" height="16" alt="Follow Me on Pinterest" /></a>';
 
 
 
871
  }
872
- else {
873
- echo'<a href="http://pinterest.com/'.$pibusername.'/"><img src="http://passets-cdn.pinterest.com/images/small-p-button.png" width="16" height="16" alt="Follow Me on Pinterest" /></a>';
874
  }
 
 
875
  }
876
 
877
  echo $after_widget;
@@ -879,66 +1118,102 @@ class Pib_Follow_Button_Widget extends WP_Widget {
879
 
880
  function update( $new_instance, $old_instance ) {
881
  $instance = $old_instance;
882
- $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'pibusername' => '', 'pib_follow_button_radio' => '1') );
 
883
  $instance['title'] = strip_tags($new_instance['title']);
884
- $instance['pibusername'] = strip_tags($new_instance['pibusername']);
885
- $instance['pib_follow_button_radio'] = strip_tags($new_instance['pib_follow_button_radio']);
886
- $instance['newwindow'] = !empty($new_instance['newwindow']) ? 1 : 0;
887
-
 
 
 
 
888
  return $instance;
889
  }
890
 
891
  function form( $instance ) {
892
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'pibusername' => '', 'pib_follow_button_radio' => '1') );
893
- $title = strip_tags($instance['title']);
894
- $pibusername = strip_tags($instance['pibusername']);
895
- $pib_follow_button_radio = $instance['pib_follow_button_radio'];
896
- $newwindow = isset( $instance['newwindow'] ) ? (bool) $instance['newwindow'] : false;
897
-
898
- ?>
899
-
900
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
 
901
  <p>
902
-
903
- <p><label for="<?php echo $this->get_field_id('pibusername'); ?>"><?php _e('Pinterest Username:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('pibusername'); ?>" name="<?php echo $this->get_field_name('pibusername'); ?>" type="text" value="<?php echo esc_attr($pibusername); ?>" /></p>
 
904
  <p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
905
 
906
- <p><label>Button image:</label></p>
907
-
908
- <table>
909
- <tr>
910
- <td><input type="radio" <?php if($pib_follow_button_radio == 1){ echo'checked="checked"';} ?> name="<?php echo $this->get_field_name('pib_follow_button_radio'); ?>" id="<?php echo $this->get_field_id('follow-on-pinterest-button'); ?>" value="1" /></td>
911
- <td><img src="http://passets-cdn.pinterest.com/images/follow-on-pinterest-button.png" width="156" height="26" alt="Follow Me on Pinterest" /></td>
912
- </tr>
913
- <tr>
914
- <td><input type="radio" <?php if($pib_follow_button_radio == 2){ echo'checked="checked"';} ?> name="<?php echo $this->get_field_name('pib_follow_button_radio'); ?>" id="<?php echo $this->get_field_id('pinterest-button'); ?>" value="2"/></td>
915
- <td><img src="http://passets-cdn.pinterest.com/images/pinterest-button.png" width="78" height="26" alt="Follow Me on Pinterest" /></td>
916
- </tr>
917
- <tr>
918
- <td><input type="radio" <?php if($pib_follow_button_radio == 3){ echo'checked="checked"';} ?> name="<?php echo $this->get_field_name('pib_follow_button_radio'); ?>" id="<?php echo $this->get_field_id('big-p-button'); ?>" value="3"/></td>
919
- <td><img src="http://passets-cdn.pinterest.com/images/big-p-button.png" width="61" height="61" alt="Follow Me on Pinterest" /></td>
920
- </tr>
921
- <tr>
922
- <td><input type="radio" <?php if($pib_follow_button_radio == 4){ echo'checked="checked"';} ?> name="<?php echo $this->get_field_name('pib_follow_button_radio'); ?>" id="<?php echo $this->get_field_id('small-p-button'); ?>" value="4"/></td>
923
- <td><img src="http://passets-cdn.pinterest.com/images/small-p-button.png" width="16" height="16" alt="Follow Me on Pinterest" /></td>
924
- </tr>
925
- </table>
926
- <br />
927
- <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('newwindow'); ?>" name="<?php echo $this->get_field_name('newwindow'); ?>" <?php checked( $newwindow ); ?> />
928
- <label for="<?php echo $this->get_field_id('newwindow'); ?>"><?php _e( 'Open in a new window' ); ?></label><br />
929
-
930
  <?php
931
  }
932
  }
933
 
934
- //Add function to the widgets_init hook.
935
- add_action( 'widgets_init', 'pib_load_follow_button_widget' );
936
 
937
- // Function that registers Follow Button widget.
938
- function pib_load_follow_button_widget() {
939
- register_widget( 'Pib_Follow_Button_Widget' );
 
940
  }
941
 
 
 
 
942
 
 
 
 
 
 
 
 
943
 
944
  ?>
1
  <?php
2
  /*
3
  Plugin Name: Pinterest "Pin It" Button
4
+ Plugin URI: http://pinterestplugin.com
5
+ Description: Add a Pinterest "Pin It" Button to your posts and pages allowing your readers easily pin your images. Also includes a shortcode.
 
6
  Author: Phil Derksen
7
+ Author URI: http://pinterestplugin.com
8
+ Version: 1.3.0
9
+ License: GPLv2
10
+ Copyright 2012 Phil Derksen (phil@pinterestplugin.com)
11
  */
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  //Set global variables
15
 
16
  if ( ! defined( 'PIB_PLUGIN_BASENAME' ) )
17
  define( 'PIB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
 
 
 
 
18
 
19
+
20
+ //Plugin install/activation
21
+
22
  function pib_install() {
23
 
24
  //Deactivate plugin if WP version too low
28
 
29
  //Setup default settings
30
  $pib_options = array(
 
31
  'display_home_page' => 1,
32
  'display_front_page' => 0,
33
  'display_posts' => 1,
36
  'display_above_content' => 0,
37
  'display_below_content' => 1,
38
  'display_on_post_excerpts' => 0,
39
+ 'button_style' => 'user_selects_image',
40
+ 'count_layout' => 'none',
41
+ 'always_show_count' => 0,
42
+ 'custom_css' => '',
43
+ 'remove_div' => 0
44
  );
45
 
46
  //Save default option values
47
+ add_option( 'pib_options', $pib_options );
48
+ add_option( 'pib_ignore', 'false');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
 
51
  register_activation_hook( __FILE__, 'pib_install' );
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  //Add settings page to admin menu
55
+ //Use $page variable to load ONLY for this admin page
56
 
57
  function pib_create_menu() {
58
+ $page = add_menu_page( 'Pin It Button Settings', 'Pin It Button', 'manage_options', __FILE__, 'pib_create_settings_page',
59
+ plugins_url( '/img/pinterest-button-icon-small.png', __FILE__ ) );
60
+
61
+ add_action('admin_print_styles-' . $page, 'pib_add_admin_css_js');
62
  }
63
 
64
  add_action( 'admin_menu', 'pib_create_menu' );
65
 
66
+
67
  //Add Admin CSS/JS
68
 
69
  function pib_add_admin_css_js() {
70
  wp_enqueue_script( 'jquery' );
71
 
72
  wp_enqueue_style( 'pinterest-pin-it-button', plugins_url( '/css/pinterest-pin-it-button-admin.css' , __FILE__ ) );
73
+ wp_enqueue_script( 'pinterest-pin-it-button', plugins_url( '/js/pinterest-pin-it-button-admin.js', __FILE__ ), array( 'jquery' ) );
74
+ }
75
+
76
+ //Add script and css for Pointer funtionallity
77
+
78
+ function pib_add_admin_css_js_pointer() {
79
+ wp_enqueue_style( 'wp-pointer' );
80
+ wp_enqueue_script( 'wp-pointer' );
81
+
82
+ add_action( 'admin_print_footer_scripts', 'pib_admin_print_footer_scripts' );
83
  }
84
 
85
+ add_action( 'admin_enqueue_scripts', 'pib_add_admin_css_js_pointer' );
86
+
87
+
88
+ //Add popup message when plugin installed
89
+
90
+ function pib_admin_print_footer_scripts() {
91
+ $pib_pointer_content = '<h3>Ready to be Pinned?</h3>';
92
+
93
+ $pib_pointer_content .= '<p>' . esc_attr('Congratulations. You have just installed the Pinterest "Pin It" Button Plugin. Now just configure ' .
94
+ 'your settings and start getting Pinned!') . '</p>';
95
+
96
+ $url = admin_url( 'admin.php?page=' . PIB_PLUGIN_BASENAME );
97
+
98
+ global $pagenow;
99
+ $pib_ignore = get_option('pib_ignore');
100
+
101
+ if ( 'plugins.php' == $pagenow && $pib_ignore == 'false' ) {
102
+ ?>
103
+
104
+ <script type="text/javascript">
105
+ //<![CDATA[
106
+ jQuery(document).ready( function($) {
107
+
108
+ $('#menu-plugins').pointer({
109
+ content: '<?php echo $pib_pointer_content; ?>',
110
+ buttons: function( event, t ) {
111
+ button = jQuery('<a id="pointer-close" class="button-secondary">' + '<?php echo "Close"; ?>' + '</a>');
112
+ button.bind( 'click.pointer', function() {
113
+ t.element.pointer('close');
114
+ });
115
+ return button;
116
+ },
117
+ position: 'left',
118
+ close: function() { }
119
+
120
+ }).pointer('open');
121
+
122
+ jQuery('#pointer-close').after('<a id="pointer-primary" class="button-primary" style="margin-right: 5px;" href="<?php echo esc_attr($url); ?>">' +
123
+ '<?php echo "Pin It Button Settings"; ?>' + '</a>');
124
+
125
+ jQuery('#pointer-primary').click( function() {
126
+ <?php update_option('pblock_ignore' , 'true'); ?>
127
+ });
128
+
129
+ jQuery('#pointer-close').click( function() {
130
+ <?php update_option('pib_ignore' , 'true'); ?>
131
+ });
132
+ });
133
+ //]]>
134
+ </script>
135
+
136
+ <?php
137
+ }
138
+ }
139
 
140
 
141
  //Register settings
146
 
147
  add_action( 'admin_init', 'pib_register_settings' );
148
 
149
+
150
  //Create settings page
151
 
152
  function pib_create_settings_page() {
157
  ?>
158
  <div class="wrap">
159
 
160
+ <a href="http://pinterestplugin.com/" target="_blank"><div id="pinterest-button-icon-32" class="icon32"
161
+ style="background: url(<?php echo plugins_url( '/img/pinterest-button-icon-med.png', __FILE__ ); ?>) no-repeat;"><br /></div></a>
162
  <h2>Pinterest "Pin It" Button Settings</h2>
163
 
164
  <div class="metabox-holder">
167
  <?php settings_errors(); //Display status messages after action ("settings saved", errors) ?>
168
 
169
  <form method="post" action="options.php">
170
+ <?php settings_fields( 'pib-settings-group' ); ?>
171
+
172
+ <div id="button-type" class="postbox pib-postbox">
173
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
174
+ <h3 class="hndle pib-hndle">What style of button would you like to use?</h3>
175
+ <?php
176
+
177
+ if ( !isset($pib_options['button_style']) ) {
178
+ $pib_options = get_option( 'pib_options' );
179
+ $pib_options['button_style'] = 'user_selects_image';
180
+ update_option( 'pib_options', $pib_options );
181
+ }
182
+
183
+ ?>
184
+ <table class="form-table inside">
185
+ <tr valign="top">
186
+ <td>
187
+ <input type="radio" id="user_selects_image" value="user_selects_image" name="pib_options[button_style]"
188
+ <?php if ($pib_options['button_style'] == 'user_selects_image' || empty($pib_options['button_style']))
189
+ echo 'checked="checked"'; ?> />
190
+ <label for="display_pinit_button"><strong>User selects image</strong> from popup</label>
191
+ </td>
192
+ </tr>
193
+ <tr valign="top">
194
+ <td>
195
+ <input type="radio" id="image_selected" value="image_selected" name="pib_options[button_style]"
196
+ <?php if ( $pib_options['button_style'] == 'image_selected' ) echo 'checked="checked"'; ?> />
197
+ <label for="display_pinit_count_button">Image is <strong>pre-selected</strong></label>
198
+ </td>
199
+ </tr>
200
+ <?php if ( !isset($pib_options['count_layout']) ) {
201
+ $pib_options = get_option( 'pib_options' );
202
+ $pib_options['count_layout'] = 'none';
203
+ update_option( 'pib_options', $pib_options );
204
+ } ?>
205
+
206
+ <tr valign="top">
207
+ <td class="pib-pad-cell-top">
208
+ <label for="pib_pin_count" class="pib-plain-label"><?php _e('Pin Count:'); ?></label>
209
+ <select id="count_layout" name="pib_options[count_layout]">
210
+ <option value="none" <?php if($pib_options['count_layout'] == 'none' || empty($pib_options['count_layout']) ) { echo'selected';} ?>><?php _e('No Count'); ?></option>
211
+ <option value="horizontal" <?php if($pib_options['count_layout'] == 'horizontal') { echo'selected';} ?>><?php _e('Horizontal'); ?></option>
212
+ <option value="vertical" <?php if($pib_options['count_layout'] == 'vertical') { echo'selected';} ?>><?php _e('Vertical'); ?></option>
213
+ </select>
214
+ </td>
215
+ </tr>
216
+
217
+ <tr valign="top">
218
+ <td>
219
+ <input id="always_show_count" name="pib_options[always_show_count]" type="checkbox" <?php if ( $pib_options['always_show_count'] ) echo 'checked="checked"'; ?> />
220
+ <label for="always_show_count">Always show pin count (even when zero)</label>
221
+ </td>
222
+ </tr>
223
+ <tr valign="top">
224
+ <td class="pib-pad-cell-top">
225
+ To specify the URL to pin, image to pin and/or pin description (other than the defaults), go to the edit screen for those posts and pages
226
+ and scroll to the bottom.
227
+ </td>
228
+ </tr>
229
+ <tr valign="top">
230
+ <td>
231
+ The button style setting applies to <strong>all</strong> "Pin It" buttons displayed on the website (widgets and shortcodes included).
232
+ </td>
233
+ </tr>
234
+ </table>
235
+
236
+ </div>
237
 
238
  <div id="pib-options" class="postbox pib-postbox">
239
  <!--Collapsable-->
240
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
241
+ <h3 class="hndle pib-hndle">What types of pages should the button appear on?</h3>
242
 
243
  <table class="form-table inside">
244
  <tr valign="top">
273
  <td>
274
  <input id="display_archives" name="pib_options[display_archives]" type="checkbox"
275
  <?php if ( $pib_options['display_archives'] ) echo 'checked="checked"'; ?> />
276
+ <label for="display_archives">Archives (includes Category, Tag, Author and date-based pages)</label>
277
  </td>
278
  </tr>
279
  <tr valign="top">
280
+ <td class="pib-pad-cell-top">
281
+ To hide the "Pin It" button for a specific post, page or category, go to the edit screen for that post, page or category,
282
+ scroll down to the bottom, and uncheck the "Show" checkbox.
283
  </td>
284
  </tr>
285
  <tr valign="top">
286
  <td>
287
+ Head over to <a href="<?php echo admin_url( 'widgets.php' ); ?>">Widgets</a> to add a "Pin It" button to your sidebar.
288
  </td>
289
  </tr>
290
  </table>
291
  </div>
292
 
293
  <div id="button-show" class="postbox pib-postbox">
294
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
295
+ <h3 class="hndle pib-hndle">Where on each page should the button appear?</h3>
296
 
297
  <table class="form-table inside">
298
  <tr valign="top">
313
  <label for="display_on_post_excerpts">On Post Excerpts</label>
314
  </td>
315
  </tr>
 
 
 
 
 
 
 
316
  </table>
317
  </div>
318
+
319
+ <div class="submit">
320
+ <input name="Submit" type="submit" value="Save All Settings" class="button-primary" />
321
+ </div>
322
 
323
  <div id="style-options" class="postbox pib-postbox">
324
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
325
+ <h3 class="hndle pib-hndle">Other CSS and Styling Options</h3>
326
 
327
  <table class="form-table inside">
328
  <tr valign="top">
332
  </tr>
333
  <tr valign="top">
334
  <td>
335
+ <textarea id="pib-custom-css" name="pib_options[custom_css]" rows="6"><?php echo $custom_css; ?></textarea>
336
  </td>
337
  </tr>
338
+
339
+ <?php if ( !isset($pib_options['remove_div']) ) {
340
+ $pib_options = get_option( 'pib_options' );
341
+ $pib_options['remove_div'] = 0;
342
+ update_option( 'pib_options', $pib_options );
343
+ } ?>
344
  <tr valign="top">
345
  <td>
346
+ <input id="remove_div" name="pib_options[remove_div]" type="checkbox" <?php if ( $pib_options['remove_div']) echo 'checked="checked"'; ?> />
347
+ <label for="remove_div">Remove div tag surrounding regular button: <code><?php echo htmlentities('<div class="pin-it-btn-wrapper"></div>'); ?></code></label>
348
  </td>
349
  </tr>
350
+
351
  <tr valign="top">
352
  <td>
353
  <a href="http://pinterestplugin.com/pin-it-button-custom-css/" target="_blank">See custom CSS examples</a> aligning the button
357
  </table>
358
  </div>
359
 
360
+ <div class="postbox pib-postbox">
361
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
362
+ <h3 class="hndle pib-hndle">Shortcode Instructions</h3>
363
+
364
+ <div class="inside">
365
+ <p>
366
+ Use the shortcode <code>[pinit]</code> to display the button within your content.
367
+ </p>
368
+ <p>
369
+ Use the function <code><?php echo htmlentities('<?php echo do_shortcode(\'[pinit]\'); ?>'); ?></code>
370
+ to display within template or theme files.
371
+ </p>
372
+ <p><strong>Shortcode parameters</strong></p>
373
+ <p>
374
+ - count: none (default), horizontal, vertical<br/>
375
+ - url: URL of the web page to be pinned (defaults to current post/page URL)<br/>
376
+ - image_url: URL of the image to be pinned (defaults to first image in post)<br/>
377
+ - description: description of the pin (defaults to post title)<br/>
378
+ - float: none (default), left, right<br/>
379
+ - remove_div: false (default), true -- if true removes surrounding div tag, which also removes float setting<br/>
380
+ - always_show_count: false (default), true -- if true will show count even if zero
381
+ </p>
382
+ <p><strong>Examples</strong></p>
383
+ <p>
384
+ <code>[pinit count="horizontal"]</code><br/>
385
+ <code>[pinit count="vertical" url="http://www.mysite.com" image_url="http://www.mysite.com/myimage.jpg"
386
+ description="My favorite image!" float="right"]</code><br/>
387
+ </p>
388
+ </div>
389
+ </div>
390
+
391
+ <div class="submit">
392
+ <input name="Submit" type="submit" value="Save All Settings" class="button-primary" />
393
+ </div>
394
+
395
  </form>
396
  </div>
397
  </div>
398
+
399
+ <div class="pib-right-column postbox-container">
400
  <div class="meta-box-sortables ui-sortable">
401
  <div id="email-signup">
402
  <h4>Like This Plugin?</h4>
403
 
404
  <p class="large-text">
405
+ Join the mailing list to be notified when new features and plugins are released.
406
  </p>
407
 
408
  <!-- Begin MailChimp Signup Form -->
425
  </div>
426
 
427
  <div id="promo-buttons" class="postbox pib-postbox">
428
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
429
+ <h3 class="hndle pib-hndle">Spread the Word!</h3>
430
 
431
  <div class="inside">
432
+ <p>Could you do me a <strong>huge</strong> favor and share this plugin with others. Thank you so much!</p>
433
 
434
  <table>
435
  <tr>
444
  <tr>
445
  <td><?php echo pib_share_pinterest(); ?></td>
446
  </tr>
447
+ <tr>
448
+ <td>(or <a href="http://wordpress.org/extend/plugins/pinterest-pin-it-button/" target="_blank">rate it on WordPress</a>)</td>
449
+ </tr>
450
  </table>
451
  </div>
452
  </div>
453
 
454
+ <div class="postbox pib-postbox">
455
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
456
+ <h3 class="hndle pib-hndle">Other Links</h3>
457
 
458
  <div class="inside">
459
  <ul>
460
+ <li><a href="http://pinterestplugin.com/" target="_blank">Pinterest Plugin Updates</a> (Official Site)</li>
461
+ <li><a href="http://wordpress.org/extend/plugins/pinterest-pin-it-button/faq/" target="_blank">Frequently Asked Questions</a></li>
462
+ <li><a href="http://pinterestplugin.com/user-support" target="_blank">User Support &amp; Feature Requests</a></li>
463
  </ul>
464
  </div>
465
  </div>
466
+ <div class="postbox pib-postbox">
467
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
468
+ <h3 class="hndle pib-hndle">More Pinterest Plugins</h3>
469
+
470
+ <div class="inside">
471
+ <ul>
472
+ <li><a href="http://wordpress.org/extend/plugins/pinterest-follow-button/" target="_blank">Pinterest "Follow" Button</a></li>
473
+ <li><a href="http://wordpress.org/extend/plugins/pinterest-block/" target="_blank">Pinterest Block</a></li>
474
+ </ul>
475
+ </div>
476
+ </div>
477
+ <!--
478
  <div id="news-links" class="postbox pib-postbox">
479
+ <div class="handlediv pib-handlediv" title="Click to toggle"><br /></div>
480
+ <h3 class="hndle pib-hndle">News from PinterestPlugin.com</h3>
481
 
482
  <div class="inside">
483
+ <? //echo pib_rss_news(); ?>
484
  </div>
485
  </div>
486
+ -->
487
  </div>
488
  </div>
489
 
492
  <?php
493
  }
494
 
495
+
496
  //Render rss items from pinterestplugin.com
497
  //http://codex.wordpress.org/Function_Reference/fetch_feed
498
+
499
  function pib_rss_news() {
500
  // Get RSS Feed(s)
501
  include_once(ABSPATH . WPINC . '/feed.php');
529
  <?php
530
  }
531
 
532
+
533
  //Render Facebook Share button
534
  //http://developers.facebook.com/docs/share/
535
  function pib_share_facebook() {
541
  <?php
542
  }
543
 
544
+
545
  //Render Twitter button
546
  //https://twitter.com/about/resources/buttons
547
  function pib_share_twitter() {
553
  <?php
554
  }
555
 
556
+
557
  //Render Google +1 button
558
  //http://www.google.com/intl/en/webmasters/+1/button/index.html
559
  function pib_share_google_plus() {
560
  ?>
561
 
562
  <!-- Place this tag where you want the +1 button to render -->
563
+ <div class="g-plusone" data-size="medium" data-href="http://pinterestplugin.com/"></div>
564
 
565
  <!-- Place this render call where appropriate -->
566
  <script type="text/javascript">
574
  <?php
575
  }
576
 
577
+
578
  //Render Pin It button
579
+ //Render in iFrame otherwise it messes up the WP admin left menu
580
+
581
  function pib_share_pinterest() {
582
  ?>
583
+
584
+ <iframe src="<?php echo plugins_url( '/inc/admin-pin-it-button-iframe.html' , __FILE__ ) ?>" scrolling="no" frameborder="0" allowtransparency="true"
585
+ style="border:none; overflow:hidden; width:90px; height:20px"></iframe>
586
+
587
  <?php
588
  }
589
 
607
  <?php
608
  }
609
 
610
+
611
+ //Add a link to the settings page on the plugins list entry
612
 
613
  function pib_plugin_action_links( $links, $file ) {
614
  if ( $file != PIB_PLUGIN_BASENAME )
624
 
625
  add_filter( 'plugin_action_links', 'pib_plugin_action_links', 10, 2 );
626
 
627
+
628
  //Adds a meta box to the main column on the Post and Page edit screens
629
 
630
  function pib_sharing_add_meta_box() {
631
+ add_meta_box( 'pib_sharing_meta','"Pin It" Button Settings', 'pib_sharing_meta_box_content', 'page', 'advanced', 'high' );
632
+ add_meta_box( 'pib_sharing_meta','"Pin It" Button Settings', 'pib_sharing_meta_box_content', 'post', 'advanced', 'high' );
633
  }
634
 
635
  add_action( 'admin_init', 'pib_sharing_add_meta_box' );
636
 
637
+
638
  //Renders the post/page meta box checkbox html
639
 
640
  function pib_sharing_meta_box_content( $post ) {
641
+ $pib_options = get_option( 'pib_options' );
642
+ $pib_sharing_checked = get_post_meta( $post->ID, 'pib_sharing_disabled', 1 );
643
 
644
+ if ( empty( $pib_sharing_checked ) || $pib_sharing_checked === false )
645
+ $pib_sharing_checked = ' checked="checked"';
646
  else
647
+ $pib_sharing_checked = '';
648
+
649
+ $pib_url_of_webpage = get_post_meta( $post->ID, 'pib_url_of_webpage', true);
650
+ $pib_url_of_img = get_post_meta( $post->ID, 'pib_url_of_img', true);
651
+ $pib_description = get_post_meta( $post->ID, 'pib_description', true);
652
+
653
+ $pib_button_style = ( $pib_options['button_style'] == 'user_selects_image' ) ? 'User selects image' : 'Image pre-selected';
654
  ?>
655
+
656
+ <p>
657
+ <em>Button style is inherited from setting saved in <a href='<?php echo 'admin.php?page=' . PIB_PLUGIN_BASENAME ?>'>"Pin It" Button Settings</a>.
658
+ Current style: <strong><?php echo $pib_button_style; ?></strong></em>
659
+ </p>
660
+ <p>
661
+ <em>These 3 text fields will be used only if the button style is: <strong>Image pre-selected</strong></em>
662
+ </p>
663
+ <p>
664
+ <table class="form-table inside">
665
+ <tr valign="top">
666
+ <td>
667
+ <label for="pib_url_of_webpage">URL of the web page to be pinned (defaults to current post/page URL):</label><br/>
668
+ <input type="text" id="pib_url_of_webpage" name="pib_url_of_webpage" value="<?php echo $pib_url_of_webpage; ?>" class="pib-full-width-textbox"/>
669
+ </td>
670
+ </tr>
671
+ <tr valign="top">
672
+ <td>
673
+ <label for="pib_url_of_img">URL of the image to be pinned (defaults to first image in post):</label><br/>
674
+ <input type="text" id="pib_url_of_img" name="pib_url_of_img" value="<?php echo $pib_url_of_img; ?>" class="pib-full-width-textbox"/>
675
+ </td>
676
+ </tr>
677
+ <tr valign="top">
678
+ <td>
679
+ <label for="pib_description">Description of the pin (defaults to post title):</label><br/>
680
+ <input type="text" id="pib_description" name="pib_description" value="<?php echo $pib_description; ?>" class="pib-full-width-textbox"/>
681
+ </td>
682
+ </tr>
683
+ </table>
684
+ <input type="hidden" name="pib_count_status_hidden" value="1" />
685
+ </p>
686
 
687
  <p>
688
  <input name="pib_enable_post_sharing" id="pib_enable_post_sharing" value="1" <?php echo $pib_sharing_checked; ?> type="checkbox" />
689
  <label for="pib_enable_post_sharing">Show "Pin It" button on this post/page.</label>
690
  <p class="description">
691
+ If checked displays the button for this post/page (if <strong>Individual Posts</strong> (for posts) or <strong>WordPress Static "Pages"</strong>
692
+ (for pages) is also checked in <a href='<?php echo 'admin.php?page=' . PIB_PLUGIN_BASENAME ?>'>"Pin It" Button Settings</a>).
693
+ If unchecked the button will <strong>always</strong> be hidden for this post/page.
 
694
  </p>
695
  <input type="hidden" name="pib_sharing_status_hidden" value="1" />
696
  </p>
697
 
698
+ <?php
699
  }
700
 
701
+
702
  //Saves display option for individual post/page
703
 
704
  function pib_sharing_meta_box_save( $post_id ) {
705
  if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
706
  return $post_id;
707
 
708
+ // Record sharing disable
709
  if ( isset( $_POST['post_type'] ) && ( 'post' == $_POST['post_type'] || 'page' == $_POST['post_type'] ) ) {
710
  if ( current_user_can( 'edit_post', $post_id ) ) {
711
  if ( isset( $_POST['pib_sharing_status_hidden'] ) ) {
712
+ if ( !isset( $_POST['pib_enable_post_sharing'] ) ) {
713
+ update_post_meta( $post_id, 'pib_sharing_disabled', 1 );
714
+ }
715
+ else {
716
+ delete_post_meta( $post_id, 'pib_sharing_disabled' );
717
+ }
718
+
719
+ if ( isset( $_POST['pib_url_of_webpage'] ) && isset( $_POST['pib_url_of_img'] ) && isset( $_POST['pib_description'] )) {
720
+ update_post_meta( $post_id, 'pib_url_of_webpage', $_POST['pib_url_of_webpage'] );
721
+ update_post_meta( $post_id, 'pib_url_of_img', $_POST['pib_url_of_img'] );
722
+ update_post_meta( $post_id, 'pib_description', $_POST['pib_description'] );
723
+ }
724
+ else {
725
+ delete_post_meta( $post_id, 'pib_url_of_webpage' );
726
+ delete_post_meta( $post_id, 'pib_url_of_img' );
727
+ delete_post_meta( $post_id, 'pib_description' );
728
+ }
729
  }
730
  }
731
  }
735
 
736
  add_action( 'save_post', 'pib_sharing_meta_box_save' );
737
 
738
+
739
+ //Add Public CSS/JS (to Header)
740
 
741
  function pib_add_public_css_js() {
742
+ wp_enqueue_style( 'pinterest_pin_it_button', plugins_url( '/css/pinterest-pin-it-button.css' , __FILE__ ) );
 
 
 
743
  }
744
 
745
  add_action( 'wp_enqueue_scripts', 'pib_add_public_css_js' );
746
 
747
+
748
+ //Add Public JS (to Footer)
749
+
750
+ function pib_add_public_js_footer() {
751
+ $pib_options = get_option( 'pib_options' );
752
+
753
+ // If option #1 selected (user selects image)
754
+ if ( $pib_options['button_style'] == 'user_selects_image' ) {
755
+ //Save iFrame URL to JS variable
756
+ echo '<script type="text/javascript">' .
757
+ 'var iFrameBtnUrl = "' . plugins_url( '/inc/pin-it-button-user-selects-image-iframe.html', __FILE__ ) . '"; ' .
758
+ '</script>' . "\n";
759
+
760
+ echo '<script type="text/javascript" src="' . plugins_url( '/js/pin-it-button-user-selects-image.js', __FILE__ ) . '"></script>' . "\n";
761
+ echo '<script type="text/javascript" src="' . plugins_url( '/js/pin-it-button-user-selects-image-assets.js', __FILE__ ) . '"></script>' . "\n";
762
+ }
763
+ // If option #2 selected (image pre-selected)
764
+ elseif ( $pib_options['button_style'] == 'image_selected' ) {
765
+ echo '<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>' . "\n";
766
+ }
767
+ }
768
+
769
+ add_action( 'wp_footer', 'pib_add_public_js_footer' );
770
+
771
+
772
  //Add Custom CSS
773
 
774
  function pib_add_custom_css() {
782
 
783
  add_action( 'wp_head', 'pib_add_custom_css' );
784
 
 
785
 
786
+ //Function for rendering "Pin It" button base html
787
+
788
+ function pib_button_base( $postUrl, $imageUrl, $description, $countLayout, $alwaysShowCount ) {
789
+ //Change css class for "user selects image" button style to avoid conflicts
790
  $pib_options = get_option( 'pib_options' );
791
+ $buttonClass = 'pin-it-button';
792
+
793
+ if ( $pib_options['button_style'] == 'user_selects_image' ) {
794
+ $buttonClass = 'pin-it-button2';
795
+ }
796
 
797
+ //HTML from Pinterest Goodies 3/19/2012
798
+ //<a href="http://pinterest.com/pin/create/button/?url=PAGE&media=IMG&description=DESC" class="pin-it-button" count-layout="horizontal">
799
+ //<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
800
+
801
+ $btn = '<a href="http://pinterest.com/pin/create/button/?url=' . urlencode($postUrl) .
802
+ '&media=' . urlencode($imageUrl) . '&description='. urlencode($description) . '" ' .
803
+ 'count-layout="' . $countLayout . '" class="' . $buttonClass . '" ' .
804
+ ( $alwaysShowCount ? 'always-show-count="true"' : '' ) .
805
+ '><img border="0" style="border:0;" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>';
806
+
807
+ return $btn;
808
+ }
809
+
810
+
811
+ //Button html to render
812
+
813
+ function pib_button_html($postID) {
814
+ $pib_url_of_webpage = get_post_meta( $postID, 'pib_url_of_webpage', true);
815
+ $pib_url_of_img = get_post_meta( $postID, 'pib_url_of_img', true );
816
+ $pib_description = get_post_meta( $postID, 'pib_description', true );
817
+
818
+ $pib_options = get_option( 'pib_options' );
819
+ $countLayout = $pib_options['count_layout'];
820
+ $permalink = get_permalink($postID);
821
+ $title = get_the_title($postID);
822
+ global $post;
823
+ $first_img = '';
824
+
825
+ //Get url of img and compare width and height
826
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
827
+ $first_img = $matches [1] [0];
828
+
829
+ if (get_post_meta($postID,'pib_sharing_disabled', 1)) {
830
+ return "";
831
  }
832
+ else {
833
+ //if url_of_webpage, url_of_img or description are not set through pinit admin setting page then set default to post/page URL for the attribute url
834
+ $pib_url_of_webpage = ( empty( $pib_url_of_webpage ) ? $permalink : $pib_url_of_webpage );
835
+ $pib_url_of_img = ( empty( $pib_url_of_img ) ? $first_img : $pib_url_of_img );
836
+ $pib_description = ( empty( $pib_description ) ? $title : $pib_description );
837
+ $pib_always_show_count = (bool)$pib_options['always_show_count'];
838
+
839
+ $baseBtn = pib_button_base($pib_url_of_webpage, $pib_url_of_img, $pib_description, $countLayout, $pib_always_show_count);
840
+
841
+ if ( $pib_options['remove_div'] ) {
842
+ return $baseBtn;
843
+ }
844
+ else {
845
+ //Surround with div tag
846
+ return '<div class="pin-it-btn-wrapper">' . $baseBtn . '</div>';
847
+ }
848
+ }
849
  }
850
 
851
+ //Register shortcode: [pinit url="" image_url="" description="" float="none" remove_div="false" always_show_count="false"]
852
 
853
+ function pib_button_shortcode_html($attr) {
854
+ $pib_options = get_option( 'pib_options' );
855
+ global $post;
856
+ $permalink = get_permalink($post->ID);
857
+ $title = get_the_title($post->ID);
858
+ $first_img = '';
859
+
860
+ //Get url of img and compare width and height
861
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
862
+ $first_img = $matches [1] [0];
863
+
864
+ $attr['url'] = ( empty( $attr['url'] ) ? $permalink : $attr['url'] );
865
+ $attr['image_url'] = ( empty( $attr['image_url']) ? $first_img : $attr['image_url'] );
866
+ $attr['description'] = ( empty( $attr['description'] ) ? $title : $attr['description'] );
867
+ $attr['count'] = ( empty( $attr['count'] ) ? 'none' : $attr['count'] );
868
+ $remove_div_bool = ( $attr['remove_div'] == 'true' );
869
+ $always_show_count_bool = ( $attr['always_show_count'] == 'true' );
870
+
871
+ $baseBtn = pib_button_base($attr['url'], $attr['image_url'], $attr['description'], $attr['count'], $always_show_count_bool);
872
+
873
+ if ( $remove_div_bool ) {
874
+ return $baseBtn;
875
+ }
876
+ else {
877
+ //Surround with div tag
878
+ $float_class = '';
879
+
880
+ if ( $attr['float'] == 'left' ) {
881
+ $float_class = 'pib-float-left';
882
+ }
883
+ elseif ( $attr['float'] == 'right' ) {
884
+ $float_class = 'pib-float-right';
885
+ }
886
+
887
+ return '<div class="pin-it-btn-wrapper-shortcode ' . $float_class . '">' . $baseBtn . '</div>';
888
+ }
889
  }
890
 
891
  add_shortcode( 'pinit', 'pib_button_shortcode_html' );
892
 
893
+
894
  //Render button on pages with regular content
895
 
896
  function pib_render_btn( $content ) {
897
  //Load options array
898
  $pib_options = get_option( 'pib_options' );
899
+ global $post;
900
+ $postID = $post->ID;
901
 
902
  //Determine if displayed on current page
903
  if (
904
  ( is_home() && ( $pib_options['display_home_page'] ) ) ||
905
+ ( is_front_page() && ( $pib_options['display_front_page'] ) ) ||
906
+ ( is_single() && ( $pib_options['display_posts'] ) ) ||
907
+ ( is_page() && ( $pib_options['display_pages'] ) && !is_front_page() ) ||
908
+
909
+ //archive pages besides categories (tag, author, date, etc)
910
+ ( is_archive() && ( $pib_options['display_archives'] ) &&
911
+ ( is_tag() || is_author() || is_date() || is_search() )
912
+ )
913
  ) {
914
  if ( $pib_options['display_above_content'] ) {
915
+ $content = pib_button_html($postID) . $content;
916
  }
 
917
  if ( $pib_options['display_below_content'] ) {
918
+ $content .= pib_button_html($postID);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
919
  }
920
+ }
921
 
922
  //Determine if displayed on Category on the base of category edit Screen Option
923
+ if ( is_archive() && ( $pib_options['display_archives'] ) ) {
 
924
  $tag_extra_fields = get_option(PIB_CATEGORY_FIELDS);
925
  $category_ids = get_all_category_ids();
926
  foreach($category_ids as $term_id) {
927
 
928
+ if($tag_extra_fields[$term_id]['checkbox'] != true) {
929
 
930
  if(is_category($term_id)) {
931
  if ( $pib_options['display_above_content'] ) {
932
+ $content = pib_button_html($postID) . $content;
933
  }
934
 
935
  if ( $pib_options['display_below_content'] ) {
936
+ $content .= pib_button_html($postID);
937
  }
938
  }
939
  }
951
  function pib_render_btn_excerpt( $content ) {
952
  //Load options array
953
  $pib_options = get_option( 'pib_options' );
954
+ global $post;
955
+ $postID = $post->ID;
956
+
957
  if ( $pib_options['display_on_post_excerpts'] ) {
958
  if (
959
  ( is_home() && ( $pib_options['display_home_page'] ) ) ||
961
 
962
  ) {
963
  if ( $pib_options['display_above_content'] ) {
964
+ $content = pib_button_html($postID) . $content;
965
  }
 
966
  if ( $pib_options['display_below_content'] ) {
967
+ $content .= pib_button_html($postID);
968
  }
969
  }
970
 
976
  $category_ids = get_all_category_ids();
977
  foreach($category_ids as $term_id) {
978
 
979
+ if($tag_extra_fields[$term_id]['checkbox'] != true) {
980
 
981
 
982
  if(is_category($term_id)) {
983
  if ( $pib_options['display_above_content'] ) {
984
+ $content = pib_button_html($postID) . $content;
985
  }
986
 
987
  if ( $pib_options['display_below_content'] ) {
988
+ $content .= pib_button_html($postID);
989
  }
990
  }
991
  }
 
992
  }
993
  }
994
  }
997
 
998
  add_filter( 'the_excerpt', 'pib_render_btn_excerpt' );
999
 
1000
+
1001
  //Option name
1002
+
1003
  define('PIB_CATEGORY_FIELDS', 'pib_category_fields_option');
1004
 
1005
+
1006
  //Add Checkbox to Category Edit Screen
1007
+
1008
  add_action('edit_category_form_fields', 'pib_category_fields');
1009
 
1010
  function pib_category_fields($tag) {
1011
  $t_id = $tag->term_id;
1012
  $tag_extra_fields = get_option(PIB_CATEGORY_FIELDS);
1013
 
1014
+ if ( $tag_extra_fields[$t_id]['checkbox'] == true)
1015
+ $pib_category_checked = '';
1016
+ else
1017
+ $pib_category_checked = 'checked="checked"';
1018
+
1019
  ?>
1020
 
1021
  <table class="form-table">
1030
  <label for="pib_category_field">Show "Pin It" Button</label>
1031
  </th>
1032
  <td>
1033
+ <input name="pib_category_field" id="pib_category_field" type="checkbox" value="true" <?php echo $pib_category_checked; ?>>
1034
  <p class="description">
1035
  If checked displays the button for this category (if <strong>Archives</strong> also checked in
1036
  <a href='<?php echo 'admin.php?page=' . PIB_PLUGIN_BASENAME ?>'>"Pin It" Button Settings</a>).
1037
+ If unchecked the button will <strong>always</strong> be hidden for this category.
1038
  </p>
1039
  </td>
1040
  </tr>
1044
  <?php
1045
  }
1046
 
1047
+
1048
  // when the form gets submitted, and the category gets updated (in your case the option will get updated with the values of your custom fields above
1049
+
1050
  add_action('edited_category', 'update_pib_category_fields');
1051
 
1052
  function update_pib_category_fields($term_id) {
1053
+ if ( $_POST['taxonomy'] == 'category' ) {
1054
+ $tag_extra_fields = get_option(PIB_CATEGORY_FIELDS);
1055
+ $tag_extra_fields[$term_id]['checkbox'] = strip_tags($_POST['pib_category_field']);
 
 
 
 
 
 
 
 
1056
 
1057
+ if ( $_POST['pib_category_field'] != true ) {
1058
+ $tag_extra_fields[$term_id]['checkbox'] = true;
1059
+ update_option( PIB_CATEGORY_FIELDS, $tag_extra_fields );
1060
+ }
1061
+ if ( $_POST['pib_category_field'] == true ) {
1062
+ $tag_extra_fields[$term_id]['checkbox'] = "";
1063
+ update_option( PIB_CATEGORY_FIELDS, $tag_extra_fields );
1064
+ }
1065
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1066
  }
1067
 
 
 
1068
 
1069
+ //Add Pinterest Pin It Button widget
 
 
 
 
 
1070
 
1071
+ class Pib_Widget extends WP_Widget {
1072
 
1073
  function __construct() {
1074
+ $widget_ops = array('classname' => 'pib-clearfix', 'description' => __( 'Add a Pinterest "Pin It" button to your sidebar with this widget.') );
1075
+ $control_ops = array('width' => 400); //doesn't use height
1076
+ parent::__construct('pib_button', __('Pinterest "Pin It" Button'), $widget_ops, $control_ops);
1077
  }
1078
 
1079
  function widget( $args, $instance ) {
1080
  extract($args);
1081
 
1082
+ $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
1083
+ $pib_url_of_webpage_widget = $instance['pib_url_of_webpage_widget'];
1084
+ $pib_url_of_img_widget = $instance['pib_url_of_img_widget'];
1085
+ $pib_description_widget = $instance['pib_description_widget'];
1086
+ $count_layout = empty( $instance['count_layout'] ) ? 'none' : $instance['count_layout'];
1087
+ $float = empty( $instance['float'] ) ? 'none' : $instance['float'];
1088
+ $pib_remove_div = (bool)$instance['remove_div'];
1089
+ $pib_always_show_count = (bool)$instance['always_show_count'];
1090
+
1091
+ $baseBtn = pib_button_base( $pib_url_of_webpage_widget, $pib_url_of_img_widget, $pib_description_widget, $count_layout, $pib_always_show_count );
1092
 
1093
  echo $before_widget;
1094
+
1095
+ if ( $title ) {
1096
+ echo $before_title . $title . $after_title;
1097
+ }
1098
+
1099
+ if ( $pib_remove_div ) {
1100
+ echo $baseBtn;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1101
  }
1102
+ else {
1103
+ //Surround with div tag
1104
+ $float_class = '';
1105
+
1106
+ if ( $float == 'left' ) {
1107
+ $float_class = 'pib-float-left';
1108
  }
1109
+ elseif ( $float == 'right' ) {
1110
+ $float_class = 'pib-float-right';
1111
  }
1112
+
1113
+ echo '<div class="pin-it-btn-wrapper-widget ' . $float_class . '">' . $baseBtn . '</div>';
1114
  }
1115
 
1116
  echo $after_widget;
1118
 
1119
  function update( $new_instance, $old_instance ) {
1120
  $instance = $old_instance;
1121
+ $new_instance = wp_parse_args( (array) $new_instance, array( 'count_layout' => 'none', 'title' => '',
1122
+ 'pib_count_button_radio' => 'user_selects_image', 'float' => 'none') );
1123
  $instance['title'] = strip_tags($new_instance['title']);
1124
+ $instance['pib_url_of_webpage_widget'] = strip_tags($new_instance['pib_url_of_webpage_widget']);
1125
+ $instance['pib_url_of_img_widget'] = strip_tags($new_instance['pib_url_of_img_widget']);
1126
+ $instance['pib_description_widget'] = strip_tags($new_instance['pib_description_widget']);
1127
+ $instance['count_layout'] = $new_instance['count_layout'];
1128
+ $instance['float'] = $new_instance['float'];
1129
+ $instance['remove_div'] = ( $new_instance['remove_div'] ? 1 : 0 );
1130
+ $instance['always_show_count'] = ( $new_instance['always_show_count'] ? 1 : 0 );
1131
+
1132
  return $instance;
1133
  }
1134
 
1135
  function form( $instance ) {
1136
+ $instance = wp_parse_args( (array) $instance, array( 'count_layout' => 'none', 'title' => '',
1137
+ 'pib_count_button_radio' => 'user_selects_image', 'float' => 'none') );
1138
+ $title = strip_tags($instance['title']);
1139
+ $pib_url_of_webpage_widget = strip_tags($instance['pib_url_of_webpage_widget']);
1140
+ $pib_url_of_img_widget = strip_tags($instance['pib_url_of_img_widget']);
1141
+ $pib_description_widget = strip_tags($instance['pib_description_widget']);
1142
+ $pib_options = get_option('pib_options');
1143
+ $pib_button_style_widget = ( $pib_options['button_style'] == 'user_selects_image' ) ? 'User selects image' : 'Image pre-selected';
1144
+ ?>
1145
+
1146
  <p>
1147
+ <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title (optional):'); ?></label>
1148
+ <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
1149
+ </p>
1150
  <p>
1151
+ <label for="<?php echo $this->get_field_id('count_layout'); ?>"><?php _e('Pin Count:'); ?></label>
1152
+ <select name="<?php echo $this->get_field_name('count_layout'); ?>" id="<?php echo $this->get_field_id('count_layout'); ?>">
1153
+ <option value="none"<?php selected( $instance['count_layout'], 'none' ); ?>><?php _e('No Count'); ?></option>
1154
+ <option value="horizontal"<?php selected( $instance['count_layout'], 'horizontal' ); ?>><?php _e('Horizontal'); ?></option>
1155
+ <option value="vertical"<?php selected( $instance['count_layout'], 'vertical' ); ?>><?php _e('Vertical'); ?></option>
1156
+ </select>
1157
+ </p>
1158
+ <p>
1159
+ <input class="checkbox" <?php checked($instance['always_show_count'], true) ?> id="<?php echo $this->get_field_id('always_show_count'); ?>" name="<?php echo $this->get_field_name('always_show_count'); ?>" type="checkbox"/>
1160
+ <label for="<?php echo $this->get_field_id('always_show_count'); ?>">Always show pin count (even when zero)</label>
1161
+ </p>
1162
+ <div class="pib-widget-text-fields">
1163
+ <p>
1164
+ <em>Button style is inherited from setting saved in <a href='<?php echo 'admin.php?page=' . PIB_PLUGIN_BASENAME ?>'>"Pin It" Button Settings</a>.
1165
+ Current style: <strong><?php echo $pib_button_style_widget; ?></strong></em>
1166
+ </p>
1167
+ <p>
1168
+ <em>These 3 text fields will be used only if the button style is <strong>"Image pre-selected"</strong></em>
1169
+ </p>
1170
+ <p>
1171
+ <label for="<?php echo $this->get_field_id('pib_url_of_webpage_widget'); ?>"><?php _e('URL of the web page to be pinned (required):'); ?></label>
1172
+ <input class="widefat" id="<?php echo $this->get_field_id('pib_url_of_webpage_widget'); ?>" name="<?php echo $this->get_field_name('pib_url_of_webpage_widget'); ?>" type="text" value="<?php echo esc_attr($pib_url_of_webpage_widget); ?>" />
1173
+ </p>
1174
+ <p>
1175
+ <label for="<?php echo $this->get_field_id('pib_url_of_img_widget'); ?>"><?php _e('URL of the image to be pinned (required):'); ?></label>
1176
+ <input class="widefat" id="<?php echo $this->get_field_id('pib_url_of_img_widget'); ?>" name="<?php echo $this->get_field_name('pib_url_of_img_widget'); ?>" type="text" value="<?php echo esc_attr($pib_url_of_img_widget); ?>" />
1177
+ </p>
1178
+ <p>
1179
+ <label for="<?php echo $this->get_field_id('pib_description_widget'); ?>"><?php _e('Description of the pin (optional):'); ?></label>
1180
+ <input class="widefat" id="<?php echo $this->get_field_id('pib_description_widget'); ?>" name="<?php echo $this->get_field_name('pib_description_widget'); ?>" type="text" value="<?php echo esc_attr($pib_description_widget); ?>" />
1181
+ </p>
1182
+ </div>
1183
 
1184
+ <p>
1185
+ <label for="<?php echo $this->get_field_id('float'); ?>"><?php _e('Align (float):'); ?></label>
1186
+ <select name="<?php echo $this->get_field_name('float'); ?>" id="<?php echo $this->get_field_id('float'); ?>">
1187
+ <option value="none"<?php selected( $instance['float'], 'none' ); ?>><?php _e('none (default)'); ?></option>
1188
+ <option value="left"<?php selected( $instance['float'], 'left' ); ?>><?php _e('left'); ?></option>
1189
+ <option value="right"<?php selected( $instance['float'], 'right' ); ?>><?php _e('right'); ?></option>
1190
+ </select>
1191
+ </p>
1192
+ <p>
1193
+ <input class="checkbox" <?php checked($instance['remove_div'], true) ?> id="<?php echo $this->get_field_id('remove_div'); ?>" name="<?php echo $this->get_field_name('remove_div'); ?>" type="checkbox"/>
1194
+ <label for="<?php echo $this->get_field_id('remove_div'); ?>">Remove div tag surrounding this widget button (also removes <strong>float</strong> setting)</label>
1195
+ </p>
 
 
 
 
 
 
 
 
 
 
 
 
1196
  <?php
1197
  }
1198
  }
1199
 
 
 
1200
 
1201
+ // Function that register Pin It Button widget.
1202
+
1203
+ function pib_load_widgets() {
1204
+ register_widget( 'Pib_Widget' );
1205
  }
1206
 
1207
+ //Add function to the widgets_init hook.
1208
+ add_action( 'widgets_init', 'pib_load_widgets' );
1209
+
1210
 
1211
+ // JavaScript alert debug function (quick & dirty)
1212
+
1213
+ function debugToJs($phpVar) {
1214
+ echo '<script type="text/javascript"> (function() { alert("' . $phpVar . '"); })() </script>' . "\n";
1215
+ //echo '<script type="text/javascript"> (function() { alert(escape("' . $phpVar . '")); })() </script>' . "\n";
1216
+ //echo '<script type="text/javascript"> (function() { console.log("' . esc_attr($phpVar) . '"); })() </script>' . "\n";
1217
+ }
1218
 
1219
  ?>
readme.txt CHANGED
@@ -3,31 +3,33 @@ Contributors: pderksen
3
  Tags: pinterest, pin it, social
4
  Requires at least: 3.0
5
  Tested up to: 3.3.1
6
- Stable tag: trunk
7
 
8
  Add a Pinterest "Pin It" Button to your posts and pages allowing your readers easily pin your images.
9
 
10
  == Description ==
11
 
12
- Add a Pinterest "Pin It" Button to your posts and pages.
13
 
14
- **"Pin It" Button Features**
15
 
16
  * Display on various page types: blog home page, front page, posts, pages, archives
17
- * Display above and/or below content
18
- * Optionally display on post excerpts
19
- * Hide on selected posts and pages
20
- * Hide on selected categories
21
- * Display within content with a shortcode
22
- * Add custom CSS for fine-tuning layout and styling
23
- * Add "Pin It" button as a sidebar widget
24
- * Add a "Follow" on Pinterest button as a sidebar widget
25
 
26
- **Resources**
27
 
28
- * Official Site: [PinterestPlugin.com](http://pinterestplugin.com)
29
- * Sample blog using plugin: http://bruisesandbandaids.com
30
- * [User Support & Feature Requests](https://pinterestplugin.uservoice.com)
 
 
 
 
 
 
 
31
 
32
  Take advantage of the exploding traffic Pinterest is generating by encouraging your readers to pin your content using this simple "Pin It" button.
33
 
@@ -37,11 +39,16 @@ Take advantage of the exploding traffic Pinterest is generating by encouraging y
37
 
38
  **Pinterest Hits 10 Million U.S. Monthly Uniques Faster Than Any Standalone Site Ever** - TechCrunch, Feb 7, 2012 [[link]](http://techcrunch.com/2012/02/07/pinterest-monthly-uniques/)
39
 
 
 
 
 
 
40
  == Installation ==
41
 
42
  1. Use the automatic installer in your WordPress admin.
43
  1. Activate the plugin.
44
- 1. Configure the plugin by going to **Pin It Button** that appears in your admin menu .
45
 
46
  Alernatively, you can download this plugin, unzip the contents, then FTP upload to the `/wp-content/plugins/` directory.
47
 
@@ -51,18 +58,20 @@ Note: If you overwrite the plugin using FTP upload, you may lose some saved sett
51
 
52
  **The "Pin It" button is showing up, but clicking it does nothing. What can I try?**
53
 
54
- To the best of our knowledge, in order please try the following:
55
 
56
- * Make sure your browser cache is cleared or test in a different browser.
57
- * Make sure any WordPress caching is emptied. In W3 Total Cache, make sure Minify mode is set to Manual, not Auto.
58
- * Disable caching plugins.
59
- * Disable other social sharing plugins.
60
- * Disable other plugins one by one until the issue is fixed. If you find an incompatible plugin please let us know.
61
- * (More solutions added here as they're found.)
 
 
62
 
63
  **How do I display the button in places other than above or below the content?**
64
 
65
- * Use the shortcode `[pinit]` to display the button within content.
66
  * Use the function `<?php echo do_shortcode('[pinit]'); ?>` to display within template or theme files.
67
 
68
  **How do I get the "Pin It" button to line up next to my other social sharing icons?**
@@ -70,18 +79,44 @@ To the best of our knowledge, in order please try the following:
70
  * Add custom CSS on the settings screen and optionally remove the surrounding `<div>` tag.
71
  * See some of our [custom CSS examples](http://pinterestplugin.com/pin-it-button-custom-css).
72
 
 
 
 
 
 
73
  **I'd like to report a bug or submit a feature request.**
74
 
75
- * Go to the [User Support & Feedback Forum](https://pinterestplugin.uservoice.com)
76
 
77
  == Screenshots ==
78
 
79
  1. Settings page
80
  2. Button display below a post
81
- 3. Button display next to other sharing buttons
 
 
82
 
83
  == Changelog ==
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  = 1.2.0 =
86
 
87
  * Added option to hide button per page/post
@@ -137,5 +172,5 @@ To the best of our knowledge, in order please try the following:
137
  = 0.1.1 =
138
  * Fixed style sheet reference
139
 
140
- = 0.1 =
141
  * Initial release
3
  Tags: pinterest, pin it, social
4
  Requires at least: 3.0
5
  Tested up to: 3.3.1
6
+ Stable tag: 1.3.0
7
 
8
  Add a Pinterest "Pin It" Button to your posts and pages allowing your readers easily pin your images.
9
 
10
  == Description ==
11
 
12
+ Add a Pinterest "Pin It" Button to your posts and pages allowing your readers easily pin your images. Includes a shortcode and widget.
13
 
14
+ ### "Pin It" Button Features: ###
15
 
16
  * Display on various page types: blog home page, front page, posts, pages, archives
17
+ * Display within content using a shortcode or on the sidebar using a widget
18
+ * Pre-select an image to be pinned or allow the user to select
19
+ * Display a horizontal or vertical Pin Count
 
 
 
 
 
20
 
21
+ = Resources =
22
 
23
+ * [View Live Demo &raquo;](http://bruisesandbandaids.com/2011/newborn-photography-props/ "Learn Your Camera on Manual | Newborn Photography Tips")
24
+ * [Pinterest Plugin Updates &raquo;](http://pinterestplugin.com "Pinterest Plugins for WordPress")
25
+ * [User Support & Feature Requests &raquo;](http://pinterestplugin.com/user-support "Pinterest Plugins for WordPress User Support")
26
+
27
+ = Other Features =
28
+
29
+ * Hide on selected posts, pages and categories
30
+ * Display above and/or below content
31
+ * Optionally display on post excerpts
32
+ * Enter custom CSS for fine-tuning layout and styling
33
 
34
  Take advantage of the exploding traffic Pinterest is generating by encouraging your readers to pin your content using this simple "Pin It" button.
35
 
39
 
40
  **Pinterest Hits 10 Million U.S. Monthly Uniques Faster Than Any Standalone Site Ever** - TechCrunch, Feb 7, 2012 [[link]](http://techcrunch.com/2012/02/07/pinterest-monthly-uniques/)
41
 
42
+ = More Pinterest Plugins =
43
+
44
+ * [Pinterest "Follow" Button](http://wordpress.org/extend/plugins/pinterest-follow-button/)
45
+ * [Pinterest Block](http://wordpress.org/extend/plugins/pinterest-block/)
46
+
47
  == Installation ==
48
 
49
  1. Use the automatic installer in your WordPress admin.
50
  1. Activate the plugin.
51
+ 1. Configure the plugin by going to **Pin It Button** that appears in your admin menu.
52
 
53
  Alernatively, you can download this plugin, unzip the contents, then FTP upload to the `/wp-content/plugins/` directory.
54
 
58
 
59
  **The "Pin It" button is showing up, but clicking it does nothing. What can I try?**
60
 
61
+ Here are some things to try. After each one re-test a couple pages on your site to see if that fixed it.
62
 
63
+ * Clear your browser cache.
64
+ * Test in a different browser.
65
+ * If using any WordPress caching plugin, please empty/clear it (examples: W3 Total Cache, WP-Cache and WP SuperCache).
66
+ * If using W3 Total Cache, make sure Minify mode is set to Manual, not Auto.
67
+ * Disable other social sharing plugins being used.
68
+ * Disable other plugins one by one until the issue is fixed. (Please let us know if you find and incompatible plugin.
69
+ * Switch to a different theme temporarily, preferably the default WordPress TwentyEleven theme. Please let us know if you find an incompatible theme.
70
+ * If you find a different solution that fixes the issue for you (or find an incompatible plugin or theme), please let us know.
71
 
72
  **How do I display the button in places other than above or below the content?**
73
 
74
+ * Use the shortcode `[pinit]` to display the button within content. See shortcode instructions on settings page for attributes you can specify.
75
  * Use the function `<?php echo do_shortcode('[pinit]'); ?>` to display within template or theme files.
76
 
77
  **How do I get the "Pin It" button to line up next to my other social sharing icons?**
79
  * Add custom CSS on the settings screen and optionally remove the surrounding `<div>` tag.
80
  * See some of our [custom CSS examples](http://pinterestplugin.com/pin-it-button-custom-css).
81
 
82
+ **I had an old version of the plugin that worked and now it doesn't. Can I get it back?
83
+
84
+ * Yes, you can [download previous versions here](http://wordpress.org/extend/plugins/pinterest-pin-it-button/download/).
85
+ * You'll need to deactivate and delete the current plugin, then go to Plugins > Add New > Upload to upload the zip file to your site.
86
+
87
  **I'd like to report a bug or submit a feature request.**
88
 
89
+ * Go to the [User Support & Feature Requests Forum](http://pinterestplugin.com/user-support)
90
 
91
  == Screenshots ==
92
 
93
  1. Settings page
94
  2. Button display below a post
95
+ 3. Widget options
96
+ 4. Per page settings
97
+ 5. Advanced settings
98
 
99
  == Changelog ==
100
 
101
+ = 1.3.0 =
102
+
103
+ * Added a Pin Count option (horizontal or vertical)
104
+ * Added new button style where image is pre-selected (like official Pinterest button)
105
+ * Added fields for specifying URL, image URL and description for new button style *image pre-selected*
106
+ * Added float option for alignment (none, left or right) to widget and shortcode
107
+ * Can now remove shortcode surrounding div tag wrapper
108
+ * Can now remove widget surrounding div tag wrapper
109
+ * Moved "Follow" button widget to separate plugin: [Pinterest Follow Button Plugin](http://wordpress.org/extend/plugins/pinterest-follow-button/)
110
+ * Both button styles now embed iframe (like official Pinterest button)
111
+ * External JavaScript now loads in footer for better performance
112
+ * Fixed bug where front page was still showing button even when Front Page was unchecked
113
+ * Fixed bug where some settings weren't saved when upgrading the plugin
114
+ * Fixed bug where tag, author, date and search archive pages were not displaying the button
115
+
116
+ = 1.2.1 =
117
+
118
+ * Fixed bug with hiding posts/pages/categories when upgrading from a previous version
119
+
120
  = 1.2.0 =
121
 
122
  * Added option to hide button per page/post
172
  = 0.1.1 =
173
  * Fixed style sheet reference
174
 
175
+ = 0.1.0 =
176
  * Initial release
screenshot-1.png CHANGED
Binary file
screenshot-2.jpg CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
screenshot-4.png ADDED
Binary file
screenshot-5.png ADDED
Binary file
uninstall.php CHANGED
@@ -4,12 +4,9 @@ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4
  exit;
5
  }
6
 
7
- //Note this will run on manual deactivate, but should not run when upgrading/overwriting plugin
8
-
9
  //Remove option records from options table
10
  delete_option( 'pib_options' );
11
  delete_option( 'pib_category_fields_option' );
12
-
13
- //Remove any additional options and custom tables
14
 
15
  ?>
4
  exit;
5
  }
6
 
 
 
7
  //Remove option records from options table
8
  delete_option( 'pib_options' );
9
  delete_option( 'pib_category_fields_option' );
10
+ delete_option( 'pib_ignore' );
 
11
 
12
  ?>