Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
alexkingorg / wp-page-tags.php
Created February 6, 2014 20:52
Enable tags for pages (old code archive) for WordPress.
<?php
/*
Plugin Name: CF Page Tags
Plugin URI: http://crowdfavorite.com/wordpress/
Description: Add the tags form to pages in WP.
Author: Crowd Favorite
Author URI: http://crowdfavorite.com
Version: 1.0
*/
<?php
$results = $wpdb->get_results(
$wpdb->prepare("
SELECT ID, post_title, post_name, post_parent
FROM $wpdb->posts
WHERE post_parent IN (".implode(',', array_map('intval', $post_ids)).")
")
);
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme and one of the
* two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* For example, it puts together the home page when no home.php file exists.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
@alexkingorg
alexkingorg / wp-customer-posts-per-page.php
Created January 12, 2014 17:31
Customize posts-per-page based on some condition.
<?php
// add filter for front-end requests
if (!is_admin() && !is_feed()) {
add_filter('parse_request', 'my_add_posts_per_page');
}
// add our condition-checking filter
function my_add_posts_per_page() {
add_filter('pre_get_posts', 'my_posts_per_page');
@alexkingorg
alexkingorg / register-all-postmeta.php
Created January 7, 2014 18:55
Register all WP postmeta keys using the [CF Revision Manager](https://github.com/crowdfavorite/wp-revision-manager)
<?php
global $wpdb;
$keys = $wpdb->get_col("
SELECT DISTINCT meta_key
FROM $wpdb->postmeta
");
foreach ($keys as $key) {
@alexkingorg
alexkingorg / spam-comment-script.txt
Created December 22, 2013 16:04
A spam comment script with replacement clauses intact - accidentally submitted in it's entirety to my site.
{
{I have|I've} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It's|It is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as you did, the {internet|net|web} will be {much more|a lot more} useful than ever before.|
I {couldn't|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I'll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch} your {rss|rss feed} as I {can not|can't} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you've} any? {Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe. Thanks.|
{It is|It's} {appropriate|perfect|the best} time to make some plans for the future and {it is|i
@alexkingorg
alexkingorg / column-view-default-hack.js
Created December 11, 2013 18:23
Replace default link with Column View
jQuery(function($) {
$('#menu-pages > a[href="edit.php?post_type=page"]')
.attr('href', 'edit.php?post_type=page&page=cf-admin-column-view-page');
})
@alexkingorg
alexkingorg / sass-selectors.scss
Last active June 3, 2016 18:30
Use SASS variables for selectors.
// Vars - note the quotes around comma separated selectors
$a-tags: 'a, a:active, a:hover, a:visited';
$a-tags-hover: 'a:active, a:hover';
// Usage
#{$a-tags} {
color: red;
font-size: 1em;
text-decoration: none;
}
@alexkingorg
alexkingorg / .gitconfig
Last active December 21, 2015 02:38
Some gitconfig aliases. #git
[alias]
up = "pull --rebase"
pullmerge = "pull --no-rebase"
subup = "!f() { git submodule sync; git submodule update --init --recursive; }; f"
subreset = "submodule foreach 'git reset --hard HEAD'"
who = shortlog -s --
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
info = remote -v
incoming = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' ..@{u})
outgoing = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' @{u}..)
@alexkingorg
alexkingorg / github-activity-feed.php
Last active December 19, 2015 17:29
Pull GitHub activity feed into WordPress and output the items of interest.
<?php
$feed = fetch_feed('https://github.com/alexkingorg.atom');
// some activity isn't interesting enough to output
$ignore_types = array(
'issue_comment',
'watch',
);