Make WordPress Core

Search Results for: open source Toggle Comment Threads | Keyboard Shortcuts

  • Scott Taylor 9:57 pm on April 8, 2013 Permalink
    Tags: Audio, , MediaElement, , ,   

    Audio / Video support in Core 

    Post Formats are a big feature in WordPress 3.6. What you may not know is: there is now native support for Audio and Video in core! There has been great support for embeds by way of WP_Embed and oEmbed providers for a while, but, if you wanted to play an MP3 from your Media Library, you had to install a plugin. Supporting audio and video in core gives bands, podcasters, vloggers, et al the ability to easily and beautifully expresses themselves through sounds and moving pictures without using an external service.

    How does this work?

    At the core of the experience is the fantastic library, MediaElement.js. MediaElement is the facade layer that gives us maximum file support and cross-browser compatibility. While some libraries require a Flash-only solution to make your media work cross-environment, MediaElement lets you use HTML5 audio / video tags in every browser, and, only when necessary, will use a Flash or Silverlight plugin in the background to make incompatible media work. Translation, things like this: <audio> tag works in old IE, Windows Media files work in Chrome.

    MediaElement uses the same HTML markup, regardless of playback implementation, and you can use CSS to skin the players.

    Shortcodes

    MediaElement’s great, but we don’t want to be locked in to one external library forever. Instead of using MediaElement-specific markup everywhere, we expose audio and video markup through shortcodes: [audio] and [video].

    For the following scenarios:

    • I have an old post that has a video in the Media Library attached to it, and I want to use the new shortcode: [video]
    • I have the URL for a video, from the Media Library or external, that I want to play:
      [video src="video-source.mp4"]
    • I have a source URL and fallbacks for other HTML5-supported filetypes:
      [video width="600" height="480" mp4="source.mp4" ogv="source.ogv" webm="source.webm"]

    Same goes for audio:

    • I have an old post that has an audio file in the Media Library attached to it, and I want to use the new shortcode: [audio]
    • I have the URL for an MP3, from the Media Library or external, that I want to play: [audio src="audio-source.mp3"]
    • I have a source URL and fallbacks for other HTML5-supported filetypes:
      [audio mp3="source.mp3" ogg="source.ogg" wav="source.wav"]

    Shortcodes focus on the “what” and abstract the “how.” If you want to use a library that is not MediaElement, you can! Just look at what to filter: here

    Embeds

    There are also new embed handlers for audio and video. Using them is easy as dropping a media link on a line by itself in the editor:

    http://my.mp3s.com/cool/songs/coolest.mp3
    
    I like this song because it is really cool!
    

    Works for both audio and video with URLs matching the allowed (and filterable) list of extensions (see: here and here)

    Admin

    Using the new post formats UI, it is even easier to get directly at the audio and video in your Media Library. When selecting, the media modal opens to your library, filtered by media type.

    Metadata

    In previous versions of WP, you could upload audio and video, but we were not generating metadata like we do for images. In 3.6, using the getID3 library, we are able to extract data from audio and video like cover art, song length, artist, album, song title, genre, codec, etc. It’s pretty great. We will soon be exposing more of this data in the admin as well, along with inline previews on the Edit Media page:

    Themers

    Themers can get in on the action, too, using structured-post-formats in their theme (Twenty Thirteen is a great place to look). The admin gives users flexibility when associating media with a post. the_post_format_audio() and the_post_format_video() will automagically retrieve and output your media in the front end.

     
    • sourceforge 10:09 pm on April 8, 2013 Permalink | Log in to Reply

      thank you, is this the html5 vid player? looks good, newer java based audio player is also needed, flash is always prone to attacks

    • Manny Fleurmond 10:11 pm on April 8, 2013 Permalink | Log in to Reply

      How does this handle m4a files?

    • Konstantin Obenland 10:59 pm on April 8, 2013 Permalink | Log in to Reply

      The attentive reader might have noticed how the buffer- and play-time-bars in the first and second screenshot have different colors.

      Themes can style these elements of the players. The first example is a screenshot from Twenty Thirteen, with a white buffer bar, an orange play time bar and no border-radius.

    • John Saddington 11:11 pm on April 8, 2013 Permalink | Log in to Reply

      this is fantastic. john dyer’s MEJS is amazing.

    • AK Ted 11:32 pm on April 8, 2013 Permalink | Log in to Reply

      This is great news! Can’t wait for stable to play with, no time atm for beta. :(

      Small grammar correction: “ability to easily and beautifully expresses themselves” (in first paragraph), should be “express”.

    • Michael Beckwith 11:51 pm on April 8, 2013 Permalink | Log in to Reply

      That’s pretty hot

    • Ipstenu (Mika Epstein) 1:07 am on April 9, 2013 Permalink | Log in to Reply

      What’s the fallback? Like if I use and they don’t allow for HTML5 (yes, I have people who don’t), what shows? Right now I made an html5video shortcode that has, at the bottom ‘Can’t see a video? Click here…’ and it defaults to the MP4.

      • Scott Taylor 2:47 am on April 9, 2013 Permalink | Log in to Reply

        I am pretty sure MP4 will win and play via Flash. If no flash and no HTML5, there will be a link that goes straight to the file.

    • Jon Brown 1:09 am on April 9, 2013 Permalink | Log in to Reply

      Not sure how I missed this on trac, but “YAY!!! & Oh No!!!!”.

      I just spent a month (not continuously) trying to figure out why MediaElements.js conflicted with Soliloquy (Flex based Slider) when both appeared on the same page on mobile. Only on mobile, everything worked fine everywhere else. I finally gave up, ditched ME.js for Video.js.

      I’m now about to test that site on 3.6 just out of curiosity as to what happens.

      I too really dislike this using shortcodes and my bigger concern is what this does to other plugins that use the shortcode already.

      Always seemed to me WP ought to follow best naming practices and use [wp_gallery], [wp_video], etc…

      • Jon Brown 1:26 am on April 9, 2013 Permalink | Log in to Reply

        That was easy to test… still conflicting somehow. I’ve let Thomas know with urls to dev/staging/live servers showing it all. It’s really bizzare that it only happens on mobile browsers (iOS chrome and safari) anbd throws no errors. Either works fine on it’s own, and we’ve recreated it on vanila WP running 2010.

    • Beau Lebens 1:42 am on April 9, 2013 Permalink | Log in to Reply

      <3

    • Tomas 4:01 am on April 9, 2013 Permalink | Log in to Reply

      WoW! This is good news!

    • Robert Chapin (miqrogroove) 1:48 pm on April 9, 2013 Permalink | Log in to Reply

      That’s hot! :D

    • redwallhp 10:35 pm on April 9, 2013 Permalink | Log in to Reply

      Awesome! The assimilation of the Crowd Favorite post format UI and MediaElement.js support in one version.

    • Eric Andrew Lewis 11:18 am on April 10, 2013 Permalink | Log in to Reply

      Totally wow.

    • hearvox 12:22 am on April 11, 2013 Permalink | Log in to Reply

      any hooks yet for skinning the default MEjs player?

    • rilwis 2:22 pm on April 11, 2013 Permalink | Log in to Reply

      This feature is really great and useful for all people. I’ve been using MEjs and it’s really great. Nice UI, great support.

    • johndyer 10:48 pm on April 11, 2013 Permalink | Log in to Reply

      So glad to hear it! Glad to have “contributed” :)

    • Maor Chasen 6:15 pm on April 12, 2013 Permalink | Log in to Reply

      Love!

    • Anderton 9:06 am on April 15, 2013 Permalink | Log in to Reply

      Have been playing around with it while developing a couple of themes for 3.6. It’s lovely, and easy to style. Have been using MediaElements,js before, and when i found out that it would be included in the Core, i was thrilled. Good move!

    • Bjarni Wark 10:25 pm on April 16, 2013 Permalink | Log in to Reply

      Really good news, thanks for the efforts of making this happen.

    • Maeve Lander 4:58 am on April 17, 2013 Permalink | Log in to Reply

      Just wondering how will this affect existing audio/video plugins? Any potential problems, conflicts, things plugin developers could do better to integrate with this etc?

    • esmi 7:49 pm on April 17, 2013 Permalink | Log in to Reply

      I have to say, I’m really disappointed that there’s no mechanism for people to add captions for videos or provide text transcripts with audio files. come on, people! We need to be encouraging people to do this kind of stuff but unless WordPress provides the methods, it just won’t happen.

      • Scott Taylor 7:57 pm on April 17, 2013 Permalink | Log in to Reply

        #patcheswelcome

      • Ipstenu (Mika Epstein) 8:18 pm on April 17, 2013 Permalink | Log in to Reply

        Speaking as someone totally ignorant of this, how DO you add captions to videos? Can I include a transcript.txt file like I do for different video versions?

        • Joe Dolson 11:26 pm on April 17, 2013 Permalink | Log in to Reply

          There are various formats for captions, but yes, essentially it amounts to referencing a text file with captions. Mediaelement.js supports .srt and .vtt caption formats, and they’re referenced as

          In this context, you should treat the terms ‘subtitles’ and ‘captions’ synonymously, although technically they are different.

          All the WP system needs to do for captions is provide a mechanism to upload them and auto-generate the relevant track elements, basically.

    • esmi 8:11 pm on April 17, 2013 Permalink | Log in to Reply

      We’ve only just picked this up in the make.wordpress.accessible group but, yes, we will be trying to come up with some patches if we can :)

    • FranciscoAMK 8:19 pm on April 21, 2013 Permalink | Log in to Reply

      Is the featured image set as the “poster” for the video post format?

  • Kim Parsell 4:37 pm on April 4, 2013 Permalink | Log in to leave a Comment

    HTML Coding Standards 

    HTML

    Validation

    All HTML pages should be verified against the W3C validator to ensure that the markup is well formed. This in and of itself is not directly indicative of good code, but it helps to weed out problems that are able to be tested via automation. It is no substitute for manual code review. (For other validators, see HTML Validation in the Codex.)

    Self-closing Elements

    All tags must be properly closed. For tags that can wrap nodes such as text or other elements, termination is a trivial enough task. For tags that are self-closing, the forward slash should have exactly one space preceding it:

    <br />

    rather than the compact but incorrect:

    <br/>

    The W3C specifies that a single space should precede the self-closing slash (source).

    Attributes and Tags

    All tags and attributes must be written in lowercase. Additionally, attribute values should be lowercase when the purpose of the text therein is only to be interpreted by machines. For instances in which the data needs to be human readable, proper title capitalization should be followed.

    For machines:

    
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    
    

    For humans:

    
    <a href="http://example.com/&quot; title="Description Here">Example.com</a>
    
    

    Quotes

    According to the W3C specifications for XHTML, all attributes must have a value, and must use double- or single-quotes (source). The following are examples of proper and improper usage of quotes and attribute/value pairs.

    Correct:

    
    <input type="text" name="email" disabled="disabled" />
    
    <input type='text' name='email' disabled='disabled' />
    
    

    Incorrect:

    
    <input type=text name=email disabled>
    
    

    In HTML, attributes do not all have to have values, and attribute values do not always have to be quoted. While all of the examples above are valid HTML, failing to quote attributes can lead to security vulnerabilities. Always quotes attributes.

    Indentation

    As with PHP, HTML indentation should always reflect logical structure. Use tabs and not spaces.

    When mixing PHP and HTML together, indent PHP blocks to match the surrounding HTML code. Closing PHP blocks should match the same indentation level as the opening block.

    Correct:

    
    <?php if ( ! have_posts() ) : ?>
    
    	<div id="post-1" class="post">
    
    		<h1 class="entry-title">Not Found</h1>
    
    		<div class="entry-content">
    
    			<p>Apologies, but no results were found.</p>
    
    			<?php get_search_form(); ?>
    
    		</div>
    
    	</div>
    
    <?php endif; ?>
    
    

    Incorrect:

    
    		<?php if ( ! have_posts() ) : ?>
    
    		<div id="post-0" class="post error404 not-found">
    
    			<h1 class="entry-title">Not Found</h1>
    
    			<div class="entry-content">
    
    			<p>Apologies, but no results were found.</p>
    
    <?php get_search_form(); ?>
    
    			</div>
    
    		</div>
    
    <?php endif; ?>
    
    

    Credits

     
  • Erick Hitter 7:43 pm on February 5, 2013 Permalink
    Tags: ,   

    Revisions Update, 2/5 

    Yesterday’s meeting focused on revisions to the revisions interface :) . @lessbloat joined us to ask some great questions, and helped refocus the UI changes that have been proposed and mocked up so far. We started off by trying to identify the major uses of revisions, and settled on two primary cases: undoing mistakes by finding the last correct revisions, and reviewing changes as part of an editorial workflow.

    In light of those focuses, we’ve decided to revisit the UI mockups we’ve (namely, @karmatosed and @adamsilverstein) worked on so far. The general consensus is that they’ve become overly complicated, and led to feature creep (looking at you, line-by-line accept/reject capabilities). @karmatosed is working on some new mockups for Thursday’s office hours. One possible source of inspiration may be @benbalter’s post forking plugin.

    On the code side, @mdawaffe worked out a pretty comprehensive patch for the display of incorrect authors on revisions (#16215). We’ll be reviewing that, along with the patches added to the other tickets we’ve scoped for 3.6. As was the case when I last posted, progress is slow at this point due to travel and the ongoing UI discussions.

    [IRC log]

     
    • adamsilverstein 8:47 pm on February 5, 2013 Permalink | Log in to Reply

      i posted patches for testing that implement some of the mockup concepts we talked about during our meeting here – #23396

    • karmatosed 2:56 pm on February 7, 2013 Permalink | Log in to Reply

      I’ve got some more mockups for discussion in the meeting today here:

      I spent some time with @benbalter’s plugin and merged that with some of the ideas that seemed ‘easy wins’ from a UI view. It’s mainly a tidy up in a lot of respects. I did one with notes but understand this feature probably will not be included – I just wanted to see what it looked like.

      I felt the picking in the post forking plugin worked well for that instance but may be overly complicating for us as the ‘new’ would always be the newer version so that’s what I was keeping to by you just picking 2. I didn’t add a submit or confirm as figured if you picked 2 it could reload – we may want to reconsider this as perhaps a pause through clicking something could be useful.

  • Helen Hou-Sandi 4:36 am on January 18, 2013 Permalink
    Tags: ,   

    Post Formats UI Update, 1/17 

    The post formats UI feature encompasses a couple things: the add/edit UI itself, and also what this means in terms of structured data and theme usage and expectations of data. Our goal is to make post formats meaningful and usable, because let’s face it: they’re not. What can we do in the admin to help a user understand what a given post format means and how it behaves in use, and what can we do to give themes something standardized and portable when it comes to data available for display?

    Had our first office hours chat today to get started – great discussion happening on a lot of fronts, especially theme compat. We identified two distinct tasks to get us through the weekend.

    The first, and most crucial piece, is thinking about/identifying what users are doing when creating a post using a post format and turning that into (likely annotated) wireframes/storyboards. That is to say – what sort of UI might we want want to see on the add/edit post screen? We’ll want to think about things like what makes it easy for a user to select a format, what a user might expect to see on the edit screen for a given format (no title, or the title is de-emphasized, or what images show in that gallery, etc.), and what happens when switching between formats. Some existing examples are CF Post Formats and WordPress.com. We also shouldn’t ignore what Tumblr does for its various formats. @alexkingorg gave us a demo link for CF and @beaulebens was kind enough to take some screenshots:

    Please post in a comment here with anything you come up with. Don’t worry about anything beyond the add/edit post screen for the moment. Also don’t worry about what data exactly is or is not represented – base your ideas on user workflows. The workflows and UI will heavily influence any structured data. There are also some other things to keep in the back of your mind as possible influences for anything core UI-related: how might a layout you’re imagining adapt to various screen sizes and devices, and are there pieces that can be used as the basis for more generalized core UI components.

    The second piece for now is functions (probably using regex, and I know) for pulling out relevant data for post formats as appropriate, e.g. the first URL in the content for the link format, oEmbed URL or appropriate HTML element for audio/video formats, etc. What might or might not be done with the data hasn’t been determined yet, but we can at least start here. Some existing examples are the twentyeleven_url_grabber() function and what they use on WordPress.com. Nobody has claimed this task. For now, go ahead and upload any patches to the main ticket, #19570.

    There are also some related existing tickets that could use testing/+1′s or patches:

    • #16047 – separate column for post format in the list table
    • #23198 – pass the post format as a class to TinyMCE
    • #15323 – list table filter by post format
    • #15514 – add to the cat-tag convertor plugin

    Read the full IRC log here.

     
    • Piet 6:52 am on January 18, 2013 Permalink | Log in to Reply

      Thinking out loud without having put too much thought in it, I think it would be user friendly that before a user starts writing a post, he/she can already choose the format.
      Upon choosing this format, the backend changes with the relevant fields. Sort of like different templates for the backend.
      Not sure though how feasible that would be.

    • Mang_ 7:44 am on January 18, 2013 Permalink | Log in to Reply

      I like a wp.com, also for continuity

      Paolo

    • Shea Bunge 7:56 am on January 18, 2013 Permalink | Log in to Reply

      I was working make a plugin a bit like this – very incomplete, but contains some regex and implementation. Most of the snippets are by @Justin Tadlock. https://github.com/bungeshea/post-formats

    • htrex 9:56 am on January 18, 2013 Permalink | Log in to Reply

      http://schema.org/docs/schemas.html
      Google,Yahoo and Bing converged on schema.org during 2011 and recently started to use it in serps displaying special snippets, that’s the effective beginning of a radical change named Web 3.0.
      Schema.org involves a radical change in how users produce content and requires structuring data far more than we do today, there are currently more than 400 standard entities and no space for interpretation: search engines expect “things” to be described in that way.
      To handle this WP backend UI needs to change and probably stop showing every custom post format at the root menu level, in the near future we may need to use post formats much more and evidently there’s no room for 400 first level menu slots.
      Schema.org entities allow inheritance with every entity as a child of “Thing”, and 8 basic direct childs:

      • Creative Work
      • Organizzation
      • Place
      • Intangible
      • Medical Entity
      • Event
      • Product
      • Person

      but there’s multiple inheritance level (eg: Thing > Organization > LocalBusiness > GovernmentOffice > PostOffice) where each subsequent child can add more fields…. in some types there are literally hundreds of fields, too much for us humans.
      How to handle all this stuff?
      The most promising idea and implementation seems to be http://decoupledcms.org/ http://bergie.iki.fi/blog/decoupling_content_management/

      • Helen Hou-Sandi 1:39 pm on January 18, 2013 Permalink | Log in to Reply

        You are talking about custom post (content) types, not post formats, and they can be submenu items rather than top level items.

    • Tom Lynch 3:07 pm on January 18, 2013 Permalink | Log in to Reply

      Just thought I would share my current solution for a network of blogs we run called GDNM.org…

      On image and video posts there is a URL box where you can enter a URL and when you tab out it will fetch the image or embed the video using oembed:

      https://www.dropbox.com/sh/xhc5vkzhbytt06q/MuUl0Eh7ZH#f:07.%20oembed.png

      The box sits just above the first post, as it’s for quick posting in the theme but either way it works well!

      No post format selected:
      https://www.dropbox.com/sh/xhc5vkzhbytt06q/MuUl0Eh7ZH#f:01.%20closed.png

      Blog post format:
      https://www.dropbox.com/sh/xhc5vkzhbytt06q/MuUl0Eh7ZH#f:02.%20blog.png

      Image post format:
      https://www.dropbox.com/sh/xhc5vkzhbytt06q/MuUl0Eh7ZH#f:03.%20image.png

      Video post format:
      https://www.dropbox.com/sh/xhc5vkzhbytt06q/MuUl0Eh7ZH#f:04.%20video.png

      Link post format:
      https://www.dropbox.com/sh/xhc5vkzhbytt06q/MuUl0Eh7ZH#f:05.%20link.png

      Quote post format:
      https://www.dropbox.com/sh/xhc5vkzhbytt06q/MuUl0Eh7ZH#f:06.%20quote.png

    • Mike Schinkel 5:58 pm on January 18, 2013 Permalink | Log in to Reply

      Hi @Helen, I’m not a UI person so don’t have any relevant comments there. However whatever get’s implemented it would be great if it can be controlled via hooks and/or if a class was introduced.

      As you know there’s a lack of flexibility for the plugin developer around the top of the post edit page and it would seem this type of UI change would require flexibility; I hope that flexibility can make it’s way into being addressable by plugin developers.

    • Manny Fleurmond 4:58 am on January 19, 2013 Permalink | Log in to Reply

      Just riffing for a bit: I hope people get what I’m trying to convey:

      So when I look at a post, I see the content data (the title and content), ie the meat and potatoes of a post and I see meta data/ taxonomies that add to the main data to categorize/tag/describe it. The content has is own area and meta data/ taxonomies/ etc are relegated to meta boxes. Looking at the different post format examples from other CMS’s, you are basically changing the type of content and therefore are changing the type of content fields you are using. Video posts may need a title and description, but they also need a video source url. An aside doesn’t even need a title. Post formats are just presets of custom content fields.

      In order to beef up post formats, I think we need to add hooks and an API that allows developers to change the content area of a post; to basically upgrade a few custom fields to content status. Not only should developers be able to add fields that are important enough to be content alongside the post title and post content fields, they should be able to replace those fields entirely, if they so wish. I have a side project where I disabled the title and content, to be replaced by a URL field and it always felt weird to me that I had to put that field in a meta box when it should have been considered the main content. A new post format UI would basically just be picking out a preset of fields that best fits the format of content. As Mike Schinkel suggested, flexibility is key as it would open some nice functionality for plugin developers as well as make WP a lot more robust.

      • Helen Hou-Sandi 5:24 am on January 19, 2013 Permalink | Log in to Reply

        The point is to create a core UI for the post formats, not leave it up to themes and plugins. Implementation details will come after a UI the supports good workflows is decided upon.

    • lessbloat 2:04 pm on January 19, 2013 Permalink | Log in to Reply

      I thought I’d run a couple users through some post format tasks to give us a baseline comparison for improvements/patches. Here are the videos from user 1 & user 2.

      User #1

      Step 1: Log in

      No issues.

      Step 2: Go to add post screen

      No issues.

      Step 3: Add text post

      No issues.

      Step 4: Add image post

      No issues.

      Step 5: Add video post

      4:34 – He tries to add the video URL through the media modal (Insert from URL screen), it inserts a link to the video instead of embedding it.
      6:55 – He finally gives up on trying to get the video to embed, “I’m assuming it just want’s me to insert this link”, he says as he moves on to the next task.

      Step 6: Add link post

      7:55 – since adding a link worked for the other two tasks, he actually used the media modal to add a link this time as well, and it worked. :-)

      Step 7: Add quote post

      9:07 – He clicked the “text” tab thinking that is where he would add the quote.

      Step 8: Preview site

      No issues.

      User #2

      Step 1: Log in

      No issues.

      Step 2: Go to add post screen

      No issues.

      Step 3: Add text post

      No issues.

      Step 4: Add image post

      4:10 – She wonders if she needs a title for the image she’s posting.

      Step 5: Add video post

      5:20 – She tried using the media modal (Insert from URL) as well.
      6:30 – She’s still searching for a way to add the video, “Not quite sure how to add the video”
      12:25 – She gives up and moves on to the next task, after making multiple attempts to embed the video.

      Step 6: Add link post

      No issues.

      Step 7: Add quote post

      14:55 – She selected the “quote” post format radio option wondering if something would happen.

      Step 8: Preview site

      No issues.

      Observations/Thoughts

      • In general, other than video embedding, everything seemed to go really smoothly.
      • I almost wonder… Could we get away with simply implementing video embedding in the media modal (on the Insert from URL screen) and calling it good? Just a thought.
      • Excited to see what comes out of this :-)
      • adamsilverstein 9:32 pm on January 19, 2013 Permalink | Log in to Reply

        love these user tests, great way to get real feedback. thanks!

      • Helen Hou-Sandi 1:49 am on January 20, 2013 Permalink | Log in to Reply

        It’s possible I missed a task (I was clicking through the videos a bit), but it doesn’t seem like they were directed to the actual post formats, not all of which are turned on in all themes. Maybe we can talk about an alternate task script to try.

        Definitely agree we could do something to pull in oEmbed data for a preview where it exists, though. Doing it in the media library also means a TinyMCE view and is probably a general thing, but what WordPress.com does is pretty neat.

        • lessbloat 1:15 pm on January 21, 2013 Permalink | Log in to Reply

          Let me know. I’m happy to run more users through with a modified script.

    • rachelbaker 1:17 am on January 21, 2013 Permalink | Log in to Reply

      My favorite example of an existing WordPress UI for adding a new “post format” post would be the P2 theme. Only the relevant fields are displayed for each post format.

      Screenshot: http://cl.ly/image/2p1H290d1T2B

      The status and link post formats only display a content textarea (no title).

      The quote format displays the content textarea and citation text input fields.

      The blog post format displays the standard title and content fields.

  • Matt Wiebe 9:47 pm on November 30, 2012 Permalink
    Tags:   

    New Color Picker in WP 3.5 

    You may have noticed that WordPress 3.5 is sporting a new color picker. We originally developed it for the Custom Colors feature on WordPress.com. We offered it to WordPress Core, and 4 months, eleventy million tests and iterations later, there’s a shiny new, HiDPI-ready, CSS gradient-based color picker called Iris in your WordPress. But how do you use it?

    The easiest way possible is in the Customizer. Keep registering your color controls the same way you always have and they’ll now sport a slick new Iris-based color picker interface. Otto’s great Theme Customizer tutorial shows you how to register controls, including a color control, so I won’t repeat that information here.

    Want to use the new color picker somewhere else? Here’s a quick guide:

    1. Enqueue the ‘wp-color-picker’ script and style

    add_action( 'admin_enqueue_scripts', 'mw_enqueue_color_picker' );
    function mw_enqueue_color_picker( $hook_suffix ) {
    	// first check that $hook_suffix is appropriate for your admin page
    	wp_enqueue_style( 'wp-color-picker' );
    	wp_enqueue_script( 'my-script-handle', plugins_url('my-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
    }
    

    My plugin now has a my-script.js file that has declared wp-color-picker as a dependency. We can now use the wpColorPicker jQuery method inside it.

    2. Add an input to your admin page

    I’m not going to tell you how to code an admin page. Somewhere on it, you’ll want:

    <input type="text" value="#bada55" class="my-color-field" />

    You can also prime a default color for the field if you want:

    <input type="text" value="#bada55" class="my-color-field" data-default-color="#effeff" />

    3. Call ‘wpColorPicker’ from your script

    Remember that we enqueued my-script.js above? Open it up, and be prepared for some long coding:

    jQuery(document).ready(function($){
    	$('.my-color-field').wpColorPicker();
    });
    

    What, you wanted more? There’s a lot more you can do, but that will get the job done for most cases. (Note that only IE8 and up are supported. IE7 and under will fail gracefully, leaving you with a perfectly usable text input.)

    4. Advanced usage

    wpColorPicker supports a few options. You can supply an options object when calling it:

    var myOptions = {
    	// you can declare a default color here,
    	// or in the data-default-color attribute on the input
    	defaultColor: false,
    	// a callback to fire whenever the color changes to a valid color
    	change: function(event, ui){},
    	// a callback to fire when the input is emptied or an invalid color
    	clear: function() {},
    	// hide the color picker controls on load
    	hide: true,
    	// show a group of common colors beneath the square
    	// or, supply an array of colors to customize further
    	palettes: true
    };
    
    $('.my-color-field').wpColorPicker(myOptions);
    

    5. More advanced usage

    wpColorPicker is set of UI controls wrapped around the underlying Iris color picker. We did things this way so that, if a better color picker comes along, we can more easily swap it out. But, if you want to just play with Iris itself, just declare iris as your script dependency instead. I’m not going to document the options here, but Iris’s GitHub repo should see some actual docs in the future.

     
  • Andrew Spittle 10:08 pm on August 5, 2012 Permalink | Log in to leave a Comment

    Files and Tools 

    gettext files

    There are three types of files used in the gettext translation framework. These files are used and/or generated by translation tools during the translation process, as follows:

    POT (Portable Object Template) files

    The first step in the localization process is that a program is used to search through the WordPress source code and pick out every message passed into a __() or _e() function. This list of English-language messages is put into a specially-formatted template file (POT file) that forms the basis of all translations. Generally, you can download a POT file for WordPress, so you shouldn’t have to generate your own. Separate POT files can also be made for themes and plugins, if the theme/plugin developer has enclosed all text in __() or _e() functions.

    PO (Portable Object) files

    The second step in the localization process is that the translator translates all the messages from the POT file into the target language, and saves both English and translated messages in a PO file.

    MO (Machine Object) files

    The final step in the localization process is that the PO file is run through a program that turns it into an optimized machine-readable binary file (MO file). Compiling the translations to machine code makes the localized program much faster in retrieving the translations while it is running.

    Translation Tools

    There are various tools available to aid in translating. You may use whichever you prefer.

    GlotPress

    GlotPress will let you, or an entire team, translate your favorite software. It is web-based and open-source. It is also completely in sync with the main repositories and the preferred method for translating WordPress into your language.

    Launchpad

    The Ubuntu Linux project has a web site that allows you to translate messages without even looking at a PO or POT file, and export directly to a MO.

    Pootle

    An open source web-based translation system. The server hosted at locamotion.org currently has WordPress translation enabled on it.

    Poedit

    An open source program for Windows, Mac OS X and UNIX/Linux which provides an easy-to-use GUI for editing PO files and generate MO files.

    KBabel

    Another open source PO editing program for the KDE window manager on Linux.

    GNU Gettext

    The official Gettext tools package contains command-line tools for creating POTs, manipulating POs, and generating MOs. For those comfortable with a command shell.

     
  • Andrew Spittle 9:54 pm on August 5, 2012 Permalink | Log in to leave a Comment

    Translating WordPress 

    Introduction

    WordPress is translated into many languages and all translations are powered by volunteer community members. If you would like to start translating WordPress, check WordPress In Your Language (and the resources cited there) to see if a translation of WordPress into your language already exists.

    It is also possible that someone, or a team, is already working on translating WordPress into your language, but they haven’t finished yet. To find out, subscribe to the polyglots’ blog, introduce yourself, and ask if there’s anyone translating into your language. There is also a list of localization teams and localization teams currently forming, which you can check to see if a translation is in progress.

    Qualifications

    If a WordPress translation in your language does not already exist or does not have someone working on it, you may want to volunteer to create a public translation of WordPress into your language. If so, here are the qualifications you will need:

    • You need to be truly bilingual – fluent in both written English and the language(s) you will be translating into. Casual knowledge of either one will make translating difficult for you, or make the localization you create confusing to native speakers.
    • You need to be familiar with PHP, as you will sometimes need to read through the WordPress code to figure out the best way to translate messages.
    • You should be familiar with human language constructs: nouns, verbs, articles, etc., different types of each, and be able to identify variations of their contexts in English.

    Tips For Good Translations

    Don’t translate literally, translate organically

    Being bi- or multi-lingual, you undoubtedly know that the languages you speak have different structures, rhythms, tones, and inflections. Translated messages don’t need to be structured the same way as the English ones: take the ideas that are presented and come up with a message that expresses the same thing in a natural way for the target language. It’s the difference between creating an equal message and an equivalent message: don’t replicate, replace. Even with more structural items in messages, you have creative license to adapt and change if you feel it will be more logical for, or better adapted to, your target audience.

    Try to keep the same level of formality (or informality)

    Each message has a different level of formality or informality. Exactly what level of formality or informality to use for each message in your target language is something you’ll have to figure out on your own (or with your team), but WordPress messages (informational messages in particular) tend to have a politely informal tone in English. Try to accomplish the equivalent in the target language, within your cultural context.

    Don’t use slang or audience-specific terms

    Some amount of terminology is to be expected in a blog, but refrain from using colloquialisms that only the “in” crowd will get. If the uninitiated blogger were to install WordPress in your language, would they know what the term means? Words like pingback, trackback, and feed are exceptions to this rule; they’re terminology that are typically difficult to translate, and many translators choose to leave in English.

    Read other software’s localizations in your language

    If you get stuck or need direction, try reading through the translations of other popular software tools to get a feel for what terms are commonly used, how formality is addressed, etc. Of course, WordPress has its own tone and feel, so keep that in mind when you’re reading other localizations, but feel free to dig up UI terms and the like to maintain consistency with other software in your language.

    Locales

    A locale is a combination of language and regional dialect. Usually locales correspond to countries, as is the case with Portuguese (Portugal) and Portuguese (Brazil).

    You can do a translation for any locale you wish, even other English locales such as Canadian English or Australian English, to adjust for regional spelling and idioms.

    The default locale of WordPress is US English.

    Localization Technology

    WordPress developers chose to use the GNU gettext localization framework to provide localization infrastructure to WordPress. gettext is a mature, widely-used framework for modular translation of software, and is the de facto standard for localization in the open source/free software realm.

    gettext uses message-level translation – that is, every “message” displayed to users is translated individually, whether it be a paragraph or a single word. In WordPress, such “messages” are generated, translated, and used by the WordPress PHP files via two PHP functions. __() is used when the message is passed as an argument to another function; _e() is used to write the message directly to the page. More detail on these two functions:

    __(‘message’)

    Searches the localization module for the translation of ‘message’, and passes the translation to the PHP return statement. If no translation is found for ‘message’, it just returns ‘message’.

    _e(‘message’)

    Searches the localization module for the translation of ‘message’, and passes the translation to the PHP echo statement. If no translation is found for ‘message’, it just echoes ‘message’.

    <?php $translated_text = __( $text, $domain ); ?>

    The gettext framework takes care of most of WordPress. However, there are a few places in the WordPress distribution where gettext cannot be used – see Files For Direct Translation for more information on how to translate these spots.

     
  • Andrew Nacin 12:26 am on July 25, 2012 Permalink | Log in to leave a Comment

    Fixing Bugs 

    If you are familiar with PHP, JavaScript, or CSS, a great way to contribute to the development of WordPress is to help patch bugs. If you have found a bug, please report it. Once you’ve either found or created a Trac ticket, you can get to work. If want to help, but don’t know which bugs to fix, review the Finding Bugs to Fix section.

    Overview

    WordPress uses Subversion for source control. You will want to check out a working copy of WordPress using a Subversion client (such as Tortoise SVN on Windows, using the command line on Mac and Linux). For more, read the Subversion article.

    One of the many benefits to using a version control system is that you can create a simple text file, called a patch, that shows exactly what you’ve changed — the lines of code you added, modified, and removed. A patch is also called a diff, for differences.

    If you are not familiar with how WordPress is written and organized, read the article on The WordPress Codebase.

    Once you’ve figured out how to fix the bug by modifying WordPress core files, you should create a patch. Review the Creating a Patch documentation.

    Once you’ve created a patch, upload it to the Trac ticket using the Attach file button, and add has-patch to the workflow keywords. Please don’t overwrite any existing, previous patches.

    Finding Bugs to Fix

    If you want to fix bugs in the core parts of WordPress, but don’t know what to fix, here are some suggestions on finding one:

     
  • Andrew Nacin 3:23 pm on July 23, 2012 Permalink | Log in to leave a Comment

    Automated Testing 

    This is an overview of running and writing tests for WordPress. Automated testing is running test cases where manual intervention is not required to run each one. This is usually in the form of writing test suites which have multiple test cases and a library and command line tool that runs the test suite or suites. The test suite execution is usually manual, from the developer choosing which suites on the command line to run, but this isn’t required. The process could be automated and looked over from time to time to ensure that when the code changed, no problems were introduced.

    Installation

    1. Install PHPUnit. WordPress uses PHPUnit, the standard for unit testing PHP projects. Installing PHPUnit is usually accomplished using the PEAR Installer. PHPUnit has instructions here, and on its Github repository. After, you may run phpunit --version from the command line to check that PHPUnit is installed correctly, and can be found in your $PATH environment variable. On Windows and having trouble? Check out this guide.

    2. Check out the test repository. The WordPress tests live outside the core repository, at https://unit-tests.svn.wordpress.org/trunk:

    
    $ svn co https://unit-tests.svn.wordpress.org/trunk wordpress-tests
    
    $ cd wordpress-tests
    
    

    3. Create an empty MySQL database. The test suite will delete all data from all tables for whichever MySQL database it is configured. Use a separate database.

    4. Set up a config file. Copy wp-tests-config-sample.php to wp-tests-config.php, and enter your database credentials. Use a separate database.

    Running the Test Suite

    In the root directory — next to wp-tests-config.php, the tests/ folder, and the phpunit.xml file:

    
    $ phpunit
    
    

    You should see output that looks roughly like the following:

    ....................................................SS.....SS 61 / 1303 ( 4%) 
    
    ...SSSSSS.............S..SSS..........SS................S.... 122 / 1303 ( 9%) 
    
    ..................................S.......................... 183 / 1303 ( 14%) 
    
    ..................S............S.................S.......S... 244 / 1303 ( 18%) 
    
    .............S.......S.S.......S............................. 305 / 1303 ( 23%) 
    
    ....SSSS.S..SSS.........S.SS................................. 366 / 1303 ( 28%) 
    
    ............................................................. 427 / 1303 ( 32%) 
    
    ............................................................. 488 / 1303 ( 37%) 
    
    ............................................................. 549 / 1303 ( 42%) 
    
    ......................................................S...... 610 / 1303 ( 46%) 
    
    ...................SS............SS.......................... 671 / 1303 ( 51%) 
    
    ..............SS.....................S....................... 732 / 1303 ( 56%) 
    
    .............SSS..SSSSSSS.................................... 793 / 1303 ( 60%) 
    
    SS.........SSSS.SS........................................... 854 / 1303 ( 65%) 
    
    ....................................S........................ 915 / 1303 ( 70%) 
    
    ..........................S..S................SS.S........... 976 / 1303 ( 74%) 
    
    ..........................................S.............S.... 1037 / 1303 ( 79%) 
    
    ............................................................. 1098 / 1303 ( 84%) 
    
    ............................................................. 1159 / 1303 ( 88%) 
    
    .....S.................S..................................... 1220 / 1303 ( 93%) 
    
    .....................................S
    
    
    
    Time: 02:24, Memory: 119.75Mb
    
    
    
    OK, but incomplete or skipped tests!
    
    Tests: 1258, Assertions: 5219, Skipped: 74.

    What each symbol means:

    • . — Each dot signifies one “test” that passed.
    • S means a test was skipped. For WordPress, this usually means that the test is linked to a bug report, and that bug report remains unfixed.
    • F means a test failed. More output will be shown for what exactly failed and where.
    • E means a test failed due to a PHP error.
    • I means a test was marked as incomplete.

    Running Specific Tests

    By default, the Ajax tests (tests written for core’s use of wp-admin/admin-ajax.php) are not run. To run these:

    
    $ phpunit --group ajax
    
    

    To run the tests under multisite, you must switch to the multisite.xml configuration file:

    
    $ phpunit -c multisite.xml
    
    

    You may also define the constant WP_TESTS_MULTISITE as true in wp-tests-config.php.

    To run an individual file, you can use the name of the class, or the full path to the file:

    
    $ phpunit Tests_Dependencies_Styles
    
    $ phpunit tests/dependencies/styles.php
    
    

    To run a group of tests — defined by @group in code comments:

    
    $ phpunit --group dependencies
    
    $ phpunit --group themes
    
    

    Many tests are marked with a @ticket annotation, which indicates they were the result of that WordPress Trac ticket. The test is skipped if the ticket is still open — in these cases, we treat the test as a “known bug” that will likely fail. To see information about skipped and incomplete tests, use --verbose:

    
    $ phpunit --group shortcode
    
    Tests: 37, Assertions: 71, Skipped: 5.
    
    
    
    $ phpunit --group shortcode --verbose
    
    There were 5 skipped tests:
    
    
    
    1) Tests_Shortcode::test_tag_hyphen_not_tag
    
    WordPress Ticket 17657 is not fixed
    
    
    
    tests/includes/testcase.php:150
    
    tests/includes/testcase.php:130
    
    

    To forcibly run the skipped tests for an open ticket, you may specify that ticket as a group:

    
    $ phpunit --group 17657
    
    Tests: 2, Assertions: 3, Failures: 2.
    
    

    You may also combine groups:

    
    $ phpunit --group shortcode,17657,6562,14050
    
    Tests: 37, Assertions: 77, Failures: 5.
    
    

    To view all groups:

    
    $ phpunit --list-groups
    
    

    Writing Tests

    TODO. Go over basic test organization, files/classes/methods, WP_UnitTestCase, setUp, tearDown, rollback, factory methods. Link to list of assertions in the PHPUnit manual.

    Contributing Tests to WordPress

    There are three primary ways to contribute:

    Write tests for a reported bug. A great way to contribute is to write tests that demonstrate an existing bug report. The core developers are reluctant to consider patches for many sensitive areas in core without test coverage. Well-written tests can help confirm that a patch fixes a problem without side effects, and can prevent any regressions from occurring in the future. When tests are particularly needed or desired for a ticket to proceed, they receive the needs-unit-tests workflow keyword. You can submit tests for existing tickets directly on the WordPress core Trac. Bonus points for submitting a bug report with a test case included.

    Write new tests to improve our code coverage. Many areas of WordPress do not have adequate test coverage. Pick a function, class, or component and write tests for it. You can submit these tests on the Unit Tests Trac.

    Fix or improve our existing test cases. There are many opportunities for improvement in the existing tests. Some of them are ancient and others are slow or fragile. Some do not tests well in multisite or under certain conditions. Some individual tests try to test too much, and could be improved by using data providers, dependencies, and more narrow assertions.

    Additionally, More than 75 tests (linked to a few dozen different tickets) are currently considered to be known WordPress bugs and therefore skipped. (If you run phpunit --verbose, you can see the complete output.) Given enough test coverage, these tests can drive these bug fixes. You may find something you want to work on among the skipped tests.

    Further Reading

     
    • presspay 9:59 pm on April 26, 2013 Permalink | Log in to Reply

      Thanks for the documentation. I’m working on setting up a test environment but it looks like I’m having MySQL trouble. When I run phpunit, I’m getting the following error:

      $phpunit

      Error establishing a database connection

      This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

      Any tips on how to debug this?

      Thanks,

      Andrew

  • Helen Hou-Sandi 2:18 pm on July 17, 2012 Permalink | Log in to leave a Comment

    CSS Coding Standards 

    Like any coding standard, the purpose of the WordPress CSS Coding Standards is to create a baseline for collaboration and review within various aspects of the WordPress open source project and community, from core code to themes to plugins. Files within a project should appear as though created by a single entity. Above all else, create code that is readable, meaningful, consistent, and beautiful.

    Within core stylesheets, inconsistencies will often be found. We are working on addressing these and make every effort to have patches and commits from this point forward follow the CSS coding standards. More information on the above and contributing to UI/front-end development will be forthcoming in a separate set of guidelines.

    Structure

    There are plenty of different methods for structuring a stylesheet. With the CSS in core, it is important to retain a high degree of legibility. This enables subsequent contributors to have a clear understanding of the flow of the document.

    • Use tabs, not spaces, to indent each property.
    • Add two blank lines between sections and one blank line between blocks in a section.
    • Each selector should be on its own line, ending in either a comma or an opening curly brace. Property-value pairs should be on their own line, with one tab of indentation and an ending semicolon. The closing brace should be flush left, using the same level of indentation as the opening selector.

    Correct:

    
    #selector-1,
    
    #selector-2,
    
    #selector-3 {
    
         background: #fff;
    
         color: #000;
    
    }
    
    

    Incorrect:

    
    #selector-1, #selector-2, #selector-3 {
    
         background: #fff;
    
         color: #000;
    
         }
    
    
    
    #selector-1 { background: #fff; color: #000; }
    
    

    Selectors

    With specificity, comes great responsibility. Broad selectors allow us to be efficient, yet can have adverse consequences if not tested. Location-specific selectors can save us time, but will quickly lead to a cluttered stylesheet. Exercise your best judgement to create selectors that find the right balance between contributing to the overall style and layout of the DOM.

    • Similar to the WordPress Coding Standards for file names, use lowercase and separate words with hyphens when naming selectors. Avoid camelcase and underscores.
    • Use human readable selectors that describe what element(s) they style.
    • Attribute selectors should use double quotes around values
    • Refrain from using over-qualified selectors, div.container can simply be stated as .container

    Correct:

    
    #comment-form {
    
         margin: 1em 0;
    
    }
    
    
    
    input[type="text"] {
    
         line-height: 1.1;
    
    }
    
    

    Incorrect:

    
    #commentForm { /* Avoid camelcase. */
    
         margin: 0;
    
    }
    
    
    
    #comment_form { /* Avoid underscores. */
    
         margin: 0;
    
    }
    
    
    
    div#comment_form { /* Avoid over-qualification. */
    
         margin: 0;
    
    }
    
    
    
    #c1-xr { /* What is a c1-xr?! Use a better name. */
    
         margin: 0;
    
    }
    
    
    
    input[type=text] { /* Should be [type="text"] */
    
         line-height: 110% /* Also doubly incorrect */
    
    }
    
    
    
    

    Properties

    Similar to selectors, properties that are too specific will hinder the flexibility of the design. Less is more. Make sure you are not repeating styling or introducing fixed dimensions (when a fluid solution is more acceptable).

    • Properties should be followed by a colon and a space.
    • All properties and values should be lowercase, except for font names and vendor-specific properties.
    • Use hex code for colors, or rgba() if opacity is needed. Avoid RGB format and uppercase, and shorten values when possible: #fff instead of #FFFFFF.
    • Use shorthand (except when overriding styles) for background, border, font, list-style, margin, and padding values as much as possible. (For a shorthand reference, see CSS Shorthand.)

    Property Ordering

    “Group like properties together, especially if you have a lot of them.”

    – Nacin

    Above all else, choose something that is meaningful to you and semantic in some way. Random ordering is chaos, not poetry. In WordPress Core, our choice is logical or grouped ordering, wherein properties are grouped by meaning and ordered specifically within those groups. The properties within groups are also strategically ordered to create transitions between sections, such as background directly before color. The baseline for ordering is:

    • Display
    • Positioning
    • Box model
    • Colors and Typography
    • Other

    Things that are not yet used in core itself, such as CSS3 animations, may not have a prescribed place above but likely would fit into one of the above in a logical manner. Just as CSS is evolving, so our standards will evolve with it.

    Top/Right/Bottom/Left (TRBL/trouble) should be the order for any relevant properties (e.g. margin), much as the order goes in values. Corner specifiers (e.g. border-radius-*-*) should be top-left, top-right, bottom-right, bottom-left. This is derived from how shorthand values would be ordered.

    Another method that is often used, including by the Automattic/WordPress.com Themes Team, is to order properties alphabetically, with or without certain exceptions.

    Example:

    
    #overlay {
    
    	 position: absolute;
    
    	 z-index: 1;
    
    	 padding: 10px;
    
    	 background: #fff;
    
    	 color: #777;
    
    }
    
    

    Vendor Prefixes

    Vendor prefixes should go longest (-webkit-) to shortest (unprefixed). Values should be right aligned with spaces after the colon provided that all the values are the same across all prefixes.

    Preferred method:

    
    .koop-shiny {
    
         -webkit-box-shadow: inset 0 0 1px 1px #eee;
    
         -moz-box-shadow:    inset 0 0 1px 1px #eee;
    
         box-shadow:         inset 0 0 1px 1px #eee;
    
    
    
         -webkit-transition: border-color 0.1s;
    
         -moz-transition:    border-color 0.1s;
    
         -ms-transition:     border-color 0.1s;
    
         -o-transition:      border-color 0.1s;
    
         transition:         border-color 0.1s;
    
    }
    
    

    Not preferred:

    
    .okay {
    
         -webkit-box-shadow: inset 0 0 1px 1px #eee;
    
         -moz-box-shadow: inset 0 0 1px 1px #eee;
    
         box-shadow: inset 0 0 1px 1px #eee;
    
    }
    
    
    
    .bad {
    
         -webkit-box-shadow: inset 0 0 1px 1px #eee;
    
            -moz-box-shadow: inset 0 0 1px 1px #eee;
    
                 box-shadow: inset 0 0 1px 1px #eee;
    
    }
    
    

    Special case for CSS gradients:

    
    .gradient {
    
        background: #fff;
    
        background-image: -webkit-gradient(linear, left bottom, left top, from(#fff), to(#000));
    
        background-image: -webkit-linear-gradient(bottom, #fff, #000);
    
        background-image:    -moz-linear-gradient(bottom, #fff, #000);
    
        background-image:      -o-linear-gradient(bottom, #fff, #000);
    
        background-image: linear-gradient(to top, #fff, #000);
    
    }
    
    

    Values

    There are numerous ways to input values for properties. Follow the guidelines below to help us retain a high degree of consistency.

    • Space before the value, after the colon
    • Do not pad parentheses with spaces
    • Always end in a semicolon
    • Use double quotes rather than single quotes, and only when needed, such as when a font name has a space.
    • 0 values should not have units unless necessary, such as with transition-duration.
    • Line height should also be unit-less, unless necessary to be defined as a specific pixel value. This is more than just a style convention, but is worth mentioning here. More information: http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/
    • Use a leading zero for decimal values, including in rgba().
    • Multiple comma-separated values for one property should be separated by either a space or a newline, including within rgba(). Newlines should be used for lengthier multi-part values such as those for shorthand properties like box-shadow and text-shadow. Each subsequent value after the first should then be on a new line, indented to the same level as the selector and then spaced over to left-align with the previous value.

    Correct:

    
    .class { /* Correct usage of quotes */
    
         background-image: url(images/bg.png);
    
         font-family: "Helvetica Neue", sans-serif;
    
    }
    
    
    
    .class { /* Correct usage of zero values */
    
         font-family: Georgia, serif;
    
         text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5),
    
                      0 1px 0 #fff;
    
    }
    
    

    Incorrect:

    
    .class { /* Avoid missing space and semicolon */
    
         background:#fff
    
    }
    
    
    
    .class { /* Avoid adding a unit on a zero value */
    
         margin: 0px 0px 20px 0px;
    
    }
    
    

    Media Queries

    Media queries allow us to gracefully degrade the DOM for different screen sizes. If you are adding any, be sure to test above and below the break-point you are targeting.

    • It is generally advisable to keep media queries grouped by media at the bottom of the stylesheet.
      • An exception is made for the wp-admin.css file in core, as it is very large and each section essentially represents a stylesheet of its own. Media queries are therefore added at the bottom of sections as applicable.
    • Rule sets for media queries should be indented one level in.

    Example:

    
    @media all and (max-width: 699px) and (min-width: 520px) {
    
    
    
           /* Your selectors */
    
    
    
    }
    
    

    Commenting

    • Comment, and comment liberally. If there are concerns about file size, utilize minified files and the SCRIPT_DEBUG constant. Long comments should manually break the line length at 80 characters.
    • A table of contents should be utilized for longer stylesheets, especially those that are highly sectioned. Using an index number (1.0, 1.1, 2.0, etc.) aids in searching and jumping to a location.
    • Comments should be formatted much as PHPDoc is. The CSSDoc standard is not necessarily widely accepted or used but some aspects of it may be adopted over time. Section/subsection headers should have newlines before and after. Inline comments should not have empty newlines separating the comment from the item to which it relates.

    For sections and subsections:

    
    /**
    
    * #.# Section title
    
    *
    
    * Description of section, whether or not it has media queries, etc.
    
    */
    
    
    
    .selector {
    
         float: left;
    
    }
    
    

    For inline:

    
    /* This is a comment about this selector */
    
     .another-selector {
    
         position: absolute;
    
         top: 0 !important; /* I should explain why this is so !important */
    
    }
    
    

    Best Practices

    Stylesheets tend to get long in length. Focus slowly gets lost whilst intended goals start repeating and overlapping. Writing smart code from the outset helps us retain the overview whilst remaining flexible throughout change.

    • If you are attempting to fix an issue, attempt to remove code before adding more.
    • Magic Numbers are unlucky. These are numbers that are used as quick fixes on a one-off basis. Example: .box { margin-top: 37px }.
    • DOM will change over time, target the element you want to use as opposed to “finding it” through its parents. Example: Use .highlight on the element as opposed to .highlight a (where the selector is on the parent)
    • Know when to use the height property. It should be used when you are including outside elements (such as images). Otherwise use line-height for more flexibility.
    • Do not restate default property & value combinations (for instance display: block; on block-level elements).

    Related Links

     
    • Dwenaus 8:02 pm on July 30, 2012 Permalink | Log in to Reply

      wow, there is some really trippy CSS going on here:

      #selector-3 {

      background: #fff;

      color: #000;

      }

      then I realized it’s just auto-trac ticket replacement!

      • Andrew Nacin 10:04 pm on July 30, 2012 Permalink | Log in to Reply

        I went ahead and updated that plugin to only touch ticket numbers that were 4 or 5 characters long. Should avoid messing with 3- and 6-character color hex codes!

    • Lance Willett 8:42 pm on August 2, 2012 Permalink | Log in to Reply

      This is super cool.

      Once it’s finalized could you merge it with the pre-existing CSS Coding Standards on the Codex? I added that over 2 years ago and we’ve been using it for default themes since.

      Biggest differences are ordering of properties, comment format (standard on Codex is more strict), and the one line between rule blocks (no line in the Codex standard when in a grouping of similar rules).

    • Noel Tock 1:13 am on August 6, 2012 Permalink | Log in to Reply

      Updated!

    • Umbrovskis.com 4:32 pm on October 11, 2012 Permalink | Log in to Reply

      is there any reason to “Avoid underscores”? As far as I can find answers in Google, there is no reason, unless we care about very,very old browsers before 2002.

      If there is, please refer to some source!

    • wpcustom 3:04 am on November 8, 2012 Permalink | Log in to Reply

      Hi, Phil here, I’m doing my first review of a wp theme. The css will not validate after the second test. The 6 errors are below, can these be fixed? there are also 71 warnings(due to the 6 errors i suppose), also, does the css have to pass validation for a wp theme? Thanks wpcustom

      294 Unknown pseudo-element or pseudo-class ::-webkit-search-decoration [-webkit-search-decoration]

      297 Unknown pseudo-element or pseudo-class ::-moz-focus-inner [-moz-focus-inner]

      298 Unknown pseudo-element or pseudo-class ::-moz-focus-inner [-moz-focus-inner]

      382 .assistive-text Value Error : clip Invalid separator in shape definition. It must be a comma. : rect(1px 1px 1px 1px)

      674 .page-links a, .more-link Value Error : background-image linear-gradient(rgba(240,240,240,0.8),rgba(210,210,210,0.8)) is not a background-image value : linear-gradient(rgba(240,240,240,0.8),rgba(210,210,210,0.8))

      1176 .widget ul li Value Error : background-image linear-gradient(rgba(240,240,240,0.8),rgba(210,210,210,0.8)) is not a background-image value : linear-gradient(rgba(240,240,240,0.8),rgba(210,210,210,0.8))

    • suastex 12:46 pm on February 22, 2013 Permalink | Log in to Reply

      Hi! would it be worth it to incorporate something about shorthand?

      http://codex.wordpress.org/CSS_Shorthand

    • Ian Dunn 6:04 pm on March 9, 2013 Permalink | Log in to Reply

      The Selectors section says,

      “As in the WordPress Coding Standards [...] separate words with hyphens when naming selectors. Avoid [...] underscores.”

      But I think that conflicts with the WordPress Coding Standards article on the Codex. In the Naming Conventions section, it says, “Separate words via underscores”, and only mentions hyphens in the context of filenames.

      Is the general coding standards article only referring to PHP, and not HTML? It seems odd to me to use underscores in PHP, but hyphens in HTML/CSS, especially since there’s so much PHP and HTML intertwined in Core. You’d end up with lines of code that looked http://pastebin.com/iZ4tu9e6, where hyphens and underscores are mixed for the same piece of data.

      Since hyphens can’t be used in PHP variable names, would be better to standardize around always using underscores for PHP, HTML and CSS? Maybe it’s too late for that, though.

      • Helen Hou-Sandi 6:27 pm on March 9, 2013 Permalink | Log in to Reply

        CSS uses hyphens itself: font-size, border-width, etc. And yes, the other coding standards are referring to PHP.

        • Ian Dunn 7:44 pm on March 9, 2013 Permalink | Log in to Reply

          Ok, thanks for updating the wording in the Selectors section; it’s clearer now.

          Is there a WP naming convention for hyphens vs underscores in HTML? I couldn’t find any. I’m wondering what’s appropriate for the example I linked to above. I’m guessing hyphens in the id attribute (because it’ll be used as a CSS selector), but underscores in the name attribute (because it’ll be processed by PHP when the form is submitted) ?

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel