mikebronner
Forum Replies Created
-
Forum: Plugins
In reply to: [Achievements for WordPress] How-To: Achievement CategoriesUpdate 4: Updated user profile admin page to group achievements by category for better overview and grouping. Add the following code to you functions.php in your child theme:
/* Group Achievements by Category in User Profile *****************************/ function dpa_achievements_add_profile_fields_with_categories($user) { if (!is_super_admin()) {return;} ?> <h3><?php _e( 'Achievements Settings', 'dpa' ); ?></h3> <table class="form-table"> <tr> <th><label for="dpa_achievements"><?php _ex( 'Total Points', "User’s total points from unlocked Achievements", 'dpa' ); ?></label></th> <td><input type="number" name="dpa_achievements" id="dpa_achievements" value="<?php echo esc_attr( dpa_get_user_points( $user->ID ) ); ?>" class="regular-text" /> </td> </tr> <?php if ( dpa_has_achievements_custom( array( 'ach_populate_progress' => $user->ID, 'ach_progress_status' => dpa_get_unlocked_status_id(), 'posts_per_page' => -1, "orderby"=>"konb_term_relationships.term_taxonomy_id",) ) ) { ?> <tr> <th scope="row"><?php _e( 'Unlocked Achievements', 'dpa' ); ?></th> <td> <fieldset> <legend class="screen-reader-text"><?php _e( 'Assign or remove achievements from this user', 'dpa' ); ?></legend> <?php $previous_achievment_category = ""; while ( dpa_achievements() ) { dpa_the_achievement(); $current_category = ""; $categories = get_the_terms($post_id, 'dpa_achievement_category'); foreach($categories as $category) { if (strlen($current_category) > 0) { $current_category .= ", "; } $current_category .= $category->name; } if ($current_category != $previous_achievment_category) { if ($previous_achievment_category != "") { ?> <br /> <?php } $previous_achievment_category = $current_category; ?> <strong><?php echo $current_category; ?>:</strong><br /> <?php } ?> <label><input type="checkbox" name="dpa_user_achievements[]" value="<?php echo esc_attr( dpa_get_the_achievement_ID() ); ?>" <?php checked( dpa_is_achievement_unlocked(), true ); ?>> <?php dpa_achievement_title(); ?></label><br /> <?php } ?> </fieldset> </td> </tr> <?php } ?> </table> <?php remove_action('edit_user_profile', array(achievements()->admin, 'add_profile_fields')); } add_action('edit_user_profile', 'dpa_achievements_add_profile_fields_with_categories', 9);
Forum: Plugins
In reply to: [Achievements for WordPress] How-To: Achievement CategoriesUpdate 3: (How I wish we could update our threads instead of having this mess of additional posts, but nevertheless, here goes.)
Updated register_achievements_post_type_override() function yet again, as the capabilities of the post type need to be reset (they are getting corrupted when they are queried, information is missing):function register_achievements_post_type_override() { global $wp_post_types; $achievements = objectToArray(get_post_types(array('name'=>dpa_get_achievement_post_type()), 'objects')); $progresses = objectToArray(get_post_types(array('name'=>dpa_get_progress_post_type()), 'objects')); $achievements = $achievements[dpa_get_achievement_post_type()]; $progresses = $progresses[dpa_get_progress_post_type()]; $achievements["taxonomies"] = array('dpa_achievement_category'); $progresses["taxonomies"] = array('dpa_achievement_category'); $achievements["capabilities"] = dpa_get_achievement_caps(); $progresses["capabilities"] = dpa_get_achievement_progress_caps(); unset($wp_post_types[dpa_get_achievement_post_type()]); unset($wp_post_types[dpa_get_progress_post_type()]); register_post_type( dpa_get_achievement_post_type(), $achievements ); register_post_type( dpa_get_progress_post_type(), $progresses ); }
Forum: Plugins
In reply to: [Achievements for WordPress] How-To: Achievement CategoriesUpdate 2: Fixed register_achievements_post_type_override() function. Had a typo, which caused achievements to become undeletable. Please replace with the following in your functions.php in your child theme:
function register_achievements_post_type_override() { global $wp_post_types; $achievements = objectToArray(get_post_types(array('name'=>dpa_get_achievement_post_type()), 'objects')); $progresses = objectToArray(get_post_types(array('name'=>dpa_get_progress_post_type()), 'objects')); $achievements = $achievements[dpa_get_achievement_post_type()]; $progresses = $progresses[dpa_get_progress_post_type()]; $achievements["taxonomies"] = array('dpa_achievement_category'); $progresses["taxonomies"] = array('dpa_achievement_category'); unset($wp_post_types[dpa_get_achievement_post_type()]); unset($wp_post_types[dpa_get_progress_post_type()]); register_post_type( dpa_get_achievement_post_type(), $achievements ); register_post_type( dpa_get_progress_post_type(), $progresses ); }
Also, replace the achievement_with_category_edit_columns and achievement_with_category_custom_column functions with the following code. It has been updated to make the column name more unique, so as not to conflict with the normal categories in wordpress:
function achievement_with_category_edit_columns($columns) { $column_position = 3; //choose what position you want the categories to be added $columns_first = array_slice($columns, 0, $column_position - 1, true ); $columns_last = array_slice($columns, $column_position - 1, null, true ); $columns = array_merge( $columns_first, array('achievement_category' => _x('Category', 'Achievement category', 'dpa')), $columns_last ); return $columns; } add_filter("manage_edit-achievement_columns", "achievement_with_category_edit_columns"); function achievement_with_category_custom_columns( $column ) { switch( $column ) { case "achievement_category": echo get_the_term_list( $post->ID, 'dpa_achievement_category', '', ', ', '' ); break; } } add_action("manage_posts_custom_column", "achievement_with_category_custom_columns");
Also add the following code to your functions.php in your child theme to make the achievement category column sortable:
function dpa_achievement_sortable_category_column( $columns ) { $columns['achievement_category'] = 'dpa_achievement_category'; return apply_filters('dpa_achievement_sortable_columns', $columns); } add_filter('manage_edit-achievement_sortable_columns', 'dpa_achievement_sortable_category_column'); function dpa_achievement_category_column_sorting( $vars ) { if( isset($vars['orderby']) && 'achievement_category' == $vars['orderby'] ) { $vars = array_merge($vars, array('meta_key' => 'dpa_achievement_category', 'orderby' => 'meta_value')); } return $vars; } add_filter('requests', 'dpa_achievement_category_column_sorting');
Forum: Plugins
In reply to: [Achievements for WordPress] How-To: Achievement CategoriesUpdate: Improved achievement_with_category_edit_column function to be dynamic, in case the plugin gets updated with new columns. I choose the categories to be listed in the third column, but you can change that to whatever you like.
function achievement_with_category_edit_columns($columns) { $column_position = 3; //choose what position you want the categories to be added $columns_first = array_slice($columns, 0, $column_position - 1, true ); $columns_last = array_slice($columns, $column_position - 1, null, true ); $columns = array_merge( $columns_first, array('category' => _x('Category', 'Achievement category', 'dpa')), $columns_last, ;) return $columns; } add_filter("manage_edit-achievement_columns", "achievement_with_category_edit_columns");
Forum: Plugins
In reply to: [Achievements for WordPress] Localization to SpanishHi Paul, good point: what to do with outdate translations?
I’ve been looking into this a bit and may have found a solution:
- Initialize localizations using the
load_plugin_textdomain
function () - For each version of the plugin where you make changes to text strings, update the domain, i.e. achievements-3-1-4_de-DE.
I believe this will only load updated translation files belonging to the correct domain. Although I’m not sure if this means you need to update your code everywhere there is a string with the new domain?
I guess that leaves the manual option: accept translation files, bearing in mind that the non-translated strings will just show as english, and send out a call to the translators to send in updated language files. But that could get into a management nightmare.
I guess short of that, you could maybe host contributed language files on your web site for people to download and update as need, then include the ones that are up-to-date.
Or you could just specify a localization directory in the plugin, then allow users to add their own translations to their child-theme, but I think a hosted option would be a step better, as it would keep you in the loop, and give your users a starting point to update localizations as needed.
This is a toughie. ??
~Mike
Forum: Plugins
In reply to: [Achievements for WordPress] Localization to SpanishHi Paul, can we submit our translations to be included with your plugin? If you don’t already have one, I’ll be happy to include a German translation.
~Mike
Forum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsNot changing the core code of a plugin is my recommendation! If you need more filters or actions to be able to do this via a helper plugin, let me know what/where.
I’ll investigate what consequences adding support for the categories taxonomy has. Particularly about any new rewrite rules/URLs it’d add, and what happens if a regular post and an achievement has the same categroy, etc.
Thanks Paul! ?? I agree, changing the core code isn’t optimal … it would be recommended to make an alternate version of dpa_has_progress in the child theme’s function.php file. And like you mentioned, adding the taxonomy in by altering the achievements.php file is less than optimal as well. Perhaps it can be hooked in via the functions file, but that would be something that needs research.
I haven’t experimented with adding normal posts to categories used for achievements. I did however notice one little bug int he process, in that the categories admin page is now a sub-item of achievements, instead of standing on its own. Not quite sure what caused that — something else to look into as well.
Admittedly this is a hack work-around to get categories functioning ASAP, and this will break once the plugin is updated.
~Mike
Forum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsOK, solution to group by (do not make the changes in the previous two posts suggested above):
- Edit /wp-content/plugins/achievements/achievements.php and add
'taxonomies' => array('category'),
near line 478 in the $cpt[‘achievement’] object. - Edit content/plugins/achievements/includes/progress/template.php and replace
$achievement_args = array( 'post__in' => $achievement_ids, // Only get achievements that relate to the progressses we've got. 'posts_per_page' => -1, // No pagination );
With:
$achievement_args = array( 'post__in' => $achievement_ids, // Only get achievements that relate to the progressses we've got. 'posts_per_page' => -1, // No pagination 'orderby' => $args["orderby"], 'order' => $args["order"], );
- When calling dpa_has_progress in your child theme template file, content-author-achievement.php, for example, replace dpa_has_progress() with this:
dpa_has_progress(array(“orderby”=>”term_taxonomy_id”))
I will work on figuring out how to filter by category tomorrow.
Example can be viewed here: https://konb.info/forums/users/mike-bronner/
~Mike
Forum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsJust found a flaw in my “solution” above. It now returns ALL achievements, instead of only the ones actually awarded. Will work on this more tomorrow.
Forum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsTo order by category, you will have to do something like the following:
- Around line 324, after $achievement_args = …, add
$args = dpa_parse_args( $args, $achievement_args, 'has_achievement' );
- Replace dpa_has_achievements( $achievement_args ); with
dpa_has_achievements( $args );
This will tie in the order-by args into the achievements list, as otherwise only the progress list is ordered, which isn’t displayed.
Paul, can you confirm that this logic won’t break anything as well? So far it appears to be working for me.
Forum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsI think I found a solution. So now to display get a certain category of achievements, make the following changes in /wp-content/plugins/achievements/includes/progress/template.php:
- Around line 120, change
$achievement_ids = wp_list_pluck( (array) achievements()->progress_query->posts, 'post_parent' );
to:$achievement_ids = wp_list_pluck( (array) achievements()->progress_query->posts, 'ID' );
- When calling dpa_has_progress in your child theme template file, content-author-achievement.php, for example, replace dpa_has_progress() with this:
dpa_has_progress(array("category_name"=>"[slug of category here]", "post_type"=>"achievement", "post_status"=>"publish"))
This worked for me. Paul, can you verify if changing post_parent to ID will have any adverse effects?
Thanks!
~MikeForum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsHere’s how you can categorize your achievements — however, I haven’t figured out yet how to include the categories in the results (working on that part).
Edit /wp-content/plugins/achievements/achievements.php and add
'taxonomies' => array('category'),
near line 478 in the$cpt['achievement']
object.This will let you assign your achievements to WP categories.
Forum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsOne other thing I was looking for was to see if we can award an achievement multiple times to a user.
Forum: Plugins
In reply to: [Achievements for WordPress] A few humble requestsI second the category option. I have different types of achievements that need to be grouped.
I’m trying to figure out a way to do this without to much coding, but it’s not looking good.Forum: Plugins
In reply to: [Achievements for WordPress] User Achievements Index Not DisplayingHere is a link to what I was working on. The medals and ribbons are just examples, we will be updating the graphics to be uniform and align nicely: https://konb.info/forums/users/mike-bronner/
- Initialize localizations using the