Forum Replies Created

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter tfouchet

    (@tfouchet)

    Hi, sorry for the delay, I had to go to school for a week.

    Thanks for the information about add_filter().

    About the wp_nav_menu, that is why I enter know my wp_nav_menu(array('menu'=>'Menu name'));At the beginning it was taking a default menu and not mine.

    Also thank you for the example.

    My bad, I didn’t know about the priority.

    I’ll try to make some research about global values and the function you gave me. So, from what you told me, I should keep my first example, using add_filter() instead of apply_filters() , and fix it/upgrade it ^^

    I’ll try to do it and let you know if I succeded or not

    Thread Starter tfouchet

    (@tfouchet)

    Oh okay I understand a little bit better then. I’ll ask some questions about some ways I tried.

    1. I’ve read the documentation with some researches my first try was this:
    function mymenu($items, $id) {
       foreach($items as $item) {
           if($item->ID == $id) {
               unset($item);
           }
       }
    }
    add_filter('wp_nav_menu_objects', 'mymenu', wp_nav_menu(array('menu'=>'Menu name')), 4);
    

    I don’t think $item->ID is correct and I don’t know either how to call this from my condition in an other function, so here is my question 2.

    2. Can I call the add_filter() hook inside a function? Like this, and call my menu function in my question 1.

    function myfunction() {
        if(mycondition) {
           add_filter('wp_nav_menu_objects', 'mymenu', wp_nav_menu(array('menu'=>'Menu name')) 4); 
        }
    }

    3. Or maybe I should call the apply_filter() instead of add_filter() hook, like I did like this, but I don’t know if $sorted_menu_items is empty at the beginning (from the documentation) :

    function myfunction() {
       $sorted_menu_items = "";
       if(mycondition){
          $id = 4;
       } else {
          $id = 5; //For example
       }
       $param = wp_nav_menu(array('menu'=>'Menu name'));
       $sorted_menu_items = apply_filters('wp_nav_menu_objects', $sorted_menu_items, $param);
       
       foreach($sorted_menu_items as $item) {
           if($item->ID == $id) {
              unset($item);
           }
       }
    }

    I call myfunction() from an other one.

    About the results, for the first one, I have an error “Object of class stdClass could not be converted to int” at if($item->ID == $id) so I really think it isn’t correct.

    When I call apply_filters() in my third code, it prints the array on the webpage, so it si good for tests but not for the final result. And I got an error telling “Invalid argument supplied for foreach()” at foreach($sorted_menu_items as $item)

    Can you tell me which one is the best and help me correcting them?

    Thread Starter tfouchet

    (@tfouchet)

    Thanks for your reply, I forgot to mention that I already have a child-theme and i want to adapt the menu in my functions.php (inside my child-theme).

    From what I see on the documentation , I can use $mypost = get_post(5959) to know the item I want to remove and use the get_permalink filter. But the only examples I have are to add a new item (with $item .= '<li>...</li> ) so I wonder how to delete the item I want from the string of items, which is “easier” as you said. Also, my menu actually includes all my possible items.

    • This reply was modified 3 years, 3 months ago by tfouchet.
    Thread Starter tfouchet

    (@tfouchet)

    Thanks, it works. For the people who will wonder, add this to redirect to your site url:

    <script>
    window.location.href = "<?php echo site_url(); ?>";
    </script> 
    Thread Starter tfouchet

    (@tfouchet)

    Oh okay, I’ll try to do it in Javascript then

    • This reply was modified 3 years, 5 months ago by tfouchet.
    Thread Starter tfouchet

    (@tfouchet)

    Hi, to answer, I am modifying my child theme from the beginning.

    About “my own unique action”, you said that I should not modify the admin files, so I can write “add_action”, but I was asking if I could add a “do_action” with my action as parameter in the admin file. Also, you said that “admin-post.php is where the action is created and applied or not” so I was wondering how my action was created if I only write “add_action”. But maybe it is created automatically by writing add_action.

    From what you said about the way to choice for submission, since i don’t succeed to understand how this works, I just gave up this morning and did it in all php. And now it works.

    Thanks for the help you gave me, but i think I won’t try again ajax.

    Thread Starter tfouchet

    (@tfouchet)

    Hi, sorry for the delay. Thanks for your explanation. I have a few new questions. If I pass my “own unique action”, where do I create it? You said I should never attempt to modify admin_post.php, so is it in functions.php?

    Also, the “do_action(“admin_post{$my_action}”);” is called in functions.php but $my_action is in admin_post right? Does my own action already exist? (If I can’t add a new one)

    But articles I’ve read don’t mention where I have to add code and this is frustrating… They are talking about a lot of files but say “add this” and that’s it. That is what I want to understand. I have my functions coded, but I don’t understand how to make them work

    Thread Starter tfouchet

    (@tfouchet)

    I’ve read the article, but I still don’t understand where I have to write the add_action(). Is it in my theme functions.php (in which I have created my form) or in admin_post.php?

    I understand that I have to add the admin-post url in the action of the form and the hidden input, but there is no bcw_dyno action in the admin-post.php.

    Finally, I don’t understand the purpose of wp_enqueue_script.

    By the way, I won’t be able to work on this project next week, so sorry if I can’t reply, I won’t be able to use the advices you’ll give me.

    Thread Starter tfouchet

    (@tfouchet)

    Thanks for your reply. I don’t understand clearly what you expect me to do. Do I have to redirect my form to one of those files (admin-ajax.php or admin-post) in the action=””?

    Then, the ajax query I added in my template, do I have to cut and paste it in the admin file (admin-ajax.php or admin-post), and link it to the template with a shortcode?

    Also what do you mean by “action query string”? Are you talking about an “add_action”? Where does it have to be? In functions.php or in admin file?

    By the way, which file do I have to choose between admin-ajax and admin-post?

    Thread Starter tfouchet

    (@tfouchet)

    Oh I get it! Thank you!!

    Thread Starter tfouchet

    (@tfouchet)

    @alanfuller Oh my mistake, I thought it was impossible when you said “unrealistic expectation”.
    I’ll try to find out what is a hook and how it works because it may be the first time I hear about it, because as I said, I’m a wordpress beginner…
    I’ll ask to the Forminator support team, they will know what is possible or not. But if it’s possible to modify the database’s requests, it would be easier.

    @alanfuller @bcworkz Thank you so much for your help and your time, both of you. It really helped me to understand better how WordPress is managed. I hope you’ll have a nice day ^^

    • This reply was modified 3 years, 6 months ago by tfouchet.
    Thread Starter tfouchet

    (@tfouchet)

    Thanks @alanfuller ! So it is impossible to do it with Forminator and any existing plugins as no plugis do this. Except if I code all of it.
    I know some plugins create customer tables, but we wanted to custom it haha.
    Well, I’ll talk to my boss about the information you gave me and we will make a decision.

    Thread Starter tfouchet

    (@tfouchet)

    @alanfuller Thanks, I will explain what I have done and what I have to do.
    I used the Forminator plugin to create the forms for the registration and the login. It works and I don’t have any issue with this plugin instead the fact that the users are saved as wp_users. But my boss said that the access should be prohibited for non admin users and that we should use a table for the wordpress users and a separated one for the customers. Thus, I want to know if there is a way or a plugin which would help us to do it.

    Also @bcworkz I asked my boss again, he told me that if customers have access to the dashboard, they can (if they are good in computing) cause security breaches (get IP addresses, mail addresses,… ), even if they are user level 0. I think that if they can’t have access to wp-admin, it’s all good, but my boss thinks that if they are not managed as wordpress users, it’s better.

    If it was just up to me, I would just block the access to wp-admin as you told me, or even create the whole website in PHP (not with wordpress lol), but the website was already created with WordPress so i have to adapt. It’s mainly because I was never introduced to wordpress and because as a developer, I don’t understand how it works haha. Also, I don’t find the database requests which is really confusing, because I would have added the customer in the customer table with a basic request

    Hope my problem is clearer ^^

    Thread Starter tfouchet

    (@tfouchet)

    @bcworkz Thanks for all of these information. I already have the customers’s table but it isn’t the same schema as wp_user. So I will change the schema. But if I submit the form, how will WordPress understant that I want to save the new user as a customer and not a wp user?

    Thread Starter tfouchet

    (@tfouchet)

    But this isn’t what I wanted to do initially. I still don’t know how to link the new registrations to the new table. Which backend file do i have to modify (there are so much files containing “wp_user” types, do I have to modify them all)?

Viewing 15 replies - 1 through 15 (of 20 total)