__('General', 'wp-ultimo'), 'desc' => __('General', 'wp-ultimo'), 'type' => 'header', ); $fields['title'] = array( 'type' => 'text', 'title' => __('Label', 'wp-ultimo'), 'value' => __('Toggle Maintenance Mode', 'wp-ultimo'), 'placeholder' => __('e.g. Toggle Maintenance Mode', 'wp-ultimo'), 'tooltip' => '', ); $fields['desc'] = array( 'type' => 'textarea', 'title' => __('Description', 'wp-ultimo'), 'value' => __('Put your site on maintenance mode. When activated, the front-end will only be accessible to logged users.', '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', * 'Billing_Address', * 'Form', * 'Cart', * ); * * @since 2.0.0 * @return array */ public function keywords() { return array( 'WP Ultimo', 'Login', 'Reset Password', ); } // 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' => __('Toggle Maintenance Mode', 'wp-ultimo'), 'desc' => __('Put your site on maintenance mode. When activated, the front-end will only be accessible to logged users.', '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; } // 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(); } // end setup_preview; /** * Registers scripts and styles necessary to render this. * * @since 2.0.0 * @return void */ public function register_scripts() { wp_register_script('wu-site-maintenance', wu_get_asset('site-maintenance.js', 'js'), array('jquery', 'wu-functions'), wu_get_version()); wp_localize_script('wu-site-maintenance', 'wu_site_maintenance', array( 'nonce' => wp_create_nonce('wu_toggle_maintenance_mode'), 'ajaxurl' => wu_ajax_url(), )); wp_enqueue_script('wu-site-maintenance'); } // end register_scripts; /** * 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) { $fields = array( 'maintenance_mode' => array( 'type' => 'toggle', 'title' => $atts['title'], 'desc' => $atts['desc'], 'value' => wu_string_to_bool($this->site->get_meta('wu_maintenance_mode')), ), 'site_hash' => array( 'type' => 'hidden', 'value' => $this->site->get_hash(), ), ); /** * Instantiate the form for the order details. * * @since 2.0.0 */ $form = new \WP_Ultimo\UI\Form('maintenance-mode', $fields, array( 'views' => 'admin-pages/fields', 'classes' => 'wu-widget-list wu-striped wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-list-none wu-p-0', 'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid', 'html_attr' => array(), )); $atts['form'] = $form; return wu_get_template_contents('dashboard-widgets/site-maintenance', $atts); } // end output; } // end class Site_Maintenance_Element;