Skip to content

Commit

Permalink
Merge pull request #1 from sterner-stuff/main
Browse files Browse the repository at this point in the history
2.4.8
  • Loading branch information
ethanclevenger91 authored Oct 27, 2022
2 parents bd2e6a5 + 282eaa6 commit 8df97f9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
4 changes: 2 additions & 2 deletions kinsta-mu-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Kinsta Must-use Plugins
* Plugin URI: https://kinsta.com/knowledgebase/kinsta-mu-plugin/
* Description: The plugin designed to work on Kinsta's managed WordPress hosting platform.
* Version: 2.4.7
* Version: 2.4.8
* Author: Kinsta Team
* Author URI: https://kinsta.com/about-us/
* Text Domain: kinsta-mu-plugins
Expand All @@ -16,7 +16,7 @@
die( 'No script kiddies please!' );
}

define( 'KINSTAMU_VERSION', '2.4.7' );
define( 'KINSTAMU_VERSION', '2.4.8' );
if ( ! defined( 'KINSTAMU_WHITELABEL' ) ) {
define( 'KINSTAMU_WHITELABEL', false );
}
Expand Down
73 changes: 46 additions & 27 deletions kinsta-mu-plugins/cache/class-cache-purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public function purge_complete_full_page_cache() {
* @return void
*/
public function purge_complete_caches() {
if ( defined( 'KINSTAMU_DISABLE_AUTOPURGE' ) && KINSTAMU_DISABLE_AUTOPURGE === true ) {
return;
}
$this->purge_complete_object_cache();
$this->purge_complete_full_page_cache();

Expand All @@ -298,8 +301,6 @@ public function initiate_purge( $post_id ) {
return false;
}

$result['time']['start'] = microtime( true );

$post = get_post( $post_id );
if ( false === is_post_type_viewable( $post->post_type ) ) {
return;
Expand Down Expand Up @@ -389,39 +390,57 @@ public function initiate_purge( $post_id ) {

$result['requests'] = $purge_request;

if ( defined( 'KINSTA_CACHE_DEBUG' ) && KINSTA_CACHE_DEBUG === true ) {
$is_cache_debug = ( defined( 'KINSTA_CACHE_DEBUG' ) ) ? KINSTA_CACHE_DEBUG : false;

$result['response'] = array(
'immediate' => $this->send_cache_purge_request( $this->kinsta_cache->config['immediate_path'], $purge_request['immediate'] ),
'throttled' => $this->send_cache_purge_request( $this->kinsta_cache->config['throttled_path'], $purge_request['throttled'] ),
);

// Hook that fires after specific event purges cache.
do_action( 'kinsta_initiate_purge_happened' );

if ( $is_cache_debug ) {
echo '<pre>';
print_r( $purge_request );
var_dump( $result['response'] );
echo '</pre>';
exit();
}
return $result;
}

$result['time']['sendrequest'] = microtime( true );

$result['response']['immediate'] = wp_remote_post(
$this->kinsta_cache->config['immediate_path'],
array(
'sslverify' => false,
'timeout' => 5,
'body' => $purge_request['immediate'],
)
);

$result['response']['throttled'] = wp_remote_post(
$this->kinsta_cache->config['throttled_path'],
array(
'sslverify' => false,
'timeout' => 5,
'body' => $purge_request['throttled'],
)
/**
* Send POST request to cache endpoint. Returns array of curl information
*
* @param string $endpoint_url Endpoint to send purge list to.
* @param array $post_body URLs to send.
*
* @return array
*/
public function send_cache_purge_request( $endpoint_url, $post_body ) {
$cache_purge_timeout = ( defined( 'KINSTAMU_CACHE_PURGE_TIMEOUT' ) ) ? (int) KINSTAMU_CACHE_PURGE_TIMEOUT : 5;
$response_data = array(
'response_code' => 0,
'error_code' => 0,
'response_body' => '',
'error_message' => '',
);

// Hook that fires after specific event purges cache.
do_action( 'kinsta_initiate_purge_happened' );

$result['time']['end'] = microtime( true );

return $result;
$post_request = curl_init( $endpoint_url );
curl_setopt( $post_request, CURLOPT_POST, true );
curl_setopt( $post_request, CURLOPT_POSTFIELDS, http_build_query( $post_body ) );
curl_setopt( $post_request, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $post_request, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $post_request, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $post_request, CURLOPT_CONNECTTIMEOUT, $cache_purge_timeout );
curl_setopt( $post_request, CURLOPT_TIMEOUT, $cache_purge_timeout );
$response_data['response_body'] = curl_exec( $post_request );
$response_data['error_code'] = curl_errno( $post_request );
$response_data['error_message'] = curl_error( $post_request );
$response_data['response_code'] = curl_getinfo( $post_request, CURLINFO_HTTP_CODE );
curl_close( $post_request );
return $response_data;
}

/**
Expand Down
17 changes: 15 additions & 2 deletions kinsta-mu-plugins/compat/class-banned-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ private function get_notifiable_plugins() {

$notifiable_plugins = array();
foreach ( $active_banned_plugins as $plugin_file ) {
$notifiable_plugins[ $plugin_file ] = $installed_plugins[ $plugin_file ];
if ( array_key_exists( $plugin_file, $installed_plugins ) ) {
$notifiable_plugins[ $plugin_file ] = $installed_plugins[ $plugin_file ];
}
}

return array_column( $notifiable_plugins, 'Name' );
Expand Down Expand Up @@ -584,9 +586,20 @@ private function shall_display_admin_notice() {

$shall = false;
$dismissed = get_transient( 'kinsta_dismiss_banned_plugins_nag' );
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$installed_plugins = get_plugins();
$active_banned_plugins = array_intersect( (array) $this->active_plugins, (array) $this->banned_list );

if ( current_user_can( 'activate_plugins' ) && ! empty( $active_banned_plugins ) && 1 !== absint( $dismissed ) ) {
$active_banned_plugin_count = 0;
foreach ( $active_banned_plugins as $plugin_file ) {
if ( array_key_exists( $plugin_file, $installed_plugins ) ) {
$active_banned_plugin_count += 1;
}
}

if ( current_user_can( 'activate_plugins' ) && 0 < $active_banned_plugin_count && 1 !== absint( $dismissed ) ) {
$shall = true;
}

Expand Down

0 comments on commit 8df97f9

Please sign in to comment.