Skip to content

Instantly share code, notes, and snippets.

View certainlyakey's full-sized avatar

Aleksandr Beliaev certainlyakey

  • Nortal AS
  • Tallinn
View GitHub Profile
@certainlyakey
certainlyakey / functions.php
Last active April 3, 2024 21:12
Wordpress - Limit pages nesting depth to 2nd level
//Limit pages nesting depth to 2nd level
//caution! by default affects all hierarchical CPTs
function limit_pages_nesting($a) {
$a['depth'] = 1;
return $a;
}
add_action('page_attributes_dropdown_pages_args','limit_pages_nesting');
@certainlyakey
certainlyakey / library.scss
Last active March 5, 2024 16:40
URL-encode color SASS function / convert color to hex SASS function
//does not work with colors containing alpha
@function encodecolor($string) {
@if type-of($string) == 'color' {
$hex: str-slice(ie-hex-str($string), 4);
$string:unquote("#{$hex}");
}
$string: '%23' + $string;
@return $string;
}
@certainlyakey
certainlyakey / functions.php
Last active December 5, 2022 02:08
Add metabox with key-value custom fields dynamically added by user
<?php
//Add metabox with dynamically added key-value (with more values possible) custom fields
//Based on http://wordpress.stackexchange.com/questions/19838/create-more-meta-boxes-as-needed/19852#19852
// Caution, there're 2 set of options below
//Variables used in the following functions should be mentioned in the 'global' statement of each of them appropriately
//=======Options 1=======
$dmb_post_type = 'tribe_events';
$dmb_metabox_label = 'Other information';
$dmb_cf_name = 'tribe_events_miscinfo';
@certainlyakey
certainlyakey / duplicate-title-checker.php
Created July 24, 2014 09:27
Wordpress Duplicate Title Checker plugin (updated version)
<?php
/*
Plugin Name: Duplicate Title Checker (zip all related files to upload it)
Plugin URI: http://wordpress.org/extend/plugins/duplicate-title-checker/
Description: This plugin provides alert message for duplicate post title and unique post title when adding new post.
Author: Ketan Ajani, improved by fuchsws and certainlyakey (see http://wordpress.org/support/topic/suggestions-35?replies=2)
Version: 1.1
Author URI: http://www.webconfines.com
*/
@certainlyakey
certainlyakey / script.jsx
Created June 22, 2014 21:36
Toggle reference point position Indesign script
//Alternates reference point position with each activation from top left to bottom right
//Assign a keyboard shortcut for fast use
if (app.activeWindow.transformReferencePoint == AnchorPoint.BOTTOM_RIGHT_ANCHOR) {
app.activeWindow.transformReferencePoint = AnchorPoint.TOP_LEFT_ANCHOR;
} else if (app.activeWindow.transformReferencePoint == AnchorPoint.TOP_LEFT_ANCHOR) {
app.activeWindow.transformReferencePoint = AnchorPoint.TOP_CENTER_ANCHOR;
} else if (app.activeWindow.transformReferencePoint == AnchorPoint.TOP_CENTER_ANCHOR) {
app.activeWindow.transformReferencePoint = AnchorPoint.TOP_RIGHT_ANCHOR;
} else if (app.activeWindow.transformReferencePoint == AnchorPoint.TOP_RIGHT_ANCHOR) {
app.activeWindow.transformReferencePoint = AnchorPoint.LEFT_CENTER_ANCHOR;
@certainlyakey
certainlyakey / functions.php
Last active May 15, 2022 20:40
Integrate Google Recaptcha v2 into custom AJAX form (Wordpress)
<?php
// First we register the Google Recaptcha script as a dependency with an onload callback
wp_register_script( 'recaptcha_v2', add_query_arg(['render' => 'explicit', 'onload' => 'onloadRecaptchaCallback'], 'https://www.google.com/recaptcha/api.js'), [], null, true);
wp_enqueue_script( 'recaptcha_v2' );
// Here we validate Google Recaptcha token issued on our frontend with Google servers using our custom 'validate_captcha' WP AJAX hook
function hh_validate_captcha() {
check_ajax_referer( 'hhsubscribe', '_ajax_nonce' );
<?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
Last active September 9, 2020 06:46
Wordpress - sort posts by title (numeric)
//Sort title by article numbers - 'Article 23. ...'
function sort_titles_article_numbers($a,$b) {
$akey = $a->post_title;
if (preg_match('/^Article (\d+)\. /', $akey, $matches)) {
$akey = $matches[1];
}
$bkey = $b->post_title;
if (preg_match('/^Article (\d+)\. /', $bkey, $matches)) {
$bkey = $matches[1];
}
@certainlyakey
certainlyakey / index.jade
Created March 23, 2015 05:59
Jade - random number in range
- var price = Math.floor(Math.random() * (15 - 1300) + 1300)
@certainlyakey
certainlyakey / functions.php
Created April 28, 2014 07:10
Wordpress - allow editors edit menus
// Allow editors edit menus
$role_object = get_role( 'editor' );
$role_object->add_cap( 'edit_theme_options' );