Skip to content

Instantly share code, notes, and snippets.

View drinkmaker's full-sized avatar
🏠
Working from home

Alexander Khmelnitskiy drinkmaker

🏠
Working from home
View GitHub Profile
@drinkmaker
drinkmaker / wp-get-widget-instance.php
Created February 3, 2020 15:20 — forked from cyberhobo/wp-get-widget-instance.php
Get a WordPress registered widget instance settings.
<?php
function get_widget_instance( $widget_id ) {
global $wp_registered_widgets;
if ( empty( $wp_registered_widgets[$widget_id]['callback'] ) )
return array();
/** @var WP_Widget $widget */
$widget = $wp_registered_widgets[$widget_id]['callback'][0];
@drinkmaker
drinkmaker / str_truncate.php
Created July 19, 2019 08:02
A PHP function to truncate a string either it contains HTML or not
/**
* Truncates text.
*
* Cuts a string to the length of $length and replaces the last characters
* with the ending if the text is longer than length.
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param boolean $exact If true, $text will not be cut mid-word
<?php
global $wp_embed;
$video_url = 'https://www.youtube.com/watch?v=b7mixrO2lzA';
echo $wp_embed->run_shortcode( '[embed]' . $video_url . '[/embed]' );