Files
ultimatemember/includes/core/um-navmenu-walker-edit.php
T
nikitozzzzzzz 9e53314c3a !!! IMPORTANT 2.0 version before upgrade please run full backup of your site !!!
- new code structure, optimized for next development;
  - created spl_autoloader for remove includes;
  - UM classes with namespaces;
  - deprecated global $ultimatemember; variable (use UM() instead);
- new UM/WP roles logic;
- new settings class and logic (deprecated Redux framework, deprecated some old options, added some new options);
- new dependencies class for extensions;
- WP native styles for backend fields;
- new upgrades and license activations for extensions;
- new logic form backend forms and fields;
- created uninstall.php file for delete permanently all UM settings;
- optimized registration/upgrade profile process;

Deprecated Hooks:

um_new_user_registration_plain
um_user_registration_extra_hook
um_add_user_frontend
um_post_registration_global_hook
um_admin_extend_directory_options_general (was action...will be filter)
2017-07-26 14:57:52 +03:00

141 lines
3.7 KiB
PHP

<?php
class UM_Menu_Item_Custom_Fields_Editor {
protected static $fields = array();
/**
* Initialize plugin
*/
public static function init() {
add_action( 'wp_nav_menu_item_custom_fields', array( __CLASS__, '_fields' ), 1, 4 );
add_action( 'wp_update_nav_menu_item', array( __CLASS__, '_save' ), 10, 3 );
add_filter( 'manage_nav-menus_columns', array( __CLASS__, '_columns' ), 99 );
self::$fields = array(
'um_nav_public' => __( 'Display Mode'),
'um_nav_roles' => __('By Role')
);
}
public static function _save( $menu_id, $menu_item_db_id, $menu_item_args ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
foreach ( self::$fields as $_key => $label ) {
if( $_key == 'um_nav_roles' ){
$key = sprintf( 'menu-item-%s', $_key );
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
}
else {
$value = null;
}
}else{
$key = sprintf( 'menu-item-%s', $_key );
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
}
else {
$value = null;
}
}
// Update
if ( ! is_null( $value ) ) {
update_post_meta( $menu_item_db_id, $key, $value );
}
else {
delete_post_meta( $menu_item_db_id, $key );
}
}
}
public static function _fields( $id, $item, $depth, $args ) {
?>
<div class="um-nav-edit">
<div class="clear"></div>
<div class="um-nav-edit-h2">UltimateMember Menu Settings</div>
<?php
foreach ( self::$fields as $_key => $label ) :
$key = sprintf( 'menu-item-%s', $_key );
$id = sprintf( 'edit-%s-%s', $key, $item->ID );
$name = sprintf( '%s[%s]', $key, $item->ID );
$value = get_post_meta( $item->ID, $key, true );
$role_name = sprintf( '%s[%s][]', $key, $item->ID );
$class = sprintf( 'field-%s', $_key );
?>
<?php if ( $_key == 'um_nav_public' ) { ?>
<div class="description-wide um-nav-mode">
<span class="description"><?php _e( "Who can see this menu link?"); ?></span><br />
<p class="description">
<label><input type="radio" name="<?php echo $name; ?>" value="0" <?php if (!isset($value) || $value == '') echo 'checked="checked"'; ?> /> Everyone</label>&nbsp;&nbsp;
<label><input type="radio" name="<?php echo $name; ?>" value="1" <?php checked(1, $value); ?> /> Logged Out Users</label>&nbsp;&nbsp;
<label><input type="radio" name="<?php echo $name; ?>" value="2" <?php checked(2, $value); ?> /> Logged In Users</label>&nbsp;&nbsp;
</p>
</div>
<?php } ?>
<?php if ( $_key == 'um_nav_roles' ) { ?>
<?php $role_value = get_post_meta( $item->ID, $_key , true ); ?>
<div class="description-wide um-nav-roles">
<span class="description"><?php _e( "Select the member roles that can see this link"); ?></span><br />
<p class="description">
<?php foreach( UM()->roles()->get_roles() as $role_id => $role) { ?>
<label><input type="checkbox" name="<?php echo $role_name; ?>" value="<?php echo $role_id; ?>" <?php if ( ( is_array($value) && in_array($role_id, $value ) ) || ( isset($value) && $role_id == $value ) ) echo 'checked="checked"'; ?> /> <?php echo $role; ?></label>&nbsp;&nbsp;
<?php } ?>
</p>
</div>
<?php } ?>
<?php
endforeach;
?>
</div>
<?php
}
public static function _columns( $columns ) {
$columns = array_merge( $columns, self::$fields );
return $columns;
}
}
UM_Menu_Item_Custom_Fields_Editor::init();