Skip to content

Instantly share code, notes, and snippets.

@esedic
esedic / oc_mods.js
Created April 25, 2024 17:38
JavaScript for triggering Clear & Refresh modifications buttons
// 1. Clear mods
const chkBoxes = document.querySelectorAll('#tab-general .table tbody tr td:first-child input[type="checkbox"]');
chkBoxes.forEach(
chkBox => {
chkBox.checked = true;
}
);
const clrBtn = document.querySelector('.page-header > .container-fluid > .pull-right > a[data-original-title="Clear"]');
clrBtn.click();
@esedic
esedic / yt_lightbox.html
Created April 25, 2024 08:40
Lightbox for 'Panel Slider', 'Slideshow' and 'Overlay Slider' Yootheme Pro Element
<!-- Yootheme Pro sliders with lightbox -->
<!--
1. For the 'Overlay Slider' or 'Panel Slider' Element:
-Add Link to the Image which has to be shown in the Lightbox
-Add element Attribute:
uk-lightbox="toggle: .uk-slider-items a"
2. For the 'SlideShow' Element:
-Add Link to the Image which has to be shown in the Lightbox
@esedic
esedic / gist:8f50ddfb2497961434bf891ac2c6395d
Created April 17, 2024 12:29 — forked from vdrover/gist:ebdbf65f5f4e9ee5545255e9c36bd422
Wordpress - Backdate scheduled posts
// Adds a meta box to the post editing screen for changing the post's publication
// date and time after it has initially been published.
// Only visible to administrators.
// Place in functions.php file.
function cdap_add_meta_box() {
// Check if the current user is an administrator
if (current_user_can('administrator')) {
add_meta_box(
'cdap_meta_box', // ID of the meta box
@esedic
esedic / removeel.js
Created March 8, 2024 18:19
Find and remove DOM elements with JavaScript
/**
* Find all the elements, that match any of the classes that are specified in the array
* and remove all the matching elements from the DOM
*/
// Step 1: Define the array of class names
const classesToRemove = ['elem1', 'elem2'];
// Step 2: Create the selector string
// This will create a string like ".class1,.class2,.class3"
@esedic
esedic / wpcli.txt
Created March 7, 2024 12:23
Install WP-CLI and check if WP-CRON works
1. Download wp-cli.phar using wget or curl:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
2. Check if it works:
php wp-cli.phar --info
3. To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. For example:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
@esedic
esedic / sameday.sql
Created February 29, 2024 11:08
Select items/articles that were created on the same day
SELECT * FROM mytable WHERE MONTH(created) = MONTH(CURDATE()) AND DAY(created) = DAY(CURDATE()));
@esedic
esedic / map.js
Created February 9, 2024 11:01
Javascirpt if/else vs switch vs object mapping
// Scenario, wher we need to determine a discount based on a customer's loyalty level
// 1. Traditional if-else approach:
function calculateDiscount(loyaltyLevel) {
console.time('if else time');
if (loyaltyLevel === 'GOLD') {
applyGoldDiscount();
} else if (loyaltyLevel === 'SILVER') {
applySilverDiscount();
} else if (loyaltyLevel === 'BRONZE') {
@esedic
esedic / mysqlpw.txt
Created February 7, 2024 13:30
Change MySQL root password
sudo mysql
// get MySQL user accounts
SELECT user,authentication_string,plugin,host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
// you should see the change
@esedic
esedic / wphook.php
Created January 30, 2024 16:32
WordPress hook inside another hook
/*
To use one hook inside another hook in WordPress, you can simply add the second hook as a callback function to the first hook
For example, let's say you want to add a custom function to the init hook, which in turn uses the wp_enqueue_scripts
hook to enqueue some scripts. You can do it like this:
*/
<?php
function my_init_function() {
// do some initialization here
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts_function' );
/*
I would like to get a plugin code for Wordpress which goes trough all posts, foreach trough each of them,
get an short meta description from main description using Microsoft OpenAI API access.
This plugin / code should be run trough CRON commands. Can you generate code for me?
-------------------------------------------------------------------------------------
Certainly, I can help you with a basic outline for a WordPress plugin that does what you've described.
Please note that you'll need to have the Microsoft OpenAI API credentials and the appropriate library installed on your server.
Also, you should handle error cases and edge cases based on your specific needs.
Here's a basic example using PHP for the plugin: