WP Customizer JS Template not saving color field

I’m trying to create a custom typography control, I’m having problem saving the value of the color, please take a look at my code: <?php class Customizer_Typo_Control_Typography extends WP_Customize_Control { /** * The type of customize control being rendered. */ public $type=”typography”; /** * Array */ public $l10n = array(); /** * Set up our … Read more

Javascript code inside “” in core WordPress files .php

I found some interesting embeding JavaScript mix with HTML in WordPress php files, for instance: <?php // Template for the Attachment Details two columns layout. ?> <script type=”text/html” id=”tmpl-attachment-details-two-column”> <div class=”attachment-media-view {{ data.orientation }}”> <h2 class=”screen-reader-text”><?php _e( ‘Attachment Preview’ ); ?></h2> <div class=”thumbnail thumbnail-{{ data.type }}”> <# if ( data.uploading ) { #> <div class=”media-progress-bar”><div></div></div> … Read more

Issue with using Underscore in WordPress

I have read in another SO post that Underscore.js is including in WordPress by default. I am using it to test if a variable is defined but get this in the browser console: pluginAdminPage.js:32 Uncaught ReferenceError: _ is not defined at pluginAdminPage.js:32 (anonymous) @ pluginAdminPage.js:32 _.VERSION // .VERSION even autofills. So then the browser has … Read more

What type of template are WP media-modal’s templates?

I was looking at the WordPress templates (html that’s written to the page instead of awkwardly adding strings in JS). There are a lot of templates like this in a post editor for example: <script type=”text/html” id=”tmpl-uploader-status-error”> <span class=”upload-error-filename”>{{{ data.filename }}}</span> <span class=”upload-error-message”>{{ data.message }}</span> </script> Now, I know these can be referenced with wp.media.template(‘uploader-status-error’)( … Read more

Can I add custom attributes while adding inline scripts?

I need to inject some underscore templates into admin screen without modifying the core. The templates look like this: <script type=”text/template” id=”template-123″> <div class=”section intro”> {{{ data.section.intro }}} </div> <div class=”section content”> {{{ data.section.content }}} </div> … </script> All templates depend on certain script handle, so I thought about using wp_add_inline_script() but it doesn’t allow … Read more

Open media frame and select an attachment

I’m using the following piece of code to open a media frame when clicking a link with a data-attachment_id attribute. This attribute holds the id of an attachment that I want to select when the frame opens: jQuery(document).ready(function($){ $( ‘#gallery_images_container’ ).on( ‘click’, ‘a.edit’, function( event ) { var $el = $( this ); var selected … Read more