Skip to content

Instantly share code, notes, and snippets.

View scarstens's full-sized avatar
🌟
Automating workflows.

Seth Carstens scarstens

🌟
Automating workflows.
View GitHub Profile
@scarstens
scarstens / wordpress.require.login.php
Created September 23, 2013 02:39
Force user to login before accessing the site (on WordPress)
//force user login, regardless of post type
//UNLESS public is in the URL
add_action('parse_request', 'rr_login_redirect');
function rr_login_redirect() {
global $wp;
if(stristr($wp->request,'public/') || stristr($wp->request,'/public')){}
elseif (!is_user_logged_in()) {
auth_redirect();
}
}
@scarstens
scarstens / functions.admin_private_parent.inc.php
Last active December 22, 2015 00:58
Function / Action to enable choosing private pages as parent pages
<?php
/*
* Function / Action to enable choosing private pages as parent pages
*/
function admin_private_parent_metabox($output)
{
global $post;
$args = array(
'post_type' => $post->post_type,
@scarstens
scarstens / sort-array-of-objects.js
Created July 15, 2013 20:45
Sort array of objects by a property in each object
function sortObjectBy(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1, property.length - 1);
}
return function (a,b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
@scarstens
scarstens / get-base-website-url.js
Created July 15, 2013 20:20
javascript function that return the main URL
function get_base_website_url() {
if (!window.location.origin)
return window.location.origin = window.location.protocol+"//"+window.location.host;
else
return window.location.origin;
}
@scarstens
scarstens / gmail.sig.sidebyside.html
Created June 12, 2013 22:42
Google Mail Side by Side Signature and Logo
<table border="0" cellpadding="0" cellspacing="0" width="400">
<tbody>
<tr height="10">
<td height="10" colspan="2"><hr style="height: 1px; border: 0; border-bottom: 1px dashed #ccc; padding: 0; margin: 12px 0 5px 0;" /></td>
</tr>
<tr style="vertical-align: middle;" height="100">
<td height="100" width="250" style="border-right: 1px dashed #ccc;"><strong>Seth Carstens</strong><br>
Rapid Recovery<br>
<a href="tel:8773727732">877-372-7732</a> office<br>
<a href="tel:4802033753">480-203-3753</a> cell<br>
<apex:page standardStylesheets="false" showHeader="false" sidebar="false">
<apex:stylesheet value="{!URLFOR($Resource.WorkBookStyles, 'styles.css')}" />
@scarstens
scarstens / jquery-trigger-event-every-x-seconds.js
Created May 16, 2013 21:10
Use jquery to trigger an event every XX amount of seconds. In this example we will trigger the click event on the "increment" ID.
/* WE ARE ASSUMING JQUERY IS LOADED AND USING jQuery instead of $ */
jQuery(document).ready(function($) {
window.setInterval(function(){
/// call your function here
$('#increment').trigger('click');
}, 5000);
});
/*
@scarstens
scarstens / php-class-file-based-password-encryption.example.php
Last active December 16, 2015 17:29
This is the example I built while learning how to properly protect password before they are stored in the database. While hashing passwords is safer, some passwords are used for "3rd party tools" and therefore can't be hashed because they need to be "unencrypted" and sent to the 3rd party service. In my case, we were building an connector betwee…
<?php
//This example encrypts and decrypts a password
//it is a good use case for a "php class file" because the __FILE__ is constant for the key
//*additional security can be added by storing or defining a unique key per website
//using __FILE__ exmaple for class files
$pass = 'samplepassword123!';
echo 'Password: '.$pass.'<br />';
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, sha1(basename(__FILE__), TRUE), $pass, MCRYPT_MODE_ECB);
echo 'Encrypted Pass: '.$encrypted.'<br />';
@scarstens
scarstens / wordpress.enable_child_page_templates.php
Last active December 16, 2015 14:28
This is a WordPress function that will extend the "template heirarchy" so that you can also load child pages in your theme using the following syntax: page-{PARENTSLUG}-child-{CHILDSLUG}.php
<?php
//apparently no need for this... page-SLUG.php matches subpage slugs,
//only need this function if subpage slug conflicts occur
//Add this code to you themes functions.php file, or some other file.
//Next create your child page lets says "domain.com/resources/faq"
//Finally, create the php template page following the naming schema:
//page-PARENTSLUG-child-CHILDSLUG.php -> page-resources-child-faq.php
add_filter( 'page_template', 'enable_child_page_templates' );
function enable_child_page_templates( $page_template ){
@scarstens
scarstens / wpfilebase.metasetter.jquery.js
Created April 2, 2013 23:09
Jquery code to use in chrome conolse to automaticly assign and submit a category and meta data selection to wpfilebase plugin since there is no bulk update tool.
jQuery('#file_category').val(4); jQuery('#file_languages\\[\\]').val('en'); jQuery('#file_requirements\\[\\]').val('pdfread');jQuery('#updatefile').submit();