Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From date behaviour #136

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ nbproject/
node_modules/
vendor/
wordpress/
test/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2022 Redbit s.r.o.
Copyright (c) since 2016 to present day Redbit s.r.o. CZ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"email": "[email protected]"
},
"require": {
"php": ">=5.6.20",
"php": ">=7.0",
"ext-json": "*",
"cmb2/cmb2": "dev-master",
"webdevstudios/cmb2-post-search-field": "dev-master",
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20,817 changes: 9,088 additions & 11,729 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"homepage": "https://github.com/redbitcz/simpleshop-wp-plugin#readme",
"devDependencies": {
"@wordpress/scripts": "^12.6.0",
"@wordpress/scripts": "^26.19.0",
"lodash.assign": "^4.2.0",
"webpack-merge": "^5.7.2"
}
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: redbitcz, simpleshopcz, jakubboucek, vasikgreif, vitvavra
Tags: simpleshop, simpleshop.cz, membership, member, access control, selling form
Requires at least: 5.0.0
Tested up to: 6.3.2
Tested up to: 6.4.2
Requires PHP: 7.4
Stable tag: trunk
License: MIT
Expand Down
47 changes: 25 additions & 22 deletions src/Access.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<?php
/**
* @package Redbit\SimpleShop\WpPlugin
* @license MIT
* @copyright 2016-2022 Redbit s.r.o.
* @author Redbit s.r.o. <[email protected]>
* @package Redbit\SimpleShop\WpPlugin
* @license MIT
* @copyright 2016-2023 Redbit s.r.o.
* @author Redbit s.r.o. <[email protected]>
*/

namespace Redbit\SimpleShop\WpPlugin;

use DateTime;
use WP_Error;
use WP_Post;

/** Handles the access for the posts / pages */
class Access {
/** @var Settings */
private $settings;

/**
* @param Settings $settings
* @param Settings $settings
*/
public function __construct( Settings $settings ) {
$this->settings = $settings;

$redirect = true;
if ( apply_filters( 'ssc_redirect_on_locked_content', $redirect ) === true ) {
if ( apply_filters( 'ssc_redirect_on_locked_content', true ) === true ) {
add_action( 'template_redirect', [ $this, 'check_access' ] );
}

Expand Down Expand Up @@ -100,8 +101,8 @@ public function get_post_groups( $post_id = '' ) {
/**
* Check if user has permission to view the post
*
* @param string $post_id
* @param string $user_id
* @param string $post_id
* @param string $user_id
*
* @return bool|WP_Error
*/
Expand Down Expand Up @@ -175,7 +176,8 @@ public function user_can_view_post( $post_id = '', $user_id = '' ) {
}

if ( $expire_days_after_registration = $this->get_expire_days_after_registration() ) {
if ( $subscription_date <= date( 'Y-m-d', strtotime( "now - $expire_days_after_registration days" ) ) ) {
if ( $subscription_date <= date( 'Y-m-d',
strtotime( "now - $expire_days_after_registration days" ) ) ) {
// if the access already expired, just break the loop here, as the user might have multiple subscriptions
continue;
}
Expand Down Expand Up @@ -210,9 +212,9 @@ public function user_is_admin() {
/**
* Get the date to access the post
*
* @param string $post_id
* @param string $post_id
*
* @return mixed
* @return false|string
*/
public function get_post_date_to_access( $post_id = '', $format = 'Y-m-d H:i:s' ) {
global $post;
Expand All @@ -227,15 +229,15 @@ public function get_post_date_to_access( $post_id = '', $format = 'Y-m-d H:i:s'

$date = get_post_meta( $post_id, SIMPLESHOP_PREFIX . 'date_to_access', true );

return $date ? (new \DateTime($date))->format($format) : '';
return $date ? ( new DateTime( $date ) )->format( $format ) : '';
}

/**
* Get the date until the access to the post is allowed
*
* @param string $post_id
* @param string $post_id
*
* @return mixed
* @return false|string
*/
public function get_post_date_until_to_access( $post_id = '', $format = 'Y-m-d H:i:s' ) {
global $post;
Expand All @@ -250,13 +252,13 @@ public function get_post_date_until_to_access( $post_id = '', $format = 'Y-m-d H

$date = get_post_meta( $post_id, SIMPLESHOP_PREFIX . 'date_until_to_access', true );

return $date ? (new \DateTime($date))->format($format) : '';
return $date ? ( new DateTime( $date ) )->format( $format ) : '';
}

/**
* Get the number of days the user has to be subscribed to have access to the post
*
* @param string $post_id
* @param string $post_id
*
* @return mixed
*/
Expand All @@ -273,7 +275,7 @@ public function get_post_days_to_access( $post_id = '' ) {
/**
* Get the number of days the user has to be subscribed to have access to the post
*
* @param string $post_id
* @param string $post_id
*
* @return mixed
*/
Expand All @@ -291,7 +293,7 @@ public function get_expire_days_after_registration( $post_id = '' ) {
/**
* Get the URL to redirect the user if he has no access
*
* @param string $post_id
* @param string $post_id
*
* @return mixed
*/
Expand Down Expand Up @@ -351,7 +353,8 @@ public function user_can_view_content( $args = [] ) {

if ( ! empty( $specific_date_to ) ) {
// Fix shortcode.
if ( date( 'H:i:s', strtotime( $specific_date_to ) ) == '00:00:00' ) { //todo figure out how to use wp_date with timezone settings
if ( date( 'H:i:s',
strtotime( $specific_date_to ) ) == '00:00:00' ) { //todo figure out how to use wp_date with timezone settings
$specific_date_to = date( 'Y-m-d', strtotime( $specific_date_to ) ) . ' 23:59:59';
}

Expand Down Expand Up @@ -463,7 +466,7 @@ public function setup_nav_menu_item( $item ) {
*/
public function hide_menu_items() {
?>
<style type="text/css">
<style>
.ssc-hide {
display: none !important;
}
Expand Down Expand Up @@ -533,7 +536,7 @@ public function send_welcome_email( $user_id ) {

// Scrub through posts and check, if some of the posts has that group assigned
foreach ( $posts as $post ) {
/** @var \WP_Post $post */
/** @var WP_Post $post */
$groups = $this->get_post_groups( $post->ID );

if ( in_array( $group, $groups ) ) {
Expand Down
Loading