hp3
Forum Replies Created
-
Forum: Plugins
In reply to: [Plugin: Import Users from CSV] adding wp_capability for usersOne other challenge is adding a user to the database with a pre-existing user id. In my case I am adding a phpbb user database to my wordpress blog. I will be transfering some posts from phpbb as well as users and want to match up the posts with user ids.
If a row in the csv has an id value that does not already exist in the wordpress user database, wordpress will generate error because the plug-in calls wp_update_user for a non existant user.
I set the $update variable to false in line 134 to require the plug-in to use wp_insert_user instead of update user.
It seems that if userdata passed to core wp_insert_user() contains an id then it will try to get the existing data for the user. In my case the user does not exist in the users table and the getuser() function returns false causing an error in other parts of wp_insert_user() which are expecting a user object.
To insert a bunch of new users with user id intact, would require modifying the core wp_insert_user method to prevent the function from always calling getuser() if there is an id field.
Forum: Plugins
In reply to: [Plugin: Import Users from CSV] adding wp_capability for usersI might also be useful to edit the above code to check if a $metavalue contains content before creating a meta table field for it. This would prevent empty meta fields in the database.
foreach ( $usermeta as $metakey => $metavalue ) { if(strlen($metavalue) > 0){ if($metakey == "wp_capabilities"){ $special_user = new WP_User($user_id); $special_user->add_cap($metavalue); } else { update_user_meta( $user_id, $metakey, $metavalue ); } } }Forum: Plugins
In reply to: [Plugin: Import Users from CSV] adding wp_capability for usersPerhaps it would be more flexible if there was a way to detect if a field value in the csv contains a serialized version of data and then save the data to the meta table without WordPress re-serializing the data as a string.
This would allow the csv to contain user meta parameters for plug-ins.
Forum: Plugins
In reply to: [Plugin: Import Users from CSV] adding wp_capability for usersI altered the plug-in code to use the WP_user->add_cap method if there is a $metakey with the name “wp_capabilities”.
I changed the original code at around line 148 in import-user-from-csv.php:
foreach ( $usermeta as $metakey => $metavalue ) { update_user_meta( $user_id, $metakey, $metavalue ); }to
foreach ( $usermeta as $metakey => $metavalue ) { if($metakey == "wp_capabilities"){ $special_user = new WP_User($user_id); $special_user->add_cap($metavalue); } else { update_user_meta( $user_id, $metakey, $metavalue ); } }This calls the add_cap method so that WordPress properly saves the value in ‘wp_capabilities’.
Forum: Plugins
In reply to: [Plugin: Import Users from CSV] adding wp_capability for usersI created a column in my csv named ‘wp_capabilities’.
I added the following capabilities string to the fields for the ‘wp_capabilities’ column.
a:2:{s:10:”subscriber”;s:1:”1″;s:16:”post_edit_recipe”;s:1:”1″;}When I upload the csv, wordpress creates the user, creates the wp_capabilities field in the meta table but converts the above string to:
s:64:”a:2:{s:10:”subscriber”;s:1:”1″;s:16:”post_edit_recipe”;s:1:”1″;}“;There is an s:64:” to the beginning of the string and “; at the end of the string. WordPress seems to ignore this capability formatting and the user does not have the capability function in the wordpress site.
If I manually remove the s:64:” and “; then wordpress recognizes the capability values and the user has appropriate capabilities in the web site.
Forum: Fixing WordPress
In reply to: front end form file upload error message for unsupported mime typesI found the is_wp_error() function to determine if there is a word press error, such as attempting to upload an unsubpported file type, and the get_error_message() function to show the error message.
if ( $file_err_check === UPLOAD_ERR_OK){ // no error in file upload $newupload = insert_attachment($file,$pid); // $newupload returns the attachment id of the file // check for word press error, like file not supported if (is_wp_error($newupload)) { $error_string = $newupload->get_error_message(); echo '<div id="message" class="error"><p>' . $error_string . '</p></div>'; } }Is there a way to customize the wording of word press errors from a lanaguage file?
Forum: Hacks
In reply to: change position of field label for comment form fieldsThanks for the suggestion. I wanted to avoid building a new template just for the form and rely on a programmatic solution.
I was able to use a filter to change the position of the label tag for the email and author fields. However the required mark no longer displays for these two fields.
The documentation for the comment_form() under $fields uses a $req variable. I am not sure if this is a legit wordpress variable or just something in the example.
I copied these example form element HTML strings, but the $req variable is probably not correctly used in my code. I tried using global in my filter function but that did not fix the problem.
ex.
function modify_form($updated_fields){
global $req;
$updated_fields[‘author’] = ‘revised html’ . ( $req ? ‘<span class=”required”>*</span>’ : ” );
$updated_fields[’email’] = ‘revised html’ . . ( $req ? ‘<span class=”required”>*</span>’ : ” );
return $updated_fields;
}
add_filter(‘comment_form_default_fields’, ‘modify_form’);How do I know if a field is required?
Forum: Themes and Templates
In reply to: margin between all widgets execept last in dynamic side barI ended up using :last-child. Its never been clear to me how well this pseudo class is supported. I dont need to worry much about IE6 for this project but which browsers are supporting :last-child these days?
Forum: Plugins
In reply to: slight modification to all widgetsThanks, both of these suggestions worked except for adding the <hr /> to the search form title.
I first removed searchform.php template from my theme files. Then I modified the code in the functions.php as you suggested. This added the <hr /> after all widget titles in the primary side bar, except the title of the default search form.
The filter replaced the wording of the button “search” with “go”. I added a second string_replace in the filter to reword the Search form widget title and add a <hr />.
However, I am wondering what is different about the search form widget that the title did not include <hr /> tag, eventhough I modified the after_title argument to include the <hr />, while the other widget titles correctly did include the <hr />. I had to resort to a search_replace to include the <hr /> for the Search form widget title. Any suggestions?
I also tested with a searchform.php template and it seems that wordpress overrides any default widget code with the code in the searchform.php, so I did not end up with two <hr /> tags. I assume register_sidebar() does not apply when there is a corresponding template file for the widget. Since the searchform.php is not really necessary I removed it and will instead rely upon modifications to the functions.php file.
Thanks again for your helpful suggestions.