586624d5 by Jeff Balicki

my account

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 271536b0
1 # Ultimate Member - Account tabs
2 Adds custom tabs to users' accounts.
3
4 This plugin has to be used with the [Ultimate Member](https://wordpress.org/plugins/ultimate-member/) plugin.
5
6 __Note:__ This is a free extension created for the community. The Ultimate Member team does not support this extension.
7
8 ## Key features
9 - Ability to create custom account tabs with custom title, content and icon.
10 - Ability to restrict custom account tabs for specific user roles.
11 - Ability to embed a profile form into the custom account tab.
12
13 ## Installation
14 ### Clone from GitHub
15 Open git bash, navigate to the **plugins** folder and execute this command:
16
17 `git clone --branch=main git@github.com:umdevelopera/um-account-tabs.git um-account-tabs`
18
19 Once the plugin is cloned, enter your site admin dashboard and go to _wp-admin > Plugins > Installed Plugins_. Find the "Ultimate Member - Account tabs" plugin and click the "Activate" link.
20
21 ### Install from ZIP archive
22 You can install this plugin from the [ZIP archive](https://drive.google.com/file/d/1mXrY5qQT-dJDlBek30kgSjlwN_eeLf0l/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin).
23
24 ## How to use
25 Once the plugin is activated go to *wp-admin > Ultimate Member > Account Tabs*.
26 Click the __Add New__ button, then configure a new account tab as shown on the image below.
27 Select the profile form you want to embed to account in the setting __Embed a profile form__.
28
29 ### Screenshots:
30
31 Image - How to create a new account tab.
32 ![WP, Ultimate Member, Account Tabs](https://user-images.githubusercontent.com/113178913/200563260-7c127190-2933-4b93-94b7-ddf190706bb9.png)
33
34 Image - Custom account tab settings.
35 ![WP, Ultimate Member, Account Tabs, Add (Edit) Tab](https://user-images.githubusercontent.com/113178913/200563285-df4bd1bc-536c-4be4-8354-bf19365b75a9.png)
36
37 Image - An example of the embed profile form in Account
38 ![example - custom tab with profile form in account](https://user-images.githubusercontent.com/113178913/200563307-c69e7d23-e568-41c6-acb6-712ea32e87a2.png)
39
40 ## Related links:
41 Download the core __Ultimate Member__ plugin: https://wordpress.org/plugins/ultimate-member/
42
43 The __Profile tabs__ extension: https://ultimatemember.com/extensions/profile-tabs/
44
45 Ultimate Member home page: https://ultimatemember.com/
46
47 Ultimate Member documentation: https://docs.ultimatemember.com/
48
49 Articles:
50 - [Account Tab](https://docs.ultimatemember.com/article/40-account-tab)
51 - [Extend Ultimate Member Account page with custom tabs/content](https://docs.ultimatemember.com/article/65-extend-ultimate-member-account-page-with-custom-tabs-content)
52 - [Extend the Account page with Ultimate Member pre-defined fields](https://docs.ultimatemember.com/article/1770-extend-the-account-page-with-ultimate-member-pre-defined-fields)
1 jQuery( document.body ).on( 'click', '#UM_fonticons a.um-admin-modal-back:not(.um-admin-modal-cancel)', function ( e ) {
2 var $input = jQuery( '#um_account_tab__icon' );
3 var icon = jQuery( e.currentTarget ).data('code') || $input.siblings( '.um-admin-icon-value' ).find( 'i' ).attr( 'class' );
4 $input.val( icon );
5 } );
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 /**
3 * Adds the Account Tabs sumbenu to the Ultimate Member admin menu.
4 *
5 * @package um_ext\um_account_tabs\admin
6 */
7
8 namespace um_ext\um_account_tabs\admin;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 if ( ! class_exists( 'um_ext\um_account_tabs\admin\Admin' ) ) {
15
16
17 /**
18 * Class Admin.
19 *
20 * @package um_ext\um_account_tabs\admin
21 */
22 class Admin {
23
24
25 /**
26 * Admin constructor.
27 */
28 public function __construct() {
29 add_action( 'admin_menu', array( &$this, 'create_admin_submenu' ), 1001 );
30 add_action( 'load-post.php', array( &$this, 'init_metaboxes' ), 9 );
31 add_action( 'load-post-new.php', array( &$this, 'init_metaboxes' ), 9 );
32 add_filter( 'um_is_ultimatememeber_admin_screen', array( &$this, 'is_um_screen' ), 10, 1 );
33 add_filter( 'wp_insert_post_data', array( &$this, 'filter_post_data' ), 10, 4 );
34 }
35
36
37 /**
38 * Add submenu for Account Tabs.
39 */
40 public function create_admin_submenu() {
41 add_submenu_page(
42 'ultimatemember',
43 __( 'Account Tabs', 'um-account-tabs' ),
44 __( 'Account Tabs', 'um-account-tabs' ),
45 'manage_options',
46 'edit.php?post_type=um_account_tabs'
47 );
48 }
49
50
51 /**
52 * Enqueue admin scripts.
53 *
54 * @global object $current_screen
55 */
56 public function enqueue() {
57 global $current_screen;
58 if ( isset( $current_screen ) && 'um_account_tabs' === $current_screen->id ) {
59 wp_enqueue_script(
60 'um-account-tabs-admin',
61 um_account_tabs_url . '/assets/js/um-account-tabs-admin.js',
62 array( 'jquery' ),
63 um_account_tabs_version,
64 true
65 );
66 }
67 }
68
69
70 /**
71 * Validates the account tab name and slug to be not empty.
72 *
73 * @param array $data An array of slashed, sanitized, and processed post data.
74 * @param array $postarr An array of sanitized (and slashed) but otherwise unmodified post data.
75 * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data.
76 * @param bool $update Whether this is an existing post being updated.
77 * @return array
78 */
79 public function filter_post_data( $data, $postarr, $unsanitized_postarr, $update ) {
80
81 if ( isset( $data['post_type'] ) && 'um_account_tabs' === $data['post_type'] && isset( $unsanitized_postarr['post_status'] ) && 'auto-draft' !== $unsanitized_postarr['post_status'] ) {
82 if ( empty( $data['post_title'] ) ) {
83 $data['post_title'] = 'Account Tab';
84 }
85 if ( empty( $data['post_name'] ) ) {
86 $tab_id = empty( $unsanitized_postarr['ID'] ) ? time() : $unsanitized_postarr['ID'];
87 $data['post_name'] = 'account-tab-' . $tab_id;
88 }
89 }
90
91 return $data;
92 }
93
94
95 /**
96 * Extends UM admin pages for enqueue scripts.
97 *
98 * @param bool $is_um Whether this screen is a part of the Ultimate Member.
99 *
100 * @return bool
101 */
102 public function is_um_screen( $is_um ) {
103 global $current_screen;
104 if ( ! empty( $current_screen ) && strstr( $current_screen->id, 'um_account_tabs' ) ) {
105 $is_um = true;
106 }
107 return $is_um;
108 }
109
110
111 /**
112 * Add metaboxes to Add/Edit Account Tab screen.
113 */
114 public function init_metaboxes() {
115 global $current_screen;
116 if ( isset( $current_screen ) && 'um_account_tabs' === $current_screen->id ) {
117 add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue' ) );
118 add_action( 'add_meta_boxes', array( &$this, 'add_metaboxes' ), 1 );
119 add_action( 'save_post_um_account_tabs', array( &$this, 'save_metaboxes_data' ), 10, 3 );
120 }
121 }
122
123
124 /**
125 * Add metaboxes.
126 */
127 public function add_metaboxes() {
128 // don't show metaboxes for translations.
129 if ( UM()->external_integrations()->is_wpml_active() ) {
130 global $post, $sitepress;
131 $tab_id = $sitepress->get_object_id( $post->ID, 'um_account_tabs', true, $sitepress->get_default_language() );
132 if ( $tab_id && $tab_id !== $post->ID ) {
133 return;
134 }
135 }
136
137 add_meta_box(
138 'um-admin-custom-account-tab/um-form{' . um_account_tabs_path . '}',
139 __( 'Pre-defined content', 'um-account-tabs' ),
140 array( UM()->metabox(), 'load_metabox_custom' ),
141 'um_account_tabs',
142 'normal',
143 'default'
144 );
145
146 add_meta_box(
147 'um-admin-custom-account-tab/access{' . um_account_tabs_path . '}',
148 __( 'Display Settings', 'um-account-tabs' ),
149 array( UM()->metabox(), 'load_metabox_custom' ),
150 'um_account_tabs',
151 'side',
152 'default'
153 );
154
155 add_meta_box(
156 'um-admin-custom-account-tab/icon{' . um_account_tabs_path . '}',
157 __( 'Customize this tab', 'um-account-tabs' ),
158 array( UM()->metabox(), 'load_metabox_custom' ),
159 'um_account_tabs',
160 'side',
161 'default'
162 );
163 }
164
165
166 /**
167 * Save settings in metaboxes.
168 *
169 * @param int $post_id Post ID.
170 * @param \WP_Post $post Post object.
171 * @param bool $update Whether this is an existing post being updated.
172 */
173 public function save_metaboxes_data( $post_id, $post, $update ) {
174 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
175 return;
176 }
177 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
178 return;
179 }
180 if ( empty( $_POST ) ) {
181 return;
182 }
183
184 check_admin_referer( 'update-post_' . $post_id );
185
186 if ( UM()->external_integrations()->is_wpml_active() ) {
187 global $sitepress;
188 $tab_id = $sitepress->get_object_id( $post_id, 'um_account_tabs', true, $sitepress->get_default_language() );
189 if ( $tab_id && $tab_id !== $post_id ) {
190 return;
191 }
192 }
193
194 if ( empty( $_POST['um_account_tab'] ) ) {
195 return;
196 }
197 $input = map_deep( wp_unslash( $_POST['um_account_tab'] ), 'sanitize_text_field' );
198
199 $form = '';
200 if ( isset( $input['_um_form'] ) ) {
201 $form = absint( $input['_um_form'] );
202 }
203 update_post_meta( $post_id, '_um_form', $form );
204
205 $roles = array();
206 if ( isset( $input['_can_have_this_tab_roles'] ) && is_array( $input['_can_have_this_tab_roles'] ) ) {
207 $roles = $input['_can_have_this_tab_roles'];
208 }
209 update_post_meta( $post_id, '_can_have_this_tab_roles', $roles );
210
211 $icon = '';
212 if ( isset( $input['_icon'] ) ) {
213 $icon = sanitize_key( $input['_icon'] );
214 }
215 update_post_meta( $post_id, '_icon', $icon );
216
217 $icon = '';
218 if ( isset( $input['_position'] ) ) {
219 $icon = sanitize_key( $input['_position'] );
220 }
221 update_post_meta( $post_id, '_position', $icon );
222 }
223 }
224 }
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 global $post;
7
8 $tab_id = $post->ID;
9 if ( UM()->external_integrations()->is_wpml_active() ) {
10 global $sitepress;
11 $default_lang_tab_id = $sitepress->get_object_id( $tab_id, 'um_account_tabs', true, $sitepress->get_default_language() );
12 if ( $default_lang_tab_id && $default_lang_tab_id !== $tab_id ) {
13 $tab_id = $default_lang_tab_id;
14 echo '<p>' . esc_html__( 'These settings are obtained from a Account tab in the default language', 'um-account-tabs' ) . '</p>';
15 }
16 }
17
18 $all_roles = UM()->roles()->get_roles();
19
20 $fields = array(
21 array(
22 'id' => '_can_have_this_tab_roles',
23 'type' => 'select',
24 'options' => $all_roles,
25 'label' => __( 'Show on these roles accounts', 'um-account-tabs' ),
26 'tooltip' => __( 'You could select the roles which have the current account tab at their form. If empty, account tab is visible for all roles at their forms.', 'um-account-tabs' ),
27 'multi' => true,
28 'value' => get_post_meta( $tab_id, '_can_have_this_tab_roles', true ),
29 ),
30 );
31
32 UM()->admin_forms(
33 array(
34 'class' => 'um-account-tab-access um-top-label',
35 'prefix_id' => 'um_account_tab',
36 'fields' => $fields,
37 )
38 )->render_form();
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 global $post;
7
8 $tab_id = $post->ID;
9 if ( UM()->external_integrations()->is_wpml_active() ) {
10 global $sitepress;
11 $default_lang_tab_id = $sitepress->get_object_id( $tab_id, 'um_account_tabs', true, $sitepress->get_default_language() );
12 if ( $default_lang_tab_id && $default_lang_tab_id !== $tab_id ) {
13 $tab_id = $default_lang_tab_id;
14 echo '<p>' . esc_html__( 'These settings are obtained from a Account tab in the default language', 'um-account-tabs' ) . '</p>';
15 }
16 }
17
18 $position = get_post_meta( $tab_id, '_position', true );
19 if ( empty( $position ) ) {
20 $position = 800;
21 }
22
23 $fields = array(
24 array(
25 'id' => '_icon',
26 'type' => 'icon',
27 'label' => __( 'Icon', 'um-account-tabs' ),
28 'value' => (string) get_post_meta( $tab_id, '_icon', true ),
29 ),
30 array(
31 'id' => '_position',
32 'type' => 'number',
33 'label' => __( 'Position', 'um-account-tabs' ),
34 'value' => (int) $position,
35 ),
36 );
37
38 UM()->admin_forms(
39 array(
40 'class' => 'um-account-tab-icon um-top-label',
41 'prefix_id' => 'um_account_tab',
42 'fields' => $fields,
43 )
44 )->render_form();
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 global $post;
7
8 $tab_id = $post->ID;
9 if ( UM()->external_integrations()->is_wpml_active() ) {
10 global $sitepress;
11 $default_lang_tab_id = $sitepress->get_object_id( $tab_id, 'um_account_tabs', true, $sitepress->get_default_language() );
12 if ( $default_lang_tab_id && $default_lang_tab_id !== $tab_id ) {
13 $tab_id = $default_lang_tab_id;
14 echo '<p>' . esc_html__( 'These settings are obtained from a Account tab in the default language', 'um-account-tabs' ) . '</p>';
15 }
16 }
17
18 $forms_options = array(
19 '' => __( 'No form', 'um-account-tabs' ),
20 );
21
22 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query
23 $forms = get_posts(
24 array(
25 'post_type' => 'um_form',
26 'posts_per_page' => -1,
27 'meta_query' => array(
28 array(
29 'key' => '_um_mode',
30 'compare' => '=',
31 'value' => 'profile',
32 ),
33 ),
34 )
35 );
36 // phpcs:enable
37 if ( is_array( $forms ) ) {
38 foreach ( $forms as $form ) {
39 $forms_options[ $form->ID ] = $form->post_title;
40 }
41 }
42
43 $selected_form = get_post_meta( $tab_id, '_um_form', true );
44
45 if ( $selected_form ) {
46 echo '<p>[ultimatemember form_id="' . absint( $selected_form ) . '" /]</p>';
47 }
48
49 $fields = array(
50 array(
51 'id' => '_um_form',
52 'type' => 'select',
53 'label' => __( 'Embed a profile form', 'um-account-tabs' ),
54 'options' => $forms_options,
55 'value' => $selected_form,
56 ),
57 );
58
59 UM()->admin_forms(
60 array(
61 'class' => 'um-account-tab-um-form um-top-label',
62 'prefix_id' => 'um_account_tab',
63 'fields' => $fields,
64 )
65 )->render_form();
1 <?php
2 /**
3 * Modifies the Account page.
4 *
5 * @package um_ext\um_account_tabs\core
6 */
7
8 namespace um_ext\um_account_tabs\core;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Class Account.
16 *
17 * @package um_ext\um_account_tabs\core
18 */
19 class Account {
20
21
22 /**
23 * Custom tabs.
24 *
25 * @var array
26 */
27 protected $tabs = null;
28
29
30 /**
31 * Account constructor.
32 */
33 public function __construct() {
34 add_filter( 'um_account_page_default_tabs_hook', array( &$this, 'add_tabs' ), 100, 1 );
35 }
36
37 /**
38 * Get all custom account tabs like posts array.
39 *
40 * @return array Posts.
41 */
42 public function get_tabs() {
43 if ( ! is_array( $this->tabs ) ) {
44 $this->tabs = get_posts(
45 array(
46 'post_type' => 'um_account_tabs',
47 'posts_per_page' => -1,
48 )
49 );
50 }
51 return $this->tabs;
52 }
53
54
55 /**
56 * Add custom account tabs.
57 *
58 * @param array $tabs All account tabs.
59 *
60 * @return array
61 */
62 public function add_tabs( $tabs ) {
63 foreach ( $this->get_tabs() as $tab ) {
64 if ( ! $this->can_have_tab( $tab->ID ) ) {
65 continue;
66 }
67
68 $icon = empty( $tab->_icon ) ? 'um-icon-plus' : $tab->_icon;
69 $position = absint( $tab->_position );
70
71 // Add tab to menu.
72 $tabs[ $position ][ $tab->post_name ] = array(
73 'icon' => $icon,
74 'title' => $tab->post_title,
75 'custom' => true,
76 'show_button' => ! empty( $tab->_um_form ),
77 'submit_title' => __( 'Update', 'um-account-tabs' ),
78 );
79
80 // Show tab content.
81 add_action(
82 'um_account_content_hook_' . $tab->post_name,
83 function( $args ) use ( $tab ) {
84 $output = '';
85
86 $userdata = get_userdata( get_current_user_id() );
87 $placeholders = array(
88 '{user_id}' => get_current_user_id(),
89 '{first_name}' => $userdata->first_name,
90 '{last_name}' => $userdata->last_name,
91 '{user_email}' => $userdata->user_email,
92 '{display_name}' => $userdata->display_name,
93 '[ultimatemember form_id=' => '[',
94 );
95
96 $tab_content = str_replace( array_keys( $placeholders ), array_values( $placeholders ), $tab->post_content );
97
98 // Fix conflict that may appear if the tab contains Elementor template.
99 if ( class_exists( '\Elementor\Plugin' ) ) {
100 \Elementor\Plugin::instance()->frontend->remove_content_filter();
101 $output .= apply_filters( 'the_content', $tab_content );
102 \Elementor\Plugin::instance()->frontend->add_content_filter();
103 } else {
104 $output .= apply_filters( 'the_content', $tab_content );
105 }
106
107 $output .= $this->um_custom_tab_form( $tab->ID, $tab->_um_form );
108
109 return $output;
110 }
111 );
112
113 }
114 return $tabs;
115 }
116
117
118 /**
119 * Check if user has the current tab by role.
120 *
121 * @param string $tab_id Tab key.
122 *
123 * @return bool
124 */
125 public function can_have_tab( $tab_id ) {
126
127 $can_have = get_post_meta( $tab_id, '_can_have_this_tab_roles', true );
128 if ( empty( $can_have ) ) {
129 return true;
130 }
131
132 $current_user_roles = UM()->roles()->get_all_user_roles( get_current_user_id() );
133 if ( ! is_array( $current_user_roles ) ) {
134 $current_user_roles = array();
135 }
136
137 if ( array_intersect( $current_user_roles, $can_have ) ) {
138 return true;
139 }
140
141 return false;
142 }
143
144
145 /**
146 * Generate content for custom tabs.
147 *
148 * @param string $tab_id Tab ID.
149 * @param int $form_id Form ID.
150 *
151 * @return string
152 */
153 public function um_custom_tab_form( $tab_id, $form_id = 0 ) {
154 if ( empty( $form_id ) ) {
155 return '';
156 }
157 $user_id = get_current_user_id();
158
159 // save profile settings.
160 $set_id = UM()->fields()->set_id;
161 $set_mode = UM()->fields()->set_mode;
162 $editing = UM()->fields()->editing;
163 $viewing = UM()->fields()->viewing;
164
165 // set profile settings.
166 UM()->fields()->set_id = $form_id;
167 UM()->fields()->set_mode = get_post_meta( $form_id, '_um_mode', true );
168 UM()->fields()->editing = true;
169 UM()->fields()->viewing = false;
170
171 $args = array(
172 'form_id' => $form_id,
173 );
174
175 ob_start();
176 do_action( 'um_before_profile_fields', $args );
177 do_action( 'um_main_profile_fields', $args );
178 do_action( 'um_after_form_fields', $args );
179
180 ?>
181 <input type="hidden" name="is_signup" value="1">
182 <input type="hidden" name="profile_nonce" value="<?php echo esc_attr( wp_create_nonce( 'um-profile-nonce' . $user_id ) ); ?>">
183 <input type="hidden" name="user_id" value="<?php echo esc_attr( $user_id ); ?>">
184 <?php
185
186 $contents = ob_get_clean();
187
188 // restore default account settings.
189 UM()->fields()->set_id = $set_id;
190 UM()->fields()->set_mode = $set_mode;
191 UM()->fields()->editing = $editing;
192 UM()->fields()->viewing = $viewing;
193
194 return $contents;
195 }
196 }
1 <?php
2 /**
3 * Adds a custom post type.
4 *
5 * @package um_ext\um_account_tabs\core
6 */
7
8 namespace um_ext\um_account_tabs\core;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Class Common.
16 *
17 * @package um_ext\um_account_tabs\core
18 */
19 class Common {
20
21
22 /**
23 * Common constructor.
24 */
25 public function __construct() {
26 add_action( 'init', array( $this, 'register_post_type' ), 2 );
27 }
28
29
30 /**
31 * Register custom post type.
32 */
33 public function register_post_type() {
34 $labels = array(
35 'name' => _x( 'Account tabs', 'Post Type General Name', 'um-account-tabs' ),
36 'singular_name' => _x( 'Account tab', 'Post Type Singular Name', 'um-account-tabs' ),
37 'menu_name' => __( 'Account Tabs', 'um-account-tabs' ),
38 'all_items' => __( 'All Tabs', 'um-account-tabs' ),
39 'add_new_item' => __( 'Add New Tab', 'um-account-tabs' ),
40 'add_new' => __( 'Add New', 'um-account-tabs' ),
41 'new_item' => __( 'New Tab', 'um-account-tabs' ),
42 'edit_item' => __( 'Edit Tab', 'um-account-tabs' ),
43 'update_item' => __( 'Update Tab', 'um-account-tabs' ),
44 'view_item' => __( 'View Tab', 'um-account-tabs' ),
45 'view_items' => __( 'View Tabs', 'um-account-tabs' ),
46 );
47
48 $args = array(
49 'label' => __( 'Account Tabs', 'um-account-tabs' ),
50 'labels' => $labels,
51 'hierarchical' => false,
52 'public' => false,
53 'show_ui' => true,
54 'show_in_menu' => false,
55 'show_in_admin_bar' => false,
56 'show_in_nav_menus' => false,
57 'can_export' => false,
58 'has_archive' => false,
59 'exclude_from_search' => true,
60 'capability_type' => 'page',
61 'supports' => array( 'title', 'editor' ),
62 );
63
64 register_post_type( 'um_account_tabs', $args );
65 }
66 }
1 <?php
2 /**
3 * Sets default settings on installation.
4 *
5 * @package um_ext\um_account_tabs\core
6 */
7
8 namespace um_ext\um_account_tabs\core;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Class Setup
16 *
17 * @package um_ext\um_account_tabs\core
18 */
19 class Setup {
20
21
22 /**
23 * Settings
24 *
25 * @var array
26 */
27 public $settings_defaults;
28
29
30 /**
31 * Setup constructor.
32 */
33 public function __construct() {
34 $this->settings_defaults = array();
35 }
36
37
38 /**
39 * Set Settings.
40 */
41 public function set_default_settings() {
42 $options = get_option( 'um_options', array() );
43
44 foreach ( $this->settings_defaults as $key => $value ) {
45 if ( ! isset( $options[ $key ] ) ) {
46 $options[ $key ] = $value;
47 }
48 }
49
50 update_option( 'um_options', $options );
51 }
52
53
54 /**
55 * Run on plugin activation.
56 */
57 public function run_setup() {
58 $this->set_default_settings();
59 }
60 }
1 <?php
2 /**
3 * Inits the extension.
4 *
5 * @package um_ext\um_account_tabs\core
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class UM_Account_Tabs
14 */
15 class UM_Account_Tabs {
16
17
18 /**
19 * An instance of the class.
20 *
21 * @var UM_Account_Tabs
22 */
23 private static $instance;
24
25
26 /**
27 * Creates an instance of the class.
28 *
29 * @return UM_Account_Tabs
30 */
31 public static function instance() {
32 if ( is_null( self::$instance ) ) {
33 self::$instance = new self();
34 }
35 return self::$instance;
36 }
37
38
39 /**
40 * UM_Account_Tabs constructor.
41 */
42 public function __construct() {
43 add_filter( 'um_call_object_Account_Tabs', array( &$this, 'get_this' ) );
44
45 $this->common();
46 if ( UM()->is_request( 'admin' ) ) {
47 $this->admin();
48 }
49 if ( UM()->is_request( 'frontend' ) ) {
50 $this->account();
51 }
52 }
53
54
55 /**
56 * @return $this UM_Account_Tabs
57 */
58 public function get_this() {
59 return $this;
60 }
61
62
63 /**
64 * @return um_ext\um_account_tabs\core\Account()
65 */
66 public function account() {
67 if ( empty( UM()->classes['um_account_tabs_account'] ) ) {
68 UM()->classes['um_account_tabs_account'] = new um_ext\um_account_tabs\core\Account();
69 }
70 return UM()->classes['um_account_tabs_account'];
71 }
72
73
74 /**
75 * @return um_ext\um_account_tabs\admin\Admin()
76 */
77 public function admin() {
78 if ( empty( UM()->classes['um_account_tabs_admin'] ) ) {
79 UM()->classes['um_account_tabs_admin'] = new um_ext\um_account_tabs\admin\Admin();
80 }
81 return UM()->classes['um_account_tabs_admin'];
82 }
83
84
85 /**
86 * @return um_ext\um_account_tabs\core\Common()
87 */
88 public function common() {
89 if ( empty( UM()->classes['um_account_tabs_common'] ) ) {
90 UM()->classes['um_account_tabs_common'] = new um_ext\um_account_tabs\core\Common();
91 }
92 return UM()->classes['um_account_tabs_common'];
93 }
94 }
95
96 /**
97 * Adds the class to the UM core.
98 */
99 function um_init_um_account_tabs() {
100 if ( function_exists( 'UM' ) ) {
101 UM()->set_class( 'Account_Tabs', true );
102 }
103 }
104 add_action( 'plugins_loaded', 'um_init_um_account_tabs', -10, 1 );
1 msgid ""
2 msgstr ""
3 "Project-Id-Version: Ultimate Member - Account tabs\n"
4 "Report-Msgid-Bugs-To: \n"
5 "POT-Creation-Date: 2022-12-11 20:06+0000\n"
6 "PO-Revision-Date: 2022-12-11 20:07+0000\n"
7 "Last-Translator: Denis Baran\n"
8 "Language-Team: English (United States)\n"
9 "Language: en_US\n"
10 "Plural-Forms: nplurals=2; plural=n != 1;\n"
11 "MIME-Version: 1.0\n"
12 "Content-Type: text/plain; charset=UTF-8\n"
13 "Content-Transfer-Encoding: 8bit\n"
14 "X-Generator: Loco https://localise.biz/\n"
15 "X-Loco-Version: 2.6.3; wp-6.1\n"
16 "X-Domain: um-account-tabs"
17
18 #: includes/admin/class-admin.php:37 includes/admin/class-admin.php:38
19 #: includes/core/class-common.php:29 includes/core/class-common.php:41
20 msgid "Account Tabs"
21 msgstr ""
22
23 #: includes/core/class-common.php:32
24 msgid "Add New"
25 msgstr ""
26
27 #: includes/core/class-common.php:31
28 msgid "Add New Tab"
29 msgstr ""
30
31 #. Description of the plugin
32 msgid "Adds custom tabs to user account."
33 msgstr ""
34
35 #: includes/core/class-common.php:30
36 msgid "All Tabs"
37 msgstr ""
38
39 #: includes/admin/class-admin.php:140
40 msgid "Customize this tab"
41 msgstr ""
42
43 #: includes/admin/class-admin.php:131
44 msgid "Display Settings"
45 msgstr ""
46
47 #: includes/core/class-common.php:34
48 msgid "Edit Tab"
49 msgstr ""
50
51 #: includes/admin/templates/account-tab/um-form.php:51
52 msgid "Embed a profile form"
53 msgstr ""
54
55 #. Author URI of the plugin
56 msgid "https://ultimatemember.com/support/"
57 msgstr ""
58
59 #: includes/admin/templates/account-tab/icon.php:27
60 msgid "Icon"
61 msgstr ""
62
63 #: includes/core/class-common.php:33
64 msgid "New Tab"
65 msgstr ""
66
67 #: includes/admin/templates/account-tab/um-form.php:19
68 msgid "No form"
69 msgstr ""
70
71 #: includes/admin/templates/account-tab/icon.php:33
72 msgid "Position"
73 msgstr ""
74
75 #: includes/core/class-common.php:27
76 msgctxt "Post Type General Name"
77 msgid "Account tabs"
78 msgstr ""
79
80 #: includes/core/class-common.php:28
81 msgctxt "Post Type Singular Name"
82 msgid "Account tab"
83 msgstr ""
84
85 #: includes/admin/class-admin.php:122
86 msgid "Pre-defined content"
87 msgstr ""
88
89 #: includes/admin/templates/account-tab/access.php:25
90 msgid "Show on these roles accounts"
91 msgstr ""
92
93 #: includes/admin/templates/account-tab/access.php:14
94 #: includes/admin/templates/account-tab/icon.php:14
95 #: includes/admin/templates/account-tab/um-form.php:14
96 msgid "These settings are obtained from a Account tab in the default language"
97 msgstr ""
98
99 #. Name of the plugin
100 msgid "Ultimate Member - Account tabs"
101 msgstr ""
102
103 #. Author of the plugin
104 msgid "Ultimate Member support"
105 msgstr ""
106
107 #: includes/core/class-account.php:72
108 msgid "Update"
109 msgstr ""
110
111 #: includes/core/class-common.php:35
112 msgid "Update Tab"
113 msgstr ""
114
115 #: includes/core/class-common.php:36
116 msgid "View Tab"
117 msgstr ""
118
119 #: includes/core/class-common.php:37
120 msgid "View Tabs"
121 msgstr ""
122
123 #: includes/admin/templates/account-tab/access.php:26
124 msgid ""
125 "You could select the roles which have the current account tab at their form. "
126 "If empty, account tab is visible for all roles at their forms."
127 msgstr ""
1 #, fuzzy
2 msgid ""
3 msgstr ""
4 "Project-Id-Version: Ultimate Member - Account tabs\n"
5 "Report-Msgid-Bugs-To: \n"
6 "POT-Creation-Date: 2022-12-11 20:06+0000\n"
7 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
8 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
9 "Language-Team: \n"
10 "Language: \n"
11 "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
12 "MIME-Version: 1.0\n"
13 "Content-Type: text/plain; charset=UTF-8\n"
14 "Content-Transfer-Encoding: 8bit\n"
15 "X-Generator: Loco https://localise.biz/\n"
16 "X-Loco-Version: 2.6.3; wp-6.1\n"
17 "X-Domain: um-account-tabs"
18
19 #: includes/admin/class-admin.php:37 includes/admin/class-admin.php:38
20 #: includes/core/class-common.php:29 includes/core/class-common.php:41
21 msgid "Account Tabs"
22 msgstr ""
23
24 #: includes/core/class-common.php:32
25 msgid "Add New"
26 msgstr ""
27
28 #: includes/core/class-common.php:31
29 msgid "Add New Tab"
30 msgstr ""
31
32 #. Description of the plugin
33 msgid "Adds custom tabs to user account."
34 msgstr ""
35
36 #: includes/core/class-common.php:30
37 msgid "All Tabs"
38 msgstr ""
39
40 #: includes/admin/class-admin.php:140
41 msgid "Customize this tab"
42 msgstr ""
43
44 #: includes/admin/class-admin.php:131
45 msgid "Display Settings"
46 msgstr ""
47
48 #: includes/core/class-common.php:34
49 msgid "Edit Tab"
50 msgstr ""
51
52 #: includes/admin/templates/account-tab/um-form.php:51
53 msgid "Embed a profile form"
54 msgstr ""
55
56 #. Author URI of the plugin
57 msgid "https://ultimatemember.com/support/"
58 msgstr ""
59
60 #: includes/admin/templates/account-tab/icon.php:27
61 msgid "Icon"
62 msgstr ""
63
64 #: includes/core/class-common.php:33
65 msgid "New Tab"
66 msgstr ""
67
68 #: includes/admin/templates/account-tab/um-form.php:19
69 msgid "No form"
70 msgstr ""
71
72 #: includes/admin/templates/account-tab/icon.php:33
73 msgid "Position"
74 msgstr ""
75
76 #: includes/core/class-common.php:27
77 msgctxt "Post Type General Name"
78 msgid "Account tabs"
79 msgstr ""
80
81 #: includes/core/class-common.php:28
82 msgctxt "Post Type Singular Name"
83 msgid "Account tab"
84 msgstr ""
85
86 #: includes/admin/class-admin.php:122
87 msgid "Pre-defined content"
88 msgstr ""
89
90 #: includes/admin/templates/account-tab/access.php:25
91 msgid "Show on these roles accounts"
92 msgstr ""
93
94 #: includes/admin/templates/account-tab/access.php:14
95 #: includes/admin/templates/account-tab/icon.php:14
96 #: includes/admin/templates/account-tab/um-form.php:14
97 msgid "These settings are obtained from a Account tab in the default language"
98 msgstr ""
99
100 #. Name of the plugin
101 msgid "Ultimate Member - Account tabs"
102 msgstr ""
103
104 #. Author of the plugin
105 msgid "Ultimate Member support"
106 msgstr ""
107
108 #: includes/core/class-account.php:72
109 msgid "Update"
110 msgstr ""
111
112 #: includes/core/class-common.php:35
113 msgid "Update Tab"
114 msgstr ""
115
116 #: includes/core/class-common.php:36
117 msgid "View Tab"
118 msgstr ""
119
120 #: includes/core/class-common.php:37
121 msgid "View Tabs"
122 msgstr ""
123
124 #: includes/admin/templates/account-tab/access.php:26
125 msgid ""
126 "You could select the roles which have the current account tab at their form. "
127 "If empty, account tab is visible for all roles at their forms."
128 msgstr ""
1 === Ultimate Member - Account tabs ===
2 Author: Ultimate Member support
3 Plugin URI: https://github.com/umdevelopera/um-account-tabs
4 Tags: ultimate member, account, profile, tabs
5 Requires at least: 6.0
6 Tested up to: 6.1.1
7 Stable tag: 1.0.1
8 License: GNU Version 2 or Any Later Version
9 License URI: http://www.gnu.org/licenses/gpl-3.0.txt
10 Requires UM core at least: 2.5.0
11
12 == Description ==
13
14 Adds custom tabs to users' accounts.
15
16 = Key Features =
17
18 * Ability to create custom account tabs with custom title, content and icon.
19 * Ability to restrict custom account tabs for specific user roles.
20 * Ability to embed a profile form into the custom account tab.
21
22 == Installation ==
23
24 1. Click the "Code" item then "Download Zip" to download the archive.
25 2. Unpack the downloaded archive and change the folder name to "um-account-tabs".
26 3. Connect your site via FTP and copy the "um-account-tabs" folder to the /wp-content/plugins/ directory.
27 4. Enter your site admin dashboard and go to Plugins > Installed Plugins.
28 5. Find the "Ultimate Member - Account tabs" plugin and click the "Activate" link.
29
30 == Changelog ==
31
32 = 1.0.1: December 11, 2022 =
33
34 * Added: Readme file.
35 * Added: Translation pattern.
36 * Improved: WordPress Coding Standards.
37
38 = 1.0.0: November 08, 2022 =
39
40 * Initial release.
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 /**
3 Plugin Name: Ultimate Member - Account tabs
4 Plugin URI: https://github.com/umdevelopera/um-account-tabs
5 Description: Adds custom tabs to user account.
6 Version: 1.0.1
7 Author: Ultimate Member support
8 Author URI: https://ultimatemember.com/support/
9 Text Domain: um-account-tabs
10 Domain Path: /languages
11 UM version: 2.5.0
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 require_once ABSPATH . 'wp-admin/includes/plugin.php';
19
20 $plugin_data = get_plugin_data( __FILE__ );
21
22 define( 'um_account_tabs_url', plugin_dir_url( __FILE__ ) );
23 define( 'um_account_tabs_path', plugin_dir_path( __FILE__ ) );
24 define( 'um_account_tabs_plugin', plugin_basename( __FILE__ ) );
25 define( 'um_account_tabs_extension', $plugin_data['Name'] );
26 define( 'um_account_tabs_version', $plugin_data['Version'] );
27 define( 'um_account_tabs_textdomain', 'um-account-tabs' );
28 define( 'um_account_tabs_requires', '2.5.0' );
29
30
31 if ( ! function_exists( 'um_account_tabs_plugins_loaded' ) ) {
32 /** Loads translation files */
33 function um_account_tabs_plugins_loaded() {
34 $locale = ( get_locale() !== '' ) ? get_locale() : 'en_US';
35 load_textdomain( um_account_tabs_textdomain, WP_LANG_DIR . '/plugins/' . um_account_tabs_textdomain . '-' . $locale . '.mo' );
36 load_plugin_textdomain( um_account_tabs_textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
37 }
38 }
39 add_action( 'plugins_loaded', 'um_account_tabs_plugins_loaded', 0 );
40
41
42 add_action( 'plugins_loaded', 'um_account_tabs_check_dependencies', -20 );
43
44 if ( ! function_exists( 'um_account_tabs_check_dependencies' ) ) {
45 /** Checks dependencies and calls the plugin main file */
46 function um_account_tabs_check_dependencies() {
47 if ( ! defined( 'um_path' ) || ! file_exists( um_path . 'includes/class-dependencies.php' ) ) {
48 /** UM is not installed. */
49 function um_account_tabs_dependencies() {
50 // translators: %s - plugin name.
51 echo '<div class="error"><p>' . wp_kses_post( sprintf( __( 'The <strong>%s</strong> extension requires the Ultimate Member plugin to be activated to work properly. You can download it <a href="https://wordpress.org/plugins/ultimate-member">here</a>', 'um-user-photos' ), um_account_tabs_extension ) ) . '</p></div>';
52 }
53
54 add_action( 'admin_notices', 'um_account_tabs_dependencies' );
55
56 } else {
57
58 if ( ! function_exists( 'UM' ) ) {
59 require_once um_path . 'includes/class-dependencies.php';
60 $is_um_active = um\is_um_active();
61 } else {
62 $is_um_active = UM()->dependencies()->ultimatemember_active_check();
63 }
64
65 if ( ! $is_um_active ) {
66 /** UM is not active. */
67 function um_account_tabs_dependencies() {
68 // translators: %s - plugin name.
69 echo '<div class="error"><p>' . wp_kses_post( sprintf( __( 'The <strong>%s</strong> extension requires the Ultimate Member plugin to be activated to work properly. You can download it <a href="https://wordpress.org/plugins/ultimate-member">here</a>', 'um-user-photos' ), um_account_tabs_extension ) ) . '</p></div>';
70 }
71
72 add_action( 'admin_notices', 'um_account_tabs_dependencies' );
73
74 } else {
75 require_once um_account_tabs_path . 'includes/core/class-um-account-tabs.php';
76 }
77 }
78 }
79 }
80
81
82 register_activation_hook( um_account_tabs_plugin, 'um_account_tabs_activation_hook' );
83 if ( ! function_exists( 'um_account_tabs_activation_hook' ) ) {
84 /** Activation script */
85 function um_account_tabs_activation_hook() {
86 // first install.
87 $version = get_option( 'um_account_tabs_version' );
88 if ( ! $version ) {
89 update_option( 'um_account_tabs_last_version_upgrade', um_account_tabs_version );
90 }
91
92 if ( um_account_tabs_version !== $version ) {
93 update_option( 'um_account_tabs_version', um_account_tabs_version );
94 }
95
96 // run setup.
97 if ( ! class_exists( 'um_ext\um_account_tabs\core\Setup' ) ) {
98 require_once um_account_tabs_path . 'includes/core/class-setup.php';
99 }
100
101 $setup = new um_ext\um_account_tabs\core\Setup();
102 $setup->run_setup();
103 }
104 }