'', 'content' => '', ); // Set up the widget name and description. public function __construct() { $widget_options = array( 'classname' => 'AMPFORWP_AMP_Code_Widget', 'description' => esc_html__('You can add the AMP code in this widget which will appear in AMP Pages','accelerated-mobile-pages') ); parent::__construct( 'AMPFORWP_AMP_Code_Widget', esc_html__('Custom AMP Code','accelerated-mobile-pages'), $widget_options ); } public function _register_one( $number = -1 ) { parent::_register_one( $number ); if ( $this->registered ) { return; } $this->registered = true; wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) ); add_action( 'admin_footer-widgets.php', array( 'AMPFORWP_AMP_Code_Widget', 'render_control_template_scripts' ) ); } public function widget( $args, $instance ) { $simulated_text_widget_instance = array_merge( $instance, array( 'text' => isset( $instance['content'] ) ? $instance['content'] : '', 'filter' => false, // Because wpautop is not applied. 'visual' => false, // Because it wasn't created in TinyMCE. ) ); unset( $simulated_text_widget_instance['content'] ); // Was moved to 'text' prop. /** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */ $content = apply_filters( 'widget_text', $instance['content'], $simulated_text_widget_instance, $this ); // Adds 'noopener' relationship, without duplicating values, to all HTML A elements that have a target. $content = wp_targeted_link_rel( $content ); $args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/', 'widget_text ', $args['before_widget'] ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['before_widget']; echo '
'; // The textwidget class is for theme styling compatibility. //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $content; echo '
'; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['after_widget']; } public function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->default_instance ); ?> default_instance, $old_instance ); $instance['title'] = sanitize_text_field( $new_instance['title'] ); if ( current_user_can( 'unfiltered_html' ) ) { $instance['content'] = $new_instance['content']; } else { $instance['content'] = wp_kses_post( $new_instance['content'] ); } return $instance; } } // Register the widget. function ampforwp_register_amp_code_widget() { register_widget( 'AMPFORWP_AMP_Code_Widget' ); } add_action( 'widgets_init', 'ampforwp_register_amp_code_widget' ); ?>