Skip to content

Instantly share code, notes, and snippets.

View nikitasinelnikov's full-sized avatar

Mykyta Synelnikov nikitasinelnikov

  • ultimatemember.com
  • Kharkiv, Ukraine
View GitHub Profile
@nikitasinelnikov
nikitasinelnikov / functions.php
Created April 30, 2021 10:16
Ultimate Member: Custom redirect after registration with auto-approve user based on the current language via WPML plugin
function um_custom_registration_redirect( $user_id ) {
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
$language_code = $sitepress->get_current_language();
if ( $language_code == 'fi' ) {
$redirect_url = 'redirect_url1';
} else {
$redirect_url = 'redirect_url2';
@nikitasinelnikov
nikitasinelnikov / functions.php
Last active May 4, 2021 12:51
Ultimate Member: Show only address instead of google map iframe on the member directory
add_action( 'um_member_directory_before_query', 'my_custom_um_remove_googlemap' );
function my_custom_um_remove_googlemap() {
if ( ! empty( $_POST['directory_id'] ) ) {
$directory_id = UM()->member_directory()->get_directory_by_hash( $_POST['directory_id'] );
if ( $directory_id == '{your directory ID here}' ) {
remove_filter( 'um_profile_field_filter_hook__googlemap', 'um_profile_field_filter_hook__googlemap', 99 );
}
}
@nikitasinelnikov
nikitasinelnikov / functions.php
Created May 10, 2021 14:41
Ultimate Member: Activate ability to add users via registration form
//to make this ability possible for all registration forms on your website
add_filter( 'um_registration_for_loggedin_users', '__return_true' );
//to make this ability possible only for {selected registration form ID here}
function my_custom_um_registration_for_loggedin_users( $activate, $args ) {
if ( $args['form_id'] == '{selected registration form ID here}' ) {
$activate = true;
}
return $activate;
}
@nikitasinelnikov
nikitasinelnikov / functions.php
Created May 12, 2021 11:46
Ultimate Member - Profile Completeness: Change field label based on the current language via WPML plugin
function my_custom_fields_array_for_titles( $fields, $key ) {
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
$language_code = $sitepress->get_current_language();
if ( $language_code == 'zh-hant' ) {
switch ( $key ) {
case 'coach-mentoring_specialties':
$fields[ $key ]['label'] = '導師(Coach-Mentoring)特長';
@nikitasinelnikov
nikitasinelnikov / functions.php
Last active May 12, 2021 11:54
Ultimate Member: Change view field value based on the current language via WPML plugin
function um_custom_field_view_wpml( $res, $data, $type ) {
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
$language_code = $sitepress->get_current_language();
if ( $language_code == 'zh-hant' ) {
switch ( $data['metakey'] ) {
case 'gender':
$res = $res == 'Female' ? '女' : '男';
@nikitasinelnikov
nikitasinelnikov / functions.php
Created May 25, 2021 12:53
JobBoardWP: Extends job structured data
// Important: you need to get the job data from the custom post meta where you save them
// there aren't salary types and amount metakey for the job by default
// location address can be extended only when GoogleMapsAPI is active in the plugin settings
// extend location
add_filter( 'jb-job-structured-data', 'jb_job_structured_data_extend_location', 10, 2 );
function jb_job_structured_data_extend_location( $data, $job ){
if ( $job->ID == {jobID here} ) {
$data['jobLocation']['address'] = array(
@nikitasinelnikov
nikitasinelnikov / locales.php
Created May 28, 2021 10:26
language codes vs. WP Locales
$data = [
'af' => 'af_ZA',
'ar' => 'ar',
'az' => 'az',
'be' => 'be_BY',
'bg' => 'bg_BG',
'bn' => 'bn_BD',
'bs' => 'bs_BA',
'ca' => 'ca',
'cs' => 'cs_CZ',
@nikitasinelnikov
nikitasinelnikov / functions.php
Created May 28, 2021 11:19
Ultimate Member v3: How to change templates path from WP native (child theme -> theme) to wp_uploads dir
function um_custom_templates_path( $path, $template_name, $module ) {
$uploads_dir = wp_get_upload_dir();
return $uploads_dir['basedir'];
}
add_filter( 'um_template_structure_custom_path', 'um_custom_templates_path', 10, 3 );
@nikitasinelnikov
nikitasinelnikov / Languages.php
Created June 2, 2021 14:29
The way how to add WP Native locales to Weglot Languages wp-content/plugins/weglot/vendor/weglot/weglot-php/src/Client/Factory/Languages.php
'en' => [ //line 82
'internal_code' => 'en',
'english' => 'English',
'local' => 'English',
'rtl' => false,
'wp_locale' => 'en_US',
],
'ru' => [ //line 340
'internal_code' => 'ru',
@nikitasinelnikov
nikitasinelnikov / functions.php
Created July 22, 2021 16:04
Ultimate Member 2.2.0. Update `Hide from queries` meta for posts and terms
// run this function only once for bulk uncheck `Hide from queries` option for restricted pages, posts
function um_update_post_restrictions() {
global $wpdb;
$posts = $wpdb->get_results("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'um_content_restriction'", ARRAY_A );
foreach ( $posts as $post ) {
$meta_value = maybe_unserialize( $post['meta_value'] );
$meta_value['_um_access_hide_from_queries'] = false;
update_post_meta( $post['post_id'], 'um_content_restriction', $meta_value );
}