function sys_recent_posts($atts, $content = null) { extract(shortcode_atts(array('limit' => '2', 'description' => '40', 'cat_id' => '23', 'thumb' => 'true', 'postdate' => ''), $atts)); $out = '<div class="widget_postslist sc">'; $out .= '<ul>'; global $wpdb; $myposts = get_posts("numberposts={$limit}&offset=0&cat={$cat_id}"); foreach ($myposts as $post) { $post_date = $post->post_date; $post_date = mysql2date('F j, Y', $post_date, false); $out .= "<li>"; if ($thumb == "true") { $thumbid = get_post_thumbnail_id($post->ID); $imgsrc = wp_get_attachment_image_src($thumbid, array(9999, 9999)); $out .= '<div class="thumb"><a href="' . get_permalink($post->ID) . '" title="' . $post->post_title . '">'; if ($thumbid) { $out .= atp_resize('', $imgsrc['0'], '50', '50', 'imgborder', ''); } else { //$out .= '<img class="imgborder" src="'.THEME_URI.'/images/no-image.jpg'.'" alt="' .$post->post_title. '" />'; } $out .= '</a></div>'; } $out .= '<div class="pdesc"><a href="' . get_permalink($post->ID) . '" rel="bookmark">' . $post->post_title . '</a>'; if ($postdate == "true") { $out .= '<div class="w-postmeta"><span>' . $post_date . '</span></div>'; } else { $out .= '<p>' . wp_html_excerpt($post->post_content, $description, '...') . '</p>'; } $out .= '</div></li>'; } $out .= '</ul></div>'; return $out; wp_reset_query(); }
function test_entities() { $this->assertEquals("Baba ", wp_html_excerpt("Baba & Dyado", 8)); $this->assertEquals("Baba ", wp_html_excerpt("Baba & Dyado", 8)); $this->assertEquals("Baba & D", wp_html_excerpt("Baba & Dyado", 12)); $this->assertEquals("Baba & Dyado", wp_html_excerpt("Baba & Dyado", 100)); }
function s8_dashboard_widget_function() { $rss = fetch_feed("http://station8branding.com/feed/"); if (is_wp_error($rss)) { if (is_admin() || current_user_can('manage_options')) { echo '<p>'; printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message()); echo '</p>'; } return; } if (!$rss->get_item_quantity()) { echo '<p>Apparently, there are no updates to show!</p>'; $rss->__destruct(); unset($rss); return; } echo "<header style='background: black; padding: 10px; text-align: center; margin: -11px -12px;'><a href='http://station8branding.com' target='_blank'><img src='http://station8branding.com/wp-content/uploads/2014/12/branding2.png'></a></header>"; echo "<ul>\n"; if (!isset($items)) { $items = 5; } foreach ($rss->get_items(0, $items) as $item) { $link = esc_url(strip_tags($item->get_link())); $title = esc_html($item->get_title()); $content = $item->get_content(); $content = wp_html_excerpt($content, 150) . ' ...'; //$image = $item->get_the_post_thumbnail(); echo "<li><a class='rsswidget' href='{$link}'>{$title}</a>\n<div class='rssSummary'>{$content}</div>\n"; } echo "</ul>\n"; echo "<a href='http://station8branding.com'>Visit Station8 for more information</a>"; $rss->__destruct(); unset($rss); }
function dashboard_widget_function() { $rss = fetch_feed("http://oldtownmediainc.com/feed/"); if (is_wp_error($rss)) { if (is_admin() || current_user_can('manage_options')) { echo '<p>'; printf(__('<strong>RSS Error</strong>: %s', 'evans-mu'), $rss->get_error_message()); echo '</p>'; } return; } if (!$rss->get_item_quantity()) { echo '<p>' . __('Apparently, there are no updates to show!', 'evans-mu') . '</p>'; $rss->__destruct(); unset($rss); return; } echo "<ul>\n"; if (!isset($items)) { $items = 5; } foreach ($rss->get_items(0, $items) as $item) { $publisher = $site_link = $link = $content = ''; $date = $item->get_date(); $link = esc_url(strip_tags($item->get_link())); $title = esc_html($item->get_title()); $content = $item->get_content(); $content = wp_html_excerpt($content, 350) . '...'; echo "<li class='rss-widget'><a class='rsswidget' href='{$link}'>{$title}</a><span class='rss-date'> - {$date}</span>\n<div class='rssSummary'>{$content}</div>\n\r\n"; } echo "</ul>\n"; $rss->__destruct(); unset($rss); }
public function new_service($label, $url, $icon) { // Validate $label = trim(wp_html_excerpt(wp_kses($label, array()), 30)); $url = trim(esc_url_raw($url)); $icon = trim(esc_url_raw($icon)); if ($label && $url && $icon) { $options = get_option('sharing-options'); if (!is_array($options)) { $options = array(); } $service_id = 'custom-' . time(); // Add a new custom service $options['global']['custom'][] = $service_id; if (false !== $this->global) { $this->global['custom'][] = $service_id; } update_option('sharing-options', $options); // Create a custom service and set the options for it $service = new Share_Custom($service_id, array('name' => $label, 'url' => $url, 'icon' => $icon)); $this->set_service($service_id, $service); // Return the service return $service; } return false; }
function widget($args, $instance) { global $familia_option; extract($args); $warrior_recent_comments_title = apply_filters('widget_title', empty($instance['warrior_recent_comments_title']) ? __('Recent Comments', 'familia') : $instance['warrior_recent_comments_title'], $instance, $this->id_base); $warrior_recent_comments_count = !empty($instance['warrior_recent_comments_count']) ? absint($instance['warrior_recent_comments_count']) : 4; $warrior_recent_excerpt_count = !empty($instance['warrior_recent_excerpt_count']) ? absint($instance['warrior_recent_excerpt_count']) : 90; if (!$warrior_recent_comments_count) { $warrior_recent_comments_count = 4; } ?> <?php echo $before_widget; ?> <?php echo $before_title . $warrior_recent_comments_title . $after_title; ?> <?php $args = array('status' => 'approve', 'number' => $warrior_recent_comments_count); $comments = get_comments($args); ?> <ul class="recent-comments-widget"> <?php foreach ($comments as $comment) { ?> <li class="recent-comments-wrapper"> <div class="comments-avatar"> <?php echo get_avatar($comment, '50'); ?> </div> <div class="detail"> <a href="<?php echo get_permalink($comment->comment_post_ID); ?> #comment-<?php echo $comment->comment_ID; ?> " rel="external nofollow"> <?php echo '<span class="recommauth">' . $comment->comment_author . '</span>'; ?> </a> <p><?php echo wp_html_excerpt($comment->comment_content, $warrior_recent_excerpt_count, '...'); ?> </p> </div> </li> <?php } ?> </ul> <?php echo $after_widget; }
/** * Creates the RSS metabox * * @access public * @since 1.0 * @return void */ function rss_box($rss) { // Get RSS Feed(s) include_once ABSPATH . WPINC . '/feed.php'; // My feeds list (add your own RSS feeds urls) $my_feeds = array('http://agora.xtec.cat/nodes/categoria/portada/feed'); // Loop through Feeds foreach ($my_feeds as $feed) { // Get a SimplePie feed object from the specified feed source. $rss = fetch_feed($feed); if (!is_wp_error($rss)) { // Checks that the object is created correctly // Figure out how many total items there are, and choose a limit $maxitems = $rss->get_item_quantity(20); // Build an array of all the items, starting with element 0 (first element). $rss_items = $rss->get_items(0, $maxitems); // Get RSS title $rss_title = '<a href="' . $rss->get_permalink() . '" target="_blank">' . strtoupper($rss->get_title()) . '</a>'; } // Display the container echo '<div class="rss-widget">'; echo '<strong>' . $rss_title . '</strong>'; echo '<hr style="border: 0; background-color: #DFDFDF; height: 1px;">'; // Starts items listing within <ul> tag echo '<ul>'; // Check items if ($maxitems == 0) { echo '<li>' . __('No item', 'rc_mdm') . '.</li>'; } else { // Loop through each feed item and display each item as a hyperlink. foreach ($rss_items as $item) { // Uncomment line below to display non human date //$item_date = $item->get_date( get_option('date_format').' @ '.get_option('time_format') ); // Get human date (comment if you want to use non human date) $item_date = human_time_diff($item->get_date('U'), current_time('timestamp')) . ' ' . __('ago', 'rc_mdm'); // Start displaying item content within a <li> tag echo '<li>'; // create item link echo '<a href="' . esc_url($item->get_permalink()) . '" title="' . $item_date . '">'; // Get item title echo esc_html($item->get_title()); echo '</a>'; // Display date echo ' <span class="rss-date">' . $item_date . '</span><br />'; // Get item content $content = $item->get_content(); // Shorten content $content = wp_html_excerpt($content, 120) . ' [...]'; // Display content echo $content; // End <li> tag echo '</li>'; } } // End <ul> tag echo '</ul></div>'; } // End foreach feed }
function widget($args, $instance) { //defaults $instance = wp_parse_args($instance, array("title" => "", "categories" => "", "count" => "", "limit" => "", "show_thumbnails" => "", "show_excerpt" => "", "thumb_width" => "", "thumb_height" => "")); extract($args); $title = !empty($instance['title']) ? apply_filters('widget_title', $instance['title']) : ""; $categories = !empty($instance['categories']) ? implode($instance['categories'], ',') : ""; $count = !empty($instance['count']) ? $instance['count'] : 5; $limit = !empty($instance['limit']) ? $instance['limit'] : 100; $show_thumbnails = !empty($instance['show_thumbnails']) ? $instance['show_thumbnails'] : ""; $show_excerpt = !empty($instance['show_excerpt']) ? $instance['show_excerpt'] : ""; $thumb_width = !empty($instance['thumb_width']) ? $instance['thumb_width'] : 260; $thumb_height = !empty($instance['thumb_height']) ? $instance['thumb_height'] : 260; $comment = ""; //remove aside and quote post formats from the list $postargs = array('orderby' => 'comment_count', 'post_type' => 'post', 'showposts' => $count, 'cat' => $categories, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1); $post_query = new WP_Query($postargs); $rt_posts = ''; if ($post_query->have_posts()) { while ($post_query->have_posts()) { $post_query->the_post(); $post_title = get_the_title(); $link = get_permalink(); $date = get_the_time('d M Y'); $comment_count = get_comment_count($post_query->post->ID); $featured_image_id = get_post_thumbnail_id(); $get_the_excerpt = $show_excerpt ? '<p>' . wp_html_excerpt(get_the_excerpt(), $limit) . '...</p>' : ""; // Create thumbnail image $thumbnail_image_output = !empty($featured_image_id) ? get_resized_image_output(array("image_url" => "", "image_id" => $featured_image_id, "w" => $thumb_width, "h" => $thumb_height, "crop" => 1, "class" => "post-thumb")) : ""; if (empty($thumbnail_image_output) || !empty($show_thumbnails)) { $thumbnail_image_output = ""; } if ($comment_count['approved'] > 0) { if ($comment_count['approved'] > 1) { $comments = $comment_count['approved'] . ' ' . __('Comments', 'rt_theme'); } else { $comments = __('1 Comment', 'rt_theme'); } $comment = ' | <span class="comment_number"><span class="icon-comment-empty"></span><a href="' . get_comments_link() . '" title="' . $comments . '" class="comment_link">' . $comment_count['approved'] . '</a></span>'; } $rt_posts .= sprintf(' <div> %1$s <a class="title" href="%2$s" title="%3$s" rel="bookmark">%3$s</a> <span class="meta">%4$s %6$s</span> %5$s </div> ', $thumbnail_image_output, $link, $post_title, get_the_date(), $get_the_excerpt, $comment); } wp_reset_postdata(); } echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo $rt_posts; echo $after_widget; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $categories = empty($instance['categories']) ? $instance['categories'] : implode($instance['categories'], ','); $count = empty($instance['count']) ? 5 : $instance['count']; $limit = empty($instance['limit']) ? 100 : $instance['limit']; $show_thumbnails = $instance['show_thumbnails']; $show_excerpt = $instance['show_excerpt']; $all_post_formats = $instance['all_post_formats']; $thumb_width = empty($instance['thumb_width']) ? 50 : $instance['thumb_width']; $thumb_height = empty($instance['thumb_height']) ? 50 : $instance['thumb_height']; //remove aside and quote post formats from the list $postargs = $all_post_formats ? array('orderby' => 'comment_count', 'post_type' => 'post', 'showposts' => $count, 'cat' => $categories, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1) : array('orderby' => 'comment_count', 'tax_query' => array(array('operator' => 'NOT IN', 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-quote', 'post-format-aside'))), 'post_type' => 'post', 'showposts' => $count, 'cat' => $categories, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1); $post_query = new WP_Query($postargs); $rt_posts = '<div class="recent_posts clearfix"><ul>'; if ($post_query->have_posts()) { while ($post_query->have_posts()) { $post_query->the_post(); $post_title = get_the_title(); $link = get_permalink(); $date = get_the_time('d M Y'); $comment_count = get_comment_count($post_query->post->ID); $rt_gallery_images = get_post_meta($post_query->post->ID, THEMESLUG . "rt_gallery_images", true) ? get_post_meta($post_query->post->ID, THEMESLUG . "rt_gallery_images", true) : ""; $rt_gallery_image_titles = get_post_meta($post_query->post->ID, THEMESLUG . "rt_gallery_image_titles", true) ? get_post_meta($post_query->post->ID, THEMESLUG . "rt_gallery_image_titles", true) : ""; $rt_gallery_image_descs = get_post_meta($post_query->post->ID, THEMESLUG . "rt_gallery_image_descs", true) ? get_post_meta($post_query->post->ID, THEMESLUG . "rt_gallery_image_descs", true) : ""; $fist_featured_image = is_array($rt_gallery_images) ? find_image_org_path($rt_gallery_images[0]) : ""; $rt_posts .= '<li class="clearfix">'; if ($fist_featured_image && !$show_thumbnails) { $f_image = @vt_resize('', $fist_featured_image, $thumb_width, $thumb_height, true); if ($f_image["url"]) { $rt_posts .= '<img src="' . $f_image["url"] . '" alt="' . $title . '" class="recent-posts-thumb" />'; } } $rt_posts .= '<span class="date">' . $date . '</span>'; $rt_posts .= '<span class="title"><a href="' . $link . '">' . $post_title . '</a></span>'; $rt_posts .= $show_excerpt ? '' . wp_html_excerpt(get_the_excerpt(), $limit) . '...' : ""; if ($comment_count['approved'] > 0) { if ($comment_count['approved'] > 1) { $comments = $comment_count['approved'] . ' ' . __('Comments', 'rt_theme'); } else { $comments = __('1 Comment', 'rt_theme'); } $rt_posts .= ' <span class="comment_number date"><a href="' . get_comments_link() . '" title="' . $comments . '" class="comment_link">' . $comments . '</a></span>'; $rt_posts .= $show_excerpt ? '<div class="space margin-b10"></div>' : ""; } $rt_posts .= '</li>'; } } wp_reset_query(); $rt_posts .= '</ul></div>'; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo $rt_posts; echo $after_widget; }
function tc_alter_wp_customizer_settings($wp_customize) { //CHANGE BLOGNAME AND BLOGDESCRIPTION TRANSPORT $wp_customize->get_setting('blogname')->transport = 'postMessage'; $wp_customize->get_setting('blogdescription')->transport = 'postMessage'; //IF WP VERSION >= 4.3 AND SITE_ICON SETTING EXISTS //=> REMOVE CUSTOMIZR FAV ICON CONTROL //=> CHANGE SITE ICON DEFAULT WP SECTION TO CUSTOMIZR LOGO SECTION global $wp_version; if (version_compare($wp_version, '4.3', '>=') && is_object($wp_customize->get_control('site_icon'))) { $tc_option_group = TC___::$tc_option_group; $wp_customize->remove_control("{$tc_option_group}[tc_fav_upload]"); //note : the setting is kept because used in the customizer js api to handle the transition between Customizr favicon to WP site icon. $wp_customize->get_control('site_icon')->section = 'logo_sec'; //add a favicon title after the logo upload add_action('__after_setting_control', array($this, 'tc_add_favicon_title')); } //end ALTER SITE ICON //CHANGE MENUS PROPERTIES $locations = get_registered_nav_menus(); $menus = wp_get_nav_menus(); $choices = array('' => __('— Select —', 'customizr')); foreach ($menus as $menu) { $choices[$menu->term_id] = wp_html_excerpt($menu->name, 40, '…'); } $_priorities = array('main' => 10, 'secondary' => 20); //WP only adds the menu(s) settings and controls if the user has created at least one menu. //1) if no menus yet, we still want to display the menu picker + add a notice with a link to the admin menu creation panel //=> add_setting and add_control for each menu location. Check if they are set first by security //2) if user has already created a menu, the settings are already created, we just need to update the controls. $_priority = 0; //assign new priorities to the menus controls foreach ($locations as $location => $description) { $menu_setting_id = "nav_menu_locations[{$location}]"; //create the settings if they don't exist //=> in the condition, make sure that the setting has really not been created yet (maybe over secured) if (!$menus && !is_object($wp_customize->get_setting($menu_setting_id))) { $wp_customize->add_setting($menu_setting_id, array('sanitize_callback' => 'absint', 'theme_supports' => 'menus')); } //remove the controls if they exists if (is_object($wp_customize->get_control($menu_setting_id))) { $wp_customize->remove_control($menu_setting_id); } //replace the controls by our custom controls $_control_properties = array('label' => $description, 'section' => 'nav', 'title' => "main" == $location ? __('Assign menus to locations', 'customizr') : false, 'type' => 'select', 'choices' => $choices, 'priority' => isset($_priorities[$location]) ? $_priorities[$location] : $_priority); //add a notice property if no menu created yet. if (!$menus) { //adapt the nav section description for v4.3 (menu in the customizer from now on) $_create_menu_link = version_compare($GLOBALS['wp_version'], '4.3', '<') ? admin_url('nav-menus.php') : "javascript:wp.customize.section('nav').container.find('.customize-section-back').trigger('click'); wp.customize.panel('nav_menus').focus();"; $_control_properties['notice'] = sprintf(__("You haven't created any menu yet. %s or check the %s to learn more about menus.", "customizr"), sprintf('<strong><a href="%1$s" title="%2$s">%2$s</a></strong>', $_create_menu_link, __("Create a new menu now", "customizr")), sprintf('<a href="%1$s" title="%2$s" target="_blank">%2$s</a>', esc_url('codex.wordpress.org/WordPress_Menu_User_Guide'), __("WordPress documentation", "customizr"))); } $wp_customize->add_control(new TC_controls($wp_customize, $menu_setting_id, $_control_properties)); $_priority = $_priority + 10; } //foreach }
function _ga_adjust_admin_bar_site_menu($admin_bar) { if (!is_user_logged_in() || !current_user_can('manage_global')) { return; } $blogname = sprintf(__('Global Admin: %s'), esc_html(get_global_option('global_name'))); $title = wp_html_excerpt($blogname, 40, '…'); $admin_bar->add_menu(array('id' => 'site-name', 'title' => $title, 'href' => home_url('/'))); $admin_bar->add_menu(array('parent' => 'site-name', 'id' => 'view-site', 'title' => __('Visit Site'), 'href' => home_url('/'))); }
function planar_dashboard_rss_box() { // Get RSS Feed(s) include_once ABSPATH . WPINC . '/feed.php'; // Feeds list (add your own RSS feeds urls) $my_feeds = array(esc_url('http://www.dinevthemes.com/feed/')); // Loop through Feeds foreach ($my_feeds as $feed) { // Get a SimplePie feed object from the specified feed source. $rss = fetch_feed($feed); if (!is_wp_error($rss)) { // Checks that the object is created correctly // Figure out how many total items there are, and choose a limit $maxitems = $rss->get_item_quantity(4); // Build an array of all the items, starting with element 0 (first element). $rss_items = $rss->get_items(0, $maxitems); // Get RSS title $rss_title = '<a class="rsswidget" href="' . $rss->get_permalink() . '" target="_blank">' . strtoupper($rss->get_title()) . '</a>'; } // Display the container echo '<div class="rss-widget">'; // Starts items listing within <ul> tag echo '<ul>'; // Check items if ($maxitems == 0) { echo '<li>' . __('No items', 'planar') . '.</li>'; } else { // Loop through each feed item and display each item as a hyperlink. foreach ($rss_items as $item) { $item_date = human_time_diff($item->get_date('U'), current_time('timestamp')) . ' ' . __('ago', 'rc_mdm'); // Start displaying item content within a <li> tag echo '<li style="margin-bottom:15px;">'; // create item link echo '<a class="rsswidget" style="font-weight:400;" href="' . esc_url($item->get_permalink()) . '" title="' . esc_html($item->get_title()) . '">'; // Get item title echo esc_html($item->get_title()); echo '</a>'; // Display date echo ' <span class="rss-date">' . $item_date . '</span><br />'; // Get item content $content = $item->get_content(); // Shorten content $content = '<div class="rssSummary">' . wp_html_excerpt($content, 140) . ' [...]</div>'; // Display content echo $content; // End <li> tag echo '</li>'; } } // End <ul> tag echo '</ul><div style="margin-top:20px;padding-top:10px;border-top:1px solid #eee;">Feed from <a href="' . esc_url('http://www.dinevthemes.com') . '">dinevthemes.com</a></div></div>'; } // End foreach feed }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $categories = empty($instance['categories']) ? $instance['categories'] : implode($instance['categories'], ','); $count = empty($instance['count']) ? 5 : $instance['count']; $limit = empty($instance['limit']) ? 100 : $instance['limit']; $show_thumbnails = $instance['show_thumbnails']; $show_excerpt = $instance['show_excerpt']; $thumb_width = empty($instance['thumb_width']) ? 50 : $instance['thumb_width']; $thumb_height = empty($instance['thumb_height']) ? 50 : $instance['thumb_height']; $comment = ""; //remove aside and quote post formats from the list $postargs = array('orderby' => 'comment_count', 'post_type' => 'post', 'showposts' => $count, 'cat' => $categories, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1); $post_query = new WP_Query($postargs); $rt_posts = '<div class="recent_posts clearfix"><ul>'; if ($post_query->have_posts()) { while ($post_query->have_posts()) { $post_query->the_post(); $post_title = get_the_title(); $link = get_permalink(); $date = get_the_time('d M Y'); $comment_count = get_comment_count($post_query->post->ID); $featured_image_id = get_post_thumbnail_id(); // Create thumbnail image $thumbnail_image_output = !empty($featured_image_id) ? get_resized_image_output(array("image_url" => "", "image_id" => $featured_image_id, "w" => $thumb_width, "h" => $thumb_height, "crop" => 1, "class" => "recent-posts-thumb")) : ""; $rt_posts .= '<li class="clearfix">'; if ($thumbnail_image_output && !$show_thumbnails) { $rt_posts .= $thumbnail_image_output; } if ($comment_count['approved'] > 0) { if ($comment_count['approved'] > 1) { $comments = $comment_count['approved'] . ' ' . __('Comments', 'rt_theme'); } else { $comments = __('1 Comment', 'rt_theme'); } $comment = ' <span class="comment_number"><span class="icon-comment-empty"></span><a href="' . get_comments_link() . '" title="' . $comments . '" class="comment_link">' . $comment_count['approved'] . '</a></span>'; } $rt_posts .= '<span class="title"><a href="' . $link . '">' . $post_title . '</a></span>'; $rt_posts .= '<div class="widget-meta"><span class="date">' . $date . '</span> ' . $comment . '</div>'; $rt_posts .= $show_excerpt ? '' . wp_html_excerpt(get_the_excerpt(), $limit) . '...' . '<div class="space margin-b10"></div>' : ""; $rt_posts .= '</li>'; } } wp_reset_query(); $rt_posts .= '</ul></div>'; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo $rt_posts; echo $after_widget; }
function lbmn_get_menuid_by_menutitle($menu_name) { $menus = wp_get_nav_menus(); // get all menus $menu_id = 0; foreach ($menus as $menu) { $current_menu_name = wp_html_excerpt($menu->name, 40, '…'); if ($menu_name == $current_menu_name) { $menu_id = $menu->term_id; } } return $menu_id; }
function sys_popular_posts($atts, $content = null) { extract(shortcode_atts(array('limit' => '2', 'description' => '40', 'thumb' => 'true', 'popular_select' => 'time'), $atts)); $out = '<div class="widget_postslist sc">'; $out .= '<ul>'; global $wpdb; $popular_limits = $limit; $show_pass_post = false; $duration = ''; $request = "SELECT ID, post_title,post_date,post_content, COUNT({$wpdb->comments}.comment_post_ID) AS 'comment_count' FROM {$wpdb->posts}, {$wpdb->comments}"; $request .= " WHERE comment_approved = '1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID AND post_status = 'publish'"; if (!$show_pass_post) { $request .= " AND post_password =''"; } if ($duration != "") { $request .= " AND DATE_SUB(CURDATE(),INTERVAL " . $duration . " DAY) < post_date "; } $request .= " GROUP BY {$wpdb->comments}.comment_post_ID ORDER BY comment_count DESC LIMIT {$popular_limits}"; $popular_posts = $wpdb->get_results($request); foreach ($popular_posts as $post) { if ($post) { $post_date = $post->post_date; $post_date = mysql2date('F j, Y', $post_date, false); $out .= "<li>"; if ($thumb == "true") { $thumbid = get_post_thumbnail_id($post->ID); $imgesc = wp_get_attachment_image_src($thumbid, array(9999, 9999)); $out .= '<div class="thumb"><a href="' . get_permalink($post->ID) . '" title="' . $post->post_title . '">'; if ($thumbid) { $out .= atp_resize('', $imgesc['0'], '50', '50', 'imgborder', ''); } else { //$out .= '<img class="imgborder" src="'. THEME_URI.'/images/no-image.jpg" title="'.$post->post_title.'" alt="" />'; } $out .= '</a></div>'; } $out .= '<div class="pdesc"><a href="' . get_permalink($post->ID) . '" rel="bookmark">' . $post->post_title . '</a>'; if ($popular_select == 'time') { $out .= '<div class="w-postmeta"><span>' . $post_date . '</span></div>'; } else { $out .= '<p>' . wp_html_excerpt($post->post_content, $description, '...') . '</p>'; } $out .= '</div></li>'; } } $out .= '</ul></div>'; return $out; wp_reset_query(); }
function xtreme_dashboard_rss_widget() { $url = 'https://github.com/xtreme-themes/xtreme-one/releases.atom'; $news = fetch_feed($url); if (is_wp_error($news)) { if (is_admin() || current_user_can('manage_options')) { echo '<p>'; printf(__('<strong>RSS Error</strong>: %s', XF_TEXTDOMAIN), $news->get_error_message()); echo '</p>'; } return; } if (!$news->get_item_quantity()) { echo '<p>' . __('An error has occurred; the feed is probably down. Try again later.', XF_TEXTDOMAIN) . '</p>'; return; } echo '<ul>'; foreach ($news->get_items(0, 5) as $item) { $link = $item->get_link(); while (stristr($link, 'http') != $link) { $link = substr($link, 1); } $link = esc_url(strip_tags($link)); $title = esc_attr(strip_tags($item->get_title())); if (empty($title)) { $title = __('Untitled', XF_TEXTDOMAIN); } $desc = str_replace(array("\n", "\r"), ' ', esc_attr(strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))))); $desc = wp_html_excerpt($desc, 360) . ' […]'; $desc = esc_html($desc); $summary = "<div class='rssSummary'>{$desc}</div>"; $date = $item->get_date(); if ($date) { if ($date_stamp = strtotime($date)) { $date = ' <span class="rss-date">' . date_i18n(get_option('date_format'), $date_stamp) . '</span>'; } else { $date = ''; } } if ($link == '') { echo "<li>{$title}{$date}{$summary}{$author}</li>"; } else { echo "<li><a class='rsswidget' href='{$link}' title='{$desc}'>{$title}</a>{$date}{$summary}</li>"; } } echo '</ul>'; }
function widget($args, $instance) { extract($args); $title = esc_attr($instance['title']); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <?php $comments = get_comments('status=approve&number=1'); ?> <?php foreach ($comments as $comment) { ?> <?php $title = get_the_title($comment->comment_post_ID); echo '<div class="whosaid"><p>Recently ' . $comment->comment_author . ''; _e(' said: ', 'cebolang'); ?> </p><span class="icon-right-quote" aria-hidden="true"></span></div><p class="quoter"> "<?php echo wp_html_excerpt($comment->comment_content, 112); ?> …"</p> <div class="saidmore"><p><a href="<?php echo get_permalink($comment->comment_post_ID); ?> " rel="external nofollow" title="<?php echo $title; ?> "><?php _e('Read The Post ', 'cebolang'); ?> </a></p></div> <?php } ?> <?php echo $after_widget; }
function tc_alter_wp_customizer_settings($wp_customize) { //CHANGE BLOGNAME AND BLOGDESCRIPTION TRANSPORT $wp_customize->get_setting('blogname')->transport = 'postMessage'; $wp_customize->get_setting('blogdescription')->transport = 'postMessage'; //CHANGE NAV SECTION DESCRIPTION $_complement_descr = sprintf(' <a class="button-primary" href="%2$s" target="_blank">%3$s</a><p>%1$s</p>', __('If a location nas no menu assigned, a default page menu will be used.', 'customizr'), admin_url('nav-menus.php'), __('Manage menus', 'customizr')); $wp_customize->get_section('nav')->description .= $_complement_descr; //CHANGE MENUS PROPERTIES $locations = get_registered_nav_menus(); $menus = wp_get_nav_menus(); $choices = array('' => __('— Select —', 'customizr')); foreach ($menus as $menu) { $choices[$menu->term_id] = wp_html_excerpt($menu->name, 40, '…'); } $_priorities = array('main' => 10, 'secondary' => 20); //WP only adds the menu(s) settings and controls if the user has created at least one menu. //1) if no menus yet, we still want to display the menu picker + add a notice with a link to the admin menu creation panel //=> add_setting and add_control for each menu location. Check if they are set first by security //2) if user has already created a menu, the settings are already created, we just need to update the controls. $_priority = 0; //assign new priorities to the menus controls foreach ($locations as $location => $description) { $menu_setting_id = "nav_menu_locations[{$location}]"; //create the settings if they don't exist //=> in the condition, make sure that the setting has really not been created yet (maybe over secured) if (!$menus && !is_object($wp_customize->get_setting($menu_setting_id))) { $wp_customize->add_setting($menu_setting_id, array('sanitize_callback' => 'absint', 'theme_supports' => 'menus')); } //remove the controls if they exists if (is_object($wp_customize->get_control($menu_setting_id))) { $wp_customize->remove_control($menu_setting_id); } //replace the controls by our custom controls $_control_properties = array('label' => $description, 'section' => 'nav', 'title' => "main" == $location ? __('Assign menus to locations', 'customizr') : false, 'type' => 'select', 'choices' => $choices, 'priority' => isset($_priorities[$location]) ? $_priorities[$location] : $_priority); //add a notice property if no menu created yet. if (!$menus) { $_control_properties['notice'] = sprintf(__("You haven't created any menu yet. %s or check the %s to learn more about menus.", "customizr"), sprintf('<strong><a href="%1$s" title="%2$s">%2$s</a></strong>', admin_url('nav-menus.php'), __("Create a new menu now", "customizr")), sprintf('<a href="%1$s" title="%2$s" target="_blank">%2$s</a>', esc_url('codex.wordpress.org/WordPress_Menu_User_Guide'), __("WordPress documentation", "customizr"))); } $wp_customize->add_control(new TC_controls($wp_customize, $menu_setting_id, $_control_properties)); $_priority = $_priority + 10; } //foreach }
/** * Returns Slider Markup * * @param string $category_name The Name of Category which post to shown in slider * @param int $slide_number The number of posts to show in slider * @param int $content_length The character limit for content * @param bool $show_title Set true to show title * @param bool $show_excerpt Set true to show excerpt content * @param bool $show_navigation Set true to show slider navigation * @param bool $show_pagination Set true to show slider pagination * @return string * * @since rtPanelChild 1.0 */ function rtp_get_cycle_slider($category_name = '', $slide_number = 10, $content_length = 100, $show_title = true, $show_excerpt = true, $show_navigation = true, $show_pagination = true) { $slider_q = new WP_Query(array('category_name' => $category_name, 'ignore_sticky_posts' => 1, 'posts_per_page' => $slide_number, 'order' => 'DESC')); if (!count($slider_q)) { $slider_q = new WP_Query(array('ignore_sticky_posts' => 1, 'posts_per_page' => $slide_number, 'order' => 'DESC')); } $slider_image = ''; $slider_pagination = false; $slider_html = '<div id="rtp-cycle-slider">'; if ($slider_q->have_posts()) { $slider_html .= '<div class="rtp-cycle-slider-container">'; while ($slider_q->have_posts()) { $slider_q->the_post(); if (has_post_thumbnail()) { $image_details = wp_get_attachment_image_src(get_post_thumbnail_id(), 'rtp-slider'); $slider_image = $image_details[0]; } else { $slider_image = rtp_generate_thumbs('', 'rtp-slider'); } if ($slider_image) { $slider_html .= '<div class="cycle-slides">'; $slider_html .= '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '"><img class="cycle-slider-img" src ="' . $slider_image . '" alt="' . esc_attr(get_the_title()) . '" /></a>'; $slider_html .= $show_title ? '<h1><a href="' . get_permalink() . '" title="' . get_the_title() . '" rel="bookmark">' . (strlen(get_the_title()) > 50 ? substr(get_the_title(), 0, 50) . "..." : get_the_title()) . '</a></h1>' : ''; $slider_html .= $show_excerpt ? strlen(get_the_content()) > $content_length ? wp_html_excerpt(get_the_content(), $content_length) . '...' : wp_html_excerpt(get_the_content(), $content_length) : ''; $slider_html .= '</div>'; } $slider_pagination = true; } $slider_html .= '</div>'; } wp_reset_postdata(); /* Uncomment following line if using pagination in the slider */ if ($slider_pagination && ($show_navigation || $show_pagination)) { $slider_html .= '<div class="rtp-cycle-pagination">'; $slider_html .= $show_navigation ? '<a href="#" id="rtp-prev-cycle" class="previous-cycle"><span>' . __('Prev', 'rtPanel') . '</span></a><a href="#" id="rtp-next-cycle" class="next-cycle"><span>' . __('Next', 'rtPanel') . '</span></a>' : ''; $slider_html .= $show_pagination ? '<div id="rtp-cycle-nav" class="rtp-pagination"></div>' : ''; $slider_html .= '</div>'; } $slider_html .= '</div>'; echo $slider_html; }
function widget($args, $instance) { $data = array(); $data['title'] = apply_filters('widget_title', empty($instance['title']) ? __('Feed') : $instance['title'], $instance, $this->id_base); // fetch rss/atom feed $rss = $instance['feed']; $rss = fetch_feed($rss); // check for errors if (!$rss->get_item_quantity()) { echo '<ul><li>' . __('An error has occurred; the feed is probably down. Try again later.') . '</li></ul>'; $rss->__destruct(); unset($rss); return; } $item_count = 5; $data['feed'] = $instance['feed']; $data['items'] = array(); foreach ($rss->get_items(0, $item_count) as $item) { $link = $item->get_link(); while (stristr($link, 'http') != $link) { $link = substr($link, 1); } $link = esc_url(strip_tags($link)); $title = esc_attr(strip_tags($item->get_title())); $desc = str_replace(array("\n", "\r"), ' ', esc_attr(strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))))); $desc = wp_html_excerpt($desc, 360); $desc = esc_html($desc); $date = $item->get_date('U'); $author = $item->get_author(); if (is_object($author)) { $author = $author->get_name(); $author = esc_html(strip_tags($author)); } else { $author = null; } $data['items'][] = array('title' => $title, 'link' => $link, 'description' => $desc, 'date' => date_i18n(get_option('date_format'), $date), 'author' => $author); } $rss->__destruct(); unset($rss); $this->display($instance, $data); }
function dialogue_manage_comment_custom_column($col, $comment_id = 0) { $comment = get_comment($comment_id, ARRAY_A); $cmid = $comment['comment_ID']; if ($col == 'comment_content') { echo '<strong>Opinião</strong><br />'; echo '<div>' . get_comment_meta($cmid, 'opiniao', true) . '</div>'; echo '<strong>Proposta</strong><br />'; echo '<div>' . get_comment_meta($cmid, 'proposta', true) . '</div>'; if (trim(get_comment_meta($cmid, 'contribuicao', true) != '')) { echo '<strong>Contribuição</strong>'; echo '<div>' . get_comment_meta($cmid, 'contribuicao', true) . '</div>'; } } else { if ($col == 'justificativa') { echo '<div>' . get_comment_meta($cmid, 'justificativa', true) . '</div>'; } else { if ($col == 'dialogue_paragraph') { $post = get_post($comment["comment_post_ID"]); $pid = (string) get_comment_meta($comment['comment_ID'], DIALOGUE_CF_PARAGRAPH, true); $paragraphs = dialogue_api_parse_content(wpautop($post->post_content)); $paragraph = $paragraphs[$pid]; echo "<strong>{$pid}</strong> &mdash "; echo wp_html_excerpt($paragraph, 128) . '...'; } else { if ($col == 'dialogue_tags') { $cid = $comment["comment_ID"]; $tags = dialogue_api_get_comment_tags($cid); $len = sizeof($tags); for ($i = 0; $i < $len; $i++) { $name = $tags[$i]->name; if (trim($name) == "") { continue; } echo "#{$name}" . ($i != $len - 1 ? ", " : ""); } } } } } }
function widget($args, $instance) { global $comments, $comment; $cache = wp_cache_get('widget_recent_comments_avatar', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } extract($args, EXTR_SKIP); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments', 'delaware-theme') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 5; } $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentcomments">'; if ($comments) { foreach ((array) $comments as $comment) { $avatar = get_avatar($comment->comment_author_email, '45'); $comment_excerpt = wp_html_excerpt($comment->comment_content, 72); $output .= '<li class="recentcomments clearfix"><div class="comments_avatar">' . $avatar . '</div><div class="l-description"><span>' . sprintf(_x('%1$s on %2$s', 'widgets', 'delaware-theme'), get_comment_author(), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</span><br /><span class="recentcomments-text">' . $comment_excerpt . '...</span></div></li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_recent_comments_avatar', $cache, 'widget'); }
/** * Build our widget and output the posts. * * Look for our RSS feed, parse for errors, and then loop through the results. */ public function build_the_widget() { $rss = fetch_feed($this->feed_url); // Look for errors and outut if necessary $errors = $this->parse_for_errors($rss); if (!empty($errors)) { echo $errors; return; } // Start the output echo "<ul>\n"; // Loop through posts foreach ($rss->get_items(0, $this->num_posts) as $item) { echo "<li class='rss-widget'>"; echo "<a class='rsswidget' href='" . esc_url(strip_tags($item->get_link())) . "'>" . esc_html($item->get_title()) . "</a>"; echo "<span class='rss-date'> - " . $item->get_date('F jS, Y') . "</span>\n"; echo "<div class='rssSummary'>" . wp_html_excerpt($item->get_content(), 350) . "...</div>\n\r\n"; echo "</li>"; } echo "</ul>\n"; $rss->__destruct(); unset($rss); }
function gabfire_dashboard_widget_function() { $rss = fetch_feed("http://feeds.feedburner.com/gabfirethemes"); if (is_wp_error($rss)) { if (is_admin() || current_user_can('manage_options')) { echo '<p><strong>'; echo $rss->get_error_message(); echo '</strong></p>'; } return; } if (!$rss->get_item_quantity()) { echo '<p>Gabfire Themes!</p>'; $rss->__destruct(); unset($rss); return; } echo "<ul>\n"; if (!isset($items)) { $items = 3; } foreach ($rss->get_items(0, $items) as $item) { $link = ''; $content = ''; $date = ''; $title = ''; $title = strip_tags($item->get_title()); $date = strip_tags($item->get_date('M j Y')); $link = esc_url(strip_tags($item->get_link())); $content = $item->get_content(); $content = wp_html_excerpt($content, 300) . ' ...'; echo "<li><a class='rsswidget' href='{$link}'>{$title}</a> <span class='rss-date'>{$date}</span> <div class='rssSummary'>{$content}</div></li>\n"; } echo "</ul>\n"; $rss->__destruct(); unset($rss); }
function dashboard_widget_function() { $rss = fetch_feed("https://sites.akdigitalegesellschaft.de/feed/"); if (is_wp_error($rss)) { if (is_admin() || current_user_can('manage_options')) { echo '<p>'; printf(__('<strong>RSS Fehler</strong>: %s'), $rss->get_error_message()); echo '</p>'; } return; } if (!$rss->get_item_quantity()) { echo '<p>Offenbar gibt es nichts Neues…</p>'; $rss->__destruct(); unset($rss); return; } echo "<ul>\n"; if (!isset($items)) { $items = 5; } foreach ($rss->get_items(0, $items) as $item) { $publisher = ''; $site_link = ''; $link = ''; $content = ''; $date = ''; $link = esc_url(strip_tags($item->get_link())); $title = esc_html($item->get_title()); $content = $item->get_content(); $content = wp_html_excerpt($content, 250) . '…'; echo "<li><a class='rsswidget' href='{$link}' target='_blank'>{$title}</a>\n<div class='rssSummary'>{$content}</div>\n"; } echo "</ul>\n"; $rss->__destruct(); unset($rss); }
function e2wdashboard_rss_dashboard_widget_function() { $rss = fetch_feed("http://www.expand2web.com/blog/feed/rss/"); if (is_wp_error($rss)) { if (is_admin() || current_user_can('manage_options')) { echo '<p>'; printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message()); echo '</p>'; } return; } if (!$rss->get_item_quantity()) { echo '<p>Visit Expand2web.com - Our feed must be down.</p>'; $rss->__destruct(); unset($rss); return; } echo "<ul>\n"; if (!isset($items)) { $items = 6; } foreach ($rss->get_items(0, $items) as $item) { $publisher = ''; $site_link = ''; $link = ''; $content = ''; $date = ''; $link = esc_url(strip_tags($item->get_link())); $title = $item->get_title(); $content = $item->get_content(); $content = wp_html_excerpt($content, 150) . ' ...'; echo "\t<li><a class='rsswidget' href='{$link}'>{$title}</a><br /> {$content}</li>\n"; } echo "</ul>\n"; $rss->__destruct(); unset($rss); }
/** * Generates the recent comments markup. */ function cwp_get_recent_comments($args = array()) { // Set up a default, empty variable. $html = ''; // Merge the input arguments and the defaults. $args = wp_parse_args($args, cwp_get_default_args()); // Extract the array to allow easy use of variables. extract($args); // Allow devs to hook in stuff before the recent comments. do_action('cwp_before_loop'); // Recent comments query. $comments = cwp_get_comments($args); if (is_array($comments) && $comments) { $html = '<ul class="cwp-ul ' . (!empty($args['css_class']) ? '' . sanitize_html_class($args['css_class']) . '' : '') . '">'; foreach ($comments as $comment) { $html .= '<li class="recentcomments cwp-li">'; if ($args['avatar']) { $html .= '<a class="comment-link cwp-comment-link" href="' . esc_url(get_comment_link($comment->comment_ID)) . '">'; $html .= '<span class="comment-avatar cwp-avatar">' . get_avatar($comment->comment_author_email, $args['avatar_size']) . '</span>'; $html .= '</a>'; } $html .= '<span class="cwp-comment-title">'; /* translators: comments widget: 1: comment author, 4: post link */ $html .= sprintf(_x('%1$s %2$son%3$s %4$s', 'widgets', 'comments-widget-plus'), '<span class="comment-author-link cwp-author-link">' . get_comment_author_link($comment->comment_ID) . '</span>', '<span class="cwp-on-text">', '</span>', '<a class="comment-link cwp-comment-link" href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>'); $html .= '</span>'; if ($args['excerpt']) { $html .= '<span class="comment-excerpt cwp-comment-excerpt">' . wp_html_excerpt($comment->comment_content, $args['excerpt_limit'], '…') . '</span>'; } $html .= '</li>'; } $html .= '</ul>'; } // Allow devs to hook in stuff after the loop. do_action('cwp_after_loop'); // Return the posts markup. return $html; }
/** * Display the Groups admin index screen. * * This screen contains a list of all BuddyPress groups. * * @since 1.7.0 * * @global BP_Groups_List_Table $bp_groups_list_table Group screen list table. * @global string $plugin_page Currently viewed plugin page. */ function bp_groups_admin_index() { global $bp_groups_list_table, $plugin_page; $messages = array(); // If the user has just made a change to a group, build status messages if (!empty($_REQUEST['deleted'])) { $deleted = !empty($_REQUEST['deleted']) ? (int) $_REQUEST['deleted'] : 0; if ($deleted > 0) { $messages[] = sprintf(_n('%s group has been permanently deleted.', '%s groups have been permanently deleted.', $deleted, 'buddypress'), number_format_i18n($deleted)); } } // Prepare the group items for display $bp_groups_list_table->prepare_items(); /** * Fires before the display of messages for the edit form. * * Useful for plugins to modify the messages before display. * * @since 1.7.0 * * @param array $messages Array of messages to be displayed. */ do_action('bp_groups_admin_index', $messages); ?> <div class="wrap"> <?php screen_icon('buddypress-groups'); ?> <h2> <?php _e('Groups', 'buddypress'); ?> <?php if (is_user_logged_in() && bp_user_can_create_groups()) { ?> <a class="add-new-h2" href="<?php echo trailingslashit(bp_get_groups_directory_permalink() . 'create'); ?> "><?php _e('Add New', 'buddypress'); ?> </a> <?php } ?> <?php if (!empty($_REQUEST['s'])) { ?> <span class="subtitle"><?php printf(__('Search results for “%s”', 'buddypress'), wp_html_excerpt(esc_html(stripslashes($_REQUEST['s'])), 50)); ?> </span> <?php } ?> </h2> <?php // If the user has just made a change to an group, display the status messages ?> <?php if (!empty($messages)) { ?> <div id="moderated" class="<?php echo !empty($_REQUEST['error']) ? 'error' : 'updated'; ?> "><p><?php echo implode("<br/>\n", $messages); ?> </p></div> <?php } ?> <?php // Display each group on its own row ?> <?php $bp_groups_list_table->views(); ?> <form id="bp-groups-form" action="" method="get"> <?php $bp_groups_list_table->search_box(__('Search all Groups', 'buddypress'), 'bp-groups'); ?> <input type="hidden" name="page" value="<?php echo esc_attr($plugin_page); ?> " /> <?php $bp_groups_list_table->display(); ?> </form> </div> <?php }
/** * Display the RSS entries in a list. * * @since 2.5.0 * * @param string|array|object $rss RSS url. * @param array $args Widget arguments. */ function wp_widget_rss_output($rss, $args = array()) { if (is_string($rss)) { $rss = fetch_feed($rss); } elseif (is_array($rss) && isset($rss['url'])) { $args = $rss; $rss = fetch_feed($rss['url']); } elseif (!is_object($rss)) { return; } if (is_wp_error($rss)) { if (is_admin() || current_user_can('manage_options')) { echo '<p>' . sprintf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message()) . '</p>'; } return; } $default_args = array('show_author' => 0, 'show_date' => 0, 'show_summary' => 0); $args = wp_parse_args($args, $default_args); extract($args, EXTR_SKIP); $items = (int) $items; if ($items < 1 || 20 < $items) { $items = 10; } $show_summary = (int) $show_summary; $show_author = (int) $show_author; $show_date = (int) $show_date; if (!$rss->get_item_quantity()) { echo '<ul><li>' . __('An error has occurred; the feed is probably down. Try again later.') . '</li></ul>'; $rss->__destruct(); unset($rss); return; } echo '<ul>'; foreach ($rss->get_items(0, $items) as $item) { $link = $item->get_link(); while (stristr($link, 'http') != $link) { $link = substr($link, 1); } $link = esc_url(strip_tags($link)); $title = esc_attr(strip_tags($item->get_title())); if (empty($title)) { $title = __('Untitled'); } $desc = str_replace(array("\n", "\r"), ' ', esc_attr(strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))))); $desc = wp_html_excerpt($desc, 360); // Append ellipsis. Change existing [...] to […]. if ('[...]' == substr($desc, -5)) { $desc = substr($desc, 0, -5) . '[…]'; } elseif ('[…]' != substr($desc, -10)) { $desc .= ' […]'; } $desc = esc_html($desc); if ($show_summary) { $summary = "<div class='rssSummary'>{$desc}</div>"; } else { $summary = ''; } $date = ''; if ($show_date) { $date = $item->get_date('U'); if ($date) { $date = ' <span class="rss-date">' . date_i18n(get_option('date_format'), $date) . '</span>'; } } $author = ''; if ($show_author) { $author = $item->get_author(); if (is_object($author)) { $author = $author->get_name(); $author = ' <cite>' . esc_html(strip_tags($author)) . '</cite>'; } } if ($link == '') { echo "<li>{$title}{$date}{$summary}{$author}</li>"; } else { echo "<li><a class='rsswidget' href='{$link}' title='{$desc}'>{$title}</a>{$date}{$summary}{$author}</li>"; } } echo '</ul>'; $rss->__destruct(); unset($rss); }
/** * Retrieve HTML form for modifying the image attachment. * * @since 2.5.0 * * @param int $attachment_id Attachment ID for modification. * @param string|array $args Optional. Override defaults. * @return string HTML form for attachment. */ function get_media_item($attachment_id, $args = null) { global $redir_tab; if (($attachment_id = intval($attachment_id)) && ($thumb_url = wp_get_attachment_image_src($attachment_id, 'thumbnail', true))) { $thumb_url = $thumb_url[0]; } else { $thumb_url = false; } $post = get_post($attachment_id); $current_post_id = !empty($_GET['post_id']) ? (int) $_GET['post_id'] : 0; $default_args = array('errors' => null, 'send' => $current_post_id ? post_type_supports(get_post_type($current_post_id), 'editor') : true, 'delete' => true, 'toggle' => true, 'show_title' => true); $args = wp_parse_args($args, $default_args); /** * Filter the arguments used to retrieve an image for the edit image form. * * @since 3.1.0 * * @see get_media_item * * @param array $args An array of arguments. */ $r = apply_filters('get_media_item_args', $args); $toggle_on = __('Show'); $toggle_off = __('Hide'); $filename = esc_html(wp_basename($post->guid)); $title = esc_attr($post->post_title); $post_mime_types = get_post_mime_types(); $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type)); $type = array_shift($keys); $type_html = "<input type='hidden' id='type-of-{$attachment_id}' value='" . esc_attr($type) . "' />"; $form_fields = get_attachment_fields_to_edit($post, $r['errors']); if ($r['toggle']) { $class = empty($r['errors']) ? 'startclosed' : 'startopen'; $toggle_links = "\n\t<a class='toggle describe-toggle-on' href='#'>{$toggle_on}</a>\n\t<a class='toggle describe-toggle-off' href='#'>{$toggle_off}</a>"; } else { $class = ''; $toggle_links = ''; } $display_title = !empty($title) ? $title : $filename; // $title shouldn't ever be empty, but just in case $display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt($display_title, 60, '…') . "</span></div>" : ''; $gallery = isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab'] || isset($redir_tab) && 'gallery' == $redir_tab; $order = ''; foreach ($form_fields as $key => $val) { if ('menu_order' == $key) { if ($gallery) { $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[{$attachment_id}][menu_order]' name='attachments[{$attachment_id}][menu_order]' value='" . esc_attr($val['value']) . "' /></div>"; } else { $order = "<input type='hidden' name='attachments[{$attachment_id}][menu_order]' value='" . esc_attr($val['value']) . "' />"; } unset($form_fields['menu_order']); break; } } $media_dims = ''; $meta = wp_get_attachment_metadata($post->ID); if (isset($meta['width'], $meta['height'])) { $media_dims .= "<span id='media-dims-{$post->ID}'>{$meta['width']} × {$meta['height']}</span> "; } /** * Filter the media metadata. * * @since 2.5.0 * * @param string $media_dims The HTML markup containing the media dimensions. * @param WP_Post $post The WP_Post attachment object. */ $media_dims = apply_filters('media_meta', $media_dims, $post); $image_edit_button = ''; if (wp_attachment_is_image($post->ID) && wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) { $nonce = wp_create_nonce("image_editor-{$post->ID}"); $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>"; } $attachment_url = get_permalink($attachment_id); $item = "\n\t{$type_html}\n\t{$toggle_links}\n\t{$order}\n\t{$display_title}\n\t<table class='slidetoggle describe {$class}'>\n\t\t<thead class='media-item-info' id='media-head-{$post->ID}'>\n\t\t<tr>\n\t\t\t<td class='A1B1' id='thumbnail-head-{$post->ID}'>\n\t\t\t<p><a href='{$attachment_url}' target='_blank'><img class='thumbnail' src='{$thumb_url}' alt='' /></a></p>\n\t\t\t<p>{$image_edit_button}</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><strong>" . __('File name:') . "</strong> {$filename}</p>\n\t\t\t<p><strong>" . __('File type:') . "</strong> {$post->post_mime_type}</p>\n\t\t\t<p><strong>" . __('Upload date:') . "</strong> " . mysql2date(get_option('date_format'), $post->post_date) . '</p>'; if (!empty($media_dims)) { $item .= "<p><strong>" . __('Dimensions:') . "</strong> {$media_dims}</p>\n"; } $item .= "</td></tr>\n"; $item .= "\n\t\t</thead>\n\t\t<tbody>\n\t\t<tr><td colspan='2' class='imgedit-response' id='imgedit-response-{$post->ID}'></td></tr>\n\t\t<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-{$post->ID}'></td></tr>\n"; $defaults = array('input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array()); if ($r['send']) { $r['send'] = get_submit_button(__('Insert into Post'), 'button', "send[{$attachment_id}]", false); } $delete = empty($r['delete']) ? '' : $r['delete']; if ($delete && current_user_can('delete_post', $attachment_id)) { if (!EMPTY_TRASH_DAYS) { $delete = "<a href='" . wp_nonce_url("post.php?action=delete&post={$attachment_id}", 'delete-post_' . $attachment_id) . "' id='del[{$attachment_id}]' class='delete-permanently'>" . __('Delete Permanently') . '</a>'; } elseif (!MEDIA_TRASH) { $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_{$attachment_id}').style.display='block';return false;\">" . __('Delete') . "</a>\n\t\t\t <div id='del_attachment_{$attachment_id}' class='del-attachment' style='display:none;'><p>" . sprintf(__('You are about to delete <strong>%s</strong>.'), $filename) . "</p>\n\t\t\t <a href='" . wp_nonce_url("post.php?action=delete&post={$attachment_id}", 'delete-post_' . $attachment_id) . "' id='del[{$attachment_id}]' class='button'>" . __('Continue') . "</a>\n\t\t\t <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a>\n\t\t\t </div>"; } else { $delete = "<a href='" . wp_nonce_url("post.php?action=trash&post={$attachment_id}", 'trash-post_' . $attachment_id) . "' id='del[{$attachment_id}]' class='delete'>" . __('Move to Trash') . "</a>\n\t\t\t<a href='" . wp_nonce_url("post.php?action=untrash&post={$attachment_id}", 'untrash-post_' . $attachment_id) . "' id='undo[{$attachment_id}]' class='undo hidden'>" . __('Undo') . "</a>"; } } else { $delete = ''; } $thumbnail = ''; $calling_post_id = 0; if (isset($_GET['post_id'])) { $calling_post_id = absint($_GET['post_id']); } elseif (isset($_POST) && count($_POST)) { // Like for async-upload where $_GET['post_id'] isn't set $calling_post_id = $post->post_parent; } if ('image' == $type && $calling_post_id && current_theme_supports('post-thumbnails', get_post_type($calling_post_id)) && post_type_supports(get_post_type($calling_post_id), 'thumbnail') && get_post_thumbnail_id($calling_post_id) != $attachment_id) { $ajax_nonce = wp_create_nonce("set_post_thumbnail-{$calling_post_id}"); $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"{$attachment_id}\", \"{$ajax_nonce}\");return false;'>" . esc_html__("Use as featured image") . "</a>"; } if (($r['send'] || $thumbnail || $delete) && !isset($form_fields['buttons'])) { $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " {$thumbnail} {$delete}</td></tr>\n"); } $hidden_fields = array(); foreach ($form_fields as $id => $field) { if ($id[0] == '_') { continue; } if (!empty($field['tr'])) { $item .= $field['tr']; continue; } $field = array_merge($defaults, $field); $name = "attachments[{$attachment_id}][{$id}]"; if ($field['input'] == 'hidden') { $hidden_fields[$name] = $field['value']; continue; } $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; $aria_required = $field['required'] ? " aria-required='true' " : ''; $class = $id; $class .= $field['required'] ? ' form-required' : ''; $item .= "\t\t<tr class='{$class}'>\n\t\t\t<th scope='row' class='label'><label for='{$name}'><span class='alignleft'>{$field['label']}</span>{$required}<br class='clear' /></label></th>\n\t\t\t<td class='field'>"; if (!empty($field[$field['input']])) { $item .= $field[$field['input']]; } elseif ($field['input'] == 'textarea') { if ('post_content' == $id && user_can_richedit()) { // Sanitize_post() skips the post_content when user_can_richedit. $field['value'] = htmlspecialchars($field['value'], ENT_QUOTES); } // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). $item .= "<textarea id='{$name}' name='{$name}' {$aria_required}>" . $field['value'] . '</textarea>'; } else { $item .= "<input type='text' class='text' id='{$name}' name='{$name}' value='" . esc_attr($field['value']) . "' {$aria_required} />"; } if (!empty($field['helps'])) { $item .= "<p class='help'>" . join("</p>\n<p class='help'>", array_unique((array) $field['helps'])) . '</p>'; } $item .= "</td>\n\t\t</tr>\n"; $extra_rows = array(); if (!empty($field['errors'])) { foreach (array_unique((array) $field['errors']) as $error) { $extra_rows['error'][] = $error; } } if (!empty($field['extra_rows'])) { foreach ($field['extra_rows'] as $class => $rows) { foreach ((array) $rows as $html) { $extra_rows[$class][] = $html; } } } foreach ($extra_rows as $class => $rows) { foreach ($rows as $html) { $item .= "\t\t<tr><td></td><td class='{$class}'>{$html}</td></tr>\n"; } } } if (!empty($form_fields['_final'])) { $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; } $item .= "\t</tbody>\n"; $item .= "\t</table>\n"; foreach ($hidden_fields as $name => $value) { $item .= "\t<input type='hidden' name='{$name}' id='{$name}' value='" . esc_attr($value) . "' />\n"; } if ($post->post_parent < 1 && isset($_REQUEST['post_id'])) { $parent = (int) $_REQUEST['post_id']; $parent_name = "attachments[{$attachment_id}][post_parent]"; $item .= "\t<input type='hidden' name='{$parent_name}' id='{$parent_name}' value='{$parent}' />\n"; } return $item; }