Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code restructuring #43

Open
3 tasks
bilfeldt opened this issue Jan 3, 2024 · 1 comment
Open
3 tasks

Code restructuring #43

bilfeldt opened this issue Jan 3, 2024 · 1 comment
Milestone

Comments

@bilfeldt
Copy link
Member

bilfeldt commented Jan 3, 2024

The current codebase is not well divided into to subclasses responsible for a single thing. It is difficult knowing where each part belongs and the classes are very long.

Notes

Best practices: https://developer.wordpress.org/plugins/plugin-basics/best-practices/
Boilerplate plugin using Main plugin file, then one or more class files

Note that namespace is not normally used in WordPress (see Boilerplate without namespaces, article about namespacing: Instead use the class name and folder structure from best practices and the Block folder structure:

  • Restructure files into the recommended file and folder structure. This includes deviding the current files into separate files when it makes sense.
    • Example: admin/class-ss-shipping-wc-order.php
  • It seems that autoloading (we cannot assume composer is available) is not widely used in WordPress and it makes no sense making our own autoloader. Instead simply using require_once No need to have our own autoloader implementation
  • Implement a order utility class that can be used to pull relevant stuff from a WC_Order instance (using the filters we offer and such).
    • Move calls from SS_SHIPPING_WC()->example() to te new SS_Order_Util::example()
@bilfeldt bilfeldt added this to the v9.0.0 milestone Feb 13, 2024
@bilfeldt
Copy link
Member Author

The following folder structure will be used:

- build/                                       | All the files produced during build process
- includes/                                    | Where to put code that isn’t exclusive to the admin or public (like SDK for external communication)
  - vendor/
    - smart-send/ 
- public/
  - css/
    - ss-shipping-frontend.css
  - class-ss-shipping-frontend.php
- admin/                                       | Contains code exclusive for admins
  - css/
    - ss-shipping-admin.css
  - js/
    - ss-shipping-test-connection.js
    - ss-shipping-label.js
    - ss-shipping-admin.js
  - partials/                                  | Include HTML formatting file like displaying the order meta box
  - class-ss-shipping-endpoint.php
  - class-ss-shipping-shipment.php
  - class-ss-shipping-wc-method.php
  - class-ss-shipping-wc-order.php
  - class-ss-shipping-wc-product.php
- src/                                        | Contains the raw, uncompiled code, including JavaScript, CSS, and other assets necessary for developing the block
  - pickup-point-block/
  - index.js
  - block.json                                | Contains metadata for automatic optimization of assets
  - styles.scss
- .prettierrc.js
- phpcs.xml
- smart-send-logistics.php                    | Main Plugin File
- smart-send-extend-woo-core.php
- readme.txt                                  | A required file for any WordPress plugin with description of author, ...
- index.php                                   | An empty file that is there for (proposed) security reasons
- uninstall.php                               | Unsed to cleanup or the like when uninstalling the plugin
- package.json
- composer.json
- composer.lock
- configuration-files (many files)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant