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 / 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;
// 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 / 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 / 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 / filterSelectByParent.js
Last active August 29, 2015 13:58
Small jQuery plugin to filter a child <select> based on a parent <select>.
/*
Based on: http://stackoverflow.com/a/878331
Filter child select from selected parent select option.
Will look for parent (options) value in child data-parent"XX".
<select id="parent">
<option value="1">Group 1</option>
<option value="2">Group 2</option>
@MartinL83
MartinL83 / bootstrap-confirm.js
Last active August 29, 2015 14:00
Simple confirm modal on inputs / links / whatever trough data-attr. Will launch a (Twitter) Bootstrap modal on elements that have a data-confirm-action="confirm". Some settings available. **Needs loads of improvements**
// Confirmation modal on elements that have 'confirm' class.
// Will launch a modal and ask for confirmation.
// data-confirm-action="confirm" - Will enable the confirm modal
// data-confirm-title="" - Custom title, optional
// data-confirm-text="" - Custom modal text, optional.
;(function ( $, window, document, undefined ) {
// Create the defaults once
var pluginName = "confirmAction",
defaults = {
@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');
@MartinL83
MartinL83 / material-ui-tab-links.jsx
Created August 14, 2017 18:52
Material-UI, changing URL when clicking on a Tab
@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={{