Skip to content

Instantly share code, notes, and snippets.

View MartinL83's full-sized avatar
🤷‍♂️
wat

Martin Lindgren MartinL83

🤷‍♂️
wat
View GitHub Profile
@MartinL83
MartinL83 / react-ts-recursive.js
Last active November 14, 2022 17:37
React Typescript - Recursive component
import React, { useState } from "react";
type ItemType = {
id: Number;
title: String;
children: Array<Number>;
};
// Each "ItemType" element in the array have a array of children ID's. These refer
// to a ItemType.
@MartinL83
MartinL83 / Create page on theme activation
Created July 23, 2013 07:15
Wordpress - Create page on theme activation
if (isset($_GET['activated']) && is_admin()){
$new_page_title = 'This is the page title';
$new_page_content = 'This is the page content';
$new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template.
$page_check = get_page_by_title($new_page_title);
$new_page = array(
'post_type' => 'page',
'post_title' => $new_page_title,
'post_content' => $new_page_content,
'post_status' => 'publish',
@MartinL83
MartinL83 / react-bootstrap-breakpoints.js
Created November 19, 2017 20:47
A simple React HOC to feed css breakpoint data to a component.
import React, { Component } from 'react';
import _ from 'lodash';
/*
HOC to feed breakpoints data to child component.
Breakpoint data is based on Bootstrap's breakpoints
Using lodash throttle to optimize the high rate of events being fired.
*/
export const Breakpoints = (WrappedComponent) => {
@MartinL83
MartinL83 / material-ui-tab-links.jsx
Created August 14, 2017 18:52
Material-UI, changing URL when clicking on a Tab
@MartinL83
MartinL83 / Datepicker swedish localization
Created September 21, 2013 10:06
Swedish translation for jQuery UI´s datepicker, as well as the timepicker addon.
$.datepicker.regional['sv'] = {
closeText: 'Stäng',
prevText: '< Föregående',
nextText: 'Nästa >',
currentText: 'Nu',
monthNames: ['Januari','Februari','Mars','April','Maj','Juni','Juli','Augusti','September','Oktober','November','December'],
monthNamesShort: ['Jan','Feb','Mar','Apr','Maj','Jun','Jul','Aug','Sep','Okt','Nov','Dec'],
dayNamesShort: ['Sön','Mån','Tis','Ons','Tor','Fre','Lör'],
dayNames: ['Söndag','Måndag','Tisdag','Onsdag','Torsdag','Fredag','Lördag'],
dayNamesMin: ['Sö','Må','Ti','On','To','Fr','Lö'],
@MartinL83
MartinL83 / read_rss.php
Created September 24, 2013 20:01
Wordpress read external RSS
<?php // Source: http://www.wpbeginner.com/wp-tutorials/55-most-wanted-wordpress-tips-tricks-and-hacks/ ?>
<?php include_once(ABSPATH.WPINC.'/feed.php');
$rss = fetch_feed('http://feeds.feedburner.com/wpbeginner');
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
@MartinL83
MartinL83 / popper-react-wrapper.js
Last active October 22, 2017 10:37
A simple React component for positioning elements with Popper.js
// NOTE: This component requires React 16 or newer.
// Usage:
/*
<Position
parent={<div>Parent element</div>}
target={ (style) => (
<div style={style}>Popper element</div>
)}
options={{
@MartinL83
MartinL83 / main.js
Last active December 18, 2016 18:27
Bootstrap 4 JS and Meteor
// Import tether.js
// We also add 'global.Tether' as a workaround for Meteor.
import tether from 'tether';
global.Tether = tether;
// Import Bootstrap js.
bootstrap = require('bootstrap');
// function to be executed when a custom post type is published
function run_when_post_published()
{
// your function code here
}
// replace {custom_post_type_name} with the name of your post type
add_action('new_to_publish_{custom_post_type_name}', 'run_when_post_published');
add_action('draft_to_publish_{custom_post_type_name}', 'run_when_post_published');
add_action('pending_to_publish_{custom_post_type_name}', 'run_when_post_published');
@MartinL83
MartinL83 / gist:3787343
Created September 26, 2012 11:01
Buddypress custom posts on activity stream.
/*
** Put this in your ( for example ) functions.php file.
** Credits
** http://pastebin.com/qrfjCat8
** http://premium.wpmudev.org/forums/topic/how-to-add-custom-posts-types-in-buddypress-activity
*/
function custom_record_activity( $post_id, $post, $user_id = false ) {
global $bp, $wpdb;