| 1 |
<?php defined( 'ABSPATH' ) or die(); |
| 2 |
|
| 3 |
class Brizy_Admin_Feedback { |
| 4 |
|
| 5 |
/** |
| 6 |
* Brizy_Admin_Feedback constructor. |
| 7 |
*/ |
| 8 |
public function __construct() { |
| 9 |
add_action( 'wp_ajax_brizy-dismiss-notice', [ $this, 'ajax_dismiss_notice' ] ); |
| 10 |
add_action( 'wp_ajax_brizy-send-feedback', [ $this, 'ajax_send_feedback' ] ); |
| 11 |
add_action( 'admin_notices', [ $this, 'admin_notices' ] ); |
| 12 |
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); |
| 13 |
add_action( 'admin_footer', [ $this, 'admin_footer' ] ); |
| 14 |
} |
| 15 |
|
| 16 |
public function admin_notices() { |
| 17 |
|
| 18 |
if ( 'dismissed' == get_user_meta( get_current_user_id(), 'brizy-notice-rating', true ) || get_transient( 'brizy-notice-rating' ) ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
if ( get_transient( 'brizy_admin_notice' ) !== false ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
?> |
| 27 |
|
| 28 |
<div class="brz-notice notice is-dismissible"> |
| 29 |
<div class="brz-notice-container"> |
| 30 |
<div class="brz-notice-image"> |
| 31 |
<img src="<?php echo plugins_url( 'static/img/logo.svg', __FILE__ ) ?>" alt="brizy-logo"> |
| 32 |
</div> |
| 33 |
<div class="brz-notice-content"> |
| 34 |
<div class="brz-notice-heading"> |
| 35 |
<?php esc_html_e( 'Hello! Seems like you are using Brizy to build your website - Thanks a lot!', 'brizy' ); ?> |
| 36 |
</div> |
| 37 |
<?php esc_html_e( 'Could you please do us a BIG favor and give it a 5-star rating on WordPress? This would boost our motivation and help other users make a comfortable decision while choosing the Brizy plugin.', 'brizy' ); ?> |
| 38 |
<br/> |
| 39 |
<div class="brz-review-notice-container"> |
| 40 |
<a href="https://wordpress.org/support/plugin/brizy/reviews/?filter=5#new-post" class="brz-review-deserve button-primary" target="_blank"> |
| 41 |
<?php esc_html_e( 'Ok, you deserve it', 'brizy' ); ?> |
| 42 |
</a> |
| 43 |
<span class="dashicons dashicons-calendar"></span> |
| 44 |
<a href="#" class="brz-review-later"> |
| 45 |
<?php esc_html_e( 'Nope, maybe later', 'brizy' ); ?> |
| 46 |
</a> |
| 47 |
<span class="dashicons dashicons-smiley"></span> |
| 48 |
<a href="#" class="brz-review-done"> |
| 49 |
<?php esc_html_e( 'I already did', 'brizy' ); ?> |
| 50 |
</a> |
| 51 |
</div> |
| 52 |
</div> |
| 53 |
</div> |
| 54 |
</div> |
| 55 |
|
| 56 |
<?php |
| 57 |
} |
| 58 |
|
| 59 |
public function ajax_dismiss_notice() { |
| 60 |
|
| 61 |
check_ajax_referer( 'brizy-admin-nonce', 'nonce' ); |
| 62 |
|
| 63 |
if ( $_POST['repeat'] == 'true' ) { |
| 64 |
set_transient( 'brizy-notice-rating', true, WEEK_IN_SECONDS ); |
| 65 |
} else { |
| 66 |
update_user_meta( get_current_user_id(), 'brizy-notice-rating', 'dismissed' ); |
| 67 |
} |
| 68 |
|
| 69 |
wp_send_json_success(); |
| 70 |
} |
| 71 |
|
| 72 |
public function ajax_send_feedback() { |
| 73 |
|
| 74 |
check_ajax_referer( 'brizy-admin-nonce', 'nonce' ); |
| 75 |
|
| 76 |
parse_str( $_POST['form'], $form ); |
| 77 |
|
| 78 |
$reason_key = $form['reason_key']; |
| 79 |
|
| 80 |
$body = [ |
| 81 |
'version' => BRIZY_VERSION, |
| 82 |
'site_lang' => get_bloginfo( 'language' ), |
| 83 |
'feedback_key' => $reason_key |
| 84 |
]; |
| 85 |
|
| 86 |
if ( ! empty( $form[ 'reason_' . $reason_key ] ) ) { |
| 87 |
$body['feedback'] = sanitize_text_field( $form[ 'reason_' . $reason_key ] ); |
| 88 |
} |
| 89 |
|
| 90 |
wp_remote_post( 'http://test.themefuse.com/', [ |
| 91 |
'timeout' => 30, |
| 92 |
'body' => $body, |
| 93 |
] ); |
| 94 |
|
| 95 |
wp_send_json_success(); |
| 96 |
} |
| 97 |
|
| 98 |
public function admin_enqueue_scripts() { |
| 99 |
|
| 100 |
if ( ! $this->is_plugins_page() ) { |
| 101 |
return; |
| 102 |
} |
| 103 |
|
| 104 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 105 |
wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 106 |
} |
| 107 |
|
| 108 |
public function admin_footer() { |
| 109 |
|
| 110 |
if ( ! $this->is_plugins_page() ) { |
| 111 |
return; |
| 112 |
} |
| 113 |
|
| 114 |
$deactivate_reasons = [ |
| 115 |
'no_longer_needed' => [ |
| 116 |
'title' => __( 'I no longer need the plugin', 'brizy' ), |
| 117 |
'input_placeholder' => '', |
| 118 |
], |
| 119 |
'found_a_better_plugin' => [ |
| 120 |
'title' => __( 'I found a better plugin', 'brizy' ), |
| 121 |
'input_placeholder' => __( 'Please share which plugin', 'brizy' ), |
| 122 |
], |
| 123 |
'couldnt_get_the_plugin_to_work' => [ |
| 124 |
'title' => __( 'I couldn\'t get the plugin to work', 'brizy' ), |
| 125 |
'input_placeholder' => '', |
| 126 |
], |
| 127 |
'temporary_deactivation' => [ |
| 128 |
'title' => __( 'It\'s a temporary deactivation', 'brizy' ), |
| 129 |
'input_placeholder' => '', |
| 130 |
], |
| 131 |
'brizy_pro' => [ |
| 132 |
'title' => __( 'I have Brizy Pro', 'brizy' ), |
| 133 |
'input_placeholder' => '', |
| 134 |
'alert' => __( 'Wait! Don\'t deactivate Brizy. You have to activate both Brizy and Brizy Pro in order for the plugin to work.', 'brizy' ), |
| 135 |
], |
| 136 |
'other' => [ |
| 137 |
'title' => __( 'Other', 'brizy' ), |
| 138 |
'input_placeholder' => __( 'Please share the reason', 'brizy' ), |
| 139 |
], |
| 140 |
]; |
| 141 |
|
| 142 |
?> |
| 143 |
|
| 144 |
<div id="brz-deactivate-feedback-dialog" class="hidden"> |
| 145 |
<div class="brz-deactivate-feedback-dialog-header"> |
| 146 |
<img class="brz-deactivate-feedback-dialog-logo" src="<?php echo plugins_url( 'static/img/logo.svg', __FILE__ ) ?>" alt="brizy-logo"> |
| 147 |
<span class="brz-deactivate-feedback-dialog-header-title"><?php echo __( 'Quick Feedback', 'brizy' ); ?></span> |
| 148 |
</div> |
| 149 |
<form class="brz-deactivate-feedback-dialog-form" method="post"> |
| 150 |
<div class="brz-deactivate-feedback-dialog-form-caption"> |
| 151 |
<?php echo __( 'If you have a moment, please share why you are deactivating Brizy:', 'brizy' ); ?> |
| 152 |
</div> |
| 153 |
<div class="brz-deactivate-feedback-dialog-form-body"> |
| 154 |
<?php foreach ( $deactivate_reasons as $reason_key => $reason ) : ?> |
| 155 |
<div class="brz-deactivate-feedback-dialog-input-wrapper"> |
| 156 |
<input id="brz-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="brz-deactivate-feedback-dialog-input" type="radio" name="reason_key" value="<?php echo esc_attr( $reason_key ); ?>" /> |
| 157 |
<label for="brz-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="brz-deactivate-feedback-dialog-label"><?php echo esc_html( $reason['title'] ); ?></label> |
| 158 |
<?php if ( ! empty( $reason['input_placeholder'] ) ) : ?> |
| 159 |
<input class="brz-feedback-text hidden" type="text" name="reason_<?php echo esc_attr( $reason_key ); ?>" placeholder="<?php echo esc_attr( $reason['input_placeholder'] ); ?>" /> |
| 160 |
<?php endif; ?> |
| 161 |
<?php if ( ! empty( $reason['alert'] ) ) : ?> |
| 162 |
<div class="brz-feedback-text-alert brz-feedback-text hidden"><?php echo esc_html( $reason['alert'] ); ?></div> |
| 163 |
<?php endif; ?> |
| 164 |
</div> |
| 165 |
<?php endforeach; ?> |
| 166 |
</div> |
| 167 |
</form> |
| 168 |
</div> |
| 169 |
<?php |
| 170 |
} |
| 171 |
|
| 172 |
private function is_plugins_page() { |
| 173 |
global $pagenow; |
| 174 |
|
| 175 |
return 'plugins.php' === $pagenow; |
| 176 |
} |
| 177 |
} |
| 178 |
|