Skip to content

Commit

Permalink
= 4.2.0 =
Browse files Browse the repository at this point in the history
~ Modified: Admin notices LP Beta version.
  • Loading branch information
tungnxt89 committed Dec 14, 2022
1 parent 41935e1 commit cb6f989
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion inc/class-lp-session-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function set_customer_session_cookie(): LP_Session_Handler {

// Set the cookie
if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
learn_press_setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, is_ssl(), true );
learn_press_setcookie( $this->_cookie, $cookie_value, $this->_session_expiration );
}

return $this;
Expand Down
7 changes: 3 additions & 4 deletions inc/lp-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1808,16 +1808,15 @@ function learn_press_add_notice( $message, $type = 'updated' ) {
* @param string $name
* @param mixed $value
* @param int $expire
* @param bool $secure
* @param bool $httponly
*
* @editor tungnx
* @version 1.0.2
* @version 1.0.3
*/
function learn_press_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
function learn_press_setcookie( string $name = '', string $value = '', int $expire = 0, bool $httponly = true ) {
$secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );

@setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, true );
@setcookie( $name, $value, $expire, COOKIEPATH ?: '/', COOKIE_DOMAIN, $secure, $httponly );
}

/**
Expand Down
15 changes: 8 additions & 7 deletions inc/rest-api/v1/admin/class-lp-admin-rest-tools-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,25 @@ public function admin_notices( WP_REST_Request $request ) {

try {
$params = $request->get_params();
$admin_notices = $_SESSION['lp_admin_notices_dismiss'] ?? [];
$admin_notices = ! empty( $_COOKIE['lp_admin_notices_dismiss'] ) ? json_decode( wp_unslash( $_COOKIE['lp_admin_notices_dismiss'] ) ) : [];
$lp_beta_version_info = LP_Admin_Notice::check_lp_beta_version();

if ( isset( $params['dismiss'] ) ) {
if ( $lp_beta_version_info ) {
// Store version of LP beta to session.
$_SESSION['lp_beta_version'] = $lp_beta_version_info['version'] ?? 0;
learn_press_setcookie( 'lp_beta_version', $lp_beta_version_info['version'] ?? 0 );
}
$admin_notices[ $params['dismiss'] ] = $params['dismiss'];
$_SESSION['lp_admin_notices_dismiss'] = $admin_notices;
$response->message = __( 'Dismissed!', 'learnpress' );

$admin_notices[ $params['dismiss'] ] = $params['dismiss'];
learn_press_setcookie( 'lp_admin_notices_dismiss', json_encode( $admin_notices ) );
$response->message = __( 'Dismissed!', 'learnpress' );
} else {
$show_notice_lp_beta_version = false;
/**
* Check if LP beta version is not dismissed or dismissed version lower than current version, will bet to so
* Check if LP beta version is not dismissed or dismissed version lower than current version, will bet to show notice.
*/
if ( $lp_beta_version_info && ! isset( $_GET['tab'] ) &&
( ! isset( $_SESSION['lp_beta_version'] ) || version_compare( $_SESSION['lp_beta_version'], $lp_beta_version_info['version'], '<' ) ) ) {
( ! isset( $_COOKIE['lp_beta_version'] ) || version_compare( $_COOKIE['lp_beta_version'], $lp_beta_version_info['version'], '<' ) ) ) {
$show_notice_lp_beta_version = true;
}

Expand Down

0 comments on commit cb6f989

Please sign in to comment.