'Drawers',
'singular_name' => 'Drawer',
'menu_name' => 'Drawers',
'name_admin_bar' => 'Drawer',
'add_new' => 'Add New',
'add_new_item' => 'Add New Drawer',
'new_item' => 'New Drawer',
'edit_item' => 'Edit Drawer',
'view_item' => 'View Drawer',
'all_items' => 'All Drawers',
'search_items' => 'Search Drawers',
'parent_item_colon' => 'Parent Drawers:',
'not_found' => 'No drawers found.',
'not_found_in_trash' => 'No drawers found in Trash.',
'featured_image' => 'Drawer Image',
'set_featured_image' => 'Set drawer image',
'remove_featured_image' => 'Remove drawer image',
'use_featured_image' => 'Use as drawer image',
'archives' => 'Drawer Archives',
'insert_into_item' => 'Insert into drawer',
'uploaded_to_this_item' => 'Uploaded to this drawer',
'filter_items_list' => 'Filter drawers list',
);
// Set up the arguments for the Drawer CPT
$args = array(
'labels' => $labels,
'public' => true, // Set this to false if you want it private
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'drawer' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false, // Set to true if you want the CPT to behave like pages
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
'taxonomies' => array(), // Optionally add taxonomies if needed
'show_in_rest' => true, // Enable for Gutenberg editor
);
// Register the Drawer CPT
register_post_type( 'drawer', $args );
}
// Hook into the 'init' action to register the CPT
add_action( 'init', 'register_drawer_cpt' );
/* KEY POINTS */
function add_key_points_meta_box() {
add_meta_box(
'key_points_meta_box', // ID of the meta box
'Key Points', // Title of the meta box
'render_key_points_meta_box', // Callback function to display the meta box
'post', // Post type (you can change it to other post types)
'normal', // Context (normal, side, advanced)
'default' // Priority
);
}
add_action('add_meta_boxes', 'add_key_points_meta_box');
// Callback function to render the meta box
function render_key_points_meta_box($post) {
// Retrieve the stored key points (serialized data)
$key_points_serialized = get_post_meta($post->ID, '_key_points', true);
$key_points = !empty($key_points_serialized) ? unserialize($key_points_serialized) : [];
?>
$point) : ?>
Custom Code Settings
' . $custom_code['js_header'] . '';
}
// Check and output CSS for header
if ( isset( $custom_code['css_header'] ) && ! empty( $custom_code['css_header'] ) ) {
echo '';
}
}
// Check if the hook is for the footer
if ($hook == "footer") {
// Check and output JS for footer
if ( isset( $custom_code['js_footer'] ) && ! empty( $custom_code['js_footer'] ) ) {
echo '';
}
// Check and output CSS for footer
if ( isset( $custom_code['css_footer'] ) && ! empty( $custom_code['css_footer'] ) ) {
echo '';
}
}
}
// Attach to wp_head and wp_footer, passing the location as a parameter
add_action( 'wp_head', function() {
lcp_custom_code_output('header');
});
add_action( 'wp_footer', function() {
lcp_custom_code_output('footer');
});
/* ------------------------ POPUPS ------------------------------- */
/**
* Register the Custom Post Type (CPT) 'lcp-popups'
*/
function lcp_popups_custom_post_type() {
$labels = array(
'name' => 'LCP Popups',
'singular_name' => 'LCP Popup',
'menu_name' => 'LCP Popups',
'name_admin_bar' => 'LCP Popup',
'add_new' => 'Add New',
'add_new_item' => 'Add New Popup',
'new_item' => 'New Popup',
'edit_item' => 'Edit Popup',
'view_item' => 'View Popup',
'all_items' => 'All Popups',
'search_items' => 'Search Popups',
'not_found' => 'No popups found.',
'not_found_in_trash' => 'No popups found in Trash.',
'parent_item_colon' => '',
'menu_icon' => 'dashicons-lightbulb', // Optional: Set an icon
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 20,
'supports' => array( 'title', 'editor' ), // You can add other supports like 'thumbnail', 'excerpt', etc.
'has_archive' => true,
'rewrite' => array( 'slug' => 'lcp-popups' ),
'show_in_rest' => true,
);
register_post_type( 'lcp-popup', $args );
}
add_action( 'init', 'lcp_popups_custom_post_type' );
/**
* Add a meta box with a toggle switch for "Show on All Pages"
*/
function lcp_popups_add_meta_box() {
add_meta_box(
'lcp_popups_toggle_meta_box', // Meta box ID
'Popup Settings', // Meta box title
'lcp_popups_meta_box_callback', // Callback function
'lcp_popups', // Post type
'side', // Context (normal, side, etc.)
'high' // Priority (default, low, high)
);
}
add_action( 'add_meta_boxes', 'lcp_popups_add_meta_box' );
/**
* Callback function to display the meta box content
*/
function lcp_popups_meta_box_callback( $post ) {
// Add a nonce for security
wp_nonce_field( 'lcp_popups_nonce_action', 'lcp_popups_nonce' );
// Get the current value of the toggle (default to false)
$show_on_all_pages = get_post_meta( $post->ID, '_lcp_popups_show_on_all_pages', true );
// Display the toggle switch (checkbox)
?>
' . $content . '';
// Get the array of post IDs from the wp_option
$post_ids = get_option('lcp_popups_every_page');
if (!empty($post_ids) && is_array($post_ids)) {
// Loop through the post IDs and get the content for each post
foreach ($post_ids as $post_id) {
// Make sure the post exists and get its content
$post = get_post($post_id);
if ($post) {
// Get the content and wrap it with a class
$content = apply_filters('the_content', $post->post_content);
// Output the popup content in the footer
echo '
' . $content . '
';
}
}
}
}
add_action('wp_footer', 'lcp_display_popups_on_every_page');
// Hook into wp_footer to add the login form in the footer
function add_login_form_to_footer() {
?>