__('General', 'wp-ultimo'), 'desc' => __('General', 'wp-ultimo'), 'type' => 'header', ]; $fields['title'] = [ 'type' => 'text', 'title' => __('Title', 'wp-ultimo'), 'value' => __('Site Limits', 'wp-ultimo'), 'desc' => __('Leave blank to hide the title completely.', 'wp-ultimo'), 'tooltip' => '', ]; $fields['columns'] = [ 'type' => 'number', 'title' => __('Columns', 'wp-ultimo'), 'desc' => __('How many columns to use.', 'wp-ultimo'), 'tooltip' => '', 'value' => 1, 'min' => 1, 'max' => 10, ]; return $fields; } /** * The list of keywords for this element. * * Return an array of strings with keywords describing this * element. Gutenberg uses this to help customers find blocks. * * e.g.: * return array( * 'WP Multisite WaaS', * 'Checkout', * 'Form', * 'Cart', * ); * * @since 2.0.0 * @return array */ public function keywords() { return [ 'WP Ultimo', 'WP Multisite WaaS', 'Account', 'Limits', 'Quotas', ]; } /** * List of default parameters for the element. * * If you are planning to add controls using the fields, * it might be a good idea to use this method to set defaults * for the parameters you are expecting. * * These defaults will be used inside a 'wp_parse_args' call * before passing the parameters down to the block render * function and the shortcode render function. * * @since 2.0.0 * @return array */ public function defaults() { return [ 'columns' => 1, 'title' => __('Site Limits', 'wp-ultimo'), ]; } /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. * * @since 2.0.0 * @return void */ public function setup(): void { $this->site = WP_Ultimo()->currents->get_site(); if ( ! $this->site || ! $this->site->is_customer_allowed()) { $this->set_display(false); } } /** * Allows the setup in the context of previews. * * @since 2.0.0 * @return void */ public function setup_preview(): void { $this->site = wu_mock_site(); } /** * The content to be output on the screen. * * Should return HTML markup to be used to display the block. * This method is shared between the block render method and * the shortcode implementation. * * @since 2.0.0 * * @param array $atts Parameters of the block/shortcode. * @param string|null $content The content inside the shortcode. * @return string */ public function output($atts, $content = null) { $post_types = get_post_types( [ 'public' => true, ], 'objects' ); /* * Remove post types that where disabled or that are not available for display. */ $post_types = array_filter($post_types, fn($post_type_slug) => $this->site->get_limitations()->post_types->{$post_type_slug}->enabled, ARRAY_FILTER_USE_KEY); /** * Allow developers to select which post types should be displayed. * * @since 2.0.0 * @param array $post_types List of post types. * @return array New list. */ $post_types = apply_filters('wu_get_post_types', $post_types); $items_to_display = wu_get_setting('limits_and_quotas'); $atts['site'] = $this->site; $atts['post_types'] = $post_types; $atts['items_to_display'] = $items_to_display ? array_keys($items_to_display) : false; $atts['post_type_limits'] = $this->site->get_limitations()->post_types; return wu_get_template_contents('dashboard-widgets/limits-and-quotas', $atts); } }