Skip to content

Commit

Permalink
dev.1.3.0 : Add a shortcode attribute.
Browse files Browse the repository at this point in the history
Add a shortcode attribute to show only specific post types.
  • Loading branch information
takashi-matsuyama committed Jun 21, 2021
1 parent 2ed41f5 commit 001b4fb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Tags: browsing history, accessibility, design
Requires at least: 4.8
Tested up to: 5.7
Requires PHP: 5.4.0
Stable tag: 1.2.2
Stable tag: 1.3.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -36,6 +36,9 @@ Detailed usage is under preparation.

## Changelog

### 1.3.0
Add a shortcode attribute to show only specific post types.

### 1.2.2
Fixed PHP 8.0 warning.

Expand Down
6 changes: 3 additions & 3 deletions assets/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Author: Takashi Matsuyama
* Author URI: https://profiles.wordpress.org/takashimatsuyama/
* Description: WordPressで投稿の閲覧履歴を一覧で表示
* Version: 1.0.0 or later
* Version: 1.3.0 or later
*/

/*
Expand All @@ -16,15 +16,15 @@ var CCC = CCC || {};
(function($) {
var content_area_elm = $('#content-ccc_browsing_history');
var post_area_elm = $('#ccc-browsing_history-list');
var posts_per_page_value = post_area_elm.data('ccc_history-posts_per_page');

var history_key = CCC.browsing_history.storage_key(); // 過去に閲覧した投稿を保存するストレージキーの名前を変数に格納(CCC.favoriteのstorage_key関数を呼び出し)
var history_value = localStorage.getItem(history_key); // ローカルストレージから指定したキーの値を取得
var data_set = {}; // オブジェクトのキーに変数を使用:ES5までの書き方(IE11以下への対応のため)
data_set['action'] = CCC_BROWSING_HISTORY_LIST.action;
data_set['nonce'] = CCC_BROWSING_HISTORY_LIST.nonce;
data_set[history_key] = history_value;
data_set['ccc-posts_per_page'] = posts_per_page_value;
data_set['ccc-posts_per_page'] = post_area_elm.data('ccc_browsing_history-posts_per_page');
data_set['ccc-post_type'] = post_area_elm.data('ccc_browsing_history-post_type');

$.ajax({
type: 'POST',
Expand Down
17 changes: 13 additions & 4 deletions assets/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ public static function action() {
$browsing_history_post_ids = array_map('htmlspecialchars', $browsing_history_post_ids); // 配列データを一括でサニタイズする

/*** 表示数の定義(指定が無ければ管理画面の表示設定(表示する最大投稿数)の値を取得) ***/
$ccc_posts_per_page = absint( $_POST['ccc-posts_per_page'] ); //負ではない整数に変換
if( $ccc_posts_per_page ) {
$posts_per_page = $ccc_posts_per_page;
if( isset( $_POST['ccc-posts_per_page'] ) ) {
$posts_per_page = absint( $_POST['ccc-posts_per_page'] ); //負ではない整数に変換
} else {
$posts_per_page = get_option('posts_per_page');
}

/*** ポストタイプの定義(指定が無ければ "any") ***/
if( isset( $_POST['ccc-post_type'] ) and $_POST['ccc-post_type'] !== 'any' ) {
$post_type = explode(',', $_POST['ccc-post_type']); //文字列をカンマで区切って配列に変換
$post_type = str_replace(array(" ", " "), "", $post_type); //配列の各要素の中にある半角空白と全角空白を取り除く(""に置き換え)
$post_type = array_map('sanitize_text_field', $post_type); // 配列データを一括でサニタイズする
} else {
$post_type = 'any'; // リビジョンと 'exclude_from_search' が true にセットされたものを除き、すべてのタイプを含める
}
//print_r($post_type);

$args= array(
'post_type' => 'any', // リビジョンと 'exclude_from_search' が true にセットされたものを除き、すべてのタイプを含める
'post_type' => $post_type,
'posts_per_page' => $posts_per_page,
'post__in' => $browsing_history_post_ids,
'orderby' => 'post__in',
Expand Down
9 changes: 8 additions & 1 deletion assets/shortcode-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static function results($atts) {
"posts_per_page" => '',
"class" => '',
"style" => '',
"post_type" => '',
"post__not_in" => '',
),$atts);
if( $atts['title'] ) {
$title = $atts['title'];
Expand All @@ -36,9 +38,14 @@ public static function results($atts) {
} else {
$style = 1;
}
if( $atts['post_type'] ) {
$post_type = $atts['post_type'];
} else {
$post_type = 'any';
}
$data = '<div id="content-ccc_browsing_history">';
$data .= '<p class="title-section">'.$title.'</p>';
$data .= '<div id="ccc-browsing_history-list" data-ccc_browsing_history-list-style="'.$style.'" data-ccc_history-posts_per_page="'.$posts_per_page.'" '.$class.'></div>'; //<!-- /#ccc-browsing_history-list -->
$data .= '<div id="ccc-browsing_history-list" data-ccc_browsing_history-list-style="'.$style.'" data-ccc_browsing_history-posts_per_page="'.$posts_per_page.'" data-ccc_browsing_history-post_type="'.$post_type.'" '.$class.'></div>'; //<!-- /#ccc-browsing_history-list -->
$data .= '</div>'; //<!-- /#content-ccc_browsing_history -->
return $data;
} //endfunction
Expand Down
4 changes: 2 additions & 2 deletions browsing-history.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Browsing History
* Plugin URI: https://wordpress.org/plugins/browsing-history
* Description: Save user’s browsing history and list them.
* Version: 1.2.2
* Version: 1.3.0
* Requires at least: 4.8
* Requires PHP: 5.4.0
* Author: Takashi Matsuyama
Expand Down Expand Up @@ -53,7 +53,7 @@ function ccc_browsing_history_initialize() {

/*** How to use this Shortcode ***/
/*
* [ccc_browsing_history_list_results title="string" posts_per_page="int" class="string" style="string"]
* [ccc_browsing_history_list_results title="string" posts_per_page="int" class="string" style="string" post_type="string (string, string, string)"]
*/
require( CCCBROWSINGHISTORY_PLUGIN_PATH .'/assets/shortcode-list.php' );

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: browsing history, accessibility, design
Requires at least: 4.8
Tested up to: 5.7
Requires PHP: 5.4.0
Stable tag: 1.2.2
Stable tag: 1.3.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -37,4 +37,7 @@ This plugin is [developed on GitHub](https://github.com/takashi-matsuyama/browsi

== Changelog ==

= 1.3.0 =
Add a shortcode attribute to show only specific post types.

See the [release notes on GitHub](https://github.com/takashi-matsuyama/browsing-history/releases).

0 comments on commit 001b4fb

Please sign in to comment.