This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * FROM mytable WHERE MONTH(created) = MONTH(CURDATE()) AND DAY(created) = DAY(CURDATE())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: clone the main repo: | |
git clone sample.com/component.git | |
Get inside the cloned repo cd folder_name. Now you have a working directory with latest version pulled | |
and you want to move back to a specific commit id, here's how you can do it: | |
Step 2: | |
git reset --hard 9a36b9e79tbb9132c7 # (takes you back to that commit) | |
Step 3: | |
git clean -df # (cleans any untracked files/folders) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeParamAndRefresh(paramToRemove) { | |
const url = new URL(window.location.href); | |
if (url.searchParams.has(paramToRemove)) { | |
url.searchParams.delete(paramToRemove); | |
// Update the URL in the address bar without reloading | |
window.history.pushState({}, '', url); | |
// Now, reload the page | |
window.location.reload(); | |
} | |
} |
NewerOlder