reduxframework / redux-framework

Redux is a simple, truly extensible options framework for WordPress themes and plugins!
http://redux.io
Other
1.73k stars 582 forks source link

flexibility of $opt_name? #3655

Closed prolifixs closed 3 years ago

prolifixs commented 5 years ago

hello good team of Reduxframework, i have a problem not so personal but perhaps a quick guidance would be appreciated.

when you give the $opt_name a data as it's settings name say ($opt_name = "settings"), it saves into the database or ($opt_name=1) everything works fine without issue. i have user id's coming from a url like admin.php?page=fego-edu-search-result&user_id=2. but when i do this - ($opt_name = $_GET['user_id']) which is also a int value, i get error saying "There was a problem with your action. Please try again or reload the page." but the user ID still stores itself and part of its options in the database but does not save anything or rather the values are sortof not completely saved, so i can't retrieve any data. is there something you can point out that is preventing me from saving multiple instances of option for each users? Because it only accepts hardcoded variables

dovy commented 5 years ago

Redux is built for a single entry site-wide. If you want to do user-specific values you have to prefix your opt_name with the username or user ID. That's what we do for the builder.

MY_OPT_NAME_[USERID]

Then you can separate.

Later we will be adding in User Meta fo redux, allowing user-specific panels, but that's not ready for the masses as of yet.

prolifixs commented 5 years ago

@dovy thank you for responding. i really need to get this functionality but i am a bit lost by your response. just to be in the same page as you. you mean to prefix like this $optname = "example"[USERID]? doing this still puts it in the database but dosen't save. you can drop a hint and i would do the research thanks.

dovy commented 5 years ago

Let's take a step back, give me more details, please.

prolifixs commented 5 years ago

@dovy of course, once again i appreciate the time you take to view this despite your busy schedule. i am creating a plugin for keeping and updating users, it's also on github if you prefer to try the plugin, here. the plugin is a list table containing users, each user has it's 'edit data' button that will redirect you to the redux sub-menu(which i placed as part of my plugin) attaching the id's along in its url. the code that does the redirection can be found in the plugin under inc/admin/class-user-list-table.php under the function 'column_user_login'. but basically is something like this

`$query_args_edit_data2 = array(
        'page'      =>  "fego-edu-search-result",
        'user_id'       => absint( $item['ID']),

    );
    $edit_data_link = esc_url( add_query_arg( $query_args_edit_data2, $admin_page_url ) );      
    $actions['edit_data'] = '<a href="' . $edit_data_link . '">' . __( 'Edit Data', $this- >plugin_text_domain ) . '</a>';`

the page is for redux framework and i appended its id. under inc/admin/views/config.php is where i placed the redux config file. this is how i got the incoming url: $user_data = $_GET['user_id']; if (isset($_GET['user_id'])) { $opt_name = "fego_sample_[$user_data]"; } and then my args are like this $args = array( 'opt_name' => $opt_name, 'menu_type' => 'submenu', 'allow_sub_menu' => true, 'menu_title' => esc_html__('Search Result', $textdomain), 'page_title'=> esc_html__('UserSearch', $textdomain) , 'global_variable' => $opt_name, 'page_priority' => null, 'page_parent' => 'fego-edu', 'page_permissions' => 'manage_options', 'menu_icon' => '', 'last_tab' => '', 'page_icon' => 'icon-themes', 'page_slug' => 'fego-edu-search-result', 'save_defaults' => true, 'default_show' => false, 'default_mark' => '', 'show_import_export' => true ); everything works fine when i manually hardcode the same thing as this: $opt_name="fego_sample_[1]"it saves fine. but when i change it back to the later i can still see but the $opt_name and its transient but saving it gives this error "There was a problem with your action. Please try again or reload the page." which is kinda weird and hard to find the fault. you can check my file if you have time and point something out so i can work his thing out i really love redux. my main file is just inc/admin/class-user-list-table.php and inc/admin/views/config.php everthing else are just wordpress plugin boiler-plates. thanks again for your attention.