lex713
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Custom Role Broken@bcworkz Doesn’t delete the roles. I don’t know what happened to create these broken rules.
function delete_role(){ $roles = wp_roles()->get_names(); foreach( $roles as $role ) { if ($role = 'test') { remove_role($role); } } } add_action('init', 'delete_role');
- This reply was modified 4 years, 1 month ago by lex713.
Forum: Developing with WordPress
In reply to: Custom Role Broken@bcworkz so translate_user_role is only called to echo the name. I don’t believe it does anything to the variable. But I’ll delete it and try. I’m also going to re write it as
add_role( $role, ( $name ), get_role ( 'restaurant_template' )->capabilities );
Forum: Developing with WordPress
In reply to: Custom Role Broken@bcworkz i figured out that if I create a form and have the restaurant name be something that has a space in it like “big boy” then it won’t work as a display name. If it is “bigboy” it will work. I don’t know why. But I tried to add the code below to get rid of spaces but still leaves me with a blank role name.
$name = str_replace(' ', '', $name);
Forum: Developing with WordPress
In reply to: Custom Role Broken@bcworkz So i got it working and deleted the roles I wanted. Then I went back edited the code a little and most of the time I get a role that has a display name but still sometimes when I use the code below I still get a blank display name. I am also unable to delete the new roles I made.
$role = get_post_meta( $post_id, 'registration_name', true ); $name = get_post_meta( $post_id, 'registration_name', true ); $name = ucfirst($name); $role .= '_role'; $role = lcfirst($role); add_role( $role, __( $name ), get_role ( 'restaurant_template' )->capabilities );
As before I solved the deleting of the old roles using
$roles = wp_roles()->get_names(); foreach( $roles as $role ) { if($role = 'role to delete') echo translate_user_role( $role ); remove_role($role); }
But I cant get it to work this time. The roles will not delete anymore. I have tried replacing remove_role($role) with remove_role(‘role to delete’) but it will not work. I have no idea what happened but all I called to create a role was add role.
Forum: Developing with WordPress
In reply to: Custom Role Broken@bcworkz so I should make a custom code that gets an array of all the roles finds the ones I want to delete and delete them thru custom code. Also the code above isn’t finished for each role or user it will be name manager, name sever, etc.
Forum: Developing with WordPress
In reply to: Post delete but goes to page saying it can’t deleteGot it working with this
function force_type_private($post) { if ($post ['post_status'] != 'trash') { if (!empty(get_field('recipe_name', $post->ID))) { $post['post_status'] = 'publish'; } } return $post; } add_action('wp_insert_post_data', 'force_type_private', 20);
Forum: Developing with WordPress
In reply to: Post delete but goes to page saying it can’t delete@bcworkz I came up with this but it isn’t working. I believe it doesn’t work because it is checking if it is in the trash but the problem is I need to check if it’s trying to go to the trash.
function force_type_private($post) { $post['post_status'] != 'trash' { $post['post_status'] = 'publish'; return $post; { } add_action('wp_insert_post_data', 'force_type_private', 20);
Forum: Developing with WordPress
In reply to: Post delete but goes to page saying it can’t delete@bcworkz so could this work I’m having a hard time finding info on hooks and what calls what so there might be some issues but I’m thinking
function force_type_private($post) { If (did_action(‘trash_post’) //if trying to trash post { } Else { if ($post[‘post_title’] = ‘ ‘ || ‘autodraft’ //check if title is empty or autodraft { } Else { $post['post_status'] = 'publish'; return $post; //if both both checks are false set stays to published } } } add_filter('wp_insert_post_data', 'force_type_private');
- This reply was modified 4 years, 2 months ago by lex713.
Forum: Developing with WordPress
In reply to: Deleting post if field is emptyfunction remove_if_empty ($post) { if ($post['post_title'] = 'autodraft') { wp_die('Post was not saved'); return $post; } } add_filter('wp_insert_post_data', 'remove_if_empty');
So I wrote this but every time I hit add new it goes to a page that says “Post was not saved.”
Forum: Developing with WordPress
In reply to: Post delete but goes to page saying it can’t delete@bcworkz @sterndata So my problem stems from custom code. I fix one thing get 5 more things I need to fix. The usual coding life. So it all starts with me wanting to hide the post editor with remove_post_type_support. When I do this I can no longer publish anything. Everything is saved as a draft. So I have this code running to force everything to be published.
function force_type_private($post) { $post['post_status'] = 'publish'; return $post; } add_filter('wp_insert_post_data', 'force_type_private');
The problem is when I try to trash something it calls the code above. My work around for that was this
add_action('wp_trash_post', 'force_trash'); function force_trash($postid) { wp_delete_post($postid); }
But when the line above trashes it redirects me to that page I stated earlier. So stevens answer won’t help unless there is a hook that plays after it goes to the trash but I don’t think it ever gets that far because of the code that calls when wp_insert_post_data. I don’t really care if things go to the trash or not. I just want it all to look smooth no error screens. Is there some hooks that I didn’t see earlier that I should be using instead? I feel like the code is all right I’m just calling them at wrong times.
Also thank you for all your help I know @bcworkz has helped me with almost every issue I have had.
Forum: Developing with WordPress
In reply to: Deleting post if field is empty@bcworkz how would I write a line of code that if the title equals auto draft delete it? I have it set up where if the field is empty it names it autodraft.
Forum: Developing with WordPress
In reply to: Green publish button won’t publish@bcworkz i believe I am the hosting account holder. I also believe I am hosting thru WordPress. I bought the business account.
Forum: Developing with WordPress
In reply to: Green publish button won’t publish@bcworkz I cant figure out how to change the function.php permission so I can edit it. If I do it thru firezilla I can’t access the theme folders. I tried using code snippet and it didn’t work.
Forum: Developing with WordPress
In reply to: Green publish button won’t publish@bcworkz I’m sorry I am fairly new to this so I paste that in the function.php. I can’t paste it there but I don’t want to get into being able to paste it and messing with the security. Until I know that’s the place to do it.
Forum: Developing with WordPress
In reply to: Green publish button won’t publish@bcworkz The title doesnt work either forgot to disable a code snippet before testing.