Skip to content

Instantly share code, notes, and snippets.

@jhaus
jhaus / SimplestWidget_Widget.php
Created November 26, 2010 03:47 — forked from straps/SimplestWidget_Widget.php
Abstract class to create easily wordpress widgets, documented here http://www.strx.it/2010/11/wordpress-widgets-template/
<?php
class SimplestWidget_Widget extends Strx_Widget {
function w_id(){ return 'simplest-widget'; }
function w_name(){ return 'My Simplest Widget'; }
/** Return the dashboard admin form */
function w_form($instance){
return '<p>'.$this->w_form_input($instance, 'title').'</p>';
}
<?php
// Initialize the Class and add the action
add_action('init', 'pTypesInit');
function pTypesInit() {
global $sites;
$sites = new TypeSites();
}
// Create a post type class for 'Site' posts
// To use as a bookmarking post type for sites you want to save/share.
@jhaus
jhaus / cpt-search.php
Created November 29, 2010 23:58
search wp custom post types too
<?php
// hook into wordpress search function
add_filter( 'the_search_query', 'aggregated_search' );// Define what post types to search
function aggregated_search( $query ) {
if( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'page', 'feed', 'attachment', 'movies', 'quotes' ));//define search types
}
return $query;
}
@jhaus
jhaus / cpt-class-create.php
Created November 29, 2010 23:59
Class for creating custom post types, taxonomies and meta boxes via: http://new2wp.com/pro/wordpress-custom-post-types-object-oriented-series2
<?php
// Create a post type class for site posts
// To use as a bookmarking post type for sites you want to save/share.
class TypeSites {
public $meta_fields = array( 'title', 'description', 'siteurl', 'category', 'post_tags' );
public function TypeSites() {
$siteArgs = array(
'labels' => array(
<?php
$q = new WP_query();
$q->query( 'post_type=site' );
/* Begin the Loop */
if ($q->have_posts()) :
while ($q->have_posts()) : $q->the_post();
/**
* Now instantiate the Sites class we made in posttypes.php setting the $s variable
@jhaus
jhaus / YQL-api-aggregation.php
Created November 30, 2010 00:01
Using cURL with YQL to aggregate content on 24ways.org via: https://github.com/codepo8/24-ways-2009/blob/master/index.php
<?php
/* YouTube RSS */
$query = 'select description from rss(5) where url="http://gdata.youtube.com/feeds/base/users/chrisheilmann/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile";';
/* Flickr search by user id */
$query .= 'select farm,id,owner,secret,server,title from flickr.photos.search where user_id="11414938@N00";';
/* Delicious RSS */
$query .= 'select title,link from rss where url="http://feeds.delicious.com/v2/rss/codepo8?count=10";';
@jhaus
jhaus / wp-multi-install
Created December 4, 2010 05:59
install wordpress automatically via: http://codex.wordpress.org install wordpress automatic via: Installing_Multiple_Blogs#Multiple_Install_Automation
#!/bin/sh -x
# script by Stephanie Booth aka bunny http://stephanie-booth.com/ to install wordpress automatically (geeky, but useful for mass installs), with help from many people: drauh, io_error, zedrdave, roddie... and all those I've forgotten to mention.
# variables: $1 whatever, $2 wp_user, $3 wp_pass, $4 root password
# prerequisites: an existing mysql db, and a root password
# care! .htaccess is not generated, needs to be done manually, by clicking on "Update Permalinks" in Options once everything is installed
# todo: add themes, check plugin list, make wrapper script for multiple installs, prepare php patch template for options and common stuff, see if the script can edit the vhost conf files for mass installs, prepare alternate version for French, add bilingual plugin and maybe cache. Add an extra user to the WP install. Also an alternate version for upgrading the school blogs.
@jhaus
jhaus / wp-remote-edit-post.php
Created December 4, 2010 23:46
remotely edit wordpress posts via: http://bit.ly/gyHw5K
<?php
// Update a Selected Post
$title= "Updated Title"; // The Title of the Post
$bodycontent="Updated Blog Article Content"; // Article Content
$categoriesu= array('Category1', 'Category2'); // Pre Existing Categories - Updated
$tagsu="tag1, tag2, $tag3"; // Updated Tags
$content = array('title'=>$title, 'description'=>$bodycontent,'categories'=>$categoriesu,'mt_keywords'=>$tagsu);
$params = array(163,$username,$password,$content,1); // First Parameter is mandatory Post Id (get your post id via Recent Blogs entries)
<?php
require_once("IXR_Library.php.inc");
$client->debug = true; //Set it to false in Production Environment
$title="Blog Title"; // $title variable will insert your blog title
$body="Blog Content"; // $body will insert your blog content (article content)
$category="category1, category2"; // Comma seperated pre existing categories. Ensure that these categories exists in your blog.
$keywords="keyword1, keyword2, keyword3";
<?php
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
$categories = implode(",", $categories);
$XML = "<title>$title</title>".
"<category>$categories</category>".
$body;
$params = array('','',$username,$password,$XML,1);
$request = xmlrpc_encode_request('blogger.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);