PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmInstallPlugin.php +94 -3 6.46.12 View file →
@@ -7,15 +7,24 @@
7 7 * @since 4.04.04
8 8 */
9 9 class FrmInstallPlugin {
10 10
11 - protected $plugin_file; // format: folder/filename.php
11 + /**
12 + * Format: folder/filename.php.
13 + *
14 + * @var string
15 + */
16 + protected $plugin_file;
17 +
18 + /**
19 + * @var string
20 + */
12 21 protected $plugin_slug;
13 22
14 23 public function __construct( $atts ) {
15 - $this->plugin_file = $atts['plugin_file'];
24 + $this->plugin_file = $atts['plugin_file'];
16 25 list( $slug, $file ) = explode( '/', $this->plugin_file );
17 - $this->plugin_slug = $slug;
26 + $this->plugin_slug = $slug;
18 27 }
19 28
20 29 public function get_activate_link() {
21 30 if ( $this->is_installed() && $this->is_active() ) {
@@ -55,6 +64,88 @@
55 64 * @return string
56 65 */
57 66 protected function activate_url() {
58 67 return wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $this->plugin_file ), 'activate-plugin_' . $this->plugin_file );
68 + }
69 +
70 + /**
71 + * Handles the AJAX request to install a plugin.
72 + *
73 + * @since 6.9
74 + *
75 + * @return void
76 + */
77 + public static function ajax_install_plugin() {
78 + // Check permission and nonce.
79 + FrmAppHelper::permission_check( 'install_plugins' );
80 + check_ajax_referer( 'frm_ajax', 'nonce' );
81 +
82 + // Get posted data.
83 + $plugin_slug = FrmAppHelper::get_post_param( 'plugin', '', 'sanitize_text_field' );
84 +
85 + // Include necessary files for plugin installation.
86 + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
87 + require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
88 +
89 + // Get the plugin information.
90 + $api = plugins_api(
91 + 'plugin_information',
92 + array(
93 + 'slug' => $plugin_slug,
94 + 'fields' => array(
95 + 'sections' => false,
96 + ),
97 + )
98 + );
99 + if ( is_wp_error( $api ) ) {
100 + wp_send_json_error( $api->get_error_message() );
101 + }
102 + if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) {
103 + wp_send_json_error( 'This download is not allowed' );
104 + }
105 +
106 + // Set up the Plugin Upgrader.
107 + $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
108 +
109 + // Install the plugin.
110 + $result = $upgrader->install( $api->versions['trunk'] );
111 + if ( is_wp_error( $result ) ) {
112 + wp_send_json_error( $result->get_error_message() );
113 + }
114 +
115 + // Activate the plugin.
116 + $activate = activate_plugin( $upgrader->plugin_info() );
117 + if ( is_wp_error( $activate ) ) {
118 + wp_send_json_error( $activate->get_error_message() );
119 + }
120 +
121 + if ( 'wp-mail-smtp' === $plugin_slug ) {
122 + update_option( 'wp_mail_smtp_activation_prevent_redirect', true );
123 + }
124 +
125 + // Send a success response.
126 + wp_send_json_success( __( 'Plugin installed and activated successfully.', 'formidable' ) );
127 + }
128 +
129 + /**
130 + * Checks plugin activation status via AJAX.
131 + *
132 + * @since 6.9
133 + *
134 + * @return void
135 + */
136 + public static function ajax_check_plugin_activation() {
137 + // Check permission and nonce.
138 + FrmAppHelper::permission_check( 'install_plugins' );
139 + check_ajax_referer( 'frm_ajax', 'nonce' );
140 +
141 + // Retrieve plugin identifier.
142 + $plugin_path = FrmAppHelper::get_post_param( 'plugin_path', '', 'sanitize_text_field' );
143 +
144 + // Respond based on plugin status.
145 + if ( is_plugin_active( $plugin_path ) ) {
146 + wp_send_json_success();
147 + } else {
148 + wp_send_json_error();
149 + }
59 150 }
60 151 }