SatisfactionSurvey.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Reach\Admin\Surveys; |
| 4 | |
| 5 | use Hostinger\Reach\Api\ApiKeyManager; |
| 6 | use Hostinger\Reach\Functions; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | die; |
| 10 | } |
| 11 | |
| 12 | class SatisfactionSurvey extends Survey { |
| 13 | protected function should_load_survey(): bool { |
| 14 | if ( ! parent::should_load_survey() ) { |
| 15 | return false; |
| 16 | } |
| 17 | |
| 18 | return $this->is_hostinger_page() && ( $this->has_any_user_action() || $this->has_been_five_days_since_connection() ); |
| 19 | } |
| 20 | |
| 21 | protected function get_score_question(): string { |
| 22 | return __( 'How would you rate your experience with Hostinger Reach so far?', 'hostinger-reach' ); |
| 23 | } |
| 24 | |
| 25 | protected function get_comment_question(): string { |
| 26 | return __( 'Any ideas or feedback to help us improve Hostinger Reach?', 'hostinger-reach' ); |
| 27 | } |
| 28 | |
| 29 | protected function get_id(): string { |
| 30 | return 'hostinger_reach_survey_satisfaction'; |
| 31 | } |
| 32 | |
| 33 | protected function get_location(): string { |
| 34 | return 'wordpress_hostinger_reach'; |
| 35 | } |
| 36 | |
| 37 | protected function has_any_user_action(): bool { |
| 38 | return get_option( Functions::HOSTINGER_REACH_HAS_USER_ACTION, false ); |
| 39 | } |
| 40 | |
| 41 | protected function has_been_five_days_since_connection(): bool { |
| 42 | $connection_time = get_option( ApiKeyManager::API_CONNECTION_TIME_NAME, null ); |
| 43 | if ( is_null( $connection_time ) ) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | return ( time() - $connection_time ) >= ( 5 * self::DAY_IN_SECONDS ); |
| 48 | } |
| 49 | |
| 50 | protected function is_hostinger_page(): bool { |
| 51 | return str_contains( $_SERVER['REQUEST_URI'], 'hostinger' ); |
| 52 | } |
| 53 | |
| 54 | protected function get_review_url(): string { |
| 55 | return 'https://wordpress.org/support/plugin/hostinger-reach/reviews/#new-post'; |
| 56 | } |
| 57 | |
| 58 | protected function get_review_min_required_score(): int { |
| 59 | return 7; |
| 60 | } |
| 61 | } |
| 62 |