Skip to content

Instantly share code, notes, and snippets.

View melissacabral's full-sized avatar

Melissa Cabral melissacabral

View GitHub Profile
<?php
// square cropping logic on lines 56-70
// header has the authentication, DB connection and doctype!
require('admin-header.php');
//begin upload parser
if($_POST['did_upload']){
//the folder where uploads will be saved
$upload_directory = '../uploads';
@melissacabral
melissacabral / php-debug-to-console.php
Created June 24, 2016 17:03
Helper function to allow PHP to use the console for debugging.
function debug_to_console( $data ) {
if ( is_array( $data ) )
$output = "<script>console.log( 'Debug Objects: " . implode( ',', $data) . "' );</script>";
else
$output = "<script>console.log( 'Debug Objects: " . $data . "' );</script>";
echo $output;
}
<?php
/*
* Plugin Name: Media Upload Widget
* Plugin URI: http://wordpress.melissacabral.com
* Description: A widget that allows you to upload media from a widget
* Version: 1.0
* Author: Melissa Cabral
* Author URI: http://wordpress.melissacabral.com
* License: GPLv3
*/
@melissacabral
melissacabral / wp-widget.php
Last active January 20, 2016 16:35
Widget API - Basic Setup. Use in a plugin or functions file
<?php
function rad_register_widget(){
register_widget('Rad_Simple_Widget');
}
add_action('widgets_init', 'rad_register_widget');
//our new widget is a copy of the WP_Widget object class
class Rad_Simple_Widget extends WP_Widget{
function __construct(){
@melissacabral
melissacabral / gist:02c89fa1bab0307dfd2e
Created January 6, 2016 19:03 — forked from engelen/gist:9df926bd9f3957394d89
Use WordPress dashicons in your theme on the frontend.
<?php
add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );
/**
* Enqueue Dashicons style for frontend use
*/
function mytheme_scripts() {
wp_enqueue_style( 'dashicons' );
}
@charset "utf-8";
/* CSS Document */
#rad-slider {
position: relative;
list-style: none;
overflow: hidden;
width: 100%;
padding: 0;
margin: 0;
max-width:1120px;
<aside id="complementary">
<?php
//get the titles of the most popular (by number of comments) 5 published posts
$query_popular = 'SELECT posts.title, posts.post_id, COUNT(*) AS numcomments
FROM posts, comments
WHERE posts.is_published = 1
AND posts.post_id = comments.post_id
GROUP BY posts.post_id
ORDER BY numcomments DESC
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pure CSS Dropdowns</title>
<link href="css/reset.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
@melissacabral
melissacabral / template-sitemap.php
Created June 18, 2013 18:00
easy automatic sitemap in wordpress page template
<?php
/*
Template Name: Automagic Sitemap
Will automatically generate a sitemap from the wordpress database of posts, pages, and categories.
*/
?>
<?php get_header(); ?>
<div id="content">