Skip to content

Instantly share code, notes, and snippets.

View jeffikus's full-sized avatar
💻
Themes at Automattic.com

Jeffrey Pearce jeffikus

💻
Themes at Automattic.com
View GitHub Profile
@jeffikus
jeffikus / sensei-admin-access.php
Created January 31, 2013 09:48
Prevent Sensei Admin Access
add_action('admin_init', 'sensei_prevent_admin_access');
function sensei_prevent_admin_access() {
if ( ! is_ajax() && ! current_user_can('edit_posts') ) {
global $woothemes_sensei;
wp_safe_redirect(get_permalink(intval( $woothemes_sensei->settings->settings[ 'course_page' ] )));
exit;
}
}
@jeffikus
jeffikus / htmlentitiesjs.js
Created February 11, 2013 09:55
HTMLEntities JS
/**
* JS version of PHP htmlentities.
*
* @since 1.0.8
* @access public
*/
jQuery.fn.htmlentities = function( str ) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
@jeffikus
jeffikus / pagination.hbs
Created September 20, 2013 13:13
Ghost Custom Pagination Partial
<nav>
{{#if pagination.prev}}<a class="prev" href="/page/{{pagination.prev}}" title="Previous">Previous</a>{{/if}}
{{#if pagination.next}}<a class="next" href="/page/{{pagination.next}}" title="Next">Next</a>{{/if}}
</nav>
@jeffikus
jeffikus / gist:6931237
Created October 11, 2013 08:05
Sensei Lessons Archive sort by Menu Order
/**
* sensei_filter_lessons_archive function.
* @access public
* @param mixed $wp_query
* @return void
*/
function sensei_filter_lessons_archive( $wp_query ) {
// Handle lesson archive page
if ( is_post_type_archive( 'lesson' ) ) {
@jeffikus
jeffikus / gist:7114667
Created October 23, 2013 08:25
Filter WordPress Registration URL
add_filter('register', 'my_custom_registration_link');
function my_custom_registration_link($link) {
if(!is_user_logged_in()) {
// In this example there is a page with slug 'register' so the url would be http://mysite.com/register
$link = '<div class="status register"><a href="' . site_url('register') . '">' . __('Register') . '</a></div>';
}
return $link;
} // End my_custom_registration_link()
@jeffikus
jeffikus / gist:9342341
Created March 4, 2014 08:22
Modify Features Post Type to only allow publicly queryable posts, but disable archive and single feature posts
add_action( 'init', 'modify_existing_post_type', 50 );
/**
* Modify Existing post type.
*
* @access public
* @param string $token
* @param string 'Features'
* @param string 'Features'
* @param array $supports
* @return void
@jeffikus
jeffikus / gist:b18a7d32736bc76e8609
Created July 18, 2014 14:42
Fix for deprecated function - get_theme_data() with wp_get_theme()
add_action( 'after_setup_theme', 'woothemes_setup' );
if ( ! function_exists( 'woothemes_setup' ) ) {
function woothemes_setup () {
// This theme styles the visual editor with editor-style.css to match the theme style.
if ( locate_template( 'editor-style.css' ) != '' ) { add_editor_style(); }
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
@jeffikus
jeffikus / gist:37dc918cecc9f5a5ecfa
Created September 15, 2014 12:37
For the Cause image slider full height - before
$style = '';
$featured_height = '';
if ( '' != $image_bg ) {
if ( '' == $title && '' == $content && '' == $embed ) {
$featured_height_id = get_post_thumbnail_id();
$featured_height = wp_get_attachment_image_src( $featured_height_id, 'large' );
$featured_height = ' height: ' . $featured_height[ 2 ] . 'px;';
}
$style = ' style="background-size: cover; background-image: url(' . $image_bg . ');' . $featured_height . '"';
}
@jeffikus
jeffikus / gist:8661b9872dad343ac108
Last active August 29, 2015 14:06
For the Cause image slider full height - after
$style = '';
$featured_height = '';
if ( '' != $image_bg ) {
$featured_height_id = get_post_thumbnail_id();
$featured_height = wp_get_attachment_image_src( $featured_height_id, 'large' );
$featured_height = ' height: ' . $featured_height[ 2 ] . 'px;';
$style = ' style="background-size: cover; background-image: url(' . $image_bg . ');' . $featured_height . '"';
}
@jeffikus
jeffikus / gist:87b31c77cccbb89fcaa1
Created October 1, 2014 22:21
SQL Injection example 1
<?php
global $wpdb;
$ID = $_GET['ID'];
$sql = "SELECT post_title from $wpdb->posts WHERE ID = '$ID';";
?>