1 | <?php |
||||
2 | /** |
||||
3 | * Functions |
||||
4 | * |
||||
5 | * @package LSX Team |
||||
6 | * @author LightSpeed |
||||
7 | * @license GPL3 |
||||
8 | * @link |
||||
9 | * @copyright 2016 LightSpeed |
||||
10 | */ |
||||
11 | |||||
12 | /** |
||||
13 | * Add our action to init to set up our vars first. |
||||
14 | */ |
||||
15 | function lsx_team_load_plugin_textdomain() { |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
16 | load_plugin_textdomain( 'lsx-team', false, basename( LSX_TEAM_PATH ) . '/languages' ); |
||||
17 | } |
||||
0 ignored issues
–
show
|
|||||
18 | add_action( 'init', 'lsx_team_load_plugin_textdomain' ); |
||||
19 | |||||
20 | /** |
||||
21 | * Wrapper function around cmb2_get_option |
||||
22 | * @since 0.1.0 |
||||
0 ignored issues
–
show
|
|||||
23 | * @param string $key Options array key |
||||
0 ignored issues
–
show
|
|||||
24 | * @param mixed $default Optional default value |
||||
0 ignored issues
–
show
|
|||||
25 | * @return mixed Option value |
||||
26 | */ |
||||
27 | function team_get_options() { |
||||
0 ignored issues
–
show
|
|||||
28 | $options = array(); |
||||
29 | if ( function_exists( 'tour_operator' ) ) { |
||||
0 ignored issues
–
show
|
|||||
30 | $options = get_option( '_lsx-to_settings', false ); |
||||
31 | } else { |
||||
32 | $options = get_option( '_lsx_settings', false ); |
||||
33 | |||||
34 | if ( false === $options ) { |
||||
0 ignored issues
–
show
|
|||||
35 | $options = get_option( '_lsx_lsx-settings', false ); |
||||
36 | } |
||||
37 | } |
||||
38 | |||||
39 | // If there are new CMB2 options available, then use those. |
||||
40 | $new_options = get_option( 'lsx_team_options', false ); |
||||
41 | if ( false !== $new_options ) { |
||||
0 ignored issues
–
show
|
|||||
42 | $options['display'] = $new_options; |
||||
43 | } |
||||
0 ignored issues
–
show
|
|||||
44 | return $options; |
||||
45 | } |
||||
0 ignored issues
–
show
|
|||||
46 | |||||
47 | /** |
||||
48 | * Wrapper function around cmb2_get_option |
||||
49 | * @since 0.1.0 |
||||
0 ignored issues
–
show
|
|||||
50 | * @param string $key Options array key |
||||
0 ignored issues
–
show
|
|||||
51 | * @param mixed $default Optional default value |
||||
0 ignored issues
–
show
|
|||||
52 | * @return mixed Option value |
||||
53 | */ |
||||
54 | function team_get_option( $key = '', $default = false ) { |
||||
55 | $options = array(); |
||||
56 | $value = $default; |
||||
57 | if ( function_exists( 'tour_operator' ) ) { |
||||
0 ignored issues
–
show
|
|||||
58 | $options = get_option( '_lsx-to_settings', false ); |
||||
59 | } else { |
||||
60 | $options = get_option( '_lsx_settings', false ); |
||||
61 | |||||
62 | if ( false === $options ) { |
||||
0 ignored issues
–
show
|
|||||
63 | $options = get_option( '_lsx_lsx-settings', false ); |
||||
64 | } |
||||
65 | } |
||||
66 | |||||
67 | // If there are new CMB2 options available, then use those. |
||||
68 | $new_options = get_option( 'lsx_team_options', false ); |
||||
69 | if ( false !== $new_options ) { |
||||
0 ignored issues
–
show
|
|||||
70 | $options['display'] = $new_options; |
||||
71 | } |
||||
72 | |||||
73 | if ( isset( $options['display'] ) && isset( $options['display'][ $key ] ) ) { |
||||
0 ignored issues
–
show
|
|||||
74 | $value = $options['display'][ $key ]; |
||||
75 | } |
||||
0 ignored issues
–
show
|
|||||
76 | return $value; |
||||
77 | } |
||||
0 ignored issues
–
show
|
|||||
78 | |||||
79 | /** |
||||
0 ignored issues
–
show
|
|||||
80 | * Wraps the output class in a function to be called in templates |
||||
81 | */ |
||||
82 | function lsx_team( $args ) { |
||||
83 | $lsx_team = new LSX_Team; |
||||
0 ignored issues
–
show
|
|||||
84 | echo wp_kses_post( $lsx_team->output( $args ) ); |
||||
85 | } |
||||
0 ignored issues
–
show
|
|||||
86 | |||||
87 | /** |
||||
0 ignored issues
–
show
|
|||||
88 | * Shortcode |
||||
89 | */ |
||||
90 | function lsx_team_shortcode( $atts ) { |
||||
91 | $lsx_team = new LSX_Team; |
||||
0 ignored issues
–
show
|
|||||
92 | return $lsx_team->output( $atts ); |
||||
93 | } |
||||
0 ignored issues
–
show
|
|||||
94 | add_shortcode( 'lsx_team', 'lsx_team_shortcode' ); |
||||
95 | |||||
96 | /** |
||||
97 | * Creates the feature images sizes for the REST API responses. |
||||
98 | * |
||||
99 | * @param [type] $object team. |
||||
0 ignored issues
–
show
|
|||||
100 | * @param [type] $field_name name. |
||||
101 | * @param [type] $request request. |
||||
102 | */ |
||||
103 | function lsx_team_get_images_urls( $object, $field_name, $request ) { |
||||
0 ignored issues
–
show
|
|||||
104 | $medium = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'medium' ); |
||||
105 | $medium_url = $medium['0']; |
||||
106 | |||||
107 | $large = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'large' ); |
||||
108 | $large_url = $large['0']; |
||||
109 | |||||
110 | return array( |
||||
111 | 'medium' => $medium_url, |
||||
112 | 'large' => $large_url, |
||||
113 | ); |
||||
114 | } |
||||
0 ignored issues
–
show
|
|||||
115 | |||||
116 | /** |
||||
117 | * Modify REST API responses to get better media urls for the blocks. |
||||
118 | * |
||||
119 | * @return void |
||||
120 | */ |
||||
121 | function lsx_team_register_images_field() { |
||||
122 | register_rest_field( |
||||
123 | 'team', |
||||
124 | 'images', |
||||
125 | array( |
||||
126 | 'get_callback' => 'lsx_team_get_images_urls', |
||||
127 | 'update_callback' => null, |
||||
128 | 'schema' => null, |
||||
129 | ) |
||||
130 | ); |
||||
131 | } |
||||
0 ignored issues
–
show
|
|||||
132 | add_action( 'rest_api_init', 'lsx_team_register_images_field' ); |
||||
133 | |||||
134 | /** |
||||
135 | * Creates the Additional Meta the REST API responses. |
||||
136 | * |
||||
137 | * @param [type] $object team. |
||||
0 ignored issues
–
show
|
|||||
138 | * @param [type] $field_name name. |
||||
139 | * @param [type] $request request. |
||||
140 | */ |
||||
141 | function lsx_team_get_additional_meta( $object, $field_name, $request ) { |
||||
0 ignored issues
–
show
|
|||||
142 | $role = get_the_terms( get_the_ID(), 'team_role' ); |
||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post of get_the_terms() does only seem to accept WP_Post|integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
143 | $job_title = get_post_meta( get_the_ID(), 'lsx_job_title', true ); |
||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post_id of get_post_meta() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
144 | $email = get_post_meta( get_the_ID(), 'lsx_email_contact', true ); |
||||
145 | $phone = get_post_meta( get_the_ID(), 'lsx_tel', true ); |
||||
146 | $skype = get_post_meta( get_the_ID(), 'lsx_skype', true ); |
||||
147 | $facebook = get_post_meta( get_the_ID(), 'lsx_facebook', true ); |
||||
148 | $twitter = get_post_meta( get_the_ID(), 'lsx_twitter', true ); |
||||
149 | $linkedin = get_post_meta( get_the_ID(), 'lsx_linkedin', true ); |
||||
150 | |||||
151 | return array( |
||||
152 | 'role' => $role, |
||||
153 | 'job_title' => $job_title, |
||||
154 | 'email' => $email, |
||||
155 | 'phone' => $phone, |
||||
156 | 'skype' => $skype, |
||||
157 | 'facebook' => $facebook, |
||||
158 | 'twitter' => $twitter, |
||||
159 | 'linkedin' => $linkedin, |
||||
160 | ); |
||||
161 | } |
||||
0 ignored issues
–
show
|
|||||
162 | |||||
163 | /** |
||||
164 | * Modify REST API responses to get better social urls for the blocks. |
||||
165 | * |
||||
166 | * @return void |
||||
167 | */ |
||||
168 | function lsx_team_register_additional_meta() { |
||||
169 | register_rest_field( |
||||
170 | 'team', |
||||
171 | 'additional_meta', |
||||
172 | array( |
||||
173 | 'get_callback' => 'lsx_team_get_additional_meta', |
||||
174 | 'update_callback' => null, |
||||
175 | 'schema' => null, |
||||
176 | ) |
||||
177 | ); |
||||
178 | } |
||||
0 ignored issues
–
show
|
|||||
179 | add_action( 'rest_api_init', 'lsx_team_register_additional_meta' ); |
||||
180 |