Skip to content

Commit

Permalink
Fix locked post return post id as permalink rather normal one
Browse files Browse the repository at this point in the history
  • Loading branch information
iniznet committed Dec 1, 2022
1 parent f2ac768 commit 817fde8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.2.6 - 2022-12-02](https://github.com/iniznet/authcred/releases/tag/v1.2.6)

### Bug Fixes
* Fix locked post return post id `?p=123` as permalink rather normal one `/2022/12/a-locked-chapter-test/`

## [1.2.5 - 2022-12-01](https://github.com/iniznet/authcred/releases/tag/v1.2.5)

### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions authcred.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: AuthCRED
* Plugin URI: https://github.com/iniznet/authcred
* Description: Provide simple authentication alongside mycred integration with shortcodes
* Version: 1.2.5
* Version: 1.2.6
* Requires at least: 5.8
* Requires PHP: 7.2
* Author: niznet
Expand All @@ -29,8 +29,8 @@ public function instantiate() {
$this->AuthShortcode = new \AuthCRED\AuthShortcode($this->plugin);
$this->CredShortcode = new \AuthCRED\CredShortcode($this->plugin);
$this->UserAuth = new \AuthCRED\UserAuth($this->plugin);
// $this->UserFields = new \AuthCRED\Fields\UserFields($this->plugin);
$this->MyCRED = new \AuthCRED\MyCRED($this->plugin);
$this->Permalinks = new \AuthCRED\Permalinks($this->plugin);

$this->Updater = new \AuthCRED\Updater();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "authcred",
"version": "1.2.5",
"version": "1.2.6",
"description": "AuthCRED WP Plugin.",
"scripts": {
"dev": "vite",
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "AuthCRED",
"version" : "1.2.5",
"download_url" : "https://github.com/iniznet/authcred/releases/download/v1.2.1/authcred-v1.2.1.zip",
"version" : "1.2.6",
"download_url" : "https://github.com/iniznet/authcred/releases/download/v1.2.6/authcred-v1.2.6.zip",
"sections" : {
"description" : "Provide Authentication pages & system alongside mycred integration."
}
Expand Down
62 changes: 62 additions & 0 deletions src/Permalinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace AuthCRED;

use WPTrait\Model;

class Permalinks extends Model
{
public $filters = [
'is_post_status_viewable' => ['futurePermalink', 999],
];

/** @var array */
public $settings = [];

public function __construct($plugin)
{
parent::__construct($plugin);

$this->settings = $this->option($this->plugin->prefix . '_settings')->get();
}

/**
* Generate future permalink similar to published permalink
* instead of returning post id
*
* @param bool $isViewable
*
* @return bool
*/
public function futurePermalink($isViewable)
{
global $wp_query, $wp_post_statuses;

if (!isset($this->settings['post_type']) || !count($wp_query->posts)) {
return $isViewable;
}

foreach ($wp_query->posts as $post) {
if ($post->post_type !== $this->settings['post_type']) {
continue;
}

if ($post->post_status !== 'future') {
return $isViewable;
}

$wp_post_statuses['future']->protected = 1;
$mycredSellMeta = get_post_meta($post->ID, 'myCRED_sell_content', true);

if (!$mycredSellMeta || $mycredSellMeta['status'] === 'disabled') {
return $isViewable;
}

$wp_post_statuses['future']->protected = 0;

return true;
}

return $isViewable;
}
}

0 comments on commit 817fde8

Please sign in to comment.