Skip to content

Instantly share code, notes, and snippets.

View adamcapriola's full-sized avatar

Adam Capriola adamcapriola

View GitHub Profile
<?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 / ac-ajax-save-views.php
Last active October 26, 2021 18:56
Save Jetpack "Site Stats" Pageviews as Post Meta
<?php
/**
* Save Jetpack views as post meta: Process Ajax request
*
*/
add_action( 'wp_ajax_save_views', 'ac_ajax_save_views' );
add_action( 'wp_ajax_nopriv_save_views', 'ac_ajax_save_views' );
function ac_ajax_save_views() {
@adamcapriola
adamcapriola / auto-tag-amazon-links-v1.php
Last active July 15, 2021 09:41
Auto-tag Amazon.com links (v1: Raw)
# Ignore everything #
**
!wp-content/
wp-content/**
!wp-content/themes/
!wp-content/plugins/
wp-content/themes/**
wp-content/plugins/**
# Add two rules for each Theme or Plugin you want to include:
@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
*
*/
@adamcapriola
adamcapriola / tinymce-add-formats.md
Created August 7, 2019 16:34 — forked from psorensen/tinymce-add-formats.md
Wordpress/TinyMCE - Add elements to formats dropdown

Adding Elements to the TinyMCE Format Dropdown

On a recent migration project, one of the requirements was to add a few blockquote styles to the TinyMCE dropdown list to match the editorial process of the old CMS. Wordpress provides a filter to add a secondary or tetriary dropdown, but if you only have a couple additional elements, it seems like bad UX to seperate it from the original dropdown.

Going off a tip from Chancey Mathews, I realized that Wordpress does not send a argument for block_formats when initializing TinyMCE, thus relying on the defaults. By adding this argument to the tiny_mce_before_init filter, we can add in our extra elements*:

* Note: since we're overriding the defaults, we need to include the original elements (p, h1-h6..etc)

function mce_formats( $init ) {
@adamcapriola
adamcapriola / query-posts-views.php
Last active January 30, 2019 18:59
Example query for popular posts (i.e., posts with most views)
<?php
/**
* Example query: Posts ordered by most views
*
*/
$args = (
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
jQuery(document).ready(function(e) {
e.ajax({
method: "POST",
url: save_views.ajax_url,
data: {
post_id: save_views.post_id,
nonce: save_views.nonce,
action: "save_views"
}
});
@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() {
@adamcapriola
adamcapriola / add-save-attachment-source-fields.php
Last active January 19, 2019 17:47
Attachment source fields (add and save)
<?php
/**
* Attachment source fields
* @link https://kaspars.net/?p=3203
* @link https://www.billerickson.net/?p=3555
*
*/
// Add fields
add_filter( 'attachment_fields_to_edit', 'ac_attachment_fields_to_edit_source', 10, 2 );