Jump to content

maxxd

Gurus
  • Content Count

    955
  • Joined

  • Last visited

  • Days Won

    24

Everything posted by maxxd

  1. Drupal works on the idea of hooks - predefined actions that fire at certain times in the execution of the application and will run any functions or object methods that have been assigned to that hook. Think mini state-machine, kinda. See here for more information, and here for a list of native hooks. I haven't dug too much into Drupal, honestly (I looked into it as a WordPress replacement at my previous job, but decided the admin area would be too difficult for our clients to work with), but once I got the list of available hooks things got much, much easier to deal with. Like any framework or CMS, there's a lot of "magic" that happens. It's kind of a pain and a bit difficult at first because - well yeah, you're absolutely right - a lot of it isn't terribly well documented if it's documented at all. However if you don't want to build the thing from scratch you're gonna have to deal with that. As far as I know, using a framework like Laravel or Symfony isn't going to be all that different with regard to this kind of thing - they're all dialects of PHP, and each has their own idiosyncrasies. Now that having been said, if what you've described is the full extent of what you're looking to do I'd be rather surprised if there weren't plugins available in the Drupal ecosystem that can do what you want without having to code at all. Maybe some custom JS or CSS just to personalize things but the heavy lifting should be taken care of out of the box.
  2. Honestly, given the light specs you've described I think a framework would probably do most of the work for you. If you're wanting to learn, do it from scratch - what you've described is not tough to do (it is, however, tough to do right - which makes it a good learning experience). If it's a work thing where you're on a deadline but you've got free reign, look at some frameworks. Heck, what you've described can be done in WordPress with little to no coding.
  3. It looks like your validation script makes zero sense, but it's hard to tell without braces and/or correct indentation. But it certainly looks like the first thing you do is attempt to assign $_POST['account'] to $acct_subject if and only if $_POST['account'] is empty.
  4. Your while() criteria is incorrect and unnecessary. I haven't tested this code, but give it a shot: $acceptedStates = [ 'Feasibility', 'Measure Up', 'Model Drawing', 'Concept Design', 'Developed Design', 'Resource Consent', 'Construction Documentation', ]; $xml = simplexml_load_string($response); $xml = usort($xml, function($a, $b){ return $a['job_due'] <=> $b['job_due']; }); foreach($xml->Jobs->Job as $item) { if(!in_array((string)$item->State, $acceptedStates)){ continue; } $projects[] = [ 'job_no' => (string)$item->ID, 'job_name' => (string)$item->Name, 'job_due' => date('d/m/Y', strtotime($item->DueDate)), 'job_status' => (string)$item->State, 'job_staff' => (string)$item->Assigned->Staff->Name, ]; }
  5. All that having been said, if you're using $_POST input in a WordPress environment (which obviously I know you are), use some kind of safety features. I'd recommend at least using a WordPress nonce in the form output and data validation routines, and use the wpdb::prepare() method on the query. It's not a prepared statement exactly, but it is a little more responsible than just blindly trusting user-submitted data, especially if you're expanding your user base as you said you were in one of the other threads.
  6. Either of these functions will do what you want, and without you having to recreate the wheel.
  7. Don't let my bad mood scare you off - most people around here are very helpful and nice. Having said that, one of the things that's going to help you learn how to code is to try things. The code you've already seen in this thread uses class-based selectors and dynamic ID and class assignment. So, if you extrapolate the two, you can use the dynamic class/ID assignment you've seen with the appropriate selector method. If you try it and it doesn't work out, then post the code you've tried and we can help you figure out why it didn't work; the important part is to show the work you've done.
  8. It's not. Here. Yes. Here. Admittedly, I'm asking you to think a little when it comes to some of it, but ... really? Beyond that, Barand has been his typical self and gone above and beyond the call of duty to answer your questions in no uncertain terms and with concrete code examples; yet there are more requests to simply do it for you.
  9. I would use grid. Using the data-pos="n" attribute selector in CSS and JS you change the color as you want. You could also just use the IDs in the linked fiddle if that's easier. You could also use the nth-of-type() selector in CSS to cut down on the typing if you want.
  10. Give them different attributes as you create them. What does your code look like so far?
  11. Use get_home_path(). require_once(get_home_path().'wp-admin/includes/class-walker-nav-menu-edit.php');
  12. Try esc_attr() or get_post_field('post_title', $post, 'display')
  13. It looks like you should urlencode($subterms->name). What CMS are you using - knowing this might help you get more specific information about your problem.
  14. There is a way to do both these things. Reading the manual is a great place to start.
  15. This is not how you do a prepared statement. You're still injecting the variable directly into the SQL string. Check the manual for the proper way to use prepare() (note that the link is for PDO, but the concept is the same for mysqli.
  16. There's a part of me that thinks they're developing future PHP specifically to make the kids think they're programming in JavaScript... I mean, I actually really like fat arrow functions in JS, but every time I see an example of it in PHP I have to pause a second and readjust my brain.
  17. Given the requirements from your company, I'd definitely argue that you're not an idiot. There are times when you have to just do what you've been asked to do, no questions. And yeah, if there's a chance that you'll be moving to a different CMS, extracting specific data from the posts table is difficult at best.
  18. Ah - OK. You can still use the WordPress WP_Query object (global $wpdb) to interact with the database, you'll just have to supply the table names yourself. Also, routing should still work as expected - if the correct rule is inserted in the rules array, you should be able to visit /kudos/JFMGTTQ5 and use get_query_var() to return 'JFMGTTQ5'. As far as an archive listing goes, I think you'll have to that yourself. Not trying to be nosy or pry, but is there a reason it's not set up as a custom post type?
  19. Also, I'm assuming quite a few things about your project that may not be true. I'm assuming, for instance, that kudos is a custom post type and you're trying to show both an archive listing of kudoses and single kudos records both. I'm also assuming that you're not wanting to show a kudos specified by URL parameter on a random page (for instance, here's 1 kudos record on the 'about us' page!). Each of these assumptions could very well change the overall approach; and even outside of all that, dealing with routing in WordPress is a convoluted and weird rabbit hole on it's own...
  20. What parse error is that throwing?
  21. It looks like your rule is slightly malformed. As I said earlier, I've found the add_rewrite_rule() function to be a bit fiddly - I try to use the 'rewrite_rules_array' filter instead. Try this: add_filter('add_rewrite_rules' ,'add_kudoskey_rule'); function add_kudoskey_rule(array $rules){ $new = [ 'kudos/([^/]+)/?$' => 'index.php?pagename=kudos&kudokey=$matches[1]', ]; $rules = array_merge($rules, $new); return $rules; } Now, with this in place you should be able to (after you've gone to the Permalinks page and clicked 'Save' to clear the rewrite cache) go to 'http://127.0.0.1/kudos/JFMGTTQ5' and it should show that specific kudos. If you want to get the kudos key referenced in the URL, use get_query_var('kudoskey'). If you want to show an archive listing of all kudos records, make sure that 'has_archive' is set to true in the arguments array of your custom post type registration call, then go to 'http://127.0.0.1/kudos' and you should see the listing. The whole point of adding a rewrite rule is to enable pretty URLs and to not have to use '?variableName=variableValue' because it's easier for the user and better for SEO.
  22. Look at the 'query_vars' and 'rewrite_rules_array' filter hooks as well - I've had varying degrees of success using either the add_rewrite_rules() function vs. just brute forcing the rewrite_rules_array array via those two hooks. I wish I could remember why, but it's late and it's been a long freaking week, so that information got purged. If I remember tomorrow I'll let you know, but in the meantime those two hooks are another way to go about skinning this particular cat that might be a bit easier to follow. Rewrites and routing can get confusing.
  23. Of course it won't work - you're not passing 'urlid' in this case. You're passing 'p'. Did you follow the link I put in the first post to the codex rewrite rules page? I think I'm still not getting what you're asking - even using post name as the permalink value in WP you can use URL parameters like normal. Just output the permalink, then append URL-encoded key/value pairs, then use them in $_GET.
  24. I'm confused by your question. In a URL, '?xx' is the first variable passed via GET, '&xx' is any of any number of variables passed in the URL after the first. So your desire to change '?urlid=abc123' to '&urlid=abc123' is solved by adding a variable before the urlid. What is the value of your permalink option in the Admin > Settings > Permalinks? If you're set to 'Post name' there are a few different things you can do. Obviously you can grab $_GET['urlid'] using an early-running hook and go if it's anywhere in the URL string. However, if you're saying that WordPress is removing the '?urlid=' part, that's a routing issue. You can set up routing in WP using the WordPress rewrite rules which will give you something along the lines of 'http://url.com/kudos/abc123' or 'http://url.com/urlid/abc123' depending on how it's all set up.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.