Skip to content

Instantly share code, notes, and snippets.

@amielucha
amielucha / iseek-permissions.php
Created November 24, 2015 10:51
WordPress Editor User Permissions
// get the the role object
$role_object = get_role( 'editor' );
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );
@amielucha
amielucha / translate-string-in-functions.php
Created November 24, 2015 16:57
WordPress translate a string
// Translate a string in functions.php
function translate_buy($translated) {
$translated = str_ireplace('Place order', 'Buy it now!', $translated);
return $translated;
}
add_filter('gettext', 'translate_buy');
add_filter('ngettext', 'translate_buy');
@amielucha
amielucha / svg-in-css.scss
Last active May 3, 2016 14:48
Embed SVG in CSS
/* Line breaks work as long as you escape them; use %23 instead of # inside of the svg */
.image {
position: absolute;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml;utf-8, \
<svg width="300px" height="300px" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">\
<g stroke-width="4" stroke="%23eaeae1" fill="%23fff"> \
<polygon points="150 205 85.3436222 238.991869 97.6918916 166.995935 45.3837832 116.008131 117.671811 105.504065 150 40 182.328189 105.504065 254.616217 116.008131 202.308108 166.995935 214.656378 238.991869 "></polygon>\
</g>\
@amielucha
amielucha / activate-fitvids.js
Created January 7, 2016 12:39
fitVids activation script
jQuery(document).ready(function($) {
// Run fitVids if it's available
if ( $.isFunction($.fn.fitVids) )
$(".entry-content").fitVids();
});
@amielucha
amielucha / types-api-get-field.php
Created January 12, 2016 12:33
WordPress Types field retrieval
<?php
// Get fields
if ( function_exists( 'types_render_field' ) ){
$address = types_render_field("address", array("output"=>"html"));
}
// Echo fields
if ($address) echo $address;
@amielucha
amielucha / wp-types-get-field.php
Created February 6, 2016 22:49
WordPress Types plugin: retrieve fields in theme files and suppress filters (Jetpack compatibility fix)
<?php
// Retrieve a WYSIWYG Types plugin field
// and suppress third-party filters
// (useful when working with Jetpack Sharedaddy)
$field = types_render_field("fieldname", array("output"=>"html", "suppress_filters"=>"true"));
@amielucha
amielucha / jquery-color-bullet-lists.js
Created February 12, 2016 12:23
Add html tags to allow styling list bullets
// Append classes to color the lists
$('.hentry ul').addClass('list-colored').children().wrapInner('<span class="li-inner">');
@amielucha
amielucha / toolkit-access-check-user-access.php
Last active April 28, 2016 15:58
Get the Toolkit Access group assigned to a post within a loop and verify if currently logged-in user has permissions to access the list.
<?php
// -----------------------------------------------------------------------------
// Usage: place the function in functions.php
// Then call it from within the loop in the theme index.php, single.php etc.
// while ( have_posts() ) : the_post(); if (iseek_user_access() ):
// ... secret content goes here
// endif;
// -----------------------------------------------------------------------------
@amielucha
amielucha / is_tree.php
Last active May 30, 2016 10:55
WordPress is_tree()
<?php
//usage: place in functions.php
// has a certain page in ID
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
if( is_page() && ( $post->post_parent == $pid || is_page( $pid ) || get_topmost_parent( $post->ID ) == $pid ) ) return true;
else return false; // we're elsewhere
}
@amielucha
amielucha / wp_translate_text.php
Created July 25, 2016 13:49
WordPress - translate a single string
<?php
// place in functions.php
add_filter('gettext', 'lightseek_translate_text');
add_filter('ngettext', 'lightseek_translate_text');
function lightseek_translate_text($translated) {
$translated = str_ireplace('Old String', 'New String', $translated);
return $translated;
}