add_control( * 'link', * [ * 'label' => __( 'Link', 'plugin-domain' ), * 'type' => Controls_Manager::URL, * 'placeholder' => __( 'https://your-link.com', 'plugin-domain' ), * 'default' => [ * 'url' => '', * 'is_external' => true, * ] * 'show_external' => true * ] * ); * * PHP usage (inside `Widget_Base::render()` method): * * $website_link = $this->get_settings( 'website_link' ); * $target = $website_link['is_external'] ? 'target="_blank"' : ''; * echo 'Visit Website'; * * JS usage (inside `Widget_Base::_content_template()` method): * * <# var target = settings.website_link.is_external ? 'target="_blank"' : ''; #> * Visit Website * * @since 1.0.0 * * @param string $label Optional. The label that appears above of the * field. Default is empty. * @param string $title Optional. The field title that appears on mouse * hover. Default is empty. * @param string $placeholder Optional. The field placeholder that appears * when the field has no values. Default is empty. * @param string $description Optional. The description that appears below the * field. Default is empty. * @param array $default { * Optional. The field default values. * * @type string $url Optional. Default is empty. * @type bool $is_external Optional. Determine whether to open the url in * the same tab or in a new one. Default is empty. * @type bool $nofollow Optional. Determine whether to add nofolloe * attribute. Default is empty. * } * @param bool $show_external Optional. Whether to show 'Is External' button. * Default is true. * @param string $separator Optional. Set the position of the control separator. * Available values are 'default', 'before', 'after' * and 'none'. 'default' will position the separator * depending on the control type. 'before' / 'after' * will position the separator before/after the * control. 'none' will hide the separator. Default * is 'default'. * @param bool $show_label Optional. Whether to display the label. Default * is true. * @param bool $label_block Optional. Whether to display the label in a * separate line. Default is false. */ class Control_URL extends Control_Base_Multiple { /** * Retrieve url control type. * * @since 1.0.0 * @access public * * @return string Control type. */ public function get_type() { return 'url'; } /** * Retrieve url control default values. * * Get the default value of the url control. Used to return the default * values while initializing the url control. * * @since 1.0.0 * @access public * * @return array Control default value. */ public function get_default_value() { return [ 'url' => '', 'is_external' => '', 'nofollow' => '', ]; } /** * Retrieve url control default settings. * * Get the default settings of the url control. Used to return the default * settings while initializing the url control. * * @since 1.0.0 * @access protected * * @return array Control default settings. */ protected function get_default_settings() { return [ 'label_block' => true, 'show_external' => true, ]; } /** * Render url control output in the editor. * * Used to generate the control HTML in the editor using Underscore JS * template. The variables for the class are available using `data` JS * object. * * @since 1.0.0 * @access public */ public function content_template() { $control_uid = $this->get_control_uid(); $more_input_control_uid = $this->get_control_uid( 'more-input' ); $is_external_control_uid = $this->get_control_uid( 'is_external' ); $nofollow_control_uid = $this->get_control_uid( 'nofollow' ); ?>