BlockCompatibility.php
1 week ago
FlexibleWishlistReview.php
1 week ago
Notice.php
1 week ago
NoticeIntegration.php
1 week ago
ReviewNotice.php
1 week ago
ReviewNotice.php
80 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FCF\Free\Notice; |
| 4 | |
| 5 | use FcfVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin; |
| 6 | |
| 7 | /** |
| 8 | * Notice about review. |
| 9 | */ |
| 10 | class ReviewNotice implements Notice { |
| 11 | |
| 12 | const ACTIVATION_OPTION_NAME = 'plugin_activation_%s'; |
| 13 | const NOTICE_OPTION_NAME = 'notice_review_%s'; |
| 14 | const NOTICE_NAME = 'notice_review'; |
| 15 | |
| 16 | /** |
| 17 | * @var AbstractPlugin |
| 18 | */ |
| 19 | private $plugin; |
| 20 | |
| 21 | public function __construct( AbstractPlugin $plugin ) { |
| 22 | $this->plugin = $plugin; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * {@inheritdoc} |
| 27 | */ |
| 28 | public function get_notice_name(): string { |
| 29 | return self::NOTICE_NAME; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * {@inheritdoc} |
| 34 | */ |
| 35 | public function is_active(): bool { |
| 36 | $option_notice = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() ); |
| 37 | $notice_date = strtotime( get_option( $option_notice, false ) ); |
| 38 | $min_date = strtotime( current_time( 'mysql' ) ); |
| 39 | |
| 40 | if ( ( basename( $_SERVER['PHP_SELF'] ) !== 'index.php' ) // phpcs:ignore |
| 41 | || ( ( $notice_date !== false ) && ( $notice_date > $min_date ) ) ) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | $option_activation = sprintf( self::ACTIVATION_OPTION_NAME, $this->plugin->get_plugin_file_path() ); |
| 46 | $activation_date = strtotime( get_option( $option_activation, current_time( 'mysql' ) ) ); |
| 47 | $min_date = strtotime( current_time( 'mysql' ) . ' -7 days' ); |
| 48 | |
| 49 | return ( $activation_date <= $min_date ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * {@inheritdoc} |
| 54 | */ |
| 55 | public function get_template_path(): string { |
| 56 | return 'notices/review'; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * {@inheritdoc} |
| 61 | */ |
| 62 | public function get_vars_for_view(): array { |
| 63 | return []; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * {@inheritdoc} |
| 68 | */ |
| 69 | public function set_notice_as_hidden( bool $is_permanently ) { |
| 70 | $option_name = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() ); |
| 71 | $notice_time = strtotime( current_time( 'mysql' ) . ( ( $is_permanently ) ? ' +10 years' : ' +1 month' ) ); |
| 72 | $notice_date = gmdate( 'Y-m-d H:i:s', $notice_time ); |
| 73 | |
| 74 | update_option( $option_name, $notice_date, true ); |
| 75 | } |
| 76 | |
| 77 | public function add_notice_scripts(): void { |
| 78 | } |
| 79 | } |
| 80 |