class-fwp-plugin-base.php
1 year ago
class-fwp-register-hook-base.php
1 year ago
class-fwp-settings-section-base.php
3 years ago
class-fwp-template-tag-base.php
3 years ago
class-fwp-register-hook-base.php
84 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class FWP_Register_Hook_Base_1x0x0 |
| 4 | * |
| 5 | * @package FWP |
| 6 | * @category WordPress Library |
| 7 | * @version 1.0.0 |
| 8 | |
| 9 | * @link https://www.webfactoryltd.com/ |
| 10 | */ |
| 11 | abstract class FWP_Register_Hook_Base_1x0x0 extends WPRun_Base_1x0x0 |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $hook_type = null; |
| 18 | |
| 19 | /** |
| 20 | * @var wpdb |
| 21 | */ |
| 22 | private $wpdb = null; |
| 23 | |
| 24 | /** |
| 25 | * Initialize |
| 26 | * @triggers E_USER_NOTICE Hook function does not exist |
| 27 | */ |
| 28 | protected function init( $plugin_file, wpdb $wpdb ) |
| 29 | { |
| 30 | $this->wpdb = $wpdb; |
| 31 | |
| 32 | $wp_hook_function = 'register_'. $this->hook_type .'_hook'; |
| 33 | |
| 34 | if ( ! function_exists( $wp_hook_function ) ) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | $wp_hook_function( |
| 39 | $plugin_file |
| 40 | , $this->get_callback( 'procedure' ) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Plugin activation procedure |
| 46 | */ |
| 47 | protected function procedure( $networkwide = null ) |
| 48 | { |
| 49 | if ( is_multisite() && $networkwide ) { |
| 50 | // network activation |
| 51 | $sites = get_sites(); |
| 52 | $active_blog = $this->wpdb->blogid; |
| 53 | |
| 54 | foreach ( $sites as $site ) { |
| 55 | switch_to_blog( $site->blog_id ); |
| 56 | $this->site_procedure(); |
| 57 | } |
| 58 | |
| 59 | // switch back to active blog |
| 60 | switch_to_blog( $active_blog ); |
| 61 | |
| 62 | $this->network_procedure(); |
| 63 | } else { |
| 64 | // single site activation |
| 65 | $this->site_procedure(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Network hook procedure |
| 71 | * @return void |
| 72 | */ |
| 73 | protected function network_procedure() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Site hook procedure |
| 79 | * @return void |
| 80 | */ |
| 81 | abstract protected function site_procedure(); |
| 82 | |
| 83 | } |
| 84 |