Last active
April 11, 2023 09:45
-
-
Save mihdan/268de9c68e717b8514e7995f231ab3d5 to your computer and use it in GitHub Desktop.
Соотношение категорий из YML и сайт в плагине WPAllImport
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 | |
/** | |
* Plugin Name: Mihdan: WP All Import Extended | |
* Description: Патчим плагин под наши нужды - хуюжды, чтобы ломать сайт-хуяйт от пользователя-хуёльзователя по имени админ-хуидмин | |
* Plugin URI: https://roomble.com/shop | |
* Author: Mikhail Kobzarev | |
* Author URI: https://roomble.com/shop | |
* Version: 2.1.0 | |
*/ | |
define( 'MIHDAN_RELATIONS', dirname(__FILE__) . '/relations/' ); | |
/** | |
* This hook is called after WP All Import creates a post | |
* @param $post_id | |
* | |
* @link http://www.wpallimport.com/documentation/developers/action-reference/ | |
*/ | |
function mihdan_pmxi_saved_post( $post_id ) { | |
$relations_id = 0; | |
// Если импорт запущен кроном, то import_id берем из переменной запроса $_GET['import_id'] | |
if ( isset( $_GET['import_id'] ) ) { | |
$relations_id = $_GET['import_id']; | |
} | |
// Если импорт запущен из админки, то import_id берем из переменной запроса $_GET['id'] | |
if ( isset( $_GET['id'] ) ) { | |
$relations_id = $_GET['id']; | |
} | |
$relations_id = absint( $relations_id ); | |
// Если нет файла соотношений рубрик | |
if ( ! file_exists( MIHDAN_RELATIONS . $relations_id . '.php' ) ) { | |
return; | |
} | |
include MIHDAN_RELATIONS . $relations_id . '.php'; | |
// Получить список категорий из метаполя (разделитель запятая) | |
$categories = get_post_meta( $post_id, '_product_categories', true ); | |
if ( ! empty( $categories ) ) { | |
// На потом | |
//$categories = explode( ',', $categories ); | |
// Если есть соотношение категории клиента к нашим | |
if ( isset( $relations[ $categories ] ) ) { | |
$c = $relations[ $categories ]; | |
// Дефолтная категория | |
} else if ( isset( $relations['default'] ) ) { | |
$c = $relations['default']; | |
} else { | |
$c = 0; | |
} | |
// Присвоить новые категории | |
wp_set_post_terms( $post_id, $c, 'product_cat', false ); | |
// Удалить метаполе | |
delete_post_meta( $post_id, '_product_categories' ); | |
} | |
} | |
add_action( 'pmxi_saved_post', 'mihdan_pmxi_saved_post' ); | |
/** | |
* Позволяет получать данные из русских атрибутов {param[@name="Цвет"]} | |
* | |
* @param $is_enabled | |
* | |
* @return bool | |
*/ | |
function roomble_is_xml_preprocess_enabled( $is_enabled ) { | |
return false; | |
} | |
add_filter( 'is_xml_preprocess_enabled', 'roomble_is_xml_preprocess_enabled', 10, 1 ); | |
// eof; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment