This file contains hidden or 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
This is a collection of my most used or most useful PHP and JS snippets | |
**Disclaimer, I didn't write most of these - I just curated them over the years** |
This file contains hidden or 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
|
This file contains hidden or 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 | |
// For whatever reason, returning `false` isn't good enough. 🤷♀️ | |
add_filter('get_user_option_elementor_enable_ai', fn () => '0', PHP_INT_MAX); |
This file contains hidden or 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 | |
/** | |
* Preload Elementor background images if they are among the first elements on a page. | |
* | |
* @return void | |
*/ | |
function sitecare_preload_elementor_background_images(): void { | |
if ( ! did_action( 'elementor/loaded' ) ) { |
This file contains hidden or 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 | |
/** | |
* Strip `width` & `height` attributes from `img` elements. | |
* | |
* @file functions.php | |
*/ | |
function remove_width_and_height_attribute( $html ) { | |
return preg_replace( '/(height|width)="\d*"\s/', "", $html ); | |
} | |
This file contains hidden or 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
class ActivityTracker { | |
constructor(totalTime, checkTime, metrikaId, debug = false) { | |
this.events = [ | |
"touchmove", | |
"blur", | |
"focus", | |
"focusin", | |
"focusout", | |
"load", | |
"resize", |
This file contains hidden or 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 wpai_import_paragraph_block($paragraph_text){ | |
$output = ""; | |
$output .= '<!-- wp:paragraph \{"placeholder":"'.$paragraph_text.'"\} -->'; | |
$output .= "\n"; | |
$output .= '<p>'.$paragraph_text.'</p>'; | |
$output .= "\n"; | |
$output .= '<!-- /wp:paragraph -->'; | |
return $output; |
This file contains hidden or 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
/** | |
* Класс для менеджера событий (целей) | |
* @constructor | |
*/ | |
function EventManager() { | |
this.init(); | |
this.initEvents(); | |
} | |
/** |
This file contains hidden or 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 | |
add_filter( 'wp_all_import_single_image_uploads_dir', 'wpai_wp_all_import_single_image_uploads_dir', 10, 6 ); | |
function wpai_wp_all_import_single_image_uploads_dir( $uploads, $image_url, $articleData, $current_xml_node, $import_id, $post_id ) { | |
$position = strpos($image_url, 'uploads'); | |
$result = substr($image_url, $position + 7,8); //eg: `/2021/05` | |
$uploads['path'] = $uploads['basedir'].$result; | |
$uploads['url'] = $uploads['baseurl'].$result; | |
$uploads['subdir']=$result; |
This file contains hidden or 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 | |
/** | |
* Vary LCP Image Optimizations WordPress Plugin. | |
* | |
* @package VaryLcpImageOptimizations | |
* @author Weston Ruter, Google | |
* @license GPL-2.0-or-later | |
* @copyright 2023 Google Inc. | |
* | |
* @wordpress-plugin |
NewerOlder