Astra_Admin_Ajax::required_plugin_install()
Handles the installation and saving of required plugins.
Description
This function is responsible for installing and saving required plugins for the Astra theme. It checks for the plugin slug in the AJAX request, verifies the nonce, and initiates the plugin installation process. If the plugin is successfully installed, it schedules a database update to map the plugin slug to a custom key for analytics tracking.
Source
File: admin/includes/class-astra-admin-ajax.php
public function required_plugin_install() { check_ajax_referer( 'updates', '_ajax_nonce' ); // Fetching the plugin slug from the AJAX request. // @psalm-suppress PossiblyInvalidArgument $plugin_slug = isset( $_POST['slug'] ) && is_string( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; if ( empty( $plugin_slug ) ) { wp_send_json_error( array( 'message' => __( 'Plugin slug is missing.', 'astra' ) ) ); } // Schedule the database update if the plugin is installed successfully. add_action( 'shutdown', function () use ( $plugin_slug ) { // Iterate through all plugins to check if the installed plugin matches the current plugin slug. $all_plugins = get_plugins(); foreach ( $all_plugins as $plugin_file => $_ ) { if ( is_callable( 'BSF_UTM_Analytics::update_referer' ) && strpos( $plugin_file, $plugin_slug . '/' ) === 0 ) { // If the plugin is found and the update_referer function is callable, update the referer with the corresponding product slug. BSF_UTM_Analytics::update_referer( 'astra', $plugin_slug ); return; } } } ); if ( function_exists( 'wp_ajax_install_plugin' ) ) { // @psalm-suppress NoValue wp_ajax_install_plugin(); } else { wp_send_json_error( array( 'message' => __( 'Plugin installation function not found.', 'astra' ) ) ); } }
Expand full source code Collapse full source code View on Trac
Changelog
Version | Description |
---|---|
4.8.12 | Introduced. |