Skip to content

Instantly share code, notes, and snippets.

View adam-laita's full-sized avatar

Adam Laita adam-laita

View GitHub Profile
@frontycore
frontycore / functions.php
Last active December 13, 2023 00:51
WP website lock using ACF
<?php
/**
* Locking whole web with simple password form
* ACF fields:
* - string 'wiki_password' - from settings, password to validate against the input form viewer login form
* - bool 'wiki_lock_site' - from settings, whether the site should be only accessible with password
* - array 'wiki_allowed_posts' - from settings, relation filed returning an array of post IDs, which are allowed to be viewed without password
*/
@hirasso
hirasso / ACFSyncFieldGroups.php
Last active December 9, 2025 13:29
A WordPress Plugin that allows to sync ACF field groups via WP CLI
<?php
/*
* Plugin Name: ACFSyncFieldGroups
* Plugin URI: https://gist.github.com/hirasso/c48c04def92f839f6264349a1be773b3
* Description: Allows to sync ACF field groups via WP CLI
* Version: 0.0.2
* Author: Rasso Hilber
* Author URI: https://rassohilber.com/
* License: GPL2+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
@dankoch-cz
dankoch-cz / read_csv.php
Created February 23, 2022 09:16
Read CSV file and return array with headers
<?php
function read_csv($file_path,$delimiter) {
$csv_rows = array();
$fp = fopen($file_path, 'r');
$head = fgetcsv($fp, 4096, $delimiter, '"');
// Rows
while($column = fgetcsv($fp, 4096, $delimiter, '"'))
@dankoch-cz
dankoch-cz / rewrite.php
Created February 19, 2022 14:23
Rewrite rules for query vars
<?php
//In functions
add_action( 'init', 'rewrite_plays_url' );
function rewrite_plays_url() {
add_rewrite_rule( 'program/([^/]+)/([^/]+)/([^/]+)?$','index.php?page_id=1&rok=$matches[1]&mesic=$matches[2]&misto=$matches[3]', 'top' );
add_rewrite_rule( 'program/([^/]+)/([^/]+)?$','index.php?page_id=1&rok=$matches[1]&mesic=$matches[2]', 'top' );
add_rewrite_rule( 'program/([^/]+)?$','index.php?page_id=1&rok=$matches[1]', 'top' );
}
add_filter( 'query_vars', 'register_custom_query_vars', 1 );
@lynt-smitka
lynt-smitka / lynt-admin.php
Last active April 10, 2024 11:07
WordPress - login as admin user
<?php
/**
* Plugin Name: Lynt Admin
* Author: Vladimir Smitka
* Author URI: https://lynt.cz/
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
defined( 'ABSPATH' ) or die( 'nothing here' );
@someguy9
someguy9 / add-admin-user-wordpress.php
Created March 17, 2020 12:35
Create an admin user in WordPress
<?php
//Create an admin user
function smartwp_create_admin_user(){
$username = 'yourusername';
$password = '2JyAEQJ9B9Jf5T8a';
$email = '[email protected]';
//This will ensure it only tries to create the user once (based on email/username)
if ( !username_exists( $username ) && !email_exists( $email ) ) {
$userid = wp_create_user( $username, $password, $email );
$user = new WP_User( $userid );
@addyosmani
addyosmani / lazyload.html
Last active November 8, 2022 11:00
Native image lazy-loading with a cross-browser fallback
<img data-src="unicorn.jpg" loading="lazy" alt=".." class="lazyload"/>
<script>
// Select all images with the class "lazyload"
const images = document.querySelectorAll("img.lazyload");
// Check if the browser supports the "loading" attribute
if ('loading' in HTMLImageElement.prototype) {
// If so, we'll update all <img src> to point to the data-src instead
images.forEach(img => {
img.src = img.dataset.src;
@voneff
voneff / functions.php
Last active May 4, 2023 16:01
WordPress: disabling Emojis and keeping emoticons as text
<?php
/**
* Disable WordPress emojis
* Source: https://kinsta.com/knowledgebase/disable-emojis-wordpress/#disable-emojis-code
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
@HoldOffHunger
HoldOffHunger / bradvin.social.share.urls.txt
Last active November 30, 2025 22:50
Social Share URL's (Summary)
https://www.facebook.com/sharer.php?u={url}
https://www.facebook.com/dialog/share?app_id={app_id}&display={page_type}&href={url}&redirect_uri={redirect_url}
https://reddit.com/submit?url={url}&title={title}
https://twitter.com/intent/tweet?url={url}&text={title}&via={user_id}&hashtags={hash_tags}
https://www.linkedin.com/sharing/share-offsite/?url={url}
https://api.whatsapp.com/send?phone={phone_number}&text={title}%20{url}
https://www.tumblr.com/widgets/share/tool?canonicalUrl={url}&title={title}&caption={text}&tags={hash_tags}
http://pinterest.com/pin/create/button/?url={url}
https://www.blogger.com/blog-this.g?u={url}&n={title}&t={text}
https://www.evernote.com/clip.action?url={url}&title={title}