-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwpsea-functionality.php
1504 lines (1282 loc) · 42.4 KB
/
wpsea-functionality.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: WP Seattle Functionality
Description: Functionality plugin for code/settings commonly use in the Seattle WordPress community. Provides Functionality this is common to most sites: Google Analytics, No wordpress update nag, Support Information Dashboard Widget
Contributors: wpseattle, blobaugh, jaffe75, awoods
Version: 0.7.5
Author: WordPress Seattle
Author URI: http://www.meetup.com/SeattleWordPressMeetup/
License: GPLv2
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or ( at your option ) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//---------------------------------
// CONSTANTS
//---------------------------------
define( 'WPSEA_FUNC_PLUGIN_DIR', trailingslashit( dirname( __FILE__) ) );
define( 'WPSEA_FUNC_TEXT_DOMAIN', 'wpsea-func' );
define( 'WPSEA_FUNC_VERSION', '0.7.5' );
$wpsea_func_google_jquery_all_versions = array(
'1.8.2', '1.8.1', '1.8.0', // 2012 Aug 09 => 1.8
'1.7.2', '1.7.1', '1.7.0', // 2011 Nov 03 => 1.7
'1.6.4', '1.6.3', '1.6.2', '1.6.1', '1.6', // 2011 May 03 => 1.6
'1.5.2', '1.5.1', '1.5' // 2011 Jan 31 => 1.5
);
$wpsea_func_admin_messages = array('ERROR' => array(), 'NOTICE' => array());
//---------------------------------
// HOOKS
//---------------------------------
if ( get_option( 'wpsea_func_generator_enabled' ) == 'no' ) {
remove_action( 'wp_head', 'wp_generator' );
}
if ( get_option( 'wpsea_func_feed_links_enabled' ) == 'no' ) {
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
}
if ( get_option( 'wpsea_func_wlwmanifest_enabled' ) == 'no' ) {
remove_action( 'wp_head', 'wlwmanifest_link' );
}
if ( get_option( 'wpsea_func_rsd_enabled' ) == 'no' ) {
remove_action( 'wp_head', 'rsd_link');
}
register_activation_hook( __FILE__, 'wpsea_func_setup' );
register_uninstall_hook( __FILE__, 'wpsea_func_teardown' );
add_action( 'init', 'wpsea_func_load_jquery' );
add_action( 'plugins_loaded', 'wpsea_func_init' );
add_action( 'wp_enqueue_scripts', 'wpsea_func_load_js' );
add_action( 'admin_init', 'no_update_nag' );
add_action( 'admin_init', 'wpsea_func_admin_init' );
add_action( 'admin_menu', 'wpsea_func_modify_menu' );
add_action( 'admin_notices', 'wpsea_func_show_admin_messages');
add_action( 'wp_dashboard_setup', 'example_remove_dashboard_widgets' );
add_action( 'wp_dashboard_setup', 'wpsea_func_add_dashboard_widgets' );
if ( get_option( 'wpsea_func_analytics_enabled' ) == 'yes' ) {
add_action( 'wp_footer', 'wpsea_func_analytics_js' );
}
add_filter( 'plugin_action_links', 'wpsea_func_settings_link', 10, 2 );
add_filter( 'user_contactmethods', 'wpsea_func_modify_user_contacts_methods' );
add_shortcode( 'wpsea_contactform', 'wpsea_func_contact_form' );
//---------------------------------
// FUNCTIONS
//---------------------------------
function wpsea_func_setup() {
add_option( 'wpsea_func_generator_enabled', 'yes' );
add_option( 'wpsea_func_feed_links_enabled', 'yes' );
add_option( 'wpsea_func_wlwmanifest_enabled', 'yes' );
add_option( 'wpsea_func_rsd_enabled', 'yes' );
add_option( 'wpsea_func_analytics_id' );
add_option( 'wpsea_func_analytics_enabled', 'yes' );
add_option( 'wpsea_func_noframes_enabled', 'no' );
add_option( 'wpsea_func_load_jquery', 'no' );
add_option( 'wpsea_func_googles_jquery', 'no' );
add_option( 'wpsea_func_googles_jquery_version', '1.8.2' );
}
function wpsea_func_teardown() {
delete_option( 'wpsea_func_generator_enabled' );
delete_option( 'wpsea_func_feed_links_enabled' );
delete_option( 'wpsea_func_wlwmanifest_enabled' );
delete_option( 'wpsea_func_rsd_enabled');
delete_option( 'wpsea_func_analytics_id' );
delete_option( 'wpsea_func_analytics_enabled' );
delete_option( 'wpsea_func_noframes_enabled' );
delete_option( 'wpsea_func_load_jquery' );
delete_option( 'wpsea_func_googles_jquery' );
delete_option( 'wpsea_func_googles_jquery_version' );
}
function wpsea_func_modify_menu() {
$_settings = wpsea_func_get_settings();
add_options_page(
$_settings['wpsea_func_page_title'], // Page Title
$_settings['wpsea_func_page_title'], // Sub-menu Title
'manage_options', // Minimum access control
'wpsea_func_settings',
'wpsea_func_options_page' // collback function
);
}
/**
* Helper function for defining variables for the current page
*
* @return array
*/
function wpsea_func_get_settings() {
$output = array();
// put together the output array
$output['wpsea_func_option_name'] = ''; // the option name as used in get_option().
$output['wpsea_func_page_title'] = __( 'Site Functionality', WPSEA_FUNC_TEXT_DOMAIN );
$output['wpsea_func_author_name'] = __( 'Wordpress Seattle Meetup', WPSEA_FUNC_TEXT_DOMAIN );
$output['wpsea_func_page_sections'] = wpsea_func_page_sections();
return $output;
}
/**
* Define our settings sections
*
* @return array
*/
function wpsea_func_page_sections() {
$sections = array();
$sections['wpsea_func_main'] = array(
'title' => __( 'Main', WPSEA_FUNC_TEXT_DOMAIN ),
'callback' => 'wpsea_func_main_callback',
);
$sections['header_section'] = array(
'title' => __( 'Page Headers', WPSEA_FUNC_TEXT_DOMAIN ),
'callback' => 'wpsea_func_header_callback',
);
$sections['analytics_section'] = array(
'title' => __( 'Analytics', WPSEA_FUNC_TEXT_DOMAIN ),
'callback' => 'wpsea_func_analytics_callback',
);
$sections['javascript_section'] = array(
'title' => __( 'Javascript', WPSEA_FUNC_TEXT_DOMAIN ),
'callback' => 'wpsea_func_javascript_callback',
);
$sections['shortcode_section'] = array(
'title' => __( 'Shortcodes', WPSEA_FUNC_TEXT_DOMAIN ),
'callback' => 'wpsea_func_shortcode_callback',
);
$sections['widget_section'] = array(
'title' => __( 'Widgets', WPSEA_FUNC_TEXT_DOMAIN ),
'callback' => 'wpsea_func_widget_callback',
);
return $sections;
}
/* stub function */
function section_callback() {
echo 'this is callback function text ';
// return;
}
/**
* Setup Essential Settings options page
*
* Register the settings and build of form fields for the options page.
*
* @since 0.1
*
* @param type $name it does something
* @return void
*/
function wpsea_func_admin_init() {
$_settings = wpsea_func_get_settings();
$_sections = wpsea_func_page_sections();
// add_settings_section( $id, $title, $callback, $page );
if ( isset( $_sections ) ) {
// call the "add_settings_section" for each!
foreach ( $_sections as $id => $data ) {
$title = $data['title'];
$callback = ( isset( $data['callback'] ) ) ? $data['callback'] : 'section_callback';
add_settings_section( $id, $title, $callback, 'wpsea_func' );
}
}
register_setting(
'analytics_section',
'wpsea_func_analytics_id'
);
register_setting(
'analytics_section',
'wpsea_func_analytics_enabled'
);
register_setting(
'javascript_section',
'wpsea_func_noframes_enabled'
);
register_setting(
'javascript_section',
'wpsea_func_setting_jquery_enabled'
);
register_setting(
'javascript_section',
'wpsea_func_googles_jquery'
);
register_setting(
'javascript_section',
'wpsea_func_googles_jquery_version'
);
register_setting(
'wpsea_func_main',
'wpsea_func_contact_sendto'
);
add_settings_field(
'wpsea_func_generator_enabled', // string used in the 'id' attribute of tags
'Generator Enabled', // Title of the Field
'wpsea_func_setting_generator_enabled', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'header_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_feed_links_enabled', // string used in the 'id' attribute of tags
'Feed Links Enabled', // Title of the Field
'wpsea_func_setting_feed_links_enabled', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'header_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_wlwmanifest_enabled', // string used in the 'id' attribute of tags
'WLW Manifest Enabled', // Title of the Field
'wpsea_func_setting_wlwmanifest_enabled', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'header_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_rsd_enabled', // string used in the 'id' attribute of tags
'RSD Enabled', // Title of the Field
'wpsea_func_setting_rsd_enabled', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'header_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_analytics_enabled', // string used in the 'id' attribute of tags
'GA Enabled', // Title of the Field
'wpsea_func_setting_analytics_enabled', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'analytics_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_analytics_id', // string used in the 'id' attribute of tags
'Google Analytics ID', // Title of the Field
'wpsea_func_setting_analytics_id', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'analytics_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_noframes_enabled', // string used in the 'id' attribute of tags
'No Frames Enabled', // Title of the Field
'wpsea_func_setting_noframes_enabled', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'javascript_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_jquery_enabled', // string used in the 'id' attribute of tags
'jQuery Enabled', // Title of the Field
'wpsea_func_setting_jquery_enabled', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'javascript_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_googles_jquery', // string used in the 'id' attribute of tags
'Use Googles jQuery instead', // Title of the Field
'wpsea_func_setting_googles_jquery', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'javascript_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_googles_jquery_version', // string used in the 'id' attribute of tags
'Use this Googles jQuery version', // Title of the Field
'wpsea_func_setting_googles_jquery_version', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'javascript_section' // The section of the settings page in which to show the box
);
add_settings_field(
'wpsea_func_contact_sendto', // string used in the 'id' attribute of tags
'Send Contact Form To', // Title of the Field
'wpsea_func_setting_contact_sendto', // function that renders the field
'wpsea_func', // the type of settings page on which to show the field
'wpsea_func_main' // The section of the settings page in which to show the box
);
wpsea_func_check_permissions();
}
function wpsea_func_check_permissions() {
global $wpsea_func_admin_messages;
$js_filename = wpsea_func_get_filename();
$writable = wpsea_func_check_writable($js_filename, 'w');
$message = $js_filename;
$message .= ($writable === TRUE) ? ' IS writable': ' IS NOT writable';
if ( ! $writable ) {
if ( WP_DEBUG ) {
error_log('check permissions message: ' . $message );
}
$wpsea_func_admin_messages['ERROR'][] = $message;
}
}
/**
* Check that the file or directory has a desired permission.
*
* validate that a permission exists before trying to perform it on a file or directory.
*
* @since 0.7.5
*
* @param string $path can be a file or directory
* @param string $perm can be any combination of r, w, x.
* @return boolean
*/
function wpsea_func_check_writable($path, $perm = 'r') {
if ( strstr($perm, 'w') && ( is_writable( dirname( $path ) ) || is_writable( $path ) ) ) {
error_log('check_permissions path=' . $path . ' is writable');
return TRUE;
}
error_log('check_permissions path=' . $path . ' is NOT writable');
return FALSE;
}
/**
* Generic function to show a message to the user using WP's
* standard CSS classes to make use of the already-defined
* message colour scheme.
*
* @param $message The message you want to tell the user.
* @param $errormsg If true, the message is an error, so use
* the red message style. If false, the message is a status
* message, so use the yellow information message style.
*/
function wpsea_func_show_admin_messages() {
global $wpsea_func_admin_messages;
if ( sizeof($wpsea_func_admin_messages['ERROR']) > 0 ) {
echo '<div id="message" class="error">';
foreach ( $wpsea_func_admin_messages['ERROR'] AS $message ) {
// do stuff
echo '<p><strong>' . $message . '</strong></p>';
}
echo '</div>';
}
if ( sizeof($wpsea_func_admin_messages['NOTICE']) > 0 ) {
echo '<div id="message" class="updated fade">';
foreach ( $wpsea_func_admin_messages['NOTICE'] AS $message ) {
// do stuff
echo '<p><strong>' . $message . '</strong></p>';
}
echo '</div>';
}
}
function wpsea_func_main_callback() {
?>
<p>
The email address is used by the Contact Form
</p>
<?php
}
function wpsea_func_header_callback() {
?>
<p>
These settings update actions that modify the page head of your theme
</p>
<?php
}
function wpsea_func_analytics_callback() {
?>
<p>
These settings provide some control over the website.
<strong>Google Analytics</strong> provides website tracking
for free. Just set the 'Google Analytics Enabled' to yes and provide the website
tracking id, and your site will be sending tracking information to Google.
</p>
<?php
}
function wpsea_func_javascript_callback() {
?>
<p>
<strong>jQuery</strong> can be turned on. Without any other settings,
jquery will be loaded from Wordpress' core. As an option, you can
choose to <strong>load jQuery from Google's CDN</strong>.
<strong>'No Frames'</strong> is an option that detects
when your website has been loaded into a frameset. When enabled, it
will break your site out of the frameset, so that your website will
behave normally and prevent other sites from branding or hijacking
your site.
</p>
<?php
}
function wpsea_func_shortcode_callback() {
?>
<p>
Simply create a page and add the shortcode to it.
There are 2 attributes that can be used to override default functionality.
This helps designers by providing flexibility.
<ul style="list-style-type: disc; list-style-position: inside;">
<li>send_to</li>
<li>redirect_to</li>
</ul>
</p>
<p> <strong>Implement the basic contact form:</strong><br />
[wpsea_contactform]
<br />
<br/>
The form will submit the information to the same page, and send the form data
to the 'Send Contact Form To' specified above.
</p>
<p> <strong>Use a different email address to send to:</strong><br/>
[wpsea_contactform send_to="[email protected]"]
<br />
<br />
</p>
<p> <strong>To Redirect the user to a new page upon success:</strong><br/>
[wpsea_contactform redirect_to="/thank-you"]
</p>
<p> <strong>Add some information above the form</strong><br/>
[wpsea_contactform sendto="[email protected]"]<br />
This will be displayed above the form<br/>
[/wpsea_contactform]
</p>
<?php
}
function wpsea_func_widget_callback() {
?>
<p>
There are 2 <a href="<?php echo admin_url('widgets.php'); ?>">widgets</a>
that come with this module - <strong>Essential Popular Posts</strong>,
and <strong>Essential Latest Post</strong>
</p>
<?php
}
/**
* Render the Analytics ID field
*
* @since 0.1
*
* @param wp_option $wpsea_func_analytics_id
* @return void
*/
function wpsea_func_setting_analytics_id() {
$analytics_id = get_option( 'wpsea_func_analytics_id' );
?>
<input id="wpsea_func_analytics_id" name="wpsea_func_analytics_id"
type="text" value="<?php echo $analytics_id; ?>" /> e.g. UA-xxxxxxxx-x
<?php
}
/**
* Render the Generator Enabled field
*
* @since 0.3
*
* @param wp_option $wpsea_func_generator_enabled
* @return void
*/
function wpsea_func_setting_generator_enabled() {
$generator_enabled = get_option( 'wpsea_func_generator_enabled', 'yes' );
if ( $generator_enabled == 'yes' ) {
?>
<input type="radio" id="wpsea_func_generator_enabled_yes"
name="wpsea_func_generator_enabled" checked="checked" value="yes"/>
<label for="wpsea_func_generator_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_generator_enabled_no"
name="wpsea_func_generator_enabled" value="no"/>
<label for="wpsea_func_generator_enabled_no">No</label>
<?php
} else {
?>
<input type="radio" id="wpsea_func_generator_enabled_yes"
name="wpsea_func_generator_enabled" value="yes"/>
<label for="wpsea_func_generator_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_generator_enabled_no"
name="wpsea_func_generator_enabled" checked="checked" value="no"/>
<label for="wpsea_func_generator_enabled_no">No</label>
<?php
}
}
/**
* Render the Manifest Enabled field
*
* @since 0.3
*
* @param wp_option $wpsea_func_wlwmanifest_enabled
* @return void
*/
function wpsea_func_setting_wlwmanifest_enabled() {
$wlwmanifest_enabled = get_option( 'wpsea_func_wlwmanifest_enabled', 'yes' );
?>
<p>Determine if <em>Windows Live Writer(WLW) manifest</em> should be available.</p>
<?php
if ( $wlwmanifest_enabled == 'yes' ) {
?>
<input type="radio" id="wpsea_func_wlwmanifest_enabled_yes"
name="wpsea_func_wlwmanifest_enabled" checked="checked" value="yes"/>
<label for="wpsea_func_wlwmanifest_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_wlwmanifest_enabled_no"
name="wpsea_func_wlwmanifest_enabled" value="no"/>
<label for="wpsea_func_wlwmanifest_enabled_no">No</label>
<?php
} else {
?>
<input type="radio" id="wpsea_func_wlwmanifest_enabled_yes"
name="wpsea_func_wlwmanifest_enabled" value="yes"/>
<label for="wpsea_func_wlwmanifest_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_wlwmanifest_enabled_no"
name="wpsea_func_wlwmanifest_enabled" checked="checked" value="no"/>
<label for="wpsea_func_wlwmanifest_enabled_no">No</label>
<?php
}
}
/**
* Render the Feed Links Enabled field
*
* @since 0.3
*
*/
function wpsea_func_setting_feed_links_enabled() {
$feed_links_enabled = get_option( 'wpsea_func_feed_links_enabled', 'yes' );
if ( $feed_links_enabled == 'yes' ) {
?>
<input type="radio" id="wpsea_func_feed_links_enabled_yes"
name="wpsea_func_feed_links_enabled" checked="checked" value="yes"/>
<label for="wpsea_func_feed_links_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_feed_links_enabled_no"
name="wpsea_func_feed_links_enabled" value="no"/>
<label for="wpsea_func_feed_links_enabled_no">No</label>
<?php
} else {
?>
<input type="radio" id="wpsea_func_feed_links_enabled_yes"
name="wpsea_func_feed_links_enabled" value="yes"/>
<label for="wpsea_func_feed_links_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_feed_links_enabled_no"
name="wpsea_func_feed_links_enabled" checked="checked" value="no"/>
<label for="wpsea_func_feed_links_enabled_no">No</label>
<?php
}
}
/**
* Render the RSD Enabled field
*
* @since 0.3
*
* @param wp_option $wpsea_func_rsd_enabled
* @return void
*/
function wpsea_func_setting_rsd_enabled() {
$rsd_enabled = get_option( 'wpsea_func_rsd_enabled', 'yes' );
if ( $rsd_enabled == 'yes' ) {
?>
<input type="radio" id="wpsea_func_rsd_enabled_yes"
name="wpsea_func_rsd_enabled" checked="checked" value="yes"/>
<label for="wpsea_func_rsd_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_rsd_enabled_no"
name="wpsea_func_rsd_enabled" value="no"/>
<label for="wpsea_func_rsd_enabled_no">No</label>
<?php
} else {
?>
<input type="radio" id="wpsea_func_rsd_enabled_yes"
name="wpsea_func_rsd_enabled" value="yes"/>
<label for="wpsea_func_rsd_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_rsd_enabled_no"
name="wpsea_func_rsd_enabled" checked="checked" value="no"/>
<label for="wpsea_func_rsd_enabled_no">No</label>
<?php
}
}
/**
* Render the Google Analytics Enabled field
*
* @since 0.7
*
* @param wp_option $wpsea_func_analytics_enabled
* @return void
*/
function wpsea_func_setting_analytics_enabled() {
$analytics_enabled = get_option( 'wpsea_func_analytics_enabled' );
if ( $analytics_enabled == 'yes' ) {
?>
<input type="radio" id="wpsea_func_analytics_enabled_yes"
name="wpsea_func_analytics_enabled" checked="checked" value="yes"/>
<label for="wpsea_func_analytics_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_analytics_enabled_no"
name="wpsea_func_analytics_enabled" value="no"/>
<label for="wpsea_func_analytics_enabled_no">No</label>
<?php
} else {
?>
<input type="radio" id="wpsea_func_analytics_enabled_yes"
name="wpsea_func_analytics_enabled" value="yes"/>
<label for="wpsea_func_analytics_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_analytics_enabled_no"
name="wpsea_func_analytics_enabled" checked="checked" value="no"/>
<label for="wpsea_func_analytics_enabled_no">No</label>
<?php
}
}
/**
* Render jquery enabled form on options page
*
* Long Description
*
* @since 0.7
*
* @param type $name it does something
* @return type it does something
*/
function wpsea_func_setting_jquery_enabled() {
$use_jquery_enabled = get_option( 'wpsea_func_load_jquery_enabled' );
if ( $use_jquery_enabled == 'yes' ) {
?>
<input type="radio" id="wpsea_func_load_jquery_enabled_yes"
name="wpsea_func_load_jquery_enabled" checked="checked" value="yes"/>
<label for="wpsea_func_load_jquery_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_load_jquery_enabled_no"
name="wpsea_func_load_jquery_enabled" value="no"/>
<label for="wpsea_func_load_jquery_enabled_no">No</label>
<?php
} else {
?>
<input type="radio" id="wpsea_func_load_jquery_enabled_yes"
name="wpsea_func_load_jquery_enabled" value="yes"/>
<label for="wpsea_func_load_jquery_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_load_jquery_enabled_no"
name="wpsea_func_load_jquery_enabled" checked="checked" value="no"/>
<label for="wpsea_func_load_jquery_enabled_no">No</label>
<?php
}
}
/**
* Render the Use Googles JQuery field
*
* @since 0.7
*
* @param wp_option $wpsea_func_googles_jquery
* @return void
*/
function wpsea_func_setting_googles_jquery() {
$use_googles_jquery = get_option( 'wpsea_func_googles_jquery' );
if ( $use_googles_jquery == 'yes' ) {
?>
<input type="radio" id="wpsea_func_googles_jquery_yes"
name="wpsea_func_googles_jquery" value="yes" checked="checked" />
<label for="wpsea_func_googles_jquery_yes">Yes</label>
<input type="radio" id="wpsea_func_googles_jquery_no"
name="wpsea_func_googles_jquery" value="no"/>
<label for="wpsea_func_googles_jquery_no">No</label>
<?php
} else {
?>
<input type="radio" id="wpsea_func_googles_jquery_yes"
name="wpsea_func_googles_jquery" value="yes"/>
<label for="wpsea_func_googles_jquery_yes">Yes</label>
<input type="radio" id="wpsea_func_googles_jquery_no"
name="wpsea_func_googles_jquery" value="no" checked="checked" />
<label for="wpsea_func_googles_jquery_no">No</label>
<?php
}
}
function wpsea_func_setting_googles_jquery_version() {
global $wpsea_func_google_jquery_all_versions;
$jquery_version = get_option( 'wpsea_func_googles_jquery_version' );
?>
<select name="wpsea_func_googles_jquery_version">
<?php foreach ( $wpsea_func_google_jquery_all_versions AS $value ):
$checked = ($jquery_version == $value) ? ' selected="selected"' : '';
?>
<option<?php echo $checked; ?>><?php echo $value; ?></option>
<?php endforeach; ?>
</select>
<?php
}
/**
* Render the No Frames field for the Settings page
*
* @since 0.1
*
* @param wp_options $wpsea_func_noframes_enabled
* @return void
*/
function wpsea_func_setting_noframes_enabled() {
$noframes_enabled = get_option( 'wpsea_func_noframes_enabled' );
if ( $noframes_enabled == 'yes' ) {
?>
<input type="radio" id="wpsea_func_noframes_enabled_yes"
name="wpsea_func_noframes_enabled" checked="checked" value="yes"/>
<label for="wpsea_func_noframes_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_noframes_enabled_no"
name="wpsea_func_noframes_enabled" value="no"/>
<label for="wpsea_func_noframes_enabled_no">No</label>
<?php
wpsea_func_noframes_append();
} else {
?>
<input type="radio" id="wpsea_func_noframes_enabled_yes"
name="wpsea_func_noframes_enabled" value="yes"/>
<label for="wpsea_func_noframes_enabled_yes">Yes</label>
<input type="radio" id="wpsea_func_noframes_enabled_no"
name="wpsea_func_noframes_enabled" checked="checked" value="no"/>
<label for="wpsea_func_noframes_enabled_no">No</label>
<?php
}
}
/**
* Render the Contact Send To field for the Settings page
*
* @since 0.1
*
* @param wp_options $wpsea_func_contact_sendto
* @return void
*/
function wpsea_func_setting_contact_sendto() {
$contact_sendto = get_option( 'wpsea_func_contact_sendto' );
?>
<input id="wpsea_func_contact_sendto" name="wpsea_func_contact_sendto"
type="text" value="<?php echo $contact_sendto; ?>" /> e.g. [email protected]
<?php
}
/**
* Add the 'No Frames' functionality to the site-essential.js
*
* @return void
*/
function wpsea_func_noframes_append() {
$filename = wpsea_func_get_filename();
$home_url = get_bloginfo( 'siteurl' );
try {
error_log( 'opening file for appending' . $filename );
$fh = fopen( $filename, 'a+' );
} catch (Exception $e) {
error_log("RAT FARTS! e=" . $e->getMessage() );
}
if ( ! $fh ){
die( 'Cannot write filename=' . $filename );
}
$no_frames_js = '
// no frames
//
try {
var parent_location = new String( parent.location );
var top_location = new String( top.location );
var cur_location = new String( document.location );
parent_location = parent_location.toLowerCase();
top_location = top_location.toLowerCase();
cur_location = cur_location.toLowerCase();
if ( ( top_location != cur_location )
&& parent_location.indexOf("' . $home_url . '" ) != 0 ){
top.location.href = document.location.href;
}
} catch ( err ) {
top.location.href = document.location.href;
}
';
fputs( $fh, $no_frames_js );
fclose( $fh );
}
/**
* Render the Form for the Options page
*
* @since 0.1
*
* @return void
*/
function wpsea_func_options_page() {
$_settings = wpsea_func_get_settings();
$errors = array();
if ( isset($_POST['wpsea_func_submit_button']) ) {
update_option( 'wpsea_func_generator_enabled', $_POST['wpsea_func_generator_enabled'] );
update_option( 'wpsea_func_feed_links_enabled', $_POST['wpsea_func_feed_links_enabled'] );
update_option( 'wpsea_func_wlwmanifest_enabled', $_POST['wpsea_func_wlwmanifest_enabled'] );
update_option( 'wpsea_func_rsd_enabled', $_POST['wpsea_func_rsd_enabled'] );
update_option( 'wpsea_func_analytics_id', $_POST['wpsea_func_analytics_id'] );
update_option( 'wpsea_func_analytics_enabled', $_POST['wpsea_func_analytics_enabled'] );
update_option( 'wpsea_func_noframes_enabled', $_POST['wpsea_func_noframes_enabled'] );
update_option( 'wpsea_func_load_jquery_enabled', $_POST['wpsea_func_load_jquery_enabled'] );
update_option( 'wpsea_func_googles_jquery', $_POST['wpsea_func_googles_jquery'] );
update_option( 'wpsea_func_googles_jquery_version', $_POST['wpsea_func_googles_jquery_version'] );
update_option( 'wpsea_func_contact_sendto', $_POST['wpsea_func_contact_sendto'] );
$check = array();
$check['analytics_id'] = $_POST['wpsea_func_analytics_id'];
$check['send_to'] = $_POST['wpsea_func_contact_sendto'];
$errors = wpsea_func_form_validate( $check );
// delete the current file if exists. Creating/Appending the file will be done
// by other functions.
$js_file = wpsea_func_get_filename();
if ( file_exists($js_file) ){
error_log('removing JS file' . $js_file);
unlink( $js_file );
}
}
?>
<div class="wrap">
<h2><?php echo $_settings['wpsea_func_page_title']; ?></h2>
<div>Send any plugin issues to <?php echo $_settings['wpsea_func_author_name']; ?></div>
<?php if ( $errors ){
?>
<div style="color: red; font-size: 18px; ">
<?php
foreach ( $errors AS $error_field => $error_message ){
echo '<span style="">' . $error_message . '</span><br />';
}
?>
</div>
<?php } ?>
<form action="" method="post" accept-charset="utf-8">
<?php
settings_fields( 'wpsea_func_options' );
do_settings_sections( 'wpsea_func' );
?>
<input type="submit" name="wpsea_func_submit_button"
value="Save Changes" id="wpsea_func_submit_button">
</form>
</div>
<?php
}
/**
* determine which source of jquery to load
*
* JQuery can be loaded from WordPress core or from Google's CDN.
* The value is determined by the Settings page for this plugin.
*
* @since 0.1
*
* @param wp_option $wpsea_func_googles_jquery
* @return void
*/
function wpsea_func_load_jquery() {
$use_jquery = get_option( 'wpsea_func_load_jquery_enabled' );
$use_googles_jquery = get_option( 'wpsea_func_googles_jquery' );
$googles_jquery_version = get_option( 'wpsea_func_googles_jquery_version' );
if ( $use_jquery == 'yes' ){
if ( $use_googles_jquery == 'yes' ){
$google_js_url = 'http://ajax.googleapis.com/ajax/libs/jquery/' . $googles_jquery_version . '/jquery.min.js';
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', $google_js_url );
}
wp_enqueue_script( 'jquery' );
}
}
/**
* Attach site_essential.js to the html page
*
* @return void
*/
function wpsea_func_load_js() {
$in_footer = false;
try {
$essential_js = plugins_url('wpsea-functionality/js/site_essential.js');
error_log('-WPSEA_FUNC_ESSENTIAL_JS_URL=' . $essential_js);
} catch (Exception $e) {
error_log("Exception occurred getting filename! " . $e->getMessage() );
}
$dependencies = array();
wp_enqueue_script(
'wpsea_func_main',
$essential_js,
$dependencies,
WPSEA_FUNC_VERSION,
$in_footer
);
}
/**
* Display the Google Analytics in the theme
* It needs to be displayed just before </body>.
* To do so, the wp_footer hook is used.
*
* @since 0.1