Massive application
-
I have a website with more than 300 pages that I want to protect.
Is there any mass application system?
If it does not exist, can you tell me some SQL code to do it through the db?
Thank you!
-
Hi @elnoi,
Thanks for reaching out Members Support Team!
We don’t have such an option like that in Members plugin.
Regards,
Can you tell me some SQL code to do it through the database with phpMyAdmin?
Thank you!
- This reply was modified 4 months, 2 weeks ago by elnoi.
The easiest way to add protection for multiple pages is to install Code Snippets plugin, add and adjust the code below and run it once (this plugin has special option to run code once without any hook):
$pages = array(1297, 14); // The list of pages IDs that need to be protected
foreach($pages as $page) {
update_post_meta($page, '_members_access_role', 'administrator'); // Replace administrator to different role
}Regards,
Thank you very much, I will try it and tell you
Hello Omar,
Until now I haven’t had time to try your solution.
I have already installed your code with Snippets and I have replaced ‘administrator’ with a new role created, to activate it on all pages.
I have activated the code.
And nothing happens. I don’t know how to run it or where to run it from.
I would appreciate any help on this.
Thanks!
Note: Because I do not master the English language, I use Google Translate, both to write and to read, so I apologize if, for this reason, I have not understood your explanation well.
Sorry! I have already found how to execute a code with Code Snippets
Still, it doesn’t work for me.
Surely I do something wrong.
I will continue experimenting
Thanks and sorryIt doesn’t work, I tried 10 times
$pages = array(1297, 14); // The list of pages IDs that need to be protected
foreach($pages as $page) {
update_post_meta($page, '_members_access_role', 'user_nivel_1'); // Replace administrator to different role
}Seeing that it didn’t work, I also tried it with a proposed code by IA ChatGPT
function assign_roles_to_pages() {
// Llista d'IDs de les pàgines a protegir
$pages = array(1297, 14); // Afegeix aquí els IDs de les pàgines que vols protegir
// El rol que vols assignar (modifica'l segons necessitis)
$roles = array('user_nivel_1'); // Afegeix aquí els rols que vols assignar
foreach($pages as $page) {
// Comprova si la pàgina existeix
if (get_post($page)) {
// Obtenir els rols actuals
$current_roles = get_post_meta($page, '_members_access_role', true);
if (!is_array($current_roles)) {
$current_roles = array();
}
// Afegir els rols nous als existents
foreach ($roles as $role) {
if (!in_array($role, $current_roles)) {
$current_roles[] = $role;
}
}
// Actualitza la metadada de la pàgina per assignar-li els rols
update_post_meta($page, '_members_access_role', $current_roles);
}
}
}
// Executa la funció una vegada
assign_roles_to_pages();IA GPT has also proposed a solution using SQL
(“If the code does not work, you can try fer-ho directly to the database with an SQL query.”)
But at the moment I don’t dare to tryUPDATE wp_postmeta
SET meta_value = 'a:1:{s:13:"administrator";b:1;}'
WHERE meta_key = '_members_access_role' AND post_id IN (1297, 14);GPT points me to review the code to make sure the _members_access_role key is correct. But I don’t know how to do it.
Anyway, I’m sorry for the inconvenience, but it would have to be something simpler, which I encourage you to implement in the plugin.Regards
- This reply was modified 4 months, 1 week ago by elnoi.
@elnoi I just tried to test code from my end it works. Please try to do SQL query but please make sure to back up database.
Regards,
It hasn’t worked for me either
I’m probably doing something wrong, although I’ve tried everything.
I have already wasted more time on proofs than perhaps what it would have taken to point out the 300 pages one by one.
In the end I will have no choice but to entertain myself by doing it manually.I encourage you to implement this massive application option.
If it existed, in cases like mine, it is easier to apply it to all the pages and then manually modify the few that vary.Maybe I’ll get by using a competitor’s plugin that does have a massive application system, even though I liked yours better.
Thank you for your patience and help even though it didn’t work in the end.
Regards,@elnoi May I ask did you applied that on custom post type or pages?
Regards,
I do not understand very well your question.
In any case, as I explained from the beginning, the idea was to apply the visibility limitation, according to one or two user roles created, on many pages or posts at once.
But I thought this had already been clear from the first consultation contact.
I apologize if I have not expressed myself well or if the translation has not been adequate.
In any case, for some strange reason, perhaps because I haven’t been able to explain myself well, none of the proposals have worked. I have tried them all.
Although it would be nice if this option were a little easier to do
I insist! I encourage you to implement this option in new versions, since there are other plugins, which do more or less the same as yours, and already have this capability implemented. For some reason it will be
Thanks to the lack of working solutions, we can close the topic.
Regards,
I will address that to dev team so they can check your request.
Regards,
- You must be logged in to reply to this topic.