Skip to content

Instantly share code, notes, and snippets.

View certainlyakey's full-sized avatar

Aleksandr Beliaev certainlyakey

  • Nortal AS
  • Tallinn
View GitHub Profile
<?php
/*
Plugin Name: GF file upload to ACF image field
Plugin URI: https://gist.github.com/certainlyakey/8c19791b3133beb62d323bf060bf4270
Description: Map Gravity forms file upload field to ACF image/file field so GF would upload the file and save id to DB instead of URL.
Version: 1.0.0
Author: Kellen Mace
*/
@certainlyakey
certainlyakey / functions.php
Created October 30, 2017 14:46
Insert breadcrumb into trail in an arbitrary position (Wordpress/Breadcrumbs NavXT)
//Insert profile link into trail on create diary page
function theme_add_to_trail_on_create_diary_entry($trail) {
if (is_page_template('custom-template.php')) {
$home = $trail->breadcrumbs[0];
$current_page = $trail->breadcrumbs[1];
$profile = new bcn_breadcrumb(__('Profile','domain'), NULL, array('c-breadcrumbs__item'), get_author_posts_url(get_current_user_id()));
// $trail->add($profile) always inserts in the beginning
$trail->breadcrumbs = array($home, $profile, $current_page);
@certainlyakey
certainlyakey / functions.php
Created October 30, 2017 10:19
Remove an item from Breadcrumbs NavXT plugin trail (Wordpress)
if (function_exists('bcn_display')) {
function theme_remove_news_from_trail_on_404($trail) {
if ( is_404() ) {
unset($trail->trail[1]);
array_keys($trail->trail);
}
}
add_action('bcn_after_fill', 'theme_remove_news_from_trail_on_404');
}
@certainlyakey
certainlyakey / fields.php
Last active October 30, 2017 08:27
Hide certain pages from WP admin (based on an ACF/custom field)
acf_add_local_field_group(array (
'key' => 'group_ujq7wrdtwyldi',
'title' => __('System settings','domain'),
'fields' => array (
array (
'key' => 'field_sf9o6xmozloau',
'label' => __('Hide this page for non admins?','domain'),
'name' => 'page_is_system',
'type' => 'true_false',
'instructions' => '',
@certainlyakey
certainlyakey / _header.scss
Last active October 31, 2017 22:38
Accessible dropdown menu in Twig/SASS/JS (Wordpress/Timber-oriented)
// @z-index space: 100-110
.c-header {
$local-spacing-top:10px;
@include t-page-wrapper;
padding-top:$local-spacing-top;
display:flex;
&__logo {
@include mq($until: mainmenu-horizontalized) {
@certainlyakey
certainlyakey / functions.php
Created October 28, 2017 19:37
Limit minimum upload dimensions automatically by smallest width of height based on image sizes currently registered (Wordpress)
<?
// Limit upload size
function themeprefix_limit_upload_size($file) {
$img = getimagesize($file['tmp_name']);
$minimum = themeprefix_get_minimum_width_height_of_all_sizes();
$width = $img[0];
$height = $img[1];
if ($width < $minimum['width'] ) {
@certainlyakey
certainlyakey / functions.php
Last active October 28, 2017 19:39
Remove author base from profile permalink (Wordpress)
<?
// From https://wp-snippet.com/snippets/remove-author-prefix-from-slug/
add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules');
function no_author_base_rewrite_rules($author_rewrite) {
global $wpdb;
$author_rewrite = array();
$authors = $wpdb->get_results("SELECT user_nicename AS nicename from $wpdb->users");
foreach($authors as $author) {
$author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
$author_rewrite["({$author->nicename})/?$"] = 'index.php?author_name=$matches[1]';
@certainlyakey
certainlyakey / functions.php
Last active November 11, 2018 18:55
Hide certain pages (ones with system-pages category assigned) from the general admin listing (Wordpress)
<?php
// Hide certain pages (ones with system-page category assigned) from the general admin listing, but keep them accessible when visiting category listing in admin
function hide_system_pages($query) {
if (
is_admin() &&
!empty( $_GET['post_type'] ) &&
$_GET['post_type'] == 'page' &&
!$_GET['category_name'] &&
$query->query['post_type'] == 'page'
@certainlyakey
certainlyakey / functions.php
Last active November 3, 2017 15:38
Get ids of forms with a certain class (Gravity forms/Wordpress)
// Get ids of forms with a certain class
function themeprefix_get_form_ids_by_form_class($class) {
$form_ids = array();
$all_forms = GFAPI::get_forms();
foreach ($all_forms as $form) {
if (isset($form['cssClass'])) {
$form_classes = explode(' ', $form['cssClass']);
if (in_array($class, $form_classes)) {
$form_ids[] = $form['id'];
@certainlyakey
certainlyakey / _mixins.scss
Last active June 11, 2019 11:27
A function that allows to have one-liners for several values of one property mapped to different media queries (widths).
// @include u-responsive-value(margin-top, (small:18px, medium:25px, large:29px, xlarge:40px));
// dependencies: sass-mq (can be replaced with a simple map of named media queries)
@mixin u-responsive-value($property, $values-map) {
@if type-of($values-map) == 'map' {
@each $mq, $value in $values-map {
@if map-has-key($mq-breakpoints, $mq) {
@if $mq == small {
#{$property}:$value;
} @else {
@include mq($from: $mq) {