-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpolldaddy.php
4671 lines (4122 loc) · 195 KB
/
polldaddy.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 // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Plugin Name: Crowdsignal Polls & Ratings
* Plugin URI: http://wordpress.org/extend/plugins/polldaddy/
* Description: Create and manage Crowdsignal polls and ratings in WordPress
* Author: Automattic, Inc.
* Author URL: https://crowdsignal.com/
* Version: 3.1.2
*/
// To hardcode your Polldaddy PartnerGUID (API Key), add the (uncommented) line below with the PartnerGUID to your `wp-config.php`
// define( 'WP_POLLDADDY__PARTNERGUID', '12345…' );
if ( ! defined( 'POLLDADDY_API_HOST' ) ) {
define( 'POLLDADDY_API_HOST', 'api.crowdsignal.com' );
}
if ( ! defined( 'POLLDADDY_API_VERSION' ) ) {
define( 'POLLDADDY_API_VERSION', 'v1' );
}
function polldaddy_api_path( $path, $version = POLLDADDY_API_VERSION ) {
return sprintf( '/%s%s', $version, $path );
}
function polldaddy_api_url( $path, $version = POLLDADDY_API_VERSION, $protocol = 'https' ) {
return sprintf(
'%s://%s%s',
$protocol,
POLLDADDY_API_HOST,
rtrim( polldaddy_api_path( $path, $version ), '/' )
);
}
function polldaddy_add_oembed_provider() {
wp_oembed_add_provider( '#https?://(.+\.)?polldaddy\.com/.*#i', 'https://api.crowdsignal.com/oembed', true );
wp_oembed_add_provider( '#https?://.+\.survey\.fm/.*#i', 'https://api.crowdsignal.com/oembed', true );
wp_oembed_add_provider( '#https?://poll\.fm/.*#i', 'https://api.crowdsignal.com/oembed', true );
}
add_action( 'init', 'polldaddy_add_oembed_provider' );
class WP_Polldaddy {
var $errors;
var $base_url;
var $is_admin;
var $is_author;
var $scheme;
var $version;
var $polldaddy_client_class;
var $polldaddy_clients;
var $id;
var $multiple_accounts;
var $user_code;
var $rating_user_code;
var $has_feedback_menu;
var $is_editor;
var $has_crowdsignal_blocks;
public $has_items = array();
function __construct() {
global $current_user;
$this->log( 'Created WP_Polldaddy Object: constructor' );
$this->errors = new WP_Error;
$this->scheme = 'https';
$this->version = '3.1.2';
$this->multiple_accounts = ! empty( get_option( 'polldaddy_usercode_user' ) );
$this->polldaddy_client_class = 'api_client';
$this->polldaddy_clients = array();
$this->is_admin = (bool) current_user_can( 'manage_options' );
$this->is_author = (bool) current_user_can( 'edit_posts' );
$this->is_editor = (bool) current_user_can( 'delete_others_pages' );
$this->user_code = null;
$this->rating_user_code = null;
$this->id = ($current_user instanceof WP_User) ? intval( $current_user->ID ): 0;
$this->has_feedback_menu = false;
$this->has_crowdsignal_blocks = ! empty( get_option( 'crowdsignal_user_code' ) );
if ( class_exists( 'Jetpack' ) ) {
if ( method_exists( 'Jetpack', 'is_active' ) && Jetpack::is_active() ) {
$jetpack_active_modules = get_option('jetpack_active_modules');
if ( $jetpack_active_modules && in_array( 'contact-form', $jetpack_active_modules ) )
$this->has_feedback_menu = true;
}
if ( class_exists( 'Jetpack_Sync' ) && defined( 'JETPACK__VERSION' ) && version_compare( JETPACK__VERSION, '4.1', '<' ) ) {
Jetpack_Sync::sync_options( __FILE__, 'polldaddy_api_key' );
}
add_filter( 'jetpack_options_whitelist', array( $this, 'add_to_jetpack_options_whitelist' ) );
}
if ( ! post_type_exists( 'feedback' ) ) {
register_post_type(
'feedback', array(
'labels' => array(
),
'menu_icon' => 'dashicons-feedback',
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=feedback',
'show_in_admin_bar' => false,
'public' => false,
'rewrite' => false,
'query_var' => false,
'capability_type' => 'page',
'show_in_rest' => true,
'rest_controller_class' => 'Grunion_Contact_Form_Endpoint',
'capabilities' => array(
'create_posts' => 'do_not_allow',
'publish_posts' => 'publish_pages',
'edit_posts' => 'edit_pages',
'edit_others_posts' => 'edit_others_pages',
'delete_posts' => 'delete_pages',
'delete_others_posts' => 'delete_others_pages',
'read_private_posts' => 'read_private_pages',
'edit_post' => 'edit_page',
'delete_post' => 'delete_page',
'read_post' => 'read_page',
),
'map_meta_cap' => true,
)
);
add_action( 'admin_menu', array( $this, 'remove_feedback_menu' ) );
}
}
/**
* Remove the feedback "All Posts" submenu if not needed.
*/
public function remove_feedback_menu() {
remove_submenu_page( 'edit.php?post_type=feedback', 'edit.php?post_type=feedback' );
}
/**
* Add the polldaddy option to the Jetpack options management whitelist.
*
* @param array $options The list of whitelisted option names.
* @return array The updated whitelist
*/
public static function add_to_jetpack_options_whitelist( $options ) {
$options[] = 'polldaddy_api_key';
return $options;
}
function &get_client( $api_key, $userCode = null ) {
if ( isset( $this->polldaddy_clients[$api_key] ) ) {
if ( !is_null( $userCode ) )
$this->polldaddy_clients[$api_key]->userCode = $userCode;
return $this->polldaddy_clients[$api_key];
}
require_once WP_POLLDADDY__POLLDADDY_CLIENT_PATH;
$this->polldaddy_clients[$api_key] = $this->config_client( new $this->polldaddy_client_class( $api_key, $userCode ) );
return $this->polldaddy_clients[$api_key];
}
function config_client( $client ) {
return $client;
}
function admin_menu() {
if ( isset( $_GET['page'] ) && 'pollsettings' === $_GET['page'] ) {
wp_safe_redirect( admin_url( 'options-general.php?page=crowdsignal-settings' ) );
die();
}
add_action( 'wp_enqueue_scripts', array( &$this, 'register_polldaddy_styles' ) );
add_action( 'admin_enqueue_scripts', array( &$this, 'menu_alter' ) );
if ( !defined( 'WP_POLLDADDY__PARTNERGUID' ) ) {
$guid = get_option( 'polldaddy_api_key' );
if ( !$guid || !is_string( $guid ) )
$guid = false;
define( 'WP_POLLDADDY__PARTNERGUID', $guid );
}
$capability = 'edit_posts';
$function = array( &$this, 'management_page' );
$icon_encoded = 'PHN2ZyBpZD0iY29udGVudCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgMjg4IDIyMCI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiNGRkZGRkY7fTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5pY29uLWJsdWU8L3RpdGxlPjxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTI2Mi40MSw4MC4xYy04LjQ3LTIyLjU1LTE5LjA1LTQyLjgzLTI5Ljc5LTU3LjFDMjIwLjc0LDcuMjQsMjEwLC41NywyMDEuNDcsMy43OWExMi4zMiwxMi4zMiwwLDAsMC0zLjcyLDIuM2wtLjA1LS4xNUwxNiwxNzMuOTRsOC4yLDE5LjEyLDMwLjU2LTEuOTJ2MTMuMDVhMTIuNTcsMTIuNTcsMCwwLDAsMTIuNTgsMTIuNTZjLjMzLDAsLjY3LDAsMSwwbDU4Ljg1LTQuNzdhMTIuNjUsMTIuNjUsMCwwLDAsMTEuNTYtMTIuNTNWMTg1Ljg2bDEyMS40NS03LjY0YTEzLjg4LDEzLjg4LDAsMCwwLDIuMDkuMjYsMTIuMywxMi4zLDAsMCwwLDQuNDEtLjhDMjg1LjMzLDE3MC43LDI3OC42MywxMjMuMzEsMjYyLjQxLDgwLjFabS0yLjI2LDg5Ljc3Yy0xMC40OC0zLjI1LTMwLjQ0LTI4LjE1LTQ2LjY4LTcxLjM5LTE1LjcyLTQxLjktMTcuNS03My4yMS0xMi4zNC04My41NGE2LjUyLDYuNTIsMCwwLDEsMy4yMi0zLjQ4LDMuODIsMy44MiwwLDAsMSwxLjQxLS4yNGMzLjg1LDAsMTAuOTQsNC4yNiwyMC4zMSwxNi43MUMyMzYuMzYsNDEuNTksMjQ2LjU0LDYxLjE1LDI1NC43NCw4M2MxOC40NCw0OS4xMiwxNy43NCw4My43OSw5LjEzLDg3QTUuOTMsNS45MywwLDAsMSwyNjAuMTUsMTY5Ljg3Wk0xMzAuNiwxOTkuNDFhNC40LDQuNCwwLDAsMS00LDQuMzdsLTU4Ljg1LDQuNzdBNC4zOSw0LjM5LDAsMCwxLDYzLDIwNC4xOVYxOTAuNjJsNjcuNjEtNC4yNVoiLz48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik02LDE4NS4yNmExMC4yNSwxMC4yNSwwLDAsMCwxMC4yNSwxMC4yNSwxMC4wNSwxMC4wNSwwLDAsMCw0LjM0LTFsLTcuOTQtMTguNzNBMTAuMiwxMC4yLDAsMCwwLDYsMTg1LjI2WiIvPjwvc3ZnPgo=';
$slug = 'edit.php?post_type=feedback';
if ( ! $this->has_feedback_menu ) {
$hook = add_menu_page(
__( 'Feedback', 'polldaddy' ),
__( 'Feedback', 'polldaddy' ),
$capability,
$slug,
$function,
'data:image/svg+xml;base64,' . $icon_encoded
);
add_action( "load-$hook", array( &$this, 'management_page_load' ) );
}
foreach( array( 'polls' => __( 'Crowdsignal', 'polldaddy' ), 'ratings' => __( 'Ratings', 'polldaddy' ) ) as $menu_slug => $page_title ) {
$menu_title = $page_title;
$hook = add_submenu_page( $this->has_feedback_menu ? 'feedback' : $slug, $menu_title, $menu_title, $capability, $menu_slug, $function, 99 );
add_action( "load-$hook", array( &$this, 'management_page_load' ) );
}
// Add settings pages.
foreach( array( 'crowdsignal-settings' => __( 'Crowdsignal', 'polldaddy' ), 'ratingsettings' => __( 'Ratings', 'polldaddy' ) ) as $menu_slug => $page_title ) {
// translators: %s placeholder is the setting page type (Poll or Rating).
$settings_page_title = sprintf( esc_html__( '%s', 'polldaddy' ), $page_title );
$hook = add_options_page( $settings_page_title, $settings_page_title, $menu_slug == 'ratingsettings' ? 'manage_options' : 'edit_others_posts', $menu_slug, array( $this, 'settings_page' ) );
add_action( "load-$hook", array( $this, 'management_page_load' ) );
}
}
function menu_alter() {
// Make sure we're working off a clean version.
include( ABSPATH . WPINC . '/version.php' );
if ( version_compare( $wp_version, '3.8', '<' ) ) {
$css = "
#toplevel_page_polldaddy .wp-menu-image {
background: url( " . plugins_url( 'img/polldaddy.png', __FILE__ ) . " ) 0 90% no-repeat;
}
/* Retina Polldaddy Menu Icon */
@media only screen and (-moz-min-device-pixel-ratio: 1.5),
only screen and (-o-min-device-pixel-ratio: 3/2),
only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min-device-pixel-ratio: 1.5) {
#toplevel_page_polldaddy .wp-menu-image {
background: url( " . plugins_url( '[email protected]', __FILE__ ) . " ) 0 90% no-repeat;
background-size:30px 64px;
}
}
#toplevel_page_polldaddy.current .wp-menu-image,
#toplevel_page_polldaddy.wp-has-current-submenu .wp-menu-image,
#toplevel_page_polldaddy:hover .wp-menu-image {
background-position: top left;
}";
wp_add_inline_style( 'wp-admin', $css );
}
}
function api_key_page_load() {
if ( 'post' != strtolower( $_SERVER['REQUEST_METHOD'] ) || empty( $_POST['action'] ) || 'account' != $_POST['action'] )
return false;
check_admin_referer( 'polldaddy-account' );
$polldaddy_email = stripslashes( $_POST['polldaddy_email'] );
$polldaddy_password = stripslashes( $_POST['polldaddy_password'] );
if ( !$polldaddy_email )
$this->errors->add( 'polldaddy_email', __( 'Email address required', 'polldaddy' ) );
if ( !$polldaddy_password )
$this->errors->add( 'polldaddy_password', __( 'Password required', 'polldaddy' ) );
if ( $this->errors->get_error_codes() )
return false;
$details = array(
'uName' => get_bloginfo( 'name' ),
'uEmail' => $polldaddy_email,
'uPass' => $polldaddy_password,
'partner_userid' => $this->id
);
if ( function_exists( 'wp_remote_post' ) ) { // WP 2.7+
$polldaddy_api_key = wp_remote_post( polldaddy_api_url( '/key' ), array(
'body' => $details
) );
if ( is_wp_error( $polldaddy_api_key ) ) {
$this->errors = $polldaddy_api_key;
return false;
}
$polldaddy_api_key = wp_remote_retrieve_body( $polldaddy_api_key );
} else {
$fp = fsockopen(
polldaddy_api_url( '/', POLLDADDY_API_VERSION, 'tls' ),
443,
$err_num,
$err_str,
5
);
if ( !$fp ) {
$this->errors->add( 'connect', __( "Can't connect to Polldaddy.com", 'polldaddy' ) );
return false;
}
if ( function_exists( 'stream_set_timeout' ) )
stream_set_timeout( $fp, 3 );
global $wp_version;
$request_body = http_build_query( $details, null, '&' );
$request = 'POST ' . polldaddy_api_path( '/key' ) . " HTTP/1.0\r\n";
$request .= 'Host: ' . POLLDADDY_API_HOST . "\r\n";
$request .= "User-agent: WordPress/$wp_version\r\n";
$request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ) . "\r\n";
$request .= 'Content-Length: ' . strlen( $request_body ) . "\r\n";
fwrite( $fp, "$request\r\n$request_body" );
$response = '';
while ( !feof( $fp ) )
$response .= fread( $fp, 4096 );
fclose( $fp );
list( $headers, $polldaddy_api_key ) = explode( "\r\n\r\n", $response, 2 );
}
if ( !$polldaddy_api_key ) {
$this->errors->add( 'polldaddy_password', __( 'Invalid Account', 'polldaddy' ) );
return false;
}
update_option( 'polldaddy_api_key', $polldaddy_api_key );
$polldaddy = $this->get_client( $polldaddy_api_key );
$polldaddy->reset();
if ( !$polldaddy->get_usercode( $this->id ) ) {
$this->parse_errors( $polldaddy );
$this->errors->add( 'GetUserCode', __( 'Account could not be accessed. Are your email address and password correct?', 'polldaddy' ) );
return false;
}
return true;
}
function parse_errors( &$polldaddy ) {
if ( $polldaddy->errors )
foreach ( $polldaddy->errors as $code => $error )
$this->errors->add( $code, $error );
if ( isset( $this->errors->errors[4] ) ) {
//need to get latest usercode
global $wp_version;
if ( version_compare( $wp_version, '4.2', '<' ) ) {
delete_option( 'pd-usercode-' . $this->id );
add_option( 'pd-usercode-' . $this->id, '', '', false );
} else {
update_option( 'pd-usercode-' . $this->id, '', false );
}
$this->set_api_user_code();
}
}
function print_errors() {
if ( !$error_codes = $this->errors->get_error_codes() )
return;
$this->render_partial( 'errors', array( 'error_codes' => $error_codes, 'errors' => $this->errors ) );
$this->errors = new WP_Error;
}
function api_key_page() {
$this->print_errors();
?>
<div class="wrap">
<h2 id="polldaddy-header"><?php _e( 'Crowdsignal', 'polldaddy' ); ?></h2>
<p><?php printf( __( 'Before you can use the Crowdsignal plugin, you need to enter your <a href="%s">Crowdsignal.com</a> account details.', 'polldaddy' ), 'https://app.crowdsignal.com/' ); ?></p>
<form action="" method="post">
<table class="form-table">
<tbody>
<tr class="form-field form-required">
<th valign="top" scope="row">
<label for="polldaddy-email"><?php _e( 'Crowdsignal Email Address', 'polldaddy' ); ?></label>
</th>
<td>
<input type="text" name="polldaddy_email" id="polldaddy-email" aria-required="true" size="40" />
</td>
</tr>
<tr class="form-field form-required">
<th valign="top" scope="row">
<label for="polldaddy-password"><?php _e( 'Crowdsignal Password', 'polldaddy' ); ?></label>
</th>
<td>
<input type="password" name="polldaddy_password" id="polldaddy-password" aria-required="true" size="40" />
</td>
</tr>
</tbody>
</table>
<p class="submit">
<?php wp_nonce_field( 'polldaddy-account' ); ?>
<input type="hidden" name="action" value="account" />
<input type="hidden" name="account" value="import" />
<input class="button-secondary" type="submit" value="<?php echo esc_attr( __( 'Submit', 'polldaddy' ) ); ?>" />
</p>
</form>
</div>
<?php
}
function get_usercode( $for_current_user = false ) {
// sitewide access to Crowdsignal account
if ( ! $for_current_user && $user_id = get_option( 'polldaddy_usercode_user' ) ) {
return get_option( 'pd-usercode-' . $user_id );
} else {
return get_option( 'pd-usercode-' . $this->id );
}
}
function set_api_user_code() {
$this->user_code = get_option( 'pd-usercode-'.$this->id );
if ( empty( $this->user_code ) ) {
$polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID );
$polldaddy->reset();
$this->user_code = $polldaddy->get_usercode( $this->id );
if ( !empty( $this->user_code ) ) {
global $wp_version;
if ( version_compare( $wp_version, '4.2', '<' ) ) {
delete_option( 'pd-usercode-' . $this->id );
add_option( 'pd-usercode-' . $this->id, $this->user_code, '', false );
} else {
update_option( 'pd-usercode-' . $this->id, $this->user_code, false );
}
} elseif ( get_option( 'crowdsignal_api_key' ) === get_option( 'polldaddy_api_key' ) ) {
// attempt to get credentials from Crowdsignal Forms.
$this->user_code = get_option( 'crowdsignal_user_code' );
} elseif ( get_option( 'polldaddy_api_key' ) ) {
$this->contact_support_message( 'There was a problem linking your account', $polldaddy->errors );
}
}
}
function management_page_load() {
wp_reset_vars( array( 'page', 'action', 'poll', 'style', 'rating', 'id' ) );
global $plugin_page, $page, $action, $poll, $style, $rating, $id, $wp_locale;
if (
isset( $_GET['step'] ) && 2 === (int) $_GET['step']
&& isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD']
&& isset( $_POST['got_api_key'] ) && get_option( 'crowdsignal_api_key_secret' ) === $_POST['got_api_key']
&& isset( $_POST['api_key'] )
) {
$api_key = sanitize_key( wp_unslash( $_POST['api_key'] ) );
$crowdsignal = $this->get_client( $api_key );
$crowdsignal->reset();
$usercode = $crowdsignal->get_usercode( $this->id );
if ( $usercode ) {
update_option( 'polldaddy_api_key', $api_key );
update_option( 'crowdsignal_api_key', $api_key );
update_option( 'crowdsignal_user_code', $usercode );
update_option( 'pd-usercode-' . $this->id, $usercode );
delete_option( 'crowdsignal_api_key_secret' );
$connected = true;
} else {
$connected = false;
}
$this->render_partial(
'html-admin-setup-step-2',
array(
'is_connected' => $connected,
)
);
die();
}
if (
isset( $_POST['action'] )
&& $_POST['action'] === 'disconnect'
&& current_user_can( 'edit_others_posts' )
) {
check_admin_referer( 'disconnect-api-key' );
delete_option( 'polldaddy_api_key' );
delete_option( 'crowdsignal_api_key' );
delete_option( 'crowdsignal_user_code' );
delete_option( 'pd-usercode-' . $this->id );
wp_safe_redirect( admin_url( 'options-general.php?page=crowdsignal-settings&msg=disconnected' ) );
}
$this->set_api_user_code();
if ( empty( $this->user_code ) && 'crowdsignal-settings' === $page && 'options' !== $action ) {
// one last try to get the user code automatically if possible
$this->user_code = apply_filters_ref_array( 'polldaddy_get_user_code', array( $this->user_code, &$this ) );
if ( false == $this->user_code && $action != 'restore-account' )
$action = 'signup';
}
require_once WP_POLLDADDY__POLLDADDY_CLIENT_PATH;
wp_enqueue_style( 'admin-styles', plugin_dir_url( __FILE__ ) . '/admin-styles.css', array(), '1.5.12' );
wp_enqueue_style( 'wp-components' );
wp_enqueue_script( 'polls', "{$this->base_url}js/polldaddy.js", array( 'jquery', 'jquery-ui-sortable', 'jquery-form', 'wp-components' ), $this->version );
wp_enqueue_script( 'polls-common', "{$this->base_url}js/common.js", array(), $this->version );
if ( $page == 'polls' ) {
if ( !$this->is_author && in_array( $action, array( 'edit', 'edit-poll', 'create-poll', 'edit-style', 'create-style', 'list-styles', 'options', 'update-options', 'import-account', 'create-block-poll' ) ) ) {//check user privileges has access to action
$action = '';
}
switch ( $action ) {
case 'create-block-poll':
$post_id = wp_insert_post(
array(
'post_title' => esc_html__( 'Crowdsignal blocks in WordPress' ),
'post_content' => '
<!-- wp:paragraph -->
<p>Welcome to this little demo page! We would love to introduce you to our set of Crowdsignal blocks and created this post for you, so that you can test and play with all of them right inside of your editor. </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p><a href="https://wordpress.org/support/article/how-to-use-the-preview-function/">Preview this post</a> if you would like to test the Crowdsignal blocks from your visitors perspective. <em>Oh and please feel free to delete this draft post anytime</em>, it was only created for demo purposes.</p>
<!-- /wp:paragraph -->
<!-- wp:spacer {"height":60} -->
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading -->
<h2>Overview</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Let\'s start with a quick overview of all our current blocks available in your WordPress editor. You can <a href="https://wordpress.com/support/wordpress-editor/">find all these blocks inside your block library via searching</a> for their name or simply by searching "Crowdsignal".</p>
<!-- /wp:paragraph -->
<!-- wp:image {"align":"wide","id":241,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image alignwide size-full"><img src="https://crowdsignal.files.wordpress.com/2021/11/crowdsignalcards.png" alt="" class="wp-image-241"/></figure>
<!-- /wp:image -->
<!-- wp:paragraph -->
<p>If you want to learn more about Crowdsignal please go to <a href="https://crowdsignal.com" data-type="URL" data-id="https://crowdsignal.com">crowdsignal.com</a> and join our little <a href="https://crowdsignalfeedback.wordpress.com/">community</a> all about feedback here.</p>
<!-- /wp:paragraph -->
<!-- wp:spacer {"height":60} -->
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading -->
<h2>Polls</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>We all have opinions! Curious about the opinion of your audience? Start asking with our poll block. It makes creating a poll as fast and simple as listing bullet points.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p> You can choose between a button or a list style for your answer options, and you can fully customize the styling of the block. By default the poll block will support your theme styling, but it’s up to you if you want to keep it. You can customize the style how you want, from font-family to border colours.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Just click in the poll below and start editing. </p>
<!-- /wp:paragraph -->
<!-- wp:crowdsignal-forms/poll {"pollId":"","title":"Demo Poll block","question":"What do you think about this demo page","answers":[{"text":"Super useful","answerId":""},{"text":"Not sure yet","answerId":""},{"text":"I don\'t like it","answerId":""}],"borderWidth":5,"borderRadius":5,"hasBoxShadow":true,"fontFamily":"Open+Sans","className":"is-style-buttons"} /-->
<!-- wp:paragraph -->
<p>And everything else you expect from a Crowdsignal poll is also available — such as setting “single answer” or “multiple answer” choices, a customised confirmation message, poll timeframe, and avoidance of double voting.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Here is a short demo video for how to set up this block, not that you would need it ;) </p>
<!-- /wp:paragraph -->
<!-- wp:video {"src":"https://crowdsignal.files.wordpress.com/2021/11/add-poll-tutorial-720.mp4"} -->
<figure class="wp-block-video"><video controls src="https://crowdsignal.files.wordpress.com/2021/11/add-poll-tutorial-720.mp4"></video></figure>
<!-- /wp:video -->
<!-- wp:spacer {"height":60} -->
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading -->
<h2>Feedback Button</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>You might have spotted it already, in the bottom left corner of this page: Our Feedback button.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>This is a floating button that lives above your site\'s content. Always visible this button makes giving feedback easy! User can send you a message and provide their email address so you could can get back to them. Needless to say that you can fully customize the design and text, including the label of the button itself. Feel free to make it a "Contact me" or "Say hello" button or anything you like.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>And yes, you can change its placement! You can put the button in any corner of your site. Just try it! Click in the feedback and start editing.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Don\'t miss out on your customers\' feedback. Keep your door open anytime and place a feedback button on all your pages. </p>
<!-- /wp:paragraph -->
<!-- wp:video {"src":"https://crowdsignal.files.wordpress.com/2021/11/add-feedback-button-tutorial.mp4"} -->
<figure class="wp-block-video"><video controls src="https://crowdsignal.files.wordpress.com/2021/11/add-feedback-button-tutorial.mp4"></video></figure>
<!-- /wp:video -->
<!-- wp:spacer {"height":60} -->
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading -->
<h2>Voting</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Sometimes we need just quick and fast feedback from our audience. A quick voting button might be all you need. Fully customizable of course.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>There is already a “like” button at the end of a WordPress post that you can click to express satisfaction or agreement. But what if you want to ask readers their opinion on a subject in the middle of a post? Or what if you want to present several ideas and find out which one is the most popular? Wouldn’t it be great to ask readers what they think without having to leave the editor or switch to another service or plugin?</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>That’s what we thought! Say hello to our Voting Block:</p>
<!-- /wp:paragraph -->
<!-- wp:crowdsignal-forms/vote {"pollId":"","title":"Demo Vote block"} -->
<!-- wp:crowdsignal-forms/vote-item {"answerId":"","type":"up","textColor":"#066127","borderColor":"#066127"} /-->
<!-- wp:crowdsignal-forms/vote-item {"answerId":"","type":"down","textColor":"#c6302e","borderColor":"#c6302e"} /-->
<!-- /wp:crowdsignal-forms/vote -->
<!-- wp:paragraph -->
<p>It’s a simple block that adds two voting buttons—thumbs up, thumbs down—to your post wherever you want to place them. Customize the block in different sizes and colors, with or without a border, and with or without a visible vote counter. Put several in a single post, next to different ideas, to see how they stack up for readers. Make the block your own!</p>
<!-- /wp:paragraph -->
<!-- wp:video {"src":"https://crowdsignal.files.wordpress.com/2021/11/add-vote-tutorial.mp4"} -->
<figure class="wp-block-video"><video controls src="https://crowdsignal.files.wordpress.com/2021/11/add-vote-tutorial.mp4"></video></figure>
<!-- /wp:video -->
<!-- wp:spacer {"height":60} -->
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading -->
<h2>Applause</h2>
<!-- /wp:heading -->
<!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://crowdsignal.files.wordpress.com/2021/11/17claps-small.gif" alt=""/></figure>
<!-- /wp:image -->
<!-- wp:paragraph -->
<p>The Applause block is a simpler and more playful version of our Voting block. The main differences are users only being able to give positive feedback and encouraging users to “make as much noise as they want”. Meaning this block does not only allow repeated voting, but even encourages it.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Let your audience make some noise with a big round of applause.</p>
<!-- /wp:paragraph -->
<!-- wp:crowdsignal-forms/applause {"pollId":"","title":"Demo Applause block","answerId":"","size":"large","borderWidth":1,"borderRadius":5} /-->
<!-- wp:paragraph -->
<p><a href="https://wordpress.org/support/article/how-to-use-the-preview-function/">Preview this post</a> and try clapping yourself! It\'s fun.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>The block currently comes in three different sizes, and can be customised with a button-like styling, including a border, border radius and some colour customisation options.</p>
<!-- /wp:paragraph -->
<!-- wp:video {"src": "https://crowdsignal.files.wordpress.com/2021/11/add-applause-block-tutorial.mp4"} -->
<figure class="wp-block-video"><video controls src="https://crowdsignal.files.wordpress.com/2021/11/add-applause-block-tutorial.mp4"></video></figure>
<!-- /wp:video -->
<!-- wp:spacer {"height":60} -->
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading -->
<h2>Embed Surveys & Forms</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>So far we only talked about quick and fast ways to collect feedback or opinions from your audience. But what if you have many questions or want to create simple forms? You can do this with Crowdsignal, too! Create a survey or form on app.crowdsignal.com and embed it into your WordPress post or site. Similar like here:</p>
<!-- /wp:paragraph -->
<!-- wp:embed {"url":"https://crowdsignal.survey.fm/product-market-fit-score","type":"rich","providerNameSlug":"crowdsignal","responsive":true,"align":"wide"} -->
<figure class="wp-block-embed alignwide is-type-rich is-provider-crowdsignal wp-block-embed-crowdsignal"><div class="wp-block-embed__wrapper">
https://crowdsignal.survey.fm/product-market-fit-score
</div></figure>
<!-- /wp:embed -->
<!-- wp:paragraph -->
<p>The Crowdsignal survey above was embedded using our "Single question per page mode." It’s exactly what it sounds like: In this mode, no matter how many questions your survey has, your respondents will always see one question at a time. Single Mode shines when you embed a survey into your website or blog post. Surveys with multiple questions can take up a lot of space, overwhelming your site. If you’re not sure whether your readers will take the survey at all, it disrupts the reading experience. With Single Mode, a survey uses the same amount of space as an image, even a really long survey.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Once they provide an answer (or skip the question), the next question loads. It has a playful feel, like flipping through a slide show. Every answered question feels like progress.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>You can choose between several transition options, and decide whether the questions should move from top to bottom, or from left to right.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p><strong>Ready to create one? Here’s how:</strong></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>- Go to <a href="https://app.crowdsignal.com/dashboard">app.crowdsignal.com</a> (we will log you in with your WordPress.com account - magic ;)) .</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>- Create a new survey.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>- In the Editor, choose “Single Mode” at the top left.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>- Then create as many questions as you like and style your theme.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>- When you are ready click on Sharing and copy the URL of your survey.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>- Go back to your WordPress editor and paste the URL of your survey into your post</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>- Done! Your survey will appear in your post.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Here is a short demo video for you that shows you how it works in less than a minute:</p>
<!-- /wp:paragraph -->
<!-- wp:video {"src": "https://crowdsignal.files.wordpress.com/2021/11/add-survey-tutorial-yt.mp4"} -->
<figure class="wp-block-video"><video controls src="https://crowdsignal.files.wordpress.com/2021/11/add-survey-tutorial-yt.mp4"></video></figure>
<!-- /wp:video -->
<!-- wp:spacer {"height":60} -->
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading -->
<h2>Measure NPS</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>While we are driving our projects, working hard on our products, we all wonder: How are we doing? Are people satisfied with our service? Are we doing better since last month? </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Sometimes you want to measure your progress over time. <a href="https://crowdsignal.com/2021/03/16/measure-nps/">Measure and monitor the customer satisfaction and growth potential of your product with a Net Promoter Score</a>. </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>We have built a Gutenberg block for you that makes it easier than ever before to track your Net Promoter Score on WordPress. If you have <a href="https://wordpress.org/support/article/how-to-use-the-preview-function/">previewed this post</a> before, you might have seen the NPS question already in a modal window. </p>
<!-- /wp:paragraph -->
<!-- wp:crowdsignal-forms/nps {"surveyId":"","title":"Demo NPS block","viewThreshold":"2"} /-->
<!-- wp:paragraph -->
<p>The moment you add the block, you are basically done. The design of the block is based on your site’s theme. You can still customize the styling of the block, or edit the questions, but that might not even be necessary.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>To get the most out of your NPS data, it is important to show the question only to users that are already familiar with your service or product. You can configure the block to only show to repeat visitors. It’s more likely you will get feedback from someone who knows what they are talking about, and you can make sure new users are not interrupted during their first visit to your site.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>After you publish the block go to the results page of the block and monitor your results. We have built a special results page for you to track your NPS score and to analyse any additional feedback. </p>
<!-- /wp:paragraph -->
<!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://s0.wp.com/wp-content/themes/a8c/crowd-signal/assets/images/AnalyseResults.png" alt=""/></figure>
<!-- /wp:image -->
<!-- wp:paragraph -->
<p>We provide an analytics dashboard with our block that automatically calculates the Net Promoter Score for you in real-time and allows you to monitor your score over time. Are the differences geographic? Filter your results based on countries.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>By the way, did you know you also can get email notifications or a ping in your Slack channel any time you get an NPS rating? Just click on the little “connect” button on your results page.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Here is a quick tutorial video on how it works.</p>
<!-- /wp:paragraph -->
<!-- wp:video {"src": "https://crowdsignal.files.wordpress.com/2021/11/add-nps-tutorial-long-3.mp4"} -->
<figure class="wp-block-video"><video controls src="https://crowdsignal.files.wordpress.com/2021/11/add-nps-tutorial-long-3.mp4"></video></figure>
<!-- /wp:video -->
<!-- wp:crowdsignal-forms/feedback {"surveyId":"","title":"Demo Feedback block"} /-->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
',
)
);
if ( ! is_wp_error( $post_id ) ) {
wp_safe_redirect( admin_url( 'post.php?post=' . intval( $post_id ) . '&action=edit' ) );
} else {
// admin.php?page=polls
// wp_safe_redirect( admin_url( 'admin.php?page=polls' ) );
}
break;
case 'edit' :
case 'edit-poll' :
case 'create-poll' :
case 'add-media' :
wp_enqueue_script( 'media-upload', array(), $this->version );
wp_enqueue_script( 'polls-style', "{$this->base_url}js/poll-style-picker.js", array( 'polls', 'polls-common' ), $this->version );
if ( $action == 'create-poll' )
$plugin_page = 'polls&action=create-poll';
break;
case 'edit-style' :
case 'create-style' :
wp_enqueue_script( 'polls-style', "{$this->base_url}js/style-editor.js", array( 'polls', 'polls-common' ), $this->version );
wp_enqueue_script( 'polls-style-color', "{$this->base_url}js/jscolor.js", array(), $this->version );
wp_enqueue_style( 'polls', "{$this->base_url}css/style-editor.css", array(), $this->version );
$plugin_page = 'polls&action=list-styles';
break;
case 'list-styles' :
$plugin_page = 'polls&action=list-styles';
break;
}//end switch
} elseif ( $page == 'crowdsignal-settings' ) {
$plugin_page = 'crowdsignal-settings';
} elseif ( $page == 'ratings' ) {
if ( empty( $action ) ) {
$action = 'reports';
}
$plugin_page = 'ratings&action=reports';
} elseif ( $page == 'ratingsettings' ) {
$plugin_page = 'ratingsettings';
wp_enqueue_script( 'rating-text-color', "{$this->base_url}js/jscolor.js", array(), $this->version );
wp_enqueue_script( 'ratings', "{$this->base_url}js/rating.js", array(), $this->version );
wp_localize_script( 'polls-common', 'adminRatingsL10n', array(
'star_colors' => __( 'Star Colors', 'polldaddy' ), 'star_size' => __( 'Star Size', 'polldaddy' ),
'nero_type' => __( 'Nero Type', 'polldaddy' ), 'nero_size' => __( 'Nero Size', 'polldaddy' ), ) );
}
wp_enqueue_style( 'polldaddy', "{$this->base_url}css/polldaddy.css", array(), $this->version );
wp_enqueue_script( 'admin-forms' );
add_thickbox();
if ( isset( $_GET['iframe'] ) ) {
add_action( 'admin_head', array( &$this, 'hide_admin_menu' ) );
}
if ( isset( $wp_locale->text_direction ) && 'rtl' == $wp_locale->text_direction )
wp_enqueue_style( 'polls-rtl', "{$this->base_url}css/polldaddy-rtl.css", array( 'global', 'wp-admin' ), $this->version );
add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
add_action( 'admin_notices', array( &$this, 'management_page_notices' ) );
$query_args = array();
$args = array();
$allowedtags = array(
'a' => array(
'href' => array(),
'title' => array(),
'target' => array() ),
'img' => array(
'alt' => array(),
'align' => array(),
'border' => array(),
'class' => array(),
'height' => array(),
'hspace' => array(),
'longdesc' => array(),
'vspace' => array(),
'src' => array(),
'width' => array() ),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'blockquote' => array( 'cite' => array() ),
'q' => array( 'cite' => array() ),
'b' => array(),
'cite' => array(),
'em' => array(),
'i' => array(),
'strike' => array(),
'strong' => array()
);
$is_POST = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] );
if ( 'polls' === $page || 'crowdsignal-settings' === $page ) {
switch ( $action ) {
case 'multi-account':
check_admin_referer( 'polldaddy-reset' . $this->id );
if ( ! isset( $_POST['crowdsignal_multiuser'] ) ) {
delete_option( 'polldaddy_usercode_user' );
}
break;
case 'reset-account' : // reset everything
global $current_user;
check_admin_referer( 'polldaddy-reset' . $this->id );
$fields = array( 'polldaddy_api_key', 'pd-rating-comments', 'pd-rating-comments-id', 'pd-rating-comments-pos', 'pd-rating-exclude-post-ids', 'pd-rating-pages', 'pd-rating-pages-id', 'pd-rating-posts', 'pd-rating-posts-id', 'pd-rating-posts-index', 'pd-rating-posts-index-id', 'pd-rating-posts-index-pos', 'pd-rating-posts-pos', 'pd-rating-title-filter', 'pd-rating-usercode', 'pd-rich-snippets', 'pd-usercode-' . $current_user->ID );
$msg = __( "You have just reset your Polldaddy connection settings." ) . "\n\n";
foreach( $fields as $field ) {
$value = get_option( $field );
if ( $value != false ) {
$settings[ $field ] = $value;
$msg .= "$field: $value\n";
delete_option( $field );
}
}
if ( isset( $_POST[ 'email' ] ) )
wp_mail( $current_user->user_email, "Crowdsignal Settings", $msg );
update_option( 'polldaddy_settings', $settings );
break;
case 'restore-account' : // restore everything
global $current_user;
check_admin_referer( 'polldaddy-restore' . $this->id );
$previous_settings = get_option( 'polldaddy_settings' );
foreach( $previous_settings as $key => $value )
update_option( $key, $value );
delete_option( 'polldaddy_settings' );
break;
case 'restore-ratings' : // restore ratings
global $current_user;
check_admin_referer( 'polldaddy-restore-ratings' . $this->id );
$previous_settings = get_option( 'polldaddy_settings' );
$fields = array( 'pd-rating-comments', 'pd-rating-comments-id', 'pd-rating-comments-pos', 'pd-rating-exclude-post-ids', 'pd-rating-pages', 'pd-rating-pages-id', 'pd-rating-posts', 'pd-rating-posts-id', 'pd-rating-posts-index', 'pd-rating-posts-index-id', 'pd-rating-posts-index-pos', 'pd-rating-posts-pos', 'pd-rating-title-filter' );
foreach( $fields as $key ) {
if ( isset( $previous_settings[ $key ] ) )
update_option( $key, $previous_settings[ $key ] );
}
break;
case 'signup' : // sign up for first time
case 'account' : // reauthenticate
case 'import-account' : // reauthenticate
if ( !$is_POST )
return;
check_admin_referer( 'polldaddy-account' );
$this->user_code = '';
global $wp_version;
if ( version_compare( $wp_version, '4.2', '<' ) ) {
delete_option( 'pd-usercode-' . $this->id );
add_option( 'pd-usercode-' . $this->id, '', false );
} else {
update_option( 'pd-usercode-' . $this->id, '', false );
}
if ( $new_args = $this->management_page_load_signup() )
$query_args = array_merge( $query_args, $new_args );
if ( $this->errors->get_error_codes() )
return false;
$query_args['message'] = 'imported-account';
wp_reset_vars( array( 'action' ) );
if ( !empty( $_GET['reaction'] ) )
$query_args['action'] = $_GET['reaction'];
elseif ( !empty( $_GET['action'] ) && 'account' == $_GET['action'] )
$query_args['action'] = $_GET['action'];
else
$query_args['action'] = false;
if ( $action == 'import-account' )
$query_args[ 'action' ] = 'options'; // make sure we redirect back to the right page.
break;
case 'delete' :
if ( empty( $poll ) )
return;
if ( is_array( $poll ) )
check_admin_referer( 'action-poll_bulk' );
else
check_admin_referer( "delete-poll_$poll" );
$polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
foreach ( (array) $_REQUEST['poll'] as $poll_id ) {
$polldaddy->reset();
$poll_object = $polldaddy->get_poll( $poll_id );
if ( !$this->can_edit( $poll_object ) ) {
$this->errors->add( 'permission', __( 'You are not allowed to delete this poll.', 'polldaddy' ) );
return false;
}
// Send Poll Author credentials
if ( !empty( $poll_object->_owner ) && $this->id != $poll_object->_owner ) {
$polldaddy->reset();
if ( !$userCode = $polldaddy->get_usercode( $poll_object->_owner ) ) {
$this->errors->add( 'no_usercode', __( 'Invalid Poll Author', 'polldaddy' ) );
}
$polldaddy->userCode = $userCode;
}
$polldaddy->reset();
$polldaddy->delete_poll( $poll_id );
}