This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Given a URL to an image maybe sideload into the media library | |
* | |
* @param string $url The URL to sideload into the media library | |
* @param string $name The title to associate with the image | |
* @param integer $associated_post_id The post ID to associate the sideloaded image to | |
*/ | |
function maybe_sideload_image( $url = '', $name = '', $associated_post_id = 0 ) { | |
require_once ABSPATH . 'wp-admin/includes/media.php'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Register a Book post type | |
$args = array( | |
'labels' => generate_post_type_labels( 'book', 'books' ), | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'query_var' => true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Put this in wp-config.php and replace https://example.com/ with the URL of the production site. | |
define( 'RH_USE_REMOTE_MEDIA_URL', 'https://example.com/' ); | |
// Put the rest of this in functions.php or a custom plugin or somewhere else. | |
if ( defined( 'RH_USE_REMOTE_MEDIA_URL' ) && ! empty( RH_USE_REMOTE_MEDIA_URL ) ) { | |
add_filter( 'wp_get_attachment_image_src', 'filter_wp_get_attachment_image_src' ); | |
add_filter( 'wp_calculate_image_srcset', 'filter_wp_calculate_image_srcset' ); | |
add_filter( 'wp_get_attachment_url', 'filter_wp_get_attachment_url' ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@use "sass:math"; | |
// via https://css-tricks.com/snippets/sass/px-to-em-functions/ | |
$browser-context: 16; | |
@function rem($pixels) { | |
@if (unitless($pixels)) { | |
$pixels: $pixels * 1px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Search post attachments where the given filename matchs the attached file path | |
* | |
* @link https://wordpress.stackexchange.com/a/405142/2744 | |
* | |
* @param string $filename The filename to search | |
* | |
* @return int The attachment ID of the first result sorted by post_date in reverse chronological order (most recent first) | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$key_file_path = __DIR__ . '/service-account-credentials.json'; | |
$google_client = new \Google_Client(); | |
$google_client->setAuthConfig( $key_file_path ); | |
// Set the scopes of whatever you need access to | |
// See https://developers.google.com/identity/protocols/oauth2/scopes | |
$google_client->setScopes( array( 'https://www.googleapis.com/auth/analytics.readonly' ) ); | |
$http_client = $client->authorize(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rh_filter_the_content( $the_content = '' ) { | |
$blocks = parse_blocks( $the_content ); | |
$new_block = array( | |
'blockName' => 'core/paragraph', | |
'attrs' => array(), | |
'innerBlocks' => array(), | |
'innerHTML' => '<p>Hello World</p>', | |
'innerContent' => array( | |
'<p>Hello World</p>', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Merge the expected data with the data recieved | |
$expected_data = array( | |
'timestamp' => '', | |
'foo' => '', | |
'bar' => '', | |
'baz' => '', | |
); | |
$data = array_merge( $expected_data, $_REQUEST ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rh_filter_the_content( $the_content = '' ) { | |
$blocks = parse_blocks( $the_content ); | |
$new_block = array( | |
'blockName' => 'core/paragraph', | |
'attrs' => array(), | |
'innerBlocks' => array(), | |
'innerHTML' => '<p>Hello World</p>', | |
'innerContent' => array( | |
'<p>Hello World</p>', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rh_filter_the_content( $the_content = '' ) { | |
$blocks = parse_blocks( $the_content ); | |
$new_block = array( | |
'blockName' => 'core/paragraph', | |
'attrs' => array(), | |
'innerBlocks' => array(), | |
'innerHTML' => '<p>Hello World</p>', | |
'innerContent' => array( | |
'<p>Hello World</p>', |
NewerOlder