PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.32
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.32
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 +109 -10 6.36.32 View file →
@@ -7,28 +7,37 @@
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
23 + /**
24 + * @param array $atts
25 + */
14 26 public function __construct( $atts ) {
15 - $this->plugin_file = $atts['plugin_file'];
27 + $this->plugin_file = $atts['plugin_file'];
16 28 list( $slug, $file ) = explode( '/', $this->plugin_file );
17 - $this->plugin_slug = $slug;
29 + $this->plugin_slug = $slug;
18 30 }
19 31
32 + /**
33 + * @return string
34 + */
20 35 public function get_activate_link() {
21 36 if ( $this->is_installed() && $this->is_active() ) {
22 37 return '';
23 38 }
24 -
25 - if ( $this->is_installed() ) {
26 - $url = $this->activate_url();
27 - } else {
28 - $url = $this->install_url();
29 - }
30 - return $url;
39 + return $this->is_installed() ? $this->activate_url() : $this->install_url();
31 40 }
32 41
33 42 /**
34 43 * @return bool
@@ -55,6 +64,96 @@
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 + if ( ! empty( get_plugins()[ $plugin_slug ] ) ) {
86 + $activate = activate_plugin( $plugin_slug );
87 + } else {
88 + // Include necessary files for plugin installation.
89 + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
90 + require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
91 +
92 + // Get the plugin information.
93 + $api = plugins_api(
94 + 'plugin_information',
95 + array(
96 + 'slug' => $plugin_slug,
97 + 'fields' => array(
98 + 'sections' => false,
99 + ),
100 + )
101 + );
102 +
103 + if ( is_wp_error( $api ) ) {
104 + wp_send_json_error( $api->get_error_message() );
105 + }
106 +
107 + if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) {
108 + wp_send_json_error( 'This download is not allowed' );
109 + }
110 +
111 + // Set up the Plugin Upgrader.
112 + $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
113 +
114 + // Install the plugin.
115 + $result = $upgrader->install( $api->versions['trunk'] );
116 +
117 + if ( is_wp_error( $result ) ) {
118 + wp_send_json_error( $result->get_error_message() );
119 + }
120 +
121 + // Activate the plugin.
122 + $activate = activate_plugin( $upgrader->plugin_info() );
123 + }//end if
124 +
125 + if ( is_wp_error( $activate ) ) {
126 + wp_send_json_error( $activate->get_error_message() );
127 + }
128 +
129 + if ( 'wp-mail-smtp' === $plugin_slug ) {
130 + update_option( 'wp_mail_smtp_activation_prevent_redirect', true );
131 + }
132 +
133 + // Send a success response.
134 + wp_send_json_success( __( 'Plugin installed and activated successfully.', 'formidable' ) );
135 + }
136 +
137 + /**
138 + * Checks plugin activation status via AJAX.
139 + *
140 + * @since 6.9
141 + *
142 + * @return void
143 + */
144 + public static function ajax_check_plugin_activation() {
145 + // Check permission and nonce.
146 + FrmAppHelper::permission_check( 'install_plugins' );
147 + check_ajax_referer( 'frm_ajax', 'nonce' );
148 +
149 + // Retrieve plugin identifier.
150 + $plugin_path = FrmAppHelper::get_post_param( 'plugin_path', '', 'sanitize_text_field' );
151 +
152 + // Respond based on plugin status.
153 + if ( is_plugin_active( $plugin_path ) ) {
154 + wp_send_json_success();
155 + } else {
156 + wp_send_json_error();
157 + }
59 158 }
60 159 }