PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/functions.php

https://github.com/monfresh/cfawp2012
PHP | 625 lines | 330 code | 73 blank | 222 comment | 25 complexity | e6e0ae46fa1867c673b4330cb55aeebe MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. * TwentyTen functions and definitions
  4. *
  5. * Sets up the theme and provides some helper functions. Some helper functions
  6. * are used in the theme as custom template tags. Others are attached to action and
  7. * filter hooks in WordPress to change core functionality.
  8. *
  9. * The first function, twentyten_setup(), sets up the theme by registering support
  10. * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11. *
  12. * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  13. * http://codex.wordpress.org/Child_Themes), you can override certain functions
  14. * (those wrapped in a function_exists() call) by defining them first in your child theme's
  15. * functions.php file. The child theme's functions.php file is included before the parent
  16. * theme's file, so the child theme functions would be used.
  17. *
  18. * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  19. * to a filter or action hook. The hook can be removed by using remove_action() or
  20. * remove_filter() and you can attach your own function to the hook.
  21. *
  22. * We can remove the parent theme's hook only after it is attached, which means we need to
  23. * wait until setting up the child theme:
  24. *
  25. * <code>
  26. * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  27. * function my_child_theme_setup() {
  28. * // We are providing our own filter for excerpt_length (or using the unfiltered value)
  29. * remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  30. * ...
  31. * }
  32. * </code>
  33. *
  34. * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
  35. *
  36. * @package WordPress
  37. * @subpackage Twenty_Ten
  38. * @since Twenty Ten 1.0
  39. */
  40. /**
  41. * Set the content width based on the theme's design and stylesheet.
  42. *
  43. * Used to set the width of images and content. Should be equal to the width the theme
  44. * is designed for, generally via the style.css stylesheet.
  45. */
  46. if ( ! isset( $content_width ) )
  47. $content_width = 640;
  48. /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
  49. add_action( 'after_setup_theme', 'twentyten_setup' );
  50. if ( ! function_exists( 'twentyten_setup' ) ):
  51. /**
  52. * Sets up theme defaults and registers support for various WordPress features.
  53. *
  54. * Note that this function is hooked into the after_setup_theme hook, which runs
  55. * before the init hook. The init hook is too late for some features, such as indicating
  56. * support post thumbnails.
  57. *
  58. * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
  59. * functions.php file.
  60. *
  61. * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  62. * @uses register_nav_menus() To add support for navigation menus.
  63. * @uses add_custom_background() To add support for a custom background.
  64. * @uses add_editor_style() To style the visual editor.
  65. * @uses load_theme_textdomain() For translation/localization support.
  66. * @uses add_custom_image_header() To add support for a custom header.
  67. * @uses register_default_headers() To register the default custom header images provided with the theme.
  68. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  69. *
  70. * @since Twenty Ten 1.0
  71. */
  72. function twentyten_setup() {
  73. // This theme styles the visual editor with editor-style.css to match the theme style.
  74. add_editor_style();
  75. // This theme uses post thumbnails
  76. add_theme_support( 'post-thumbnails' );
  77. // Add default posts and comments RSS feed links to head
  78. add_theme_support( 'automatic-feed-links' );
  79. // Make theme available for translation
  80. // Translations can be filed in the /languages/ directory
  81. load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
  82. $locale = get_locale();
  83. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  84. if ( is_readable( $locale_file ) )
  85. require_once( $locale_file );
  86. // This theme uses wp_nav_menu() in one location.
  87. register_nav_menus( array(
  88. 'primary' => __( 'Primary Navigation', 'twentyten' ),
  89. ) );
  90. // This theme allows users to set a custom background
  91. add_custom_background();
  92. // Your changeable header business starts here
  93. define( 'HEADER_TEXTCOLOR', '' );
  94. // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
  95. define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
  96. // The height and width of your custom header. You can hook into the theme's own filters to change these values.
  97. // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
  98. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
  99. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
  100. // We'll be using post thumbnails for custom header images on posts and pages.
  101. // We want them to be 940 pixels wide by 198 pixels tall.
  102. // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  103. set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
  104. // Don't support text inside the header image.
  105. define( 'NO_HEADER_TEXT', true );
  106. // Add a way for the custom header to be styled in the admin panel that controls
  107. // custom headers. See twentyten_admin_header_style(), below.
  108. add_custom_image_header( '', 'twentyten_admin_header_style' );
  109. // ... and thus ends the changeable header business.
  110. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  111. register_default_headers( array(
  112. 'berries' => array(
  113. 'url' => '%s/images/headers/berries.jpg',
  114. 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
  115. /* translators: header image description */
  116. 'description' => __( 'Berries', 'twentyten' )
  117. ),
  118. 'cherryblossom' => array(
  119. 'url' => '%s/images/headers/cherryblossoms.jpg',
  120. 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
  121. /* translators: header image description */
  122. 'description' => __( 'Cherry Blossoms', 'twentyten' )
  123. ),
  124. 'concave' => array(
  125. 'url' => '%s/images/headers/concave.jpg',
  126. 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
  127. /* translators: header image description */
  128. 'description' => __( 'Concave', 'twentyten' )
  129. ),
  130. 'fern' => array(
  131. 'url' => '%s/images/headers/fern.jpg',
  132. 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
  133. /* translators: header image description */
  134. 'description' => __( 'Fern', 'twentyten' )
  135. ),
  136. 'forestfloor' => array(
  137. 'url' => '%s/images/headers/forestfloor.jpg',
  138. 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
  139. /* translators: header image description */
  140. 'description' => __( 'Forest Floor', 'twentyten' )
  141. ),
  142. 'inkwell' => array(
  143. 'url' => '%s/images/headers/inkwell.jpg',
  144. 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
  145. /* translators: header image description */
  146. 'description' => __( 'Inkwell', 'twentyten' )
  147. ),
  148. 'path' => array(
  149. 'url' => '%s/images/headers/path.jpg',
  150. 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
  151. /* translators: header image description */
  152. 'description' => __( 'Path', 'twentyten' )
  153. ),
  154. 'sunset' => array(
  155. 'url' => '%s/images/headers/sunset.jpg',
  156. 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
  157. /* translators: header image description */
  158. 'description' => __( 'Sunset', 'twentyten' )
  159. )
  160. ) );
  161. }
  162. endif;
  163. add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
  164. add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
  165. function my_show_extra_profile_fields( $user ) { ?>
  166. <h3>Extra profile information</h3>
  167. <table class="form-table">
  168. <tr>
  169. <th><label for="oneline">One Line Bio</label></th>
  170. <td>
  171. <input type="text" name="oneline" id="online" value="<?php echo esc_attr( get_the_author_meta( 'oneline', $user->ID ) ); ?>" class="regular-text" /><br />
  172. <span class="description">Please enter your One Line Bio.</span>
  173. </td>
  174. </tr>
  175. <tr>
  176. <th><label for="twitter">Twitter Handle</label></th>
  177. <td>
  178. <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
  179. <span class="description">Please enter your twitter handle <strong>with @</strong></span>
  180. </td>
  181. </tr>
  182. </table>
  183. <?php }
  184. add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
  185. add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
  186. function my_save_extra_profile_fields( $user_id ) {
  187. if ( !current_user_can( 'edit_user', $user_id ) )
  188. return false;
  189. /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
  190. update_usermeta( $user_id, 'oneline', $_POST['oneline'] );
  191. update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
  192. }
  193. if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
  194. /**
  195. * Styles the header image displayed on the Appearance > Header admin panel.
  196. *
  197. * Referenced via add_custom_image_header() in twentyten_setup().
  198. *
  199. * @since Twenty Ten 1.0
  200. */
  201. function twentyten_admin_header_style() {
  202. ?>
  203. <style type="text/css">
  204. /* Shows the same border as on front end */
  205. #headimg {
  206. border-bottom: 1px solid #000;
  207. border-top: 4px solid #000;
  208. }
  209. /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
  210. #headimg #name { }
  211. #headimg #desc { }
  212. */
  213. </style>
  214. <?php
  215. }
  216. endif;
  217. /**
  218. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  219. *
  220. * To override this in a child theme, remove the filter and optionally add
  221. * your own function tied to the wp_page_menu_args filter hook.
  222. *
  223. * @since Twenty Ten 1.0
  224. */
  225. function twentyten_page_menu_args( $args ) {
  226. $args['show_home'] = true;
  227. return $args;
  228. }
  229. add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
  230. /**
  231. * Sets the post excerpt length to 40 characters.
  232. *
  233. * To override this length in a child theme, remove the filter and add your own
  234. * function tied to the excerpt_length filter hook.
  235. *
  236. * @since Twenty Ten 1.0
  237. * @return int
  238. */
  239. function twentyten_excerpt_length( $length ) {
  240. return 40;
  241. }
  242. add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  243. /**
  244. * Returns a "Continue Reading" link for excerpts
  245. *
  246. * @since Twenty Ten 1.0
  247. * @return string "Continue Reading" link
  248. */
  249. function twentyten_continue_reading_link() {
  250. return ' ';
  251. }
  252. /**
  253. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
  254. *
  255. * To override this in a child theme, remove the filter and add your own
  256. * function tied to the excerpt_more filter hook.
  257. *
  258. * @since Twenty Ten 1.0
  259. * @return string An ellipsis
  260. */
  261. function twentyten_auto_excerpt_more( $more ) {
  262. return ' &hellip;';
  263. }
  264. add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
  265. /**
  266. * Adds a pretty "Continue Reading" link to custom post excerpts.
  267. *
  268. * To override this link in a child theme, remove the filter and add your own
  269. * function tied to the get_the_excerpt filter hook.
  270. *
  271. * @since Twenty Ten 1.0
  272. * @return string Excerpt with a pretty "Continue Reading" link
  273. */
  274. function twentyten_custom_excerpt_more( $output ) {
  275. if ( has_excerpt() && ! is_attachment() ) {
  276. $output .= twentyten_continue_reading_link();
  277. }
  278. return $output;
  279. }
  280. add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
  281. /**
  282. * Remove inline styles printed when the gallery shortcode is used.
  283. *
  284. * Galleries are styled by the theme in Twenty Ten's style.css.
  285. *
  286. * @since Twenty Ten 1.0
  287. * @return string The gallery style filter, with the styles themselves removed.
  288. */
  289. function twentyten_remove_gallery_css( $css ) {
  290. return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  291. }
  292. add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
  293. if ( ! function_exists( 'twentyten_comment' ) ) :
  294. /**
  295. * Template for comments and pingbacks.
  296. *
  297. * To override this walker in a child theme without modifying the comments template
  298. * simply create your own twentyten_comment(), and that function will be used instead.
  299. *
  300. * Used as a callback by wp_list_comments() for displaying the comments.
  301. *
  302. * @since Twenty Ten 1.0
  303. */
  304. function twentyten_comment( $comment, $args, $depth ) {
  305. $GLOBALS['comment'] = $comment;
  306. switch ( $comment->comment_type ) :
  307. case '' :
  308. ?>
  309. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  310. <div id="comment-<?php comment_ID(); ?>">
  311. <div class="comment-author vcard">
  312. <?php echo get_avatar( $comment, 40 ); ?>
  313. <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  314. </div><!-- .comment-author .vcard -->
  315. <?php if ( $comment->comment_approved == '0' ) : ?>
  316. <em><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
  317. <br />
  318. <?php endif; ?>
  319. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  320. <?php
  321. /* translators: 1: date, 2: time */
  322. printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
  323. ?>
  324. </div><!-- .comment-meta .commentmetadata -->
  325. <div class="comment-body"><?php comment_text(); ?></div>
  326. <div class="reply">
  327. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  328. </div><!-- .reply -->
  329. </div><!-- #comment-## -->
  330. <?php
  331. break;
  332. case 'pingback' :
  333. case 'trackback' :
  334. ?>
  335. <li class="post pingback">
  336. <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'twentyten'), ' ' ); ?></p>
  337. <?php
  338. break;
  339. endswitch;
  340. }
  341. endif;
  342. /**
  343. * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  344. *
  345. * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
  346. * function tied to the init hook.
  347. *
  348. * @since Twenty Ten 1.0
  349. * @uses register_sidebar
  350. */
  351. function twentyten_widgets_init() {
  352. // Area 1, located at the top of the sidebar.
  353. register_sidebar( array(
  354. 'name' => __( 'Primary Widget Area', 'twentyten' ),
  355. 'id' => 'primary-widget-area',
  356. 'description' => __( 'The primary widget area', 'twentyten' ),
  357. 'before_widget' => '<div id="wp-widget">',
  358. 'after_widget' => '</div>',
  359. 'before_title' => '<h3 class="widget-title">',
  360. 'after_title' => '</h3>',
  361. ) );
  362. // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
  363. register_sidebar( array(
  364. 'name' => __( 'Secondary Widget Area', 'twentyten' ),
  365. 'id' => 'secondary-widget-area',
  366. 'description' => __( 'The secondary widget area', 'twentyten' ),
  367. 'before_widget' => '<div style="margin-bottom: 15px;">',
  368. 'after_widget' => '</div>',
  369. 'before_title' => '<h3 class="widget-title">',
  370. 'after_title' => '</h3>',
  371. ) );
  372. // Area 3, located in the footer. Empty by default.
  373. register_sidebar( array(
  374. 'name' => __( 'First Footer Widget Area', 'twentyten' ),
  375. 'id' => 'first-footer-widget-area',
  376. 'description' => __( 'The first footer widget area', 'twentyten' ),
  377. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  378. 'after_widget' => '</li>',
  379. 'before_title' => '<h3 class="widget-title">',
  380. 'after_title' => '</h3>',
  381. ) );
  382. // Area 4, located in the footer. Empty by default.
  383. register_sidebar( array(
  384. 'name' => __( 'Second Footer Widget Area', 'twentyten' ),
  385. 'id' => 'second-footer-widget-area',
  386. 'description' => __( 'The second footer widget area', 'twentyten' ),
  387. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  388. 'after_widget' => '</li>',
  389. 'before_title' => '<h3 class="widget-title">',
  390. 'after_title' => '</h3>',
  391. ) );
  392. // Area 5, located in the footer. Empty by default.
  393. register_sidebar( array(
  394. 'name' => __( 'Third Footer Widget Area', 'twentyten' ),
  395. 'id' => 'third-footer-widget-area',
  396. 'description' => __( 'The third footer widget area', 'twentyten' ),
  397. 'before_widget' => '',
  398. 'after_widget' => '',
  399. 'before_title' => '<h3 class="widget-title">',
  400. 'after_title' => '</h3>',
  401. ) );
  402. // Area 6, located in the footer. Empty by default.
  403. register_sidebar( array(
  404. 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
  405. 'id' => 'fourth-footer-widget-area',
  406. 'description' => __( 'The fourth footer widget area', 'twentyten' ),
  407. 'before_widget' => '',
  408. 'after_widget' => '',
  409. 'before_title' => '',
  410. 'after_title' => '',
  411. ) );
  412. }
  413. /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
  414. add_action( 'widgets_init', 'twentyten_widgets_init' );
  415. /**
  416. * Removes the default styles that are packaged with the Recent Comments widget.
  417. *
  418. * To override this in a child theme, remove the filter and optionally add your own
  419. * function tied to the widgets_init action hook.
  420. *
  421. * @since Twenty Ten 1.0
  422. */
  423. function twentyten_remove_recent_comments_style() {
  424. global $wp_widget_factory;
  425. remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  426. }
  427. add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
  428. if ( ! function_exists( 'twentyten_posted_on' ) ) :
  429. /**
  430. * Prints HTML with meta information for the current post—date/time and author.
  431. *
  432. * @since Twenty Ten 1.0
  433. */
  434. function twentyten_posted_on() {
  435. printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
  436. 'meta-prep meta-prep-author',
  437. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  438. get_permalink(),
  439. esc_attr( get_the_time() ),
  440. get_the_date()
  441. ),
  442. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  443. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  444. sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
  445. get_the_author()
  446. )
  447. );
  448. }
  449. endif;
  450. function excerpt($limit) {
  451. $excerpt = explode(' ', get_the_excerpt(), $limit);
  452. if (count($excerpt)>=$limit) {
  453. array_pop($excerpt);
  454. $excerpt = implode(" ",$excerpt).'...';
  455. } else {
  456. $excerpt = implode(" ",$excerpt);
  457. }
  458. $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
  459. return $excerpt;
  460. }
  461. if ( ! function_exists( 'twentyten_posted_in' ) ) :
  462. /**
  463. * Prints HTML with meta information for the current post (category, tags and permalink).
  464. *
  465. * @since Twenty Ten 1.0
  466. */
  467. function twentyten_posted_in() {
  468. // Retrieves tag list of current post, separated by commas.
  469. $tag_list = get_the_tag_list( '', ', ' );
  470. if ( $tag_list ) {
  471. $posted_in = __( 'in <a href="%3$s" title="Permalink to %4$s" rel="bookmark">%1$s</a>', 'twentyten' );
  472. } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  473. $posted_in = __( 'in <a href="%3$s" title="Permalink to %4$s" rel="bookmark">%1$s</a>', 'twentyten' );
  474. } else {
  475. $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  476. }
  477. // Prints the string, replacing the placeholders.
  478. printf(
  479. $posted_in,
  480. get_the_category_list( ', ' ),
  481. $tag_list,
  482. get_permalink(),
  483. the_title_attribute( 'echo=0' )
  484. );
  485. }
  486. endif;
  487. /* Define the custom box */
  488. // WP 3.0+
  489. // add_action('add_meta_boxes', 'myplugin_add_custom_box');
  490. // backwards compatible
  491. add_action('admin_init', 'myplugin_add_custom_box', 1);
  492. /* Do something with the data entered */
  493. add_action('save_post', 'myplugin_save_postdata');
  494. /* Adds a box to the main column on the Post and Page edit screens */
  495. function myplugin_add_custom_box() {
  496. add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ),
  497. 'myplugin_inner_custom_box', 'post' );
  498. add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ),
  499. 'myplugin_inner_custom_box', 'page' );
  500. add_meta_box( 'myplugin_sectionid', __( 'Take Action Link', 'myplugin_textdomain' ),
  501. 'myplugin_inner_custom_box', 'cfa_project' );
  502. }
  503. /* Prints the box content */
  504. function myplugin_inner_custom_box() {
  505. // Use nonce for verification
  506. wp_nonce_field( plugin_basename(__FILE__), 'myplugin_noncename' );
  507. // The actual fields for data entry
  508. echo '<label for="myplugin_new_field">' . __("Paste link to key way to get involved", 'myplugin_textdomain' ) . '</label> ';
  509. echo '<input type="text" id= "myplugin_new_field" name="myplugin_new_field" value="" size="80" />';
  510. }
  511. /* When the post is saved, saves our custom data */
  512. function myplugin_save_postdata( $post_id ) {
  513. // verify this came from the our screen and with proper authorization,
  514. // because save_post can be triggered at other times
  515. if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) )) {
  516. return $post_id;
  517. }
  518. // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want
  519. // to do anything
  520. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  521. return $post_id;
  522. // Check permissions
  523. if ( 'page' == $_POST['post_type'] ) {
  524. if ( !current_user_can( 'edit_page', $post_id ) )
  525. return $post_id;
  526. } else {
  527. if ( !current_user_can( 'edit_post', $post_id ) )
  528. return $post_id;
  529. }
  530. // OK, we're authenticated: we need to find and save the data
  531. $mydata = $_POST['myplugin_new_field'];
  532. // Do something with $mydata
  533. // probably using add_post_meta(), update_post_meta(), or
  534. // a custom table (see Further Reading section below)
  535. return $mydata;
  536. }
  537. add_action( 'init', 'create_post_type' );
  538. function create_post_type() {
  539. register_post_type( 'cfa_project',
  540. array(
  541. 'labels' => array(
  542. 'name' => __( 'Projects' ),
  543. 'singular_name' => __( 'Projects' )
  544. ),
  545. 'public' => true,
  546. 'rewrite' => false,
  547. 'capability_type' => 'post',
  548. 'supports' => array('title','editor','author', 'excerpt', 'custom-fields', 'thumbnail',)
  549. )
  550. );
  551. }
  552. ?>