Skip to content

Commit 7e30676

Browse files
committed
.
1 parent 5f3b5aa commit 7e30676

File tree

3 files changed

+66
-39
lines changed

3 files changed

+66
-39
lines changed

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Donate link: https://www.patreon.com/shydevil
33
Requires at least: 6.6.1
44
Tested up to: 6.6.1
5-
Stable tag: 1.0
5+
Stable tag: 1.6
66
License: GPLv2
77
License URI: https://www.gnu.org/licenses/gpl-2.0.html
88
Tags: tutorial, handbook, simple, free

shys-tutorials-handbooks.zip

-15.7 MB
Binary file not shown.

tuts.php

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,61 @@
22
/*
33
Plugin Name: Shy's Tutorials & Handbooks
44
Description: Create, manage, and restrict access to tutorials and handbooks, with features for manual user assignment and private content sharing.
5-
Version: 1.5
5+
Version: 1.6
66
License: GPLv2
77
Author: HackTheDev
88
Text Domain: shys-tutorials-handbooks
99
*/
1010

11-
if ( ! defined( 'ABSPATH' ) ) exit;
12-
1311
require 'PayPalLibrary.php';
1412

13+
14+
// Register Custom Post Type
15+
function thp_register_custom_post_type() {
16+
17+
18+
$labels = array(
19+
'name' => 'Tutorials & Handbooks',
20+
'singular_name' => 'Tutorial & Handbook',
21+
'menu_name' => 'Tutorials & Handbooks',
22+
'name_admin_bar' => 'Tutorials & Handbooks',
23+
'add_new' => 'Add New',
24+
'add_new_item' => 'Add New Tutorial',
25+
'new_item' => 'New Tutorial',
26+
'edit_item' => 'Edit Tutorial',
27+
'view_item' => 'View Tutorial',
28+
'all_items' => 'All Tutorials',
29+
'search_items' => 'Search Tutorials',
30+
'not_found' => 'No tutorials found.',
31+
'not_found_in_trash' => 'No tutorials found in Trash.',
32+
);
33+
34+
$args = array(
35+
'labels' => $labels,
36+
'public' => true,
37+
'publicly_queryable' => true,
38+
'show_ui' => true,
39+
'show_in_menu' => true,
40+
'query_var' => true,
41+
'rewrite' => array('slug' => 'tutorials'),
42+
'capability_type' => 'post',
43+
'has_archive' => false,
44+
'hierarchical' => false,
45+
'menu_position' => 0,
46+
'supports' => array('title', 'editor', 'thumbnail'),
47+
'show_in_rest' => true, // Important for block editor and REST API support
48+
);
49+
50+
register_post_type('shy_tut_book', $args);
51+
}
52+
add_action('init', 'thp_register_custom_post_type');
53+
54+
55+
56+
1557
// Function to output meta description based on tutorial's short description
1658
function thp_add_meta_description() {
17-
if (is_singular('shys_tutorial_handbook')) {
59+
if (is_singular('shy_tut_book')) {
1860
global $post;
1961

2062
// Retrieve the custom short description
@@ -46,7 +88,7 @@ function thp_add_paid_meta_box() {
4688
'thp_paid_meta_box',
4789
'Paid Tutorial',
4890
'thp_paid_meta_box_callback',
49-
'shys_tutorial_handbook',
91+
'shy_tut_book',
5092
'side'
5193
);
5294
}
@@ -77,7 +119,7 @@ function thp_add_price_meta_box() {
77119
'thp_price_meta_box',
78120
'Tutorial Price',
79121
'thp_price_meta_box_callback',
80-
'shys_tutorial_handbook', // Ensure this matches your custom post type
122+
'shy_tut_book', // Ensure this matches your custom post type
81123
'side',
82124
'high' // Position it high up in the sidebar
83125
);
@@ -112,26 +154,11 @@ function thp_save_price_meta_box($post_id) {
112154
add_action('save_post', 'thp_save_price_meta_box');
113155

114156

115-
// Register Custom Post Type
116-
function thp_register_custom_post_type() {
117-
$args = array(
118-
'public' => true,
119-
'label' => 'Tutorials & Handbooks',
120-
'supports' => array('title', 'editor', 'thumbnail'),
121-
'has_archive' => true,
122-
'rewrite' => array('slug' => 'tutorials'),
123-
'publicly_queryable' => true,
124-
'show_in_rest' => true
125-
);
126-
register_post_type('shys_tutorial_handbook', $args);
127-
}
128-
add_action('init', 'thp_register_custom_post_type');
129-
130157
// Generate nested toc
131158
function thp_generate_toc($content) {
132159
global $post;
133160

134-
if ($post->post_type === 'shys_tutorial_handbook') {
161+
if ($post->post_type === 'shy_tut_book') {
135162
$matches = array();
136163
preg_match_all('/<h([2-6])[^>]*>([^<]+)<\/h[2-6]>/', $content, $matches);
137164

@@ -211,7 +238,7 @@ function thp_add_hide_meta_box() {
211238
'thp_hide_meta_box',
212239
'Hide from General Listing',
213240
'thp_hide_meta_box_callback',
214-
'shys_tutorial_handbook',
241+
'shy_tut_book',
215242
'side'
216243
);
217244
}
@@ -241,7 +268,7 @@ function thp_add_description_meta_box() {
241268
'thp_description_meta_box', // ID
242269
'Post Description', // Title
243270
'thp_description_meta_box_callback', // Callback
244-
'shys_tutorial_handbook', // Post type
271+
'shy_tut_book', // Post type
245272
'normal', // Context
246273
'high' // Priority
247274
);
@@ -279,7 +306,7 @@ function thp_save_description_meta_box($post_id) {
279306
}
280307

281308
// Check the user's permissions.
282-
if (isset($_POST['post_type']) && $_POST['post_type'] === 'shys_tutorial_handbook') {
309+
if (isset($_POST['post_type']) && $_POST['post_type'] === 'shy_tut_book') {
283310
if (!current_user_can('edit_post', $post_id)) {
284311
return;
285312
}
@@ -301,7 +328,7 @@ function thp_add_memo_meta_box() {
301328
'thp_memo_meta_box', // ID
302329
'Internal Memo', // Title
303330
'thp_memo_meta_box_callback', // Callback
304-
'shys_tutorial_handbook', // Post type
331+
'shy_tut_book', // Post type
305332
'normal', // Context
306333
'high' // Priority
307334
);
@@ -339,7 +366,7 @@ function thp_save_memo_meta_box($post_id) {
339366
}
340367

341368
// Check the user's permissions.
342-
if (isset($_POST['post_type']) && $_POST['post_type'] === 'shys_tutorial_handbook') {
369+
if (isset($_POST['post_type']) && $_POST['post_type'] === 'shy_tut_book') {
343370
if (!current_user_can('edit_post', $post_id)) {
344371
return;
345372
}
@@ -359,9 +386,9 @@ function thp_save_memo_meta_box($post_id) {
359386
function thp_enqueue_toc_styles() {
360387
global $post;
361388

362-
// Check if the post is of type 'tutorial_handbook' or if it contains the shortcodes
389+
// Check if the post is of type 'shy_tut_book' or if it contains the shortcodes
363390
if (
364-
is_singular('shys_tutorial_handbook') ||
391+
is_singular('shy_tut_book') ||
365392
(isset($post->post_content) && (has_shortcode($post->post_content, 'shy_tutorials') || has_shortcode($post->post_content, 'shy_private_tutorials')))
366393
) {
367394
wp_enqueue_style('thp_toc_styles', plugin_dir_url(__FILE__) . 'style.css', array(), filemtime(plugin_dir_path(__FILE__) . 'style.css'));
@@ -371,7 +398,7 @@ function thp_enqueue_toc_styles() {
371398

372399
// Access Control - Assign users to specific tutorials (simplified example)
373400
function thp_add_meta_boxes() {
374-
add_meta_box('thp_access_control', 'Access Control', 'thp_access_control_callback', 'shys_tutorial_handbook', 'side');
401+
add_meta_box('thp_access_control', 'Access Control', 'thp_access_control_callback', 'shy_tut_book', 'side');
375402
}
376403
add_action('add_meta_boxes', 'thp_add_meta_boxes');
377404

@@ -397,7 +424,7 @@ function thp_save_post($post_id) {
397424
add_action('save_post', 'thp_save_post');
398425

399426
function thp_restrict_access($content) {
400-
if (get_post_type() === 'shys_tutorial_handbook') {
427+
if (get_post_type() === 'shy_tut_book') {
401428
$is_paid = get_post_meta(get_the_ID(), '_is_paid', true); // Check if the post is marked as paid
402429

403430
if ($is_paid) {
@@ -433,8 +460,8 @@ function shy_assigned_articles_shortcode($atts) {
433460
</style>
434461

435462
<?php
436-
// Query for all posts in the 'tutorial_handbook' post type
437-
$args = array('post_type' => 'shys_tutorial_handbook', 'posts_per_page' => -1);
463+
// Query for all posts in the 'shy_tut_book' post type
464+
$args = array('post_type' => 'shy_tut_book', 'posts_per_page' => -1);
438465
$query = new WP_Query($args);
439466

440467
if ($query->have_posts()) {
@@ -507,8 +534,8 @@ function shy_knowledge_base_shortcode($atts) {
507534
<div class="articles-list">
508535

509536
<?php
510-
// Query for all posts in the 'shys_tutorial_handbook' post type
511-
$args = array('post_type' => 'shys_tutorial_handbook', 'posts_per_page' => -1);
537+
// Query for all posts in the 'shy_tut_book' post type
538+
$args = array('post_type' => 'shy_tut_book', 'posts_per_page' => -1);
512539
$query = new WP_Query($args);
513540

514541
if ($query->have_posts()) :
@@ -581,7 +608,7 @@ function shy_knowledge_base_shortcode($atts) {
581608
// Add PayPal Settings submenu
582609
function thp_add_paypal_settings_submenu() {
583610
add_submenu_page(
584-
'edit.php?post_type=shys_tutorial_handbook', // Parent slug
611+
'edit.php?post_type=shy_tut_book', // Parent slug
585612
'PayPal Settings', // Page title
586613
'PayPal Settings', // Menu title
587614
'manage_options', // Capability
@@ -749,7 +776,7 @@ function thp_render_single_article($post_id, $is_paid, $user_has_access, $descri
749776
/* Logs */
750777
function thp_register_logs_page() {
751778
add_submenu_page(
752-
'edit.php?post_type=shys_tutorial_handbook', // Parent slug
779+
'edit.php?post_type=shy_tut_book', // Parent slug
753780
'Logs', // Page title
754781
'Logs', // Menu title
755782
'manage_options', // Capability
@@ -1043,7 +1070,7 @@ function thp_register_transaction_post_type() {
10431070
'public' => false,
10441071
'publicly_queryable' => false,
10451072
'show_ui' => true,
1046-
'show_in_menu' => 'edit.php?post_type=shys_tutorial_handbook', // Make it a sub-menu
1073+
'show_in_menu' => 'edit.php?post_type=shy_tut_book', // Make it a sub-menu
10471074
'query_var' => true,
10481075
'capability_type' => 'post',
10491076
'has_archive' => false,

0 commit comments

Comments
 (0)