Skip to content

Instantly share code, notes, and snippets.

@cb99999
cb99999 / wp-add-users
Created July 14, 2014 13:27
Wordpress - add users
/*----------------------------
wordpress function to add
users to database programatically
-----------------------------*/
function fb_wp_insert_user() {
$user_data = array(
'ID' => '',
'user_pass' => wp_generate_password(),
'user_login' => 'dummy',
'user_nicename' => 'Dummy',
@cb99999
cb99999 / php-wordpress-autologin.php
Created November 6, 2013 19:04
php > auto login for wordpress users
// put in functions.php
function auto_login( $user ) {
$username = $user;
if ( !is_user_logged_in() ) {
$user = get_userdatabylogin( $username );
$user_id = $user->ID;
wp_set_current_user( $user_id, $user_login );
wp_set_auth_cookie( $user_id );
do_action( 'wp_login', $user_login );
@cb99999
cb99999 / jquery-clickable-div.js
Last active December 7, 2018 05:34
jquery -> make entire div a clickable link
<script>
jQuery(document).ready(function($) {
/*----------------------------
make entire div clickable
-----------------------------*/
$(".myBox").click(function(){
window.location=$(this).find("a").attr("href");
return false;
@cb99999
cb99999 / php-number-suffix.php
Created May 28, 2013 17:28
add th, st, nd to numbers
function ordinal($cdnl){
$test_c = abs($cdnl) % 10;
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th'
: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
? 'th' : 'st' : 'nd' : 'rd' : 'th'));
return $cdnl.$ext;
}
for($i=1;$i<100;$i++){
echo ordinal($i).'<br>';
}
@cb99999
cb99999 / php-clean-Input.php
Last active February 16, 2016 02:22
php -> clean input before a mysql insert
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
@cb99999
cb99999 / bs-tabs
Created May 3, 2013 15:11
bootstrap > template > tabs
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#1" data-toggle="tab">Section 1</a></li>
<li class=""><a href="#2" data-toggle="tab">Section 2</a></li>
<li class=""><a href="#3" data-toggle="tab">Section 3</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="1">
<p>You are watching section 1.</p>
</div><!-- /end tab1 -->
@cb99999
cb99999 / css-dynamic-font-size
Created May 3, 2013 14:59
css > dynamic font size
<style>
h1 {
font-size: 3.0vw;
}
p.lead {
font-size: 2.5vh;
}
p {
font-size: 2vmin;
}
@cb99999
cb99999 / jquery-dynamic-resizer
Created May 3, 2013 14:54
jquery > dynamic resizer script
<script>
$(document).ready(function(){
resizeDiv();
});
window.onresize = function(event) {
resizeDiv();
}
/**
@cb99999
cb99999 / php-current-URL
Created May 2, 2013 19:39
php > function: get current url
/*************************
/* function: get current url
/*************************/
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
@cb99999
cb99999 / php-copy-directories
Created May 2, 2013 19:37
php > copy target set of files to multiple directories
<?php
/*************************
/* copy master files to the farm
/*************************/
function full_copy( $source, $target )
{
if ( is_dir( $source ) ) {
@mkdir( $target ); $d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) ) {
if ( $entry == '.' || $entry == '..' ) { continue; }