Skip to content

Instantly share code, notes, and snippets.

Avatar

Philipp Stracker stracker-phil

View GitHub Profile
@stracker-phil
stracker-phil / class-mycode.php
Last active Apr 6, 2020
Sample Block for MailPoet feature request
View class-mycode.php
<?php
/**
* Custom Block to output Code.
*/
namespace MailPoet\Newsletter\Renderer\Blocks;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
@stracker-phil
stracker-phil / global-search.js
Last active Aug 3, 2020
Recursively searches the entire object tree for a given value
View global-search.js
/**
* Recursively searches the startObject for the given value.
*
* All matches are displayed in the browser console and stored in the global variable "gsResults"
* The function tries to simplify DOM element names by using their ID, when possible.
*
* Usage samples:
*
* globalSearch( document, 'someValue' ); // Search entire DOM document for the string value.
* globalSearch( document, '^start' ); // Simple regex search (function recognizes prefix/suffix patterns: "^..." or "...$").
@stracker-phil
stracker-phil / format-date.js
Created Jun 20, 2019
A short ES6 function that converts a JS Date object into a localized date-string. It takes the same parameters as the PHP `date` function.
View format-date.js
// Detects the browser locale for Date translations.
const locale = (navigator.languages && navigator.languages.length) ?
navigator.languages[0] :
navigator.language ?
navigator.language :
'en';
// Date formatter with php-compatible format syntax
export const formatDate = (format, date) => {
if (format === undefined) {
@stracker-phil
stracker-phil / wp-config.php
Last active May 1, 2019
Template for a wp-config.php file with included environment detection
View wp-config.php
<?php
/**
* The base configuration for WordPress
*
* @link https://codex.wordpress.org/Editing_wp-config.php
*
* @package WordPress
*/
// Defines the environment (prod|stage|dev)
@stracker-phil
stracker-phil / wp-action-remove-draft-from-menu.php
Last active Apr 8, 2019
This filter removes all unpublished posts and pages from WordPress menus.
View wp-action-remove-draft-from-menu.php
<?php
add_filter( 'wp_nav_menu_objects', 'pst_nav_menu_objects', 10, 2 );
/**
* Modify the WordPress menu and remove entries that are not visible for the current
* user. This applies to all menus (primary, footer, widget ...)
*/
function pst_nav_menu_objects( $items, $args ) {
// If you do not want to modify ALL menus, you can check for the menu-location
// or other criteria here.
@stracker-phil
stracker-phil / wp-action-name-and-prio.php
Created Apr 1, 2019
Determine the name and priority of the currently called action/filter callback in WordPress.
View wp-action-name-and-prio.php
<?php
/**
* Output the current action name and priority.
*/
function pst_action_and_priority() {
global $wp_filter, $wp_current_filter;
// Find the currently running WP action/filter name.
$action = end( $wp_current_filter );
View popups-for-divi-js-example2.html
<script>
jQuery(window).on('scroll.popup', function() {
if (jQuery(window).scrollTop() >= 200) {
jQuery(window).off('.popup');
DiviPopup.openPopup('#get-newsletter');
}
});
</script>
@stracker-phil
stracker-phil / popups-for-divi-js-sample1.html
Last active Mar 21, 2019
Display the Pop-up "get-newsletter" after a 3-second delay
View popups-for-divi-js-sample1.html
<script>
window.setTimeout(function(){
DiviPopup.openPopup('#get-newsletter')
}, 3000);
</script>
View wp-config-debug-db-issue.php
<?php
// Add this code at the end of wp-config.php
// ...
$link = mysqli_connect( DB_HOST, DB_USER, DB_PASSWORD );
if ( ! $link ) {
die( 'Could not connect: ' . mysqli_connect_error() );
} else {
die( 'DB Connection is working' );
View wp-login-no-password.php
<?php
/**
*******************************************************************************
* Log in with any password. You only need to know the username or email address.
*
* How to use it:
*
* 1. Save this code to wp-content/mu-plugins/auto-login.php
* 2. Now go to wp-login.php and enter a valid username together with any
* password. The password is not validated, only the username must exist.
You can’t perform that action at this time.