-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
102 lines (76 loc) · 2.56 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
class BlogsMapPlugin {
var $version = '0.0.1';
// plugin general initialization
private static $instance = null;
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance( $plugin_name = null ) {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
// register plugin
if ( $plugin_name ) {
register_activation_hook( $plugin_name, array( self::$instance, 'activate' ) ); // plugin activation actions
register_deactivation_hook( $plugin_name, array( self::$instance, 'deactivate' ) );
}
return self::$instance;
}
function __construct() {
// register shortcodes api
self::register_shortcodes();
// register callbacks
self::register_callbacks();
// register stylesheet
self::register_stylesheet();
}
/**
* Activation hook for the plugin.
*/
function activate() {
$this->includes();
//verify user is running WP 3.0 or newer
if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate our plugin
wp_die( __( 'This plugin requires WordPress version 3.0 or higher.', 'grants-review' ) );
}
flush_rewrite_rules();
}
/**
* Deactivation hook for the plugin.
*/
function deactivate() {
flush_rewrite_rules();
}
// plugin custom codes
function register_shortcodes() {}
function register_callbacks() {
add_action( 'wpmu_new_blog', array( $this, 'map_blogs' ));
}
function register_stylesheet() {}
function includes() {
$this->map_blogs();
}
//function map_blogs( $blog_id = null, $user_id = null, $domain = null, $path = null, $site_id = null, $meta = null ) {
function map_blogs() {
global $wpdb;
// get all the blogs info
$query = sprintf( "SELECT blog_id, domain from %s", $wpdb->prefix .'blogs' );
$blogs = $wpdb->get_results( $query );
if ( empty( $blogs ) ) return;
// update blog mapping
// Open the text file in wordpress home directory
$f = fopen( get_home_path() . 'map.conf', 'w' );
foreach ( $blogs as $blog ) {
fwrite( $f, "{$blog->domain} {$blog->blog_id};" );
}
fclose( $f );
}
}
?>