*/
class Survey extends Base {
public $slug;
public $name;
public $base_file;
public $notice_heading;
public $notice_message;
public $notice_button_text;
public $notice_delay = 2 * DAY_IN_SECONDS;
public function __construct( $plugin ) {
$this->plugin = $plugin;
$this->server = $this->plugin['server'];
$this->slug = $this->plugin['TextDomain'];
$this->name = $this->plugin['Name'];
$this->api_url = "{$this->server}/wp-json/codexpert-lead/v1.0/";
$this->notice_heading = '
' . sprintf( __( 'Thanks for using \'%s\'', 'codexpert' ), $this->name ) . '
';
$this->notice_message = '
' . __( 'We want to know what type of sites use this plugin. Users\' satisfaction is our first priority and we\'re continuously working on it. This is why we need some information so that we can improve it even more. Help us with your site URL and a few basic information. It doesn\'t include your password or any secret data. Would you like to help us?', 'codexpert' ) . '
';
$this->notice_button_text = __( 'Okay. Don\'t bother me again!', 'codexpert' );
self::hooks();
}
public function hooks(){
$this->activate( 'activation' );
$this->deactivate( 'deactivation' );
$this->action( 'admin_enqueue_scripts', 'enqueue_scripts', 99 );
$this->action( 'admin_notices', 'admin_notices' );
$this->priv( "{$this->slug}_survey", 'survey' );
}
/**
* Supports HTML
*/
public function set_heading( $heading = null ) {
$this->notice_heading = $heading;
}
public function get_heading() {
return $this->notice_heading;
}
/**
* Supports HTML
*/
public function set_message( $message = null ) {
$this->notice_message = $message;
}
public function get_message() {
return $this->notice_message;
}
/**
* Does not support noHTML
*/
public function set_button_text( $button_text = null ) {
$this->notice_button_text = $button_text;
}
public function get_button_text() {
return $this->notice_button_text;
}
/**
* Set a delay for the notice
*/
public function set_delay( $delay ) {
$this->notice_delay = $delay;
}
public function get_delay() {
return $this->notice_delay;
}
/**
* Trigger when activates
*
*/
public function activation() {
if( get_option( "{$this->slug}_survey_agreed" ) == 1 ) :
$endpoint = $this->api_url . 'update-lead';
$params = array(
'item' => $this->slug,
'siteurl' => get_option( 'siteurl' ),
'is_active' => 1,
);
$endpoint = add_query_arg( $params, $endpoint );
wp_remote_get( $endpoint );
endif;
if( get_option( "{$this->slug}_installed" ) == '' ) :
update_option( "{$this->slug}_installed", time() );
endif;
}
/**
* Trigger when deactivates
*
*/
public function deactivation() {
if( get_option( "{$this->slug}_survey_agreed" ) == 1 ) :
$endpoint = $this->api_url . 'update-lead';
$params = array(
'item' => $this->slug,
'siteurl' => get_option( 'siteurl' ),
'is_active' => 0,
);
$endpoint = add_query_arg( $params, $endpoint );
wp_remote_get( $endpoint );
endif;
}
public function enqueue_scripts() {
wp_enqueue_style( 'codexpert-product-survey', plugins_url( 'assets/css/survey.css', __FILE__ ), [], $this->plugin['Version'] );
wp_enqueue_script( 'codexpert-product-survey', plugins_url( 'assets/js/survey.js', __FILE__ ), [ 'jquery' ], $this->plugin['Version'], true );
}
/**
* Show admin notices
*
*/
public function admin_notices() {
if( get_option( "{$this->slug}_survey" ) != 1 && ( get_option( "{$this->slug}_installed" ) < time() - $this->get_delay() ) ) :
?>