Skip to content

Instantly share code, notes, and snippets.

View maxkostinevich's full-sized avatar
🚧
Work in progress

Max Kostinevich maxkostinevich

🚧
Work in progress
View GitHub Profile
@maxkostinevich
maxkostinevich / functions.php
Created August 21, 2015 08:40
Get Website Domain TLD
// Get Website Domain TLD
function get_site_tld($url){
$host = parse_url($url);
preg_match('/(.*?)((\.co)?.[a-z]{2,4})$/i', $host['host'], $m);
$ext = isset($m[2]) ? $m[2]: '';
return $ext; // Domain TLD
}
// For WP just call
get_site_tld( get_site_url() );
@maxkostinevich
maxkostinevich / etc.sh
Last active February 2, 2016 09:28
Update Ubuntu Packages
# Create symlink
ln -s target dest
@maxkostinevich
maxkostinevich / functions.php
Last active March 18, 2016 06:31
Allow to open password protected pages with the password in URL
<?php
/**
* Allow to open password protected pages with the password in URL
* For example: http://examle.com/my-protected-page?access_token=2341223 (GET param: ?access_token=[POST PASSWORD])
* Feel free to replace 'access_token' with any other string
*
* Author: Max Kostinevich
* Author URI: https://maxkostinevich.com
*/
@maxkostinevich
maxkostinevich / app.js
Created November 9, 2015 06:53
Angular - ng-submit access to form fields
myApp.controller('myCtrl', function( $scope ) {
$scope.addNewItem = function ( event ) {
var formElement = angular.element(event.target);
var itemIndex = formElement[0].itemIndex.value;
var optionName = formElement[0].optionName.value;
@maxkostinevich
maxkostinevich / functions.php
Created December 22, 2015 16:15
bbPress: User Roles Custom Titles
<?php
add_filter( 'bbp_get_dynamic_roles', 'my_bbp_custom_role_names');
function my_bbp_custom_role_names(){
return array(
// Keymaster
bbp_get_keymaster_role() => array(
'name' => __( 'Keymaster', 'bbpress' ),
'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
@maxkostinevich
maxkostinevich / index.php
Created December 22, 2015 16:17
WordPress Custom Loop Markup
<?php
// Loop Markup (lm)
// Show 9 posts
// add "first" class for each first post in line (3 per line)
$lm_ItemsPerLine=3;
$lm_CurrentItem=1;
$lm_LineClose='';
$lm_LineOpen='<div style="overflow:hidden;">';
query_posts(array ('posts_per_page' =>9) );
if (have_posts()) : while (have_posts()) : the_post(); ?>
@maxkostinevich
maxkostinevich / functions.php
Created December 22, 2015 16:19
PHP: Get Upload Filesize
<?php
// Return allowed upload filesize in MB.
function get_upload_max_filesize(){
$upload_max_filesize = (int)(ini_get('upload_max_filesize'));
$post_max_size = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
$allowed_size = min($upload_max_filesize, $post_max_size, $memory_limit);
return $allowed_size;
}
@maxkostinevich
maxkostinevich / index.php
Created December 26, 2015 19:19
SEO-Friendly Maintenance Mode
<?php
$protocol = "HTTP/1.0";
if ( "HTTP/1.1" == $_SERVER["SERVER_PROTOCOL"] )
$protocol = "HTTP/1.1";
header( "$protocol 503 Service Unavailable", true, 503 );
header( "Retry-After: Mon, 28 Dec 2015 12:00:00 GMT" );
?>
<!DOCTYPE html>
<html lang="en">
@maxkostinevich
maxkostinevich / script.js
Created December 29, 2015 19:13
JS: Get <img> file name using regexp
var previewImg = $(this);
var previewImgSrc=previewImg.attr('src');
var previewImgName=previewImgSrc.match('[^/]*$'); // Get image name
@maxkostinevich
maxkostinevich / functions.php
Created December 29, 2015 19:14
WP-Admin: Change post title placeholder
<?php
add_filter( 'enter_title_here', 'my_filter' );
function my_filter( $title ){
$screen = get_current_screen();
if ( 'invoice' == $screen->post_type ){
$title = 'Your placeholder here';
}
return $title;
}