PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 2.2
Admin Columns v2.2
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / addons.php
codepress-admin-columns / classes Last commit date
column 12 years ago storage_model 12 years ago addons.php 12 years ago column.php 12 years ago settings.php 12 years ago storage_model.php 12 years ago third_party.php 12 years ago upgrade.php 12 years ago utility.php 12 years ago
addons.php
267 lines
1 <?php
2 class CPAC_Addons {
3
4 /**
5 * CPAC class
6 *
7 * @since 2.2
8 */
9 private $cpac;
10
11 /**
12 * @since 2.2
13 *
14 * @param CPAC
15 */
16 function __construct( $cpac ) {
17
18 $this->cpac = $cpac;
19
20 // Redirect to addons settings tab on activation & deactivation
21 if ( is_admin() ) {
22 add_filter( 'wp_redirect', array( $this, 'addon_plugin_statuschange_redirect' ) );
23 }
24
25 // Handle install request
26 add_action( 'admin_init', array( $this, 'handle_install_request' ) );
27 }
28
29 /**
30 * Handles the installation of the add-on
31 *
32 * @since 2.2
33 */
34 public function handle_install_request() {
35
36 if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'install-cac-addon' ) || ! isset( $_GET['plugin'] ) )
37 return;
38
39 if ( ! $this->get_addon( $_GET['plugin'] ) ) {
40 cpac_admin_message( 'Addon does not exist.', 'error' );
41 return;
42 }
43
44 if ( ! class_exists('CAC_Addon_Pro') ) {
45 cpac_admin_message( 'You need Admin Columns Pro.', 'error' );
46 return;
47 }
48
49 // Hook: trigger possible warning message before running WP installer ( api errors etc. )
50 if ( $error = apply_filters( 'cac/addons/install_request/maybe_error', false, $_GET['plugin'] ) ) {
51 cpac_admin_message( $error, 'error' );
52 return;
53 }
54
55 $install_url = add_query_arg( array(
56 'action' => 'install-plugin',
57 'plugin' => $_GET['plugin'],
58 'cpac-redirect' => true
59 ), wp_nonce_url( network_admin_url( 'update.php'), 'install-plugin_' . $_GET['plugin'] ) );
60
61 wp_redirect( $install_url );
62 exit;
63 }
64
65 /**
66 * Redirect the user to the Admin Columns add-ons page after activation/deactivation of an add-on from the add-ons page
67 *
68 * @since 2.2
69 *
70 * @see filter:wp_redirect
71 */
72 public function addon_plugin_statuschange_redirect( $location ) {
73
74 if ( ! isset( $_GET['cpac-redirect'] ) ) {
75 return $location;
76 }
77
78 $urlparts = parse_url( $location );
79
80 if ( ! $urlparts ) {
81 return $location;
82 }
83
84 if ( ! empty( $urlparts['query'] ) ) {
85 $admin_url = $urlparts['scheme'] . '://' . $urlparts['host'] . $urlparts['path'];
86
87 // activate or deactivae plugin
88 if ( admin_url( 'plugins.php' ) == $admin_url ) {
89 parse_str( $urlparts['query'], $request );
90
91 if ( empty( $request['error'] ) ) {
92 $location = add_query_arg( empty( $request['activate'] ) ? 'deactivate' : 'activate', true, $this->cpac->settings()->get_settings_url( 'addons' ) );
93 }
94 }
95 }
96
97 return $location;
98 }
99
100 /**
101 * Addons are grouped into addon groups by providing the group an addon belongs to (see CPAC_Addons::get_available_addons()).
102 *
103 * @since 2.2
104 *
105 * @return array Available addon groups ([group_name] => [label])
106 */
107 public function get_addon_groups() {
108
109 $addon_groups = array(
110 'integration' => __( 'Third party plugin integration', 'cpac' )
111 );
112
113 /**
114 * Filter the addon groups
115 *
116 * @since 2.2
117 *
118 * @param array $addon_groups Available addon groups ([group_name] => [label])
119 */
120 $addon_groups = apply_filters( 'cpac/addons/addon_groups', $addon_groups );
121
122 return $addon_groups;
123 }
124
125 /**
126 * @since 2.2
127 *
128 * @param bool $grouped Whether to group the plugins by addon group ()
129 * @return array Available addons ([addon_basename] => (array) [addon_details] if not grouped, a list of these key-value pairs per group otherwise ([group_name] => (array) [group_addons]))
130 */
131 public function get_available_addons( $grouped = false ) {
132
133 $addons = array(
134 'cac-addon-acf' => array(
135 'title' => __( 'Advanced Custom Fields', 'cpac' ),
136 'description' => __( 'Display and edit Advanced Custom Fields fields in the posts overview in seconds!', 'cpac' ),
137 'group' => 'integration',
138 'image' => CPAC_URL . 'assets/images/addons/acf.png'
139 )
140 );
141
142 /**
143 * Filter the available addons
144 *
145 * @since 2.2
146 *
147 * @param array $addons Available addons ([addon_name] => (array) [addon_details])
148 */
149 $addons = apply_filters( 'cpac/addons/available_addons', $addons );
150
151 foreach ( $addons as $addon_name => $addon ) {
152 $addons[ $addon_name ] = wp_parse_args( $addon, array(
153 'title' => '',
154 'group' => '',
155 'image' => ''
156 ) );
157 }
158
159 // Maybe group add-ons
160 if ( $grouped ) {
161 $addons = $this->group_addons( $addons );
162 }
163
164 return $addons;
165 }
166
167 /**
168 * Get add-on details from the available add-ons list
169 *
170 * @since 2.2
171 *
172 * @param string $id Unique addon ID
173 * @return bool|array Returns addon details if the add-on exists, false otherwise
174 */
175 public function get_addon( $id ) {
176
177 $addons = $this->get_available_addons();
178
179 if ( isset( $addons[ $id ] ) ) {
180 return $addons[ $id ];
181 }
182
183 return false;
184 }
185
186 /**
187 * Group a list of add-ons
188 *
189 * @since 2.2
190 * @uses CPAC_Addons::group_addons()
191 *
192 * @param array $addons List of addons ([addon_name] => (array) [addon_details])
193 * @return array A list of addons per group: [group_name] => (array) [group_addons], where [group_addons] is an array ([addon_name] => (array) [addon_details])
194 */
195 public function group_addons( $addons ) {
196
197 $groups = $this->get_addon_groups();
198 $grouped_addons = array();
199
200 foreach ( $addons as $addon_name => $addon ) {
201 if ( ! isset( $groups[ $addon['group'] ] ) ) {
202 continue;
203 }
204
205 if ( ! isset( $grouped_addons[ $addon['group'] ] ) ) {
206 $grouped_addons[ $addon['group'] ] = array();
207 }
208
209 $grouped_addons[ $addon['group'] ][ $addon_name ] = $addon;
210 }
211 return $grouped_addons;
212 }
213
214 /**
215 * Get whether an add-on is installed (i.e. the plugin is available in the plugin directory)
216 *
217 * @since 2.2
218 *
219 * @param string $slug Plugin dirname/slug
220 * @return bool Returns true if there is no add-on installed with the passed ID, false otherwise
221 */
222 public function is_addon_installed( $slug ) {
223
224 return $this->get_installed_addon_plugin_basename( $slug ) ? true : false;
225 }
226
227 /**
228 * Get the plugin basename (see plugin_basename()) from a plugin, for example "my-plugin/my-plugin.php"
229 *
230 * @since 2.2
231 *
232 * @param string $slug Plugin dirname/slug
233 * @return string|bool Returns the plugin basename if the plugin is installed, false otherwise
234 */
235 public function get_installed_addon_plugin_basename( $slug ) {
236
237 $plugins = get_plugins();
238
239 foreach ( $plugins as $plugin_basename => $plugin ) {
240 if ( $slug == dirname( $plugin_basename ) ) {
241 return $plugin_basename;
242 }
243 }
244
245 return false;
246 }
247
248 /**
249 * @since 2.2
250 *
251 * @param string $slug Plugin dirname/slug
252 * @return string|bool Returns the plugin version if the plugin is installed, false otherwise
253 */
254 public function get_installed_addon_plugin_version( $slug ) {
255
256 $plugins = get_plugins();
257
258 foreach ( $plugins as $plugin_basename => $plugin ) {
259 if ( $slug == dirname( $plugin_basename ) ) {
260 return $plugin['Version'];
261 }
262 }
263
264 return false;
265 }
266 }
267