Skip to content

Instantly share code, notes, and snippets.

View Prroffessorr's full-sized avatar
🏡
In search of incredible

Andrey Prroffessorr

🏡
In search of incredible
View GitHub Profile
@Prroffessorr
Prroffessorr / parser.php
Created May 16, 2022 17:31
fansmetrics.com - parser example
<?php
function get_models_for_parsing($driver, $site_url, $settings, $only_free){
$driver->get($site_url);
$driver->wait(180)->until(
Facebook\WebDriver\WebDriverExpectedCondition::urlContains($site_url)
);
//get source form page
@Prroffessorr
Prroffessorr / index.php
Last active May 9, 2022 16:55
Chromedriver - how to crach porn site
<?php
require 'vendor/autoload.php';
include("vendor/anticaptcha-php-master/anticaptcha.php");
include("vendor/anticaptcha-php-master/recaptchaV2proxyless.php");
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
$chrome_options = new \Facebook\WebDriver\Chrome\ChromeOptions();
@Prroffessorr
Prroffessorr / 1 functions.php
Last active September 29, 2021 08:34
Retrieving a list of posts by tag_id (wordpress)
<?php
function show_posts_by_tags($tag_id, $post_id, $post_per_page, $orderby, $order){
$params = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => $orderby,
'order' => $order,
'posts_per_page' => $post_per_page,
'tag_id' => $tag_id,
'post__not_in' => array($post_id),
@Prroffessorr
Prroffessorr / 1 Form.html
Created September 12, 2021 14:23
Sending a form attachment using wp_mail()
<form action="" method="post" class="block-form" enctype="multipart/form-data">
<h4 class="form-heading"><?php _e("Have an idea? Let’s discuss!","Inmost"); ?></h4>
<div class="d-flex flex-column form-item">
<label class="label-form" for="email"><?php _e("Email","Inmost"); ?></label>
<!--Email-->
<input class="input-form" type="email" name="email" id="email" pattern="^(0|[1-9][0-9]*)$" placeholder="<?php _e("Email*","Inmost"); ?>" required>
<p class="message-error"><?php _e("This field is required","Inmost"); ?></p>
</div>
<div class="form-item">
<!--Phone number-->
@Prroffessorr
Prroffessorr / 1 index.php
Last active July 9, 2021 14:38
Получение категории товара на странице магазина файл(archive-product.php)
<?php $terms_post = get_the_terms( $the_query->ID , 'product_cat' ); ?>
<div>
<?php echo _e( 'Category', 'woocommerce' ) ?>: <?php
$iterator=1;
foreach ($terms_post as $term_cat): echo $term_cat->name;
if(count($terms_post)>1 && $iterator<count($terms_post)):
echo ", ";
endif; $iterator++;
endforeach; ?>
</div>
@Prroffessorr
Prroffessorr / 1 index.php
Last active July 9, 2021 11:17
Вывод списка категорий с помощью плагина ACF. Настройки поля (Тип поля: Таксономия. Таксономия: Категория. Возвращаемое значение: ID Термина)
<?php
//Первый вариант с настройкой отображения
$args = array(
'orderby'=> 'menu_order',
'order'=>'ASC',
'hide_empty'=> true,
'include'=> get_field("main_woo_category"),
'parent'=> 0,
);
$category_products = get_terms( 'product_cat', $args );
@Prroffessorr
Prroffessorr / 1 functions.php
Created June 1, 2021 14:09
WordPress Пример фильтрации с множественными значения (Множество параметров, Отображение в начале списка в зависимости от значения, Строгое следования условиям )
<?php
//Все такосномии этом примере были созданы отедельно. в WP таких изначально нет. Имейте это в виду
//Получам все параметры (В нашем случае это все массивы, поэтому сначала их нужно будет подготовить к работе)
$clubs_city = $_POST['city'];
$clubs_metro = $_POST['metro'];
$clubs_ages = $_POST['ages'];
$clubs_price = $_POST['price'];
//Получаем _clubs_organization_adress_metro
@Prroffessorr
Prroffessorr / 1 functions.php
Created June 1, 2021 14:00
Wordpress. Как создать свой фильтр для постов (Выбор по нескольким параметрам) Carbon fields + WP_query
<?php
//Добавление своего типа поста с полной настройкой.
add_action('init', 'activities_init');
function activities_init() {
$labels = array(
'name' => __('Мероприятия'),
'singular_name' => __('Мероприятие'),
'add_new' => __('Добавить новое'),
'all_items' => __('Все Мероприятия'),
@Prroffessorr
Prroffessorr / 1 index.php
Created June 1, 2021 13:12
AJAX Загрузка постов по скролу. WordPress (Примечание: для корректной работы wp_localize_script, необходимо чтобы у вас был подключен wp_head()). Иначе будут ошибки
<?php
$posts_id = 3; //получаем id рубрики. Любым удобным способом
$count_of_posts = 2; //кол-во выводимых элементов
$paged = get_query_var('paged', 1);//Получаем текущую страницу
if(!empty($id)){
$get_posts = new WP_Query( "category__in=$posts_id&posts_per_page=$count_of_posts&paged=$paged" );
}
else{
$get_posts = new WP_Query( "category__in=1&posts_per_page=$count_of_posts&paged=$paged" );
} ?>
@Prroffessorr
Prroffessorr / 1 functions.php
Created May 26, 2021 07:31
Ускорения сайта WP самостоятельно (Замена <iframe> Youtube, на превью с загрузкой видео после нажатия)
<?php
//Асинхронная загрузка видео YouTube (Примимает такие параметры: ссылка на видео и CSS классы)
function lazy_iframe($youtube_url, $css_class){
//Получение уникального идетнификатора для видео
preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $youtube_url, $matches);
if(isset($matches[2]) && $matches[2] != ''){
$YoutubeCode = $matches[2];}
?>
<iframe class="<?php echo $css_class; ?>"
src="<?php echo $youtube_url; ?>&amp;controls=0&amp;showinfo=0&amp;autoplay=1"