Skip to content

Instantly share code, notes, and snippets.

View salvatorecapolupo's full-sized avatar
🎯
Focusing

Salvatore Capolupo salvatorecapolupo

🎯
Focusing
View GitHub Profile
@theprincy
theprincy / install.php
Created February 9, 2021 14:51 — forked from tschoffelen/install.php
A simple PHP script that automatically downloads and unzips the latest version of Wordpress in the current directory (./), so that I don't have to download it and upload it to my server through FTP manually.
<?php
echo '<pre>';
echo '<span style="color:blue">DOWNLOADING...</span>'.PHP_EOL;
// Download file
file_put_contents('wp.zip', file_get_contents('https://wordpress.org/latest.zip'));
$zip = new ZipArchive();
$res = $zip->open('wp.zip');
if ($res === TRUE) {
@marcosvpj
marcosvpj / vscode-remove-duplicate-lines.md
Last active March 22, 2024 13:41
How to remove duplicate lines in Visual Studio Code?

If the order of lines is not important##

Sort lines alphabetically, if they aren't already, and perform these steps:
(based on this related question: https://stackoverflow.com/q/1573361/3258851)

  1. Control+F

  2. Toggle "Replace mode"

  3. Toggle "Use Regular Expression" (the icon with the .* symbol)

@plugn
plugn / leet.js
Created November 16, 2017 15:34
leet.js
var leet = {
/**
* Map of conversions.
*
* @var object
*/
characterMap: {
'a': '4',
'b': '8',
@salvatorecapolupo
salvatorecapolupo / noduplicates.sql
Last active September 9, 2022 06:29
WordPress find post duplicates via MySQL query - Used to remove duplicated posts from WordPress - i.e https://www.lipercubo.it, https://capolooper.it
SELECT a.ID, a.post_title, a.post_type, a.post_status
FROM wp_posts AS a
INNER JOIN (
SELECT post_title, MIN( id ) AS min_id
FROM wp_posts
WHERE post_type = 'post'
AND post_status = 'publish'
GROUP BY post_title
HAVING COUNT( * ) > 1
) AS b ON b.post_title = a.post_title
@devinsays
devinsays / example-ajax-enqueue.php
Last active October 4, 2023 13:09
Simple WordPress Ajax Example
<?php
function example_ajax_enqueue() {
// Enqueue javascript on the frontend.
wp_enqueue_script(
'example-ajax-script',
get_template_directory_uri() . '/js/simple-ajax-example.js',
array( 'jquery' )
);
@bateller
bateller / FizzBuzz.php
Last active February 28, 2024 11:00
FizzBuzz solution in PHP
<?php
if (php_sapi_name() === 'cli') $lb = "\n";
else $lb = "<br />";
for ($i = 1; $i <= 100; $i++)
{
if ($i % 15 === 0) {
echo "FizzBuzz $lb";
}
@seoagentur-hamburg
seoagentur-hamburg / .htaccess
Last active March 28, 2024 16:24
UPDATE 2024/03: Perfect .htaccess file for highspeed and security. You can use it for every WordPress-Website without problems. Highspeed and Security - testet on hundreds of Websites. If you are using a WordPress Multisite, change the last part of this file.
########################################################################
# OPTIMAL .htaccess FILE FOR SPEED AND SECURITY @Version 2.0.9 - 03/2024
# ----------------------------------------------------------------------
# @Author: Andreas Hecht
# @Author URI: https://seoagentur-hamburg.com
# License: GNU General Public License v2 or later
# License URI: http://www.gnu.org/licenses/gpl-2.0.html
########################################################################
@anttiviljami
anttiviljami / wp-admin-modal-dialog.php
Last active January 5, 2024 14:25
WordPress admin modal dialog example
<?php
// enqueue these scripts and styles before admin_head
wp_enqueue_script( 'jquery-ui-dialog' ); // jquery and jquery-ui should be dependencies, didn't check though...
wp_enqueue_style( 'wp-jquery-ui-dialog' );
?>
<!-- The modal / dialog box, hidden somewhere near the footer -->
<div id="my-dialog" class="hidden" style="max-width:800px">
<h3>Dialog content</h3>
<p>This is some terribly exciting content inside this dialog. Don't you agree?</p>
@julianxhokaxhiu
julianxhokaxhiu / pagespeed_optimize_images.sh
Last active February 19, 2024 05:04
Recursively optimize all PNG and JPG files wherever they are from the script position and inner ( based on OPTING, PNGCRUSH, ADVANCECOMP and JPEGOPTIM )
#!/bin/bash
# Improved as per feedback from @pascal - https://gist.github.com/julianxhokaxhiu/c0a8e813eabf9d6d9873#gistcomment-3086462
find . -type f -iname "*.png" -exec optipng -nb -nc {} \;
find . -type f -iname "*.png" -exec advpng -z4 {} \;
find . -type f -iname "*.png" -exec pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --strip-all {} \;
@scottopolis
scottopolis / wp-api-user-meta.php
Last active April 18, 2020 19:13
Add user meta to the WP-API
<?php
/* Adds all user meta to the /wp-json/wp/v2/user/[id] endpoint */
function sb_user_meta( $data, $field_name, $request ) {
if( $data['id'] ){
$user_meta = get_user_meta( $data['id'] );
}
if ( !$user_meta ) {
return new WP_Error( 'No user meta found', 'No user meta found', array( 'status' => 404 ) );
}