jQuery Pin It Button for Images - Version 1.00

Version Description

  • Released 2013-08-09
  • Major source code redesign
  • Small changes in how the plugin works on client side
  • WordPress-style settings panel
  • Fixed a little glitch from previous version
Download this release

Release Info

Developer mrsztuczkens
Plugin Icon wp plugin jQuery Pin It Button for Images
Version 1.00
Comparing to
See all releases

Code changes from version 0.9.99 to 1.00

css/admin.css CHANGED
@@ -1,90 +1,17 @@
1
- .settings-table {
2
- padding:20px;
3
- width:100%;
4
- border-collapse: collapse
5
- }
6
-
7
- .settings-table td {
8
- padding-bottom: 20px;
9
- }
10
-
11
- .settings-table th {
12
- vertical-align:top;
13
- font-weight: normal;
14
- text-align:left;
15
- padding:0px 10px;
16
- width:200px;
17
- }
18
-
19
- .settings-table th label{
20
- font-weight:bold;
21
- }
22
-
23
- .settings-table p {
24
- margin-top: 4px;
25
- }
26
-
27
- .settings-table select, .settings-table textarea, .settings-table input[type='text'] {
28
- width: 180px;
29
- }
30
-
31
- .settings-table textarea:disabled {
32
- background-color: #E0E0E0;
33
- }
34
-
35
- .jpibfi-success-message, .jpibfi-error-message {
36
- border: 1px solid;
37
- border-radius: 10px;
38
- margin: 10px 0px;
39
- padding:10px;
40
- width: 90%;
41
- }
42
-
43
- .jpibfi-success-message {
44
- color: #4F8A10;
45
- background-color: #DFF2BF;
46
}
47
48
.jpibfi-error-message {
49
- color: #D8000C;
50
- background-color: #FFBABA;
51
- }
52
-
53
- .settings-table .error-border {
54
- border: 2px solid #ff8387;
55
- -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
56
- -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
57
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
58
- }
59
-
60
- #errors_div div {
61
- border: 1px solid #eed3d7;;
62
- -webkit-border-radius: 4px;
63
- -moz-border-radius: 4px;
64
- border-radius: 4px;
65
- background-color: #f2dede;
66
- color: #b94a48;
67
- padding: 8px 14px;
68
- text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
69
- }
70
-
71
- .jpibfi-visible {
72
- display: block;
73
- }
74
-
75
- .jpibfi-hidden {
76
- display: none;
77
- }
78
-
79
- #errors_div div :after,.description {
80
- clear:both;
81
}
82
83
input[type="checkbox"] ~ label {
84
padding-left: 5px;
85
}
86
87
- .jpibfi-admin-number {
88
- width: 60px;
89
- text-align: right;
90
}
1
+ #custom_button_preview {
2
+ text-indent: -9999px;
3
+ display:block;
4
}
5
6
.jpibfi-error-message {
7
+ font-weight: bold;
8
+ color: red;
9
}
10
11
input[type="checkbox"] ~ label {
12
padding-left: 5px;
13
}
14
15
+ input#custom_image_url {
16
+ width: 100%;
17
}
css/style.css CHANGED
@@ -1,28 +1,15 @@
1
- .pinit {
2
- position:relative;
3
- display:inline-block;
4
- overflow: hidden;
5
- max-width: 100%;
6
- }
7
-
8
- .pinit.aligncenter {
9
- clear: both;
10
- display: block;
11
- }
12
-
13
- .pinit .pinit-overlay {
14
position:absolute;
15
- top:0;
16
- left:0;
17
- width:100%;
18
- height:100%;
19
z-index:200;
20
display:none;
21
- text-align:left;
22
}
23
-
24
- .pinit .pinit-overlay a {
25
position:absolute;
26
- display:block;
27
text-indent:-9999em;
28
}
1
+ .pinit-overlay {
2
+ background-color: transparent;
3
position:absolute;
4
z-index:200;
5
display:none;
6
+ border-width: 0 0;
7
+ padding: 0 0;
8
+ margin: 0 0;
9
+ box-shadow: none;
10
}
11
+ .pinit-overlay a {
12
position:absolute;
13
+ display:none;
14
text-indent:-9999em;
15
}
images/transparency_0.png ADDED
Binary file
jpibfi-admin.php DELETED
@@ -1,314 +0,0 @@
1
- <?php
2
- if ( ! function_exists( 'add_action' ) ) {
3
- echo "Hi there! I'm just a plugin, not much I can do when called directly.";
4
- exit;
5
- }
6
-
7
- //require_once( "jpibfi-validation.php" );
8
- //require_once( "jpibfi-constants.php" );
9
-
10
- function jpibfi_conditional( $condition, $true_value = "", $false_value = "", $echo = true) {
11
- if ( $condition ) {
12
- if ( $echo )
13
- echo $true_value;
14
- return $true_value;
15
- }
16
- if ( $echo )
17
- echo $false_value;
18
- return $false_value;
19
- }
20
-
21
- //Prints out the admin page
22
- function jpibfi_print_admin_page() {
23
- global $jpibfi_button_dropdown;
24
- global $jpibfi_button_css;
25
-
26
- $dev_options = jpibfi_get_basic_options();
27
- $advanced_dev_options = jpibfi_get_advanced_options();
28
- $custom_button_css = jpibfi_get_button_css();
29
- $errors = array(
30
- 'disabled_classes' => false,
31
- 'enabled_classes' => false,
32
- 'custom_image_height' => false,
33
- 'custom_image_width' => false,
34
- 'transparency_value' => false,
35
- 'min_image_height' => false,
36
- 'min_image_width' => false
37
- );
38
- ?>
39
-
40
- <div class="wrap" id="top_anchor">
41
- <h2>jQuery Pin It Button For Images</h2>
42
-
43
- <?php
44
-
45
- if ( isset( $_POST['update_jQuery_Pin_It_Button_For_Images'] ) ) {
46
- //security check
47
- if ( ! wp_verify_nonce( $_POST['jpibfi_nonce'], 'jpibfi_admin_settings' ) )
48
- die( 'Security alert' );
49
-
50
- $errors['disabled_classes'] = ! jpibfi_contains_css_class_names_or_empty( $_POST['disabled_classes'] );
51
- $errors['enabled_classes'] = ! jpibfi_contains_css_class_names_or_empty( $_POST['enabled_classes'] );
52
- $errors['custom_image_height'] = ! jpibfi_is_numeric_and_more_or_equal_to_zero( $_POST['custom_image_height'] );
53
- $errors['custom_image_width'] = ! jpibfi_is_numeric_and_more_or_equal_to_zero( $_POST['custom_image_width'] );
54
- $errors['min_image_height'] = ! jpibfi_is_numeric_and_more_or_equal_to_zero( $_POST['min_image_height'] );
55
- $errors['min_image_width'] = ! jpibfi_is_numeric_and_more_or_equal_to_zero( $_POST['min_image_width'] );
56
-
57
- //rewrite settings that came from the POST request
58
- $dev_options['image_selector'] = sanitize_text_field( $_POST['image_selector'] );
59
- $dev_options['transparency_value'] = $_POST['standard_transparency'];
60
- $dev_options['disabled_classes'] = $_POST['disabled_classes'];
61
- $dev_options['enabled_classes'] = $_POST['enabled_classes'];
62
- $dev_options['description_option'] = $_POST['description_option'];
63
- $dev_options['min_image_height'] = $_POST['min_image_height'];
64
- $dev_options['min_image_width'] = $_POST['min_image_width'];
65
- $dev_options['use_custom_image'] = isset( $_POST['use_custom_image'] )? "1" : "0";
66
-
67
- $dev_options['custom_image_url'] = $_POST['custom_image_url'];
68
- $dev_options['custom_image_height'] = $_POST['custom_image_height'];
69
- $dev_options['custom_image_width'] = $_POST['custom_image_width'];
70
-
71
- $dev_options['use_post_url'] = isset( $_POST['use_post_url'] ) ? "1" : "0";
72
- $dev_options['button_position'] = $_POST['button_position'];
73
-
74
- $errors['transparency_value'] = ! is_numeric( $dev_options['transparency_value'] ) || ( $dev_options['transparency_value'] < 0.0 ) || ( $dev_options['transparency_value'] > 1.0 );
75
-
76
- $advanced_dev_options['on_home'] = isset( $_POST['on_home'] ) ? '1' : '0';
77
- $advanced_dev_options['on_page'] = isset( $_POST['on_page'] ) ? '1' : '0';
78
- $advanced_dev_options['on_single'] = isset( $_POST['on_single'] ) ? '1' : '0';
79
- $advanced_dev_options['on_category'] = isset( $_POST['on_category'] ) ? '1' : '0';
80
- $advanced_dev_options['on_blog'] = isset( $_POST['on_blog'] ) ? '1' : '0';
81
-
82
- // 5 means we need to use custom CSS
83
- if ( "5" == $dev_options['button_position'] )
84
- $custom_button_css = $_POST['custom_button_css'];
85
- else
86
- $custom_button_css = $jpibfi_button_css[$dev_options['button_position']];
87
-
88
- $any_errors = false;
89
- foreach ( $errors as $value )
90
- $any_errors = $any_errors || $value;
91
-
92
- if ( ! $any_errors ) { //save only if there are no errors
93
- update_option( JPIBFI_BASIC_OPTIONS, $dev_options );
94
- update_option( JPIBFI_ADVANCED_OPTIONS, $advanced_dev_options );
95
- update_option( JPIBFI_BUTTON_CUSTOM_CSS, $custom_button_css );
96
- //delete_option( JPIBFI_BUTTON_CUSTOM_CSS );
97
-
98
- ?>
99
- <p class='jpibfi-success-message'><?php _e( "Settings Updated.", "jpibfi" );?></p>
100
- <?php
101
- }
102
- else { //otherwise inform that there are some errors
103
- ?>
104
- <p class='jpibfi-error-message'><?php _e( "Error. Settings not updated. Look for details below.", "jpibfi" ); ?></p>
105
- <?php
106
- }
107
- }
108
- ?>
109
- <div id="errors_div">
110
- <div id="disabled_classes_error" class="<?php jpibfi_conditional( $errors["disabled_classes"], "jpibfi-visible", "jpibfi-hidden" ); ?>">
111
- Disabled classes setting error. Please change it and try submitting again.
112
- </div>
113
- <div id="enabled_classes_error" class="<?php jpibfi_conditional( $errors["enabled_classes"], "jpibfi-visible", "jpibfi-hidden" ); ?>">
114
- Enabled classes setting error. Please change it and try submitting again.
115
- </div>
116
- <div id="standard_transparency_error" class="<?php jpibfi_conditional( $errors["transparency_value"], "jpibfi-visible", "jpibfi-hidden" ); ?>">
117
- The given transparency error is not valid. Please change the value and try submitting again.
118
- </div>
119
- <div id="custom_image_height_error" class="<?php jpibfi_conditional( $errors["custom_image_height"], "jpibfi-visible", "jpibfi-hidden" ); ?>">
120
- Custom image height must be a number larger than or equal to zero.
121
- </div>
122
- <div id="custom_image_width_error" class="<?php jpibfi_conditional( $errors["custom_image_width"], "jpibfi-visible", "jpibfi-hidden" ); ?>">
123
- Custom image width must be a number larger than or equal to zero.
124
- </div>
125
- <div id="min_image_height_error" class="<?php jpibfi_conditional( $errors["min_image_height"], "jpibfi-visible", "jpibfi-hidden" ); ?>">
126
- Minimum image height must be a number larger than or equal to zero.
127
- </div>
128
- <div id="min_image_width_error" class="<?php jpibfi_conditional( $errors["min_image_width"], "jpibfi-visible", "jpibfi-hidden" ); ?>">
129
- Minimum image width must be a number larger than or equal to zero.
130
- </div>
131
- </div>
132
-
133
- <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
134
- <?php wp_nonce_field( "jpibfi_admin_settings", 'jpibfi_nonce' ); ?>
135
- <h3>Which images can be pinned</h3>
136
- <hr/>
137
-
138
- <table class="settings-table">
139
- <tbody>
140
- <tr>
141
- <th scope="row"><label for="image_selector">Image selector</label></th>
142
- <td>
143
- <input type="text" id="image_selector" name="image_selector"
144
- value="<?php echo esc_attr( $dev_options['image_selector'] );?>" />
145
-
146
- <p class="description">jQuery selector for all the images that should have the "Pin it" button. Set
147
- the value to <a href="#" class="jpibfi_selector_option">div.jpibfi_container img</a> if you want
148
- the "Pin it" button to appear only on images in content or <a href="#" class="jpibfi_selector_option">img</a>
149
- to appear on all images on site (including sidebar, header and footer). If you know a thing or two about jQuery, you might use your own selector.
150
- <a href="http://api.jquery.com/category/selectors/" target="_blank">Click here</a> to read
151
- about jQuery selectors.</p>
152
- </td>
153
- </tr>
154
- <tr>
155
- <th scope="row"><label for="disabled_classes">Disabled classes</label></th>
156
- <td>
157
- <textarea id="disabled_classes" name="disabled_classes" <?php jpibfi_conditional( $errors["disabled_classes"], "class='error-border'" ); ?>
158
- ><?php echo esc_attr( $dev_options['disabled_classes'] );?></textarea>
159
-
160
- <p class="description">Pictures with these CSS classes won't show the "Pin it" button. Please separate multiple classes with semicolons. Spaces are not accepted.</p>
161
- </td>
162
- </tr>
163
- <tr>
164
- <th scope="row"><label for="enabled_classes">Enabled classes</label></th>
165
- <td>
166
- <textarea id="enabled_classes" name="enabled_classes" <?php jpibfi_conditional( $errors["enabled_classes"], "class='error-border'" ); ?>
167
- ><?php echo esc_attr( $dev_options['enabled_classes'] );?></textarea>
168
- <p class="description">Pictures with these CSS classes will show the "Pin it" button. Please
169
- separate multiple classes with semicolons. If this field is empty, images with any (besides
170
- disabled ones) classes will show the Pin It button.</p>
171
- </td>
172
- </tr>
173
- <tr>
174
- <th scope="row"><label>On which pages the "Pin it" button should be shown</label></th>
175
- <td>
176
- <input type="checkbox" id="on_home" name="on_home" <?php checked( "1", $advanced_dev_options['on_home'] ); ?> value="1" />
177
- <label for="on_home"> Home page</label><br />
178
- <input type="checkbox" id="on_page" name="on_page" <?php checked( "1", $advanced_dev_options['on_page'] ); ?> value="1" />
179
- <label for="on_page"> Pages</label><br />
180
- <input type="checkbox" id="on_single" name="on_single" <?php checked( "1", $advanced_dev_options['on_single'] ); ?> value="1" />
181
- <label for="on_single"> Single posts</label><br />
182
- <input type="checkbox" id="on_category" name="on_category" <?php checked( "1", $advanced_dev_options['on_category'] ); ?> value="1" />
183
- <label for="on_category"> Category and archive pages</label><br />
184
- <input type="checkbox" id="on_blog" name="on_blog" <?php checked( "1", $advanced_dev_options['on_blog'] ); ?> value="1" />
185
- <label for="on_blog"> Blog pages</label>
186
-
187
- <p class="description">Check on which pages you want the Pinterest button to show up.</p>
188
- </td>
189
- </tr>
190
- <tr>
191
- <th scope="row"><label>Minimum resolution that should trigger the "Pin it" button to show up</label></th>
192
- <td>
193
- <p>
194
- <label for="min_image_height">Height</label>
195
- <input type="number" min="0" step="1" id="min_image_height" name="min_image_height" value="<?php echo $dev_options["min_image_height"]; ?>"
196
- class="jpibfi-admin-number <?php jpibfi_conditional( $errors['min_image_height'], "error-border"); ?>" /> px
197
- </p>
198
-
199
- <p>
200
- <label for="min_image_width">Width</label>
201
- <input type="number" min="0" step="1" id="min_image_width" name="min_image_width" value="<?php echo $dev_options["min_image_width"]; ?>"
202
- class="jpibfi-admin-number <?php jpibfi_conditional( $errors['min_image_width'], "error-border" ); ?>" /> px
203
- </p>
204
- <p class="description">If you'd like the "Pin it" button to not show up on small images (e.g. social media icons), just set the appropriate values above. The default value (0,0) causes the "Pin it" button to show on every eligible image.</p>
205
- </td>
206
- </tr>
207
- </tbody>
208
- </table>
209
- <h3>Visual settings</h3>
210
- <hr/>
211
- <table class="settings-table">
212
- <tbody>
213
- <tr>
214
- <th scope="row"><label for="description_option">Description source</label></th>
215
- <td>
216
- <select id="description_option" name="description_option">
217
- <option value="1" <?php selected ( "1", $dev_options['description_option'] ); ?>>Page title</option>
218
- <option value="2" <?php selected ( "2", $dev_options['description_option'] ); ?>>Page description</option>
219
- <option value="3" <?php selected ( "3", $dev_options['description_option'] ); ?>>Picture title or (if title not available) alt attribute</option>
220
- <option value="4" <?php selected ( "4", $dev_options['description_option'] ); ?>>Site title (Settings->General)</option>
221
- </select>
222
-
223
- <p class="description">From where the Pinterest message should be taken.</p>
224
- </td>
225
- </tr>
226
- <tr>
227
- <th scope="row"><label for="use_post_url">Linked page</label></th>
228
- <td>
229
- <input type="checkbox" id="use_post_url" name="use_post_url" value="1" <?php checked( "1", $dev_options["use_post_url"] ); ?> />
230
- <label class="chbox-label" for="use_post_url">Always link to individual post page</label>
231
- <p class="description">Experimental feature. When checked, the link on Pinterest will always point to the individual page with the image, even when the image was pinned on an archive page, category page or homepage. If false, the link will point to the URL the user is currently on.</p>
232
- </td>
233
- </tr>
234
- <tr>
235
- <th scope="row"><label for="standard_transparency">Transparency</label></th>
236
- <td>
237
- <label for="standard_transparency">Choose transparency (between 0.00 and 1.00)</label><br />
238
- <input type="number" min="0" max="1" step="0.01" id="standard_transparency" name="standard_transparency"
239
- value="<?php echo $dev_options['transparency_value'];?>" <?php jpibfi_conditional( $errors["transparency_value"], "class='error-border'" ); ?>/>
240
- <p class="description">This setting sets the transparency of the layer covering the image..</p>
241
- </td>
242
- </tr>
243
- <tr>
244
- <th scope="row"><label>Custom "Pin It" button</label></th>
245
- <td>
246
- <p>
247
- <input type="checkbox" id="use_custom_image" name="use_custom_image" value="1" <?php checked( "1", $dev_options["use_custom_image"] ); ?> />
248
- <label class="chbox-label" for="use_custom_image">Use custom image</label>
249
- </p>
250
-
251
- <input id="upload-image" type='button' class='button' value='Upload an image using media library' /><br />
252
-
253
- <p>
254
- <label for="custom_image_url">URL address of the image</label>
255
- <input type="url" id="custom_image_url" name="custom_image_url" value="<?php echo $dev_options["custom_image_url"]; ?>" style="width: 100%;" />
256
- </p>
257
-
258
- <p>
259
- <label for="custom_image_height">Height</label>
260
- <input type="number" min="0" step="1" id="custom_image_height" name="custom_image_height" value="<?php echo $dev_options["custom_image_height"]; ?>"
261
- class="jpibfi-admin-number <?php jpibfi_conditional( $errors['custom_image_height'], "error-border"); ?>" /> px
262
- </p>
263
-
264
- <p>
265
- <label for="custom_image_width">Width</label>
266
- <input type="number" min="0" step="1" id="custom_image_width" name="custom_image_width" value="<?php echo $dev_options["custom_image_width"]; ?>"
267
- class="jpibfi-admin-number <?php jpibfi_conditional( $errors['custom_image_width'], "error-border" ); ?>" /> px
268
- </p>
269
-
270
- <p class="description">
271
- Check the <b>Use custom image</b> checkbox, specify image's URL, height and width to use your own Pinterest button design. You can just upload an image using Wordpress media library if you wish.
272
- </p>
273
- </td>
274
- </tr>
275
- <tr>
276
- <th scope="row"><label for="button_position">Pin it button position</label></th>
277
- <td>
278
- <select name="button_position" id="button_position">
279
- <?php foreach( $jpibfi_button_dropdown as $key => $value ) { ?>
280
- <option value="<?php echo $key; ?>" <?php selected( $key, $dev_options['button_position'] ); ?>><?php echo $value; ?></option>
281
- <?php } ?>
282
- </select><br/>
283
- <textarea id="custom_button_css" rows="5" name="custom_button_css"><?php echo $custom_button_css; ?></textarea>
284
-
285
- </td>
286
- </tr>
287
- <tr>
288
- <th scope="row"><label>Preview</label></th>
289
- <td>
290
- <img src="<?php echo plugins_url( '/images/image_preview.jpg', __FILE__ ); ?>" id="<?php echo JPIBFI_PREVIEW_IMAGE_ID; ?>"
291
- alt="This is a preview"/>
292
- <p class="description">Make sure you reload the settings page (click the proper link in Settings section) once again after saving the settings to make preview work properly.</p>
293
- </td>
294
- </tr>
295
- <tr>
296
- <th scope="row"><label>Donate</label></th>
297
- <td>
298
- <a href="http://bit.ly/Uw2mEP" target="_blank" rel="nofollow" class="button"><b>Donate</b></a>
299
- <p class="description">If you like the plugin and would like to support its author, please donate.</p>
300
- </td>
301
- </tr>
302
- <tr>
303
- <th scope="row"></th>
304
- <td>
305
- <?php submit_button( null, 'primary', "update_jQuery_Pin_It_Button_For_Images", true, array( 'id' => 'submit_form' ) ); ?>
306
- </td>
307
- </tr>
308
- </tbody>
309
- </table>
310
- </form>
311
- </div>
312
- <?php
313
- }
314
- ?>
jpibfi-constants.php DELETED
@@ -1,34 +0,0 @@
1
- <?php
2
-
3
- if ( ! function_exists( 'add_action' ) ) {
4
- echo "Hi there! I'm just a plugin, not much I can do when called directly.";
5
- exit;
6
- }
7
-
8
- define( "JPIBFI_VERSION", "0.9.95" );
9
- define( "JPIBFI_BASIC_OPTIONS", "jptbfi_options" );
10
- define( "JPIBFI_ADVANCED_OPTIONS", "jptbfi_advanced_options" );
11
- define( "JPIBFI_BUTTON_CUSTOM_CSS", "jpibfi_button_custom_css" );
12
- define( "JPIBFI_METADATA", "jpibfi_meta");
13
-
14
- //DEFAULT PIN BUTTON IMAGE
15
- define( "JPIBFI_IMAGE_URL", plugins_url( '/images/pinit-button.png', __FILE__ ) );
16
- define( "JPIBFI_IMAGE_WIDTH", 65 );
17
- define( "JPIBFI_IMAGE_HEIGHT", 41 );
18
-
19
- define( "JPIBFI_PREVIEW_IMAGE_ID", "jpibfi_preview_image" );
20
-
21
- $jpibfi_button_css[0] = esc_html( "top:0%;&#10;left:0%;&#10;margin:20px 0 0 20px;" ); //Top left
22
- $jpibfi_button_css[1] = esc_html( "top:0%;&#10;right:0%;&#10;margin:20px 20px 0 0;" ); //Top right
23
- $jpibfi_button_css[2] = esc_html( "bottom:0%;&#10;left:0%;&#10;margin:0 0 20px 20px;" ); //Bottom left
24
- $jpibfi_button_css[3] = esc_html( "bottom:0%;&#10;right:0%;&#10;margin:0 20px 20px 0;" ); //Bottom right
25
- $jpibfi_button_css[4] = esc_html( "top:0;&#10;left:0;&#10;right:0;&#10;bottom:0;&#10;margin:auto;" ); //Middle
26
-
27
- $jpibfi_button_dropdown = array(
28
- "Top left (default)",
29
- "Top right",
30
- "Bottom left",
31
- "Bottom right",
32
- "Middle",
33
- "Custom"
34
- );
jpibfi-validation.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
-
3
- if ( ! function_exists( 'add_action' ) ) {
4
- echo "Hi there! I'm just a plugin, not much I can do when called directly.";
5
- exit;
6
- }
7
-
8
- function jpibfi_is_string_css_class_name( $class_name ) {
9
- return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*#x2F;", $class_name );
10
- }
11
-
12
- function jpibfi_contains_css_class_names_or_empty( $str ) {
13
- if ( strlen( $str ) == 0 )
14
- return true;
15
-
16
- $names = explode( ";", $str );
17
- $only_css_class_names = true;
18
-
19
- foreach ( $names as $name ) {
20
- if ( ! jpibfi_is_string_css_class_name( $name ) ) {
21
- $only_css_class_names = false;
22
- break;
23
- }
24
- }
25
- return $only_css_class_names;
26
- }
27
-
28
- function jpibfi_is_numeric_and_more_or_equal_to_zero( $str ) {
29
- return ( is_numeric( $str ) && $str >= 0 );
30
- }
jquery-pin-it-button-for-images.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: jQuery Pin It Button For Images
4
Plugin URI: http://wordpress.org/extend/plugins/jquery-pin-it-button-for-images/
5
Description: Highlights images on hover and adds a "Pin It" button over them for easy pinning.
6
Author: Marcin Skrzypiec
7
- Version: 0.9.99
8
Author URI: http://profiles.wordpress.org/mrsztuczkens
9
*/
10
@@ -13,140 +13,36 @@ if ( ! function_exists( 'add_action' ) ) {
13
exit;
14
}
15
16
- require_once( "jpibfi-constants.php" );
17
- require_once( "jpibfi-validation.php" );
18
- require_once( "jpibfi-admin.php" );
19
-
20
-
21
- //Returns an array of basic admin options, updates settings if necessary
22
- function jpibfi_get_basic_options() {
23
-
24
- $admin_options = array(
25
- 'image_selector' => 'div.jpibfi_container img',
26
- 'disabled_classes' => 'nopin;wp-smiley',
27
- 'description_option' => 1,
28
- 'enabled_classes' => '',
29
- 'transparency_value' => '0.5',
30
- 'use_custom_image' => '0',
31
- 'custom_image_url' => '',
32
- 'custom_image_height' => '0',
33
- 'custom_image_width' => '0',
34
- 'use_post_url' => '0',
35
- 'min_image_height' => '0',
36
- 'min_image_width' => '0',
37
- 'button_position' => '0'
38
- );
39
-
40
- $dev_options = get_option( JPIBFI_BASIC_OPTIONS );
41
-
42
- $changes_in_db = count( $admin_options ) != count( $dev_options ); //if arrays aren't of the same length, changes in db needed
43
-
44
- //invalid values need to be corrected and saved in db
45
- if ( ! empty( $dev_options ) ) {
46
- foreach ( $dev_options as $key => $option ) {
47
- switch ( $key ) {
48
- case "image_selector": //no constraints
49
- case "custom_image_url":
50
- $admin_options[$key] = $option;
51
- break;
52
- case "disabled_classes": //contains list of css classes or is empty
53
- case "enabled_classes":
54
- if ( jpibfi_contains_css_class_names_or_empty( $option ) )
55
- $admin_options[$key] = $option;
56
- else
57
- $changes_in_db = true;
58
- break;
59
- case "description_option":
60
- if ( in_array( $option, array( '1', '2', '3', '4' ) ) )
61
- $admin_options[$key] = $option;
62
- else
63
- $changes_in_db = true;
64
- break;
65
- case "use_custom_image": //0 or 1 values
66
- case "use_post_url":
67
- if ( strcmp( $option, '0' ) != 0 && strcmp( $option, '1' ) != 0 ) //invalid value in database
68
- $changes_in_db = true;
69
- else
70
- $admin_options[$key] = $option;
71
- break;
72
- case "transparency_value": //between 0 and 1
73
- if ( ! is_numeric( $option ) || ( $option < 0 ) || ( $option > 1 ) )
74
- $changes_in_db = true;
75
- else
76
- $admin_options[$key] = $option;
77
- break;
78
- case "custom_image_width": //numeric value or empty
79
- case "custom_image_height":
80
- case "min_image_width":
81
- case "min_image_height":
82
- case "button_position":
83
- if ( jpibfi_is_numeric_and_more_or_equal_to_zero( $option ) )
84
- $admin_options[$key] = $option;
85
- else
86
- $changes_in_db = true;
87
- break;
88
- }
89
- }
90
- }
91
- else {
92
- $changes_in_db = true;
93
- }
94
- //if something changed in the database, we need to save it
95
- if ( $changes_in_db )
96
- update_option( JPIBFI_BASIC_OPTIONS, $admin_options );
97
-
98
- return $admin_options;
99
- }
100
-
101
- //Returns an array of advanced admin options, updates settings if necessary
102
- function jpibfi_get_advanced_options() {
103
-
104
- $admin_options = array(
105
- 'on_home' => '1',
106
- 'on_single' => '1',
107
- 'on_page' => '1',
108
- 'on_category' => '1',
109
- 'on_blog' => '1'
110
- );
111
-
112
- $dev_options = get_option( JPIBFI_ADVANCED_OPTIONS );
113
- $changes_in_db = ! $dev_options || count( $admin_options ) != count( $dev_options ); //if arrays aren't of the same length, changes in db needed
114
-
115
- if ( !empty( $dev_options ) ) {
116
- foreach ( $admin_options as $setting_name => $setting_value ) {
117
- if ( array_key_exists( $setting_name, $dev_options ) )
118
- $admin_options[$setting_name] = $dev_options[$setting_name];
119
- }
120
- }
121
-
122
- //if something changed in the database, we need to save it
123
- if ( $changes_in_db )
124
- update_option( JPIBFI_ADVANCED_OPTIONS, $admin_options );
125
- return $admin_options;
126
- }
127
-
128
- function jpibfi_get_button_css() {
129
- global $jpibfi_button_css;
130
-
131
- $button_css = $jpibfi_button_css[0];
132
-
133
- $button_css_from_db = get_option( JPIBFI_BUTTON_CUSTOM_CSS );
134
-
135
- if ( empty( $button_css_from_db ) ) {
136
- update_option( JPIBFI_BUTTON_CUSTOM_CSS, $button_css );
137
- return $button_css;
138
- }
139
140
- return $button_css_from_db;
141
- }
142
143
144
- //returns false if plugin shouldn't be added to certain post based on metadata, otherwise true
145
function jpibfi_add_plugin_to_post( $post_id ) {
146
$post_meta = get_post_meta( $post_id, JPIBFI_METADATA, true );
147
- if ( ! empty( $post_meta ) && array_key_exists( 'jpibfi_disable_for_post', $post_meta ) && $post_meta['jpibfi_disable_for_post'] == '1' )
148
- return false;
149
- return true;
150
}
151
152
/*
@@ -160,176 +56,143 @@ function jpibfi_is_blog_page() {
160
return ( ( is_home() || is_archive() || is_single() ) && ( $post_type == 'post' ) );
161
}
162
163
- //Returns true if plugin should be added to a certain page
164
function jpibfi_add_plugin() {
165
- if ( is_admin() )
166
- return true;
167
168
global $post;
169
- $advanced_settings = jpibfi_get_advanced_options();
170
171
if ( is_front_page() )
172
- return $advanced_settings['on_home'] == "1";
173
else if ( is_single() )
174
- return $advanced_settings['on_single'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
175
else if ( is_page() )
176
- return $advanced_settings['on_page'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
177
else if ( is_category() || is_archive() || is_search() )
178
- return $advanced_settings['on_category'] == "1";
179
else if ( jpibfi_is_blog_page() )
180
- return $advanced_settings['on_blog'] == "1";
181
return true;
182
}
183
184
- //fire it when activating the plugin - add all necessary db entries
185
- function jpibfi_init_plugin() {
186
- jpibfi_get_basic_options();
187
- jpibfi_get_advanced_options();
188
- }
189
-
190
//Adds all necessary scripts
191
function jpibfi_add_plugin_scripts() {
192
if ( ! ( jpibfi_add_plugin() ) )
193
return;
194
195
wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.min.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION, false );
196
197
- $dev_options = jpibfi_get_basic_options();
198
$parameters_array = array(
199
- 'image_selector' => $dev_options['image_selector'],
200
- 'disabled_classes' => $dev_options['disabled_classes'],
201
- 'enabled_classes' => $dev_options['enabled_classes'],
202
- 'description_option'=> $dev_options['description_option'],
203
- 'use_post_url' => $dev_options['use_post_url'],
204
- 'min_image_height' => $dev_options['min_image_height'],
205
- 'min_image_width' => $dev_options['min_image_width'],
206
'site_title' => get_bloginfo( 'name', 'display' )
207
);
208
wp_localize_script( 'jquery-pin-it-button-script', 'jpibfi_options', $parameters_array );
209
}
210
211
function jpibfi_print_header_style_action() {
212
if ( ! ( jpibfi_add_plugin() ) )
213
return;
214
215
- $dev_options = jpibfi_get_basic_options();
216
217
- $button_css = jpibfi_get_button_css();
218
219
- if ( $dev_options['use_custom_image'] == "1" ) {
220
- $width = $dev_options['custom_image_width'];
221
- $height = $dev_options['custom_image_height'];
222
- $url = $dev_options['custom_image_url'];
223
- }
224
- else {
225
- $width = JPIBFI_IMAGE_WIDTH;
226
- $height = JPIBFI_IMAGE_HEIGHT;
227
- $url = JPIBFI_IMAGE_URL;
228
- }
229
230
- $transparencyDec = floatval( $dev_options['transparency_value'] ); //I need to convert 0.0..1.0 value to 0..255
231
- $transparencyDec = (int)( $transparencyDec * 255 );
232
- $transparencyHex = dechex( (int) $transparencyDec );
233
- if ( strlen( $transparencyHex) == 1 )
234
- $transparencyHex = "0" . $transparencyHex;
235
- $transparencyHex = "#" . $transparencyHex . "ffffff";
236
237
?>
238
<!--[if lt IE 9]>
239
<style type="text/css">
240
.pinit-overlay {
241
- filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='<?php echo $transparencyHex; ?>',endColorstr='<?php echo $transparencyHex; ?>');
242
- background:transparent;
243
- zoom: 1;
244
}
245
</style>
246
- <script type="text/javascript">
247
- var jpibfi_is_ie8 = true;
248
- </script>
249
<![endif]-->
250
251
<style type="text/css">
252
- .pinit-overlay {
253
- background-color: rgba(255, 255, 255, <?php echo $dev_options['transparency_value']; ?>);
254
- position:absolute;
255
- z-index:200;
256
- display:none;
257
}
258
.pinit-overlay a {
259
- <?php
260
- printf( 'width:%spx; height:%spx; background:transparent url("%s") no-repeat 0 0;', $width, $height, $url );
261
- echo $button_css;
262
- ?>
263
- position:absolute;
264
- display:block;
265
- text-indent:-9999em;
266
}
267
</style>
268
<?php
269
}
270
271
function jpibfi_print_hidden_field_script( $content ) {
272
if ( ! jpibfi_add_plugin() )
273
return $content;
274
global $post;
275
- return "<input class='jpibfi' type='hidden' data-jpibfi-url='". get_permalink( $post->ID ) . "'/>" . $content;
276
- }
277
278
- //ADMIN PAGE CODE
279
280
- //add admin scripts
281
- function jpibfi_add_admin_site_scripts() {
282
- global $jpibfi_button_css;
283
284
- wp_register_style( 'jquery-pin-it-button-admin-style', plugins_url( '/css/admin.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
285
- wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
286
287
- wp_enqueue_script( 'jquery-pin-it-button-admin-script', plugins_url( '/js/admin.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION, false );
288
- wp_localize_script( 'jquery-pin-it-button-admin-script', 'jpibfi_button_css', $jpibfi_button_css );
289
290
- if ( function_exists( "wp_enqueue_media") ) {
291
- wp_enqueue_media();
292
- wp_enqueue_script( 'jpibfi-upload-new', plugins_url( '/js/upload-button-new.js', __FILE__ ), array(), JPIBFI_VERSION, false );
293
- } else {
294
- wp_enqueue_script( 'jpibfi-upload-old', plugins_url( '/js/upload-button-old.js', __FILE__ ), array('thickbox', 'media-upload' ), JPIBFI_VERSION, false );
295
}
296
297
- //for preview purposes
298
- jpibfi_print_header_style_action();
299
- wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.min.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION, false );
300
301
- $parameters_array = array(
302
- 'image_selector' => '#' . JPIBFI_PREVIEW_IMAGE_ID,
303
- 'disabled_classes' => "",
304
- 'enabled_classes' => "",
305
- 'description_option' => 3,
306
- 'use_post_url' => 1,
307
- 'min_image_height' => '0',
308
- 'min_image_width' => '0'
309
- );
310
- wp_localize_script('jquery-pin-it-button-script', 'jpibfi_options', $parameters_array);
311
}
312
313
- function jpibfi_print_admin_page_action() {
314
- $page = add_options_page( 'jQuery Pin It Button For Images', 'jQuery Pin It Button For Images', 'manage_options', basename( __FILE__ ), 'jpibfi_print_admin_page' );
315
- add_action( 'admin_print_styles-' . $page, 'jpibfi_add_admin_site_scripts' );
316
- }
317
318
- function jpibfi_plugin_settings_filter( $links ) {
319
- $settings_link = '<a href="options-general.php?page=jquery-pin-it-button-for-images.php">Settings</a>';
320
- array_unshift( $links, $settings_link );
321
- return $links;
322
- }
323
-
324
- //END ADMIN PAGE CODE
325
-
326
- //POST EDITOR CODE
327
328
function jpibfi_add_meta_box() {
329
//for posts
330
add_meta_box(
331
'jpibfi_settings_id', // this is HTML id of the box on edit screen
332
- 'jQuery Pin It Button for Images - Settings', // title of the box
333
'jpibfi_print_meta_box', // function to be called to display the checkboxes, see the function below
334
'post', // on which edit screen the box should appear
335
'side', // part of page where the box should appear
@@ -339,7 +202,7 @@ function jpibfi_add_meta_box() {
339
//for pages
340
add_meta_box(
341
'jpibfi_settings_id',
342
- 'jQuery Pin It Button for Images - Settings',
343
'jpibfi_print_meta_box',
344
'page',
345
'side',
@@ -347,6 +210,8 @@ function jpibfi_add_meta_box() {
347
);
348
}
349
350
// display the metabox
351
function jpibfi_print_meta_box( $post, $metabox ) {
352
@@ -355,21 +220,22 @@ function jpibfi_print_meta_box( $post, $metabox ) {
355
$post_meta = get_post_meta( $post->ID, JPIBFI_METADATA, true );
356
$checked = isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1';
357
358
- echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"'
359
- . checked( $checked, true, false ) . ' /><label for="jpibfi_disable_for_post"> Disable "Pin it" button for this post (works only on single pages/posts)</label><br />';
360
}
361
362
function jpibfi_save_meta_data( $post_id ) {
363
364
// check if this isn't an auto save
365
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
366
return;
367
// security check = updating possible only using post edit form
368
if ( !isset( $_POST['jpibfi_nonce'] ) || ! wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
369
return;
370
- //check user's permissions
371
- if ( ! current_user_can( 'edit_post', $post_id ) )
372
- return;
373
374
$post_meta = array( 'jpibfi_disable_for_post' => '0' );
375
// now store data in custom fields based on checkboxes selected
@@ -382,31 +248,878 @@ function jpibfi_save_meta_data( $post_id ) {
382
delete_post_meta( $post_id, JPIBFI_METADATA );
383
}
384
385
//END POST EDITOR CODE
386
387
- //fire it when the plugin is deleted
388
function jpibfi_uninstall_plugin() {
389
390
//delete all added options
391
- delete_option( JPIBFI_BASIC_OPTIONS );
392
- delete_option( JPIBFI_ADVANCED_OPTIONS );
393
394
//delete added metadata from all posts
395
delete_post_meta_by_key( JPIBFI_METADATA );
396
}
397
398
- //Actions and Filters
399
400
- register_activation_hook( __FILE__, 'jpibfi_init_plugin' );
401
- register_uninstall_hook( __FILE__, 'jpibfi_uninstall_plugin' );
402
- //Actions
403
- add_action( 'wp_enqueue_scripts', 'jpibfi_add_plugin_scripts' );
404
- add_action( 'admin_menu', 'jpibfi_print_admin_page_action' );
405
- add_action( 'wp_head', 'jpibfi_print_header_style_action' );
406
- add_action( 'add_meta_boxes', 'jpibfi_add_meta_box' );
407
- add_action( 'save_post', 'jpibfi_save_meta_data' );
408
409
- //Filters
410
- $plugin = plugin_basename( __FILE__ );
411
- add_filter( "plugin_action_links_$plugin", 'jpibfi_plugin_settings_filter' );
412
- add_filter( "the_content", 'jpibfi_print_hidden_field_script' );
4
Plugin URI: http://wordpress.org/extend/plugins/jquery-pin-it-button-for-images/
5
Description: Highlights images on hover and adds a "Pin It" button over them for easy pinning.
6
Author: Marcin Skrzypiec
7
+ Version: 1.00
8
Author URI: http://profiles.wordpress.org/mrsztuczkens
9
*/
10
13
exit;
14
}
15
16
+ /*
17
+ *
18
+ * CONSTANTS
19
+ *
20
+ */
21
+ define( "JPIBFI_VERSION", "1.00" );
22
+ define( "JPIBFI_METADATA", "jpibfi_meta" );
23
+ define( "JPIBFI_SELECTION_OPTIONS", "jpibfi_selection_options" );
24
+ define( "JPIBFI_VISUAL_OPTIONS", "jpibfi_visual_options" );
25
+ define( "JPIBFI_VERSION_OPTION", "jpibfi_version");
26
27
+ //DEFAULT PIN BUTTON IMAGE
28
+ define( "JPIBFI_IMAGE_URL", plugins_url( '/images/pinit-button.png', __FILE__ ) );
29
+ define( "JPIBFI_IMAGE_WIDTH", 65 );
30
+ define( "JPIBFI_IMAGE_HEIGHT", 41 );
31
32
+ /*
33
+ *
34
+ * FRONT END STUFF
35
+ *
36
+ */
37
38
+ /*
39
+ * Checks if the plugin wasn't deactivated in the given post/page
40
+ */
41
function jpibfi_add_plugin_to_post( $post_id ) {
42
$post_meta = get_post_meta( $post_id, JPIBFI_METADATA, true );
43
+ return empty( $post_meta )
44
+ || false == array_key_exists( 'jpibfi_disable_for_post', $post_meta )
45
+ || '1' != $post_meta['jpibfi_disable_for_post'];
46
}
47
48
/*
56
return ( ( is_home() || is_archive() || is_single() ) && ( $post_type == 'post' ) );
57
}
58
59
+ /*
60
+ * True if plugin should be added to the current post/page
61
+ */
62
function jpibfi_add_plugin() {
63
64
global $post;
65
+ $options = get_option( JPIBFI_SELECTION_OPTIONS );
66
67
if ( is_front_page() )
68
+ return isset( $options['show_on_home'] ) && $options['show_on_home'] == "1";
69
else if ( is_single() )
70
+ return isset( $options['show_on_single'] ) && $options['show_on_single'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
71
else if ( is_page() )
72
+ return isset( $options['show_on_page'] ) && $options['show_on_page'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
73
else if ( is_category() || is_archive() || is_search() )
74
+ return isset( $options['show_on_category'] ) && $options['show_on_category'] == "1";
75
else if ( jpibfi_is_blog_page() )
76
+ return isset( $options['show_on_blog'] ) && $options['show_on_blog'] == "1";
77
return true;
78
}
79
80
//Adds all necessary scripts
81
function jpibfi_add_plugin_scripts() {
82
if ( ! ( jpibfi_add_plugin() ) )
83
return;
84
85
+ wp_register_style( 'jquery-pin-it-button-style', plugins_url( '/css/style.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
86
+ wp_enqueue_style( 'jquery-pin-it-button-style' );
87
+
88
wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.min.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION, false );
89
90
+ $visual_options = get_option( JPIBFI_VISUAL_OPTIONS );
91
+ $selection_options = get_option( JPIBFI_SELECTION_OPTIONS );
92
+
93
$parameters_array = array(
94
+ 'image_selector' => $selection_options['image_selector'],
95
+ 'disabled_classes' => $selection_options['disabled_classes'],
96
+ 'enabled_classes' => $selection_options['enabled_classes'],
97
+ 'description_option'=> $visual_options['description_option'],
98
+ 'use_post_url' => isset ( $visual_options['use_post_url'] ) ? $visual_options['use_post_url'] : '0',
99
+ 'min_image_height' => $selection_options['min_image_height'],
100
+ 'min_image_width' => $selection_options['min_image_width'],
101
'site_title' => get_bloginfo( 'name', 'display' )
102
);
103
wp_localize_script( 'jquery-pin-it-button-script', 'jpibfi_options', $parameters_array );
104
}
105
106
+ add_action( 'wp_enqueue_scripts', 'jpibfi_add_plugin_scripts' );
107
+
108
function jpibfi_print_header_style_action() {
109
if ( ! ( jpibfi_add_plugin() ) )
110
return;
111
112
+ $options = get_option( JPIBFI_VISUAL_OPTIONS );
113
114
+ $button_css = $options[ 'button_css' ];
115
+ $use_custom_image = isset( $options[ 'use_custom_image' ] ) && $options[ 'use_custom_image' ] == "1";
116
117
+ $width = $use_custom_image ? $options['custom_image_width'] : JPIBFI_IMAGE_WIDTH;
118
+ $height = $use_custom_image ? $options['custom_image_height'] : JPIBFI_IMAGE_HEIGHT;
119
+ $url = $use_custom_image ? $options['custom_image_url'] : JPIBFI_IMAGE_URL;
120
121
+ $transHex = "#" . jpibfi_convert_to_hex( $options['transparency_value'] ) . "ffffff";
122
123
?>
124
<!--[if lt IE 9]>
125
<style type="text/css">
126
.pinit-overlay {
127
+ background-image: url( '<?php echo plugins_url( '/images/transparency_0.png', __FILE__ ); ?>' );
128
+ }
129
+ .pinit-overlay:hover {
130
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='<?php echo $transHex; ?>',endColorstr='<?php echo $transHex; ?>');
131
}
132
</style>
133
<![endif]-->
134
135
<style type="text/css">
136
+ .pinit-overlay:hover {
137
+ background-color: rgba(255, 255, 255, <?php echo $options['transparency_value']; ?>);
138
}
139
.pinit-overlay a {
140
+ width: <?php echo $width; ?>px;
141
+ height: <?php echo $height; ?>px;
142
+ background: transparent url('<?php echo $url; ?>') no-repeat 0 0;
143
+ <?php echo $button_css; ?>
144
}
145
</style>
146
<?php
147
}
148
149
+ add_action( 'wp_head', 'jpibfi_print_header_style_action' );
150
+
151
+ /*
152
+ * Adds a hidden field with url and and description of the pin that's used when user uses "Link to individual page"
153
+ * Thanks to go brocheafoin, who added most of the code that handles creating description
154
+ */
155
function jpibfi_print_hidden_field_script( $content ) {
156
if ( ! jpibfi_add_plugin() )
157
return $content;
158
global $post;
159
160
+ $options = get_option( JPIBFI_VISUAL_OPTIONS );
161
162
+ $add_attributes = false == is_singular() && isset( $options[ 'use_post_url' ] ) && '1' == $options[ 'use_post_url' ];
163
164
+ $attributes_html = '';
165
166
+ //if we need to add additional attributes to handle use_post_url setting
167
+ if ( $add_attributes ){
168
+ //if page description should be used as pin description and an excerpt for the post exists
169
+ if ( has_excerpt( $post->ID ) && 2 == $options[ 'description_option' ] )
170
+ $description = wp_kses( $post->post_excerpt, array() );
171
+ else
172
+ $description = get_the_title($post->ID);
173
174
+ $attributes_html .= 'data-jpibfi-url="' . get_permalink( $post->ID ) . '" ' ;
175
+ $attributes_html .= 'data-jpibfi-description ="' . esc_attr( $description ) . '" ';
176
}
177
178
179
+ $input_html = '<input class="jpibfi" type="hidden" ' . $attributes_html . '>';
180
+ return $input_html . $content;
181
}
182
183
+ add_filter( "the_content", 'jpibfi_print_hidden_field_script' );
184
185
+ /*
186
+ *
187
+ * POST EDITOR CODE
188
+ *
189
+ */
190
191
function jpibfi_add_meta_box() {
192
//for posts
193
add_meta_box(
194
'jpibfi_settings_id', // this is HTML id of the box on edit screen
195
+ 'jQuery Pin It Button for Images - ' . __( 'Settings', 'jpibfi' ), // title of the box
196
'jpibfi_print_meta_box', // function to be called to display the checkboxes, see the function below
197
'post', // on which edit screen the box should appear
198
'side', // part of page where the box should appear
202
//for pages
203
add_meta_box(
204
'jpibfi_settings_id',
205
+ 'jQuery Pin It Button for Images - ' . __( 'Settings', 'jpibfi' ),
206
'jpibfi_print_meta_box',
207
'page',
208
'side',
210
);
211
}
212
213
+ add_action( 'add_meta_boxes', 'jpibfi_add_meta_box' );
214
+
215
// display the metabox
216
function jpibfi_print_meta_box( $post, $metabox ) {
217
220
$post_meta = get_post_meta( $post->ID, JPIBFI_METADATA, true );
221
$checked = isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1';
222
223
+ echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"' . checked( $checked, true, false ) . '>';
224
+ echo '<label for="jpibfi_disable_for_post">' . __( 'Disable "Pin it" button for this post (works only on single pages/posts)', 'jpibfi' ) . '</label><br />';
225
}
226
227
function jpibfi_save_meta_data( $post_id ) {
228
229
+ //check user's permissions
230
+ if ( ! current_user_can( 'edit_post', $post_id ) )
231
+ return;
232
// check if this isn't an auto save
233
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
234
return;
235
// security check = updating possible only using post edit form
236
if ( !isset( $_POST['jpibfi_nonce'] ) || ! wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
237
return;
238
+
239
240
$post_meta = array( 'jpibfi_disable_for_post' => '0' );
241
// now store data in custom fields based on checkboxes selected
248
delete_post_meta( $post_id, JPIBFI_METADATA );
249
}
250
251
+ add_action( 'save_post', 'jpibfi_save_meta_data' );
252
+
253
//END POST EDITOR CODE
254
255
+ //Delete everything the plugin added into DB
256
function jpibfi_uninstall_plugin() {
257
258
//delete all added options
259
+ delete_option( JPIBFI_SELECTION_OPTIONS );
260
+ delete_option( JPIBFI_VISUAL_OPTIONS );
261
+ delete_option( JPIBFI_VERSION_OPTION );
262
263
//delete added metadata from all posts
264
delete_post_meta_by_key( JPIBFI_METADATA );
265
}
266
267
+ register_uninstall_hook( __FILE__, 'jpibfi_uninstall_plugin' );
268
+
269
+ /*
270
+ *
271
+ * ADMIN SETTINGS
272
+ *
273
+ */
274
+
275
+ /*
276
+ * Function updates DB if it detects new version of the plugin
277
+ */
278
+ function jpibfi_update_plugin() {
279
+
280
+
281
+ $version = get_option( JPIBFI_VERSION_OPTION );
282
+
283
+ //if the plugin isn't installed at all or the version is below 1.00
284
+ if ( false == $version ) {
285
+ //rewrite old settings (if they exist) to new settings
286
+ jpibfi_convert_settings();
287
+
288
+ //if new settings are still absent (plugin wasn't installed previously), we need to add them
289
+ if( false == get_option( JPIBFI_VISUAL_OPTIONS ) )
290
+ add_option( JPIBFI_VISUAL_OPTIONS, jpibfi_default_visual_options() );
291
+
292
+ if( false == get_option( JPIBFI_SELECTION_OPTIONS ) )
293
+ add_option( JPIBFI_SELECTION_OPTIONS, jpibfi_default_selection_options() );
294
+
295
+ } else if ( (float)$version < (float)JPIBFI_VERSION ) { //if the plugins version is older than current, we need to update options with new defaults
296
+
297
+ $option = get_option( JPIBFI_VISUAL_OPTIONS );
298
+ jpibfi_update_option_fields( $option, jpibfi_default_visual_options(), JPIBFI_VISUAL_OPTIONS );
299
+
300
+ $option = get_option( JPIBFI_SELECTION_OPTIONS );
301
+ jpibfi_update_option_fields( $option, jpibfi_default_selection_options(), JPIBFI_SELECTION_OPTIONS );
302
+ }
303
+
304
+ //update the version of the plugin stored in option
305
+ update_option( JPIBFI_VERSION_OPTION, JPIBFI_VERSION );
306
+ }
307
+
308
+ register_activation_hook( __FILE__, 'jpibfi_update_plugin' );
309
+ add_action( 'plugins_loaded', 'jpibfi_update_plugin' );
310
+
311
+ /*
312
+ * This function converts old settings from versions earlier than 1.00 (if there are any) format to new settings format (changed names of options, etc)
313
+ */
314
+ function jpibfi_convert_settings() {
315
+ //get all old options
316
+ $basic_option = get_option( "jptbfi_options" );
317
+ $advanced_options = get_option( 'jptbfi_advanced_options' );
318
+ $button_css = get_option( 'jpibfi_button_custom_css' );
319
+
320
+ //if options don't exist, there's nothing to convert so the function ends
321
+ if ( false == $basic_option || false == $advanced_options )
322
+ return;
323
+
324
+ //rewrite them to new options
325
+ $default_selection_options = jpibfi_default_selection_options();
326
+
327
+ $selection_options = array();
328
+ $selection_options[ 'image_selector' ] = isset ( $basic_option[ 'image_selector' ] ) ? $basic_option[ 'image_selector' ] : $default_selection_options[ 'image_selector' ];
329
+ $selection_options[ 'disabled_classes' ] = isset ( $basic_option[ 'disabled_classes' ] ) ? $basic_option[ 'disabled_classes' ] : $default_selection_options[ 'disabled_classes' ];
330
+ $selection_options[ 'enabled_classes' ] = isset ( $basic_option[ 'enabled_classes' ] ) ? $basic_option[ 'enabled_classes' ] : $default_selection_options[ 'enabled_classes' ];
331
+ $selection_options[ 'min_image_height' ] = isset ( $basic_option[ 'min_image_height' ] ) ? $basic_option[ 'min_image_height' ] : $default_selection_options[ 'min_image_height' ];
332
+ $selection_options[ 'min_image_width' ] = isset ( $basic_option[ 'min_image_width' ] ) ? $basic_option[ 'min_image_width' ] : $default_selection_options[ 'min_image_width' ];
333
+
334
+ $selection_options[ 'show_on_home' ] = isset ( $advanced_options[ 'on_home' ] ) && '1' == $advanced_options[ 'on_home' ] ? '1' : '0';
335
+ $selection_options[ 'show_on_single' ] = isset ( $advanced_options[ 'on_single' ] ) && '1' == $advanced_options[ 'on_single' ] ? '1' : '0';
336
+ $selection_options[ 'show_on_page' ] = isset ( $advanced_options[ 'on_page' ] ) && '1' == $advanced_options[ 'on_page' ] ? '1' : '0';
337
+ $selection_options[ 'show_on_category' ] = isset ( $advanced_options[ 'on_category' ] )&& '1' == $advanced_options[ 'on_category' ] ? '1' : '0';
338
+ $selection_options[ 'show_on_blog' ] = isset ( $advanced_options[ 'on_blog' ] ) && '1' == $advanced_options[ 'on_blog' ] ? '1' : '0';
339
+
340
+ update_option( JPIBFI_SELECTION_OPTIONS, $selection_options );
341
+ //just in case any new fields are added to the option in the future
342
+ jpibfi_update_option_fields( $selection_options, jpibfi_default_selection_options(), JPIBFI_SELECTION_OPTIONS );
343
+
344
+ //visual options
345
+ $default_visual_options = jpibfi_default_visual_options();
346
+
347
+ $visual_options = array();
348
+ $visual_options[ 'description_option' ] = isset ( $basic_option[ 'description_option' ] ) ? $basic_option[ 'description_option' ] : $default_visual_options[ 'description_option' ];
349
+ $visual_options[ 'transparency_value' ] = isset ( $basic_option[ 'transparency_value' ] ) ? $basic_option[ 'transparency_value' ] : $default_visual_options[ 'transparency_value' ];
350
+ $visual_options[ 'use_custom_image' ] = isset ( $basic_option[ 'use_custom_image' ] ) && '1' == $basic_option[ 'use_custom_image' ] ? '1' : '0';
351
+ $visual_options[ 'custom_image_url' ] = isset ( $basic_option[ 'custom_image_url' ] ) ? $basic_option[ 'custom_image_url' ] : $default_visual_options[ 'custom_image_url' ];
352
+ $visual_options[ 'custom_image_height' ] = isset ( $basic_option[ 'custom_image_height' ] ) ? $basic_option[ 'custom_image_height' ] : $default_visual_options[ 'custom_image_height' ];
353
+ $visual_options[ 'custom_image_width' ] = isset ( $basic_option[ 'custom_image_width' ] ) ? $basic_option[ 'custom_image_width' ] : $default_visual_options[ 'custom_image_width' ];
354
+ $visual_options[ 'use_post_url' ] = isset ( $basic_option[ 'use_post_url' ] ) && '1' == $basic_option[ 'use_post_url' ] ? '1' : '0';
355
+ $visual_options[ 'button_position' ] = isset ( $basic_option[ 'button_position' ] ) ? $basic_option[ 'button_position' ] : $default_visual_options[ 'button_position' ];
356
+ $visual_options[ 'button_css' ] = true == $button_css ? $button_css : $default_visual_options[ 'button_css' ];
357
+
358
+ update_option( JPIBFI_VISUAL_OPTIONS, $visual_options );
359
+ //just in case any new fields are added to the option in the future
360
+ jpibfi_update_option_fields( $visual_options, jpibfi_default_visual_options(), JPIBFI_VISUAL_OPTIONS );
361
+
362
+ //delete all old options
363
+ delete_option( "jptbfi_options" );
364
+ delete_option( 'jptbfi_advanced_options' );
365
+ delete_option( 'jpibfi_button_custom_css' );
366
+ }
367
+
368
+ function jpibfi_print_admin_page_action() {
369
+ $page = add_submenu_page(
370
+ 'options-general.php',
371
+ 'jQuery Pin It Button For Images', // The value used to populate the browser's title bar when the menu page is active
372
+ 'jQuery Pin It Button For Images', // The text of the menu in the administrator's sidebar
373
+ 'administrator', // What roles are able to access the menu
374
+ 'jpibfi_settings', // The ID used to bind submenu items to this menu
375
+ 'jpibfi_print_admin_page' // The callback function used to render this menu
376
+ );
377
+
378
+ add_action( 'admin_print_styles-' . $page, 'jpibfi_add_admin_site_scripts' );
379
+ }
380
+
381
+ add_action( 'admin_menu', 'jpibfi_print_admin_page_action' );
382
+
383
+ /*
384
+ * adds admin scripts
385
+ */
386
+ function jpibfi_add_admin_site_scripts() {
387
+ $jpibfi_button_css = jpibfi_button_css();
388
+
389
+ wp_register_style( 'jquery-pin-it-button-admin-style', plugins_url( '/css/admin.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
390
+ wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
391
+
392
+ wp_enqueue_script( 'jquery-pin-it-button-admin-script', plugins_url( '/js/admin.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION, false );
393
+ wp_localize_script( 'jquery-pin-it-button-admin-script', 'jpibfi_button_css', $jpibfi_button_css );
394
+
395
+ if ( function_exists( "wp_enqueue_media") ) {
396
+ wp_enqueue_media();
397
+ wp_enqueue_script( 'jpibfi-upload-new', plugins_url( '/js/upload-button-new.js', __FILE__ ), array(), JPIBFI_VERSION, false );
398
+ } else {
399
+ wp_enqueue_script( 'jpibfi-upload-old', plugins_url( '/js/upload-button-old.js', __FILE__ ), array('thickbox', 'media-upload' ), JPIBFI_VERSION, false );
400
+ }
401
+ }
402
+
403
+
404
+ function jpibfi_plugin_settings_filter( $links ) {
405
+ $settings_link = '<a href="options-general.php?page=jpibfi_settings">' . __( 'Settings', 'jpibfi' ) . '</a>';
406
+ array_unshift( $links, $settings_link );
407
+ return $links;
408
+ }
409
+
410
+ $jpibfi_plugin = plugin_basename( __FILE__ );
411
+ add_filter( "plugin_action_links_$jpibfi_plugin", 'jpibfi_plugin_settings_filter' );
412
+
413
+ function jpibfi_print_admin_page() {
414
+ ?>
415
+ <!-- Create a header in the default WordPress 'wrap' container -->
416
+ <div class="wrap">
417
+
418
+ <h2><?php _e( 'jQuery Pin It Button For Images Options', 'jpibfi' ); ?></h2>
419
+
420
+ <?php
421
+ $tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'selection_options';
422
+ if ( 'selection_options' != $tab && 'visual_options' != $tab )
423
+ $tab = 'selection_options';
424
+ ?>
425
+ <div id="icon-plugins" class="icon32"></div>
426
+ <h2 class="nav-tab-wrapper">
427
+ <a href="?page=jpibfi_settings&tab=selection_options" class="nav-tab <?php echo $tab == 'selection_options' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Selection Options', 'jpibfi' ); ?></a>
428
+ <a href="?page=jpibfi_settings&tab=visual_options" class="nav-tab <?php echo $tab == 'visual_options' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Visual Options', 'jpibfi' ); ?></a>
429
+ </h2>
430
+
431
+ <p>
432
+ If you like the plugin and would like to support its development, please <a href="http://bit.ly/Uw2mEP" target="_blank" rel="nofollow"><b>donate</b></a>.
433
+ </p>
434
+ <form method="post" action="options.php">
435
+ <?php
436
+
437
+ if ( 'selection_options' == $tab ) {
438
+ settings_fields( 'jpibfi_selection_options' );
439
+ do_settings_sections( 'jpibfi_selection_options' );
440
+ } else if ( 'visual_options' == $tab) {
441
+ settings_fields( 'jpibfi_visual_options' );
442
+ do_settings_sections( 'jpibfi_visual_options' );
443
+ }
444
+
445
+ submit_button();
446
+ ?>
447
+ </form>
448
+
449
+ </div>
450
+ <?php
451
+
452
+ //cumbersome, but needed for error management to work properly in WP 3.3
453
+ delete_option( JPIBFI_SELECTION_OPTIONS . '_errors' );
454
+ delete_option( JPIBFI_VISUAL_OPTIONS . '_errors' );
455
+ }
456
+
457
+ /*
458
+ *
459
+ * SELECTION OPTIONS
460
+ *
461
+ */
462
+
463
+ /*
464
+ * Default values for selection options section
465
+ */
466
+ function jpibfi_default_selection_options() {
467
+ $defaults = array(
468
+ 'image_selector' => 'div.jpibfi_container img',
469
+ 'disabled_classes' => 'nopin;wp-smiley',
470
+ 'enabled_classes' => '',
471
+ 'min_image_height' => '0',
472
+ 'min_image_width' => '0',
473
+ 'show_on_home' => '1',
474
+ 'show_on_single' => '1',
475
+ 'show_on_page' => '1',
476
+ 'show_on_category' => '1',
477
+ 'show_on_blog' => '1'
478
+ );
479
+
480
+ return $defaults;
481
+ }
482
+
483
+ /*
484
+ * Defines selection options section and adds all required fields
485
+ */
486
+ function jpibfi_initialize_selection_options() {
487
+
488
+ // First, we register a section.
489
+ add_settings_section(
490
+ 'selection_options_section', // ID used to identify this section and with which to register options
491
+ __( 'Selection', 'jpibfi' ), // Title to be displayed on the administration page
492
+ 'jpibfi_selection_options_callback', // Callback used to render the description of the section
493
+ 'jpibfi_selection_options' // Page on which to add this section of options
494
+ );
495
+
496
+ //lThen add all necessary fields to the section
497
+ add_settings_field(
498
+ 'image_selector', // ID used to identify the field throughout the plugin
499
+ __( 'Image selector', 'jpibfi' ), // The label to the left of the option interface element
500
+ 'jpibfi_image_selector_callback', // The name of the function responsible for rendering the option interface
501
+ 'jpibfi_selection_options', // The page on which this option will be displayed
502
+ 'selection_options_section', // The name of the section to which this field belongs
503
+ array( // The array of arguments to pass to the callback. In this case, just a description.
504
+ __( 'jQuery selector for all the images that should have the "Pin it" button. Set
505
+ the value to <a href="#" class="jpibfi_selector_option">div.jpibfi_container img</a> if you want
506
+ the "Pin it" button to appear only on images in content or <a href="#" class="jpibfi_selector_option">img</a>
507
+ to appear on all images on site (including sidebar, header and footer). If you know a thing or two about jQuery, you might use your own selector.
508
+ <a href="http://api.jquery.com/category/selectors/" target="_blank">Click here</a> to read
509
+ about jQuery selectors.', 'jpibfi' ),
510
+ )
511
+ );
512
+
513
+ add_settings_field(
514
+ 'disabled_classes',
515
+ __( 'Disabled classes', 'jpibfi' ),
516
+ 'jpibfi_classes_callback',
517
+ 'jpibfi_selection_options',
518
+ 'selection_options_section',
519
+ array(
520
+ 'disabled_classes',
521
+ __( 'Pictures with these CSS classes won\'t show the "Pin it" button. Please separate multiple classes with semicolons. Spaces are not accepted.', 'jpibfi' ),
522
+ )
523
+ );
524
+
525
+ add_settings_field(
526
+ 'enabled_classes',
527
+ __( 'Enabled classes', 'jpibfi' ),
528
+ 'jpibfi_classes_callback',
529
+ 'jpibfi_selection_options',
530
+ 'selection_options_section',
531
+ array(
532
+ 'enabled_classes',
533
+ __( 'Only pictures with these CSS classes will show the "Pin it" button. Please
534
+ separate multiple classes with semicolons. If this field is empty, images with any (besides
535
+ disabled ones) classes will show the Pin It button.', 'jpibfi' ),
536
+ )
537
+ );
538
+
539
+ add_settings_field(
540
+ 'show_on_field',
541
+ __( 'On which pages the "Pin it" button should be shown', 'jpibfi' ),
542
+ 'jpibfi_show_on_field_callback',
543
+ 'jpibfi_selection_options',
544
+ 'selection_options_section',
545
+ array(
546
+ __( 'Check on which pages you want the Pinterest button to show up.', 'jpibfi' ),
547
+ )
548
+ );
549
+
550
+ add_settings_field(
551
+ 'min_image',
552
+ __( 'Minimum resolution that should trigger the "Pin it" button to show up', 'jpibfi' ),
553
+ 'jpibfi_min_image_callback',
554
+ 'jpibfi_selection_options',
555
+ 'selection_options_section',
556
+ array(
557
+ __( 'If you\'d like the "Pin it" button to not show up on small images (e.g. social media icons), just set the appropriate values above. The default value (0,0) causes the "Pin it" button to show on every eligible image.', 'jpibfi' ),
558
+ )
559
+ );
560
+
561
+ register_setting(
562
+ 'jpibfi_selection_options',
563
+ 'jpibfi_selection_options',
564
+ 'jpibfi_sanitize_selection_options'
565
+ );
566
+ }
567
+
568
+ add_action( 'admin_init', 'jpibfi_initialize_selection_options' );
569
+
570
+ function jpibfi_selection_options_callback() {
571
+ echo '<p>' . __('Which images can be pinned', 'jpibfi') . '</p>';
572
+ }
573
+
574
+ function jpibfi_image_selector_callback( $args ) {
575
+
576
+ $options = jpibfi_get_selection_options();
577
+
578
+ $selector = esc_attr( $options['image_selector'] );
579
+
580
+ echo '<input type="text" id="image_selector" name="jpibfi_selection_options[image_selector]" value="' . $selector . '"/>';
581
+ echo jpibfi_create_description( $args[0] );
582
+ }
583
+
584
+ function jpibfi_classes_callback( $args ) {
585
+
586
+ $options = jpibfi_get_selection_options();
587
+
588
+ $value = esc_attr( $options[ $args[0] ] );
589
+
590
+ echo '<textarea id="' . $args[0] . '" name="jpibfi_selection_options[' . $args[0] . ']">' . $value . '</textarea>';
591
+ echo jpibfi_create_description( $args[1] );
592
+ echo jpibfi_create_errors( $args[0] );
593
+ }
594
+
595
+ function jpibfi_show_on_field_callback( $args ) {
596
+ $options = jpibfi_get_selection_options();
597
+
598
+ $show_on_home = jpibfi_exists_and_equal_to( $options, 'show_on_home', '1' );
599
+ $show_on_page = jpibfi_exists_and_equal_to( $options, 'show_on_page', '1' );
600
+ $show_on_single = jpibfi_exists_and_equal_to( $options, 'show_on_single', '1' );
601
+ $show_on_category = jpibfi_exists_and_equal_to( $options, 'show_on_category', '1' );
602
+ $show_on_blog = jpibfi_exists_and_equal_to( $options, 'show_on_blog', '1' );
603
+ ?>
604
+
605
+ <input type="checkbox" id="show_on_home" name="jpibfi_selection_options[show_on_home]" <?php checked( true, $show_on_home ); ?> value="1" />
606
+ <label for="show_on_home"><?php _e( 'Home page', 'jpibfi' ); ?></label><br/>
607
+ <input type="checkbox" id="show_on_page" name="jpibfi_selection_options[show_on_page]" <?php checked( true, $show_on_page ); ?> value="1" />
608
+ <label for="show_on_page"><?php _e( 'Pages', 'jpibfi' ); ?></label><br />
609
+ <input type="checkbox" id="show_on_single" name="jpibfi_selection_options[show_on_single]" <?php checked( true, $show_on_single ); ?> value="1" />
610
+ <label for="show_on_single"><?php _e( 'Single posts', 'jpibfi' ); ?></label><br />
611
+ <input type="checkbox" id="show_on_category" name="jpibfi_selection_options[show_on_category]" <?php checked( true, $show_on_category ); ?> value="1" />
612
+ <label for="show_on_category"><?php _e( 'Category and archive pages', 'jpibfi' ); ?></label><br />
613
+ <input type="checkbox" id="show_on_blog" name="jpibfi_selection_options[show_on_blog]" <?php checked( true, $show_on_blog ); ?> value="1" />
614
+ <label for="show_on_blog"><?php _e( 'Blog pages', 'jpibfi' ); ?></label>
615
+
616
+ <?php
617
+ echo jpibfi_create_description( $args[0] );
618
+ }
619
+
620
+ function jpibfi_min_image_callback( $args ) {
621
+ $options = jpibfi_get_selection_options();
622
+
623
+ $min_image_height = $options[ 'min_image_height' ];
624
+ $min_image_width = $options[ 'min_image_width' ];
625
+ ?>
626
+
627
+ <p>
628
+ <label for="min_image_height"><?php _e('Height', 'jpibfi'); ?></label>
629
+ <input type="number" min="0" step="1" id="min_image_height" name="jpibfi_selection_options[min_image_height]" value="<?php echo $min_image_height; ?>"
630
+ class="small-text" /> px
631
+ <?php echo jpibfi_create_errors( 'min_image_height' ); ?>
632
+ </p>
633
+
634
+ <p>
635
+ <label for="min_image_width"><?php _e('Width', 'jpibfi'); ?></label>
636
+ <input type="number" min="0" step="1" id="min_image_width" name="jpibfi_selection_options[min_image_width]" value="<?php echo $min_image_width; ?>"
637
+ class="small-text" /> px
638
+ <?php echo jpibfi_create_errors( 'min_image_width' ); ?>
639
+ </p>
640
+
641
+ <?php
642
+
643
+ echo jpibfi_create_description( $args[0] );
644
+ }
645
+
646
+ function jpibfi_sanitize_selection_options( $input ) {
647
+
648
+ foreach( $input as $key => $value ) {
649
+ switch($key) {
650
+ case 'disabled_classes':
651
+ case 'enabled_classes':
652
+ if ( false == jpibfi_contains_css_class_names_or_empty( $input [ $key ] ) ) {
653
+
654
+ $field = '';
655
+ if ( 'disabled_classes' == $key )
656
+ $field = __( 'Disabled classes', 'jpibfi' );
657
+ else if ( 'enabled_classes' == $key )
658
+ $field = __( 'Enabled classes', 'jpibfi' );
659
+
660
+ add_settings_error(
661
+ $key,
662
+ esc_attr( 'settings_updated' ),
663
+ $field . ' - ' . __('the given value doesn\'t meet the requirements. Please correct it and try again.', 'jpibfi')
664
+ );
665
+ }
666
+ break;
667
+ case 'min_image_height':
668
+ case 'min_image_width':
669
+ if ( !is_numeric( $value ) || $value < 0 ) {
670
+
671
+ $field = '';
672
+ if ( 'min_image_height' == $key )
673
+ $field = __( 'Minimum image height', 'jpibfi' );
674
+ else if ( 'min_image_width' == $key )
675
+ $field = __( 'Minimum image width', 'jpibfi' );
676
+
677
+ add_settings_error(
678
+ $key,
679
+ esc_attr( 'settings_updated' ),
680
+ $field . ' - ' . __('value must be a number greater or equal to 0.', 'jpibfi')
681
+ );
682
+ }
683
+ break;
684
+ }
685
+
686
+ }
687
+
688
+ $errors = get_settings_errors();
689
+
690
+ if ( count( $errors ) > 0 ) {
691
+
692
+ update_option( JPIBFI_SELECTION_OPTIONS . '_errors', $input );
693
+ return get_option( JPIBFI_SELECTION_OPTIONS );
694
+
695
+ } else {
696
+
697
+ delete_option( JPIBFI_SELECTION_OPTIONS . '_errors' );
698
+ return $input;
699
+
700
+ }
701
+ }
702
+
703
+ function jpibfi_get_selection_options() {
704
+ return jpibfi_get_options( JPIBFI_SELECTION_OPTIONS );
705
+ }
706
+
707
+ /*
708
+ *
709
+ * VISUAL OPTIONS
710
+ *
711
+ */
712
+
713
+ /*
714
+ * Default values for visual options section
715
+ */
716
+ function jpibfi_default_visual_options() {
717
+ $jpibfi_button_css = jpibfi_button_css();
718
+
719
+ $defaults = array(
720
+ 'transparency_value' => '0.5',
721
+ 'description_option' => '1',
722
+ 'use_custom_image' => '0',
723
+ 'custom_image_url' => '',
724
+ 'custom_image_height' => '0',
725
+ 'custom_image_width' => '0',
726
+ 'use_post_url' => '0',
727
+ 'button_position' => '0',
728
+ 'button_css' => $jpibfi_button_css[0]
729
+ );
730
+
731
+ return $defaults;
732
+ }
733
+
734
+ /*
735
+ * Defines visual options section and defines all required fields
736
+ */
737
+ function jpibfi_initialize_visual_options() {
738
+
739
+ // First, we register a section.
740
+ add_settings_section(
741
+ 'visual_options_section', // ID used to identify this section and with which to register options
742
+ __( 'Visual', 'jpibfi' ), // Title to be displayed on the administration page
743
+ 'jpibfi_visual_options_callback', // Callback used to render the description of the section
744
+ 'jpibfi_visual_options' // Page on which to add this section of options
745
+ );
746
+
747
+ //Then add all necessary fields to the section
748
+ add_settings_field(
749
+ 'description_option',
750
+ __( 'Description source', 'jpibfi' ),
751
+ 'jpibfi_description_option_callback',
752
+ 'jpibfi_visual_options',
753
+ 'visual_options_section',
754
+ array(
755
+ __( 'From where the Pinterest message should be taken.', 'jpibfi' ),
756
+ )
757
+ );
758
+
759
+ add_settings_field(
760
+ 'use_post_url',
761
+ __( 'Linked page', 'jpibfi' ),
762
+ 'jpibfi_use_post_url_callback',
763
+ 'jpibfi_visual_options',
764
+ 'visual_options_section',
765
+ array(
766
+ __( 'When checked, the link on Pinterest will always point to the individual page with the image and title of this individual page will be used if you\'ve selected Title as the description source, even when the image was pinned on an archive page, category page or homepage. If false, the link will point to the URL the user is currently on.', 'jpibfi' ),
767
+ )
768
+ );
769
+
770
+ add_settings_field(
771
+ 'transparency_value',
772
+ __( 'Transparency value', 'jpibfi' ),
773
+ 'jpibfi_transparency_value_callback',
774
+ 'jpibfi_visual_options',
775
+ 'visual_options_section',
776
+ array(
777
+ __( 'This setting sets the transparency of the layer covering the image.', 'jpibfi' ),
778
+ )
779
+ );
780
+
781
+ add_settings_field(
782
+ 'custom_pin_it_button',
783
+ __( 'Custom "Pin It" button', 'jpibfi' ),
784
+ 'jpibfi_custom_pin_it_button_callback',
785
+ 'jpibfi_visual_options',
786
+ 'visual_options_section',
787
+ array(
788
+ __( 'Check the <b>Use custom image</b> checkbox, specify image\'s URL, height and width to use your own Pinterest button design. You can just upload an image using Wordpress media library if you wish.', 'jpibfi' ),
789
+ )
790
+ );
791
+
792
+ add_settings_field(
793
+ 'pin_it_button_position',
794
+ __( '"Pin it" button position', 'jpibfi' ),
795
+ 'jpibfi_pin_it_button_position_callback',
796
+ 'jpibfi_visual_options',
797
+ 'visual_options_section',
798
+ array(
799
+ __( 'Where the "Pin it" button should appear on the image.', 'jpibfi' ),
800
+ )
801
+ );
802
+
803
+ register_setting(
804
+ 'jpibfi_visual_options',
805
+ 'jpibfi_visual_options',
806
+ 'jpibfi_sanitize_visual_options'
807
+ );
808
+
809
+ }
810
+
811
+ add_action( 'admin_init', 'jpibfi_initialize_visual_options' );
812
+
813
+ function jpibfi_visual_options_callback() {
814
+ echo '<p>' . __('How it should look like', 'jpibfi') . '</p>';
815
+ }
816
+
817
+ function jpibfi_description_option_callback( $args ) {
818
+ $options = jpibfi_get_visual_options();
819
+
820
+
821
+ $description_option = $options[ 'description_option' ];
822
+ ?>
823
+
824
+ <select id="description_option" name="jpibfi_visual_options[description_option]">
825
+ <option value="1" <?php selected ( "1", $description_option ); ?>><?php _e( 'Page title', 'jpibfi' ); ?></option>
826
+ <option value="2" <?php selected ( "2", $description_option ); ?>><?php _e( 'Page description', 'jpibfi' ); ?></option>
827
+ <option value="3" <?php selected ( "3", $description_option ); ?>><?php _e( 'Picture title or (if title not available) alt attribute', 'jpibfi' ); ?></option>
828
+ <option value="4" <?php selected ( "4", $description_option ); ?>><?php _e( 'Site title (Settings->General)', 'jpibfi' ); ?></option>
829
+ </select>
830
+
831
+ <?php
832
+ echo jpibfi_create_description( $args[0] );
833
+ }
834
+
835
+ function jpibfi_use_post_url_callback( $args ) {
836
+
837
+ $options = jpibfi_get_visual_options();
838
+ $use_post_url = jpibfi_exists_and_equal_to( $options, 'use_post_url', '1' );
839
+
840
+ echo '<input type="checkbox" id="use_post_url" name="jpibfi_visual_options[use_post_url]" value="1" ' . checked( "1", $use_post_url, false ) . '>';
841
+ echo '<label for="use_post_url">' . __( 'Always link to individual post page', 'jpibfi' ) . '</label>';
842
+
843
+ echo jpibfi_create_description( $args[0] );
844
+ }
845
+
846
+ function jpibfi_transparency_value_callback( $args ) {
847
+ $options = jpibfi_get_visual_options();
848
+
849
+ $transparency_value = $options[ 'transparency_value' ];
850
+
851
+ echo '<label for="transparency_value">' . _e('Choose transparency (between 0.00 and 1.00)', 'jpibfi') . '</label><br/>';
852
+ echo '<input type="number" min="0" max="1" step="0.01" id="transparency_value" name="jpibfi_visual_options[transparency_value]"' .
853
+ 'value="' . $transparency_value . '" class="small-text" >';
854
+ echo jpibfi_create_description( $args[0] );
855
+ echo jpibfi_create_errors( 'transparency_value' );
856
+ }
857
+
858
+ function jpibfi_custom_pin_it_button_callback( $args ) {
859
+ $options = jpibfi_get_visual_options();
860
+
861
+ $use_custom_image = jpibfi_exists_and_equal_to( $options, 'use_custom_image', '1' );
862
+ $custom_image_url = $options[ 'custom_image_url' ];
863
+ $custom_image_height = $options[ 'custom_image_height' ];
864
+ $custom_image_width = $options[ 'custom_image_width' ];
865
+
866
+ ?>
867
+ <p>
868
+ <input type="checkbox" id="use_custom_image" name="jpibfi_visual_options[use_custom_image]" value="1" <?php checked( true, $use_custom_image ); ?> >
869
+ <label class="chbox-label" for="use_custom_image"><?php _e( 'Use custom image', 'jpibfi' ); ?></label>
870
+ </p>
871
+
872
+ <button id=upload-image><?php _e( 'Upload an image using media library','jpibfi' ); ?></button><br />
873
+
874
+ <p>
875
+ <label for="custom_image_url"><?php _e( 'URL address of the image', 'jpibfi' ); ?></label>
876
+ <input type="url" id="custom_image_url" name="jpibfi_visual_options[custom_image_url]" value="<?php echo $custom_image_url; ?>">
877
+ </p>
878
+
879
+ <p>
880
+ <label for="custom_image_height"><?php _e( 'Height', 'jpibfi' ); ?></label>
881
+ <input type="number" min="0" step="1" id="custom_image_height" name="jpibfi_visual_options[custom_image_height]" value="<?php echo $custom_image_height; ?>"
882
+ class="small-text" /> px
883
+ <?php echo jpibfi_create_errors( 'custom_image_height' ); ?>
884
+ </p>
885
+
886
+ <p>
887
+ <label for="custom_image_width"><?php _e( 'Width', 'jpibfi' ); ?></label>
888
+ <input type="number" min="0" step="1" id="custom_image_width" name="jpibfi_visual_options[custom_image_width]" value="<?php echo $custom_image_width; ?>"
889
+ class="small-text" /> px
890
+ <?php echo jpibfi_create_errors( 'custom_image_width' ); ?>
891
+ </p>
892
+
893
+ <p>
894
+ <b><?php _e( 'Custom Pin It button preview', 'jpibfi' ); ?></b><br/>
895
+ <span id="custom_button_preview" style="width: <?php echo $custom_image_width; ?>px; height: <?php echo $custom_image_height; ?>px; background-image: url('<?php echo $custom_image_url; ?>');">
896
+ Preview
897
+ </span><br/>
898
+ <button id="refresh_custom_button_preview"><?php _e( 'Refresh preview', 'jpibfi' ); ?></button>
899
+ </p>
900
+
901
+ <?php
902
+
903
+ echo jpibfi_create_description( $args[0] );
904
+ }
905
+
906
+ function jpibfi_pin_it_button_position_callback( $args ) {
907
+ $options = jpibfi_get_visual_options();
908
+
909
+ $jpibfi_button_dropdown = array(
910
+ __( 'Top left (default)', 'jpibfi' ),
911
+ __( 'Top right', 'jpibfi' ),
912
+ __( 'Bottom left', 'jpibfi' ),
913
+ __( 'Bottom right', 'jpibfi' ),
914
+ __( 'Middle', 'jpibfi' ),
915
+ __( 'Custom', 'jpibfi' )
916
+ );
917
+
918
+ $button_position = $options[ 'button_position' ];
919
+ $button_css = $options[ 'button_css' ];
920
+
921
+ ?>
922
+
923
+ <select name="jpibfi_visual_options[button_position]" id="button_position">
924
+ <?php for( $i = 0; $i < count( $jpibfi_button_dropdown ); $i++) { ?>
925
+ <option value="<?php echo $i; ?>" <?php selected( $i, $button_position ); ?>><?php echo $jpibfi_button_dropdown[ $i ]; ?></option>
926
+ <?php } ?>
927
+ </select><br/>
928
+ <textarea id="button_css" rows="5" cols="50" name="jpibfi_visual_options[button_css]"><?php echo $button_css; ?></textarea>
929
+
930
+ <?php
931
+ echo jpibfi_create_description( $args[0] );
932
+ }
933
+
934
+ function jpibfi_sanitize_visual_options( $input ) {
935
+ $jpibfi_button_css = jpibfi_button_css();
936
+
937
+ foreach( $input as $key => $value ) {
938
+
939
+ switch($key) {
940
+ case 'transparency_value':
941
+ if ( !is_numeric( $input[ $key ] ) || ( $input[ $key ] < 0.0 ) || ( $input[ $key ] > 1.0 ) ) {
942
+
943
+ add_settings_error(
944
+ $key,
945
+ esc_attr( 'settings_updated' ),
946
+ __('Transparency value must be a number between 0.0 and 1.0.', 'jpibfi')
947
+ );
948
+ }
949
+ break;
950
+ case 'custom_image_height':
951
+ case 'custom_image_width':
952
+ $name = "";
953
+ if ( 'custom_image_height' == $key )
954
+ $name = __('Custom image height', 'jpibfi' );
955
+ else if ( 'custom_image_width' == $key )
956
+ $name = __('Custom image width', 'jpibfi' );
957
+
958
+ if ( '' != $value && ( !is_numeric( $value ) || $value < 0 ) ) {
959
+ add_settings_error(
960
+ $key,
961
+ esc_attr( 'settings_updated' ),
962
+ $name . __(' must be a number greater or equal to 0.', 'jpibfi')
963
+ );
964
+ }
965
+ break;
966
+ }
967
+ }
968
+
969
+ //if user didn't specify his custom css, we need to save button_css setting as one of the defaults
970
+ if ( '5' != $input[ 'button_position' ] )
971
+ $input[ 'button_css' ] = $jpibfi_button_css[ $input[ 'button_position' ] ];
972
+
973
+ $errors = get_settings_errors();
974
+
975
+ if ( count( $errors ) > 0 ) {
976
+
977
+ update_option( JPIBFI_VISUAL_OPTIONS . '_errors', $input );
978
+ return get_option( JPIBFI_VISUAL_OPTIONS );
979
+
980
+ } else {
981
+
982
+ delete_option( JPIBFI_VISUAL_OPTIONS . '_errors' );
983
+ return $input;
984
+
985
+ }
986
+ }
987
+
988
+ function jpibfi_get_visual_options() {
989
+ return jpibfi_get_options( JPIBFI_VISUAL_OPTIONS );
990
+ }
991
+
992
+ /*
993
+ *
994
+ * UTILITIES
995
+ *
996
+ */
997
+
998
+ /*
999
+ * Function returns properly formatted description of a setting
1000
+ */
1001
+ function jpibfi_create_description( $desc ) {
1002
+ return '<p class="description">' . $desc . '</p>';
1003
+ }
1004
+
1005
+ function jpibfi_create_errors( $setting_name ) {
1006
+ $error = "";
1007
+
1008
+ $errors_array = get_settings_errors( $setting_name );
1009
+
1010
+ if ( count ( $errors_array ) > 0 ) {
1011
+ $error .= '<div class="jpibfi-error-message">';
1012
+ for( $i = 0; $i < count( $errors_array ); $i++ ){
1013
+ $error .= $errors_array[ $i ]['message'] . '</br>';
1014
+ }
1015
+ $error .= '</div>';
1016
+ }
1017
+
1018
+ return $error;
1019
+ }
1020
+
1021
+ /*
1022
+ * writes or returns chosen text depending whether the given condition is true or false
1023
+ */
1024
+ function jpibfi_conditional( $condition, $true_value = "", $false_value = "", $echo = true) {
1025
+ if ( $condition ) {
1026
+ if ( $echo )
1027
+ echo $true_value;
1028
+ return $true_value;
1029
+ }
1030
+ if ( $echo )
1031
+ echo $false_value;
1032
+ return $false_value;
1033
+ }
1034
+
1035
+ function jpibfi_exists_and_equal_to( $array , $name, $expected_value = "1" ) {
1036
+ return isset( $array[ $name ] ) && $array[ $name ] == $expected_value;
1037
+ }
1038
+
1039
+ /*
1040
+ * If there are errors, let's return the array with 'unsaved' data
1041
+ * 'Saved' settings otherwise
1042
+ */
1043
+ function jpibfi_get_options( $name ) {
1044
+ //cumbersome, but works in WP 3.3
1045
+ $options = get_option( $name . '_errors' );
1046
+
1047
+ return false == $options ? get_option( $name ) : $options;
1048
+
1049
+ //the code below is a much better error management solution, but doesn't work in WP 3.3
1050
+ // if ( JPIBFI_SELECTION_OPTIONS == $name )
1051
+ // $settings_list = jpibfi_default_selection_options();
1052
+ // else
1053
+ // $settings_list = jpibfi_default_visual_options();
1054
+ //
1055
+ // $errors = false;
1056
+ //
1057
+ // foreach( $settings_list as $key => $value) {
1058
+ // if ( count( get_settings_errors( $key ) ) > 0 ) {
1059
+ // $errors = true;
1060
+ // break;
1061
+ // }
1062
+ // }
1063
+ // return $errors ? get_option( $name . '_errors' ) : get_option( $name );
1064
+ }
1065
+
1066
+ /*
1067
+ * Function makes sure that option has all needed fields by checking with defaults
1068
+ */
1069
+ function jpibfi_update_option_fields( $option, $default_option, $option_name ) {
1070
+
1071
+ $option_changed = false;
1072
+
1073
+ foreach($default_option as $key => $value) {
1074
+ if ( false == array_key_exists( $key, $option ) ) {
1075
+ $options [ $key ] = $value;
1076
+ $option_changed = true;
1077
+ }
1078
+ }
1079
+
1080
+ if ( $option_changed )
1081
+ update_option( $option_name, $option );
1082
+
1083
+ }
1084
+
1085
+ /*
1086
+ * function converts 0.0..1.0 value to 00..FF
1087
+ */
1088
+ function jpibfi_convert_to_hex( $val ) {
1089
1090
+ $transparencyDec = floatval( $val );
1091
+ $transparencyDec = (int)( $transparencyDec * 255 );
1092
+ $transparencyHex = dechex( (int) $transparencyDec );
1093
+ if ( strlen( $transparencyHex) == 1 )
1094
+ $transparencyHex = "0" . $transparencyHex;
1095
+
1096
+ return $transparencyHex;
1097
+ }
1098
+
1099
+ function jpibfi_is_string_css_class_name( $class_name ) {
1100
+ return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*#x2F;", $class_name );
1101
+ }
1102
+
1103
+ //checks if given string contains class names separated by semicolons or is empty
1104
+ function jpibfi_contains_css_class_names_or_empty( $str ) {
1105
+ if ( 0 == strlen( $str ) )
1106
+ return true;
1107
+
1108
+ $names = explode( ';', $str );
1109
+ $only_class_names = true;
1110
+
1111
+ for( $i = 0; $i < count( $names ) && $only_class_names; $i++ )
1112
+ $only_class_names = jpibfi_is_string_css_class_name( $names [ $i ] );
1113
+
1114
+ return $only_class_names;
1115
+ }
1116
1117
+ function jpibfi_button_css() {
1118
+ $css = array();
1119
+ $css[0] = esc_html( "top:0%;&#10;left:0%;&#10;margin:20px 0 0 20px;" ); //Top left
1120
+ $css[1] = esc_html( "top:0%;&#10;right:0%;&#10;margin:20px 20px 0 0;" ); //Top right
1121
+ $css[2] = esc_html( "bottom:0%;&#10;left:0%;&#10;margin:0 0 20px 20px;" ); //Bottom left
1122
+ $css[3] = esc_html( "bottom:0%;&#10;right:0%;&#10;margin:0 20px 20px 0;" ); //Bottom right
1123
+ $css[4] = esc_html( "top:0;&#10;left:0;&#10;right:0;&#10;bottom:0;&#10;margin:auto;" ); //Middle
1124
+ return $css;
1125
+ }
js/admin.js CHANGED
@@ -4,86 +4,29 @@ jQuery(document).ready(function($) {
4
$('#image_selector').val($(this).text());
5
e.preventDefault();
6
});
7
-
8
- $('#submit_form').click(function(e){
9
- var error = false;
10
-
11
- var areas = ["#disabled_classes", "#enabled_classes"];
12
- for (var i = 0; i < areas.length; i++) {
13
- if ( !contains_css_class_names_or_empty( $(areas[i]).val() ) ) {
14
- $(areas[i]).addClass('error-border');
15
- $(areas[i] + "_error").show();
16
- error = true;
17
- }
18
- else {
19
- $(areas[i]).removeClass('error-border');
20
- $(areas[i] + "_error").hide();
21
- }
22
- }
23
-
24
- var value = parseFloat($('#standard_transparency').val());
25
- var regExp = /^((\d+(\.\d+)?)|(\.\d+))\s*#x2F;;
26
-
27
- if (!regExp.test($('#standard_transparency').val()) || isNaN(value) || value < 0 || value > 1) {
28
- $('#standard_transparency').addClass('error-border');
29
- $("#standard_transparency_error").show();
30
- error = true;
31
- } else {
32
- $('#standard_transparency').removeClass('error-border');
33
- $("#standard_transparency_error").hide();
34
- }
35
-
36
- var number_values = ['#custom_image_width', '#custom_image_height', '#min_image_width', '#min_image_height']
37
- for (var i = 0; i < number_values.length; i++) {
38
- var field = $(number_values[i]);
39
- if ( !contains_number_larger_or_equal_to_zero(field.val()) ) {
40
- field.addClass('error-border');
41
- $(number_values[i] + "_error").show();
42
- error = true;
43
- } else {
44
- field.removeClass('error-border');
45
- $(number_values[i] + "_error").hide();
46
- }
47
- }
48
-
49
- if (error) {
50
- e.preventDefault();
51
- location.hash = "#top_anchor";
52
- }
53
54
});
55
-
56
- $("#custom_button_css").prop('disabled', $('#button_position').val() != "5");
57
58
$('#button_position').change( function() {
59
var buttonPos = $(this).val()
60
- $("#custom_button_css").prop('disabled', buttonPos != "5");
61
if ( buttonPos >= 0 && buttonPos <= 4 )
62
- $('#custom_button_css').html( jpibfi_button_css[buttonPos] );
63
});
64
-
65
- function is_string_css_class_name(class_name) {
66
- var regExp = new RegExp("^-?[_a-zA-Z]+[_a-zA-Z0-9-]*quot;);
67
- return regExp.test(class_name);
68
- }
69
-
70
- function contains_css_class_names_or_empty(str) {
71
- if ( str.length == 0 )
72
- return true;
73
-
74
- var names = str.split(";");
75
- var only_css_class_names = true;
76
-
77
- for (var i = 0; i < names.length; i++ ) {
78
- if ( !is_string_css_class_name(names[i]) ) {
79
- only_css_class_names = false;
80
- break;
81
- }
82
- }
83
- return only_css_class_names;
84
- }
85
-
86
- function contains_number_larger_or_equal_to_zero(value){
87
- return /^(\d+)\s*#x2F;.test(value) && value >= 0;
88
- }
89
});
4
$('#image_selector').val($(this).text());
5
e.preventDefault();
6
});
7
8
+ $("#refresh_custom_button_preview").click( function(e) {
9
+ var customWidth = $('#custom_image_width').val();
10
+ var customHeight = $('#custom_image_height').val();
11
+ var customUrl = $('#custom_image_url').val();
12
+
13
+ $('#custom_button_preview')
14
+ .css(
15
+ {
16
+ width: customWidth,
17
+ height: customHeight,
18
+ "background-image": "url('" + customUrl + "')"
19
+ }
20
+ );
21
+ return false;
22
});
23
+
24
+ $("#button_css").prop('disabled', $('#button_position').val() != "5");
25
26
$('#button_position').change( function() {
27
var buttonPos = $(this).val()
28
+ $("#button_css").prop('disabled', buttonPos != "5");
29
if ( buttonPos >= 0 && buttonPos <= 4 )
30
+ $('#button_css').html( jpibfi_button_css[buttonPos] );
31
});
<