Skip to content

Instantly share code, notes, and snippets.

View kellenmace's full-sized avatar

Kellen Mace kellenmace

View GitHub Profile
<?php
// Pull $username, $password, $client_id, $client_secret from the options table
$connection = new \RebuildTexasMigrations\Core\Connection( $username, $password, $client_id, $client_secret );
$connection->connect();
if ( ! $connection->is_connected() ) {
wp_send_json_error( esc_html__( 'An error occurred while connecting to the Salesforce API. Please check your username and password and try again.', 'rebuild-migration' ) );
}
"dataCells": [
{
"escapedLabel": "Aransas Pass Chamber of Commerce - Mar 2018",
"label": "Aransas Pass Chamber of Commerce - Mar 2018",
"value": "Aransas Pass Chamber of Commerce - Mar 2018"
},
{
"label": "a0q1I000000xh0Y",
"value": "a0q1I000000xh0YQAQ"
},
@kellenmace
kellenmace / remote-image-file-exists-usage.php
Created July 6, 2018 19:12
Remote image file exists function usage
<?php
$image_url = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
if ( km_remote_image_file_exists( $url ) ) {
echo 'The remote image exists! Hooray!';
} else {
echo 'The remote image does not exist. Boooooo.';
}
@kellenmace
kellenmace / remote-image-file-exists.php
Created July 6, 2018 19:08
Check if a remote image file exists in WordPress
<?php
/**
* Check if a remote image file exists.
*
* @param string $url The url to the remote image.
* @return bool Whether the remote image exists.
*/
function km_remote_image_file_exists( $url ) {
$response = wp_remote_head( $url );
@kellenmace
kellenmace / limit-page-post-collection-request.php
Created June 23, 2018 03:52
Limit a WordPress Pages post collection request to only users with the required permissions
<?php
/**
* Limit a Pages post collection request to only users with the required permissions.
*
* @author Kellen Mace
*
* @param array $args Key value array of query var to query value.
*
* @return array $args Key value array of query var to query value, possibly modified.
@kellenmace
kellenmace / custom-wordpress-page-rest-controller-.php
Created June 22, 2018 21:09
Create a custom WordPress REST API controller class for the Page post type.
<?php
/**
* Class to access pages via the REST API.
*
* @author Kellen Mace
*
* @see WP_REST_Posts_Controller
* @see WP_REST_Controller
*/
@kellenmace
kellenmace / custom-wordpress-page-rest-controller.php
Last active June 22, 2018 21:04
Set up a custom WordPress REST API controller class for the Page post type.
<?php
/**
* Set up a custom REST API controller class for the Page post type.
*
* @author Kellen Mace
*
* @param array $args The post type arguments.
* @param string $name The name of the post type.
*
@kellenmace
kellenmace / save-menu-date-modified-timestamps.php
Last active February 23, 2018 16:23
Set of functions for storing and getting last modified timestamps for WordPress menus
<?php
/**
* Save the date modified timestamp for a WordPress menu.
*
* @param int $menu_id Term ID of the menu being created/updated.
*/
function wds_save_menu_modified_timestamp( $menu_id ) {
$modified_timestamps = get_option( '_wds_menu_modified', array() );
@kellenmace
kellenmace / download-remote-image-example.php
Last active November 15, 2021 14:19
Download Remote Image Example
<?php
// Require the file that contains the KM_Download_Remote_Image class.
require_once plugin_dir_path( __FILE__ ) . 'inc/class-download-remote-image.php';
/**
* Download a remote image, insert it into the media library
* and set it as a post's featured image.
*
@kellenmace
kellenmace / class-download-remote-image.php
Last active October 13, 2022 13:24
Download and Insert a Remote Image File into the WordPress Media Library
<?php
/**
* This class handles downloading a remote image file and inserting it
* into the WP Media Library.
*
* Usage:
* $download_remote_image = new KM_Download_Remote_Image( $url );
* $attachment_id = $download_remote_image->download();
*