1 | <?php |
||
45 | class FooGallery_Plugin extends Foo_Plugin_Base_v2_3 { |
||
46 | |||
47 | private static $instance; |
||
48 | |||
49 | public static function get_instance() { |
||
56 | |||
57 | /** |
||
58 | * Initialize the plugin by setting localization, filters, and administration functions. |
||
59 | */ |
||
60 | private function __construct() { |
||
61 | |||
62 | //include everything we need! |
||
63 | require_once( FOOGALLERY_PATH . 'includes/includes.php' ); |
||
64 | |||
65 | register_activation_hook( __FILE__, array( 'FooGallery_Plugin', 'activate' ) ); |
||
66 | |||
67 | //init FooPluginBase |
||
68 | $this->init( FOOGALLERY_FILE, FOOGALLERY_SLUG, FOOGALLERY_VERSION, 'FooGallery' ); |
||
69 | |||
70 | //setup text domain |
||
71 | $this->load_plugin_textdomain(); |
||
72 | |||
73 | //setup gallery post type |
||
74 | new FooGallery_PostTypes(); |
||
75 | |||
76 | //load any extensions |
||
77 | new FooGallery_Extensions_Loader(); |
||
78 | |||
79 | if ( is_admin() ) { |
||
80 | new FooGallery_Admin(); |
||
81 | add_action( 'wpmu_new_blog', array( $this, 'set_default_extensions_for_multisite_network_activated' ) ); |
||
82 | } else { |
||
83 | new FooGallery_Public(); |
||
84 | } |
||
85 | |||
86 | new FooGallery_Thumbnails(); |
||
87 | |||
88 | new FooGallery_Polylang_Compatibility(); |
||
89 | |||
90 | $checker = new FooGallery_Version_Check(); |
||
91 | $checker->wire_up_checker(); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Set default extensions when a new site is created in multisite and FooGallery is network activated |
||
96 | * |
||
97 | * @since 1.2.5 |
||
98 | * |
||
99 | * @param int $blog_id The ID of the newly created site |
||
100 | */ |
||
101 | public function set_default_extensions_for_multisite_network_activated( $blog_id ) { |
||
114 | |||
115 | /** |
||
116 | * Fired when the plugin is activated. |
||
117 | * |
||
118 | * @since 1.0.0 |
||
119 | * |
||
120 | * @param boolean $network_wide True if WPMU superadmin uses |
||
121 | * "Network Activate" action, false if |
||
122 | * WPMU is disabled or plugin is |
||
123 | * activated on an individual blog. |
||
124 | */ |
||
125 | public static function activate( $network_wide ) { |
||
150 | |||
151 | /** |
||
152 | * Fired for each blog when the plugin is activated. |
||
153 | * |
||
154 | * @since 1.0.0 |
||
155 | */ |
||
156 | private static function single_activate( $multisite = true ) { |
||
157 | if ( false === get_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, false ) ) { |
||
158 | $api = new FooGallery_Extensions_API(); |
||
159 | |||
160 | $api->auto_activate_extensions(); |
||
161 | |||
162 | update_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, true ); |
||
163 | } |
||
164 | if ( false === $multisite ) { |
||
165 | //Make sure we redirect to the welcome page |
||
166 | set_transient( FOOGALLERY_ACTIVATION_REDIRECT_TRANSIENT_KEY, true, 30 ); |
||
167 | } |
||
168 | |||
169 | //force a version check on activation to make sure housekeeping is performed |
||
170 | foogallery_perform_version_check(); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Get all blog ids of blogs in the current network that are: |
||
175 | * - not archived |
||
176 | * - not spam |
||
177 | * - not deleted |
||
178 | * |
||
179 | * @since 1.0.0 |
||
180 | * |
||
181 | * @return array|false The blog ids, false if no matches. |
||
182 | */ |
||
183 | private static function get_blog_ids() { |
||
203 | } |
||
204 | } |
||
205 | |||
207 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.