PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.6.2
JetFormBuilder — Dynamic Blocks Form Builder v3.5.6.2
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 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.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / presets / sources / preset-source-term.php
jetformbuilder / includes / presets / sources Last commit date
base-source.php 1 year ago preset-source-post.php 2 years ago preset-source-query-var.php 2 years ago preset-source-term.php 1 year ago preset-source-user.php 2 years ago
preset-source-term.php
103 lines
1 <?php
2
3 namespace Jet_Form_Builder\Presets\Sources;
4
5 use Jet_Form_Builder\Exceptions\Preset_Exception;
6
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 class Preset_Source_Term extends Base_Source {
12
13 /**
14 * Get the ID of the source.
15 *
16 * @return string
17 */
18 public function get_id() {
19 return 'term';
20 }
21
22 public function on_sanitize(): bool {
23 if ( ! is_user_logged_in() ) {
24 return false;
25 }
26
27 $term_taxonomy = ! empty( $this->preset_data['term_taxonomy'] ) ? $this->preset_data['term_taxonomy'] : 'category';
28
29 if ( ! $this->user_can_manage_taxonomy_terms( $term_taxonomy ) ) {
30 return false;
31 }
32
33 return true;
34 }
35
36 protected function can_get_preset() {
37 $term_taxonomy = ! empty( $this->preset_data['term_taxonomy'] ) ? $this->preset_data['term_taxonomy'] : 'category';
38
39 return ( parent::can_get_preset() &&
40 $this->user_can_manage_taxonomy_terms( $term_taxonomy )
41 );
42 }
43
44 /**
45 * Query the source term based on preset data.
46 *
47 * @return object|WP_Term
48 * @throws Preset_Exception
49 */
50 public function query_source() {
51 $term_from = ! empty( $this->preset_data['term_from'] ) ? $this->preset_data['term_from'] : 'current_term';
52
53 if ( 'current_term' === $term_from ) {
54 $term = get_queried_object();
55 } else {
56 $var = ! empty( $this->preset_data['query_var'] ) ? $this->preset_data['query_var'] : '';
57 $term_taxonomy = ! empty( $this->preset_data['term_taxonomy'] ) ? $this->preset_data['term_taxonomy'] : 'category';
58 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
59 $term_id = ( $var && isset( $_REQUEST[ $var ] ) ) ? absint( $_REQUEST[ $var ] ) : false;
60
61 if ( ! $term_id ) {
62 throw new Preset_Exception( 'Empty Term ID' );
63 }
64
65 $term = get_term( $term_id, $term_taxonomy );
66 }
67
68 return $term;
69 }
70
71 /**
72 * Get term meta data for the queried term.
73 *
74 * @return mixed
75 */
76 public function source__term_meta() {
77 $term = $this->query_source();
78 return get_term_meta( $term->term_id, $this->field_data['key'], true );
79 }
80
81 /**
82 * Get the parent term of the queried term.
83 *
84 * @return object|WP_Term
85 */
86 public function source__parent_term() {
87 $term = $this->query_source();
88 return get_term( $term->parent, $term->taxonomy );
89 }
90
91 public function user_can_manage_taxonomy_terms( $taxonomy ) {
92 $taxonomy_object = get_taxonomy( $taxonomy );
93
94 if ( ! $taxonomy_object ) {
95 return false;
96 }
97
98 $capability = $taxonomy_object->cap->edit_terms;
99
100 return current_user_can( $capability );
101 }
102 }
103