-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvote.php
More file actions
101 lines (81 loc) · 4.88 KB
/
vote.php
File metadata and controls
101 lines (81 loc) · 4.88 KB
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
<?php
//delete_option( 'sm_vote' );
class SM_Vote {
public function __construct() {
add_action( 'load-plugins.php', array( __CLASS__, 'vote_init' ) );
add_action( 'wp_ajax_sm_vote', array( __CLASS__, 'vote' ) );
}
public static function vote_init() {
/*$sm_votes = get_option( 'sm_vote' );
!is_array($sm_votes) ? $sm_votes = array() : '';*/
//if ( in_array( $vote, array( 'yes', 'tweet' , 'facebook', 'suggest', 'no' ) ) || !$timein ) return;
add_action( 'admin_notices', array( __CLASS__, 'message' ) );
add_action( 'admin_head', array( __CLASS__, 'register' ) );
add_action( 'admin_footer', array( __CLASS__, 'enqueue' ) );
}
public static function register() {
wp_register_style( 'sm-vote', SHORTCODE_MAKER_ASSET_PATH.'/css/vote.css', false );
wp_register_script( 'sm-vote', SHORTCODE_MAKER_ASSET_PATH.'/js/vote.js', array( 'jquery' ), false, true );
}
public static function enqueue() {
wp_enqueue_style( 'sm-vote' );
wp_enqueue_script( 'sm-vote' );
}
public static function message() {
$timein = time() > ( get_option( 'sm_later' ) );
if ( !$timein ) return;
$sm_votes = get_option( 'sm_vote' );
!is_array($sm_votes) ? $sm_votes = array() : '';
if( isset( $sm_votes['no'] ) ){
return;
} else {
$btn_str = '';
if( !isset( $sm_votes['yes'] ) ) {
$btn_str .= '<a href="'.admin_url( 'admin-ajax.php' ).'?action=sm_vote&vote=yes" class="sm-vote-action sm-vote-button button button-small button-primary" data-action="http://wordpress.org/support/view/plugin-reviews/shortcode-maker?rate=5#postform">'.__( 'Rate us', 'sm' ).'</a>';
}
if( !isset( $sm_votes['tweet'] ) ) {
$btn_str .= '<a href="'.admin_url( 'admin-ajax.php' ).'?action=sm_vote&vote=tweet" class="sm-vote-action sm-vote-button button button-small" data-action="http://twitter.com/share?url=http://bit.ly/2mXDU5t&text='.urlencode( __( 'Shortcode Maker - must have WordPress plugin #shortcodemaker', 'sm' ) ).'">'.__( 'Tweet', 'sm' ).'</a>';
}
if( !isset( $sm_votes['facebook'] ) ) {
$btn_str .= '<a href="'.admin_url( 'admin-ajax.php' ).'?action=sm_vote&vote=facebook" class="sm-vote-action sm-vote-button button button-small" data-action="http://facebook.com/sharer?u=http://bit.ly/2mXDU5t&text='.urlencode( __( 'Shortcode Maker - must have WordPress plugin #shortcodemaker', 'sm' ) ).'">'.__( 'Share on facebook', 'sm' ).'</a>';
}
if( !isset( $sm_votes['no'] ) ) {
$btn_str .= '<a href="'.admin_url( 'admin-ajax.php' ).'?action=sm_vote&vote=no" class="sm-vote-action sm-vote-button sm-cancel-button button button-small">'.__( 'No, thanks', 'sm' ).'</a>';
}
$btn_str .= '<a href="'.admin_url( 'admin-ajax.php' ).'?action=sm_vote&vote=suggest" class="sm-vote-action sm-vote-button sugget-button button button-small" data-action="http://cybercraftit.com/contact/">'.__( 'Suggest us', 'sm' ).'</a>';
if( !isset( $sm_votes['later'] ) ) {
$btn_str .= '<a href="'.admin_url( 'admin-ajax.php' ).'?action=sm_vote&vote=later" class="sm-vote-action sm-vote-button button button-small">'.__( 'Remind me later', 'sm' ).'</a>';
}
}
if( !empty( $btn_str ) ) :
?>
<div class="sm-vote">
<div class="sm-vote-wrap">
<div class="sm-vote-gravatar">
<a href="http://cybercraftit.com/" target="_blank"><img src="http://2.gravatar.com/avatar/b81a0fdd8fafcb4148aa8c5b41e56431?s=64&d=mm&r=g" alt="<?php _e( 'Mithu A Quayium', 'sm' ); ?>" width="50" height="50"></a>
</div>
<div class="sm-vote-message">
<p><?php _e( '<h3>We Need Your Support</h3>Thanks for using <strong>Shortcode Maker</strong>.<br>If you find this plugin useful, please rate us, share and tweet to let
others know about it, and help us improving it by your valuable suggestions .<br><b>Thank you!</b>', 'sm' ); ?></p>
<p>
<?php echo $btn_str; ?>
</p>
</div>
<div class="sm-vote-clear"></div>
</div>
</div>
<?php
endif;
}
public static function vote() {
$vote = sanitize_key( $_GET['vote'] );
if ( !is_user_logged_in() || !in_array( $vote, array( 'yes', 'tweet' , 'facebook', 'no', 'suggest', 'later' ) ) ) die( 'error' );
$sm_votes = get_option( 'sm_vote' );
!is_array($sm_votes)?$sm_votes = array() : '';
$sm_votes[$vote] = $vote;
update_option( 'sm_vote', $sm_votes );
if ( $vote === 'later' ) update_option( 'sm_later', time() + 60*60*24*3 );
die( 'OK: ' . $vote );
}
}
new SM_Vote();