Skip to content

Instantly share code, notes, and snippets.

View adamcapriola's full-sized avatar

Adam Capriola adamcapriola

View GitHub Profile
@adamcapriola
adamcapriola / page_discourse-sso.php
Last active March 24, 2020 14:21
WordPress Page Template for SSO with Discourse
<?php
/**
* Template Name: Discourse SSO
* Author: Adam Capriola
* Version: 1.1
* Author URI: https://meta.discourse.org/users/AdamCapriola/activity
* Adapted From: https://github.com/ArmedGuy/discourse_sso_php
* Uses: https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045
*
*/
<?php
/**
* Sync Groups from WordPress to Discourse
*
* First creates 'groups' meta_key (which should be customized to your needs)
* Then it monitors for changes in the 'groups' meta_value and connects to Discourse API to sync groups
*
* WordPress References
* https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/meta.php?order=name#L235
* http://wordpress.stackexchange.com/questions/16835/how-to-hook-update-post-meta-and-delete-post-meta
@adamcapriola
adamcapriola / wordpress-discourse-sso.php
Created February 5, 2015 04:13
WordPress --> Discourse SSO
<?php
/**
* SSO "Page"
*
*/
add_action( 'parse_request', 'ac_parse_request' );
function ac_parse_request() {
// Check for SSO request
<?php
/**
* Add user meta to signify the user has just logged in
*
*/
add_action( 'wp_login', 'ac_fresh_login', 10, 2 );
function ac_fresh_login( $user_login, $user ) {
update_user_meta( $user->ID, 'fresh_login', 1 );
<?php
/*
Plugin Name: Discourse WordPress Integration
Description: This plugin contains all of the functions that deal with integrating WordPress and Discourse.
Author: Adam Capriola
Version: 1.0
Author URI: https://meta.discourse.org/users/adamcapriola/activity
*/
// Discourse info
@adamcapriola
adamcapriola / login-form-labels.php
Last active January 26, 2019 21:39
Filter WordPress login form labels
<?php
/**
* Filter login form labels
*
* @link https://wpartisan.me/?p=444
*
*/
add_action( 'login_head', 'ac_login_head_form_labels' );
function ac_login_head_form_labels() {
<?php
/**
* Remove &nbsp;'s
* @link https://core.trac.wordpress.org/ticket/31157
* @link https://core.trac.wordpress.org/ticket/31676
*
*/
add_filter( 'the_content', 'ac_remove_nbsps', 10 ); // Adjust priorities if necessary
add_filter( 'widget_text', 'ac_remove_nbsps', 10 );
@adamcapriola
adamcapriola / lede-words.php
Last active January 18, 2019 21:59
Automatically Bold (or Style) the First X Words of Content
<?php
/**
* Lede words
*
*/
add_filter( 'the_content', 'ac_the_content_lede_words' );
function ac_the_content_lede_words( $content ) {
// Get number of lede words
@adamcapriola
adamcapriola / lede-words.css
Created January 18, 2019 16:00
Styling for lede words
.lede-words {
font-weight: 700;
}
<?php
/**
* Carbon Fields: Post: Formatting
*
*/
add_action( 'carbon_fields_register_fields', 'ac_crb_register_fields_post_formatting' );
function ac_crb_register_fields_post_formatting() {
Container::make( 'post_meta', 'Formatting' )