• Resolved Docwatsons

    (@docwatsons)


    I am attempting to build a set of “extra information” forms for my WP users. I get basic WP registration and some additional demographics from WooCommerce, but I need more bits of information about the users. I created a table “CompanyContact” from which I want to make a page showing and allow editing the information only pertaining to the logged-in user. I was able to get the WP user_login to populate a page I’ve set up in the Data Designer, with $$USER$$ as the default value. I can’t seem to get the WHERE clause correct, however. If I enter user_login=$$user$$ to the WHERE clause field on the page, I get no records. If I leave it blank, I see all the records I put in to test. If I use text in quotes of an actual user login value, in place of the $$USER$$, it produces the filtered records. Any suggestions how to get this WHERE clause correct would be much appreciated. Also, whether and what kind of link there should be between wp_users and CompanyContact.

    I would have preferred pulling in the wp_users ID instead of the user_login value, but I can work with it.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    It looks like your where clause is defined correctly. So this might be a bug.

    I changed to $$USER$$ value replacement code and uploaded a small patch which you can download from here: https://wpdataaccess.com/wp-content/uploads/2019/10/patch.zip

    The patch includes two files. Please copy these files into the following folders:
    WPDP.php >>> WPDataProjects
    WPDP_Simple_Form.php >>> WPDataProjects/Simple_Form

    Please let me know if this solves your problem.

    Best regards,
    Peter

    Thread Starter Docwatsons

    (@docwatsons)

    The good news is that I have achieved the filtering desired on one of the pages in question. Thank you very much, I think this will allow me to move forward. Strangely, I have another page which I think is identical, I intend to use for display of all records for admins and editors, on which the filter does not seem to work properly when I test it with myfield=$$USER$$. That still returns empty set. I’ll fiddle with it to see what I’m missing. Am I correct that $$USER$$ returns user_login from wp_users?

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    Good to hear the filtering works. Did you use the patch I provided? I like to know to decide whether I should add it to the plugin code or not.

    >>> Strangely, I have another page … on which the filter does not seem to work…
    Are the column value and the user login equal? What happens if you add the use login hard coded to the where clause?

    >>> Am I correct that $$USER$$ returns user_login from wp_users?
    That’s correct!

    Best regards,
    Peter

    Thread Starter Docwatsons

    (@docwatsons)

    Good to hear the filtering works. Did you use the patch I provided? I like to know to decide whether I should add it to the plugin code or not.
    >>>>I did use the patch, and I’m pretty certain that made the difference. My only reservation is saying so is that the difference between the two pages confused me, so at first I didn’t think it had been successful. I played with the WP Roles setting a bit on one of the pages, before I noticed there had been success.

    >>> Strangely, I have another page … on which the filter does not seem to work…
    Are the column value and the user login equal? What happens if you add the use login hard coded to the where clause?
    >>>Using the hard code on that page does return the correctly filtered results. I’ve matched the data types. I’ve tried all combinations of Roles which are eligible. There must be a setting I’m not noticing which is different. I’ll keep pegging away, let you know if I find it. I’m functional with the pages as they are, I believe, so thank you very much.

    >>> Am I correct that $$USER$$ returns user_login from wp_users?
    That’s correct!
    >>>>I would generally link my tables with by inclusion of the parent table’s primary key in the child table’s second column. I’m not clear how to get the parent table into the child’s.

    Now to master the table structure. Your videos are quite fine but I get a bit strained trying to conceptualize my data model. I’m curious, where do your graphic representations of the sample data come from? Also, where can I find the files for the school project?

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    Yesterday I provided a patch. One of the files in the patch is named WPDP.php. To get a better idea of what’s going wrong in the page that does not filter correctly, you could add the following debug lines after line 344 in file WPDP.php:
    var_dump($current_user);
    var_dump($user_login);

    Can you please let me know what you get?

    You can find the school data project here:
    https://wpdataaccess.com/wp-content/uploads/2019/10/sas.zip

    Below your plugin folder is a folder tutorials/wpda_sas. It contains all other files for this project, including a data model.

    The school demo uses a lookup. You can define a lookup in Manage Table Options (the lookup goes into the child table). A lookup is in fact the opposit of a one to many relationship. If you add a lookup to your child table, the plugin generates a listbox from the parent table. You can select which column you want to appear in Manage Table Options as well.

    I have not yet created a tutorial to explain lookups. Guess that might be helpful. I’ll see what I can do…

    Best regards,
    Peter

    Thread Starter Docwatsons

    (@docwatsons)

    With that code inserted, I get about 20 lines of info, but it includes the correct login data for the current user (me).

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Can you add one more line just before the switch statement:
    var_dump($where_clause);

    That should give you the where clause used to filter

    Thread Starter Docwatsons

    (@docwatsons)

    I’m not clear where I’m putting the code. I’ve moved things around a bit and am not clear what was on line 344 before I started messing with it. Meanwhile, the pages in question seem to be working as expected.

    Thread Starter Docwatsons

    (@docwatsons)

    Now that the Data Project appears to provide appropriate forms for the client to fill out, (aside from a tab problem in a different thread) I realize I don’t know how I’m to “front end” this on my site. I looked at the Data Publisher and see no connection to the links and filtering we’ve worked out. I watched your tutorial again and understand I can use a View instead of a table to publish, but I’m not clear how I create a view to connect my employers and contacts, other than the WP interface.

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    You can use your Data Project in two ways:
    (1) In the WordPress dashboard
    (2) On your website

    (1) Your users need to have a WordPress account to work with your app. My preferred way to give users access to an app is by letting them work in the dashboard. If you are on https you have at least some basic security for free and users can use a theme that will be reflected in your app. Most important, you don’t need to do any CSS styling as this is already done for you.

    (2) You can add your Data Project to your website with short wpdadiehard. This is not the same as the Data Publisher. The Data Publisher is a read only list that does not allow any kind of updating. The Data Publisher uses shortcode wpdataaccess. Make sure you pick the right shortcode. With option 2 you have to create a menu yourself and add your pages to it one by one. You also have to do some CSS styling to make it work with your WordPress theme.

    You can find instructions for shortcode wpdadiehard here:
    https://wpdataaccess.com/docs/documentation/shortcodes/shortcode-wpdadiehard/

    And for styling your shortcode wpdadiehard here:
    https://wpdataaccess.com/docs/documentation/shortcodes/styling-wpdadiehard-pages/

    For what’s its worth… I would give my users access to the WordPress dashboard! It saves you a lot of time as you don’t need to do any CSS styling, the layout is consistant, you have some basic security and personally I think it gives your app a professional look and feel. The choice is yours.

    Best regards,
    Peter

    Thread Starter Docwatsons

    (@docwatsons)

    Thank you for this helpful summary. Despite reading much of it before, I didn’t realize how applicable it would be.
    I’ve now tried the wpdadiehard shortcode. The Project Page I “filtered” with $$USER$$ does not filter in this setting. Perhaps I need to learn more about creating views in mySQL to allow more options?
    I’ll have a go at setting up my clients to use the WP dashboard as you suggest. I had planned to do so for my staff.

    Thanks, Ben

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    >>> The Project Page I “filtered” with $$USER$$ does not filter in this setting.
    You are right! This is a bug. Sorry, I was not aware of it. I fixed it right away. In the next release it works. I still prefer to use the dashboard if possible, but at least you have a choice. I’m actually extending the SQL export. As soon as I’m finished I’ll upload the new release.

    While you are learning to work with the plugin, I’m learning to improve the documentation and code. Thank you for your feedback! It has proved to be very valuable.

    Best regards,
    Peter

    Thread Starter Docwatsons

    (@docwatsons)

    I’m glad to have contributed. I very much appreciate your efforts, as well. I’ve just identified a WooCommerce table that contains much of my Contacts information, so I need to rework my model. I’ll watch for the update and thank you for this fine work.
    BW

    Thread Starter Docwatsons

    (@docwatsons)

    I guess I’m not clear how to give users access to the dashboard. I’m not sure how to frame the question for searching. I understand roles. The only way I know to go in is via wp-admin for administrator roles.

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    Good you mentioned this! I realise now this might be an issue for other users as well. Interestingly, giving users access to the WordPress dashboard is much simpler than setting up a secure web page.

    I will dive into this subject and write some instructions on how to do this. I’ll come back to you as soon as possible…

    Best regards,
    Peter

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Filter with $$USER$$’ is closed to new replies.