Skip to content

Instantly share code, notes, and snippets.

View Pleiades's full-sized avatar

Nicholas R. Batik Pleiades

  • Pleiades Publishing Services, Co.
  • Austin, TX
View GitHub Profile
@Pleiades
Pleiades / starts-with-ends-with.php
Created May 5, 2019 00:05
Take a string and return if it starts with the specified character/string or ends with it
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
@Pleiades
Pleiades / custom-icon-lib.php
Created May 4, 2019 22:44
Change the default icon directory in WordPress
/*
* Replaces the default media-type icon library in wp-includes/images/crystal with wp-content/themes/{theme-name}/images/
* WordPress default media types include archive, audio, code, document, interactive, spreadsheet, text, and video.
*
*/
add_filter( 'icon_dir', 'wpdocs_theme_icon_directory' );
add_filter( 'icon_dir_uri', 'wpdocs_theme_icon_uri' );
/*
* Return my desired icon directory
@Pleiades
Pleiades / PODS Package Migration
Created November 1, 2017 23:49
Austin Wordcamp 2017
{
"meta":{
"version":"2.6.11",
"build":1509578938
},
"pods":{
"527":{
"id":527,
"name":"credit_card",
"label":"Credit Cards",
@Pleiades
Pleiades / gist:b9711273719a401d52f3
Created August 26, 2014 22:09
Sample WordPress Action and Filter Hooks
Code Samples for Hooks And Filters Class
<?php
/* Filter the title to add a page number if necessary.
------------------------------------------------------------------------------------ */
add_filter( 'wp_title', 'page_numbered_wp_title', 10, 2 );
function page_numbered_wp_title( $title, $sep ) {
@Pleiades
Pleiades / ppsc_array_sort.php
Created November 19, 2012 22:22
Sort an Array by Key
<?php
function ppsc_array_sort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
asort($sorter);
foreach ($sorter as $ii => $va) {
@Pleiades
Pleiades / twittersharebutton.php
Created November 15, 2012 23:35
Twitter Share button
function twitter( $atts, $content=null ){
/* Author: Nicholas P. Iler
* URL: http://www.ilertech.com/2011/07/add-twitter-share-button-to-wordpress-3-0-with-a-simple-shortcode/
*/
extract(shortcode_atts(array(
'url' => null,
'counturl' => null,
'via' => '',
'text' => '',
'related' => '',
@Pleiades
Pleiades / showblogstatistics.php
Created November 15, 2012 23:23
Show Blog Statistics
add_shortcode('wcs_count', 'wcs_count_shortcode_handler');
function wcs_count_shortcode_handler($atts)
{
// extract parameters
$parms = shortcode_atts(array(
'type' => 'posts',
'format' => 'true',
'extra' => '1',
), $atts);
$type = strtolower($parms['type']);
@Pleiades
Pleiades / obfucateemailaddress.php
Created November 15, 2012 23:10
Obfuscate an Email Address
function munge_mail_shortcode( $atts , $content=null ) {
for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';';
return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>';
}
add_shortcode('mailto', 'munge_mail_shortcode');
@Pleiades
Pleiades / executeshortcodesinsidecustomfields.php
Created November 15, 2012 23:03
How to execute shortcodes inside custom fields
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?>
@Pleiades
Pleiades / googledocsviewer.php
Created November 15, 2012 22:55
Google Docs Viewer
function pdflink($attr, $content) {
if ($attr['href']) {
return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
} else {
$src = str_replace("=", "", $attr[0]);
return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $src . '">'.$content.'</a>';
}
}
add_shortcode('pdf', 'pdflink');