Pinterest "Pin It" Button - Version 2.0.7

Version Description

  • Tested with WordPress 4.0.
  • Button will now pin full size image instead of thumbnail.
Download this release

Release Info

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

Code changes from version 2.0.6 to 2.0.7

assets/icon-128x128.png ADDED
Binary file
assets/icon-256x256.png ADDED
Binary file
assets/icon-external-link.gif DELETED
Binary file
class-pinterest-pin-it-button.php CHANGED
@@ -1,447 +1,461 @@
1
- <?php
2
-
3
- /**
4
- * Main Pinterest_Pin_It_Button class
5
- *
6
- * @package PIB
7
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
- */
9
-
10
- // Exit if accessed directly.
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit;
13
- }
14
-
15
- class Pinterest_Pin_It_Button {
16
-
17
- /**
18
- * Plugin version, used for cache-busting of style and script file references.
19
- *
20
- * @since 2.0.0
21
- *
22
- * @var string
23
- */
24
-
25
- /**************************************
26
- * UPDATE VERSION HERE
27
- * and main plugin file header comments
28
- * and README.txt changelog
29
- **************************************/
30
-
31
- protected $version = '2.0.6';
32
-
33
- /**
34
- * Unique identifier for your plugin.
35
- *
36
- * Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
37
- * match the Text Domain file header in the main plugin file.
38
- *
39
- * @since 2.0.0
40
- *
41
- * @var string
42
- */
43
- protected $plugin_slug = 'pinterest-pin-it-button';
44
-
45
- /**
46
- * Instance of this class.
47
- *
48
- * @since 2.0.0
49
- *
50
- * @var object
51
- */
52
- protected static $instance = null;
53
-
54
- /**
55
- * Slug of the plugin screen.
56
- *
57
- * @since 2.0.0
58
- *
59
- * @var string
60
- */
61
- protected $plugin_screen_hook_suffix = null;
62
-
63
- /**
64
- * Initialize the plugin by setting localization, filters, and administration functions.
65
- *
66
- * @since 2.0.0
67
- */
68
-
69
- /**
70
- * Initialize main plugin functions and add appropriate hooks/filter calls
71
- *
72
- * @since 2.0.0
73
- *
74
- */
75
- private function __construct() {
76
- // Setup constants.
77
- $this->setup_constants();
78
-
79
- // Run our upgrade checks first and update our version option.
80
- if( ! get_option( 'pib_upgrade_has_run' ) ) {
81
- add_action( 'init', array( $this, 'upgrade_plugin' ), 0 );
82
- update_option( 'pib_version', $this->version );
83
- }
84
-
85
- // Include required files.
86
- add_action( 'init', array( $this, 'includes' ), 1 );
87
-
88
- // Add the options page and menu item.
89
- add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 2 );
90
-
91
- // Enqueue admin styles and scripts.
92
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
93
-
94
- // Enqueue public style and scripts.
95
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
96
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
97
-
98
- // Add admin notice after plugin activation. Also check if should be hidden.
99
- add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
100
-
101
- // Add Post Meta stuff.
102
- add_action( 'add_meta_boxes', array( $this, 'display_post_meta') );
103
- add_action( 'save_post', array( $this, 'save_meta_data') );
104
-
105
- // Add plugin listing "Settings" action link.
106
- add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . $this->plugin_slug . '.php' ), array( $this, 'settings_link' ) );
107
-
108
- // Check WP version
109
- add_action( 'admin_init', array( $this, 'check_wp_version' ) );
110
- }
111
-
112
- /**
113
- * Make sure user has the minimum required version of WordPress installed to use the plugin
114
- *
115
- * @since 1.0.0
116
- */
117
- public function check_wp_version() {
118
- global $wp_version;
119
- $required_wp_version = '3.6.1';
120
-
121
- if ( version_compare( $wp_version, $required_wp_version, '<' ) ) {
122
- deactivate_plugins( PIB_MAIN_FILE );
123
- wp_die( sprintf( __( $this->get_plugin_title() . ' requires WordPress version <strong>' . $required_wp_version . '</strong> to run properly. ' .
124
- 'Please update WordPress before reactivating this plugin. <a href="%s">Return to Plugins</a>.', 'pib' ), get_admin_url( '', 'plugins.php' ) ) );
125
- }
126
- }
127
-
128
- /**
129
- * Return an instance of this class.
130
- *
131
- * @since 2.0.0
132
- *
133
- * @return object A single instance of this class.
134
- */
135
- public static function get_instance() {
136
- // If the single instance hasn't been set, set it now.
137
- if ( null == self::$instance ) {
138
- self::$instance = new self;
139
- }
140
-
141
- return self::$instance;
142
- }
143
-
144
- /**
145
- * Setup plugin constants.
146
- *
147
- * @since 2.0.0
148
- */
149
- public function setup_constants() {
150
- // Plugin slug.
151
- if ( ! defined( 'PIB_PLUGIN_SLUG' ) ) {
152
- define( 'PIB_PLUGIN_SLUG', $this->plugin_slug );
153
- }
154
-
155
- // Plugin version.
156
- if ( ! defined( 'PIB_VERSION' ) ) {
157
- define( 'PIB_VERSION', $this->version );
158
- }
159
-
160
- // Plugin title.
161
- if ( ! defined( 'PIB_PLUGIN_TITLE' ) ) {
162
- define( 'PIB_PLUGIN_TITLE', $this->get_plugin_title() );
163
- }
164
-
165
- // Plugin folder URL.
166
- if ( ! defined( 'PIB_PLUGIN_URL' ) ) {
167
- define( 'PIB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
168
- }
169
-
170
- if( ! defined( 'PINPLUGIN_BASE_URL' ) ) {
171
- define( 'PINPLUGIN_BASE_URL', 'http://pinplugins.com/' );
172
- }
173
- }
174
-
175
- /**
176
- * Fired when the plugin is activated.
177
- *
178
- * @since 2.0.0
179
- */
180
- public static function activate() {
181
- update_option( 'pib_show_admin_install_notice', 1 );
182
- }
183
-
184
- /**
185
- * Run upgrade plugin process.
186
- *
187
- * @since 2.0.0
188
- */
189
- public function upgrade_plugin() {
190
- include_once( 'includes/upgrade-plugin.php' );
191
- }
192
-
193
- /**
194
- * Include required files (admin and frontend).
195
- *
196
- * @since 2.0.0
197
- */
198
- public function includes() {
199
- // Load global options.
200
- global $pib_options;
201
-
202
- // Include the file to register all of the plugin settings.
203
- include_once( 'includes/register-settings.php' );
204
-
205
- // Load global options settings.
206
- $pib_options = pib_get_settings();
207
-
208
- // Include widgets file if on widgets admin or public.
209
- include_once( dirname( __FILE__ ) . '/includes/widgets.php' );
210
-
211
- // Other common includes.
212
- include_once( 'includes/misc-functions.php' );
213
-
214
- // Admin-only includes.
215
- if ( is_admin() ) {
216
- include_once( 'includes/admin-notices.php' );
217
- } else {
218
- // Frontend-only includes.
219
- include_once( 'includes/shortcodes.php' );
220
- include_once( 'views/public.php' );
221
- }
222
- }
223
-
224
- /**
225
- * Return localized base plugin title.
226
- *
227
- * @since 2.0.0
228
- *
229
- * @return string
230
- */
231
- public static function get_plugin_title() {
232
- return __( 'Pinterest "Pin It" Button Lite', 'pib' );
233
- }
234
-
235
- /**
236
- * Enqueue admin-specific style sheets for this plugin's admin pages only.
237
- *
238
- * @since 2.0.0
239
- *
240
- * @return null Return early if no settings page is registered.
241
- */
242
- public function enqueue_admin_styles() {
243
-
244
- if ( $this->viewing_this_plugin() ) {
245
- // Plugin admin CSS. Tack on plugin version.
246
- wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version );
247
- }
248
- }
249
-
250
- /**
251
- * Enqueue public-facing style sheets.
252
- *
253
- * @since 2.0.0
254
- */
255
- public function enqueue_styles() {
256
- global $pib_options;
257
-
258
- if( ! in_array( 'no_buttons', pib_render_button() ) ) {
259
- // Check to see if setting to disable is true first.
260
- if ( empty( $pib_options['disable_css'] ) ) {
261
- wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'css/public.css', __FILE__ ), array(), $this->version );
262
- }
263
- }
264
-
265
- }
266
-
267
- /**
268
- * Enqueues public-facing script files.
269
- *
270
- * @since 2.0.0
271
- */
272
- public function enqueue_scripts() {
273
- global $pib_options;
274
-
275
- if( ! in_array( 'no_buttons', pib_render_button() ) ) {
276
- // If this option is empty then it means we can load the pinit.js, otherwise do not load it
277
- if( empty( $pib_options['no_pinit_js'] ) ) {
278
- // Enqueue Pinterest JS plugin boilerplate style. Don't tack on plugin version.
279
- // We DO NOT include the plugin slug here. This is so that this can be uniform across all of our plugins
280
- wp_enqueue_script( 'pinterest-pinit-js', '//assets.pinterest.com/js/pinit.js', array(), null, true );
281
- }
282
- }
283
- }
284
-
285
- /**
286
- * Register the administration menu for this plugin into the WordPress Dashboard menu.
287
- *
288
- * @since 2.0.0
289
- */
290
- public function add_plugin_admin_menu() {
291
- // Add main menu item
292
- $this->plugin_screen_hook_suffix[] = add_menu_page(
293
- $this->get_plugin_title() . __( ' Settings', 'pib' ),
294
- __( 'Pin It Button', 'pib' ),
295
- 'manage_options',
296
- $this->plugin_slug,
297
- array( $this, 'display_plugin_admin_page' ),
298
- plugins_url( 'assets/pinterest-icon-16.png', __FILE__ )
299
- );
300
-
301
- // Add Help submenu page
302
- $this->plugin_screen_hook_suffix[] = add_submenu_page(
303
- $this->plugin_slug,
304
- $this->get_plugin_title() . __( ' Help', 'pib' ),
305
- __( 'Help', 'pib' ),
306
- 'manage_options',
307
- $this->plugin_slug . '_help',
308
- array( $this, 'display_admin_help_page' )
309
- );
310
- }
311
-
312
- /**
313
- * Render the admin pages for this plugin.
314
- *
315
- * @since 2.0.0
316
- */
317
- public function display_plugin_admin_page() {
318
- include_once( 'views/admin.php' );
319
- }
320
-
321
- public function display_admin_help_page() {
322
- include_once( 'views/admin-help.php' );
323
- }
324
-
325
- /**
326
- * Render the post meta for this plugin.
327
- *
328
- * @since 2.0.0
329
- */
330
- public function display_post_meta() {
331
- // Add the meta boxes for both posts and pages
332
- add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'post', 'advanced', 'high');
333
- add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'page', 'advanced', 'high');
334
-
335
- // function to output the HTML for meta box
336
- function add_meta_form( $post ) {
337
-
338
- wp_nonce_field( basename( __FILE__ ), 'pib_meta_nonce' );
339
-
340
- include_once( 'views/post-meta-display.php' );
341
- }
342
- }
343
-
344
- /**
345
- * Save the post meta for this plugin.
346
- *
347
- * @since 2.0.0
348
- *
349
- * @param int $post_id
350
- * @return int $post_id
351
- */
352
- public function save_meta_data( $post_id ) {
353
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
354
- return $post_id;
355
-
356
- // An array to hold all of our post meta ids so we can run them through a loop
357
- $post_meta_fields = array(
358
- 'pib_url_of_webpage',
359
- 'pib_url_of_img',
360
- 'pib_description'
361
- );
362
-
363
- $post_meta_fields = apply_filters( 'pib_post_meta_fields', $post_meta_fields );
364
-
365
- // Record sharing disable
366
-
367
- if ( current_user_can( 'edit_post', $post_id ) ) {
368
- if ( isset( $_POST['pib_sharing_status_hidden'] ) ) {
369
- if ( !isset( $_POST['pib_enable_post_sharing'] ) ) {
370
- update_post_meta( $post_id, 'pib_sharing_disabled', 1 );
371
- }
372
- else {
373
- delete_post_meta( $post_id, 'pib_sharing_disabled' );
374
- }
375
-
376
- // Loop through our array and make sure it is posted and not empty in order to update it, otherwise we delete it
377
- foreach ( $post_meta_fields as $pmf ) {
378
- if ( isset( $_POST[$pmf] ) && !empty( $_POST[$pmf] ) ) {
379
- update_post_meta( $post_id, $pmf, sanitize_text_field( stripslashes( $_POST[$pmf] ) ) );
380
- } else {
381
- delete_post_meta( $post_id, $pmf );
382
- }
383
- }
384
- }
385
- }
386
-
387
-
388
- return $post_id;
389
- }
390
-
391
- /**
392
- * Add Settings action link to left of existing action links on plugin listing page.
393
- *
394
- * @since 2.0.0
395
- *
396
- * @param array $links Default plugin action links.
397
- * @return array $links Amended plugin action links.
398
- */
399
- public function settings_link( $links ) {
400
- $setting_link = sprintf( '<a href="%s">%s</a>', add_query_arg( 'page', $this->plugin_slug, admin_url( 'admin.php' ) ), __( 'Settings', 'pib' ) );
401
- array_unshift( $links, $setting_link );
402
-
403
- return $links;
404
- }
405
-
406
- /**
407
- * Check if viewing one of this plugin's admin pages.
408
- *
409
- * @since 2.0.0
410
- *
411
- * @return bool
412
- */
413
- private function viewing_this_plugin() {
414
- if ( ! isset( $this->plugin_screen_hook_suffix ) )
415
- return false;
416
-
417
- $screen = get_current_screen();
418
-
419
- if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) )
420
- return true;
421
- else
422
- return false;
423
- }
424
-
425
- /**
426
- * Show notice after plugin install/activate in admin dashboard until user acknowledges.
427
- * Also check if user chooses to hide it.
428
- *
429
- * @since 2.0.0
430
- */
431
- public function admin_install_notice() {
432
- // Exit all of this is stored value is false/0 or not set.
433
- if ( false == get_option( 'pib_show_admin_install_notice' ) )
434
- return;
435
-
436
- // Delete stored value if "hide" button click detected (custom querystring value set to 1).
437
- // or if on a PIB admin page. Then exit.
438
- if ( ! empty( $_REQUEST['pib-dismiss-install-nag'] ) || $this->viewing_this_plugin() ) {
439
- delete_option( 'pib_show_admin_install_notice' );
440
- return;
441
- }
442
-
443
- // At this point show install notice. Show it only on the plugin screen.
444
- if( get_current_screen()->id == 'plugins' )
445
- include_once( 'views/admin-install-notice.php' );
446
- }
447
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Main Pinterest_Pin_It_Button class
5
+ *
6
+ * @package PIB
7
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
+ */
9
+
10
+ // Exit if accessed directly.
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ class Pinterest_Pin_It_Button {
16
+
17
+ /**
18
+ * Plugin version, used for cache-busting of style and script file references.
19
+ *
20
+ * @since 2.0.0
21
+ *
22
+ * @var string
23
+ */
24
+
25
+ /**************************************
26
+ * UPDATE VERSION HERE
27
+ * and main plugin file header comments
28
+ * and README.txt changelog
29
+ **************************************/
30
+
31
+ protected $version = '2.0.7';
32
+
33
+ /**
34
+ * Unique identifier for your plugin.
35
+ *
36
+ * Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
37
+ * match the Text Domain file header in the main plugin file.
38
+ *
39
+ * @since 2.0.0
40
+ *
41
+ * @var string
42
+ */
43
+ protected $plugin_slug = 'pinterest-pin-it-button';
44
+
45
+ /**
46
+ * Instance of this class.
47
+ *
48
+ * @since 2.0.0
49
+ *
50
+ * @var object
51
+ */
52
+ protected static $instance = null;
53
+
54
+ /**
55
+ * Slug of the plugin screen.
56
+ *
57
+ * @since 2.0.0
58
+ *
59
+ * @var string
60
+ */
61
+ protected $plugin_screen_hook_suffix = null;
62
+
63
+ /**
64
+ * Initialize the plugin by setting localization, filters, and administration functions.
65
+ *
66
+ * @since 2.0.0
67
+ */
68
+
69
+ /**
70
+ * Initialize main plugin functions and add appropriate hooks/filter calls
71
+ *
72
+ * @since 2.0.0
73
+ *
74
+ */
75
+ private function __construct() {
76
+ // Setup constants.
77
+ $this->setup_constants();
78
+
79
+ // Run our upgrade checks first and update our version option.
80
+ if( ! get_option( 'pib_upgrade_has_run' ) ) {
81
+ add_action( 'init', array( $this, 'upgrade_plugin' ), 0 );
82
+ update_option( 'pib_version', $this->version );
83
+ }
84
+
85
+ // Include required files.
86
+ add_action( 'init', array( $this, 'includes' ), 1 );
87
+
88
+ // Add the options page and menu item.
89
+ add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 2 );
90
+
91
+ // Enqueue admin styles and scripts.
92
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
93
+
94
+ // Enqueue public style and scripts.
95
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
96
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
97
+
98
+ // Add admin notice after plugin activation. Also check if should be hidden.
99
+ add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
100
+
101
+ // Add Post Meta stuff.
102
+ add_action( 'add_meta_boxes', array( $this, 'display_post_meta') );
103
+ add_action( 'save_post', array( $this, 'save_meta_data') );
104
+
105
+ // Add plugin listing "Settings" action link.
106
+ add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . $this->plugin_slug . '.php' ), array( $this, 'settings_link' ) );
107
+
108
+ // Check WP version
109
+ add_action( 'admin_init', array( $this, 'check_wp_version' ) );
110
+ }
111
+
112
+ /**
113
+ * Make sure user has the minimum required version of WordPress installed to use the plugin
114
+ *
115
+ * @since 1.0.0
116
+ */
117
+ public function check_wp_version() {
118
+ global $wp_version;
119
+ $required_wp_version = '3.6.1';
120
+
121
+ if ( version_compare( $wp_version, $required_wp_version, '<' ) ) {
122
+ deactivate_plugins( PIB_MAIN_FILE );
123
+ wp_die( sprintf( __( $this->get_plugin_title() . ' requires WordPress version <strong>' . $required_wp_version . '</strong> to run properly. ' .
124
+ 'Please update WordPress before reactivating this plugin. <a href="%s">Return to Plugins</a>.', 'pib' ), get_admin_url( '', 'plugins.php' ) ) );
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Return an instance of this class.
130
+ *
131
+ * @since 2.0.0
132
+ *
133
+ * @return object A single instance of this class.
134
+ */
135
+ public static function get_instance() {
136
+ // If the single instance hasn't been set, set it now.
137
+ if ( null == self::$instance ) {
138
+ self::$instance = new self;
139
+ }
140
+
141
+ return self::$instance;
142
+ }
143
+
144
+ /**
145
+ * Setup plugin constants.
146
+ *
147
+ * @since 2.0.0
148
+ */
149
+ public function setup_constants() {
150
+ // Plugin slug.
151
+ if ( ! defined( 'PIB_PLUGIN_SLUG' ) ) {
152
+ define( 'PIB_PLUGIN_SLUG', $this->plugin_slug );
153
+ }
154
+
155
+ // Plugin version.
156
+ if ( ! defined( 'PIB_VERSION' ) ) {
157
+ define( 'PIB_VERSION', $this->version );
158
+ }
159
+
160
+ // Plugin title.
161
+ if ( ! defined( 'PIB_PLUGIN_TITLE' ) ) {
162
+ define( 'PIB_PLUGIN_TITLE', $this->get_plugin_title() );
163
+ }
164
+
165
+ // Plugin folder URL.
166
+ if ( ! defined( 'PIB_PLUGIN_URL' ) ) {
167
+ define( 'PIB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
168
+ }
169
+
170
+ if( ! defined( 'PINPLUGIN_BASE_URL' ) ) {
171
+ define( 'PINPLUGIN_BASE_URL', 'http://pinplugins.com/' );
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Fired when the plugin is activated.
177
+ *
178
+ * @since 2.0.0
179
+ */
180
+ public static function activate() {
181
+ update_option( 'pib_show_admin_install_notice', 1 );
182
+ }
183
+
184
+ /**
185
+ * Run upgrade plugin process.
186
+ *
187
+ * @since 2.0.0
188
+ */
189
+ public function upgrade_plugin() {
190
+ include_once( 'includes/upgrade-plugin.php' );
191
+ }
192
+
193
+ /**
194
+ * Include required files (admin and frontend).
195
+ *
196
+ * @since 2.0.0
197
+ */
198
+ public function includes() {
199
+ // Load global options.
200
+ global $pib_options;
201
+
202
+ // Include the file to register all of the plugin settings.
203
+ include_once( 'includes/register-settings.php' );
204
+
205
+ // Include simplehtmldom
206
+ if( ! class_exists( 'simple_html_dom_node' ) ) {
207
+ include_once( 'includes/simple_html_dom.php' );
208
+ }
209
+
210
+ // Load global options settings.
211
+ $pib_options = pib_get_settings();
212
+
213
+ // Include widgets file if on widgets admin or public.
214
+ include_once( dirname( __FILE__ ) . '/includes/widgets.php' );
215
+
216
+ // Other common includes.
217
+ include_once( 'includes/misc-functions.php' );
218
+
219
+ // Admin-only includes.
220
+ if ( is_admin() ) {
221
+ include_once( 'includes/admin-notices.php' );
222
+ } else {
223
+ // Frontend-only includes.
224
+ include_once( 'includes/shortcodes.php' );
225
+ include_once( 'views/public.php' );
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Return localized base plugin title.
231
+ *
232
+ * @since 2.0.0
233
+ *
234
+ * @return string
235
+ */
236
+ public static function get_plugin_title() {
237
+ return __( 'Pinterest "Pin It" Button Lite', 'pib' );
238
+ }
239
+
240
+ /**
241
+ * Enqueue admin-specific style sheets for this plugin's admin pages only.
242
+ *
243
+ * @since 2.0.0
244
+ *
245
+ * @return null Return early if no settings page is registered.
246
+ */
247
+ public function enqueue_admin_styles() {
248
+
249
+ if ( $this->viewing_this_plugin() ) {
250
+ // Plugin admin CSS. Tack on plugin version.
251
+ wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version );
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Enqueue public-facing style sheets.
257
+ *
258
+ * @since 2.0.0
259
+ */
260
+ public function enqueue_styles() {
261
+ global $pib_options;
262
+
263
+ if( ! in_array( 'no_buttons', pib_render_button() ) ) {
264
+ // Check to see if setting to disable is true first.
265
+ if ( empty( $pib_options['disable_css'] ) ) {
266
+ wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'css/public.css', __FILE__ ), array(), $this->version );
267
+ }
268
+ }
269
+
270
+ }
271
+
272
+ /**
273
+ * Enqueues public-facing script files.
274
+ *
275
+ * @since 2.0.0
276
+ */
277
+ public function enqueue_scripts() {
278
+ global $pib_options;
279
+
280
+ if( ! in_array( 'no_buttons', pib_render_button() ) ) {
281
+ // If this option is empty then it means we can load the pinit.js, otherwise do not load it
282
+ if( empty( $pib_options['no_pinit_js'] ) ) {
283
+ // Enqueue Pinterest JS plugin boilerplate style. Don't tack on plugin version.
284
+ // We DO NOT include the plugin slug here. This is so that this can be uniform across all of our plugins
285
+ wp_enqueue_script( 'pinterest-pinit-js', '//assets.pinterest.com/js/pinit.js', array(), null, true );
286
+ }
287
+ }
288
+ }
289
+
290
+ /**
291
+ * Register the administration menu for this plugin into the WordPress Dashboard menu.
292
+ *
293
+ * @since 2.0.0
294
+ */
295
+ public function add_plugin_admin_menu() {
296
+ // Add main menu item
297
+ $this->plugin_screen_hook_suffix[] = add_menu_page(
298
+ $this->get_plugin_title() . ' ' . __( 'Settings', 'pib' ),
299
+ __( 'Pin It Button', 'pib' ),
300
+ 'manage_options',
301
+ $this->plugin_slug,
302
+ array( $this, 'display_plugin_admin_page' ),
303
+ plugins_url( 'assets/pinterest-icon-16.png', __FILE__ )
304
+ );
305
+
306
+ $this->plugin_screen_hook_suffix[] = add_submenu_page(
307
+ $this->plugin_slug,
308
+ $this->get_plugin_title() . ' ' . __( 'Settings', 'pib' ),
309
+ __( 'Settings', 'pib' ),
310
+ 'manage_options',
311
+ $this->plugin_slug,
312
+ array( $this, 'display_plugin_admin_page' )
313
+ );
314
+
315
+ // Add Help submenu page
316
+ $this->plugin_screen_hook_suffix[] = add_submenu_page(
317
+ $this->plugin_slug,
318
+ $this->get_plugin_title() . __( ' Help', 'pib' ),
319
+ __( 'Help', 'pib' ),
320
+ 'manage_options',
321
+ $this->plugin_slug . '_help',
322
+ array( $this, 'display_admin_help_page' )
323
+ );
324
+ }
325
+
326
+ /**
327
+ * Render the admin pages for this plugin.
328
+ *
329
+ * @since 2.0.0
330
+ */
331
+ public function display_plugin_admin_page() {
332
+ include_once( 'views/admin.php' );
333
+ }
334
+
335
+ public function display_admin_help_page() {
336
+ include_once( 'views/admin-help.php' );
337
+ }
338
+
339
+ /**
340
+ * Render the post meta for this plugin.
341
+ *
342
+ * @since 2.0.0
343
+ */
344
+ public function display_post_meta() {
345
+ // Add the meta boxes for both posts and pages
346
+ add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'post', 'advanced', 'high');
347
+ add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'page', 'advanced', 'high');
348
+
349
+ // function to output the HTML for meta box
350
+ function add_meta_form( $post ) {
351
+
352
+ wp_nonce_field( basename( __FILE__ ), 'pib_meta_nonce' );
353
+
354
+ include_once( 'views/post-meta-display.php' );
355
+ }
356
+ }
357
+
358
+ /**
359
+ * Save the post meta for this plugin.
360
+ *
361
+ * @since 2.0.0
362
+ *
363
+ * @param int $post_id
364
+ * @return int $post_id
365
+ */
366
+ public function save_meta_data( $post_id ) {
367
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
368
+ return $post_id;
369
+
370
+ // An array to hold all of our post meta ids so we can run them through a loop
371
+ $post_meta_fields = array(
372
+ 'pib_url_of_webpage',
373
+ 'pib_url_of_img',
374
+ 'pib_description'
375
+ );
376
+
377
+ $post_meta_fields = apply_filters( 'pib_post_meta_fields', $post_meta_fields );
378
+
379
+ // Record sharing disable
380
+
381
+ if ( current_user_can( 'edit_post', $post_id ) ) {
382
+ if ( isset( $_POST['pib_sharing_status_hidden'] ) ) {
383
+ if ( !isset( $_POST['pib_enable_post_sharing'] ) ) {
384
+ update_post_meta( $post_id, 'pib_sharing_disabled', 1 );
385
+ }
386
+ else {
387
+ delete_post_meta( $post_id, 'pib_sharing_disabled' );
388
+ }
389
+
390
+ // Loop through our array and make sure it is posted and not empty in order to update it, otherwise we delete it
391
+ foreach ( $post_meta_fields as $pmf ) {
392
+ if ( isset( $_POST[$pmf] ) && !empty( $_POST[$pmf] ) ) {
393
+ update_post_meta( $post_id, $pmf, sanitize_text_field( stripslashes( $_POST[$pmf] ) ) );
394
+ } else {
395
+ delete_post_meta( $post_id, $pmf );
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+
402
+ return $post_id;
403
+ }
404
+
405
+ /**
406
+ * Add Settings action link to left of existing action links on plugin listing page.
407
+ *
408
+ * @since 2.0.0
409
+ *
410
+ * @param array $links Default plugin action links.
411
+ * @return array $links Amended plugin action links.
412
+ */
413
+ public function settings_link( $links ) {
414
+ $setting_link = sprintf( '<a href="%s">%s</a>', add_query_arg( 'page', $this->plugin_slug, admin_url( 'admin.php' ) ), __( 'Settings', 'pib' ) );
415
+ array_unshift( $links, $setting_link );
416
+
417
+ return $links;
418
+ }
419
+
420
+ /**
421
+ * Check if viewing one of this plugin's admin pages.
422
+ *
423
+ * @since 2.0.0
424
+ *
425
+ * @return bool
426
+ */
427
+ private function viewing_this_plugin() {
428
+ if ( ! isset( $this->plugin_screen_hook_suffix ) )
429
+ return false;
430
+
431
+ $screen = get_current_screen();
432
+
433
+ if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) )
434
+ return true;
435
+ else
436
+ return false;
437
+ }
438
+
439
+ /**
440
+ * Show notice after plugin install/activate in admin dashboard until user acknowledges.
441
+ * Also check if user chooses to hide it.
442
+ *
443
+ * @since 2.0.0
444
+ */
445
+ public function admin_install_notice() {
446
+ // Exit all of this is stored value is false/0 or not set.
447
+ if ( false == get_option( 'pib_show_admin_install_notice' ) )
448
+ return;
449
+
450
+ // Delete stored value if "hide" button click detected (custom querystring value set to 1).
451
+ // or if on a PIB admin page. Then exit.
452
+ if ( ! empty( $_REQUEST['pib-dismiss-install-nag'] ) || $this->viewing_this_plugin() ) {
453
+ delete_option( 'pib_show_admin_install_notice' );
454
+ return;
455
+ }
456
+
457
+ // At this point show install notice. Show it only on the plugin screen.
458
+ if( get_current_screen()->id == 'plugins' )
459
+ include_once( 'views/admin-install-notice.php' );
460
+ }
461
+ }
css/admin.css CHANGED
@@ -1,57 +1,48 @@
1
- /* This stylesheet is used to style the admin option form of the plugin. */
2
-
3
- #icon-pinterest-32 {
4
- background: transparent url('../assets/pinterest-icon-32.png') no-repeat;
5
- }
6
-
7
- /* This icon is taken from the Flat Social Media Icons from Designmodo at
8
- * http://designmodo.com/flat-social-icons/
9
- */
10
- a.pib-external-link {
11
- background: transparent url('../assets/icon-external-link.gif') center right no-repeat;
12
- padding-right: 17px;
13
- }
14
-
15
- /* Layout the page similar to the built-in post edit screen. */
16
- #pib-settings {
17
- margin-right: 310px;
18
- }
19
-
20
- #pib-settings-content {
21
- width: 100%;
22
- float: left;
23
- }
24
-
25
- #pib-settings-sidebar {
26
- float: right;
27
- margin-top: 9px;
28
- margin-right: -310px;
29
- width: 290px;
30
- }
31
-
32
- #pib-settings-sidebar .centered {
33
- text-align: center;
34
- }
35
-
36
- #pib-settings-sidebar .button-large {
37
- font-size: 17px;
38
- line-height: 30px;
39
- height: 32px;
40
- }
41
-
42
- #pib-settings-sidebar .last-blurb {
43
- font-size: 17px;
44
- }
45
-
46
- /* postbox overrides */
47
- #pib-settings-sidebar .sidebar-container .postbox .inside,
48
- #pib-settings-sidebar .sidebar-container .postbox .inside ul {
49
- margin-bottom: 0;
50
- }
51
-
52
- /* Admin pages styles */
53
- .pib-checkbox-label, .pib-radio-label {
54
- line-height: 1.4em;
55
- margin: .25em 0 .5em!important;
56
- display: block;
57
- }
1
+ /* This stylesheet is used to style the admin option form of the plugin. */
2
+
3
+ #icon-pinterest-32 {
4
+ background: transparent url('../assets/pinterest-icon-32.png') no-repeat;
5
+ }
6
+
7
+ /* Layout the page similar to the built-in post edit screen. */
8
+ #pib-settings {
9
+ margin-right: 310px;
10
+ }
11
+
12
+ #pib-settings-content {
13
+ width: 100%;
14
+ float: left;
15
+ }
16
+
17
+ #pib-settings-sidebar {
18
+ float: right;
19
+ margin-right: -310px;
20
+ width: 290px;
21
+ }
22
+
23
+ #pib-settings-sidebar .centered {
24
+ text-align: center;
25
+ }
26
+
27
+ #pib-settings-sidebar .button-large {
28
+ font-size: 17px;
29
+ line-height: 30px;
30
+ height: 32px;
31
+ }
32
+
33
+ #pib-settings-sidebar .last-blurb {
34
+ font-size: 17px;
35
+ }
36
+
37
+ /* postbox overrides */
38
+ #pib-settings-sidebar .sidebar-container .postbox .inside,
39
+ #pib-settings-sidebar .sidebar-container .postbox .inside ul {
40
+ margin-bottom: 0;
41
+ }
42
+
43
+ /* Admin pages styles */
44
+ .pib-checkbox-label,
45
+ .pib-radio-label {
46
+ margin: .25em 0 .5em !important;
47
+ display: block;
48
+ }
 
 
 
 
 
 
 
 
 
css/public.css CHANGED
@@ -1,58 +1,58 @@
1
- /* This stylesheet is used to style the public view of the plugin. */
2
-
3
- /* Pinterest "Pin It" Button Public CSS */
4
-
5
- /* Styles for the Pin It Button wrapper DIV */
6
- div.pin-it-btn-wrapper,
7
- div.pin-it-btn-wrapper-shortcode,
8
- div.pin-it-btn-wrapper-widget {
9
- }
10
-
11
- div.pin-it-btn-wrapper {
12
- padding-bottom: 10px;
13
- position: relative;
14
- clear: both;
15
- }
16
-
17
- div.pin-it-btn-wrapper a,
18
- div.pin-it-btn-wrapper a:hover,
19
- div.pin-it-btn-wrapper-shortcode a,
20
- div.pin-it-btn-wrapper-shortcode a:hover,
21
- div.pin-it-btn-wrapper-widget a,
22
- div.pin-it-btn-wrapper-widget a:hover {
23
- background: none;
24
- border: 0;
25
- text-decoration: none;
26
- width: auto;
27
- margin: 0;
28
- max-width: none;
29
- padding: 0;
30
- -webkit-box-shadow: 0 0 0;
31
- box-shadow: 0 0 0;
32
- -webkit-border-radius: 0;
33
- border-radius: 0;
34
- }
35
-
36
- /* Latest "clearfix" utility class from Bootstrap 3 */
37
- .pib-clearfix:before,
38
- .pib-clearfix:after {
39
- display: table;
40
- content: " ";
41
- }
42
-
43
- .pib-clearfix:after {
44
- clear: both;
45
- }
46
-
47
- /* Align left/right/center options */
48
- .pib-align-left {
49
- text-align: left;
50
- }
51
-
52
- .pib-align-right {
53
- text-align: right;
54
- }
55
-
56
- .pib-align-center {
57
- text-align: center;
58
- }
1
+ /* This stylesheet is used to style the public view of the plugin. */
2
+
3
+ /* Pinterest "Pin It" Button Public CSS */
4
+
5
+ /* Styles for the Pin It Button wrapper DIV */
6
+ div.pin-it-btn-wrapper,
7
+ div.pin-it-btn-wrapper-shortcode,
8
+ div.pin-it-btn-wrapper-widget {
9
+ }
10
+
11
+ div.pin-it-btn-wrapper {
12
+ padding-bottom: 10px;
13
+ position: relative;
14
+ clear: both;
15
+ }
16
+
17
+ div.pin-it-btn-wrapper a,
18
+ div.pin-it-btn-wrapper a:hover,
19
+ div.pin-it-btn-wrapper-shortcode a,
20
+ div.pin-it-btn-wrapper-shortcode a:hover,
21
+ div.pin-it-btn-wrapper-widget a,
22
+ div.pin-it-btn-wrapper-widget a:hover {
23
+ background: none;
24
+ border: 0;
25
+ text-decoration: none;
26
+ width: auto;
27
+ margin: 0;
28
+ max-width: none;
29
+ padding: 0;
30
+ -webkit-box-shadow: 0 0 0;
31
+ box-shadow: 0 0 0;
32
+ -webkit-border-radius: 0;
33
+ border-radius: 0;
34
+ }
35
+
36
+ /* Latest "clearfix" utility class from Bootstrap 3 */
37
+ .pib-clearfix:before,
38
+ .pib-clearfix:after {
39
+ display: table;
40
+ content: " ";
41
+ }
42
+
43
+ .pib-clearfix:after {
44
+ clear: both;
45
+ }
46
+
47
+ /* Align left/right/center options */
48
+ .pib-align-left {
49
+ text-align: left;
50
+ }
51
+
52
+ .pib-align-right {
53
+ text-align: right;
54
+ }
55
+
56
+ .pib-align-center {
57
+ text-align: center;
58
+ }
includes/admin-notices.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
-
3
- /**
4
- * Admin settings page update notices.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- /**
17
- * Register admin notices that are used when plugin settings are saved
18
- *
19
- * @since 2.0.0
20
- */
21
- function pib_register_admin_notices() {
22
-
23
- global $pib_vars;
24
-
25
- // The first check will show message if general tab is updated. The additional check is if the plugin page is first clicked on and the 'tab' has not been set yet.
26
- $is_pib_settings_page = strpos( ( isset( $_GET['page'] ) ? $_GET['page'] : '' ), 'pinterest-pin-it-button' );
27
-
28
- if ( ( isset( $_GET['tab'] ) && 'general' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] )
29
- || ( !isset( $_GET['tab'] ) && $is_pib_settings_page !== false && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) ) {
30
- add_settings_error( 'pib-notices', 'pib-general-updated', __( 'General settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
31
- }
32
-
33
- if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'post_visibility' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
34
- add_settings_error( 'pib-notices', 'pib-post_visibility-updated', __( 'Post Visibility settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
35
- }
36
-
37
- if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'styles' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
38
- add_settings_error( 'pib-notices', 'pib-styles-updated', __( 'Styles settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
39
- }
40
-
41
- if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'advanced' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
42
- add_settings_error( 'pib-notices', 'pib-advanced-updated', __( 'Advanced settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
43
- }
44
-
45
- settings_errors( 'pib-notices' );
46
- }
47
-
48
- add_action( 'admin_notices', 'pib_register_admin_notices' );
1
+ <?php
2
+
3
+ /**
4
+ * Admin settings page update notices.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Register admin notices that are used when plugin settings are saved
18
+ *
19
+ * @since 2.0.0
20
+ */
21
+ function pib_register_admin_notices() {
22
+
23
+ global $pib_vars;
24
+
25
+ // The first check will show message if general tab is updated. The additional check is if the plugin page is first clicked on and the 'tab' has not been set yet.
26
+ $is_pib_settings_page = strpos( ( isset( $_GET['page'] ) ? $_GET['page'] : '' ), 'pinterest-pin-it-button' );
27
+
28
+ if ( ( isset( $_GET['tab'] ) && 'general' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] )
29
+ || ( !isset( $_GET['tab'] ) && $is_pib_settings_page !== false && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) ) {
30
+ add_settings_error( 'pib-notices', 'pib-general-updated', __( 'General settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
31
+ }
32
+
33
+ if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'post_visibility' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
34
+ add_settings_error( 'pib-notices', 'pib-post_visibility-updated', __( 'Post Visibility settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
35
+ }
36
+
37
+ if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'styles' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
38
+ add_settings_error( 'pib-notices', 'pib-styles-updated', __( 'Styles settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
39
+ }
40
+
41
+ if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'advanced' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
42
+ add_settings_error( 'pib-notices', 'pib-advanced-updated', __( 'Advanced settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
43
+ }
44
+
45
+ settings_errors( 'pib-notices' );
46
+ }
47
+
48
+ add_action( 'admin_notices', 'pib_register_admin_notices' );
includes/hooks-examples.php CHANGED
@@ -1,112 +1,112 @@
1
- <?php
2
-
3
- /*************************
4
- * FILTER HOOKS
5
- ************************/
6
-
7
- // Exit if accessed directly.
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit;
10
- }
11
-
12
- /**
13
- * Modifies the HTML output of the shortcode button
14
- *
15
- * @since 2.0.3
16
- */
17
- function test_pib_shortcode_html( $html ) {
18
- return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
19
- }
20
- //add_filter( 'pib_shortcode_html', 'test_pib_shortcode_html' );
21
-
22
-
23
- /**
24
- * Used to modify the widget HTML
25
- *
26
- * @since 2.0.3
27
- */
28
- function test_pib_widget_html( $html ) {
29
- return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
30
- }
31
- //add_filter( 'pib_widget_html', 'test_pib_widget_html' );
32
-
33
-
34
- /**
35
- * Used to modify the regular button HTML
36
- *
37
- * @since 2.0.3
38
- */
39
- function test_pib_button_html( $html ) {
40
- return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
41
- }
42
- //add_filter( 'pib_button_html', 'test_pib_button_html' );
43
-
44
-
45
- /**
46
- * Outputs additional HTML before the PIB shortcode
47
- *
48
- * @since 2.0.3
49
- */
50
- function test_pib_shortcode_before( $before_html ) {
51
- return $before_html . '<p>Before</p>';
52
- }
53
- //add_filter( 'pib_shortcode_before', 'test_pib_shortcode_before' );
54
-
55
-
56
- /**
57
- * Outputs additional HTML after the PIB shortcode
58
- *
59
- * @since 2.0.3
60
- */
61
- function test_pib_shortcode_after() {
62
- return $after_html . '<p>After</p>';
63
- }
64
- //add_filter( 'pib_shortcode_after', 'test_pib_shortcode_after' );
65
-
66
-
67
- /**
68
- * Outputs additional HTML before the default button
69
- *
70
- * @since 2.0.3
71
- */
72
- function test_pib_button_before( $before_html ) {
73
- return '<p>Button Before</p>';
74
- }
75
- add_filter( 'pib_button_before', 'test_pib_button_before' );
76
-
77
-
78
- /**
79
- * Outputs additional HTML after the default button
80
- *
81
- * @since 2.0.3
82
- */
83
- function test_pib_button_after( $after_html ) {
84
- return '<p>Button After</p>';
85
- }
86
- add_filter( 'pib_button_after', 'test_pib_button_after' );
87
-
88
-
89
- /*************************
90
- * ACTION HOOKS
91
- ************************/
92
-
93
- /**
94
- * Outputs additional HTML after the default button
95
- *
96
- * @since 2.0.3
97
- */
98
- function test_pib_widget_before() {
99
- echo '<p>Widget Before</p>';
100
- }
101
- add_action( 'pib_widget_before', 'test_pib_widget_before' );
102
-
103
-
104
- /**
105
- * Outputs additional HTML after the default button
106
- *
107
- * @since 2.0.3
108
- */
109
- function test_pib_widget_after() {
110
- echo '<p>Widget After</p>';
111
- }
112
- add_action( 'pib_widget_after', 'test_pib_widget_after' );
1
+ <?php
2
+
3
+ /*************************
4
+ * FILTER HOOKS
5
+ ************************/
6
+
7
+ // Exit if accessed directly.
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ /**
13
+ * Modifies the HTML output of the shortcode button
14
+ *
15
+ * @since 2.0.3
16
+ */
17
+ function test_pib_shortcode_html( $html ) {
18
+ return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
19
+ }
20
+ //add_filter( 'pib_shortcode_html', 'test_pib_shortcode_html' );
21
+
22
+
23
+ /**
24
+ * Used to modify the widget HTML
25
+ *
26
+ * @since 2.0.3
27
+ */
28
+ function test_pib_widget_html( $html ) {
29
+ return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
30
+ }
31
+ //add_filter( 'pib_widget_html', 'test_pib_widget_html' );
32
+
33
+
34
+ /**
35
+ * Used to modify the regular button HTML
36
+ *
37
+ * @since 2.0.3
38
+ */
39
+ function test_pib_button_html( $html ) {
40
+ return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
41
+ }
42
+ //add_filter( 'pib_button_html', 'test_pib_button_html' );
43
+
44
+
45
+ /**
46
+ * Outputs additional HTML before the PIB shortcode
47
+ *
48
+ * @since 2.0.3
49
+ */
50
+ function test_pib_shortcode_before( $before_html ) {
51
+ return $before_html . '<p>Before</p>';
52
+ }
53
+ //add_filter( 'pib_shortcode_before', 'test_pib_shortcode_before' );
54
+
55
+
56
+ /**
57
+ * Outputs additional HTML after the PIB shortcode
58
+ *
59
+ * @since 2.0.3
60
+ */
61
+ function test_pib_shortcode_after() {
62
+ return $after_html . '<p>After</p>';
63
+ }
64
+ //add_filter( 'pib_shortcode_after', 'test_pib_shortcode_after' );
65
+
66
+
67
+ /**
68
+ * Outputs additional HTML before the default button
69
+ *
70
+ * @since 2.0.3
71
+ */
72
+ function test_pib_button_before( $before_html ) {
73
+ return '<p>Button Before</p>';
74
+ }
75
+ add_filter( 'pib_button_before', 'test_pib_button_before' );
76
+
77
+
78
+ /**
79
+ * Outputs additional HTML after the default button
80
+ *
81
+ * @since 2.0.3
82
+ */
83
+ function test_pib_button_after( $after_html ) {
84
+ return '<p>Button After</p>';
85
+ }
86
+ add_filter( 'pib_button_after', 'test_pib_button_after' );
87
+
88
+
89
+ /*************************
90
+ * ACTION HOOKS
91
+ ************************/
92
+
93
+ /**
94
+ * Outputs additional HTML after the default button
95
+ *
96
+ * @since 2.0.3
97
+ */
98
+ function test_pib_widget_before() {
99
+ echo '<p>Widget Before</p>';
100
+ }
101
+ add_action( 'pib_widget_before', 'test_pib_widget_before' );
102
+
103
+
104
+ /**
105
+ * Outputs additional HTML after the default button
106
+ *
107
+ * @since 2.0.3
108
+ */
109
+ function test_pib_widget_after() {
110
+ echo '<p>Widget After</p>';
111
+ }
112
+ add_action( 'pib_widget_after', 'test_pib_widget_after' );
includes/misc-functions.php CHANGED
@@ -1,193 +1,193 @@
1
- <?php
2
-
3
- /**
4
- * Misc functions to use throughout the plugin.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
-
17
- /*
18
- * Reusable variables
19
- *
20
- * @since 2.0.3
21
- */
22
- global $pib_vars;
23
-
24
- $pib_vars['cache_message'] = 'If you have caching enabled please empty it before viewing your changes.';
25
- $pib_vars['post_meta_message'] = '';
26
-
27
-
28
- /**
29
- * Google Analytics campaign URL.
30
- *
31
- * @since 2.0.0
32
- *
33
- * @param string $base_url Plain URL to navigate to
34
- * @param string $source GA "source" tracking value
35
- * @param string $medium GA "medium" tracking value
36
- * @param string $campaign GA "campaign" tracking value
37
- * @return string $url Full Google Analytics campaign URL
38
- */
39
- function pib_ga_campaign_url( $base_url, $source, $medium, $campaign ) {
40
- // $source is always 'pib_lite_2' for Pit It Button Lite 2.x
41
- // $medium examples: 'sidebar_link', 'banner_image'
42
-
43
- $url = add_query_arg( array(
44
- 'utm_source' => $source,
45
- 'utm_medium' => $medium,
46
- 'utm_campaign' => $campaign
47
- ), $base_url );
48
-
49
- return $url;
50
- }
51
-
52
- /**
53
- * Render RSS items from pinplugins.com in unordered list.
54
- * http://codex.wordpress.org/Function_Reference/fetch_feed
55
- *
56
- * @since 2.0.0
57
- */
58
- function pib_rss_news() {
59
- // Get RSS Feed(s).
60
- include_once( ABSPATH . WPINC . '/feed.php' );
61
-
62
- // Get a SimplePie feed object from the specified feed source.
63
- $rss = fetch_feed( PINPLUGIN_BASE_URL . 'feed/' );
64
-
65
- if ( ! is_wp_error( $rss ) ) {
66
- // Checks that the object is created correctly.
67
- // Figure out how many total items there are, but limit it to 5.
68
- $maxitems = $rss->get_item_quantity( 3 );
69
-
70
- // Build an array of all the items, starting with element 0 (first element).
71
- $rss_items = $rss->get_items( 0, $maxitems );
72
- }
73
- ?>
74
-
75
- <ul>
76
- <?php if ($maxitems == 0): ?>
77
- <li><?php _e( 'No items.', 'pib' ); ?></li>
78
- <?php else: ?>
79
- <?php
80
- // Loop through each feed item and display each item as a hyperlink.
81
- foreach ( $rss_items as $item ): ?>
82
- <?php $post_url = add_query_arg( array(
83
-
84
- // Google Analytics campaign URL
85
- 'utm_source' => 'pib_lite_2',
86
- 'utm_medium' => 'sidebar_link',
87
- 'utm_campaign' => 'blog_post_link'
88
-
89
- ), esc_url( $item->get_permalink() ) ); ?>
90
-
91
- <li>
92
- <div class="dashicons dashicons-arrow-right-alt2"></div>
93
- <a href="<?php echo $post_url; ?>" target="_blank" class="pib-external-link"><?php echo esc_html( $item->get_title() ); ?></a>
94
- </li>
95
- <?php endforeach; ?>
96
- <?php endif; ?>
97
- </ul>
98
-
99
- <?php
100
- }
101
-
102
- /**
103
- * Check if the WooCommerce plugin is active.
104
- *
105
- * @since 2.0.0
106
- *
107
- * @return boolean
108
- */
109
- function pib_is_woo_commerce_active() {
110
- return class_exists( 'WooCommerce' );
111
-
112
- /*
113
- * Could also do:
114
- * if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
115
- *
116
- * References:
117
- * http://docs.woothemes.com/document/create-a-plugin/
118
- * http://www.wpmayor.com/articles/how-to-check-whether-a-plugin-is-active/
119
- * http://pippinsplugins.com/checking-dependent-plugin-active/
120
- */
121
- }
122
-
123
- /**
124
- * Check if the Article Rich Pins plugin is active.
125
- *
126
- * @since 2.0.2
127
- *
128
- * @return boolean
129
- */
130
- function pib_is_article_rich_pins_active() {
131
- return class_exists( 'Article_Rich_Pins' );
132
- }
133
-
134
- /**
135
- * Check if the WooCommerce Rich Pins plugin is active.
136
- *
137
- * @since 2.0.2
138
- *
139
- * @return boolean
140
- */
141
- function pib_is_wc_rich_pins_active() {
142
- return class_exists( 'WooCommerce_Rich_Pins' );
143
- }
144
-
145
-
146
- /**
147
- * Check if we should render the Pinterest button
148
- *
149
- * @since 2.0.2
150
- *
151
- * @return boolean
152
- */
153
- function pib_render_button() {
154
- global $pib_options, $post;
155
-
156
- $return = array();
157
-
158
- //Determine if button displayed on current page from main admin settings
159
- if (
160
- ( is_home() && ( ! empty( $pib_options['post_page_types']['display_home_page'] ) ) ) ||
161
- ( is_front_page() && ( ! empty( $pib_options['post_page_types']['display_front_page'] ) ) ) ||
162
- ( is_single() && ( ! empty( $pib_options['post_page_types']['display_posts'] ) ) ) ||
163
- ( is_page() && ( ! empty( $pib_options['post_page_types']['display_pages'] ) ) && !is_front_page() ) ||
164
-
165
- //archive pages besides categories (tag, author, date, search)
166
- //http://codex.wordpress.org/Conditional_Tags
167
- ( is_archive() && ( ! empty( $pib_options['post_page_types']['display_archives'] ) ) &&
168
- ( is_tag() || is_author() || is_date() || is_search() || is_category() )
169
- )
170
- ) {
171
- // Make sure the button is enabled for this post via post meta setting
172
- if( ! ( get_post_meta( $post->ID, 'pib_sharing_disabled', 1 ) ) ) {
173
- $return[] = 'button';
174
- }
175
-
176
- }
177
-
178
- // Check if a shortcode exists
179
- if( has_shortcode( $post->post_content, 'pinit' ) ) {
180
- $return[] = 'shortcode';
181
- }
182
-
183
- // Check if there is a widget
184
- if( is_active_widget( false, false, 'pib_button', true ) ) {
185
- $return[] = 'widget';
186
- }
187
-
188
- if( empty( $return ) ) {
189
- $return[] = 'no_buttons';
190
- }
191
-
192
- return $return;
193
- }
1
+ <?php
2
+
3
+ /**
4
+ * Misc functions to use throughout the plugin.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+
17
+ /*
18
+ * Reusable variables
19
+ *
20
+ * @since 2.0.3
21
+ */
22
+ global $pib_vars;
23
+
24
+ $pib_vars['cache_message'] = 'If you have caching enabled please empty it before viewing your changes.';
25
+ $pib_vars['post_meta_message'] = '';
26
+
27
+
28
+ /**
29
+ * Google Analytics campaign URL.
30
+ *
31
+ * @since 2.0.0
32
+ *
33
+ * @param string $base_url Plain URL to navigate to
34
+ * @param string $source GA "source" tracking value
35
+ * @param string $medium GA "medium" tracking value
36
+ * @param string $campaign GA "campaign" tracking value
37
+ * @return string $url Full Google Analytics campaign URL
38
+ */
39
+ function pib_ga_campaign_url( $base_url, $source, $medium, $campaign ) {
40
+ // $source is always 'pib_lite_2' for Pit It Button Lite 2.x
41
+ // $medium examples: 'sidebar_link', 'banner_image'
42
+
43
+ $url = add_query_arg( array(
44
+ 'utm_source' => $source,
45
+ 'utm_medium' => $medium,
46
+ 'utm_campaign' => $campaign
47
+ ), $base_url );
48
+
49
+ return $url;
50
+ }
51
+
52
+ /**
53
+ * Render RSS items from pinplugins.com in unordered list.
54
+ * http://codex.wordpress.org/Function_Reference/fetch_feed
55
+ *
56
+ * @since 2.0.0
57
+ */
58
+ function pib_rss_news() {
59
+ // Get RSS Feed(s).
60
+ include_once( ABSPATH . WPINC . '/feed.php' );
61
+
62
+ // Get a SimplePie feed object from the specified feed source.
63
+ $rss = fetch_feed( PINPLUGIN_BASE_URL . 'feed/' );
64
+
65
+ if ( ! is_wp_error( $rss ) ) {
66
+ // Checks that the object is created correctly.
67
+ // Figure out how many total items there are, but limit it to 5.
68
+ $maxitems = $rss->get_item_quantity( 3 );
69
+
70
+ // Build an array of all the items, starting with element 0 (first element).
71
+ $rss_items = $rss->get_items( 0, $maxitems );
72
+ }
73
+ ?>
74
+
75
+ <ul>
76
+ <?php if ($maxitems == 0): ?>
77
+ <li><?php _e( 'No items.', 'pib' ); ?></li>
78
+ <?php else: ?>
79
+ <?php
80
+ // Loop through each feed item and display each item as a hyperlink.
81
+ foreach ( $rss_items as $item ): ?>
82
+ <?php $post_url = add_query_arg( array(
83
+
84
+ // Google Analytics campaign URL
85
+ 'utm_source' => 'pib_lite_2',
86
+ 'utm_medium' => 'sidebar_link',
87
+ 'utm_campaign' => 'blog_post_link'
88
+
89
+ ), esc_url( $item->get_permalink() ) ); ?>
90
+
91
+ <li>
92
+ <div class="dashicons dashicons-arrow-right-alt2"></div>
93
+ <a href="<?php echo $post_url; ?>" target="_blank"><?php echo esc_html( $item->get_title() ); ?></a>
94
+ </li>
95
+ <?php endforeach; ?>
96
+ <?php endif; ?>
97
+ </ul>
98
+
99
+ <?php
100
+ }
101
+
102
+ /**
103
+ * Check if the WooCommerce plugin is active.
104
+ *
105
+ * @since 2.0.0
106
+ *
107
+ * @return boolean
108
+ */
109
+ function pib_is_woo_commerce_active() {
110
+ return class_exists( 'WooCommerce' );
111
+
112
+ /*
113
+ * Could also do:
114
+ * if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
115
+ *
116
+ * References:
117
+ * http://docs.woothemes.com/document/create-a-plugin/
118
+ * http://www.wpmayor.com/articles/how-to-check-whether-a-plugin-is-active/
119
+ * http://pippinsplugins.com/checking-dependent-plugin-active/
120
+ */
121
+ }
122
+
123
+ /**
124
+ * Check if the Article Rich Pins plugin is active.
125
+ *
126
+ * @since 2.0.2
127
+ *
128
+ * @return boolean
129
+ */
130
+ function pib_is_article_rich_pins_active() {
131
+ return class_exists( 'Article_Rich_Pins' );
132
+ }
133
+
134
+ /**
135
+ * Check if the WooCommerce Rich Pins plugin is active.
136
+ *
137
+ * @since 2.0.2
138
+ *
139
+ * @return boolean
140
+ */
141
+ function pib_is_wc_rich_pins_active() {
142
+ return class_exists( 'WooCommerce_Rich_Pins' );
143
+ }
144
+
145
+
146
+ /**
147
+ * Check if we should render the Pinterest button
148
+ *
149
+ * @since 2.0.2
150
+ *
151
+ * @return boolean
152
+ */
153
+ function pib_render_button() {
154
+ global $pib_options, $post;
155
+
156
+ $return = array();
157
+
158
+ //Determine if button displayed on current page from main admin settings
159
+ if (
160
+ ( is_home() && ( ! empty( $pib_options['post_page_types']['display_home_page'] ) ) ) ||
161
+ ( is_front_page() && ( ! empty( $pib_options['post_page_types']['display_front_page'] ) ) ) ||
162
+ ( is_single() && ( ! empty( $pib_options['post_page_types']['display_posts'] ) ) ) ||
163
+ ( is_page() && ( ! empty( $pib_options['post_page_types']['display_pages'] ) ) && !is_front_page() ) ||
164
+
165
+ //archive pages besides categories (tag, author, date, search)
166
+ //http://codex.wordpress.org/Conditional_Tags
167
+ ( is_archive() && ( ! empty( $pib_options['post_page_types']['display_archives'] ) ) &&
168
+ ( is_tag() || is_author() || is_date() || is_search() || is_category() )
169
+ )
170
+ ) {
171
+ // Make sure the button is enabled for this post via post meta setting
172
+ if( ! ( get_post_meta( $post->ID, 'pib_sharing_disabled', 1 ) ) ) {
173
+ $return[] = 'button';
174
+ }
175
+
176
+ }
177
+
178
+ // Check if a shortcode exists
179
+ if( has_shortcode( $post->post_content, 'pinit' ) ) {
180
+ $return[] = 'shortcode';
181
+ }
182
+
183
+ // Check if there is a widget
184
+ if( is_active_widget( false, false, 'pib_button', true ) ) {
185
+ $return[] = 'widget';
186
+ }
187
+
188
+ if( empty( $return ) ) {
189
+ $return[] = 'no_buttons';
190
+ }
191
+
192
+ return $return;
193
+ }
includes/register-settings.php CHANGED
@@ -1,539 +1,539 @@
1
- <?php
2
-
3
- /**
4
- * Register all settings needed for the Settings API.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- /**
17
- * Main function to register all of the plugin settings
18
- *
19
- * @since 2.0.0
20
- */
21
- function pib_register_settings() {
22
- $pib_settings = array(
23
-
24
- /* General Settings */
25
- 'general' => array(
26
- 'button_type' => array(
27
- 'id' => 'button_type',
28
- 'name' => __( 'Button Type', 'pib' ),
29
- 'desc' => '',
30
- 'type' => 'radio',
31
- 'std' => 'no',
32
- 'options' => array(
33
- 'user_selects_image' => __( 'User selects image from popup (any image)', 'pib' ),
34
- 'image_selected' => __( 'Image is pre-selected (one image -- defaults to first image in post)', 'pib' )
35
- )
36
- ),
37
- 'count_layout' => array(
38
- 'id' => 'count_layout',
39
- 'name' => __( 'Pin Count', 'pib' ),
40
- 'desc' => '',
41
- 'type' => 'select',
42
- 'options' => array(
43
- 'none' => __( 'Not Shown', 'pib' ),
44
- 'horizontal' => __( 'Beside the Button', 'pib' ),
45
- 'vertical' => __( 'Above the Button', 'pib' )
46
- )
47
- ),
48
- 'show_zero_count' => array(
49
- 'id' => 'show_zero_count',
50
- 'name' => '',
51
- 'desc' => __( 'Show count bubble when there are zero pins.', 'pib' ),
52
- 'type' => 'checkbox'
53
- ),
54
- 'data_pin_size' => array(
55
- 'id' => 'data_pin_size',
56
- 'name' => __( 'Button Size', 'pib' ),
57
- 'desc' => '',
58
- 'type' => 'select',
59
- 'options' => array(
60
- 'small' => __( 'Small', 'pib' ),
61
- 'large' => __( 'Large', 'pib' )
62
- )
63
- ),
64
- 'data_pin_shape' => array(
65
- 'id' => 'data_pin_shape',
66
- 'name' => __( 'Button Shape', 'pib' ),
67
- 'desc' => '',
68
- 'type' => 'select',
69
- 'options' => array(
70
- 'rectangular' => __( 'Rectangular', 'pib' ),
71
- 'circular' => __( 'Circular', 'pib' )
72
- )
73
- ),
74
- 'data_pin_color' => array(
75
- 'id' => 'data_pin_color',
76
- 'name' => __( 'Button Color', 'pib' ),
77
- 'desc' => __( 'Color ignored if button shape is <strong>Circular</strong>.', 'pib' ),
78
- 'type' => 'select',
79
- 'options' => array(
80
- 'gray' => __( 'Gray', 'pib' ),
81
- 'red' => __( 'Red', 'pib' ),
82
- 'white' => __( 'White', 'pib' )
83
- )
84
- ),
85
- 'uninstall_save_settings' => array(
86
- 'id' => 'uninstall_save_settings',
87
- 'name' => __( 'Save Settings', 'pib' ),
88
- 'desc' => __( 'Save your settings when uninstalling this plugin. Useful when upgrading or re-installing.', 'pib' ),
89
- 'type' => 'checkbox'
90
- )
91
- ),
92
-
93
- /* Post Visibility Settings */
94
- 'post_visibility' => array(
95
- 'post_page_types' => array(
96
- 'id' => 'post_page_types',
97
- 'name' => __( 'Post/Page Types', 'pib' ),
98
- 'desc' => __( 'You may individually hide the "Pin It" button per post/page. This field is located towards the bottom of the post/page edit screen.', 'pib' ),
99
- 'type' => 'multicheck',
100
- 'options' => array(
101
- 'display_home_page' => __( 'Home Page (or latest posts page)', 'pib' ),
102
- 'display_front_page' => __( 'Front Page (different from Home Page only if set in Settings > Reading)', 'pib' ),
103
- 'display_posts' => __( 'Individual Posts', 'pib' ),
104
- 'display_pages' => __( 'Individual Pages (WordPress static pages)', 'pib' ),
105
- 'display_archives' => __( 'Archive Pages (includes Category, Tag, Author, and date-based pages)', 'pib' )
106
- )
107
- ),
108
- 'post_page_placement' => array(
109
- 'id' => 'post_page_placement',
110
- 'name' => __( 'Post/Page Placement', 'pib' ),
111
- 'desc' => __( 'Only the button style <strong>"Image is pre-selected"</strong> will use the individual post URL when a visitor pins from a post excerpt.', 'pib' ) . '<br />' .
112
- sprintf( __( 'Go to Appearance &rarr; <a href="%s">Widgets</a> to add a "Pin It" button to your sidebar or other widget area.', 'pib' ), admin_url( 'widgets.php' ) ),
113
- 'type' => 'multicheck',
114
- 'options' => array(
115
- 'display_above_content' => __( 'Above Content', 'pib' ),
116
- 'display_below_content' => __( 'Below Content', 'pib' ),
117
- 'display_on_post_excerpts' => __( 'Include in Post Excerpts', 'pib' )
118
- )
119
- )
120
- ),
121
-
122
- /* Styles Settings */
123
- 'styles' => array(
124
- 'custom_css' => array(
125
- 'id' => 'custom_css',
126
- 'name' => __( 'Custom CSS', 'pib' ),
127
- 'desc' => __( 'Custom CSS can be used to override other CSS style rules.', 'pib' ) . '<br />' .
128
- sprintf( __( 'Visit the <a href="%s">Help Section</a> for CSS override examples.', 'pib' ), add_query_arg( 'page', PIB_PLUGIN_SLUG . '_help', admin_url( 'admin.php' ) ) ),
129
- 'type' => 'textarea'
130
- ),
131
- 'remove_div' => array(
132
- 'id' => 'remove_div',
133
- 'name' => __( 'Remove DIV Container', 'pib' ),
134
- 'desc' => __( 'Remove DIV tag surrounding regular button', 'pib' ) . '(<code>' . htmlspecialchars( '<div class="pin-it-btn-wrapper"></div>' ) . '</code>)',
135
- 'type' => 'checkbox'
136
- ),
137
- 'disable_css' => array(
138
- 'id' => 'disable_css',
139
- 'name' => __( 'Disable CSS File Reference', 'pib' ),
140
- 'desc' => __( 'Advanced. Will prevent the plugin\'s CSS file from being referenced. Custom CSS above will still be included.', 'pib' ),
141
- 'type' => 'checkbox'
142
- )
143
- ),
144
-
145
- /* Advanced Settings */
146
- 'advanced' => array(
147
- 'no_pinit_js' => array(
148
- 'id' => 'no_pinit_js',
149
- 'name' => __( 'Disable <code>pinit.js</code>', 'pib' ),
150
- 'desc' => __( 'Disable output of <code>pinit.js</code>, the JavaScript file for all widgets from Pinterest.', 'pib' ) .
151
- '<p class="description">' . __( 'Check this option if you have <code>pinit.js</code> referenced in another plugin, widget or your theme. ' .
152
- 'Ouputting <code>pinit.js</code> more than once on a page can cause conflicts.', 'pib' ) . '</p>',
153
- 'type' => 'checkbox'
154
- )
155
- )
156
- );
157
-
158
- /* If the options do not exist then create them for each section */
159
- if ( false == get_option( 'pib_settings_general' ) ) {
160
- add_option( 'pib_settings_general' );
161
- }
162
-
163
- if ( false == get_option( 'pib_settings_post_visibility' ) ) {
164
- add_option( 'pib_settings_post_visibility' );
165
- }
166
-
167
- if ( false == get_option( 'pib_settings_styles' ) ) {
168
- add_option( 'pib_settings_styles' );
169
- }
170
-
171
- if( false == get_option( 'pib_settings_advanced' ) ){
172
- add_option( 'pib_settings_advanced' );
173
- }
174
-
175
- /* Add the General Settings section */
176
- add_settings_section(
177
- 'pib_settings_general',
178
- __( 'General Settings', 'pib' ),
179
- '__return_false',
180
- 'pib_settings_general'
181
- );
182
-
183
- foreach ( $pib_settings['general'] as $option ) {
184
- add_settings_field(
185
- 'pib_settings_general[' . $option['id'] . ']',
186
- $option['name'],
187
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
188
- 'pib_settings_general',
189
- 'pib_settings_general',
190
- pib_get_settings_field_args( $option, 'general' )
191
- );
192
- }
193
-
194
- /* Add the Post Visibility Settings section */
195
- add_settings_section(
196
- 'pib_settings_post_visibility',
197
- __( 'Post Visibility Settings', 'pib' ),
198
- '__return_false',
199
- 'pib_settings_post_visibility'
200
- );
201
-
202
- foreach ( $pib_settings['post_visibility'] as $option ) {
203
- add_settings_field(
204
- 'pib_settings_post_visibility[' . $option['id'] . ']',
205
- $option['name'],
206
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
207
- 'pib_settings_post_visibility',
208
- 'pib_settings_post_visibility',
209
- pib_get_settings_field_args( $option, 'post_visibility' )
210
- );
211
- }
212
-
213
- /* Add the Styles Settings section */
214
- add_settings_section(
215
- 'pib_settings_styles',
216
- __( 'Style Settings', 'pib' ),
217
- '__return_false',
218
- 'pib_settings_styles'
219
- );
220
-
221
- foreach ( $pib_settings['styles'] as $option ) {
222
- add_settings_field(
223
- 'pib_settings_styles[' . $option['id'] . ']',
224
- $option['name'],
225
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
226
- 'pib_settings_styles',
227
- 'pib_settings_styles',
228
- pib_get_settings_field_args( $option, 'styles' )
229
- );
230
- }
231
-
232
- /* Add the Advanced Settings section */
233
- add_settings_section(
234
- 'pib_settings_advanced',
235
- __( 'Advanced Settings', 'pib' ),
236
- '__return_false',
237
- 'pib_settings_advanced'
238
- );
239
-
240
- foreach ( $pib_settings['advanced'] as $option ) {
241
- add_settings_field(
242
- 'pib_settings_advanced[' . $option['id'] . ']',
243
- $option['name'],
244
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
245
- 'pib_settings_advanced',
246
- 'pib_settings_advanced',
247
- pib_get_settings_field_args( $option, 'advanced' )
248
- );
249
- }
250
-
251
- /* Register all settings or we will get an error when trying to save */
252
- register_setting( 'pib_settings_general', 'pib_settings_general', 'pib_settings_sanitize' );
253
- register_setting( 'pib_settings_post_visibility', 'pib_settings_post_visibility', 'pib_settings_sanitize' );
254
- register_setting( 'pib_settings_styles', 'pib_settings_styles', 'pib_settings_sanitize' );
255
- register_setting( 'pib_settings_advanced', 'pib_settings_advanced', 'pib_settings_sanitize' );
256
-
257
- }
258
- add_action( 'admin_init', 'pib_register_settings' );
259
-
260
- /*
261
- * Return generic add_settings_field $args parameter array.
262
- *
263
- * @since 2.0.0
264
- *
265
- * @param string $option Single settings option key.
266
- * @param string $section Section of settings apge.
267
- * @return array $args parameter to use with add_settings_field call.
268
- */
269
- function pib_get_settings_field_args( $option, $section ) {
270
- $settings_args = array(
271
- 'id' => $option['id'],
272
- 'desc' => $option['desc'],
273
- 'name' => $option['name'],
274
- 'section' => $section,
275
- 'size' => isset( $option['size'] ) ? $option['size'] : null,
276
- 'options' => isset( $option['options'] ) ? $option['options'] : '',
277
- 'std' => isset( $option['std'] ) ? $option['std'] : ''
278
- );
279
-
280
- // Link label to input using 'label_for' argument if text, textarea, password, select, or variations of.
281
- // Just add to existing settings args array if needed.
282
- if ( in_array( $option['type'], array( 'text', 'select', 'textarea', 'password', 'number' ) ) ) {
283
- $settings_args = array_merge( $settings_args, array( 'label_for' => 'pib_settings_' . $section . '[' . $option['id'] . ']' ) );
284
- }
285
-
286
- return $settings_args;
287
- }
288
-
289
- /*
290
- * Radio button callback function
291
- *
292
- * @since 2.0.0
293
- *
294
- */
295
- function pib_radio_callback( $args ) {
296
- global $pib_options;
297
-
298
- // Return empty string if no options.
299
- if ( empty( $args['options'] ) ) {
300
- echo '';
301
- return;
302
- }
303
-
304
- $html = "\n";
305
-
306
- foreach ( $args['options'] as $key => $option ) {
307
- $checked = false;
308
-
309
- if ( isset( $pib_options[ $args['id'] ] ) && $pib_options[ $args['id'] ] == $key )
310
- $checked = true;
311
- elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( $pib_options[ $args['id'] ] ) )
312
- $checked = true;
313
-
314
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-radio-label">';
315
- $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>' . "\n";
316
- $html .= $option . '</label>';
317
- }
318
-
319
- // Render and style description text underneath if it exists.
320
- if ( ! empty( $args['desc'] ) )
321
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
322
-
323
- echo $html;
324
- }
325
-
326
- /*
327
- * Single checkbox callback function
328
- *
329
- * @since 2.0.0
330
- *
331
- */
332
- function pib_checkbox_callback( $args ) {
333
- global $pib_options;
334
-
335
- $checked = isset( $pib_options[$args['id']] ) ? checked( 1, $pib_options[$args['id']], false ) : '';
336
- $html = "\n" . '<input type="checkbox" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" value="1" ' . $checked . '/>' . "\n";
337
-
338
- // Render description text directly to the right in a label if it exists.
339
- if ( ! empty( $args['desc'] ) )
340
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>' . "\n";
341
-
342
- echo $html;
343
- }
344
-
345
- /*
346
- * Multiple checkboxes callback function
347
- *
348
- * @since 2.0.0
349
- *
350
- */
351
- function pib_multicheck_callback( $args ) {
352
- global $pib_options;
353
-
354
- // Return empty string if no options.
355
- if ( empty( $args['options'] ) ) {
356
- echo '';
357
- return;
358
- }
359
-
360
- $html = "\n";
361
-
362
- foreach ( $args['options'] as $key => $option ) {
363
- if ( isset( $pib_options[$args['id']][$key] ) ) { $enabled = $option; } else { $enabled = NULL; }
364
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-checkbox-label">';
365
- $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="checkbox" value="' . $option . '" ' . checked($option, $enabled, false) . '/>' . "\n";
366
- $html .= $option . '</label>';
367
- }
368
-
369
- // Render and style description text underneath if it exists.
370
- if ( ! empty( $args['desc'] ) )
371
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
372
-
373
- echo $html;
374
- }
375
-
376
- /*
377
- * Select box callback function
378
- *
379
- * @since 2.0.0
380
- *
381
- */
382
- function pib_select_callback( $args ) {
383
- global $pib_options;
384
-
385
- // Return empty string if no options.
386
- if ( empty( $args['options'] ) ) {
387
- echo '';
388
- return;
389
- }
390
-
391
- $html = "\n" . '<select id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"/>' . "\n";
392
-
393
- foreach ( $args['options'] as $option => $name ) :
394
- $selected = isset( $pib_options[$args['id']] ) ? selected( $option, $pib_options[$args['id']], false ) : '';
395
- $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>' . "\n";
396
- endforeach;
397
-
398
- $html .= '</select>' . "\n";
399
-
400
- // Render and style description text underneath if it exists.
401
- if ( ! empty( $args['desc'] ) )
402
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
403
-
404
- echo $html;
405
- }
406
-
407
- /*
408
- * Textarea callback function
409
- *
410
- * @since 2.0.0
411
- *
412
- */
413
- function pib_textarea_callback( $args ) {
414
- global $pib_options;
415
-
416
- if ( isset( $pib_options[ $args['id'] ] ) )
417
- $value = $pib_options[ $args['id'] ];
418
- else
419
- $value = isset( $args['std'] ) ? $args['std'] : '';
420
-
421
- // Ignoring size at the moment.
422
- $html = "\n" . '<textarea class="large-text" cols="50" rows="10" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']">' . esc_textarea( $value ) . '</textarea>' . "\n";
423
-
424
- // Render and style description text underneath if it exists.
425
- if ( ! empty( $args['desc'] ) )
426
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
427
-
428
- echo $html;
429
- }
430
-
431
- /**
432
- * Number callback function
433
- *
434
- * @since 2.0.0
435
- *
436
- */
437
- function pib_number_callback( $args ) {
438
- global $pib_options;
439
-
440
- if ( isset( $pib_options[ $args['id'] ] ) )
441
- $value = $pib_options[ $args['id'] ];
442
- else
443
- $value = isset( $args['std'] ) ? $args['std'] : '';
444
-
445
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
446
- $html = "\n" . '<input type="number" class="' . $size . '-text" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" step="1" value="' . esc_attr( $value ) . '"/>' . "\n";
447
-
448
- // Render description text directly to the right in a label if it exists.
449
- if ( ! empty( $args['desc'] ) )
450
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>' . "\n";
451
-
452
- echo $html;
453
- }
454
-
455
- /**
456
- * Textbox callback function
457
- * Valid built-in size CSS class values:
458
- * small-text, regular-text, large-text
459
- *
460
- * @since 2.0.0
461
- *
462
- */
463
- function pib_text_callback( $args ) {
464
- global $pib_options;
465
-
466
- if ( isset( $pib_options[ $args['id'] ] ) )
467
- $value = $pib_options[ $args['id'] ];
468
- else
469
- $value = isset( $args['std'] ) ? $args['std'] : '';
470
-
471
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : '';
472
- $html = "\n" . '<input type="text" class="' . $size . '" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>' . "\n";
473
-
474
- // Render and style description text underneath if it exists.
475
- if ( ! empty( $args['desc'] ) )
476
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
477
-
478
- echo $html;
479
- }
480
-
481
- /*
482
- * Function we can use to sanitize the input data and return it when saving options
483
- *
484
- * @since 2.0.0
485
- *
486
- */
487
- function pib_settings_sanitize( $input ) {
488
- add_settings_error( 'pib-notices', '', '', '' );
489
- return $input;
490
- }
491
-
492
- /*
493
- * Default callback function if correct one does not exist
494
- *
495
- * @since 2.0.0
496
- *
497
- */
498
- function pib_missing_callback( $args ) {
499
- printf( __( 'The callback function used for the <strong>%s</strong> setting is missing.', 'pib' ), $args['id'] );
500
- }
501
-
502
- /*
503
- * Function used to return an array of all of the plugin settings
504
- *
505
- * @since 2.0.0
506
- *
507
- */
508
- function pib_get_settings() {
509
-
510
- // If this is the first time running we need to set the defaults
511
- if ( !get_option( 'pib_upgrade_has_run' ) ) {
512
-
513
- // set default post visibility options
514
- $post_visibility = get_option( 'pib_settings_post_visibility' );
515
- $post_visibility['post_page_types']['display_home_page'] = 1;
516
- $post_visibility['post_page_types']['display_posts'] = 1;
517
- $post_visibility['post_page_placement']['display_below_content'] = 1;
518
-
519
- update_option( 'pib_settings_post_visibility', $post_visibility );
520
-
521
- // set default general settings options
522
- $general = get_option( 'pib_settings_general' );
523
- $general['button_type'] = 'user_selects_image';
524
- $general['count_layout'] = 'none';
525
- $general['uninstall_save_settings'] = 1;
526
-
527
- update_option( 'pib_settings_general', $general );
528
-
529
- // add an option to let us know the initial settings have been run and we don't run them again
530
- add_option( 'pib_upgrade_has_run', 1 );
531
- }
532
-
533
- $general_settings = is_array( get_option( 'pib_settings_general' ) ) ? get_option( 'pib_settings_general' ) : array();
534
- $post_visibility_settings = is_array( get_option( 'pib_settings_post_visibility' ) ) ? get_option( 'pib_settings_post_visibility' ) : array();
535
- $style_settings = is_array( get_option( 'pib_settings_styles' ) ) ? get_option( 'pib_settings_styles' ) : array();
536
- $advanced_settings = is_array( get_option( 'pib_settings_advanced' ) ) ? get_option( 'pib_settings_advanced' ) : array();
537
-
538
- return array_merge( $general_settings, $post_visibility_settings, $style_settings, $advanced_settings );
539
- }
1
+ <?php
2
+
3
+ /**
4
+ * Register all settings needed for the Settings API.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Main function to register all of the plugin settings
18
+ *
19
+ * @since 2.0.0
20
+ */
21
+ function pib_register_settings() {
22
+ $pib_settings = array(
23
+
24
+ /* General Settings */
25
+ 'general' => array(
26
+ 'button_type' => array(
27
+ 'id' => 'button_type',
28
+ 'name' => __( 'Button Type', 'pib' ),
29
+ 'desc' => '',
30
+ 'type' => 'radio',
31
+ 'std' => 'no',
32
+ 'options' => array(
33
+ 'user_selects_image' => __( 'User selects image from popup (any image)', 'pib' ),
34
+ 'image_selected' => __( 'Image is pre-selected (one image -- defaults to first image in post)', 'pib' )
35
+ )
36
+ ),
37
+ 'count_layout' => array(
38
+ 'id' => 'count_layout',
39
+ 'name' => __( 'Pin Count', 'pib' ),
40
+ 'desc' => '',
41
+ 'type' => 'select',
42
+ 'options' => array(
43
+ 'none' => __( 'Not Shown', 'pib' ),
44
+ 'horizontal' => __( 'Beside the Button', 'pib' ),
45
+ 'vertical' => __( 'Above the Button', 'pib' )
46
+ )
47
+ ),
48
+ 'show_zero_count' => array(
49
+ 'id' => 'show_zero_count',
50
+ 'name' => '',
51
+ 'desc' => __( 'Show count bubble when there are zero pins.', 'pib' ),
52
+ 'type' => 'checkbox'
53
+ ),
54
+ 'data_pin_size' => array(
55
+ 'id' => 'data_pin_size',
56
+ 'name' => __( 'Button Size', 'pib' ),
57
+ 'desc' => '',
58
+ 'type' => 'select',
59
+ 'options' => array(
60
+ 'small' => __( 'Small', 'pib' ),
61
+ 'large' => __( 'Large', 'pib' )
62
+ )
63
+ ),
64
+ 'data_pin_shape' => array(
65
+ 'id' => 'data_pin_shape',
66
+ 'name' => __( 'Button Shape', 'pib' ),
67
+ 'desc' => '',
68
+ 'type' => 'select',
69
+ 'options' => array(
70
+ 'rectangular' => __( 'Rectangular', 'pib' ),
71
+ 'circular' => __( 'Circular', 'pib' )
72
+ )
73
+ ),
74
+ 'data_pin_color' => array(
75
+ 'id' => 'data_pin_color',
76
+ 'name' => __( 'Button Color', 'pib' ),
77
+ 'desc' => __( 'Color ignored if button shape is <strong>Circular</strong>.', 'pib' ),
78
+ 'type' => 'select',
79
+ 'options' => array(
80
+ 'gray' => __( 'Gray', 'pib' ),
81
+ 'red' => __( 'Red', 'pib' ),
82
+ 'white' => __( 'White', 'pib' )
83
+ )
84
+ ),
85
+ 'uninstall_save_settings' => array(
86
+ 'id' => 'uninstall_save_settings',
87
+ 'name' => __( 'Save Settings', 'pib' ),
88
+ 'desc' => __( 'Save your settings when uninstalling this plugin. Useful when upgrading or re-installing.', 'pib' ),
89
+ 'type' => 'checkbox'
90
+ )
91
+ ),
92
+
93
+ /* Post Visibility Settings */
94
+ 'post_visibility' => array(
95
+ 'post_page_types' => array(
96
+ 'id' => 'post_page_types',
97
+ 'name' => __( 'Post/Page Types', 'pib' ),
98
+ 'desc' => __( 'You may individually hide the "Pin It" button per post/page. This field is located towards the bottom of the post/page edit screen.', 'pib' ),
99
+ 'type' => 'multicheck',
100
+ 'options' => array(
101
+ 'display_home_page' => __( 'Home Page (or latest posts page)', 'pib' ),
102
+ 'display_front_page' => __( 'Front Page (different from Home Page only if set in Settings > Reading)', 'pib' ),
103
+ 'display_posts' => __( 'Individual Posts', 'pib' ),
104
+ 'display_pages' => __( 'Individual Pages (WordPress static pages)', 'pib' ),
105
+ 'display_archives' => __( 'Archive Pages (includes Category, Tag, Author, and date-based pages)', 'pib' )
106
+ )
107
+ ),
108
+ 'post_page_placement' => array(
109
+ 'id' => 'post_page_placement',
110
+ 'name' => __( 'Post/Page Placement', 'pib' ),
111
+ 'desc' => __( 'Only the button style <strong>"Image is pre-selected"</strong> will use the individual post URL when a visitor pins from a post excerpt.', 'pib' ) . '<br />' .
112
+ sprintf( __( 'Go to Appearance &rarr; <a href="%s">Widgets</a> to add a "Pin It" button to your sidebar or other widget area.', 'pib' ), admin_url( 'widgets.php' ) ),
113
+ 'type' => 'multicheck',
114
+ 'options' => array(
115
+ 'display_above_content' => __( 'Above Content', 'pib' ),
116
+ 'display_below_content' => __( 'Below Content', 'pib' ),
117
+ 'display_on_post_excerpts' => __( 'Include in Post Excerpts', 'pib' )
118
+ )
119
+ )
120
+ ),
121
+
122
+ /* Styles Settings */
123
+ 'styles' => array(
124
+ 'custom_css' => array(
125
+ 'id' => 'custom_css',
126
+ 'name' => __( 'Custom CSS', 'pib' ),
127
+ 'desc' => __( 'Custom CSS can be used to override other CSS style rules.', 'pib' ) . '<br />' .
128
+ sprintf( __( 'Visit the <a href="%s">Help Section</a> for CSS override examples.', 'pib' ), add_query_arg( 'page', PIB_PLUGIN_SLUG . '_help', admin_url( 'admin.php' ) ) ),
129
+ 'type' => 'textarea'
130
+ ),
131
+ 'remove_div' => array(
132
+ 'id' => 'remove_div',
133
+ 'name' => __( 'Remove DIV Container', 'pib' ),
134
+ 'desc' => __( 'Remove DIV tag surrounding regular button', 'pib' ) . '(<code>' . htmlspecialchars( '<div class="pin-it-btn-wrapper"></div>' ) . '</code>)',
135
+ 'type' => 'checkbox'
136
+ ),
137
+ 'disable_css' => array(
138
+ 'id' => 'disable_css',
139
+ 'name' => __( 'Disable CSS File Reference', 'pib' ),
140
+ 'desc' => __( 'Advanced. Will prevent the plugin\'s CSS file from being referenced. Custom CSS above will still be included.', 'pib' ),
141
+ 'type' => 'checkbox'
142
+ )
143
+ ),
144
+
145
+ /* Advanced Settings */
146
+ 'advanced' => array(
147
+ 'no_pinit_js' => array(
148
+ 'id' => 'no_pinit_js',
149
+ 'name' => __( 'Disable <code>pinit.js</code>', 'pib' ),
150
+ 'desc' => __( 'Disable output of <code>pinit.js</code>, the JavaScript file for all widgets from Pinterest.', 'pib' ) .
151
+ '<p class="description">' . __( 'Check this option if you have <code>pinit.js</code> referenced in another plugin, widget or your theme. ' .
152
+ 'Ouputting <code>pinit.js</code> more than once on a page can cause conflicts.', 'pib' ) . '</p>',
153
+ 'type' => 'checkbox'
154
+ )
155
+ )
156
+ );
157
+
158
+ /* If the options do not exist then create them for each section */
159
+ if ( false == get_option( 'pib_settings_general' ) ) {
160
+ add_option( 'pib_settings_general' );
161
+ }
162
+
163
+ if ( false == get_option( 'pib_settings_post_visibility' ) ) {
164
+ add_option( 'pib_settings_post_visibility' );
165
+ }
166
+
167
+ if ( false == get_option( 'pib_settings_styles' ) ) {
168
+ add_option( 'pib_settings_styles' );
169
+ }
170
+
171
+ if( false == get_option( 'pib_settings_advanced' ) ){
172
+ add_option( 'pib_settings_advanced' );
173
+ }
174
+
175
+ /* Add the General Settings section */
176
+ add_settings_section(
177
+ 'pib_settings_general',
178
+ __( 'General Settings', 'pib' ),
179
+ '__return_false',
180
+ 'pib_settings_general'
181
+ );
182
+
183
+ foreach ( $pib_settings['general'] as $option ) {
184
+ add_settings_field(
185
+ 'pib_settings_general[' . $option['id'] . ']',
186
+ $option['name'],
187
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
188
+ 'pib_settings_general',
189
+ 'pib_settings_general',
190
+ pib_get_settings_field_args( $option, 'general' )
191
+ );
192
+ }
193
+
194
+ /* Add the Post Visibility Settings section */
195
+ add_settings_section(
196
+ 'pib_settings_post_visibility',
197
+ __( 'Post Visibility Settings', 'pib' ),
198
+ '__return_false',
199
+ 'pib_settings_post_visibility'
200
+ );
201
+
202
+ foreach ( $pib_settings['post_visibility'] as $option ) {
203
+ add_settings_field(
204
+ 'pib_settings_post_visibility[' . $option['id'] . ']',
205
+ $option['name'],
206
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
207
+ 'pib_settings_post_visibility',
208
+ 'pib_settings_post_visibility',
209
+ pib_get_settings_field_args( $option, 'post_visibility' )
210
+ );
211
+ }
212
+
213
+ /* Add the Styles Settings section */
214
+ add_settings_section(
215
+ 'pib_settings_styles',
216
+ __( 'Style Settings', 'pib' ),
217
+ '__return_false',
218
+ 'pib_settings_styles'
219
+ );
220
+
221
+ foreach ( $pib_settings['styles'] as $option ) {
222
+ add_settings_field(
223
+ 'pib_settings_styles[' . $option['id'] . ']',
224
+ $option['name'],
225
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
226
+ 'pib_settings_styles',
227
+ 'pib_settings_styles',
228
+ pib_get_settings_field_args( $option, 'styles' )
229
+ );
230
+ }
231
+
232
+ /* Add the Advanced Settings section */
233
+ add_settings_section(
234
+ 'pib_settings_advanced',
235
+ __( 'Advanced Settings', 'pib' ),
236
+ '__return_false',
237
+ 'pib_settings_advanced'
238
+ );
239
+
240
+ foreach ( $pib_settings['advanced'] as $option ) {
241
+ add_settings_field(
242
+ 'pib_settings_advanced[' . $option['id'] . ']',
243
+ $option['name'],
244
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
245
+ 'pib_settings_advanced',
246
+ 'pib_settings_advanced',
247
+ pib_get_settings_field_args( $option, 'advanced' )
248
+ );
249
+ }
250
+
251
+ /* Register all settings or we will get an error when trying to save */
252
+ register_setting( 'pib_settings_general', 'pib_settings_general', 'pib_settings_sanitize' );
253
+ register_setting( 'pib_settings_post_visibility', 'pib_settings_post_visibility', 'pib_settings_sanitize' );
254
+ register_setting( 'pib_settings_styles', 'pib_settings_styles', 'pib_settings_sanitize' );
255
+ register_setting( 'pib_settings_advanced', 'pib_settings_advanced', 'pib_settings_sanitize' );
256
+
257
+ }
258
+ add_action( 'admin_init', 'pib_register_settings' );
259
+
260
+ /*
261
+ * Return generic add_settings_field $args parameter array.
262
+ *
263
+ * @since 2.0.0
264
+ *
265
+ * @param string $option Single settings option key.
266
+ * @param string $section Section of settings apge.
267
+ * @return array $args parameter to use with add_settings_field call.
268
+ */
269
+ function pib_get_settings_field_args( $option, $section ) {
270
+ $settings_args = array(
271
+ 'id' => $option['id'],
272
+ 'desc' => $option['desc'],
273
+ 'name' => $option['name'],
274
+ 'section' => $section,
275
+ 'size' => isset( $option['size'] ) ? $option['size'] : null,
276
+ 'options' => isset( $option['options'] ) ? $option['options'] : '',
277
+ 'std' => isset( $option['std'] ) ? $option['std'] : ''
278
+ );
279
+
280
+ // Link label to input using 'label_for' argument if text, textarea, password, select, or variations of.
281
+ // Just add to existing settings args array if needed.
282
+ if ( in_array( $option['type'], array( 'text', 'select', 'textarea', 'password', 'number' ) ) ) {
283
+ $settings_args = array_merge( $settings_args, array( 'label_for' => 'pib_settings_' . $section . '[' . $option['id'] . ']' ) );
284
+ }
285
+
286
+ return $settings_args;
287
+ }
288
+
289
+ /*
290
+ * Radio button callback function
291
+ *
292
+ * @since 2.0.0
293
+ *
294
+ */
295
+ function pib_radio_callback( $args ) {
296
+ global $pib_options;
297
+
298
+ // Return empty string if no options.
299
+ if ( empty( $args['options'] ) ) {
300
+ echo '';
301
+ return;
302
+ }
303
+
304
+ $html = "\n";
305
+
306
+ foreach ( $args['options'] as $key => $option ) {
307
+ $checked = false;
308
+
309
+ if ( isset( $pib_options[ $args['id'] ] ) && $pib_options[ $args['id'] ] == $key )
310
+ $checked = true;
311
+ elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( $pib_options[ $args['id'] ] ) )
312
+ $checked = true;
313
+
314
+ $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-radio-label">';
315
+ $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>' . "\n";
316
+ $html .= $option . '</label>';
317
+ }
318
+
319
+ // Render and style description text underneath if it exists.
320
+ if ( ! empty( $args['desc'] ) )
321
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
322
+
323
+ echo $html;
324
+ }
325
+
326
+ /*
327
+ * Single checkbox callback function
328
+ *
329
+ * @since 2.0.0
330
+ *
331
+ */
332
+ function pib_checkbox_callback( $args ) {
333
+ global $pib_options;
334
+
335
+ $checked = isset( $pib_options[$args['id']] ) ? checked( 1, $pib_options[$args['id']], false ) : '';
336
+ $html = "\n" . '<input type="checkbox" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" value="1" ' . $checked . '/>' . "\n";
337
+
338
+ // Render description text directly to the right in a label if it exists.
339
+ if ( ! empty( $args['desc'] ) )
340
+ $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>' . "\n";
341
+
342
+ echo $html;
343
+ }
344
+
345
+ /*
346
+ * Multiple checkboxes callback function
347
+ *
348
+ * @since 2.0.0
349
+ *
350
+ */
351
+ function pib_multicheck_callback( $args ) {
352
+ global $pib_options;
353
+
354
+ // Return empty string if no options.
355
+ if ( empty( $args['options'] ) ) {
356
+ echo '';
357
+ return;
358
+ }
359
+
360
+ $html = "\n";
361
+
362
+ foreach ( $args['options'] as $key => $option ) {
363
+ if ( isset( $pib_options[$args['id']][$key] ) ) { $enabled = $option; } else { $enabled = NULL; }
364
+ $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-checkbox-label">';
365
+ $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="checkbox" value="' . $option . '" ' . checked($option, $enabled, false) . '/>' . "\n";
366
+ $html .= $option . '</label>';
367
+ }
368
+
369
+ // Render and style description text underneath if it exists.
370
+ if ( ! empty( $args['desc'] ) )
371
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
372
+
373
+ echo $html;
374
+ }
375
+
376
+ /*
377
+ * Select box callback function
378
+ *
379
+ * @since 2.0.0
380
+ *
381
+ */
382
+ function pib_select_callback( $args ) {
383
+ global $pib_options;
384
+
385
+ // Return empty string if no options.
386
+ if ( empty( $args['options'] ) ) {
387
+ echo '';
388
+ return;
389
+ }
390
+
391
+ $html = "\n" . '<select id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"/>' . "\n";
392
+
393
+ foreach ( $args['options'] as $option => $name ) :
394
+ $selected = isset( $pib_options[$args['id']] ) ? selected( $option, $pib_options[$args['id']], false ) : '';
395
+ $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>' . "\n";
396
+ endforeach;
397
+
398
+ $html .= '</select>' . "\n";
399
+
400
+ // Render and style description text underneath if it exists.
401
+ if ( ! empty( $args['desc'] ) )
402
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
403
+
404
+ echo $html;
405
+ }
406
+
407
+ /*
408
+ * Textarea callback function
409
+ *
410
+ * @since 2.0.0
411
+ *
412
+ */
413
+ function pib_textarea_callback( $args ) {
414
+ global $pib_options;
415
+
416
+ if ( isset( $pib_options[ $args['id'] ] ) )
417
+ $value = $pib_options[ $args['id'] ];
418
+ else
419
+ $value = isset( $args['std'] ) ? $args['std'] : '';
420
+
421
+ // Ignoring size at the moment.
422
+ $html = "\n" . '<textarea class="large-text" cols="50" rows="10" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']">' . esc_textarea( $value ) . '</textarea>' . "\n";
423
+
424
+ // Render and style description text underneath if it exists.
425
+ if ( ! empty( $args['desc'] ) )
426
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
427
+
428
+ echo $html;
429
+ }
430
+
431
+ /**
432
+ * Number callback function
433
+ *
434
+ * @since 2.0.0
435
+ *
436
+ */
437
+ function pib_number_callback( $args ) {
438
+ global $pib_options;
439
+
440
+ if ( isset( $pib_options[ $args['id'] ] ) )
441
+ $value = $pib_options[ $args['id'] ];
442
+ else
443
+ $value = isset( $args['std'] ) ? $args['std'] : '';
444
+
445
+ $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
446
+ $html = "\n" . '<input type="number" class="' . $size . '-text" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" step="1" value="' . esc_attr( $value ) . '"/>' . "\n";
447
+
448