-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal-snippet.php
More file actions
71 lines (59 loc) · 1.91 KB
/
Copy pathuniversal-snippet.php
File metadata and controls
71 lines (59 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
Plugin Name: Form Guardian
Description: A plugin to handle forms
Version: 1.0.0
Author: Christopher Nathaniel
Author URI: https://christophernathaniel.co.uk
*/
// if accessed directly, exit
if (!defined('ABSPATH')) {
exit;
}
// Register Post Type
function form_guardian_post_type()
{
$args = array(
'public' => true,
'label' => 'Forms',
'supports' => array('title', 'editor'),
'has_archive' => true,
'rewrite' => array('slug' => 'form-guardian'),
);
register_post_type('form-guardian', $args);
}
add_action('init', 'form_guardian_post_type');
// Register Shortcode
function form_guardian_shortcode($atts)
{
// Extract shortcode attributes
$atts = shortcode_atts(array(
'id' => null, // Default to null
), $atts, 'form_guardian_shortcode');
// Get custom page content based on provided page ID
$custom_page_content = '';
if ($atts['id']) {
$page = get_post($atts['id']);
if ($page) {
$custom_page_content = apply_filters('the_content', $page->post_content);
}
}
return $custom_page_content;
}
add_shortcode('form_guardian', 'form_guardian_shortcode');
// Usage: [form_guardian page_id="1"]
// Display Shortcode Example
// Function to insert example shortcode into page content in the CMS
function insert_shortcode_example_into_page_editor($content)
{
global $post;
// Check if we are on the page editor screen
if ($post->post_type === 'form-guardian') { // Replace 'your-page-slug' with the slug of your page
$theContent = '<div class="shortcode-example">
<p>Below is an example of the custom page shortcode:</p>
<p>[form_guardian id="' . $post->ID . '"]</p> <!-- Replace "123" with the actual ID of your custom page -->
</div>';
echo $theContent;
}
}
add_filter('edit_form_after_title', 'insert_shortcode_example_into_page_editor');