| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; // if direct access |
| 3 |
|
| 4 |
add_filter('the_content', 'team_preview_content'); |
| 5 |
function team_preview_content($content) |
| 6 |
{ |
| 7 |
if (is_singular('team')) { |
| 8 |
$post_id = get_the_id(); |
| 9 |
$content .= do_shortcode('[team id="' . $post_id . '"]'); |
| 10 |
} |
| 11 |
|
| 12 |
return $content; |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
function team_first_team_member() |
| 17 |
{ |
| 18 |
|
| 19 |
$args = array( |
| 20 |
'post_type' => 'team_member', |
| 21 |
'post_status' => 'publish', |
| 22 |
'posts_per_page' => 1, |
| 23 |
); |
| 24 |
|
| 25 |
$post_id = ''; |
| 26 |
|
| 27 |
$wp_query = new WP_Query($args); |
| 28 |
|
| 29 |
if ($wp_query->have_posts()) : |
| 30 |
while ($wp_query->have_posts()) : $wp_query->the_post(); |
| 31 |
$team_member_id = get_the_id(); |
| 32 |
return $team_member_id; |
| 33 |
endwhile; |
| 34 |
else : |
| 35 |
|
| 36 |
endif; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
function team_first_team_layout() |
| 41 |
{ |
| 42 |
|
| 43 |
$args = array( |
| 44 |
'post_type' => 'team_layout', |
| 45 |
'post_status' => 'publish', |
| 46 |
'posts_per_page' => 1, |
| 47 |
); |
| 48 |
|
| 49 |
$post_id = ''; |
| 50 |
|
| 51 |
$wp_query = new WP_Query($args); |
| 52 |
|
| 53 |
if ($wp_query->have_posts()) : |
| 54 |
while ($wp_query->have_posts()) : $wp_query->the_post(); |
| 55 |
|
| 56 |
$post_id = get_the_id(); |
| 57 |
|
| 58 |
return $post_id; |
| 59 |
endwhile; |
| 60 |
else : |
| 61 |
|
| 62 |
endif; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
add_image_size('team-500px', 500, 500, true); |
| 71 |
add_theme_support('post-thumbnails', array('team_member')); |
| 72 |
|
| 73 |
function team_term_slug_list($post_id) |
| 74 |
{ |
| 75 |
|
| 76 |
$term_slug_list = ''; |
| 77 |
$post_taxonomies = get_post_taxonomies($post_id); |
| 78 |
|
| 79 |
foreach ($post_taxonomies as $taxonomy) { |
| 80 |
|
| 81 |
$term_list[] = wp_get_post_terms(get_the_ID(), $taxonomy, array("fields" => "all")); |
| 82 |
} |
| 83 |
|
| 84 |
if (!empty($term_list)) { |
| 85 |
foreach ($term_list as $term_key => $term) { |
| 86 |
foreach ($term as $term_id => $term) { |
| 87 |
$term_slug_list .= $term->slug . ' '; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
return $term_slug_list; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
function single_team_member_content($content) |
| 102 |
{ |
| 103 |
|
| 104 |
if (is_singular('team_member')) { |
| 105 |
|
| 106 |
$team_id = get_the_id(); |
| 107 |
|
| 108 |
ob_start(); |
| 109 |
|
| 110 |
?> |
| 111 |
<div class="team-member single-team-member"> |
| 112 |
<?php |
| 113 |
do_action('team_single_team_member', $team_id); |
| 114 |
?> |
| 115 |
</div> |
| 116 |
<?php |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
$content = ob_get_clean(); |
| 121 |
return $content; |
| 122 |
} else { |
| 123 |
return $content; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
add_filter('the_content', 'single_team_member_content'); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
function single_team_member_post_title($post_title) |
| 132 |
{ |
| 133 |
|
| 134 |
if (is_singular('team_member') && in_the_loop()) { |
| 135 |
$team_settings = get_option('team_settings'); |
| 136 |
$hide_post_title = isset($team_settings['team_member']['hide_post_title']) ? $team_settings['team_member']['hide_post_title'] : ''; |
| 137 |
|
| 138 |
if ($hide_post_title == 'yes') return; |
| 139 |
|
| 140 |
|
| 141 |
return $post_title; |
| 142 |
} else { |
| 143 |
return $post_title; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
add_filter('the_title', 'single_team_member_post_title'); |
| 148 |
|
| 149 |
|
| 150 |
function single_team_member_post_thumbnail($post_thumbnail) |
| 151 |
{ |
| 152 |
|
| 153 |
if (is_singular('team_member')) { |
| 154 |
$team_settings = get_option('team_settings'); |
| 155 |
$hide_featured_image = isset($team_settings['team_member']['hide_featured_image']) ? $team_settings['team_member']['hide_featured_image'] : ''; |
| 156 |
|
| 157 |
//var_dump($hide_featured_image); |
| 158 |
|
| 159 |
if ($hide_featured_image == 'yes') return; |
| 160 |
|
| 161 |
|
| 162 |
return $post_thumbnail; |
| 163 |
} else { |
| 164 |
return $post_thumbnail; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
add_filter('post_thumbnail_html', 'single_team_member_post_thumbnail'); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
add_filter('manage_team_member_posts_columns', 'team_add_thumb_column'); |
| 176 |
|
| 177 |
function team_add_thumb_column($columns) |
| 178 |
{ |
| 179 |
$columns['thumb'] = __('Thumb', 'team'); |
| 180 |
return $columns; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
add_action('manage_team_member_posts_custom_column', 'team_member_posts_thumb_display', 10, 2); |
| 186 |
|
| 187 |
function team_member_posts_thumb_display($column, $post_id) |
| 188 |
{ |
| 189 |
|
| 190 |
if ($column == 'thumb') { |
| 191 |
$team_thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'thumbnail'); |
| 192 |
$team_thumb_url = isset($team_thumb['0']) ? $team_thumb['0'] : ''; |
| 193 |
|
| 194 |
$team_member_data = get_post_meta($post_id, 'team_member_data', true); |
| 195 |
$member_image_id = isset($team_member_data['member_image']) ? $team_member_data['member_image'] : ''; |
| 196 |
$member_image_url = wp_get_attachment_url($member_image_id, 'full'); |
| 197 |
|
| 198 |
//var_dump($member_image_id); |
| 199 |
|
| 200 |
if (!empty($member_image_url)) |
| 201 |
echo '<img width="40px" src="' . esc_url($member_image_url) . '">'; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
function team_add_shortcode_column($columns) |
| 209 |
{ |
| 210 |
return array_merge( |
| 211 |
$columns, |
| 212 |
array('shortcode' => __('Shortcode', 'team')) |
| 213 |
); |
| 214 |
} |
| 215 |
add_filter('manage_team_posts_columns', 'team_add_shortcode_column'); |
| 216 |
|
| 217 |
|
| 218 |
function team_posts_shortcode_display($column, $post_id) |
| 219 |
{ |
| 220 |
if ($column == 'shortcode') { |
| 221 |
?> |
| 222 |
<input style="background:#bfefff" type="text" onClick="this.select();" value="[team <?php echo 'id="' . esc_attr($post_id) . '"'; ?>]" /><br /> |
| 223 |
<textarea cols="50" rows="1" style="background:#bfefff" onClick="this.select();"><?php echo '<?php echo do_shortcode("[team id='; |
| 224 |
echo "'" . esc_attr($post_id) . "']"; |
| 225 |
echo '"); ?>'; ?></textarea> |
| 226 |
<?php |
| 227 |
|
| 228 |
} |
| 229 |
} |
| 230 |
add_action('manage_team_posts_custom_column', 'team_posts_shortcode_display', 10, 2); |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
function team_recursive_sanitize_arr($array) |
| 236 |
{ |
| 237 |
|
| 238 |
foreach ($array as $key => &$value) { |
| 239 |
if (is_array($value)) { |
| 240 |
$value = team_recursive_sanitize_arr($value); |
| 241 |
} else { |
| 242 |
$value = wp_kses_post($value); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
return $array; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
add_shortcode('team_import_xml_layouts', 'team_import_xml_layouts'); |
| 251 |
|
| 252 |
function team_import_xml_layouts($xml_source) |
| 253 |
{ |
| 254 |
|
| 255 |
|
| 256 |
if (!current_user_can('manage_options')) return; |
| 257 |
|
| 258 |
|
| 259 |
$response = array(); |
| 260 |
$user_id = get_current_user_id(); |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
$json_obj = file_get_contents($xml_source); |
| 266 |
|
| 267 |
//$xml_json = json_encode($html_obj); |
| 268 |
$xml_arr = json_decode($json_obj, true); |
| 269 |
|
| 270 |
|
| 271 |
$items = $xml_arr['rss']['channel']['item']; |
| 272 |
|
| 273 |
foreach ($items as $item) { |
| 274 |
|
| 275 |
$post_title = isset($item['title']) ? $item['title'] : ''; |
| 276 |
$postmeta = isset($item['postmeta']) ? $item['postmeta'] : array(); |
| 277 |
|
| 278 |
$post_id = wp_insert_post( |
| 279 |
array( |
| 280 |
'post_title' => $post_title, |
| 281 |
'post_content' => '', |
| 282 |
'post_status' => 'publish', |
| 283 |
'post_type' => 'team_layout', |
| 284 |
'post_author' => $user_id, |
| 285 |
) |
| 286 |
); |
| 287 |
|
| 288 |
// echo '<br>'; |
| 289 |
// echo $post_title. ' Created'; |
| 290 |
// echo '<br>'; |
| 291 |
|
| 292 |
|
| 293 |
foreach ($postmeta as $meta) { |
| 294 |
|
| 295 |
$meta_key = isset($meta['meta_key']['__cdata']) ? $meta['meta_key']['__cdata'] : ''; |
| 296 |
$meta_value = isset($meta['meta_value']['__cdata']) ? $meta['meta_value']['__cdata'] : ''; |
| 297 |
|
| 298 |
// echo '<br>'; |
| 299 |
// //var_dump(unserialize($meta_value)); |
| 300 |
// echo '<br>'; |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
if ($meta_key == 'layout_options' || $meta_key == 'layout_elements_data' || $meta_key == 'custom_scripts') { |
| 305 |
//var_dump($meta_value); |
| 306 |
|
| 307 |
update_post_meta($post_id, $meta_key, unserialize($meta_value)); |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
$response['success'] = __('Import done', 'team'); |
| 314 |
|
| 315 |
$team_plugin_info = get_option('team_plugin_info'); |
| 316 |
|
| 317 |
if (strpos($xml_source, 'team-pro')) { |
| 318 |
$team_plugin_info['import_pro_layouts'] = 'done'; |
| 319 |
} else { |
| 320 |
$team_plugin_info['import_layouts'] = 'done'; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
update_option('team_plugin_info', $team_plugin_info); |
| 325 |
} |
| 326 |
|