Skip to content

Instantly share code, notes, and snippets.

View kierzniak's full-sized avatar

Piotr Kierzniewski kierzniak

View GitHub Profile
@kierzniak
kierzniak / 01-macOS.md
Last active December 11, 2019 10:06 — forked from zenorocha/.hyper.js

Setup Mac OS X

1. Run Software Update

Make sure everything is up to date. Go to "System Preferences" > "Software Updates". If necessary, update your system.

2. Install Xcode and its "Command Line Tools"

  1. Go to App Store and install Xcode.
  2. Open Xcode and accept the terms
@kierzniak
kierzniak / functions.php
Last active March 8, 2024 15:19
Remove accents from url slug before WordPress search for a post
<?php
/**
* Remove accents from url slug before WordPress search for a post
*
* When you access page with accents you will not find any posts because
* WordPress is removing accents from url before saving it to database.
* This function will remove accents from url before WordPress start looking
* for post.
*
@kierzniak
kierzniak / functions.php
Last active January 2, 2018 08:06
Remove unwanted content from posts
<?php
/**
* Remove unwanted content from posts
*
* When your site get hacked you can have some unwanted content in database like
* links or script tags. This script will mass update all your posts to remove
* this kind of content. Take a look to $regex variable and remove or add pattern
* to fit your needs. To test regex you can use tool like https://regex101.com/
*
@kierzniak
kierzniak / functions.php
Created January 17, 2018 21:55
Search across all network blogs in elasticpress
<?php
/**
* Search across all network blogs with elasticpress
*
* @param $scope string Search scope
*
* @return string
*/
function motivast_ep_search_scope( $scope ) {
@kierzniak
kierzniak / functions.php
Created January 19, 2018 09:35
Allow number slug in page url
<?php
/**
* Allow number slug in page url
*
* Since WordPress do not allow number links in url we must generate it using
* `wp_unique_post_slug` filter.
*
* @link https://github.com/WordPress/WordPress/blob/4.9.2/wp-includes/post.php#L3798
*
@kierzniak
kierzniak / functions.php
Last active February 16, 2018 08:58
Save user activity to log file when post is saved
<?php
/**
* Function to save activity to log file when post is saved
*
* @param int $post_id Saved post id
*/
function motivast_add_activity_log_on_post_save( $post_id ) {
$format = '[%s] Post with ID %d was updated by user %s from IP %s';
@kierzniak
kierzniak / functions.php
Created February 28, 2018 10:02
Redirect posts with old permalink structure to new links.
<?php
/**
* Redirect posts with old permalink structure to new links.
*
* If you change your posts permalink structure you should redirect all
* trafic from old permalink to new one. This script will redirect posts
* from /%postname%/ to current post link using 301 status.
*
* This script is working only for /%postname%/ => current link
@kierzniak
kierzniak / functions.php
Created May 2, 2018 21:34
Sanitize filename on WordPress upload to not brake links with UTF-8 characters
<?php
/**
* Sanitize filename to not brake links with UTF-8 characters
*
* WordPress allow to upload files with names containing UTF-8 characters. Some
* browsers do not handle properly UTF-8 characters in url which causes 404 errors.
* This filter will remove UTF-8 characters from filename before saving it.
*
* @see https://core.trac.wordpress.org/ticket/22363 Bug request
*
@kierzniak
kierzniak / plugin.php
Last active May 11, 2018 07:35
Provide custom download link for password protected files
<?php
/**
* Provide custom download link for password protected files
*/
/**
* This probably should not be constant but for sake of example
* leave it like this;
*/
@kierzniak
kierzniak / functions.php
Last active May 25, 2018 15:15
Require basic authentication for all pages except home page
<?php
/**
* Require basic authentication for all pages except home page
*
* @return void
*/
function motivast_require_auth() {
define('AUTH_USER', 'admin');