name = $name; $this->plugin = $plugin; // Don't run deactivation survey on dev sites. if ( $this->is_dev_url() ) { return; } add_action( 'admin_print_scripts', array( $this, 'js' ), 20 ); add_action( 'admin_print_scripts', array( $this, 'css' ) ); add_action( 'admin_footer', array( $this, 'modal' ) ); } /** * Checks if current site is a development one. * * @since 1.2.0 * @return bool */ public function is_dev_url() { // If it is an AM dev site, return false, so we can see them on our dev sites. if ( defined ('AWESOMEMOTIVE_DEV_MODE' ) && AWESOMEMOTIVE_DEV_MODE ) { return false; } $url = network_site_url( '/' ); $is_local_url = false; // Trim it up $url = strtolower( trim( $url ) ); // Need to get the host...so let's add the scheme so we can use parse_url if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) { $url = 'http://' . $url; } $url_parts = parse_url( $url ); $host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false; if ( ! empty( $url ) && ! empty( $host ) ) { if ( false !== ip2long( $host ) ) { if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { $is_local_url = true; } } else if ( 'localhost' === $host ) { $is_local_url = true; } $tlds_to_check = array( '.dev', '.local', ':8888' ); foreach ( $tlds_to_check as $tld ) { if ( false !== strpos( $host, $tld ) ) { $is_local_url = true; continue; } } if ( substr_count( $host, '.' ) > 1 ) { $subdomains_to_check = array( 'dev.', '*.staging.', 'beta.', 'test.' ); foreach ( $subdomains_to_check as $subdomain ) { $subdomain = str_replace( '.', '(.)', $subdomain ); $subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain ); if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) { $is_local_url = true; continue; } } } } return $is_local_url; } /** * Checks if current admin screen is the plugins page. * * @since 1.0.0 * @return bool */ public function is_plugin_page() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false; if ( empty( $screen ) ) { return false; } return ( ! empty( $screen->id ) && in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ); } /** * Survey javascript. * * @since 1.0.0 */ public function js() { if ( ! $this->is_plugin_page() ) { return; } ?> is_plugin_page() ) { return; } ?> is_plugin_page() ) { return; } $options = array( 1 => array( 'title' => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ), ), 2 => array( 'title' => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ), 'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ), ), 3 => array( 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ), ), 4 => array( 'title' => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ), ), 5 => array( 'title' => esc_html__( 'Other', 'google-analytics-for-wordpress' ), 'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ), ), ); ?>