diff --git a/lib/AdminPages/Pages/FormEditor.php b/lib/AdminPages/Pages/FormEditor.php index f577cdec13..bd44266c59 100644 --- a/lib/AdminPages/Pages/FormEditor.php +++ b/lib/AdminPages/Pages/FormEditor.php @@ -154,7 +154,7 @@ class FormEditor { 'iframe' => Export::get('iframe', $form), 'shortcode' => Export::get('shortcode', $form), ], - 'pages' => Pages::getAll(), + 'mailpoet_pages' => Pages::getAll(), 'segments' => Segment::getSegmentsWithSubscriberCount(), 'styles' => $this->formRenderer->getCustomStyles($form), 'date_types' => array_map(function ($label, $value) { @@ -170,6 +170,10 @@ class FormEditor { 'preview_page_url' => $this->getPreviewPageUrl(), 'custom_fonts' => CustomFonts::FONTS, 'translations' => $this->getGutenbergScriptsTranslations(), + 'posts' => $this->getAllPosts(), + 'pages' => $this->getAllPages(), + 'categories' => $this->getAllCategories(), + 'tags' => $this->getAllTags(), ]; $this->wp->wpEnqueueMedia(); $this->pageRenderer->displayPage('form/editor.html', $data); @@ -254,4 +258,42 @@ class FormEditor { } return $translations; } + + private function getAllPosts() { + return $this->formatPosts($this->wp->getPosts()); + } + + private function getAllPages() { + return $this->formatPosts($this->wp->getPages()); + } + + private function getAllCategories() { + return $this->formatTerms($this->wp->getCategories()); + } + + private function getAllTags() { + return $this->formatTerms($this->wp->getTags()); + } + + private function formatPosts($posts) { + $result = []; + foreach ($posts as $post) { + $result[] = [ + 'id' => $post->ID, + 'name' => $post->post_title,// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps + ]; + } + return $result; + } + + private function formatTerms($terms) { + $result = []; + foreach ($terms as $term) { + $result[] = [ + 'id' => $term->term_id,// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps + 'name' => $term->name, + ]; + } + return $result; + } } diff --git a/lib/WP/Functions.php b/lib/WP/Functions.php index e6b5721287..04df3c0ad2 100644 --- a/lib/WP/Functions.php +++ b/lib/WP/Functions.php @@ -160,6 +160,10 @@ class Functions { return get_categories($args); } + public function getTags($args = '') { + return get_tags($args); + } + public function getComment($comment = null, $output = OBJECT) { return get_comment($comment, $output); } diff --git a/views/form/editor.html b/views/form/editor.html index fa18ecd5ba..a1c232f122 100644 --- a/views/form/editor.html +++ b/views/form/editor.html @@ -23,7 +23,7 @@ var mailpoet_form_data = <%= json_encode(form) %>; var mailpoet_form_exports = <%= json_encode(form_exports) %>; var mailpoet_form_segments = <%= json_encode(segments) %>; - var mailpoet_form_pages = <%= json_encode(pages) %>; + var mailpoet_form_pages = <%= json_encode(mailpoet_pages) %>; var mailpoet_custom_fields = <%= json_encode(custom_fields) %>; var mailpoet_date_types = <%= json_encode(date_types) %>; var mailpoet_date_formats = <%= json_encode(date_formats) %>; @@ -31,6 +31,10 @@ var mailpoet_form_preview_page = <%= json_encode(preview_page_url) %>; var mailpoet_custom_fonts = <%= json_encode(custom_fonts) %>; var mailpoet_translations = <%= json_encode(translations) %>; + var mailpoet_all_wp_posts = <%= json_encode(posts) %>; + var mailpoet_all_wp_pages = <%= json_encode(pages) %>; + var mailpoet_all_wp_categories = <%= json_encode(categories) %>; + var mailpoet_all_wp_tags = <%= json_encode(tags) %>; var mailpoet_close_icons_url = '<%= image_url("form_close_icon") %>'; <% endautoescape %>