Best way to track down dependencies? (Wordpress + Woocommerce) - wordpress

I am wondering what the best ways are to track down dependencies (I think that is the best way to describe it) between several files. Here are the details.
Context: I am working on adding a plugin called WooCommerce Product Bundles to the online store that I am managing. The plugin takes several products and combines them onto one page with a short description for each product.
The Problem: When the plugin is pulling in the short description for each product it is also pulling in the contents of product-elements.php which has a "Find a Dealer" button inside of it. This big button is then repeated 4 times on the rendered page and looks terrible.
The Goal: Is to remove these buttons by removing the hook for "product-elements.php" from the plugin, since nothing in that file needs to be displayed on the rendered page.
However... I cannot for the life of me find any references to product-elements.php in the plugin files... which means it is probably referencing another product page template file, which is then referencing something else, which is then referencing "product-elements.php".
If you guys understand what I am saying here... what is the best way to trace the full path of these files so I can find the actual reference I am looking for (and kill it with fire)?
Additional details:
- product-elements.php is a file in my theme. It is a default Woocommerce file that has been copied over and modified (sort of like a child theme, but it is a child file).
- Something in the bundle plugin files is pulling product-elements.php into the rendered page, but it is not referenced directly.
- There has to be some middle step in between these directories where there is a trail of references, how do I find it?
- Tools I am using, OSX, Tower(GIT), Atom text editor

Related

Which is faster: loading images via repo, or loading via ACF/Media Library in WordPress?

I have two methods of loading images in my mind right now during WP Theme Development:
1 - I store an image in a folder within my repo, and load it as a background image, defining it statically in CSS/Inline CSS.
2 - I store an image in the WordPress Media Library, upload it to an Image Content field within Advanced Custom Fields, and then load the src using inline styles in the template.
Which of these is faster?
My mind is telling me #1 because I don't have to go and get the img url from the uploads folder as directed by ACF, which is stored in the database but equally I don't know WordPress that well, so I might be wrong.
Thanks
Two observations:
You write that this question comes up "during WP Theme Development", and
You're loading it "as a background image".
If the end-user of the theme won't be uploading their own image for that part of the theme, then #1, the "store in repo" method, is definitely the way to go. Simpler, too.
However, if this background image is expected to change from time to time, you might be smart to leverage Advanced Custom Fields and save yourself the boilerplate code of adding image-upload fields to WP.
This being the case, you can still encourage your theme's end-users to use some cache (to cut down on those db queries to reference the image) and/or image CDN (to improve the HTTP part of the image's journey) plugins in the WordPress plugin codex.

Using a Wordpress plugin feature elsewhere within theme files

I'm using the ultimate member online plugin, which shows members' online status.
When enabled to show on a user's UM profile page, it looks like this, for example:
When creating posts, it is common for data pertaining to the author to display somewhere within the post. For example:
What I'd like to accomplish is to have online status (shown in first image, above) also be displayed within this author data, shown within a post.
I've poked around in theme/plugin files, and I'm CLOSE!
I found where I need to edit, within the theme files (wp-content/themes/plum/inc/template-tags.php file)
I've narrowed the plugin files and content within them down, to what i believe would be the appropriate code to insert into theme files. Screenshots and copied [relevant] text can be found here:
Ive been playing around, reading the web, creating a post on the official wp forums (as well as searching within them), and this is the best I've got so far:
On the surface, it looks like the problem is solved. However, that user ("testAuthor1"), is offline (and the greenlight there in that very last imgur link displays the user as online).

Wordpress uses backed-up theme files instead of customized file. (solved by myself // little how-to)

I just wrote a long and detailed question and when I was about to submit it, I fixed the problem by myself. The problem did cost me about 5 hours and now I will just post this little explanation, so maybe it helps others and they will not feel as stupid as I do right now.
In my defense: I do not have that much experience with this system.
What was the Problem? When did it show up?
Before I change a file on the server, I always duplicate it and change the file name to originalFileName_yyyymmdd_hhmm.php (filename + date + time). I want to keep track of the changes, and when we launch the website, I wanted to do a local backup and then delete them from the server.
Let's say, in the folder of the active theme there is a file called home.php.
It is a template file, which means that you can select it as a template for a page when editing it in the backend of WordPress.
I duplicated it and called the new file home_20180301_2300.php.
Then I edited the home.php, but the changes were not displayed on the website.
I checked for any known cache issue, but that was not the problem. So I installed a debugging plugin (Template Debugger) to see which files are used by the server to create the website.
Wordpress used the home_20180301_2300.php instead of the home.php and I did not know why. When I deleted home_20180301_2300.php WordPress did NOT use home.php It just took the standard template instead.
What I think what happened
In the last moment before submitting this question I realized what happened:
In the process of working, there was a situation where I deleted the home.php and then edited the page in the backend. WordPress could not find the home.php, which was set as the template for this page. BUT it found home_20180301_2300.php and used it. (Because WordPress is smart [sometimes {not a joke}]). When home.php was back in its place, WordPress did not care. It looks like as long as there is no problem, WordPress does not search for other (or newer, or better suiting) files. It still used home_20180301_2300.php, because it worked. That's why my changes in home.php did not have any effect. home.php was ignored.
The Solution
I had to delete home_20180301_2300.php, open the page in edit mode and select home.php as the template again. WordPress did not find home_20180301_2300.php, "BUT HEY! There is home.php, my old friend, so I can use it", WordPress said and they happily lived together for the rest of their time.
Feel free to comment!
I am sure my explanation is quite simple and not showing the whole picture. If anyone knows better, I would be glad to hear it. Better knowledge of the problem and the way WordPress works can help me and others to better understand future issues.
Peace out,
Nils

WordPress - add Database driven tables

I'm just trying to move one of my old php sites to wordpress. As part of the site I have 'top tables' e.g. top 10 cars, listing their features etc. At the moment that all comes from a database and the HTML is generated from the data.
So if a car soon gets a hybrid engine I just check that in the database and my web site table updates to reflect that.
This all works fine. I just don't know where to start when trying to implement something like this in wordpress. I want to keep the WP header, footer, nav... and put my table in to the content area.
Someone recommended simply copying the current generated HTML in to a new post and editing the HTML when anything changes, this sounds like a quick solution but there must be a better way of doing this.
Ideally I would want to keep my current data input pages (and separate database) for all of this 'table data' and present the out put as a post.
If anyone can point me in the right direction (key words I should search for, a guide) that would be great.
Depending on your usecase, you'll usually want to use a static page template:
http://codex.wordpress.org/Page_Templates
Or shortcodes:
http://codex.wordpress.org/Shortcode_API

Find every instance of a CSS id/class across a whole site

Before making a CSS change that might possibly have unintended consequences, what's a good way to find where else on the whole site (not just this page) that id or class is used? (It doesn't have to be exhaustive, and semi-manual processes are ok, too.)
For a bit of context, it's a Joomla-based site with a lot of content, and I'm not yet familiar with most of it. The id in question has a two letter name, and I have no idea where else it might be used. I don't have direct access to the server for any grep-like approaches.
The only technique I can think of is using Stylish to make an obvious change to that one selector, and browsing the site for a bit to see where it pops up.
The easiest way would be a local grep, but since you don't have access to the server, try downloading it locally using wget:
wget -r -l --domains=http://yourdomain.com http://yourdomain.com
That'll recursively retrieve pages from your domain to an infinite depth, but only following links to pages within your domain.
Once it's on disk, do a local grep and you're golden.
I use unused-css.com for this sort of thing. You simply put in your webpage, and it will look through the whole site (incl. login) and give you the CSS that you actually are using.
I've found it to be 95% correct - but it only doesn't pick up on things like some CSS browser hacks and some errors (ie. the CSS only displays after an error), so it should work fine for this.
You could also check the original template (assuming the template is a commercial one) to see where the id perhaps should be (they usually lay everything out in their demo template), but unused-css won't tell you exactly where it is used, only if it is or not. For that, I'd start with a view-source -> find on the major pages, and then try other mentioned solutions.
Get the whole site's source tree into an IDE like NetBeans or Eclipse and then do a recursive search for id="theid" on the root folder.
If this is not possible, how are you updating the CSS?
Assuming you don't want to do the grep approach:
Is the ID in question appearing in the actual content area of the page, or in the 'surrounding' areas? If it seems like it's not part of the content, but rather appears in a template, you could search the template files for it. As you're updating the CSS, I'm going to assume you can at least get a hold of the template files. Many text editors/IDE's will let you do a 'global search'. I'd load the template files in TextMate (my texteditor of choice) and do a "search in project" for the particular ID.
That will at least give you a semblance of an idea of where in the site that ID shows up. No, it won't be every 'page', but you'll know what kind of page it appears on (which, with a CMS, is really what you're after).
If the ID in question appears in the content, that is, it was hand-entered by content creators, you'll have to go another route. Do you have access to the database? If you can get a dump of the database (I think Joomla! is MySQL based), you can open the sql in something like Sequel Pro and do a search in the content records for that ID.
This is not actually as hard as it sounds. First place to look the index.php file for the template. This file should be pretty small without a ton of code unless the template is from a developer that uses a template framework. If the ID is in there, then it will show up on every page in the website since this is the foundation that every page is built on.
If you don't find it in there, then you need to determine whether it is displaying in a module position or in the component area. You should be able to tell the difference by looking at the index.php file from the template.
If it's in a module position, then the ID should only show up in instances of that particular module.
If it's in the component area, then it should only display in any pages being created by the component. That does leave the possibility of it affecting many elements you don't want changed. But there is a solution for that. you can use the page class suffix in a menu item to add a unique id/class to the page you want to change (depends on your template). With that unique suffix you can create a specific selector that will only affect the pages you want to change.

Resources