Skip to content

Instantly share code, notes, and snippets.

View karlazz's full-sized avatar

Karla Leibowitz karlazz

  • herself
  • Walnut Creek, CA
View GitHub Profile
@karlazz
karlazz / gist:419faa1e6a1216aea8aa5316c77a6ed8
Last active April 2, 2019 22:34
SQL for getting users from multisite, not network admins
SELECT u.user_login, b.domain, b.path,
SUBSTRING_INDEX(SUBSTRING_INDEX(um.meta_value,'"', 2), '"', -1) as role
FROM wp_users u
JOIN wp_usermeta um ON u.ID = um.user_id
JOIN wp_blogs b ON b.blog_id = SUBSTRING(um.meta_key, 4, LENGTH(um.meta_key)-16)
WHERE um.meta_key LIKE 'wp_%_capabilities'
ORDER BY 1
--https://wordpress.stackexchange.com/questions/127081/sql-query-to-get-list-of-all-users-along-with-their-blogs
-- network admins are in sitemeta
@karlazz
karlazz / WP-ajax-example.txt
Last active September 14, 2018 22:56
Another WP Ajax example
//https://wordpress.stackexchange.com/questions/106427/using-ajax-with-a-class-file
<script>
jQuery(document).ready(function($)
{
$('#wpse').click(function(e)
{
e.preventDefault();
var data = {
action: 'process_reservation',
nonce: myAjax.nonce
@karlazz
karlazz / Wordpress oop starter example
Last active July 18, 2018 23:18
Wordpress OOP starter example tidbits
class MyPlugin {
function __construct() {
add_shortcode('ShowMsg', [$this,'ShowMsg']);
//add_action( 'admin_menu', [$this,'load_starter_tab'] );
add_action( 'admin_menu',
function () {
add_menu_page( 'Publications Upload', 'Publications Upload',
'manage_options', 'ha_pubs_load', [$this,'load_starter']);
function filter_joblisting_json( $data, $post, $context ) {
$phone = get_post_meta( $post->ID, '_phone', true );
if( $phone ) {
$data->data['phone'] = $phone;
}
return $data;
}
add_filter( 'rest_prepare_joblisting', 'filter_joblisting_json', 10, 3 );
/*
https://wordpress.stackexchange.com/questions/216376/how-do-i-add-a-template-to-a-theme-using-a-plugin
Here is a fairly simple approach I was able to get working within a plugin. You'll want to reference https://developer.wordpress.org/reference/hooks/theme_page_templates/ and https://developer.wordpress.org/reference/hooks/template_include/ as you review the code below.
*/
<?php
//Add our custom template to the admin's templates dropdown
add_filter( 'theme_page_templates', 'pluginname_template_as_option', 10, 3 );
function pluginname_template_as_option( $page_templates, $this, $post ){
$page_templates['template-landing.php'] = 'Example Landing Page';
@karlazz
karlazz / gist:2bffba4d0330bf746998319ae144ccaa
Created November 22, 2017 21:57
add a route to wordpress example from delicious brains
function benchmark_request() {
$result = array( 'time' => time() );
echo json_encode( $result );
exit;
}
add_action( 'wp_ajax_benchmark_request', 'benchmark_request' );
add_action( 'rest_api_init', function() {
register_rest_route( 'benchmark/v1', '/benchmark/', array(
'methods' => 'POST',
@karlazz
karlazz / jQuery and WordPress no noconflict
Last active February 20, 2023 08:57
Getting around noconflict mode for jQuery and WordPress
From: https://stackoverflow.com/questions/17687619/is-there-a-way-turn-off-jquery-noconflict-mode-in-wordpress
Is there a way turn off jquery noconflict mode in Wordpress? I don't mean loading an alternative version of jquery or the common workarounds:
jQuery(document).ready(function( $ ) {
});
or:
(function($) {
sed -ie 's/utf8mb4_unicode_520_ci/utf8_general_ci/g' mysql.sql
sed -ie 's/CHARSET=utf8mb4/CHARSET=utf8/g' mysql.sql
sed -ie 's/utf8mb4_unicode_ci/utf8_general_ci/g' mysql.sql
@karlazz
karlazz / gist:8d5fd25701761abd0030706ec90cab0f
Created April 11, 2017 20:06
check route on wordpress and redirect
add_action('template_redirect','twilio_check_route');
function twilio_check_route() {
global $wp;
$path = explode('/',$wp->request);
trace($path);
if (strtolower($path[0])=='safety-forums') {
/* triggered from google connect */
/* set in the google connect option for redirect on login */
if (! is_user_logged_in() ) {
@karlazz
karlazz / Wordpress plugin load without ftp
Created April 5, 2017 20:14
Config item for Wordpress plugin load without ftp
define('FS_METHOD','direct');