Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / file1.php
Created Apr 25, 2012
An alternative "Hide ACF Menu from Clients"
View file1.php
add_action( 'admin_menu', function() {
if (! current_user_can('administrator')) {
remove_menu_page('edit.php?post_type=acf');
}
});
@soderlind
soderlind / config.ru
Created Dec 4, 2012 — forked from paulcook/config.ru
config.ru for Pow + Wordpress - based on http://stuff-things.net/2011/05/16/legacy-development-with-pow/. Added rewrite rule for WordPress Multi Site. More at http://soderlind.no/archives/2012/12/02/wordpress-and-pow/
View config.ru
# config.ru for Pow + Wordpress, based on http://stuff-things.net/2011/05/16/legacy-development-with-pow/
# added hackery to work around wordpress issues - Patrick Anderson (patrick@trinity-ai.com)
# added rubygems, replaced script_path with script from path_parts, added to_return to fix return error - Paul Cook
# clearly this could be cleaner, but it does work
# added rewrite rule for WordPress Multi Site - Per Soderlind (see also http://soderlind.no/archives/2012/12/02/wordpress-and-pow/)
require 'rubygems'
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
@soderlind
soderlind / get_attachment_id_from_post.php
Last active Dec 30, 2015
WordPress: Get image id from WordPress post. Images first added to the media uploader and then added to a post aren't attached i.e. you can't use $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' =>'inherit', 'post_parent' => $post->ID));
View get_attachment_id_from_post.php
<?php
// you need to add the post content to $post_content
preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $post_content, $images);
if (count($images[2]) > 0) {
foreach ($images[2] as $src) {
$image_id = pn_get_attachment_id_from_url($src);
/*
Do something with the $image_id
View tablepress-load-tables.php
<?php
$tables = array();
$m = TablePress::load_model( 'table' );
$ids = $m->load_all( true, false );
foreach ($ids as $id) {
$table = $m->load( $id );
$tables[$table['id']] = $table['name'];
}
@soderlind
soderlind / Gruntfile.js
Last active Aug 29, 2015
Automating WordPress plugin updates and releases with Grunt
View Gruntfile.js
/*
* Based on http://torquemag.io/automating-wordpress-plugin-updates-releases-grunt/
*
* added:
* copy:svn_assets task
* makepot, creates read-offline.pot
*/
module.exports = function (grunt) {
@soderlind
soderlind / force-protocol-less-url.php
Last active Jan 28, 2016
remove http and https from links
View force-protocol-less-url.php
<?php
//code from https://wordpress.org/plugins/cloudflare/
/**
* remove http and https from links, save in mu-plugins
*/
if (true !== function_exists('cloudflare_buffer_wrapup')) {
function cloudflare_buffer_wrapup($buffer) {
// Check for a Content-Type header. Currently only apply rewriting to "text/html" or undefined
@soderlind
soderlind / wp-cli-gears.php
Last active Feb 26, 2016
Testing WP CLI and WP Gears. WP Gears integrates Gearman with WordPress for asynchronous task running. WP Gears is available at https://github.com/10up/WP-Gears
View wp-cli-gears.php
<?php
/*
Plugin Name: WP CLI GEARS
Version: 0.0.2
Description: Testing WP CLI and WP Gears
Author: Per Soderlind
Author URI: https://soderlind.no
Plugin URI: https://gist.github.com/soderlind/a27527c3ed6545f594d7
License: GPL
*/
View gravatar_site_icon.php
<?php
/**
* Use Gravatar as your site icon, add the code to your (child) theme functions.php or use it in a plugin
* Requires: WordPress 4.3
*
* @param array $meta_tags default site icon meta tags array
* @return array return the modified site icon meta tags array
*/
function gravatar_site_icon ($meta_tags) {
@soderlind
soderlind / a_faster_load_textdomain.php
Created Oct 26, 2015
A faster load_textdomain for WordPress
View a_faster_load_textdomain.php
<?php
/*
Plugin Name: A faster load_textdomain
Version: 0.0.1
Description: While we're wating for https://core.trac.wordpress.org/ticket/32052.
Author: Per Soderlind
Author URI: https://soderlind.no
Plugin URI: https://gist.github.com/soderlind/610a9b24dbf95a678c3e
License: GPL
@soderlind
soderlind / not-so-super-admins.php
Last active Jan 9, 2018
Control what (super) admins can do. Works with regular and multisite WordPress
View not-so-super-admins.php
<?php
/*
Plugin Name: Not So Super Admin
Plugin URI: https://gist.github.com/soderlind/8101b2e45e80b594e9c5
Description: Control what (super) admins can do
Author: Per Soderlind
Author URI: http://soderlind.no
Version: 0.0.6
License: GPL
Tags: multisite, admin
You can’t perform that action at this time.