Skip to content

Instantly share code, notes, and snippets.

View luisabarca's full-sized avatar
🏠
Working from home

Luis Abarca luisabarca

🏠
Working from home
View GitHub Profile
@luisabarca
luisabarca / admin.php
Last active July 25, 2019 03:01
Create a PDF file from a plugin.
<?php
add_action( 'save_post', 'bp_generate_pdf', 10, 2 );
public function bp_generate_pdf( $post_id, $post ) {
// check autosave and permissions.
$should_generate_pdf = $_POST['generatepdf'] ?? 0;
if ( $should_generate_pdf ) {
@luisabarca
luisabarca / fix-ios-deploy-global.sh
Created July 7, 2018 21:08
Fix iOS-deploy installation
# Maybe
#sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo npm install --global --unsafe-perm ios-deploy
@luisabarca
luisabarca / gist:760bd0d53623ec99ffec2c74d1e86921
Created April 2, 2018 20:15
Regexp for valid instagram username
# Regex by Jonathan Stassen. http://blog.jstassen.com/2016/03/code-regex-for-instagram-username-and-hashtags
/(?:@)([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)/g
@luisabarca
luisabarca / bp-user-per-site.php
Last active June 20, 2017 22:35
Users registered on the main site can't login on subsites on a multisite installation
<?php
/*
Plugin Name: bPlus User per site
*/
// Url to redirect
define( 'BP_DEFAULT_URL', 'http://superpositif.com/interne/');
function is_valid_user_login( $user = null ) {
// Current site
@luisabarca
luisabarca / get-vimeo-private-video-thumb.php
Last active April 20, 2020 02:15
Get a thumbnail from Vimeo private videos
<?php
// You need Vimeo API https://github.com/vimeo/vimeo.php
require 'path-to-your-lib/vimeo/vimeo.php';
// Get this from your account
$vimeo_client_id = 'xxxxx';
$vimeo_client_secret = 'xxxxxxxxxxx';
// This has to be generated on your site, plugin or theme
$vimeo_token = 'xxxxxx';
@luisabarca
luisabarca / get_post_by_custom_field.php
Last active February 24, 2016 00:25
Get a WordPress post with a specific value in the custom fields
<?php
function get_post_by_custom_field($args)
{
$defaults = array(
'post_type' => 'post',
'key' => '',
'value' => '',
'compare' => '='
);
@luisabarca
luisabarca / 0_reuse_code.js
Created June 1, 2014 14:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@luisabarca
luisabarca / Piwik user tracking
Last active August 29, 2015 13:57
Track logged in user with piwik
<?php
$uname = '';
$user =& JFactory::getUser();
if ( is_object($user) ) {
$uname = $user->name;
}
?>
<!-- Piwik -->
<script type="text/javascript">
@luisabarca
luisabarca / gist:9243710
Created February 27, 2014 03:14
Get WordPress administrator email from an external PHP script
<?php
// Load WordPress
require_once('../../../../wp-load.php');
$this_form_spam = trim($_POST['this_title']);
if ( empty($this_form_spam) ) {
// Get values from form
$name = $_POST['name'];
$phone = $_POST['phone'];
@luisabarca
luisabarca / migrate-wordpress-domain
Created December 23, 2013 17:18
Migrating WordPress to a new domain. (Ex. Migrate Wordpress from dev to a production server)
# Update WordPress home and url
UPDATE wp_options SET option_value = replace(option_value, 'beta.mydoamin.com', 'mydomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
# Update URL's of every entry (post, page, custom post type)
UPDATE wp_posts SET guid = replace(guid, 'beta.mydomain.com', 'mydomain.com');
# Update post content
UPDATE wp_posts SET post_content = replace(post_content, 'beta.mydomain.com', 'mydomain.com');
# Update menus