install( self::CONTENT_EMBED_LINK ); if ( is_wp_error( $result ) ) { $status['errorCode'] = 'GENERIC_ERROR'; $status['errorMessage'] = $result->get_error_message(); wp_send_json_error( $status ); } if ( is_wp_error( $skin->result ) ) { $status['errorCode'] = 'GENERIC_ERROR'; $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error( $status ); } if ( $skin->get_errors()->has_errors() ) { $status['errorCode'] = 'GENERIC_ERROR'; $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error( $status ); } if ( is_null( $result ) ) { global $wp_filesystem; $status['errorCode'] = 'FILESYSTEM_ERROR'; $status['errorMessage'] = 'Unable to connect to the filesystem. Please confirm your credentials.'; // Pass through the error from WP_Filesystem if one was raised. if ( $wp_filesystem instanceof \WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } wp_send_json_error( $status ); } $plugin_info = $upgrader->plugin_info(); if ( ! $plugin_info ) { return wp_send_json_error( array( 'errorCode' => 'INFO_FETCH_ERROR', 'errorMessage' => 'Plugin installation failed, could not retrieve plugin info', ), 500 ); } $status = array( 'message' => 'Plugin installed and activated successfully', 'plugin_info' => $plugin_info, 'activated' => false, ); if ( current_user_can( 'activate_plugins' ) ) { $activation_response = activate_plugin( $plugin_info ); if ( is_wp_error( $activation_response ) ) { $status['errorCode'] = 'ACTIVATION_ERROR'; $status['errorMessage'] = $activation_response->get_error_message(); } else { $status['activated'] = true; } } update_option( self::INSTALL_OPTION, true ); return wp_send_json_success( $status ); } /** * Determine if there is a copy of Content embed installed, and if so, if it is active. * Checks for path names with junk at the end to handle multiple installs */ public static function is_content_embed_active_installed() { $content_embed_regex = '/hubspot-content-embed((-.*)?)\/content-embed.php/'; if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // Filter based on regex in case there are multiple copies installed for some reason. $all_plugins = array_keys( get_plugins() ); $content_embed_paths = array_filter( $all_plugins, function ( $plugin_path ) use ( $content_embed_regex ) { return preg_match( $content_embed_regex, $plugin_path ); } ); $installed = ! empty( $content_embed_paths ); $active = ! empty( array_filter( $content_embed_paths, function ( $plugin_path ) { return is_plugin_active( $plugin_path ); } ) ); return array( 'installed' => $installed, 'active' => $active, ); } }