<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[1271] sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer: developer.wordpress.org: Add usage examples for `add_menu_page()` and `register_post_type()` on dashicons page.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/1271">1271</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/1271","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coffee2code</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-02-17 21:33:10 +0000 (Tue, 17 Feb 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>developer.wordpress.org: Add usage examples for `add_menu_page()` and `register_post_type()` on dashicons page.
Fixes <a href="http://meta.trac.wordpress.org/ticket/758">#758</a>.
Props ryelle.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperjspagedashiconsjs">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/page-dashicons.js</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperpagedashiconsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/page-dashicons.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperscsspagedashiconsscss">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/page-dashicons.scss</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperstylesheetspagedashiconscss">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/page-dashicons.css</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperjspagedashiconsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/page-dashicons.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/page-dashicons.js 2015-02-17 19:38:34 UTC (rev 1270)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/page-dashicons.js 2015-02-17 21:33:10 UTC (rev 1271)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -37,11 +37,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var tmpl = wp.template( 'glyphs' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> jQuery( '#glyph' ).html( tmpl({
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- cssClass: cssClass,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ cssClass: 'dashicons-' + permalink,
</ins><span class="cx" style="display: block; padding: 0 10px"> attr: attr,
</span><span class="cx" style="display: block; padding: 0 10px"> html: htmltext,
</span><span class="cx" style="display: block; padding: 0 10px"> glyph: glyphtext
</span><span class="cx" style="display: block; padding: 0 10px"> }) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ jQuery( '#wp-class-example' ).text( permalink );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,7 +52,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> jQuery(document).ready(function() {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // pick random icon if no permalink, otherwise go to permalink
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( window.location.hash ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( window.location.hash && '#instructions' !== window.location.hash ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> permalink = "dashicons-" + window.location.hash.split('#')[1];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // sanitize
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperpagedashiconsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/page-dashicons.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/page-dashicons.php 2015-02-17 19:38:34 UTC (rev 1270)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/page-dashicons.php 2015-02-17 21:33:10 UTC (rev 1271)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -318,27 +318,80 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <div id="instructions">
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <h3><?php _e( 'Photoshop Usage', 'wporg' ); ?></h3>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <h3><?php _e( 'WordPress Usage', 'wporg' ); ?></h3>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <p><?php _e( 'Use the .OTF version of the font for Photoshop mockups, the web-font versions won\'t work. For most accurate results, pick the "Sharp" font smoothing.', 'wporg' ); ?></p>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <p><?php printf(
+ __( 'Admin menu items can be added with <code><a href="%s">register_post_type()</a></code> and <code><a href="%s">add_menu_page()</a></code>, which both have an option to set an icon. To show the current icon, you should pass in %s.', 'wporg' ),
+ 'https://developer.wordpress.org/reference/functions/register_post_type/',
+ 'https://developer.wordpress.org/reference/functions/add_menu_page/',
+ '<code>\'dashicons-<span id="wp-class-example">{icon}</span>\'</code>'
+ ); ?></p>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <h3><?php _e( 'CSS Usage', 'wporg' ); ?></h3>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <h4><?php _e( 'Examples', 'wporg' ); ?></h4>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <p><?php _e( 'Link the stylesheet:', 'wporg' ); ?></p>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <p><?php printf(
+ __( 'In <code><a href="">register_post_type()</a></code>, set <code>menu_icon</code> in the arguments array.', 'wporg' ),
+ 'https://developer.wordpress.org/reference/functions/register_post_type/'
+ ); ?></p>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <pre><link rel="stylesheet" href="css/dashicons.css"></pre>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<pre><?php
+add_action( 'init', 'create_post_type' );
+//Registers the Product's post type
+function create_post_type() {
+ register_post_type( 'acme_product',
+ array(
+ 'labels' => array(
+ 'name' => __( 'Products' ),
+ 'singular_name' => __( 'Product' )
+ ),
+ 'public' => true,
+ 'has_archive' => true,
+ 'menu_icon' => 'dashicons-products',
+ )
+ );
+}
+</pre>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <p><?php printf( __( 'Now add the icons using the %s selector. You can insert the Star icon like this:', 'wporg' ), '<code>:before</code>' ); ?></p>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <p><?php printf(
+ __( 'The function <code><a href="%s">add_menu_page()</a></code> accepts a parameter after the callback function for an icon URL, which can also accept a dashicons class.', 'wporg' ),
+ 'https://developer.wordpress.org/reference/functions/add_menu_page/'
+ ); ?></p>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<textarea class="code" onclick="select();">
-.myicon:before {
- content: "\f155";
- display: inline-block;
- -webkit-font-smoothing: antialiased;
- font: normal 20px/1 'dashicons';
- vertical-align: top;
-}</textarea>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<pre><?php
+function add_my_custom_menu() {
+ //add an item to the menu
+ add_menu_page (
+ 'My Page',
+ 'My Title',
+ 'manage_options',
+ 'my-page',
+ 'my_admin_page_function',
+ 'dashicons-admin-media',
+ );
+}</pre>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <h3><?php _e( 'CSS/HTML Usage', 'wporg' ); ?></h3>
+
+ <p><?php _e( "If you want to use dashicons in the admin outside of the menu, there are two helper classes you can use. These are <code>dashicons-before</code> and <code>dashicons</code>, and they can be thought of as setting up dashicons (since you still need your icon's class, too).", 'wporg' ); ?></p>
+
+ <h4><?php _e( 'Examples', 'wporg' ); ?></h4>
+
+ <p><?php _e( 'Adding an icon to a header, with the <code>dashicons-before</code> class. This can be added right to the element with text.', 'wporg' ); ?></p>
+
+<pre>
+<h2 class="dashicons-before dashicons-smiley"><?php _e( 'A Cheerful Headline', 'wporg' ); ?></h2>
+</pre>
+
+ <p><?php _e( 'Adding an icon to a header, with the <code>dashicons</code> class. Note that here, you need extra markup specifically for the icon.', 'wporg' ); ?></p>
+
+<pre>
+<h2><span class="dashicons dashicons-smiley"></span> <?php _e( 'A Cheerful Headline', 'wporg' ); ?></h2>
+</pre>
+
+ <h3><?php _e( 'Photoshop Usage', 'wporg' ); ?></h3>
+
+ <p><?php _e( 'Use the .OTF version of the font for Photoshop mockups, the web-font versions won\'t work. For most accurate results, pick the "Sharp" font smoothing.', 'wporg' ); ?></p>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> </div><!-- /#instructions -->
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> </main><!-- #main -->
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -349,7 +402,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <script type="text/html" id="tmpl-glyphs">
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="dashicons {{data.cssClass}}"></div>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="info">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <span class="name">← {{data.cssClass}}</span>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <span class="name"><code>{{data.cssClass}}</code></span>
</ins><span class="cx" style="display: block; padding: 0 10px"> <span class="link"><a href='javascript:dashicons.copy( "content: \"\\{{data.attr}}\";", "css" )'><?php _e( 'Copy CSS', 'wporg' ); ?></a></span>
</span><span class="cx" style="display: block; padding: 0 10px"> <span class="link"><a href="javascript:dashicons.copy( '{{data.html}}', 'html' )"><?php _e( 'Copy HTML', 'wporg' ); ?></a></span>
</span><span class="cx" style="display: block; padding: 0 10px"> <span class="link"><a href="javascript:dashicons.copy( '{{data.glyph}}' )"><?php _e( 'Copy Glyph', 'wporg' ); ?></a></span>
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperscsspagedashiconsscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/page-dashicons.scss</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/page-dashicons.scss 2015-02-17 19:38:34 UTC (rev 1270)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/page-dashicons.scss 2015-02-17 21:33:10 UTC (rev 1271)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -133,6 +133,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> h3 {
</span><span class="cx" style="display: block; padding: 0 10px"> margin: 1.5em 0 0.75em;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ h4 {
+ margin-top: 0;
+ padding-top: 0;
+ border-top: none;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> .code {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperstylesheetspagedashiconscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/page-dashicons.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/page-dashicons.css 2015-02-17 19:38:34 UTC (rev 1270)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/page-dashicons.css 2015-02-17 21:33:10 UTC (rev 1271)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -111,6 +111,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> .dashicons-page #instructions h3 {
</span><span class="cx" style="display: block; padding: 0 10px"> margin: 1.5em 0 0.75em;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.dashicons-page #instructions h4 {
+ margin-top: 0;
+ padding-top: 0;
+ border-top: none;
+}
</ins><span class="cx" style="display: block; padding: 0 10px"> .dashicons-page .code {
</span><span class="cx" style="display: block; padding: 0 10px"> display: block;
</span><span class="cx" style="display: block; padding: 0 10px"> font: 14px/1.5 monospace;
</span></span></pre>
</div>
</div>
</body>
</html>