Permalink
Browse files

Use the new register_meta() functionality in conjunction with its san…

…itizing method with the framework meta.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@940 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
greenshady
greenshady committed Dec 9, 2011
1 parent 807141f commit ab93562e6d63548d2ea9dcc6001e62b460a8a4c2
Showing with 19 additions and 16 deletions.
  1. +9 −9 admin/meta-box-post-seo.php
  2. +7 −7 admin/meta-box-post-template.php
  3. +3 −0 hybrid.php
@@ -78,14 +78,10 @@ function hybrid_meta_box_post_save_seo( $post_id, $post ) {
if ( !isset( $_POST['hybrid-core-post-seo'] ) || !wp_verify_nonce( $_POST['hybrid-core-post-seo'], basename( __FILE__ ) ) )
return $post_id;
- /* Check if the current user has permission to edit the post meta. */
- if ( !current_user_can( 'edit_post_meta', $post_id ) )
- return $post_id;
-
$meta = array(
- 'Title' => strip_tags( $_POST['hybrid-document-title'] ),
- 'Description' => strip_tags( $_POST['hybrid-meta-description'] ),
- 'Keywords' => strip_tags( $_POST['hybrid-meta-keywords'] )
+ 'Title' => $_POST['hybrid-document-title'],
+ 'Description' => $_POST['hybrid-meta-description'],
+ 'Keywords' => $_POST['hybrid-meta-keywords']
);
foreach ( $meta as $meta_key => $new_meta_value ) {
@@ -94,11 +90,15 @@ function hybrid_meta_box_post_save_seo( $post_id, $post ) {
$meta_value = get_post_meta( $post_id, $meta_key, true );
/* If there is no new meta value but an old value exists, delete it. */
- if ( '' == $new_meta_value && $meta_value )
+ if ( current_user_can( 'delete_post_meta', $post_id, $meta_key ) && '' == $new_meta_value && $meta_value )
delete_post_meta( $post_id, $meta_key, $meta_value );
+ /* If a new meta value was added and there was no previous value, add it. */
+ elseif ( current_user_can( 'add_post_meta', $post_id, $meta_key ) && $new_meta_value && '' == $meta_value )
+ add_post_meta( $post_id, $meta_key, $new_meta_value, true );
+
/* If the new meta value does not match the old value, update it. */
- elseif ( $new_meta_value && $new_meta_value != $meta_value )
+ elseif ( current_user_can( 'edit_post_meta', $post_id, $meta_key ) && $new_meta_value && $new_meta_value != $meta_value )
update_post_meta( $post_id, $meta_key, $new_meta_value );
}
}
@@ -80,16 +80,12 @@ function hybrid_meta_box_post_save_template( $post_id, $post ) {
if ( !isset( $_POST['hybrid-core-post-meta-box-template'] ) || !wp_verify_nonce( $_POST['hybrid-core-post-meta-box-template'], basename( __FILE__ ) ) )
return $post_id;
- /* Check if the current user has permission to edit the post meta. */
- if ( !current_user_can( 'edit_post_meta', $post_id ) )
- return $post_id;
-
/* Return here if the template is not set. There's a chance it won't be if the post type doesn't have any templates. */
if ( !isset( $_POST['hybrid-post-template'] ) )
return $post_id;
/* Get the posted meta value. */
- $new_meta_value = strip_tags( $_POST['hybrid-post-template'] );
+ $new_meta_value = $_POST['hybrid-post-template'];
/* Set the $meta_key variable based off the post type name. */
$meta_key = "_wp_{$post->post_type}_template";
@@ -98,11 +94,15 @@ function hybrid_meta_box_post_save_template( $post_id, $post ) {
$meta_value = get_post_meta( $post_id, $meta_key, true );
/* If there is no new meta value but an old value exists, delete it. */
- if ( '' == $new_meta_value && $meta_value )
+ if ( current_user_can( 'delete_post_meta', $post_id ) && '' == $new_meta_value && $meta_value )
delete_post_meta( $post_id, $meta_key, $meta_value );
+ /* If a new meta value was added and there was no previous value, add it. */
+ elseif ( current_user_can( 'add_post_meta', $post_id, $meta_key ) && $new_meta_value && '' == $meta_value )
+ add_post_meta( $post_id, $meta_key, $new_meta_value, true );
+
/* If the new meta value does not match the old value, update it. */
- elseif ( $new_meta_value && $new_meta_value != $meta_value )
+ elseif ( current_user_can( 'edit_post_meta', $post_id ) && $new_meta_value && $new_meta_value != $meta_value )
update_post_meta( $post_id, $meta_key, $new_meta_value );
}
View
@@ -223,6 +223,9 @@ function functions() {
/* Load media-related functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'media.php' );
+ /* Load the metadata functions. */
+ require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'meta.php' );
+
/* Load the utility functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'utility.php' );

0 comments on commit ab93562

Please sign in to comment.