PluginProbe
bbPress / 2.1
bbPress v2.1
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-core-update.php

bbp-core-update.php in bbPress 2.1, at bbp-includes/bbp-core-update.php

212 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Updater
5 *
6 * @package bbPress
7 * @subpackage Updater
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * If there is no raw DB version, this is the first installation
15 *
16 * @since bbPress (r3764)
17 *
18 * @uses get_option()
19 * @uses bbp_get_db_version() To get bbPress's database version
20 * @return bool True if update, False if not
21 */
22 function bbp_is_install() {
23 return ! bbp_get_db_version_raw();
24 }
25
26 /**
27 * Compare the bbPress version to the DB version to determine if updating
28 *
29 * @since bbPress (r3421)
30 *
31 * @uses get_option()
32 * @uses bbp_get_db_version() To get bbPress's database version
33 * @return bool True if update, False if not
34 */
35 function bbp_is_update() {
36 return (bool) ( (int) bbp_get_db_version_raw() < (int) bbp_get_db_version() );
37 }
38
39 /**
40 * Determine if bbPress is being activated
41 *
42 * Note that this function currently is not used in bbPress core and is here
43 * for third party plugins to use to check for bbPress activation.
44 *
45 * @since bbPress (r3421)
46 *
47 * @return bool True if activating bbPress, false if not
48 */
49 function bbp_is_activation( $basename = '' ) {
50 $bbp = bbpress();
51
52 $action = false;
53 if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) )
54 $action = $_REQUEST['action'];
55 elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) )
56 $action = $_REQUEST['action2'];
57
58 // Bail if not activating
59 if ( empty( $action ) || !in_array( $action, array( 'activate', 'activate-selected' ) ) )
60 return false;
61
62 // The plugin(s) being activated
63 if ( $action == 'activate' )
64 $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
65 else
66 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
67
68 // Set basename if empty
69 if ( empty( $basename ) && !empty( $bbp->basename ) )
70 $basename = $bbp->basename;
71
72 // Bail if no basename
73 if ( empty( $basename ) )
74 return false;
75
76 // Is bbPress being deactivated?
77 return in_array( $basename, $plugins );
78 }
79
80 /**
81 * Determine if bbPress is being deactivated
82 *
83 * @since bbPress (r3421)
84 * @return bool True if deactivating bbPress, false if not
85 */
86 function bbp_is_deactivation( $basename = '' ) {
87 $bbp = bbpress();
88
89 $action = false;
90 if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) )
91 $action = $_REQUEST['action'];
92 elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) )
93 $action = $_REQUEST['action2'];
94
95 // Bail if not deactivating
96 if ( empty( $action ) || !in_array( $action, array( 'deactivate', 'deactivate-selected' ) ) )
97 return false;
98
99 // The plugin(s) being deactivated
100 if ( $action == 'deactivate' )
101 $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
102 else
103 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
104
105 // Set basename if empty
106 if ( empty( $basename ) && !empty( $bbp->basename ) )
107 $basename = $bbp->basename;
108
109 // Bail if no basename
110 if ( empty( $basename ) )
111 return false;
112
113 // Is bbPress being deactivated?
114 return in_array( $basename, $plugins );
115 }
116
117 /**
118 * Update the DB to the latest version
119 *
120 * @since bbPress (r3421)
121 * @uses update_option()
122 * @uses bbp_get_db_version() To get bbPress's database version
123 */
124 function bbp_version_bump() {
125 $db_version = bbp_get_db_version();
126 update_option( '_bbp_db_version', $db_version );
127 }
128
129 /**
130 * Setup the bbPress updater
131 *
132 * @since bbPress (r3419)
133 *
134 * @uses bbp_version_bump()
135 * @uses bbp_deactivation()
136 * @uses bbp_activation()
137 */
138 function bbp_setup_updater() {
139
140 // Are we running an outdated version of bbPress?
141 if ( bbp_is_update() ) {
142
143 // Bump the version
144 bbp_version_bump();
145
146 // Run the deactivation function to wipe roles, caps, and rewrite rules
147 bbp_deactivation();
148
149 // Run the activation function to reset roles, caps, and rewrite rules
150 bbp_activation();
151 }
152 }
153
154 /**
155 * Create a default forum, topic, and reply
156 *
157 * @since bbPress (r3767)
158 * @param array $args Array of arguments to override default values
159 */
160 function bbp_create_initial_content( $args = array() ) {
161
162 $defaults = array(
163 'forum_parent' => 0,
164 'forum_status' => 'publish',
165 'forum_title' => __( 'General', 'bbpress' ),
166 'forum_content' => __( 'General chit-chat', 'bbpress' ),
167 'topic_title' => __( 'Hello World!', 'bbpress' ),
168 'topic_content' => __( 'I am the first topic in your new forums.', 'bbpress' ),
169 'reply_title' => __( 'Re: Hello World!', 'bbpress' ),
170 'reply_content' => __( 'Oh, and this is what a reply looks like.', 'bbpress' ),
171 );
172 $r = bbp_parse_args( $args, $defaults, 'create_initial_content' );
173 extract( $r );
174
175 // Create the initial forum
176 $forum_id = bbp_insert_forum( array(
177 'post_parent' => $forum_parent,
178 'post_status' => $forum_status,
179 'post_title' => $forum_title,
180 'post_content' => $forum_content
181 ) );
182
183 // Create the initial topic
184 $topic_id = bbp_insert_topic(
185 array(
186 'post_parent' => $forum_id,
187 'post_title' => $topic_title,
188 'post_content' => $topic_content
189 ),
190 array( 'forum_id' => $forum_id )
191 );
192
193 // Create the initial reply
194 $reply_id = bbp_insert_reply(
195 array(
196 'post_parent' => $topic_id,
197 'post_title' => $reply_title,
198 'post_content' => $reply_content
199 ),
200 array(
201 'forum_id' => $forum_id,
202 'topic_id' => $topic_id
203 )
204 );
205
206 return array(
207 'forum_id' => $forum_id,
208 'topic_id' => $topic_id,
209 'reply_id' => $reply_id
210 );
211 }
212