UpgradeNotice.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonorDashboards\Admin; |
| 4 | |
| 5 | class UpgradeNotice |
| 6 | { |
| 7 | |
| 8 | /** |
| 9 | * Register upgrade notice |
| 10 | * |
| 11 | * @since 2.10.0 |
| 12 | * @return void |
| 13 | * |
| 14 | */ |
| 15 | public function register() |
| 16 | { |
| 17 | if ($this->shouldRenderOutput()) { |
| 18 | $this->renderOutput(); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Return true if notice should be rendered, false if not |
| 24 | * |
| 25 | * @since 2.10.0 |
| 26 | * @return boolean |
| 27 | * |
| 28 | */ |
| 29 | protected function shouldRenderOutput() |
| 30 | { |
| 31 | if ( ! give_is_admin_page()) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | $donorDashboardPageIsSet = ! empty(give_get_option('donor_dashboard_page')) && get_post_status( |
| 36 | give_get_option('donor_dashboard_page') |
| 37 | ); |
| 38 | $historyPageIsSet = ! empty(give_get_option('history_page')); |
| 39 | |
| 40 | return ! $donorDashboardPageIsSet && $historyPageIsSet; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Render notice output |
| 45 | * |
| 46 | * @since 2.10.0 |
| 47 | * @return void |
| 48 | * |
| 49 | */ |
| 50 | protected function renderOutput() |
| 51 | { |
| 52 | echo $this->getOutput(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get notice output |
| 57 | * |
| 58 | * @since 2.10.0 |
| 59 | * @return string |
| 60 | * |
| 61 | */ |
| 62 | protected function getOutput() |
| 63 | { |
| 64 | ob_start(); |
| 65 | $output = ''; |
| 66 | require $this->getTemplatePath(); |
| 67 | $output = ob_get_contents(); |
| 68 | ob_end_clean(); |
| 69 | |
| 70 | return $output; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get template path for notice output |
| 75 | * |
| 76 | * @since 2.10.0 |
| 77 | * @return string |
| 78 | * |
| 79 | */ |
| 80 | protected function getTemplatePath() |
| 81 | { |
| 82 | return GIVE_PLUGIN_DIR . '/src/DonorDashboards/resources/views/upgradenotice.php'; |
| 83 | } |
| 84 | } |
| 85 |