Skip to content

Instantly share code, notes, and snippets.

View uptimizt's full-sized avatar
💻
Code is poetry...

Antony I uptimizt

💻
Code is poetry...
View GitHub Profile
@uptimizt
uptimizt / gist:0707f6e7ff1f4c772f39c5aacbdea828
Created April 7, 2016 23:06
Example Metrika Goal & GTM
<script>
//контроль цели отправки формы
(function ($) {
$('.menu-item-34927 a').click(function(){
yaCounter27903495.reachGoal('help_click');
});
}(jQuery));
</script>
@uptimizt
uptimizt / php
Created July 17, 2016 09:12
WP Example: Get data JSON
<?php
$key_oer = '???'; // тут указываем ключ API
$url_api_oer = 'https://openexchangerates.org/api/latest.json?app_id=' . $key_oer;
$response = wp_remote_get($url_api_oer);
$data_exchange = json_decode( wp_remote_retrieve_body( $response ) );
var_dump($data_exchange); // вернет объект с данными, которые можно далее использовать в коде
@uptimizt
uptimizt / save_array_to_csv.php
Created January 9, 2017 16:19
Save array to CSV (for php and WordPress)
function save_data_to_file(){
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
$data = array(
@uptimizt
uptimizt / acl_wordpress.php
Last active March 21, 2017 11:44
Контроль доступа к постам WordPress основанный на метаполе 'acl_users_s' в котором записан список ИД пользователей, для которых есть доступ к посту
<?php
if ( ! function_exists( 'acl_filter_posts_where' ) ) :
function acl_filter_posts_where($where){
global $wpdb;
$current_user_id = get_current_user_id();
@uptimizt
uptimizt / snippets.cson
Created March 25, 2017 13:52
Snippets WordPress for atom.io
'.text.html':
'Plugin':
'prefix': 'plugin-wp'
'body': '<?php\n/*\nPlugin Name: $1\nVersion: ${2:0.1}\nPlugin URI: ${TM_PLUGIN_BASE}$3\nDescription: $4\nAuthor: ${TM_NAME}\nAuthor URI: ${TM_HOMEPAGE}\n*/\n\n$5\n\n\n?>\n'
'Readme.txt':
'prefix': 'readme-wp-plugin'
'body': '=== ${1:Plugin Name} ===\nContributors: ${TM_WP_LOGIN}\nDonate link: ${TM_HOMEPAGE}\nTags: ${2:tag, tag}\nRequires at least: ${3:2.5}\nTested up to: ${4:2.8}\nStable tag: ${5:0.1}\n\n${6:Short description}\n\n== Description ==\n\n${7:Short description}\n\n== Installation ==\n\n1. Upload the \\`${8:plugin}\\` folder to the \\`/wp-content/plugins/\\` directory\n1. Activate the plugin through the \'Plugins\' menu in WordPress\n1. $9\n\n== Changelog ==\n\n= $5 =\n* Initial release.'
@uptimizt
uptimizt / example.php
Created May 13, 2017 10:39
Меняем классы у меню WordPress
<?php
function wpc37174_special_nav_class($classes, $item){
if( is_single() && $item->title == "Blog"){
$classes[] = "special-class";
}
return $classes;
@uptimizt
uptimizt / example.php
Created May 19, 2017 17:33
Allow zip and gzip files (mime type) for WordPress
<?php
function wpcraft_zip_gzip_mime_types ( $mimes ) {
$existing_mimes['zip'] = 'application/zip';
$existing_mimes['gz'] = 'application/x-gzip';
return $mimes;
}
add_filter('upload_mimes', 'wpcraft_zip_gzip_mime_types');
?>
private function wooms_nonce_check($nonce = ''){
if(empty($nonce)){
return false;
}
if($nonce == get_transient('wooms_nonce')){
delete_transient('wooms_nonce');
return true;
} else {
return false;
@uptimizt
uptimizt / php
Created November 14, 2017 19:15
Use HTTPS for some sites of network
<?php
/**
* Use HTTPS for some sites of network
*/
function rsssl_check_protocol_multisite($url, $scheme, $orig_scheme){
if(get_current_blog_id() == 23){
$url = str_replace("http://", "https://", $url);
@uptimizt
uptimizt / snippet.php
Created December 18, 2017 09:31
If isset cookie - clear value and redirect to url - WordPress.
<?php
/**
* If isset cookie - clear value and redirect to url
*/
function redirect_after_signin(){
if(is_user_logged_in()){
if( ! empty($_COOKIE["redirect_url_sso"])){
$url = $_COOKIE["redirect_url_sso"];
setcookie("redirect_url_sso", "", time() - 3600);