|
6 | 6 | use App\Hooks\Sites\Block; |
7 | 7 | use App\Hooks\Sites\Post; |
8 | 8 | use App\Hooks\Sites\Routes; |
| 9 | +use Roots\WPConfig\Config; |
9 | 10 |
|
10 | 11 | class Sites |
11 | 12 | { |
| 13 | + public const LAST_UPDATE = 'Dool|Tinky|Sonya|Simple'; |
| 14 | + public const CREATE_SITE_PAGE_CONTENT = <<<EOF |
| 15 | +<!-- wp:group {"className":"wizard-form flex flex-column justify-center p-4 rounded radius-md bg-white","layout":{"type":"constrained"}} --> |
| 16 | +<div class="wp-block-group wizard-form flex flex-column justify-center p-4 rounded radius-md bg-white"><!-- wp:image {"width":"200px","sizeSlug":"medium","linkDestination":"none","align":"center"} --> |
| 17 | +<figure class="wp-block-image aligncenter size-medium is-resized"><img src="https://modycloud.test/content/uploads/2024/12/logo-mody-cloud-300x148.png" alt="" class="wp-image-51" style="width:200px"/></figure> |
| 18 | +<!-- /wp:image --> |
| 19 | +
|
| 20 | +<!-- wp:app/create-site-v2 --> |
| 21 | +<p class="wp-block-app-create-site-v2">Auth Module for Mody Cloud</p> |
| 22 | +<!-- /wp:app/create-site-v2 --></div> |
| 23 | +<!-- /wp:group --> |
| 24 | +EOF; |
| 25 | + |
12 | 26 | public static function init(): void |
13 | 27 | { |
| 28 | + add_action('init', self::wp_init(...)); |
14 | 29 | add_action('init', Routes::permalink_structure(...)); |
15 | 30 | add_action('init', Post::register_post_type(...)); |
16 | 31 | add_action('wp_install', Routes::migrate(...)); |
17 | 32 | add_action('wp_ajax_check_setup_finished', Ajax::check_setup_finished(...)); |
18 | 33 | add_action('wp_ajax_check_space_name_exists', Ajax::check_space_name_exists(...)); |
19 | 34 | add_action('wp_ajax_create_space', Ajax::create_space(...)); |
20 | 35 | add_filter('app_before_render_block_create-site', Block::app_before_render_block(...)); |
| 36 | + add_filter('render_block', Block::app_render_block(...), 10, 3); |
| 37 | + } |
| 38 | + |
| 39 | + public static function wp_init(): void |
| 40 | + { |
| 41 | + if (Config::get('CHILD_SITE')) { |
| 42 | + return; |
| 43 | + } |
| 44 | + $get_post_by_name = get_page_by_path('create-site'); |
| 45 | + $create_site_page_id_option = get_option('create_site_page_id'); |
| 46 | + if ($get_post_by_name?->ID && $create_site_page_id_option !== $get_post_by_name?->ID) { |
| 47 | + $create_site_page_id = $get_post_by_name?->ID; |
| 48 | + } else { |
| 49 | + $create_site_page_id = $create_site_page_id_option; |
| 50 | + } |
| 51 | + $create_site_option_last_update = get_option('create_site_option_last_update'); |
| 52 | + if (! $create_site_page_id || $create_site_option_last_update !== self::LAST_UPDATE) { |
| 53 | + if (!$create_site_page_id) { |
| 54 | + $create_site_page_id = wp_insert_post([ |
| 55 | + 'post_type' => 'page', |
| 56 | + 'post_title' => __('Create site', APP_THEME_LOCALE), |
| 57 | + 'post_status' => 'publish', |
| 58 | + 'post_author' => 1, |
| 59 | + 'post_name' => 'create_site', |
| 60 | + 'post_content' => self::CREATE_SITE_PAGE_CONTENT, |
| 61 | + ]); |
| 62 | + } |
| 63 | + |
| 64 | + wp_update_post([ |
| 65 | + 'ID' => $create_site_page_id, |
| 66 | + 'post_content' => self::CREATE_SITE_PAGE_CONTENT, |
| 67 | + ]); |
| 68 | + |
| 69 | + update_option('create_site_option_last_update', self::LAST_UPDATE); |
| 70 | + update_option('create_site_page_id', $create_site_page_id); |
| 71 | + } |
21 | 72 | } |
22 | 73 | } |
0 commit comments