EasyDigitalDownloads
3 years ago
Elementor
2 years ago
Integrations
3 years ago
MemberPress
2 years ago
Plugins
2 years ago
Promos
3 years ago
Rules
2 years ago
Shortcodes
2 years ago
WPForms
3 years ago
WooCommerce
2 years ago
Actions.php
2 years ago
Ajax.php
4 years ago
Api.php
2 years ago
ApiAuth.php
4 years ago
ApiKey.php
2 years ago
AssetLoader.php
5 years ago
BaseRestApi.php
3 years ago
Blocks.php
2 years ago
ClassicEditor.php
3 years ago
ConstantContact.php
4 years ago
Debug.php
4 years ago
EasyDigitalDownloads.php
3 years ago
Elementor.php
3 years ago
Inserter.php
3 years ago
InstallSkin.php
5 years ago
InstallSkinCompat.php
5 years ago
MailPoet.php
4 years ago
MemberPress.php
2 years ago
Menu.php
2 years ago
Notifications.php
3 years ago
OmuApi.php
4 years ago
Output.php
2 years ago
Pages.php
2 years ago
Partners.php
2 years ago
Plugins.php
3 years ago
Promos.php
3 years ago
Refresh.php
2 years ago
RestApi.php
2 years ago
RevenueAttribution.php
4 years ago
Review.php
4 years ago
Rules.php
3 years ago
Save.php
2 years ago
Shortcode.php
4 years ago
Sites.php
2 years ago
Support.php
3 years ago
Type.php
3 years ago
Urls.php
2 years ago
Utils.php
3 years ago
Validate.php
4 years ago
WPForms.php
2 years ago
Welcome.php
4 years ago
Widget.php
4 years ago
WooCommerce.php
2 years ago
Wordfence.php
3 years ago
WpErrorException.php
5 years ago
Plugins.php
373 lines
| 1 | <?php |
| 2 | /** |
| 3 | * AM Plugins class. |
| 4 | * |
| 5 | * @since 1.9.10 |
| 6 | * |
| 7 | * @package OMAPI |
| 8 | * @author Justin Sternberg |
| 9 | */ |
| 10 | |
| 11 | // Exit if accessed directly. |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * AM Plugins class. |
| 18 | * |
| 19 | * @since 1.9.10 |
| 20 | */ |
| 21 | class OMAPI_Plugins { |
| 22 | |
| 23 | /** |
| 24 | * The Base OMAPI Object |
| 25 | * |
| 26 | * @since 1.8.0 |
| 27 | * |
| 28 | * @var OMAPI |
| 29 | */ |
| 30 | protected $base; |
| 31 | |
| 32 | /** |
| 33 | * Plugins array. |
| 34 | * |
| 35 | * @since 2.10.0 |
| 36 | * |
| 37 | * @var array |
| 38 | */ |
| 39 | protected static $plugins = array(); |
| 40 | |
| 41 | /** |
| 42 | * Constructor. |
| 43 | * |
| 44 | * @since 1.8.0 |
| 45 | */ |
| 46 | public function __construct() { |
| 47 | $this->base = OMAPI::get_instance(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Gets the list of AM plugins. |
| 52 | * |
| 53 | * @since 2.0.0 |
| 54 | * |
| 55 | * @return array List of AM plugins. |
| 56 | */ |
| 57 | public function get_list() { |
| 58 | if ( empty( self::$plugins ) ) { |
| 59 | self::$plugins = array( |
| 60 | 'wpforms-lite/wpforms.php' => array( |
| 61 | 'slug' => 'wpforms', |
| 62 | 'icon' => $this->base->url . 'assets/images/about/plugin-wp-forms.png', |
| 63 | 'class' => 'wpforms-litewpformsphp', |
| 64 | 'check' => array( 'function' => 'wpforms' ), |
| 65 | 'name' => 'WPForms', |
| 66 | 'desc' => __( 'WPForm’s easy drag & drop WordPress form builder allows you to create contact forms, online surveys, donation forms, order forms and morein just a few minutes without writing any code.', 'optin-monster-api' ), |
| 67 | 'url' => 'https://downloads.wordpress.org/plugin/wpforms-lite.zip', |
| 68 | 'pro' => array( |
| 69 | 'plugin' => 'wpforms-premium/wpforms.php', |
| 70 | 'name' => 'WPForms Pro', |
| 71 | 'url' => 'https://wpforms.com/?utm_source=WordPress&utm_medium=Plugin&utm_campaign=OptinMonsterAboutUs', |
| 72 | ), |
| 73 | ), |
| 74 | 'google-analytics-for-wordpress/googleanalytics.php' => array( |
| 75 | 'slug' => 'monsterinsights', |
| 76 | 'icon' => $this->base->url . 'assets/images/about/plugin-mi.png', |
| 77 | 'class' => 'google-analytics-for-wordpressgoogleanalyticsphp', |
| 78 | 'check' => array( 'function' => 'MonsterInsights' ), |
| 79 | 'name' => 'MonsterInsights', |
| 80 | /* translators: %s - MonsterInsights Plugin name.*/ |
| 81 | 'desc' => sprintf( __( '%s makes it effortless to properly connect your WordPress site with Google Analytics, so you can start making data-driven decisions to grow your business.', 'optin-monster-api' ), 'MonsterInsights' ), |
| 82 | 'url' => 'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.zip', |
| 83 | 'pro' => array( |
| 84 | 'plugin' => 'google-analytics-premium/googleanalytics-premium.php', |
| 85 | 'name' => 'MonsterInsights Pro', |
| 86 | 'url' => 'https://www.monsterinsights.com/?utm_source=WordPress&utm_medium=Plugin&utm_campaign=OptinMonsterAboutUs', |
| 87 | ), |
| 88 | ), |
| 89 | 'rafflepress/rafflepress.php' => array( |
| 90 | 'slug' => 'rafflepress', |
| 91 | 'icon' => $this->base->url . 'assets/images/about/plugin-rafflepress.png', |
| 92 | 'class' => 'rafflepressrafflepressphp', |
| 93 | 'check' => array( |
| 94 | 'constant' => array( |
| 95 | 'RAFFLEPRESS_VERSION', |
| 96 | 'RAFFLEPRESS_PRO_VERSION', |
| 97 | ), |
| 98 | ), |
| 99 | 'name' => 'RafflePress', |
| 100 | 'desc' => __( 'Turn your visitors into brand ambassadors! Easily grow your email list, website traffic, and social media followers with powerful viral giveaways & contests.', 'optin-monster-api' ), |
| 101 | 'url' => 'https://downloads.wordpress.org/plugin/rafflepress.zip', |
| 102 | 'pro' => array( |
| 103 | 'plugin' => '', |
| 104 | 'name' => 'RafflePress', |
| 105 | 'url' => 'https://rafflepress.com/?utm_source=WordPress&utm_medium=Plugin&utm_campaign=OptinMonsterAboutUs', |
| 106 | ), |
| 107 | ), |
| 108 | 'wp-mail-smtp/wp_mail_smtp.php' => array( |
| 109 | 'slug' => 'wpmailsmtp', |
| 110 | 'icon' => $this->base->url . 'assets/images/about/plugin-wp-mail-smtp.png', |
| 111 | 'class' => 'wp-mail-smtpwp-mail-smtpphp', |
| 112 | 'check' => array( 'function' => 'wp_mail_smtp' ), |
| 113 | 'name' => 'WP Mail SMTP', |
| 114 | 'desc' => __( 'Make sure your website’s emails reach the inbox. Our goal is to make email deliverability easy and reliable. Trusted by over 1 MILLION websites.', 'optin-monster-api' ), |
| 115 | 'url' => 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip', |
| 116 | 'pro' => array( |
| 117 | 'plugin' => 'wp-mail-smtp-pro/wp_mail_smtp.php', |
| 118 | 'name' => 'WP Mail SMTP', |
| 119 | 'url' => 'https://wpmailsmtp.com/?utm_source=WordPress&utm_medium=Plugin&utm_campaign=OptinMonsterAboutUs', |
| 120 | ), |
| 121 | ), |
| 122 | 'all-in-one-seo-pack/all_in_one_seo_pack.php' => array( |
| 123 | 'slug' => 'aioseo', |
| 124 | 'icon' => $this->base->url . 'assets/images/about/plugin-aioseo.png', |
| 125 | 'class' => 'all-in-one-seo-packall-in-one-seo-packphp', |
| 126 | 'check' => array( |
| 127 | 'constant' => array( |
| 128 | 'AIOSEOP_VERSION', |
| 129 | 'AIOSEO_VERSION', |
| 130 | ), |
| 131 | ), |
| 132 | 'name' => 'AIOSEO', |
| 133 | /* translators: %s - AIOSEO Plugin name.*/ |
| 134 | 'desc' => sprintf( __( 'Easily set up proper SEO foundations for your site in less than 10 minutes with %s. It’s the most powerful and user-friendly WordPress SEO plugin, used by over 2 MILLION sites.', 'optin-monster-api' ), 'All-in-One SEO' ), |
| 135 | 'url' => 'https://downloads.wordpress.org/plugin/all-in-one-seo-pack.zip', |
| 136 | 'pro' => array( |
| 137 | 'plugin' => '', |
| 138 | 'name' => 'All-in-One SEO Pack', |
| 139 | 'url' => 'https://aioseo.com/?utm_source=WordPress&utm_medium=Plugin&utm_campaign=OptinMonsterAboutUs', |
| 140 | ), |
| 141 | ), |
| 142 | 'coming-soon/coming-soon.php' => array( |
| 143 | 'slug' => 'seedprod', |
| 144 | 'icon' => $this->base->url . 'assets/images/about/plugin-seedprod.png', |
| 145 | 'class' => 'coming-sooncoming-soonphp', |
| 146 | 'check' => array( |
| 147 | 'constant' => array( |
| 148 | 'SEEDPROD_PRO_VERSION', |
| 149 | 'SEEDPROD_VERSION', |
| 150 | ), |
| 151 | ), |
| 152 | 'name' => 'SeedProd', |
| 153 | 'desc' => __( 'Professionally design landing page templates like coming soon pages and sales pages that get you up and going with just a few clicks of a mouse. Used on over 1 MILLION sites! ', 'optin-monster-api' ), |
| 154 | 'url' => 'https://downloads.wordpress.org/plugin/coming-soon.zip', |
| 155 | 'pro' => array( |
| 156 | 'plugin' => '~seedprod-coming-soon-pro*~', |
| 157 | 'name' => 'SeedProd', |
| 158 | 'url' => 'https://www.seedprod.com/?utm_source=WordPress&utm_medium=Plugin&utm_campaign=OptinMonsterAboutUs', |
| 159 | ), |
| 160 | ), |
| 161 | 'trustpulse-api/trustpulse.php' => array( |
| 162 | 'slug' => 'trustpulse', |
| 163 | 'icon' => $this->base->url . 'assets/images/about/plugin-trustpulse.png', |
| 164 | 'class' => 'trustpulse-apitrustpulsephp', |
| 165 | 'check' => array( 'class' => 'TPAPI' ), |
| 166 | 'name' => 'TrustPulse', |
| 167 | 'desc' => __( 'TrustPulse is the honest marketing platform that leverages and automates the real power of social proof to instantly increase trust, conversions and sales.', 'optin-monster-api' ), |
| 168 | 'url' => 'https://downloads.wordpress.org/plugin/trustpulse-api.zip', |
| 169 | 'pro' => array( |
| 170 | 'plugin' => '', |
| 171 | 'name' => 'TrustPulse', |
| 172 | 'url' => 'https://trustpulse.com/?utm_source=WordPress&utm_medium=Plugin&utm_campaign=OptinMonsterAboutUs', |
| 173 | ), |
| 174 | ), |
| 175 | 'pushengage/main.php' => array( |
| 176 | 'slug' => 'pushengage', |
| 177 | 'icon' => $this->base->url . 'assets/images/about/plugin-pushengage.png', |
| 178 | 'class' => 'pushengagemainphp', |
| 179 | 'check' => array( 'constant' => 'PUSHENGAGE_VERSION' ), |
| 180 | 'name' => 'PushEngage', |
| 181 | 'desc' => __( 'Plugin to push notifications for Chrome, Firefox, Opera, Microsoft Edge, Safari, UC Browser and Samsung Internet browsers.', 'optin-monster-api' ), |
| 182 | 'url' => 'https://downloads.wordpress.org/plugin/pushengage.zip', |
| 183 | ), |
| 184 | ); |
| 185 | foreach ( self::$plugins as $plugin_id => $plugin ) { |
| 186 | self::$plugins[ $plugin_id ]['id'] = $plugin_id; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return self::$plugins; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Gets the list of AM plugins which include plugin status (installed/activated). |
| 195 | * |
| 196 | * @since 2.10.0 |
| 197 | * |
| 198 | * @return array List of AM plugins. |
| 199 | */ |
| 200 | public function get_list_with_status() { |
| 201 | $this->get_list(); |
| 202 | foreach ( self::$plugins as $plugin_id => $data ) { |
| 203 | if ( ! isset( $data['status'] ) ) { |
| 204 | self::$plugins[ $plugin_id ] = $this->get( $plugin_id )->get_data(); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return self::$plugins; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Get given Plugin instance. |
| 213 | * |
| 214 | * @since 2.10.0 |
| 215 | * |
| 216 | * @param string $plugin_id The plugin ID. |
| 217 | * |
| 218 | * @return OMAPI_Plugins_Plugin |
| 219 | */ |
| 220 | public function get( $plugin_id ) { |
| 221 | return OMAPI_Plugins_Plugin::get( $plugin_id ); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Installs and activates a plugin for a given url (if user is allowed). |
| 226 | * |
| 227 | * @since 2.0.0 |
| 228 | * |
| 229 | * @param OMAPI_Plugins_Plugin $plugin The Plugin instance. |
| 230 | * @return array On success. |
| 231 | * @throws Exception On error. |
| 232 | */ |
| 233 | public function install_plugin( OMAPI_Plugins_Plugin $plugin ) { |
| 234 | |
| 235 | $not_allowed_exception = new Exception( esc_html__( 'Sorry, not allowed!', 'optin-monster-api' ), rest_authorization_required_code() ); |
| 236 | |
| 237 | // Check for permissions. |
| 238 | if ( ! current_user_can( 'install_plugins' ) ) { |
| 239 | throw $not_allowed_exception; |
| 240 | } |
| 241 | |
| 242 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 243 | $creds = request_filesystem_credentials( admin_url( 'admin.php' ), '', false, false, null ); |
| 244 | |
| 245 | // Check for file system permissions. |
| 246 | if ( false === $creds ) { |
| 247 | throw $not_allowed_exception; |
| 248 | } |
| 249 | |
| 250 | // We do not need any extra credentials if we have gotten this far, so let's install the plugin. |
| 251 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 252 | if ( ! function_exists( 'get_plugin_data' ) ) { |
| 253 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 254 | } |
| 255 | |
| 256 | $skin = version_compare( $GLOBALS['wp_version'], '5.3', '>=' ) |
| 257 | ? new OMAPI_InstallSkin() |
| 258 | : new OMAPI_InstallSkinCompat(); |
| 259 | |
| 260 | // Create the plugin upgrader with our custom skin. |
| 261 | $installer = new Plugin_Upgrader( $skin ); |
| 262 | |
| 263 | // Error check. |
| 264 | if ( ! method_exists( $installer, 'install' ) ) { |
| 265 | throw new Exception( esc_html__( 'Missing required installer!', 'optin-monster-api' ), 500 ); |
| 266 | } |
| 267 | |
| 268 | $result = $installer->install( esc_url_raw( $plugin['url'] ) ); |
| 269 | |
| 270 | if ( ! $installer->plugin_info() ) { |
| 271 | throw new Exception( esc_html__( 'Plugin failed to install!', 'optin-monster-api' ), 500 ); |
| 272 | } |
| 273 | |
| 274 | update_option( |
| 275 | sanitize_text_field( $plugin['slug'] . '_referred_by' ), |
| 276 | 'optinmonster' |
| 277 | ); |
| 278 | |
| 279 | $plugin_basename = $installer->plugin_info(); |
| 280 | |
| 281 | // Activate the plugin silently. |
| 282 | try { |
| 283 | $this->activate_plugin( $plugin_basename ); |
| 284 | |
| 285 | return array( |
| 286 | 'message' => esc_html__( 'Plugin installed & activated.', 'optin-monster-api' ), |
| 287 | 'is_activated' => true, |
| 288 | 'basename' => $plugin_basename, |
| 289 | ); |
| 290 | |
| 291 | } catch ( \Exception $e ) { |
| 292 | |
| 293 | return array( |
| 294 | 'message' => esc_html__( 'Plugin installed.', 'optin-monster-api' ), |
| 295 | 'is_activated' => false, |
| 296 | 'basename' => $plugin_basename, |
| 297 | ); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Activates a plugin with a given plugin name (if user is allowed). |
| 303 | * |
| 304 | * @since 2.0.0 |
| 305 | * |
| 306 | * @param string $plugin_id |
| 307 | * @return array On success. |
| 308 | * @throws Exception On error. |
| 309 | */ |
| 310 | public function activate_plugin( $plugin_id ) { |
| 311 | |
| 312 | // Check for permissions. |
| 313 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 314 | throw new Exception( esc_html__( 'Sorry, not allowed!', 'optin-monster-api' ), rest_authorization_required_code() ); |
| 315 | } |
| 316 | |
| 317 | if ( ! function_exists( 'get_plugin_data' ) ) { |
| 318 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 319 | } |
| 320 | |
| 321 | $activate = activate_plugin( sanitize_text_field( $plugin_id ), '', false, true ); |
| 322 | |
| 323 | if ( is_wp_error( $activate ) ) { |
| 324 | $e = new OMAPI_WpErrorException(); |
| 325 | throw $e->setWpError( $activate ); |
| 326 | } |
| 327 | |
| 328 | // Prevent the various welcome/onboarding redirects that may occur when activating plugins. |
| 329 | switch ( $plugin_id ) { |
| 330 | case 'google-analytics-for-wordpress/googleanalytics.php': |
| 331 | delete_transient( '_monsterinsights_activation_redirect' ); |
| 332 | break; |
| 333 | case 'wpforms-lite/wpforms.php': |
| 334 | update_option( 'wpforms_activation_redirect', true ); |
| 335 | break; |
| 336 | case 'all-in-one-seo-pack/all_in_one_seo_pack.php': |
| 337 | update_option( 'aioseo_activation_redirect', true ); |
| 338 | break; |
| 339 | case 'trustpulse-api/trustpulse.php': |
| 340 | delete_option( 'trustpulse_api_plugin_do_activation_redirect' ); |
| 341 | break; |
| 342 | } |
| 343 | |
| 344 | return array( |
| 345 | 'message' => esc_html__( 'Plugin activated.', 'optin-monster-api' ), |
| 346 | 'basename' => $plugin_id, |
| 347 | ); |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Get a active plugins header value for OM app requests. |
| 352 | * |
| 353 | * @since 2.9.0 |
| 354 | * |
| 355 | * @return string The plugins header value. |
| 356 | */ |
| 357 | public function get_active_plugins_header_value() { |
| 358 | $wpf_active = $this->base->wpforms->is_active(); |
| 359 | |
| 360 | // Set initial values. |
| 361 | $plugins = array( |
| 362 | // We want to know information about WPForms regardless |
| 363 | // of if it's active. We'll use this to "disconnect" WPForms if it's not active. |
| 364 | 'wpf' => array( |
| 365 | 'a' => $wpf_active, |
| 366 | 'v' => $wpf_active ? $this->base->wpforms->version() : 0, |
| 367 | ), |
| 368 | ); |
| 369 | |
| 370 | return http_build_query( $plugins ); |
| 371 | } |
| 372 | } |
| 373 |