Skip to content

Instantly share code, notes, and snippets.

View goranseric's full-sized avatar

Goran Šerić goranseric

View GitHub Profile
<?php
/* set the url of the file to sideload - probably be from $_POST or something */
$url = 'http://domain.com/image.jpg';
/**
* donwload the url into wordpress
* saved temporarly for now
*/
$tmp = download_url( $url );
@goranseric
goranseric / .htaccess
Created November 21, 2019 08:37
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@goranseric
goranseric / acf-gravity-forms-field.php
Created November 18, 2019 09:56 — forked from psaikali/acf-gravity-forms-field.php
Populate ACF select field options with Gravity Forms to select a specific form
<?php
/**
* Populate ACF select field options with Gravity Forms forms
*/
function acf_populate_gf_forms_ids( $field ) {
if ( class_exists( 'GFFormsModel' ) ) {
$choices = [];
foreach ( \GFFormsModel::get_forms() as $form ) {
$choices[ $form->id ] = $form->title;
@goranseric
goranseric / make_slug.php
Created November 11, 2019 10:47 — forked from meSingh/make_slug.php
Create WordPress like slugs from any string in php.
<?php
/**
*
* Genrate Slugs from Title or any given string
*
* @param string $str
* @return Slug
*
**/
// credit: https://wordpress.stackexchange.com/questions/191918/custom-post-preview-without-saving
// related: https://support.advancedcustomfields.com/forums/topic/preview-solution/
add_filter( 'preview_post_link', function ( $link ) {
return 'http://domain.com/mobile-preview/?src=' . urlencode($link) . '%26admin_bar=false';
} );
--
(function ($) {
@goranseric
goranseric / wordpress_author_url.php
Created October 2, 2019 12:00 — forked from davekellam/wordpress_author_url.php
Remove the WordPress front matter slug from the author url.
<?php
/**
* Modify Author links go to the right page
*/
function dk_author_link( $link, $author_id ) {
$link = str_replace( 'FRONT_URL_PATH/', '', $link );
return $link;
}
add_filter( 'author_link', 'dk_author_link', 10, 2 );
@goranseric
goranseric / acf-migrate-db-pro.php
Created September 19, 2019 18:32 — forked from daltonrooney/acf-migrate-db-pro.php
Prevent ACF Pro license key from being overwritten during WP Migrate DB Pro migration
<?php
/*
Based on http://github.com/deliciousbrains/wp-migrate-db-pro-tweaks
*/
class ACF_WP_Migrate_DB_Pro_Tweaks {
function __construct() {
add_filter( 'wpmdb_preserved_options', array( $this, 'preserved_options' ) );
}
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var elements = document.body.getElementsByTagName('*');
var items = [];
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) {
items.push(elements[i]);
}
}
@goranseric
goranseric / register-post-type.php
Created January 7, 2019 19:00 — forked from justintadlock/register-post-type.php
Help file when registering post types.
<?php
# Register custom post types on the 'init' hook.
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 1.0.0
* @access public
@goranseric
goranseric / gist:2da4723a5b31e0176be052b836303fc9
Created October 12, 2018 03:47
show subpages recursively
wpse13669_show_all_children( $post_id, $current_level ) {
$children = get_posts( array(
'post_type' =>'page',
'posts_per_page' =>-1,
'post_parent' => $post_id,
'order_by' => 'title',
'order' => 'ASC' ) );
if ( empty($children) ) return;
echo '<ul class="children level-'.$current_level.'-children">';