Skip to content

Instantly share code, notes, and snippets.

Avatar

Melissa Cabral melissacabral

View GitHub Profile
@melissacabral
melissacabral / about.md
Last active May 8, 2019
PHP Class Like Button Interface Starter
View about.md

TODO

  • Import the likes table (likes.sql) into our DB
  • write the HTML for the like button interface (index.php)
  • Add the CSS for the heart button (css/style.css)
  • Add the count_likes function (includes/functions.php)
  • add the likes interface function (includes/functions.php)
  • add the JS AJAX call when the user clicks the heart button (includes/footer.php)
  • add the ajax handler PHP file to update the DB behind the scenes (ajax-handlers/like-unlike.php)
@melissacabral
melissacabral / json-mysql-php.php
Created Apr 30, 2019
Make a JSON object from a mysql query
View json-mysql-php.php
<?php //connect to DB
require('config.php');
include_once('includes/functions.php');
//get 10 of the recent published posts out of the DB
$query = "SELECT posts.title AS post_title, posts.body AS description, posts.image AS url, users.username
FROM posts, users
WHERE posts.user_id = users.user_id
AND posts.is_published = 1
ORDER BY date DESC
@melissacabral
melissacabral / image-preserve-aspect-ratio.php
Created Feb 12, 2018
Change the image uploader we built so that it preserves the original aspect ratio. Replaces lines in the foreach($sizes) loop. Prevents up-sampling
View image-preserve-aspect-ratio.php
if($width >= $pixels){
//wider than desired size
$newwidth = $pixels;
//calculate the correct height
$newheight=($height/$width) * $newwidth;
}else{
//smaller than desired size. preserve original width and height
$newwidth=$width;
$newheight=$height;
}
@melissacabral
melissacabral / plugincomment.php
Created Oct 25, 2017
WordPress Plugin Comment
View plugincomment.php
<?php
/*
Plugin Name: Unique Name Here
Plugin URI: http://yoursite.com/plugin
Description: Does an awesome thing
Version: 0.1
Author: Your Name Here
Author URI: http://yoursite.com
License: GPLv3
*/
@melissacabral
melissacabral / comments.php
Last active Feb 26, 2018
step 1 of customizing comments display
View comments.php
<?php
//hide all of this file if the post if password protected
if( post_password_required() ){
return;
}
//get a distinct count of comments vs. pings
$comm = get_comments( array(
'status' => 'approve',
'post_id' => $id, //This post
View admin-editprofile-square-crop.php
<?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 Jun 24, 2016
Helper function to allow PHP to use the console for debugging.
View php-debug-to-console.php
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;
}
View wordpress-blog-page-featured-image.php
View image-upload-widget.php
<?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 / gist:02c89fa1bab0307dfd2e
Created Jan 6, 2016 — forked from engelen/gist:9df926bd9f3957394d89
Use WordPress dashicons in your theme on the frontend.
View gist:02c89fa1bab0307dfd2e
<?php
add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );
/**
* Enqueue Dashicons style for frontend use
*/
function mytheme_scripts() {
wp_enqueue_style( 'dashicons' );
}
You can’t perform that action at this time.