wp/wp-includes/widgets/class-wp-widget-custom-html.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    68 		}
    68 		}
    69 		$this->registered = true;
    69 		$this->registered = true;
    70 
    70 
    71 		wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
    71 		wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
    72 
    72 
    73 		// Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
    73 		// Note that the widgets component in the customizer will also do
       
    74 		// the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
    74 		add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
    75 		add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
    75 
    76 
    76 		// Note that the widgets component in the customizer will also do the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
    77 		// Note that the widgets component in the customizer will also do
       
    78 		// the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
    77 		add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Custom_HTML', 'render_control_template_scripts' ) );
    79 		add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Custom_HTML', 'render_control_template_scripts' ) );
    78 
    80 
    79 		// Note this action is used to ensure the help text is added to the end.
    81 		// Note this action is used to ensure the help text is added to the end.
    80 		add_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) );
    82 		add_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) );
    81 	}
    83 	}
   101 	/**
   103 	/**
   102 	 * Outputs the content for the current Custom HTML widget instance.
   104 	 * Outputs the content for the current Custom HTML widget instance.
   103 	 *
   105 	 *
   104 	 * @since 4.8.1
   106 	 * @since 4.8.1
   105 	 *
   107 	 *
   106 	 * @global WP_Post $post
   108 	 * @global WP_Post $post Global post object.
       
   109 	 *
   107 	 * @param array $args     Display arguments including 'before_title', 'after_title',
   110 	 * @param array $args     Display arguments including 'before_title', 'after_title',
   108 	 *                        'before_widget', and 'after_widget'.
   111 	 *                        'before_widget', and 'after_widget'.
   109 	 * @param array $instance Settings for the current Custom HTML widget instance.
   112 	 * @param array $instance Settings for the current Custom HTML widget instance.
   110 	 */
   113 	 */
   111 	public function widget( $args, $instance ) {
   114 	public function widget( $args, $instance ) {
   219 		}
   222 		}
   220 		wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.init( %s );', wp_json_encode( $settings ) ), 'after' );
   223 		wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.init( %s );', wp_json_encode( $settings ) ), 'after' );
   221 
   224 
   222 		$l10n = array(
   225 		$l10n = array(
   223 			'errorNotice' => array(
   226 			'errorNotice' => array(
   224 				/* translators: %d: error count */
   227 				/* translators: %d: Error count. */
   225 				'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ),
   228 				'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ),
   226 				/* translators: %d: error count */
   229 				/* translators: %d: Error count. */
   227 				'plural'   => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
   230 				'plural'   => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ),
       
   231 				// @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
   228 			),
   232 			),
   229 		);
   233 		);
   230 		wp_add_inline_script( 'custom-html-widgets', sprintf( 'jQuery.extend( wp.customHtmlWidgets.l10n, %s );', wp_json_encode( $l10n ) ), 'after' );
   234 		wp_add_inline_script( 'custom-html-widgets', sprintf( 'jQuery.extend( wp.customHtmlWidgets.l10n, %s );', wp_json_encode( $l10n ) ), 'after' );
   231 	}
   235 	}
   232 
   236 
   235 	 *
   239 	 *
   236 	 * @since 4.8.1
   240 	 * @since 4.8.1
   237 	 * @since 4.9.0 The form contains only hidden sync inputs. For the control UI, see `WP_Widget_Custom_HTML::render_control_template_scripts()`.
   241 	 * @since 4.9.0 The form contains only hidden sync inputs. For the control UI, see `WP_Widget_Custom_HTML::render_control_template_scripts()`.
   238 	 *
   242 	 *
   239 	 * @see WP_Widget_Custom_HTML::render_control_template_scripts()
   243 	 * @see WP_Widget_Custom_HTML::render_control_template_scripts()
       
   244 	 *
   240 	 * @param array $instance Current instance.
   245 	 * @param array $instance Current instance.
   241 	 * @returns void
       
   242 	 */
   246 	 */
   243 	public function form( $instance ) {
   247 	public function form( $instance ) {
   244 		$instance = wp_parse_args( (array) $instance, $this->default_instance );
   248 		$instance = wp_parse_args( (array) $instance, $this->default_instance );
   245 		?>
   249 		?>
   246 		<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" class="title sync-input" type="hidden" value="<?php echo esc_attr( $instance['title'] ); ?>"/>
   250 		<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" class="title sync-input" type="hidden" value="<?php echo esc_attr( $instance['title'] ); ?>"/>
   301 		$content .= '</p>';
   305 		$content .= '</p>';
   302 
   306 
   303 		if ( 'false' !== wp_get_current_user()->syntax_highlighting ) {
   307 		if ( 'false' !== wp_get_current_user()->syntax_highlighting ) {
   304 			$content .= '<p>';
   308 			$content .= '<p>';
   305 			$content .= sprintf(
   309 			$content .= sprintf(
   306 				/* translators: 1: link to user profile, 2: additional link attributes, 3: accessibility text */
   310 				/* translators: 1: Link to user profile, 2: Additional link attributes, 3: Accessibility text. */
   307 				__( 'The edit field automatically highlights code syntax. You can disable this in your <a href="%1$s" %2$s>user profile%3$s</a> to work in plain text mode.' ),
   311 				__( 'The edit field automatically highlights code syntax. You can disable this in your <a href="%1$s" %2$s>user profile%3$s</a> to work in plain text mode.' ),
   308 				esc_url( get_edit_profile_url() ),
   312 				esc_url( get_edit_profile_url() ),
   309 				'class="external-link" target="_blank"',
   313 				'class="external-link" target="_blank"',
   310 				sprintf(
   314 				sprintf(
   311 					'<span class="screen-reader-text"> %s</span>',
   315 					'<span class="screen-reader-text"> %s</span>',
   312 					/* translators: accessibility text */
   316 					/* translators: Accessibility text. */
   313 					__( '(opens in a new tab)' )
   317 					__( '(opens in a new tab)' )
   314 				)
   318 				)
   315 			);
   319 			);
   316 			$content .= '</p>';
   320 			$content .= '</p>';
   317 
   321