| 1 |  |  | <?php namespace EmailLog\Core\UI; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use EmailLog\Core\Loadie; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use EmailLog\Core\UI\Page\LogListPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Admin UI Loader. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Loads and initializes all admin pages and components. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @since 2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class UILoader implements Loadie { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	 * UI Component List. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	protected $components = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	 * List of Admin pages. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	 * @var \EmailLog\Core\UI\Page\BasePage[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	protected $pages = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * Load all components and setup hooks. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	public function load() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$this->initialize_components(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		$this->initialize_pages(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		foreach ( $this->components as $component ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			$component->load(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		foreach ( $this->pages as $page ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			$page->load(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 	public function is_show_dashboard_widget() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 		$this->components['core_settings'] = new Setting\CoreSetting(); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 		$dashboard_status                  = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 		$options                           = get_option( 'email-log-core' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 		if( isset( $options['hide_dashboard_widget'] ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 			$dashboard_status = $options['hide_dashboard_widget']; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 		return $dashboard_status; | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	 * Initialize UI component Objects. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	 * This method may be overwritten in tests. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	protected function initialize_components() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		if ( current_user_can( LogListPage::CAPABILITY ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			$this->components['admin_ui_enhancer'] = new Component\AdminUIEnhancer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			if( ! $this->is_show_dashboard_widget() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 				$this->components['dashboard_widget']  = new Component\DashboardWidget(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 * Initialize Admin page Objects. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * This method may be overwritten in tests. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	 * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	protected function initialize_pages() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		$this->pages['log_list_page']   = new Page\LogListPage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$this->pages['settings_page']   = new Page\SettingsPage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		$this->pages['addon_list_page'] = new Page\AddonListPage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  | 
            
                        
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.