PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/link-template.php

https://github.com/gplsek/competitor-mu
PHP | 1507 lines | 821 code | 201 blank | 485 comment | 209 complexity | a7110d9052cf2dedbbcff430df74e6fa MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * WordPress Link Template Functions
  4. *
  5. * @package WordPress
  6. * @subpackage Template
  7. */
  8. /**
  9. * Display the permalink for the current post.
  10. *
  11. * @since 1.2.0
  12. * @uses apply_filters() Calls 'the_permalink' filter on the permalink string.
  13. */
  14. function the_permalink() {
  15. echo apply_filters('the_permalink', get_permalink());
  16. }
  17. /**
  18. * Retrieve trailing slash string, if blog set for adding trailing slashes.
  19. *
  20. * Conditionally adds a trailing slash if the permalink structure has a trailing
  21. * slash, strips the trailing slash if not. The string is passed through the
  22. * 'user_trailingslashit' filter. Will remove trailing slash from string, if
  23. * blog is not set to have them.
  24. *
  25. * @since 2.2.0
  26. * @uses $wp_rewrite
  27. *
  28. * @param $string String a URL with or without a trailing slash.
  29. * @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter.
  30. * @return string
  31. */
  32. function user_trailingslashit($string, $type_of_url = '') {
  33. global $wp_rewrite;
  34. if ( $wp_rewrite->use_trailing_slashes )
  35. $string = trailingslashit($string);
  36. else
  37. $string = untrailingslashit($string);
  38. // Note that $type_of_url can be one of following:
  39. // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
  40. $string = apply_filters('user_trailingslashit', $string, $type_of_url);
  41. return $string;
  42. }
  43. /**
  44. * Display permalink anchor for current post.
  45. *
  46. * The permalink mode title will use the post title for the 'a' element 'id'
  47. * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
  48. *
  49. * @since 0.71
  50. *
  51. * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
  52. */
  53. function permalink_anchor($mode = 'id') {
  54. global $post;
  55. switch ( strtolower($mode) ) {
  56. case 'title':
  57. $title = sanitize_title($post->post_title) . '-' . $post->ID;
  58. echo '<a id="'.$title.'"></a>';
  59. break;
  60. case 'id':
  61. default:
  62. echo '<a id="post-' . $post->ID . '"></a>';
  63. break;
  64. }
  65. }
  66. /**
  67. * Retrieve full permalink for current post or post ID.
  68. *
  69. * @since 1.0.0
  70. *
  71. * @param int $id Optional. Post ID.
  72. * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
  73. * @return string
  74. */
  75. function get_permalink($id = 0, $leavename = false) {
  76. $rewritecode = array(
  77. '%year%',
  78. '%monthnum%',
  79. '%day%',
  80. '%hour%',
  81. '%minute%',
  82. '%second%',
  83. $leavename? '' : '%postname%',
  84. '%post_id%',
  85. '%category%',
  86. '%author%',
  87. $leavename? '' : '%pagename%',
  88. );
  89. $post = &get_post($id);
  90. if ( empty($post->ID) ) return false;
  91. if ( $post->post_type == 'page' )
  92. return get_page_link($post->ID, $leavename);
  93. elseif ($post->post_type == 'attachment')
  94. return get_attachment_link($post->ID);
  95. $permalink = get_option('permalink_structure');
  96. if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
  97. $unixtime = strtotime($post->post_date);
  98. $category = '';
  99. if ( strpos($permalink, '%category%') !== false ) {
  100. $cats = get_the_category($post->ID);
  101. if ( $cats ) {
  102. usort($cats, '_usort_terms_by_ID'); // order by ID
  103. $category = $cats[0]->slug;
  104. if ( $parent = $cats[0]->parent )
  105. $category = get_category_parents($parent, false, '/', true) . $category;
  106. }
  107. // show default category in permalinks, without
  108. // having to assign it explicitly
  109. if ( empty($category) ) {
  110. $default_category = get_category( get_option( 'default_category' ) );
  111. $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
  112. }
  113. }
  114. $author = '';
  115. if ( strpos($permalink, '%author%') !== false ) {
  116. $authordata = get_userdata($post->post_author);
  117. $author = $authordata->user_nicename;
  118. }
  119. $date = explode(" ",date('Y m d H i s', $unixtime));
  120. $rewritereplace =
  121. array(
  122. $date[0],
  123. $date[1],
  124. $date[2],
  125. $date[3],
  126. $date[4],
  127. $date[5],
  128. $post->post_name,
  129. $post->ID,
  130. $category,
  131. $author,
  132. $post->post_name,
  133. );
  134. $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
  135. $permalink = user_trailingslashit($permalink, 'single');
  136. return apply_filters('post_link', $permalink, $post, $leavename);
  137. } else { // if they're not using the fancy permalink option
  138. $permalink = get_option('home') . '/?p=' . $post->ID;
  139. return apply_filters('post_link', $permalink, $post, $leavename);
  140. }
  141. }
  142. /**
  143. * Retrieve permalink from post ID.
  144. *
  145. * @since 1.0.0
  146. *
  147. * @param int $post_id Optional. Post ID.
  148. * @param mixed $deprecated Not used.
  149. * @return string
  150. */
  151. function post_permalink($post_id = 0, $deprecated = '') {
  152. return get_permalink($post_id);
  153. }
  154. /**
  155. * Retrieve the permalink for current page or page ID.
  156. *
  157. * Respects page_on_front. Use this one.
  158. *
  159. * @since 1.5.0
  160. *
  161. * @param int $id Optional. Post ID.
  162. * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
  163. * @return string
  164. */
  165. function get_page_link($id = false, $leavename = false) {
  166. global $post;
  167. $id = (int) $id;
  168. if ( !$id )
  169. $id = (int) $post->ID;
  170. if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
  171. $link = get_option('home');
  172. else
  173. $link = _get_page_link( $id , $leavename );
  174. return apply_filters('page_link', $link, $id);
  175. }
  176. /**
  177. * Retrieve the page permalink.
  178. *
  179. * Ignores page_on_front. Internal use only.
  180. *
  181. * @since 2.1.0
  182. * @access private
  183. *
  184. * @param int $id Optional. Post ID.
  185. * @param bool $leavename Optional. Leave name.
  186. * @return string
  187. */
  188. function _get_page_link( $id = false, $leavename = false ) {
  189. global $post, $wp_rewrite;
  190. if ( !$id )
  191. $id = (int) $post->ID;
  192. else
  193. $post = &get_post($id);
  194. $pagestruct = $wp_rewrite->get_page_permastruct();
  195. if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) {
  196. $link = get_page_uri($id);
  197. $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
  198. $link = get_option('home') . "/$link";
  199. $link = user_trailingslashit($link, 'page');
  200. } else {
  201. $link = get_option('home') . "/?page_id=$id";
  202. }
  203. return apply_filters( '_get_page_link', $link, $id );
  204. }
  205. /**
  206. * Retrieve permalink for attachment.
  207. *
  208. * This can be used in the WordPress Loop or outside of it.
  209. *
  210. * @since 2.0.0
  211. *
  212. * @param int $id Optional. Post ID.
  213. * @return string
  214. */
  215. function get_attachment_link($id = false) {
  216. global $post, $wp_rewrite;
  217. $link = false;
  218. if (! $id) {
  219. $id = (int) $post->ID;
  220. }
  221. $object = get_post($id);
  222. if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
  223. $parent = get_post($object->post_parent);
  224. if ( 'page' == $parent->post_type )
  225. $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
  226. else
  227. $parentlink = get_permalink( $object->post_parent );
  228. if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
  229. $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
  230. else
  231. $name = $object->post_name;
  232. if (strpos($parentlink, '?') === false)
  233. $link = user_trailingslashit( trailingslashit($parentlink) . $name );
  234. }
  235. if (! $link ) {
  236. $link = get_bloginfo('url') . "/?attachment_id=$id";
  237. }
  238. return apply_filters('attachment_link', $link, $id);
  239. }
  240. /**
  241. * Retrieve the permalink for the year archives.
  242. *
  243. * @since 1.5.0
  244. *
  245. * @param int|bool $year False for current year or year for permalink.
  246. * @return string
  247. */
  248. function get_year_link($year) {
  249. global $wp_rewrite;
  250. if ( !$year )
  251. $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
  252. $yearlink = $wp_rewrite->get_year_permastruct();
  253. if ( !empty($yearlink) ) {
  254. $yearlink = str_replace('%year%', $year, $yearlink);
  255. return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
  256. } else {
  257. return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year);
  258. }
  259. }
  260. /**
  261. * Retrieve the permalink for the month archives with year.
  262. *
  263. * @since 1.0.0
  264. *
  265. * @param bool|int $year False for current year. Integer of year.
  266. * @param bool|int $month False for current month. Integer of month.
  267. * @return string
  268. */
  269. function get_month_link($year, $month) {
  270. global $wp_rewrite;
  271. if ( !$year )
  272. $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
  273. if ( !$month )
  274. $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
  275. $monthlink = $wp_rewrite->get_month_permastruct();
  276. if ( !empty($monthlink) ) {
  277. $monthlink = str_replace('%year%', $year, $monthlink);
  278. $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
  279. return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
  280. } else {
  281. return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
  282. }
  283. }
  284. /**
  285. * Retrieve the permalink for the day archives with year and month.
  286. *
  287. * @since 1.0.0
  288. *
  289. * @param bool|int $year False for current year. Integer of year.
  290. * @param bool|int $month False for current month. Integer of month.
  291. * @param bool|int $day False for current day. Integer of day.
  292. * @return string
  293. */
  294. function get_day_link($year, $month, $day) {
  295. global $wp_rewrite;
  296. if ( !$year )
  297. $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
  298. if ( !$month )
  299. $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
  300. if ( !$day )
  301. $day = gmdate('j', time()+(get_option('gmt_offset') * 3600));
  302. $daylink = $wp_rewrite->get_day_permastruct();
  303. if ( !empty($daylink) ) {
  304. $daylink = str_replace('%year%', $year, $daylink);
  305. $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
  306. $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
  307. return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
  308. } else {
  309. return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
  310. }
  311. }
  312. /**
  313. * Retrieve the permalink for the feed type.
  314. *
  315. * @since 1.5.0
  316. *
  317. * @param string $feed Optional, defaults to default feed. Feed type.
  318. * @return string
  319. */
  320. function get_feed_link($feed = '') {
  321. global $wp_rewrite;
  322. $permalink = $wp_rewrite->get_feed_permastruct();
  323. if ( '' != $permalink ) {
  324. if ( false !== strpos($feed, 'comments_') ) {
  325. $feed = str_replace('comments_', '', $feed);
  326. $permalink = $wp_rewrite->get_comment_feed_permastruct();
  327. }
  328. if ( get_default_feed() == $feed )
  329. $feed = '';
  330. $permalink = str_replace('%feed%', $feed, $permalink);
  331. $permalink = preg_replace('#/+#', '/', "/$permalink");
  332. $output = get_option('home') . user_trailingslashit($permalink, 'feed');
  333. } else {
  334. if ( empty($feed) )
  335. $feed = get_default_feed();
  336. if ( false !== strpos($feed, 'comments_') )
  337. $feed = str_replace('comments_', 'comments-', $feed);
  338. $output = get_option('home') . "/?feed={$feed}";
  339. }
  340. return apply_filters('feed_link', $output, $feed);
  341. }
  342. /**
  343. * Retrieve the permalink for the post comments feed.
  344. *
  345. * @since 2.2.0
  346. *
  347. * @param int $post_id Optional. Post ID.
  348. * @param string $feed Optional. Feed type.
  349. * @return string
  350. */
  351. function get_post_comments_feed_link($post_id = '', $feed = '') {
  352. global $id;
  353. if ( empty($post_id) )
  354. $post_id = (int) $id;
  355. if ( empty($feed) )
  356. $feed = get_default_feed();
  357. if ( '' != get_option('permalink_structure') ) {
  358. $url = trailingslashit( get_permalink($post_id) ) . 'feed';
  359. if ( $feed != get_default_feed() )
  360. $url .= "/$feed";
  361. $url = user_trailingslashit($url, 'single_feed');
  362. } else {
  363. $type = get_post_field('post_type', $post_id);
  364. if ( 'page' == $type )
  365. $url = get_option('home') . "/?feed=$feed&amp;page_id=$post_id";
  366. else
  367. $url = get_option('home') . "/?feed=$feed&amp;p=$post_id";
  368. }
  369. return apply_filters('post_comments_feed_link', $url);
  370. }
  371. /**
  372. * Display the comment feed link for a post.
  373. *
  374. * Prints out the comment feed link for a post. Link text is placed in the
  375. * anchor. If no link text is specified, default text is used. If no post ID is
  376. * specified, the current post is used.
  377. *
  378. * @package WordPress
  379. * @subpackage Feed
  380. * @since 2.5.0
  381. *
  382. * @param string $link_text Descriptive text.
  383. * @param int $post_id Optional post ID. Default to current post.
  384. * @param string $feed Optional. Feed format.
  385. * @return string Link to the comment feed for the current post.
  386. */
  387. function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
  388. $url = get_post_comments_feed_link($post_id, $feed);
  389. if ( empty($link_text) )
  390. $link_text = __('Comments Feed');
  391. echo "<a href='$url'>$link_text</a>";
  392. }
  393. /**
  394. * Retrieve the feed link for a given author.
  395. *
  396. * Returns a link to the feed for all posts by a given author. A specific feed
  397. * can be requested or left blank to get the default feed.
  398. *
  399. * @package WordPress
  400. * @subpackage Feed
  401. * @since 2.5.0
  402. *
  403. * @param int $author_id ID of an author.
  404. * @param string $feed Optional. Feed type.
  405. * @return string Link to the feed for the author specified by $author_id.
  406. */
  407. function get_author_feed_link( $author_id, $feed = '' ) {
  408. $author_id = (int) $author_id;
  409. $permalink_structure = get_option('permalink_structure');
  410. if ( empty($feed) )
  411. $feed = get_default_feed();
  412. if ( '' == $permalink_structure ) {
  413. $link = get_option('home') . "?feed=$feed&amp;author=" . $author_id;
  414. } else {
  415. $link = get_author_posts_url($author_id);
  416. if ( $feed == get_default_feed() )
  417. $feed_link = 'feed';
  418. else
  419. $feed_link = "feed/$feed";
  420. $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
  421. }
  422. $link = apply_filters('author_feed_link', $link, $feed);
  423. return $link;
  424. }
  425. /**
  426. * Retrieve the feed link for a category.
  427. *
  428. * Returns a link to the feed for all post in a given category. A specific feed
  429. * can be requested or left blank to get the default feed.
  430. *
  431. * @package WordPress
  432. * @subpackage Feed
  433. * @since 2.5.0
  434. *
  435. * @param int $cat_id ID of a category.
  436. * @param string $feed Optional. Feed type.
  437. * @return string Link to the feed for the category specified by $cat_id.
  438. */
  439. function get_category_feed_link($cat_id, $feed = '') {
  440. $cat_id = (int) $cat_id;
  441. $category = get_category($cat_id);
  442. if ( empty($category) || is_wp_error($category) )
  443. return false;
  444. if ( empty($feed) )
  445. $feed = get_default_feed();
  446. $permalink_structure = get_option('permalink_structure');
  447. if ( '' == $permalink_structure ) {
  448. $link = get_option('home') . "?feed=$feed&amp;cat=" . $cat_id;
  449. } else {
  450. $link = get_category_link($cat_id);
  451. if( $feed == get_default_feed() )
  452. $feed_link = 'feed';
  453. else
  454. $feed_link = "feed/$feed";
  455. $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
  456. }
  457. $link = apply_filters('category_feed_link', $link, $feed);
  458. return $link;
  459. }
  460. /**
  461. * Retrieve permalink for feed of tag.
  462. *
  463. * @since 2.3.0
  464. *
  465. * @param int $tag_id Tag ID.
  466. * @param string $feed Optional. Feed type.
  467. * @return string
  468. */
  469. function get_tag_feed_link($tag_id, $feed = '') {
  470. $tag_id = (int) $tag_id;
  471. $tag = get_tag($tag_id);
  472. if ( empty($tag) || is_wp_error($tag) )
  473. return false;
  474. $permalink_structure = get_option('permalink_structure');
  475. if ( empty($feed) )
  476. $feed = get_default_feed();
  477. if ( '' == $permalink_structure ) {
  478. $link = get_option('home') . "?feed=$feed&amp;tag=" . $tag->slug;
  479. } else {
  480. $link = get_tag_link($tag->term_id);
  481. if ( $feed == get_default_feed() )
  482. $feed_link = 'feed';
  483. else
  484. $feed_link = "feed/$feed";
  485. $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
  486. }
  487. $link = apply_filters('tag_feed_link', $link, $feed);
  488. return $link;
  489. }
  490. /**
  491. * Retrieve edit tag link.
  492. *
  493. * @since 2.7.0
  494. *
  495. * @param int $tag_id Tag ID
  496. * @return string
  497. */
  498. function get_edit_tag_link( $tag_id = 0 ) {
  499. $tag = get_term($tag_id, 'post_tag');
  500. if ( !current_user_can('manage_categories') )
  501. return;
  502. $location = admin_url('edit-tags.php?action=edit&amp;tag_ID=') . $tag->term_id;
  503. return apply_filters( 'get_edit_tag_link', $location );
  504. }
  505. /**
  506. * Display or retrieve edit tag link with formatting.
  507. *
  508. * @since 2.7.0
  509. *
  510. * @param string $link Optional. Anchor text.
  511. * @param string $before Optional. Display before edit link.
  512. * @param string $after Optional. Display after edit link.
  513. * @param int|object $tag Tag object or ID
  514. * @return string|null HTML content, if $echo is set to false.
  515. */
  516. function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
  517. $tag = get_term($tag, 'post_tag');
  518. if ( !current_user_can('manage_categories') )
  519. return;
  520. if ( empty($link) )
  521. $link = __('Edit This');
  522. $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>';
  523. echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after;
  524. }
  525. /**
  526. * Retrieve the permalink for the feed of the search results.
  527. *
  528. * @since 2.5.0
  529. *
  530. * @param string $search_query Optional. Search query.
  531. * @param string $feed Optional. Feed type.
  532. * @return string
  533. */
  534. function get_search_feed_link($search_query = '', $feed = '') {
  535. if ( empty($search_query) )
  536. $search = attribute_escape(get_search_query());
  537. else
  538. $search = attribute_escape(stripslashes($search_query));
  539. if ( empty($feed) )
  540. $feed = get_default_feed();
  541. $link = get_option('home') . "?s=$search&amp;feed=$feed";
  542. $link = apply_filters('search_feed_link', $link);
  543. return $link;
  544. }
  545. /**
  546. * Retrieve the permalink for the comments feed of the search results.
  547. *
  548. * @since 2.5.0
  549. *
  550. * @param string $search_query Optional. Search query.
  551. * @param string $feed Optional. Feed type.
  552. * @return string
  553. */
  554. function get_search_comments_feed_link($search_query = '', $feed = '') {
  555. if ( empty($search_query) )
  556. $search = attribute_escape(get_search_query());
  557. else
  558. $search = attribute_escape(stripslashes($search_query));
  559. if ( empty($feed) )
  560. $feed = get_default_feed();
  561. $link = get_option('home') . "?s=$search&amp;feed=comments-$feed";
  562. $link = apply_filters('search_feed_link', $link);
  563. return $link;
  564. }
  565. /**
  566. * Retrieve edit posts link for post.
  567. *
  568. * Can be used within the WordPress loop or outside of it. Can be used with
  569. * pages, posts, attachments, and revisions.
  570. *
  571. * @since 2.3.0
  572. *
  573. * @param int $id Optional. Post ID.
  574. * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
  575. * @return string
  576. */
  577. function get_edit_post_link( $id = 0, $context = 'display' ) {
  578. if ( !$post = &get_post( $id ) )
  579. return;
  580. if ( 'display' == $context )
  581. $action = 'action=edit&amp;';
  582. else
  583. $action = 'action=edit&';
  584. switch ( $post->post_type ) :
  585. case 'page' :
  586. if ( !current_user_can( 'edit_page', $post->ID ) )
  587. return;
  588. $file = 'page';
  589. $var = 'post';
  590. break;
  591. case 'attachment' :
  592. if ( !current_user_can( 'edit_post', $post->ID ) )
  593. return;
  594. $file = 'media';
  595. $var = 'attachment_id';
  596. break;
  597. case 'revision' :
  598. if ( !current_user_can( 'edit_post', $post->ID ) )
  599. return;
  600. $file = 'revision';
  601. $var = 'revision';
  602. $action = '';
  603. break;
  604. default :
  605. if ( !current_user_can( 'edit_post', $post->ID ) )
  606. return;
  607. $file = 'post';
  608. $var = 'post';
  609. break;
  610. endswitch;
  611. return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context );
  612. }
  613. /**
  614. * Retrieve edit posts link for post.
  615. *
  616. * @since 1.0.0
  617. *
  618. * @param string $link Optional. Anchor text.
  619. * @param string $before Optional. Display before edit link.
  620. * @param string $after Optional. Display after edit link.
  621. */
  622. function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) {
  623. global $post;
  624. if ( $post->post_type == 'page' ) {
  625. if ( !current_user_can( 'edit_page', $post->ID ) )
  626. return;
  627. } else {
  628. if ( !current_user_can( 'edit_post', $post->ID ) )
  629. return;
  630. }
  631. $link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . attribute_escape( __( 'Edit post' ) ) . '">' . $link . '</a>';
  632. echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
  633. }
  634. /**
  635. * Retrieve edit comment link.
  636. *
  637. * @since 2.3.0
  638. *
  639. * @param int $comment_id Optional. Comment ID.
  640. * @return string
  641. */
  642. function get_edit_comment_link( $comment_id = 0 ) {
  643. $comment = &get_comment( $comment_id );
  644. $post = &get_post( $comment->comment_post_ID );
  645. if ( $post->post_type == 'page' ) {
  646. if ( !current_user_can( 'edit_page', $post->ID ) )
  647. return;
  648. } else {
  649. if ( !current_user_can( 'edit_post', $post->ID ) )
  650. return;
  651. }
  652. $location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
  653. return apply_filters( 'get_edit_comment_link', $location );
  654. }
  655. /**
  656. * Display or retrieve edit comment link with formatting.
  657. *
  658. * @since 1.0.0
  659. *
  660. * @param string $link Optional. Anchor text.
  661. * @param string $before Optional. Display before edit link.
  662. * @param string $after Optional. Display after edit link.
  663. * @return string|null HTML content, if $echo is set to false.
  664. */
  665. function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
  666. global $comment, $post;
  667. if ( $post->post_type == 'attachment' ) {
  668. } elseif ( $post->post_type == 'page' ) {
  669. if ( !current_user_can( 'edit_page', $post->ID ) )
  670. return;
  671. } else {
  672. if ( !current_user_can( 'edit_post', $post->ID ) )
  673. return;
  674. }
  675. $link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
  676. echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
  677. }
  678. /**
  679. * Display edit bookmark (literally a URL external to blog) link.
  680. *
  681. * @since 2.7.0
  682. *
  683. * @param int $link Optional. Bookmark ID.
  684. * @return string
  685. */
  686. function get_edit_bookmark_link( $link = 0 ) {
  687. $link = get_bookmark( $link );
  688. if ( !current_user_can('manage_links') )
  689. return;
  690. $location = admin_url('link.php?action=edit&amp;link_id=') . $link->link_id;
  691. return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
  692. }
  693. /**
  694. * Display edit bookmark (literally a URL external to blog) link anchor content.
  695. *
  696. * @since 2.7.0
  697. *
  698. * @param string $link Optional. Anchor text.
  699. * @param string $before Optional. Display before edit link.
  700. * @param string $after Optional. Display after edit link.
  701. * @param int $bookmark Optional. Bookmark ID.
  702. */
  703. function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
  704. $bookmark = get_bookmark($bookmark);
  705. if ( !current_user_can('manage_links') )
  706. return;
  707. if ( empty($link) )
  708. $link = __('Edit This');
  709. $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
  710. echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
  711. }
  712. // Navigation links
  713. /**
  714. * Retrieve previous post link that is adjacent to current post.
  715. *
  716. * @since 1.5.0
  717. *
  718. * @param bool $in_same_cat Optional. Whether link should be in same category.
  719. * @param string $excluded_categories Optional. Excluded categories IDs.
  720. * @return string
  721. */
  722. function get_previous_post($in_same_cat = false, $excluded_categories = '') {
  723. return get_adjacent_post($in_same_cat, $excluded_categories);
  724. }
  725. /**
  726. * Retrieve next post link that is adjacent to current post.
  727. *
  728. * @since 1.5.0
  729. *
  730. * @param bool $in_same_cat Optional. Whether link should be in same category.
  731. * @param string $excluded_categories Optional. Excluded categories IDs.
  732. * @return string
  733. */
  734. function get_next_post($in_same_cat = false, $excluded_categories = '') {
  735. return get_adjacent_post($in_same_cat, $excluded_categories, false);
  736. }
  737. /**
  738. * Retrieve adjacent post link.
  739. *
  740. * Can either be next or previous post link.
  741. *
  742. * @since 2.5.0
  743. *
  744. * @param bool $in_same_cat Optional. Whether link should be in same category.
  745. * @param string $excluded_categories Optional. Excluded categories IDs.
  746. * @param bool $previous Optional. Whether to retrieve previous post.
  747. * @return string
  748. */
  749. function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
  750. global $post, $wpdb;
  751. if( empty($post) || !is_single() || is_attachment() )
  752. return null;
  753. $current_post_date = $post->post_date;
  754. $join = '';
  755. $posts_in_ex_cats_sql = '';
  756. if ( $in_same_cat || !empty($excluded_categories) ) {
  757. $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
  758. if ( $in_same_cat ) {
  759. $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
  760. $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
  761. }
  762. $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
  763. if ( !empty($excluded_categories) ) {
  764. $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
  765. if ( !empty($cat_array) ) {
  766. $excluded_categories = array_diff($excluded_categories, $cat_array);
  767. $posts_in_ex_cats_sql = '';
  768. }
  769. if ( !empty($excluded_categories) ) {
  770. $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
  771. }
  772. }
  773. }
  774. $adjacent = $previous ? 'previous' : 'next';
  775. $op = $previous ? '<' : '>';
  776. $order = $previous ? 'DESC' : 'ASC';
  777. $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
  778. $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date), $in_same_cat, $excluded_categories );
  779. $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
  780. return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
  781. }
  782. /**
  783. * Display previous post link that is adjacent to the current post.
  784. *
  785. * @since 1.5.0
  786. *
  787. * @param string $format Optional. Link anchor format.
  788. * @param string $link Optional. Link permalink format.
  789. * @param bool $in_same_cat Optional. Whether link should be in same category.
  790. * @param string $excluded_categories Optional. Excluded categories IDs.
  791. */
  792. function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
  793. adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
  794. }
  795. /**
  796. * Display next post link that is adjacent to the current post.
  797. *
  798. * @since 1.5.0
  799. *
  800. * @param string $format Optional. Link anchor format.
  801. * @param string $link Optional. Link permalink format.
  802. * @param bool $in_same_cat Optional. Whether link should be in same category.
  803. * @param string $excluded_categories Optional. Excluded categories IDs.
  804. */
  805. function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
  806. adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
  807. }
  808. /**
  809. * Display adjacent post link.
  810. *
  811. * Can be either next post link or previous.
  812. *
  813. * @since 2.5.0
  814. *
  815. * @param string $format Link anchor format.
  816. * @param string $link Link permalink format.
  817. * @param bool $in_same_cat Optional. Whether link should be in same category.
  818. * @param string $excluded_categories Optional. Excluded categories IDs.
  819. * @param bool $previous Optional, default is true. Whether display link to previous post.
  820. */
  821. function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
  822. if ( $previous && is_attachment() )
  823. $post = & get_post($GLOBALS['post']->post_parent);
  824. else
  825. $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
  826. if ( !$post )
  827. return;
  828. $title = $post->post_title;
  829. if ( empty($post->post_title) )
  830. $title = $previous ? __('Previous Post') : __('Next Post');
  831. $title = apply_filters('the_title', $title, $post);
  832. $date = mysql2date(get_option('date_format'), $post->post_date);
  833. $string = '<a href="'.get_permalink($post).'">';
  834. $link = str_replace('%title', $title, $link);
  835. $link = str_replace('%date', $date, $link);
  836. $link = $string . $link . '</a>';
  837. $format = str_replace('%link', $link, $format);
  838. $adjacent = $previous ? 'previous' : 'next';
  839. echo apply_filters( "{$adjacent}_post_link", $format, $link );
  840. }
  841. /**
  842. * Retrieve get links for page numbers.
  843. *
  844. * @since 1.5.0
  845. *
  846. * @param int $pagenum Optional. Page ID.
  847. * @return string
  848. */
  849. function get_pagenum_link($pagenum = 1) {
  850. global $wp_rewrite;
  851. $pagenum = (int) $pagenum;
  852. $request = remove_query_arg( 'paged' );
  853. $home_root = parse_url(get_option('home'));
  854. $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
  855. $home_root = preg_quote( trailingslashit( $home_root ), '|' );
  856. $request = preg_replace('|^'. $home_root . '|', '', $request);
  857. $request = preg_replace('|^/+|', '', $request);
  858. if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
  859. $base = trailingslashit( get_bloginfo( 'home' ) );
  860. if ( $pagenum > 1 ) {
  861. $result = add_query_arg( 'paged', $pagenum, $base . $request );
  862. } else {
  863. $result = $base . $request;
  864. }
  865. } else {
  866. $qs_regex = '|\?.*?$|';
  867. preg_match( $qs_regex, $request, $qs_match );
  868. if ( !empty( $qs_match[0] ) ) {
  869. $query_string = $qs_match[0];
  870. $request = preg_replace( $qs_regex, '', $request );
  871. } else {
  872. $query_string = '';
  873. }
  874. $request = preg_replace( '|page/\d+/?$|', '', $request);
  875. $request = preg_replace( '|^index\.php|', '', $request);
  876. $request = ltrim($request, '/');
  877. $base = trailingslashit( get_bloginfo( 'url' ) );
  878. if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
  879. $base .= 'index.php/';
  880. if ( $pagenum > 1 ) {
  881. $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
  882. }
  883. $result = $base . $request . $query_string;
  884. }
  885. $result = apply_filters('get_pagenum_link', $result);
  886. return $result;
  887. }
  888. /**
  889. * Retrieve next posts pages link.
  890. *
  891. * Backported from 2.1.3 to 2.0.10.
  892. *
  893. * @since 2.0.10
  894. *
  895. * @param int $max_page Optional. Max pages.
  896. * @return string
  897. */
  898. function get_next_posts_page_link($max_page = 0) {
  899. global $paged;
  900. if ( !is_single() ) {
  901. if ( !$paged )
  902. $paged = 1;
  903. $nextpage = intval($paged) + 1;
  904. if ( !$max_page || $max_page >= $nextpage )
  905. return get_pagenum_link($nextpage);
  906. }
  907. }
  908. /**
  909. * Display or return the next posts pages link.
  910. *
  911. * @since 0.71
  912. *
  913. * @param int $max_page Optional. Max pages.
  914. * @param boolean $echo Optional. Echo or return;
  915. */
  916. function next_posts( $max_page = 0, $echo = true ) {
  917. $output = clean_url( get_next_posts_page_link( $max_page ) );
  918. if ( $echo )
  919. echo $output;
  920. else
  921. return $output;
  922. }
  923. /**
  924. * Return the next posts pages link.
  925. *
  926. * @since 2.7.0
  927. *
  928. * @param string $label Content for link text.
  929. * @param int $max_page Optional. Max pages.
  930. * @return string|null
  931. */
  932. function get_next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
  933. global $paged, $wp_query;
  934. if ( !$max_page ) {
  935. $max_page = $wp_query->max_num_pages;
  936. }
  937. if ( !$paged )
  938. $paged = 1;
  939. $nextpage = intval($paged) + 1;
  940. if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
  941. $attr = apply_filters( 'next_posts_link_attributes', '' );
  942. return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
  943. }
  944. }
  945. /**
  946. * Display the next posts pages link.
  947. *
  948. * @since 0.71
  949. * @uses get_next_posts_link()
  950. *
  951. * @param string $label Content for link text.
  952. * @param int $max_page Optional. Max pages.
  953. */
  954. function next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
  955. echo get_next_posts_link( $label, $max_page );
  956. }
  957. /**
  958. * Retrieve previous post pages link.
  959. *
  960. * Will only return string, if not on a single page or post.
  961. *
  962. * Backported to 2.0.10 from 2.1.3.
  963. *
  964. * @since 2.0.10
  965. *
  966. * @return string|null
  967. */
  968. function get_previous_posts_page_link() {
  969. global $paged;
  970. if ( !is_single() ) {
  971. $nextpage = intval($paged) - 1;
  972. if ( $nextpage < 1 )
  973. $nextpage = 1;
  974. return get_pagenum_link($nextpage);
  975. }
  976. }
  977. /**
  978. * Display or return the previous posts pages link.
  979. *
  980. * @since 0.71
  981. *
  982. * @param boolean $echo Optional. Echo or return;
  983. */
  984. function previous_posts( $echo = true ) {
  985. $output = clean_url( get_previous_posts_page_link() );
  986. if ( $echo )
  987. echo $output;
  988. else
  989. return $output;
  990. }
  991. /**
  992. * Return the previous posts pages link.
  993. *
  994. * @since 2.7.0
  995. *
  996. * @param string $label Optional. Previous page link text.
  997. * @return string|null
  998. */
  999. function get_previous_posts_link( $label = '&laquo; Previous Page' ) {
  1000. global $paged;
  1001. if ( !is_single() && $paged > 1 ) {
  1002. $attr = apply_filters( 'previous_posts_link_attributes', '' );
  1003. return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label ) .'</a>';
  1004. }
  1005. }
  1006. /**
  1007. * Display the previous posts page link.
  1008. *
  1009. * @since 0.71
  1010. * @uses get_previous_posts_link()
  1011. *
  1012. * @param string $label Optional. Previous page link text.
  1013. */
  1014. function previous_posts_link( $label = '&laquo; Previous Page' ) {
  1015. echo get_previous_posts_link( $label );
  1016. }
  1017. /**
  1018. * Display post pages link navigation for previous and next pages.
  1019. *
  1020. * @since 0.71
  1021. *
  1022. * @param string $sep Optional. Separator for posts navigation links.
  1023. * @param string $prelabel Optional. Label for previous pages.
  1024. * @param string $nxtlabel Optional Label for next pages.
  1025. */
  1026. function posts_nav_link( $sep = ' &#8212; ', $prelabel = '&laquo; Previous Page', $nxtlabel = 'Next Page &raquo;' ) {
  1027. global $wp_query;
  1028. if ( !is_singular() ) {
  1029. $max_num_pages = $wp_query->max_num_pages;
  1030. $paged = get_query_var('paged');
  1031. //only have sep if there's both prev and next results
  1032. if ($paged < 2 || $paged >= $max_num_pages) {
  1033. $sep = '';
  1034. }
  1035. if ( $max_num_pages > 1 ) {
  1036. previous_posts_link($prelabel);
  1037. echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
  1038. next_posts_link($nxtlabel);
  1039. }
  1040. }
  1041. }
  1042. /**
  1043. * Retrieve page numbers links.
  1044. *
  1045. * @since 2.7.0
  1046. *
  1047. * @param int $pagenum Optional. Page number.
  1048. * @return string
  1049. */
  1050. function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
  1051. global $post, $wp_rewrite;
  1052. $pagenum = (int) $pagenum;
  1053. $result = get_permalink( $post->ID );
  1054. if ( 'newest' == get_option('default_comments_page') ) {
  1055. if ( $pagenum != $max_page ) {
  1056. if ( $wp_rewrite->using_permalinks() )
  1057. $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
  1058. else
  1059. $result = add_query_arg( 'cpage', $pagenum, $result );
  1060. }
  1061. } elseif ( $pagenum > 1 ) {
  1062. if ( $wp_rewrite->using_permalinks() )
  1063. $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
  1064. else
  1065. $result = add_query_arg( 'cpage', $pagenum, $result );
  1066. }
  1067. $result .= '#comments';
  1068. $result = apply_filters('get_comments_pagenum_link', $result);
  1069. return $result;
  1070. }
  1071. /**
  1072. * Display link to next comments pages.
  1073. *
  1074. * @since 2.7.0
  1075. *
  1076. * @param string $label Optional. Label for link text.
  1077. * @param int $max_page Optional. Max page.
  1078. */
  1079. function next_comments_link($label='', $max_page = 0) {
  1080. global $wp_query;
  1081. if ( !is_singular() )
  1082. return;
  1083. $page = get_query_var('cpage');
  1084. if ( !$page )
  1085. $page = 1;
  1086. $nextpage = intval($page) + 1;
  1087. if ( empty($max_page) )
  1088. $max_page = $wp_query->max_num_comment_pages;
  1089. if ( empty($max_page) )
  1090. $max_page = get_comment_pages_count();
  1091. if ( $nextpage > $max_page )
  1092. return;
  1093. if ( empty($label) )
  1094. $label = __('Newer Comments &raquo;');
  1095. echo '<a href="' . clean_url( get_comments_pagenum_link( $nextpage, $max_page ) );
  1096. $attr = apply_filters( 'next_comments_link_attributes', '' );
  1097. echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
  1098. }
  1099. /**
  1100. * Display the previous comments page link.
  1101. *
  1102. * @since 2.7.0
  1103. *
  1104. * @param string $label Optional. Label for comments link text.
  1105. */
  1106. function previous_comments_link($label='') {
  1107. if ( !is_singular() )
  1108. return;
  1109. $page = get_query_var('cpage');
  1110. if ( !$page )
  1111. $page = 1;
  1112. if ( $page <= 1 )
  1113. return;
  1114. $prevpage = intval($page) - 1;
  1115. if ( empty($label) )
  1116. $label = __('&laquo; Older Comments');
  1117. echo '<a href="' . clean_url(get_comments_pagenum_link($prevpage));
  1118. $attr = apply_filters( 'previous_comments_link_attributes', '' );
  1119. echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
  1120. }
  1121. /**
  1122. * Create pagination links for the comments on the current post.
  1123. *
  1124. * @see paginate_links()
  1125. * @since 2.7.0
  1126. *
  1127. * @param string|array $args Optional args. See paginate_links.
  1128. * @return string Markup for pagination links.
  1129. */
  1130. function paginate_comments_links($args = array()) {
  1131. global $wp_query, $wp_rewrite;
  1132. if ( !is_singular() )
  1133. return;
  1134. $page = get_query_var('cpage');
  1135. if ( !$page )
  1136. $page = 1;
  1137. $max_page = get_comment_pages_count();
  1138. $defaults = array(
  1139. 'base' => add_query_arg( 'cpage', '%#%' ),
  1140. 'format' => '',
  1141. 'total' => $max_page,
  1142. 'current' => $page,
  1143. 'echo' => true,
  1144. 'add_fragment' => '#comments'
  1145. );
  1146. if ( $wp_rewrite->using_permalinks() )
  1147. $defaults['base'] = user_trailingslashit(get_permalink() . 'comment-page-%#%', 'commentpaged');
  1148. $args = wp_parse_args( $args, $defaults );
  1149. $page_links = paginate_links( $args );
  1150. if ( $args['echo'] )
  1151. echo $page_links;
  1152. else
  1153. return $page_links;
  1154. }
  1155. /**
  1156. * Retrieve shortcut link.
  1157. *
  1158. * Use this in 'a' element 'href' attribute.
  1159. *
  1160. * @since 2.6.0
  1161. *
  1162. * @return string
  1163. */
  1164. function get_shortcut_link() {
  1165. $link = "javascript:
  1166. var d=document,
  1167. w=window,
  1168. e=w.getSelection,
  1169. k=d.getSelection,
  1170. x=d.selection,
  1171. s=(e?e():(k)?k():(x?x.createRange().text:0)),
  1172. f='" . admin_url('press-this.php') . "',
  1173. l=d.location,
  1174. e=encodeURIComponent,
  1175. g=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=2';
  1176. function a(){
  1177. if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=720,height=570')){
  1178. l.href=g;
  1179. }
  1180. }";
  1181. if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)
  1182. $link .= 'setTimeout(a,0);';
  1183. else
  1184. $link .= 'a();';
  1185. $link .= "void(0);";
  1186. $link = str_replace(array("\r", "\n", "\t"), '', $link);
  1187. return apply_filters('shortcut_link', $link);
  1188. }
  1189. /**
  1190. * Retrieve the site url.
  1191. *
  1192. * Returns the 'site_url' option with the appropriate protocol, 'https' if
  1193. * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
  1194. * overridden.
  1195. *
  1196. * @package WordPress
  1197. * @since 2.6.0
  1198. *
  1199. * @param string $path Optional. Path relative to the site url.
  1200. * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
  1201. * @return string Site url link with optional path appended.
  1202. */
  1203. function site_url($path = '', $scheme = null) {
  1204. // should the list of allowed schemes be maintained elsewhere?
  1205. $orig_scheme = $scheme;
  1206. if ( !in_array($scheme, array('http', 'https')) ) {
  1207. if ( ('login_post' == $scheme) && ( force_ssl_login() || force_ssl_admin() ) )
  1208. $scheme = 'https';
  1209. elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
  1210. $scheme = 'https';
  1211. elseif ( ('admin' == $scheme) && force_ssl_admin() )
  1212. $scheme = 'https';
  1213. else
  1214. $scheme = ( is_ssl() ? 'https' : 'http' );
  1215. }
  1216. $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
  1217. if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  1218. $url .= '/' . ltrim($path, '/');
  1219. return apply_filters('site_url', $url, $path, $orig_scheme);
  1220. }
  1221. /**
  1222. * Retrieve the url to the admin area.
  1223. *
  1224. * @package WordPress
  1225. * @since 2.6.0
  1226. *
  1227. * @param string $path Optional path relative to the admin url
  1228. * @return string Admin url link with optional path appended
  1229. */
  1230. function admin_url($path = '') {
  1231. $url = site_url('wp-admin/', 'admin');
  1232. if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  1233. $url .= ltrim($path, '/');
  1234. return $url;
  1235. }
  1236. /**
  1237. * Retrieve the url to the includes directory.
  1238. *
  1239. * @package WordPress
  1240. * @since 2.6.0
  1241. *
  1242. * @param string $path Optional. Path relative to the includes url.
  1243. * @return string Includes url link with optional path appended.
  1244. */
  1245. function includes_url($path = '') {
  1246. $url = site_url() . '/' . WPINC . '/';
  1247. if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  1248. $url .= ltrim($path, '/');
  1249. return $url;
  1250. }
  1251. /**
  1252. * Retrieve the url to the content directory.
  1253. *
  1254. * @package WordPress
  1255. * @since 2.6.0
  1256. *
  1257. * @param string $path Optional. Path relative to the content url.
  1258. * @return string Content url link with optional path appended.
  1259. */
  1260. function content_url($path = '') {
  1261. $scheme = ( is_ssl() ? 'https' : 'http' );
  1262. $url = WP_CONTENT_URL;
  1263. if ( 0 === strpos($url, 'http') ) {
  1264. if ( is_ssl() )
  1265. $url = str_replace( 'http://', "{$scheme}://", $url );
  1266. }
  1267. if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  1268. $url .= '/' . ltrim($path, '/');
  1269. return $url;
  1270. }
  1271. /**
  1272. * Retrieve the url to the plugins directory.
  1273. *
  1274. * @package WordPress
  1275. * @since 2.6.0
  1276. *
  1277. * @param string $path Optional. Path relative to the plugins url.
  1278. * @return string Plugins url link with optional path appended.
  1279. */
  1280. function plugins_url($path = '') {
  1281. $scheme = ( is_ssl() ? 'https' : 'http' );
  1282. $url = WP_PLUGIN_URL;
  1283. if ( 0 === strpos($url, 'http') ) {
  1284. if ( is_ssl() )
  1285. $url = str_replace( 'http://', "{$scheme}://", $url );
  1286. }
  1287. if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  1288. $url .= '/' . ltrim($path, '/');
  1289. return $url;
  1290. }
  1291. ?>