Skip to content

Commit

Permalink
Fix transients (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxsimoxx authored Apr 18, 2024
1 parent 7185dfe commit a0d42ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions classes/PluginUpdate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private function get_directory_data($force = false) {
// We have it in memory
return $this->cp_plugins_directory_data;
}
$this->cp_plugins_directory_data = get_transient('cpdi_directory_data');
$this->cp_plugins_directory_data = get_transient('cpdi_directory_data_plugins');
if (!$force && $this->cp_plugins_directory_data !== false) {
// We have it in transient
return $this->cp_plugins_directory_data;
Expand Down Expand Up @@ -320,7 +320,7 @@ private function get_directory_data($force = false) {
}

$this->cp_plugins_directory_data = $data;
set_transient('cpdi_directory_data', $this->cp_plugins_directory_data, 3 * HOUR_IN_SECONDS);
set_transient('cpdi_directory_data_plugins', $this->cp_plugins_directory_data, 3 * HOUR_IN_SECONDS);
return $this->cp_plugins_directory_data;

}
Expand Down
8 changes: 4 additions & 4 deletions classes/ThemeInstall.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,25 @@ public static function do_directory_request($args = [], $type = 'themes')
// Enqueue a notice
private function add_notice($message, $failure = false)
{
$other_notices = get_transient('cpdi_pi_notices');
$other_notices = get_transient('cpdi_ti_notices');
$notice = $other_notices === false ? '' : $other_notices;
$failure_style = $failure ? 'notice-error' : 'notice-success';
$notice .= '<div class="notice ' . $failure_style . ' is-dismissible">';
$notice .= ' <p>' . esc_html($message) . '</p>';
$notice .= '</div>';
set_transient('cpdi_pi_notices', $notice, \HOUR_IN_SECONDS);
set_transient('cpdi_ti_notices', $notice, \HOUR_IN_SECONDS);
}

// Display notices
private function display_notices()
{
$notices = get_transient('cpdi_pi_notices');
$notices = get_transient('cpdi_ti_notices');
if ($notices === false) {
return;
}
// This contains html formatted from 'add_notice' function that uses 'esc_html'.
echo $notices; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
delete_transient('cpdi_pi_notices');
delete_transient('cpdi_ti_notices');
}

// Deal with activation requests
Expand Down
3 changes: 2 additions & 1 deletion classes/WPCLI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class CPDICLI{
public function flush($args, $assoc_args) {
$transients = [
'cpdi_pi_notices',
'cpdi_directory_data',
'cpdi_ti_notices',
'cpdi_directory_data_plugins',
'cpdi_directory_data_themes',
];

Expand Down

0 comments on commit a0d42ab

Please sign in to comment.