Skip to content

Instantly share code, notes, and snippets.

View lenasterg's full-sized avatar

Lena Stergatou lenasterg

View GitHub Profile
@lenasterg
lenasterg / lsfilt_hide_empty_widget_title.php
Created February 11, 2026 10:13
Validates the widget title and returns it only if it contains non-whitespace characters.
/**
* Validates the widget title and returns it only if it contains non-whitespace characters.
*
* This filter checks if the title is not empty and contains at least one
* character that is not a space (using the \S regex pattern). If the title
* consists only of whitespace, it returns an empty string to prevent
* empty titles from rendering.
*
* @param string $title The original widget title.
* @return string The original title if it has content, otherwise an empty string.
@lenasterg
lenasterg / ls-multisite-w3tc-admin-controls.php
Created May 27, 2025 12:51
Restrict W3 Total Cache admin bar, remove help tabs and meta boxes in WordPress Multisite for non-super admins
<?php
/**
* Customizes W3 Total Cache admin interface for non-super admin users in multisite WordPress environments.
*
* This code provides three main functionalities:
* 1. Customizes access to W3 Total Cache admin bar menu items by defining specific user capabilities
* for each menu item using the 'w3tc_capability_admin_bar' and 'w3tc_capability_admin_bar_*' filters.
* In multisite, site administrators with 'manage_options' can access the main W3TC menu and certain sub-menus,
* while restricted items (e.g., 'Purge All Caches', 'General Settings') require 'setup_network' (super admin).
* In single-site environments, the default capability ('manage_options') is retained for all menu items.
@lenasterg
lenasterg / res_admin_crossword-admin.js
Last active May 3, 2019 08:08
wha-crossword plugin changed files
jQuery(document).ready(function ($) {
var slider = $('.range-slider'),
range = $('.range-slider__range'),
value = $('.range-slider__value');
slider.each(function(){
value.each(function(){
var value = $(this).prev().attr('value');
$(this).html(value + 'px');
@lenasterg
lenasterg / ls_hideYouTubeRelatedVideos.php
Created June 7, 2018 09:11
Hide YouTube Related Videos from wordpress embeds. Add this code to your theme's functions.php file or better into a custom plugin.
//Hide YouTube Related Videos
add_filter( 'embed_oembed_html', 'sch_embed_oembed_html', 99, 4 );
function sch_embed_oembed_html($data, $url, $args = array()) {
if ( false !== strpos( $url, 'youtu' ) ) {
//Autoplay
$autoplay = strpos($url, "autoplay=1") !== false ? "&autoplay=1" : "";
//Setup the string to inject into the url
$str_to_add = apply_filters("sch_extra_querystring_parameters", "wmode=transparent&amp;") . 'rel=0';
@lenasterg
lenasterg / ls_remove_unwanted from json.php
Created May 30, 2018 09:55
PHP JSON - Remove unwanted keys from json
/**
* Removes unwanted keys from JSON string
* @param string $response
* @param array $exclude
* @return string
*
*
*/
function ls_remove_unwanted_from_json($response , $exclude) {
@lenasterg
lenasterg / ls_filter_sow_slider_add_hide.php
Created March 13, 2018 16:07
Extend Siteorigin slider (https://wordpress.org/plugins/so-widgets-bundle/) with hide frames functionality
<?php
/**
*
* @param array $form_options
* @param type $widget
* @return array
*/
function ls_extend_sow_slider_form_add_hide_frame($form_options, $widget) {
$form_options['frames']['fields']['hide_frame'] = array('type' => 'checkbox',
@lenasterg
lenasterg / ls_user_id_colunm.php
Last active March 6, 2023 22:39
Adds a sortable user id colunn into the WordPress users admin table, right after the checkbox. In a multisite WordPress installation it displays the ID only in network users admin page.
<?php
/**
* Add the user id column after the user's checkbox
* @param array $array
* @param int $index
* @param array $insert
* @return array
*/
function ls_array_insert($array, $index, $insert) {
return array_slice($array, 0, $index, true) + $insert + array_slice($array, $index, count($array) - $index, true);
@lenasterg
lenasterg / ls_user_id_colunm.php
Created February 14, 2018 14:12
Sometimes it is useful to find the user_id of eache user you have in your WordPress site. In order to have that kind of functionality, you can add the following code in your theme’s functions.php
/**
* Add the user id column after the user's checkbox
* @param array $array
* @param int $index
* @param array $insert
* @return array
*/
function ls_array_insert($array, $index, $insert) {
return array_slice($array, 0, $index, true) + $insert + array_slice($array, $index, count($array) - $index, true);
@lenasterg
lenasterg / bp-signups_view_overide.php
Last active December 11, 2017 10:29
Filter the WP Users List Table views to override 'bp-signups' with 'new-user-approve-admin'.
<?php
/**
* Filter the WP Users List Table views to override 'bp-signups' with 'new-user-approve-admin'.
*
*
* @param array $views WP List Table views.
* @return array The views with the signup view replaced with 'new-user-approve-admin' link.
* @author lenasterg
*/
function ls_change_signup_filter_view_to_new_user_approve_admin($views = array()) {
@lenasterg
lenasterg / export-opml.php
Created August 3, 2017 09:15
Exports blogroll plugins from a wordpress site.
<?php
require_once( dirname( __FILE__ ) . '/wp-load.php' );
header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
/*
Plugin Name: Export Blogroll in OPML Format
Plugin URI: http://w3.ipublicis.com/
Description: Exports your public blogroll in OPML format to a file on blog root.
Version: 1.0
Author: Lopo Lencastre de Almeida - iPublicis.com