Skip to content

Instantly share code, notes, and snippets.

View psorensen's full-sized avatar

Peter Sorensen psorensen

  • 10up
  • United States
View GitHub Profile
<?php
/*
* Converts CSV to JSON
* Example uses Google Spreadsheet CSV feed
* csvToArray function I think I found on php.net
*/
header('Content-type: application/json');
// Set your CSV feed
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
add_action('pmxi_attachment_uploaded', 'my_attachment_uploaded', 10, 3);
function my_attachment_uploaded($pid, $attid, $filepath){
$attachment = get_post($attid);
// do something with $attachment file
if (get_post($pid) == 'industry-resource') {
wp_update_post(array('ID' => $attid, 'guid' => str_replace('uploads/', 'uploads/indres/', $filepath)));
}
}
@psorensen
psorensen / Yoast_SEO_JS_fix
Created February 13, 2015 14:36
Yoast SEO JS Fix
function yst_clean(a){if(""==a||void 0==a)return"";try{a=jQuery("<div/>").html(a).text(),a=a.replace(/<\/?[^>]+>/gi,""),a=a.replace(/\[(.+?)\](.+?\[\/\\1\])?/g,"")}catch(b){}return a}function ptest(a,b){a=yst_clean(a),a=a.toLowerCase();var c=a.match(b);return null!=c?'<span class="good">Yes ('+c.length+")</span>":'<span class="wrong">No</span>'}function removeLowerCaseDiacritics(a){var b,c=[{base:"a",letters:/[\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250]/g},{base:"aa",letters:/[\uA733]/g},{base:"ae",letters:/[\u00E6\u01FD\u01E3]/g},{base:"ao",letters:/[\uA735]/g},{base:"au",letters:/[\uA737]/g},{base:"av",letters:/[\uA739\uA73B]/g},{base:"ay",letters:/[\uA73D]/g},{base:"b",letters:/[\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253]/g},{base:"c",letters:/[\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184]/g},{ba
<style>.om-feed-container{width: 100%;max-width: 300px;background: #dfdfdf;font-family: arial;float: left;}.om-feed-header{background: #505050;color: white;padding: 10px;clear: both;}.om-feed-header img, .om-feed-header h4{float: left;}.clear:after{clear: both; content: ""; display: table;}ul#feed{width: 100%;display: block;padding-left: 0;padding: 10px;/*margin-left: 0;*/}ul#feed li{list-style: none;margin-bottom: 10px;}ul#feed li a{color: #3d8180;font-size: 12px;}.gist{max-width: 600px;float: left;margin-left: 50px;}</style> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript">google.load("feeds", "1"); function initialize(){var feed=new google.feeds.Feed("https://www.openminds.com/market/child-welfare/feed/"); feed.setNumEntries(6); feed.load(function(result){if (!result.error){var container=document.getElementById("feed"); for (var i=0; i < result.feed.entries.length; i++){var entry=result.feed.entries[i]; var li=document.createElement("li"); var a=doc
@psorensen
psorensen / om_feed
Last active August 29, 2015 14:16
OPEN MINDS Child Welfare Feed
<style>.om-feed-container{width:100%;max-width:300px;background:#dfdfdf;font-family:arial;float:left}.om-feed-header{background:#505050;color:#fff;padding:10px;clear:both}.om-feed-header h4,.om-feed-header img{float:left}.clear:after{clear:both;content:"";display:table}ul#feed{width:100%;display:block;padding-left:0;padding:10px;box-sizing:border-box}ul#feed li{list-style:none;margin-bottom:10px}ul#feed li a{color:#3d8180;font-size:12px}</style><script type="text/javascript" src="https://www.google.com/jsapi"></script><script type="text/javascript">function initialize(){var e=new google.feeds.Feed("https://www.openminds.com/market/child-welfare/feed/");e.setNumEntries(6),e.load(function(e){if(!e.error)for(var t=document.getElementById("feed"),n=0;n<e.feed.entries.length;n++){var d=e.feed.entries[n],i=document.createElement("li"),l=document.createElement("a"),a=document.createTextNode(d.title);l.appendChild(a),l.title=d.title,l.href=d.link,i.className="om-rss-entry",i.appendChild(l),t.appendChild(i)}})}google.
@psorensen
psorensen / convertformdatatoobject.js
Last active September 25, 2015 19:20
Convert form data to object
function get_form_data($form){
var search_form_data = $($form),
search_form_data_object = search_form_data.serializeArray(),
search_form_data_len = search_form_data_object.length;
// loop through object and asign key/value pairs
var returnObj = {};
for (var i = 0; i < search_form_data_len; i++) {
returnObj[search_form_data_object[i].name] = search_form_data_object[i].value;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello!</title>
<link rel="stylesheet" href="https://stackedit.io/res-min/themes/base.css" />
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body><div class="container"><h1 id="membership-transition-notes">Membership Transition Notes</h1>
@psorensen
psorensen / slimes.php
Created October 2, 2015 18:43
slimes app->request
object(Slim\Http\Request)[39]
protected 'env' =>
object(Slim\Environment)[36]
protected 'properties' =>
array (size=25)
'REQUEST_METHOD' => string 'POST' (length=4)
'REMOTE_ADDR' => string '::1' (length=3)
'SCRIPT_NAME' => string '/slimes' (length=7)
'PATH_INFO' => string '/contact' (length=8)
'QUERY_STRING' => string '' (length=0)
@psorensen
psorensen / user_exists_by_id.php
Created August 5, 2016 19:20
Wordpress: Find If User exists by ID
/**
* Determine if user exists by ID
* @param int $user_id User ID
* @return bool true if user exists
*/
public function user_id_exists( $user_id ){
global $wpdb;
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->users WHERE ID = %d", $user ) );