Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/leadin/public/admin
File: class-contentembedinstaller.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Leadin\admin;
[2] Fix | Delete
[3] Fix | Delete
use Leadin\utils\QueryParameters;
[4] Fix | Delete
[5] Fix | Delete
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Class used to install the Content embed plugin
[9] Fix | Delete
*/
[10] Fix | Delete
class ContentEmbedInstaller {
[11] Fix | Delete
[12] Fix | Delete
const CONTENT_EMBED_LINK = 'https://api.hubapi.com/content-embed/v1/plugin/download/content-hub-embed.zip';
[13] Fix | Delete
const INSTALL_ARG = 'contentembed_install';
[14] Fix | Delete
const INSTALL_OPTION = LEADIN_PREFIX . '_content_embed_ui_install';
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Class constructor, adds the necessary hooks.
[18] Fix | Delete
*/
[19] Fix | Delete
public function __construct() {
[20] Fix | Delete
if ( is_admin() ) {
[21] Fix | Delete
add_action( 'wp_ajax_content_embed_install', array( $this, 'wp_ajax_install_content_embed' ) );
[22] Fix | Delete
}
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* AJAX to install Content embed plugin by downloading from URL in Content embed API.
[28] Fix | Delete
* Modified from: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-admin/includes/ajax-actions.php#L4444
[29] Fix | Delete
*/
[30] Fix | Delete
public function wp_ajax_install_content_embed() {
[31] Fix | Delete
$nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( ( $_REQUEST['_wpnonce'] ) ) ) : '';
[32] Fix | Delete
[33] Fix | Delete
if ( ! current_user_can( 'install_plugins' ) || ! wp_verify_nonce( $nonce, self::INSTALL_ARG ) ) {
[34] Fix | Delete
$status['errorCode'] = 'PERMISSIONS_ERROR';
[35] Fix | Delete
$status['errorMessage'] = 'User does not have permission to install or activate plugins.';
[36] Fix | Delete
return wp_send_json_error( $status, 403 );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$active_or_installed = self::is_content_embed_active_installed();
[40] Fix | Delete
$activated = $active_or_installed['active'];
[41] Fix | Delete
$installed = $active_or_installed['installed'];
[42] Fix | Delete
[43] Fix | Delete
if ( $activated || $installed ) {
[44] Fix | Delete
$status['errorCode'] = $activated ? 'ALREADY_ACTIVATED' : 'ALREADY_INSTALLED';
[45] Fix | Delete
$status['errorMessage'] = 'Content embed already installed or activated';
[46] Fix | Delete
wp_send_json_error( $status );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
[50] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
[51] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin.php';
[52] Fix | Delete
[53] Fix | Delete
$skin = new \WP_Ajax_Upgrader_Skin();
[54] Fix | Delete
$upgrader = new \Plugin_Upgrader( $skin );
[55] Fix | Delete
$result = $upgrader->install( self::CONTENT_EMBED_LINK );
[56] Fix | Delete
[57] Fix | Delete
if ( is_wp_error( $result ) ) {
[58] Fix | Delete
$status['errorCode'] = 'GENERIC_ERROR';
[59] Fix | Delete
$status['errorMessage'] = $result->get_error_message();
[60] Fix | Delete
wp_send_json_error( $status );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
if ( is_wp_error( $skin->result ) ) {
[64] Fix | Delete
$status['errorCode'] = 'GENERIC_ERROR';
[65] Fix | Delete
$status['errorMessage'] = $skin->result->get_error_message();
[66] Fix | Delete
wp_send_json_error( $status );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
if ( $skin->get_errors()->has_errors() ) {
[70] Fix | Delete
$status['errorCode'] = 'GENERIC_ERROR';
[71] Fix | Delete
$status['errorMessage'] = $skin->get_error_messages();
[72] Fix | Delete
wp_send_json_error( $status );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
if ( is_null( $result ) ) {
[76] Fix | Delete
global $wp_filesystem;
[77] Fix | Delete
$status['errorCode'] = 'FILESYSTEM_ERROR';
[78] Fix | Delete
$status['errorMessage'] = 'Unable to connect to the filesystem. Please confirm your credentials.';
[79] Fix | Delete
[80] Fix | Delete
// Pass through the error from WP_Filesystem if one was raised.
[81] Fix | Delete
if ( $wp_filesystem instanceof \WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
[82] Fix | Delete
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
[83] Fix | Delete
}
[84] Fix | Delete
wp_send_json_error( $status );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
$plugin_info = $upgrader->plugin_info();
[88] Fix | Delete
if ( ! $plugin_info ) {
[89] Fix | Delete
return wp_send_json_error(
[90] Fix | Delete
array(
[91] Fix | Delete
'errorCode' => 'INFO_FETCH_ERROR',
[92] Fix | Delete
'errorMessage' => 'Plugin installation failed, could not retrieve plugin info',
[93] Fix | Delete
),
[94] Fix | Delete
500
[95] Fix | Delete
);
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
$status = array(
[99] Fix | Delete
'message' => 'Plugin installed and activated successfully',
[100] Fix | Delete
'plugin_info' => $plugin_info,
[101] Fix | Delete
'activated' => false,
[102] Fix | Delete
);
[103] Fix | Delete
[104] Fix | Delete
if ( current_user_can( 'activate_plugins' ) ) {
[105] Fix | Delete
$activation_response = activate_plugin( $plugin_info );
[106] Fix | Delete
if ( is_wp_error( $activation_response ) ) {
[107] Fix | Delete
$status['errorCode'] = 'ACTIVATION_ERROR';
[108] Fix | Delete
$status['errorMessage'] = $activation_response->get_error_message();
[109] Fix | Delete
} else {
[110] Fix | Delete
$status['activated'] = true;
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
update_option( self::INSTALL_OPTION, true );
[115] Fix | Delete
return wp_send_json_success( $status );
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Determine if there is a copy of Content embed installed, and if so, if it is active.
[120] Fix | Delete
* Checks for path names with junk at the end to handle multiple installs
[121] Fix | Delete
*/
[122] Fix | Delete
public static function is_content_embed_active_installed() {
[123] Fix | Delete
$content_embed_regex = '/hubspot-content-embed((-.*)?)\/content-embed.php/';
[124] Fix | Delete
if ( ! function_exists( 'get_plugins' ) ) {
[125] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin.php';
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// Filter based on regex in case there are multiple copies installed for some reason.
[129] Fix | Delete
$all_plugins = array_keys( get_plugins() );
[130] Fix | Delete
$content_embed_paths = array_filter(
[131] Fix | Delete
$all_plugins,
[132] Fix | Delete
function ( $plugin_path ) use ( $content_embed_regex ) {
[133] Fix | Delete
return preg_match( $content_embed_regex, $plugin_path );
[134] Fix | Delete
}
[135] Fix | Delete
);
[136] Fix | Delete
[137] Fix | Delete
$installed = ! empty( $content_embed_paths );
[138] Fix | Delete
$active = ! empty(
[139] Fix | Delete
array_filter(
[140] Fix | Delete
$content_embed_paths,
[141] Fix | Delete
function ( $plugin_path ) {
[142] Fix | Delete
return is_plugin_active( $plugin_path );
[143] Fix | Delete
}
[144] Fix | Delete
)
[145] Fix | Delete
);
[146] Fix | Delete
[147] Fix | Delete
return array(
[148] Fix | Delete
'installed' => $installed,
[149] Fix | Delete
'active' => $active,
[150] Fix | Delete
);
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function