function bawmrp_field_post_types() { $bawmrp_options = get_option('bawmrp'); global $sitepress; if (isset($sitepress) && defined('ICL_LANGUAGE_CODE')) { $lang = bawmrp_wpml_lang_by_code(ICL_LANGUAGE_CODE); $code = ICL_LANGUAGE_CODE; $flag = sprintf(' <img src="%s" alt="%s" />', $sitepress->get_flag_url($code), $code); } else { $lang = $code = get_locale(); $flag = ''; } $bawmrp_options['post_types'] = !empty($bawmrp_options['post_types']) ? $bawmrp_options['post_types'] : array(); foreach (get_post_types(array('public' => true, 'show_ui' => true), 'objects') as $cpt) { echo '<label><input type="checkbox" ' . checked(in_array($cpt->name, $bawmrp_options['post_types']) ? 'on' : '', 'on', false) . ' name="bawmrp[post_types][]" value="' . esc_attr($cpt->name) . '" /> ' . esc_html($cpt->label) . '</label><br />' . ' ' . sprintf(__('Front-end title for %s%s', 'bawmrp'), strtolower(esc_html($cpt->label)), $flag) . '<br /> '; if (isset($sitepress)) { $langs = $sitepress->get_languages("en' AND active='1"); } else { $langs = array(array('default_locale' => get_locale())); } foreach ($langs as $_lang) { if (isset($bawmrp_options['head_titles'][$cpt->name][$_lang['default_locale']])) { $value = esc_attr($bawmrp_options['head_titles'][$cpt->name][$_lang['default_locale']]); } elseif (isset($bawmrp_options['head_titles'][$cpt->name]) && is_string($bawmrp_options['head_titles'][$cpt->name])) { $value = esc_attr($bawmrp_options['head_titles'][$cpt->name]); } else { $value = __('You may also like:', 'bawmrp'); } $type = $_lang['default_locale'] != $lang ? 'hidden' : 'text'; echo '<input type="' . $type . '" class="regular-text" name="bawmrp[head_titles][' . esc_attr($cpt->name) . '][' . $_lang['default_locale'] . ']" value="' . $value . '" />'; } echo '<br />'; } }
function bawmrp_the_content($content = '') { global $post, $in_bawmrp_loop; $bawmrp_options = get_option('bawmrp'); if (!$post || $bawmrp_options['in_content'] != 'on' && $content != '' || apply_filters('stop_bawmrp', false)) { return $content; } if (is_home() && $bawmrp_options['in_homepage'] == 'on' && in_the_loop() || is_singular($bawmrp_options['post_types'])) { $ids_manual = wp_parse_id_list(bawmrp_get_related_posts($post->ID)); $lang = isset($_GET['lang']) ? $_GET['lang'] : get_locale(); $transient_name = apply_filters('bawmrp_transient_name', 'bawmrp_' . $post->ID . '_' . substr(md5(serialize($ids_manual) . serialize($bawmrp_options) . get_permalink($post->ID) . $lang), 0, 12)); if ($contents = get_transient($transient_name)) { extract($contents); if (!empty($list) && is_array($list) && isset($bawmrp_options['random_posts'])) { shuffle($list); } $final = $content . $head . @implode("\n", $list) . $foot; $content = apply_filters('bawmrp_posts_content', $final, $content, $head, $list, $foot); return $content; } $ids_auto = isset($bawmrp_options['auto_posts']) && 'none' != $bawmrp_options['auto_posts'] ? bawmrp_get_related_posts_auto($post) : array(); $ids = wp_parse_id_list(array_merge($ids_manual, $ids_auto)); if (defined('ICL_LANGUAGE_CODE')) { $head_title = isset($bawmrp_options['head_titles'][$post->post_type][bawmrp_wpml_lang_by_code(ICL_LANGUAGE_CODE)]) && is_string($bawmrp_options['head_titles'][$post->post_type][bawmrp_wpml_lang_by_code(ICL_LANGUAGE_CODE)]) ? $bawmrp_options['head_titles'][$post->post_type][bawmrp_wpml_lang_by_code(ICL_LANGUAGE_CODE)] : $head_title; } elseif (isset($bawmrp_options['head_titles'][$post->post_type][get_locale()]) && is_string($bawmrp_options['head_titles'][$post->post_type][get_locale()])) { $head_title = $bawmrp_options['head_titles'][$post->post_type][get_locale()]; } else { $head_title = isset($bawmrp_options['head_titles'][$post->post_type]) && is_string($bawmrp_options['head_titles'][$post->post_type]) ? $bawmrp_options['head_titles'][$post->post_type] : $head_title; } if (!empty($ids) && is_array($ids) && isset($ids[0]) && $ids[0] != 0) { $ids = wp_parse_id_list($ids); $list = array(); if (isset($bawmrp_options['random_posts'])) { shuffle($ids); } if ((int) $bawmrp_options['max_posts'] > 0 && count($ids) > (int) $bawmrp_options['max_posts']) { $ids = array_slice($ids, 0, (int) $bawmrp_options['max_posts']); } $head = '<div class="bawmrp"><h3>' . $head_title . '</h3><ul>'; do_action('bawmrp_first_li'); $style = apply_filters('bawmrp_li_style', 'float:left;width:120px;height:auto;overflow:hidden;list-style:none;border-right: 1px solid #ccc;text-align:center;padding:0px 5px;'); $n = 0; $in_bawmrp_loop = true; foreach ($ids as $id) { if (in_array($id, $ids_manual)) { $class = 'bawmrp_manual'; } elseif (in_array($id, get_option('sticky_posts'))) { $class = 'bawmrp_sticky'; } elseif (in_array($id, $ids_auto)) { $class = 'bawmrp_auto'; } $_content = ''; if (isset($bawmrp_options['display_content'])) { $p = get_post($id); $_content = '<br />' . apply_filters('the_excerpt', $p->post_excerpt) . '<p> </p>'; } $_content = apply_filters('bawmrp_the_content', $_content, $id); $_content = apply_filters('bawmrp_more_content', $_content); if ($bawmrp_options['in_content_mode'] == 'list') { $list[] = '<li class="' . $class . '">' . '<a href="' . esc_url(apply_filters('the_permalink', get_permalink($id))) . '">' . get_the_title($id) . '</a>' . $_content . '</li>'; } else { $no_thumb = apply_filters('bawmrp_no_thumb', admin_url('/images/w-logo-blue.png'), $id); $thumb_size = apply_filters('bawmrp_thumb_size', array(100, 100)); if (current_theme_supports('post-thumbnails')) { $thumb = has_post_thumbnail($id) ? get_the_post_thumbnail($id, $thumb_size) : '<img alt="" src="' . baw_first_image(isset($bawmrp_options['first_image']) && $bawmrp_options['first_image'] == 'on' ? $id : null, $no_thumb) . '" height="' . $thumb_size[0] . '" width="' . $thumb_size[1] . '" />'; } else { $thumb = '<img src="' . baw_first_image(isset($bawmrp_options['first_image']) && $bawmrp_options['first_image'] == 'on' ? $id : null, $no_thumb) . '" height="' . $thumb_size[0] . '" width="' . $thumb_size[1] . '" />'; } $list[] = '<li style="' . esc_attr($style) . '" class="' . $class . '"><a href="' . esc_url(apply_filters('the_permalink', get_permalink($id))) . '">' . $thumb . '<br />' . get_the_title($id) . '</a></li>'; } $list = apply_filters('bawmrp_li', $list, ++$n); } do_action('bawmrp_last_li'); $list = apply_filters('bawmrp_list_li', $list); if ($bawmrp_options['in_content_mode'] == 'list') { $foot = '</ul></div>'; } else { $foot = '</ul></div><div style="clear:both;"></div>'; } $final = $content . $head . implode("\n", $list) . $foot; $content = apply_filters('bawmrp_posts_content', $final, $content, $head, $list, $foot); } else { $head = ''; //<div class="bawmrp"><h3>' . esc_html( $head_title ) . '</h3>'; $list = ''; //<ul><li>' . __( 'No posts found.' ) . '</li></ul>'; $foot = ''; //</div>'; $final = $content . $head . $list . $foot; $content = apply_filters('bawmrp_posts_content', $final, $content, $head, $list, $foot); } } if (!empty($list)) { set_transient($transient_name, array('head' => $head, 'list' => $list, 'foot' => $foot)); } $in_bawmrp_loop = false; return $content; }