Skip to content

Instantly share code, notes, and snippets.

@imath

imath/admin.php Secret

Last active December 20, 2020 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/df65b7c856fbd02024a84c7ecc016090 to your computer and use it in GitHub Desktop.
Save imath/df65b7c856fbd02024a84c7ecc016090 to your computer and use it in GitHub Desktop.
Extract of the upgrade function used by the "Types de membre" plugin
<?php
function unique_prefix_upgrade_plugin() {
// Old way of storing Member type props.
$member_type_props = get_option(
'_unique_prefix_option_name'
array(
// Term ID => Member Type plural name.
170 => 'Company service A',
177 => 'Company service B',
)
);
// BuddyPress required file.
$bp_file = trailingslashit( buddypress()->plugin_dir ) . 'bp-core/admin/bp-core-admin-types.php';
if ( $member_types_props && file_exists( $bp_file ) ) {
require_once $bp_file;
$member_types = bp_get_terms(
array(
'taxonomy' => bp_get_member_type_tax_name(),
'include' => array_keys( $member_type_props ),
'fields' => 'id=>slug',
)
);
foreach ( $member_types as $term_id => $slug ) {
if ( ! isset( $member_type_props[ $term_id ] ) ) {
continue;
}
bp_core_admin_update_type(
array(
'taxonomy' => bp_get_member_type_tax_name(),
'type_term_id' => $term_id,
'bp_type_name' => $member_type_props[ $term_id ], // Plural name.
'bp_type_singular_name' => $member_type_props[ $term_id ], // Singular name.
'bp_type_has_directory' => true, // True to allow the Members directory to be filtered by this type.
'bp_type_directory_slug' => $slug,
'bp_type_show_in_list' => true, // True to allow the type to be listed into the Member page's header.
)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment