Skip to content

Instantly share code, notes, and snippets.

View sergeliatko's full-sized avatar
💭
Looking for talented PHP / JavaScript / WordPress developers. Apply now!

Serge Liatko sergeliatko

💭
Looking for talented PHP / JavaScript / WordPress developers. Apply now!
View GitHub Profile
@sergeliatko
sergeliatko / wp_import_image_from_url.php
Last active January 16, 2018 23:36
PHP function to import an image from URL into WordPress media library
<?php
/**
* Imports an image from URL into media libarary.
*
* @param string $url The image URL
* @param string|null $title The title to use for image in the media library (also will be added as ALT text)
* @param int $post_parent_id Post parent ID if applicable
*
* @return int|\WP_Error ID of the newly created attachment or Wp_Error object on failure
@deconf
deconf / functions.php
Last active January 19, 2018 16:17
Examples for GADWP v5 Tracking Code customization
<?php
/* Analytics Code */
function gadwp_addcode( $gadwp ) {
$commands = $gadwp->get(); // Get commands array
array_pop( $commands ); // Pop the last element
$fields = array();
$fields['hitType'] = 'pageview';
$commands[] = $gadwp->prepare( 'send', $fields ); // Add a new line to the commands array
@sergeliatko
sergeliatko / wp_parse_args_recursive.php
Last active November 27, 2016 13:26
Parses arguments considering multi-dimensional arrays and objects
<?php
if( ! function_exists('wp_parse_args_recursive') ) {
/**
* Parses arguments considering multi-dimensional arrays and objects.
*
* @param mixed $args
* @param mixed $default
* @param bool $preserve_integer_keys
*
* @return mixed
@cliffordp
cliffordp / functions.php
Last active September 23, 2023 06:22
Automatically login a single WordPress user upon arrival to a specific page.
<?php
/**
* Automatically login a single WordPress user upon arrival to a specific page.
*
* Redirect to home page once logged in and prevent viewing of the login page.
* Compatible with WordPress 3.9.1+
* Updated 2014-07-18 to resolve WP_DEBUG notice: "get_userdatabylogin is deprecated since version 3.3! Use get_user_by('login') instead."
* Updated 2019-07-09 to reformat code, pass 2nd parameter to `do_action()`, and hook into priority 1.
*