Skip to content

Instantly share code, notes, and snippets.

View bobwol's full-sized avatar
💭
coding as usual

bobwol

💭
coding as usual
View GitHub Profile
@bobwol
bobwol / child-theme-functions.php
Created July 7, 2016 01:58 — forked from lots0logs/child-theme-functions.php
WordPress :: Divi Builder :: Search Module :: Custom Post Types
<?php
function my_remove_default_et_pb_custom_search() {
remove_action( 'pre_get_posts', 'et_pb_custom_search' );
add_action( 'pre_get_posts', 'my_et_pb_custom_search' );
}
add_action( 'wp_loaded', 'my_remove_default_et_pb_custom_search' );
function my_et_pb_custom_search( $query = false ) {
if ( is_admin() || ! is_a( $query, 'WP_Query' ) || ! $query->is_search ) {
@bobwol
bobwol / README.MD
Created July 19, 2016 20:21 — forked from jkasten2/README.MD
Use a local OneSignal SDK .aar file with Android Studio

Using a local OneSignal-release.aar file

1- Create a libs folder under the app directory in your project.

2- Place OneSignal-release.aar in the newly created app/libs directory.

3- Open your project's root build.gradle file and add the folowing under repositories {...}.

flatDir {
 dirs 'libs'
@bobwol
bobwol / auto-activate-plugins.php
Created July 30, 2016 02:57
WordPress Multisite: Automatically enable plugins in new blogs
<?php
// There are three options (that I know of) for automatically enabling a plugin
// in new sites.
// 1. Move the plugin from wp-content/plugins/ to wp-content/mu-plugins/ (MU =
// Must Use). But then it cannot be deactivated for any site.
// 2. Click "Network Activate" instead of "Activate" to enable it for all sites.
// I didn't want to use this though because I didn't want to affect existing
@bobwol
bobwol / functions.php
Created July 30, 2016 03:05
WordPress: Split functions.php into multiple files and autoload them
<?php
// I use this to split my theme’s functions.php into multiple smaller files on
// particularly complex sites, and to autoload those files (instead of having to
// require each one) to make development easier.
// Note that glob() is not particularly efficient since it has to do a directory
// scan, so when development is complete it’s better to replace most of this
// with manual require lines. (Having said that I don’t usually bother.)
@bobwol
bobwol / zip-file.php
Created July 30, 2016 03:05
PHP: Zip a single dynamically generated file
<?php
// Generate the contents of the file somehow
$content = '...';
// Zip the file
$zipFile = tempnam(sys_get_temp_dir(), 'zipfile');
$zip = new ZipArchive;
$zip->open($zipFile, ZipArchive::OVERWRITE);
$zip->addFromString('sample.txt', $content);
@bobwol
bobwol / wp-config.php
Created July 30, 2016 03:07
WordPress Multisite: Set default theme for new blogs
<?php
// Even if you disable all but one theme, WordPress seems to default to
// TwentyTen when creating a new Multisite blog. The fix is simple though - add
// this to wp-config.php:
define('WP_DEFAULT_THEME', 'yourthemename');
@bobwol
bobwol / set-options-for-all-blogs.php
Created July 30, 2016 03:08
WordPress Multisite: Set site/plugin options for all blogs in a network
<?php
// I used this code snippet as part of a WordPress Multisite plugin, to allow me
// to quickly set some options for all the blogs on a WordPress Multisite
// installation.
// Also see: Automatically enable plugins in new WordPress Multisite blogs -
// https://gist.github.com/1966425
@bobwol
bobwol / README.md
Created July 30, 2016 03:08
PHP: HTML to PDF conversion using wkhtmltopdf (and Smarty)

Recently I was asked to generate PDF invoices for an online shop. I looked at various PHP PDF generators, but wasn't particularly impressed with any of them.

Then I found (via Stack Overflow) a command-line HTML-to-PDF convertor called wkhtmltopdf, which uses WebKit (the same layout engine as Safari and Google Chrome) and therefore is very accurate.

There is a class for PHP integration on the Wiki, but I found it overly complicated and it uses temp files which aren't necessary. This is the code I wrote instead.

I used Smarty for generating the HTML for the PDF, but you can use any template engine, or pure PHP if you prefer.

Note: I originally tried to install wkhtmltopdf from source, but it's much easier to use the static binary instead.

@bobwol
bobwol / ios-create-gradient-background
Created September 19, 2016 19:44 — forked from dtrauger/ios-create-gradient-background
Create Gradient Background for View in Objective C
// Create the colors
UIColor *topColor = [UIColor colorWithRed:50.0/255.0 green:50.0/255.0 blue:50.0/255.0 alpha:1.0];
UIColor *bottomColor = [UIColor colorWithRed:56.0/255.0 green:56.0/255.0 blue:56.0/255.0 alpha:1.0];
// Create the gradient
CAGradientLayer *theViewGradient = [CAGradientLayer layer];
theViewGradient.colors = [NSArray arrayWithObjects: (id)topColor.CGColor, (id)bottomColor.CGColor, nil];
theViewGradient.frame = theView.bounds;
//Add gradient to view
@bobwol
bobwol / ios-add-border-to-view
Created September 19, 2016 19:45 — forked from dtrauger/ios-add-border-to-view
Programatically Adding Border to View in Objective C
CALayer *topBorder = [CALayer layer];
topBorder.frame = CGRectMake(0.0f, 0.0, viewForBorder.frame.size.width, 1.0f);
topBorder.borderWidth = 1;
topBorder.borderColor = [UIColor colorWithRed:58.0/255.0 green:58.0/255.0 blue:58.0/255.0 alpha:1.0].CGColor;
[theView.layer addSublayer:topBorder];