| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
|
|
|
| add_action( 'init', function() {
|
|
|
| register_post_type( 'wpcode_snippets_sync', array(
|
| 'labels' => array(
|
| 'name' => 'Code Snippets (Sync)',
|
| 'singular_name' => 'Code Snippet (Sync)',
|
| 'menu_name' => 'Code Snippets',
|
| 'add_new' => 'Add New',
|
| 'add_new_item' => 'Add New Code Snippet',
|
| 'edit_item' => 'Edit Code Snippet',
|
| 'new_item' => 'New Code Snippet',
|
| 'view_item' => 'View Code Snippet',
|
| 'search_items' => 'Search Code Snippets',
|
| 'not_found' => 'No code snippets found',
|
| 'not_found_in_trash' => 'No code snippets found in Trash',
|
| 'all_items' => 'All Code Snippets',
|
| ),
|
| 'public' => false,
|
| 'show_ui' => true,
|
| 'show_in_menu' => true,
|
| 'show_in_nav_menus' => false,
|
| 'show_in_admin_bar' => true,
|
| 'menu_position' => 25,
|
| 'menu_icon' => 'dashicons-code-standards',
|
| 'capability_type' => 'post',
|
| 'hierarchical' => false,
|
| 'supports' => array( 'title' ),
|
| 'has_archive' => false,
|
| 'rewrite' => false,
|
| 'query_var' => false,
|
| 'can_export' => true,
|
| 'delete_with_user' => false,
|
|
|
|
|
| 'show_in_rest' => true,
|
| 'rest_base' => 'wpcode-snippets-sync',
|
| 'rest_controller_class' => 'WP_REST_Posts_Controller',
|
| ) );
|
|
|
| } );
|
|
|
|
|
|
|
|
|
| add_action( 'admin_notices', function() {
|
| $screen = get_current_screen();
|
|
|
| if ( $screen && 'wpcode_snippets_sync' === $screen->post_type ) {
|
| ?>
|
| <div class="notice notice-info">
|
| <p>
|
| <strong>ℹ️ Read-Only Mirror:</strong>
|
| This is a synced copy of your WPCode snippets for REST API access.
|
| To edit snippets, use the <a href="<?php echo admin_url( 'admin.php?page=wpcode' ); ?>">WPCode plugin</a>.
|
| </p>
|
| </div>
|
| <?php
|
| }
|
| } );
|
|
|
| /**
|
| * Make title field read-only in admin
|
| */
|
| add_action( 'admin_head-post.php', function() {
|
| global $post_type;
|
|
|
| if ( 'wpcode_snippets_sync' === $post_type ) {
|
| ?>
|
| <style>
|
|
|
| background:
|
| cursor: not-allowed;
|
| }
|
| </style>
|
| <script>
|
| jQuery(document).ready(function($) {
|
| $('#title').prop('readonly', true);
|
| });
|
| </script>
|
| <?php
|
| }
|
| } );
|
|
|
|
|
|
|
|
|
| register_activation_hook( __FILE__, function() {
|
|
|
| add_action( 'init', function() {
|
| register_post_type( 'wpcode_snippets_sync', array(
|
| 'show_in_rest' => true,
|
| 'rest_base' => 'wpcode-snippets-sync',
|
| ) );
|
| } );
|
|
|
|
|
| flush_rewrite_rules();
|
| } );
|
| |
| |
Comments