GFPDFControllerController_Welcome_Screen

Controller_Welcome_Screen A general class for About / Intro Screen.

Defined (1)

The class is defined in the following location(s).

/src/controller/Controller_Welcome_Screen.php  
  1. class Controller_Welcome_Screen extends Helper_Abstract_Controller implements Helper_Interface_Actions, Helper_Interface_Filters { 
  2.  
  3. /** 
  4. * Holds our log class 
  5. * @var \Monolog\Logger|LoggerInterface 
  6. * @since 4.0 
  7. */ 
  8. protected $log; 
  9.  
  10. /** 
  11. * Holds our Helper_Data object 
  12. * which we can autoload with any data needed 
  13. * @var \GFPDF\Helper\Helper_Data 
  14. * @since 4.0 
  15. */ 
  16. protected $data; 
  17.  
  18. /** 
  19. * Holds our Helper_Abstract_Options / Helper_Options_Fields object 
  20. * Makes it easy to access global PDF settings and individual form PDF settings 
  21. * @var \GFPDF\Helper\Helper_Abstract_Options 
  22. * @since 4.0 
  23. */ 
  24. protected $options; 
  25.  
  26. /** 
  27. * Setup our class by injecting all our dependancies 
  28. * @param Helper_Abstract_Model|\GFPDF\Model\Model_Welcome_Screen $model Our Welcome Screen Model the controller will manage 
  29. * @param Helper_Abstract_View|\GFPDF\View\View_Welcome_Screen $view Our Welcome Screen View the controller will manage 
  30. * @param \Monolog\Logger|LoggerInterface $log Our logger class 
  31. * @param \GFPDF\Helper\Helper_Data $data Our plugin data store 
  32. * @param \GFPDF\Helper\Helper_Abstract_Options $options Our options class which allows us to access any settings 
  33. * @since 4.0 
  34. */ 
  35. public function __construct( Helper_Abstract_Model $model, Helper_Abstract_View $view, LoggerInterface $log, Helper_Data $data, Helper_Abstract_Options $options ) { 
  36.  
  37. /** Assign our internal variables */ 
  38. $this->log = $log; 
  39. $this->data = $data; 
  40. $this->options = $options; 
  41.  
  42. /** Load our model and view */ 
  43. $this->model = $model; 
  44. $this->model->setController( $this ); 
  45.  
  46. $this->view = $view; 
  47. $this->view->setController( $this ); 
  48.  
  49. /** 
  50. * Initialise our class defaults 
  51. * @since 4.0 
  52. * @return void 
  53. */ 
  54. public function init() { 
  55. $this->add_actions(); 
  56. $this->add_filters(); 
  57.  
  58. /** 
  59. * Apply any actions needed for the welcome page 
  60. * @since 4.0 
  61. * @return void 
  62. */ 
  63. public function add_actions() { 
  64. /** Load the welcome screen into the menu */ 
  65. add_action( 'admin_menu', [ $this->model, 'admin_menus' ] ); 
  66. add_action( 'admin_head', [ $this->model, 'hide_admin_menus' ] ); 
  67. add_action( 'init', [ $this, 'maybe_show_welcome_screen' ] ); 
  68.  
  69. /** 
  70. * Apply any filters needed for the welcome page 
  71. * @since 4.0 
  72. * @return void 
  73. */ 
  74. public function add_filters() { 
  75. add_filter( 'admin_title', [ $this->model, 'add_page_title' ], 10, 3 ); 
  76.  
  77. /** 
  78. * Check if headers have already been sent and then try show the welcome screen 
  79. * @since 4.1.1 
  80. * @return void 
  81. */ 
  82. public function maybe_show_welcome_screen() { 
  83. /** Exit early if headers have already been sent */ 
  84. if ( headers_sent() ) { 
  85. return null; 
  86.  
  87. $this->welcome(); 
  88.  
  89. /** 
  90. * Sends user to the Welcome page on first activation, as well as everytime plugin is upgraded 
  91. * @since 4.0 
  92. * @return void 
  93. */ 
  94. public function welcome() { 
  95.  
  96. /** Bail if no activation redirect */ 
  97. if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! is_admin() || ! current_user_can( 'activate_plugins' ) ) { 
  98. return null; 
  99.  
  100. $version = PDF_EXTENDED_VERSION; 
  101.  
  102. /** Bail if we do not have a transient set (activation hook) and the versions match */ 
  103. if ( ! get_transient( '_gravitypdf_activation_redirect' ) && $version === get_option( 'gfpdf_current_version' ) ) { 
  104. return null; 
  105.  
  106. /** Delete the redirect transient */ 
  107. delete_transient( '_gravitypdf_activation_redirect' ); 
  108.  
  109. /** Bail if we are already on the welcome page */ 
  110. if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'gfpdf-getting-started' || $_GET['page'] == 'gfpdf-update' ) ) { 
  111. return null; 
  112.  
  113. /** Bail if activating from network, or bulk */ 
  114. if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { 
  115. $this->log->addNotice( 'Network Activation.' ); 
  116.  
  117. return null; 
  118.  
  119. /** Check if it's a fresh installation and we should display the welcome screen, or whether we should display the update screen */ 
  120. if ( ! $this->data->is_installed && ! is_file( PDF_TEMPLATE_LOCATION . 'configuration.php' ) ) { 
  121. $this->log->addNotice( 'Redirect to Getting Started page (first time activated).' ); 
  122. $this->redirect( admin_url( 'index.php?page=gfpdf-getting-started' ) ); 
  123. } else { 
  124. $this->maybe_display_update_screen( $version ); 
  125.  
  126. /** 
  127. * Check if our Gravity PDF update screen should be displayed to the user 
  128. * @param string $current_version 
  129. * @return void 
  130. * @since 4.0 
  131. */ 
  132. public function maybe_display_update_screen( $current_version ) { 
  133.  
  134. /** Check we actually upgraded, otherwise don't redirect */ 
  135. $preview_version = get_option( 'gfpdf_current_version' ); 
  136.  
  137. if ( $current_version === $preview_version ) { 
  138. return null; 
  139.  
  140. /** Check current version is not a bug patch AND the old version isn't a previous major / minor release */ 
  141. $previous_version_breakdown = explode( '.', $preview_version ); 
  142. $current_version_breakdown = explode( '.', $current_version ); 
  143.  
  144. /** 
  145. * Compare the major and minor version (if any) of the old and new versions to see if they are equal. 
  146. * If they are, we know the user updated from a patch release in the current branch 
  147. * and we don't want to show the update page 
  148. */ 
  149. if( (int) $previous_version_breakdown[0] === (int) $current_version_breakdown[0] 
  150. && (int) $previous_version_breakdown[1] >= (int) $current_version_breakdown[1] ) { 
  151. /** bug fix or security release, do not redirect */ 
  152. return null; 
  153.  
  154. /** Check if the user has opted to view the What's New page */ 
  155. $show_update_page = $this->options->get_option( 'update_screen_action', 'Enable' ); 
  156.  
  157. /** Redirect if correct setting is enabled */ 
  158. if ( 'Enable' === $show_update_page ) { 
  159. $this->log->addNotice( 'Redirect to Update page (previously activated).' ); 
  160. $this->redirect( admin_url( 'index.php?page=gfpdf-update' ) ) ; 
  161.  
  162. /** 
  163. * Do a safe redirect 
  164. * @param string $url The URL to redirect to 
  165. * @since 4.1 
  166. */ 
  167. protected function redirect( $url ) { 
  168. wp_safe_redirect( $url ); 
  169. exit; 
  170.  
  171. /** 
  172. * Load our welcome screen 
  173. * @return void 
  174. * @since 4.0 
  175. */ 
  176. public function getting_started_screen() { 
  177. $this->view->welcome(); 
  178.  
  179. /** 
  180. * Load our update welcome screen 
  181. * @return void 
  182. * @since 4.0 
  183. */ 
  184. public function update_screen() { 
  185. $this->view->update();