diff --git a/lib/AdminPages/Pages/FormEditor.php b/lib/AdminPages/Pages/FormEditor.php index a5c08135ca..0b79212a38 100644 --- a/lib/AdminPages/Pages/FormEditor.php +++ b/lib/AdminPages/Pages/FormEditor.php @@ -174,6 +174,9 @@ class FormEditor { 'pages' => $this->getAllPages(), 'categories' => $this->getAllCategories(), 'tags' => $this->getAllTags(), + 'products' => $this->getWooCommerceProducts(), + 'product_categories' => $this->getWooCommerceCategories(), + 'product_tags' => $this->getWooCommerceTags(), ]; $this->wp->wpEnqueueMedia(); $this->pageRenderer->displayPage('form/editor.html', $data); @@ -260,13 +263,25 @@ class FormEditor { } private function getAllPosts() { - return $this->formatPosts($this->wp->getPosts()); + return $this->formatPosts($this->wp->getPosts(['numberposts' => -1])); + } + + private function getWooCommerceProducts() { + return $this->formatPosts($this->wp->getPosts(['post_type' => 'product', 'numberposts' => -1])); } private function getAllPages() { return $this->formatPosts($this->wp->getPages()); } + private function getWooCommerceCategories() { + return $this->formatTerms($this->wp->getCategories(['taxonomy' => 'product_cat'])); + } + + private function getWooCommerceTags() { + return $this->formatTerms($this->wp->getTerms('product_tag')); + } + private function getAllCategories() { return $this->formatTerms($this->wp->getCategories()); } @@ -276,6 +291,7 @@ class FormEditor { } private function formatPosts($posts) { + if (empty($posts)) return []; $result = []; foreach ($posts as $post) { $result[] = [ @@ -287,6 +303,8 @@ class FormEditor { } private function formatTerms($terms) { + if (empty($terms)) return []; + if (!is_array($terms)) return []; // there can be instance of WP_Error instead of list of terms if woo commerce is not active $result = []; foreach ($terms as $term) { $result[] = [ diff --git a/views/form/editor.html b/views/form/editor.html index 5e2161e1ce..4c98ea097e 100644 --- a/views/form/editor.html +++ b/views/form/editor.html @@ -35,6 +35,9 @@ 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_woocommerce_products = <%= json_encode(products) %>; + var mailpoet_woocommerce_categories = <%= json_encode(product_categories) %>; + var mailpoet_woocommerce_tags = <%= json_encode(product_tags) %>; var mailpoet_close_icons_url = '<%= image_url("form_close_icon") %>'; <% endautoescape %>