eturn $templates; } foreach ($this->getBlockTemplates() as $blockTemplate) { $templates[$blockTemplate->slug] = $blockTemplate; } return $templates; } /** * This is a workaround to ensure the post object passed to `inject_ignored_hooked_blocks_metadata_attributes` contains * content to prevent the template being empty when saved. The issue currently occurs when WooCommerce enables block hooks, * and when older versions of `inject_ignored_hooked_blocks_metadata_attributes` are * used (before https://github.com/WordPress/WordPress/commit/725f302121c84c648c38789b2e88dbd1eb41fa48). * This can be removed in the future. * * To test the issue create a new email, revert template changes, save a color change, then save a color change again. * When you refresh if the post is blank, the issue is present. * * @param \stdClass $changes */ public function forcePostContent($changes) { if (empty($changes->post_content) && !empty($changes->ID)) { // Find the existing post object. $post = get_post($changes->ID); if ($post && !empty($post->post_content)) { $changes->post_content = $post->post_content; } } return $changes; } /** * Add details to templates in editor. * * @param WP_Block_Template $block_template Block template object. * @return WP_Block_Template */ public function addBlockTemplateDetails($block_template) { if (!$block_template || !isset($this->templates[$block_template->slug])) { return $block_template; } if (empty($block_template->title)) { $block_template->title = $this->templates[$block_template->slug]['title']; } if (empty($block_template->description)) { $block_template->description = $this->templates[$block_template->slug]['description']; } return $block_template; } /** * Initialize template details. This is done at runtime because of localisation. */ private function initializeTemplates(): void { $this->templates['email-general'] = [ 'title' => __('General Email', 'mailpoet'), 'description' => __('A general template for emails.', 'mailpoet'), ]; $this->templates['awesome-one'] = [ 'title' => __('Awesome Template One', 'mailpoet'), 'description' => __('A template used in testing.', 'mailpoet'), ]; $this->templates['awesome-two'] = [ 'title' => __('Awesome Template Two', 'mailpoet'), 'description' => __('A template used in testing.', 'mailpoet'), ]; $this->templates['email-computing-mag'] = [ 'title' => __('Retro Computing Mag', 'mailpoet'), 'description' => __('A retro themed template.', 'mailpoet'), ]; } private function initializeApi(): void { register_post_meta( 'wp_template', self::MAILPOET_EMAIL_META_THEME_TYPE, [ 'show_in_rest' => [ 'schema' => (new EmailStylesSchema())->getSchema(), ], 'single' => true, 'type' => 'object', 'default' => self::MAILPOET_TEMPLATE_EMPTY_THEME, ] ); register_rest_field( 'wp_template', self::MAILPOET_EMAIL_META_THEME_TYPE, [ 'get_callback' => function($object) { return $this->getBlockTemplateTheme($object['id'], $object['wp_id']); }, 'update_callback' => function($value, $template) { return update_post_meta($template->wp_id, self::MAILPOET_EMAIL_META_THEME_TYPE, $value); }, 'schema' => (new EmailStylesSchema())->getSchema(), ] ); } /** * Gets block templates indexed by ID. */ private function getBlockTemplates() { $blockTemplates = array_map(function($templateSlug) { return $this->getBlockTemplateFromFile($templateSlug . '.html'); }, array_keys($this->templates)); $customTemplates = $this->getCustomTemplates(); // From the DB. $customTemplateIds = wp_list_pluck($customTemplates, 'id'); // Combine to remove duplicates if a custom template has the same ID as a file template. return array_column( array_merge( $customTemplates, array_filter( $blockTemplates, function($blockTemplate) use ($customTemplateIds) { return !in_array($blockTemplate->id, $customTemplateIds, true); } ), ), null, 'id' ); } private function getBlockTemplateFromFile(string $template) { $template_slug = $this->utils->getBlockTemplateSlugFromPath($template); $templateObject = (object)[ 'slug' => $template_slug, 'id' => $this->pluginSlug . '//' . $template_slug, 'title' => $this->templates[$template_slug]['title'] ?? '', 'description' => $this->templates[$template_slug]['description'] ?? '', 'path' => $this->templateDirectory . $template, 'type' => 'wp_template', 'theme' => $this->pluginSlug, 'source' => 'plugin', 'post_types' => [ $this->postType, ], ]; return $this->utils->buildBlockTemplateFromFile($templateObject); } private function getCustomTemplates($slugs = [], $template_type = 'wp_template') { $check_query_args = [ 'post_type' => $template_type, 'posts_per_page' => -1, 'no_found_rows' => true, 'tax_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query [ 'taxonomy' => 'wp_theme', 'field' => 'name', 'terms' => [ $this->pluginSlug, get_stylesheet() ], ], ], ]; if (is_array($slugs) && count($slugs) > 0) { $check_query_args['post_name__in'] = $slugs; } $check_query = new \WP_Query($check_query_args); $custom_templates = $check_query->posts; return array_map( function($custom_template) { return $this->utils->buildBlockTemplateFromPost($custom_template); }, $custom_templates ); } private function getCustomTemplateTheme($templateWpId) { if (!$templateWpId) { return null; } $theme = get_post_meta($templateWpId, self::MAILPOET_EMAIL_META_THEME_TYPE, true); if (is_array($theme) && isset($theme['styles'])) { return $theme; } return null; } }
Fatal error: Uncaught Error: Class "MailPoet\EmailEditor\Engine\Templates\Templates" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:3426 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(3396): MailPoetGenerated\FreeCachedContainer->getTemplatesService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(4031): MailPoetGenerated\FreeCachedContainer->getRenderer2Service() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5088): MailPoetGenerated\FreeCachedContainer->getRenderer6Service() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5098): MailPoetGenerated\FreeCachedContainer->getConfirmationEmailCustomizerService() #4 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5198): MailPoetGenerated\FreeCachedContainer->getConfirmationEmailMailerService() #5 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5368): MailPoetGenerated\FreeCachedContainer->getSubscriberActionsService() #6 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2612): MailPoetGenerated\FreeCachedContainer->getCommentService() #7 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getHooks2Service() #8 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #9 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #10 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #11 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #12 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...') #13 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #14 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #15 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #16 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #17 /htdocs/index.php(17): require('/htdocs/wp-blog...') #18 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 3426