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 / php
Last active March 21, 2016 09:40
добавляем скрипт в тему и плагин
//пример для плагина
function add_script_in_plugin_1(){
wp_enqueue_script('custom-script', plugins_url( '/js/newscript.js', __FILE__ ), array('jquery'));
wp_enqueue_style( 'style-name', plugins_url( '/css/custom.css', __FILE__ ) );
@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 / 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 18, 2017 13:04
Check rules for endpoint and reset rewrite rule
<?php
/**
* Add Endpoint for URL Callback OAuth2
*/
class HAWP_Endpoint_Callback {
function __construct() {
add_action( 'init', array($this, 'add_endpoint') );
add_action( 'wp_loaded', array($this, 'flush_rewrite_rules_hack') );
@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');
?>
@uptimizt
uptimizt / userlogingenerate.php
Created June 1, 2017 08:26
Generate user login in WordPress - function example
<?php
/**
* Generate login for new WP user
*
* return string uniq login
*/
function generate_new_userlogin(){
$users_ids = get_users('fields=ID&number=3&orderby=registered&order=DESC');
$last_id = max($users_ids);
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;