Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<exclude-pattern>/node_modules/</exclude-pattern>
<exclude-pattern>/dependencies/</exclude-pattern>
<exclude-pattern>/../wordpress/</exclude-pattern>
<exclude-pattern>/inc/site-exporter/mu-migration/</exclude-pattern>

<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
Expand Down Expand Up @@ -111,7 +112,7 @@
</property>
</properties>
</rule>
<rule ref="WordPress.WP.I18n.MissingArgDomain">
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="ultimate-multisite"/>
Expand Down
184 changes: 184 additions & 0 deletions assets/js/template-library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/* global Vue, wu_template_library, ajaxurl, _ */
(function($) {

const search_template = new Vue({
el: '#search-templates',
data: {
search: wu_template_library.search,
},
});

const wu_main_template_app = new Vue({
el: '#wu-template-library',
data() {

return {
loading: true,
category: wu_template_library.category,
templates: [],
};

},
mounted() {

this.fetch_templates_list();

},
computed: {
search() {

return search_template.search;

},
i18n() {

return window.wu_template_library.i18n;

},
categories() {

let categories = [];

_.each(this.templates, function(template) {

if (template.categories && Array.isArray(template.categories)) {
categories = categories.concat(template.categories);
}

});

return _.unique(categories, function(cat) {
return cat.slug;
});

},
templates_list() {

const app = this;

return _.filter(app.templates, function(template) {

// Filter by category
if (app.category !== 'all') {
const hasCategory = template.categories && template.categories.some(cat => cat.slug === app.category);
if (!hasCategory) {
return false;
}
}

// Filter by search
if (!app.search) {

return true;

}

const search_fields = [
template.slug || '',
template.name || '',
template.description || '',
template.short_description || '',
template.author || '',
template.industry_type || '',
];

// Add category names to search
if (template.categories && Array.isArray(template.categories)) {
template.categories.forEach(function(cat) {
search_fields.push(cat.name || cat.slug || '');
});
}

return search_fields.join(' ').toLowerCase().indexOf(app.search.toLowerCase()) > -1;

});

},
count() {

return this.templates_list.length;

},
},
methods: {
fetch_templates_list() {

const app = this;

$.ajax({
method: 'GET',
url: ajaxurl,
data: {
action: 'serve_templates_list',
},
success(data) {

if (data.success && data.data) {
app.templates = data.data;
} else {
app.templates = [];
}

app.loading = false;

},
error() {

app.templates = [];
app.loading = false;

},
});

},
},
});

new Vue({
el: '.wp-heading-inline',
data: {},
computed: {
count() {

return wu_main_template_app.count;

},
},
});

new Vue({
el: '#templates-menu',
data: {},
methods: {
set_category(category) {

this.main_app.category = category;

const url = new URL(window.location.href);

url.searchParams.set('tab', category);

history.pushState({}, null, url);

},
},
computed: {
main_app() {

return wu_main_template_app;

},
category() {

return wu_main_template_app.category;

},
available_categories() {

return wu_main_template_app.categories;

},
},
});

}(jQuery));
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"jasny/sso": "^0.4.2",
"nyholm/psr7": "^1.8.0",
"symfony/cache": "^5.4.29",
"symfony/finder": "^5.4",
"scssphp/scssphp": "^1.11.1",
"cweagans/composer-patches": "^1.7",
"woocommerce/action-scheduler": "^3.9.1",
Expand Down
128 changes: 64 additions & 64 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion inc/admin-pages/class-base-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function __construct() {
__FUNCTION__,
sprintf(
/* translators: 1: The current class. 2: 'init'. */
esc_html__('Admin page %1$s loaded too early. Admin page should be loaded at the %2$s action or later.'),
esc_html__('Admin page %1$s loaded too early. Admin page should be loaded at the %2$s action or later.', 'ultimate-multisite'),
'<code>' . static::class . '</code>',
'<code>init</code>'
),
Expand Down
9 changes: 9 additions & 0 deletions inc/admin-pages/class-site-edit-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ public function register_widgets(): void {

parent::register_widgets();

/**
* Allows other components to register widgets on the Site edit page.
*
* @since 2.5.0
*
* @param Site_Edit_Admin_Page $page The current admin page instance.
*/
do_action('wu_edit_site_page_register_widgets', $this);

$label = $this->get_object()->get_type_label();

$class = $this->get_object()->get_type_class();
Expand Down
Loading
Loading