Created
July 29, 2013 08:41
-
-
Save ginsterbusch/6103000 to your computer and use it in GitHub Desktop.
Enable custom fields for the WordPress comments only for pages/posts with a specific custom field key and value. Quick'n'dirty copy + paste out of a plugin I've been working on (also see the debug inserts) ;) In this case, the custom meta field key is $this->pluginPrefix . 'page' = participant_list_page (that should already tell you what I'm aim…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_participant_page() { | |
global $post; | |
$return = false; | |
$arrDebug = array( | |
'post' => $post, | |
); | |
// check custom field | |
$strIsParticipantsPage = get_post_meta( $post->ID, $this->pluginPrefix . 'page', true ); | |
$arrDebug['post_meta'] = $strIsParticipantsPage; | |
if( !empty( $strIsParticipantsPage ) && $strIsParticipantsPage == '1' ) { | |
$return = true; | |
//echo '<!-- custom post meta: enabled -->'; | |
} else { | |
//echo '<!-- custom post meta: disabled -->'; | |
} | |
//echo '<!-- debug: '. print_r( $arrDebug, true ) . ' -->'; | |
return $return; | |
} | |
// add a participant to the current list | |
public function custom_comment_fields( $fields ) { | |
$return = $fields; | |
if( $this->is_participant_page() ) { | |
$commenter = wp_get_current_commenter(); | |
$req = get_option( 'require_name_email' ); | |
$aria_req = ( $req ? " aria-required='true'" : '' ); | |
$return[ 'author' ] = '<p class="comment-form-author custom-field">'. | |
'<label for="author">' . __( 'Name' ) . '</label>'. | |
( $req ? '<span class="required">*</span>' : '' ). | |
'<input id="author" name="author" type="text" value="'. esc_attr( $commenter['comment_author'] ) . | |
'" size="30" tabindex="1"' . $aria_req . ' /></p>'; | |
$return[ 'email' ] = '<p class="comment-form-email custom-field">'. | |
'<label for="email">' . __( 'Email' ) . '</label>'. | |
( $req ? '<span class="required">*</span>' : '' ). | |
'<input id="email" name="email" type="text" value="'. esc_attr( $commenter['comment_author_email'] ) . | |
'" size="30" tabindex="2"' . $aria_req . ' /></p>'; | |
$return[ 'url' ] = '<p class="comment-form-url custom-field">'. | |
'<label for="url">' . __( 'Website' ) . '</label>'. | |
'<input id="url" name="url" type="text" value="'. esc_attr( $commenter['comment_author_url'] ) . | |
'" size="30" tabindex="3" /></p>'; | |
$return[ 'phone' ] = '<p class="comment-form-phone custom-field">'. | |
'<label for="phone">' . __( 'Phone' ) . '</label>'. | |
'<input id="phone" name="phone" type="text" size="30" tabindex="4" /></p>'; | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment