Skip to content

Instantly share code, notes, and snippets.

View frontycore's full-sized avatar

Ondřej Šeliga frontycore

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
*/
@frontycore
frontycore / functions.php
Created June 29, 2023 22:27
Unlock WP post with fobidden wp-login.php due to security
<?php
/**
* Change the password form action URL.
*/
add_filter('the_password_form', function($form, $post) {
$url = add_query_arg('unlock', 'post', get_permalink($post->ID));
$form = preg_replace('/action="([^\"]+)"/', 'action="' . $url . '"', $form);
return $form;
}, 10, 2);
@frontycore
frontycore / Calendar.php
Created May 27, 2023 17:56
Export to calendar (Google + Outlook + ICS)
<?php
namespace App\Utils;
use DateTime;
use App\PostTypes\Event;
use Nette\Utils\Strings;
use Jsvrcek\ICS\CalendarExport;
use Jsvrcek\ICS\CalendarStream;
use Jsvrcek\ICS\Utility\Formatter;
@frontycore
frontycore / social-links.php
Last active May 27, 2023 21:20
Socials share link
@frontycore
frontycore / FileUploader.php
Last active November 11, 2022 16:10
Wordpress class to upload files from external URL to media library.
<?php
namespace App;
use RuntimeException;
require_once(ABSPATH . '/wp-load.php');
require_once(ABSPATH . '/wp-admin/includes/image.php');
require_once(ABSPATH . '/wp-admin/includes/file.php');
require_once(ABSPATH . '/wp-admin/includes/media.php');
@frontycore
frontycore / Role.php
Last active April 4, 2022 23:52
WP Role managing class
<?php
namespace App\Users;
use WP_User;
use WP_Role;
use WP_Query;
use WP_Term_Query;
class Role {