PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.1
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / admin / charitable-admin-addons-functions.php

charitable-admin-addons-functions.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11.1, at includes/admin/charitable-admin-addons-functions.php

465 lines 24.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Admin Addons helper functions.
4 *
5 * @package Charitable/Admin Functions
6 * @author David Bisset
7 * @copyright Copyright (c) 2024, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.7.6
10 * @version 1.8.7.6
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 // Note: charitable_can_install() and charitable_can_activate() are already defined in charitable-core-admin-functions.php
19
20 /**
21 * Get the list of AM plugins that we propose to install.
22 *
23 * @since 1.8.7.6
24 *
25 * @return array
26 */
27 function charitable_get_am_plugins() {
28 $images_url = charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/';
29
30 return array(
31 'optinmonster/optin-monster-wp-api.php' => array(
32 'icon' => $images_url . 'om.png',
33 'name' => esc_html__( 'OptinMonster', 'charitable' ),
34 'desc' => esc_html__( 'Instantly get more subscribers, leads, and sales with the #1 conversion optimization toolkit. Create high converting popups, announcement bars, spin a wheel, and more with smart targeting and personalization.', 'charitable' ),
35 'wporg' => 'https://wordpress.org/plugins/optinmonster/',
36 'url' => 'https://downloads.wordpress.org/plugin/optinmonster.zip',
37 ),
38 'google-analytics-for-wordpress/googleanalytics.php' => array(
39 'icon' => $images_url . 'mi.png',
40 'name' => esc_html__( 'MonsterInsights', 'charitable' ),
41 'desc' => esc_html__( 'The leading WordPress analytics plugin that shows you how people find and use your website, so you can make data driven decisions to grow your business. Properly set up Google Analytics without writing code.', 'charitable' ),
42 'wporg' => 'https://wordpress.org/plugins/google-analytics-for-wordpress/',
43 'url' => 'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.zip',
44 'pro' => array(
45 'plug' => 'google-analytics-premium/googleanalytics-premium.php',
46 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-mi.png',
47 'name' => esc_html__( 'MonsterInsights Pro', 'charitable' ),
48 'desc' => esc_html__( 'The leading WordPress analytics plugin that shows you how people find and use your website, so you can make data driven decisions to grow your business. Properly set up Google Analytics without writing code.', 'charitable' ),
49 'url' => 'https://www.monsterinsights.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
50 'act' => 'go-to-url',
51 ),
52 ),
53 'wp-mail-smtp/wp_mail_smtp.php' => array(
54 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-smtp.png',
55 'name' => esc_html__( 'WP Mail SMTP', 'charitable' ),
56 'desc' => esc_html__( "Improve your WordPress email deliverability and make sure that your website emails reach user's inbox with the #1 SMTP plugin for WordPress. Over 3 million websites use it to fix WordPress email issues.", 'charitable' ),
57 'wporg' => 'https://wordpress.org/plugins/wp-mail-smtp/',
58 'url' => 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip',
59 'pro' => array(
60 'plug' => 'wp-mail-smtp-pro/wp_mail_smtp.php',
61 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-smtp.png',
62 'name' => esc_html__( 'WP Mail SMTP Pro', 'charitable' ),
63 'desc' => esc_html__( "Improve your WordPress email deliverability and make sure that your website emails reach user's inbox with the #1 SMTP plugin for WordPress. Over 3 million websites use it to fix WordPress email issues.", 'charitable' ),
64 'url' => 'https://wpmailsmtp.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
65 'act' => 'go-to-url',
66 ),
67 ),
68 'all-in-one-seo-pack/all_in_one_seo_pack.php' => array(
69 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-aioseo.png',
70 'name' => esc_html__( 'AIOSEO', 'charitable' ),
71 'desc' => esc_html__( "The original WordPress SEO plugin and toolkit that improves your website's search rankings. Comes with all the SEO features like Local SEO, WooCommerce SEO, sitemaps, SEO optimizer, schema, and more.", 'charitable' ),
72 'wporg' => 'https://wordpress.org/plugins/all-in-one-seo-pack/',
73 'url' => 'https://downloads.wordpress.org/plugin/all-in-one-seo-pack.zip',
74 'pro' => array(
75 'plug' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
76 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-aioseo.png',
77 'name' => esc_html__( 'AIOSEO Pro', 'charitable' ),
78 'desc' => esc_html__( "The original WordPress SEO plugin and toolkit that improves your website's search rankings. Comes with all the SEO features like Local SEO, WooCommerce SEO, sitemaps, SEO optimizer, schema, and more.", 'charitable' ),
79 'url' => 'https://aioseo.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
80 'act' => 'go-to-url',
81 ),
82 ),
83 'coming-soon/coming-soon.php' => array(
84 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-seedprod.png',
85 'name' => esc_html__( 'SeedProd', 'charitable' ),
86 'desc' => esc_html__( 'The fastest drag & drop landing page builder for WordPress. Create custom landing pages without writing code, connect them with your CRM, collect subscribers, and grow your audience. Trusted by 1 million sites.', 'charitable' ),
87 'wporg' => 'https://wordpress.org/plugins/coming-soon/',
88 'url' => 'https://downloads.wordpress.org/plugin/coming-soon.zip',
89 'pro' => array(
90 'plug' => 'seedprod-coming-soon-pro-5/seedprod-coming-soon-pro-5.php',
91 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-seedprod.png',
92 'name' => esc_html__( 'SeedProd Pro', 'charitable' ),
93 'desc' => esc_html__( 'The fastest drag & drop landing page builder for WordPress. Create custom landing pages without writing code, connect them with your CRM, collect subscribers, and grow your audience. Trusted by 1 million sites.', 'charitable' ),
94 'url' => 'https://www.seedprod.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
95 'act' => 'go-to-url',
96 ),
97 ),
98 'rafflepress/rafflepress.php' => array(
99 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-rp.png',
100 'name' => esc_html__( 'RafflePress', 'charitable' ),
101 'desc' => esc_html__( 'Turn your website visitors into brand ambassadors! Easily grow your email list, website traffic, and social media followers with the most powerful giveaways & contests plugin for WordPress.', 'charitable' ),
102 'wporg' => 'https://wordpress.org/plugins/rafflepress/',
103 'url' => 'https://downloads.wordpress.org/plugin/rafflepress.zip',
104 'pro' => array(
105 'plug' => 'rafflepress-pro/rafflepress-pro.php',
106 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-rp.png',
107 'name' => esc_html__( 'RafflePress Pro', 'charitable' ),
108 'desc' => esc_html__( 'Turn your website visitors into brand ambassadors! Easily grow your email list, website traffic, and social media followers with the most powerful giveaways & contests plugin for WordPress.', 'charitable' ),
109 'url' => 'https://rafflepress.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
110 'act' => 'go-to-url',
111 ),
112 ),
113 'pushengage/main.php' => array(
114 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-pushengage.png',
115 'name' => esc_html__( 'PushEngage', 'charitable' ),
116 'desc' => esc_html__( 'Connect with your visitors after they leave your website with the leading web push notification software. Over 10,000+ businesses worldwide use PushEngage to send 15 billion notifications each month.', 'charitable' ),
117 'wporg' => 'https://wordpress.org/plugins/pushengage/',
118 'url' => 'https://downloads.wordpress.org/plugin/pushengage.zip',
119 ),
120 'instagram-feed/instagram-feed.php' => array(
121 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-instagram.png',
122 'name' => esc_html__( 'Smash Balloon Instagram Feeds', 'charitable' ),
123 'desc' => esc_html__( 'Easily display Instagram content on your WordPress site without writing any code. Comes with multiple templates, ability to show content from multiple accounts, hashtags, and more. Trusted by 1 million websites.', 'charitable' ),
124 'wporg' => 'https://wordpress.org/plugins/instagram-feed/',
125 'url' => 'https://downloads.wordpress.org/plugin/instagram-feed.zip',
126 'pro' => array(
127 'plug' => 'instagram-feed-pro/instagram-feed.php',
128 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-instagram.png',
129 'name' => esc_html__( 'Smash Balloon Instagram Feeds Pro', 'charitable' ),
130 'desc' => esc_html__( 'Easily display Instagram content on your WordPress site without writing any code. Comes with multiple templates, ability to show content from multiple accounts, hashtags, and more. Trusted by 1 million websites.', 'charitable' ),
131 'url' => 'https://smashballoon.com/instagram-feed/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
132 'act' => 'go-to-url',
133 ),
134 ),
135 'custom-facebook-feed/custom-facebook-feed.php' => array(
136 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-fb.png',
137 'name' => esc_html__( 'Smash Balloon Facebook Feeds', 'charitable' ),
138 'desc' => esc_html__( 'Easily display Facebook content on your WordPress site without writing any code. Comes with multiple templates, ability to embed albums, group content, reviews, live videos, comments, and reactions.', 'charitable' ),
139 'wporg' => 'https://wordpress.org/plugins/custom-facebook-feed/',
140 'url' => 'https://downloads.wordpress.org/plugin/custom-facebook-feed.zip',
141 'pro' => array(
142 'plug' => 'custom-facebook-feed-pro/custom-facebook-feed.php',
143 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-fb.png',
144 'name' => esc_html__( 'Smash Balloon Facebook Feeds Pro', 'charitable' ),
145 'desc' => esc_html__( 'Easily display Facebook content on your WordPress site without writing any code. Comes with multiple templates, ability to embed albums, group content, reviews, live videos, comments, and reactions.', 'charitable' ),
146 'url' => 'https://smashballoon.com/custom-facebook-feed/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
147 'act' => 'go-to-url',
148 ),
149 ),
150 'feeds-for-youtube/youtube-feed.php' => array(
151 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-youtube.png',
152 'name' => esc_html__( 'Smash Balloon YouTube Feeds', 'charitable' ),
153 'desc' => esc_html__( 'Easily display YouTube videos on your WordPress site without writing any code. Comes with multiple layouts, ability to embed live streams, video filtering, ability to combine multiple channel videos, and more.', 'charitable' ),
154 'wporg' => 'https://wordpress.org/plugins/feeds-for-youtube/',
155 'url' => 'https://downloads.wordpress.org/plugin/feeds-for-youtube.zip',
156 'pro' => array(
157 'plug' => 'youtube-feed-pro/youtube-feed.php',
158 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-youtube.png',
159 'name' => esc_html__( 'Smash Balloon YouTube Feeds Pro', 'charitable' ),
160 'desc' => esc_html__( 'Easily display YouTube videos on your WordPress site without writing any code. Comes with multiple layouts, ability to embed live streams, video filtering, ability to combine multiple channel videos, and more.', 'charitable' ),
161 'url' => 'https://smashballoon.com/youtube-feed/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
162 'act' => 'go-to-url',
163 ),
164 ),
165 'custom-twitter-feeds/custom-twitter-feed.php' => array(
166 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-twitter.png',
167 'name' => esc_html__( 'Smash Balloon Twitter Feeds', 'charitable' ),
168 'desc' => esc_html__( 'Easily display Twitter content in WordPress without writing any code. Comes with multiple layouts, ability to combine multiple Twitter feeds, Twitter card support, tweet moderation, and more.', 'charitable' ),
169 'wporg' => 'https://wordpress.org/plugins/custom-twitter-feeds/',
170 'url' => 'https://downloads.wordpress.org/plugin/custom-twitter-feeds.zip',
171 'pro' => array(
172 'plug' => 'custom-twitter-feeds-pro/custom-twitter-feed.php',
173 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sb-twitter.png',
174 'name' => esc_html__( 'Smash Balloon Twitter Feeds Pro', 'charitable' ),
175 'desc' => esc_html__( 'Easily display Twitter content in WordPress without writing any code. Comes with multiple layouts, ability to combine multiple Twitter feeds, Twitter card support, tweet moderation, and more.', 'charitable' ),
176 'url' => 'https://smashballoon.com/custom-twitter-feeds/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
177 'act' => 'go-to-url',
178 ),
179 ),
180 'trustpulse-api/trustpulse.php' => array(
181 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-trustpulse.png',
182 'name' => esc_html__( 'TrustPulse', 'charitable' ),
183 'desc' => esc_html__( 'Boost your sales and conversions by up to 15% with real-time social proof notifications. TrustPulse helps you show live user activity and purchases to help convince other users to purchase.', 'charitable' ),
184 'wporg' => 'https://wordpress.org/plugins/trustpulse-api/',
185 'url' => 'https://downloads.wordpress.org/plugin/trustpulse-api.zip',
186 ),
187 'searchwp/index.php' => array(
188 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-searchwp.png',
189 'name' => esc_html__( 'SearchWP', 'charitable' ),
190 'desc' => esc_html__( 'The most advanced WordPress search plugin. Customize your WordPress search algorithm, reorder search results, track search metrics, and everything you need to leverage search to grow your business.', 'charitable' ),
191 'wporg' => false,
192 'url' => 'https://searchwp.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
193 'act' => 'go-to-url',
194 ),
195 'affiliate-wp/affiliate-wp.php' => array(
196 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-affwp.png',
197 'name' => esc_html__( 'AffiliateWP', 'charitable' ),
198 'desc' => esc_html__( 'The #1 affiliate management plugin for WordPress. Easily create an affiliate program for your eCommerce store or membership site within minutes and start growing your sales with the power of referral marketing.', 'charitable' ),
199 'wporg' => false,
200 'url' => 'https://affiliatewp.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
201 'act' => 'go-to-url',
202 ),
203 'stripe/stripe-checkout.php' => array(
204 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-wp-simple-pay.png',
205 'name' => esc_html__( 'WP Simple Pay', 'charitable' ),
206 'desc' => esc_html__( 'The #1 Stripe payments plugin for WordPress. Start accepting one-time and recurring payments on your WordPress site without setting up a shopping cart. No code required.', 'charitable' ),
207 'wporg' => 'https://wordpress.org/plugins/stripe/',
208 'url' => 'https://downloads.wordpress.org/plugin/stripe.zip',
209 'pro' => array(
210 'plug' => 'wp-simple-pay-pro-3/simple-pay.php',
211 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-wp-simple-pay.png',
212 'name' => esc_html__( 'WP Simple Pay Pro', 'charitable' ),
213 'desc' => esc_html__( 'The #1 Stripe payments plugin for WordPress. Start accepting one-time and recurring payments on your WordPress site without setting up a shopping cart. No code required.', 'charitable' ),
214 'url' => 'https://wpsimplepay.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
215 'act' => 'go-to-url',
216 ),
217 ),
218 'easy-digital-downloads/easy-digital-downloads.php' => array(
219 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-edd.png',
220 'name' => esc_html__( 'Easy Digital Downloads', 'charitable' ),
221 'desc' => esc_html__( 'The best WordPress eCommerce plugin for selling digital downloads. Start selling eBooks, software, music, digital art, and more within minutes. Accept payments, manage subscriptions, advanced access control, and more.', 'charitable' ),
222 'wporg' => 'https://wordpress.org/plugins/easy-digital-downloads/',
223 'url' => 'https://downloads.wordpress.org/plugin/easy-digital-downloads.zip',
224 ),
225 'sugar-calendar-lite/sugar-calendar-lite.php' => array(
226 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sugarcalendar.png',
227 'name' => esc_html__( 'Sugar Calendar', 'charitable' ),
228 'desc' => esc_html__( 'A simple & powerful event calendar plugin for WordPress that comes with all the event management features including payments, scheduling, timezones, ticketing, recurring events, and more.', 'charitable' ),
229 'wporg' => 'https://wordpress.org/plugins/sugar-calendar-lite/',
230 'url' => 'https://downloads.wordpress.org/plugin/sugar-calendar-lite.zip',
231 'pro' => array(
232 'plug' => 'sugar-calendar/sugar-calendar.php',
233 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-sugarcalendar.png',
234 'name' => esc_html__( 'Sugar Calendar Pro', 'charitable' ),
235 'desc' => esc_html__( 'A simple & powerful event calendar plugin for WordPress that comes with all the event management features including payments, scheduling, timezones, ticketing, recurring events, and more.', 'charitable' ),
236 'url' => 'https://sugarcalendar.com/?utm_source=charitableplugin&utm_medium=link&utm_campaign=About%20Charitable',
237 'act' => 'go-to-url',
238 ),
239 ),
240 'insert-headers-and-footers/ihaf.php' => array(
241 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-wpcode.png',
242 'name' => esc_html__( 'WPCode', 'charitable' ),
243 'desc' => esc_html__( 'Future proof your WordPress customizations with the most popular code snippet management plugin for WordPress. Trusted by over 1,500,000+ websites for easily adding code to WordPress right from the admin area.', 'charitable' ),
244 'wporg' => 'https://wordpress.org/plugins/insert-headers-and-footers/',
245 'url' => 'https://downloads.wordpress.org/plugin/insert-headers-and-footers.zip',
246 ),
247 'duplicator/duplicator.php' => array(
248 'icon' => charitable()->get_path( 'assets', false ) . 'images/plugins/third-party/plugin-duplicator.png',
249 'name' => esc_html__( 'Duplicator', 'charitable' ),
250 'desc' => esc_html__( 'Leading WordPress backup & site migration plugin. Over 1,500,000+ smart website owners use Duplicator to make reliable and secure WordPress backups to protect their websites. It also makes website migration really easy.', 'charitable' ),
251 'wporg' => 'https://wordpress.org/plugins/duplicator/',
252 'url' => 'https://downloads.wordpress.org/plugin/duplicator.zip',
253 ),
254 );
255 }
256
257 /**
258 * Get AM plugin data to display in the Addons section of About tab.
259 *
260 * @since 1.8.7.6
261 *
262 * @param string $plugin Plugin slug.
263 * @param array $details Plugin details.
264 * @param array $all_plugins List of all plugins.
265 *
266 * @return array
267 */
268 function charitable_get_plugin_data( $plugin, $details, $all_plugins ) {
269 $have_pro = ( ! empty( $details['pro'] ) && ! empty( $details['pro']['plug'] ) );
270 $show_pro = false;
271
272 $plugin_data = array();
273
274 if ( $have_pro ) {
275 // Only promote Pro if the Pro plugin is installed (exists in the plugins list).
276 if ( array_key_exists( $details['pro']['plug'], $all_plugins ) ) {
277 $show_pro = true;
278 }
279 if ( $show_pro ) {
280 $plugin = $details['pro']['plug'];
281 $details = $details['pro'];
282 }
283 }
284
285 if ( array_key_exists( $plugin, $all_plugins ) ) {
286 if ( is_plugin_active( $plugin ) ) {
287 // Status text/status.
288 $plugin_data['status_class'] = 'status-active';
289 $plugin_data['status_text'] = esc_html__( 'Active', 'charitable' );
290 // Button text/status.
291 $plugin_data['action_class'] = $plugin_data['status_class'] . ' button button-secondary disabled';
292 $plugin_data['action_text'] = esc_html__( 'Activated', 'charitable' );
293 $plugin_data['plugin_src'] = esc_attr( $plugin );
294 } else {
295 // Status text/status.
296 $plugin_data['status_class'] = 'status-installed';
297 $plugin_data['status_text'] = esc_html__( 'Inactive', 'charitable' );
298 // Button text/status.
299 $plugin_data['action_class'] = $plugin_data['status_class'] . ' button button-secondary';
300 $plugin_data['action_text'] = esc_html__( 'Activate', 'charitable' );
301 $plugin_data['plugin_src'] = esc_attr( $plugin );
302 }
303 } else {
304 // Doesn't exist, install.
305 // Status text/status.
306 $plugin_data['status_class'] = 'status-missing';
307
308 if ( isset( $details['act'] ) && 'go-to-url' === $details['act'] ) {
309 $plugin_data['status_class'] = 'status-go-to-url';
310 }
311 $plugin_data['status_text'] = esc_html__( 'Not Installed', 'charitable' );
312 // Button text/status.
313 $plugin_data['action_class'] = $plugin_data['status_class'] . ' button button-primary';
314 $plugin_data['action_text'] = esc_html__( 'Install Plugin', 'charitable' );
315 $plugin_data['plugin_src'] = esc_url( $details['url'] );
316 }
317
318 $plugin_data['details'] = $details;
319
320 return $plugin_data;
321 }
322
323 /**
324 * Install a WordPress.org plugin.
325 *
326 * @since 1.8.7.6
327 * @version 1.8.9.1
328 *
329 * @param string $plugin Plugin slug or URL.
330 * @return WP_Error|true
331 */
332 function charitable_install_wporg_plugin( $plugin ) {
333 // Include required files.
334 if ( ! function_exists( 'download_url' ) ) {
335 require_once ABSPATH . 'wp-admin/includes/file.php';
336 }
337 if ( ! function_exists( 'unzip_file' ) ) {
338 require_once ABSPATH . 'wp-admin/includes/file.php';
339 }
340 // For plugins_api.
341 if ( ! function_exists( 'plugins_api' ) ) {
342 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
343 }
344
345 // Download the plugin.
346 $download_link = $plugin;
347
348 if ( ! filter_var( $plugin, FILTER_VALIDATE_URL ) ) {
349 // Normalize slug if a basename like "slug/plugin.php" was passed.
350 $slug = $plugin;
351 if ( strpos( $slug, '/' ) !== false ) {
352 $parts = explode( '/', $slug );
353 $slug = reset( $parts );
354 }
355 $slug = str_replace( '.php', '', $slug );
356
357 // Get download URL from WordPress.org.
358 $api = plugins_api( 'plugin_information', array(
359 'slug' => $slug,
360 'fields' => array( 'download_link' => true ),
361 ) );
362
363 if ( is_wp_error( $api ) ) {
364 return $api;
365 }
366
367 $download_link = $api->download_link;
368 }
369
370 // Download the plugin.
371 $download = download_url( $download_link );
372 if ( is_wp_error( $download ) ) {
373 return $download;
374 }
375
376 // Unzip the file.
377 $unzip = unzip_file( $download, WP_PLUGIN_DIR );
378 if ( is_wp_error( $unzip ) ) {
379 unlink( $download ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
380 return $unzip;
381 }
382
383 // Clean up the zip file.
384 unlink( $download ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
385
386 return true;
387 }
388
389 /**
390 * Activate a WordPress.org plugin.
391 *
392 * @since 1.8.7.6
393 *
394 * @param string $plugin Plugin basename.
395 * @return WP_Error|true
396 */
397 function charitable_activate_wporg_plugin( $plugin ) {
398 if ( ! function_exists( 'activate_plugin' ) ) {
399 require_once ABSPATH . 'wp-admin/includes/plugin.php';
400 }
401
402 $result = activate_plugin( $plugin );
403 if ( is_wp_error( $result ) ) {
404 return $result;
405 }
406
407 return true;
408 }
409
410 /**
411 * Deactivate a WordPress.org plugin.
412 *
413 * @since 1.8.7.6
414 *
415 * @param string $plugin Plugin basename.
416 * @return WP_Error|true
417 */
418 function charitable_deactivate_wporg_plugin( $plugin ) {
419 if ( ! function_exists( 'deactivate_plugins' ) ) {
420 require_once ABSPATH . 'wp-admin/includes/plugin.php';
421 }
422
423 $result = deactivate_plugins( $plugin );
424 if ( is_wp_error( $result ) ) {
425 return $result;
426 }
427
428 return true;
429 }
430
431 /**
432 * Get plugin basename from slug.
433 *
434 * @since 1.8.7.6
435 * @version 1.8.9.1
436 *
437 * @param string $plugin Plugin slug.
438 * @return string
439 */
440 function charitable_get_plugin_basename_from_slug( $plugin ) {
441 $all_plugins = get_plugins();
442
443 // If a full URL was provided (e.g. downloads.wordpress.org/plugin/slug.zip), derive slug from URL.
444 if ( filter_var( $plugin, FILTER_VALIDATE_URL ) ) {
445 $path = wp_parse_url( $plugin, PHP_URL_PATH );
446 $base = $path ? basename( $path ) : '';
447 $slug = $base ? preg_replace( '/\.zip$/', '', $base ) : '';
448 if ( $slug ) {
449 $plugin = $slug;
450 }
451 }
452
453 // If a "folder/file.php" was provided, reduce to folder (slug).
454 if ( strpos( $plugin, '/' ) !== false ) {
455 $plugin = explode( '/', $plugin )[0];
456 }
457
458 foreach ( $all_plugins as $basename => $plugin_data ) {
459 if ( strpos( $basename, $plugin ) === 0 ) {
460 return $basename;
461 }
462 }
463
464 return $plugin;
465 }