Skip to content

Instantly share code, notes, and snippets.

View davidshq's full-sized avatar

Dave Mackey davidshq

View GitHub Profile
@davidshq
davidshq / answer.md
Last active August 29, 2015 14:21 — forked from non/answer.md

What is the appeal of dynamically-typed languages?

Kris Nuttycombe asks:

I genuinely wish I understood the appeal of unityped languages better. Can someone who really knows both well-typed and unityped explain?

I think the terms well-typed and unityped are a bit of question-begging here (you might as well say good-typed versus bad-typed), so instead I will say statically-typed and dynamically-typed.

I'm going to approach this article using Scala to stand-in for static typing and Python for dynamic typing. I feel like I am credibly proficient in both languages: I don't currently write a lot of Python, but I still have affection for the language, and have probably written hundreds of thousands of lines of Python code over the years.

@davidshq
davidshq / wp_customizer_cp_example.php
Created January 6, 2016 16:34
WordPress Customizer - Color Picker Object Example
<?php
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize, 'color_control', array(
'label' => __( 'Accent Color', 'theme_textdomain' ), 'section' => 'media',
)
) );
?>
@davidshq
davidshq / wp_customizer_mc_example.php
Created January 6, 2016 16:37
WordPress Customizer - Media Control Object Example
<?php
$wp_customize->add_control(
new WP_Customize_Media_Control(
$wp_customize, 'image_control', array(
'label' => __( 'Featured Home Page Image', 'theme_textdomain' ),
'section' => 'media',
'mime_type' => 'image', // other options, e.g. audio
)
) );
?>
@davidshq
davidshq / wp_customizer_lpss_example.php
Created January 6, 2016 16:51
WordPress Customizer Live Preview / Save / Sanitize Example
<?php
$wp_customize->add_setting( 'setting_id', array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed
'default' => '',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => '',
'sanitize_js_callback' => '', // Essentially converts to JSON
) );
@davidshq
davidshq / wp_customizer_add_setting_ex.php
Created January 6, 2016 16:55
WordPress Customizer Add Setting Example
<?php
$wp_customize->add_setting(
'custom_theme_css' , array(
'type'    => 'theme_mod',
) );
$wp_customize->add_setting(
'custom_plugin_css' , array(
'type'    => 'option',
) );
@davidshq
davidshq / wp_customizer_retrieve_setting_ex.php
Created January 6, 2016 16:59
WordPress Customizer Retrieve Setting Example
<?php
function output_css_setting() {
echo '<style type="text/css" id="custom-theme-css">' . get_theme_mod( 'custom_theme_css', '') . '</style>';
echo '<style type="text/css" id="custom-plugin-css">' . get_option( 'custom_plugin_css', '' ) . '</style>';
}
add_action( 'wp_head', 'theme_custom_css_output');
?>
@davidshq
davidshq / wp_customizer_add_control_ex.php
Created January 6, 2016 19:21
WordPress Customizer - Adding a Control Example
<?php
$wp_customize->add_control( 'setting_name', array(
'type' => 'date',
'priority' => 10, // Within the section.
'section' => 'colors', // Required, can be either a built-in or custom.
'label' => __( 'Date' ),
'description' => __( 'This is a date control with a red border.' ),
'input_attrs' => array(
'class' => 'my-custom-class-for-js',
'style' => 'border: 1px solid #900',
@davidshq
davidshq / wp_customizer_add_section_ex.php
Created January 6, 2016 19:24
WordPress Customizer - Add Section Example
<?php
$wp_customize->add_section( 'custom_css', array(
'title' => __( 'Custom CSS' ),
'description' => __( 'Add custom CSS here' ),
'panel' => '', // Not typically needed
'priority' => 160,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed
) );
?>
@davidshq
davidshq / wp_customizer_add_panel_ex.php
Created January 6, 2016 19:26
WordPress Customizer - Add Panel Example
<?php
$wp_customize->add_panel( 'menus', array(
'title' => __( 'Menus'),
'description' => $description, // Include html tags
'priority' => 160,
) );
$wp_customize->add_section( $section_id , array(
'title' => $menu->name,
'panel' => 'menus',
) );
@davidshq
davidshq / wp_customizer_agr_objects_ex.php
Last active January 6, 2016 19:58
WP Customizer - Add/Get/Remove Objects Example
<?php
function mytheme_customize_register( $wp_customize )
{
$wp_customize->add_panel();
$wp_customize->get_panel();
$wp_customize->remove_panel();
}
add_action( 'customize_register', 'mytheme_customize_register' );
?>