Skip to content

Commit 2822d89

Browse files
authored
Add files via upload
1 parent 6ab154d commit 2822d89

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

readme.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== Tutorials & Handbooks ===
2+
Donate link: https://www.patreon.com/shydevil
3+
Requires at least: 6.6.1
4+
Tested up to: 6.6.1
5+
Stable tag: 1.0
6+
License: GPLv2
7+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
8+
Tags: tutorial, handbook, simple, free
9+
10+
Create, manage, and restrict access to tutorials and handbooks, with features for manual user assignment and private content sharing.
11+
12+
== Description ==
13+
This plugin enables you to list and manage tutorials and handbooks on your WordPress site. From the admin dashboard, you can easily create new posts (referred to as \"tutorials\"). These tutorials can be locked, restricting access to specific users. It\'s possible to manually grant users access to individual posts, and you can also mark a post as \"not listed\" and assign it to a specific user—ideal for custom-made tutorials or private documentation.
14+
15+
Currently, users must be manually assigned to tutorials, as this plugin was initially designed for companies with a small customer base requiring custom documentation. The purpose of this plugin is to provide such companies (or any users) with a platform to create, host, and share documentation with their customers, friends, or communities.
16+
17+
Future updates will aim to automate this process, potentially adding an optional purchase button, either through direct PayPal integration or WooCommerce support.

tuts.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22
/*
3-
Plugin Name: Shy's Tutorial & Handbook Plugin
4-
Description: A simple plugin to create tutorials and handbooks with a table of contents and access control.
3+
Plugin Name: Shy's Tutorials & Handbooks
4+
Description: Create, manage, and restrict access to tutorials and handbooks, with features for manual user assignment and private content sharing.
55
Version: 1.0
6-
Author: Shy Devil
6+
License: GPLv2
7+
Author: HackTheDev
78
*/
89

910

10-
1111
// Add a meta box for marking a tutorial as paid/locked
1212
function thp_add_paid_meta_box() {
1313
add_meta_box(
@@ -21,6 +21,8 @@ function thp_add_paid_meta_box() {
2121
add_action('add_meta_boxes', 'thp_add_paid_meta_box');
2222

2323
function thp_paid_meta_box_callback($post) {
24+
25+
wp_nonce_field('thp_save_paid_meta_box', 'thp_paid_meta_nonce');
2426
$is_paid = get_post_meta($post->ID, '_is_paid', true);
2527
?>
2628
<label for="thp_is_paid">Post can only be accessed if paid</label>
@@ -29,7 +31,7 @@ function thp_paid_meta_box_callback($post) {
2931
}
3032

3133
function thp_save_paid_meta_box($post_id) {
32-
if (isset($_POST['thp_is_paid'])) {
34+
if (isset($_POST['thp_is_paid']) && check_admin_referer('thp_save_paid_meta_box', 'thp_paid_meta_nonce')) {
3335
update_post_meta($post_id, '_is_paid', '1');
3436
} else {
3537
update_post_meta($post_id, '_is_paid', '0');
@@ -249,7 +251,15 @@ function thp_save_memo_meta_box($post_id) {
249251

250252
// Enqueue styles for TOC
251253
function thp_enqueue_toc_styles() {
252-
wp_enqueue_style('thp_toc_styles', plugin_dir_url(__FILE__) . 'style.css');
254+
global $post;
255+
256+
// Check if the post is of type 'tutorial_handbook' or if it contains the shortcodes
257+
if (
258+
is_singular('tutorial_handbook') ||
259+
(isset($post->post_content) && (has_shortcode($post->post_content, 'shy_tutorials') || has_shortcode($post->post_content, 'shy_private_tutorials')))
260+
) {
261+
wp_enqueue_style('thp_toc_styles', plugin_dir_url(__FILE__) . 'style.css', array(), filemtime(plugin_dir_path(__FILE__) . 'style.css'));
262+
}
253263
}
254264
add_action('wp_enqueue_scripts', 'thp_enqueue_toc_styles');
255265

@@ -266,7 +276,7 @@ function thp_access_control_callback($post) {
266276
echo '<ul>';
267277
foreach ($users as $user) {
268278
$checked = in_array($user->ID, $assigned_users) ? 'checked' : '';
269-
echo '<li><label><input type="checkbox" name="assigned_users[]" value="' . $user->ID . '" ' . $checked . '> ' . $user->display_name . '</label></li>';
279+
echo '<li><label><input type="checkbox" name="assigned_users[]" value="' . esc_attr($user->ID) . '" ' . esc_attr($checked) . '> ' . esc_attr($user->display_name) . '</label></li>';
270280
}
271281
echo '</ul>';
272282
}
@@ -341,7 +351,7 @@ function shy_assigned_articles_shortcode($atts) {
341351
$description = get_post_meta($post_id, '_thp_description', true); // Get the custom description
342352

343353
// Use the common rendering function
344-
echo thp_render_single_article($post_id, $is_paid, true, $description);
354+
echo wp_kses_post(thp_render_single_article($post_id, $is_paid, true, $description));
345355
}
346356

347357
endwhile;
@@ -409,7 +419,7 @@ function shy_knowledge_base_shortcode($atts) {
409419
$user_has_access = in_array(get_current_user_id(), $assigned_users);
410420

411421
// Use the common rendering function
412-
echo thp_render_single_article($post_id, $is_paid, $user_has_access, $description);
422+
echo wp_kses_post(thp_render_single_article($post_id, $is_paid, $user_has_access, $description));
413423

414424
endwhile;
415425
else : ?>
@@ -451,9 +461,9 @@ function thp_render_single_article($post_id, $is_paid, $user_has_access, $descri
451461
<?php endif; ?>
452462
<h2 class="article-title">
453463
<?php if (!$is_paid || $user_has_access) : ?>
454-
<a href="<?php echo get_permalink($post_id); ?>"><?php echo get_the_title($post_id); ?></a>
464+
<a href="<?php echo esc_html(get_permalink($post_id)); ?>"><?php echo esc_html(get_the_title($post_id)); ?></a>
455465
<?php else : ?>
456-
<?php echo get_the_title($post_id); ?>
466+
<?php echo esc_html(get_the_title($post_id)); ?>
457467
<?php endif; ?>
458468
</h2>
459469
</div>

0 commit comments

Comments
 (0)