Skip to content

Instantly share code, notes, and snippets.

View ajskelton's full-sized avatar

Anthony ajskelton

View GitHub Profile
@ajskelton
ajskelton / Meta_Box.php
Last active January 31, 2024 23:30
Add 'searchwp_related_sample_engines' filter to the get_samples function
/**
* Get associative array of sample results for keywords
*
* @param string $existing_keywords
*
* @param int $post_id
*
* @return array
*/
public function get_samples( $existing_keywords = '', $post_id = 0 ) {
@ajskelton
ajskelton / WP Customizer - Text
Last active February 27, 2023 11:57
Add a Text field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_text_setting_id', array(
'capability' => 'edit_theme_options',
'default' => 'Lorem Ipsum',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'themeslug_text_setting_id', array(
'type' => 'text',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Text' ),
@ajskelton
ajskelton / WP Customizer - Dropdown-pages
Last active February 13, 2023 08:04
Add a Dropdown-pages field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_dropdownpages_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_dropdown_pages',
) );
$wp_customize->add_control( 'themeslug_dropdownpages_setting_id', array(
'type' => 'dropdown-pages',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Dropdown Pages' ),
'description' => __( 'This is a custom dropdown pages option.' ),
@ajskelton
ajskelton / WP Customizer - Textarea
Last active December 14, 2022 15:10
Add a Textarea field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_textarea_setting_id', array(
'capability' => 'edit_theme_options',
'default' => 'Lorem Ipsum Dolor Sit amet',
'sanitize_callback' => 'sanitize_textarea_field',
) );
$wp_customize->add_control( 'themeslug_textarea_setting_id', array(
'type' => 'textarea',
'section' => 'custom_section', // // Add a default or your own section
'label' => __( 'Custom Text Area' ),
@ajskelton
ajskelton / WP Customizer - Radio Buttons
Last active December 7, 2022 04:48
Add a Radio field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_radio_setting_id', array(
'capability' => 'edit_theme_options',
'default' => 'blue',
'sanitize_callback' => 'themeslug_customizer_sanitize_radio',
) );
$wp_customize->add_control( 'themeslug_radio_setting_id', array(
'type' => 'radio',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Radio Selection' ),
@ajskelton
ajskelton / WP Customizer - Checkbox
Last active August 23, 2022 15:59
Add a Checkbox field to the WordPress Customizer.
$wp_customize->add_setting( 'themecheck_checkbox_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_checkbox',
) );
$wp_customize->add_control( 'themeslug_checkbox_setting_id', array(
'type' => 'checkbox',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Checkbox' ),
'description' => __( 'This is a custom checkbox input.' ),
@ajskelton
ajskelton / WP Customizer - Number
Last active May 28, 2022 14:13
Add a Number field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_number_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_number_absint',
'default' => 1,
) );
$wp_customize->add_control( 'themeslug_number_setting_id', array(
'type' => 'number',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Number' ),
@ajskelton
ajskelton / WP Customizer - Time
Last active March 24, 2022 08:44
Add a Time field to the WordPress Customizer. Includes sanitize function that formats the time as ('H:i')
$wp_customize->add_setting( 'themeslug_time_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => '',
'default' => 1,
) );
$wp_customize->add_control( 'themeslug_time_setting_id', array(
'type' => 'time',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Time' ),
@ajskelton
ajskelton / wp-external-image-handler.php
Last active March 15, 2022 04:47
WordPress External Image Handler - Add External URL image as featured image for a post
/**
* Uploads an image from remote url and sets as featured image of the new post
*
* @param int $post_id The id of the new post
* @param string $thumbnail_url Url of the preview image hosted by BrightTalk
*/
private function image_handler( $post_id, $thumbnail_url ) {
$image_url = $thumbnail_url; // Define the image URL here
$image_name = basename( $thumbnail_url );
$wp_customize->add_setting( 'themeslug_media_setting_id', array(
'sanitize_callback' => 'absint',
'validate_callback' => 'themeslug_validate_image,
) );
$wp_customize->add_control(
new WP_Customize_Media_Control( $wp_customize, 'themeslug_media_setting_id', array(
'label' => __( 'Custom Core Media Setting' ),
'section' => 'custom_section', // Add a default or your own section
'mime_type' => 'image',