forked from anspress/anspress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivate.php
More file actions
114 lines (85 loc) · 3.2 KB
/
activate.php
File metadata and controls
114 lines (85 loc) · 3.2 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Installation and activation of anspress, register hooks that are fired when the plugin is activated.
*
* @package AnsPress
* @copyright Copyright (c) 2013, Rahul Aryan
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 0.1
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Create base pages, add roles, add caps and create tables
* @param $network_wide
*/
function anspress_activate( $network_wide ) {
$category_ext = 'categories-for-anspress/categories-for-anspress.php';
$category_error = false;
if(file_exists(WP_PLUGIN_DIR.'/'.$category_ext)){
$category_ext_data = get_plugin_data( WP_PLUGIN_DIR.'/'.$category_ext);
$category_error = !version_compare ( $category_ext_data['Version'], '1.3.5', '>=') ? true : false;
}
$tag_ext = 'tags-for-anspress/tags-for-anspress.php';
$tag_error = false;
if(file_exists(WP_PLUGIN_DIR.'/'.$tag_ext)){
$tag_ext_data = get_plugin_data( WP_PLUGIN_DIR.'/'.$tag_ext);
$tag_error = !version_compare ( $tag_ext_data['Version'], '1.2.7', '>=') ? true : false;
}
if ( $category_error || $tag_error ) {
echo '<h3>'.__('Please update all AnsPress extensions before activating. <a target="_blank" href="http://anspress.io/questions/ask/">Ask for help</a>', 'ap').'</h3>';
@trigger_error(__('Please update all AnsPress extensions before activating.', 'ap'), E_USER_ERROR);
}
// add roles
$ap_roles = new AP_Roles;
$ap_roles->add_roles();
$ap_roles->add_capabilities();
global $wpdb;
// check if page already exists
$page_id = ap_opt("base_page");
$post = get_post($page_id);
if(!$post){
$args = array();
$args['post_type'] = "page";
$args['post_content'] = "[anspress]";
$args['post_status'] = "publish";
$args['post_title'] = "ANSPRESS_TITLE";
$args['comment_status'] = 'closed';
// now create post
$new_page_id = wp_insert_post ($args);
if($new_page_id){
$page = get_post($new_page_id);
ap_opt("base_page", $page->ID);
ap_opt("base_page_id", $page->post_name);
}
}
if( ap_opt ('ap_version') != AP_VERSION ) {
ap_opt('ap_installed', 'false');
ap_opt('ap_version', AP_VERSION);
}
/**
* Run DB quries only if AP_DB_VERSION does not match
*/
if( ap_opt ('ap_db_version') != AP_DB_VERSION ) {
$charset_collate = !empty($wpdb->charset) ? "DEFAULT CHARACTER SET ".$wpdb->charset : '';
$meta_table = "CREATE TABLE IF NOT EXISTS `".$wpdb->base_prefix."ap_meta` (
`apmeta_id` bigint(20) NOT NULL AUTO_INCREMENT,
`apmeta_userid` bigint(20) DEFAULT NULL,
`apmeta_type` varchar(256) DEFAULT NULL,
`apmeta_actionid` bigint(20) DEFAULT NULL,
`apmeta_value` text,
`apmeta_param` LONGTEXT DEFAULT NULL,
`apmeta_date` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`apmeta_id`)
)".$charset_collate.";";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta ($meta_table);
ap_opt ('ap_db_version', AP_DB_VERSION);
}
if(!get_option('anspress_opt'))
update_option('anspress_opt', ap_default_options());
else
update_option('anspress_opt', get_option('anspress_opt') + ap_default_options());
ap_opt('ap_flush', 'true');
flush_rewrite_rules( false );
}