Creating a SiteDrive Post Type Integration
While you can manually add post types in the SiteDrive settings under Integrations > Post > Configure, adding a custom post type integration can help to further tailor the experience.
The following is a sample from our Breakdance Builder integration, which adds all the custom Breakdance post types. It also adds it's logo to posts that use Breakdance but do not have a featured image set.
<?php namespace SiteDrive\BreakdanceIntegration; const POST_TYPES = [ 'breakdance_template', 'breakdance_header', 'breakdance_footer', 'breakdance_block', 'breakdance_acf_block', 'breakdance_popup', ]; // Breakdance Provider sitedrive_provider_register('breakdance', [ 'name' => __('Breakdance', SITEDRIVE_LOCALIZE), 'icon' => SITEDRIVE_URL . 'assets/img/breakdance-logo.png', ]); // Add special Breakdance post types add_filter('sitedrive_post_provider_post_types', function($types) { $settings = sitedrive_settings(); // Not enabled if (empty($settings['provider_breakdance'])) { return $types; } // Add special post types foreach (POST_TYPES as $postType) { $types[] = $postType; } return $types; }); // Image overwrite add_filter('sitedrive_post_default_image', function($defaultLogo, $post) { // Not enabled if (!sitedrive_provider_enabled('breakdance')) { return $defaultLogo; } $specialImage = SITEDRIVE_URL . 'assets/img/breakdance-default.png'; // Special CS post types if (in_array($post->post_type, POST_TYPES)) { return $specialImage; } $metaData = get_post_meta($post->ID, '_breakdance_data', true); if (!empty($metaData)) { return $specialImage; } return $defaultLogo; }, 10, 2);
Custom Import or Export
You can also overwrite the export and import functions used by SiteDrive if your post type needs a different type of export and import strategy. You can utilize the sitedrive_post_export_data
and sitedrive_post_import_data
filters to overwrite this. If anything is returned from these filters, SiteDrive considers there to be a custom import or export strategy.
The following is a sample from the Cornerstone Builder integration which integrates with the Cornerstone Template API.
<?php namespace Sitedrive\CSIntegration; use SiteDrive\Data\Files; const POST_TYPES = [ 'cs_template', 'cs_user_templates', 'cs_global_block', 'cs_header', 'cs_footer', 'cs_layout', 'cs_layout_single', 'cs_layout_single_wc', 'cs_layout_archive', 'cs_layout_archive_wc', ]; /** * Custom export overwrite for Post provider */ add_filter('sitedrive_post_export_data', function($results, $post) { add_filter('cs_permissions_user', function($permissions) { $permissions['template'] = true; return $permissions; }); $csData = get_post_meta($post->ID, '_cornerstone_data', true); $layoutTypes = cornerstone('Resolver')->getDocumentLayoutTypes(); $specialPostTypes = ['cs_global_block', 'cs_template']; $isLayoutType = false; foreach ($layoutTypes as $type) { if ($type['postType'] !== $post->post_type) { continue; } $isLayoutType = true; } if (empty($csData) && !$isLayoutType && !in_array($post->post_type, $specialPostTypes)) { return $results; } $exportType = $post->post_type === 'cs_template' ? 'template' : 'document'; $tco = cs_export_documents_as_base64($post->ID, $exportType, 'replace'); return [ 'content' => 'data:application/zip;base64,' . $tco, 'filename' => sitedrive_sanitize_post_title($post->post_title) . '.tco', 'last_updated' => get_the_modified_date('U', $post->ID), 'is_tco' => true, ]; }, 10, 2); add_filter('sitedrive_post_import_data', function($results, $drive, $file, $contents) { // Not TCO if (!is_array($contents) && empty($contents['is_tco'])) { return $results; } $metaId = sitedrive_generate_meta_id($drive, $file); $justBase64 = preg_replace('/.*base64,/', '', $contents['content']); // Place tco into a temp file for usage by CS $dir = get_temp_dir(); $filename = $dir . 'sitedrive-' . $contents['filename']; wp_mkdir_p($dir); sitedrive_file_put_contents($filename, base64_decode($justBase64), 'Could not place .tco file into the temporary directory. You probably need to change the file permissions for the WordPress temporary directory'); // Import TCO file $postID = cs_import_tco($filename); // Sitedrive meta update_post_meta($postID, Files::META_UPDATED_KEY, $file['last_updated']); update_post_meta($postID, Files::META_KEY, $metaId); return $postID; }, 10, 4);