Skip to content

Instantly share code, notes, and snippets.

View Inzman's full-sized avatar

Indrek Palm Inzman

  • Tartu, Estonia
View GitHub Profile
@Inzman
Inzman / gist:755283ea16ffe0f40a128ce73a6ac633
Created August 23, 2018 08:29
Remove key from array by value
$to_remove = array('john');
$result = array_diff($your_array_name, $to_remove);
@Inzman
Inzman / gist:ce52814df063e2b6abbbe53c05f944a7
Created August 22, 2018 07:13
To escape backslashes that cause problems for JSON data I use this function.
//escape backslash to avoid errors
var escapeJSON = function(str) {
return str.replace(/\\/g,'\\');
};
@Inzman
Inzman / gist:59c66456f4373de04978536707996d5d
Created August 17, 2018 10:25
Cross-Origin Request Blocked
<FilesMatch "\.(php)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
@Inzman
Inzman / gist:9b03b7ec114df236b65190611b4d72c1
Created August 16, 2018 05:02
Search multidimensional array by value
$key = array_search($item_id, array_column($array_name, 'id'));
____________________________
function search($array, $key, $value)
{
$results = array();
if (is_array($array))
{
@Inzman
Inzman / gist:25ae694d518829296cd4e54a7e93c5f9
Created August 1, 2018 09:09
Allow HTML in WordPress Category & Taxonomy Descriptions
// https://docs.appthemes.com/tutorials/allow-html-in-wordpress-category-taxonomy-descriptions/
// allow html in category and taxonomy descriptions
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'pre_link_description', 'wp_filter_kses' );
remove_filter( 'pre_link_notes', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
@Inzman
Inzman / gist:e9806e9376bf59ebdb49c8d2f9af28a2
Created August 1, 2018 09:08
How to get the tag's slug on the tag page
<?php
$tag = get_queried_object();
echo $tag->slug
?>
<?php
$a = Array(
1 => Array(
'name' => 'Peter',
'age' => 17
),
0 => Array(
'name' => 'Nina',
'age' => 21
),
@Inzman
Inzman / gist:e6b52081bcf612182864b3b7b930724d
Created July 2, 2018 14:06
Write to daily log in Wordpress
if(!function_exists('write_log')){
function write_log($log){
//if(true === WP_DEBUG){
$log_file_name = WP_CONTENT_DIR.'/logs/'.date('Y-m-d').'.log';
if(is_writable($log_file_name)){
if(is_array($log) || is_object($log)){
error_log(print_r($log, true)."\n", 3, $log_file_name);
} else {
error_log($log."\n", 3, $log_file_name);
}
<?php
if(is_user_logged_in()){
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'any',
'suppress_filters' => true
);
@Inzman
Inzman / gist:e6dd62c3e9dfa6668afeb1128a48f9ea
Created April 19, 2018 07:46
If page slug contains a number
<?php
if(is_user_logged_in()){
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'publish',
'suppress_filters' => false
);