Jump to content

maxxd

Gurus
  • Content Count

    1,006
  • Joined

  • Last visited

  • Days Won

    25

Everything posted by maxxd

  1. If you've got some time, you could use Docker or install WSL. Otherwise, you'll have to set up another version of your production server and blow things up there instead of the live site.
  2. // $id may or may not exist, doesn't matter for ($i = 0; $i <= 5; $i++) { if (isset($_REQUEST["element_id_$i"])) { // Now you're checking _any_ input for anything called element_id_{0-5} and assigning it to the session variable. // $id is still potentially undefined $_SESSION["element_id_$i"] = $_REQUEST["element_id_$i"]; // OK, so now $id is a string or integer or float or whatever (validate your input, please) $id = $_SESSION["element_id_$i"]; // $_SESSION['element_id'] is an array because you're using array_push array_push($_SESSION["element_id"], $id); } // And now $id is an array because you're overwriting the value you've already put in there // Also, at this point if $_REQUEST['element_id_{0-5}'] _isn't_ set, $_SESSION['element_id'] should // not exist and you'll get an error $id = $_SESSION["element_id"]; } So $id is an array. You can use variables as array keys, but the value of those variables has to be a string or integer - you can't use an array as an index in another array.
  3. $cart_items[$id] = $quantity; and $cart_items = array($id => $quantity); are two very different things. What's the value of $id?
  4. You can use variables as the index when you create an associative array. Considering that, and as you already have the variables that contain the id and quantity, the solution should be pretty obvious...
  5. Comment when and where it's necessary. When it comes to methods, I'm a fan of always writing documentation but at least document the parameters, regardless the scope of the method - I've heard people say it's only important to document the public API of a class. This is utter bullshit. However, when it comes to initial documentation for a class if it does something weird, then yeah - document that sucker. For instance, your Formatter class seems simple enough - it formats a thing. However, if you're not using namespaces and your system formats both HTML and JSON, but Formatter only deals with JSON then document that. I'd argue you should use namespaces or rethink your class naming scheme, but sometimes you come into legacy code and have to do what you have to do.
  6. Yeah, I got nothin'. The only thing I know about cars is where the gas goes and where to take it when something sounds weird. Again, I know very little but serial numbers should be specific to each engine, correct? So that doesn't seem like an issue in any way. Wut? At any rate, I would think if you're trying to keep track of modifications to cars and car parts the best bet would be a car table, a parts table, and a modifications table with a compound foreign key of car_id and part_id. That _theoretically_ should give you a time-specific snapshot of parts and mods per car.
  7. I strongly recommend against that. As one who will drive a car until it falls apart completely, I can see a situation where a single car can could have multiple motors, the defining data of which could be repeated. [Disclaimer: I know nothing about cars or engines, so please don't take my example as a real-world situation] If my Honda Element has a Hemi when I buy it, but I drive it to the point that the hemi dies and I put a V8 in there, cool with the unique limiter. However, if I then drive the same Element until the V8 dies and I decide to put different hemi in there, well then there's a problem. Play it safe for the future - Barand's junction table is the way to go; even if you don't use it as a many-to-many junction point right now, you may have to later.
  8. I'm sorry, but what? I'm not trying to be an ass, but take a breath, step back, and describe what you want to do one simple step at a time. Write out the pseudo-code, then post it here.
  9. And thankfully, those versions are mostly dead at this point. Or so I choose to believe, anyway...
  10. The two chunks of code you've posted are completely unrelated. I don't know what mf_get_option('login_reg_popup') should or could return, but if it's falsey it'll set the action parameter of your checkout button link to the login page. If it's truthy it'll set it to ... nothing, really. Your second chunk of code redirects everything to $_SERVER['HTTP_REFERRER'] (which I'm pretty sure is a massive security issue, not to mention the fact that it applies to everything). Then, later - assuming the code gets there after the ill-advised redirect - it sets up an action handler for template_redirect that again calls the wpse_131562_redirect() function on every page load. Assuming mf_get_option('login_reg_popup') returns false if the user is not logged in, I think what you want to do is replace the '#' in your first code chunk with wc_get_checkout_url().
  11. <td><?= $bitcoinPrice->dash->usd_24h_change ?>%</td> <td><?= $dashPrice->dash->usd_24h_change ?>%</td> <td><?= $netchainPrice->dash->usd_24h_change ?>%</td> <td><?= $pivxPrice->dash->usd_24h_change ?>%</td> Your markup is malformed - use this instead.
  12. OK - we don't know what playServerURL() or getURL() look like, so no idea what those are doing in the meantime. However, in my experience when you're dealing with AJAX you'll need to stop the actual click event from happening until you want it to. However, before we even consider that, there's a syntax error you should be seeing: $('.btn').click( function() startSound(); }); Note that there's no opening brace after the function() declaration, but there is a closing brace before the closing parenthesis. This alone should be breaking everything. Once that's fixed, I still think you'll need to block the submit until you've got done what you need done, so update like so: $('.btn').click( function(e){ e.preventDefault(); startSound(); });
  13. Just feel like this should be repeated (maybe some of my coworkers will happen across it).
  14. It's a longshot, but try flushing your rewrite rules. In WordPress admin, got to Settings > Permalinks and click 'Save'.
  15. You don't have a function named 'drop_2'. Check the documentation - the second parameter of add_action() is the function to be run. So instead of randomly having this: if (isset($_GET['func'])&& $_GET['func'] == 'drop_bl' ) { drop_bl($_GET['drop_var']); } in your functions file, change the 'action' parameter of your AJAX call to 'drop_bl'. Then don't expect to pass a parameter to the function, just check $_POST directly. Which brings up another point, you're checking $_GET but using jQuery's post() method, which is basically a shortcut for using jQuery's ajax() function with method $_POST.
  16. Few things here. I could be wrong, but I think it's too late to call the wp_enqueue_scripts hook after the template is loaded. In the JavaScript file, your AJAX url value is incorrectly formed - you're using `nova_ajax_url,ajax_url`. You need to use a period between the object and the property, not a comma. WordPress doesn't know what 'func' means as a parameter passed to the AJAX handlers - it's looking for 'action'. I don't have the slightest idea what `drop_var` is. You show a functions file, but there's no AJAX handling in what you've shown. WordPress looks for `wp_ajax_{whatever_your_action_value_is}` and `wp_ajax_nopriv_{whatever_your_action_value_is}` action hooks to handle AJAX functionality. If you're using setTimeout() to wait for a response to be returned, it's unnecessary - AJAX is asynchronous and the .done() or .fail() chained functions await the promise resolution.
  17. Describe "working" and "not working". I've just eaten and had a couple glasses of wine so I may be missing something glaring, but the code you've posted should work. Of course, that assumes your query returns more than one page of posts.
  18. In my experience, from both an API and UI-based perspective, MailChimp is much easier to use than Constant Contact. Just a personal opinion on the matter, but I will always lean towards MC over CC.
  19. Depending on what theme you're using, it's very possible that that exact code is duplicated across multiple templates, so you could be in the wrong file without knowing it. WordPress doesn't exactly require - or even in a lot of ways promote - good practices when it comes to PHP and coding for the web. And some of the Automattic plugins are the worst offenders (WooCommerce, I'm looking at you), so don't assume it's good just because it came from the same company as WP or it's got a lot of stars.
  20. Also, <%php is not the correct opening tag. Use <?php. However, sounds like requinix is right - you're in an admin or restricted area of the template. What's the file name and location you're working with?
  21. Because the database server is on the same machine as the web server. All the time, actually. If you feel strongly about using an IP address you can try http://127.0.0.1 and that should work - although honestly, it's GoDaddy so I can't guarantee it.
  22. OK - sorry. A little closer look at the question you're actually asking. first off, date's format 'h' is a 12-hour format with leading 0, so it won't read as '20'. And MySQL TIME type doesn't include AM/PM. Try changing the date format to 'H:i:s'.
  23. OK - technically, the open brace at // WHAT IS THIS FOR? matches the closing brace at // WHAT? and doesn't really do any harm programmatically (I think...), but wow is that hard to read.
×
×
  • 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.