Skip to content

Instantly share code, notes, and snippets.

View maciejbis's full-sized avatar

Maciej Bis maciejbis

View GitHub Profile
@maciejbis
maciejbis / whatissoslow.php
Created October 15, 2023 17:00 — forked from Viper007Bond/whatissoslow.php
WordPress: Times how long it takes each filter and action to run and displays results at the end of the page. Quick and dirty.
<?php
/**
* This little class records how long it takes each WordPress action or filter
* to execute which gives a good indicator of what hooks are being slow.
* You can then debug those hooks to see what hooked functions are causing problems.
*
* This class does NOT time the core WordPress code that is being run between hooks.
* You could use similar code to this that doesn't have an end processor to do that.
*
@maciejbis
maciejbis / filter_permastructure_post.php
Last active October 25, 2022 14:27
Filter default post & term permalinks (Permalink Manager)
<?php
/**
* 1A. How to programmatically modify post permalink formats (permastructures)
*
* @param string $permastructure The permastructure string used when default custom permalink is generated.
* @param WP_Post|WP_Term $post Post or term object
* @return string The new, filtered permastructure string used when default custom permalink is generated (for new posts or existing ones if "Regenerate/reset" tool is used)
*/
function pm_filter_post_permastructure($permastructure, $post) {
// Filter only 'Post' permalinks
@maciejbis
maciejbis / pm_gsk.php
Created June 16, 2021 12:33
Permalink Manager - Site Kit by Google (compatibility snippet)
<?php
function pm_fix_googlesitekit_urls() {
global $permalink_manager_ignore_permalink_filters;
if(is_user_logged_in() && isset($_GET['permaLink']) && class_exists('Permalink_Manager_Core_Functions')) {
$old_url = trim(esc_url_raw($_GET['permaLink']), '/');
$post = Permalink_Manager_Core_Functions::detect_post(null, $old_url, true);
if(!empty($post->ID)) {
@maciejbis
maciejbis / permalink-manager-qtranslatext.php
Last active September 22, 2023 21:00
Permalink Manager & qTranslate-XT support
@maciejbis
maciejbis / wp-job-manager-field-editor.php
Last active November 12, 2018 22:22
WP Job Manager Field Editor - support custom fields
<?php
function pm_replace_job_meta_tags($default_uri, $native_slug, $element, $slug, $native_uri) {
if(function_exists('get_job_field') && !empty($element->ID)) {
$fields = array(
'first-field', // in Permalink Manager Permastructures settings it will be '%__first-field%'
'second-field' // in Permalink Manager Permastructures settings it will be '%__second-field%'
);
foreach($fields as $field) {
@maciejbis
maciejbis / rewrite-wordpress-uploads-urls.php
Last active March 15, 2024 01:04
Rewrite Wordpress uploads URLs
<?php
/*
* Plugin Name: Rewrite Wordpress uploads URLs
* Plugin URI: https://permalinkmanager.pro?utm_source=plugin
* Description: Replace /wp-content/uploads/YYYY/MM/ with different directory
* Version: 1.0.0
* Author: Maciej Bis
* Author URI: http://maciejbis.net/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt