2
2
/*
3
3
Plugin Name: Shy's Tutorials & Handbooks
4
4
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
6
6
License: GPLv2
7
7
Author: HackTheDev
8
8
Text Domain: shys-tutorials-handbooks
9
9
*/
10
10
11
- if ( ! defined ( 'ABSPATH ' ) ) exit ;
12
-
13
11
require 'PayPalLibrary.php ' ;
14
12
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
+
15
57
// Function to output meta description based on tutorial's short description
16
58
function thp_add_meta_description () {
17
- if (is_singular ('shys_tutorial_handbook ' )) {
59
+ if (is_singular ('shy_tut_book ' )) {
18
60
global $ post ;
19
61
20
62
// Retrieve the custom short description
@@ -46,7 +88,7 @@ function thp_add_paid_meta_box() {
46
88
'thp_paid_meta_box ' ,
47
89
'Paid Tutorial ' ,
48
90
'thp_paid_meta_box_callback ' ,
49
- 'shys_tutorial_handbook ' ,
91
+ 'shy_tut_book ' ,
50
92
'side '
51
93
);
52
94
}
@@ -77,7 +119,7 @@ function thp_add_price_meta_box() {
77
119
'thp_price_meta_box ' ,
78
120
'Tutorial Price ' ,
79
121
'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
81
123
'side ' ,
82
124
'high ' // Position it high up in the sidebar
83
125
);
@@ -112,26 +154,11 @@ function thp_save_price_meta_box($post_id) {
112
154
add_action ('save_post ' , 'thp_save_price_meta_box ' );
113
155
114
156
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
-
130
157
// Generate nested toc
131
158
function thp_generate_toc ($ content ) {
132
159
global $ post ;
133
160
134
- if ($ post ->post_type === 'shys_tutorial_handbook ' ) {
161
+ if ($ post ->post_type === 'shy_tut_book ' ) {
135
162
$ matches = array ();
136
163
preg_match_all ('/<h([2-6])[^>]*>([^<]+)<\/h[2-6]>/ ' , $ content , $ matches );
137
164
@@ -211,7 +238,7 @@ function thp_add_hide_meta_box() {
211
238
'thp_hide_meta_box ' ,
212
239
'Hide from General Listing ' ,
213
240
'thp_hide_meta_box_callback ' ,
214
- 'shys_tutorial_handbook ' ,
241
+ 'shy_tut_book ' ,
215
242
'side '
216
243
);
217
244
}
@@ -241,7 +268,7 @@ function thp_add_description_meta_box() {
241
268
'thp_description_meta_box ' , // ID
242
269
'Post Description ' , // Title
243
270
'thp_description_meta_box_callback ' , // Callback
244
- 'shys_tutorial_handbook ' , // Post type
271
+ 'shy_tut_book ' , // Post type
245
272
'normal ' , // Context
246
273
'high ' // Priority
247
274
);
@@ -279,7 +306,7 @@ function thp_save_description_meta_box($post_id) {
279
306
}
280
307
281
308
// 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 ' ) {
283
310
if (!current_user_can ('edit_post ' , $ post_id )) {
284
311
return ;
285
312
}
@@ -301,7 +328,7 @@ function thp_add_memo_meta_box() {
301
328
'thp_memo_meta_box ' , // ID
302
329
'Internal Memo ' , // Title
303
330
'thp_memo_meta_box_callback ' , // Callback
304
- 'shys_tutorial_handbook ' , // Post type
331
+ 'shy_tut_book ' , // Post type
305
332
'normal ' , // Context
306
333
'high ' // Priority
307
334
);
@@ -339,7 +366,7 @@ function thp_save_memo_meta_box($post_id) {
339
366
}
340
367
341
368
// 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 ' ) {
343
370
if (!current_user_can ('edit_post ' , $ post_id )) {
344
371
return ;
345
372
}
@@ -359,9 +386,9 @@ function thp_save_memo_meta_box($post_id) {
359
386
function thp_enqueue_toc_styles () {
360
387
global $ post ;
361
388
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
363
390
if (
364
- is_singular ('shys_tutorial_handbook ' ) ||
391
+ is_singular ('shy_tut_book ' ) ||
365
392
(isset ($ post ->post_content ) && (has_shortcode ($ post ->post_content , 'shy_tutorials ' ) || has_shortcode ($ post ->post_content , 'shy_private_tutorials ' )))
366
393
) {
367
394
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() {
371
398
372
399
// Access Control - Assign users to specific tutorials (simplified example)
373
400
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 ' );
375
402
}
376
403
add_action ('add_meta_boxes ' , 'thp_add_meta_boxes ' );
377
404
@@ -397,7 +424,7 @@ function thp_save_post($post_id) {
397
424
add_action ('save_post ' , 'thp_save_post ' );
398
425
399
426
function thp_restrict_access ($ content ) {
400
- if (get_post_type () === 'shys_tutorial_handbook ' ) {
427
+ if (get_post_type () === 'shy_tut_book ' ) {
401
428
$ is_paid = get_post_meta (get_the_ID (), '_is_paid ' , true ); // Check if the post is marked as paid
402
429
403
430
if ($ is_paid ) {
@@ -433,8 +460,8 @@ function shy_assigned_articles_shortcode($atts) {
433
460
</style>
434
461
435
462
<?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 );
438
465
$ query = new WP_Query ($ args );
439
466
440
467
if ($ query ->have_posts ()) {
@@ -507,8 +534,8 @@ function shy_knowledge_base_shortcode($atts) {
507
534
<div class="articles-list">
508
535
509
536
<?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 );
512
539
$ query = new WP_Query ($ args );
513
540
514
541
if ($ query ->have_posts ()) :
@@ -581,7 +608,7 @@ function shy_knowledge_base_shortcode($atts) {
581
608
// Add PayPal Settings submenu
582
609
function thp_add_paypal_settings_submenu () {
583
610
add_submenu_page (
584
- 'edit.php?post_type=shys_tutorial_handbook ' , // Parent slug
611
+ 'edit.php?post_type=shy_tut_book ' , // Parent slug
585
612
'PayPal Settings ' , // Page title
586
613
'PayPal Settings ' , // Menu title
587
614
'manage_options ' , // Capability
@@ -749,7 +776,7 @@ function thp_render_single_article($post_id, $is_paid, $user_has_access, $descri
749
776
/* Logs */
750
777
function thp_register_logs_page () {
751
778
add_submenu_page (
752
- 'edit.php?post_type=shys_tutorial_handbook ' , // Parent slug
779
+ 'edit.php?post_type=shy_tut_book ' , // Parent slug
753
780
'Logs ' , // Page title
754
781
'Logs ' , // Menu title
755
782
'manage_options ' , // Capability
@@ -1043,7 +1070,7 @@ function thp_register_transaction_post_type() {
1043
1070
'public ' => false ,
1044
1071
'publicly_queryable ' => false ,
1045
1072
'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
1047
1074
'query_var ' => true ,
1048
1075
'capability_type ' => 'post ' ,
1049
1076
'has_archive ' => false ,
0 commit comments