Skip to content

Instantly share code, notes, and snippets.

@patrickposner
patrickposner / singular.php
Created January 26, 2022 15:57
Protect entire singular.php template with Passster and password lists.
<?php
echo do_shortcode( '[passster password_list="115"]' );
$atts = array( 'password_list' => '115' );
$valid = passster\PS_Conditional::is_valid( $atts );
if ( $valid ) {
get_template_part( 'template-parts/content', get_post_type() );
// You can also use any other template of ACF layout here.
}
@patrickposner
patrickposner / functions.php
Last active December 23, 2022 10:25
Simply Static Pro: Single Export after save_post
<?php
add_action( 'save_post', 'ssp_auto_export', 10, 3 );
/**
* Automatically run a static export after post is saved.
*
* @param int $post_id given post id.
* @param object $post given post object.
* @param bool $update if it's updated or not.
@patrickposner
patrickposner / functions.php
Created December 6, 2021 16:27
Passster - Logout Button
<?php
// logout button
add_shortcode( 'passster-logout', function() {
?>
<button id="ps-logout">Logout</button>
<script>
jQuery(document).ready(function( $ ) {
$('#ps-logout').on('click', function() {
Cookies.set('passster', '', {
expires: 0,
@patrickposner
patrickposner / functions.php
Created October 13, 2021 19:19
Fire Cloudflare Pages Webhook after Simply Static exported successfully
<?php
add_action( 'ss_after_cleanup', function() {
$webhook_url = 'https://api.cloudflare.com/client/v4/pages/webhooks/';
wp_remote_get( $webhook_url, array() );
});
<?php
add_action( 'passster_validation_success', function( $password ) {
?>
<script>
jQuery(document).ready(function( $ ) {
$('html, body').animate({
scrollTop: $('#passster-scroll').offset().top
}, 'slow');
});
</script>
@patrickposner
patrickposner / functions.php
Created July 13, 2021 17:26
Use Passster for WooCommerce product protection
<?php
add_action( 'woocommerce_before_single_product_summary', function() {
$post_id = get_the_id();
$activate_protection = get_post_meta( $post_id, 'passster_activate_protection', true );
// user restriction.
$user_restriction_type = get_post_meta( $post_id, 'passster_user_restriction_type', true );
$user_restriction = get_post_meta( $post_id, 'passster_user_restriction', true );
@patrickposner
patrickposner / functions.php
Last active April 3, 2024 14:09
Simply Static: Set up a build to run daily with cron.
<?php
register_activation_hook( __FILE__, 'setup_build_cron' );
/**
* Setup a cron job to run daily.
*
* @return void
*/
function setup_build_cron() {
@patrickposner
patrickposner / functions.php
Created June 23, 2021 19:17
Simply Static run exports with PHP
<?php
// Full static export
$simply_static = Simply_Static\Plugin::instance();
$simply_static->run_static_export();
// Exporting a build with Pro
update_option( 'simply-static-use-build', $build_id );
$simply_static = Simply_Static\Plugin::instance();
$simply_static->run_static_export();
@patrickposner
patrickposner / functions.php
Created June 9, 2021 17:43
Passster: Redirect after successfull unlock.
<?php
add_action( 'passster_validation_success', function( $password ) {
$url = 'https://www.mydomain.de';
wp_safe_redirect( $url );
exit;
});
@patrickposner
patrickposner / functions.php
Created June 9, 2021 17:24
Adds FILR documents to the WordPress search.
<?php
/**
* Adds FILR documents to the WordPress search.
*
* @param object $query current query.
* @return object
*/
function add_filr_to_search( $query ) {
if ( $query->is_search ) {