PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.9
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.9
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / vendor / wpdeveloper / lib-utility / lib / class-term.php

class-term.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.9, at vendor/wpdeveloper/lib-utility/lib/class-term.php

128 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Wordpress Terms ( taxonomies ) meta manager.
4 * Moved from theme Flawless.
5 *
6 * @author Usability Dynamics, Inc. <info@usabilitydynamics.com>
7 * @package Theme
8 * @author potanin@UD
9 * @author peshkov@UD
10 */
11 namespace UsabilityDynamics {
12
13 if( !class_exists( 'UsabilityDynamics\Term' ) ) {
14
15 class Term {
16
17 /**
18 * Add meta data field to a term.
19 *
20 */
21 static public function add_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
22
23 if( current_theme_supports( 'extended-taxonomies' ) ) {
24 return add_post_meta( self::get_post_for_extended_term( $term_id )->ID, $meta_key, $meta_value, $unique );
25 }
26
27 return add_metadata( 'taxonomy', $term_id, $meta_key, $meta_value, $unique );
28 }
29
30 /**
31 * Remove metadata matching criteria from a term.
32 *
33 *
34 */
35 static public function delete_meta( $term_id, $meta_key, $meta_value = '' ) {
36
37 if( current_theme_supports( 'extended-taxonomies' ) ) {
38 return delete_post_meta( self::get_post_for_extended_term( $term_id )->ID, $meta_key, $meta_value );
39 }
40
41 return delete_metadata( 'taxonomy', $term_id, $meta_key, $meta_value );
42 }
43
44 /**
45 * Retrieve term meta field for a term.
46 *
47 */
48 static public function get_meta( $term_id, $key, $single = false ) {
49
50 if( current_theme_supports( 'extended-taxonomies' ) ) {
51 return get_post_meta( self::get_post_for_extended_term( $term_id )->ID, $key, $single );
52 }
53
54 return get_metadata( 'taxonomy', $term_id, $key, $single );
55 }
56
57 /**
58 * Update term meta field based on term ID.
59 *
60 */
61 static public function update_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
62
63 if( current_theme_supports( 'extended-taxonomies' ) ) {
64 return update_post_meta( self::get_post_for_extended_term( $term_id )->ID, $meta_key, $meta_value, $prev_value );
65 }
66
67 return update_metadata( 'taxonomy', $term_id, $meta_key, $meta_value, $prev_value );
68 }
69
70 /**
71 * {}
72 *
73 * @author potanin@UD
74 */
75 static public function get_post_for_extended_term( $term_id = false, $taxonomy = false ) {
76 global $wpdb;
77
78 if( !$term_id ) {
79 return false;
80 }
81
82 if( is_object( $term_id ) ) {
83 $term_id = $term_id->term_id;
84 $taxonomy = $taxonomy ? $taxonomy : $term_id->taxonomy;
85 }
86
87 //** Try to get taxonomy -if this term only has one relationship, it's a good guess */
88 if( !$taxonomy ) {
89 $taxonomy = $wpdb->get_col( "SELECT taxonomy FROM {$wpdb->term_taxonomy} WHERE term_id = {$term_id}" );
90
91 if( count( $taxonomy ) > 1 ) {
92 return false;
93 } else {
94 $taxonomy = $taxonomy[0];
95 }
96 }
97
98 if( !is_numeric( $term_id ) || empty( $taxonomy ) ) {
99 return false;
100 }
101
102 $post_id = $wpdb->get_var( "SELECT post_id FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE meta_key = 'extended_term_id' AND meta_value = '{$term_id}' AND post_type = '_tp_{$taxonomy}' " );
103
104 if( !$post_id ) {
105 return false;
106 }
107
108 if( $post_id ) {
109 $post = get_post( $post_id );
110 }
111
112 if( !$post ) {
113 return false;
114 }
115
116 return $post;
117
118 }
119
120 }
121
122 }
123
124 }
125
126
127
128