Skip to content

Instantly share code, notes, and snippets.

View rwsite's full-sized avatar
✌️

Aleksei Tikhomirov rwsite

✌️
View GitHub Profile
@rwsite
rwsite / Editor.php
Last active June 7, 2024 11:40
Livewire 3 component - TinyMce editor
<?php
/**
* Livewire 3 component - TinyMce editor
*
* 1. Add component to LiveWire folder in project
* 2. Register component, for example add node to AppServiceProvider boot method: Blade::component('editor', Editor::class);
* 3. Register route for file uploader :
* Route::middleware(['web', 'auth'])->post('/file/upload', function (Request $request) {
* $disk = $request->disk ?? 'public';
* $folder = $request->folder ?? 'editor';
@rwsite
rwsite / functions.php
Created June 3, 2024 11:48
woo2iiko - вывод бонусного баланса для зарегистрированных пользовтаелей
function true_logged_in_user_content( $atts, $content = null ) {
if(!class_exists('\iiko\bonuses\Bonuses')){
return 'Ошибка вывода баланса. woo2iiko не подключен';
}
$bonuses = \iiko\bonuses\Bonuses::getInstance();
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) {
$balance = $bonuses->get_user_balances();
return 'Ваш бонусный баланс: ' . ($balance ?: '0');
@rwsite
rwsite / example.php
Last active May 24, 2024 11:13
Вывод определенных файлов из папки по шаблону
<?php
/**
* Вывод / Удаление файлов из директории по шаблону
*/
// создание
foreach ( array_fill(0, 6, '// silence is golden') as $key => $value) {
if (!file_exists("АВР № $key.php")) {
file_put_contents("АВР № $key.php", $value);
}
@rwsite
rwsite / wp-autoloader-psr4.php
Last active March 24, 2024 23:51
Wordpress class autoloder with PSR4 standart.
spl_autoload_register(function ($className){
if ( strpos( $className, __NAMESPACE__ ) !== 0 ) {
return;
}
$className = str_replace(__NAMESPACE__ . '\\', 'includes\\', $className);
$path = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($className, '\\', DIRECTORY_SEPARATOR) . '.php';
if (is_readable($path)) {
require_once $path;
}
});
@rwsite
rwsite / php-8-attribute-example.php
Last active January 23, 2024 20:38
Пример создания и использования атрибутов PHЗ 8
<?php
/**
* Пример создания и использования атрибутов PHP 8
*/
// Объявление атрибута
#[Attribute]
final class MyAttribute
{
public $value;
@rwsite
rwsite / breadcrumb-category.php
Last active November 19, 2023 22:32
get woocommerce categories sorting by order
<ul>
<?php $term_children = get_term_children( get_queried_object()->term_id, 'product_cat' ); ?>
<?php if($term_children) {
$sorted=[];
foreach ( $term_children as $child ) {
$child_category = get_term_by( 'id', $child, 'product_cat' );
$meta = get_term_meta($child_category->term_id,'order', true);
$child_category->position = intval($meta);
$sorted[$meta] = $child_category;
@rwsite
rwsite / woo2iiko-functions
Created September 18, 2023 12:31
remove DeliveryDurationInMinutes
add_action('woocommerce_before_thankyou', function ($wc_order_id){
$wc_order = wc_get_order($wc_order_id);
if (empty($wc_order) || $wc_order->has_status('failed')) {
return;
}
$wc_order->update_meta_data('deliveryDurationInMinutes', '');
$wc_order->save_meta_data();
}, 5);
@rwsite
rwsite / wp-theme.php
Created December 28, 2022 01:46
Wordpress Autoload classes
/**
* WordPress Autoload classes.
*/
spl_autoload_register( function ( $full_class_name ) { //phpcs:ignore PEAR.Functions.FunctionCallSignature
if ( strpos( $full_class_name, __NAMESPACE__ ) !== 0 ) { // . '\Core'
return; // Not in the plugin namespace, don't check.
}
$full_class_name = strtolower( str_replace( '_', '-', $full_class_name ) );
$class_parts = explode( '\\', $full_class_name );
unset( $class_parts[0] ); // Unset the __NAMESPACE__.
@rwsite
rwsite / class-wp-ajax-example.php
Last active December 21, 2022 22:48
WP AJAX Example class
<?php
// WP AJAX example
class WP_AJAX_Example{
/**
* Add WP actions. Must be called only once.
* @return void
*/
public function add_actions(){
add_filter('wc_iiko_product', function (ProductArg $data, \iiko\classes\Product $iiko_product ){
if(!empty($iiko_product->tags) && false !== strpos($iiko_product->tags, 'Избранные' )) {
$data->featured = true;
}
return $data;
}, 10, 2 );