forked from soflyy/wp-all-import-action-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmxi_single_category.php
50 lines (43 loc) · 1.44 KB
/
pmxi_single_category.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* ==========================================
* Filter: pmxi_single_category
* ==========================================
*
* @param $term_into - ?.
* @param $tx_name - The taxonomy name.
*
*/
add_filter( 'pmxi_single_category', 'wpai_pmxi_single_category', 10, 2 );
function wpai_pmxi_single_category( $term_into, $tx_name ) {
// Code here.
}
// ----------------------------
// Example uses below
// ----------------------------
/**
* Example: Only import existing hierarchical categories
*
*/
add_filter( 'pmxi_single_category', 'wpai_pmxi_single_category', 10, 2 );
function wpai_pmxi_single_category( $term_into, $tx_name ) {
// here we can check is term exists
$term = empty($term_into['parent']) ? term_exists( $term_into['name'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_name, $term_into['parent'] );
// if term doesn't exists we can return false, so WP All Import will not create it
if ( empty($term) and !is_wp_error($term) ) {
return false;
}
return $term_into;
}
/**
* Example: Only import existing Single Categories
*
*/
add_filter( 'pmxi_single_category', 'wpai_pmxi_single_category', 10, 2 );
function wpai_pmxi_single_category( $ctx, $tx_name ) {
$term = is_exists_term($ctx['name'], $tx_name);
if ( empty($term) and ! is_wp_error($term) ) {
$ctx = false;
}
return $ctx;
}