__('General', 'wp-ultimo'), 'desc' => __('General', 'wp-ultimo'), 'type' => 'header', ); $fields['title'] = array( 'type' => 'text', 'title' => __('Title', 'wp-ultimo'), 'value' => __('About this Site', 'wp-ultimo'), 'desc' => __('Leave blank to hide the title completely.', 'wp-ultimo'), 'tooltip' => '', ); return $fields; } // end 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 Ultimo', * 'Checkout', * 'Form', * 'Cart', * ); * * @since 2.0.0 * @return array */ public function keywords() { return array( 'WP Ultimo', 'Account', 'Summary', ); } // end keywords; /** * 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 array( 'title' => __('About this Site', 'wp-ultimo'), ); } // end defaults; /** * Runs early on the request lifecycle as soon as we detect the shortcode is present. * * @since 2.0.0 * @return void */ public function setup() { $this->site = WP_Ultimo()->currents->get_site(); if (!$this->site || !$this->site->is_customer_allowed()) { $this->set_display(false); return; } // end if; $this->membership = $this->site->get_membership(); $this->product = $this->membership ? $this->membership->get_plan() : false; is_multisite() && switch_to_blog($this->site->get_id()); $space_used = get_space_used() * 1024 * 1024; $space_allowed = get_space_allowed() ? get_space_allowed() * 1024 * 1024 : 1; $percentage = ceil($space_used / $space_allowed * 100); $unlimited_space = get_site_option('upload_space_check_disabled'); $message = $unlimited_space ? '%s' : '%s / %s'; is_multisite() && restore_current_blog(); $this->atts = array( 'site_trial' => 0, // @todo: fix this 'space_used' => $space_used, 'space_allowed' => $space_allowed, 'percentage' => $percentage, 'unlimited_space' => $unlimited_space, 'message' => $message, ); } // end setup; /** * Allows the setup in the context of previews. * * @since 2.0.0 * @return void */ public function setup_preview() { $this->site = wu_mock_site(); $this->membership = wu_mock_membership(); $this->product = wu_mock_product(); $unlimited_space = get_site_option('upload_space_check_disabled'); $message = $unlimited_space ? '%s' : '%s / %s'; $this->atts = array( 'site_trial' => 30, // @todo: fix this 'space_used' => 120 * MB_IN_BYTES, 'space_allowed' => 1 * GB_IN_BYTES, 'percentage' => 120 * MB_IN_BYTES / 1 * GB_IN_BYTES, 'unlimited_space' => $unlimited_space, 'message' => $message, ); } // end setup_preview; /** * 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) { $atts = array_merge($atts, $this->atts); $atts['site'] = $this->site; $atts['membership'] = $this->membership; $atts['product'] = $this->product; return wu_get_template_contents('dashboard-widgets/account-summary', $atts); } // end output; /** * Returns the manage URL for sites, depending on the environment. * * @since 2.0.0 * * @param int $site_id A Site ID. * @return string */ public function get_manage_url($site_id) { $base_url = \WP_Ultimo\Current::get_manage_url($site_id, 'site'); return is_admin() ? add_query_arg('page', 'account', $base_url . '/admin.php') : $base_url; } // end get_manage_url; } // end class Account_Summary_Element;