Blog

  • Media Upload

    audio-player.php

    add_filter("attachment_fields_to_edit", array(&$this, "insertAudioPlayerButton"), 10, 2);
    			add_filter("media_send_to_editor", array(&$this, "sendToEditor"));
    
    		/**
    		 * Inserts Audio Player button into media library popup
    		 * @return the amended form_fields structure
    		 * @param $form_fields Object
    		 * @param $post Object
    		 */
    		function insertAudioPlayerButton($form_fields, $post) {
    			global $wp_version;
    			
    			$file = wp_get_attachment_url($post->ID);
    			
    			// Only add the extra button if the attachment is an mp3 file
    			if ($post->post_mime_type == 'audio/mpeg') {
    				$form_fields["url"]["html"] .= "<button type='button' class='button urlaudioplayer audio-player-" . $post->ID . "' value='[audio:" . attribute_escape($file) . "]' title='[audio:" . attribute_escape($file) . "]'>Audio Player</button>";
    				
    				if (version_compare($wp_version, "2.7", "<")) {
    					$form_fields["url"]["html"] .= "<script type='text/javascript'>
    					jQuery('button.audio-player-" . $post->ID . "').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
    					</script>\n";
    				}
    			}
    			
    			return $form_fields;
    		}
    
    		/**
    		 * Format the html inserted when the Audio Player button is used
    		 * @param $html String
    		 * @return String 
    		 */
    		function sendToEditor($html) {
    			if (preg_match("/<a ([^=]+=['\"][^\"']+['\"] )*href=['\"](\[audio:([^\"']+\.mp3)])['\"]( [^=]+=['\"][^\"']+['\"])*>([^<]*)<\/a>/i", $html, $matches)) {
    				$html = $matches[2];
    				if (strlen($matches[5]) > 0) {
    					$html = preg_replace("/]$/i", "|titles=" . $matches[5] . "]", $html);
    				}
    			}
    			return $html;
    		}
    
  • CSS

    Force CSS changes to “live” immediately | Mark on WordPress

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />
    
  • P2 Theme

    add title and edit link (dashboard edit) to lists and single post:
    inc/entry.php, ln 26

    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    

    inc/entry.php, ln 51

    				if ( current_user_can( 'edit_post', get_the_ID() ) ) : ?> | <a href="<?php echo ( get_edit_post_link( get_the_ID() ) ); ?>" class="edit-post-link" rel="<?php the_ID(); ?>"><?php _e( 'Edit', 'p2' ); ?></a> <?php edit_post_link('[edit2]', '| <span style="font:italic 12px serif;">', '</span>'); ?>
    

    (XXX not working yet) prevent new title when using front-end edit:
    functions.php, ln 222:

    function p2_the_title( $before = '&lt;h2&gt;', $after = '&lt;/h2&gt;', $echo = true ) {
    	global $post;
    if ( ! $post-&gt;post_title ) :
    

    front-end editor seems to be visual: messes up code.

  • Slugs

    https://dev.pubmedia.us/slug/ ‎

    example.com/slugname

    Page slug: cpthi, child of p
    https://dev.pubmedia.us/cpthi/testing-2/

    Page slug:
    cpthi=testing-2&post_type=cpthi&name=testing-2

    finds directory in root named: /slugname
    finds CPT slug (post_type or rewrite>slug) defined as: slugname
    finds permalink category base option set to be: slugname
    finds template in active theme file named: page-slugname.php
    finds Page w/ slug (Post_name): “slug-name”
    %postname%

    refresh permalinks
    retention after name change.

    ?finds CPT (hier and non-hi?) w/ slug: “slug-name”
    ?finds category base w/ slug: “slug-name”

    https://dev.pubmedia.us/testing/testing/ finds category-base/
    category_name=testing-2%2Ftesting

    pagename=cpthi

    may depend on which is created first, aka, some remnant of redirect.

    Unique Slug Name

    taxonomy.php in tags/3.3/wp-includes – WordPress Trac

    http://core.trac.wordpress.org/browser/tags/3.3/wp-includes/taxonomy.php#L2175

    Function Reference/wp unique post slug « WordPress Codex

    wp_insert_post()
    wp_insert_attachment()
    calls wp_unique_post_slug()
    $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);

    wp_unique_post_slug() /wp-includes/post.php
    wp_term_post_slug() /wp-includes/taxonomy.php

    http://www.bernzilla.com/item.php?id=1007

    gastropod mollusc

    Function_Reference/sanitize_title_with_dashes
    wp/includes/formatting.php:855: function sanitize_title_with_dashes

    https://dev.pubmedia.us/testing/

    wp_unique_post_slug()
    http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/post.php.source.html#l2779

    wp_unique_term_slug()
    http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/post.php.source.html#l2779

    User:Amereservant/Editing and Customizing htaccess Indirectly « WordPress Codex

    [wp-testers] WordPress scaling problems

    Class Reference/WP Rewrite « WordPress Codex

    How the Postname Permalinks in WordPress 3.3 Work » Otto on WordPress

    http://codex.wordpress.org/Query_Overview

    Function_Reference/wp_parse_args
    /wp-includes/functions.php

    in wp-includes/theme.php
    bunch of theme files camparisons to
    Function_Reference/get_queried_object
    /wp-includes/query.php.

    /wp-includes/rewrite.php
    builds global $wp_rewrite;

    load up array in:
    locate_template()
    wp-includes/theme.php

    wp-includes/link-template.php

    Query_Overview
    wp-includes/classes.php
    parse_request()

    Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request

    ie, on a wp_insert_post() WP will accurately return the results of wp_unique_post_slug() as the “Permalink:” URL on the Page Edit screen (and store it as ___ in the db). but whether that URL will find the page has nada to do w/ either of those functions.

    some retention of some of these values for redirects even after the value changed.

    once the top-level match is found, next level don’t affect query.

    tag base

    http://lists.automattic.com/pipermail/wp-testers/2009-January/011099.html

    /%category%/%postname%/
    /{category_base}/{term_id}/
    whether plugins can affect

    give users the tools to make good choices in naming slugs and defining permalink structure, and to eval what might have gone astray when they get 404s.

    How to change your WordPress Permalink Structure • Yoast

  • Search

    Site-specific Google Search:

    <form method="get" action="http://www.google.com/search">
    <input type="text"   name="q" size="25" maxlength="255" value="" /><br />
    <input type="radio" name="sitesearch" value="http://codex.wordpress.org/" checked /><a href="http://codex.wordpress.org/ title="codex.wordpress.org">WordPress Docs</a><br />
    <input type="radio" name="sitesearch" value="http://wordpress.org/support/" /><a href="http://wordpress.org/support/" title="wordpress.org/support">WordPress Forums</a><br />
    <input type="radio" name="sitesearch" value="http://wordpress.org/extend/plugins/" /><a href="http://wordpress.org/extend/plugins/" title="wordpress.org/extend/plugins">WordPress Plugins</a><br />
    <input type="radio" name="sitesearch" value="http://phpxref.ftwr.co.uk/wordpress/" /><a href="http://phpxref.ftwr.co.uk/wordpress/" title="phpxref.ftwr.co.uk/wordpress">WordPress phpxref</a><br />
    <input type="radio" name="sitesearch" value="http://php.net/" /><a href="http://php.net/" title="php.net">PHP Manual</a><br />
    <input type="radio" name="sitesearch" value="https://dev.pubmedia.us/" /><a href="Dev.Pubmedia.us" title="php.net">Dev.Pubmedia</a><br />
    <input type="submit" value="Google Search" />
    </form>
    
  • Dreamweaver, WordPress, MAMP, VirtualHostX

    VirtualHostX – Mac OS X Apache Virtual Hosting
    http://clickontyler.com/virtualhostx/

    MAMP: Mac, Apache, MySQL, PHP
    http://www.mamp.info/en/index.html

    Mac web development made easy – Bitbob
    http://bitbob.com/mac-web-development-made-easy

    Editing a WordPress theme with Dreamweaver CS5 – Part 1: Learning the basics | Adobe Developer Connection
    http://www.adobe.com/devnet/dreamweaver/articles/dw_wordpress_pt1.html

    “#2006 – MySQL server has gone away”
    ..\MAMP\bin\startMysql.sh” start up batch file. Add the option ” –max_allowed_packet=268435456″
    http://forum.mamp.info/viewtopic.php?f=2&t=14115#p28568

  • Performance

    Bottom of page testing info:

    <!-- (<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds uses <?php echo round(memory_get_peak_usage() / 1024 / 1024, 3); ?>MB peak memory -->
    

    Or:

    <!--
    (<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?>  seconds)
    =TEMPLATE: <?php echo $GLOBALS['pagenow']; ?>
    -->
    

    Or:

    <?php echo '<p>' . get_num_queries() . ' queries in ' . timer_stop() . ' seconds uses ' . round( memory_get_peak_usage() / 1024 / 1024, 3 ) . ' MB peak memory.</p>'; ?>
    

    http://webpagetest.org

    https://developers.google.com/speed/pagespeed/insights/