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(); | |
} | |
} |
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
// VALUE UNIT STRIPPING AND CONVERSION FUNCTION TOOLS | |
// By Nicolas Giethlen (aka Chmood) | |
// VARIABLES | |
$browser-fontsize-base: 16 !default; // Default browser font-size in px (unitless) | |
$pixels-per-rem: 10 !default; // Root font-size in px (unitless) | |
// FUNCTIONS |
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
var el = document.getElementById('target'); | |
function extractHexBackgroundColorFromElement(element) { | |
return getComputedStyle(element)['background-color'].split('(')[1].split(')')[0].split(',').map((x) => x.trim()).map((x) => { x = parseInt(x).toString(16); return (x.length === 1) ? '0' + x : x }).join(''); | |
} | |
console.log(extractHexBackgroundColorFromElement(el)); |
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 em2px(em) { | |
return Number(em) * Number(window.getComputedStyle(document.body).getPropertyValue('font-size').match(/\d+/)[0]); | |
} | |
console.log(em2px(2)); |
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
<?php | |
// While not foolproof, you can check the USER_AGENT string and only run that code if 'bot' does not exist. | |
if(stripos($_SERVER['HTTP_USER_AGENT'],'bot') === false){ } | |
// This would stop any bot that actually has bot in the user agent string that also does not pay attention to robots.txt. | |
// Source: https://stackoverflow.com/a/17600047/1090042 |
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
<?php | |
/*********************************** | |
* | |
* ! DISABLE COMMENTS | |
* | |
* *********************************/ | |
function df_disable_comments_post_types_support() | |
{ |
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
<?php | |
class WPSVG{ | |
function __construct(){ | |
add_action( 'admin_init', array( $this, 'add_svg_support' ) ); | |
add_action( 'admin_footer', array( $this, 'fix_svg_thumbnail_size' ) ); | |
add_filter( 'upload_mimes', array( $this, 'add_svg_mime' ) ); | |
add_filter( 'wp_check_filetype_and_ext', array( $this, 'wp_check_filetype_and_ext' ), 100, 4 ); | |
add_filter( 'wp_generate_attachment_metadata', array( $this, 'wp_generate_attachment_metadata' ), 10, 2 ); | |
add_filter( 'fl_module_upload_regex', array( $this, 'fl_module_upload_regex' ), 10, 4 ); |