This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function jsonFixer($json){ | |
$patterns = []; | |
/** garbage removal */ | |
$patterns[0] = "/([\s:,\{}\[\]])\s*'([^:,\{}\[\]]*)'\s*([\s:,\{}\[\]])/"; //Find any character except colons, commas, curly and square brackets surrounded or not by spaces preceded and followed by spaces, colons, commas, curly or square brackets... | |
$patterns[1] = '/([^\s:,\{}\[\]]*)\{([^\s:,\{}\[\]]*)/'; //Find any left curly brackets surrounded or not by one or more of any character except spaces, colons, commas, curly and square brackets... | |
$patterns[2] = "/([^\s:,\{}\[\]]+)}/"; //Find any right curly brackets preceded by one or more of any character except spaces, colons, commas, curly and square brackets... | |
$patterns[3] = "/(}),\s*/"; //JSON.parse() doesn't allow trailing commas | |
/** reformatting */ | |
$patterns[4] = '/([^\s:,\{}\[\]]+\s*)*[^\s:,\{}\[\]]+/'; //Find or not one or more of any character except spaces, colons, commas, curly and square brackets followed by one or more of any character except spaces, c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref: https://1loc.dev/function/compose-functions/ | |
// Compose functions from right to left | |
const compose = | |
(...fns) => | |
(x) => | |
fns.reduceRight((y, f) => f(y), x); | |
// Example | |
const lowercase = (str) => str.toLowerCase(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sendRequest = async data => { | |
try { | |
const response = await fetch(window.ajax_url, { | |
method: 'POST', | |
credentials: 'same-origin', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Cache-Control': 'no-cache', | |
}, | |
body: new URLSearchParams(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('11', 'admin', MD5('admin'), 'Admin', 'admin@test.com', '', '2019-11-11 00:00:00', '', '0', 'Admin'); | |
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '11', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}'); | |
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '11', 'wp_user_level', '10'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
</php | |
function get_fan_count(){ | |
$fb_id = '106900272716297'; | |
$count = get_transient('fan_count'); | |
if ($count !== false) return $count; | |
$count = 0; | |
$data = wp_remote_get('http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id='.$fb_id.''); | |
if (is_wp_error($data)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Sets post views during create a post | |
* @param int $post_id The post ID. | |
* @param object $post The post object. | |
* @param bool $update Whether this is an existing post being updated or not. | |
*/ | |
function add_post_views_after_save_post( $post_ID, $post, $update ) { | |
$count_key = 'post_views_count'; | |
$count = get_post_meta($post_ID, $count_key, true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="stars-rating"> | |
<?php | |
for($x=1;$x<=$rank;$x++) { | |
echo "<li class=\"stars-rating_item full\"><i class=\"star\">$x</i></li>"; | |
} | |
if (strpos($rank,'.')) { | |
echo "<li class=\"stars-rating_item half\"><i class=\"star\">$x</i></li>"; | |
$x++; | |
} | |
while ($x<=5) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@supports (-ms-ime-align:auto) { | |
.selector { | |
property: value; | |
} | |
} | |
/* https://browserstrangeness.github.io/css_hacks.html */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
function to create sitemap.xml file in root directory of site | |
*/ | |
add_action("publish_post", "pm_create_sitemap"); | |
add_action("publish_page", "pm_create_sitemap"); | |
add_action( "save_post", "pm_create_sitemap" ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_relationship_result( $title, $post, $field, $post_id ) { | |
$editLang = $_COOKIE['qtrans_edit_language']; | |
if($editLang) { | |
return qtranxf_use($editLang, $title, false, false); | |
} else { | |
return qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($title); | |
} | |
} |
NewerOlder