Home / Admin / DIR_ACF_WPCODE – ACF Fields for WPCode Snippets Sync
Duplicate Snippet

Embed Snippet on Your Site

DIR_ACF_WPCODE – ACF Fields for WPCode Snippets Sync

/**
* WPCode Snippet: ACF Fields for WPCode Snippets Sync
* Description: Registers ACF fields to store WPCode snippet data in sync CPT
* Location: Run Everywhere
* Priority: 10
*
* INSTALL ORDER: #2 - Install after CPT registration, before sync code
* REQUIRES: Advanced Custom Fields (ACF) plugin
*
* ✅ UPDATED: Added snippet_code_file attachment field for downloadable code files
*/

ismail daugherty PRO
<10
Code Preview
php
<?php
/**
 * WPCode Snippet: ACF Fields for WPCode Snippets Sync
 * Description: Registers ACF fields to store WPCode snippet data in sync CPT
 * Location: Run Everywhere
 * Priority: 10
 * 
 * INSTALL ORDER: #2 - Install after CPT registration, before sync code
 * REQUIRES: Advanced Custom Fields (ACF) plugin
 * 
 * ✅ UPDATED: Added snippet_code_file attachment field for downloadable code files
 */
defined( 'ABSPATH' ) || exit;
add_action( 'acf/init', function() {
    if ( ! function_exists( 'acf_add_local_field_group' ) ) {
        return;
    }
    acf_add_local_field_group( array(
        'key' => 'group_wpcode_snippets_sync',
        'title' => 'WPCode Snippet Data',
        'fields' => array(
            
            // ==========================================
            // TAB 1: SNIPPET OVERVIEW
            // ==========================================
            array(
                'key' => 'field_tab_snippet_overview',
                'label' => 'Snippet Overview',
                'name' => '',
                'type' => 'tab',
                'placement' => 'top',
                'endpoint' => 0,
            ),
            
            // Original WPCode Snippet ID
            array(
                'key' => 'field_original_wpcode_id',
                'label' => 'Original WPCode Snippet ID',
                'name' => 'original_wpcode_id',
                'type' => 'text',
                'instructions' => 'The ID from the actual wpcode post type',
                'required' => 1,
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // KIC Snippet ID (Universal Identifier)
            array(
                'key' => 'field_kic_snippet_id',
                'label' => 'KIC Snippet ID',
                'name' => 'kic_snippet_id',
                'type' => 'text',
                'instructions' => 'Universal identifier: wpcode_{ID}',
                'required' => 0,
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // Snippet Active Status
            array(
                'key' => 'field_snippet_active',
                'label' => 'Active',
                'name' => 'snippet_active',
                'type' => 'true_false',
                'instructions' => 'Is this snippet active in WPCode?',
                'ui' => 1,
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // Last Sync Time
            array(
                'key' => 'field_last_sync_time',
                'label' => 'Last Synced',
                'name' => 'last_sync_time',
                'type' => 'date_time_picker',
                'instructions' => 'When this snippet was last synced',
                'display_format' => 'M j, Y g:i a',
                'return_format' => 'Y-m-d H:i:s',
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // ==========================================
            // TAB 2: SNIPPET CODE & TYPE
            // ==========================================
            array(
                'key' => 'field_tab_code',
                'label' => 'Code & Type',
                'name' => '',
                'type' => 'tab',
                'placement' => 'top',
                'endpoint' => 0,
            ),
            
            // Snippet Name/Title
            array(
                'key' => 'field_snippet_title',
                'label' => 'Snippet Name',
                'name' => 'snippet_title',
                'type' => 'text',
                'instructions' => 'Name of the snippet from WPCode',
                'wrapper' => array( 'width' => '100' ),
                'readonly' => 1,
            ),
            
            // Snippet Code (Text Area)
            array(
                'key' => 'field_snippet_code',
                'label' => 'Code',
                'name' => 'snippet_code',
                'type' => 'textarea',
                'instructions' => 'The actual code content (text area)',
                'rows' => 10,
                'wrapper' => array( 'width' => '100' ),
                'readonly' => 1,
            ),
            
            // ==========================================
            // ✅ NEW: Code File Attachment
            // ==========================================
            array(
                'key' => 'field_snippet_code_file',
                'label' => 'Code File (Download)',
                'name' => 'snippet_code_file',
                'type' => 'file',
                'instructions' => 'Downloadable code file - automatically generated from snippet code',
                'return_format' => 'array', // Returns array with URL, ID, filename, filesize, etc.
                'library' => 'all',
                'mime_types' => 'txt,php,js,css,html', // Allow text and code file types
                'wrapper' => array( 'width' => '100' ),
                'readonly' => 1,
            ),
            
            // Snippet Type
            array(
                'key' => 'field_snippet_type',
                'label' => 'Code Type',
                'name' => 'snippet_type',
                'type' => 'select',
                'choices' => array(
                    'php' => 'PHP',
                    'html' => 'HTML',
                    'css' => 'CSS',
                    'js' => 'JavaScript',
                    'text' => 'Text',
                ),
                'wrapper' => array( 'width' => '33' ),
                'readonly' => 1,
            ),
            
            // Auto Insert Location
            array(
                'key' => 'field_snippet_location',
                'label' => 'Auto Insert Location',
                'name' => 'snippet_location',
                'type' => 'text',
                'wrapper' => array( 'width' => '33' ),
                'readonly' => 1,
            ),
            
            // Priority
            array(
                'key' => 'field_snippet_priority',
                'label' => 'Priority',
                'name' => 'snippet_priority',
                'type' => 'number',
                'default_value' => 10,
                'wrapper' => array( 'width' => '34' ),
                'readonly' => 1,
            ),
            
            // ==========================================
            // TAB 3: TARGETING & SCHEDULING
            // ==========================================
            array(
                'key' => 'field_tab_targeting',
                'label' => 'Targeting & Scheduling',
                'name' => '',
                'type' => 'tab',
                'placement' => 'top',
                'endpoint' => 0,
            ),
            
            // Auto Insert Enabled
            array(
                'key' => 'field_snippet_auto_insert',
                'label' => 'Auto Insert Enabled',
                'name' => 'snippet_auto_insert',
                'type' => 'true_false',
                'ui' => 1,
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // Device Type
            array(
                'key' => 'field_snippet_device_type',
                'label' => 'Device Type',
                'name' => 'snippet_device_type',
                'type' => 'select',
                'choices' => array(
                    'all' => 'All Devices',
                    'mobile' => 'Mobile Only',
                    'desktop' => 'Desktop Only',
                ),
                'default_value' => 'all',
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // Schedule Start
            array(
                'key' => 'field_snippet_schedule_start',
                'label' => 'Schedule Start',
                'name' => 'snippet_schedule_start',
                'type' => 'date_time_picker',
                'display_format' => 'M j, Y g:i a',
                'return_format' => 'Y-m-d H:i:s',
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // Schedule End
            array(
                'key' => 'field_snippet_schedule_end',
                'label' => 'Schedule End',
                'name' => 'snippet_schedule_end',
                'type' => 'date_time_picker',
                'display_format' => 'M j, Y g:i a',
                'return_format' => 'Y-m-d H:i:s',
                'wrapper' => array( 'width' => '25' ),
                'readonly' => 1,
            ),
            
            // ==========================================
            // TAB 4: ORGANIZATION & METADATA
            // ==========================================
            array(
                'key' => 'field_tab_metadata',
                'label' => 'Metadata',
                'name' => '',
                'type' => 'tab',
                'placement' => 'top',
                'endpoint' => 0,
            ),
            
            // Tags
            array(
                'key' => 'field_snippet_tags',
                'label' => 'Tags',
                'name' => 'snippet_tags',
                'type' => 'text',
                'instructions' => 'Comma-separated tags',
                'wrapper' => array( 'width' => '50' ),
                'readonly' => 1,
            ),
            
            // Description
            array(
                'key' => 'field_snippet_description',
                'label' => 'Description',
                'name' => 'snippet_description',
                'type' => 'textarea',
                'rows' => 3,
                'wrapper' => array( 'width' => '50' ),
                'readonly' => 1,
            ),
            
            // Dependencies
            array(
                'key' => 'field_snippet_dependencies',
                'label' => 'Dependencies',
                'name' => 'snippet_dependencies',
                'type' => 'textarea',
                'instructions' => 'List snippets this code depends on (comma-separated names or IDs)',
                'rows' => 3,
                'wrapper' => array( 'width' => '100' ),
                'readonly' => 0, // Allow manual editing
            ),
            
            // Created Date
            array(
                'key' => 'field_snippet_created_date',
                'label' => 'Created Date',
                'name' => 'snippet_created_date',
                'type' => 'date_time_picker',
                'display_format' => 'M j, Y g:i a',
                'return_format' => 'Y-m-d H:i:s',
                'wrapper' => array( 'width' => '33' ),
                'readonly' => 1,
            ),
            
            // Modified Date
            array(
                'key' => 'field_snippet_modified_date',
                'label' => 'Modified Date',
                'name' => 'snippet_modified_date',
                'type' => 'date_time_picker',
                'display_format' => 'M j, Y g:i a',
                'return_format' => 'Y-m-d H:i:s',
                'wrapper' => array( 'width' => '33' ),
                'readonly' => 1,
            ),
            
            // Author
            array(
                'key' => 'field_snippet_author',
                'label' => 'Author',
                'name' => 'snippet_author',
                'type' => 'text',
                'wrapper' => array( 'width' => '50' ),
                'readonly' => 1,
            ),
            
            // Snippet Version
            array(
                'key' => 'field_snippet_version',
                'label' => 'Snippet Version',
                'name' => 'snippet_version',
                'type' => 'text',
                'instructions' => 'Version number from WPCode',
                'wrapper' => array( 'width' => '50' ),
                'readonly' => 1,
            ),
            
        ),
        'location' => array(
            array(
                array(
                    'param' => 'post_type',
                    'operator' => '==',
                    'value' => 'wpcode_snippets_sync',
                ),
            ),
        ),
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'active' => true,
        'show_in_rest' => 1,
    ) );
} );

Comments

Add a Comment