Skip to content

Instantly share code, notes, and snippets.

View mor10's full-sized avatar

Morten Rand-Hendriksen mor10

View GitHub Profile
@mor10
mor10 / openweatherAPI.json
Last active January 11, 2024 20:18
OpenWeather OpenAPI schema
{
"openapi": "3.1.0",
"info": {
"title": "OpenWeatherMap One Call API",
"description": "Provides access to current weather, hourly forecast, and daily forecast data.",
"version": "v1.0.0"
},
"servers": [
{
"url": "https://api.openweathermap.org"
@mor10
mor10 / Related-Component.php
Last active March 13, 2024 12:57
Extend WP Rig to display related posts using the REST API
@mor10
mor10 / Component.php
Created July 22, 2019 22:54
Add color palette option to Customizer in WP Rig theme
<?php
/**
* WP_Rig\WP_Rig\Customizer\Component class
*
* @package wp_rig
*/
namespace WP_Rig\WP_Rig\Customizer;
use WP_Rig\WP_Rig\Component_Interface;
@mor10
mor10 / leos-twisty-toy.ino
Created February 7, 2018 02:15
Arduino script for detecting three analog potentiometer inputs and output four LEDs: red, green, blue, and RGB
// Pin declarations
int potPinR= A0; // Declare potPinR to be analog pin A0
int potPinG= A1; // Declare potPinG to be analog pin A1
int potPinB= A2; // Declare potPinB to be analog pin A2
int LEDPinR= 9; // Declare LEDPinR to be arduino pin 9
int LEDPinG= 10; // Declare LEDPinR to be arduino pin 10
int LEDPinB= 11; // Declare LEDPinR to be arduino pin 11
// Variables
int readValueR; // Use to store value from red potentiometer
@mor10
mor10 / wpcampus-functionality.php
Created July 14, 2016 18:53
Add custom post type to index and search results
<?php
/**
* Include Lecture post type in the main and search queries
*/
function wpcampuscpt_query_filter( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( $query->is_search() || $query->is_home() ) {
$query->set('post_type', array( 'post', 'lecture' ) );
}
}
@mor10
mor10 / wpcampus-functionality.php
Created July 14, 2016 18:12
Create a basic WordPress plugin
<?php
/*
Plugin Name: WPCampus Functionality
Plugin URI: https://2016.wpcampus.org/schedule/wordpress-masterclass/
Description: Adds custom post types and taxonomies
Version: 1.0.0
Author: Morten Rand-Hendriksen
Author URI: https://lynda.com/mor10
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@mor10
mor10 / content-single.php
Created July 13, 2016 23:10
Generate automatic oEmbed from URL with Advanced Custom Field
<?php
// Make sure the plugin is active
if ( function_exists( 'get_field' ) ) {
$lecture_video = get_field('lecture_video');
}
// If the current post is a Lecture post and we have a lecture video URL, use oEmbed
if ( 'lecture' === get_post_type() ) {
if ( $lecture_video ) {
echo wp_oembed_get( $lecture_video );
}
@mor10
mor10 / functions.php
Created July 12, 2016 23:08
Display custom taxonomies in taxonomy lists in Twenty Sixteen child theme
<?php
/**
* Prints HTML with category and tags for current post.
* Augmented from the Twenty Sixteen original, found in inc/template-tags.php
*/
function twentysixteen_entry_taxonomies() {
// Display Class taxonomy when available
$tax_class_title = '<span class="tax-title">' . __( 'Class:', 'wpcampus' ) . '</span> ';
$class_list = get_the_term_list( $post->ID, 'class', $tax_class_title, _x( ', ', 'Used between list items, there is a space after the comma.', 'wpcampus' ) );
@mor10
mor10 / functions.php
Last active January 25, 2017 23:08
Print Twenty Sixteen meta content in custom post type posts through child theme
<?php
/**
* Prints HTML with meta information for the categories, tags, etc.
* Augmented from the Twenty Sixteen original, found in inc/template-tags.php
*/
function twentysixteen_entry_meta() {
if ( 'post' === get_post_type() || 'lecture' === get_post_type() ) {
$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
printf( '<span class="byline"><span class="author vcard">%1$s<span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>',
get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ),
@mor10
mor10 / wpcampus-functionality.php
Created July 12, 2016 22:14
Create custom taxonomies (hierarchical and non-hierarchical) in a WordPress plugin
<?php
// Create two taxonomies, Class and Year, for the post type "Lecture"
function wpcampuscpt_lecture_taxonomies() {
// Add Class taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Classs', 'taxonomy general name' ),
'singular_name' => _x( 'Class', 'taxonomy singular name' ),
'search_items' => __( 'Search Classes' ),
'all_items' => __( 'All Classes' ),
'parent_item' => __( 'Parent Class' ),