after-kubio-activation.php
3 months ago
allow-kubio-blog-override.php
2 years ago
cache-plugins.php
4 years ago
default-editor-overlay.php
1 year ago
dismissable-notice.php
2 days ago
gutenerg-plugin-check.php
1 year ago
image-size-auto-fix.php
1 year ago
kubio-fresh-site.php
2 years ago
post-insert.php
2 months ago
register-meta-fields.php
3 years ago
requirements-notices.php
1 year ago
site-urls.php
1 year ago
starter-sites-feature.php
1 year ago
svg-kses.php
1 year ago
wp-import.php
1 month ago
post-insert.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | use Kubio\Core\Importer; |
| 4 | use Kubio\Core\Utils; |
| 5 | |
| 6 | function kubio_rest_pre_insert_import_assets( $prepared_post ) { |
| 7 | if ( ! current_user_can( 'upload_files' ) ) { |
| 8 | return $prepared_post; |
| 9 | } |
| 10 | //if you make changes to the post that does not include it's content. For example featured image, template, |
| 11 | // slug etc... . we need to stop the function or the post content will be removed |
| 12 | if ( ! isset( $prepared_post->post_content ) ) { |
| 13 | return $prepared_post; |
| 14 | } |
| 15 | $content = $prepared_post->post_content; |
| 16 | |
| 17 | $blocks = parse_blocks( $content ); |
| 18 | |
| 19 | $blocks = Importer::maybeImportBlockAssets( $blocks ); |
| 20 | |
| 21 | $blocks = apply_filters( 'kubio/rest-pre-save-post/import-assets', $blocks, $prepared_post ); |
| 22 | |
| 23 | $prepared_post->post_content = kubio_serialize_blocks( $blocks ); |
| 24 | |
| 25 | return $prepared_post; |
| 26 | } |
| 27 | |
| 28 | function kubio_import_assets_filter() { |
| 29 | $post_types = array( 'page', 'post', 'wp_template', 'wp_template_part' ); |
| 30 | |
| 31 | foreach ( $post_types as $post_type ) { |
| 32 | add_filter( "rest_pre_insert_{$post_type}", 'kubio_rest_pre_insert_import_assets' ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | add_action( 'init', 'kubio_import_assets_filter' ); |
| 37 | |
| 38 | //when in site editor mode disable import download |
| 39 | add_filter( |
| 40 | 'kubio/importer/skip-remote-file-import', |
| 41 | function ( $result ) { |
| 42 | if ( Utils::getIsAISiteEditor() ) { |
| 43 | return true; |
| 44 | } |
| 45 | return $result; |
| 46 | }, |
| 47 | 9 |
| 48 | ); |
| 49 |