:100644 100644 412443a 0000000 M __plugins/polylang-pro-3.7.6/include/Options/Business/Machine_Translation_Enabled.php :100644 100644 96ce719 0000000 M __plugins/polylang-pro-3.7.6/include/Options/Business/Machine_Translation_Services.php :100644 100644 942f25c 0000000 M __plugins/polylang-pro-3.7.6/include/Options/Business/Media.php :100644 100644 868a43d 0000000 M __plugins/polylang-pro-3.7.6/include/Options/Registry.php :100644 100644 eed01b5 0000000 M __plugins/polylang-pro-3.7.6/include/functions.php :100644 100644 4642a35 0000000 M __plugins/polylang-pro-3.7.6/include/pro.php :100644 100644 1987c8b 0000000 M __plugins/polylang-pro-3.7.6/include/upgrade.php :100644 100644 44140e0 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Ajax_Lang_Choice.php :100644 100644 113476b 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Dispatcher.php :100644 100644 14e9a46 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Entity/Abstract_Object.php :100644 100644 a5f610d 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Entity/Blocks.php :100644 100644 17e1792 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Entity/Media.php :100644 100644 42868d6 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Entity/Post.php :100644 100644 0c65264 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Entity/Term.php :100644 100644 4c5e48f 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Entity/Translatable_Entity_Interface.php :100644 100644 d6f3f2d 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Field_Settings.php :100644 100644 70debe2 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Labels/Abstract_Object_Type.php :100644 100644 b8c5c9b 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Labels/Field_Groups.php :100644 100644 6570b6e 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Labels/Post_Type.php :100644 100644 f9dd26f 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Labels/Taxonomy.php :100644 100644 4564fff 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Location_Language.php :100644 100644 8c4e37a 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Main.php :100644 100644 0278a00 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Collect_Ids.php :100644 100644 b64eae9 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Strategy.php :100644 100644 3797562 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Collect_Post_Ids.php :100644 100644 3db8a93 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Collect_Term_Ids.php :100644 100644 c49a1cc 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Copy.php :100644 100644 aa465ca 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Copy_All.php :100644 100644 a63d2f8 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Export.php :100644 100644 db87232 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Import.php :100644 100644 0ff82e5 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Synchronize.php :100644 100644 c31956c 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/Translation_Instructions.php :100644 100644 b12a45b 0000000 M __plugins/polylang-pro-3.7.6/integrations/acf/load.php :100644 100644 9d18841 0000000 M __plugins/polylang-pro-3.7.6/integrations/admin-columns/cpac.php :100644 100644 2247d39 0000000 M __plugins/polylang-pro-3.7.6/integrations/admin-columns/load.php :100644 100644 017ab15 0000000 M __plugins/polylang-pro-3.7.6/integrations/beaver-builder/flbuilder.php :100644 100644 5d8eace 0000000 M __plugins/polylang-pro-3.7.6/integrations/beaver-builder/load.php :100644 100644 550eda7 0000000 M __plugins/polylang-pro-3.7.6/integrations/content-blocks/content-blocks.php :100644 100644 6958c71 0000000 M __plugins/polylang-pro-3.7.6/integrations/content-blocks/load.php :100644 100644 9f38972 0000000 M __plugins/polylang-pro-3.7.6/integrations/cptui/cptui.php :100644 100644 6544896 0000000 M __plugins/polylang-pro-3.7.6/integrations/cptui/load.php :100644 100644 57a8733 0000000 M __plugins/polylang-pro-3.7.6/integrations/divi/divi-builder.php :100644 100644 3beb9bc 0000000 M __plugins/polylang-pro-3.7.6/integrations/divi/load.php :100644 100644 fda0420 0000000 M __plugins/polylang-pro-3.7.6/integrations/events-calendar/load.php :100644 100644 5b0394a 0000000 M __plugins/polylang-pro-3.7.6/integrations/events-calendar/tec.php :100644 100644 9211ac5 0000000 M __plugins/polylang-pro-3.7.6/polylang.php :100644 100644 78c349c 0000000 M __plugins/polylang-pro-3.7.6/services/admin-loader/admin-loader.php :100644 100644 d9a3320 0000000 M __plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-posts.php :100644 100644 e58ea14 0000000 M __plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-terms.php :100644 100644 c007a1a 0000000 M __plugins/polylang-pro-3.7.6/services/context.php :100644 100644 84e45c7 0000000 M __plugins/polylang-pro-3.7.6/services/data-encoding.php :100644 100644 7dfd5fe 0000000 M __plugins/polylang-pro-3.7.6/services/dom/dom-content.php :100644 100644 728f362 0000000 M __plugins/polylang-pro-3.7.6/services/dom/dom-document.php :100644 100644 e0c22d4 0000000 M __plugins/polylang-pro-3.7.6/services/dom/dom-nodes-iterator.php :100644 100644 e19ecee 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-container.php :100644 100644 d4c7f21 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-data-from-posts.php :100644 100644 bfa430a 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-data-from-strings.php :100644 100644 b7ce428 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-data.php :100644 100644 cede422 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-metas.php :100644 100644 7bd6b4f 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-post-metas.php :100644 100644 5c6b9ca 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-posts.php :100644 100644 6ef683a 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-strings.php :100644 100644 1e8ba4c 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-term-metas.php :100644 100644 c90f100 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-terms.php :100644 100644 f67ceaa 0000000 M __plugins/polylang-pro-3.7.6/services/exporter/export-translated-objects.php :100644 100644 d9e1acb 0000000 M __plugins/polylang-pro-3.7.6/services/manage-user-capabilities.php :100644 100644 20e2d02 0000000 M __plugins/polylang-pro-3.7.6/services/metabox-button/metabox-button.php :100644 100644 0825a0a 0000000 M __plugins/polylang-pro-3.7.6/services/metabox-button/metabox-user-button.php :100644 100644 0984a27 0000000 M __plugins/polylang-pro-3.7.6/services/metabox-button/toggle-user-meta.php :100644 100644 88b0071 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-block-parsing-rules.php :100644 100644 dc05340 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-content.php :100644 100644 a0b0e42 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-data-model-interface.php :100644 100644 4398df5 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-metas.php :100644 100644 e4e66dc 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-object-model-trait.php :100644 100644 1157b32 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-post-metas.php :100644 100644 004e061 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-post-model.php :100644 100644 ac402f3 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-strings-model.php :100644 100644 f0536dc 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-term-metas.php :100644 100644 1222404 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-term-model.php :100644 100644 4e06bc4 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-walker-blocks.php :100644 100644 ad484db 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-walker-classic.php :100644 100644 c9da8b4 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-walker-factory.php :100644 100644 a907fc2 0000000 M __plugins/polylang-pro-3.7.6/services/translation/translation-walker-interface.php :100644 100644 d02dcb2 0000000 M __plugins/polylang-pro-3.7.6/uninstall.php :100644 100644 6881284 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/src/Common_Trait.php :100644 100644 cff8552 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/src/EDD_SL_Plugin_Updater.php :100644 100644 aa20991 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/src/License.php :100644 100644 1c78f39 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/src/Settings.php :100644 100644 4862761 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/src/Translations.php :100644 100644 4f2b5b7 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/src/Updater.php :100644 100644 d8aaf2a 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/src/Wizard_Licenses_Step.php :100644 100644 e3743f0 0000000 M __plugins/polylang-wc/dependencies/wpsyntex/updater/uninstall.php :100644 100644 5431f87 0000000 M __plugins/polylang-wc/polylang-wc.php :100644 100644 68e5643 0000000 M __plugins/polylang-wc/src/Cart/Item.php :100644 100644 3f7d1db 0000000 M __plugins/polylang-wc/src/admin/admin-coupons.php :100644 100644 514b208 0000000 M __plugins/polylang-wc/src/admin/admin-orders-hpos.php :100644 100644 5b8acb8 0000000 M __plugins/polylang-wc/src/admin/admin-orders-legacy.php :100644 100644 2c9e712 0000000 M __plugins/polylang-wc/src/admin/admin-orders.php :100644 100644 8884eae 0000000 M __plugins/polylang-wc/src/admin/admin-product-duplicate.php :100644 100644 d646dc4 0000000 M __plugins/polylang-wc/src/admin/admin-products.php :100644 100644 55eb2dc 0000000 M __plugins/polylang-wc/src/admin/admin-reports.php :100644 100644 c5a2834 0000000 M __plugins/polylang-wc/src/admin/admin-site-health.php :100644 100644 9b60ad6 0000000 M __plugins/polylang-wc/src/admin/admin-status-reports.php :100644 100644 a2271b5 0000000 M __plugins/polylang-wc/src/admin/admin-taxonomies.php :100644 100644 4defd32 0000000 M __plugins/polylang-wc/src/admin/admin-wc-install.php :100644 100644 0596235 0000000 M __plugins/polylang-wc/src/admin/admin.php :100644 100644 23c14fc 0000000 M __plugins/polylang-wc/src/admin/wizard.php :100644 100644 d9928b5 0000000 M __plugins/polylang-wc/src/countries.php :100644 100644 622f3f0 0000000 M __plugins/polylang-wc/src/coupons.php :100644 100644 25df217 0000000 M __plugins/polylang-wc/src/data-store.php :100644 100644 9eb73fa 0000000 M __plugins/polylang-wc/src/emails.php :100644 100644 6656a3e 0000000 M __plugins/polylang-wc/src/export.php :100644 100644 db6d6f6 0000000 M __plugins/polylang-wc/src/filter-wc-pages.php :100644 100644 8561f43 0000000 M __plugins/polylang-wc/src/frontend/frontend-account.php :100644 100644 fd2c91e 0000000 M __plugins/polylang-wc/src/frontend/frontend-cart.php :100644 100644 77d6710 0000000 M __plugins/polylang-wc/src/frontend/frontend-wc-pages.php :100644 100644 f40496e 0000000 M __plugins/polylang-wc/src/frontend/frontend.php :100644 100644 420ce81 0000000 M __plugins/polylang-wc/src/functions.php :100644 100644 ac57316 0000000 M __plugins/polylang-wc/src/hpos-orders-query.php :100644 100644 98a5857 0000000 M __plugins/polylang-wc/src/import.php :100644 100644 0717db2 0000000 M __plugins/polylang-wc/src/install.php :100644 100644 9e54317 0000000 M __plugins/polylang-wc/src/legacy/rest-api.php :100644 100644 2b99d68 0000000 M __plugins/polylang-wc/src/legacy/rest-attribute-term.php :100644 100644 baabc27 0000000 M __plugins/polylang-wc/src/legacy/rest-order.php :100644 100644 e6b0101 0000000 M __plugins/polylang-wc/src/legacy/rest-product.php :100644 100644 d2d5ac6 0000000 M __plugins/polylang-wc/src/links-pro.php :100644 100644 25273a8 0000000 M __plugins/polylang-wc/src/links.php :100644 100644 1c8b4e4 0000000 M __plugins/polylang-wc/src/object-language.php :100644 100644 a8fc185 0000000 M __plugins/polylang-wc/src/order-language-cpt.php :100644 100644 44f87ca 0000000 M __plugins/polylang-wc/src/plugins/bookings.php :100644 100644 2151d4b 0000000 M __plugins/polylang-wc/src/plugins/composite-products.php :100644 100644 f91de57 0000000 M __plugins/polylang-wc/src/plugins/dynamic-pricing.php :100644 100644 9f03691 0000000 M __plugins/polylang-wc/src/plugins/follow-up-emails.php :100644 100644 91d96ed 0000000 M __plugins/polylang-wc/src/plugins/free-gift-coupons.php :100644 100644 37847fa 0000000 M __plugins/polylang-wc/src/plugins/germanized.php :100644 100644 68ab9cf 0000000 M __plugins/polylang-wc/src/plugins/min-max-quantities.php :100644 100644 07f42e1 0000000 M __plugins/polylang-wc/src/plugins/mix-match.php :100644 100644 4b2c0fa 0000000 M __plugins/polylang-wc/src/plugins/plugins-compat.php :100644 100644 c09d9a4 0000000 M __plugins/polylang-wc/src/plugins/product-bundles.php :100644 100644 2a7a9b9 0000000 M __plugins/polylang-wc/src/plugins/shipment-tracking.php :100644 100644 3402509 0000000 M __plugins/polylang-wc/src/plugins/stock-manager.php :100644 100644 abd783a 0000000 M __plugins/polylang-wc/src/plugins/stripe.php :100644 100644 b87e358 0000000 M __plugins/polylang-wc/src/plugins/subscriptions.php :100644 100644 3221bcd 0000000 M __plugins/polylang-wc/src/plugins/swatches.php :100644 100644 18a6ae8 0000000 M __plugins/polylang-wc/src/plugins/table-rate-shipping.php :100644 100644 2262b81 0000000 M __plugins/polylang-wc/src/plugins/wc-brands.php :100644 100644 37ef1c3 0000000 M __plugins/polylang-wc/src/plugins/wcfd.php :100644 100644 15300e0 0000000 M __plugins/polylang-wc/src/plugins/yith-wcas.php :100644 100644 92c3e4a 0000000 M __plugins/polylang-wc/src/post-types.php :100644 100644 4029dff 0000000 M __plugins/polylang-wc/src/product-data-store-cpt.php :100644 100644 90b0c37 0000000 M __plugins/polylang-wc/src/product-language-cpt.php :100644 100644 1352aff 0000000 M __plugins/polylang-wc/src/products.php :100644 100644 7348422 0000000 M __plugins/polylang-wc/src/stock.php :100644 100644 08a0a3a 0000000 M __plugins/polylang-wc/src/store-blocks.php :100644 100644 ffc2ce2 0000000 M __plugins/polylang-wc/src/strings.php :100644 100644 0fcfd58 0000000 M __plugins/polylang-wc/src/sync-content.php :100644 100644 9eb76bb 0000000 M __plugins/polylang-wc/src/translated-object-language.php :100644 100644 73a861e 0000000 M __plugins/polylang-wc/src/variation-data-store-cpt.php :100644 100644 399e341 0000000 M __plugins/polylang-wc/src/xdata-session-manager.php :100644 100644 ceeb1af 0000000 M __plugins/polylang-wc/src/xdata.php :100644 100644 80d040a 0000000 M __plugins/polylang-wc/uninstall.php :100644 100644 51a854c 0000000 M app/Admin/AdminOptions.php :100644 100644 fb66ba2 0000000 M app/Admin/SmtpConfig.php :100644 100644 a07993c 0000000 M app/Admin/TimberContextProvider.php :100644 100644 1e9f34e 0000000 M app/Controllers/AccountController.php :100644 100644 01baac8 0000000 M app/Controllers/CategoryController.php :100644 100644 fd8ae40 0000000 M app/Controllers/CheckoutController.php :100644 100644 4391563 0000000 M app/Controllers/ProductController.php :100644 100644 8ac3ed8 0000000 M app/Controllers/ShopController.php :100644 100644 a024842 0000000 M app/Handlers/AjaxHandlers/register.php :100644 100644 a137fa0 0000000 M app/Services/ProductFilterQuery.php :100644 100644 4f33424 0000000 M app/Traits/HandlesWcNotices.php :100644 100644 c1d6e86 0000000 M routes/base.php :100644 100644 539647d 0000000 M woocommerce/archive-product.php :100644 100644 a9b6bee 0000000 M woocommerce/brands/taxonomy-product_brand.php :100644 100644 c485fa8 0000000 M woocommerce/brands/widgets/brand-description.php :100644 100644 ca06354 0000000 M woocommerce/checkout/thankyou.php :100644 100644 63a45b8 0000000 M woocommerce/emails/block/general-block-content-for-fulfillment-emails.php :100644 100644 2e30f1a 0000000 M woocommerce/emails/email-mobile-messaging.php :100644 100644 0b1970a 0000000 M woocommerce/emails/plain/admin-cancelled-order.php :100644 100644 edca955 0000000 M woocommerce/emails/plain/admin-failed-order.php :100644 100644 fbae069 0000000 M woocommerce/emails/plain/admin-new-order.php :100644 100644 c42004e 0000000 M woocommerce/emails/plain/admin-payment-gateway-enabled.php :100644 100644 f28d680 0000000 M woocommerce/emails/plain/customer-cancelled-order.php :100644 100644 bbbfc1b 0000000 M woocommerce/emails/plain/customer-completed-order.php :100644 100644 601d5d5 0000000 M woocommerce/emails/plain/customer-failed-order.php :100644 100644 6cd86b4 0000000 M woocommerce/emails/plain/customer-fulfillment-created.php :100644 100644 8ffb754 0000000 M woocommerce/emails/plain/customer-fulfillment-deleted.php :100644 100644 8b2a3d5 0000000 M woocommerce/emails/plain/customer-fulfillment-updated.php :100644 100644 8e69e1d 0000000 M woocommerce/emails/plain/customer-invoice.php :100644 100644 58fc630 0000000 M woocommerce/emails/plain/customer-new-account.php :100644 100644 a246075 0000000 M woocommerce/emails/plain/customer-note.php :100644 100644 8dc8080 0000000 M woocommerce/emails/plain/customer-on-hold-order.php :100644 100644 09c66af 0000000 M woocommerce/emails/plain/customer-pos-completed-order.php :100644 100644 1cd139d 0000000 M woocommerce/emails/plain/customer-pos-refunded-order.php :100644 100644 005e506 0000000 M woocommerce/emails/plain/customer-processing-order.php :100644 100644 243cf94 0000000 M woocommerce/emails/plain/customer-refunded-order.php :100644 100644 ec6c16d 0000000 M woocommerce/emails/plain/customer-reset-password.php :100644 100644 8815828 0000000 M woocommerce/emails/plain/customer-stock-notification-verified.php :100644 100644 8fd2b41 0000000 M woocommerce/emails/plain/customer-stock-notification-verify.php :100644 100644 1030f9c 0000000 M woocommerce/emails/plain/customer-stock-notification.php :100644 100644 1ecbd9c 0000000 M woocommerce/emails/plain/email-addresses.php :100644 100644 f11d9bd 0000000 M woocommerce/emails/plain/email-customer-details.php :100644 100644 15bc1dd 0000000 M woocommerce/emails/plain/email-downloads.php :100644 100644 bfd1953 0000000 M woocommerce/emails/plain/email-fulfillment-details.php :100644 100644 f40c35b 0000000 M woocommerce/emails/plain/email-fulfillment-items.php :100644 100644 e0fcb21 0000000 M woocommerce/emails/plain/email-order-details.php :100644 100644 3448ba4 0000000 M woocommerce/emails/plain/email-order-items.php :100644 100644 6d30df6 0000000 M woocommerce/global/breadcrumb.php :100644 100644 a57a5c6 0000000 M woocommerce/global/sidebar.php :100644 100644 a147eec 0000000 M woocommerce/global/wrapper-end.php :100644 100644 bb88400 0000000 M woocommerce/global/wrapper-start.php :100644 100644 bc6dc56 0000000 M woocommerce/loop/rating.php :100644 100644 8ffbba9 0000000 M woocommerce/myaccount/dashboard.php :100644 100644 eb49b00 0000000 M woocommerce/myaccount/downloads.php :100644 100644 54b078f 0000000 M woocommerce/myaccount/form-add-payment-method.php :100644 100644 a8c5362 0000000 M woocommerce/myaccount/form-edit-account.php :100644 100644 633c3d2 0000000 M woocommerce/myaccount/form-edit-address.php :100644 100644 32f402d 0000000 M woocommerce/myaccount/form-login.php :100644 100644 5e46eb9 0000000 M woocommerce/myaccount/form-lost-password.php :100644 100644 309d926 0000000 M woocommerce/myaccount/form-reset-password.php :100644 100644 a265914 0000000 M woocommerce/myaccount/my-address.php :100644 100644 b8b6290 0000000 M woocommerce/myaccount/navigation.php :100644 100644 06be696 0000000 M woocommerce/myaccount/orders.php :100644 100644 2f1f773 0000000 M woocommerce/myaccount/payment-methods.php :100644 100644 50eff35 0000000 M woocommerce/myaccount/view-order.php :100644 100644 6b622ab 0000000 M woocommerce/single-product.php :100644 100644 04b5777 0000000 M woocommerce/single-product/product-thumbnails.php :100644 100644 f996b43 0000000 M woocommerce/single-product/review-rating.php :100644 100644 f94e287 0000000 M woocommerce/single-product/share.php :100644 100644 0ee0a4c 0000000 M woocommerce/single-product/title.php :100644 100644 c46ad71 0000000 M woocommerce/taxonomy-product-attribute.php :100644 100644 a7cb911 0000000 M woocommerce/taxonomy-product-cat.php :100644 100644 5286fa0 0000000 M woocommerce/taxonomy-product-tag.php diff --git a/__plugins/polylang-pro-3.7.6/include/Options/Business/Machine_Translation_Enabled.php b/__plugins/polylang-pro-3.7.6/include/Options/Business/Machine_Translation_Enabled.php index 412443a5874764d4840dafda3b323ba85e6e3098..07bb1a3d2cd4e915d42533a7a353c2c3b9308c9d 100644 --- a/__plugins/polylang-pro-3.7.6/include/Options/Business/Machine_Translation_Enabled.php +++ b/__plugins/polylang-pro-3.7.6/include/Options/Business/Machine_Translation_Enabled.php @@ -1,9 +1,5 @@ 'object', // Correspond to associative array in PHP, @see{https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#primitive-types}. - 'properties' => array(), + 'properties' => [], 'additionalProperties' => false, - ); + ]; foreach (Factory::get_classnames() as $service) { - $structure['properties'][ $service::get_slug() ] = array( + $structure['properties'][$service::get_slug()] = [ 'type' => 'object', 'properties' => $service::get_option_schema(), 'additionalProperties' => false, - ); + ]; } return $structure; diff --git a/__plugins/polylang-pro-3.7.6/include/Options/Business/Media.php b/__plugins/polylang-pro-3.7.6/include/Options/Business/Media.php index 942f25cfb42a03c099103ced2517269e9f49d66d..ee1fe8f102505c4627de9068d2c92d32fd1f9f7e 100644 --- a/__plugins/polylang-pro-3.7.6/include/Options/Business/Media.php +++ b/__plugins/polylang-pro-3.7.6/include/Options/Business/Media.php @@ -1,9 +1,5 @@ false ); + return ['duplicate' => false]; } /** @@ -63,16 +59,16 @@ class Media extends Abstract_Option */ protected function get_data_structure(): array { - return array( + return [ 'type' => 'object', // Correspond to associative array in PHP, @see{https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#primitive-types}. - 'properties' => array( - 'duplicate' => array( + 'properties' => [ + 'duplicate' => [ 'type' => 'boolean', 'required' => true, - ), - ), + ], + ], 'additionalProperties' => false, - ); + ]; } /** diff --git a/__plugins/polylang-pro-3.7.6/include/Options/Registry.php b/__plugins/polylang-pro-3.7.6/include/Options/Registry.php index 868a43d181a89642c1d4ac4b2ce11a36468ae551..99e38cecb2ac0cae54206102d0621833179da4c5 100644 --- a/__plugins/polylang-pro-3.7.6/include/Options/Registry.php +++ b/__plugins/polylang-pro-3.7.6/include/Options/Registry.php @@ -1,9 +1,5 @@ get_method(), array( 'PATCH', 'POST', 'PUT' ), true)) { + if (in_array($request->get_method(), ['PATCH', 'POST', 'PUT'], true)) { return true; } diff --git a/__plugins/polylang-pro-3.7.6/include/pro.php b/__plugins/polylang-pro-3.7.6/include/pro.php index 4642a35dc930fbde1197547c1aaedff609074351..adabaca327c18d8b0bbc59a26b60b1df348e0add 100644 --- a/__plugins/polylang-pro-3.7.6/include/pro.php +++ b/__plugins/polylang-pro-3.7.6/include/pro.php @@ -1,11 +1,7 @@ options; - add_action('pll_upgrade', array( new Upgrade($options), 'upgrade' )); + add_action('pll_upgrade', [new Upgrade($options), 'upgrade']); if ($polylang instanceof PLL_Admin_Base) { // new PLL_License( POLYLANG_PRO_FILE, 'Polylang Pro', POLYLANG_VERSION, 'WP SYNTEX' ); new PLL_T15S('polylang-pro', 'https://packages.translationspress.com/wp-syntex/polylang-pro/packages.json'); // Download Polylang language packs. - add_filter('http_request_args', array( $this, 'http_request_args' ), 10, 2); // phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args - add_filter('pre_set_site_transient_update_plugins', array( $this, 'pre_set_site_transient_update_plugins' )); + add_filter('http_request_args', [$this, 'http_request_args'], 10, 2); // phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args + add_filter('pre_set_site_transient_update_plugins', [$this, 'pre_set_site_transient_update_plugins']); } // Prolylang Pro is equivalent to Polylang for plugin dependencies. - add_filter('wp_plugin_dependencies_slug', array( $this, 'convert_plugin_dependency' )); + add_filter('wp_plugin_dependencies_slug', [$this, 'convert_plugin_dependency']); // Loads the modules. - $load_scripts = glob(POLYLANG_PRO_DIR . '/modules/*/load.php', GLOB_NOSORT); + $load_scripts = glob(POLYLANG_PRO_DIR.'/modules/*/load.php', GLOB_NOSORT); if (is_array($load_scripts)) { foreach ($load_scripts as $load_script) { require_once $load_script; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable @@ -71,12 +68,13 @@ class PLL_Pro } /** - * Hack to download Polylang languages packs + * Hack to download Polylang languages packs. * * @since 1.9 * * @param array $args HTTP request args. * @param string $url The url of the request. + * * @return array */ public function http_request_args($args, $url) @@ -84,25 +82,27 @@ class PLL_Pro if (false !== strpos($url, '//api.wordpress.org/plugins/update-check/')) { $plugins = (array) json_decode($args['body']['plugins'], true); if (empty($plugins['plugins']['polylang/polylang.php'])) { - $plugins['plugins']['polylang/polylang.php'] = array( 'Version' => POLYLANG_VERSION ); + $plugins['plugins']['polylang/polylang.php'] = ['Version' => POLYLANG_VERSION]; $args['body']['plugins'] = wp_json_encode($plugins); } } + return $args; } /** - * Remove Polylang from the list of plugins to update if it is not installed + * Remove Polylang from the list of plugins to update if it is not installed. * * @since 2.1.1 * * @param stdClass $value The value stored in the update_plugins site transient. + * * @return stdClass */ public function pre_set_site_transient_update_plugins($value) { // We encountered a 3rd party plugin setting the transient before the function get_plugins() is available. - require_once ABSPATH . 'wp-admin/includes/plugin.php'; + require_once ABSPATH.'wp-admin/includes/plugin.php'; $plugins = get_plugins(); if (isset($value->response)) { @@ -113,6 +113,7 @@ class PLL_Pro unset($value->response['polylang/polylang.php']); } } + return $value; } @@ -124,6 +125,7 @@ class PLL_Pro * @since 3.7 * * @param string $slug The plugin slug. + * * @return string */ public function convert_plugin_dependency($slug): string diff --git a/__plugins/polylang-pro-3.7.6/include/upgrade.php b/__plugins/polylang-pro-3.7.6/include/upgrade.php index 1987c8b5c77f2fe8f7cb9e24a00ed7fb3c55794c..b50c7a81d8d35955e1f983d1b086560a3c013040 100644 --- a/__plugins/polylang-pro-3.7.6/include/upgrade.php +++ b/__plugins/polylang-pro-3.7.6/include/upgrade.php @@ -1,9 +1,5 @@ options->get('version'), $version, '<')) { - $method_to_call = array( $this, 'upgrade_' . str_replace('.', '_', $version) ); + $method_to_call = [$this, 'upgrade_'.str_replace('.', '_', $version)]; if (is_callable($method_to_call)) { call_user_func($method_to_call); } @@ -64,11 +60,11 @@ class Upgrade */ private function upgrade_3_7() { - if (! ACF_Main::can_use()) { + if (!ACF_Main::can_use()) { return; } - if (! in_array('acf-field-group', $this->options->get('post_types'), true)) { + if (!in_array('acf-field-group', $this->options->get('post_types'), true)) { return; } @@ -76,7 +72,7 @@ class Upgrade 'post_types', array_diff( $this->options->get('post_types'), - array( 'acf-field-group' ) + ['acf-field-group'] ) ); $this->options->save(); @@ -93,11 +89,11 @@ class Upgrade } $group_language = $group_language[0]; - $new_location = array( + $new_location = [ 'param' => 'language', 'operator' => '==', 'value' => $group_language->slug, - ); + ]; foreach ($group['location'] as &$location) { $location[] = $new_location; diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Ajax_Lang_Choice.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Ajax_Lang_Choice.php index 44140e0cfede19e175c9e4ba1b184b723830d39b..b03942f7e132ebbafd8e47a64605b4cec3d5028c 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Ajax_Lang_Choice.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Ajax_Lang_Choice.php @@ -1,9 +1,5 @@ model->is_translated_post_type($typenow) ) { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_script('pll_acf', plugins_url('/js/build/integrations/acf' . $suffix . '.js', POLYLANG_ROOT_FILE), array( 'wp-api-fetch', 'acf-input' ), POLYLANG_VERSION); + wp_enqueue_script('pll_acf', plugins_url('/js/build/integrations/acf'.$suffix.'.js', POLYLANG_ROOT_FILE), ['wp-api-fetch', 'acf-input'], POLYLANG_VERSION); } } @@ -62,21 +58,21 @@ class Ajax_Lang_Choice { check_ajax_referer('pll_language', '_pll_nonce'); - if (! isset($_POST['fields'], $_POST['lang'], $_POST['post_id'])) { + if (!isset($_POST['fields'], $_POST['lang'], $_POST['post_id'])) { wp_die(0); } $post_id = (int) $_POST['post_id']; - if (! current_user_can('edit_post', $post_id)) { + if (!current_user_can('edit_post', $post_id)) { wp_die(-1); } $language = PLL()->model->languages->get(sanitize_key($_POST['lang'])); - if (! $language) { + if (!$language) { wp_die(0); } - $response = array(); + $response = []; $fields = explode(',', sanitize_text_field(wp_unslash($_POST['fields']))); foreach ($fields as $field) { @@ -86,26 +82,26 @@ class Ajax_Lang_Choice continue; } - $from_value = acf_get_value($post_id, $field_array); + $from_value = acf_get_value($post_id, $field_array); $field_array['value'] = (new Copy())->execute( new Post($post_id), $from_value, $field_array, - array( + [ 'target_language' => $language, 'original_value' => $from_value, - ) + ] ); acf_update_value($field_array['value'], $post_id, $field_array); ob_start(); - acf_render_fields(array( $field_array )); + acf_render_fields([$field_array]); $field_wrap = ob_get_clean(); - $response[] = array( + $response[] = [ 'field_key' => str_replace('_', '-', $field), 'field_data' => false !== $field_wrap ? $field_wrap : '', - ); + ]; } wp_send_json($response); diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Dispatcher.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Dispatcher.php index 113476b4b274126195e2df37798105b3cf889fad..b4f4b6a28d480ad79dc8b622eea6c4ea6ede6730 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Dispatcher.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Dispatcher.php @@ -1,24 +1,20 @@ options['media_support']) { - add_action('pll_translate_media', array( static::class, 'copy_media_fields' ), 10, 3); + add_action('pll_translate_media', [static::class, 'copy_media_fields'], 10, 3); } } @@ -75,15 +71,15 @@ class Dispatcher */ public static function on_blocks_registered(): void { - if (! function_exists('acf_get_block_types') || empty(acf_get_block_types())) { + if (!function_exists('acf_get_block_types') || empty(acf_get_block_types())) { return; } - add_filter('pll_collect_post_ids', array( static::class, 'collect_post_ids_in_blocks' ), 10, 2); - add_filter('pll_collect_term_ids', array( static::class, 'collect_term_ids_in_blocks' ), 10, 2); - add_filter('pll_translate_blocks_with_context', array( static::class, 'copy_blocks' ), 10, 3); - add_filter('pll_filter_translated_post', array( static::class, 'translate_blocks' ), 10, 4); - add_action('pll_after_post_export', array( static::class, 'export_blocks' ), 10, 2); + add_filter('pll_collect_post_ids', [static::class, 'collect_post_ids_in_blocks'], 10, 2); + add_filter('pll_collect_term_ids', [static::class, 'collect_term_ids_in_blocks'], 10, 2); + add_filter('pll_translate_blocks_with_context', [static::class, 'copy_blocks'], 10, 3); + add_filter('pll_filter_translated_post', [static::class, 'translate_blocks'], 10, 4); + add_action('pll_after_post_export', [static::class, 'export_blocks'], 10, 2); } /** @@ -93,11 +89,13 @@ class Dispatcher * * @param array $field Custom field definition. * @param int|string $acf_id ACF post ID. + * * @return mixed Modified custom field. */ public static function render_field($field, $acf_id) { $object = static::get_by_acf_id($acf_id); + return empty($object) ? $field : $object->render_field($field); } @@ -109,11 +107,13 @@ class Dispatcher * @param mixed $value Custom field value. * @param int|string $acf_id ACF post ID. * @param array $field Custom field definition. + * * @return mixed Modified custom field value. */ public static function update($value, $acf_id, $field) { $object = static::get_by_acf_id($acf_id); + return empty($object) ? $value : $object->update($value, $field); } @@ -126,7 +126,8 @@ class Dispatcher * @param int $post_id ID of the source post. * @param int $tr_post_id ID of the target post. * @param string $lang Language of the target post. - * @param string $sync `sync` if doing synchro, `copy` otherwise. + * @param string $sync `sync` if doing synchro, `copy` otherwise. + * * @return void * * @phpstan-param 'sync'|'copy' $sync @@ -144,12 +145,13 @@ class Dispatcher * @param PLL_Export_Data $export The export object. * @param object $from The object to export. * @param object|null $to The translated object if it exists, `null` otherwise. + * * @return void */ public static function export($export, $from, $to) { $object = self::get_by_object($from); - if (! empty($object) && $export instanceof PLL_Export_Data) { + if (!empty($object) && $export instanceof PLL_Export_Data) { $object->export($export, $to); } } @@ -161,13 +163,14 @@ class Dispatcher * * @param int[] $linked_ids Object IDs linked to a post. * @param WP_Post $post The post we get other post from. + * * @return int[] */ public static function collect_post_ids($linked_ids, $post) { $object = self::get_by_object($post); - if (! empty($object)) { + if (!empty($object)) { return array_merge((array) $linked_ids, (new Collect_Post_Ids())->get($object)); } @@ -181,6 +184,7 @@ class Dispatcher * * @param int[] $linked_ids Object IDs linked to a post. * @param WP_Post $post The post we get other post from. + * * @return int[] */ public static function collect_post_ids_in_blocks($linked_ids, $post) @@ -199,20 +203,20 @@ class Dispatcher * * @param int[] $linked_ids Object IDs linked to a post. * @param WP_Post $post The post we get other term from. + * * @return int[] */ public static function collect_term_ids($linked_ids, $post) { $object = self::get_by_object($post); - if (! empty($object)) { + if (!empty($object)) { return array_merge((array) $linked_ids, (new Collect_Term_Ids())->get($object)); } return $linked_ids; } - /** * Collects term IDs from fields in ACF blocks. * @@ -220,6 +224,7 @@ class Dispatcher * * @param int[] $linked_ids Object IDs linked to a post. * @param WP_Post $post The post we get other term from. + * * @return int[] */ public static function collect_term_ids_in_blocks($linked_ids, $post) @@ -240,6 +245,7 @@ class Dispatcher * @param object $to Translated object to translate the custom fields from. * @param PLL_Language $target_lang Target language object. * @param Translations $translations A set of translations to search the custom fields translations in. + * * @return void */ public static function translate($from, $to, $target_lang, $translations) @@ -248,15 +254,14 @@ class Dispatcher * Remove filter for `Dispatcher::render_field` to avoid running `Strategy\Copy` on the same object. * For instance, when translating fields with DeepL, we don't want to override the translated values with the original ones with `Strategy\Copy`. */ - remove_filter('acf/pre_render_field', array( self::class, 'render_field' )); + remove_filter('acf/pre_render_field', [self::class, 'render_field']); $object = self::get_by_object($from); - if (! empty($object) && $target_lang instanceof PLL_Language && $translations instanceof Translations) { + if (!empty($object) && $target_lang instanceof PLL_Language && $translations instanceof Translations) { $object->translate($to, $target_lang, $translations); } } - /** * Adds the language of the current object to the arguments that will be used for the query in the `relationship` ACF field. * @@ -265,6 +270,7 @@ class Dispatcher * @param array $args Arguments to retrieve posts. * @param array $field The current field. * @param int|string $acf_id ACF post ID. + * * @return array The arguments to retrieve posts with the current object language. */ public static function add_language_to_query($args, $field, $acf_id) @@ -296,6 +302,7 @@ class Dispatcher * @param int $from_id The source media ID. * @param int $to_id The target media ID. * @param PLL_Language $target_language The target language. + * * @return void */ public static function copy_media_fields($from_id, $to_id, $target_language) @@ -311,6 +318,7 @@ class Dispatcher * @param int $from Term ID of the source term. * @param int $to Term ID of the new term translation. * @param string $lang Language code of the new translation. + * * @return void */ public static function on_duplicate_term($from, $to, $lang) @@ -320,7 +328,7 @@ class Dispatcher (new Term($from))->apply_to_all_fields( new Copy(), $to, - array( 'target_language' => $lang ) + ['target_language' => $lang] ); } } @@ -333,13 +341,15 @@ class Dispatcher * @param array $blocks The blocks. * @param PLL_Language $target_lang The target language. * @param WP_Post|null $source_post The source post, `null` if not available. + * * @return array The blocks. */ public static function copy_blocks($blocks, $target_lang, $source_post) { - if (! is_array($blocks) || ! $target_lang instanceof PLL_Language || ! $source_post instanceof WP_Post) { + if (!is_array($blocks) || !$target_lang instanceof PLL_Language || !$source_post instanceof WP_Post) { return $blocks; } + return (new Blocks())->copy($blocks, $target_lang, $source_post); } @@ -348,15 +358,16 @@ class Dispatcher * * @since 3.7 * - * @param WP_Post $to Translated post where to translate the custom fields included in blocks. - * @param WP_Post $from Source post where to get the custom fields included in blocks. - * @param PLL_Language $target_lang The target language. - * @param Translations $translations A set of translations where to search translations of the custom fields translations included in blocks. + * @param WP_Post $to Translated post where to translate the custom fields included in blocks. + * @param WP_Post $from Source post where to get the custom fields included in blocks. + * @param PLL_Language $target_lang The target language. + * @param Translations $translations A set of translations where to search translations of the custom fields translations included in blocks. + * * @return WP_Post The translated post. */ public static function translate_blocks($to, $from, $target_lang, $translations) { - if (! $to instanceof WP_Post) { + if (!$to instanceof WP_Post) { return $to; } @@ -370,6 +381,7 @@ class Dispatcher * * @param PLL_Export_Data $export The export data. * @param WP_Post $from The source post. + * * @return void */ public static function export_blocks($export, $from) @@ -383,12 +395,13 @@ class Dispatcher * @since 3.7 * * @param int|string $acf_id ACF post ID. + * * @return Abstract_Object|null. */ protected static function get_by_acf_id($acf_id): ?Abstract_Object { $decoded = acf_decode_post_id($acf_id); - $id = (int) $decoded['id']; + $id = (int) $decoded['id']; switch ($decoded['type']) { case 'post': @@ -406,7 +419,7 @@ class Dispatcher } // No nonce to check. - if (0 === $id && ! empty($_GET['new_lang']) && ! empty($_GET['taxonomy']) // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if (0 === $id && !empty($_GET['new_lang']) && !empty($_GET['taxonomy']) // phpcs:ignore WordPress.Security.NonceVerification.Recommended && pll_is_translated_taxonomy(sanitize_key($_GET['taxonomy']))) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended // This is a term creation with `term_0`, see `acf_form_taxonomy::add_term()`. return new Term($id); @@ -423,6 +436,7 @@ class Dispatcher * @since 3.7 * * @param object $object The object. + * * @return Abstract_Object|null. */ protected static function get_by_object($object): ?Abstract_Object diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Abstract_Object.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Abstract_Object.php index 14e9a46cb730ec37ded1ef6cba9fb62569124a0c..2cfe1ab22fb801541d43e5e3382516bdc8b37b32 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Abstract_Object.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Abstract_Object.php @@ -1,20 +1,16 @@ execute( $this, $from_value, $field, - array( + [ 'target_language' => $lang, 'source_language' => PLL()->model->{$this->get_type()}->get_language($from_id), 'original_value' => $original_value, - ) + ] ); + return $field; } @@ -96,6 +94,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * * @param mixed $value Custom field value of the source object. * @param array $field Custom field definition. + * * @return mixed Custom field value of the target object. */ public function update($value, $field) @@ -107,8 +106,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface $strategy = new Synchronize(new Copy()); - - if (! $strategy->can_execute($field)) { + if (!$strategy->can_execute($field)) { return $value; } @@ -123,20 +121,20 @@ abstract class Abstract_Object implements Translatable_Entity_Interface self::$updated[] = $this->get_storage_key($tr_id, $field['key']); - $acf_id = static::acf_id($tr_id); + $acf_id = static::acf_id($tr_id); $tr_value = acf_get_value($acf_id, $field); $tr_value = $strategy->execute( $this, $value, $field, - array( + [ 'target_language' => $lang, 'original_value' => $tr_value, 'target_id' => $tr_id, - ) + ] ); - if (! empty($field['sub_fields']) && is_array($tr_value) && empty($tr_value)) { + if (!empty($field['sub_fields']) && is_array($tr_value) && empty($tr_value)) { /* * The fields has subfields but they have been removed * by `Abstract_Strategy::apply_on_subfield()` @@ -160,28 +158,29 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * @param Abstract_Strategy $strategy Strategy to execute. * @param int $to ID of the target object. * @param array $args { - * Array of arguments. + * Array of arguments. + * + * @var mixed $original_value Optional. The translated value of the field, if any. + * @var bool $update Optional. Tells if we can update the target ID fields, default `true`. + * } * - * @type mixed $original_value Optional. The translated value of the field, if any. - * @type bool $update Optional. Tells if we can update the target ID fields, default `true`. - * } * @return void */ - public function apply_to_all_fields(Abstract_Strategy $strategy, int $to = 0, array $args = array()) + public function apply_to_all_fields(Abstract_Strategy $strategy, int $to = 0, array $args = []) { // Removes filters on `Dispatcher::update()` to avoid unnecessary operations on `acf_update_value`. - remove_filter('acf/update_value', array( Dispatcher::class, 'update' ), 5); + remove_filter('acf/update_value', [Dispatcher::class, 'update'], 5); $fields = get_field_objects(static::acf_id($this->get_id()), false); if (empty($fields)) { - $fields = array(); + $fields = []; } - $args['update'] = ! isset($args['update']) || (bool) $args['update']; + $args['update'] = !isset($args['update']) || (bool) $args['update']; foreach ($fields as $field) { - if (empty($field['value']) && ! is_string($field['value'])) { + if (empty($field['value']) && !is_string($field['value'])) { continue; } @@ -197,7 +196,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface $args ); - if (0 < $to && ! empty($args['update'])) { + if (0 < $to && !empty($args['update'])) { acf_update_value( $tr_value, static::acf_id($to), @@ -207,7 +206,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface } // Reset filter for `Dispatcher::update` so our integration works for later operations. - add_filter('acf/update_value', array( Dispatcher::class, 'update' ), 5, 3); + add_filter('acf/update_value', [Dispatcher::class, 'update'], 5, 3); } /** @@ -215,7 +214,9 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * * @param PLL_Export_Data $export The export object. * @param object|null $to The translated object if it exists, `null` otherwise. + * * @return void + * * @since 3.7 */ public function export(PLL_Export_Data $export, ?object $to) @@ -223,10 +224,10 @@ abstract class Abstract_Object implements Translatable_Entity_Interface $this->apply_to_all_fields( new Export($export), empty($to) ? 0 : $this->get_object_id($to), - array( + [ 'target_language' => $export->get_target_language(), 'update' => false, - ) + ] ); } @@ -238,6 +239,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * @param object $to The target object. * @param PLL_Language $target_lang Target language object. * @param Translations $translations A set of translations to search the custom fields translations in. + * * @return object The translated object. */ public function translate(object $to, PLL_Language $target_lang, Translations $translations): object @@ -245,7 +247,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface $this->apply_to_all_fields( new Import($translations), $this->get_object_id($to), - array( 'target_language' => $target_lang ) + ['target_language' => $target_lang] ); return $to; @@ -261,16 +263,17 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * @param bool $sync True if it is synchronization, false if it is a copy. * @param int|string $from ID of the object from which we copy information. * @param int|string $to ID of the object to which we copy information. + * * @return string[] */ public static function remove_acf_metas_from_pll_sync($metas, $sync, $from, $to) { - if (! is_array($metas)) { + if (!is_array($metas)) { return $metas; } $from = static::acf_id((int) $from); - $to = static::acf_id((int) $to); + $to = static::acf_id((int) $to); $acf_metas = array_merge((array) acf_get_meta($from), (array) acf_get_meta($to)); $acf_metas = array_keys($acf_metas); @@ -297,11 +300,12 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * * @param int $id Object ID. * @param string $key The custom field key. + * * @return string */ protected function get_storage_key($id, $key) { - return static::acf_id($id) . '|' . $key; + return static::acf_id($id).'|'.$key; } /** @@ -310,6 +314,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * @since 3.7 * * @param object $object The object. + * * @return int */ abstract protected function get_object_id($object): int; @@ -320,6 +325,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * @since 3.7 * * @param int $id Object ID. + * * @return int|string ACF post ID. */ abstract protected static function acf_id($id); @@ -343,6 +349,7 @@ abstract class Abstract_Object implements Translatable_Entity_Interface * @since 3.7 * * @return string + * * @phpstan-return non-falsy-string */ abstract public function get_type(): string; diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Blocks.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Blocks.php index a5f610d55cd0a56727a20ae550878813b276ea8a..a559e52cc920ee2a1df318d9738a075290d2788b 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Blocks.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Blocks.php @@ -1,19 +1,15 @@ id); - if (empty($post) || ! has_blocks($post)) { + if (empty($post) || !has_blocks($post)) { return $to; } @@ -100,13 +98,14 @@ class Blocks implements Translatable_Entity_Interface * @since 3.7 * * @param PLL_Export_Data $export The export data. + * * @return void */ public function export(PLL_Export_Data $export) { $post = get_post($this->id); - if (empty($post) || ! has_blocks($post)) { + if (empty($post) || !has_blocks($post)) { return; } @@ -126,17 +125,18 @@ class Blocks implements Translatable_Entity_Interface * @param Abstract_Strategy $strategy Strategy to execute. * @param int $to ID of the target post. Not used. * @param array $args { - * Array of arguments. + * Array of arguments. + * + * @var PLL_Language|null $target_language The language used to apply the strategy. + * } * - * @type PLL_Language|null $target_language The language used to apply the strategy. - * } * @return void */ - public function apply_to_all_fields(Abstract_Strategy $strategy, int $to = 0, array $args = array()) + public function apply_to_all_fields(Abstract_Strategy $strategy, int $to = 0, array $args = []) { $post = get_post($this->id); - if (empty($post) || ! has_blocks($post)) { + if (empty($post) || !has_blocks($post)) { return; } @@ -159,18 +159,19 @@ class Blocks implements Translatable_Entity_Interface * @param PLL_Language|null $language The language used to apply the strategy: * the target language when applying a translate strategy, * unused i.e. null when collecting linked content. + * * @return array The blocks. */ private function apply_on_blocks(Abstract_Strategy $strategy, array $blocks, int $id, ?PLL_Language $language = null): array { foreach ($blocks as &$block) { - if (! isset($block['blockName'], $block['attrs'])) { + if (!isset($block['blockName'], $block['attrs'])) { // No can do. continue; } if (empty(acf_get_block_type($block['blockName']))) { - if (! empty($block['innerBlocks'])) { + if (!empty($block['innerBlocks'])) { $block['innerBlocks'] = $this->apply_on_blocks($strategy, $block['innerBlocks'], $id, $language); } continue; @@ -186,18 +187,18 @@ class Blocks implements Translatable_Entity_Interface $block = acf_prepare_block($block); - if (! isset($block['data'])) { + if (!isset($block['data'])) { // No can do. continue; } // Backward compatibility with ACF < 6.3. if (function_exists('acf_add_block_meta_values') && function_exists('acf_block_uses_post_meta') && acf_block_uses_post_meta($block)) { - $block = acf_add_block_meta_values($block, $id); + $block = acf_add_block_meta_values($block, $id); $block['attrs']['data'] = $block['data']; } - if (! isset($block['attrs']['data'])) { + if (!isset($block['attrs']['data'])) { // No can do. continue; } @@ -208,21 +209,21 @@ class Blocks implements Translatable_Entity_Interface */ acf_setup_meta($block['attrs']['data'], $block['id'], true); - $values = array(); + $values = []; foreach (acf_get_block_fields($block['attrs']) as $field) { - $value = acf_get_value($block['id'], $field); - $values[ $field['key'] ] = $strategy->execute( + $value = acf_get_value($block['id'], $field); + $values[$field['key']] = $strategy->execute( new Post($id), $value, $field, - array( + [ 'target_language' => $language, 'original_value' => $field['default_value'] ?? null, - ) + ] ); } - if (! empty($values)) { + if (!empty($values)) { /* * Converts "data" to "meta" and ensures the block attributes are all set. * `acf_setup_meta()` cannot be used directly because it relies on form data, which is not the case here. @@ -246,7 +247,7 @@ class Blocks implements Translatable_Entity_Interface */ acf_reset_meta($block['id']); - if (! empty($block['innerBlocks'])) { + if (!empty($block['innerBlocks'])) { $block['innerBlocks'] = $this->apply_on_blocks($strategy, $block['innerBlocks'], $id, $language); } } @@ -261,13 +262,14 @@ class Blocks implements Translatable_Entity_Interface * @since 3.7 * * @param array $block The block to convert. + * * @return array The converted block. */ private function prepare_block_post_meta(array $block): array { - $new_data = array(); + $new_data = []; foreach ($block['attrs']['data'] as $key => $value) { - if (! str_starts_with($key, '_') || empty($value)) { + if (!str_starts_with($key, '_') || empty($value)) { continue; } @@ -277,7 +279,7 @@ class Blocks implements Translatable_Entity_Interface continue; } - $new_data[ $field['key'] ] = acf_get_value($block['id'], $field); + $new_data[$field['key']] = acf_get_value($block['id'], $field); } $block['attrs']['data'] = $new_data; diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Media.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Media.php index 17e17927436e0f4dd2fd44e65a52ba7f0904d904..0847e947233b06468fa7145bbd4d71ed1fdbc031 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Media.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Media.php @@ -1,9 +1,5 @@ maybe_reset_fields_store($target_language); - $this->apply_to_all_fields(new Copy(), $to_id, array( 'target_language' => $target_language )); + $this->apply_to_all_fields(new Copy(), $to_id, ['target_language' => $target_language]); } /** @@ -44,11 +41,12 @@ class Media extends Post * @since 3.7 * * @param int $id Post ID. + * * @return string ACF post ID. */ protected static function acf_id($id): string { - return 'attachment_' . $id; + return 'attachment_'.$id; } /** @@ -57,6 +55,7 @@ class Media extends Post * @since 3.7 * * @param array $field Custom field definition. + * * @return array Custom field of the target object. */ public function render_field($field) // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Post.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Post.php index 42868d61306ed18248fb44870c2469662a072ab7..884d66384294e697b7c8743ef300d4d18ffb700e 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Post.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Post.php @@ -1,15 +1,11 @@ links instanceof PLL_Admin_Links) { + if (!PLL()->links instanceof PLL_Admin_Links) { return 0; } @@ -71,7 +69,7 @@ class Post extends Abstract_Object (string) get_post_type($this->get_id()) ); - return ! empty($data['from_post']) ? $data['from_post']->ID : 0; + return !empty($data['from_post']) ? $data['from_post']->ID : 0; } /** @@ -80,6 +78,7 @@ class Post extends Abstract_Object * @since 3.7 * * @return string + * * @phpstan-return non-falsy-string */ public function get_type(): string @@ -95,7 +94,8 @@ class Post extends Abstract_Object * * @param int $tr_post_id ID of the target post. * @param string $lang Language of the target post. - * @param string $sync `sync` if doing synchro, `copy` otherwise. + * @param string $sync `sync` if doing synchro, `copy` otherwise. + * * @return void * * @phpstan-param 'sync'|'copy' $sync @@ -110,20 +110,21 @@ class Post extends Abstract_Object $this->maybe_reset_fields_store($lang); if (PLL_Sync_Post_Model::COPY === $sync) { - $this->apply_to_all_fields(new Copy(), $tr_post_id, array( 'target_language' => $lang )); + $this->apply_to_all_fields(new Copy(), $tr_post_id, ['target_language' => $lang]); + return; } // Sync all custom fields between synchronized posts. $post_id = $this->get_id(); foreach (pll_get_post_translations($post_id) as $tr_lang => $tr_id) { - if ($tr_id === $post_id || ! PLL()->sync_post_model->are_synchronized($post_id, $tr_id)) { + if ($tr_id === $post_id || !PLL()->sync_post_model->are_synchronized($post_id, $tr_id)) { continue; } /** @var PLL_Language */ $tr_lang = PLL()->model->get_language($tr_lang); - $this->apply_to_all_fields(new Copy_All(), $tr_id, array( 'target_language' => $tr_lang )); + $this->apply_to_all_fields(new Copy_All(), $tr_id, ['target_language' => $tr_lang]); } } @@ -134,6 +135,7 @@ class Post extends Abstract_Object * @since 3.7 * * @param PLL_Language $lang Language of the target post. + * * @return void */ protected function maybe_reset_fields_store(PLL_Language $lang) diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Term.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Term.php index 0c652641208d53b6dc3be21e3d5402e6bbeb93d9..1495544431dc1fd86ff33d36e255e58aa9fc5a8e 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Term.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Entity/Term.php @@ -1,9 +1,5 @@ category) { - add_action("acf/render_field_settings/type={$type->name}", array( $this, 'render_field_settings' )); + add_action("acf/render_field_settings/type={$type->name}", [$this, 'render_field_settings']); } } } @@ -37,17 +33,18 @@ class Field_Settings * @since 3.7.3 * * @param int $id The fields group ID to check. + * * @return bool True if the fields group is from Polylang Pro < 3.7 and had been translated, false otherwise. */ public static function is_legacy_translated_field_group(int $id) { - return ! empty( + return !empty( get_terms( - array( + [ 'taxonomy' => 'language', 'fields' => 'ids', 'object_ids' => $id, - ) + ] ) ); } @@ -60,20 +57,21 @@ class Field_Settings * @since 3.7 Added `translate_once` option. * * @param array $field Custom field definition. + * * @return void */ public function render_field_settings($field) { $field_group = Location_Language::get_field_group_from_field($field); - if (! empty($field_group) && Location_Language::has_language_location_rule($field_group) && ! $this::is_legacy_translated_field_group((int) $field_group['ID'])) { + if (!empty($field_group) && Location_Language::has_language_location_rule($field_group) && !$this::is_legacy_translated_field_group((int) $field_group['ID'])) { return; } - $choices = array( + $choices = [ 'ignore' => __('Ignore', 'polylang-pro'), 'copy_once' => __('Copy once', 'polylang-pro'), 'sync' => __('Synchronize', 'polylang-pro'), - ); + ]; $default = in_array('post_meta', PLL()->options['sync']) ? 'sync' : 'copy_once'; switch ($field['type']) { @@ -92,10 +90,10 @@ class Field_Settings // Add translate and translate_once option from the 3rd position. $choices = array_merge( array_slice($choices, 0, 2), - array( + [ 'translate' => __('Translate', 'polylang-pro'), 'translate_once' => __('Translate once', 'polylang-pro'), - ), + ], array_slice($choices, -1) ); break; @@ -111,20 +109,21 @@ class Field_Settings * @param array $field Custom field definition. * @param array $choices An array of choices for the select (value as key and label as value). * @param string $default Default value for the select. + * * @return void */ protected function render_field_setting($field, $choices, $default) { acf_render_field_setting( // Since ACF 5.7.10. $field, - array( + [ 'label' => __('Translations', 'polylang-pro'), 'instructions' => '', 'name' => 'translations', 'type' => 'select', 'choices' => $choices, 'default_value' => $default, - ), + ], false // The setting is depending on the type of field. ); } diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Abstract_Object_Type.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Abstract_Object_Type.php index 70debe23bc08182c3cbac53dade64b5d2a407bb4..4e9ac5ffd19dd77701ec08f8144bcf862f14d7e1 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Abstract_Object_Type.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Abstract_Object_Type.php @@ -1,13 +1,9 @@ translate_registered_strings(); } else { // Special case when the language is set from the content as CPT and taxonomies are registered before the language is defined. - add_action('pll_language_defined', array( $this, 'translate_registered_strings' )); + add_action('pll_language_defined', [$this, 'translate_registered_strings']); } } @@ -60,8 +56,8 @@ abstract class Abstract_Object_Type */ public function register_strings(): void { - foreach ($this->get_acf_type_instance()->get_posts(array( 'active' => true )) as $acf_object) { - $label_start = sprintf('ACF %s, %s,', $this->get_type_label(), $acf_object[ $this->get_type() ]); + foreach ($this->get_acf_type_instance()->get_posts(['active' => true]) as $acf_object) { + $label_start = sprintf('ACF %s, %s,', $this->get_type_label(), $acf_object[$this->get_type()]); pll_register_string("{$label_start} title", $acf_object['title'], 'ACF'); pll_register_string("{$label_start} description", $acf_object['description'], 'ACF', true); @@ -81,12 +77,12 @@ abstract class Abstract_Object_Type */ public function translate_registered_strings(): void { - $acf_objects = $this->get_acf_type_instance()->get_posts(array( 'active' => true )); + $acf_objects = $this->get_acf_type_instance()->get_posts(['active' => true]); $acf_objects = array_column($acf_objects, $this->get_type(), $this->get_type()); $acf_objects = array_intersect_key($this->get_type_objects(), $acf_objects); foreach ($acf_objects as $type) { - $type->label = pll__($type->label); + $type->label = pll__($type->label); $type->description = pll__($type->description); foreach (array_keys(get_object_vars($type->labels)) as $key) { diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Field_Groups.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Field_Groups.php index b8c5c9bcd51814e29e0eda58707d7889d13fe07d..6f10d94fdaf9649cc4e9c33269a7c3172765df99 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Field_Groups.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Field_Groups.php @@ -1,13 +1,9 @@ register_field_groups(); - if (! $this->can_translate_labels()) { + if (!$this->can_translate_labels()) { return; } - add_filter('acf/load_field', array( $this, 'translate_field_labels' ), 20); // After `child_of_acf_field::load_field()` (prio 10). - add_filter('acf/load_field_groups', array( $this, 'translate_field_groups_labels' ), 25); // After `_acf_apply_get_local_internal_posts()` (prio 20). + add_filter('acf/load_field', [$this, 'translate_field_labels'], 20); // After `child_of_acf_field::load_field()` (prio 10). + add_filter('acf/load_field_groups', [$this, 'translate_field_groups_labels'], 25); // After `_acf_apply_get_local_internal_posts()` (prio 20). } /** @@ -74,18 +70,19 @@ class Field_Groups * @since 3.7 * * @param array $field The field array. + * * @return array */ public function translate_field_labels($field) { - if (! is_array($field) || ! isset($field['type'])) { + if (!is_array($field) || !isset($field['type'])) { return $field; } $matcher = new PLL_Format_Util(); foreach ($this->get_field_labels_to_translate() as $field_type => $field_labels) { - if (! $matcher->matches($field['type'], $field_type)) { + if (!$matcher->matches($field['type'], $field_type)) { continue; } @@ -112,7 +109,7 @@ class Field_Groups } // ACF's settings pages. - $acf_post_types = array( 'acf-field-group', 'acf-post-type', 'acf-taxonomy', 'acf-ui-options-page' ); + $acf_post_types = ['acf-field-group', 'acf-post-type', 'acf-taxonomy', 'acf-ui-options-page']; if ('edit.php' === $pagenow && isset($_GET['post_type']) && in_array($_GET['post_type'], $acf_post_types, true)) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return false; @@ -132,6 +129,7 @@ class Field_Groups * * @param array $labels An array of labels to translate with label keys as array keys and label names as array values. * @param array $field A custom field definition. + * * @return array The translated labels. * * @phpstan-param LabelsMap $labels @@ -158,10 +156,10 @@ class Field_Groups * ) */ if (is_array($field_value)) { - $field[ $key ] = $this->translate_field_labels_recursive($sub_labels, $field_value); + $field[$key] = $this->translate_field_labels_recursive($sub_labels, $field_value); } } elseif ('' !== $field_value) { - $field[ $key ] = pll__($field_value); + $field[$key] = pll__($field_value); } } } @@ -176,17 +174,18 @@ class Field_Groups * not to be overridden by ACF when its local store is enabled. * * @see _acf_apply_get_local_internal_posts() - * * @since 3.7 * * @param array[] $posts An array of ACF posts. + * * @return array[] The array of ACF posts with the translated post title. */ public function translate_field_groups_labels($posts) { foreach ($posts as $key => $post) { - $posts[ $key ]['title'] = pll__($post['title']); + $posts[$key]['title'] = pll__($post['title']); } + return $posts; } @@ -197,6 +196,7 @@ class Field_Groups * @since 3.7 * * @param array $fields An array of Custom field definitions. + * * @return void */ private function register_fields($fields) @@ -216,7 +216,7 @@ class Field_Groups $matcher = new PLL_Format_Util(); foreach ($this->get_field_labels_to_translate() as $field_type => $field_labels) { - if (! is_string($field['type']) || ! $matcher->matches($field['type'], (string) $field_type)) { + if (!is_string($field['type']) || !$matcher->matches($field['type'], (string) $field_type)) { continue; } @@ -235,6 +235,7 @@ class Field_Groups * * @param array $labels An array of labels to register with label keys as array keys and label names as array values. * @param array $field A custom field definition. + * * @return void * * @phpstan-param LabelsMap $labels @@ -272,8 +273,8 @@ class Field_Groups * @since 3.7 * * @return array { - * An array with field types as array keys, and recursive sub-arrays as array values. - * These sub-arrays have label keys as array keys, and label names as array values. + * An array with field types as array keys, and recursive sub-arrays as array values. + * These sub-arrays have label keys as array keys, and label names as array values. * * Ex: * array( @@ -295,7 +296,7 @@ class Field_Groups return $this->labels; } - $labels = array( + $labels = [ 'default_value' => _x('Default value', 'ACF field setting label', 'polylang-pro'), 'placeholder' => _x('Placeholder', 'ACF field setting label', 'polylang-pro'), 'prepend' => _x('Prefix', 'ACF field setting label', 'polylang-pro'), @@ -305,94 +306,94 @@ class Field_Groups 'ui_off_text' => _x('OFF text', 'ACF field setting label', 'polylang-pro'), 'choice' => _x('Choice', 'ACF field setting label', 'polylang-pro'), 'label' => _x('Label', 'ACF field setting label', 'polylang-pro'), - ); + ]; - $this->labels = array( - '*' => array( + $this->labels = [ + '*' => [ 'label' => $labels['label'], 'instructions' => _x('Instructions', 'ACF field setting label', 'polylang-pro'), - ), - 'button_group' => array( - 'choices' => array( + ], + 'button_group' => [ + 'choices' => [ '*' => $labels['choice'], - ), - ), - 'checkbox' => array( - 'choices' => array( + ], + ], + 'checkbox' => [ + 'choices' => [ '*' => $labels['choice'], - ), - ), - 'email' => array( + ], + ], + 'email' => [ 'default_value' => $labels['default_value'], 'placeholder' => $labels['placeholder'], 'prepend' => $labels['prepend'], 'append' => $labels['append'], - ), - 'flexible_content' => array( - 'layouts' => array( - '*' => array( + ], + 'flexible_content' => [ + 'layouts' => [ + '*' => [ 'label' => $labels['label'], - ), - ), - ), - 'number' => array( + ], + ], + ], + 'number' => [ 'placeholder' => $labels['placeholder'], 'prepend' => $labels['prepend'], 'append' => $labels['append'], - ), - 'message' => array( + ], + 'message' => [ 'message' => $labels['message'], - ), - 'password' => array( + ], + 'password' => [ 'placeholder' => $labels['placeholder'], 'prepend' => $labels['prepend'], 'append' => $labels['append'], - ), - 'radio' => array( - 'choices' => array( + ], + 'radio' => [ + 'choices' => [ '*' => $labels['choice'], - ), - ), - 'range' => array( + ], + ], + 'range' => [ 'prepend' => $labels['prepend'], 'append' => $labels['append'], - ), - 'select' => array( - 'choices' => array( + ], + 'select' => [ + 'choices' => [ '*' => $labels['choice'], - ), - ), - 'text' => array( + ], + ], + 'text' => [ 'default_value' => $labels['default_value'], 'placeholder' => $labels['placeholder'], 'prepend' => $labels['prepend'], 'append' => $labels['append'], - ), - 'textarea' => array( + ], + 'textarea' => [ 'default_value' => $labels['default_value'], 'placeholder' => $labels['placeholder'], - ), - 'true_false' => array( + ], + 'true_false' => [ 'message' => $labels['message'], 'ui_on_text' => $labels['ui_on_text'], 'ui_off_text' => $labels['ui_off_text'], - ), - 'url' => array( + ], + 'url' => [ 'default_value' => $labels['default_value'], 'placeholder' => $labels['placeholder'], - ), - 'wysiwyg' => array( + ], + 'wysiwyg' => [ 'default_value' => $labels['default_value'], - ), - ); + ], + ]; /** * Filters the list of field keys to translate, by field type. * Wildcards are supported for the field types. * * @var array $labels array { - * An array with field types as array keys, and recursive sub-arrays as array values. - * These sub-arrays have label keys as array keys, and label names as array values. + * An array with field types as array keys, and recursive sub-arrays as array values. + * These sub-arrays have label keys as array keys, and label names as array values. * * Ex: * array( diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Post_Type.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Post_Type.php index 6570b6ee4d394f1222b52e0afa43fd60fbcc355f..0a20b6d003cd2529202757c58c0c947f048309ff 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Post_Type.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Labels/Post_Type.php @@ -1,13 +1,9 @@ name = 'language'; - $this->label = __('Language', 'polylang-pro'); + $this->name = 'language'; + $this->label = __('Language', 'polylang-pro'); $this->category = $this->label; // Create a new category with the same name. } @@ -38,10 +34,13 @@ class Location_Language extends ACF_Location * @param array $rule The location rule. * @param array $screen The screen args. * @param array $field_group The field group settings. - * @return bool + * + * @return bool */ public function match($rule, $screen, $field_group) // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - {$language = pll_current_language(); + { + $language = pll_current_language(); + return empty($language) || $this->compare_to_rule($language, $rule); } @@ -51,10 +50,12 @@ class Location_Language extends ACF_Location * @since 3.7 * * @param array $rule A location rule. + * * @return array */ public function get_values($rule) // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - {return array_combine(pll_languages_list(), pll_languages_list(array( 'fields' => 'name' ))); + { + return array_combine(pll_languages_list(), pll_languages_list(['fields' => 'name'])); } /** @@ -63,6 +64,7 @@ class Location_Language extends ACF_Location * @since 3.7.1 * * @param array $field_group Field group definition. + * * @return bool True if the field group has a language location rule, false otherwise. */ public static function has_language_location_rule(array $field_group): bool @@ -100,20 +102,22 @@ class Location_Language extends ACF_Location if (0 === $field['ID']) { // New field. $field_group = acf_get_field_group(0); - return ! empty($field_group) ? $field_group : array(); + + return !empty($field_group) ? $field_group : []; } if (empty($field['parent'])) { - return array(); + return []; } $field_group = acf_get_field_group($field['parent']); - if (! empty($field_group)) { + if (!empty($field_group)) { return $field_group; } // If not a field group, get parent field and continue. $parent_field = acf_get_field($field['parent']); - return $parent_field ? self::get_field_group_from_field($parent_field) : array(); + + return $parent_field ? self::get_field_group_from_field($parent_field) : []; } } diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Main.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Main.php index 8c4e37a616e9dcc988e0cc09973dc5c7f3f06a54..1b2873c22b053714c47bd4a3af5c192a206da024 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Main.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Main.php @@ -1,9 +1,5 @@ ajax = new Ajax_Lang_Choice(); - $this->field_settings = new Field_Settings(); - $this->field_groups_labels = new Field_Groups(); - $this->post_types_labels = new Post_Type(); - $this->taxonomies_labels = new Taxonomy(); + $this->ajax = new Ajax_Lang_Choice(); + $this->field_settings = new Field_Settings(); + $this->field_groups_labels = new Field_Groups(); + $this->post_types_labels = new Post_Type(); + $this->taxonomies_labels = new Taxonomy(); $this->translation_instructions = new Translation_Instructions(); } @@ -94,9 +90,9 @@ class Main acf_register_location_type(Location_Language::class); - add_filter('acf/get_taxonomies', array( $this, 'get_taxonomies' )); - add_filter('pll_get_post_types', array( $this, 'get_post_types' )); - add_action('init', array( Dispatcher::class, 'on_blocks_registered' ), 999); // Late so blocks have a chance to register, usually done on `init`. + add_filter('acf/get_taxonomies', [$this, 'get_taxonomies']); + add_filter('pll_get_post_types', [$this, 'get_post_types']); + add_action('init', [Dispatcher::class, 'on_blocks_registered'], 999); // Late so blocks have a chance to register, usually done on `init`. PLL()->model->cache->clean('post_types'); // A bit hacky. } @@ -119,11 +115,12 @@ class Main * @since 2.8 * * @param string[] $taxonomies Taxonomy names. + * * @return string[] */ public function get_taxonomies($taxonomies) { - return array_diff($taxonomies, get_taxonomies(array( '_pll' => true ))); + return array_diff($taxonomies, get_taxonomies(['_pll' => true])); } /** @@ -133,11 +130,13 @@ class Main * @since 3.7 Removed second param and disallow to translate the field groups. * * @param string[] $post_types List of post types. + * * @return string[] */ public function get_post_types($post_types) { unset($post_types['acf-field-group']); + return $post_types; } } diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Collect_Ids.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Collect_Ids.php index 0278a00bff308a1aae1e156681bd4859a447bee4..d5fc567634bc284fd4f1fde6d4a419177aaeca21 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Collect_Ids.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Collect_Ids.php @@ -1,9 +1,5 @@ linked_ids = array_merge( - $this->linked_ids, - $this->sanitize_ids($this->get_ids_from_field($value, $field)) - ); + protected function apply(Abstract_Object $object, $value, array $field, array $args = []) // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + { + $this->linked_ids = array_merge( + $this->linked_ids, + $this->sanitize_ids($this->get_ids_from_field($value, $field)) + ); return $value; } @@ -50,6 +48,7 @@ abstract class Abstract_Collect_Ids extends Abstract_Strategy * @since 3.7 * * @param array $field Custom field definition. + * * @return bool */ protected function can_execute_recursive(array $field): bool @@ -67,19 +66,20 @@ abstract class Abstract_Collect_Ids extends Abstract_Strategy * @since 3.7 * * @param int|int[]|scalar|scalar[] $value Custom field value of the source object. + * * @return int[] */ protected function sanitize_ids($value): array { if (is_numeric($value)) { - return array( (int) $value ); + return [(int) $value]; } if (is_array($value)) { return array_map('intval', $value); } - return array(); + return []; } /** @@ -88,6 +88,7 @@ abstract class Abstract_Collect_Ids extends Abstract_Strategy * @since 3.7 * * @param Translatable_Entity_Interface $object Object holding the logic to apply the strategy. + * * @return int[] */ public function get(Translatable_Entity_Interface $object): array @@ -104,6 +105,7 @@ abstract class Abstract_Collect_Ids extends Abstract_Strategy * * @param mixed $value Custom field value of the source object. * @param array $field Custom field definition. + * * @return int|int[]|scalar|scalar[] Custom field value. */ abstract protected function get_ids_from_field($value, array $field); diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Strategy.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Strategy.php index b64eae9811e3fa2a4d69ddf5d5a18835f463298a..18e0192399f1e844b53c54801b073b780e98d8a5 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Strategy.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Abstract_Strategy.php @@ -1,9 +1,5 @@ can_execute[ $key ])) { - $this->can_execute[ $key ] = $this->can_execute_recursive($field); + if (!isset($this->can_execute[$key])) { + $this->can_execute[$key] = $this->can_execute_recursive($field); } - return $this->can_execute[ $key ]; + return $this->can_execute[$key]; } /** @@ -53,17 +50,18 @@ abstract class Abstract_Strategy * @param mixed $value Custom field value of the source object. * @param array $field Custom field definition. * @param array $args { - * Array of arguments. + * Array of arguments. + * + * @var mixed $original_value Optional. The translated value of the field, if any. + * } * - * @type mixed $original_value Optional. The translated value of the field, if any. - * } * @return mixed Custom field value of the target object. */ - public function execute(Abstract_Object $object, $value, array $field, array $args = array()) + public function execute(Abstract_Object $object, $value, array $field, array $args = []) { - $args = wp_parse_args($args, array( 'original_value' => null )); + $args = wp_parse_args($args, ['original_value' => null]); - if (! $this->can_execute($field)) { + if (!$this->can_execute($field)) { return $args['original_value']; } @@ -79,20 +77,20 @@ abstract class Abstract_Strategy */ case 'flexible_content': if (is_array($value)) { - $args['original_value'] = is_array($args['original_value']) ? $args['original_value'] : array(); + $args['original_value'] = is_array($args['original_value']) ? $args['original_value'] : []; $value = $this->apply_on_layouts($object, $value, $field, $args); } break; case 'repeater': if (is_array($value)) { - $args['original_value'] = is_array($args['original_value']) ? $args['original_value'] : array(); + $args['original_value'] = is_array($args['original_value']) ? $args['original_value'] : []; $value = $this->apply_on_rows($object, $value, $field, $args); } break; case 'clone': case 'group': if (is_array($value)) { - $args['original_value'] = is_array($args['original_value']) ? $args['original_value'] : array(); + $args['original_value'] = is_array($args['original_value']) ? $args['original_value'] : []; $value = $this->apply_on_group($object, $value, $field, $args); } break; @@ -109,6 +107,7 @@ abstract class Abstract_Strategy * @since 3.7 * * @param array $field Custom field definition. + * * @return bool */ protected function can_execute_recursive(array $field): bool @@ -147,9 +146,10 @@ abstract class Abstract_Strategy * @param mixed $value Custom field value of the source object. * @param array $field Custom field definition. * @param array $args Array of arguments. + * * @return mixed Custom field value of the target object. */ - abstract protected function apply(Abstract_Object $object, $value, array $field, array $args = array()); + abstract protected function apply(Abstract_Object $object, $value, array $field, array $args = []); /** * Copies or synchronizes subfields in a repeater or flexible content field. @@ -160,13 +160,14 @@ abstract class Abstract_Strategy * @param array $values Custom field value of the source object. * @param array $field Custom field definition. * @param array $args { - * Array of arguments. + * Array of arguments. + * + * @var mixed $original_value The translated value of the field, if any. + * } * - * @type mixed $original_value The translated value of the field, if any. - * } * @return array Custom field value of the target object. */ - protected function apply_on_rows(Abstract_Object $object, array $values, array $field, array $args = array()): array + protected function apply_on_rows(Abstract_Object $object, array $values, array $field, array $args = []): array { if (empty($field['sub_fields'])) { return $values; @@ -176,14 +177,13 @@ abstract class Abstract_Strategy foreach ($field['sub_fields'] as $subfield) { foreach ($values as $row => $subvalues) { - if (! is_array($subvalues)) { + if (!is_array($subvalues)) { continue; } - - $subfield['pll_key'] = $this->get_field_key($field) . '_' . $row . '_' . $subfield['key']; // Adds an entry in `subfield` with the full path of the field. - $args['original_value'] = $original_value[ $row ] ?? null; - $values[ $row ] = $this->apply_on_subfield( + $subfield['pll_key'] = $this->get_field_key($field).'_'.$row.'_'.$subfield['key']; // Adds an entry in `subfield` with the full path of the field. + $args['original_value'] = $original_value[$row] ?? null; + $values[$row] = $this->apply_on_subfield( $object, $subvalues, $subfield, @@ -204,9 +204,10 @@ abstract class Abstract_Strategy * @param array $values Custom field value of the source object. * @param array $field Custom field definition. * @param array $args Array of arguments. + * * @return array Custom field value of the target object. */ - protected function apply_on_layouts(Abstract_Object $object, array $values, array $field, array $args = array()): array + protected function apply_on_layouts(Abstract_Object $object, array $values, array $field, array $args = []): array { if (empty($field['layouts'])) { return $values; @@ -232,13 +233,14 @@ abstract class Abstract_Strategy * @param array $values Custom field value of the source object. * @param array $field Custom field definition. * @param array $args Array of arguments. + * * @return array Custom field value of the target object. */ - protected function apply_on_group(Abstract_Object $object, array $values, array $field, array $args = array()): array + protected function apply_on_group(Abstract_Object $object, array $values, array $field, array $args = []): array { foreach ($field['sub_fields'] as $subfield) { - $subfield['pll_key'] = $this->get_field_key($subfield) . '_' . $subfield['key']; // Adds an entry in `subfield` with the full path of the field. - $values = $this->apply_on_subfield( + $subfield['pll_key'] = $this->get_field_key($subfield).'_'.$subfield['key']; // Adds an entry in `subfield` with the full path of the field. + $values = $this->apply_on_subfield( $object, $values, $subfield, @@ -258,37 +260,39 @@ abstract class Abstract_Strategy * @param array $subvalues Custom field values of the source object. * @param array $subfield Custom subfield definition. * @param array $args { - * Array of arguments. + * Array of arguments. + * + * @var mixed $original_value The translated value of the field, if any. + * } * - * @type mixed $original_value The translated value of the field, if any. - * } * @return array Custom field value of the target object. */ - protected function apply_on_subfield(Abstract_Object $object, array $subvalues, array $subfield, array $args = array()): array + protected function apply_on_subfield(Abstract_Object $object, array $subvalues, array $subfield, array $args = []): array { if (empty($subfield['parent'])) { // Not a subfield. return $subvalues; } - if (! $this->can_execute($subfield)) { - if (isset($args['original_value'][ $subfield['key'] ])) { + if (!$this->can_execute($subfield)) { + if (isset($args['original_value'][$subfield['key']])) { // If original values are hold with field key. - $subvalues[ $subfield['key'] ] = $args['original_value'][ $subfield['key'] ]; - } elseif (isset($args['original_value'][ $subfield['name'] ])) { + $subvalues[$subfield['key']] = $args['original_value'][$subfield['key']]; + } elseif (isset($args['original_value'][$subfield['name']])) { // If original values are hold with field name. - $subvalues[ $subfield['name'] ] = $args['original_value'][ $subfield['name'] ]; + $subvalues[$subfield['name']] = $args['original_value'][$subfield['name']]; } else { // Strip out the subfield if it can't be executed so the value won't be processed. - unset($subvalues[ $subfield['name'] ], $subvalues[ $subfield['key'] ]); + unset($subvalues[$subfield['name']], $subvalues[$subfield['key']]); } + return $subvalues; } - if (isset($subvalues[ $subfield['name'] ])) { + if (isset($subvalues[$subfield['name']])) { // Is the group value update with field name as key? $selector = $subfield['name']; - } elseif (isset($subvalues[ $subfield['key'] ])) { + } elseif (isset($subvalues[$subfield['key']])) { // Is the group value update with field key as key? $selector = $subfield['key']; } @@ -297,11 +301,11 @@ abstract class Abstract_Strategy return $subvalues; } - $args['original_value'] = $args['original_value'][ $selector ] ?? null; + $args['original_value'] = $args['original_value'][$selector] ?? null; - $subvalues[ $selector ] = $this->execute( + $subvalues[$selector] = $this->execute( $object, - $subvalues[ $selector ], + $subvalues[$selector], $subfield, $args ); @@ -316,6 +320,7 @@ abstract class Abstract_Strategy * @since 3.7 * * @param array $field Field definition. + * * @return string Field key. */ protected function get_field_key(array $field): string diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Collect_Post_Ids.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Collect_Post_Ids.php index 3797562788c64572b77ddee59121af4e0e02d5d6..c8438951fe8ebe8935cb7b749ced9e61ba5859c9 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Collect_Post_Ids.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Collect_Post_Ids.php @@ -1,9 +1,5 @@ translate_post($value, $args['target_language']); } break; case 'taxonomy': - if (! is_array($value) && ! (is_numeric($value) && ! is_float($value))) { + if (!is_array($value) && !(is_numeric($value) && !is_float($value))) { break; } if (pll_is_translated_taxonomy($field['taxonomy'])) { @@ -79,7 +76,6 @@ class Copy extends Abstract_Strategy null, $args['target_language'] ); - } break; } @@ -94,18 +90,18 @@ class Copy extends Abstract_Strategy * * @param mixed $value Custom field value of the source object. * @param array $field Custom field definition. - * @param array $args { - * Array of arguments. + * @param array $args { + * Array of arguments. * - * @type PLL_Language $source_language Optional. The language object of the source object. - * @type mixed $original_value Optional. The translated value of the field, if any. - * } + * @var PLL_Language $source_language Optional. The language object of the source object. + * @var mixed $original_value Optional. The translated value of the field, if any. + * } * * @return mixed Custom field value of the target object. */ - protected function maybe_translate_field_default_value($value, array $field, array $args = array()) + protected function maybe_translate_field_default_value($value, array $field, array $args = []) { - if (! isset($field['pll_default_value'], $args['source_language']) || ! $args['source_language'] instanceof PLL_Language) { + if (!isset($field['pll_default_value'], $args['source_language']) || !$args['source_language'] instanceof PLL_Language) { return $value; } @@ -120,6 +116,7 @@ class Copy extends Abstract_Strategy * @since 3.7 * * @param array $field Custom field definition. + * * @return bool */ protected function can_execute_recursive(array $field): bool @@ -138,6 +135,7 @@ class Copy extends Abstract_Strategy * * @param int $value Custom field value of the source object. * @param PLL_Language $lang Language object of the target object. + * * @return int Custom field value of the target object. */ protected function translate_media(int $value, PLL_Language $lang): int @@ -158,14 +156,16 @@ class Copy extends Abstract_Strategy * * @param int[] $values Custom field value of the source object. * @param PLL_Language $lang Language object of the target object. + * * @return string[] Custom field value of the target object. * * @phpstan-param array $values + * * @phpstan-return list */ protected function translate_gallery(array $values, PLL_Language $lang): array { - $return = array(); + $return = []; foreach ($values as $value) { $return[] = $this->translate_media((int) $value, $lang); @@ -182,9 +182,11 @@ class Copy extends Abstract_Strategy * * @param int|int[] $value Custom field value of the source object. * @param PLL_Language $lang Language object of the target object. + * * @return int|string[] Custom field value of the target object. * * @phpstan-param int|numeric-string|array $value + * * @phpstan-return ( * $value is array ? list : int * ) @@ -192,10 +194,10 @@ class Copy extends Abstract_Strategy protected function translate_post($value, PLL_Language $lang) { if (is_numeric($value)) { - $value = (int) $value; + $value = (int) $value; $post_type = get_post_type($value); - if (! $post_type || ! pll_is_translated_post_type($post_type)) { + if (!$post_type || !pll_is_translated_post_type($post_type)) { // Same ID for not-translated languages. return $value; } @@ -204,10 +206,11 @@ class Copy extends Abstract_Strategy } if (is_array($value)) { - $return = array(); + $return = []; foreach ($value as $id) { $return[] = $this->translate_post($id, $lang); } + /** @phpstan-var list */ return array_map('strval', $return); // See the method update_value() for these fields. } @@ -223,9 +226,11 @@ class Copy extends Abstract_Strategy * * @param int|int[] $value Custom field value of the source object. * @param PLL_Language $lang Language object of the target object. + * * @return int|int[] Custom field value of the target object. * * @phpstan-param int|numeric-string|array $value + * * @phpstan-return ( * $value is array ? list : int * ) @@ -237,10 +242,11 @@ class Copy extends Abstract_Strategy } if (is_array($value)) { - $return = array(); + $return = []; foreach ($value as $id) { $return[] = $this->translate_term($id, $lang); } + return $return; } @@ -255,6 +261,7 @@ class Copy extends Abstract_Strategy * * @param int|string|(int|string)[] $value Custom field value of the source object. * @param PLL_Language $lang Language slug of the target object. + * * @return int|string|string[] Custom field value of the target object. */ protected function translate_page_link($value, PLL_Language $lang) @@ -265,7 +272,7 @@ class Copy extends Abstract_Strategy if (is_array($value)) { // Multiple choices. - $return = array(); + $return = []; foreach ($value as $p) { if (is_numeric($p)) { $return[] = (int) pll_get_post((int) $p, $lang); @@ -273,6 +280,7 @@ class Copy extends Abstract_Strategy $return[] = $this->translate_cpt_archive_link($p, $lang); // Archive. } } + return array_map('strval', $return); // See `acf_field_page_link::update_value()`. } @@ -287,6 +295,7 @@ class Copy extends Abstract_Strategy * * @param string $link CPT archive link. * @param PLL_Language $lang Language object of the target object. + * * @return string Modified link. */ protected function translate_cpt_archive_link(string $link, PLL_Language $lang): string @@ -300,18 +309,19 @@ class Copy extends Abstract_Strategy $link = home_url('/'); } - $show_on_front = get_option('show_on_front'); + $show_on_front = get_option('show_on_front'); $page_for_posts = get_option('page_for_posts'); if ('page' === $show_on_front && is_numeric($page_for_posts)) { // Gets `page_for_posts` URL of the target language. $post_archive_link = get_permalink($lang->page_for_posts); - return ! empty($post_archive_link) ? $post_archive_link : $link; + + return !empty($post_archive_link) ? $post_archive_link : $link; } $link = PLL()->links_model->switch_language_in_link($link, $lang); - if (! isset(PLL()->translate_slugs)) { + if (!isset(PLL()->translate_slugs)) { return $link; } diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Copy_All.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Copy_All.php index aa465cadc8a1ffcc60b02647dc4299dcd5976dea..278c55969da946060da7cfcf024ca4c0bd5a6384 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Copy_All.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Copy_All.php @@ -1,9 +1,5 @@ model->{$object->get_type()}->get($object->get_id(), $args['target_language'])) { @@ -60,19 +58,19 @@ class Export extends Abstract_Strategy return $value; } - if (! is_string($value) || empty($value)) { + if (!is_string($value) || empty($value)) { return $value; } $original_value = is_string($args['original_value']) ? $args['original_value'] : ''; $this->export->add_translation_entry( - array( + [ 'object_type' => $object->get_type(), 'field_type' => 'acf', 'field_id' => $this->get_field_key($field), 'object_id' => $object->get_id(), - ), + ], $value, $original_value === $field['default_value'] ? '' : $original_value // Do not export translated default values. ); @@ -86,11 +84,12 @@ class Export extends Abstract_Strategy * @since 3.7 * * @param array $field Custom field definition. + * * @return bool */ protected function can_execute_recursive(array $field): bool { - if (isset($field['translations']) && in_array($field['translations'], array( 'translate', 'translate_once' ), true)) { + if (isset($field['translations']) && in_array($field['translations'], ['translate', 'translate_once'], true)) { return true; } diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Import.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Import.php index db8723218322a10c1495a2edcf8b94c05d1c932b..ad204d1371a0201a27f04d1ea93194a525c13676 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Import.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Import.php @@ -1,21 +1,17 @@ null )); + $args = wp_parse_args($args, ['original_value' => null]); - if (! $this->can_execute($field)) { + if (!$this->can_execute($field)) { return $args['original_value']; } @@ -70,31 +68,31 @@ class Import extends Copy return $value; } - if (! is_string($value)) { + if (!is_string($value)) { return parent::execute($object, $value, $field, $args); } $args['original_value'] = is_string($args['original_value']) ? $args['original_value'] : ''; $entry = new Translation_Entry( - array( + [ 'singular' => $value, 'context' => Context::to_string( - array( + [ Context::FIELD => 'acf', Context::ID => $this->get_field_key($field), - ) + ] ), - ) + ] ); /* * Use `translate_entry()` to know whether the entry is in the translation set or not. * Because `translate()` doesn't return false but the source string if the entry doesn't exist. */ - if (! $this->translations->translate_entry($entry)) { + if (!$this->translations->translate_entry($entry)) { // The entry is not in the translation set. - if ('translate_once' === $field['translations'] && ! empty($args['original_value'])) { + if ('translate_once' === $field['translations'] && !empty($args['original_value'])) { /* * If there is no entry in the translation set and the field is set to `translate_once`, * it means that it has already been translated. diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Synchronize.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Synchronize.php index 0ff82e5b9dfb438a2d3a70790bd78f1e225ddbd0..cf603b238814f63f7b9f42d74f56315e76ff091d 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Synchronize.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Strategy/Synchronize.php @@ -1,9 +1,5 @@ null )); + $args = wp_parse_args($args, ['original_value' => null]); - if (! $this->can_execute($field)) { + if (!$this->can_execute($field)) { return $args['original_value']; } @@ -66,19 +63,19 @@ class Synchronize extends Copy return parent::execute($object, $value, $field, $args); } - if (! isset($args['target_language']) || ! $args['target_language'] instanceof PLL_Language) { + if (!isset($args['target_language']) || !$args['target_language'] instanceof PLL_Language) { return $value; } - if (! pll_is_translated_taxonomy($field['taxonomy']) - || ! in_array($field['taxonomy'], get_object_taxonomies($object->get_type()), true)) { + if (!pll_is_translated_taxonomy($field['taxonomy']) + || !in_array($field['taxonomy'], get_object_taxonomies($object->get_type()), true)) { // Do not go any further if a taxonomy is not registered for the current object type. return $value; } $value = $this->translate_term($value, $args['target_language']); - if (! empty($field['save_terms']) && isset($args['target_id'])) { + if (!empty($field['save_terms']) && isset($args['target_id'])) { /* * Save terms for the target object. * @@ -98,6 +95,7 @@ class Synchronize extends Copy * @since 3.7 * * @param array $field Custom field definition. + * * @return bool */ protected function can_execute_recursive(array $field): bool @@ -150,15 +148,16 @@ class Synchronize extends Copy * @param array $values Custom field value of the source object. * @param array $field Custom field definition. * @param array $args { - * Array of arguments. + * Array of arguments. + * + * @var PLL_Language $target_language Language object of the target object. + * @var array $original_value The value to return if the field must not be synced/copied. Basically it's + * the field's original value. + * } * - * @type PLL_Language $target_language Language object of the target object. - * @type array $original_value The value to return if the field must not be synced/copied. Basically it's - * the field's original value. - * } * @return array Custom field value of the target object. */ - protected function apply_on_rows(Abstract_Object $object, array $values, array $field, array $args = array()): array + protected function apply_on_rows(Abstract_Object $object, array $values, array $field, array $args = []): array { if (empty($field['sub_fields'])) { return $values; @@ -168,37 +167,37 @@ class Synchronize extends Copy foreach ($values as $row => $subvalues) { if (preg_match('/^row-(?.+)$/', (string) $row, $matches)) { // Row already exists, let's update it. - if (! is_array($subvalues)) { + if (!is_array($subvalues)) { continue; } - $i = $matches['incr']; - $parent = $this->get_field_key($field); - $subfield['pll_key'] = $parent . '_' . $i . '_' . $subfield['key']; // Adds an entry in `subfield` with the full path of the field. - $values[ $row ] = $this->apply_on_subfield( + $i = $matches['incr']; + $parent = $this->get_field_key($field); + $subfield['pll_key'] = $parent.'_'.$i.'_'.$subfield['key']; // Adds an entry in `subfield` with the full path of the field. + $values[$row] = $this->apply_on_subfield( $object, $subvalues, $subfield, - array( + [ 'target_language' => $args['target_language'], - 'original_value' => $args['original_value'][ $i ] ?? null, - ) + 'original_value' => $args['original_value'][$i] ?? null, + ] ); continue; } // New row added, let's copy it. - $parent = $this->get_field_key($field); - $subfield['pll_key'] = $parent . '_' . $row . '_' . $subfield['key']; // Adds an entry in `subfield` with the full path of the field. - $values[ $row ] = $this->copy->apply_on_subfield( + $parent = $this->get_field_key($field); + $subfield['pll_key'] = $parent.'_'.$row.'_'.$subfield['key']; // Adds an entry in `subfield` with the full path of the field. + $values[$row] = $this->copy->apply_on_subfield( $object, $subvalues, $subfield, - array( + [ 'target_language' => $args['target_language'], 'original_value' => null, - ) + ] ); } } diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/Translation_Instructions.php b/__plugins/polylang-pro-3.7.6/integrations/acf/Translation_Instructions.php index c31956c463becf25e45614dbe62b9465eedc166a..626f5f91b4e11d92f99bdb4ccc700503e980fd94 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/Translation_Instructions.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/Translation_Instructions.php @@ -1,9 +1,5 @@ 'no_translations_settings', 'required' => 0, 'label' => esc_html__('No translations settings', 'polylang-pro'), 'instructions' => esc_html__('No translations settings are available for field group with language location rules.', 'polylang-pro'), - ); + ]; acf_render_field_instructions($no_translations_settings); + return; } - if ($is_legacy_translated_field_group && ! isset($field_group[ self::SETTING_KEY ])) { - $field_group[ self::SETTING_KEY ] = 1; + if ($is_legacy_translated_field_group && !isset($field_group[self::SETTING_KEY])) { + $field_group[self::SETTING_KEY] = 1; } acf_render_field_wrap( - array( + [ 'label' => esc_html__('Display translation field instructions', 'polylang-pro'), 'instructions' => esc_html__('When enabled, the translation field instructions will be displayed below the field label.', 'polylang-pro'), 'type' => 'true_false', 'name' => self::SETTING_KEY, 'prefix' => 'acf_field_group', - 'value' => $field_group[ self::SETTING_KEY ] ?? 1, + 'value' => $field_group[self::SETTING_KEY] ?? 1, 'ui' => 1, - ) + ] ); } @@ -100,11 +99,12 @@ class Translation_Instructions * @since 3.7.2 Moved from Dispatcher. * * @param array $fields The fields being rendered. + * * @return array The fields. */ public static function append_translation_instructions($fields) { - add_filter('acf/prepare_field', array( static::class, 'get_field_instructions' )); + add_filter('acf/prepare_field', [static::class, 'get_field_instructions']); return $fields; } @@ -116,23 +116,24 @@ class Translation_Instructions * @since 3.7.2 Moved from Dispatcher. * * @param array|false $field The field array or false. + * * @return array|false The field array or false. */ public static function get_field_instructions($field) { - if (! is_array($field)) { + if (!is_array($field)) { return $field; } $field_group = acf_get_field_group($field['parent']); - if (! $field_group || ! isset($field_group[ self::SETTING_KEY ]) || ! $field_group[ self::SETTING_KEY ]) { + if (!$field_group || !isset($field_group[self::SETTING_KEY]) || !$field_group[self::SETTING_KEY]) { return $field; } $instructions = ' ' - . self::get_field_instruction($field); + .self::get_field_instruction($field); - $field['instructions'] = ! empty($field['instructions']) ? $field['instructions'] . '
' . $instructions : $instructions; + $field['instructions'] = !empty($field['instructions']) ? $field['instructions'].'
'.$instructions : $instructions; return $field; } @@ -145,6 +146,7 @@ class Translation_Instructions * @since 3.7.5 Changed visibility from private to public. * * @param array $field The field. + * * @return string The instruction. */ public static function get_field_instruction(array $field): string @@ -154,7 +156,7 @@ class Translation_Instructions } if (empty($field['translations'])) { - if (in_array($field['type'], array( 'group', 'repeater', 'clone', 'flexible_content' ), true)) { + if (in_array($field['type'], ['group', 'repeater', 'clone', 'flexible_content'], true)) { $copy_strategy = new Copy(); if ($copy_strategy->can_execute($field)) { return __('This field is copied.', 'polylang-pro'); diff --git a/__plugins/polylang-pro-3.7.6/integrations/acf/load.php b/__plugins/polylang-pro-3.7.6/integrations/acf/load.php index b12a45b2dad7a3ff9bf7781948c707271316a216..19c6fcf6c80cf042a9bcd13c0d9fbe09c89cf38b 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/acf/load.php +++ b/__plugins/polylang-pro-3.7.6/integrations/acf/load.php @@ -1,14 +1,10 @@ model->has_languages()) { + if (!did_action('pll_init') || !PLL()->model->has_languages()) { // Run only if Polylang (and its API) is loaded, and if there is at least one language. return; } PLL_Integrations::instance()->acf = new Main(); - add_action('acf/init', array( PLL_Integrations::instance()->acf, 'on_acf_init' )); + add_action('acf/init', [PLL_Integrations::instance()->acf, 'on_acf_init']); } ); diff --git a/__plugins/polylang-pro-3.7.6/integrations/admin-columns/cpac.php b/__plugins/polylang-pro-3.7.6/integrations/admin-columns/cpac.php index 9d18841082caf6bd5bd2a7024b8febd9a3e996c6..5ff8818c95ed1556c1bc1865376a6765b2bcb30b 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/admin-columns/cpac.php +++ b/__plugins/polylang-pro-3.7.6/integrations/admin-columns/cpac.php @@ -1,9 +1,5 @@ model->get_translated_post_types() as $type) { if (isset($_REQUEST['list_screen'])) { // phpcs:ignore WordPress.Security.NonceVerification - $filter = 'manage_' . ('attachment' === $type ? 'upload' : 'edit-' . $type) . '_columns'; - add_filter($filter, array( $this, 'remove_filter_lang' ), 90); // Before Polylang. + $filter = 'manage_'.('attachment' === $type ? 'upload' : 'edit-'.$type).'_columns'; + add_filter($filter, [$this, 'remove_filter_lang'], 90); // Before Polylang. } - $filter = 'option_cpac_options_' . ('attachment' === $type ? 'wp-media' : $type) . '__default'; - add_filter($filter, array( $this, 'filter_default_columns' )); + $filter = 'option_cpac_options_'.('attachment' === $type ? 'wp-media' : $type).'__default'; + add_filter($filter, [$this, 'filter_default_columns']); } } @@ -38,11 +34,13 @@ class PLL_CPAC * @since 2.4 * * @param array $columns List of table columns. + * * @return array */ public function remove_filter_lang($columns) { PLL()->filters_columns->filter_lang = ''; + return $columns; } @@ -52,6 +50,7 @@ class PLL_CPAC * @since 2.4 * * @param array $columns List of table columns. + * * @return array */ public function filter_default_columns($columns) @@ -59,12 +58,12 @@ class PLL_CPAC $screen = get_current_screen(); if (isset($screen->base)) { - $is_post_type = 'edit' === $screen->base && has_filter('manage_edit-' . $screen->post_type . '_columns', array( PLL()->filters_columns, 'add_post_column' )); - $is_media = 'upload' === $screen->base && has_filter('manage_upload_columns', array( PLL()->filters_columns, 'add_post_column' )); + $is_post_type = 'edit' === $screen->base && has_filter('manage_edit-'.$screen->post_type.'_columns', [PLL()->filters_columns, 'add_post_column']); + $is_media = 'upload' === $screen->base && has_filter('manage_upload_columns', [PLL()->filters_columns, 'add_post_column']); if ($is_post_type || $is_media) { foreach (pll_languages_list() as $lang) { - unset($columns[ 'language_' . $lang ]); + unset($columns['language_'.$lang]); } $columns = PLL()->filters_columns->add_post_column($columns); diff --git a/__plugins/polylang-pro-3.7.6/integrations/admin-columns/load.php b/__plugins/polylang-pro-3.7.6/integrations/admin-columns/load.php index 2247d39064e4b24bff7875801184459095fe2935..993d46da751f94271d25ba91d0313ec70faa43bc 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/admin-columns/load.php +++ b/__plugins/polylang-pro-3.7.6/integrations/admin-columns/load.php @@ -1,10 +1,6 @@ cpac = new PLL_CPAC(), 'init' )); + add_action('admin_init', [PLL_Integrations::instance()->cpac = new PLL_CPAC(), 'init']); } } ); diff --git a/__plugins/polylang-pro-3.7.6/integrations/beaver-builder/flbuilder.php b/__plugins/polylang-pro-3.7.6/integrations/beaver-builder/flbuilder.php index 017ab15b77535d8268c0ecbce3aae837dbfd93ae..bcf1503421f1c961e2843c3fcf72b8e32879fde5 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/beaver-builder/flbuilder.php +++ b/__plugins/polylang-pro-3.7.6/integrations/beaver-builder/flbuilder.php @@ -1,9 +1,5 @@ content_blocks = new PLL_Content_Blocks(), 'init' )); + add_action('pll_init', [PLL_Integrations::instance()->content_blocks = new PLL_Content_Blocks(), 'init']); } }, 0 diff --git a/__plugins/polylang-pro-3.7.6/integrations/cptui/cptui.php b/__plugins/polylang-pro-3.7.6/integrations/cptui/cptui.php index 9f38972df280d1504c1e516a009dbfec27547235..33cd51357e0c10d6eac010945deb8c004f6339c3 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/cptui/cptui.php +++ b/__plugins/polylang-pro-3.7.6/integrations/cptui/cptui.php @@ -1,9 +1,5 @@ array( + $keys = [ + '*' => [ 'label' => 1, 'singular_label' => 1, 'description' => 1, - 'labels' => array( + 'labels' => [ '*' => 1, - ), - ), - ); + ], + ], + ]; - new PLL_Translate_Option('cptui_post_types', $keys, array( 'context' => 'CPT UI' )); - new PLL_Translate_Option('cptui_taxonomies', $keys, array( 'context' => 'CPT UI' )); + new PLL_Translate_Option('cptui_post_types', $keys, ['context' => 'CPT UI']); + new PLL_Translate_Option('cptui_taxonomies', $keys, ['context' => 'CPT UI']); - if (PLL() instanceof PLL_Frontend && ! PLL()->options['force_lang']) { + if (PLL() instanceof PLL_Frontend && !PLL()->options['force_lang']) { // Special case when the language is set from the content as CPT and taxonomies are registered before the language is defined. - add_action('pll_language_defined', array( $this, 'pll_language_defined' )); + add_action('pll_language_defined', [$this, 'pll_language_defined']); } - // Add CPT UI post types and taxonomies to Polylang settings. - add_filter('pll_get_post_types', array( $this, 'pll_get_types' ), 10, 2); - add_filter('pll_get_taxonomies', array( $this, 'pll_get_types' ), 10, 2); + add_filter('pll_get_post_types', [$this, 'pll_get_types'], 10, 2); + add_filter('pll_get_taxonomies', [$this, 'pll_get_types'], 10, 2); } /** @@ -58,7 +53,7 @@ class PLL_CPTUI { foreach ($types as $name => $type) { if (in_array($name, $cptui_types)) { - $type->label = pll__($type->label); + $type->label = pll__($type->label); $type->description = pll__($type->description); foreach (array_keys(get_object_vars($type->labels)) as $key) { @@ -75,8 +70,8 @@ class PLL_CPTUI */ public function pll_language_defined() { - $this->translate_registered_types($GLOBALS['wp_post_types'], array_keys(get_option('cptui_post_types', array()))); - $this->translate_registered_types($GLOBALS['wp_taxonomies'], array_keys(get_option('cptui_taxonomies', array()))); + $this->translate_registered_types($GLOBALS['wp_post_types'], array_keys(get_option('cptui_post_types', []))); + $this->translate_registered_types($GLOBALS['wp_taxonomies'], array_keys(get_option('cptui_taxonomies', []))); } /** @@ -86,18 +81,20 @@ class PLL_CPTUI * * @param string[] $types List of post type or taxonomy names. * @param bool $is_settings True when displaying the list in Polylang settings. + * * @return string[] */ public function pll_get_types($types, $is_settings) { if ($is_settings) { - $type = substr(current_filter(), 8); + $type = substr(current_filter(), 8); $cptui_types = get_option("cptui_{$type}"); if (is_array($cptui_types)) { $types = array_merge($types, array_keys($cptui_types)); } } + return $types; } } diff --git a/__plugins/polylang-pro-3.7.6/integrations/cptui/load.php b/__plugins/polylang-pro-3.7.6/integrations/cptui/load.php index 6544896a968498c379684020e18306156dea3a98..ad685d4887124090c4e77b45683d7423f5b01752 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/cptui/load.php +++ b/__plugins/polylang-pro-3.7.6/integrations/cptui/load.php @@ -1,10 +1,6 @@ cptui = new PLL_CPTUI(), 'init' )); + add_action('pll_init', [PLL_Integrations::instance()->cptui = new PLL_CPTUI(), 'init']); } }, 0 diff --git a/__plugins/polylang-pro-3.7.6/integrations/divi/divi-builder.php b/__plugins/polylang-pro-3.7.6/integrations/divi/divi-builder.php index 57a8733a361b4a0de8bc801ab3fd714f15d0b4be..d68316d8f28fb6d78c04c2528f728f1969c82c93 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/divi/divi-builder.php +++ b/__plugins/polylang-pro-3.7.6/integrations/divi/divi-builder.php @@ -1,9 +1,5 @@ divi_builder = new PLL_Divi_Builder(); } } diff --git a/__plugins/polylang-pro-3.7.6/integrations/events-calendar/load.php b/__plugins/polylang-pro-3.7.6/integrations/events-calendar/load.php index fda04207dff21b7f55dc9dcc86a8fc009af1d3c9..9d0f669c039dfffd0b6b444ebb12b43f2b3b0ead 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/events-calendar/load.php +++ b/__plugins/polylang-pro-3.7.6/integrations/events-calendar/load.php @@ -1,10 +1,6 @@ tec = new PLL_TEC(), 'init' )); + add_action('pll_init', [PLL_Integrations::instance()->tec = new PLL_TEC(), 'init']); } }, 0 diff --git a/__plugins/polylang-pro-3.7.6/integrations/events-calendar/tec.php b/__plugins/polylang-pro-3.7.6/integrations/events-calendar/tec.php index 5b0394a18788bc8b360ef0ba97e0d20896800fc8..73f4dfa151e943d6bece85ca4463d6fc363e3e14 100644 --- a/__plugins/polylang-pro-3.7.6/integrations/events-calendar/tec.php +++ b/__plugins/polylang-pro-3.7.6/integrations/events-calendar/tec.php @@ -1,17 +1,13 @@ model->has_languages()) { + if (!$polylang->model->has_languages()) { return; } - $this->polylang = $polylang; - $this->curlang = null; - $this->slugs_model = ! empty($polylang->translate_slugs) && ! empty($polylang->translate_slugs->slugs_model) ? $polylang->translate_slugs->slugs_model : null; - $this->is_tec_rest_request = array(); - $this->translatable_slug_ids = array(); + $this->polylang = $polylang; + $this->curlang = null; + $this->slugs_model = !empty($polylang->translate_slugs) && !empty($polylang->translate_slugs->slugs_model) ? $polylang->translate_slugs->slugs_model : null; + $this->is_tec_rest_request = []; + $this->translatable_slug_ids = []; if ($polylang->links instanceof PLL_Admin_Links) { $this->links = $polylang->links; } - add_filter('pll_get_taxonomies', array( $this, 'translate_taxonomies' ), 10, 2); - add_filter('pll_get_post_types', array( $this, 'translate_types' ), 10, 2); + add_filter('pll_get_taxonomies', [$this, 'translate_taxonomies'], 10, 2); + add_filter('pll_get_post_types', [$this, 'translate_types'], 10, 2); - add_action('save_post_' . Venue::POSTTYPE, array( $this, 'set_language' ), 10, 3); - add_action('save_post_' . Organizer::POSTTYPE, array( $this, 'set_language' ), 10, 3); + add_action('save_post_'.Venue::POSTTYPE, [$this, 'set_language'], 10, 3); + add_action('save_post_'.Organizer::POSTTYPE, [$this, 'set_language'], 10, 3); $tec = TEC::instance(); if (empty($polylang->options['force_lang'])) { - add_action('pll_language_defined', array( $this, 'fix_date_translations' )); + add_action('pll_language_defined', [$this, 'fix_date_translations']); } - self::$metas = array_merge($tec->metaTags, $tec->venueTags, $tec->organizerTags, array( '_VenueShowMap', '_VenueShowMapLink' )); + self::$metas = array_merge($tec->metaTags, $tec->venueTags, $tec->organizerTags, ['_VenueShowMap', '_VenueShowMapLink']); - if (! empty($this->links) && ! empty($GLOBALS['post'])) { + if (!empty($this->links) && !empty($GLOBALS['post'])) { $data = $this->links->get_data_from_new_post_translation_request($GLOBALS['post']->post_type); - if (! empty($data)) { + if (!empty($data)) { // Default values for events. foreach (self::$metas as $meta) { - $filter = str_replace(array( '_Event', '_Organizer', '_Venue' ), array( '', 'Organizer', 'Venue' ), $meta); - add_filter('tribe_get_meta_default_value_' . $filter, array( $this, 'copy_event_meta' ), 10, 4); // Since TEC 4.0.7. + $filter = str_replace(['_Event', '_Organizer', '_Venue'], ['', 'Organizer', 'Venue'], $meta); + add_filter('tribe_get_meta_default_value_'.$filter, [$this, 'copy_event_meta'], 10, 4); // Since TEC 4.0.7. } - add_filter('tribe_display_event_linked_post_dropdown_id', array( $this, 'translate_linked_post' )); + add_filter('tribe_display_event_linked_post_dropdown_id', [$this, 'translate_linked_post']); } } - add_action('pre_get_posts', array( $this, 'pre_get_posts' ), 60); // After `Tribe__Events__Query->pre_get_posts()`. + add_action('pre_get_posts', [$this, 'pre_get_posts'], 60); // After `Tribe__Events__Query->pre_get_posts()`. - add_filter('pll_copy_post_metas', array( $this, 'copy_post_metas' )); - add_filter('pll_translate_post_meta', array( $this, 'translate_meta' ), 10, 3); + add_filter('pll_copy_post_metas', [$this, 'copy_post_metas']); + add_filter('pll_translate_post_meta', [$this, 'translate_meta'], 10, 3); // Translate links with translated slugs - add_action('init', array( $this, 'reset_slugs' ), 11); // Just after `Tribe__Events__Main->init()`. - add_filter('register_taxonomy_args', array( $this, 'register_taxonomy_args' ), 10, 2); - add_filter('tribe_events_get_link', array( $this, 'get_link' )); - add_filter('pll_get_archive_url', array( $this, 'pll_get_archive_url' ), 10, 2); - add_filter('pll_term_link', array( $this, 'filter_tec_term_link' ), 5, 3); // Before `PLL_Translate_Slugs->pll_term_link()`. - add_filter('pll_translated_slugs', array( $this, 'pll_translated_slugs' ), 10, 3); - add_filter('pll_sanitize_string_translation', array( $this, 'sanitize_string_translation' ), 10, 2); - add_filter('tribe_events_rewrite_i18n_slugs_raw', array( $this, 'rewrite_slugs' )); + add_action('init', [$this, 'reset_slugs'], 11); // Just after `Tribe__Events__Main->init()`. + add_filter('register_taxonomy_args', [$this, 'register_taxonomy_args'], 10, 2); + add_filter('tribe_events_get_link', [$this, 'get_link']); + add_filter('pll_get_archive_url', [$this, 'pll_get_archive_url'], 10, 2); + add_filter('pll_term_link', [$this, 'filter_tec_term_link'], 5, 3); // Before `PLL_Translate_Slugs->pll_term_link()`. + add_filter('pll_translated_slugs', [$this, 'pll_translated_slugs'], 10, 3); + add_filter('pll_sanitize_string_translation', [$this, 'sanitize_string_translation'], 10, 2); + add_filter('tribe_events_rewrite_i18n_slugs_raw', [$this, 'rewrite_slugs']); // Options to translate. - $keys = array( + $keys = [ 'dateWithYearFormat' => 1, 'dateWithoutYearFormat' => 1, 'monthAndYearFormat' => 1, @@ -140,34 +137,34 @@ class PLL_TEC 'timeRangeSeparator' => 1, 'tribeEventsBeforeHTML' => 1, 'tribeEventsAfterHTML' => 1, - ); + ]; - $args = array( + $args = [ 'context' => 'The Events Calendar', - 'sanitize_callback' => array( $this, 'sanitize_strings' ), - ); + 'sanitize_callback' => [$this, 'sanitize_strings'], + ]; new PLL_Translate_Option('tribe_events_calendar_options', $keys, $args); // TEC views V2. add_filter('tribe_events_rewrite_i18n_domains', '__return_empty_array', 10000); // No i18n domains, no translations to deal with. - add_filter('tribe_events_rewrite_i18n_slugs', array( $this, 'fix_escaped_dashes_in_slugs' ), 10, 2); + add_filter('tribe_events_rewrite_i18n_slugs', [$this, 'fix_escaped_dashes_in_slugs'], 10, 2); - add_filter('tribe_events_category_slug', array( $this, 'get_category_slug' )); - add_filter('tribe_events_tag_slug', array( $this, 'get_tag_slug' )); + add_filter('tribe_events_category_slug', [$this, 'get_category_slug']); + add_filter('tribe_events_tag_slug', [$this, 'get_tag_slug']); - add_filter('tribe_events_views_v2_endpoint_url', array( $this, 'add_missing_lang_to_rest_url' )); - add_filter('locale', array( $this, 'filter_locale_for_rest' ), 5); + add_filter('tribe_events_views_v2_endpoint_url', [$this, 'add_missing_lang_to_rest_url']); + add_filter('locale', [$this, 'filter_locale_for_rest'], 5); - add_filter('tribe_events_views_v2_publicly_visible_views_query_args', array( $this, 'add_language_to_publicly_visible_views_query_args' ), 5); - add_filter('tribe_events_views_v2_view_template_vars', array( $this, 'translate_widget_view_more_link' ), 5); - add_filter('tribe_rewrite_parse_query_vars', array( $this, 'force_language_on_tec_parse_query_vars' ), 10, 3); - add_filter('tribe_events_views_v2_url_query_args', array( $this, 'add_missing_lang_to_query_arg' )); - add_filter('tribe_rewrite_pre_canonical_url', array( $this, 'add_missing_lang_to_non_canonical_url' ), 10, 2); - add_filter('tribe_rewrite_pre_canonical_url', array( $this, 'remove_name_arg_from_non_canonical_url' ), 10, 2); + add_filter('tribe_events_views_v2_publicly_visible_views_query_args', [$this, 'add_language_to_publicly_visible_views_query_args'], 5); + add_filter('tribe_events_views_v2_view_template_vars', [$this, 'translate_widget_view_more_link'], 5); + add_filter('tribe_rewrite_parse_query_vars', [$this, 'force_language_on_tec_parse_query_vars'], 10, 3); + add_filter('tribe_events_views_v2_url_query_args', [$this, 'add_missing_lang_to_query_arg']); + add_filter('tribe_rewrite_pre_canonical_url', [$this, 'add_missing_lang_to_non_canonical_url'], 10, 2); + add_filter('tribe_rewrite_pre_canonical_url', [$this, 'remove_name_arg_from_non_canonical_url'], 10, 2); - add_filter('tribe_rewrite_canonical_url', array( $this, 'fix_language_in_canonical_url' ), 5, 2); - add_filter('tribe_rewrite_canonical_url', array( $this, 'translate_canonical_url' ), 5, 2); + add_filter('tribe_rewrite_canonical_url', [$this, 'fix_language_in_canonical_url'], 5, 2); + add_filter('tribe_rewrite_canonical_url', [$this, 'translate_canonical_url'], 5, 2); } /** @@ -177,12 +174,13 @@ class PLL_TEC * * @param string[] $taxonomies List of taxonomy names for which Polylang manages language and translations. * @param bool $hide True when displaying the list in Polylang settings. + * * @return string[] List of taxonomy names for which Polylang manages language and translations. */ public function translate_taxonomies($taxonomies, $hide) { // Hide from Polylang settings - return $hide ? array_diff($taxonomies, array( TEC::TAXONOMY )) : array_merge($taxonomies, array( TEC::TAXONOMY )); + return $hide ? array_diff($taxonomies, [TEC::TAXONOMY]) : array_merge($taxonomies, [TEC::TAXONOMY]); } /** @@ -192,11 +190,13 @@ class PLL_TEC * * @param string[] $types List of post type names for which Polylang manages language and translations. * @param bool $hide True when displaying the list in Polylang settings. + * * @return string[] List of post type names for which Polylang manages language and translations. */ public function translate_types($types, $hide) { - $tec_types = array( TEC::POSTTYPE, TEC::VENUE_POST_TYPE, TEC::ORGANIZER_POST_TYPE ); + $tec_types = [TEC::POSTTYPE, TEC::VENUE_POST_TYPE, TEC::ORGANIZER_POST_TYPE]; + return $hide ? array_diff($types, $tec_types) : array_merge($types, $tec_types); } @@ -209,24 +209,25 @@ class PLL_TEC * @param int $post_id Post id. * @param WP_Post $post Post object. * @param bool $update Whether it is an update or not. + * * @return void */ public function set_language($post_id, $post, $update) { - if ($update || ! isset($_POST['post_lang_choice'])) { + if ($update || !isset($_POST['post_lang_choice'])) { return; } $post_type_object = get_post_type_object($post->post_type); - if (! $post_type_object || ! current_user_can($post_type_object->cap->create_posts)) { + if (!$post_type_object || !current_user_can($post_type_object->cap->create_posts)) { return; } check_admin_referer('pll_language', '_pll_nonce'); $lang = $this->polylang->model->get_language(sanitize_key($_POST['post_lang_choice'])); - if (! $lang) { + if (!$lang) { return; } @@ -247,24 +248,24 @@ class PLL_TEC */ public function fix_date_translations() { - $properties = array( + $properties = [ 'localized_months_full', 'localized_months_short', 'localized_weekdays', 'localized_months', - ); + ]; foreach ($properties as $property) { $property = new ReflectionProperty(Tribe__Date_Utils::class, $property); $property->setAccessible(true); - $property->setValue(array()); + $property->setValue([]); } TEC::instance()->setup_l10n_strings(); } /** - * Populates default event metas for a newly created event translation + * Populates default event metas for a newly created event translation. * * @since 2.2 * @@ -272,13 +273,15 @@ class PLL_TEC * @param int $id Post id. * @param string $meta Meta key. * @param bool $single Whether to return a single value. + * * @return mixed */ public function copy_event_meta($value, $id, $meta, $single) { - if (! empty($_GET['from_post'])) { // phpcs:ignore WordPress.Security.NonceVerification + if (!empty($_GET['from_post'])) { // phpcs:ignore WordPress.Security.NonceVerification $value = get_post_meta((int) $_GET['from_post'], $meta, $single); // phpcs:ignore WordPress.Security.NonceVerification } + return $value; } @@ -288,6 +291,7 @@ class PLL_TEC * @since 2.2 * * @param array $posts Array of linked posts. + * * @return array */ public function translate_linked_post($posts) @@ -302,14 +306,14 @@ class PLL_TEC return $posts; } - $lang = $data['new_lang']->slug; - $post_metas = ! empty($this->polylang->sync) && ! empty($this->polylang->sync->post_metas) ? $this->polylang->sync->post_metas : false; + $lang = $data['new_lang']->slug; + $post_metas = !empty($this->polylang->sync) && !empty($this->polylang->sync->post_metas) ? $this->polylang->sync->post_metas : false; foreach ($posts as $key => $post_id) { $tr_id = pll_get_post($post_id, $lang); - if (! empty($tr_id)) { - $posts[ $key ] = $tr_id; + if (!empty($tr_id)) { + $posts[$key] = $tr_id; continue; } @@ -325,29 +329,29 @@ class PLL_TEC $tr_id = wp_insert_post(wp_slash($post)); - if (! is_int($tr_id)) { + if (!is_int($tr_id)) { // `WP_Error` value. continue; } - $translations = pll_get_post_translations($post_id); - $translations[ $lang ] = $tr_id; + $translations = pll_get_post_translations($post_id); + $translations[$lang] = $tr_id; pll_set_post_language($tr_id, $lang); pll_save_post_translations($translations); - if (! empty($post_metas)) { + if (!empty($post_metas)) { $post_metas->copy($post_id, $tr_id, $lang); } - $posts[ $key ] = $tr_id; + $posts[$key] = $tr_id; } return $posts; } /** - * Removes date filters when searching for untranslated events in the metabox autocomplete field + * Removes date filters when searching for untranslated events in the metabox autocomplete field. * * @since 2.2.8 * @@ -357,9 +361,9 @@ class PLL_TEC { if (wp_doing_ajax() && isset($_GET['action']) && 'pll_posts_not_translated' === $_GET['action']) { // phpcs:ignore WordPress.Security.NonceVerification // See Tribe__Events__Query::pre_get_posts() when should_remove_date_filters() returns true - remove_filter('posts_where', array( 'Tribe__Events__Query', 'posts_where' )); - remove_filter('posts_fields', array( 'Tribe__Events__Query', 'posts_fields' )); - remove_filter('posts_orderby', array( 'Tribe__Events__Query', 'posts_orderby' )); + remove_filter('posts_where', ['Tribe__Events__Query', 'posts_where']); + remove_filter('posts_fields', ['Tribe__Events__Query', 'posts_fields']); + remove_filter('posts_orderby', ['Tribe__Events__Query', 'posts_orderby']); } } @@ -369,6 +373,7 @@ class PLL_TEC * @since 2.2 * * @param array $metas Custom fields to copy or synchronize. + * * @return array */ public function copy_post_metas($metas) @@ -384,6 +389,7 @@ class PLL_TEC * @param mixed $value Meta value. * @param string $key Meta key. * @param string $lang Language of target. + * * @return mixed */ public function translate_meta($value, $key, $lang) @@ -391,6 +397,7 @@ class PLL_TEC if (('_EventVenueID' === $key || '_EventOrganizerID' === $key) && $tr_value = pll_get_post($value, $lang)) { $value = $tr_value; } + return $value; } @@ -411,8 +418,8 @@ class PLL_TEC } // Those are deprecated since TEC 4.0 and should not appear in the list of translatable strings anymore. - $tec->taxRewriteSlug = $tec->rewriteSlug . '/category'; - $tec->tagRewriteSlug = $tec->rewriteSlug . '/tag'; + $tec->taxRewriteSlug = $tec->rewriteSlug.'/category'; + $tec->tagRewriteSlug = $tec->rewriteSlug.'/tag'; } /** @@ -422,12 +429,13 @@ class PLL_TEC * * @param array $args Array of arguments for registering a taxonomy. * @param string $taxonomy Taxonomy key. + * * @return array */ public function register_taxonomy_args($args, $taxonomy) { if (TEC::TAXONOMY === $taxonomy && is_array($args['rewrite'])) { - $args['rewrite']['slug'] = TEC::instance()->rewriteSlug . '/category'; + $args['rewrite']['slug'] = TEC::instance()->rewriteSlug.'/category'; } return $args; @@ -439,6 +447,7 @@ class PLL_TEC * @since 2.2 * * @param string $link Link generated by The Events Calendar. + * * @return string */ public function get_link($link) @@ -465,11 +474,12 @@ class PLL_TEC * * @param string $url Url in the language switcher. * @param PLL_Language $language Language object. + * * @return string Modified url. */ public function pll_get_archive_url($url, $language) { - if (empty($this->slugs_model) || ! is_post_type_archive(TEC::POSTTYPE)) { + if (empty($this->slugs_model) || !is_post_type_archive(TEC::POSTTYPE)) { return $url; } @@ -490,9 +500,10 @@ class PLL_TEC * @see PLL_TEC->reset_slugs() * @see PLL_TEC->pll_translated_slugs() * - * @param string $url The term link. - * @param PLL_Language $lang The term language. - * @param WP_Term $term The term object. + * @param string $url The term link. + * @param PLL_Language $lang The term language. + * @param WP_Term $term The term object. + * * @return string */ public function filter_tec_term_link($url, $lang, $term) @@ -501,7 +512,8 @@ class PLL_TEC return $url; } - $url = $this->slugs_model->translate_slug($url, $lang, 'archive_' . TEC::POSTTYPE); + $url = $this->slugs_model->translate_slug($url, $lang, 'archive_'.TEC::POSTTYPE); + return $this->slugs_model->translate_slug($url, $lang, 'tribe_category'); } @@ -514,6 +526,7 @@ class PLL_TEC * @param array $slugs Translated slugs. * @param PLL_Language $language Language object. * @param PLL_MO $mo Strings translations object. + * * @return array */ public function pll_translated_slugs($slugs, $language, &$mo) @@ -523,16 +536,16 @@ class PLL_TEC * our translated strings, as it is deprecated in TEC 4.0 and also a composite of * `{post type archive slug}/{tax base slug}`. This is why we unset `$slugs[ TEC::TAXONOMY ]` here. */ - unset($slugs[ 'archive_' . TEC::POSTTYPE ]['hide'], $slugs[ TEC::TAXONOMY ]); + unset($slugs['archive_'.TEC::POSTTYPE]['hide'], $slugs[TEC::TAXONOMY]); - $slugs[ 'archive_' . TEC::POSTTYPE ]['slug'] = $slug = TEC::instance()->getRewriteSlug(); + $slugs['archive_'.TEC::POSTTYPE]['slug'] = $slug = TEC::instance()->getRewriteSlug(); $tr_slug = $mo->translate($slug); - $slugs[ 'archive_' . TEC::POSTTYPE ]['translations'][ $language->slug ] = empty($tr_slug) ? $slug : $tr_slug; + $slugs['archive_'.TEC::POSTTYPE]['translations'][$language->slug] = empty($tr_slug) ? $slug : $tr_slug; foreach ($this->get_slugs_to_reset() as $slug) { - $slugs[ 'tribe_' . $slug ]['slug'] = $slug; + $slugs['tribe_'.$slug]['slug'] = $slug; $tr_slug = $mo->translate($slug); - $slugs[ 'tribe_' . $slug ]['translations'][ $language->slug ] = empty($tr_slug) ? $slug : $tr_slug; + $slugs['tribe_'.$slug]['translations'][$language->slug] = empty($tr_slug) ? $slug : $tr_slug; } return $slugs; @@ -540,12 +553,13 @@ class PLL_TEC /** * Performs the sanitization ( before saving in DB ) of slugs translations - * The Events Calendar does not accept accents, but let's accept slashes for the event category slug + * The Events Calendar does not accept accents, but let's accept slashes for the event category slug. * * @since 1.9 * * @param string $translation Translation to sanitize. * @param string $name Unique name for the string. + * * @return string */ public function sanitize_string_translation($translation, $name) @@ -553,8 +567,10 @@ class PLL_TEC if ('slug_archive_tribe_events' === $name || 0 === strpos($name, 'slug_tribe_')) { $slugs = explode('/', $translation); $slugs = array_map('sanitize_title', $slugs); + return implode('/', $slugs); } + return $translation; } @@ -564,6 +580,7 @@ class PLL_TEC * @since 2.2 * * @param array $bases Array of arrays of rewrite base slugs. + * * @return array */ public function rewrite_slugs($bases) @@ -579,7 +596,7 @@ class PLL_TEC foreach ($translatable_slugs as $slugs) { if ($slugs['slug'] === $default_slug) { - $bases[ $type ] = array_unique(array_merge(array( $default_slug ), $slugs['translations'])); + $bases[$type] = array_unique(array_merge([$default_slug], $slugs['translations'])); break; } } @@ -597,6 +614,7 @@ class PLL_TEC * @param string $translation Translated string. * @param string $name String name. * @param string $context String context. + * * @return string Sanitized translation. */ public function sanitize_strings($translation, $name, $context) @@ -618,8 +636,9 @@ class PLL_TEC * @since 3.1 * @see $this->rewrite_slugs() * - * @param string[] $bases An array of rewrite bases that have been generated. - * @param string $method The method that's being used to generate the bases; defaults to `regex`. + * @param string[] $bases An array of rewrite bases that have been generated. + * @param string $method The method that's being used to generate the bases; defaults to `regex`. + * * @return string[] */ public function fix_escaped_dashes_in_slugs($bases, $method) @@ -670,8 +689,9 @@ class PLL_TEC * * @since 3.1 * - * @param string $url The View endpoint URL, either a REST API URL or a admin-ajax.php fallback URL if REST API - * is not available. + * @param string $url The View endpoint URL, either a REST API URL or a admin-ajax.php fallback URL if REST API + * is not available. + * * @return string */ public function add_missing_lang_to_rest_url($url) @@ -684,11 +704,11 @@ class PLL_TEC $lang = $this->get_lang_from_url_query_arg($url); - if (! empty($lang)) { + if (!empty($lang)) { return $url; } - return add_query_arg(array( 'lang' => $curlang->slug ), $url); + return add_query_arg(['lang' => $curlang->slug], $url); } /** @@ -696,12 +716,13 @@ class PLL_TEC * * @since 3.1 * - * @param string $locale The locale ID. + * @param string $locale The locale ID. + * * @return string */ public function filter_locale_for_rest($locale) { - if (! $this->is_tec_rest_request()) { + if (!$this->is_tec_rest_request()) { return $locale; } @@ -720,17 +741,19 @@ class PLL_TEC * * @since 3.1 * - * @param mixed[] $url_args The current URL query arguments, created from a filtered version of the current - * request context. + * @param mixed[] $url_args The current URL query arguments, created from a filtered version of the current + * request context. + * * @return mixed[] */ public function add_language_to_publicly_visible_views_query_args($url_args) { $curlang = $this->get_curlang(); - if (! empty($curlang)) { + if (!empty($curlang)) { $url_args['lang'] = $curlang->slug; } + return $url_args; } @@ -739,13 +762,14 @@ class PLL_TEC * * @since 3.1 * - * @param mixed[] $template_vars An associative array of template variables. Variables will be extracted in the - * template hence the key will be the name of the variable available in the template. + * @param mixed[] $template_vars An associative array of template variables. Variables will be extracted in the + * template hence the key will be the name of the variable available in the template. + * * @return mixed[] */ public function translate_widget_view_more_link($template_vars) { - if (! isset($template_vars['view_more_link'])) { + if (!isset($template_vars['view_more_link'])) { return $template_vars; } @@ -755,9 +779,9 @@ class PLL_TEC return $template_vars; } - $template_vars['view_more_link'] = home_url('/' . tribe_get_option('eventsSlug', 'events')); + $template_vars['view_more_link'] = home_url('/'.tribe_get_option('eventsSlug', 'events')); $template_vars['view_more_link'] = $this->polylang->links_model->add_language_to_link($template_vars['view_more_link'], $curlang); - $template_vars['view_more_link'] = $this->slugs_model->translate_slug($template_vars['view_more_link'], $curlang, 'archive_' . TEC::POSTTYPE); + $template_vars['view_more_link'] = $this->slugs_model->translate_slug($template_vars['view_more_link'], $curlang, 'archive_'.TEC::POSTTYPE); $template_vars['view_more_link'] = user_trailingslashit($template_vars['view_more_link']); return $template_vars; @@ -774,10 +798,11 @@ class PLL_TEC * @see Tribe__Rewrite->parse_request() * @see PLL_TEC->add_language_to_publicly_visible_views_query_args() * - * @param string[] $query_vars The parsed query vars array. - * @param string[] $extra_query_vars An associative array of extra query vars that will be processed before - * the WordPress defined ones. - * @param string $url The URL to parse. + * @param string[] $query_vars The parsed query vars array. + * @param string[] $extra_query_vars An associative array of extra query vars that will be processed before + * the WordPress defined ones. + * @param string $url The URL to parse. + * * @return string[] */ public function force_language_on_tec_parse_query_vars($query_vars, $extra_query_vars, $url) @@ -785,7 +810,7 @@ class PLL_TEC // Find the lang in the URL... $lang = $this->get_lang_from_url_query_arg($url); - if (! empty($lang)) { + if (!empty($lang)) { // ... and add it to the query vars. $query_vars['lang'] = $lang->slug; } @@ -799,7 +824,8 @@ class PLL_TEC * * @since 3.1 * - * @param mixed[] $query_args An array of query args that will be used to build the URL for the View. + * @param mixed[] $query_args An array of query args that will be used to build the URL for the View. + * * @return mixed[] */ public function add_missing_lang_to_query_arg($query_args) @@ -810,7 +836,7 @@ class PLL_TEC $curlang = $this->get_curlang(); - $query_args['lang'] = ! empty($curlang) ? $curlang->slug : $this->polylang->options['default_lang']; + $query_args['lang'] = !empty($curlang) ? $curlang->slug : $this->polylang->options['default_lang']; return $query_args; } @@ -821,16 +847,17 @@ class PLL_TEC * * @since 3.1 * - * @param string|null $canonical_url The canonical URL, defaults to `null`; returning a non `null` value will - * make the logic bail and return the value. - * @param string $url The input URL to resolve to a canonical one. + * @param string|null $canonical_url The canonical URL, defaults to `null`; returning a non `null` value will + * make the logic bail and return the value. + * @param string $url The input URL to resolve to a canonical one. + * * @return string|null */ public function add_missing_lang_to_non_canonical_url($canonical_url, $url) { $lang = $this->get_lang_from_url_query_arg($url); - if (! empty($lang)) { + if (!empty($lang)) { // All good. return $canonical_url; } @@ -852,9 +879,10 @@ class PLL_TEC * * @since 3.1 * - * @param string|null $canonical_url The canonical URL, defaults to `null`; returning a non `null` value will - * make the logic bail and return the value. - * @param string $url The input URL to resolve to a canonical one. + * @param string|null $canonical_url The canonical URL, defaults to `null`; returning a non `null` value will + * make the logic bail and return the value. + * @param string $url The input URL to resolve to a canonical one. + * * @return string|null */ public function remove_name_arg_from_non_canonical_url($canonical_url, $url) @@ -865,14 +893,14 @@ class PLL_TEC return $canonical_url; } - $parsed_query = array(); + $parsed_query = []; wp_parse_str($url_query, $parsed_query); if (empty($parsed_query)) { return $canonical_url; } - if (empty($parsed_query['post_type']) || empty($parsed_query['name']) || ! empty($parsed_query['ical'])) { + if (empty($parsed_query['post_type']) || empty($parsed_query['name']) || !empty($parsed_query['ical'])) { return $canonical_url; } @@ -880,7 +908,7 @@ class PLL_TEC return $canonical_url; } - if (! empty($parsed_query['lang']) && $parsed_query['lang'] === $parsed_query['name']) { + if (!empty($parsed_query['lang']) && $parsed_query['lang'] === $parsed_query['name']) { // ¯\(°_o)/¯. $remove = true; } elseif (tribe_get_option('eventsSlug') === $parsed_query['name']) { @@ -904,8 +932,9 @@ class PLL_TEC * * @since 3.1 * - * @param string $resolved The resolved, canonical URL. - * @param string $url The original URL to resolve. + * @param string $resolved The resolved, canonical URL. + * @param string $url The original URL to resolve. + * * @return string */ public function fix_language_in_canonical_url($resolved, $url) @@ -914,10 +943,10 @@ class PLL_TEC // Remove the default language if it must be hidden in the URLs. $languages = $this->polylang->model->get_languages_list( - array( + [ 'hide_default' => $options['hide_default'], 'fields' => 'slug', - ) + ] ); if (empty($languages)) { @@ -929,7 +958,7 @@ class PLL_TEC * Ex: `/(en|fr|de)`, `/language/(fr|de)`. */ $language_path = $options['rewrite'] ? '' : '/language'; - $to_replace = $language_path . '/(' . implode('|', $languages) . ')/'; + $to_replace = $language_path.'/('.implode('|', $languages).')/'; if (strpos($resolved, $to_replace) === false) { return $resolved; @@ -941,7 +970,7 @@ class PLL_TEC if (empty($lang)) { // We need a lang, whichever it is. $curlang = $this->get_curlang(); - $lang = ! empty($curlang) ? $curlang->slug : $options['default_lang']; + $lang = !empty($curlang) ? $curlang->slug : $options['default_lang']; } else { $lang = $lang->slug; } @@ -964,8 +993,9 @@ class PLL_TEC * @since 3.1 * @see Tribe__Events__Rewrite->get_dynamic_matchers() * - * @param string $resolved The resolved, canonical URL. - * @param string $url The original URL to resolve. + * @param string $resolved The resolved, canonical URL. + * @param string $url The original URL to resolve. + * * @return string */ public function translate_canonical_url($resolved, $url) @@ -1002,27 +1032,28 @@ class PLL_TEC * @since 3.1 * @see Tribe\Events\Views\V2\Rest_Endpoint->get_url() * - * @param string $requested_url The requested URL. Falls back to the current URL. - * @return bool|null Whether the request is a TEC REST API request. Null if not ready to answer yet. + * @param string $requested_url The requested URL. Falls back to the current URL. + * + * @return bool|null Whether the request is a TEC REST API request. Null if not ready to answer yet. */ protected function is_tec_rest_request($requested_url = null) { - if (! isset($this->is_tec_rest_request['views_v2_is_enabled'])) { - if (! function_exists('tribe_events_views_v2_is_enabled')) { + if (!isset($this->is_tec_rest_request['views_v2_is_enabled'])) { + if (!function_exists('tribe_events_views_v2_is_enabled')) { return null; } $this->is_tec_rest_request['views_v2_is_enabled'] = tribe_events_views_v2_is_enabled(); } - if (! $this->is_tec_rest_request['views_v2_is_enabled']) { + if (!$this->is_tec_rest_request['views_v2_is_enabled']) { // If the views V2 are not enabled, no REST requests. return false; } - if (empty($requested_url) || ! is_string($requested_url)) { + if (empty($requested_url) || !is_string($requested_url)) { // Fall back to the current URL. - if (! isset($this->is_tec_rest_request['pll_requested_url'])) { + if (!isset($this->is_tec_rest_request['pll_requested_url'])) { $this->is_tec_rest_request['pll_requested_url'] = (string) set_url_scheme(pll_get_requested_url()); } @@ -1031,13 +1062,13 @@ class PLL_TEC $requested_url = (string) set_url_scheme($requested_url); } - if (isset($this->is_tec_rest_request[ 'is:' . $requested_url ])) { - return $this->is_tec_rest_request[ 'is:' . $requested_url ]; + if (isset($this->is_tec_rest_request['is:'.$requested_url])) { + return $this->is_tec_rest_request['is:'.$requested_url]; } if (false === strpos($requested_url, '/admin-ajax.php')) { // Test against the REST URL. - if (! isset($this->is_tec_rest_request['tec_rest_url_pattern'])) { + if (!isset($this->is_tec_rest_request['tec_rest_url_pattern'])) { $url = $this->get_tec_rest_url(true); if (empty($url)) { @@ -1049,28 +1080,29 @@ class PLL_TEC $this->is_tec_rest_request['tec_rest_url_pattern'] = sprintf('@^%s[/?#]@i', preg_quote($this->is_tec_rest_request['tec_rest_url_pattern'], '@')); } - $this->is_tec_rest_request[ 'is:' . $requested_url ] = (bool) preg_match($this->is_tec_rest_request['tec_rest_url_pattern'], $requested_url); + $this->is_tec_rest_request['is:'.$requested_url] = (bool) preg_match($this->is_tec_rest_request['tec_rest_url_pattern'], $requested_url); - return $this->is_tec_rest_request[ 'is:' . $requested_url ]; + return $this->is_tec_rest_request['is:'.$requested_url]; } // Test against the admin ajax URL. - if (! isset($this->is_tec_rest_request['tec_ajax_url_action'])) { + if (!isset($this->is_tec_rest_request['tec_ajax_url_action'])) { $this->is_tec_rest_request['tec_ajax_url_action'] = $this->get_tec_rest_url(false); $this->is_tec_rest_request['tec_ajax_url_action'] = $this->get_query_arg_from_url($this->is_tec_rest_request['tec_ajax_url_action'], 'action'); } if (empty($this->is_tec_rest_request['tec_ajax_url_action'])) { // Uh? - $this->is_tec_rest_request[ 'is:' . $requested_url ] = false; + $this->is_tec_rest_request['is:'.$requested_url] = false; + return false; } $requested_action = $this->get_query_arg_from_url($requested_url, 'action'); - $this->is_tec_rest_request[ 'is:' . $requested_url ] = $requested_action === $this->is_tec_rest_request['tec_ajax_url_action']; + $this->is_tec_rest_request['is:'.$requested_url] = $requested_action === $this->is_tec_rest_request['tec_ajax_url_action']; - return $this->is_tec_rest_request[ 'is:' . $requested_url ]; + return $this->is_tec_rest_request['is:'.$requested_url]; } /** @@ -1083,28 +1115,30 @@ class PLL_TEC */ protected function get_curlang() { - if (! empty($this->curlang)) { + if (!empty($this->curlang)) { return $this->curlang; } - if (! empty($_REQUEST['lang']) && is_string($_REQUEST['lang']) && Polylang::is_rest_request()) { // phpcs:ignore WordPress.Security.NonceVerification + if (!empty($_REQUEST['lang']) && is_string($_REQUEST['lang']) && Polylang::is_rest_request()) { // phpcs:ignore WordPress.Security.NonceVerification // REST request. $curlang = $this->polylang->model->get_language(sanitize_key($_REQUEST['lang'])); // phpcs:ignore WordPress.Security.NonceVerification - if (! empty($curlang)) { - $this->curlang = $curlang; + if (!empty($curlang)) { + $this->curlang = $curlang; $this->polylang->curlang = $this->curlang; + return $this->curlang; } } - if (! empty($this->polylang->curlang)) { + if (!empty($this->polylang->curlang)) { // Global context. $this->curlang = &$this->polylang->curlang; + return $this->curlang; } - if (empty($this->polylang->options['force_lang']) && $this->polylang instanceof PLL_Frontend && ! did_action('pll_language_defined')) { + if (empty($this->polylang->options['force_lang']) && $this->polylang instanceof PLL_Frontend && !did_action('pll_language_defined')) { // Lang defined by content: too soon. return null; } @@ -1118,6 +1152,7 @@ class PLL_TEC // Default lang. $this->curlang = $curlang; + return $this->curlang; } @@ -1131,7 +1166,7 @@ class PLL_TEC */ protected function get_slugs_to_reset() { - return array( + return [ 'category_slug' => 'category', 'tag_slug' => 'tag', 'monthSlug' => 'month', @@ -1142,7 +1177,7 @@ class PLL_TEC 'todaySlug' => 'today', 'featured_slug' => 'featured', 'all_slug' => 'all', - ); + ]; } /** @@ -1155,21 +1190,21 @@ class PLL_TEC */ protected function get_translatable_slug_ids() { - if (! empty($this->translatable_slug_ids)) { + if (!empty($this->translatable_slug_ids)) { return $this->translatable_slug_ids; } - $slug_ids = array( + $slug_ids = [ Venue::POSTTYPE, Organizer::POSTTYPE, TEC::POSTTYPE, - 'archive_' . TEC::POSTTYPE, + 'archive_'.TEC::POSTTYPE, 'post_tag', 'paged', - ); + ]; foreach ($this->get_slugs_to_reset() as $slug) { - $slug_ids[] = 'tribe_' . $slug; + $slug_ids[] = 'tribe_'.$slug; } $this->translatable_slug_ids = array_combine($slug_ids, $slug_ids); @@ -1187,7 +1222,7 @@ class PLL_TEC protected function get_translatable_slugs() { if (empty($this->slugs_model)) { - return array(); + return []; } return array_intersect_key($this->slugs_model->get_translatable_slugs(), $this->get_translatable_slug_ids()); @@ -1198,14 +1233,15 @@ class PLL_TEC * * @since 3.1 * - * @param string $url The URL to retrieve the arg from. + * @param string $url The URL to retrieve the arg from. + * * @return PLL_Language|null The lang object. Null if not found or invalid. */ protected function get_lang_from_url_query_arg($url) { $lang = $this->get_query_arg_from_url($url, 'lang'); - if (empty($lang) || ! is_string($lang)) { + if (empty($lang) || !is_string($lang)) { return null; } @@ -1223,27 +1259,28 @@ class PLL_TEC * * @since 3.1 * - * @param string $url The URL to retrieve the arg from. + * @param string $url The URL to retrieve the arg from. + * * @return PLL_Language|null The lang object. Null if not found or invalid. */ protected function get_lang_from_url_query_arg_or_fallback($url) { $lang = $this->get_lang_from_url_query_arg($url); - if (! empty($lang)) { + if (!empty($lang)) { return $lang; } $lang = $this->get_curlang(); - if (! empty($lang)) { + if (!empty($lang)) { return $lang; } // Uh? $lang = $this->polylang->model->get_default_language(); - if (! empty($lang)) { + if (!empty($lang)) { return $lang; } @@ -1256,17 +1293,18 @@ class PLL_TEC * * @since 3.1 * - * @param string $url The URL to retrieve the arg from. - * @param string $query_arg_name The name of the query arg to retrieve. - * @return string|null The raw value of the query arg. Null if not found. + * @param string $url The URL to retrieve the arg from. + * @param string $query_arg_name The name of the query arg to retrieve. + * + * @return string|null The raw value of the query arg. Null if not found. */ protected function get_query_arg_from_url($url, $query_arg_name) { - if (empty($url) || ! is_string($url)) { + if (empty($url) || !is_string($url)) { return null; } - if (empty($query_arg_name) || ! is_string($query_arg_name)) { + if (empty($query_arg_name) || !is_string($query_arg_name)) { return null; } @@ -1276,14 +1314,14 @@ class PLL_TEC return null; } - $parsed = array(); + $parsed = []; wp_parse_str($url_query, $parsed); - if (empty($parsed[ $query_arg_name ]) || ! is_string($parsed[ $query_arg_name ])) { + if (empty($parsed[$query_arg_name]) || !is_string($parsed[$query_arg_name])) { return null; } - return sanitize_key($parsed[ $query_arg_name ]); + return sanitize_key($parsed[$query_arg_name]); } /** @@ -1291,9 +1329,10 @@ class PLL_TEC * * @since 3.1 * - * @param bool $enable_rest True to get the REST URL. False to get the admin ajax URL. - * @return string|null The REST URL. Null if too soon to be determined: this may happen when requesting the - * the real REST URL (`$enable_rest` is true) but `$wp_rewrite` is not ready. + * @param bool $enable_rest True to get the REST URL. False to get the admin ajax URL. + * + * @return string|null The REST URL. Null if too soon to be determined: this may happen when requesting the + * the real REST URL (`$enable_rest` is true) but `$wp_rewrite` is not ready. */ protected function get_tec_rest_url($enable_rest) { @@ -1303,7 +1342,7 @@ class PLL_TEC // In this case, `Rest_Endpoint->get_url()` will use `get_rest_url()`. if ((is_multisite() && get_blog_option(0, 'permalink_structure')) || get_option('permalink_structure')) { // See the same test done in `get_rest_url()`. // We test `$wp_rewrite` to prevent `get_rest_url()` to explode. - if (! $wp_rewrite instanceof WP_Rewrite) { + if (!$wp_rewrite instanceof WP_Rewrite) { return null; } } diff --git a/__plugins/polylang-pro-3.7.6/polylang.php b/__plugins/polylang-pro-3.7.6/polylang.php index 9211ac50e9eefd957d323864d379c4bf1e32e074..931b95e9cc8f862f72f2e7231c308d638bed62c5 100644 --- a/__plugins/polylang-pro-3.7.6/polylang.php +++ b/__plugins/polylang-pro-3.7.6/polylang.php @@ -1,9 +1,8 @@ time() ) + (array) get_option('recently_activated')); + if (!is_network_admin()) { + update_option('recently_activated', [POLYLANG_BASENAME => time()] + (array) get_option('recently_activated')); } else { - update_site_option('recently_activated', array( POLYLANG_BASENAME => time() ) + (array) get_site_option('recently_activated')); + update_site_option('recently_activated', [POLYLANG_BASENAME => time()] + (array) get_site_option('recently_activated')); } } else { define('POLYLANG_BASENAME', plugin_basename(__FILE__)); // Plugin name as known by WP. } -require __DIR__ . '/vendor/autoload.php'; -require __DIR__ . '/vendor/wpsyntex/polylang/polylang.php'; +require __DIR__.'/vendor/autoload.php'; +require __DIR__.'/vendor/wpsyntex/polylang/polylang.php'; if (empty($_GET['deactivate-polylang'])) { // phpcs:ignore WordPress.Security.NonceVerification - add_action('pll_init_options_for_blog', array( Options_Registry::class, 'register' ), 15); // After Polylang. - add_action('pll_pre_init', array( new PLL_Pro(), 'init' ), 0); + add_action('pll_init_options_for_blog', [Options_Registry::class, 'register'], 15); // After Polylang. + add_action('pll_pre_init', [new PLL_Pro(), 'init'], 0); } diff --git a/__plugins/polylang-pro-3.7.6/services/admin-loader/admin-loader.php b/__plugins/polylang-pro-3.7.6/services/admin-loader/admin-loader.php index 78c349c97bbb50e13c7902ffc7a4581831cf5178..268f3ee3f0871226847ea95331dbdab118e928b0 100644 --- a/__plugins/polylang-pro-3.7.6/services/admin-loader/admin-loader.php +++ b/__plugins/polylang-pro-3.7.6/services/admin-loader/admin-loader.php @@ -1,9 +1,5 @@ polylang = &$polylang; $this->property = $property; - $this->args = $args; + $this->args = $args; - add_action('admin_init', array( $this, 'load' ), 20); // After fusion Builder. + add_action('admin_init', [$this, 'load'], 20); // After fusion Builder. } /** @@ -64,7 +60,7 @@ class PLL_Admin_Loader { if ('post-new.php' === $GLOBALS['pagenow']) { // We need to wait until we know which editor is in use - add_filter('use_block_editor_for_post', array( $this, '_load' ), 999); // After the plugin Classic Editor + add_filter('use_block_editor_for_post', [$this, '_load'], 999); // After the plugin Classic Editor } elseif ('post.php' === $GLOBALS['pagenow'] && isset($_GET['action'], $_GET['post']) && 'edit' === $_GET['action'] && empty($_GET['meta-box-loader'])) { // phpcs:ignore WordPress.Security.NonceVerification $this->_load(use_block_editor_for_post((int) $_GET['post'])); // phpcs:ignore WordPress.Security.NonceVerification } else { @@ -80,6 +76,7 @@ class PLL_Admin_Loader * @since 2.8 * * @param bool $is_block_editor Whether to use the block editor or not. + * * @return bool */ public function _load($is_block_editor) @@ -96,7 +93,7 @@ class PLL_Admin_Loader break; default: - $classname = 'PLL_' . ucwords($prop, '_'); + $classname = 'PLL_'.ucwords($prop, '_'); break; } @@ -104,9 +101,9 @@ class PLL_Admin_Loader $classname = "{$classname}_REST"; } - $args = array( $this->polylang ); + $args = [$this->polylang]; - if (! empty($this->args)) { + if (!empty($this->args)) { $args = array_merge($args, array_values($this->args)); } diff --git a/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-posts.php b/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-posts.php index d9a3320668b3d824c670f1e3ed89b9b0daa52c42..f84ea9186ad339664601b07527c9abdf9260bf58 100644 --- a/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-posts.php +++ b/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-posts.php @@ -1,9 +1,5 @@ get_post_ids_from_post($post)); @@ -55,18 +52,18 @@ class PLL_Collect_Linked_Posts $linked_ids = array_unique($linked_ids); if (empty($linked_ids)) { - return array(); + return []; } // Query all the linked posts outside the PLL_Export_Bulk_Option::translate() loop to avoid multiple SQL queries with get_post() call. return get_posts( - array( + [ 'include' => $linked_ids, 'post_type' => $post_types, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', - ) + ] ); } @@ -76,11 +73,12 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param WP_Post $post A given WP_Post object. + * * @return int[] An array of post ids. */ protected function get_post_ids_from_post($post) { - $linked_ids = array(); + $linked_ids = []; if (function_exists('has_blocks') && has_blocks($post->post_content)) { $linked_ids = $this->get_post_ids_from_block_content($post->post_content); @@ -114,6 +112,7 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param string $post_content The content of the post. + * * @return int[] An array of post ids. */ protected function get_post_ids_from_block_content($post_content) @@ -129,11 +128,12 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param array $blocks An array of blocks. + * * @return int[] An array of post ids. */ protected function get_post_ids_from_blocks_deep($blocks) { - $post_ids = array(); + $post_ids = []; foreach ($blocks as $block) { if ($this->options['media_support']) { @@ -142,6 +142,7 @@ class PLL_Collect_Linked_Posts $post_ids = array_merge($post_ids, $this->get_navigation_block_ids($block)); $post_ids = array_merge($post_ids, $this->get_reusable_block_ids($block)); } + return array_unique($post_ids); } @@ -151,11 +152,12 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param array $block A representative array of a block. + * * @return int[] An array of media ids, empty if none found. */ protected function get_media_ids_from_block($block) { - $post_ids = array(); + $post_ids = []; switch ($block['blockName']) { case 'core/audio': @@ -163,28 +165,28 @@ class PLL_Collect_Linked_Posts case 'core/file': case 'core/image': case 'core/video': - if (! empty($block['attrs']['id'])) { + if (!empty($block['attrs']['id'])) { $post_ids[] = $block['attrs']['id']; } break; case 'core/gallery': // Backward compatibility with WP < 5.9. - if (! empty($block['attrs']['ids']) && is_array($block['attrs']['ids'])) { + if (!empty($block['attrs']['ids']) && is_array($block['attrs']['ids'])) { $post_ids = array_merge($post_ids, $block['attrs']['ids']); } break; case 'core/media-text': - if (! empty($block['attrs']['mediaId'])) { + if (!empty($block['attrs']['mediaId'])) { $post_ids[] = $block['attrs']['mediaId']; } break; default: - if (! empty($block['innerHTML'])) { + if (!empty($block['innerHTML'])) { $post_ids = array_merge($post_ids, $this->get_medias_from_html_content($block['innerHTML'])); } break; } - if (! empty($block['innerBlocks'])) { + if (!empty($block['innerBlocks'])) { $post_ids = array_merge($post_ids, $this->get_post_ids_from_blocks_deep($block['innerBlocks'])); } @@ -197,11 +199,11 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param string $post_content The content of the post. + * * @return int[] */ protected function get_medias_from_html_content($post_content) { - return array_merge($this->get_medias_from_img_tags($post_content), $this->get_medias_from_shortcodes($post_content)); } @@ -211,13 +213,14 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param string $post_content The content of the required post. + * * @return int[] The media ids. */ protected function get_medias_from_shortcodes($post_content) { - $media_ids = array(); + $media_ids = []; - if (preg_match_all('/' . get_shortcode_regex() . '/s', $post_content, $matches, PREG_SET_ORDER)) { + if (preg_match_all('/'.get_shortcode_regex().'/s', $post_content, $matches, PREG_SET_ORDER)) { foreach ($matches as $shortcode) { $attributes = shortcode_parse_atts($shortcode[3]); // $shortcode[3] returns the shortcode attributes as string. @@ -241,18 +244,19 @@ class PLL_Collect_Linked_Posts } /** - * Gets media ids from img tags + * Gets media ids from img tags. * * @since 3.3 * * @param string $post_content The content of the post to search from. + * * @return int[] An array of media ids (empty if no media is found). */ protected function get_medias_from_img_tags($post_content) { - $media_ids = array(); - $textarr = wp_html_split($post_content); - if (! is_array($textarr)) { + $media_ids = []; + $textarr = wp_html_split($post_content); + if (!is_array($textarr)) { return $media_ids; } foreach ($textarr as $text) { @@ -260,7 +264,7 @@ class PLL_Collect_Linked_Posts continue; } $attributes = wp_kses_attr_parse($text); - if (! is_array($attributes)) { + if (!is_array($attributes)) { continue; } foreach ($attributes as $attr) { @@ -280,11 +284,12 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param array $block An array containing block data. + * * @return int[] An array of reusable block ids, empty if none found. */ protected function get_reusable_block_ids($block) { - $ids = array(); + $ids = []; if ('core/block' !== $block['blockName']) { return $ids; @@ -307,13 +312,15 @@ class PLL_Collect_Linked_Posts * @since 3.3 * * @param array $block An array containing block data. + * * @return int[] An array of navigation post IDs, empty if none found. */ protected function get_navigation_block_ids($block) { if ('core/navigation' !== $block['blockName']) { - return array(); + return []; } - return array( (int) $block['attrs']['ref'] ); + + return [(int) $block['attrs']['ref']]; } } diff --git a/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-terms.php b/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-terms.php index e58ea1446794382548a178a395b65f2c94d89fe3..dbf28c404dfc808ab8a424c9b2e26751d9a56072 100644 --- a/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-terms.php +++ b/__plugins/polylang-pro-3.7.6/services/collect-linked-objects/collect-linked-terms.php @@ -1,9 +1,5 @@ */ - protected $processed_posts = array(); + protected $processed_posts = []; /** * Gets all the term objects linked to a set of posts. * * @since 3.3 * - * @param WP_Post[] $posts An array of post objects. - * @param string[] $taxonomies Optional. Terms will be limited to the given taxonomies. - * @return WP_Term[] An array of linked term objects. + * @param WP_Post[] $posts An array of post objects. + * @param string[] $taxonomies Optional. Terms will be limited to the given taxonomies. + * + * @return WP_Term[] An array of linked term objects. */ - public function get_linked_terms(array $posts, array $taxonomies = array()) + public function get_linked_terms(array $posts, array $taxonomies = []) { $terms = $this->get_terms_assigned_to_posts($posts, $taxonomies); @@ -43,16 +41,17 @@ class PLL_Collect_Linked_Terms * * @since 3.7 * - * @param WP_Post[] $posts An array of post objects. - * @param string[] $taxonomies Terms will be limited to the given taxonomies. - * @return WP_Term[] An array of assigned term objects. + * @param WP_Post[] $posts An array of post objects. + * @param string[] $taxonomies Terms will be limited to the given taxonomies. + * + * @return WP_Term[] An array of assigned term objects. */ protected function get_terms_assigned_to_posts(array $posts, array $taxonomies): array { - $post_ids = wp_list_pluck($posts, 'ID'); + $post_ids = wp_list_pluck($posts, 'ID'); $post_terms = wp_get_object_terms($post_ids, $taxonomies); - return is_array($post_terms) ? $post_terms : array(); + return is_array($post_terms) ? $post_terms : []; } /** @@ -60,36 +59,37 @@ class PLL_Collect_Linked_Terms * * @since 3.7 * - * @param WP_Post[] $posts An array of post objects. - * @param string[] $taxonomies Terms will be limited to the given taxonomies. - * @return WP_Term[] An array of linked term objects. + * @param WP_Post[] $posts An array of post objects. + * @param string[] $taxonomies Terms will be limited to the given taxonomies. + * + * @return WP_Term[] An array of linked term objects. */ protected function get_terms_from_posts(array $posts, array $taxonomies): array { - $this->processed_posts = array(); - $linked_ids = array(); + $this->processed_posts = []; + $linked_ids = []; foreach ($posts as $post) { $linked_ids = array_merge($linked_ids, $this->get_term_ids_from_post($post)); } - $this->processed_posts = array(); + $this->processed_posts = []; if (empty($linked_ids)) { - return array(); + return []; } $linked_ids = array_unique($linked_ids); $terms = get_terms( - array( + [ 'include' => $linked_ids, 'taxonomy' => $taxonomies, 'hide_empty' => false, - ) + ] ); - return is_array($terms) ? $terms : array(); + return is_array($terms) ? $terms : []; } /** @@ -98,18 +98,20 @@ class PLL_Collect_Linked_Terms * @since 3.3 * * @param WP_Post $post A given WP_Post object. + * * @return int[] An array of term IDs. + * * @phpstan-return array, positive-int> */ protected function get_term_ids_from_post(WP_Post $post) { - if (isset($this->processed_posts[ $post->ID ])) { - return array(); + if (isset($this->processed_posts[$post->ID])) { + return []; } - $this->processed_posts[ $post->ID ] = $post->ID; + $this->processed_posts[$post->ID] = $post->ID; - $linked_ids = array(); + $linked_ids = []; if (has_blocks($post->post_content)) { $linked_ids = $this->get_term_ids_from_block_content($post->post_content); @@ -135,6 +137,7 @@ class PLL_Collect_Linked_Terms * @since 3.3 * * @param string $post_content The content of the post. + * * @return int[] An array of term IDs. * * @phpstan-return array, positive-int> @@ -150,13 +153,14 @@ class PLL_Collect_Linked_Terms * @since 3.3 * * @param array[] $blocks An array of blocks. + * * @return int[] An array of term IDs. * * @phpstan-return array, positive-int> */ protected function get_term_ids_from_blocks(array $blocks) { - $term_ids = array(); + $term_ids = []; foreach ($blocks as $block) { $term_ids = array_merge($term_ids, $this->get_term_ids_from_block($block)); @@ -171,13 +175,14 @@ class PLL_Collect_Linked_Terms * @since 3.3 * * @param array $block A representative array of a block. + * * @return int[] An array of term IDs. * * @phpstan-return array, positive-int> */ protected function get_term_ids_from_block(array $block) { - $term_ids = array(); + $term_ids = []; switch ($block['blockName']) { case 'core/block': @@ -193,7 +198,7 @@ class PLL_Collect_Linked_Terms break; } - if (! empty($block['innerBlocks'])) { + if (!empty($block['innerBlocks'])) { $term_ids = array_merge($term_ids, $this->get_term_ids_from_blocks($block['innerBlocks'])); } @@ -206,28 +211,29 @@ class PLL_Collect_Linked_Terms * @since 3.3 * * @param array $block A representative array of a block. + * * @return int[] An array of term IDs. * * @phpstan-return array, positive-int> */ protected function get_term_ids_from_reusable_block(array $block) { - if (empty($block['attrs']['ref']) || ! is_int($block['attrs']['ref'])) { - return array(); + if (empty($block['attrs']['ref']) || !is_int($block['attrs']['ref'])) { + return []; } $post_id = $block['attrs']['ref']; - if (isset($this->processed_posts[ $post_id ])) { - return array(); + if (isset($this->processed_posts[$post_id])) { + return []; } - $this->processed_posts[ $post_id ] = $post_id; + $this->processed_posts[$post_id] = $post_id; $linked_post = get_post($post_id); - if (! $linked_post instanceof WP_Post) { - return array(); + if (!$linked_post instanceof WP_Post) { + return []; } return $this->get_term_ids_from_block_content($linked_post->post_content); @@ -239,14 +245,15 @@ class PLL_Collect_Linked_Terms * @since 3.3 * * @param array $block A representative array of a block. + * * @return int[] An array of term IDs. * * @phpstan-return array, positive-int> */ protected function get_term_ids_from_latest_posts_block(array $block) { - if (empty($block['attrs']['categories']) || ! is_array($block['attrs']['categories'])) { - return array(); + if (empty($block['attrs']['categories']) || !is_array($block['attrs']['categories'])) { + return []; } /** @@ -274,14 +281,15 @@ class PLL_Collect_Linked_Terms * @since 3.3 * * @param array $block A representative array of a block. + * * @return int[] An array of term IDs. * * @phpstan-return array, positive-int> */ protected function get_term_ids_from_query_block(array $block) { - if (empty($block['attrs']['query']['taxQuery']) || ! is_array($block['attrs']['query']['taxQuery'])) { - return array(); + if (empty($block['attrs']['query']['taxQuery']) || !is_array($block['attrs']['query']['taxQuery'])) { + return []; } /** @@ -311,11 +319,12 @@ class PLL_Collect_Linked_Terms * @since 3.7 * * @param WP_Term[] $terms An array of terms. + * * @return array The array of terms parents, if any. */ protected function get_terms_parents(array $terms): array { - $term_parents_ids = array(); + $term_parents_ids = []; foreach ($terms as $term) { if (empty($term->parent)) { continue; @@ -330,16 +339,16 @@ class PLL_Collect_Linked_Terms } if (empty($term_parents_ids)) { - return array(); + return []; } $terms_parents = get_terms( - array( + [ 'include' => $term_parents_ids, 'hide_empty' => false, - ) + ] ); - return is_array($terms_parents) ? $terms_parents : array(); + return is_array($terms_parents) ? $terms_parents : []; } } diff --git a/__plugins/polylang-pro-3.7.6/services/context.php b/__plugins/polylang-pro-3.7.6/services/context.php index c007a1a6eaa36d6887100dd69e59c0edf91dc4b3..c9d81ee9f2f7fa7e621da3b1365831a48d09db75 100644 --- a/__plugins/polylang-pro-3.7.6/services/context.php +++ b/__plugins/polylang-pro-3.7.6/services/context.php @@ -1,9 +1,5 @@ @@ -43,6 +40,7 @@ class Context * @since 3.6 * * @param string $context Raw context from a `Translation_Entry`. + * * @return array Extracted array of data. * * @phpstan-return array<'encoding'|'field'|'id', string> @@ -50,7 +48,7 @@ class Context public static function to_array(string $context): array { $context = json_decode($context, true); - $context = is_array($context) ? $context : array(); + $context = is_array($context) ? $context : []; $context = array_filter($context, 'is_string'); $default = static::get_default(); @@ -68,11 +66,11 @@ class Context */ public static function get_default(): array { - return array( + return [ self::FIELD => '', self::ID => '', self::ENCODING => '', - ); + ]; } /** @@ -81,13 +79,14 @@ class Context * @since 3.6 * * @param Translation_Entry $entry Entry to get field from. + * * @return string */ public static function get_field(Translation_Entry $entry): string { $context = self::to_array($entry->context); - return $context[ static::FIELD ]; + return $context[static::FIELD]; } /** @@ -96,13 +95,14 @@ class Context * @since 3.6 * * @param Translation_Entry $entry Entry to get id from. + * * @return string */ public static function get_id(Translation_Entry $entry): string { $context = self::to_array($entry->context); - return $context[ static::ID ]; + return $context[static::ID]; } /** @@ -111,12 +111,13 @@ class Context * @since 3.6 * * @param Translation_Entry $entry Entry to get encoding from. + * * @return string */ public static function get_encoding(Translation_Entry $entry): string { $context = self::to_array($entry->context); - return $context[ static::ENCODING ]; + return $context[static::ENCODING]; } } diff --git a/__plugins/polylang-pro-3.7.6/services/data-encoding.php b/__plugins/polylang-pro-3.7.6/services/data-encoding.php index 84e45c7fdcaae6a6fc90f1cc17919bef8debffa4..57feffba007e61393e06686fbd57780e68fdc331 100644 --- a/__plugins/polylang-pro-3.7.6/services/data-encoding.php +++ b/__plugins/polylang-pro-3.7.6/services/data-encoding.php @@ -1,9 +1,5 @@ format = ! empty($format) ? $format : 'serialize'; + $this->format = !empty($format) ? $format : 'serialize'; } /** @@ -55,6 +51,7 @@ class PLL_Data_Encoding * @since 3.6 * * @param mixed $data Data. + * * @return mixed|WP_Error Decoded data. A `WP_Error` object upon decoding failure. */ public function decode($data) @@ -78,6 +75,7 @@ class PLL_Data_Encoding * @since 3.6 * * @param mixed $data Data, passed by reference. + * * @return WP_Error */ public function decode_reference(&$data): WP_Error @@ -89,6 +87,7 @@ class PLL_Data_Encoding } $data = $value; + return new WP_Error(); } @@ -99,6 +98,7 @@ class PLL_Data_Encoding * @since 3.6 * * @param mixed $data Data. + * * @return mixed Decoded data. A `WP_Error` object upon encoding failure. */ public function encode($data) @@ -122,6 +122,7 @@ class PLL_Data_Encoding * @since 3.6 * * @param mixed $data Data, passed by reference. + * * @return WP_Error */ public function encode_reference(&$data): WP_Error @@ -133,6 +134,7 @@ class PLL_Data_Encoding } $data = $value; + return new WP_Error(); } @@ -142,11 +144,12 @@ class PLL_Data_Encoding * @since 3.6 * * @param mixed $data Data. + * * @return mixed|WP_Error Decoded data. A `WP_Error` object upon decoding failure. */ private function decode_from_json($data) { - if (! is_string($data)) { + if (!is_string($data)) { return new WP_Error('pll-json-not-a-string', 'Value is not a string.'); } @@ -165,13 +168,14 @@ class PLL_Data_Encoding * @since 3.6 * * @param mixed $data Data. + * * @return string|WP_Error Encoded data. A `WP_Error` object upon decoding failure. */ private function encode_to_json($data) { $encoded = wp_json_encode($data, JSON_PRESERVE_ZERO_FRACTION); // Cannot trigger an Exception since we use the default value for `$depth`. - if (! is_string($encoded)) { + if (!is_string($encoded)) { return new WP_Error('pll-json-encoding-error', json_last_error_msg()); } diff --git a/__plugins/polylang-pro-3.7.6/services/dom/dom-content.php b/__plugins/polylang-pro-3.7.6/services/dom/dom-content.php index 7dfd5fe566816045aebe31c29ffe961c2a40569e..2f1b9c8d2d831b86dbeeeee377349a2f9d0801ec 100644 --- a/__plugins/polylang-pro-3.7.6/services/dom/dom-content.php +++ b/__plugins/polylang-pro-3.7.6/services/dom/dom-content.php @@ -1,9 +1,5 @@ content = $content; - $this->charset = get_bloginfo('charset'); - $this->charset = is_string($this->charset) && ! empty($this->charset) ? $this->charset : 'UTF-8'; + $this->content = $content; + $this->charset = get_bloginfo('charset'); + $this->charset = is_string($this->charset) && !empty($this->charset) ? $this->charset : 'UTF-8'; $this->placeholder = substr(uniqid('pll_'), 0, 10); $this->placeholder = "@@{$this->placeholder}-%d@@"; } @@ -57,6 +54,7 @@ class PLL_DOM_Content * @uses DOMXPath * * @param string[] $rules Parsing rules. Ex: `[ '//figure/img/@alt' ]`. + * * @return string[] Path to matching nodes as array keys, extracted strings as array values. * Ex: `[ '/figure/img[1]/@alt' => 'Image alt text.' ]`. * @@ -65,12 +63,12 @@ class PLL_DOM_Content public function get_strings(array $rules) { if (empty($rules)) { - return array(); + return []; } - $matched_parts = array(); - $document = PLL_DOM_Document::from_html($this->content); - $xpath = new DOMXPath($document); + $matched_parts = []; + $document = PLL_DOM_Document::from_html($this->content); + $xpath = new DOMXPath($document); foreach ($rules as $parsing_rule) { $node_list = $xpath->query($parsing_rule); @@ -81,13 +79,13 @@ class PLL_DOM_Content } foreach ($node_list as $node) { - if (! $node instanceof DOMNode) { + if (!$node instanceof DOMNode) { continue; } $node_path = $node->getNodePath(); - if (! is_string($node_path)) { + if (!is_string($node_path)) { // Trouble. continue; } @@ -100,7 +98,7 @@ class PLL_DOM_Content $node_path = preg_replace('@/text\(\)$@', '', $node_path); - $matched_parts[ $node_path ] = $node_content; + $matched_parts[$node_path] = $node_content; } } @@ -116,21 +114,22 @@ class PLL_DOM_Content * * @param string[] $new_strings Path to matching nodes as array keys, new strings as array values. * Ex: `[ '/figure/img[1]/@alt' => 'New image alt text.' ]`. + * * @return string Content with replaced strings. * * @phpstan-param array $new_strings */ public function replace_content(array $new_strings) { - $document = PLL_DOM_Document::from_html($this->content); - $xpath = new DOMXPath($document); - $node_values = array(); - $incr = 0; + $document = PLL_DOM_Document::from_html($this->content); + $xpath = new DOMXPath($document); + $node_values = []; + $incr = 0; foreach ($new_strings as $node_path => $new_string) { $node_list = $xpath->query($node_path); - if (! $node_list instanceof DOMNodeList) { + if (!$node_list instanceof DOMNodeList) { // Error. continue; } @@ -138,40 +137,40 @@ class PLL_DOM_Content // Each node path corresponds to only one node: get the first node then. $node = $this->get_first_dom_node($node_list); - if (! $node instanceof DOMNode) { + if (!$node instanceof DOMNode) { continue; } - $node_placeholder = sprintf($this->placeholder, ++$incr); - $node_values[ $node_placeholder ] = html_entity_decode($new_string, ENT_QUOTES, $this->charset); + $node_placeholder = sprintf($this->placeholder, ++$incr); + $node_values[$node_placeholder] = html_entity_decode($new_string, ENT_QUOTES, $this->charset); if ($node instanceof DOMAttr) { /** * Tag attribute. * Escape the value and insert the placeholder. */ - $node_values[ $node_placeholder ] = esc_attr($node_values[ $node_placeholder ]); - $node->nodeValue = $node_placeholder; + $node_values[$node_placeholder] = esc_attr($node_values[$node_placeholder]); + $node->nodeValue = $node_placeholder; continue; } /** * Tag content. */ - if (! $node->ownerDocument instanceof DOMDocument) { + if (!$node->ownerDocument instanceof DOMDocument) { // Trouble. continue; } // 1- Remove all child nodes. while ($node->hasChildNodes()) { - if (! empty($node->firstChild)) { + if (!empty($node->firstChild)) { $node->removeChild($node->firstChild); } } // 2- Insert a placeholder node. - $node_values[ $node_placeholder ] = wp_kses_post($node_values[ $node_placeholder ]); + $node_values[$node_placeholder] = wp_kses_post($node_values[$node_placeholder]); $node->appendChild($node->ownerDocument->createTextNode($node_placeholder)); } @@ -192,6 +191,7 @@ class PLL_DOM_Content * @since 3.3 * * @param DOMNodeList $node_list A `DOMNodeList` element. + * * @return DOMNode|null A `DOMNode` element, or null if no elements have been found. */ private function get_first_dom_node(DOMNodeList $node_list) @@ -213,13 +213,14 @@ class PLL_DOM_Content * @since 3.3 * * @param DOMNode $node A node. + * * @return string */ private function get_node_content(DOMNode $node) { - if ($node instanceof DOMAttr || ! $node->hasChildNodes()) { + if ($node instanceof DOMAttr || !$node->hasChildNodes()) { // Tag attribute. - if (! is_string($node->nodeValue)) { + if (!is_string($node->nodeValue)) { return ''; } @@ -227,7 +228,7 @@ class PLL_DOM_Content } // Tag content. - if (! $node->ownerDocument instanceof DOMDocument) { + if (!$node->ownerDocument instanceof DOMDocument) { // Trouble. return ''; } @@ -235,14 +236,14 @@ class PLL_DOM_Content $content = ''; foreach (iterator_to_array($node->childNodes) as $node) { - if (! $node instanceof DOMNode || ! $node->ownerDocument instanceof DOMDocument) { + if (!$node instanceof DOMNode || !$node->ownerDocument instanceof DOMDocument) { // Don't return partial content: if there is at least 1 error, return an empty content. return ''; } $node_content = $node->ownerDocument->saveHTML($node); - if (! is_string($node_content)) { + if (!is_string($node_content)) { // Don't return partial content: if there is at least 1 error, return an empty content. return ''; } diff --git a/__plugins/polylang-pro-3.7.6/services/dom/dom-document.php b/__plugins/polylang-pro-3.7.6/services/dom/dom-document.php index 728f362afee21751ffafdfd77977eb3a5ba9e29b..b110a53c2fe596aa4dd7a5276706ceced7304224 100644 --- a/__plugins/polylang-pro-3.7.6/services/dom/dom-document.php +++ b/__plugins/polylang-pro-3.7.6/services/dom/dom-document.php @@ -1,11 +1,7 @@ preserveWhiteSpace = false; - $document->formatOutput = true; + $document->formatOutput = true; - return self::from_string($xml, $document, array( $document, 'loadXML' ), $flags); + return self::from_string($xml, $document, [$document, 'loadXML'], $flags); } /** @@ -60,6 +58,7 @@ class PLL_DOM_Document extends DOMDocument * @param int $flags Optional. A series of libxml flags to parameterize the loading. * Default is `LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD`. * {@link https://www.php.net/manual/en/libxml.constants.php}. + * * @return PLL_DOM_Document */ public static function from_html($html, $version = '1.0', $encoding = 'UTF-8', $flags = 0) @@ -71,11 +70,11 @@ class PLL_DOM_Document extends DOMDocument * Hack to enforce that the string will be processed with the right encoding by DOMDocument. * The added processing instruction is then removed by contains_not_allowed_node(). */ - $html = '' . $html; + $html = ''.$html; - $flags = ! empty($flags) ? $flags : LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD; + $flags = !empty($flags) ? $flags : LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD; - $document = self::from_string($html, $document, array( $document, 'loadHTML' ), $flags); + $document = self::from_string($html, $document, [$document, 'loadHTML'], $flags); $document->encoding = $encoding; // Enforce encoding, as it is not set by DOMDocument. return $document; @@ -92,15 +91,16 @@ class PLL_DOM_Document extends DOMDocument * @param PLL_DOM_Document $document A document parameterized to load the content into. * @param callable $function Method name which will handle the loading. * @param int $flags A series of libxml flags to parameterize the loading. {@link https://www.php.net/manual/en/libxml.constants.php}. + * * @return PLL_DOM_Document */ private static function from_string($string, $document, $function, $flags = 0) { - if (! empty($string)) { + if (!empty($string)) { // libxml2 version 2.9.0 and superior doesn't load external entities by default. libxml_disable_entity_loader() is deprecated since PHP 8.0.0 . $internal_errors = libxml_use_internal_errors(true); libxml_clear_errors(); - if (! defined('LIBXML_DOTTED_VERSION') || version_compare(LIBXML_DOTTED_VERSION, '2.9.0', '<')) { + if (!defined('LIBXML_DOTTED_VERSION') || version_compare(LIBXML_DOTTED_VERSION, '2.9.0', '<')) { $entity_loader = libxml_disable_entity_loader(true); // phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated $document = self::safe_load_string($string, $document, $function, $flags); libxml_disable_entity_loader($entity_loader); // phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated @@ -123,6 +123,7 @@ class PLL_DOM_Document extends DOMDocument * @param PLL_DOM_Document $document A configured instance of PLL_DOM_Document to load the string into. * @param callable $function Name of the loading method to use. * @param int $flags A series of libxml flags to parameterize the loading. {@link https://www.php.net/manual/en/libxml.constants.php}. + * * @return PLL_DOM_Document */ private static function safe_load_string($string, $document, $function, $flags = 0) @@ -140,7 +141,6 @@ class PLL_DOM_Document extends DOMDocument * Verifies that the document contains only nodes of allowed types. * * @since 3.1 - * * @see https://www.php.net/manual/en/dom.constants.php. * * @return bool @@ -148,9 +148,9 @@ class PLL_DOM_Document extends DOMDocument public function contains_not_allowed_node() { foreach ($this->childNodes as $node) { - if (! $node instanceof DOMNode || ! in_array( + if (!$node instanceof DOMNode || !in_array( $node->nodeType, - array( + [ XML_DOCUMENT_NODE, XML_ELEMENT_NODE, XML_ATTRIBUTE_NODE, @@ -158,7 +158,7 @@ class PLL_DOM_Document extends DOMDocument XML_COMMENT_NODE, XML_CDATA_SECTION_NODE, XML_PI_NODE, - ) + ] )) { return true; } @@ -167,6 +167,7 @@ class PLL_DOM_Document extends DOMDocument $this->removeChild($node); // Remove our hacky errors); + return !empty($this->errors); } /** diff --git a/__plugins/polylang-pro-3.7.6/services/dom/dom-nodes-iterator.php b/__plugins/polylang-pro-3.7.6/services/dom/dom-nodes-iterator.php index e0c22d4e0bb9fe0307294a79d190d6844094de43..9c0705495aac6c67cf21eb48748268485febf92b 100644 --- a/__plugins/polylang-pro-3.7.6/services/dom/dom-nodes-iterator.php +++ b/__plugins/polylang-pro-3.7.6/services/dom/dom-nodes-iterator.php @@ -1,8 +1,6 @@ current()) { return $this->current()->nodeName; } + return null; } @@ -95,7 +93,7 @@ class PLL_DOM_Nodes_Iterator implements RecursiveIterator #[\ReturnTypeWillChange] public function next() { - ++$this->offset; + $this->offset++; } /** @@ -135,6 +133,7 @@ class PLL_DOM_Nodes_Iterator implements RecursiveIterator if ($this->current()) { return new self($this->current()->childNodes); } + return null; } } diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-container.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-container.php index e19ecee80582c8a379142de561ce1d59a32a849f..7eeae9e02b4a828fcda80a3201462aaad73001d4 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-container.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-container.php @@ -1,9 +1,5 @@ */ - private $exports = array(); + private $exports = []; /** * Constructor. @@ -54,6 +50,7 @@ class PLL_Export_Container implements IteratorAggregate, Countable * * @param PLL_Language $source_language The export's source language. * @param PLL_Language $target_language The export's target language. + * * @return PLL_Export_Data */ public function get(PLL_Language $source_language, PLL_Language $target_language): PLL_Export_Data @@ -61,11 +58,11 @@ class PLL_Export_Container implements IteratorAggregate, Countable $export_key = "{$source_language->slug}/{$target_language->slug}"; $class_name = $this->class_name; - if (! array_key_exists($export_key, $this->exports)) { - $this->exports[ $export_key ] = new $class_name($source_language, $target_language); + if (!array_key_exists($export_key, $this->exports)) { + $this->exports[$export_key] = new $class_name($source_language, $target_language); } - return $this->exports[ $export_key ]; + return $this->exports[$export_key]; } /** diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-posts.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-posts.php index d4c7f21a2fee4d7c01f3d90b85e367f784363483..84278d89b8af1abc17fdf3ee64397022630edaee 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-posts.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-posts.php @@ -1,9 +1,5 @@ model = $model; - $this->export_posts = new PLL_Export_Posts($this->model->post); - $this->export_terms = new PLL_Export_Terms($this->model->term); + $this->export_posts = new PLL_Export_Posts($this->model->post); + $this->export_terms = new PLL_Export_Terms($this->model->term); $this->collect_posts = new PLL_Collect_Linked_Posts($this->model->options); $this->collect_terms = new PLL_Collect_Linked_Terms(); } @@ -71,16 +67,17 @@ class PLL_Export_Data_From_Posts * @param PLL_Export_Container $container Data to export. * @param WP_Post[] $posts An array containing `WP_Post` objects. * @param PLL_Language $target_language The target language of the posts. - * @param array $args { - * Optional. A list of optional arguments. + * @param array $args { + * Optional. A list of optional arguments. + * + * @var bool $include_translated_items Tells if items that are already translated in the target languages must + * also be exported. This applies only to linked items (like assigned + * terms, items from reusable blocks, etc). Default is false. + * } * - * @type bool $include_translated_items Tells if items that are already translated in the target languages must - * also be exported. This applies only to linked items (like assigned - * terms, items from reusable blocks, etc). Default is false. - * } * @return void */ - public function send_to_export(PLL_Export_Container $container, array $posts, PLL_Language $target_language, array $args = array()) + public function send_to_export(PLL_Export_Container $container, array $posts, PLL_Language $target_language, array $args = []) { $posts_to_export = $this->get_posts_to_export($posts, $target_language, $args); $this->export_posts->add_items($container, $posts_to_export, $target_language); @@ -97,23 +94,24 @@ class PLL_Export_Data_From_Posts * @param WP_Post[] $posts An array of posts. * @param PLL_Language $lang The target language of the posts. * @param array $args A list of optional arguments. + * * @return WP_Post[] */ - protected function get_posts_to_export(array $posts, PLL_Language $lang, array $args = array()): array + protected function get_posts_to_export(array $posts, PLL_Language $lang, array $args = []): array { - $include_translated_items = ! empty($args['include_translated_items']); - $post_types = $this->model->get_translated_post_types(); - $collected_posts = array_merge( + $include_translated_items = !empty($args['include_translated_items']); + $post_types = $this->model->get_translated_post_types(); + $collected_posts = array_merge( $posts, $this->collect_posts->get_linked_posts($posts, $post_types) ); - if (! $include_translated_items) { + if (!$include_translated_items) { // Remove items that are already translated in this language. foreach ($collected_posts as $i => $linked_post) { if ($this->model->post->get_translation($linked_post->ID, $lang)) { // A translation already exists. - unset($collected_posts[ $i ]); + unset($collected_posts[$i]); } } } @@ -130,22 +128,23 @@ class PLL_Export_Data_From_Posts * @param WP_Post[] $posts An array of posts. * @param PLL_Language $lang The target language of the posts. * @param array $args A list of optional arguments. + * * @return WP_Term[] */ - protected function get_terms_to_export(array $posts, PLL_Language $lang, array $args = array()): array + protected function get_terms_to_export(array $posts, PLL_Language $lang, array $args = []): array { - $include_translated_items = ! empty($args['include_translated_items']); - $taxonomies = $this->model->get_translated_taxonomies(); + $include_translated_items = !empty($args['include_translated_items']); + $taxonomies = $this->model->get_translated_taxonomies(); // Collect terms in posts. $collected_terms = $this->collect_terms->get_linked_terms($posts, $taxonomies); - if (! $include_translated_items) { + if (!$include_translated_items) { // Remove items that are already translated in this language. foreach ($collected_terms as $i => $term) { if ($this->model->term->get_translation($term->term_id, $lang)) { // A translation already exists. - unset($collected_terms[ $i ]); + unset($collected_terms[$i]); } } } diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-strings.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-strings.php index bfa430a7be971f4f7294220fe84d1f842af3c8e7..ad651294d533109946fd8a4bcf09a07c844dc711 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-strings.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-data-from-strings.php @@ -1,9 +1,5 @@ = 0 - && ! empty($ref['object_type']) && is_string($ref['object_type']) - && ! empty($ref['field_type']) && is_string($ref['field_type']); + && !empty($ref['object_type']) && is_string($ref['object_type']) + && !empty($ref['field_type']) && is_string($ref['field_type']); } /** diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-metas.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-metas.php index cede42274f0eaad49b2be6dfd1aa9e36ae88b274..35836c99cd6d20eea40e73ae6699d285f7d95380 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-metas.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-metas.php @@ -1,9 +1,5 @@ 1, * 'meta_to_translate_2' => 1, @@ -64,10 +62,11 @@ abstract class PLL_Export_Metas * ), * ), * ) + * * @param int $from ID of the source object. * @param int $to ID of the target object. */ - return (array) apply_filters("pll_{$this->meta_type}_metas_to_export", array(), $from, $to); + return (array) apply_filters("pll_{$this->meta_type}_metas_to_export", [], $from, $to); } /** @@ -77,6 +76,7 @@ abstract class PLL_Export_Metas * * @param int $from ID of the source object. * @param int $to ID of the target object. + * * @return array List of custom fields encodings. */ protected function get_meta_encodings(int $from, int $to): array @@ -90,14 +90,16 @@ abstract class PLL_Export_Metas * @param array $keys A recursive array containing nested meta sub keys to translate. Wildcards (`*`) can be * used to match any characters. If `*` are already present in the meta name or sub-key, * escape them with a baclslash: `\*`. + * * @example array( * 'meta_to_translate_1' => 'json', * 'meta_name_*_foobar' => 'json', * ) + * * @param int $from ID of the source object. * @param int $to ID of the target object. */ - return (array) apply_filters("pll_{$this->meta_type}_meta_encodings", array(), $from, $to); + return (array) apply_filters("pll_{$this->meta_type}_meta_encodings", [], $from, $to); } /** @@ -108,6 +110,7 @@ abstract class PLL_Export_Metas * @param PLL_Export_Data $export Export object. * @param int $from ID of the source object. * @param int $to ID of the target object. + * * @return void */ public function export(PLL_Export_Data $export, int $from, int $to = 0) @@ -120,23 +123,23 @@ abstract class PLL_Export_Metas $source_metas = get_metadata($this->meta_type, $from); - if (empty($source_metas) || ! is_array($source_metas)) { + if (empty($source_metas) || !is_array($source_metas)) { return; } - $tr_metas = get_metadata($this->meta_type, $to); - $tr_metas = is_array($tr_metas) ? $tr_metas : array(); + $tr_metas = get_metadata($this->meta_type, $to); + $tr_metas = is_array($tr_metas) ? $tr_metas : []; $encodings = $this->get_meta_encodings($from, $to); - $matcher = new PLL_Format_Util(); + $matcher = new PLL_Format_Util(); foreach ($meta_names_to_export as $meta_name => $meta_subfield) { $entries = $matcher->filter_list($source_metas, (string) $meta_name); foreach ($entries as $meta_name => $meta_values) { - $tr_meta_values = $tr_metas[ $meta_name ] ?? array(); - $encodings[ $meta_name ] = $encodings[ $meta_name ] ?? ''; - $decoder = new PLL_Data_Encoding($encodings[ $meta_name ]); - $index = 0; + $tr_meta_values = $tr_metas[$meta_name] ?? []; + $encodings[$meta_name] = $encodings[$meta_name] ?? ''; + $decoder = new PLL_Data_Encoding($encodings[$meta_name]); + $index = 0; foreach ($meta_values as $value_index => $meta_value) { if ($decoder->decode_reference($meta_value)->has_errors()) { @@ -144,12 +147,12 @@ abstract class PLL_Export_Metas continue; } - $meta_subfield = is_array($meta_subfield) ? $meta_subfield : array(); - $tr_value = isset($tr_meta_values[ $value_index ]) ? $tr_meta_values[ $value_index ] : array(); + $meta_subfield = is_array($meta_subfield) ? $meta_subfield : []; + $tr_value = isset($tr_meta_values[$value_index]) ? $tr_meta_values[$value_index] : []; if ($decoder->decode_reference($tr_value)->has_errors()) { // Error while decoding. - $tr_value = array(); + $tr_value = []; } $index += (int) $this->maybe_export_metas_sub_fields( @@ -160,7 +163,7 @@ abstract class PLL_Export_Metas $tr_value, $from, $export, - $encodings[ $meta_name ] + $encodings[$meta_name] ); } } @@ -173,7 +176,8 @@ abstract class PLL_Export_Metas * @since 3.3 * @since 3.6 New parameter `$object_id`. * - * @param array $fields_to_export A recursive array containing nested meta sub keys to translate. + * @param array $fields_to_export A recursive array containing nested meta sub keys to translate. + * * @example array( * 'sub_key_to_translate_1' => 1, * 'sub_key_to_translate_2' => array( @@ -181,6 +185,7 @@ abstract class PLL_Export_Metas * ), * ), * ) + * * @param string $parent_key_string A string containing parent keys separated with pipes. Each pipe in key * should be escaped to avoid conflicts. * @param int $index Index of the current meta value. Useful when a meta has several values. @@ -189,16 +194,17 @@ abstract class PLL_Export_Metas * @param int $object_id ID of the object the meta belongs to. * @param PLL_Export_Data $export Export object. * @param string $encoding Encoding format for the field group. + * * @return bool True if the meta value has been exported, false otherwise. */ protected function maybe_export_metas_sub_fields(array $fields_to_export, string $parent_key_string, int $index, $source_metas, $tr_metas, int $object_id, PLL_Export_Data $export, string $encoding = ''): bool { $is_exported = false; - if (! empty($fields_to_export)) { + if (!empty($fields_to_export)) { if (is_object($source_metas)) { $source_metas = get_object_vars($source_metas); - } elseif (! is_array($source_metas)) { + } elseif (!is_array($source_metas)) { return false; } @@ -209,15 +215,15 @@ abstract class PLL_Export_Metas foreach ($entries as $key => $meta_values) { $escaped_key = addcslashes((string) $key, '\\|'); - $key_string = "$parent_key_string|$escaped_key"; - $sub_field = is_array($field_value) ? $field_value : array(); + $key_string = "$parent_key_string|$escaped_key"; + $sub_field = is_array($field_value) ? $field_value : []; - if (is_array($tr_metas) && isset($tr_metas[ $key ])) { - $tr_sub_meta = $tr_metas[ $key ]; + if (is_array($tr_metas) && isset($tr_metas[$key])) { + $tr_sub_meta = $tr_metas[$key]; } elseif (is_object($tr_metas) && isset($tr_metas->$key)) { $tr_sub_meta = $tr_metas->$key; } else { - $tr_sub_meta = array(); + $tr_sub_meta = []; } $is_exported = $this->maybe_export_metas_sub_fields( @@ -247,26 +253,27 @@ abstract class PLL_Export_Metas } $export->add_translation_entry( - array( + [ 'object_type' => $this->meta_type, 'field_type' => $this->import_export_meta_type, 'object_id' => $object_id, - 'field_id' => $parent_key_string . $id_suffix, + 'field_id' => $parent_key_string.$id_suffix, 'encoding' => $encoding, - ), + ], $source_metas, is_scalar($tr_metas) ? (string) $tr_metas : '' ); + return true; } - if (! is_array($source_metas)) { + if (!is_array($source_metas)) { return false; } $tr_metas = (array) $tr_metas; foreach ($source_metas as $sub_field_index => $source_value) { - if (! is_scalar($source_value)) { + if (!is_scalar($source_value)) { continue; } @@ -277,15 +284,15 @@ abstract class PLL_Export_Metas } $escaped_key = addcslashes((string) $sub_field_index, '\\|'); - $tr_values = isset($tr_metas[ $sub_field_index ]) && is_scalar($tr_metas[ $sub_field_index ]) ? (string) $tr_metas[ $sub_field_index ] : ''; + $tr_values = isset($tr_metas[$sub_field_index]) && is_scalar($tr_metas[$sub_field_index]) ? (string) $tr_metas[$sub_field_index] : ''; $export->add_translation_entry( - array( + [ 'object_type' => $this->meta_type, 'field_type' => $this->import_export_meta_type, 'object_id' => $object_id, 'field_id' => "{$parent_key_string}|{$escaped_key}{$id_suffix}", 'encoding' => $encoding, - ), + ], $source_value, $tr_values ); diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-post-metas.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-post-metas.php index 7bd6b4f5dbbaeb83c4a719f62c12bcfa33812585..6ec924b0dd61374c4080e8b2dd4d64b4d1c79e1a 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-post-metas.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-post-metas.php @@ -1,11 +1,7 @@ meta_type = 'post'; + $this->meta_type = 'post'; $this->import_export_meta_type = PLL_Import_Export::POST_META; } @@ -29,18 +25,19 @@ class PLL_Export_Post_Metas extends PLL_Export_Metas * * @param int $from ID of the source object. * @param int $to ID of the target object. + * * @return string[] List of custom fields names. */ protected function get_meta_names_to_export(int $from, int $to): array { - $default_metas_to_export = array( + $default_metas_to_export = [ '_wp_attachment_image_alt' => 1, - 'footnotes' => array( - '*' => array( + 'footnotes' => [ + '*' => [ 'content' => 1, - ), - ), - ); + ], + ], + ]; /** This filter is documented in modules/import-export/export/export-metas.php */ return (array) apply_filters("pll_{$this->meta_type}_metas_to_export", $default_metas_to_export, $from, $to); @@ -53,13 +50,14 @@ class PLL_Export_Post_Metas extends PLL_Export_Metas * * @param int $from ID of the source object. * @param int $to ID of the target object. + * * @return array List of custom fields formats. */ protected function get_meta_encodings(int $from, int $to): array { - $formats = array( + $formats = [ 'footnotes' => 'json', - ); + ]; /** This filter is documented in modules/import-export/export/export-metas.php */ return (array) apply_filters("pll_{$this->meta_type}_meta_encodings", $formats, $from, $to); diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-posts.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-posts.php index 5c6b9ca1194104dd5a1fc3e6e72fa5c7e499064b..ce4a4e756a9809b505219879332b8f8286e3dcc8 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-posts.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-posts.php @@ -1,9 +1,5 @@ translated_object->get($item->ID, $export->get_target_language()); + $tr_id = $this->translated_object->get($item->ID, $export->get_target_language()); $tr_item = get_post($tr_id); - $default_fields = array( + $default_fields = [ PLL_Import_Export::POST_TITLE, PLL_Import_Export::POST_CONTENT, PLL_Import_Export::POST_EXCERPT, - ); + ]; /** * Filters which post fields we want to export. @@ -76,11 +73,11 @@ class PLL_Export_Posts extends PLL_Export_Translated_Objects ); } else { $export->add_translation_entry( - array( + [ 'object_type' => PLL_Import_Export::TYPE_POST, 'field_type' => $field, 'object_id' => $item->ID, - ), + ], $item->$field, $tr_item instanceof WP_Post ? $tr_item->$field : '' ); @@ -107,6 +104,7 @@ class PLL_Export_Posts extends PLL_Export_Translated_Objects * @since 3.6 * * @param int[] $ids Post IDs. + * * @return void * * @phpstan-param non-empty-array $ids @@ -122,6 +120,7 @@ class PLL_Export_Posts extends PLL_Export_Translated_Objects * @since 3.6 * * @param WP_Post $item Post to get ID from. + * * @return int Post ID. */ protected function get_item_id($item): int @@ -137,13 +136,14 @@ class PLL_Export_Posts extends PLL_Export_Translated_Objects * @param PLL_Export_Data $export Export object. * @param WP_Post $post Source post. * @param string $translation Translated post content. + * * @return void */ private function add_post_content(PLL_Export_Data $export, WP_Post $post, string $translation) { - $content = PLL_Translation_Walker_Factory::create_from($post->post_content); + $content = PLL_Translation_Walker_Factory::create_from($post->post_content); $translations = new Translations(); - $content->walk(array( $translations, 'add_entry' )); + $content->walk([$translations, 'add_entry']); foreach ($translations->entries as $entry) { if ('' === $entry->singular) { @@ -153,11 +153,11 @@ class PLL_Export_Posts extends PLL_Export_Translated_Objects // The translated post content isn't exported when source or translated posts have blocks. $translation = has_blocks($translation) || has_blocks($post->post_content) ? '' : $translation; $export->add_translation_entry( - array( + [ 'object_type' => PLL_Import_Export::TYPE_POST, 'field_type' => PLL_Import_Export::POST_CONTENT, 'object_id' => $post->ID, - ), + ], $entry->singular, $translation ); diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-strings.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-strings.php index 6ef683a3ca61aeb28b4c125365e9c7375bf68461..4d8314d30522ef89cbe3d540b466001d56db6bce 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-strings.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-strings.php @@ -1,9 +1,5 @@ */ - private $mo = array(); + private $mo = []; /** * Constructor. @@ -53,6 +49,7 @@ class PLL_Export_Strings * @param PLL_Export_Container $export_container Export container. * @param string[][] $items Items to export. * @param PLL_Language $target_language Language to translate into. + * * @return void * * @phpstan-param non-empty-array $items @@ -80,6 +77,7 @@ class PLL_Export_Strings * * @param PLL_Export_Data $export Export object. * @param string[] $item Item to export. + * * @return void * * @phpstan-param exportSource $item @@ -87,16 +85,16 @@ class PLL_Export_Strings public function add_item(PLL_Export_Data $export, array $item) { $translation = $this->get_translation($item['string'], $export->get_target_language()); - $ref = array( + $ref = [ 'object_type' => PLL_Import_Export::STRINGS_TRANSLATIONS, 'field_type' => 'string_translation', 'object_id' => 0, // Set 0 for strings so that this parameter is always filled. 'field_comment' => sprintf('%s, %s', $item['context'], $item['name']), - ); + ]; // Arrays use Windows line ending syntax. This is also performed in {@see Translation_Entry::key()}. - $source_string = str_replace(array( "\r\n", "\r" ), "\n", $item['string']); - $translation = str_replace(array( "\r\n", "\r" ), "\n", $translation); + $source_string = str_replace(["\r\n", "\r"], "\n", $item['string']); + $translation = str_replace(["\r\n", "\r"], "\n", $translation); if ('' === $source_string) { return; @@ -112,16 +110,17 @@ class PLL_Export_Strings * * @param string $item Source string. * @param PLL_Language $target_language Language to translate into. + * * @return string */ private function get_translation(string $item, PLL_Language $target_language): string { - if (! isset($this->mo[ $target_language->slug ])) { + if (!isset($this->mo[$target_language->slug])) { // Cache translations. - $this->mo[ $target_language->slug ] = new PLL_MO(); - $this->mo[ $target_language->slug ]->import_from_db($target_language); + $this->mo[$target_language->slug] = new PLL_MO(); + $this->mo[$target_language->slug]->import_from_db($target_language); } - return $this->mo[ $target_language->slug ]->translate($item); + return $this->mo[$target_language->slug]->translate($item); } } diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-term-metas.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-term-metas.php index 1e8ba4c8765883a74e4c7488c9278f114122db03..762db32c10a8aa6a37f38a00b3c6f838b45049d1 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-term-metas.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-term-metas.php @@ -1,11 +1,7 @@ meta_type = 'term'; + $this->meta_type = 'term'; $this->import_export_meta_type = PLL_Import_Export::TERM_META; } } diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-terms.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-terms.php index c90f1004feece7d61add7c57d917fda95c3dcc5c..5bcbba5d8cb611b52b3bc911e5ee690468bd5977 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-terms.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-terms.php @@ -1,9 +1,5 @@ translated_object->get($item->term_id, $export->get_target_language()); + $tr_id = $this->translated_object->get($item->term_id, $export->get_target_language()); $tr_item = get_term($tr_id); if ('' !== $item->name) { $export->add_translation_entry( - array( + [ 'object_type' => PLL_Import_Export::TYPE_TERM, 'field_type' => PLL_Import_Export::TERM_NAME, 'object_id' => $item->term_id, - ), + ], $item->name, $tr_item instanceof WP_Term ? $tr_item->name : '' ); @@ -62,11 +58,11 @@ class PLL_Export_Terms extends PLL_Export_Translated_Objects if ('' !== $item->description) { $export->add_translation_entry( - array( + [ 'object_type' => PLL_Import_Export::TYPE_TERM, 'field_type' => PLL_Import_Export::TERM_DESCRIPTION, 'object_id' => $item->term_id, - ), + ], $item->description, $tr_item instanceof WP_Term ? $tr_item->description : '' ); @@ -92,6 +88,7 @@ class PLL_Export_Terms extends PLL_Export_Translated_Objects * @since 3.6 * * @param int[] $ids Term IDs. + * * @return void * * @phpstan-param non-empty-array $ids @@ -107,6 +104,7 @@ class PLL_Export_Terms extends PLL_Export_Translated_Objects * @since 3.6 * * @param WP_Term $item Term to get ID from. + * * @return int Term ID. */ protected function get_item_id($item): int diff --git a/__plugins/polylang-pro-3.7.6/services/exporter/export-translated-objects.php b/__plugins/polylang-pro-3.7.6/services/exporter/export-translated-objects.php index f67ceaa8e79d77233726831fecf0deedc5f5f489..ffdb9ca3d7c54bd13b1b73171e9439abd221cffe 100644 --- a/__plugins/polylang-pro-3.7.6/services/exporter/export-translated-objects.php +++ b/__plugins/polylang-pro-3.7.6/services/exporter/export-translated-objects.php @@ -1,9 +1,5 @@ translated_object->get($this->get_item_id($item), $target_language); @@ -51,7 +48,7 @@ abstract class PLL_Export_Translated_Objects $tr_ids = array_filter($tr_ids); - if (! empty($tr_ids)) { + if (!empty($tr_ids)) { $this->add_to_cache($tr_ids); } @@ -73,6 +70,7 @@ abstract class PLL_Export_Translated_Objects * * @param PLL_Export_Data $export Export object. * @param object $item Item to export. + * * @return void */ abstract public function add_item(PLL_Export_Data $export, $item); @@ -83,15 +81,16 @@ abstract class PLL_Export_Translated_Objects * @since 3.6 * * @param array $items An array of items of the same instance. + * * @return array Array without duplicate items. */ public function remove_duplicate_items(array $items): array { - $all_items = array(); + $all_items = []; foreach ($items as $item) { - if (! isset($all_items[ $this->get_item_id($item) ])) { - $all_items[ $this->get_item_id($item) ] = $item; + if (!isset($all_items[$this->get_item_id($item)])) { + $all_items[$this->get_item_id($item)] = $item; } } @@ -104,6 +103,7 @@ abstract class PLL_Export_Translated_Objects * @since 3.6 * * @param int[] $ids Object IDs. + * * @return void * * @phpstan-param non-empty-array $ids @@ -116,6 +116,7 @@ abstract class PLL_Export_Translated_Objects * @since 3.6 * * @param object $item Item to get ID from. + * * @return int Object ID. * * @phpstan-return int<0, max> diff --git a/__plugins/polylang-pro-3.7.6/services/manage-user-capabilities.php b/__plugins/polylang-pro-3.7.6/services/manage-user-capabilities.php index d9e1acb381b114b8218ff56c2546973998e0cf3e..f6ed51a971daadc682193118aa64c5cb3a7d1470 100644 --- a/__plugins/polylang-pro-3.7.6/services/manage-user-capabilities.php +++ b/__plugins/polylang-pro-3.7.6/services/manage-user-capabilities.php @@ -1,9 +1,5 @@ id = $id; + $this->id = $id; $this->args = array_merge( - array( + [ 'class' => '', 'icon' => '', 'before' => '', 'after' => '', 'priority' => 10, - ), + ], $args ); @@ -75,9 +71,9 @@ abstract class PLL_Metabox_Button $this->args['class'] .= ' pll-before-post-translations-button'; } - add_action('pll_' . $args['position'], array( $this, 'add_icon' ), $this->args['priority']); - add_action('wp_ajax_toggle_' . $id, array( $this, 'toggle' )); - add_action('admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' )); + add_action('pll_'.$args['position'], [$this, 'add_icon'], $this->args['priority']); + add_action('wp_ajax_toggle_'.$id, [$this, 'toggle']); + add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); } /** @@ -96,10 +92,12 @@ abstract class PLL_Metabox_Button * * @param string $post_type Current post type. * @param bool $active New requested button state. + * * @return bool Whether the new button state is accepted or not. */ protected function toggle_option($post_type, $active) // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - {return true; + { + return true; } /** @@ -108,6 +106,7 @@ abstract class PLL_Metabox_Button * @since 2.1 * * @param string $post_type The current post type. + * * @return void */ public function add_icon($post_type) @@ -133,7 +132,7 @@ abstract class PLL_Metabox_Button $post_type = sanitize_key($_POST['post_type']); if (post_type_exists($post_type) && $this->toggle_option($post_type, $is_active)) { - $x = new WP_Ajax_Response(array( 'what' => 'icon', 'data' => $this->get_text($is_active) )); + $x = new WP_Ajax_Response(['what' => 'icon', 'data' => $this->get_text($is_active)]); $x->send(); } } @@ -147,6 +146,7 @@ abstract class PLL_Metabox_Button * @since 2.1 * * @param bool $is_active Whether the button is already active or not. + * * @return string */ protected function get_text($is_active) @@ -160,6 +160,7 @@ abstract class PLL_Metabox_Button * @since 2.1 * * @param bool $is_active Whether the button is already active or not. + * * @return string */ protected function get_html($is_active) @@ -169,7 +170,7 @@ abstract class PLL_Metabox_Button return sprintf( '%6$s%7$s', $this->id, - esc_attr($this->args['class']) . ($is_active ? ' wp-ui-text-highlight' : ''), + esc_attr($this->args['class']).($is_active ? ' wp-ui-text-highlight' : ''), esc_attr($text), esc_html($text), $is_active ? 'true' : 'false', @@ -190,13 +191,13 @@ abstract class PLL_Metabox_Button { $screen = get_current_screen(); - if ($screen && in_array($screen->base, array( 'post', 'media' )) && ! wp_script_is('pll_metabox_button', 'enqueued')) { + if ($screen && in_array($screen->base, ['post', 'media']) && !wp_script_is('pll_metabox_button', 'enqueued')) { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script( 'pll_metabox_button', - plugins_url('/js/build/metabox-button' . $suffix . '.js', POLYLANG_ROOT_FILE), - array( 'jquery', 'wp-ajax-response', 'post' ), + plugins_url('/js/build/metabox-button'.$suffix.'.js', POLYLANG_ROOT_FILE), + ['jquery', 'wp-ajax-response', 'post'], POLYLANG_VERSION, true ); @@ -204,13 +205,13 @@ abstract class PLL_Metabox_Button wp_localize_script( 'pll_metabox_button', 'pll_sync_post', - array( 'confirm_text' => __('You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang-pro') ) + ['confirm_text' => __('You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang-pro')] ); wp_enqueue_style( 'pll_metabox_button', - plugins_url('/css/build/metabox-button' . $suffix . '.css', POLYLANG_ROOT_FILE), - array(), + plugins_url('/css/build/metabox-button'.$suffix.'.css', POLYLANG_ROOT_FILE), + [], POLYLANG_VERSION ); } diff --git a/__plugins/polylang-pro-3.7.6/services/metabox-button/metabox-user-button.php b/__plugins/polylang-pro-3.7.6/services/metabox-button/metabox-user-button.php index 0825a0a2a6a0c57e673b16ba39b9e2300fc5ec40..c82b5837a72b1b44250218a7eb42daea734d0431 100644 --- a/__plugins/polylang-pro-3.7.6/services/metabox-button/metabox-user-button.php +++ b/__plugins/polylang-pro-3.7.6/services/metabox-button/metabox-user-button.php @@ -1,9 +1,5 @@ get(); - return ! empty($user_meta[ $post->post_type ]); + + return !empty($user_meta[$post->post_type]); } /** @@ -70,7 +67,8 @@ class PLL_Toggle_User_Meta public function get() { $user_meta = get_user_meta((int) get_current_user_id(), $this->get_meta_name(), true); - return is_array($user_meta) ? $user_meta : array(); + + return is_array($user_meta) ? $user_meta : []; } /** @@ -80,11 +78,12 @@ class PLL_Toggle_User_Meta * * @param bool[] $user_meta An array with post type as key and boolean as value. * @param WP_User|null $user An instance of `WP_User`. + * * @return bool */ public function update($user_meta, $user = null) { - if (! $user instanceof WP_User) { + if (!$user instanceof WP_User) { $user = wp_get_current_user(); } @@ -98,12 +97,13 @@ class PLL_Toggle_User_Meta * * @param string $post_type Current post type. * @param bool $active New requested button state. + * * @return bool Whether the new button state is accepted or not. */ public function toggle_option($post_type, $active) { - $user_meta = $this->get(); - $user_meta[ $post_type ] = (bool) $active; + $user_meta = $this->get(); + $user_meta[$post_type] = (bool) $active; return $this->update($user_meta); } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-block-parsing-rules.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-block-parsing-rules.php index 88b0071c9cacffe935f5d8e3e6ed8ef938a4be54..7d15702d5b80f375d3a71cd927e6a9b262d32b6b 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-block-parsing-rules.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-block-parsing-rules.php @@ -1,9 +1,5 @@ array( + private $parsing_rules_attributes = [ + 'core/comments-pagination-next' => [ 'label' => true, - ), - 'core/comments-pagination-previous' => array( + ], + 'core/comments-pagination-previous' => [ 'label' => true, - ), - 'core/home-link' => array( + ], + 'core/home-link' => [ 'label' => true, - ), - 'core/more' => array( + ], + 'core/more' => [ 'customText' => true, - ), - 'core/navigation-link' => array( + ], + 'core/navigation-link' => [ 'label' => true, 'title' => true, 'description' => true, - ), - 'core/navigation-submenu' => array( + ], + 'core/navigation-submenu' => [ 'label' => true, 'title' => true, 'description' => true, - ), - 'core/page-list-item' => array( + ], + 'core/page-list-item' => [ 'label' => true, 'title' => true, - ), - 'core/post-excerpt' => array( + ], + 'core/post-excerpt' => [ 'moreText' => true, - ), - 'core/post-navigation-link' => array( + ], + 'core/post-navigation-link' => [ 'label' => true, - ), - 'core/post-terms' => array( + ], + 'core/post-terms' => [ 'prefix' => true, 'suffix' => true, - ), - 'core/query' => array( - 'query' => array( + ], + 'core/query' => [ + 'query' => [ 'search' => true, - ), - ), - 'core/query-pagination-next' => array( + ], + ], + 'core/query-pagination-next' => [ 'label' => true, - ), - 'core/query-pagination-previous' => array( + ], + 'core/query-pagination-previous' => [ 'label' => true, - ), - 'core/read-more' => array( + ], + 'core/read-more' => [ 'content' => true, - ), - 'core/search' => array( + ], + 'core/search' => [ 'label' => true, 'placeholder' => true, 'buttonText' => true, - ), - 'core/social-link' => array( + ], + 'core/social-link' => [ 'label' => true, - ), - 'core/widget-group' => array( + ], + 'core/widget-group' => [ 'title' => true, - ), - ); + ], + ]; /** * Holds some rules as Xpath expressions to evaluate in the blocks content. * Keep this list alphabetically sorted when adding entries. * * @var string[][] + * * @phpstan-var XpathParsingRules */ - private $parsing_rules = array( - 'core/accordion-heading' => array( + private $parsing_rules = [ + 'core/accordion-heading' => [ '//span[@class="wp-block-accordion-heading__toggle-title"]', - ), - 'core/audio' => array( + ], + 'core/audio' => [ '//figure/figcaption', - ), - 'core/button' => array( + ], + 'core/button' => [ '//a', '//a/@href', - ), - 'core/cover' => array( + ], + 'core/cover' => [ '//div/p', - ), - 'core/cover-image' => array( + ], + 'core/cover-image' => [ '//div/p', - ), - 'core/details' => array( + ], + 'core/details' => [ '//details/summary', - ), - 'core/embed' => array( + ], + 'core/embed' => [ '//figure/figcaption', - ), - 'core/file' => array( + ], + 'core/file' => [ '//div/a', - ), - 'core/gallery' => array( + ], + 'core/gallery' => [ '//figure/figcaption', '//figure/img/@alt', // Backward compatibility. - ), - 'core/heading' => array( + ], + 'core/heading' => [ '//*[self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6]', - ), - 'core/image' => array( + ], + 'core/image' => [ '//figure/figcaption', '//figure/img/@alt|//figure/a/img/@alt', '//figure/img/@title|//figure/a/img/@title', '//figure/a/@href', - ), - 'core/list' => array( + ], + 'core/list' => [ '//ul/li|//ol/li', - ), - 'core/media-text' => array( + ], + 'core/media-text' => [ '//figure/img/@alt', - ), - 'core/paragraph' => array( + ], + 'core/paragraph' => [ '//p', - ), - 'core/preformatted' => array( + ], + 'core/preformatted' => [ '//pre', - ), - 'core/pullquote' => array( + ], + 'core/pullquote' => [ '//blockquote/p', '//blockquote/cite', - ), - 'core/quote' => array( + ], + 'core/quote' => [ '//blockquote/p', '//blockquote/cite', - ), - 'core/subhead' => array( + ], + 'core/subhead' => [ '//p', - ), - 'core/table' => array( + ], + 'core/table' => [ '//th', '//td', '//figure/figcaption', - ), - 'core/text-columns' => array( + ], + 'core/text-columns' => [ '//div[@class="wp-block-column"]', - ), - 'core/verse' => array( + ], + 'core/verse' => [ '//pre', - ), - 'core/video' => array( + ], + 'core/video' => [ '//figure/figcaption', - ), - ); + ], + ]; /** * List of known blocks that don't need to be parsed, because they don't contain contents to be translated. @@ -191,7 +189,7 @@ class PLL_Translation_Block_Parsing_Rules * * @var string[] */ - private $blocks_not_to_parse = array( + private $blocks_not_to_parse = [ 'core/buttons', 'core/code', 'core/column', @@ -202,12 +200,12 @@ class PLL_Translation_Block_Parsing_Rules 'core/separator', 'core/shortcode', 'core/spacer', - ); + ]; /** * Holds the name of the block type being currently parsed. * - * @var string $block_type Similar to {@see WP_Block_Parser_Block::$blockName}. + * @var string Similar to {@see WP_Block_Parser_Block::$blockName}. */ private $block_type; @@ -217,11 +215,13 @@ class PLL_Translation_Block_Parsing_Rules * @since 3.3 * * @param string $block_type {@see WP_Block_Parser_Block::$blockName}. + * * @return PLL_Translation_Block_Parsing_Rules $this This object with its $rules property updated. */ public function set_block_name($block_type) { $this->block_type = $block_type; + return $this; } @@ -232,6 +232,7 @@ class PLL_Translation_Block_Parsing_Rules * @since 3.3 * * @param string $content {@see WP_Block_Parser_Block::$innerContent}. + * * @return string[] Parsing rules as array keys, strings to translate as array values. * * @phpstan-return array @@ -240,18 +241,18 @@ class PLL_Translation_Block_Parsing_Rules { $rules = $this->get_parsing_rules($this->block_type); - if (! isset($rules[ $this->block_type ])) { - return array(); + if (!isset($rules[$this->block_type])) { + return []; } // Check if there's HTML encoded non-breaking-space, if so decode it for consistency. $content = str_replace(' ', html_entity_decode(' '), $content); - $rules = $rules[ $this->block_type ]; + $rules = $rules[$this->block_type]; $sanitized_content = wp_kses_post($content); if (empty($sanitized_content)) { - return array(); + return []; } return (new PLL_DOM_Content($content))->get_strings($rules); @@ -263,12 +264,14 @@ class PLL_Translation_Block_Parsing_Rules * @since 3.3 * * @param array $block An array mimicking a {@see WP_Block_Parser_Block}. + * * @return bool */ public function has_parsing_rules($block) { $rules = $this->get_parsing_rules($block['blockName']); - return isset($rules[ $block['blockName'] ]); + + return isset($rules[$block['blockName']]); } /** @@ -278,6 +281,7 @@ class PLL_Translation_Block_Parsing_Rules * @since 3.3 * * @param array $block An array mimicking a {@see WP_Block_Parser_Block}. + * * @return bool */ public function should_be_parsed($block) @@ -305,13 +309,14 @@ class PLL_Translation_Block_Parsing_Rules * * @param string|null $block_name Optional. The block name we want to get the parsing rules for. * Only necessary for back-compatibility with the old `core-embed/` blocks. + * * @return string[][] * * @phpstan-return XpathParsingRules */ private function get_parsing_rules($block_name = null) { - if (! isset($this->cache['parsing_rules']) || ! is_array($this->cache['parsing_rules'])) { + if (!isset($this->cache['parsing_rules']) || !is_array($this->cache['parsing_rules'])) { /** * Filters the rules as Xpath expressions to evaluate in the blocks content. * @@ -326,10 +331,10 @@ class PLL_Translation_Block_Parsing_Rules $parsing_rules = $this->cache['parsing_rules']; - if (is_string($block_name) && ! isset($parsing_rules[ $block_name ]) && strpos($block_name, 'core-embed/') === 0) { - $parsing_rules[ $block_name ] = array( + if (is_string($block_name) && !isset($parsing_rules[$block_name]) && strpos($block_name, 'core-embed/') === 0) { + $parsing_rules[$block_name] = [ '//figure/figcaption', - ); + ]; } return $parsing_rules; @@ -346,19 +351,19 @@ class PLL_Translation_Block_Parsing_Rules * Arrays values are `true` or an array containing sub attributes. * Wildcards are allowed. Ex: * array( - * 'block/name' => array( - * 'sub_key_1' => true, - * 'sub_key_2' => array( - * 'sub_sub_key_*' => true, - * ), - * ), + * 'block/name' => array( + * 'sub_key_1' => true, + * 'sub_key_2' => array( + * 'sub_sub_key_*' => true, + * ), + * ), * ) * * @phpstan-return AttributesParsingRules */ private function get_parsing_rules_for_attributes() { - if (! isset($this->cache['parsing_rules_for_attributes']) || ! is_array($this->cache['parsing_rules_for_attributes'])) { + if (!isset($this->cache['parsing_rules_for_attributes']) || !is_array($this->cache['parsing_rules_for_attributes'])) { /** * Filters the list of blocks attributes to translate. * @@ -366,17 +371,17 @@ class PLL_Translation_Block_Parsing_Rules * @since 3.6 Format changed from `array` to `array>`. * * @param array $parsing_rules_attributes Rules for block attributes to translate. - * Array keys are block names for the 1st level, then attribute names for the next levels. - * Arrays values are `true` or an array containing sub attributes. - * Wildcards are allowed. Ex: - * array( - * 'block/name' => array( - * 'sub_key_1' => true, - * 'sub_key_2' => array( - * 'sub_sub_key_*' => true, - * ), - * ), - * ) + * Array keys are block names for the 1st level, then attribute names for the next levels. + * Arrays values are `true` or an array containing sub attributes. + * Wildcards are allowed. Ex: + * array( + * 'block/name' => array( + * 'sub_key_1' => true, + * 'sub_key_2' => array( + * 'sub_sub_key_*' => true, + * ), + * ), + * ) */ $this->cache['parsing_rules_for_attributes'] = (array) apply_filters('pll_blocks_rules_for_attributes', $this->parsing_rules_attributes); @@ -394,22 +399,24 @@ class PLL_Translation_Block_Parsing_Rules * @since 3.6 * * @param array $rules Rules for attributes (old and new formats). + * * @return array Rules for attributes (new format only). * * @phpstan-param array|array)> $rules + * * @phpstan-return AttributesParsingRules */ private function handle_blocks_rules_for_attributes_old_format(array $rules): array { - $deprecated = array(); + $deprecated = []; // Change old format into new format. foreach ($rules as $block_name => $attributes) { foreach ($attributes as $index => $value) { if (is_string($value)) { $deprecated[] = $value; - $rules[ $block_name ][ $value ] = true; - unset($rules[ $block_name ][ $index ]); + $rules[$block_name][$value] = true; + unset($rules[$block_name][$index]); } } } @@ -421,9 +428,9 @@ class PLL_Translation_Block_Parsing_Rules * * @param bool $trigger Whether to trigger the error for deprecated argument format. Default true. */ - if (! empty($deprecated) && WP_DEBUG && apply_filters('deprecated_argument_trigger_error', true)) { - $message = "Filter 'pll_blocks_rules_for_attributes' was used with an argument format that is deprecated since version 3.6!"; - $message .= "\n
\n" . wp_strip_all_tags(var_export($deprecated, true)) . "\n
"; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export + if (!empty($deprecated) && WP_DEBUG && apply_filters('deprecated_argument_trigger_error', true)) { + $message = "Filter 'pll_blocks_rules_for_attributes' was used with an argument format that is deprecated since version 3.6!"; + $message .= "\n
\n".wp_strip_all_tags(var_export($deprecated, true))."\n
"; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export trigger_error($message, E_USER_DEPRECATED); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error, WordPress.Security.EscapeOutput.OutputNotEscaped } @@ -465,6 +472,7 @@ class PLL_Translation_Block_Parsing_Rules * @since 3.3 * * @param array $block An array mimicking a {@see WP_Block_Parser_Block}. + * * @return array An array with attributes to translate or an empty array. * * @phpstan-return array @@ -472,14 +480,14 @@ class PLL_Translation_Block_Parsing_Rules public function get_attributes_to_translate($block) { if (empty($block['attrs'])) { - return array(); + return []; } $rules = $this->get_parsing_rules_for_attributes(); - if (! isset($rules[ $block['blockName'] ])) { - return array(); + if (!isset($rules[$block['blockName']])) { + return []; } - return $rules[ $block['blockName'] ]; + return $rules[$block['blockName']]; } } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-content.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-content.php index dc05340c41e077d427b44d5d642daa812bcfa216..6d37413b6b14d4b699aee349b9b6df22b472a93d 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-content.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-content.php @@ -1,9 +1,7 @@ translations->translate( $from_post, Context::to_string( - array( + [ Context::FIELD => PLL_Import_Export::POST_TITLE, - ) + ] ) ); } @@ -63,13 +63,14 @@ class PLL_Translation_Content * @since 3.3 * * @param string $content The post_content field of the original WP_Post. + * * @return string */ public function translate_content($content) { $walker = PLL_Translation_Walker_Factory::create_from($content); - return $walker->walk(array( $this->translations, 'translate_entry' )); + return $walker->walk([$this->translations, 'translate_entry']); } /** @@ -78,6 +79,7 @@ class PLL_Translation_Content * @since 3.3 * * @param string $post_excerpt The post_excerpt field of the original WP_Post. + * * @return string */ public function translate_excerpt($post_excerpt) @@ -85,9 +87,9 @@ class PLL_Translation_Content return $this->translations->translate( $post_excerpt, Context::to_string( - array( + [ Context::FIELD => PLL_Import_Export::POST_EXCERPT, - ) + ] ) ); } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-data-model-interface.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-data-model-interface.php index a0b0e42b5f89e644d0809333f06cbf33652dfcd9..74b4ee6a2b401b11b90ca89894acebe8f68a441d 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-data-model-interface.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-data-model-interface.php @@ -1,9 +1,5 @@ , value_position: int, encoding: string}> */ protected $metas_to_translate; @@ -50,12 +48,12 @@ abstract class PLL_Translation_Metas * @since 3.3 * @since 3.7 $translations parameter added. * - * @param PLL_Sync_Metas $sync_metas Object to manage copied metas during import. - * @param Translations $translations Translations set where to look for the metas translations. + * @param PLL_Sync_Metas $sync_metas Object to manage copied metas during import. + * @param Translations $translations Translations set where to look for the metas translations. */ public function __construct(PLL_Sync_Metas $sync_metas, Translations $translations) { - $this->sync_metas = $sync_metas; + $this->sync_metas = $sync_metas; $this->translations = $this->sanitize_translations($translations); } @@ -86,6 +84,7 @@ abstract class PLL_Translation_Metas * @param int $tr_object_id Translated object to translate the metas from. * @param PLL_Language $target_language Target language object. * @param bool $copy Whether to copy source metas. For instance, if the translation is updated, there is no need to copy source metas. + * * @return void */ public function translate($src_object_id, $tr_object_id, PLL_Language $target_language, $copy) @@ -97,9 +96,9 @@ abstract class PLL_Translation_Metas * This avoids to copy source meta value and add another translated value to it... */ if ($copy) { - add_filter("pll_copy_{$this->get_type()}_metas", array( $this, 'remove_metas_to_translate' )); + add_filter("pll_copy_{$this->get_type()}_metas", [$this, 'remove_metas_to_translate']); $this->sync_metas->copy($src_object_id, $tr_object_id, $target_language->slug, false); - remove_filter("pll_copy_{$this->get_type()}_metas", array( $this, 'remove_metas_to_translate' )); + remove_filter("pll_copy_{$this->get_type()}_metas", [$this, 'remove_metas_to_translate']); } $this->translate_metas_values($src_object_id, $tr_object_id); @@ -111,6 +110,7 @@ abstract class PLL_Translation_Metas * @since 3.3 * * @param string[] $meta_keys Meta keys to copy. + * * @return string[] Filtered array of meta to copy. */ public function remove_metas_to_translate($meta_keys) @@ -125,51 +125,52 @@ abstract class PLL_Translation_Metas * * @param int $src_object_id Source object id. * @param int $tr_object_id Translated object id. + * * @return void */ private function translate_metas_values($src_object_id, $tr_object_id) { $src_metas = get_metadata($this->get_type(), $src_object_id); - if (! is_array($src_metas) || empty($src_metas)) { + if (!is_array($src_metas) || empty($src_metas)) { return; } - $tr_metas = array(); - $formats = array(); + $tr_metas = []; + $formats = []; foreach ($this->metas_to_translate as $meta) { $meta_key = $meta['meta_key']; - if (empty($src_metas[ $meta_key ])) { + if (empty($src_metas[$meta_key])) { // Exported meta key doesn't exist anymore ?! continue; } - if (! isset($formats[ $meta_key ])) { - $formats[ $meta_key ] = $meta['encoding']; + if (!isset($formats[$meta_key])) { + $formats[$meta_key] = $meta['encoding']; } - $src_meta_values = $src_metas[ $meta_key ]; - $decoder = new PLL_Data_Encoding($formats[ $meta_key ]); + $src_meta_values = $src_metas[$meta_key]; + $decoder = new PLL_Data_Encoding($formats[$meta_key]); - if (! empty($meta['meta_sub_keys']) && is_array($src_meta_values) && count($src_meta_values) > 1 && ! $this->has_only_scalar_values($src_meta_values, $decoder)) { + if (!empty($meta['meta_sub_keys']) && is_array($src_meta_values) && count($src_meta_values) > 1 && !$this->has_only_scalar_values($src_meta_values, $decoder)) { // Do not import meta with multiple non scalar values. continue; } - if (! isset($src_meta_values[ $meta['value_position'] ])) { + if (!isset($src_meta_values[$meta['value_position']])) { // Meta value doesn't match. continue; } - if (isset($tr_metas[ $meta_key ][ $meta['value_position'] ])) { + if (isset($tr_metas[$meta_key][$meta['value_position']])) { // Meta has already been decoded and translated, but other subfields remain to be processed. - $value_to_translate = $tr_metas[ $meta_key ][ $meta['value_position'] ]; + $value_to_translate = $tr_metas[$meta_key][$meta['value_position']]; } else { - $value_to_translate = $src_meta_values[ $meta['value_position'] ]; + $value_to_translate = $src_meta_values[$meta['value_position']]; - if (! empty($meta['meta_sub_keys'])) { + if (!empty($meta['meta_sub_keys'])) { // Sub field has to be translated, let's decode its value. if ($decoder->decode_reference($value_to_translate)->has_errors()) { // Error while decoding. @@ -178,7 +179,7 @@ abstract class PLL_Translation_Metas } } - $tr_metas[ $meta_key ][ $meta['value_position'] ] = $this->maybe_translate_metas_sub_fields($value_to_translate, $meta); + $tr_metas[$meta_key][$meta['value_position']] = $this->maybe_translate_metas_sub_fields($value_to_translate, $meta); } // Re-encode. @@ -192,7 +193,7 @@ abstract class PLL_Translation_Metas continue; } - foreach ($tr_metas[ $meta_key ] as &$tr_meta) { + foreach ($tr_metas[$meta_key] as &$tr_meta) { $decoder->encode_reference($tr_meta); } } @@ -211,6 +212,7 @@ abstract class PLL_Translation_Metas * * @param int $tr_object_id Translated object id. * @param array $tr_metas Translated metas value(s). + * * @return void */ private function insert_translated_metas($tr_object_id, array $tr_metas) @@ -243,20 +245,20 @@ abstract class PLL_Translation_Metas * @since 3.3 * * @return array[] { - * A list of arrays described as follows: + * A list of arrays described as follows: * - * @type string $meta_key The name of the meta. - * @type string[] $meta_sub_keys The meta subfields to translate. - * @type int $value_position The position of the value in case of multiple values. - * @type string $encoding Encoding format of the meta value. - * @type string $context_id ID key from entry context, useful to translate back. - * } + * @var string $meta_key The name of the meta. + * @var string[] $meta_sub_keys The meta subfields to translate. + * @var int $value_position The position of the value in case of multiple values. + * @var string $encoding Encoding format of the meta value. + * @var string $context_id ID key from entry context, useful to translate back. + * } * * @phpstan-return array, value_position: int, encoding: string}> */ private function get_metas_to_translate() { - $metas = array(); + $metas = []; foreach ($this->translations->entries as $entry) { if (Context::get_field($entry) !== $this->get_context()) { @@ -269,25 +271,25 @@ abstract class PLL_Translation_Metas } $position = 0; - $sub_keys = array(); + $sub_keys = []; if (preg_match('/^(?.+)(?::(?\d+))?$/U', $meta_identifier, $matches)) { // Extract position (i.e. index) of the meta string. $position = isset($matches['position']) ? absint($matches['position']) : 0; $sub_keys = preg_split('/(? ! empty($meta_key) ? $meta_key : '', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + $metas[] = [ + 'meta_key' => !empty($meta_key) ? $meta_key : '', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key 'meta_sub_keys' => $sub_keys, 'value_position' => $position, 'encoding' => Context::get_encoding($entry), 'context_id' => $meta_identifier, - ); + ]; } return $metas; @@ -299,19 +301,20 @@ abstract class PLL_Translation_Metas * @since 3.3 * * @param mixed $meta_value Meta value(s) to translate. - * @param array $meta { - * An array with the meta_key, subfields to translate (ordered by dimension) and value position. - * - * @type array $meta_sub_keys The meta sub keys. - * @type int $value_position The value position. - * @type string $encoding Meta encoding. - * @type string $context_id ID key from entry context, useful to translate back. - * } + * @param array $meta { + * An array with the meta_key, subfields to translate (ordered by dimension) and value position. + * + * @var array $meta_sub_keys The meta sub keys. + * @var int $value_position The value position. + * @var string $encoding Meta encoding. + * @var string $context_id ID key from entry context, useful to translate back. + * } + * * @return mixed Translated meta value(s). */ private function maybe_translate_metas_sub_fields($meta_value, array $meta) { - if (! is_array($meta_value) && ! is_object($meta_value) && ! is_scalar($meta_value)) { + if (!is_array($meta_value) && !is_object($meta_value) && !is_scalar($meta_value)) { // We're not able to translate something else for now. return $meta_value; } @@ -323,8 +326,8 @@ abstract class PLL_Translation_Metas $first_key = array_shift($meta['meta_sub_keys']); // Let's get the first subfield key to process. - if (is_array($meta_value) && isset($meta_value[ $first_key ])) { - $meta_value[ $first_key ] = $this->maybe_translate_sub_fields($meta_value[ $first_key ], $meta); + if (is_array($meta_value) && isset($meta_value[$first_key])) { + $meta_value[$first_key] = $this->maybe_translate_sub_fields($meta_value[$first_key], $meta); } elseif (is_object($meta_value) && isset($meta_value->$first_key)) { $meta_value->$first_key = $this->maybe_translate_sub_fields($meta_value->$first_key, $meta); } @@ -338,14 +341,15 @@ abstract class PLL_Translation_Metas * @since 3.7 * * @param array|object $meta_value Meta value(s) to translate. - * @param array $meta { - * An array with the meta_key, subfields to translate (ordered by dimension) and value position. - * - * @type array $meta_sub_keys The meta sub keys. - * @type int $value_position The value position. - * @type string $encoding Meta encoding. - * @type string $context_id ID key from entry context, useful to translate back. - * } + * @param array $meta { + * An array with the meta_key, subfields to translate (ordered by dimension) and value position. + * + * @var array $meta_sub_keys The meta sub keys. + * @var int $value_position The value position. + * @var string $encoding Meta encoding. + * @var string $context_id ID key from entry context, useful to translate back. + * } + * * @return mixed Translated meta value(s). */ private function maybe_translate_sub_fields($meta_value, array $meta) @@ -364,30 +368,31 @@ abstract class PLL_Translation_Metas * @since 3.7 * * @param mixed $meta_value Meta value to translate. - * @param array $meta { - * An array with the meta_key, subfields to translate (ordered by dimension) and value position. - * - * @type array $meta_sub_keys The meta sub keys. - * @type int $value_position The value position. - * @type string $encoding Meta encoding. - * @type string $context_id ID key from entry context, useful to translate back. - * } + * @param array $meta { + * An array with the meta_key, subfields to translate (ordered by dimension) and value position. + * + * @var array $meta_sub_keys The meta sub keys. + * @var int $value_position The value position. + * @var string $encoding Meta encoding. + * @var string $context_id ID key from entry context, useful to translate back. + * } + * * @return mixed Translated meta value. */ private function maybe_translate_field($meta_value, array $meta) { - if (! is_scalar($meta_value)) { + if (!is_scalar($meta_value)) { return $meta_value; } return $this->translations->translate( (string) $meta_value, Context::to_string( - array( + [ Context::FIELD => $this->get_context(), Context::ID => $meta['context_id'], Context::ENCODING => $meta['encoding'], - ) + ] ) ); } @@ -400,13 +405,14 @@ abstract class PLL_Translation_Metas * * @param array $array Array to check. * @param PLL_Data_Encoding $decoder Data decoder. + * * @return bool True if the array contains only scalar values, false otherwise. */ private function has_only_scalar_values(array $array, PLL_Data_Encoding $decoder) { foreach ($array as $value) { $value = $decoder->decode($value); - if (! is_scalar($value)) { + if (!is_scalar($value)) { return false; } } @@ -420,6 +426,7 @@ abstract class PLL_Translation_Metas * @since 3.7 * * @param Translations $translations Translations to sanitize. + * * @return Translations Sanitized translations. */ private function sanitize_translations(Translations $translations): Translations @@ -434,7 +441,7 @@ abstract class PLL_Translation_Metas continue; } - $translations->entries[ $key ]->translations[ $i ] = wp_kses_post($translation); + $translations->entries[$key]->translations[$i] = wp_kses_post($translation); } } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-object-model-trait.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-object-model-trait.php index e4e66dccdba145018d8d1fed91f3ddb3a73eb47a..c2dfe3f5c270c36304cf8852bfdfd063e5761f91 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-object-model-trait.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-object-model-trait.php @@ -1,9 +1,5 @@ model = &$polylang->model; - $this->sync = &$polylang->sync; - $this->sync_post_model = &$polylang->sync_post_model; - $this->sync_content = &$polylang->sync_content; + $this->model = &$polylang->model; + $this->sync = &$polylang->sync; + $this->sync_post_model = &$polylang->sync_post_model; + $this->sync_content = &$polylang->sync_content; $this->user_capabilities_manager = new PLL_Manage_User_Capabilities(); } @@ -73,35 +69,36 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * * @since 3.3 * - * @param array $entry { - * Import data. - * int $id Source object ID. - * Translations $data Object containing translated data. - * array $fields { - * Fields to create the new translation. - * string $post_status Post status to use during translation creation. - * } - * }. - * @param PLL_Language $target_language A language to translate into. + * @param array $entry { + * Import data. + * int $id Source object ID. + * Translations $data Object containing translated data. + * array $fields { + * Fields to create the new translation. + * string $post_status Post status to use during translation creation. + * } + * }. + * @param PLL_Language $target_language A language to translate into. + * * @return int|WP_Error The translated post ID, `WP_Error` on failure. * * @phpstan-param EntryData $entry */ public function translate(array $entry, PLL_Language $target_language) { - if (! $entry['data'] instanceof Translations) { + if (!$entry['data'] instanceof Translations) { /* translators: %d is a post ID. */ return new WP_Error('pll_translate_post_no_translations', sprintf(__('The post with ID %d could not be translated.', 'polylang-pro'), (int) $entry['id'])); } $source_post = get_post($entry['id']); - if (! $source_post instanceof WP_Post || ! $source_post->ID) { + if (!$source_post instanceof WP_Post || !$source_post->ID) { /* translators: %d is a post ID. */ return new WP_Error('pll_translate_post_no_source_post', sprintf(__('The post with ID %d could not be translated as it doesn\'t exist.', 'polylang-pro'), (int) $entry['id'])); } $tr_post_id = $this->model->post->get($entry['id'], $target_language); - $tr_post = $tr_post_id ? get_post($tr_post_id) : null; + $tr_post = $tr_post_id ? get_post($tr_post_id) : null; $this->user_capabilities_manager->forbid_unfiltered_html($source_post); @@ -122,17 +119,17 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface ); } - if (! $tr_post instanceof WP_Post) { + if (!$tr_post instanceof WP_Post) { /* translators: %d is a post ID. */ return new WP_Error('pll_translate_post_failed', sprintf(__('The post with ID %d could not be translated.', 'polylang-pro'), (int) $entry['id'])); } // Fix for `term_exists()`. - add_filter('term_exists_default_query_args', array( $this, 'term_exists_default_query_args' ), 10, 3); + add_filter('term_exists_default_query_args', [$this, 'term_exists_default_query_args'], 10, 3); $this->sync->taxonomies->copy($source_post->ID, $tr_post->ID, $target_language->slug); (new PLL_Translation_Post_Metas($this->sync->post_metas, $entry['data'])) - ->translate($source_post->ID, $tr_post->ID, $target_language, ! $translation_exists); + ->translate($source_post->ID, $tr_post->ID, $target_language, !$translation_exists); /** * Fires once a post has been translated. @@ -162,6 +159,7 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * @param array $data_import Import data, @see {self::translate()}. * @param WP_Post $source_post The source post object. * @param PLL_Language $target_language The language to translate into. + * * @return WP_Post|null The translated post object, `null` on failure. * * @phpstan-param EntryData $data_import @@ -175,18 +173,18 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface $tr_post = $this->translate_content($data_import, $source_post, $target_language, $tr_post); - if (! $tr_post instanceof WP_Post) { + if (!$tr_post instanceof WP_Post) { return null; } // Set post status in post data. - $data_import['fields'] = wp_parse_args($data_import['fields'], array( 'post_status' => 'draft' )); - $tr_post->post_status = $data_import['fields']['post_status']; + $data_import['fields'] = wp_parse_args($data_import['fields'], ['post_status' => 'draft']); + $tr_post->post_status = $data_import['fields']['post_status']; $tr_post_args = $tr_post->to_array(); $tr_id = wp_update_post(wp_slash($tr_post_args)); - if (! $tr_id) { + if (!$tr_id) { // Failure during post update. return null; } @@ -204,12 +202,13 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * @param int $from_id The post source id. * @param int $tr_id The translated post id. * @param string $lang The language slug of the translated post. + * * @return void */ protected function save_translations_group($from_id, $tr_id, $lang) { - $translations = $this->model->post->get_translations($from_id); - $translations[ $lang ] = $tr_id; + $translations = $this->model->post->get_translations($from_id); + $translations[$lang] = $tr_id; $this->model->post->save_translations($from_id, $translations); } @@ -223,6 +222,7 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * @param WP_Post $source_post The source post object. * @param PLL_Language $target_language The language to translate into. * @param WP_Post $tr_post The translated post object. + * * @return WP_Post|null The translated post object, `null` on failure. * * @phpstan-param EntryData $data_import @@ -232,7 +232,7 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface $this->maybe_unsync_posts($source_post->ID, $tr_post->ID, $target_language); $tr_post = $this->translate_content($data_import, $source_post, $target_language, $tr_post); - if (! $tr_post instanceof WP_Post) { + if (!$tr_post instanceof WP_Post) { return null; } @@ -251,12 +251,13 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * @param WP_Post $source_post The source post object. * @param PLL_Language $target_language The language to translate into. * @param WP_Post $tr_post The translated post object. + * * @return WP_Post|null The translated post object populated with new data. Null otherwise. */ protected function translate_content(array $data_import, WP_Post $source_post, PLL_Language $target_language, WP_Post $tr_post): ?WP_Post { - $translate_content = new PLL_Translation_Content($data_import['data']); - $tr_post->post_title = $translate_content->translate_title($source_post->post_title); + $translate_content = new PLL_Translation_Content($data_import['data']); + $tr_post->post_title = $translate_content->translate_title($source_post->post_title); $tr_post->post_excerpt = $translate_content->translate_excerpt($source_post->post_excerpt); $tr_post->post_content = $this->sync_content->translate_content( $translate_content->translate_content($source_post->post_content), @@ -287,12 +288,13 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * * @param WP_Post $source_post The Source Post. * @param WP_Post $tr_post The translated Post. + * * @return WP_Post The translated post. */ protected function copy_source_post($source_post, $tr_post) { // The columns to copy. - $columns = array( + $columns = [ 'post_author', 'post_content', 'post_title', @@ -303,7 +305,7 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface 'menu_order', 'post_mime_type', 'post_password', - ); + ]; foreach ($columns as $column) { $tr_post->{$column} = $source_post->{$column}; @@ -320,21 +322,22 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * * @param int[] $ids Array of source post ids. * @param PLL_Language $target_language The target language. + * * @return void */ private function assign_parents(array $ids, PLL_Language $target_language) { // Keep only the posts that have a parent. $posts = get_posts( - array( + [ 'include' => $ids, 'post_type' => 'any', 'post_status' => 'any', - 'post_parent__not_in' => array( 0 ), + 'post_parent__not_in' => [0], 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'fields' => 'id=>parent', - ) + ] ); if (empty($posts)) { @@ -342,9 +345,9 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface return; } - $tr_ids = array(); + $tr_ids = []; foreach ($posts as $child => $post) { - $tr_ids[ $child ] = $this->model->post->get($child, $target_language->slug); + $tr_ids[$child] = $this->model->post->get($child, $target_language->slug); } $tr_ids = array_filter($tr_ids); @@ -354,7 +357,7 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface } foreach ($posts as $child => $post) { - if (empty($tr_ids[ $child ])) { + if (empty($tr_ids[$child])) { // Not translated. continue; } @@ -367,10 +370,10 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface } wp_update_post( - array( - 'ID' => $tr_ids[ $child ], + [ + 'ID' => $tr_ids[$child], 'post_parent' => $tr_parent_post, - ) + ] ); } } @@ -379,26 +382,27 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * Filters default query arguments when checking if a term exists. * In `term_exists()`, WP 6.0 uses `get_terms()`, which is filtered by language by Polylang. * This filter prevents `term_exists()` to be filtered by language. - * Copied from PLL_Filters::term_exists_default_query_args + * Copied from PLL_Filters::term_exists_default_query_args. * * @since 3.3 * * @param array $defaults An array of arguments passed to get_terms(). * @param int|string $term The term to check. Accepts term ID, slug, or name. * @param string $taxonomy The taxonomy name to use. An empty string indicates the search is against all taxonomies. + * * @return array */ public function term_exists_default_query_args($defaults, $term, $taxonomy) { - if (! empty($taxonomy) && ! $this->model->is_translated_taxonomy($taxonomy)) { + if (!empty($taxonomy) && !$this->model->is_translated_taxonomy($taxonomy)) { return $defaults; } - if (! is_array($defaults)) { - $defaults = array(); + if (!is_array($defaults)) { + $defaults = []; } - if (! isset($defaults['lang'])) { + if (!isset($defaults['lang'])) { $defaults['lang'] = ''; } @@ -413,21 +417,22 @@ class PLL_Translation_Post_Model implements PLL_Translation_Data_Model_Interface * @param int $source_post_id Source post ID. * @param int $target_post_id Translated post ID. * @param PLL_Language $target_language Translated post language object. + * * @return void */ protected function maybe_unsync_posts($source_post_id, $target_post_id, $target_language) { - if (! $this->sync_post_model->are_synchronized($source_post_id, $target_post_id)) { + if (!$this->sync_post_model->are_synchronized($source_post_id, $target_post_id)) { return; } $sync_posts = $this->sync_post_model->get($source_post_id); - if (! isset($sync_posts[ $target_language->slug ]) || $sync_posts[ $target_language->slug ] !== $target_post_id) { + if (!isset($sync_posts[$target_language->slug]) || $sync_posts[$target_language->slug] !== $target_post_id) { return; } - unset($sync_posts[ $target_language->slug ]); + unset($sync_posts[$target_language->slug]); $this->sync_post_model->save_group($source_post_id, array_keys($sync_posts)); } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-strings-model.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-strings-model.php index ac402f3e5e9082951ba76be6a827b197b63e88cb..8f910696156b30a4206c49a8f675964784d529ee 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-strings-model.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-strings-model.php @@ -1,9 +1,5 @@ imported_strings = array(); // Reset the imported strings array. + $this->imported_strings = []; // Reset the imported strings array. $pll_mo = new PLL_MO(); $pll_mo->import_from_db($target_language); @@ -52,7 +51,7 @@ class PLL_Translation_Strings_Model implements PLL_Translation_Data_Model_Interf foreach ($translations->entries as $entry) { if (empty($entry->translations)) { - $entry->translations = array( '' ); + $entry->translations = ['']; } /** This filter is documented in /polylang/settings/table-string.php */ @@ -70,9 +69,9 @@ class PLL_Translation_Strings_Model implements PLL_Translation_Data_Model_Interf if (empty($key)) { continue; } - if (isset($pll_mo_clone->entries[ $key ]->translations[0]) || isset($registered_strings[ md5($key) ])) { + if (isset($pll_mo_clone->entries[$key]->translations[0]) || isset($registered_strings[md5($key)])) { // Checks that the string did not exist or has been edited before updating. - if (! isset($pll_mo_clone->entries[ $key ]->translations[0]) || $pll_mo_clone->entries[ $key ]->translations[0] !== $sanitized_translation) { + if (!isset($pll_mo_clone->entries[$key]->translations[0]) || $pll_mo_clone->entries[$key]->translations[0] !== $sanitized_translation) { $pll_mo->add_entry($pll_mo->make_entry($entry->singular, $sanitized_translation)); // Store the source strings as ids during the import process. $this->imported_strings[] = $entry->singular; @@ -97,6 +96,7 @@ class PLL_Translation_Strings_Model implements PLL_Translation_Data_Model_Interf * * @param string[] $ids The entity ids to process after translation. * @param PLL_Language $target_language The target language. + * * @return void */ public function do_after_process(array $ids, PLL_Language $target_language) //phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable @@ -110,14 +110,16 @@ class PLL_Translation_Strings_Model implements PLL_Translation_Data_Model_Interf * @since 3.3 Moved from PLL_Import_Action to PLL_Import_Strings. * @since 3.7 Moved from PLL_Import_Strings to PLL_Translation_Strings_Model. * - * @param Translation_Entry[] $translations An array with all the entries. - * @return Translation_Entry[] An array with the same entries with an empty context. + * @param Translation_Entry[] $translations An array with all the entries. + * + * @return Translation_Entry[] An array with the same entries with an empty context. */ private function remove_context_from_translations($translations) { foreach ($translations as $translation_entry) { $translation_entry->context = ''; } + return $translations; } } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-term-metas.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-term-metas.php index f0536dcf2b752d16d4608d291caa9b0a3588ad9e..67e1c9c89a5ad07760fb3ddcd18e87321f49ab25 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-term-metas.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-term-metas.php @@ -1,11 +1,7 @@ model = &$polylang->model; + $this->model = &$polylang->model; $this->sync_term_metas = &$polylang->sync->term_metas; } @@ -49,30 +45,31 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface * * @param array $entry Properties array of an entry. * @param PLL_Language $target_language The target language. + * * @return int|WP_Error The translated term id, `WP_Error` on failure. */ public function translate(array $entry, PLL_Language $target_language) { - if (! $entry['data'] instanceof Translations) { + if (!$entry['data'] instanceof Translations) { /* translators: %d is a term ID. */ return new WP_Error('pll_translate_term_no_translations', sprintf(__('The term with ID %d could not be translated.', 'polylang-pro'), (int) $entry['id'])); } $source_term = get_term($entry['id']); - if (! $source_term instanceof WP_Term) { + if (!$source_term instanceof WP_Term) { /* translators: %d is a term ID. */ return new WP_Error('pll_translate_term_no_source_term', sprintf(__('The term with ID %d could not be translated as it doesn\'t exist.', 'polylang-pro'), (int) $entry['id'])); } - $tr_term_name = $this->get_translated_term_name($source_term, $entry['data']); + $tr_term_name = $this->get_translated_term_name($source_term, $entry['data']); $tr_term_description = $this->get_translated_term_description($source_term, $entry['data']); - $tr_term_id = $this->model->term->get($entry['id'], $target_language); - $translation_exists = $tr_term_id > 0; + $tr_term_id = $this->model->term->get($entry['id'], $target_language); + $translation_exists = $tr_term_id > 0; if ($tr_term_id) { // The translation already exists. - $args = array(); + $args = []; // Don't update name or description if not provided in translations. if ($source_term->name !== $tr_term_name) { $args['name'] = $tr_term_name; @@ -87,10 +84,10 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface return new WP_Error('pll_translate_update_term_failed', sprintf(__('The term with ID %d could not be updated.', 'polylang-pro'), (int) $tr_term_id)); } } else { - $args = array( + $args = [ 'translations' => $this->model->term->get_translations($source_term->term_id), 'description' => $tr_term_description, - ); + ]; $tr_term = $this->model->term->insert($tr_term_name, $source_term->taxonomy, $target_language, $args); if (is_wp_error($tr_term)) { @@ -105,7 +102,7 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface $source_term->term_id, $tr_term_id, $target_language, - ! $translation_exists + !$translation_exists ); /** @var WP_Term $tr_term */ @@ -137,16 +134,17 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface * * @param WP_Term $source_term The source term object. * @param Translations $translations Translated data object. + * * @return string The translated name. */ private function get_translated_term_name(WP_Term $source_term, Translations $translations) { $translated = $translations->translate( $source_term->name, - Context::to_string(array( Context::FIELD => PLL_Import_Export::TERM_NAME )) + Context::to_string([Context::FIELD => PLL_Import_Export::TERM_NAME]) ); - return ! empty($translated) ? $translated : $source_term->name; + return !empty($translated) ? $translated : $source_term->name; } /** @@ -157,16 +155,17 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface * * @param WP_Term $source_term The source term object. * @param Translations $translations Translated data object. + * * @return string The translated description. */ private function get_translated_term_description(WP_Term $source_term, Translations $translations) { $translated = $translations->translate( $source_term->description, - Context::to_string(array( Context::FIELD => PLL_Import_Export::TERM_DESCRIPTION )) + Context::to_string([Context::FIELD => PLL_Import_Export::TERM_DESCRIPTION]) ); - return ! empty($translated) ? $translated : $source_term->description; + return !empty($translated) ? $translated : $source_term->description; } /** @@ -177,20 +176,21 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface * * @param int[] $ids Array of source term ids. * @param PLL_Language $target_language The target language. + * * @return void */ public function assign_parents(array $ids, PLL_Language $target_language) { // Get the terms with their parents (or 0). $terms = get_terms( - array( + [ 'include' => $ids, 'hide_empty' => false, 'fields' => 'id=>parent', - ) + ] ); - if (! is_array($terms)) { + if (!is_array($terms)) { // No terms with parents. return; } @@ -206,9 +206,9 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface return; } - $tr_ids = array(); + $tr_ids = []; foreach ($terms as $child => $term_id) { - $tr_ids[ $child ] = $this->model->term->get($child, $target_language->slug); + $tr_ids[$child] = $this->model->term->get($child, $target_language->slug); } $tr_ids = array_filter($tr_ids); @@ -218,7 +218,7 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface } foreach ($terms as $child => $term_id) { - if (empty($tr_ids[ $child ])) { + if (empty($tr_ids[$child])) { // Not translated. continue; } @@ -229,18 +229,18 @@ class PLL_Translation_Term_Model implements PLL_Translation_Data_Model_Interface continue; } - $tr_term_id = $this->model->term->get($tr_ids[ $child ], $target_language->slug); + $tr_term_id = $this->model->term->get($tr_ids[$child], $target_language->slug); if (empty($tr_term_id)) { continue; } $tr_term = get_term($tr_term_id); - if (! $tr_term instanceof WP_Term) { + if (!$tr_term instanceof WP_Term) { continue; } // Set term parent for shared slugs. - $this->model->term->update($tr_term->term_id, array( 'parent' => $tr_parent_term )); + $this->model->term->update($tr_term->term_id, ['parent' => $tr_parent_term]); } } } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-blocks.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-blocks.php index 4e06bc461be619677ffb4719635655927192ee98..12d7e0eb6120e0d8170c6b69b70ba44d3d6ab58d 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-blocks.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-blocks.php @@ -1,9 +1,5 @@ parsing_rules = new PLL_Translation_Block_Parsing_Rules(); - $this->blocks = parse_blocks($content); + $this->parsing_rules = new PLL_Translation_Block_Parsing_Rules(); + $this->blocks = parse_blocks($content); $this->placeholder_delimiter = sprintf('', wp_rand(1, 100000)); } @@ -80,12 +77,13 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * @since 3.3 * * @param callable $callback A callable to be applied on each block. + * * @return string The walked content, eventually transformed by the callback. */ public function walk($callback) { $this->callback = $callback; - $this->blocks = array_map(array( $this, 'apply' ), $this->blocks); + $this->blocks = array_map([$this, 'apply'], $this->blocks); return serialize_blocks($this->blocks); } @@ -98,24 +96,26 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * @since 3.3 * * @param array $block An associative array mimicking a WP_Block_Parser_Block object. + * * @return array An array mimicking a WP_Block_Parser_Block object. * * @phpstan-param Block $block + * * @phpstan-return Block */ private function apply($block) { - if (! empty($block['innerBlocks'])) { - $block['innerBlocks'] = array_map(array( $this, 'apply' ), $block['innerBlocks']); + if (!empty($block['innerBlocks'])) { + $block['innerBlocks'] = array_map([$this, 'apply'], $block['innerBlocks']); } - if (! $this->parsing_rules->should_be_parsed($block)) { + if (!$this->parsing_rules->should_be_parsed($block)) { // No contents to translate. return $block; } $attributes_to_translate = $this->parsing_rules->get_attributes_to_translate($block); - if (! empty($attributes_to_translate)) { + if (!empty($attributes_to_translate)) { $block['attrs'] = $this->parse_attributes($block['attrs'], $attributes_to_translate); } @@ -138,9 +138,11 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * @since 3.3 * * @param array $block An associative array mimicking a WP_Block_Parser_Block object. + * * @return array An array mimicking a WP_Block_Parser_Block object. * * @phpstan-param Block $block + * * @phpstan-return Block */ private function parse_with_rules($block) @@ -156,23 +158,23 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface return $block; } - $to_replace = array(); + $to_replace = []; foreach ($parsed_strings as $node_path => $parsed_string) { $entry = new Translation_Entry( - array( + [ 'singular' => $parsed_string, 'context' => Context::to_string( - array( + [ Context::FIELD => PLL_Import_Export::POST_CONTENT, - ) + ] ), - ) + ] ); - $result = call_user_func_array($this->callback, array( &$entry )); + $result = call_user_func_array($this->callback, [&$entry]); - if (! $result instanceof Translation_Entry || empty($result->translations)) { + if (!$result instanceof Translation_Entry || empty($result->translations)) { continue; } @@ -182,7 +184,7 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface continue; } - $to_replace[ $node_path ] = $translation; + $to_replace[$node_path] = $translation; } if (empty($to_replace)) { @@ -203,9 +205,11 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * @since 3.3 * * @param array $block An associative array mimicking a WP_Block_Parser_Block object. + * * @return array An array mimicking a WP_Block_Parser_Block object. * * @phpstan-param Block $block + * * @phpstan-return Block */ private function parse_as_html($block) @@ -213,7 +217,7 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface // Get the whole block's content to parse with placeholders. $source_string = $this->get_block_content_to_parse($block); - $walker = new PLL_Translation_Walker_Classic($source_string, array( self::BLOCK_PLACEHOLDER )); + $walker = new PLL_Translation_Walker_Classic($source_string, [self::BLOCK_PLACEHOLDER]); $result_string = $walker->walk($this->callback); // Put the content back into the block. @@ -226,6 +230,7 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * @since 3.3 * * @param array $block An associative array mimicking a WP_Block_Parser_Block object. + * * @return string The block's content as a string and with placeholders in place of sub-blocks. * * @phpstan-param Block $block @@ -249,9 +254,11 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * * @param array $block An associative array mimicking a WP_Block_Parser_Block object. * @param string $content The content to put back into the block. + * * @return array An array mimicking a WP_Block_Parser_Block object. * * @phpstan-param Block $block + * * @phpstan-return Block */ private function update_block_with_content(array $block, $content) @@ -259,7 +266,7 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface // Explode by using a delimiter. $content = str_replace( self::BLOCK_PLACEHOLDER, - $this->placeholder_delimiter . self::BLOCK_PLACEHOLDER . $this->placeholder_delimiter, + $this->placeholder_delimiter.self::BLOCK_PLACEHOLDER.$this->placeholder_delimiter, $content ); $content = explode($this->placeholder_delimiter, $content); @@ -284,20 +291,22 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * * @param mixed $attrs An array of attributes to parse, or an attribute value. * @param string[] $attributes_to_translate Optional. An array of attributes to translate. + * * @return mixed An array of parsed attributes, or a translated attribute value. * * @phpstan-param array $attributes_to_translate + * * @phpstan-return ( * $attrs is array ? array : ( * $attrs is scalar ? string : mixed * ) * ) */ - private function parse_attributes($attrs, array $attributes_to_translate = array()) + private function parse_attributes($attrs, array $attributes_to_translate = []) { - if (! empty($attributes_to_translate)) { + if (!empty($attributes_to_translate)) { // We have sub-keys to match. - if (! is_array($attrs)) { + if (!is_array($attrs)) { // No more attributes. return $attrs; } @@ -306,12 +315,12 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface foreach ($attributes_to_translate as $attribute_name => $attribute_sub_fields) { // Find the attributes matching `$attribute_name` (may contain wildcards). - $entries = $matcher->filter_list($attrs, (string) $attribute_name); - $sub_field = is_array($attribute_sub_fields) ? $attribute_sub_fields : array(); + $entries = $matcher->filter_list($attrs, (string) $attribute_name); + $sub_field = is_array($attribute_sub_fields) ? $attribute_sub_fields : []; foreach ($entries as $key => $values) { // Parse sub-attributes. - $attrs[ $key ] = $this->parse_attributes($attrs[ $key ], $sub_field); + $attrs[$key] = $this->parse_attributes($attrs[$key], $sub_field); } } @@ -320,7 +329,7 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface if (is_array($attrs)) { // No more sub-keys to match but we still have sub-attributes: return everything. - return array_map(array( $this, 'parse_attributes' ), $attrs); + return array_map([$this, 'parse_attributes'], $attrs); } if (is_scalar($attrs)) { @@ -350,9 +359,11 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * @since 3.6 * * @param array $block An associative array mimicking a WP_Block_Parser_Block object. + * * @return array An array mimicking a WP_Block_Parser_Block object. * * @phpstan-param Block $block + * * @phpstan-return Block */ private function parse_specific_blocks(array $block): array @@ -360,7 +371,7 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface if ('core/more' === $block['blockName'] && isset($block['attrs']['customText'])) { // Special case for 'core/more' block content that need to be updated according to its translated attribute. $core_more_content = ""; - $block = $this->update_block_with_content($block, $core_more_content); + $block = $this->update_block_with_content($block, $core_more_content); } return $block; @@ -372,23 +383,24 @@ class PLL_Translation_Walker_Blocks implements PLL_Translation_Walker_Interface * @since 3.6 * * @param string $attribute_value The attribute value. + * * @return string Translated entry, empty if none. */ private function add_entry_and_translate(string $attribute_value): string { $entry = new Translation_Entry( - array( + [ 'singular' => trim($attribute_value), 'context' => Context::to_string( - array( + [ Context::FIELD => PLL_Import_Export::POST_CONTENT, - ) + ] ), - ) + ] ); - $result = call_user_func_array($this->callback, array( &$entry )); - if (! $result instanceof Translation_Entry || empty($result->translations[0])) { + $result = call_user_func_array($this->callback, [&$entry]); + if (!$result instanceof Translation_Entry || empty($result->translations[0])) { return ''; } diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-classic.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-classic.php index ad484dbd1ca6064b7fd6679c07b377c70efd8796..ca918c22aa4ded5ea0d93cc712c681d124d769e4 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-classic.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-classic.php @@ -1,13 +1,9 @@ non_translatable_contents = $non_translatable_contents; - $this->content = $content; + $this->content = $content; } /** @@ -56,6 +52,7 @@ class PLL_Translation_Walker_Classic implements PLL_Translation_Walker_Interface * @since 3.3 * * @param callable $callback A transformation to apply to the content, whether it is for export or import. + * * @return string */ public function walk($callback) @@ -71,6 +68,7 @@ class PLL_Translation_Walker_Classic implements PLL_Translation_Walker_Interface * @since 3.3 * * @param string $content A post content to apply a callback onto. + * * @return string The processed content. */ private function apply($content) @@ -80,17 +78,17 @@ class PLL_Translation_Walker_Classic implements PLL_Translation_Walker_Interface return $content; } - $args = array( + $args = [ 'singular' => $content, 'context' => Context::to_string( - array( + [ Context::FIELD => PLL_Import_Export::POST_CONTENT, - ) + ] ), - ); + ]; $entry = new Translation_Entry($args); - $return = call_user_func_array($this->callback, array( &$entry )); + $return = call_user_func_array($this->callback, [&$entry]); if ($return instanceof Translation_Entry) { return $this->maybe_translate_entry($return); @@ -105,6 +103,7 @@ class PLL_Translation_Walker_Classic implements PLL_Translation_Walker_Interface * @since 3.3 * * @param Translation_Entry $entry A translation entry parsed from a translation document. + * * @return string The translated string. */ private function maybe_translate_entry($entry) diff --git a/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-factory.php b/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-factory.php index c9da8b481fd41f6dabfd76dc3b41971cf4e1824a..82317fcf7c655d95785c1716fb5eb01a16b619e9 100644 --- a/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-factory.php +++ b/__plugins/polylang-pro-3.7.6/services/translation/translation-walker-factory.php @@ -1,11 +1,7 @@ items = (array) apply_filters('pll_settings_licenses', array()); + $this->items = (array) apply_filters('pll_settings_licenses', []); + return $this->items; } @@ -60,8 +57,8 @@ trait Common_Trait */ private function hooks(): void { - add_action('admin_enqueue_scripts', array( $this, 'enqueue_scripts' )); - add_action('wp_ajax_pllu_deactivate_license', array( $this, 'deactivate_license' )); + add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); + add_action('wp_ajax_pllu_deactivate_license', [$this, 'deactivate_license']); } /** @@ -80,10 +77,10 @@ trait Common_Trait * in mind if this file is moved. */ $style_url = plugins_url("/css/build/license{$suffix}.css", __DIR__); - wp_enqueue_style('pll_license', $style_url, array(), POLYLANG_VERSION); + wp_enqueue_style('pll_license', $style_url, [], POLYLANG_VERSION); $script_url = plugins_url("/js/build/license{$suffix}.js", __DIR__); - wp_enqueue_script('pll_license', $script_url, array( 'wp-api-fetch' ), POLYLANG_VERSION, true); + wp_enqueue_script('pll_license', $script_url, ['wp-api-fetch'], POLYLANG_VERSION, true); } /** @@ -102,28 +99,28 @@ trait Common_Trait { check_ajax_referer(self::DEACTIVATE_LICENSE_NONCE_ACTION, '_pll_nonce'); - if (! current_user_can('manage_options')) { + if (!current_user_can('manage_options')) { wp_die(-1); } - if (! isset($_POST['id'])) { + if (!isset($_POST['id'])) { wp_die(0); } - $id = substr(sanitize_text_field(wp_unslash($_POST['id'])), 11); + $id = substr(sanitize_text_field(wp_unslash($_POST['id'])), 11); $licenses = $this->get_licenses(); - if (! isset($licenses[ $id ])) { + if (!isset($licenses[$id])) { wp_die(0); } - $license = $licenses[ $id ]->deactivate_license(); + $license = $licenses[$id]->deactivate_license(); wp_send_json_success( - array( + [ 'id' => $id, 'html' => $license->get_form_field(), - ) + ] ); } } diff --git a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/EDD_SL_Plugin_Updater.php b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/EDD_SL_Plugin_Updater.php index cff8552e4efd2ec71d43aa8261e0c90e9da4630f..af6b8c908a0c7212201b8cb289d0c7f9491c3bd5 100644 --- a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/EDD_SL_Plugin_Updater.php +++ b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/EDD_SL_Plugin_Updater.php @@ -1,20 +1,11 @@ api_url = trailingslashit($_api_url); - $this->api_data = $_api_data; - $this->plugin_file = $_plugin_file; - $this->name = plugin_basename($_plugin_file); - $this->slug = basename(dirname($_plugin_file)); - $this->version = $_api_data['version']; - $this->wp_override = isset($_api_data['wp_override']) ? (bool) $_api_data['wp_override'] : false; - $this->beta = ! empty($this->api_data['beta']) ? true : false; - $this->failed_request_cache_key = 'edd_sl_failed_http_' . md5($this->api_url); + $this->api_url = trailingslashit($_api_url); + $this->api_data = $_api_data; + $this->plugin_file = $_plugin_file; + $this->name = plugin_basename($_plugin_file); + $this->slug = basename(dirname($_plugin_file)); + $this->version = $_api_data['version']; + $this->wp_override = isset($_api_data['wp_override']) ? (bool) $_api_data['wp_override'] : false; + $this->beta = !empty($this->api_data['beta']) ? true : false; + $this->failed_request_cache_key = 'edd_sl_failed_http_'.md5($this->api_url); - $edd_plugin_data[ $this->slug ] = $this->api_data; + $edd_plugin_data[$this->slug] = $this->api_data; /** * Fires after the $edd_plugin_data is setup. @@ -85,11 +76,10 @@ class EDD_SL_Plugin_Updater */ public function init() { - - add_filter('pre_set_site_transient_update_plugins', array( $this, 'check_update' )); - add_filter('plugins_api', array( $this, 'plugins_api_filter' ), 10, 3); - add_action('after_plugin_row', array( $this, 'show_update_notification' ), 10, 2); - add_action('admin_init', array( $this, 'show_changelog' )); + add_filter('pre_set_site_transient_update_plugins', [$this, 'check_update']); + add_filter('plugins_api', [$this, 'plugins_api_filter'], 10, 3); + add_action('after_plugin_row', [$this, 'show_update_notification'], 10, 2); + add_action('admin_init', [$this, 'show_changelog']); } /** @@ -102,31 +92,31 @@ class EDD_SL_Plugin_Updater * * @uses api_request() * - * @param array $_transient_data Update array build by WordPress. + * @param array $_transient_data Update array build by WordPress. + * * @return array Modified update array with custom plugin data. */ public function check_update($_transient_data) { - - if (! is_object($_transient_data)) { + if (!is_object($_transient_data)) { $_transient_data = new stdClass(); } - if (! empty($_transient_data->response) && ! empty($_transient_data->response[ $this->name ]) && false === $this->wp_override) { + if (!empty($_transient_data->response) && !empty($_transient_data->response[$this->name]) && false === $this->wp_override) { return $_transient_data; } $current = $this->get_update_transient_data(); if (false !== $current && is_object($current) && isset($current->new_version)) { if (version_compare($this->version, $current->new_version, '<')) { - $_transient_data->response[ $this->name ] = $current; + $_transient_data->response[$this->name] = $current; } else { // Populating the no_update information is required to support auto-updates in WordPress 5.5. - $_transient_data->no_update[ $this->name ] = $current; + $_transient_data->no_update[$this->name] = $current; } } - $_transient_data->last_checked = time(); - $_transient_data->checked[ $this->name ] = $this->version; + $_transient_data->last_checked = time(); + $_transient_data->checked[$this->name] = $this->version; return $_transient_data; } @@ -144,23 +134,23 @@ class EDD_SL_Plugin_Updater if (false === $version_info) { $version_info = $this->api_request( 'plugin_latest_version', - array( + [ 'slug' => $this->slug, 'beta' => $this->beta, - ) + ] ); - if (! $version_info) { + if (!$version_info) { return false; } // This is required for your plugin to support auto-updates in WordPress 5.5. $version_info->plugin = $this->name; - $version_info->id = $this->name; + $version_info->id = $this->name; $version_info->tested = $this->get_tested_version($version_info); - if (! isset($version_info->requires)) { + if (!isset($version_info->requires)) { $version_info->requires = ''; } - if (! isset($version_info->requires_php)) { + if (!isset($version_info->requires_php)) { $version_info->requires_php = ''; } @@ -168,16 +158,16 @@ class EDD_SL_Plugin_Updater } // Added by Polylang. - $defaults = array( - 'url' => '', + $defaults = [ + 'url' => '', 'package' => '', - 'new_version' => '', - 'tested' => '', - 'requires' => '', - 'requires_php' => '', - 'icons' => new stdClass(), - 'banners' => new stdClass(), - ); + 'new_version' => '', + 'tested' => '', + 'requires' => '', + 'requires_php' => '', + 'icons' => new stdClass(), + 'banners' => new stdClass(), + ]; $version_info = (object) array_merge($defaults, (array) $version_info); // End of added by Polylang. @@ -190,26 +180,27 @@ class EDD_SL_Plugin_Updater * This is used for the update_plugins transient. * * @since 3.8.12 + * * @return \stdClass|false */ private function get_update_transient_data() { $version_info = $this->get_repo_api_data(); - if (! $version_info) { + if (!$version_info) { return false; } - $limited_data = new \stdClass(); - $limited_data->slug = $this->slug; - $limited_data->plugin = $this->name; - $limited_data->url = $version_info->url; - $limited_data->package = $version_info->package; - $limited_data->icons = $this->convert_object_to_array($version_info->icons); - $limited_data->banners = $this->convert_object_to_array($version_info->banners); - $limited_data->new_version = $version_info->new_version; - $limited_data->tested = $version_info->tested; - $limited_data->requires = $version_info->requires; + $limited_data = new \stdClass(); + $limited_data->slug = $this->slug; + $limited_data->plugin = $this->name; + $limited_data->url = $version_info->url; + $limited_data->package = $version_info->package; + $limited_data->icons = $this->convert_object_to_array($version_info->icons); + $limited_data->banners = $this->convert_object_to_array($version_info->banners); + $limited_data->new_version = $version_info->new_version; + $limited_data->tested = $version_info->tested; + $limited_data->requires = $version_info->requires; $limited_data->requires_php = $version_info->requires_php; return $limited_data; @@ -219,12 +210,13 @@ class EDD_SL_Plugin_Updater * Gets the plugin's tested version. * * @since 1.9.2 + * * @param object $version_info + * * @return null|string */ private function get_tested_version($version_info) { - // There is no tested version. if (empty($version_info->tested)) { return null; @@ -238,7 +230,7 @@ class EDD_SL_Plugin_Updater return $version_info->tested; } $current_version_parts = explode('.', $current_wp_version); - $tested_parts = explode('.', $version_info->tested); + $tested_parts = explode('.', $version_info->tested); // The current WordPress version is x.y.z, so update the tested version to match it. if (isset($current_version_parts[2]) && $current_version_parts[0] === $tested_parts[0] && $current_version_parts[1] === $tested_parts[1]) { @@ -251,19 +243,18 @@ class EDD_SL_Plugin_Updater /** * Show the update notification on multisite subsites. * - * @param string $file - * @param array $plugin + * @param string $file + * @param array $plugin */ public function show_update_notification($file, $plugin) { - // Return early if in the network admin, or if this is not a multisite install. - if (is_network_admin() || ! is_multisite()) { + if (is_network_admin() || !is_multisite()) { return; } // Allow single site admins to see that an update is available. - if (! current_user_can('activate_plugins')) { + if (!current_user_can('activate_plugins')) { return; } @@ -274,15 +265,15 @@ class EDD_SL_Plugin_Updater // Do not print any message if update does not exist. $update_cache = get_site_transient('update_plugins'); - if (! isset($update_cache->response[ $this->name ])) { - if (! is_object($update_cache)) { + if (!isset($update_cache->response[$this->name])) { + if (!is_object($update_cache)) { $update_cache = new stdClass(); } - $update_cache->response[ $this->name ] = $this->get_repo_api_data(); + $update_cache->response[$this->name] = $this->get_repo_api_data(); } // Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin. - if (empty($update_cache->response[ $this->name ]) || version_compare($this->version, $update_cache->response[ $this->name ]->new_version, '>=')) { + if (empty($update_cache->response[$this->name]) || version_compare($this->version, $update_cache->response[$this->name]->new_version, '>=')) { return; } @@ -297,24 +288,24 @@ class EDD_SL_Plugin_Updater echo '

'; $changelog_link = ''; - if (! empty($update_cache->response[ $this->name ]->sections->changelog)) { + if (!empty($update_cache->response[$this->name]->sections->changelog)) { $changelog_link = add_query_arg( - array( + [ 'edd_sl_action' => 'view_plugin_changelog', 'plugin' => urlencode($this->name), 'slug' => urlencode($this->slug), 'TB_iframe' => 'true', 'width' => 77, 'height' => 911, - ), + ], self_admin_url('index.php') ); } $update_link = add_query_arg( - array( + [ 'action' => 'upgrade-plugin', 'plugin' => urlencode($this->name), - ), + ], self_admin_url('update.php') ); @@ -324,33 +315,33 @@ class EDD_SL_Plugin_Updater esc_html($plugin['Name']) ); - if (! current_user_can('update_plugins')) { + if (!current_user_can('update_plugins')) { echo ' '; esc_html_e('Contact your network administrator to install the update.', 'polylang-wc'); - } elseif (empty($update_cache->response[ $this->name ]->package) && ! empty($changelog_link)) { + } elseif (empty($update_cache->response[$this->name]->package) && !empty($changelog_link)) { echo ' '; printf( /* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */ __('%1$sView version %2$s details%3$s.', 'polylang-wc'), - '', - esc_html($update_cache->response[ $this->name ]->new_version), + '', + esc_html($update_cache->response[$this->name]->new_version), '' ); - } elseif (! empty($changelog_link)) { + } elseif (!empty($changelog_link)) { echo ' '; printf( /* translators: 1. and 4. are opening anchor tags 2. the new plugin version 3. and 5. are closing anchor tags. */ __('%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'polylang-wc'), - '', - esc_html($update_cache->response[ $this->name ]->new_version), + '', + esc_html($update_cache->response[$this->name]->new_version), '', - '', + '', '' ); } else { printf( ' %1$s%2$s%3$s', - '', + '', esc_html__('Update now.', 'polylang-wc'), '' ); @@ -368,7 +359,7 @@ class EDD_SL_Plugin_Updater */ private function get_active_plugins() { - $active_plugins = (array) get_option('active_plugins'); + $active_plugins = (array) get_option('active_plugins'); $active_network_plugins = (array) get_site_option('active_sitewide_plugins'); return array_merge($active_plugins, array_keys($active_network_plugins)); @@ -379,42 +370,37 @@ class EDD_SL_Plugin_Updater * * @uses api_request() * - * @param mixed $_data - * @param string $_action - * @param object $_args + * @param mixed $_data + * @param string $_action + * @param object $_args + * * @return object $_data */ public function plugins_api_filter($_data, $_action = '', $_args = null) { - if ('plugin_information' !== $_action) { - return $_data; - } - if (! isset($_args->slug) || ($_args->slug !== $this->slug)) { - + if (!isset($_args->slug) || ($_args->slug !== $this->slug)) { return $_data; - } - $to_send = array( + $to_send = [ 'slug' => $this->slug, 'is_ssl' => is_ssl(), - 'fields' => array( - 'banners' => array(), + 'fields' => [ + 'banners' => [], 'reviews' => false, - 'icons' => array(), - ), - ); + 'icons' => [], + ], + ]; // Get the transient where we store the api request for this plugin for 24 hours $edd_api_request_transient = $this->get_cached_version_info(); //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now. if (empty($edd_api_request_transient)) { - $api_response = $this->api_request('plugin_information', $to_send); if (empty($api_response)) { return $_data; @@ -429,30 +415,30 @@ class EDD_SL_Plugin_Updater } // Convert sections into an associative array, since we're getting an object, but Core expects an array. - if (isset($_data->sections) && ! is_array($_data->sections)) { + if (isset($_data->sections) && !is_array($_data->sections)) { $_data->sections = $this->convert_object_to_array($_data->sections); } // Convert banners into an associative array, since we're getting an object, but Core expects an array. - if (isset($_data->banners) && ! is_array($_data->banners)) { + if (isset($_data->banners) && !is_array($_data->banners)) { $_data->banners = $this->convert_object_to_array($_data->banners); } // Convert icons into an associative array, since we're getting an object, but Core expects an array. - if (isset($_data->icons) && ! is_array($_data->icons)) { + if (isset($_data->icons) && !is_array($_data->icons)) { $_data->icons = $this->convert_object_to_array($_data->icons); } // Convert contributors into an associative array, since we're getting an object, but Core expects an array. - if (isset($_data->contributors) && ! is_array($_data->contributors)) { + if (isset($_data->contributors) && !is_array($_data->contributors)) { $_data->contributors = $this->convert_object_to_array($_data->contributors); } - if (! isset($_data->plugin)) { + if (!isset($_data->plugin)) { $_data->plugin = $this->name; } - if (! isset($_data->version) && ! empty($_data->new_version)) { + if (!isset($_data->version) && !empty($_data->new_version)) { $_data->version = $_data->new_version; } @@ -460,7 +446,7 @@ class EDD_SL_Plugin_Updater } /** - * Convert some objects to arrays when injecting data into the update API + * Convert some objects to arrays when injecting data into the update API. * * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON * decoding, they are objects. This method allows us to pass in the object and return an associative array. @@ -473,30 +459,31 @@ class EDD_SL_Plugin_Updater */ private function convert_object_to_array($data) { - if (! is_array($data) && ! is_object($data)) { - return array(); + if (!is_array($data) && !is_object($data)) { + return []; } - $new_data = array(); + $new_data = []; foreach ($data as $key => $value) { - $new_data[ $key ] = is_object($value) ? $this->convert_object_to_array($value) : $value; + $new_data[$key] = is_object($value) ? $this->convert_object_to_array($value) : $value; } return $new_data; } /** - * Disable SSL verification in order to prevent download update failures + * Disable SSL verification in order to prevent download update failures. + * + * @param array $args + * @param string $url * - * @param array $args - * @param string $url * @return object $array */ public function http_request_args($args, $url) { - if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) { $args['sslverify'] = $this->verify_ssl(); } + return $args; } @@ -507,8 +494,9 @@ class EDD_SL_Plugin_Updater * @uses wp_remote_post() * @uses is_wp_error() * - * @param string $_action The requested action. - * @param array $_data Parameters for the API action. + * @param string $_action The requested action. + * @param array $_data Parameters for the API action. + * * @return false|object|void */ private function api_request($_action, $_data) @@ -543,7 +531,7 @@ class EDD_SL_Plugin_Updater $failed_request_details = get_option($this->failed_request_cache_key); // Request has never failed. - if (empty($failed_request_details) || ! is_numeric($failed_request_details)) { + if (empty($failed_request_details) || !is_numeric($failed_request_details)) { return false; } @@ -568,7 +556,6 @@ class EDD_SL_Plugin_Updater * it with failed API requests. * * @see EDD_SL_Plugin_Updater::request_recently_failed - * * @since 1.9.1 */ private function log_failed_request() @@ -581,7 +568,6 @@ class EDD_SL_Plugin_Updater */ public function show_changelog() { - if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action']) { return; } @@ -594,15 +580,15 @@ class EDD_SL_Plugin_Updater return; } - if (! current_user_can('update_plugins')) { - wp_die(esc_html__('You do not have permission to install plugin updates', 'polylang-wc'), esc_html__('Error', 'polylang-wc'), array( 'response' => 403 )); + if (!current_user_can('update_plugins')) { + wp_die(esc_html__('You do not have permission to install plugin updates', 'polylang-wc'), esc_html__('Error', 'polylang-wc'), ['response' => 403]); } $version_info = $this->get_repo_api_data(); if (isset($version_info->sections)) { $sections = $this->convert_object_to_array($version_info->sections); - if (! empty($sections['changelog'])) { - echo '

' . wp_kses_post($sections['changelog']) . '
'; + if (!empty($sections['changelog'])) { + echo '
'.wp_kses_post($sections['changelog']).'
'; } } @@ -616,9 +602,9 @@ class EDD_SL_Plugin_Updater */ private function get_version_from_remote() { - $api_params = array( + $api_params = [ 'edd_action' => 'get_version', - 'license' => ! empty($this->api_data['license']) ? $this->api_data['license'] : '', + 'license' => !empty($this->api_data['license']) ? $this->api_data['license'] : '', 'item_name' => isset($this->api_data['item_name']) ? $this->api_data['item_name'] : false, 'item_id' => isset($this->api_data['item_id']) ? $this->api_data['item_id'] : false, 'version' => isset($this->api_data['version']) ? $this->api_data['version'] : false, @@ -628,7 +614,7 @@ class EDD_SL_Plugin_Updater 'beta' => $this->beta, 'php_version' => phpversion(), 'wp_version' => get_bloginfo('version'), - ); + ]; /** * Filters the parameters sent in the API request. @@ -641,11 +627,11 @@ class EDD_SL_Plugin_Updater $request = wp_remote_post( $this->api_url, - array( + [ 'timeout' => 15, 'sslverify' => $this->verify_ssl(), 'body' => $api_params, - ) + ] ); if (is_wp_error($request) || (200 !== wp_remote_retrieve_response_code($request))) { @@ -670,7 +656,7 @@ class EDD_SL_Plugin_Updater $request->icons = maybe_unserialize($request->icons); } - if (! empty($request->sections)) { + if (!empty($request->sections)) { foreach ($request->sections as $key => $section) { $request->$key = (array) $section; } @@ -683,11 +669,11 @@ class EDD_SL_Plugin_Updater * Get the version info from the cache, if it exists. * * @param string $cache_key + * * @return object */ public function get_cached_version_info($cache_key = '') { - if (empty($cache_key)) { $cache_key = $this->get_cache_key(); } @@ -701,7 +687,7 @@ class EDD_SL_Plugin_Updater // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point. $cache['value'] = json_decode($cache['value']); - if (! empty($cache['value']->icons)) { + if (!empty($cache['value']->icons)) { $cache['value']->icons = (array) $cache['value']->icons; } @@ -716,26 +702,26 @@ class EDD_SL_Plugin_Updater */ public function set_version_info_cache($value = '', $cache_key = '') { - if (empty($cache_key)) { $cache_key = $this->get_cache_key(); } - $data = array( + $data = [ 'timeout' => strtotime('+3 hours', time()), 'value' => wp_json_encode($value), - ); + ]; update_option($cache_key, $data, 'no'); // Delete the duplicate option - delete_option('edd_api_request_' . md5(serialize($this->slug . $this->api_data['license'] . $this->beta))); + delete_option('edd_api_request_'.md5(serialize($this->slug.$this->api_data['license'].$this->beta))); } /** * Returns if the SSL of the store should be verified. * * @since 1.6.13 + * * @return bool */ private function verify_ssl() @@ -747,12 +733,13 @@ class EDD_SL_Plugin_Updater * Gets the unique key (option name) for a plugin. * * @since 1.9.0 + * * @return string */ private function get_cache_key() { - $string = $this->slug . $this->api_data['license'] . $this->beta; + $string = $this->slug.$this->api_data['license'].$this->beta; - return 'edd_sl_' . md5(serialize($string)); + return 'edd_sl_'.md5(serialize($string)); } } diff --git a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/License.php b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/License.php index aa209917ab4d0a0bdc262d1c0100644943ece58e..dfceb2d2ae65911bd1314260298c9e159a06863c 100644 --- a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/License.php +++ b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/License.php @@ -1,9 +1,5 @@ id = sanitize_title($item_name); - $this->file = $file; - $this->name = $item_name; + $this->id = sanitize_title($item_name); + $this->file = $file; + $this->name = $item_name; $this->version = $version; - $licenses = (array) get_option('polylang_licenses', array()); - $license = isset($licenses[ $this->id ]) && is_array($licenses[ $this->id ]) ? $licenses[ $this->id ] : array(); - $this->license_key = ! empty($license['key']) ? (string) $license['key'] : ''; + $licenses = (array) get_option('polylang_licenses', []); + $license = isset($licenses[$this->id]) && is_array($licenses[$this->id]) ? $licenses[$this->id] : []; + $this->license_key = !empty($license['key']) ? (string) $license['key'] : ''; - if (! empty($license['data'])) { + if (!empty($license['data'])) { $this->license_data = (object) $license['data']; } @@ -106,15 +102,15 @@ class License $this->auto_updater(); // Register settings. - add_filter('pll_settings_modules', array( $this, 'settings_module' )); - add_filter('pll_settings_licenses', array( $this, 'settings' )); + add_filter('pll_settings_modules', [$this, 'settings_module']); + add_filter('pll_settings_licenses', [$this, 'settings']); // Weekly schedule. - if (! wp_next_scheduled('polylang_check_licenses')) { + if (!wp_next_scheduled('polylang_check_licenses')) { wp_schedule_event(time(), 'weekly', 'polylang_check_licenses'); } - add_action('polylang_check_licenses', array( $this, 'check_license' )); + add_action('polylang_check_licenses', [$this, 'check_license']); } /** @@ -126,12 +122,12 @@ class License */ public function auto_updater(): void { - $args = array( + $args = [ 'version' => $this->version, 'license' => $this->license_key, 'author' => $this->author, 'item_name' => $this->name, - ); + ]; // Setup the updater. new EDD_SL_Plugin_Updater($this->api_url, $this->file, $args); @@ -144,6 +140,7 @@ class License * @since 1.0 * * @param string[] $modules The list of module classes. + * * @return string[] */ public function settings_module($modules) @@ -152,11 +149,12 @@ class License * Backward compatibility with Polylang < 3.7. * Remove old license settings class to avoid duplicate. */ - $modules = array_diff($modules, array( 'PLL_Settings_Licenses' )); + $modules = array_diff($modules, ['PLL_Settings_Licenses']); if (empty($modules['licenses'])) { $modules['licenses'] = Settings::class; } + return $modules; } @@ -167,11 +165,13 @@ class License * @since 1.0 * * @param License[] $items Array of objects allowing to manage a license. + * * @return License[] */ public function settings($items) { - $items[ $this->id ] = $this; + $items[$this->id] = $this; + return $items; } @@ -181,6 +181,7 @@ class License * @since 1.0 * * @param string $license_key Activation key. + * * @return self Updated License object. */ public function activate_license( @@ -192,10 +193,10 @@ class License // Tell WordPress to look for updates. delete_site_transient('update_plugins'); + return $this; } - /** * Deactivates the license key. * @@ -206,6 +207,7 @@ class License public function deactivate_license(): self { $this->api_request('deactivate_license'); + return $this; } @@ -229,6 +231,7 @@ class License * @since 1.0 * * @param string $request Type of request: check_license | activate_license | deactivate_license. + * * @return void * * @phpstan-param 'check_license'|'activate_license'|'deactivate_license' $request @@ -238,29 +241,29 @@ class License $licenses = get_option('polylang_licenses'); if (is_array($licenses)) { - unset($licenses[ $this->id ]); + unset($licenses[$this->id]); } else { - $licenses = array(); + $licenses = []; } unset($this->license_data); - if (! empty($this->license_key)) { + if (!empty($this->license_key)) { // Data to send in our API request. - $api_params = array( + $api_params = [ 'edd_action' => $request, 'license' => $this->license_key, 'item_name' => rawurlencode($this->name), 'url' => home_url(), - ); + ]; // Call the API. $response = wp_remote_post( $this->api_url, - array( + [ 'timeout' => 3, 'sslverify' => false, 'body' => $api_params, - ) + ] ); // Update the option only if we got a response. @@ -269,13 +272,13 @@ class License } // Save new license info. - $licenses[ $this->id ] = array( 'key' => $this->license_key ); + $licenses[$this->id] = ['key' => $this->license_key]; $data = (object) json_decode(wp_remote_retrieve_body($response)); if (isset($data->license) && 'deactivated' !== $data->license) { - $licenses[ $this->id ]['data'] = $data; - $this->license_data = $data; + $licenses[$this->id]['data'] = $data; + $this->license_data = $data; } } @@ -291,33 +294,33 @@ class License */ public function get_form_field(): string { - if (! empty($this->license_data)) { + if (!empty($this->license_data)) { $license = $this->license_data; } - $atts = array( + $atts = [ 'id' => $this->id, 'name' => $this->name, 'license_key' => $this->license_key, 'row_class' => 'license-null', 'button_text' => '', 'message' => '', - ); + ]; - if (! empty($license) && is_object($license)) { - $now = time(); + if (!empty($license) && is_object($license)) { + $now = time(); $expiration = isset($license->expires) ? strtotime($license->expires) : false; // Special case: the license expired after the last check. if ($license->success && $expiration && $expiration < $now) { $license->success = false; - $license->error = 'expired'; + $license->error = 'expired'; } if (false === $license->success) { $atts['row_class'] = 'notice-error notice-alt'; - if (empty($license->error) && ! empty($license->license)) { + if (empty($license->error) && !empty($license->license)) { $license->error = $license->license; } @@ -372,14 +375,14 @@ class License break; } } else { - $atts['row_class'] = 'license-valid'; + $atts['row_class'] = 'license-valid'; $atts['button_text'] = __('Deactivate', 'polylang-wc'); if ('lifetime' === $license->expires) { $atts['message'] = __('The license key never expires.', 'polylang-wc'); } elseif ($expiration > $now && $expiration - $now < (DAY_IN_SECONDS * 30)) { $atts['row_class'] = 'notice-warning notice-alt'; - $atts['message'] = sprintf( + $atts['message'] = sprintf( /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ __('Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s', 'polylang-wc'), date_i18n(get_option('date_format'), $expiration), @@ -397,7 +400,8 @@ class License } ob_start(); - include __DIR__ . '/views/view-field-row.php'; + include __DIR__.'/views/view-field-row.php'; + return (string) ob_get_clean(); } } diff --git a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Settings.php b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Settings.php index 1c78f397a924acd0e8a03993fbd9d33d316ce2f6..aa5e3881c0fd8bfda617a1cc53b7726df0b7c85d 100644 --- a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Settings.php +++ b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Settings.php @@ -1,9 +1,5 @@ 'licenses', 'title' => __('License keys', 'polylang-wc'), 'description' => __('Manage licenses for Polylang Pro and add-ons.', 'polylang-wc'), - ) + ] ); $this->buttons['cancel'] = sprintf('', __('Close', 'polylang-wc')); @@ -73,15 +69,15 @@ class Settings extends PLL_Settings_Module * Useless because replaced by the following hook, so let's remove it so it doesn't clutter * the global `$wp_filter`. */ - remove_action('wp_ajax_pll_save_options', array( $this, 'save_options' )); + remove_action('wp_ajax_pll_save_options', [$this, 'save_options']); /* * Before `PLL_Settings_Module::save_options()`, to ensure that our response to * ajax action is executed and not the Polylang legacy licenses system. */ - add_action('wp_ajax_pll_save_options', array( $this, 'save_options' ), 5); + add_action('wp_ajax_pll_save_options', [$this, 'save_options'], 5); - add_action('wp_ajax_' . self::GET_LICENSES_DATA_ACTION, array( $this, 'display_licenses' )); + add_action('wp_ajax_'.self::GET_LICENSES_DATA_ACTION, [$this, 'display_licenses']); } /** @@ -93,7 +89,7 @@ class Settings extends PLL_Settings_Module */ public function is_active(): bool { - return ! empty($this->get_licenses()); + return !empty($this->get_licenses()); } /** @@ -103,16 +99,16 @@ class Settings extends PLL_Settings_Module */ protected function form(): void { - if (! $this->is_active()) { + if (!$this->is_active()) { return; } - $atts = array( + $atts = [ 'action' => self::GET_LICENSES_DATA_ACTION, 'nonce' => wp_create_nonce(self::GET_LICENSES_DATA_ACTION), - ); + ]; - include __DIR__ . '/views/view-settings-licenses.php'; + include __DIR__.'/views/view-settings-licenses.php'; } /** @@ -127,29 +123,29 @@ class Settings extends PLL_Settings_Module { check_ajax_referer('pll_options', '_pll_nonce'); - if (! current_user_can('manage_options')) { + if (!current_user_can('manage_options')) { wp_die(-1); } - if (! isset($_POST['module']) || $this->module !== $_POST['module'] || empty($_POST['licenses'])) { + if (!isset($_POST['module']) || $this->module !== $_POST['module'] || empty($_POST['licenses'])) { return; } $response = new WP_Ajax_Response(); - $what = 'success'; + $what = 'success'; foreach ($this->get_licenses() as $item) { - if (! isset($_POST['licenses'][ $item->id ])) { + if (!isset($_POST['licenses'][$item->id])) { continue; } - $updated_item = $item->activate_license(sanitize_key($_POST['licenses'][ $item->id ])); + $updated_item = $item->activate_license(sanitize_key($_POST['licenses'][$item->id])); $response->Add( - array( + [ 'what' => 'pllu-license-update', 'data' => $item->id, - 'supplemental' => array( 'html' => $updated_item->get_form_field() ), - ) + 'supplemental' => ['html' => $updated_item->get_form_field()], + ] ); if (empty($updated_item->license_data->success)) { @@ -163,10 +159,10 @@ class Settings extends PLL_Settings_Module ob_start(); settings_errors('polylang'); $response->Add( - array( + [ 'what' => $what, 'data' => (string) ob_get_clean(), - ) + ] ); $response->send(); } @@ -185,20 +181,20 @@ class Settings extends PLL_Settings_Module { check_ajax_referer(self::GET_LICENSES_DATA_ACTION, '_pll_nonce'); - if (! current_user_can('manage_options')) { + if (!current_user_can('manage_options')) { wp_die(-1); } - $rows = array(); + $rows = []; foreach ($this->get_licenses() as $license) { $license->check_license(); // Get the license information from the server to ensure it's up to date. $rows[] = $license->get_form_field(); } wp_send_json_success( - array( + [ 'row' => $rows, - ) + ] ); } } diff --git a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Translations.php b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Translations.php index 4862761a0e84a449bd6dda01c48931b7875d7b07..c5e7399e0504b46413a1a0eb6c2feb2e7bbab3f5 100644 --- a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Translations.php +++ b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Translations.php @@ -1,9 +1,5 @@ slug = $slug; - add_action('init', array( self::class, 'register_clean_translations_cache' ), 9999); - add_filter('translations_api', array( $this, 'translations_api' ), 10, 3); - add_filter('site_transient_update_plugins', array( $this, 'site_transient_update_plugins' )); + add_action('init', [self::class, 'register_clean_translations_cache'], 9999); + add_filter('translations_api', [$this, 'translations_api'], 10, 3); + add_filter('site_transient_update_plugins', [$this, 'site_transient_update_plugins']); } /** @@ -80,6 +76,7 @@ class Translations * @param bool|array $result The result object. Default false. * @param string $requested_type The type of translations being requested. * @param object $args Translation API arguments. + * * @return bool|array */ public function translations_api($result, $requested_type, $args) @@ -97,25 +94,25 @@ class Translations * Hooked to `site_transient_update_plugins`. * * @see wp_get_translation_updates(). - * * @since 1.0 * * @param stdClass|false $value The transient value. + * * @return stdClass|false */ public function site_transient_update_plugins($value) { - if (! $value instanceof stdClass) { + if (!$value instanceof stdClass) { $value = new stdClass(); } - if (! isset($value->translations)) { - $value->translations = array(); + if (!isset($value->translations)) { + $value->translations = []; } $translations = self::get_translations($this->slug); - if (! isset($translations['translations'])) { + if (!isset($translations['translations'])) { return $value; } @@ -123,8 +120,8 @@ class Translations foreach ((array) $translations['translations'] as $translation) { if (in_array($translation['language'], self::get_available_languages(), true)) { - if (isset($installed_translations[ $this->slug ][ $translation['language'] ]) && $translation['updated']) { - $local = new DateTime($installed_translations[ $this->slug ][ $translation['language'] ]['PO-Revision-Date']); + if (isset($installed_translations[$this->slug][$translation['language']]) && $translation['updated']) { + $local = new DateTime($installed_translations[$this->slug][$translation['language']]['PO-Revision-Date']); $remote = new DateTime($translation['updated']); if ($local >= $remote) { @@ -152,8 +149,8 @@ class Translations */ public static function register_clean_translations_cache(): void { - add_action('set_site_transient_update_plugins', array( self::class, 'clean_translations_cache' )); - add_action('delete_site_transient_update_plugins', array( self::class, 'clean_translations_cache' )); + add_action('set_site_transient_update_plugins', [self::class, 'clean_translations_cache']); + add_action('delete_site_transient_update_plugins', [self::class, 'clean_translations_cache']); } /** @@ -167,7 +164,7 @@ class Translations { $translations = get_site_transient(self::TRANSIENT_KEY); - if (! is_object($translations)) { + if (!is_object($translations)) { return; } @@ -175,10 +172,10 @@ class Translations * Don't delete the cache if the transient gets changed multiple times * during a single request. Set cache lifetime to maximum 15 seconds. */ - $cache_lifespan = 15; + $cache_lifespan = 15; $time_not_changed = isset($translations->_last_checked) && (time() - $translations->_last_checked) > $cache_lifespan; - if (! $time_not_changed) { + if (!$time_not_changed) { return; } @@ -191,13 +188,14 @@ class Translations * @since 1.0 * * @param string $slug Project directory slug. + * * @return array Translation data. */ private static function get_translations(string $slug): array { $translations = get_site_transient(self::TRANSIENT_KEY); - if (! $translations instanceof stdClass) { + if (!$translations instanceof stdClass) { $translations = new stdClass(); } @@ -205,7 +203,7 @@ class Translations return $translations->{$slug}; } - $translations = json_decode(wp_remote_retrieve_body(wp_remote_get(self::API_URL, array( 'timeout' => 3 ))), true); + $translations = json_decode(wp_remote_retrieve_body(wp_remote_get(self::API_URL, ['timeout' => 3])), true); if (is_array($translations)) { $translations = (object) $translations; @@ -221,7 +219,7 @@ class Translations return $translations->{$slug}; } - return array(); + return []; } /** @@ -238,6 +236,7 @@ class Translations if (null === self::$installed_translations) { self::$installed_translations = wp_get_installed_translations('plugins'); } + return self::$installed_translations; } @@ -255,6 +254,7 @@ class Translations if (null === self::$available_languages) { self::$available_languages = (array) get_available_languages(); } + return self::$available_languages; } } diff --git a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Updater.php b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Updater.php index 4f2b5b760ec30c1f9c457525e07a3abfabd0268f..aa2fc303de65e972e831b61ed449627ea37494ba 100644 --- a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Updater.php +++ b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Updater.php @@ -1,9 +1,5 @@ license = new License($file, $name, $version); + $this->license = new License($file, $name, $version); $this->translations = new Translations($text_domain); - add_action('pll_init', array( $this, 'load_wizard' )); + add_action('pll_init', [$this, 'load_wizard']); } /** @@ -58,11 +54,12 @@ class Updater * @since 1.0 * * @param PLL_Base $polylang Polylang object. + * * @return void */ public function load_wizard($polylang): void { - if (! empty($polylang->wizard)) { + if (!empty($polylang->wizard)) { $this->wizard_licenses_step = new Wizard_Licenses_Step($polylang->wizard); } } diff --git a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Wizard_Licenses_Step.php b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Wizard_Licenses_Step.php index d8aaf2a0131be4de74de2701ec6bb870f736653c..f909bdfee37fbe6e58e576531e60857c28f0d328 100644 --- a/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Wizard_Licenses_Step.php +++ b/__plugins/polylang-wc/dependencies/wpsyntex/updater/src/Wizard_Licenses_Step.php @@ -1,9 +1,5 @@ wizard = $wizard; - add_filter('pll_wizard_steps', array( $this, 'add' ), 101); // After `PLL_Wizard::add_step_licenses()`, so this can override it. + add_filter('pll_wizard_steps', [$this, 'add'], 101); // After `PLL_Wizard::add_step_licenses()`, so this can override it. } /** @@ -67,9 +63,11 @@ class Wizard_Licenses_Step * @since 1.0 * * @param array $steps List of steps. + * * @return array List of steps updated. * * @phpstan-param Steps $steps + * * @phpstan-return Steps */ public function add($steps) @@ -82,21 +80,21 @@ class Wizard_Licenses_Step } if ($first_step instanceof PLL_Wizard) { // Remove the old system, so we don't send 2 AJAX requests for the same action (deactivate license). - remove_action('wp_ajax_pll_deactivate_license', array( $first_step, 'deactivate_license' )); + remove_action('wp_ajax_pll_deactivate_license', [$first_step, 'deactivate_license']); wp_dequeue_script('pll_settings'); } } $this->hooks(); - if (! empty($this->get_licenses())) { - $steps['licenses'] = array( + if (!empty($this->get_licenses())) { + $steps['licenses'] = [ 'name' => esc_html__('Licenses', 'polylang-wc'), - 'view' => array( $this, 'display' ), - 'handler' => array( $this, 'save' ), - 'scripts' => array( 'pll_license' ), - 'styles' => array( 'pll_license' ), - ); + 'view' => [$this, 'display'], + 'handler' => [$this, 'save'], + 'scripts' => ['pll_license'], + 'styles' => ['pll_license'], + ]; } return $steps; @@ -111,15 +109,15 @@ class Wizard_Licenses_Step */ public function display(): void { - $atts = array( - 'license_rows' => array(), + $atts = [ + 'license_rows' => [], 'is_error' => isset($_GET['activate_error']) && 'i18n_license_key_error' === sanitize_key($_GET['activate_error']), // phpcs:ignore WordPress.Security.NonceVerification.Recommended - ); + ]; foreach ($this->get_licenses() as $license) { $atts['license_rows'][] = $license->get_form_field(); } - include __DIR__ . '/views/view-wizard-step-licenses.php'; + include __DIR__.'/views/view-wizard-step-licenses.php'; } /** @@ -139,11 +137,11 @@ class Wizard_Licenses_Step $redirect = $this->wizard->get_next_step_link(); foreach ($this->get_licenses() as $license) { - if (! isset($_POST['licenses'][ $license->id ])) { + if (!isset($_POST['licenses'][$license->id])) { continue; } - $updated_license = $license->activate_license(sanitize_key($_POST['licenses'][ $license->id ])); + $updated_license = $license->activate_license(sanitize_key($_POST['licenses'][$license->id])); if (empty($updated_license->license_data) || false !== $updated_license->license_data->success) { // Success. @@ -152,10 +150,10 @@ class Wizard_Licenses_Step // Stay on this step with an error. $redirect = add_query_arg( - array( + [ 'step' => $this->get_current_step(), 'activate_error' => 'i18n_license_key_error', - ) + ] ); } @@ -174,8 +172,8 @@ class Wizard_Licenses_Step private function get_current_step(): string { /** This filter is documented in `PLL_Wizard::setup_wizard_page()`. */ - $steps = apply_filters('pll_wizard_steps', array()); - $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : false; // phpcs:ignore WordPress.Security.NonceVerification + $steps = apply_filters('pll_wizard_steps', []); + $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : false; // phpcs:ignore WordPress.Security.NonceVerification // @phpstan-var non-empty-array $steps // @phpstan-var string|false $step diff --git a/__plugins/polylang-wc/dependencies/wpsyntex/updater/uninstall.php b/__plugins/polylang-wc/dependencies/wpsyntex/updater/uninstall.php index e3743f0a8c7cea2ab8eb44da7ad6e63a9743cbcd..7f8acd5f5104a40977e784300667df29906105e8 100644 --- a/__plugins/polylang-wc/dependencies/wpsyntex/updater/uninstall.php +++ b/__plugins/polylang-wc/dependencies/wpsyntex/updater/uninstall.php @@ -1,11 +1,7 @@ . */ -use Automattic\WooCommerce\Utilities\OrderUtil; -use WP_Syntex\Polylang_WC\Updater\Updater; use Automattic\WooCommerce\Utilities\FeaturesUtil; +use Automattic\WooCommerce\Utilities\OrderUtil; use WP_Syntex\Polylang_WC\REST; +use WP_Syntex\Polylang_WC\Updater\Updater; defined('ABSPATH') || exit; @@ -55,8 +54,8 @@ define('PLLWC_MIN_PLL_VERSION', '3.7'); define('PLLWC_FILE', __FILE__); // This file. define('PLLWC_BASENAME', plugin_basename(PLLWC_FILE)); // Plugin name as known by WP. -require_once __DIR__ . '/vendor/autoload.php'; -require_once __DIR__ . '/src/functions.php'; +require_once __DIR__.'/vendor/autoload.php'; +require_once __DIR__.'/src/functions.php'; /** * Plugin controller. @@ -235,7 +234,7 @@ class Polylang_Woocommerce public function __construct() { // Registers an action when the plugin is activated. - add_action('activated_plugin', array( $this, 'activated_plugin' ), 10, 2); + add_action('activated_plugin', [$this, 'activated_plugin'], 10, 2); $install = new PLLWC_Install(plugin_basename(__FILE__)); @@ -247,25 +246,25 @@ class Polylang_Woocommerce // WC 3.3: Maybe update default product categories after WooCommerce did it. $db_version = get_option('woocommerce_db_version'); if (is_string($db_version) && version_compare($db_version, '3.3.0', '<')) { - add_action('add_option_woocommerce_db_version', array( 'PLLWC_Admin_WC_Install', 'update_330_wc_db_version' ), 10, 2); + add_action('add_option_woocommerce_db_version', ['PLLWC_Admin_WC_Install', 'update_330_wc_db_version'], 10, 2); } /* * Fix home url when using plain permalinks and the shop is on front. * Added here because the filter is fired before the action 'pll_init'. */ - add_filter('pll_additional_language_data', array( 'PLLWC_Links', 'set_home_url' ), 20, 2); // After Polylang. + add_filter('pll_additional_language_data', ['PLLWC_Links', 'set_home_url'], 20, 2); // After Polylang. - add_filter('pll_is_ajax_on_front', array( $this, 'fix_ajax_product_import' )); + add_filter('pll_is_ajax_on_front', [$this, 'fix_ajax_product_import']); // The "ajax" request for feature product is indeed a direct link and thus does not include the pll_ajax_backend query var. if (isset($_GET['action']) && 'woocommerce_feature_product' === $_GET['action']) { // phpcs:ignore WordPress.Security.NonceVerification define('PLL_ADMIN', true); } - add_action('pll_pre_init', array( $this, 'pre_init' )); // `plugins_loaded` prio 1. + add_action('pll_pre_init', [$this, 'pre_init']); // `plugins_loaded` prio 1. PLLWC_Plugins_Compat::instance(); - add_action('before_woocommerce_init', array( $this, 'declare_features_compatibility' ), 0); // `init` prio 0. + add_action('before_woocommerce_init', [$this, 'declare_features_compatibility'], 0); // `init` prio 0. } /** @@ -280,6 +279,7 @@ class Polylang_Woocommerce if (empty(self::$instance)) { self::$instance = new self(); } + return self::$instance; } @@ -289,6 +289,7 @@ class Polylang_Woocommerce * @since 1.5.3 * * @param bool $is_ajax_on_front Whether the current request is an ajax request on front. + * * @return bool */ public function fix_ajax_product_import($is_ajax_on_front) @@ -302,18 +303,20 @@ class Polylang_Woocommerce * @since 2.2 * * @param PLL_Base $polylang Polylang object. + * * @return void */ public function pre_init($polylang): void { // Silently disable the plugin if WooCommerce are not active. - if (! defined('WOOCOMMERCE_VERSION')) { + if (!defined('WOOCOMMERCE_VERSION')) { return; } // If the version of Polylang is too old. if (version_compare(POLYLANG_VERSION, PLLWC_MIN_PLL_VERSION, '<')) { - add_action('all_admin_notices', array( $this, 'admin_notices' )); + add_action('all_admin_notices', [$this, 'admin_notices']); + return; } @@ -321,7 +324,7 @@ class Polylang_Woocommerce // $this->updater = new Updater( __FILE__, 'Polylang for WooCommerce', PLLWC_VERSION, 'polylang-wc' ); // } - add_action('pll_init', array( $this, 'init' )); // `plugins_loaded` prio 1. + add_action('pll_init', [$this, 'init']); // `plugins_loaded` prio 1. } /** @@ -331,6 +334,7 @@ class Polylang_Woocommerce * @since 2.2 Pass Polylang's instance as 1st parameter. * * @param PLL_Base $polylang Polylang object. + * * @return void */ public function init($polylang): void @@ -343,29 +347,29 @@ class Polylang_Woocommerce $this->admin_status_reports = new PLLWC_Admin_Status_Reports(); } - add_action('admin_init', array( $this, 'maybe_install' )); + add_action('admin_init', [$this, 'maybe_install']); // Bail early if no language has been defined yet. - if (! pll_languages_list()) { + if (!pll_languages_list()) { return; } - add_action('admin_init', array( $this, 'maybe_upgrade' )); + add_action('admin_init', [$this, 'maybe_upgrade']); - add_action('woocommerce_delete_product_transients', array( $this, 'delete_product_transients' )); + add_action('woocommerce_delete_product_transients', [$this, 'delete_product_transients']); PLLWC_Variation_Data_Store_CPT::init(); - $this->post_types = new PLLWC_Post_Types(); - $this->links = defined('POLYLANG_PRO') && POLYLANG_PRO && get_option('permalink_structure') ? new PLLWC_Links_Pro() : new PLLWC_Links(); - $this->stock = new PLLWC_Stock(); - $this->emails = new PLLWC_Emails(); - $this->strings = new PLLWC_Strings(); - $this->data = new PLLWC_Xdata(); + $this->post_types = new PLLWC_Post_Types(); + $this->links = defined('POLYLANG_PRO') && POLYLANG_PRO && get_option('permalink_structure') ? new PLLWC_Links_Pro() : new PLLWC_Links(); + $this->stock = new PLLWC_Stock(); + $this->emails = new PLLWC_Emails(); + $this->strings = new PLLWC_Strings(); + $this->data = new PLLWC_Xdata(); $this->product_export = new PLLWC_Product_Export(); $this->product_import = new PLLWC_Product_Import(); - $this->products = new PLLWC_Products(); - $this->blocks = new PLLWC_Store_Blocks(); + $this->products = new PLLWC_Products(); + $this->blocks = new PLLWC_Store_Blocks(); if (OrderUtil::custom_orders_table_usage_is_enabled()) { $this->hpos_orders_query = (new PLLWC_HPOS_Orders_Query())->init(); @@ -375,7 +379,7 @@ class Polylang_Woocommerce if (defined('POLYLANG_PRO') && POLYLANG_PRO) { // Backward compatibility with Polylang < 3.8. - if (! class_exists('WP_Syntex\Polylang_Pro\REST\Translated\Post')) { + if (!class_exists('WP_Syntex\Polylang_Pro\REST\Translated\Post')) { $this->rest_api = new PLLWC_REST_API(); } else { $this->rest_api = new REST\Module(); @@ -388,13 +392,13 @@ class Polylang_Woocommerce * but also on REST requests for WooCommerce Blocks 2.5+. */ if ($polylang instanceof PLL_Frontend || wp_doing_ajax() || $polylang instanceof PLL_REST_Request) { - $this->cart = new PLLWC_Frontend_Cart(); + $this->cart = new PLLWC_Frontend_Cart(); $this->coupons = new PLLWC_Coupons(); } // Frontend only. if ($polylang instanceof PLL_Frontend) { - $this->frontend = new PLLWC_Frontend(); + $this->frontend = new PLLWC_Frontend(); $this->my_account = new PLLWC_Frontend_Account(); // WC pages on front. @@ -406,14 +410,14 @@ class Polylang_Woocommerce // Admin only ( but not useful on Polylang settings pages ). if ($polylang instanceof PLL_Admin) { - $this->admin_taxonomies = new PLLWC_Admin_Taxonomies(); - $this->admin_products = new PLLWC_Admin_Products(); + $this->admin_taxonomies = new PLLWC_Admin_Taxonomies(); + $this->admin_products = new PLLWC_Admin_Products(); $this->admin_product_duplicate = new PLLWC_Admin_Product_Duplicate(); - $this->admin_reports = new PLLWC_Admin_Reports(); - $this->admin_menus = new PLLWC_Admin_Menus(); - $this->coupons = new PLLWC_Admin_Coupons(); - $this->site_health = new PLLWC_Admin_Site_Health(); - $this->admin_orders = OrderUtil::custom_orders_table_usage_is_enabled() ? + $this->admin_reports = new PLLWC_Admin_Reports(); + $this->admin_menus = new PLLWC_Admin_Menus(); + $this->coupons = new PLLWC_Admin_Coupons(); + $this->site_health = new PLLWC_Admin_Site_Health(); + $this->admin_orders = OrderUtil::custom_orders_table_usage_is_enabled() ? new PLLWC_Admin_Orders_HPOS() : new PLLWC_Admin_Orders_Legacy(); if (defined('POLYLANG_PRO') && POLYLANG_PRO) { @@ -421,8 +425,8 @@ class Polylang_Woocommerce $this->translation_import = (new PLLWC_Translation_Import($this->products))->init(); } - add_action('woocommerce_system_status_report', array( $this->admin_status_reports, 'status_report' )); - add_action('admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' )); + add_action('woocommerce_system_status_report', [$this->admin_status_reports, 'status_report']); + add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); } // Translation import is also needed in Polylang settings pages for XLIFF import. @@ -438,7 +442,7 @@ class Polylang_Woocommerce * * @param object &$this The Polylang for WooCommerce object. */ - do_action_ref_array('pllwc_init', array( &$this )); + do_action_ref_array('pllwc_init', [&$this]); } /** @@ -492,7 +496,7 @@ class Polylang_Woocommerce if (version_compare($options['version'], '0.4.6', '<')) { // Same as Polylang 2.0.8, for WP 4.7. global $wpdb; - $wpdb->update($wpdb->usermeta, array( 'meta_key' => 'locale' ), array( 'meta_key' => 'user_lang' )); + $wpdb->update($wpdb->usermeta, ['meta_key' => 'locale'], ['meta_key' => 'user_lang']); } // Version 0.9.3, if already updated to WC 3.3. @@ -523,7 +527,7 @@ class Polylang_Woocommerce $options = get_option('polylang-wc'); if (empty($options)) { - $options = array( 'version' => PLLWC_VERSION ); + $options = ['version' => PLLWC_VERSION]; update_option('polylang-wc', $options); } } @@ -534,6 +538,7 @@ class Polylang_Woocommerce * @since 0.4.5 * * @param int $product_id Product ID. + * * @return void */ public function delete_product_transients($product_id) @@ -543,7 +548,7 @@ class Polylang_Woocommerce $data_store = PLLWC_Data_Store::load('product_language'); foreach ($data_store->get_translations($product_id) as $tr_id) { - if (! in_array($tr_id, $ids)) { + if (!in_array($tr_id, $ids)) { wc_delete_product_transients($tr_id); } } @@ -559,7 +564,7 @@ class Polylang_Woocommerce public function admin_enqueue_scripts() { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_style('pll_wc_admin', plugins_url('/css/build/admin' . $suffix . '.css', PLLWC_FILE), array(), PLLWC_VERSION); + wp_enqueue_style('pll_wc_admin', plugins_url('/css/build/admin'.$suffix.'.css', PLLWC_FILE), [], PLLWC_VERSION); } /** @@ -569,13 +574,14 @@ class Polylang_Woocommerce * * @param string $plugin_name Plugin basename. * @param bool $network_wide If activated for all sites in the network. + * * @return void */ public static function activated_plugin($plugin_name, $network_wide) { $options = get_option('polylang-wc'); // If the polylang-wc option is set, the wizard has already been launched once. - if (wp_doing_ajax() || $network_wide || ! empty($options)) { + if (wp_doing_ajax() || $network_wide || !empty($options)) { return; } diff --git a/__plugins/polylang-wc/src/Cart/Item.php b/__plugins/polylang-wc/src/Cart/Item.php index 68e56434c6b8a5215b0fca616672c43c9b9135d4..502632ebfeb0c0a5803165f918d1f4a65cb6aa40 100644 --- a/__plugins/polylang-wc/src/Cart/Item.php +++ b/__plugins/polylang-wc/src/Cart/Item.php @@ -1,15 +1,11 @@ item = $item; - $this->data_store = PLLWC_Data_Store::load('product_language'); - $this->is_variation = ! empty($item['variation_id']); + $this->item = $item; + $this->data_store = PLLWC_Data_Store::load('product_language'); + $this->is_variation = !empty($item['variation_id']); } /** @@ -70,14 +68,15 @@ class Item * @since 2.2 * * @param PLL_Language $lang The target language. + * * @return array The translated cart item array. */ public function translate(PLL_Language $lang): array { $untranslated_items = $this->item; if ( - ($this->is_variation && ! $this->translate_variation($lang)) - || ! $this->translate_parent($lang) + ($this->is_variation && !$this->translate_variation($lang)) + || !$this->translate_parent($lang) ) { return $untranslated_items; } @@ -89,6 +88,7 @@ class Item * * @param array $item Cart item. * @param string $lang Language code. + * * @phpstan-param CartItem $item */ $this->item = apply_filters('pllwc_translate_cart_item', $this->item, $lang->slug); @@ -103,9 +103,10 @@ class Item * * @param array $cart_item_data Cart item data. * @param array $item Cart item. + * * @phpstan-param CartItem $item */ - $cart_item_data = (array) apply_filters('pllwc_add_cart_item_data', array(), $this->item); + $cart_item_data = (array) apply_filters('pllwc_add_cart_item_data', [], $this->item); $this->item['key'] = WC()->cart->generate_cart_id($this->item['product_id'], $this->item['variation_id'], $this->item['variation'], $cart_item_data); return $this->item; @@ -117,6 +118,7 @@ class Item * @since 2.2 * * @param PLL_Language $lang The target language. + * * @return bool Whether the variation was translated. */ private function translate_variation(PLL_Language $lang): bool @@ -124,7 +126,7 @@ class Item /** @var PLL_Language|false $orig_lang */ $orig_lang = $this->data_store->get_language($this->item['variation_id'], \OBJECT); - if (! $orig_lang || $lang->slug === $orig_lang->slug) { + if (!$orig_lang || $lang->slug === $orig_lang->slug) { return false; } @@ -134,13 +136,13 @@ class Item } $tr_variation = wc_get_product($tr_id); - if (! $tr_variation) { + if (!$tr_variation) { return false; } $this->item['variation_id'] = $tr_variation->get_id(); - $this->item['data'] = $tr_variation; - $this->item['variation'] = $this->translate_attributes($this->item['variation'], $lang, $orig_lang); + $this->item['data'] = $tr_variation; + $this->item['variation'] = $this->translate_attributes($this->item['variation'], $lang, $orig_lang); return true; } @@ -151,6 +153,7 @@ class Item * @since 2.2 * * @param PLL_Language $lang The target language. + * * @return bool Whether the parent was translated. */ private function translate_parent(PLL_Language $lang): bool @@ -161,12 +164,12 @@ class Item } $tr_product = wc_get_product($tr_id); - if (! $tr_product) { + if (!$tr_product) { return false; } $this->item['product_id'] = $tr_product->get_id(); - $this->item['data'] = $tr_product; + $this->item['data'] = $tr_product; return true; } @@ -178,7 +181,8 @@ class Item * * @param array $attributes The variation attributes array. * @param PLL_Language $lang The target language. - * @param PLL_Language $orig_lang The original language. + * @param PLL_Language $orig_lang The original language. + * * @return array The translated attributes array. */ public function translate_attributes(array $attributes, PLL_Language $lang, PLL_Language $orig_lang): array @@ -190,33 +194,33 @@ class Item $taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($name))); - if (! taxonomy_exists($taxonomy)) { + if (!taxonomy_exists($taxonomy)) { continue; } // Don't use get_term_by( 'slug' ) which is filtered in the current language by Polylang Pro. - $terms = get_terms(array( 'taxonomy' => $taxonomy, 'slug' => $value, 'lang' => $orig_lang->slug )); + $terms = get_terms(['taxonomy' => $taxonomy, 'slug' => $value, 'lang' => $orig_lang->slug]); - if (empty($terms) || ! is_array($terms)) { + if (empty($terms) || !is_array($terms)) { continue; } $term = reset($terms); - if (! $term instanceof WP_Term) { + if (!$term instanceof WP_Term) { continue; } $term_id = pll_get_term($term->term_id, $lang); - if (! $term_id) { + if (!$term_id) { continue; } $term = get_term($term_id, $taxonomy); - if (! $term instanceof WP_Term) { + if (!$term instanceof WP_Term) { continue; } - $attributes[ $name ] = $term->slug; + $attributes[$name] = $term->slug; } return $attributes; diff --git a/__plugins/polylang-wc/src/admin/admin-coupons.php b/__plugins/polylang-wc/src/admin/admin-coupons.php index 3f7d1db080c2f38f9cd2f88128987250c9f8b3a8..690b72f27cd05f6b5fb42244222552dd7f71e64c 100644 --- a/__plugins/polylang-wc/src/admin/admin-coupons.php +++ b/__plugins/polylang-wc/src/admin/admin-coupons.php @@ -1,9 +1,5 @@ data_store->get_post_types('display'); foreach ($translated_order_types as $translated_order_type) { - add_filter('woocommerce_' . $translated_order_type . '_list_table_columns', array( PLLWC()->admin_orders, 'add_order_column' ), 100); - add_action('woocommerce_' . $translated_order_type . '_list_table_custom_column', array( PLLWC()->admin_orders, 'order_column' ), 10, 2); + add_filter('woocommerce_'.$translated_order_type.'_list_table_columns', [PLLWC()->admin_orders, 'add_order_column'], 100); + add_action('woocommerce_'.$translated_order_type.'_list_table_custom_column', [PLLWC()->admin_orders, 'order_column'], 10, 2); } } @@ -50,6 +46,7 @@ class PLLWC_Admin_Orders_HPOS extends PLLWC_Admin_Orders * @since 1.9 * * @param WC_Order $order Order object. + * * @return void */ public function order_language($order) @@ -75,6 +72,7 @@ class PLLWC_Admin_Orders_HPOS extends PLLWC_Admin_Orders * @since 1.9 * * @param array $params List of parameters to add to the admin ajax request. + * * @return array Modified list of parameters to add to the admin ajax request. */ public function set_pll_order_id($params) @@ -82,6 +80,7 @@ class PLLWC_Admin_Orders_HPOS extends PLLWC_Admin_Orders if ($this->is_allowed_screen() && isset($_GET['id'])) { // phpcs:ignore WordPress.Security.NonceVerification $params['pll_order_id'] = (int) $_GET['id']; // phpcs:ignore WordPress.Security.NonceVerification } + return $params; } @@ -91,14 +90,15 @@ class PLLWC_Admin_Orders_HPOS extends PLLWC_Admin_Orders * @since 1.9 * * @param PLL_Language|bool $current_language The current language already set. + * * @return PLL_Language|bool */ public function set_current_language($current_language) { - if (! empty($_GET['page']) && ! empty($_GET['id']) && is_numeric($_GET['id']) && 'admin.php' === $GLOBALS['pagenow'] && 'wc-orders' === $_GET['page']) { // phpcs:ignore WordPress.Security.NonceVerification + if (!empty($_GET['page']) && !empty($_GET['id']) && is_numeric($_GET['id']) && 'admin.php' === $GLOBALS['pagenow'] && 'wc-orders' === $_GET['page']) { // phpcs:ignore WordPress.Security.NonceVerification // Case for the order checkout link. $lang = PLL()->model->post->get_language((int) $_GET['id']); // phpcs:ignore WordPress.Security.NonceVerification - } elseif (wp_doing_ajax() && ! empty($_GET['pll_order_id']) && is_numeric($_GET['pll_order_id'])) { // phpcs:ignore WordPress.Security.NonceVerification + } elseif (wp_doing_ajax() && !empty($_GET['pll_order_id']) && is_numeric($_GET['pll_order_id'])) { // phpcs:ignore WordPress.Security.NonceVerification // Case for filtering products search by the order language. $lang = PLL()->model->post->get_language((int) $_GET['pll_order_id']); // phpcs:ignore WordPress.Security.NonceVerification } @@ -112,24 +112,25 @@ class PLLWC_Admin_Orders_HPOS extends PLLWC_Admin_Orders * @since 1.9 * * @param WC_Order $order Order object being saved. + * * @return void */ public function save_order_language($order) { - if (! isset($_GET['id'], $_GET['page'], $_GET['action'], $_POST['post_lang_choice'], $_POST['_pll_nonce'])) { + if (!isset($_GET['id'], $_GET['page'], $_GET['action'], $_POST['post_lang_choice'], $_POST['_pll_nonce'])) { return; } - if (! $this->is_allowed_screen() || 'edit' !== $_GET['action']) { + if (!$this->is_allowed_screen() || 'edit' !== $_GET['action']) { return; } check_admin_referer('pll_language', '_pll_nonce'); - $new_lang = PLL()->model->get_language(sanitize_key($_POST['post_lang_choice'])); + $new_lang = PLL()->model->get_language(sanitize_key($_POST['post_lang_choice'])); $order_lang = $this->data_store->get_language($order->get_id()); - if (empty($new_lang) || (! empty($order_lang) && $new_lang->slug === $order_lang)) { + if (empty($new_lang) || (!empty($order_lang) && $new_lang->slug === $order_lang)) { return; } @@ -152,13 +153,13 @@ class PLLWC_Admin_Orders_HPOS extends PLLWC_Admin_Orders */ public function enqueue_order_script() { - if (! $this->is_allowed_screen()) { + if (!$this->is_allowed_screen()) { return; } wp_dequeue_script('pll_classic-editor'); $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_script('pllwc_order', plugins_url('/js/build/order' . $suffix . '.js', PLLWC_FILE), array(), PLLWC_VERSION, true); + wp_enqueue_script('pllwc_order', plugins_url('/js/build/order'.$suffix.'.js', PLLWC_FILE), [], PLLWC_VERSION, true); } } diff --git a/__plugins/polylang-wc/src/admin/admin-orders-legacy.php b/__plugins/polylang-wc/src/admin/admin-orders-legacy.php index 5b8acb8eb8e2b8e4f9b83cb314875c9d4edb2690..b6928a8acd48c81f3eb0f0b1ecf825d915299ac1 100644 --- a/__plugins/polylang-wc/src/admin/admin-orders-legacy.php +++ b/__plugins/polylang-wc/src/admin/admin-orders-legacy.php @@ -1,11 +1,7 @@ filters_columns; - remove_filter('manage_edit-' . $translated_order_type . '_columns', array( $class, 'add_post_column' ), 100); - remove_action('manage_' . $translated_order_type . '_posts_custom_column', array( $class, 'post_column' )); + remove_filter('manage_edit-'.$translated_order_type.'_columns', [$class, 'add_post_column'], 100); + remove_action('manage_'.$translated_order_type.'_posts_custom_column', [$class, 'post_column']); - add_filter('manage_edit-' . $translated_order_type . '_columns', array( $this, 'add_order_column' ), 100); - add_action('manage_' . $translated_order_type . '_posts_custom_column', array( $this, 'order_column' ), 10, 2); + add_filter('manage_edit-'.$translated_order_type.'_columns', [$this, 'add_order_column'], 100); + add_action('manage_'.$translated_order_type.'_posts_custom_column', [$this, 'order_column'], 10, 2); } } @@ -40,6 +36,7 @@ class PLLWC_Admin_Orders_Legacy extends PLLWC_Admin_Orders * @since 0.1 * * @param WP_Post $order Order object. + * * @return void */ public function order_language($order) diff --git a/__plugins/polylang-wc/src/admin/admin-orders.php b/__plugins/polylang-wc/src/admin/admin-orders.php index 2c9e71236acd0a9d93b38e5b0da186b41e821a46..1738988683b668ad1ca0cff1e5709b665684770f 100644 --- a/__plugins/polylang-wc/src/admin/admin-orders.php +++ b/__plugins/polylang-wc/src/admin/admin-orders.php @@ -1,9 +1,5 @@ data_store = PLLWC_Data_Store::load('order_language'); - add_action('wp_loaded', array( $this, 'custom_columns' ), 20); - add_action('add_meta_boxes', array( $this, 'add_meta_boxes' ), 50); // After WC_Admin_Meta_Boxes:add_meta_boxes(). - add_filter('woocommerce_admin_order_actions', array( $this, 'admin_order_actions' )); - add_filter('woocommerce_admin_order_preview_actions', array( $this, 'admin_order_actions' )); + add_action('wp_loaded', [$this, 'custom_columns'], 20); + add_action('add_meta_boxes', [$this, 'add_meta_boxes'], 50); // After WC_Admin_Meta_Boxes:add_meta_boxes(). + add_filter('woocommerce_admin_order_actions', [$this, 'admin_order_actions']); + add_filter('woocommerce_admin_order_preview_actions', [$this, 'admin_order_actions']); } /** @@ -49,13 +45,14 @@ abstract class PLLWC_Admin_Orders * @since 0.1 * * @param string[] $columns List of table columns. + * * @return string[] modified list of columns. */ public function add_order_column($columns) { // Don't add the column when the admin language filter is active. if (empty(PLL()->curlang)) { - $columns['language'] = '' . __('Language', 'polylang-wc') . ''; + $columns['language'] = ''.__('Language', 'polylang-wc').''; } return $columns; @@ -69,6 +66,7 @@ abstract class PLLWC_Admin_Orders * * @param string $column Column name. * @param WC_Order|int $order Order object when using HPOS, or order ID otherwise. + * * @return void */ public function order_column($column, $order) @@ -81,7 +79,7 @@ abstract class PLLWC_Admin_Orders $lang = PLL()->model->get_language($lang); if ('language' === $column && $lang) { - echo $lang->flag ? $lang->flag . '' . esc_html($lang->name) . '' : esc_html($lang->slug); // PHPCS:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo $lang->flag ? $lang->flag.''.esc_html($lang->name).'' : esc_html($lang->slug); // PHPCS:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } @@ -93,37 +91,38 @@ abstract class PLLWC_Admin_Orders * @since 0.1 * * @param string $screen_id Screen id of the order edit page. + * * @return void */ public function add_meta_boxes($screen_id) { global $wp_meta_boxes; - if (! $this->is_allowed_screen($screen_id)) { + if (!$this->is_allowed_screen($screen_id)) { return; } PLLWC_Filter_WC_Pages::init(); remove_meta_box('ml_box', $screen_id, 'side'); // Remove Polylang metabox if necessary. - add_meta_box('pllwc_box', __('Language', 'polylang-wc'), array( $this, 'order_language' ), $screen_id, 'side', 'high'); + add_meta_box('pllwc_box', __('Language', 'polylang-wc'), [$this, 'order_language'], $screen_id, 'side', 'high'); /* * Replaces the default order downloads meta box. * To be able to update download links with the order language. */ if (PLL()->options['force_lang'] > 1) { - $context = 'normal'; + $context = 'normal'; $priority = 'default'; // Keeps the title of the original metabox before removing it. - $meta_box_title = $wp_meta_boxes[ $screen_id ][ $context ][ $priority ]['woocommerce-order-downloads']['title'] ?? ''; + $meta_box_title = $wp_meta_boxes[$screen_id][$context][$priority]['woocommerce-order-downloads']['title'] ?? ''; remove_meta_box('woocommerce-order-downloads', $screen_id, $context); add_meta_box( 'woocommerce-order-downloads', $meta_box_title, - array( $this, 'update_order_download_links' ), + [$this, 'update_order_download_links'], $screen_id, $context, $priority @@ -137,13 +136,14 @@ abstract class PLLWC_Admin_Orders * @since 2.2 * * @param object $order_object Order object. + * * @return void */ public function update_order_download_links($order_object) { $order = wc_get_order($order_object); - if (! $order instanceof WC_Order) { + if (!$order instanceof WC_Order) { return; } @@ -151,6 +151,7 @@ abstract class PLLWC_Admin_Orders if (empty($language)) { WC_Meta_Box_Order_Downloads::output($order); + return; } @@ -160,13 +161,14 @@ abstract class PLLWC_Admin_Orders if (empty($meta_box_content)) { WC_Meta_Box_Order_Downloads::output($order); + return; } $content_tags = new WP_HTML_Tag_Processor($meta_box_content); - while ($content_tags->next_tag(array( 'tag_name' => 'a', 'class_name' => 'button' ))) { - if ('copy-download-link' !== $content_tags->get_attribute('id') || ! is_string($content_tags->get_attribute('href'))) { + while ($content_tags->next_tag(['tag_name' => 'a', 'class_name' => 'button'])) { + if ('copy-download-link' !== $content_tags->get_attribute('id') || !is_string($content_tags->get_attribute('href'))) { continue; } @@ -182,6 +184,7 @@ abstract class PLLWC_Admin_Orders * @since 0.1 * * @param object $order Order object. + * * @return void */ abstract public function order_language($order); @@ -192,6 +195,7 @@ abstract class PLLWC_Admin_Orders * @since 1.9 * * @param int $order_id Order id. + * * @return void */ protected function display_language_metabox($order_id) @@ -202,21 +206,21 @@ abstract class PLLWC_Admin_Orders $dropdown = new PLL_Walker_Dropdown(); // NOTE: the class "tags-input" allows to include the field in the autosave $_POST ( see autosave.js ). - $args = array( + $args = [ 'name' => 'post_lang_choice', 'class' => 'post_lang_choice tags-input', 'selected' => $lang, 'flag' => true, - ); + ]; - $languages = PLL()->model->get_languages_list(); + $languages = PLL()->model->get_languages_list(); $dropdown_html = $dropdown->walk($languages, -1, $args); wp_nonce_field('pll_language', '_pll_nonce'); - $flags_data = array(); + $flags_data = []; foreach ($languages as $language) { - $flags_data[ $language->slug ] = empty($language->flag) ? esc_html($language->slug) : $language->flag; + $flags_data[$language->slug] = empty($language->flag) ? esc_html($language->slug) : $language->flag; } $flags_data = (string) wp_json_encode($flags_data); @@ -236,6 +240,7 @@ abstract class PLLWC_Admin_Orders * @since 1.0.4 * * @param array $actions Admin order actions. + * * @return array */ public function admin_order_actions($actions) @@ -246,9 +251,10 @@ abstract class PLLWC_Admin_Orders foreach ($actions as $key => $arr) { if (false !== strpos($arr['url'], 'admin-ajax.php')) { - $actions[ $key ]['url'] = add_query_arg('pll_ajax_backend', 1, $arr['url']); + $actions[$key]['url'] = add_query_arg('pll_ajax_backend', 1, $arr['url']); } } + return $actions; } @@ -258,16 +264,17 @@ abstract class PLLWC_Admin_Orders * @since 1.9 * * @param string $screen_id Optional screen id, defaults to the current screen. + * * @return bool */ protected function is_allowed_screen($screen_id = '') { // If we have a specific screen_id passed, check it directly. - if (! empty($screen_id)) { + if (!empty($screen_id)) { return in_array($screen_id, $this->get_allowed_screens(), true); } - if (! function_exists('get_current_screen')) { + if (!function_exists('get_current_screen')) { return false; } diff --git a/__plugins/polylang-wc/src/admin/admin-product-duplicate.php b/__plugins/polylang-wc/src/admin/admin-product-duplicate.php index 8884eaea1f7d3fb85612d0465cefed7b51be1426..eca398b2a0bd78d136b9e1d99814452c2785593d 100644 --- a/__plugins/polylang-wc/src/admin/admin-product-duplicate.php +++ b/__plugins/polylang-wc/src/admin/admin-product-duplicate.php @@ -1,9 +1,5 @@ data_store = PLLWC_Data_Store::load('product_language'); add_filter('woocommerce_duplicate_product_exclude_children', '__return_true'); - add_action('admin_action_duplicate_product', array( $this, 'duplicate_product_action' ), 5); // Before WooCommerce. - add_action('woocommerce_product_duplicate', array( $this, 'product_duplicate' ), 10, 2); + add_action('admin_action_duplicate_product', [$this, 'duplicate_product_action'], 5); // Before WooCommerce. + add_action('woocommerce_product_duplicate', [$this, 'product_duplicate'], 10, 2); } /** @@ -43,7 +39,7 @@ class PLLWC_Admin_Product_Duplicate */ public function duplicate_product_action() { - remove_action('set_object_terms', array( PLL()->posts, 'set_object_terms' )); + remove_action('set_object_terms', [PLL()->posts, 'set_object_terms']); } /** @@ -58,6 +54,7 @@ class PLLWC_Admin_Product_Duplicate * * @param WC_Product $duplicate Duplicated product. * @param WC_Product $product Original product. + * * @return void */ public function product_duplicate($duplicate, $product) @@ -68,7 +65,7 @@ class PLLWC_Admin_Product_Duplicate $meta_to_exclude = (array) array_filter( apply_filters( 'woocommerce_duplicate_product_exclude_meta', - array(), + [], array_map( function ($datum) { return $datum->key; @@ -80,8 +77,8 @@ class PLLWC_Admin_Product_Duplicate // First set the language of the product duplicated by WooCommerce. $lang = $this->data_store->get_language($product->get_id()); - $new_tr_ids = array( $lang => $duplicate->get_id() ); - $this->data_store->set_language($new_tr_ids[ $lang ], $lang); + $new_tr_ids = [$lang => $duplicate->get_id()]; + $this->data_store->set_language($new_tr_ids[$lang], $lang); // Duplicate the translations. foreach ($tr_ids as $lang => $tr_id) { @@ -95,7 +92,7 @@ class PLLWC_Admin_Product_Duplicate $tr_duplicate->set_status('draft'); $tr_duplicate->set_date_created(null); $tr_duplicate->set_slug(''); - $tr_duplicate->set_rating_counts(array()); + $tr_duplicate->set_rating_counts([]); $tr_duplicate->set_average_rating(0); $tr_duplicate->set_review_count(0); @@ -111,9 +108,9 @@ class PLLWC_Admin_Product_Duplicate do_action('woocommerce_product_duplicate_before_save', $tr_duplicate, $tr_product); $tr_duplicate->save(); - $new_tr_ids[ $lang ] = $tr_duplicate->get_id(); + $new_tr_ids[$lang] = $tr_duplicate->get_id(); - $this->data_store->set_language($new_tr_ids[ $lang ], $lang); + $this->data_store->set_language($new_tr_ids[$lang], $lang); // Set the SKU only now that the language is known. if ('' !== $duplicate->get_sku('edit')) { @@ -132,8 +129,8 @@ class PLLWC_Admin_Product_Duplicate $tr_ids = $this->data_store->get_translations($child_id); if ($tr_ids && $child = wc_get_product($child_id)) { - $new_child_tr_ids = array(); - $tr_child_duplicates = array(); + $new_child_tr_ids = []; + $tr_child_duplicates = []; $sku = wc_product_generate_unique_sku(0, $child->get_sku('edit')); @@ -146,37 +143,37 @@ class PLLWC_Admin_Product_Duplicate foreach ($tr_ids as $lang => $tr_id) { $tr_child = wc_get_product($tr_id); - if (! $tr_child instanceof WC_Product) { + if (!$tr_child instanceof WC_Product) { continue; } $tr_child->read_meta_data(); - $tr_child_duplicates[ $lang ] = clone $tr_child; - $tr_child_duplicates[ $lang ]->set_parent_id($this->data_store->get($duplicate->get_id(), $lang)); - $tr_child_duplicates[ $lang ]->set_id(0); - $tr_child_duplicates[ $lang ]->set_date_created(null); + $tr_child_duplicates[$lang] = clone $tr_child; + $tr_child_duplicates[$lang]->set_parent_id($this->data_store->get($duplicate->get_id(), $lang)); + $tr_child_duplicates[$lang]->set_id(0); + $tr_child_duplicates[$lang]->set_date_created(null); if ('' !== $child->get_sku('edit')) { - $tr_child_duplicates[ $lang ]->set_sku($sku); + $tr_child_duplicates[$lang]->set_sku($sku); } // Clear the product unique ID (since WC 9.2.0). if (method_exists('WC_Product', 'set_global_unique_id')) { - $tr_child_duplicates[ $lang ]->set_global_unique_id(''); + $tr_child_duplicates[$lang]->set_global_unique_id(''); } - $this->generate_unique_slug($tr_child_duplicates[ $lang ]); + $this->generate_unique_slug($tr_child_duplicates[$lang]); foreach ($meta_to_exclude as $meta_key) { - $tr_child_duplicates[ $lang ]->delete_meta_data($meta_key); + $tr_child_duplicates[$lang]->delete_meta_data($meta_key); } - do_action('woocommerce_product_duplicate_before_save', $tr_child_duplicates[ $lang ], $tr_child); + do_action('woocommerce_product_duplicate_before_save', $tr_child_duplicates[$lang], $tr_child); } foreach ($tr_child_duplicates as $lang => $child) { $child->save(); - $new_child_tr_ids[ $lang ] = $child->get_id(); + $new_child_tr_ids[$lang] = $child->get_id(); $this->data_store->set_language($child->get_id(), $lang); } @@ -191,11 +188,12 @@ class PLLWC_Admin_Product_Duplicate * behavior of wp_unique_post_slug(). The normal slug generation will run single * select queries on every non-unique slug, resulting in very bad performance. * This is an exact copy of WC_Admin_Duplicate_Product::generate_unique_slug() - * Code last checked: WC 4.0 + * Code last checked: WC 4.0. * * @since 1.5 * * @param WC_Product $product The product to generate a slug for. + * * @return void */ private function generate_unique_slug($product) @@ -206,7 +204,7 @@ class PLLWC_Admin_Product_Duplicate // filling, this shouldn't matter for our use-case. $root_slug = preg_replace('/-[0-9]+$/', '', $product->get_slug()); $results = $wpdb->get_results( - $wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name LIKE %s AND post_type IN ( 'product', 'product_variation' )", $root_slug . '%') + $wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name LIKE %s AND post_type IN ( 'product', 'product_variation' )", $root_slug.'%') ); // The slug is already unique! if (empty($results)) { @@ -221,6 +219,6 @@ class PLLWC_Admin_Product_Duplicate $max_suffix = $suffix; } } - $product->set_slug($root_slug . '-' . ($max_suffix + 1)); + $product->set_slug($root_slug.'-'.($max_suffix + 1)); } } diff --git a/__plugins/polylang-wc/src/admin/admin-products.php b/__plugins/polylang-wc/src/admin/admin-products.php index d646dc4c51a8447f29a54b8290c95a3bfd003b71..084c19dc333613617d562bcbdab439adceddd838 100644 --- a/__plugins/polylang-wc/src/admin/admin-products.php +++ b/__plugins/polylang-wc/src/admin/admin-products.php @@ -1,9 +1,5 @@ data_store = PLLWC_Data_Store::load('product_language'); // Ajax. - add_action('admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' )); - add_action('wp_ajax_product_lang_choice', array( $this, 'product_lang_choice' )); + add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); + add_action('wp_ajax_product_lang_choice', [$this, 'product_lang_choice']); // Ajax product ordering. if (in_array('menu_order', PLL()->options['sync'])) { - add_action('woocommerce_after_product_ordering', array( $this, 'product_ordering' ), 10, 2); + add_action('woocommerce_after_product_ordering', [$this, 'product_ordering'], 10, 2); } // Autocomplete ajax products search. - add_filter('woocommerce_json_search_found_products', array( $this, 'search_found_products' )); - add_filter('woocommerce_json_search_found_grouped_products', array( $this, 'search_found_products' )); + add_filter('woocommerce_json_search_found_products', [$this, 'search_found_products']); + add_filter('woocommerce_json_search_found_grouped_products', [$this, 'search_found_products']); // Search in Products list table. - add_filter('pll_filter_query_excluded_query_vars', array( $this, 'fix_products_search' ), 10, 2); // Since Polylang 2.3.5. + add_filter('pll_filter_query_excluded_query_vars', [$this, 'fix_products_search'], 10, 2); // Since Polylang 2.3.5. // Deactivate the German and Danish specific sanitization for product attributes titles. - $specific_locales = array( 'da_DK', 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal' ); - if (array_intersect(PLL()->model->get_languages_list(array( 'fields' => 'locale' )), $specific_locales)) { - add_action('wp_ajax_woocommerce_load_variations', array( $this, 'remove_sanitize_title' ), 5); - add_action('woocommerce_product_write_panel_tabs', array( $this, 'remove_sanitize_title' ), 5); - add_action('woocommerce_product_data_panels', array( $this, 'add_sanitize_title' ), 5); + $specific_locales = ['da_DK', 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal']; + if (array_intersect(PLL()->model->get_languages_list(['fields' => 'locale']), $specific_locales)) { + add_action('wp_ajax_woocommerce_load_variations', [$this, 'remove_sanitize_title'], 5); + add_action('woocommerce_product_write_panel_tabs', [$this, 'remove_sanitize_title'], 5); + add_action('woocommerce_product_data_panels', [$this, 'add_sanitize_title'], 5); } } @@ -63,9 +59,9 @@ class PLLWC_Admin_Products public function admin_enqueue_scripts() { $screen = get_current_screen(); - if (! empty($screen) && 'post' === $screen->base && 'product' === $screen->post_type) { + if (!empty($screen) && 'post' === $screen->base && 'product' === $screen->post_type) { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_script('pllwc_product', plugins_url('/js/build/product' . $suffix . '.js', PLLWC_FILE), array( 'jquery', 'wp-ajax-response' ), PLLWC_VERSION, true); + wp_enqueue_script('pllwc_product', plugins_url('/js/build/product'.$suffix.'.js', PLLWC_FILE), ['jquery', 'wp-ajax-response'], PLLWC_VERSION, true); } } @@ -81,11 +77,11 @@ class PLLWC_Admin_Products check_ajax_referer('pll_language', '_pll_nonce'); if (isset($_POST['post_id'], $_POST['lang'], $_POST['attributes']) && is_array($_POST['attributes'])) { - $post_id = (int) $_POST['post_id']; - $lang = PLL()->model->get_language(sanitize_key($_POST['lang'])); + $post_id = (int) $_POST['post_id']; + $lang = PLL()->model->get_language(sanitize_key($_POST['lang'])); $attributes = array_map('sanitize_title', wp_unslash($_POST['attributes'])); - $supplemental = array(); + $supplemental = []; $x = new WP_Ajax_Response(); @@ -96,10 +92,10 @@ class PLLWC_Admin_Products $out = ''; $product_terms = get_the_terms($post_id, $taxonomy); - $term_ids = is_array($product_terms) ? wp_list_pluck($product_terms, 'term_id') : array(); - $tr_term_ids = array_map('pll_get_term', $term_ids); + $term_ids = is_array($product_terms) ? wp_list_pluck($product_terms, 'term_id') : []; + $tr_term_ids = array_map('pll_get_term', $term_ids); - $all_terms = get_terms(array( 'taxonomy' => $taxonomy, 'orderby' => 'name', 'hide_empty' => 0, 'lang' => $lang->slug )); + $all_terms = get_terms(['taxonomy' => $taxonomy, 'orderby' => 'name', 'hide_empty' => 0, 'lang' => $lang->slug]); if (is_array($all_terms)) { foreach ($all_terms as $term) { @@ -112,12 +108,12 @@ class PLLWC_Admin_Products } } - $supplemental[ 'value-' . $i ] = $out; + $supplemental['value-'.$i] = $out; } } - if (! empty($supplemental)) { - $x->Add(array( 'what' => 'attributes', 'supplemental' => $supplemental )); + if (!empty($supplemental)) { + $x->Add(['what' => 'attributes', 'supplemental' => $supplemental]); } $x->send(); @@ -132,6 +128,7 @@ class PLLWC_Admin_Products * * @param int $id Product id. * @param int[] $menu_orders An array with product ids as key and menu_order as value. + * * @return void */ public function product_ordering($id, $menu_orders) @@ -156,18 +153,19 @@ class PLLWC_Admin_Products * @since 0.1 * * @param string[] $products array with product ids as keys and names as values. + * * @return string[] */ public function search_found_products($products) { // Either we are editing a product or an order. - if (! isset($_REQUEST['pll_post_id']) || ! $lang = $this->data_store->get_language((int) $_REQUEST['pll_post_id'])) { // phpcs:ignore WordPress.Security.NonceVerification + if (!isset($_REQUEST['pll_post_id']) || !$lang = $this->data_store->get_language((int) $_REQUEST['pll_post_id'])) { // phpcs:ignore WordPress.Security.NonceVerification $lang = PLLWC_Admin::get_preferred_language(); } foreach (array_keys($products) as $id) { if ($this->data_store->get_language($id) !== $lang) { - unset($products[ $id ]); + unset($products[$id]); } } @@ -184,13 +182,15 @@ class PLLWC_Admin_Products * * @param string[] $excludes Query vars excluded from the language filter. * @param WP_Query $query WP Query object. + * * @return string[] */ public function fix_products_search($excludes, $query) { - if (! empty($query->query['product_search'])) { - $excludes = array_diff($excludes, array( 'post__in' )); + if (!empty($query->query['product_search'])) { + $excludes = array_diff($excludes, ['post__in']); } + return $excludes; } @@ -204,7 +204,7 @@ class PLLWC_Admin_Products public function remove_sanitize_title() { if (isset(PLL()->filters_sanitization)) { - remove_filter('sanitize_title', array( PLL()->filters_sanitization, 'sanitize_title' )); + remove_filter('sanitize_title', [PLL()->filters_sanitization, 'sanitize_title']); } } @@ -218,7 +218,7 @@ class PLLWC_Admin_Products public function add_sanitize_title() { if (isset(PLL()->filters_sanitization)) { - add_filter('sanitize_title', array( PLL()->filters_sanitization, 'sanitize_title' ), 10, 3); + add_filter('sanitize_title', [PLL()->filters_sanitization, 'sanitize_title'], 10, 3); } } } diff --git a/__plugins/polylang-wc/src/admin/admin-reports.php b/__plugins/polylang-wc/src/admin/admin-reports.php index 55eb2dc9d617443a21b47aae2c6dab04c55a73bc..4d1a54aeb738e253d77578ba73411eab67c71d4c 100644 --- a/__plugins/polylang-wc/src/admin/admin-reports.php +++ b/__plugins/polylang-wc/src/admin/admin-reports.php @@ -1,9 +1,5 @@ data_store = PLLWC_Data_Store::load('product_language'); // Combines products per language. - add_filter('woocommerce_reports_get_order_report_query', array( $this, 'report_query' )); - add_filter('woocommerce_reports_get_order_report_data', array( $this, 'report_data' )); + add_filter('woocommerce_reports_get_order_report_query', [$this, 'report_query']); + add_filter('woocommerce_reports_get_order_report_data', [$this, 'report_data']); // Sales by category. - add_filter('woocommerce_report_sales_by_category_get_products_in_category', array( $this, 'get_products_in_category' ), 10, 2); - add_filter('terms_clauses', array( $this, 'terms_clauses' ), 10, 3); + add_filter('woocommerce_report_sales_by_category_get_products_in_category', [$this, 'get_products_in_category'], 10, 2); + add_filter('terms_clauses', [$this, 'terms_clauses'], 10, 3); // Filters stock queries per language. - add_filter('woocommerce_report_low_in_stock_query_from', array( $this, 'stock_query' )); - add_filter('woocommerce_report_out_of_stock_query_from', array( $this, 'stock_query' )); - add_filter('woocommerce_report_most_stocked_query_from', array( $this, 'stock_query' )); + add_filter('woocommerce_report_low_in_stock_query_from', [$this, 'stock_query']); + add_filter('woocommerce_report_out_of_stock_query_from', [$this, 'stock_query']); + add_filter('woocommerce_report_most_stocked_query_from', [$this, 'stock_query']); } /** @@ -50,6 +46,7 @@ class PLLWC_Admin_Reports * @since 0.1 * * @param string[] $query Array of SQL clauses. + * * @return string[] */ public function report_query($query) @@ -65,10 +62,10 @@ class PLLWC_Admin_Reports * Thus we need to make sure to get the correct language thanks to the woocommerce_reports_get_order_report_data filter. * FIXME never return a product which has no translation. */ - $query['join'] .= " INNER JOIN {$wpdb->term_relationships} AS pll_tr ON order_item_meta__product_id.meta_value = pll_tr.object_id"; - $query['join'] .= " INNER JOIN {$wpdb->term_taxonomy} AS pll_tt ON pll_tr.term_taxonomy_id = pll_tt.term_taxonomy_id"; - $query['where'] .= $wpdb->prepare(' AND pll_tt.taxonomy = %s', $this->data_store->get_tax_translations()); - $query['where'] .= $wpdb->prepare(' AND %s = %s', $lang, $lang); // Hack to be sure to get one query per filtered language to pass into woocommerce_reports_get_order_report_data filter. + $query['join'] .= " INNER JOIN {$wpdb->term_relationships} AS pll_tr ON order_item_meta__product_id.meta_value = pll_tr.object_id"; + $query['join'] .= " INNER JOIN {$wpdb->term_taxonomy} AS pll_tt ON pll_tr.term_taxonomy_id = pll_tt.term_taxonomy_id"; + $query['where'] .= $wpdb->prepare(' AND pll_tt.taxonomy = %s', $this->data_store->get_tax_translations()); + $query['where'] .= $wpdb->prepare(' AND %s = %s', $lang, $lang); // Hack to be sure to get one query per filtered language to pass into woocommerce_reports_get_order_report_data filter. $query['group_by'] = 'GROUP BY pll_tr.term_taxonomy_id'; } @@ -76,16 +73,16 @@ class PLLWC_Admin_Reports if (false !== strpos($query['select'], 'sparkline')) { $pattern = "#order_item_meta__product_id.meta_value = '([0-9]+)'#"; if (preg_match($pattern, $query['where'], $matches)) { - $ids = array(); + $ids = []; foreach ($this->data_store->get_translations((int) $matches[1]) as $tr_id) { $ids[] = $tr_id; } - if (! empty($ids)) { - $ids = array_unique($ids); - $ids = array_map('absint', $ids); - $replace = "order_item_meta__product_id.meta_value IN ('" . implode("','", $ids) . "')"; + if (!empty($ids)) { + $ids = array_unique($ids); + $ids = array_map('absint', $ids); + $replace = "order_item_meta__product_id.meta_value IN ('".implode("','", $ids)."')"; $query['where'] = (string) preg_replace($pattern, $replace, $query['where']); } } @@ -95,7 +92,7 @@ class PLLWC_Admin_Reports if (false !== strpos($query['select'], 'order_item_count') || false !== strpos($query['select'], 'order_item_amount')) { $pattern = "#order_item_meta__product_id_array.meta_value IN \('([\',0-9]+)'\)#"; if (preg_match($pattern, $query['where'], $matches)) { - $ids = array(); + $ids = []; foreach (array_map('absint', explode("','", $matches[1])) as $id) { foreach ($this->data_store->get_translations($id) as $tr_id) { @@ -103,10 +100,10 @@ class PLLWC_Admin_Reports } } - if (! empty($ids)) { - $ids = array_unique($ids); - $ids = array_map('absint', $ids); - $replace = "order_item_meta__product_id_array.meta_value IN ('" . implode("','", $ids) . "')"; + if (!empty($ids)) { + $ids = array_unique($ids); + $ids = array_map('absint', $ids); + $replace = "order_item_meta__product_id_array.meta_value IN ('".implode("','", $ids)."')"; $query['where'] = (string) preg_replace($pattern, $replace, $query['where']); } } @@ -122,11 +119,12 @@ class PLLWC_Admin_Reports * @since 0.1 * * @param array $results Array of products returned by WC_Admin_Report::get_order_report_data(). + * * @return array */ public function report_data($results) { - if (! is_array($results)) { + if (!is_array($results)) { return $results; } @@ -137,8 +135,8 @@ class PLLWC_Admin_Reports } foreach ($results as $key => $result) { - if (! empty($result->product_id)) { - $results[ $key ]->product_id = $this->data_store->get($result->product_id, $lang); + if (!empty($result->product_id)) { + $results[$key]->product_id = $this->data_store->get($result->product_id, $lang); } } @@ -153,15 +151,16 @@ class PLLWC_Admin_Reports * * @param int[] $product_ids Not used. * @param int $category_id Product category id. + * * @return int[] */ public function get_products_in_category($product_ids, $category_id) { - $term_ids = array(); + $term_ids = []; foreach (pll_get_term_translations($category_id) as $tr_id) { $term_ids[] = $tr_id; - $tr_children = get_term_children($tr_id, 'product_cat'); + $tr_children = get_term_children($tr_id, 'product_cat'); if (is_wp_error($tr_children)) { continue; @@ -172,7 +171,7 @@ class PLLWC_Admin_Reports $terms = get_objects_in_term($term_ids, 'product_cat'); - return is_array($terms) ? array_map('intval', $terms) : array(); + return is_array($terms) ? array_map('intval', $terms) : []; } /** @@ -184,6 +183,7 @@ class PLLWC_Admin_Reports * @param string[] $clauses SQL clauses. * @param string[] $taxonomies Not used. * @param array $args WP_Term_Query arguments. + * * @return string[] Modified SQL clauses */ public function terms_clauses($clauses, $taxonomies, $args) @@ -196,6 +196,7 @@ class PLLWC_Admin_Reports return PLL()->model->terms_clauses($clauses, $lang); } } + return $clauses; } @@ -205,6 +206,7 @@ class PLLWC_Admin_Reports * @since 0.1 * * @param string $query_from Part of the SQL query (FROM, JOIN, WHERE clauses). + * * @return string */ public function stock_query($query_from) @@ -215,6 +217,6 @@ class PLLWC_Admin_Reports return $query_from; } - return str_replace('WHERE 1=1', $this->data_store->join_clause('posts') . ' WHERE 1=1' . $this->data_store->where_clause($lang), $query_from); + return str_replace('WHERE 1=1', $this->data_store->join_clause('posts').' WHERE 1=1'.$this->data_store->where_clause($lang), $query_from); } } diff --git a/__plugins/polylang-wc/src/admin/admin-site-health.php b/__plugins/polylang-wc/src/admin/admin-site-health.php index c5a2834bb2c01080b5346b19ca3a6c8bb1690fea..49e465a786ccf0fc5ee4b7e48cd5797b9b89a21f 100644 --- a/__plugins/polylang-wc/src/admin/admin-site-health.php +++ b/__plugins/polylang-wc/src/admin/admin-site-health.php @@ -1,11 +1,7 @@ admin_status_reports->get_woocommerce_pages_status(); - $fields = array(); + $fields = []; if (false === $pages_status->is_error) { $fields['pllwc']['label'] = __('WooCommerce pages translations', 'polylang-wc'); $fields['pllwc']['value'] = __('All WooCommerce pages are translated.', 'polylang-wc'); } else { foreach ($pages_status->pages as $page => $value) { if (true === $value->is_error) { - $fields[ $page ]['label'] = $value->page_name; - $fields[ $page ]['value'] = $value->page_id . ' - ' . $value->error_message; + $fields[$page]['label'] = $value->page_name; + $fields[$page]['value'] = $value->page_id.' - '.$value->error_message; } } } - $debug_info['polylang-wc'] = array( + $debug_info['polylang-wc'] = [ 'label' => 'Polylang for WooCommerce', 'fields' => $fields, - ); + ]; return $debug_info; } diff --git a/__plugins/polylang-wc/src/admin/admin-status-reports.php b/__plugins/polylang-wc/src/admin/admin-status-reports.php index 9b60ad61a55bd7b9724faa9469c124851c827720..d51e0f4ed3f019ffd518fc9396a0cc455bfa4b91 100644 --- a/__plugins/polylang-wc/src/admin/admin-status-reports.php +++ b/__plugins/polylang-wc/src/admin/admin-status-reports.php @@ -1,9 +1,5 @@ woocommerce_pages_status)) { + if (!empty($this->woocommerce_pages_status)) { return $this->woocommerce_pages_status; } - $this->woocommerce_pages_status = (object) array( + $this->woocommerce_pages_status = (object) [ 'is_error' => false, - 'pages' => array(), - ); + 'pages' => [], + ]; - $check_pages = array( - _x('Shop base', 'Page setting', 'polylang-wc') => array( + $check_pages = [ + _x('Shop base', 'Page setting', 'polylang-wc') => [ 'option' => 'woocommerce_shop_page_id', 'shortcode' => '', 'block' => '', 'help' => __('The status of your WooCommerce shop\'s homepage translations.', 'polylang-wc'), - ), - _x('Cart', 'Page setting', 'polylang-wc') => array( + ], + _x('Cart', 'Page setting', 'polylang-wc') => [ 'option' => 'woocommerce_cart_page_id', 'shortcode' => apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart'), 'block' => 'woocommerce/cart', 'help' => __('The status of your WooCommerce shop\'s cart translations.', 'polylang-wc'), - ), - _x('Checkout', 'Page setting', 'polylang-wc') => array( + ], + _x('Checkout', 'Page setting', 'polylang-wc') => [ 'option' => 'woocommerce_checkout_page_id', 'shortcode' => apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout'), 'block' => 'woocommerce/checkout', 'help' => __('The status of your WooCommerce shop\'s checkout page translations.', 'polylang-wc'), - ), - _x('My account', 'Page setting', 'polylang-wc') => array( + ], + _x('My account', 'Page setting', 'polylang-wc') => [ 'option' => 'woocommerce_myaccount_page_id', 'shortcode' => apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account'), 'block' => '', 'help' => __('The status of your WooCommerce shop\'s “My Account” page translations.', 'polylang-wc'), - ), - _x('Terms and conditions', 'Page setting', 'polylang-wc') => array( + ], + _x('Terms and conditions', 'Page setting', 'polylang-wc') => [ 'option' => 'woocommerce_terms_page_id', 'shortcode' => '', 'block' => '', 'help' => __('The status of your WooCommerce shop\'s “Terms and conditions” page translations.', 'polylang-wc'), - ), - ); + ], + ]; $languages = pll_languages_list(); - $pages = array(); + $pages = []; foreach ($check_pages as $page_name => $values) { $page_id = get_option($values['option']); $page_id = is_numeric($page_id) ? (int) $page_id : 0; - $page_properties = array( + $page_properties = [ 'page_id' => $page_id, 'page_name' => $page_name, 'help' => $values['help'], 'is_error' => false, - ); + ]; - if (! $page_id) { - $page_properties['is_error'] = true; + if (!$page_id) { + $page_properties['is_error'] = true; $page_properties['error_message'] = __('Page not set', 'polylang-wc'); } else { $translations = pll_get_post_translations($page_id); - $missing = array_diff($languages, array_keys($translations)); + $missing = array_diff($languages, array_keys($translations)); // Do translations exist? if ($missing) { foreach ($missing as $key => $slug) { - $missing[ $key ] = PLL()->model->get_language($slug)->name; + $missing[$key] = PLL()->model->get_language($slug)->name; } - $page_properties['is_error'] = true; + $page_properties['is_error'] = true; $page_properties['error_message'] = sprintf( /* translators: %s comma separated list of native languages names */ _n('Missing translation: %s', 'Missing translations: %s', count($missing), 'polylang-wc'), @@ -135,8 +132,8 @@ class PLLWC_Admin_Status_Reports } // Do translations have the correct shortcode or block? - elseif (! empty($values['block'] || ! empty($values['shortcode']))) { - $wrong_translations = array(); + elseif (!empty($values['block'] || !empty($values['shortcode']))) { + $wrong_translations = []; foreach ($translations as $lang => $translation) { $_page = get_post($translation); @@ -146,12 +143,12 @@ class PLLWC_Admin_Status_Reports // Shortcode checks. $page_is_set = false; - if (! empty($values['shortcode'])) { + if (!empty($values['shortcode'])) { if (has_shortcode($_page->post_content, $values['shortcode'])) { $page_is_set = true; } // Compatibility with the classic shortcode block which can be used instead of shortcodes. - if (! $page_is_set && ! empty($values['block'])) { + if (!$page_is_set && !empty($values['block'])) { $page_is_set = $this->has_block_variation( 'woocommerce/classic-shortcode', 'shortcode', @@ -162,17 +159,17 @@ class PLLWC_Admin_Status_Reports } // Block checks. - if (! $page_is_set && ! empty($values['block'])) { + if (!$page_is_set && !empty($values['block'])) { $page_is_set = has_block($values['block'], $_page->post_content); } - if (! $page_is_set) { + if (!$page_is_set) { $wrong_translations[] = PLL()->model->get_language($lang)->name; } } if ($wrong_translations) { - $page_properties['is_error'] = true; + $page_properties['is_error'] = true; $page_properties['error_message'] = sprintf( /* translators: %s comma separated list of native languages names */ _n('The shortcode or block is missing for the translation in %s', 'The shortcode or block is missing for the translations in %s', count($wrong_translations), 'polylang-wc'), @@ -184,9 +181,9 @@ class PLLWC_Admin_Status_Reports } } - $pages[ $page_name ] = (object) $page_properties; - if ($pages[ $page_name ]->is_error) { - $this->woocommerce_pages_status->is_error = $pages[ $page_name ]->is_error; + $pages[$page_name] = (object) $page_properties; + if ($pages[$page_name]->is_error) { + $this->woocommerce_pages_status->is_error = $pages[$page_name]->is_error; } } @@ -204,7 +201,7 @@ class PLLWC_Admin_Status_Reports */ public function status_report() { - include __DIR__ . '/view-status-report.php'; + include __DIR__.'/view-status-report.php'; } /** @@ -216,7 +213,7 @@ class PLLWC_Admin_Status_Reports */ public function wizard_status_report() { - include __DIR__ . '/view-wizard-status-report.php'; + include __DIR__.'/view-wizard-status-report.php'; } /** @@ -226,10 +223,11 @@ class PLLWC_Admin_Status_Reports * * @since 2.1.5 * - * @param string $block_id The block ID to check for. - * @param string $attribute The attribute to check. - * @param string $value The value to check for. - * @param string $post_content The post content to check. + * @param string $block_id The block ID to check for. + * @param string $attribute The attribute to check. + * @param string $value The value to check for. + * @param string $post_content The post content to check. + * * @return bool */ private function has_block_variation($block_id, $attribute, $value, $post_content) @@ -238,7 +236,7 @@ class PLLWC_Admin_Status_Reports return CartCheckoutUtils::has_block_variation($block_id, $attribute, $value, $post_content); } - if (! $post_content) { + if (!$post_content) { return false; } @@ -246,11 +244,11 @@ class PLLWC_Admin_Status_Reports $blocks = (array) parse_blocks($post_content); foreach ($blocks as $block) { - if (isset($block['attrs'][ $attribute ]) && $value === $block['attrs'][ $attribute ]) { + if (isset($block['attrs'][$attribute]) && $value === $block['attrs'][$attribute]) { return true; } // Cart is default so it will be empty. - if ('woocommerce/classic-shortcode' === $block_id && 'shortcode' === $attribute && 'cart' === $value && ! isset($block['attrs']['shortcode'])) { + if ('woocommerce/classic-shortcode' === $block_id && 'shortcode' === $attribute && 'cart' === $value && !isset($block['attrs']['shortcode'])) { return true; } } diff --git a/__plugins/polylang-wc/src/admin/admin-taxonomies.php b/__plugins/polylang-wc/src/admin/admin-taxonomies.php index a2271b5b43fee9e59ae848535f713169ab9019b4..eb547277132d3cda485c5c563f82f14ebfb98102 100644 --- a/__plugins/polylang-wc/src/admin/admin-taxonomies.php +++ b/__plugins/polylang-wc/src/admin/admin-taxonomies.php @@ -1,9 +1,5 @@ options['media_support']) { - add_filter('pll_translate_term_meta', array( $this, 'translate_meta' ), 10, 3); + add_filter('pll_translate_term_meta', [$this, 'translate_meta'], 10, 3); // WooCommerce ( verified in 2.5.5 ) inconsistently uses created_term and edit_term so we can't use pll_save_term. - add_action('created_product_cat', array( $this, 'fix_term_thumbnail' ), 999); - add_action('edited_product_cat', array( $this, 'fix_term_thumbnail' ), 999); + add_action('created_product_cat', [$this, 'fix_term_thumbnail'], 999); + add_action('edited_product_cat', [$this, 'fix_term_thumbnail'], 999); } // Attributes. - add_action('create_term', array( $this, 'create_attribute_term' ), 10, 3); + add_action('create_term', [$this, 'create_attribute_term'], 10, 3); /* * Workaround WooCommerce not providing access its WC_Admin_Taxonomies object. * This is possible since WC 3.6 with WC_Admin_Taxonomies::get_instance(). * It would be better if filters could allow to pre-populate term meta the same way 'taxonomy_parent_dropdown_args' does. */ - pll_remove_anonymous_object_filter('product_cat_add_form_fields', array( 'WC_Admin_Taxonomies', 'add_category_fields' )); - add_action('product_cat_add_form_fields', array( $this, 'add_category_fields' )); + pll_remove_anonymous_object_filter('product_cat_add_form_fields', ['WC_Admin_Taxonomies', 'add_category_fields']); + add_action('product_cat_add_form_fields', [$this, 'add_category_fields']); - add_action('admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' )); + add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); } /** @@ -65,6 +61,7 @@ class PLLWC_Admin_Taxonomies * @param int $from Id of the term from which we copy information. * @param int $to Id of the term to which we paste information. * @param string $lang Language slug. + * * @return string[] */ public function get_metas_to_copy($to_copy, $sync, $from, $to, $lang) @@ -73,12 +70,12 @@ class PLLWC_Admin_Taxonomies // Product categories. if ($term instanceof WP_Term && 'product_cat' === $term->taxonomy) { - $_to_copy = array( + $_to_copy = [ 'display_type', 'thumbnail_id', - ); + ]; - if (! $sync) { + if (!$sync) { $_to_copy[] = 'order'; } @@ -86,7 +83,7 @@ class PLLWC_Admin_Taxonomies } // Add attributes order. - if ($term instanceof WP_Term && ! $sync && 0 === strpos($term->taxonomy, 'pa_')) { + if ($term instanceof WP_Term && !$sync && 0 === strpos($term->taxonomy, 'pa_')) { $metas = get_term_meta($from); if (is_array($metas)) { @@ -117,10 +114,10 @@ class PLLWC_Admin_Taxonomies * because WC modifies the orderby arg to meta_value_num in wc_change_pre_get_terms(). * * @see PLL_CRUD_Terms::get_terms_args() - * * @since 1.2.1 * * @param array $args WP_Term_Query arguments. + * * @return array Modified arguments */ public function get_terms_args($args) @@ -128,6 +125,7 @@ class PLLWC_Admin_Taxonomies if ('all' === $args['get'] && 'meta_value_num' === $args['orderby'] && 'id=>parent' === $args['fields']) { $args['lang'] = ''; } + return $args; } @@ -139,14 +137,16 @@ class PLLWC_Admin_Taxonomies * @param mixed $value Meta value. * @param string $key Meta key. * @param string $lang Language of target. + * * @return mixed */ public function translate_meta($value, $key, $lang) { - if ('thumbnail_id' === $key && is_numeric($value) && ! empty($value)) { + if ('thumbnail_id' === $key && is_numeric($value) && !empty($value)) { $tr_value = pll_get_post((int) $value, $lang); $value = $tr_value ? $tr_value : $value; } + return $value; } @@ -158,6 +158,7 @@ class PLLWC_Admin_Taxonomies * @since 0.1 * * @param int $term_id Term id. + * * @return void */ public function fix_term_thumbnail($term_id) @@ -171,8 +172,8 @@ class PLLWC_Admin_Taxonomies if ($thumbnail_id && $lang && pll_get_post_language($thumbnail_id) !== $lang) { $translations = pll_get_post_translations($thumbnail_id); - if (! empty($translations[ $lang ])) { - update_term_meta($term_id, 'thumbnail_id', $translations[ $lang ]); // Take the translation in the right language. + if (!empty($translations[$lang])) { + update_term_meta($term_id, 'thumbnail_id', $translations[$lang]); // Take the translation in the right language. } else { pll_set_post_language($thumbnail_id, $lang); // Or fix the language. } @@ -187,19 +188,20 @@ class PLLWC_Admin_Taxonomies * @param int $term_id Term id. * @param int $tt_id Term taxonomy id. * @param string $taxonomy Taxonomy name. + * * @return void */ public function create_attribute_term($term_id, $tt_id, $taxonomy) { - if (! doing_action('wp_ajax_woocommerce_add_new_attribute') || ! str_starts_with($taxonomy, 'pa_')) { + if (!doing_action('wp_ajax_woocommerce_add_new_attribute') || !str_starts_with($taxonomy, 'pa_')) { return; } - if (! isset($_POST['pll_post_id'], $_REQUEST['security'])) { + if (!isset($_POST['pll_post_id'], $_REQUEST['security'])) { return; } - if (! wp_verify_nonce($_REQUEST['security'], 'add-attribute')) { + if (!wp_verify_nonce($_REQUEST['security'], 'add-attribute')) { return; } @@ -223,7 +225,7 @@ class PLLWC_Admin_Taxonomies $term = get_term((int) $_GET['from_tag'], 'product_cat'); // phpcs:ignore WordPress.Security.NonceVerification } - if (! empty($term)) { + if (!empty($term)) { WC_Admin_Taxonomies::get_instance()->edit_category_fields($term); } else { WC_Admin_Taxonomies::get_instance()->add_category_fields(); @@ -240,7 +242,7 @@ class PLLWC_Admin_Taxonomies public function admin_enqueue_scripts() { $screen = get_current_screen(); - if (! empty($screen) && in_array($screen->base, array( 'edit-tags', 'term' )) && 'product_cat' === $screen->taxonomy) { + if (!empty($screen) && in_array($screen->base, ['edit-tags', 'term']) && 'product_cat' === $screen->taxonomy) { $this->load_scripts(); } } @@ -255,6 +257,6 @@ class PLLWC_Admin_Taxonomies public function load_scripts() { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_script('pllwc_product_cat', plugins_url('/js/build/filter-media-taxonomy' . $suffix . '.js', PLLWC_FILE), array( 'jquery' ), PLLWC_VERSION, true); + wp_enqueue_script('pllwc_product_cat', plugins_url('/js/build/filter-media-taxonomy'.$suffix.'.js', PLLWC_FILE), ['jquery'], PLLWC_VERSION, true); } } diff --git a/__plugins/polylang-wc/src/admin/admin-wc-install.php b/__plugins/polylang-wc/src/admin/admin-wc-install.php index 4defd32a62986028b59499d23a04533e0e42d8b8..72f3bc9cdc9181eb7dfc8fb3d33bf8a9d0273429 100644 --- a/__plugins/polylang-wc/src/admin/admin-wc-install.php +++ b/__plugins/polylang-wc/src/admin/admin-wc-install.php @@ -1,9 +1,5 @@ >> */ - private $pages = array(); + private $pages = []; /** * Constructor. @@ -27,22 +23,22 @@ class PLLWC_Admin_WC_Install public function __construct() { // Add post state for translations of the shop, cart, etc... - add_filter('display_post_states', array( $this, 'display_post_states' ), 10, 2); + add_filter('display_post_states', [$this, 'display_post_states'], 10, 2); // Allow WC to install the default pages and their translations through status page. - add_filter('woocommerce_debug_tools', array( $this, 'debug_tools' )); + add_filter('woocommerce_debug_tools', [$this, 'debug_tools']); // Make sure to load only on setup wizard as initializing translated pages is expensive. if (isset($_GET['page'], $_GET['path']) && 'wc-admin' === $_GET['page'] && '/setup-wizard' === $_GET['path']) { // phpcs:ignore WordPress.Security.NonceVerification $this->init_translated_pages(); - if (! empty($this->pages)) { - add_action('init', array( $this, 'translate_default_wc_pages' )); // $wp_rewrite is not available yet and is required when wp_unique_post_slug() is called, so we need to wait for init. + if (!empty($this->pages)) { + add_action('init', [$this, 'translate_default_wc_pages']); // $wp_rewrite is not available yet and is required when wp_unique_post_slug() is called, so we need to wait for init. } } // Add default product category when adding a new language. - add_action('pll_add_language', array( $this, 'add_language' )); + add_action('pll_add_language', [$this, 'add_language']); } /** @@ -55,7 +51,7 @@ class PLLWC_Admin_WC_Install public function translate_default_wc_pages() { foreach (pll_languages_list() as $lang) { - foreach (array_keys($this->pages[ $lang ]) as $key) { + foreach (array_keys($this->pages[$lang]) as $key) { $this->translate_page($key, $lang); } } @@ -68,6 +64,7 @@ class PLLWC_Admin_WC_Install * * @param string[] $post_states List of post display states. * @param WP_Post $post The post object. + * * @return string[] */ public function display_post_states($post_states, $post) @@ -101,6 +98,7 @@ class PLLWC_Admin_WC_Install * @since 0.1 * * @param array $tools List of available tools. + * * @return array */ public function debug_tools($tools) @@ -111,10 +109,10 @@ class PLLWC_Admin_WC_Install return $tools; } - $end = array_slice($tools, $n + 1); + $end = array_slice($tools, $n + 1); $tools = array_slice($tools, 0, $n); - $tools['pll_install_pages'] = array( + $tools['pll_install_pages'] = [ 'name' => __('Install WooCommerce pages', 'polylang-wc'), 'button' => __('Install pages', 'polylang-wc'), 'desc' => sprintf( @@ -122,8 +120,8 @@ class PLLWC_Admin_WC_Install __('Note:', 'polylang-wc'), __('This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'polylang-wc') ), - 'callback' => array( $this, 'install_pages' ), - ); + 'callback' => [$this, 'install_pages'], + ]; return array_merge($tools, $end); } @@ -142,7 +140,7 @@ class PLLWC_Admin_WC_Install public function init_translated_pages() { /** @var PLL_Language $language */ - foreach (pll_languages_list(array( 'fields' => '' )) as $language) { + foreach (pll_languages_list(['fields' => '']) as $language) { // Load all text domains in the new language. switch_to_locale($language->locale); @@ -150,30 +148,30 @@ class PLLWC_Admin_WC_Install * Partly copy paste of WC_Install::create_pages that we can't use it directly * because Woocommerce checks for the unicity of each page. */ - $this->pages[ $language->slug ] = apply_filters( + $this->pages[$language->slug] = apply_filters( 'woocommerce_create_pages', - array( - 'shop' => array( + [ + 'shop' => [ 'name' => _x('shop', 'Page slug', 'polylang-wc'), 'title' => _x('Shop', 'Page title', 'polylang-wc'), 'content' => '', - ), - 'cart' => array( + ], + 'cart' => [ 'name' => _x('cart', 'Page slug', 'polylang-wc'), 'title' => _x('Cart', 'Page title', 'polylang-wc'), - 'content' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']', - ), - 'checkout' => array( + 'content' => '['.apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart').']', + ], + 'checkout' => [ 'name' => _x('checkout', 'Page slug', 'polylang-wc'), 'title' => _x('Checkout', 'Page title', 'polylang-wc'), - 'content' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']', - ), - 'myaccount' => array( + 'content' => '['.apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout').']', + ], + 'myaccount' => [ 'name' => _x('my-account', 'Page slug', 'polylang-wc'), 'title' => _x('My account', 'Page title', 'polylang-wc'), - 'content' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']', - ), - ) + 'content' => '['.apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account').']', + ], + ] ); } @@ -198,9 +196,9 @@ class PLLWC_Admin_WC_Install $default_language = pll_default_language(); // In case pages were installed before Polylang, the pages may have no language. We must assign one. - foreach (array_keys($this->pages[ $default_language ]) as $key) { + foreach (array_keys($this->pages[$default_language]) as $key) { $post_id = wc_get_page_id($key); - if (! pll_get_post_language($post_id)) { + if (!pll_get_post_language($post_id)) { pll_set_post_language($post_id, (string) $default_language); } } @@ -218,6 +216,7 @@ class PLLWC_Admin_WC_Install * * @param string $page WooCommerce Page slug. * @param string $lang Language slug. + * * @return void */ public function translate_page($page, $lang) @@ -232,14 +231,14 @@ class PLLWC_Admin_WC_Install $translations = pll_get_post_translations($post_id); // Create the translation only if it doesn't exist yet. - if (! empty($translations[ $lang ])) { + if (!empty($translations[$lang])) { return; } $post = get_post($post_id, ARRAY_A); unset($post['ID']); // FIXME post parent? - $post['post_title'] = $this->pages[ $lang ][ $page ]['title']; + $post['post_title'] = $this->pages[$lang][$page]['title']; $post['post_status'] = 'draft'; // Keep it draft before we set the language, to correctly handle auto added pages to menu. $tr_id = wp_insert_post(wp_slash($post)); @@ -249,7 +248,7 @@ class PLLWC_Admin_WC_Install // Assign the language and translations. pll_set_post_language($tr_id, $lang); - $translations[ $lang ] = $tr_id; + $translations[$lang] = $tr_id; pll_save_post_translations($translations); $tr_post = get_post($tr_id); @@ -262,7 +261,7 @@ class PLLWC_Admin_WC_Install * We can now publish the page which will also add it to menus if auto add pages to menu is checked * and attempt to share the slug if needed ( to do after the language has been set ). */ - $tr_post->post_name = $this->pages[ $lang ][ $page ]['name']; + $tr_post->post_name = $this->pages[$lang][$page]['name']; $tr_post->post_status = 'publish'; wp_update_post($tr_post); } @@ -273,13 +272,14 @@ class PLLWC_Admin_WC_Install * @since 0.9.3 * * @param string $lang Language code. + * * @return void */ protected static function create_default_product_cat($lang) { $default = get_option('default_product_cat'); - if (empty($default) || ! is_numeric($default)) { + if (empty($default) || !is_numeric($default)) { return; } @@ -290,8 +290,8 @@ class PLLWC_Admin_WC_Install } $name = _x('Uncategorized', 'Default category slug', 'polylang-wc'); - $slug = sanitize_title($name . '-' . $lang); - $cat = wp_insert_term($name, 'product_cat', array( 'slug' => $slug )); + $slug = sanitize_title($name.'-'.$lang); + $cat = wp_insert_term($name, 'product_cat', ['slug' => $slug]); // Bail in case of database error, but continue if we got a term. if (is_wp_error($cat) && array_key_exists('term_exists', $cat->errors) && isset($cat->error_data['term_exists'])) { @@ -307,7 +307,7 @@ class PLLWC_Admin_WC_Install // Assign the language and translations. pll_set_term_language((int) $cat_id, $lang); $translations = pll_get_term_translations($default); - $translations[ $lang ] = $cat_id; + $translations[$lang] = $cat_id; pll_save_term_translations($translations); } @@ -317,13 +317,14 @@ class PLLWC_Admin_WC_Install * @since 0.9.3 * * @param array $args New language arguments. + * * @return void */ public function add_language($args) { $default = get_option('default_product_cat'); - if (empty($default) || ! is_numeric($default)) { + if (empty($default) || !is_numeric($default)) { return; } @@ -351,7 +352,7 @@ class PLLWC_Admin_WC_Install { $default = get_option('default_product_cat'); - if (empty($default) || ! is_numeric($default)) { + if (empty($default) || !is_numeric($default)) { return; } @@ -365,7 +366,7 @@ class PLLWC_Admin_WC_Install } foreach (pll_languages_list() as $language) { - if ($language !== $default_cat_lang && ! pll_get_term($default, $language)) { + if ($language !== $default_cat_lang && !pll_get_term($default, $language)) { self::create_default_product_cat($language); } } @@ -384,13 +385,13 @@ class PLLWC_Admin_WC_Install $default = get_option('default_product_cat'); - if (empty($default) || ! is_numeric($default)) { + if (empty($default) || !is_numeric($default)) { return; } $default_category = get_term((int) $default, 'product_cat'); - if (! $default_category instanceof WP_Term) { + if (!$default_category instanceof WP_Term) { return; } @@ -407,7 +408,7 @@ class PLLWC_Admin_WC_Install $tr_cat = get_term($tr_cat, 'product_cat'); - if (! $tr_cat instanceof WP_Term) { + if (!$tr_cat instanceof WP_Term) { continue; } @@ -437,6 +438,7 @@ class PLLWC_Admin_WC_Install * * @param string $option Option name. * @param string $value WooCommerce DB version. + * * @return void */ public static function update_330_wc_db_version($option, $value) diff --git a/__plugins/polylang-wc/src/admin/admin.php b/__plugins/polylang-wc/src/admin/admin.php index 0596235ec67ab03901596f0ab0f647004b897cda..2dd9a841b5f19319d1672e1a95fc8d803b433c6c 100644 --- a/__plugins/polylang-wc/src/admin/admin.php +++ b/__plugins/polylang-wc/src/admin/admin.php @@ -1,9 +1,5 @@ curlang)) { + if (!empty(PLL()->curlang)) { return PLL()->curlang->slug; } // Or the current locale (admin language). $curlang = PLL()->model->get_language(get_user_locale()); - if (! empty($curlang)) { + if (!empty($curlang)) { return $curlang->slug; } diff --git a/__plugins/polylang-wc/src/admin/wizard.php b/__plugins/polylang-wc/src/admin/wizard.php index 23c14fc8b5649cecebc800053cd111d64b17b682..a3c07ce0a8cc9b87fc970e29e8b8e18a28fa746a 100644 --- a/__plugins/polylang-wc/src/admin/wizard.php +++ b/__plugins/polylang-wc/src/admin/wizard.php @@ -1,9 +1,5 @@ model = $model; + $this->model = $model; $this->wizard = $wizard; // Add the WooCommerce specific step in the Wizard at the right place. - add_filter('pll_wizard_steps', array( $this, 'add_step_wc_pages' ), 600); + add_filter('pll_wizard_steps', [$this, 'add_step_wc_pages'], 600); } /** @@ -55,22 +51,24 @@ class PLLWC_Wizard * @since 1.4 * * @param array $steps List of steps. + * * @return array List of steps updated. */ public function add_step_wc_pages($steps) { $this->translation_updates = $this->get_translation_updates(); - wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION); + wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url().'/assets/css/admin.css', [], WC_VERSION); // See Polylang PLL_Wizard::steps property documentation https://github.com/polylang/polylang/blob/2.8.2/modules/wizard/wizard.php#L26 . - $steps['wc-pages'] = array( + $steps['wc-pages'] = [ 'name' => 'WooCommerce', - 'view' => array( $this, 'display_step_wc_pages' ), - 'handler' => array( $this, 'save_step_wc_pages' ), - 'scripts' => array(), - 'styles' => array( 'woocommerce_admin_styles' ), - ); + 'view' => [$this, 'display_step_wc_pages'], + 'handler' => [$this, 'save_step_wc_pages'], + 'scripts' => [], + 'styles' => ['woocommerce_admin_styles'], + ]; + return $steps; } @@ -83,9 +81,9 @@ class PLLWC_Wizard */ public function display_step_wc_pages() { - $model = $this->model; + $model = $this->model; $translation_updates = $this->translation_updates; - include __DIR__ . '/view-wizard-step-wc-pages.php'; + include __DIR__.'/view-wizard-step-wc-pages.php'; } /** @@ -102,11 +100,11 @@ class PLLWC_Wizard $translation_updates = $this->get_translation_updates(); if (count($translation_updates) > 0) { - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php'; - $url = sanitize_url($this->wizard->get_next_step_link()); - $nonce = 'pll-wizard'; - $title = esc_html__('Update translations', 'polylang-wc'); + $url = sanitize_url($this->wizard->get_next_step_link()); + $nonce = 'pll-wizard'; + $title = esc_html__('Update translations', 'polylang-wc'); $context = WP_LANG_DIR; $upgrader = new Language_Pack_Upgrader(new Automatic_Upgrader_Skin(compact('url', 'nonce', 'title', 'context'))); @@ -133,24 +131,25 @@ class PLLWC_Wizard */ public function get_translation_updates() { - add_filter('site_transient_update_plugins', array( $this, 'update_last_checked' )); + add_filter('site_transient_update_plugins', [$this, 'update_last_checked']); wp_update_plugins(); // To ensure the transient is updated recently. - remove_filter('site_transient_update_plugins', array( $this, 'update_last_checked' )); + remove_filter('site_transient_update_plugins', [$this, 'update_last_checked']); - $translations = array(); - $transient = get_site_transient('update_plugins'); + $translations = []; + $transient = get_site_transient('update_plugins'); - if (! is_object($transient) || empty($transient->translations)) { + if (!is_object($transient) || empty($transient->translations)) { return $translations; } foreach ($transient->translations as $translation) { // Remove plugin translation update which is not necessary yet. - if (! in_array($translation['slug'], self::PLUGIN_FILTER)) { + if (!in_array($translation['slug'], self::PLUGIN_FILTER)) { continue; } $translations[] = (object) $translation; } + return $translations; } @@ -160,12 +159,14 @@ class PLLWC_Wizard * @since 1.4 * * @param StdClass $updates Transient value of plugins which need to be updated. + * * @return StdClass Filtered value of the transient. */ public function update_last_checked($updates) { // Unset to always search for the translations updates. See `wp_update_plugins()`. unset($updates->last_checked); + return $updates; } } diff --git a/__plugins/polylang-wc/src/countries.php b/__plugins/polylang-wc/src/countries.php index d9928b53418918955f55da17d827ce84f6a0a35c..5c6bb30ab5db989246ab66670c810f803888bc63 100644 --- a/__plugins/polylang-wc/src/countries.php +++ b/__plugins/polylang-wc/src/countries.php @@ -1,9 +1,5 @@ curlang instanceof PLL_Language) { // Do not hit the cache if current language is not defined yet. + if (!PLL()->curlang instanceof PLL_Language) { // Do not hit the cache if current language is not defined yet. return $this->read_countries(); } @@ -53,7 +49,7 @@ class PLLWC_Countries extends WC_Countries private function read_countries() { /** This filter is documented in woocommerce/include/class-wc-countries.php */ - $countries = apply_filters('woocommerce_countries', include WC()->plugin_path() . '/i18n/countries.php'); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomFunction + $countries = apply_filters('woocommerce_countries', include WC()->plugin_path().'/i18n/countries.php'); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomFunction if (apply_filters('woocommerce_sort_countries', true)) { wc_asort_by_locale($countries); } diff --git a/__plugins/polylang-wc/src/coupons.php b/__plugins/polylang-wc/src/coupons.php index 622f3f06e01be31d6a975fdc250b632031ae8144..15f5c3e837d18a4cacc5f742ba0c403ea2cf023d 100644 --- a/__plugins/polylang-wc/src/coupons.php +++ b/__plugins/polylang-wc/src/coupons.php @@ -1,9 +1,5 @@ data_store = PLLWC_Data_Store::load('product_language'); - add_action('woocommerce_coupon_loaded', array( $this, 'coupon_loaded' )); + add_action('woocommerce_coupon_loaded', [$this, 'coupon_loaded']); } /** @@ -36,16 +32,17 @@ class PLLWC_Coupons * @since 0.3.6 * * @param WC_Coupon $data Coupon properties. + * * @return void */ public function coupon_loaded($data) { // Test pll_current_language() not to break the Coupons admin page when the admin language filter shows all languages. if (pll_current_language()) { - $data->set_product_ids(array_map(array( $this, 'maybe_get_translated_product' ), $data->get_product_ids())); - $data->set_excluded_product_ids(array_map(array( $this, 'maybe_get_translated_product' ), $data->get_excluded_product_ids())); - $data->set_product_categories(array_map(array( $this, 'maybe_get_translated_term' ), $data->get_product_categories())); - $data->set_excluded_product_categories(array_map(array( $this, 'maybe_get_translated_term' ), $data->get_excluded_product_categories())); + $data->set_product_ids(array_map([$this, 'maybe_get_translated_product'], $data->get_product_ids())); + $data->set_excluded_product_ids(array_map([$this, 'maybe_get_translated_product'], $data->get_excluded_product_ids())); + $data->set_product_categories(array_map([$this, 'maybe_get_translated_term'], $data->get_product_categories())); + $data->set_excluded_product_categories(array_map([$this, 'maybe_get_translated_term'], $data->get_excluded_product_categories())); } } @@ -55,11 +52,13 @@ class PLLWC_Coupons * @since 1.0 * * @param int $id Product id. + * * @return int Translated product id. */ protected function maybe_get_translated_product($id) { $tr_id = $this->data_store->get($id); + return $tr_id ? $tr_id : $id; } @@ -69,11 +68,13 @@ class PLLWC_Coupons * @since 1.0 * * @param int $id Term id. + * * @return int Translated term id. */ protected function maybe_get_translated_term($id) { $tr_id = pll_get_term($id); + return $tr_id ? $tr_id : $id; } } diff --git a/__plugins/polylang-wc/src/data-store.php b/__plugins/polylang-wc/src/data-store.php index 25df217deec149697e7b28dc09cf8cb5470de4c0..1d83d0f66feb342b00addb96ab19bbb28e119108 100644 --- a/__plugins/polylang-wc/src/data-store.php +++ b/__plugins/polylang-wc/src/data-store.php @@ -1,9 +1,5 @@ */ - private static $stores = array( + private static $stores = [ 'order_language' => 'PLLWC_Order_Language_CPT', 'product_language' => 'PLLWC_Product_Language_CPT', - ); + ]; /** * Loads a data store. * * @since 1.0 * + * @param 'order_language'|'product_language' $object_type Identifier for the data store. + * * @throws Exception If the data store doesn't exist. * - * @param 'order_language'|'product_language' $object_type Identifier for the data store. * @return PLLWC_Order_Language_CPT|PLLWC_Product_Language_CPT - * PLLWC_Order_Language_CPT if $object_type is 'order_language', - * PLLWC_Product_Language_CPT if $object_type is 'product_language'. + * PLLWC_Order_Language_CPT if $object_type is 'order_language', + * PLLWC_Product_Language_CPT if $object_type is 'product_language'. + * * @phpstan-return ($object_type is 'order_language' ? PLLWC_Order_Language_CPT : PLLWC_Product_Language_CPT) */ public static function load($object_type) @@ -50,7 +48,7 @@ class PLLWC_Data_Store self::$stores = apply_filters('pllwc_data_stores', self::$stores); /** @var class-string */ - $store = self::$stores[ $object_type ]; + $store = self::$stores[$object_type]; if (class_exists($store)) { /** @var PLLWC_Order_Language_CPT|PLLWC_Product_Language_CPT */ diff --git a/__plugins/polylang-wc/src/emails.php b/__plugins/polylang-wc/src/emails.php index 9eb73fa2b5b23f3c9a26278579157dfedee5b267..b90f66cd503cb6f722496cb34b01ac379a1cbb9b 100644 --- a/__plugins/polylang-wc/src/emails.php +++ b/__plugins/polylang-wc/src/emails.php @@ -1,9 +1,5 @@ */ - private $previous_languages = array(); + private $previous_languages = []; /** * Constructor. @@ -41,29 +37,29 @@ class PLLWC_Emails { $this->data_store = PLLWC_Data_Store::load('order_language'); - add_action('change_locale', array( $this, 'change_locale' ), 1); // Soon to load the plugin_locale filter. + add_action('change_locale', [$this, 'change_locale'], 1); // Soon to load the plugin_locale filter. // Deactivate the email locale switch from WooCommerce. add_filter('woocommerce_email_setup_locale', '__return_false'); add_filter('woocommerce_email_restore_locale', '__return_false'); // Define the customer preferred language. - add_action('woocommerce_created_customer', array( $this, 'created_customer' ), 5); // Before WC sends the notification. - add_action('woocommerce_new_order', array( $this, 'new_order' )); + add_action('woocommerce_created_customer', [$this, 'created_customer'], 5); // Before WC sends the notification. + add_action('woocommerce_new_order', [$this, 'new_order']); // Manually sent order emails from order action metabox. - add_action('woocommerce_before_resend_order_emails', array( $this, 'resend_order_email' ), 10, 2); - add_action('woocommerce_after_resend_order_email', array( $this, 'after_email' )); + add_action('woocommerce_before_resend_order_emails', [$this, 'resend_order_email'], 10, 2); + add_action('woocommerce_after_resend_order_email', [$this, 'after_email']); // Translate site title. - add_filter('woocommerce_email_format_string_replace', array( $this, 'format_string_replace' ), 10, 2); + add_filter('woocommerce_email_format_string_replace', [$this, 'format_string_replace'], 10, 2); // Delays the the addition of other actions after WC_Emails init. - add_action('woocommerce_email', array( $this, 'mailer_init' )); + add_action('woocommerce_email', [$this, 'mailer_init']); if (is_user_logged_in()) { // Sets the email language for previewed emails in the admin. Useful when displaying and sending the previewed emails. - add_filter('woocommerce_prepare_email_for_preview', array( $this, 'set_previewed_email_language' )); + add_filter('woocommerce_prepare_email_for_preview', [$this, 'set_previewed_email_language']); } } @@ -74,6 +70,7 @@ class PLLWC_Emails * @since 2.2 * * @param WC_Email $email The email object. Unused. + * * @return WC_Email */ public function set_previewed_email_language($email) @@ -89,7 +86,6 @@ class PLLWC_Emails return $email; } - /** * Setups actions related to automatically sent emails. * @@ -99,6 +95,7 @@ class PLLWC_Emails * @since 1.6.3 * * @param WC_Emails $mailer The WooCommerce emails controller. + * * @return void */ public function mailer_init($mailer) @@ -137,15 +134,15 @@ class PLLWC_Emails */ $actions = apply_filters( 'pllwc_user_email_actions', - array( + [ 'woocommerce_created_customer_notification', // Customer new account. 'woocommerce_reset_password_notification', // Reset password. - ) + ] ); foreach ($actions as $action) { - add_action($action, array( $this, 'before_user_email' ), 1); // Switch the language for the email. - add_action($action, array( $this, 'after_email' ), 999); // Switch the language back after the email has been sent. + add_action($action, [$this, 'before_user_email'], 1); // Switch the language for the email. + add_action($action, [$this, 'after_email'], 999); // Switch the language back after the email has been sent. } } @@ -168,7 +165,7 @@ class PLLWC_Emails */ $actions = apply_filters( 'pllwc_order_email_actions', - array( + [ // Completed order. 'woocommerce_order_status_completed_notification', // Customer note. @@ -185,12 +182,12 @@ class PLLWC_Emails // Refunded order. 'woocommerce_order_fully_refunded_notification', 'woocommerce_order_partially_refunded_notification', - ) + ] ); foreach ($actions as $action) { - add_action($action, array( $this, 'before_order_email' ), 1); // Switch the language for the email. - add_action($action, array( $this, 'after_email' ), 999); // Switch the language back after the email has been sent. + add_action($action, [$this, 'before_order_email'], 1); // Switch the language for the email. + add_action($action, [$this, 'after_email'], 999); // Switch the language back after the email has been sent. } } @@ -200,6 +197,7 @@ class PLLWC_Emails * @since 1.7 * * @param WC_Emails $mailer The WooCommerce emails controller. + * * @return void */ protected function shop_manager_emails_init($mailer) @@ -209,23 +207,23 @@ class PLLWC_Emails } // Define email types and their corresponding actions. - $email_config = array( - 'WC_Email_Cancelled_Order' => array( - 'actions' => array( // Cancelled order emails sent to shop managers. + $email_config = [ + 'WC_Email_Cancelled_Order' => [ + 'actions' => [ // Cancelled order emails sent to shop managers. 'woocommerce_order_status_processing_to_cancelled_notification', 'woocommerce_order_status_on-hold_to_cancelled_notification', - ), + ], 'callback' => 'send_cancelled_order_email', - ), - 'WC_Email_Failed_Order' => array( - 'actions' => array( // Failed order emails sent to shop managers. + ], + 'WC_Email_Failed_Order' => [ + 'actions' => [ // Failed order emails sent to shop managers. 'woocommerce_order_status_pending_to_failed_notification', 'woocommerce_order_status_on-hold_to_failed_notification', - ), + ], 'callback' => 'send_failed_order_email', - ), - 'WC_Email_New_Order' => array( - 'actions' => array( // New order emails sent to shop managers. + ], + 'WC_Email_New_Order' => [ + 'actions' => [ // New order emails sent to shop managers. 'woocommerce_order_status_pending_to_processing_notification', 'woocommerce_order_status_pending_to_completed_notification', 'woocommerce_order_status_pending_to_on-hold_notification', @@ -235,21 +233,21 @@ class PLLWC_Emails 'woocommerce_order_status_cancelled_to_processing_notification', 'woocommerce_order_status_cancelled_to_completed_notification', 'woocommerce_order_status_cancelled_to_on-hold_notification', - ), + ], 'callback' => 'send_new_order_email', - ), - ); + ], + ]; // Process each email type. foreach ($email_config as $email_class => $config) { - if (! isset($mailer->emails[ $email_class ])) { + if (!isset($mailer->emails[$email_class])) { continue; } - $email = $mailer->emails[ $email_class ]; + $email = $mailer->emails[$email_class]; foreach ($config['actions'] as $action) { - remove_action($action, array( $email, 'trigger' )); - add_action($action, array( $this, $config['callback'] )); + remove_action($action, [$email, 'trigger']); + add_action($action, [$this, $config['callback']]); } } } @@ -261,6 +259,7 @@ class PLLWC_Emails * @since 0.1 * * @param int $user_id User ID. + * * @return void */ public function created_customer($user_id) @@ -276,6 +275,7 @@ class PLLWC_Emails * @since 1.0 * * @param int $order_id Order ID. + * * @return void */ public function new_order($order_id) @@ -286,8 +286,8 @@ class PLLWC_Emails $user_id = $order->get_user_id(); if ($user_id) { $order_locale = $this->data_store->get_language($order_id, 'locale'); - $user_locale = get_user_meta($user_id, 'locale', true); - if (! empty($order_locale) && $order_locale !== $user_locale) { + $user_locale = get_user_meta($user_id, 'locale', true); + if (!empty($order_locale) && $order_locale !== $user_locale) { update_user_meta($user_id, 'locale', $order_locale); } } @@ -307,15 +307,15 @@ class PLLWC_Emails { if (is_locale_switched()) { if (isset(PLL()->filters)) { - remove_filter('locale', array( PLL()->filters, 'get_locale' )); - remove_filter('load_textdomain_mofile', array( PLL()->filters, 'load_textdomain_mofile' )); + remove_filter('locale', [PLL()->filters, 'get_locale']); + remove_filter('load_textdomain_mofile', [PLL()->filters, 'load_textdomain_mofile']); } - add_filter('get_user_metadata', array( $this, 'filter_user_locale' ), 10, 3); + add_filter('get_user_metadata', [$this, 'filter_user_locale'], 10, 3); } else { if (PLL() instanceof PLL_Frontend && isset(PLL()->filters)) { - add_filter('locale', array( PLL()->filters, 'get_locale' )); + add_filter('locale', [PLL()->filters, 'get_locale']); } - remove_filter('get_user_metadata', array( $this, 'filter_user_locale' )); + remove_filter('get_user_metadata', [$this, 'filter_user_locale']); } if (version_compare($GLOBALS['wp_version'], '6.7-beta', '<') && method_exists(WC(), 'load_plugin_textdomain')) { @@ -330,20 +330,21 @@ class PLLWC_Emails * @since 0.1 * * @param PLL_Language $language An instance of PLL_Language. + * * @return void */ public function set_email_language($language) { - $this->previous_languages[] = array( + $this->previous_languages[] = [ 'switched' => switch_to_locale($language->locale), 'language' => empty(PLL()->curlang) ? null : PLL()->curlang, - ); + ]; PLL()->curlang = $language; PLLWC_Filter_WC_Pages::init(); - if (! is_locale_switched()) { + if (!is_locale_switched()) { PLL()->load_strings_translations($language->get_locale()); } @@ -362,6 +363,7 @@ class PLLWC_Emails * @since 0.1 * * @param int|array|WC_Order $order Order or order ID. + * * @return void */ public function before_order_email($order) @@ -374,7 +376,7 @@ class PLLWC_Emails $order_id = $order->get_id(); } - if (! empty($order_id)) { + if (!empty($order_id)) { $lang = $this->data_store->get_language($order_id); $language = PLL()->model->get_language($lang); if ($language) { @@ -390,6 +392,7 @@ class PLLWC_Emails * @since 0.1 * * @param int|string $user User ID or user login. + * * @return void */ public function before_user_email($user) @@ -444,19 +447,21 @@ class PLLWC_Emails * * @param string[] $replace Array of strings to replace placeholders in emails. * @param WC_Email $email Instance of WC_Email. + * * @return string[] */ public function format_string_replace($replace, $email) { - $replace['blogname'] = $email->get_blogname(); + $replace['blogname'] = $email->get_blogname(); $replace['site-title'] = $email->get_blogname(); // Ensures the date format is used in the correct language for previewed emails. if ($email->object instanceof WC_Order) { $order_date = $email->object->get_date_created(); - if (! empty($order_date)) { + if (!empty($order_date)) { $replace['order-date'] = wc_format_datetime($order_date); } } + return $replace; } @@ -468,6 +473,7 @@ class PLLWC_Emails * @param mixed $value The value get_metadata() should return. * @param int $user_id User ID. * @param string $meta_key Meta key. + * * @return mixed The meta value. */ public function filter_user_locale($value, $user_id, $meta_key) @@ -481,6 +487,7 @@ class PLLWC_Emails * @nince 1.6 * * @param string $email Email. + * * @return PLL_Language The language of the user having this email, the default language if not found. */ protected function get_language_by_email($email) @@ -507,6 +514,7 @@ class PLLWC_Emails * * @param WC_Email $email WooCommerce Email Class. * @param int $order_id Order id. + * * @return void */ protected function send_order_email($email, $order_id) @@ -514,14 +522,14 @@ class PLLWC_Emails if (method_exists($email, 'trigger')) { $recipients = $this->get_recipients($email); - remove_filter('get_user_metadata', array( $this, 'filter_user_locale' )); + remove_filter('get_user_metadata', [$this, 'filter_user_locale']); - $emails_by_language = array(); + $emails_by_language = []; foreach ($recipients as $recipient) { $language = $this->get_language_by_email($recipient); - $emails_by_language[ $language->slug ]['language'] = $language; - $emails_by_language[ $language->slug ]['recipients'][] = $recipient; + $emails_by_language[$language->slug]['language'] = $language; + $emails_by_language[$language->slug]['recipients'][] = $recipient; } foreach ($emails_by_language as $em) { @@ -539,6 +547,7 @@ class PLLWC_Emails * @since 1.6 * * @param int $order_id Order id. + * * @return void */ public function send_cancelled_order_email($order_id) @@ -552,6 +561,7 @@ class PLLWC_Emails * @since 1.6 * * @param int $order_id Order id. + * * @return void */ public function send_failed_order_email($order_id) @@ -565,6 +575,7 @@ class PLLWC_Emails * @since 1.6 * * @param int $order_id Order id. + * * @return void */ public function send_new_order_email($order_id) @@ -580,6 +591,7 @@ class PLLWC_Emails * * @param WC_Order $order Order. * @param string $action Order action. + * * @return void */ public function resend_order_email($order, $action) @@ -598,6 +610,7 @@ class PLLWC_Emails * @since 1.8 * * @param WC_Email $email Email object. + * * @return string[] Array of recipients for the email. */ protected function get_recipients($email) @@ -605,6 +618,7 @@ class PLLWC_Emails $recipients = $email->get_option('recipient', get_option('admin_email')); $recipients = explode(',', $recipients); $recipients = array_map('trim', $recipients); + return array_filter($recipients); } } diff --git a/__plugins/polylang-wc/src/export.php b/__plugins/polylang-wc/src/export.php index 6656a3ec7da7afbe8b405d592815bd2c7662a269..d344d35e55e548b054885ebff179e46cdbd97434 100644 --- a/__plugins/polylang-wc/src/export.php +++ b/__plugins/polylang-wc/src/export.php @@ -1,9 +1,5 @@ __('Language', 'polylang-wc'), 'translations' => __('Translation group', 'polylang-wc'), - ) + ] ); } @@ -51,6 +48,7 @@ class PLLWC_Product_Export * * @param array $row Data exported in a CSV row. * @param WC_Product $product Product. + * * @return array */ public function row_data($row, $product) diff --git a/__plugins/polylang-wc/src/filter-wc-pages.php b/__plugins/polylang-wc/src/filter-wc-pages.php index db6d6f6ac3678391ceb2f887cd3c4df51101b7ae..4d4889c643b52435f94e856896c36deeafb4f523 100644 --- a/__plugins/polylang-wc/src/filter-wc-pages.php +++ b/__plugins/polylang-wc/src/filter-wc-pages.php @@ -1,9 +1,5 @@ query_vars; // Customers should see all their orders whatever the language. - if (! isset($qvars['lang']) && (isset($qvars['post_type']) && ('shop_order' === $qvars['post_type'] || (is_array($qvars['post_type']) && in_array('shop_order', $qvars['post_type']))))) { + if (!isset($qvars['lang']) && (isset($qvars['post_type']) && ('shop_order' === $qvars['post_type'] || (is_array($qvars['post_type']) && in_array('shop_order', $qvars['post_type']))))) { $query->set('lang', ''); } } @@ -97,6 +96,7 @@ class PLLWC_Frontend_Account * @param string $item_name Product name. * @param WC_Order_Item_Product $item Order item. * @param bool $is_visible Whether the product is visible. + * * @return string Translated product name. */ public function order_item_name($item_name, $item, $is_visible) @@ -104,7 +104,7 @@ class PLLWC_Frontend_Account $data_store = PLLWC_Data_Store::load('product_language'); $product_id = $item->get_variation_id(); - if (! $product_id) { + if (!$product_id) { $product_id = $item->get_product_id(); } @@ -129,18 +129,20 @@ class PLLWC_Frontend_Account * * @param string[][] $rows Order item totals. * @param WC_Order $order Order. + * * @return string[][] */ public function translate_payment_method($rows, $order) { if (method_exists($order, 'get_payment_method')) { $payment_method = $order->get_payment_method(); - $gateways = WC_Payment_Gateways::instance()->payment_gateways(); - if (isset($gateways[ $payment_method ]) && ! empty($rows['payment_method'])) { + $gateways = WC_Payment_Gateways::instance()->payment_gateways(); + if (isset($gateways[$payment_method]) && !empty($rows['payment_method'])) { // Check $rows['payment_method'] for an issue (where the payment method was not set) introduced in WC 7.7.0 and fixed in 7.8 {@see https://github.com/polylang/polylang-wc/issues/629}. - $rows['payment_method']['value'] = $gateways[ $payment_method ]->get_title(); + $rows['payment_method']['value'] = $gateways[$payment_method]->get_title(); } } + return $rows; } } diff --git a/__plugins/polylang-wc/src/frontend/frontend-cart.php b/__plugins/polylang-wc/src/frontend/frontend-cart.php index fd2c91e1aa5a85213374d47c1190fabba100fe5e..7e6950048bd39e803360b876a0e42bbf0ebacee0 100644 --- a/__plugins/polylang-wc/src/frontend/frontend-cart.php +++ b/__plugins/polylang-wc/src/frontend/frontend-cart.php @@ -1,9 +1,5 @@ init(); } else { - add_action('pll_language_defined', array( $this, 'init' ), 1); - add_filter('option_woocommerce_cart_page_id', array( $this, 'translate_add_to_cart_page_id' )); + add_action('pll_language_defined', [$this, 'init'], 1); + add_filter('option_woocommerce_cart_page_id', [$this, 'translate_add_to_cart_page_id']); } if ($this->enable_cart_translation) { $this->data_store = PLLWC_Data_Store::load('product_language'); - add_filter('pll_set_language_from_query', array( $this, 'pll_set_language_from_query' ), 5); // Before Polylang. + add_filter('pll_set_language_from_query', [$this, 'pll_set_language_from_query'], 5); // Before Polylang. - add_filter('woocommerce_cart_hash', array( $this, 'cart_hash' ), 10, 2); // Hash should be language independent. - add_filter('woocommerce_cart_item_data_to_validate', array( $this, 'cart_item_data_to_validate' ), 10, 2); // Since WC 3.4. - add_filter('woocommerce_add_to_cart_product_id', array( $this, 'translate_product_id_added_to_cart' )); + add_filter('woocommerce_cart_hash', [$this, 'cart_hash'], 10, 2); // Hash should be language independent. + add_filter('woocommerce_cart_item_data_to_validate', [$this, 'cart_item_data_to_validate'], 10, 2); // Since WC 3.4. + add_filter('woocommerce_add_to_cart_product_id', [$this, 'translate_product_id_added_to_cart']); } } @@ -80,13 +76,13 @@ class PLLWC_Frontend_Cart * Resets the cart when switching the language, even when the cart translation is disabled, * to translate the mini cart the theme. */ - if (isset($_COOKIE[ PLL_COOKIE ]) && pll_current_language() !== $_COOKIE[ PLL_COOKIE ]) { - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' )); // After WooCommerce load_scripts(). + if (isset($_COOKIE[PLL_COOKIE]) && pll_current_language() !== $_COOKIE[PLL_COOKIE]) { + add_action('wp_enqueue_scripts', [$this, 'wp_enqueue_scripts']); // After WooCommerce load_scripts(). } if ($this->enable_cart_translation) { // Translates the products in the cart. - add_action('woocommerce_cart_loaded_from_session', array( $this, 'woocommerce_cart_loaded_from_session' )); + add_action('woocommerce_cart_loaded_from_session', [$this, 'woocommerce_cart_loaded_from_session']); } } @@ -96,11 +92,12 @@ class PLLWC_Frontend_Cart * @since 0.3.2 * * @param PLL_Language|false $lang False or language object. + * * @return PLL_Language|false */ public function pll_set_language_from_query($lang) { - if (! PLL()->options['force_lang']) { + if (!PLL()->options['force_lang']) { if (did_action('pll_language_defined')) { /* * Handle a specific case for the Site home (when the language code is hidden for the default language). @@ -108,7 +105,7 @@ class PLLWC_Frontend_Cart */ WC()->cart->get_cart_from_session(); } else { - add_action('pll_language_defined', array( WC()->cart, 'get_cart_from_session' )); + add_action('pll_language_defined', [WC()->cart, 'get_cart_from_session']); } } @@ -127,8 +124,8 @@ class PLLWC_Frontend_Cart // Reset shipping methods (required since WC 2.6). WC()->shipping()->calculate_shipping(WC()->cart->get_shipping_packages()); - $cart_hash_key = apply_filters('woocommerce_cart_hash_key', 'wc_cart_hash_' . md5(get_current_blog_id() . '_' . get_site_url(get_current_blog_id(), '/') . get_template())); - $fragment_name = apply_filters('woocommerce_cart_fragment_name', 'wc_fragments_' . md5(get_current_blog_id() . '_' . get_site_url(get_current_blog_id(), '/') . get_template())); + $cart_hash_key = apply_filters('woocommerce_cart_hash_key', 'wc_cart_hash_'.md5(get_current_blog_id().'_'.get_site_url(get_current_blog_id(), '/').get_template())); + $fragment_name = apply_filters('woocommerce_cart_fragment_name', 'wc_fragments_'.md5(get_current_blog_id().'_'.get_site_url(get_current_blog_id(), '/').get_template())); // Add js to reset the cart. wp_add_inline_script( // Since WP 4.5. @@ -153,7 +150,9 @@ class PLLWC_Frontend_Cart * * @param array $contents Cart contents. * @param PLL_Language|null $lang Language. + * * @return array + * * @phpstan-param array $contents */ protected function translate_cart_contents($contents, ?PLL_Language $lang = null) @@ -161,20 +160,20 @@ class PLLWC_Frontend_Cart $lang ??= pll_current_language(\OBJECT); /** @var PLL_Language|false $lang */ - if (! $lang) { + if (!$lang) { return $contents; } foreach ($contents as $key => $item) { - unset($contents[ $key ]); + unset($contents[$key]); $item = (new Item($item))->translate($lang); - if (! empty($contents[ $item['key'] ])) { + if (!empty($contents[$item['key']])) { // The cart already contains an item in this language. - $item['quantity'] += $contents[ $item['key'] ]['quantity']; + $item['quantity'] += $contents[$item['key']]['quantity']; } - $contents[ $item['key'] ] = $item; + $contents[$item['key']] = $item; /** * Fires after a cart item has been translated. @@ -220,43 +219,47 @@ class PLLWC_Frontend_Cart * * @param string $hash Cart hash. * @param array $cart_session Cart session. + * * @return string Modified cart hash. */ public function cart_hash($hash, $cart_session) { - if (! empty($cart_session)) { + if (!empty($cart_session)) { /** @var PLL_Language $def_lang */ - $def_lang = pll_default_language(\OBJECT); + $def_lang = pll_default_language(\OBJECT); $cart_session = $this->translate_cart_contents($cart_session, $def_lang); // Generate cart session like Woo does, @see{WC_Cart::get_cart_for_session()}. foreach ($cart_session as $key => $item) { - unset($cart_session[ $key ]['data']); + unset($cart_session[$key]['data']); } - $hash = md5(wp_json_encode($cart_session) . WC()->cart->get_total('edit')); + $hash = md5(wp_json_encode($cart_session).WC()->cart->get_total('edit')); } + return $hash; } /** - * Makes the cart item hash language independent by relying on attributes in default language + * Makes the cart item hash language independent by relying on attributes in default language. * * @since 1.0 * * @param array $data Data to validate in the hash. * @param WC_Product $product Product in the cart item. + * * @return array */ public function cart_item_data_to_validate($data, $product) { - if (! empty($data['attributes'])) { + if (!empty($data['attributes'])) { $tr_product_id = $this->data_store->get($product->get_id(), (string) pll_default_language()); - $tr_product = wc_get_product($tr_product_id); + $tr_product = wc_get_product($tr_product_id); if ($tr_product && method_exists($tr_product, 'get_variation_attributes')) { $data['attributes'] = $tr_product->get_variation_attributes(); } } + return $data; } @@ -269,6 +272,7 @@ class PLLWC_Frontend_Cart * @see https://github.com/polylang/polylang-wc/issues/843 * * @param int $product_id A product ID. + * * @return int A product ID. */ public function translate_product_id_added_to_cart($product_id) @@ -288,6 +292,7 @@ class PLLWC_Frontend_Cart * @since 1.6 * * @param int $page_id Cart page id. + * * @return int */ public function translate_add_to_cart_page_id($page_id) @@ -299,9 +304,10 @@ class PLLWC_Frontend_Cart $product_id = absint(wp_unslash($_REQUEST['add-to-cart'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $language = $this->data_store->get_language($product_id); - if (! empty($language)) { + if (!empty($language)) { $page_id = pll_get_post($page_id, $language); } + return $page_id ? $page_id : 0; } } diff --git a/__plugins/polylang-wc/src/frontend/frontend-wc-pages.php b/__plugins/polylang-wc/src/frontend/frontend-wc-pages.php index 77d67107c53366c3346b5fafbf66b691bacac2d6..dced0b8f91d6923a39784881fdbd1ac1bc09aef6 100644 --- a/__plugins/polylang-wc/src/frontend/frontend-wc-pages.php +++ b/__plugins/polylang-wc/src/frontend/frontend-wc-pages.php @@ -1,9 +1,5 @@ query_vars['pagename']) && isset($query->queried_object_id)) { + if (!empty($query->query_vars['pagename']) && isset($query->queried_object_id)) { return $query->queried_object_id; } @@ -52,13 +49,14 @@ class PLLWC_Frontend_WC_Pages * * @param PLL_Language|false $lang False or language object. * @param WP_Query $query WP_Query object. + * * @return PLL_Language|false */ public function pll_set_language_from_query($lang, $query) { - $qvars = $query->query_vars; + $qvars = $query->query_vars; $languages = PLL()->model->get_languages_list(); - $pages = wp_list_pluck($languages, 'page_on_front'); + $pages = wp_list_pluck($languages, 'page_on_front'); // Shop on front. if (in_array(wc_get_page_id('shop'), $pages)) { @@ -69,56 +67,56 @@ class PLLWC_Frontend_WC_Pages && $this->is_front_page($query) ) { $lang = PLL()->model->get_language($qvars['lang']); - $query->is_home = false; - $query->is_tax = false; - $query->is_page = true; + $query->is_home = false; + $query->is_tax = false; + $query->is_page = true; $query->is_post_type_archive = true; $query->set('page_id', $lang->page_on_front); $query->set('post_type', 'product'); unset($query->query_vars['lang']); // Reset queried object. - $query->queried_object = null; + $query->queried_object = null; $query->queried_object_id = 0; } // Set the language when requesting a static front page. elseif (($page_id = $this->get_page_id($query)) && false !== $n = array_search($page_id, $pages)) { - $lang = $languages[ $n ]; - $query->is_home = false; - $query->is_page = true; + $lang = $languages[$n]; + $query->is_home = false; + $query->is_page = true; $query->is_post_type_archive = true; $query->set('page_id', $page_id); $query->set('post_type', 'product'); } // Multiple domains (when the url contains the page slug). - elseif (is_post_type_archive('product') && ! empty(PLL()->curlang)) { + elseif (is_post_type_archive('product') && !empty(PLL()->curlang)) { $query->is_page = true; $query->set('page_id', PLL()->curlang->page_on_front); } // Language set from the content. - elseif (is_post_type_archive('product') && ! empty($qvars['lang']) && $lang = PLL()->model->get_language($qvars['lang'])) { + elseif (is_post_type_archive('product') && !empty($qvars['lang']) && $lang = PLL()->model->get_language($qvars['lang'])) { $query->is_page = true; $query->set('page_id', $lang->page_on_front); } } // My Account and checkout endpoints. - if (array_intersect(array( wc_get_page_id('myaccount'), wc_get_page_id('checkout') ), $pages) && array_intersect(array_keys($query->query), WC()->query->get_query_vars())) { - if (! $this->get_page_id($query)) { - if (empty($qvars['lang']) || ! $lang = PLL()->model->get_language($qvars['lang'])) { + if (array_intersect([wc_get_page_id('myaccount'), wc_get_page_id('checkout')], $pages) && array_intersect(array_keys($query->query), WC()->query->get_query_vars())) { + if (!$this->get_page_id($query)) { + if (empty($qvars['lang']) || !$lang = PLL()->model->get_language($qvars['lang'])) { // Language set from the content + language code hidden in the url. $lang = PLL()->model->get_language(PLL()->options['default_lang']); } - $query->is_home = false; - $query->is_tax = false; - $query->is_archive = false; - $query->is_page = true; + $query->is_home = false; + $query->is_tax = false; + $query->is_archive = false; + $query->is_page = true; $query->is_singular = true; $query->set('page_id', $lang->page_on_front); // Reset queried object. - $query->queried_object = null; + $query->queried_object = null; $query->queried_object_id = 0; } add_filter('redirect_canonical', '__return_false'); @@ -135,10 +133,10 @@ class PLLWC_Frontend_WC_Pages * (`rating_filter` comes from WC's widget "Products by Rating list"). * * @see WC_Widget_Layered_Nav_Filters - * * @since 1.8.1 * * @param WP_Query $query An instance of the main query. + * * @return bool */ private function is_front_page(WP_Query $query) @@ -148,7 +146,7 @@ class PLLWC_Frontend_WC_Pages return false; } - $vars = array( + $vars = [ // WP. 'cpage', 'orderby', @@ -161,7 +159,7 @@ class PLLWC_Frontend_WC_Pages 'max_price', 'min_price', 'rating_filter', - ); + ]; foreach (wc_get_attribute_taxonomies() as $attribute) { $vars[] = "filter_{$attribute->attribute_name}"; diff --git a/__plugins/polylang-wc/src/frontend/frontend.php b/__plugins/polylang-wc/src/frontend/frontend.php index f40496eeee9206e1cf397f586f50dd17bdd10c75..27ae2d048717d660315edb54a67d6c878c2401bb 100644 --- a/__plugins/polylang-wc/src/frontend/frontend.php +++ b/__plugins/polylang-wc/src/frontend/frontend.php @@ -1,9 +1,5 @@ init(); } else { - add_action('pll_language_defined', array( $this, 'init' ), 1); - add_action('woocommerce_init', array( $this, 'override_countries' ), 1); + add_action('pll_language_defined', [$this, 'init'], 1); + add_action('woocommerce_init', [$this, 'override_countries'], 1); // Set the language early if a form has been posted with a language value. - if (! empty($_REQUEST['lang']) && $lang = PLL()->model->get_language(sanitize_key($_REQUEST['lang']))) { // phpcs:ignore WordPress.Security.NonceVerification + if (!empty($_REQUEST['lang']) && $lang = PLL()->model->get_language(sanitize_key($_REQUEST['lang']))) { // phpcs:ignore WordPress.Security.NonceVerification PLL()->curlang = $lang; $GLOBALS['text_direction'] = $lang->is_rtl ? 'rtl' : 'ltr'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride do_action('pll_language_defined', $lang->slug, $lang); @@ -45,56 +41,56 @@ class PLLWC_Frontend PLLWC_Filter_WC_Pages::init(); // Filters the product search form. - if (is_callable(array( PLL()->filters_search, 'get_search_form' ))) { - add_filter('get_product_search_form', array( PLL()->filters_search, 'get_search_form' ), 99); - add_filter('render_block_woocommerce/product-search', array( PLL()->filters_search, 'get_search_form' )); + if (is_callable([PLL()->filters_search, 'get_search_form'])) { + add_filter('get_product_search_form', [PLL()->filters_search, 'get_search_form'], 99); + add_filter('render_block_woocommerce/product-search', [PLL()->filters_search, 'get_search_form']); } - if (! PLL()->options['force_lang']) { - if (! get_option('permalink_structure')) { + if (!PLL()->options['force_lang']) { + if (!get_option('permalink_structure')) { // Fix product page when using plain permalinks and the language is set from the content. - add_filter('pll_check_canonical_url', array( $this, 'pll_check_canonical_url' )); - add_filter('pll_translation_url', array( $this, 'pll_translation_url' ), 10, 2); + add_filter('pll_check_canonical_url', [$this, 'pll_check_canonical_url']); + add_filter('pll_translation_url', [$this, 'pll_translation_url'], 10, 2); } else { // Fix shop link when using pretty permalinks and the language is set from the content. - add_filter('post_type_archive_link', array( $this, 'post_type_archive_link' ), 99, 2); // After Polylang. + add_filter('post_type_archive_link', [$this, 'post_type_archive_link'], 99, 2); // After Polylang. } // Add the language input field to forms to detect the language before wp_loaded is fired. - $actions = array( + $actions = [ 'woocommerce_login_form_start', // Login. 'woocommerce_register_form_start', // Register. 'woocommerce_before_cart_table', // Cart. 'woocommerce_before_add_to_cart_button', // Product. 'woocommerce_lostpassword_form', // Lost password. - ); + ]; foreach ($actions as $action) { - add_action($action, array( $this, 'language_form_field' )); + add_action($action, [$this, 'language_form_field']); } - add_filter('woocommerce_get_remove_url', array( $this, 'add_lang_query_arg' )); + add_filter('woocommerce_get_remove_url', [$this, 'add_lang_query_arg']); } // Translates home url in widgets. - add_filter('pll_home_url_white_list', array( $this, 'home_url_white_list' )); + add_filter('pll_home_url_white_list', [$this, 'home_url_white_list']); // Layered nav chosen attributes. - add_filter('woocommerce_product_query_tax_query', array( $this, 'product_tax_query' )); + add_filter('woocommerce_product_query_tax_query', [$this, 'product_tax_query']); if (PLL()->options['force_lang'] > 1) { - add_filter('home_url', array( $this, 'fix_widget_price_filter' ), 10, 2); + add_filter('home_url', [$this, 'fix_widget_price_filter'], 10, 2); } // Object cache compatibility. - add_filter('woocommerce_shortcode_products_query', array( $this, 'shortcode_products_query' )); // Since WC 3.0.2. - add_filter('woocommerce_get_product_subcategories_cache_key', array( $this, 'get_product_subcategories_cache_key' )); + add_filter('woocommerce_shortcode_products_query', [$this, 'shortcode_products_query']); // Since WC 3.0.2. + add_filter('woocommerce_get_product_subcategories_cache_key', [$this, 'get_product_subcategories_cache_key']); // Ajax endpoint. - add_filter('woocommerce_ajax_get_endpoint', array( $this, 'ajax_get_endpoint' ), 10, 2); + add_filter('woocommerce_ajax_get_endpoint', [$this, 'ajax_get_endpoint'], 10, 2); // Handles Coming Soon for product and taxonomy pages. - add_filter('woocommerce_is_extension_store_page', array( $this, 'is_store_page' )); + add_filter('woocommerce_is_extension_store_page', [$this, 'is_store_page']); } /** @@ -110,11 +106,12 @@ class PLLWC_Frontend } /** - * Fixes the canonical redirection from the shop page to the product archive when using plain permalinks and the language is set from the content + * Fixes the canonical redirection from the shop page to the product archive when using plain permalinks and the language is set from the content. * * @since 0.3.2 * * @param string $redirect_url Redirect url. + * * @return string|false */ public function pll_check_canonical_url($redirect_url) @@ -122,6 +119,7 @@ class PLLWC_Frontend if (is_post_type_archive('product')) { return false; } + return $redirect_url; } @@ -132,6 +130,7 @@ class PLLWC_Frontend * * @param string $url Translation url. * @param string $lang Language code. + * * @return string */ public function pll_translation_url($url, $lang) @@ -141,7 +140,7 @@ class PLLWC_Frontend if ($lang) { if (PLL()->options['hide_default'] && 'page' === get_option('show_on_front') && PLL()->options['default_lang'] === $lang->slug) { - $pages = pll_languages_list(array( 'fields' => 'page_on_front' )); + $pages = pll_languages_list(['fields' => 'page_on_front']); if (in_array(wc_get_page_id('shop'), $pages)) { return $lang->get_home_url(); } @@ -152,6 +151,7 @@ class PLLWC_Frontend $url = PLL()->links_model->remove_paged_from_link($url); } } + return $url; } @@ -164,6 +164,7 @@ class PLLWC_Frontend * * @param string $link Post type archive link. * @param string $post_type Post type name. + * * @return string Modified link. */ public function post_type_archive_link($link, $post_type) @@ -189,6 +190,7 @@ class PLLWC_Frontend * @since 0.5 * * @param string $url URL to modify. + * * @return string */ public function add_lang_query_arg($url) @@ -197,32 +199,33 @@ class PLLWC_Frontend } /** - * Fixes the home url in widgets + * Fixes the home url in widgets. * * @since 0.5 * * @param string[][] $arr List of files and functions to whitelist for the home_url filter. + * * @return string[][] */ public function home_url_white_list($arr) { $arr = array_merge( $arr, - array( array( 'file' => 'abstract-wc-widget.php' ) ) + [['file' => 'abstract-wc-widget.php']] ); // Avoid a redirect when the language is set from the content. if (PLL()->options['force_lang'] > 0) { $arr = array_merge( $arr, - array( array( 'file' => 'class-wc-widget-product-categories.php' ) ) + [['file' => 'class-wc-widget-product-categories.php']] ); } if (PLL()->options['force_lang'] > 1) { $arr = array_merge( $arr, - array( array( 'file' => 'class-wc-widget-price-filter.php' ) ) + [['file' => 'class-wc-widget-price-filter.php']] ); } @@ -236,19 +239,21 @@ class PLLWC_Frontend * @since 0.5 * * @param array $tax_query Tax query parameter in WP_Query. + * * @return array */ public function product_tax_query($tax_query) { foreach ($tax_query as $k => $q) { - if (is_array($q) && ! empty($q['field']) && 'slug' === $q['field']) { - $terms = get_terms(array( 'taxonomy' => $q['taxonomy'], 'slug' => $q['terms'] )); + if (is_array($q) && !empty($q['field']) && 'slug' === $q['field']) { + $terms = get_terms(['taxonomy' => $q['taxonomy'], 'slug' => $q['terms']]); if (is_array($terms)) { - $tax_query[ $k ]['terms'] = wp_list_pluck($terms, 'term_taxonomy_id'); - $tax_query[ $k ]['field'] = 'term_taxonomy_id'; + $tax_query[$k]['terms'] = wp_list_pluck($terms, 'term_taxonomy_id'); + $tax_query[$k]['field'] = 'term_taxonomy_id'; } } } + return $tax_query; } @@ -259,13 +264,14 @@ class PLLWC_Frontend * * @param string $url Form action url. * @param string $path Path. + * * @return string */ public function fix_widget_price_filter($url, $path) { global $wp; - if (! empty($wp->request) && trailingslashit($wp->request) === $path && ! empty(PLL()->curlang)) { + if (!empty($wp->request) && trailingslashit($wp->request) === $path && !empty(PLL()->curlang)) { $url = PLL()->links_model->switch_language_in_link($url, PLL()->curlang); } @@ -274,11 +280,12 @@ class PLLWC_Frontend /** * Adds the language to the shortcodes query args to get one cache key per language. - * Needed for WC 3.0, Requires WC 3.0.2+ + * Needed for WC 3.0, Requires WC 3.0.2+. * * @since 0.7.4 * * @param array $args WP_Query arguments. + * * @return array */ public function shortcode_products_query($args) @@ -287,12 +294,12 @@ class PLLWC_Frontend return $args; } - $args['tax_query'][] = array( + $args['tax_query'][] = [ 'taxonomy' => 'language', 'field' => 'term_taxonomy_id', 'terms' => PLL()->curlang->get_tax_prop('language', 'term_taxonomy_id'), 'operator' => 'IN', - ); + ]; return $args; } @@ -303,12 +310,14 @@ class PLLWC_Frontend * @since 1.2.3 * * @param string $cache_key WooCommerce product subcategories cache key. + * * @return string */ public function get_product_subcategories_cache_key($cache_key) { $curlang = pll_current_language(); - return $cache_key . '-' . $curlang; + + return $cache_key.'-'.$curlang; } /** @@ -319,15 +328,17 @@ class PLLWC_Frontend * * @param string $url Ajax endpoint. * @param string $request Ajax endpoint request. + * * @return string */ public function ajax_get_endpoint($url, $request) { // Remove wc-ajax to avoid the value %%endpoint%% to be encoded by add_query_arg (used in plain permalinks). $url = remove_query_arg('wc-ajax', $url); - if (! empty(PLL()->curlang)) { + if (!empty(PLL()->curlang)) { $url = PLL()->links_model->switch_language_in_link($url, PLL()->curlang); } + return add_query_arg('wc-ajax', $request, $url); } @@ -337,6 +348,7 @@ class PLLWC_Frontend * @since 2.1 * * @param bool $is_store_page Whether or not we're on a store page. + * * @return bool */ public function is_store_page($is_store_page) diff --git a/__plugins/polylang-wc/src/functions.php b/__plugins/polylang-wc/src/functions.php index 420ce81934cd4f068ff7660513a905c2c24b2c23..40d774537aa3de70e1073d646ee220e15aca57bd 100644 --- a/__plugins/polylang-wc/src/functions.php +++ b/__plugins/polylang-wc/src/functions.php @@ -1,62 +1,59 @@ class name, [1] => method name. * @param int $priority Hook priority, defaults to 10. + * * @return void */ function pll_remove_anonymous_object_filter($tag, $method, $priority = 10) { - if (! empty($GLOBALS['wp_filter'][ $tag ][ $priority ])) { - foreach ($GLOBALS['wp_filter'][ $tag ][ $priority ] as $function) { + if (!empty($GLOBALS['wp_filter'][$tag][$priority])) { + foreach ($GLOBALS['wp_filter'][$tag][$priority] as $function) { if (is_array($function) && is_array($function['function']) && is_a($function['function'][0], $method[0]) && $method[1] === $function['function'][1]) { - remove_filter($tag, array( $function['function'][0], $method[1] ), $priority); + remove_filter($tag, [$function['function'][0], $method[1]], $priority); } } } } } -if (! function_exists('pll_get_anonymous_object_from_filter')) { +if (!function_exists('pll_get_anonymous_object_from_filter')) { /** * Get an anonymous object from one of its known filter. * * @see pll_remove_anonymous_object_filter() - * * @since 0.1 * * @param string $tag Hook name. * @param array $method [0] => class name, [1] => method name. * @param int $priority Hook priority, defaults to 10. + * * @return object|null */ function pll_get_anonymous_object_from_filter($tag, $method, $priority = 10) { - if (! empty($GLOBALS['wp_filter'][ $tag ][ $priority ])) { - foreach ($GLOBALS['wp_filter'][ $tag ][ $priority ] as $function) { + if (!empty($GLOBALS['wp_filter'][$tag][$priority])) { + foreach ($GLOBALS['wp_filter'][$tag][$priority] as $function) { if (is_array($function) && is_array($function['function']) && is_a($function['function'][0], $method[0]) && $method[1] === $function['function'][1]) { return $function['function'][0]; } } } + return null; } } -if (! function_exists('PLLWC')) { +if (!function_exists('PLLWC')) { /** * Returns the Polylang for WooCommerce instance. * @@ -65,6 +62,7 @@ if (! function_exists('PLLWC')) { * @return Polylang_Woocommerce */ function PLLWC() // PHPCS:ignore WordPress.NamingConventions.ValidFunctionName - {return Polylang_Woocommerce::instance(); + { + return Polylang_Woocommerce::instance(); } } diff --git a/__plugins/polylang-wc/src/hpos-orders-query.php b/__plugins/polylang-wc/src/hpos-orders-query.php index ac5731668945c1f98ac9997dc24269b72ab7748c..4bd73054d6220f6a6954d5a3f7c3eb70df818d08 100644 --- a/__plugins/polylang-wc/src/hpos-orders-query.php +++ b/__plugins/polylang-wc/src/hpos-orders-query.php @@ -1,9 +1,5 @@ are_translated_types((array) $query->get('type'), $store)) { + if (!$this->are_translated_types((array) $query->get('type'), $store)) { return $clauses; } @@ -80,15 +80,15 @@ class PLLWC_HPOS_Orders_Query return $clauses; } - $tt_ids = array(); - $alias = $query->get_core_mapping_alias('orders'); + $tt_ids = []; + $alias = $query->get_core_mapping_alias('orders'); foreach ($languages as $language) { $tt_ids[] = (int) $language->get_tax_prop($store->get_tax_language(), 'term_taxonomy_id'); } - $clauses['join'] .= " INNER JOIN {$wpdb->term_relationships} AS pll_tr ON pll_tr.object_id = {$alias}.id"; - $clauses['where'] .= ' AND pll_tr.term_taxonomy_id IN ( ' . implode(',', $tt_ids) . ' )'; + $clauses['join'] .= " INNER JOIN {$wpdb->term_relationships} AS pll_tr ON pll_tr.object_id = {$alias}.id"; + $clauses['where'] .= ' AND pll_tr.term_taxonomy_id IN ( '.implode(',', $tt_ids).' )'; return $clauses; } @@ -100,28 +100,29 @@ class PLLWC_HPOS_Orders_Query * @since 1.9 * * @param string[]|string|null $languages An array of language codes, a comma-separated list of language codes, or `null`. + * * @return PLL_Language[] A list of `PLL_Language` objects. */ private function get_languages($languages): array { - if (! isset($languages) && ! empty(PLL()->curlang)) { + if (!isset($languages) && !empty(PLL()->curlang)) { // `lang` is not set at all: return the current language. - return array( PLL()->curlang ); + return [PLL()->curlang]; } if (empty($languages)) { // `lang` is set to an empty string: don't filter by language. - return array(); + return []; } if (is_string($languages)) { $languages = explode(',', $languages); - } elseif (! is_array($languages)) { - return array(); + } elseif (!is_array($languages)) { + return []; } $languages = array_map('trim', $languages); - $languages = array_map(array( PLL()->model, 'get_language' ), $languages); + $languages = array_map([PLL()->model, 'get_language'], $languages); return array_filter($languages); } @@ -133,6 +134,7 @@ class PLLWC_HPOS_Orders_Query * * @param string[] $types Order types. * @param PLLWC_Order_Language_CPT $store The order language store. + * * @return bool */ private function are_translated_types(array $types, PLLWC_Order_Language_CPT $store) @@ -142,7 +144,7 @@ class PLLWC_HPOS_Orders_Query return false; } - $translated = $store->translated_post_types(array(), false); + $translated = $store->translated_post_types([], false); return empty(array_diff($types, $translated)); } diff --git a/__plugins/polylang-wc/src/import.php b/__plugins/polylang-wc/src/import.php index 98a58571971458a265c080d9fc3f625a3bf8b966..49435c2462f76a028c0c069b30729b89c091b77c 100644 --- a/__plugins/polylang-wc/src/import.php +++ b/__plugins/polylang-wc/src/import.php @@ -1,9 +1,5 @@ data_store = PLLWC_Data_Store::load('product_language'); - add_filter('woocommerce_csv_product_import_mapping_default_columns', array( $this, 'default_columns' )); - add_filter('woocommerce_csv_product_import_mapping_options', array( $this, 'mapping_options' ), 1); - add_action('woocommerce_product_import_inserted_product_object', array( $this, 'inserted_product_object' ), 10, 2); + add_filter('woocommerce_csv_product_import_mapping_default_columns', [$this, 'default_columns']); + add_filter('woocommerce_csv_product_import_mapping_options', [$this, 'mapping_options'], 1); + add_action('woocommerce_product_import_inserted_product_object', [$this, 'inserted_product_object'], 10, 2); - add_action('woocommerce_product_importer_before_set_parsed_data', array( $this, 'before_set_parsed_data' ), 10, 2); - add_action('woocommerce_product_import_before_import', array( $this, 'set_language' )); - add_action('woocommerce_product_import_before_process_item', array( $this, 'set_language' )); + add_action('woocommerce_product_importer_before_set_parsed_data', [$this, 'before_set_parsed_data'], 10, 2); + add_action('woocommerce_product_import_before_import', [$this, 'set_language']); + add_action('woocommerce_product_import_before_process_item', [$this, 'set_language']); - add_filter('woocommerce_product_importer_formatting_callbacks', array( $this, 'formatting_callbacks' ), 10, 2); + add_filter('woocommerce_product_importer_formatting_callbacks', [$this, 'formatting_callbacks'], 10, 2); } /** @@ -51,16 +47,17 @@ class PLLWC_Product_Import * @since 0.8 * * @param string[] $mappings Importer columns mappings. + * * @return string[] */ public function default_columns($mappings) { return array_merge( $mappings, - array( + [ __('Language', 'polylang-wc') => 'language', __('Translation group', 'polylang-wc') => 'translations', - ) + ] ); } @@ -72,21 +69,22 @@ class PLLWC_Product_Import * @since 0.8 * * @param string[] $options Mapping options. + * * @return string[] */ public function mapping_options($options) { if ($n = array_search('price', array_keys($options))) { - $end = array_slice($options, $n); + $end = array_slice($options, $n); $options = array_slice($options, 0, $n); } $options = array_merge( $options, - array( + [ 'language' => __('Language', 'polylang-wc'), 'translations' => __('Translation group', 'polylang-wc'), - ) + ] ); return isset($end) ? array_merge($options, $end) : $options; @@ -100,6 +98,7 @@ class PLLWC_Product_Import * * @param WC_Product $object Product object. * @param array $data Data in a row of the CSV file. + * * @return void */ public function inserted_product_object($object, $data) @@ -112,7 +111,7 @@ class PLLWC_Product_Import } // Shared slug. - if (! empty($data['name'])) { + if (!empty($data['name'])) { $object->set_slug($data['name']); // WooCommerce keeps the slug empty in the product object. $object->save(); } @@ -120,12 +119,13 @@ class PLLWC_Product_Import } /** - * Assigns the translations group + * Assigns the translations group. * * @since 0.8 * * @param int $id Product id. * @param array $data Data in a row of the CSV file. + * * @return void */ public function set_translation_group($id, $data) @@ -135,14 +135,14 @@ class PLLWC_Product_Import $term = get_term_by('name', $group, $taxonomy); if (empty($term)) { - $translations = array( $data['language'] => $id ); - $term = wp_insert_term($group, $taxonomy, array( 'description' => serialize($translations) )); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions - if (! is_wp_error($term)) { + $translations = [$data['language'] => $id]; + $term = wp_insert_term($group, $taxonomy, ['description' => serialize($translations)]); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions + if (!is_wp_error($term)) { wp_set_object_terms($id, $term['term_id'], $taxonomy); } } elseif ($term instanceof WP_Term) { $translations = unserialize($term->description); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions - $translations[ $data['language'] ] = $id; + $translations[$data['language']] = $id; /** @var int[] $translations */ $this->data_store->save_translations($translations); } @@ -157,20 +157,21 @@ class PLLWC_Product_Import * * @param array $row Row values. * @param string[] $mapped_keys Mapped keys. + * * @return void */ public function before_set_parsed_data($row, $mapped_keys) { // Add filters which must be used only during the import. - add_filter('get_terms_args', array( $this, 'get_terms_args' ), 5); // Before Polylang. - add_filter('woocommerce_get_product_id_by_sku', array( $this, 'get_product_id_by_sku' ), 10, 2); - add_filter('pllwc_language_for_unique_sku', array( $this, 'language_for_unique_sku' )); + add_filter('get_terms_args', [$this, 'get_terms_args'], 5); // Before Polylang. + add_filter('woocommerce_get_product_id_by_sku', [$this, 'get_product_id_by_sku'], 10, 2); + add_filter('pllwc_language_for_unique_sku', [$this, 'language_for_unique_sku']); add_filter('pllwc_copy_post_metas', '__return_empty_array', 999); // Avoids _children, _crosssell_ids, etc.. to be wrongly overwritten. // Preferred language for terms. $col = array_search('language', $mapped_keys); - if (! empty($col) && ! empty($row[ $col ]) && $language = PLL()->model->get_language($row[ $col ])) { + if (!empty($col) && !empty($row[$col]) && $language = PLL()->model->get_language($row[$col])) { PLL()->pref_lang = $language; } } @@ -181,6 +182,7 @@ class PLLWC_Product_Import * @since 0.8 * * @param array $data Data in a row of the CSV file. + * * @return void */ public function set_language($data) @@ -198,11 +200,12 @@ class PLLWC_Product_Import * @since 0.8 * * @param array $args WP_Term_Query arguments. + * * @return array */ public function get_terms_args($args) { - if (! isset($args['lang']) && ! empty(PLL()->pref_lang)) { + if (!isset($args['lang']) && !empty(PLL()->pref_lang)) { $args['lang'] = PLL()->pref_lang->slug; } @@ -217,11 +220,12 @@ class PLLWC_Product_Import * * @param int $product_id Product id found by WooCommerce. * @param string $sku Product SKU. + * * @return int */ public function get_product_id_by_sku($product_id, $sku) { - if ($sku && ! empty(PLL()->pref_lang)) { + if ($sku && !empty(PLL()->pref_lang)) { $product_id = $this->data_store->get_product_id_by_sku($sku, PLL()->pref_lang->slug); } @@ -249,6 +253,7 @@ class PLLWC_Product_Import * * @param callable[] $callbacks Array of parsing callbacks. * @param WC_Product_CSV_Importer $importer WC_Product_CSV_Importer object. + * * @return callable[] */ public function formatting_callbacks($callbacks, $importer) @@ -256,11 +261,11 @@ class PLLWC_Product_Import $this->importer = $importer; if (false !== $key = array_search('category_ids', $importer->get_mapped_keys())) { - $callbacks[ $key ] = array( $this, 'parse_categories_field' ); + $callbacks[$key] = [$this, 'parse_categories_field']; } if (false !== $key = array_search('tag_ids', $importer->get_mapped_keys())) { - $callbacks[ $key ] = array( $this, 'parse_tags_field' ); + $callbacks[$key] = [$this, 'parse_tags_field']; } return $callbacks; @@ -273,11 +278,12 @@ class PLLWC_Product_Import * @since 1.0.3 * * @param string $value Field value. + * * @return array of arrays with "parent" and "name" keys. */ public function parse_categories_field($value) { - if (! empty(PLL()->pref_lang)) { + if (!empty(PLL()->pref_lang)) { // Worst hack ever, for shared slug. $_POST['term_lang_choice'] = PLL()->pref_lang->slug; $_REQUEST['_pll_nonce'] = wp_create_nonce('pll_language'); @@ -292,12 +298,13 @@ class PLLWC_Product_Import * @since 1.0.3 * * @param string $value Field value. + * * @return array */ public function parse_tags_field($value) { // Worst hack ever, for shared slug. - if (! empty(PLL()->pref_lang)) { + if (!empty(PLL()->pref_lang)) { $_POST['term_lang_choice'] = PLL()->pref_lang->slug; $_REQUEST['_pll_nonce'] = wp_create_nonce('pll_language'); } diff --git a/__plugins/polylang-wc/src/install.php b/__plugins/polylang-wc/src/install.php index 0717db271383763c6a78014e9b453793a3bf0bad..42d53a26e84c5ae1926105a963151c895bff43f7 100644 --- a/__plugins/polylang-wc/src/install.php +++ b/__plugins/polylang-wc/src/install.php @@ -1,9 +1,5 @@ plugin_basename = $plugin_basename; // Manages plugin activation and deactivation. - register_activation_hook($plugin_basename, array( $this, 'activate' )); - register_deactivation_hook($plugin_basename, array( $this, 'deactivate' )); + register_activation_hook($plugin_basename, [$this, 'activate']); + register_deactivation_hook($plugin_basename, [$this, 'deactivate']); // Blog creation on multisite. - add_action('wpmu_new_blog', array( $this, 'wpmu_new_blog' ), 5); // Before WP attempts to send mails which can break on some PHP versions. + add_action('wpmu_new_blog', [$this, 'wpmu_new_blog'], 5); // Before WP attempts to send mails which can break on some PHP versions. } /** @@ -57,6 +53,7 @@ class PLLWC_Install * * @param string $what Either 'activate' or 'deactivate'. * @param bool $networkwide True if the plugin is network activated, false otherwise. + * * @return void */ protected function do_for_all_blogs($what, $networkwide) @@ -80,6 +77,7 @@ class PLLWC_Install * @since 0.1 * * @param bool $networkwide True if the plugin is network activated, false otherwise. + * * @return void */ public function activate($networkwide) @@ -105,6 +103,7 @@ class PLLWC_Install * @since 0.1 * * @param bool $networkwide True if the plugin is network activated, false otherwise. + * * @return void */ public function deactivate($networkwide) @@ -130,6 +129,7 @@ class PLLWC_Install * @since 0.9.4 * * @param int $blog_id Blog ID. + * * @return void */ public function wpmu_new_blog($blog_id) diff --git a/__plugins/polylang-wc/src/legacy/rest-api.php b/__plugins/polylang-wc/src/legacy/rest-api.php index 9e54317bda96b18a6261a478927eb5f6d261c12d..0fc3a9456440e1c38a2b8159e4598732b0652ae6 100644 --- a/__plugins/polylang-wc/src/legacy/rest-api.php +++ b/__plugins/polylang-wc/src/legacy/rest-api.php @@ -1,9 +1,5 @@ rest_api) || ! PLL()->rest_api instanceof PLL_REST_API) { + if (!isset(PLL()->rest_api) || !PLL()->rest_api instanceof PLL_REST_API) { // Should not happen since this class is instantiated only if `POLYLANG_PRO` is defined. return; } - $this->product = new PLLWC_REST_Product(PLL()->rest_api); - $this->order = new PLLWC_REST_Order(PLL()->rest_api); + $this->product = new PLLWC_REST_Product(PLL()->rest_api); + $this->order = new PLLWC_REST_Order(PLL()->rest_api); $this->attribute_term = new PLLWC_REST_Attribute_Term(PLL()->rest_api); } @@ -66,12 +62,14 @@ class PLLWC_REST_API * @since 0.9 * * @param array $args Options passed to PLL_REST_Post. + * * @return array */ public function post_types($args) { - $args['product_variation'] = array(); + $args['product_variation'] = []; $args['shop_order']['translations'] = false; + return $args; } @@ -81,13 +79,15 @@ class PLLWC_REST_API * @since 0.9 * * @param array $args Options passed to PLL_REST_Term. + * * @return array */ public function taxonomies($args) { - $args['product_cat'] = array(); - $args['product_tag'] = array(); + $args['product_cat'] = []; + $args['product_tag'] = []; unset($args['product_attribute_term']); // Handled in `PLLWC_REST_Attribute_Term`. + return $args; } } diff --git a/__plugins/polylang-wc/src/legacy/rest-attribute-term.php b/__plugins/polylang-wc/src/legacy/rest-attribute-term.php index 2b99d68fca82e24b66f28d6a5cecd7e118f7dbfb..7661db158edf030dc49d5a46562f37188fdfdf3b 100644 --- a/__plugins/polylang-wc/src/legacy/rest-attribute-term.php +++ b/__plugins/polylang-wc/src/legacy/rest-attribute-term.php @@ -1,9 +1,5 @@ array( 'filters' => false ) )); + parent::__construct($rest_api, ['product_attribute_term' => ['filters' => false]]); } /** @@ -30,6 +26,7 @@ class PLLWC_REST_Attribute_Term extends PLL_REST_Term * @since 2.2 * * @param string $type Taxonomy name. + * * @return string REST API field type. */ protected function get_rest_field_type($type) diff --git a/__plugins/polylang-wc/src/legacy/rest-order.php b/__plugins/polylang-wc/src/legacy/rest-order.php index baabc2701aa7443ad66f69c5d6d3022dfa66cb2e..786334b68adf11786dae5f11430f8decc2a3b383 100644 --- a/__plugins/polylang-wc/src/legacy/rest-order.php +++ b/__plugins/polylang-wc/src/legacy/rest-order.php @@ -1,9 +1,5 @@ array( 'filters' => false, 'translations' => false ) )); + parent::__construct($rest_api, ['shop_order' => ['filters' => false, 'translations' => false]]); $this->data_store = PLLWC_Data_Store::load('order_language'); } @@ -42,11 +38,11 @@ class PLLWC_REST_Order extends PLL_REST_Translated_Object * Hooked to `woocommerce_rest_{$post_type}_object_query`. * * @see WC_REST_CRUD_Controller::prepare_objects_query() - * * @since 1.9 * * @param array $args Key value array of query var to query value. * @param WP_REST_Request $request The request used. + * * @return array * * @phpstan-param WP_REST_Request $request @@ -54,6 +50,7 @@ class PLLWC_REST_Order extends PLL_REST_Translated_Object public function add_language_query_arg_in_rest($args, $request) { $args['lang'] = $request->get_param('lang'); + return $args; } @@ -63,6 +60,7 @@ class PLLWC_REST_Order extends PLL_REST_Translated_Object * @since 1.1 * * @param array $object Order array. + * * @return string|false */ public function get_language($object) @@ -77,6 +75,7 @@ class PLLWC_REST_Order extends PLL_REST_Translated_Object * * @param string $lang Language code. * @param WC_Order $object Instance of WC_Order. + * * @return bool */ public function set_language($lang, $object) @@ -84,6 +83,7 @@ class PLLWC_REST_Order extends PLL_REST_Translated_Object if ($object instanceof WC_Order) { $this->data_store->set_language($object->get_id(), $lang); } + return true; } } diff --git a/__plugins/polylang-wc/src/legacy/rest-product.php b/__plugins/polylang-wc/src/legacy/rest-product.php index e6b0101a87673c47b6deb0ab97520cbdb2562ecd..f5c5602322804093b14e9f766b06f535fa684417 100644 --- a/__plugins/polylang-wc/src/legacy/rest-product.php +++ b/__plugins/polylang-wc/src/legacy/rest-product.php @@ -1,9 +1,5 @@ array( 'filters' => false ) )); + parent::__construct($rest_api, ['product' => ['filters' => false]]); - $this->type = 'post'; + $this->type = 'post'; $this->setter_id_name = 'ID'; $this->data_store = PLLWC_Data_Store::load('product_language'); - foreach (array( 'product', 'product_variation' ) as $post_type) { - add_filter("woocommerce_rest_prepare_{$post_type}_object", array( $this, 'prepare_response' ), 10, 3); + foreach (['product', 'product_variation'] as $post_type) { + add_filter("woocommerce_rest_prepare_{$post_type}_object", [$this, 'prepare_response'], 10, 3); } - add_filter('get_terms_args', array( $this, 'get_terms_args' )); // Before Auto translate. + add_filter('get_terms_args', [$this, 'get_terms_args']); // Before Auto translate. - add_filter('pllwc_language_for_unique_sku', array( $this, 'filter_language_with_request' )); - add_filter('pllwc_language_for_lock_on_sku', array( $this, 'filter_language_with_request' )); - add_filter('pllwc_language_for_global_unique_id', array( $this, 'filter_language_with_request' )); + add_filter('pllwc_language_for_unique_sku', [$this, 'filter_language_with_request']); + add_filter('pllwc_language_for_lock_on_sku', [$this, 'filter_language_with_request']); + add_filter('pllwc_language_for_global_unique_id', [$this, 'filter_language_with_request']); } /** @@ -53,6 +49,7 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object * @since 1.1 * * @param array $object Product array. + * * @return string|false */ public function get_language($object) @@ -67,6 +64,7 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object * * @param string $lang Language code. * @param object $object Instance of WC_Product. + * * @return bool */ public function set_language($lang, $object) @@ -76,6 +74,7 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object } else { parent::set_language($lang, $object); } + return true; } @@ -85,6 +84,7 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object * @since 1.1 * * @param array $object Product array. + * * @return array */ public function get_translations($object) @@ -99,16 +99,18 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object * * @param int[] $translations Array of translations with language codes as keys and object ids as values. * @param object $object Instance of WC_Product. + * * @return bool */ public function save_translations($translations, $object) { if ($object instanceof WC_Product) { - $translations[ $this->data_store->get_language($object->get_id()) ] = $object->get_id(); + $translations[$this->data_store->get_language($object->get_id())] = $object->get_id(); $this->data_store->save_translations($translations); } else { parent::save_translations($translations, $object); } + return true; } @@ -118,13 +120,15 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object * @since 1.1 * * @param array $args WP_Term_Query arguments. + * * @return array */ public function get_terms_args($args) { - if (! empty($args['include'])) { + if (!empty($args['include'])) { $args['lang'] = ''; } + return $args; } @@ -134,11 +138,12 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object * @since 1.3 * * @param PLL_Language|false $language Found language object, `false` if none. + * * @return PLL_Language|false The requested language object, `false` if a wrong slug is passed. */ public function filter_language_with_request($language) { - if (isset($this->request['lang']) && in_array($this->request['lang'], $this->model->get_languages_list(array( 'fields' => 'slug' )))) { + if (isset($this->request['lang']) && in_array($this->request['lang'], $this->model->get_languages_list(['fields' => 'slug']))) { $language = PLL()->model->get_language($this->request['lang']); } @@ -154,39 +159,40 @@ class PLLWC_REST_Product extends PLL_REST_Translated_Object * @param WP_REST_Response $response The response object. * @param WC_Product $product Product object. * @param WP_REST_Request $request Request object. + * * @return WP_REST_Response The response object. */ public function prepare_response($response, $product, $request) { global $wpdb; - if (! in_array($request->get_method(), array( 'POST', 'PUT', 'PATCH' ), true)) { + if (!in_array($request->get_method(), ['POST', 'PUT', 'PATCH'], true)) { return $response; } $data = $response->get_data(); - if (! is_array($data) || empty($data['slug'])) { + if (!is_array($data) || empty($data['slug'])) { return $response; } - $params = $request->get_params(); + $params = $request->get_params(); $attributes = $request->get_attributes(); - if (! empty($params['slug'])) { + if (!empty($params['slug'])) { $requested_slug = $params['slug']; } elseif (is_array($attributes['callback']) && 'create_item' === $attributes['callback'][1]) { // Allow sharing slug by default when creating a new product. $requested_slug = sanitize_title($product->get_name()); } - if (! isset($requested_slug) || $product->get_slug() === $requested_slug) { + if (!isset($requested_slug) || $product->get_slug() === $requested_slug) { return $response; } $slug = wp_unique_post_slug($requested_slug, $product->get_id(), $product->get_status(), (string) get_post_type($product->get_id()), $product->get_parent_id()); - if ($slug === $data['slug'] || ! $wpdb->update($wpdb->posts, array( 'post_name' => $slug ), array( 'ID' => $product->get_id() ))) { + if ($slug === $data['slug'] || !$wpdb->update($wpdb->posts, ['post_name' => $slug], ['ID' => $product->get_id()])) { return $response; } diff --git a/__plugins/polylang-wc/src/links-pro.php b/__plugins/polylang-wc/src/links-pro.php index d2d5ac6d782bd7392fd0f875fe1dc84d566b467e..83be43397b2347372e055400ff7d1c5fea3fc94e 100644 --- a/__plugins/polylang-wc/src/links-pro.php +++ b/__plugins/polylang-wc/src/links-pro.php @@ -1,9 +1,5 @@ slugs_model = PLL()->translate_slugs->slugs_model; // Endpoints slugs. - add_filter('pll_translated_slugs', array( $this, 'pll_translated_slugs' ), 10, 3); - add_filter('woocommerce_get_endpoint_url', array( $this, 'get_endpoint_url' ), 10, 2); - add_filter('woocommerce_edit_address_slugs', array( $this, 'edit_address_slugs' )); + add_filter('pll_translated_slugs', [$this, 'pll_translated_slugs'], 10, 3); + add_filter('woocommerce_get_endpoint_url', [$this, 'get_endpoint_url'], 10, 2); + add_filter('woocommerce_edit_address_slugs', [$this, 'edit_address_slugs']); } /** @@ -58,10 +54,11 @@ class PLLWC_Links_Pro extends PLLWC_Links */ $query_vars = apply_filters_deprecated( 'pllwc_endpoints_query_vars', - array( WC()->query->get_query_vars() ), + [WC()->query->get_query_vars()], '2.0', 'woocommerce_get_query_vars' ); + return array_filter((array) $query_vars); } @@ -73,6 +70,7 @@ class PLLWC_Links_Pro extends PLLWC_Links * @param array $slugs The list of slugs. * @param PLL_Language $language Instance of PLL_Language. * @param PLL_MO $mo The translations object, instance of PLL_MO. + * * @return array */ public function pll_translated_slugs($slugs, $language, &$mo) @@ -86,19 +84,20 @@ class PLLWC_Links_Pro extends PLLWC_Links if ($slug) { $slugs['product']['slug'] = $slug; $tr_slug = $mo->translate($slug); - $slugs['product']['translations'][ $language->slug ] = empty($tr_slug) ? $slug : $tr_slug; + $slugs['product']['translations'][$language->slug] = empty($tr_slug) ? $slug : $tr_slug; } else { unset($slugs['product']); } } $endpoints = $this->get_query_vars(); - $endpoints = array_merge($endpoints, array( 'billing', 'shipping' )); // Adds edit-address slugs. + $endpoints = array_merge($endpoints, ['billing', 'shipping']); // Adds edit-address slugs. foreach ($endpoints as $slug) { - $slugs[ 'wc_' . $slug ]['slug'] = $slug; + $slugs['wc_'.$slug]['slug'] = $slug; $tr_slug = $mo->translate($slug); - $slugs[ 'wc_' . $slug ]['translations'][ $language->slug ] = empty($tr_slug) ? $slug : $tr_slug; + $slugs['wc_'.$slug]['translations'][$language->slug] = empty($tr_slug) ? $slug : $tr_slug; } + return $slugs; } @@ -115,8 +114,8 @@ class PLLWC_Links_Pro extends PLLWC_Links { parent::prepare_rewrite_rules(); - if (! has_filter('page_rewrite_rules', array( $this, 'rewrite_translated_slug' ))) { - add_filter('page_rewrite_rules', array( $this, 'rewrite_translated_slug' ), 5); + if (!has_filter('page_rewrite_rules', [$this, 'rewrite_translated_slug'])) { + add_filter('page_rewrite_rules', [$this, 'rewrite_translated_slug'], 5); } } @@ -127,13 +126,15 @@ class PLLWC_Links_Pro extends PLLWC_Links * @since 0.1 * * @param string[] $rules Rewrite rules. + * * @return string[] modified rewrite rules. */ public function rewrite_translated_slug($rules) { foreach ($this->get_query_vars() as $slug) { - $rules = $this->translate_rule($rules, 'wc_' . $slug); + $rules = $this->translate_rule($rules, 'wc_'.$slug); } + return $rules; } @@ -144,6 +145,7 @@ class PLLWC_Links_Pro extends PLLWC_Links * * @param string[] $rules Rewrite rules. * @param string $type Type of slug to translate. + * * @return string[] Modified rewrite rules. */ public function translate_rule($rules, $type) @@ -153,27 +155,28 @@ class PLLWC_Links_Pro extends PLLWC_Links * '/' replaced by '(/' in old and new * and the [1] which is not replaced */ - if (empty($this->slugs_model->translated_slugs[ $type ])) { + if (empty($this->slugs_model->translated_slugs[$type])) { return $rules; } - $newrules = array(); + $newrules = []; - $old = $this->slugs_model->translated_slugs[ $type ]['slug'] . '(/'; - $new = '(' . implode('|', $this->slugs_model->translated_slugs[ $type ]['translations']) . ')(/'; + $old = $this->slugs_model->translated_slugs[$type]['slug'].'(/'; + $new = '('.implode('|', $this->slugs_model->translated_slugs[$type]['translations']).')(/'; foreach ($rules as $key => $rule) { if (false !== $found = strpos($key, $old)) { - $new_key = 0 === $found ? str_replace($old, $new, $key) : str_replace('/' . $old, '/' . $new, $key); - $newrules[ $new_key ] = str_replace( - array( '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]' ), - array( '[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]' ), + $new_key = 0 === $found ? str_replace($old, $new, $key) : str_replace('/'.$old, '/'.$new, $key); + $newrules[$new_key] = str_replace( + ['[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]'], + ['[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]'], $rule ); // Hopefully it is sufficient! } else { - $newrules[ $key ] = $rule; + $newrules[$key] = $rule; } } + return $newrules; } @@ -184,12 +187,14 @@ class PLLWC_Links_Pro extends PLLWC_Links * * @param string $link Endpoint url. * @param string $endpoint Endpoint name. + * * @return string */ public function get_endpoint_url($link, $endpoint) { $lang = PLL()->model->get_language(PLLWC_Admin::get_preferred_language()); // The function translate_slug expects the language object. - return $this->slugs_model->translate_slug($link, $lang, 'wc_' . $endpoint); + + return $this->slugs_model->translate_slug($link, $lang, 'wc_'.$endpoint); } /** @@ -198,17 +203,19 @@ class PLLWC_Links_Pro extends PLLWC_Links * @øince 0.1 * * @param string[] $slugs Edit address endpoint slugs, typically 'billing' and 'shipping'. + * * @return string[] */ public function edit_address_slugs($slugs) { foreach (array_keys($slugs) as $key) { - if (isset($this->slugs_model->translated_slugs[ 'wc_' . $key ]) && $lang = pll_current_language()) { - $slugs[ $key ] = rawurlencode($this->slugs_model->translated_slugs[ 'wc_' . $key ]['translations'][ $lang ]); + if (isset($this->slugs_model->translated_slugs['wc_'.$key]) && $lang = pll_current_language()) { + $slugs[$key] = rawurlencode($this->slugs_model->translated_slugs['wc_'.$key]['translations'][$lang]); } else { - $slugs[ $key ] = rawurlencode($key); // Don't rely on woocommerce mo file and accept translation only from our own system. + $slugs[$key] = rawurlencode($key); // Don't rely on woocommerce mo file and accept translation only from our own system. } } + return $slugs; } @@ -220,6 +227,7 @@ class PLLWC_Links_Pro extends PLLWC_Links * * @param string $url Translation url. * @param string $lang Language slug. + * * @return string */ public function pll_translation_url($url, $lang) @@ -230,18 +238,18 @@ class PLLWC_Links_Pro extends PLLWC_Links $language = PLL()->model->get_language($lang); $endpoint = WC()->query->get_current_endpoint(); - if (! $language || ! $endpoint) { + if (!$language || !$endpoint) { return $url; } $query_vars = WC()->query->get_query_vars(); - $url = $this->slugs_model->switch_translated_slug($url, $language, 'wc_' . $query_vars[ $endpoint ]); + $url = $this->slugs_model->switch_translated_slug($url, $language, 'wc_'.$query_vars[$endpoint]); if ('edit-address' === $endpoint) { - $value = wc_edit_address_i18n($wp->query_vars[ $endpoint ], true); + $value = wc_edit_address_i18n($wp->query_vars[$endpoint], true); $url = trailingslashit($url); - $url = $this->slugs_model->switch_translated_slug($url, $language, 'wc_' . $value); + $url = $this->slugs_model->switch_translated_slug($url, $language, 'wc_'.$value); } return $url; diff --git a/__plugins/polylang-wc/src/links.php b/__plugins/polylang-wc/src/links.php index 25273a832a74adaa46f833bc3f0a935b3d693327..5381e5df7086dd550f48de74212339e07d778aae 100644 --- a/__plugins/polylang-wc/src/links.php +++ b/__plugins/polylang-wc/src/links.php @@ -1,9 +1,5 @@ options['force_lang'] > 1) { - add_filter('woocommerce_customer_available_downloads', array( $this, 'filter_download_urls' )); - add_filter('woocommerce_get_item_downloads', array( $this, 'filter_download_urls' )); - add_filter('woocommerce_product_file_download_path', array( $this, 'filter_download_url' )); + add_filter('woocommerce_customer_available_downloads', [$this, 'filter_download_urls']); + add_filter('woocommerce_get_item_downloads', [$this, 'filter_download_urls']); + add_filter('woocommerce_product_file_download_path', [$this, 'filter_download_url']); } } @@ -52,9 +48,9 @@ class PLLWC_Links */ public function prepare_rewrite_rules() { - if (! has_filter('rewrite_rules_array', array( $this, 'rewrite_shop_rules' ))) { - add_filter('rewrite_rules_array', array( $this, 'rewrite_shop_rules' ), 5); // Before Polylang. - add_filter('rewrite_rules_array', array( $this, 'rewrite_shop_subpages_rules' ), 20); // After wc_fix_rewrite_rules(). + if (!has_filter('rewrite_rules_array', [$this, 'rewrite_shop_rules'])) { + add_filter('rewrite_rules_array', [$this, 'rewrite_shop_rules'], 5); // Before Polylang. + add_filter('rewrite_rules_array', [$this, 'rewrite_shop_subpages_rules'], 20); // After wc_fix_rewrite_rules(). } } @@ -67,14 +63,14 @@ class PLLWC_Links */ protected function get_all_shop_page_slugs() { - $slugs = array(); - $id = wc_get_page_id('shop'); - $ids = pll_get_post_translations($id); + $slugs = []; + $id = wc_get_page_id('shop'); + $ids = pll_get_post_translations($id); _prime_post_caches($ids); // Prime posts cache before `get_page_uri()` calls in the loop. foreach ($ids as $lang => $id) { - $slugs[ $lang ] = urldecode((string) get_page_uri($id)); + $slugs[$lang] = urldecode((string) get_page_uri($id)); } return array_filter($slugs); @@ -89,32 +85,33 @@ class PLLWC_Links * @since 0.1 * * @param string[] $rules Rewrite rules. + * * @return string[] Modified rewrite rules. */ public function rewrite_shop_rules($rules) { - $new_rules = array(); + $new_rules = []; $id = wc_get_page_id('shop'); if ($id) { - $uri = urldecode((string) get_page_uri($id)) . '/'; // The page uri got from the WooCommerce option. + $uri = urldecode((string) get_page_uri($id)).'/'; // The page uri got from the WooCommerce option. $translations = $this->get_all_shop_page_slugs(); if (count($translations) > 1) { if (PLL()->options['force_lang'] > 0) { // The language is set from the directory, subdomain or domain. $translations = array_unique($translations); - $new_uri = '(' . implode('|', $translations) . ')/'; + $new_uri = '('.implode('|', $translations).')/'; foreach ($rules as $key => $rule) { if (0 === strpos($key, $uri)) { // OK if we are acting before Polylang. - $new_rules[ str_replace($uri, $new_uri, $key) ] = str_replace( - array( '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]' ), - array( '[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]' ), + $new_rules[str_replace($uri, $new_uri, $key)] = str_replace( + ['[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]'], + ['[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]'], $rule ); // Hopefully it is sufficient! - unset($rules[ $key ]); // Now useless. + unset($rules[$key]); // Now useless. } } } else { @@ -125,10 +122,10 @@ class PLLWC_Links foreach ($rules as $key => $rule) { if (0 === strpos($key, $uri) && false !== strpos($rule, 'post_type=product')) { foreach ($translations as $lang => $new_uri) { - $new_rules[ str_replace($uri, $new_uri . '/', $key) ] = str_replace('?', "?lang=$lang&", $rule); + $new_rules[str_replace($uri, $new_uri.'/', $key)] = str_replace('?', "?lang=$lang&", $rule); } - unset($rules[ $key ]); // Now useless. + unset($rules[$key]); // Now useless. } } } @@ -145,6 +142,7 @@ class PLLWC_Links * @since 0.9.5 * * @param string[] $rules Rewrite rules. + * * @return string[] Modified rewrite rules. */ public function rewrite_shop_subpages_rules($rules) @@ -152,7 +150,7 @@ class PLLWC_Links global $wp_rewrite; $permalinks = wc_get_permalink_structure(); - $page_rewrite_rules = array(); + $page_rewrite_rules = []; if ($permalinks['use_verbose_page_rules'] && $id = wc_get_page_id('shop')) { foreach (pll_get_post_translations($id) as $lang => $shop_page_id) { @@ -163,30 +161,31 @@ class PLLWC_Links // Remove rules added by WooCommerce as it is easier to add our own rather than modifying them separately. foreach ($rules as $key => $rule) { - if (false !== strpos($rule, 'pagename=' . $uri)) { - unset($rules[ $key ]); + if (false !== strpos($rule, 'pagename='.$uri)) { + unset($rules[$key]); } } if (PLL()->options['hide_default'] && PLL()->options['default_lang'] === $lang) { $slug = $uri; } else { - $slug = $lang . '/' . $uri; + $slug = $lang.'/'.$uri; } /* * Inspired by WooCommerce wc_fix_rewrite_rules(). * Code last checked: WC 4.0 */ - $page_rewrite_rules[ $slug . '/?$' ] = 'index.php?pagename=' . $uri; + $page_rewrite_rules[$slug.'/?$'] = 'index.php?pagename='.$uri; $wp_generated_rewrite_rules = $wp_rewrite->generate_rewrite_rules($slug, EP_PAGES, true, true, false, false); foreach ($wp_generated_rewrite_rules as $key => $value) { - $wp_generated_rewrite_rules[ $key ] = $value . '&pagename=' . $uri; + $wp_generated_rewrite_rules[$key] = $value.'&pagename='.$uri; } $page_rewrite_rules = array_merge($page_rewrite_rules, $wp_generated_rewrite_rules); } } } + return $page_rewrite_rules + $rules; } @@ -199,6 +198,7 @@ class PLLWC_Links * @param string[] $rule Original rewrite rule. * @param string $filter Current set of rules being modified. * @param string|bool $archive Custom post post type archive name or false if it is not a cpt archive. + * * @return bool */ public function fix_rewrite_rules($modify, $rule, $filter, $archive) @@ -207,7 +207,7 @@ class PLLWC_Links return false; } - if (! PLL()->options['force_lang'] && 'rewrite_rules_array' === $filter && 'product' === $archive) { + if (!PLL()->options['force_lang'] && 'rewrite_rules_array' === $filter && 'product' === $archive) { return false; } @@ -222,6 +222,7 @@ class PLLWC_Links * * @param string $url Translation url. * @param string $lang Language slug. + * * @return string */ public function pll_translation_url($url, $lang) @@ -229,7 +230,7 @@ class PLLWC_Links global $wp; // Shop. - if (is_shop() && ! is_search()) { + if (is_shop() && !is_search()) { $url = ''; $tr_shop_id = pll_get_post(wc_get_page_id('shop'), $lang); @@ -238,10 +239,10 @@ class PLLWC_Links // Layered nav. foreach (wc_get_attribute_taxonomies() as $tax) { - $name = 'filter_' . $tax->attribute_name; + $name = 'filter_'.$tax->attribute_name; - if (! empty($_GET[ $name ]) && $tr_id = pll_get_term((int) $_GET[ $name ], $lang)) { // phpcs:ignore WordPress.Security.NonceVerification - $url = add_query_arg(array( $name => $tr_id ), $url); + if (!empty($_GET[$name]) && $tr_id = pll_get_term((int) $_GET[$name], $lang)) { // phpcs:ignore WordPress.Security.NonceVerification + $url = add_query_arg([$name => $tr_id], $url); } } } @@ -249,7 +250,7 @@ class PLLWC_Links // Endpoints. if ($endpoint = WC()->query->get_current_endpoint()) { - $value = wc_edit_address_i18n($wp->query_vars[ $endpoint ], true); // Address. + $value = wc_edit_address_i18n($wp->query_vars[$endpoint], true); // Address. $url = wc_get_endpoint_url($endpoint, $value, $url); if (PLL()->links_model->using_permalinks) { $url = trailingslashit($url); // Needed for address. @@ -266,10 +267,10 @@ class PLLWC_Links $order = wc_get_order($value); if ($order instanceof WC_Order) { $url = add_query_arg( - array( + [ 'pay_for_order' => 'true', 'key' => $order->get_order_key(), - ), + ], $url ); } @@ -287,17 +288,18 @@ class PLLWC_Links * @since 0.3.6 * * @param string[] $permalinks WooCommerce permalinks options. + * * @return string[] */ public function option_woocommerce_permalinks($permalinks) { if (isset($permalinks['product_base']) && did_action('pll_language_defined')) { $slugs = $this->get_all_shop_page_slugs(); - $lang = pll_current_language(); + $lang = pll_current_language(); - if (count($slugs) > 1 && ! empty($slugs[ $lang ])) { - $pattern = '#(' . implode('|', $slugs) . ')#'; - $permalinks['product_base'] = (string) preg_replace($pattern, $slugs[ $lang ], $permalinks['product_base']); + if (count($slugs) > 1 && !empty($slugs[$lang])) { + $pattern = '#('.implode('|', $slugs).')#'; + $permalinks['product_base'] = (string) preg_replace($pattern, $slugs[$lang], $permalinks['product_base']); } } @@ -309,8 +311,9 @@ class PLLWC_Links * * @since 1.8 * - * @param array $additional_data Array of editable language properties. - * @param array $data Language data Array of `PLL_Language` object properties currently created. + * @param array $additional_data Array of editable language properties. + * @param array $data Language data Array of `PLL_Language` object properties currently created. + * * @return array Editable properties with `home_url` set. * * @phpstan-param array $additional_data @@ -319,18 +322,17 @@ class PLLWC_Links public static function set_home_url($additional_data, $data) { if ( - ! function_exists('wc_get_page_id') // Test that wc_get_page_id() exists as the filter is applied before we check if WooCommerce is activated. + !function_exists('wc_get_page_id') // Test that wc_get_page_id() exists as the filter is applied before we check if WooCommerce is activated. || get_option('permalink_structure') // Plain permalink sets `permalink_structure` option to empty string. || 'page' !== get_option('show_on_front') ) { - return $additional_data; } // Use `PLL_Translated_Post::get_raw_translation()` instead of `PLL_Translated_Post::get_translations()` to avoid calling `PLL_Model::get_languages_list()` while languages are created. $shop_page_translations = PLL()->model->post->get_raw_translations(wc_get_page_id('shop')); - if (isset($additional_data['page_on_front']) && ! in_array($additional_data['page_on_front'], $shop_page_translations, true)) { + if (isset($additional_data['page_on_front']) && !in_array($additional_data['page_on_front'], $shop_page_translations, true)) { return $additional_data; } @@ -338,7 +340,7 @@ class PLLWC_Links return $additional_data; } - $additional_data['home_url'] = home_url('/?post_type=product&lang=' . $data['slug']); + $additional_data['home_url'] = home_url('/?post_type=product&lang='.$data['slug']); return $additional_data; } @@ -352,6 +354,7 @@ class PLLWC_Links * * @param string $url Order received url. * @param WC_Order $order WC_Order object. + * * @return string */ public function checkout_order_received_url($url, $order) @@ -378,6 +381,7 @@ class PLLWC_Links $avoid_recursion = false; PLL()->curlang = $saved_curlang; } + return $url; } @@ -387,11 +391,12 @@ class PLLWC_Links * @since 2.2 * * @param array $downloads List of downloads. + * * @return array List of downloads updated with their URL corresponding to the current language. */ public function filter_download_urls($downloads) { - if (! is_array($downloads) || ! PLL()->curlang instanceof PLL_Language) { + if (!is_array($downloads) || !PLL()->curlang instanceof PLL_Language) { return $downloads; } @@ -400,7 +405,7 @@ class PLLWC_Links continue; } - $downloads[ $key ]['download_url'] = PLL()->links_model->switch_language_in_link($download['download_url'], PLL()->curlang); + $downloads[$key]['download_url'] = PLL()->links_model->switch_language_in_link($download['download_url'], PLL()->curlang); } return $downloads; @@ -411,15 +416,15 @@ class PLLWC_Links * This prevents to trigger a "File not found" error when trying to download a file. * * @since 2.2 - * * @see WC_Download_Handler::download_product() * * @param string $download_url File download URL. + * * @return string */ public function filter_download_url($download_url) { - if (empty($download_url) || ! PLL()->curlang instanceof PLL_Language) { + if (empty($download_url) || !PLL()->curlang instanceof PLL_Language) { return $download_url; } diff --git a/__plugins/polylang-wc/src/object-language.php b/__plugins/polylang-wc/src/object-language.php index 1c8b4e434e0e1d26011a8bd8706065eb2f7db17e..9ed16b6d99741733b551b406e411c3fa432ebb78 100644 --- a/__plugins/polylang-wc/src/object-language.php +++ b/__plugins/polylang-wc/src/object-language.php @@ -1,9 +1,5 @@ @@ -94,7 +93,7 @@ abstract class PLLWC_Object_Language return $lang; } - return ! empty($lang) ? $lang->get_prop($field) : false; + return !empty($lang) ? $lang->get_prop($field) : false; } /** @@ -104,6 +103,7 @@ abstract class PLLWC_Object_Language * @since 1.9 Type-hinted. * * @param string $alias Optional alias for object table. + * * @return string The JOIN clause. * * @phpstan-return non-empty-string @@ -121,6 +121,7 @@ abstract class PLLWC_Object_Language * * @param PLL_Language|PLL_Language[]|string|string[] $lang A `PLL_Language` object, or a comma separated list of * language slugs, or an array of language slugs or objects. + * * @return string The WHERE clause. * * @phpstan-param PLL_Language|PLL_Language[]|non-empty-string|non-empty-string[] $lang @@ -140,14 +141,16 @@ abstract class PLLWC_Object_Language * * @param array $wp_query_args Query arguments after WooCommerce processing. * @param array $query_vars Original query arguments before WooCommerce processing. + * * @return array Modified query arguments with 'lang' restored if needed. */ public function restore_lang_query_arg($wp_query_args, $query_vars) { // Only restore if 'lang' was explicitly set in the original query. - if (array_key_exists('lang', $query_vars) && ! isset($wp_query_args['lang'])) { + if (array_key_exists('lang', $query_vars) && !isset($wp_query_args['lang'])) { $wp_query_args['lang'] = $query_vars['lang']; } + return $wp_query_args; } } diff --git a/__plugins/polylang-wc/src/order-language-cpt.php b/__plugins/polylang-wc/src/order-language-cpt.php index a8fc185a3131f81acdff20fa9ba63c5b7092e3a9..2506435401a537b6b428669bb0549dc7336c9a7d 100644 --- a/__plugins/polylang-wc/src/order-language-cpt.php +++ b/__plugins/polylang-wc/src/order-language-cpt.php @@ -1,9 +1,5 @@ $types + * * @phpstan-return array */ public function translated_post_types($types, $hide) @@ -65,9 +64,11 @@ class PLLWC_Order_Language_CPT extends PLLWC_Object_Language * @since 1.0.4 * * @param string[] $types List of post type names for which Polylang manages the bulk translate. + * * @return string[] * * @phpstan-param array $types + * * @phpstan-return array */ public function bulk_translate_post_types($types) @@ -88,7 +89,7 @@ class PLLWC_Order_Language_CPT extends PLLWC_Object_Language */ public function get_post_types($context = 'default') { - $woo_types = array( 'shop_order' ); + $woo_types = ['shop_order']; if ('display' !== $context) { $woo_types[] = 'shop_order_placehold'; diff --git a/__plugins/polylang-wc/src/plugins/bookings.php b/__plugins/polylang-wc/src/plugins/bookings.php index 44f87caac8becd7c9fd0704210e659f48295c977..f5ed7a6b6cd033c5c4144a5cf531f2e590ce3687 100644 --- a/__plugins/polylang-wc/src/plugins/bookings.php +++ b/__plugins/polylang-wc/src/plugins/bookings.php @@ -1,9 +1,5 @@ translate_slugs)) { - add_action('pllwc_email_language', array( PLL()->translate_slugs->slugs_model, 'init_translated_slugs' )); + add_action('pllwc_email_language', [PLL()->translate_slugs->slugs_model, 'init_translated_slugs']); } // Bookings endpoint. - add_filter('pll_translation_url', array( $this, 'pll_translation_url' ), 10, 2); - add_filter('woocommerce_get_query_vars', array( $this, 'get_endpoints_query_vars' )); + add_filter('pll_translation_url', [$this, 'pll_translation_url'], 10, 2); + add_filter('woocommerce_get_query_vars', [$this, 'get_endpoints_query_vars']); if (PLL() instanceof PLL_Frontend) { - add_action('parse_query', array( $this, 'parse_query' ), 3); // Before Polylang (for orders). + add_action('parse_query', [$this, 'parse_query'], 3); // Before Polylang (for orders). } } @@ -105,13 +100,14 @@ class PLLWC_Bookings * @since 1.6 * * @param string[] $actions Array of actions used to send emails. + * * @return string[] */ public function filter_order_email_actions($actions) { return array_merge( $actions, - array( + [ // Cancelled booking. 'woocommerce_booking_pending-confirmation_to_cancelled_notification', 'woocommerce_booking_confirmed_to_cancelled_notification', @@ -125,7 +121,7 @@ class PLLWC_Bookings // New booking. 'woocommerce_new_booking_notification', 'woocommerce_admin_new_booking_notification', - ) + ] ); } @@ -137,11 +133,13 @@ class PLLWC_Bookings * * @param array $types List of post type names for which Polylang manages language and translations. * @param bool $hide True when displaying the list in Polylang settings. + * * @return array List of post type names for which Polylang manages language and translations. */ public function translate_types($types, $hide) { - $wc_bookings_types = array( 'bookable_resource', 'bookable_person', 'wc_booking' ); + $wc_bookings_types = ['bookable_resource', 'bookable_person', 'wc_booking']; + return $hide ? array_diff($types, $wc_bookings_types) : array_merge($types, $wc_bookings_types); } @@ -156,11 +154,11 @@ class PLLWC_Bookings */ public function custom_columns() { - remove_filter('manage_edit-wc_booking_columns', array( PLL()->filters_columns, 'add_post_column' ), 100); - remove_action('manage_wc_booking_posts_custom_column', array( PLL()->filters_columns, 'post_column' ), 10, 2); + remove_filter('manage_edit-wc_booking_columns', [PLL()->filters_columns, 'add_post_column'], 100); + remove_action('manage_wc_booking_posts_custom_column', [PLL()->filters_columns, 'post_column'], 10, 2); - add_filter('manage_edit-wc_booking_columns', array( PLLWC()->admin_orders, 'add_order_column' ), 100); - add_action('manage_wc_booking_posts_custom_column', array( PLLWC()->admin_orders, 'order_column' ), 10, 2); + add_filter('manage_edit-wc_booking_columns', [PLLWC()->admin_orders, 'add_order_column'], 100); + add_action('manage_wc_booking_posts_custom_column', [PLLWC()->admin_orders, 'order_column'], 10, 2); // FIXME add a filter in PLLWC for the position of the column? } @@ -172,6 +170,7 @@ class PLLWC_Bookings * @since 0.6 * * @param string $post_type Post type. + * * @return void */ public function add_meta_boxes($post_type) @@ -192,7 +191,7 @@ class PLLWC_Bookings */ public function change_locale() { - load_plugin_textdomain('woocommerce-bookings', false, plugin_basename(__DIR__) . '/languages'); + load_plugin_textdomain('woocommerce-bookings', false, plugin_basename(__DIR__).'/languages'); } /** @@ -202,6 +201,7 @@ class PLLWC_Bookings * @since 0.6 * * @param int $post_id Booking ID. + * * @return void */ public function before_booking_metabox_save($post_id) @@ -236,6 +236,7 @@ class PLLWC_Bookings * @since 0.6 * * @param int $booking_id Booking ID. + * * @return void */ public function new_booking($booking_id) @@ -243,10 +244,10 @@ class PLLWC_Bookings $data_store = PLLWC_Data_Store::load('product_language'); $booking = get_wc_booking($booking_id); - $lang = $data_store->get_language($booking->product_id); + $lang = $data_store->get_language($booking->product_id); pll_set_post_language($booking->id, $lang); - if (! empty($booking->order_id)) { + if (!empty($booking->order_id)) { $data_store = PLLWC_Data_Store::load('order_language'); $data_store->set_language($booking->order_id, $lang); } @@ -260,19 +261,20 @@ class PLLWC_Bookings * * @since 1.9 * - * @param int $item_id An order item ID. - * @param WC_Order_Item|false $order_item Order item object. + * @param int $item_id An order item ID. + * @param WC_Order_Item|false $order_item Order item object. + * * @return int */ public function set_booking_language_at_checkout($item_id, $order_item) { - if (empty($order_item->legacy_values) || ! is_array($order_item->legacy_values) || empty($order_item->legacy_values['booking'])) { + if (empty($order_item->legacy_values) || !is_array($order_item->legacy_values) || empty($order_item->legacy_values['booking'])) { return $item_id; } $booking_id = $order_item->legacy_values['booking']['_booking_id']; $lang = pll_current_language(); - if (! empty($lang) && pll_get_post_language($booking_id) !== $lang) { + if (!empty($lang) && pll_get_post_language($booking_id) !== $lang) { pll_set_post_language($booking_id, $lang); } @@ -287,6 +289,7 @@ class PLLWC_Bookings * @param array $post Bookable post to copy (person or resource). * @param int $to ID of the product to which we paste information. * @param string $lang Language slug. + * * @return int Translated bookable post. */ protected function copy_bookable_post($post, $to, $lang) @@ -298,18 +301,18 @@ class PLLWC_Bookings // If the translated bookable_person already exists, make sure it has the right post_parent. $post = get_post($tr_id); if ($post->post_parent !== $to) { - wp_update_post(array( 'ID' => $tr_id, 'post_parent' => $to )); + wp_update_post(['ID' => $tr_id, 'post_parent' => $to]); } } else { // Creates the bookable_resource if it does not exist yet. - $post['ID'] = null; + $post['ID'] = null; $post['post_parent'] = $to; - $tr_id = wp_insert_post($post); + $tr_id = wp_insert_post($post); pll_set_post_language($tr_id, $lang); $translations = pll_get_post_translations($id); - $translations[ pll_get_post_language($id) ] = $id; // In case this is the first translation created. - $translations[ $lang ] = $tr_id; + $translations[pll_get_post_language($id)] = $id; // In case this is the first translation created. + $translations[$lang] = $tr_id; pll_save_post_translations($translations); } @@ -328,6 +331,7 @@ class PLLWC_Bookings * @param int $from ID of the product from which we copy information. * @param int $to ID of the product to which we paste information. * @param string $lang Language slug. + * * @return void */ public function copy_resources($from, $to, $lang) @@ -336,11 +340,11 @@ class PLLWC_Bookings $relationships = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wc_booking_relationships WHERE product_id = %d", $from), ARRAY_A); foreach ($relationships as $relationship) { - $resource = get_post($relationship['resource_id'], ARRAY_A); // wp_insert_post() expects an array. + $resource = get_post($relationship['resource_id'], ARRAY_A); // wp_insert_post() expects an array. $tr_resource_id = $this->copy_bookable_post($resource, $to, $lang); - if (! $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wc_booking_relationships WHERE product_id = %d AND resource_id = %d", $to, $tr_resource_id))) { + if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wc_booking_relationships WHERE product_id = %d AND resource_id = %d", $to, $tr_resource_id))) { unset($relationship['ID']); - $relationship['product_id'] = $to; + $relationship['product_id'] = $to; $relationship['resource_id'] = $tr_resource_id; $wpdb->insert("{$wpdb->prefix}wc_booking_relationships", $relationship); @@ -360,17 +364,18 @@ class PLLWC_Bookings * @param int $from ID of the product from which we copy information. * @param int $to ID of the product to which we paste information. * @param string $lang Language slug. + * * @return void */ public function copy_persons($from, $to, $lang) { // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_children $persons = get_children( - array( + [ 'post_parent' => $from, 'post_type' => 'bookable_person', 'lang' => '', - ), + ], ARRAY_A // wp_insert_post() expects an array. ); @@ -391,15 +396,15 @@ class PLLWC_Bookings { global $wpdb; - if (! isset($_POST['post_id'], $_POST['resource_id'], $_REQUEST['security'])) { + if (!isset($_POST['post_id'], $_POST['resource_id'], $_REQUEST['security'])) { return; } - if (! wp_verify_nonce($_REQUEST['security'], 'delete-bookable-resource')) { + if (!wp_verify_nonce($_REQUEST['security'], 'delete-bookable-resource')) { return; } - $product_id = absint($_POST['post_id']); + $product_id = absint($_POST['post_id']); $resource_id = absint($_POST['resource_id']); $data_store = PLLWC_Data_Store::load('product_language'); @@ -413,10 +418,10 @@ class PLLWC_Bookings $wpdb->delete( "{$wpdb->prefix}wc_booking_relationships", - array( + [ 'product_id' => $tr_id, 'resource_id' => $tr_resource_id, - ) + ] ); } } @@ -431,18 +436,18 @@ class PLLWC_Bookings */ public function unlink_bookable_person() { - if (! isset($_POST['person_id'], $_REQUEST['security'])) { + if (!isset($_POST['person_id'], $_REQUEST['security'])) { return; } - if (! wp_verify_nonce($_REQUEST['security'], 'unlink-bookable-person')) { + if (!wp_verify_nonce($_REQUEST['security'], 'unlink-bookable-person')) { return; } $person_type_id = intval($_POST['person_id']); - $person_type = get_post($person_type_id); + $person_type = get_post($person_type_id); - if (! $person_type || 'bookable_person' !== $person_type->post_type) { + if (!$person_type || 'bookable_person' !== $person_type->post_type) { return; } @@ -465,57 +470,58 @@ class PLLWC_Bookings * @param int $post_id New product or resource. * @param array $translations Existing product or resource translations. * @param string $meta_key Meta to add to the booking. + * * @return void */ protected function add_metas_to_booking($post_id, $translations, $meta_key) { global $wpdb; - if (! empty($translations)) { // If there is no translation, the query returns all bookings! + if (!empty($translations)) { // If there is no translation, the query returns all bookings! $query_translations = new WP_Query( - array( + [ 'fields' => 'ids', 'post_type' => 'wc_booking', 'numberposts' => -1, 'nopaging' => true, // phpcs:ignore WordPressVIPMinimum.Performance.NoPaging.nopaging_nopaging 'lang' => '', - 'meta_query' => array( - array( + 'meta_query' => [ + [ 'key' => $meta_key, 'value' => $translations, 'compare' => 'IN', - ), - ), - ) + ], + ], + ] ); $query_current = new WP_Query( - array( + [ 'fields' => 'ids', 'post_type' => 'wc_booking', 'numberposts' => -1, 'nopaging' => true, // phpcs:ignore WordPressVIPMinimum.Performance.NoPaging.nopaging_nopaging 'lang' => '', - 'meta_query' => array( - array( + 'meta_query' => [ + [ 'key' => $meta_key, - 'value' => array( $post_id ), + 'value' => [$post_id], 'compare' => 'IN', - ), - ), - ) + ], + ], + ] ); $booking_ids = array_diff($query_translations->posts, $query_current->posts); - if (! empty($booking_ids)) { - $values = array(); + if (!empty($booking_ids)) { + $values = []; foreach ($booking_ids as $booking) { $values[] = $wpdb->prepare('( %d, %s, %d )', $booking, $meta_key, $post_id); } - $wpdb->query("INSERT INTO {$wpdb->postmeta} ( post_id, meta_key, meta_value ) VALUES " . implode(',', $values)); // // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query("INSERT INTO {$wpdb->postmeta} ( post_id, meta_key, meta_value ) VALUES ".implode(',', $values)); // // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared } } } @@ -530,11 +536,12 @@ class PLLWC_Bookings * @param int $post_id Post id. * @param WP_Post $post Post object. * @param array $translations Post translations. + * * @return void */ public function save_post($post_id, $post, $translations) { - $translations = array_diff($translations, array( $post_id )); + $translations = array_diff($translations, [$post_id]); if ('product' === $post->post_type) { $this->add_metas_to_booking($post_id, $translations, '_booking_product_id'); @@ -555,18 +562,20 @@ class PLLWC_Bookings * @param int $post_id Booking id. * @param string $meta_key Meta key. * @param int|string $meta_value Meta value. + * * @return null|bool */ public function update_post_metadata($r, $post_id, $meta_key, $meta_value) { static $once = false; - if (in_array($meta_key, array( '_booking_product_id', '_booking_resource_id' )) && ! empty($meta_value) && ! $once) { + if (in_array($meta_key, ['_booking_product_id', '_booking_resource_id']) && !empty($meta_value) && !$once) { $once = true; $r = $this->update_post_meta($post_id, $meta_key, $meta_value); } $once = false; + return $r; } @@ -578,6 +587,7 @@ class PLLWC_Bookings * @param int $post_id Booking id. * @param string $meta_key Meta key. * @param int $meta_value Product id. + * * @return bool */ protected function update_post_meta($post_id, $meta_key, $meta_value) @@ -590,10 +600,10 @@ class PLLWC_Bookings } } else { $to_keep = array_intersect($values, pll_get_post_translations($meta_value)); - $olds = array_values(array_diff($values, $to_keep)); - $news = array_values(array_diff(pll_get_post_translations($meta_value), $to_keep)); + $olds = array_values(array_diff($values, $to_keep)); + $news = array_values(array_diff(pll_get_post_translations($meta_value), $to_keep)); foreach ($olds as $k => $old) { - update_post_meta($post_id, $meta_key, $news[ $k ], $old); + update_post_meta($post_id, $meta_key, $news[$k], $old); } } @@ -607,18 +617,20 @@ class PLLWC_Bookings * * @param array $persons An array of persons. * @param string $language Language slug. + * * @return array */ protected function translate_booking_persons_meta($persons, $language) { - if (! empty($persons)) { - $_persons = array(); + if (!empty($persons)) { + $_persons = []; foreach ($persons as $person => $n) { - $_persons[ pll_get_post($person, $language) ] = $n; + $_persons[pll_get_post($person, $language)] = $n; } $persons = $_persons; } + return $persons; } @@ -632,45 +644,49 @@ class PLLWC_Bookings * @param int $post_id Booking id. * @param string $meta_key Meta key. * @param bool $single Whether a single meta value has been requested. + * * @return mixed */ public function get_post_metadata($r, $post_id, $meta_key, $single) { static $once = false; - if (! $once && $single) { + if (!$once && $single) { switch ($meta_key) { case '_booking_product_id': case '_booking_resource_id': - $once = true; - $value = get_post_meta($post_id, $meta_key, true); + $once = true; + $value = get_post_meta($post_id, $meta_key, true); $language = PLL() instanceof PLL_Frontend ? pll_current_language() : pll_get_post_language($post_id); - $once = false; + $once = false; + return pll_get_post($value, $language); case '_booking_persons': - $once = true; + $once = true; $value = get_post_meta($post_id, $meta_key, true); - $once = false; - return array( $this->translate_booking_persons_meta($value, pll_get_post_language($post_id)) ); + $once = false; + + return [$this->translate_booking_persons_meta($value, pll_get_post_language($post_id))]; } } - if (! $once && empty($meta_key) && 'wc_booking' === get_post_type($post_id)) { - $once = true; - $value = get_post_meta($post_id); + if (!$once && empty($meta_key) && 'wc_booking' === get_post_type($post_id)) { + $once = true; + $value = get_post_meta($post_id); $language = PLL() instanceof PLL_Frontend ? pll_current_language() : pll_get_post_language($post_id); - foreach (array( '_booking_product_id', '_booking_resource_id' ) as $key) { - if (! empty($value[ $key ])) { - $value[ $key ] = array( pll_get_post(reset($value[ $key ]), $language) ); + foreach (['_booking_product_id', '_booking_resource_id'] as $key) { + if (!empty($value[$key])) { + $value[$key] = [pll_get_post(reset($value[$key]), $language)]; } } if (isset($value['_booking_persons']) && is_array($value['_booking_persons'])) { - $value['_booking_persons'] = array( serialize($this->translate_booking_persons_meta(maybe_unserialize(reset($value['_booking_persons'])), pll_get_post_language($post_id))) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions + $value['_booking_persons'] = [serialize($this->translate_booking_persons_meta(maybe_unserialize(reset($value['_booking_persons'])), pll_get_post_language($post_id)))]; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions } $once = false; + return $value; } @@ -684,11 +700,12 @@ class PLLWC_Bookings * @since 0.6 * * @param string[] $metas List of custom fields names. + * * @return string[] */ public function copy_post_metas($metas) { - $to_sync = array( + $to_sync = [ '_wc_display_cost', '_wc_booking_base_cost', // Renamed to _wc_booking_block_cost, maybe in v1.10.9. '_wc_booking_block_cost', @@ -728,7 +745,7 @@ class PLLWC_Bookings '_wc_booking_restricted_days', // Since 1.10.7. '_resource_base_costs', // To translate. '_resource_block_costs', // To translate. - ); + ]; // wc_booking_resource_label is automatically copied, not synced as public meta. return array_merge($metas, $to_sync); @@ -743,19 +760,21 @@ class PLLWC_Bookings * @param mixed $value Meta value. * @param string $key Meta key. * @param string $lang Language of target. + * * @return mixed */ public function translate_post_meta($value, $key, $lang) { - if (in_array($key, array( '_resource_base_costs', '_resource_block_costs' ))) { - $tr_value = array(); + if (in_array($key, ['_resource_base_costs', '_resource_block_costs'])) { + $tr_value = []; foreach ($value as $post_id => $cost) { if ($tr_id = pll_get_post($post_id, $lang)) { - $tr_value[ $tr_id ] = $cost; + $tr_value[$tr_id] = $cost; } } $value = $tr_value; } + return $value; } @@ -765,11 +784,12 @@ class PLLWC_Bookings * @since 1.8 * * @param array $metas An array of post metas to export. + * * @return array */ public function get_metas_to_translate($metas) { - return array_merge($metas, array( 'wc_booking_resource_label' => 1 )); + return array_merge($metas, ['wc_booking_resource_label' => 1]); } /** @@ -781,66 +801,67 @@ class PLLWC_Bookings * * @param array $item Cart item. * @param string $lang Language code. + * * @return array */ public function translate_cart_item($item, $lang) { - if (! empty($item['booking'])) { - $persons = array(); + if (!empty($item['booking'])) { + $persons = []; $booking = &$item['booking']; // Translate persons types. - if (! empty($booking['_persons'])) { + if (!empty($booking['_persons'])) { foreach ($booking['_persons'] as $id => $n) { $tr_id = pll_get_post($id, $lang); - $persons[ $tr_id ] = $n; - unset($booking[ get_the_title($id) ]); - $booking[ get_the_title($tr_id) ] = $n; + $persons[$tr_id] = $n; + unset($booking[get_the_title($id)]); + $booking[get_the_title($tr_id)] = $n; } $booking['_persons'] = $persons; } // Translate resource. - if (! empty($booking['_resource_id'])) { - $tr_id = pll_get_post($booking['_resource_id'], $lang); + if (!empty($booking['_resource_id'])) { + $tr_id = pll_get_post($booking['_resource_id'], $lang); $booking['_resource_id'] = $tr_id; - $booking['type'] = get_the_title($tr_id); + $booking['type'] = get_the_title($tr_id); } // Translate date. - if (! empty($booking['date']) && ! empty($booking['_date'])) { + if (!empty($booking['date']) && !empty($booking['_date'])) { $booking['date'] = date_i18n(wc_date_format(), strtotime($booking['_date'])); } // Translate time. - if (! empty($booking['time']) && ! empty($booking['_time'])) { + if (!empty($booking['time']) && !empty($booking['_time'])) { $booking['time'] = date_i18n(get_option('time_format'), strtotime("{$booking['_year']}-{$booking['_month']}-{$booking['_day']} {$booking['_time']}")); } // Translate Duration. - if (! empty($booking['duration']) && ! empty($booking['_duration']) && $product = wc_get_product($item['product_id'])) { + if (!empty($booking['duration']) && !empty($booking['_duration']) && $product = wc_get_product($item['product_id'])) { $total_duration = $booking['_duration'] * $product->get_duration(); switch ($booking['_duration_unit']) { case 'month': - $booking['duration'] = $total_duration . ' ' . _n('month', 'months', $total_duration, 'polylang-wc'); + $booking['duration'] = $total_duration.' '._n('month', 'months', $total_duration, 'polylang-wc'); break; case 'day': if ($total_duration % 7) { - $booking['duration'] = $total_duration . ' ' . _n('day', 'days', $total_duration, 'polylang-wc'); + $booking['duration'] = $total_duration.' '._n('day', 'days', $total_duration, 'polylang-wc'); } else { - $booking['duration'] = ($total_duration / 7) . ' ' . _n('week', 'weeks', $total_duration, 'polylang-wc'); + $booking['duration'] = ($total_duration / 7).' '._n('week', 'weeks', $total_duration, 'polylang-wc'); } break; case 'hour': - $booking['duration'] = $total_duration . ' ' . _n('hour', 'hours', $total_duration, 'polylang-wc'); + $booking['duration'] = $total_duration.' '._n('hour', 'hours', $total_duration, 'polylang-wc'); break; case 'minute': - $booking['duration'] = $total_duration . ' ' . _n('minute', 'minutes', $total_duration, 'polylang-wc'); + $booking['duration'] = $total_duration.' '._n('minute', 'minutes', $total_duration, 'polylang-wc'); break; case 'night': - $booking['duration'] = $total_duration . ' ' . _n('night', 'nights', $total_duration, 'polylang-wc'); + $booking['duration'] = $total_duration.' '._n('night', 'nights', $total_duration, 'polylang-wc'); break; default: $booking['duration'] = $total_duration; @@ -849,7 +870,7 @@ class PLLWC_Bookings } // We need to set the price. - if (! empty($item['data']) && ! empty($booking['_cost'])) { + if (!empty($item['data']) && !empty($booking['_cost'])) { $item['data']->set_price($booking['_cost']); } } @@ -865,6 +886,7 @@ class PLLWC_Bookings * * @param array $cart_item_data Cart item data. * @param array $item Cart item. + * * @return array */ public function add_cart_item_data($cart_item_data, $item) @@ -872,6 +894,7 @@ class PLLWC_Bookings if (isset($item['booking'])) { $cart_item_data['booking'] = $item['booking']; } + return $cart_item_data; } @@ -882,6 +905,7 @@ class PLLWC_Bookings * @since 0.6 * * @param WP_Query $query WP_Query object. + * * @return void */ public function filter_bookings_notifications($query) @@ -902,6 +926,7 @@ class PLLWC_Bookings * * @param string $url URL of the translation, to modify. * @param string $lang Language slug. + * * @return string */ public function pll_translation_url($url, $lang) @@ -910,10 +935,10 @@ class PLLWC_Bookings $endpoint = apply_filters('woocommerce_bookings_account_endpoint', 'bookings'); - if (isset(PLL()->translate_slugs->slugs_model, $wp->query_vars[ $endpoint ])) { + if (isset(PLL()->translate_slugs->slugs_model, $wp->query_vars[$endpoint])) { $language = PLL()->model->get_language($lang); - $url = wc_get_endpoint_url($endpoint, '', $url); - $url = PLL()->translate_slugs->slugs_model->switch_translated_slug($url, $language, 'wc_bookings'); + $url = wc_get_endpoint_url($endpoint, '', $url); + $url = PLL()->translate_slugs->slugs_model->switch_translated_slug($url, $language, 'wc_bookings'); } return $url; @@ -927,11 +952,13 @@ class PLLWC_Bookings * @since 0.6 * * @param array $slugs Endpoints slugs. + * * @return array */ public function get_endpoints_query_vars($slugs) { $slugs[] = apply_filters('woocommerce_bookings_account_endpoint', 'bookings'); + return $slugs; } @@ -942,6 +969,7 @@ class PLLWC_Bookings * @since 0.6 * * @param WP_Query $query WP_Query object. + * * @return void */ public function parse_query($query) diff --git a/__plugins/polylang-wc/src/plugins/composite-products.php b/__plugins/polylang-wc/src/plugins/composite-products.php index 2151d4b0fd9e31f5538c88dcdcd83ed8cf637ab8..0920a2f55e32d6f5c32d1cfba4baea10e32db3d7 100644 --- a/__plugins/polylang-wc/src/plugins/composite-products.php +++ b/__plugins/polylang-wc/src/plugins/composite-products.php @@ -1,9 +1,5 @@ array( - '*' => array( + [ + '_bto_data' => [ + '*' => [ 'title' => 1, 'description' => 1, - ), - ), - '_bto_scenario_data' => array( - '*' => array( + ], + ], + '_bto_scenario_data' => [ + '*' => [ 'title' => 1, 'description' => 1, - ), - ), - ) + ], + ], + ] ); } - /** * Keeps the text untouched in synchronized complex metas. * @@ -111,6 +108,7 @@ class PLLWC_Composite_Products * @param array $value Meta value. * @param string $key Meta key. * @param int $product_id Target product id. + * * @return array */ private function maybe_keep_text_in_meta($value, $key, $product_id) @@ -128,12 +126,12 @@ class PLLWC_Composite_Products } foreach (array_keys($value) as $component_id) { - if (! empty($data[ $component_id ]['title'])) { - $value[ $component_id ]['title'] = $data[ $component_id ]['title']; + if (!empty($data[$component_id]['title'])) { + $value[$component_id]['title'] = $data[$component_id]['title']; } - if (! empty($data[ $component_id ]['description'])) { - $value[ $component_id ]['description'] = $data[ $component_id ]['description']; + if (!empty($data[$component_id]['description'])) { + $value[$component_id]['description'] = $data[$component_id]['description']; } } } @@ -152,6 +150,7 @@ class PLLWC_Composite_Products * @param string $lang Target language. * @param int $from Source product id. * @param int $to Target product id. + * * @return array */ public function translate_product_meta($value, $key, $lang, $from, $to) @@ -159,23 +158,23 @@ class PLLWC_Composite_Products switch ($key) { case '_bto_data': $data_store = PLLWC_Data_Store::load('product_language'); - $value = $this->maybe_keep_text_in_meta($value, $key, $to); + $value = $this->maybe_keep_text_in_meta($value, $key, $to); foreach ($value as $component_id => $component) { if (isset($component['assigned_ids'])) { foreach ($component['assigned_ids'] as $k => $product_id) { - $value[ $component_id ]['assigned_ids'][ $k ] = $data_store->get((int) $product_id, $lang); + $value[$component_id]['assigned_ids'][$k] = $data_store->get((int) $product_id, $lang); } } if (isset($component['assigned_category_ids'])) { foreach ($component['assigned_category_ids'] as $k => $category_id) { - $value[ $component_id ]['assigned_category_ids'][ $k ] = pll_get_term($category_id, $lang); + $value[$component_id]['assigned_category_ids'][$k] = pll_get_term($category_id, $lang); } } if (isset($component['default_id'])) { - $value[ $component_id ]['default_id'] = $data_store->get((int) $component['default_id'], $lang); + $value[$component_id]['default_id'] = $data_store->get((int) $component['default_id'], $lang); } } break; @@ -183,12 +182,12 @@ class PLLWC_Composite_Products $value = $this->maybe_keep_text_in_meta($value, $key, $to); foreach ($value as $scenario_id => $scenario) { - $value[ $scenario_id ]['component_data'] = $this->translate_component_ids($scenario['component_data'], $lang); + $value[$scenario_id]['component_data'] = $this->translate_component_ids($scenario['component_data'], $lang); - if (! isset($scenario['scenario_actions']['conditional_options']['component_data'])) { + if (!isset($scenario['scenario_actions']['conditional_options']['component_data'])) { continue; } - $value[ $scenario_id ]['scenario_actions']['conditional_options']['component_data'] = $this->translate_component_ids( + $value[$scenario_id]['scenario_actions']['conditional_options']['component_data'] = $this->translate_component_ids( $scenario['scenario_actions']['conditional_options']['component_data'], $lang ); @@ -196,6 +195,7 @@ class PLLWC_Composite_Products break; } + return $value; } @@ -206,6 +206,7 @@ class PLLWC_Composite_Products * * @param array $component_data The components to translate. * @param string $lang Target language. + * * @return array The translated components. */ private function translate_component_ids(array $component_data, string $lang): array @@ -214,7 +215,7 @@ class PLLWC_Composite_Products foreach ($component_data as $component_id => $products_in_scenario) { foreach ($products_in_scenario as $k => $product_id) { - $component_data[ $component_id ][ $k ] = $data_store->get($product_id, $lang); + $component_data[$component_id][$k] = $data_store->get($product_id, $lang); } } @@ -228,28 +229,29 @@ class PLLWC_Composite_Products * @since 1.3 * * @param array $item Cart item. + * * @return array */ public function translate_cart_item($item) { - if (! empty($item['composite_data'])) { - $composite = &$item['composite_data']; + if (!empty($item['composite_data'])) { + $composite = &$item['composite_data']; $data_store = PLLWC_Data_Store::load('product_language'); foreach (array_keys($composite) as $key) { - $composite[ $key ]['product_id'] = $data_store->get((int) $composite[ $key ]['product_id']); - $composite[ $key ]['composite_id'] = $data_store->get((int) $composite[ $key ]['composite_id']); + $composite[$key]['product_id'] = $data_store->get((int) $composite[$key]['product_id']); + $composite[$key]['composite_id'] = $data_store->get((int) $composite[$key]['composite_id']); - $product = wc_get_product($composite[ $key ]['composite_id']); + $product = wc_get_product($composite[$key]['composite_id']); if ($product && $product instanceof WC_Product_Composite) { $data = $product->get_composite_data(); - $composite[ $key ]['title'] = $data[ $key ]['title']; + $composite[$key]['title'] = $data[$key]['title']; } } } - if (isset($item['composite_parent'], $this->translated_cart_keys[ $item['composite_parent'] ])) { - $item['composite_parent'] = $this->translated_cart_keys[ $item['composite_parent'] ]; + if (isset($item['composite_parent'], $this->translated_cart_keys[$item['composite_parent']])) { + $item['composite_parent'] = $this->translated_cart_keys[$item['composite_parent']]; } return $item; @@ -263,19 +265,20 @@ class PLLWC_Composite_Products * * @param array $cart_item_data Cart item data. * @param array $item Cart item. + * * @return array */ public function add_cart_item_data($cart_item_data, $item) { - $keys = array( + $keys = [ 'composite_children', 'composite_data', 'composite_item', 'composite_parent', - ); + ]; if (isset($item['composite_children'])) { - $item['composite_children'] = array(); + $item['composite_children'] = []; } return array_merge($cart_item_data, array_intersect_key($item, array_flip($keys))); @@ -290,11 +293,12 @@ class PLLWC_Composite_Products * * @param array $item Cart item. * @param string $key Previous cart item key. The new key can be found in $item['key']. + * * @return void */ public function translated_cart_item($item, $key) { - $this->translated_cart_keys[ $key ] = $item['key']; + $this->translated_cart_keys[$key] = $item['key']; } /** @@ -305,22 +309,23 @@ class PLLWC_Composite_Products * @since 1.3 * * @param array $contents Cart contents. + * * @return array */ public function translate_cart_contents($contents) { - $parents = array(); + $parents = []; foreach ($contents as $cart_key => $item) { if (isset($item['composite_parent'])) { - $parents[ $cart_key ] = $item['composite_parent']; + $parents[$cart_key] = $item['composite_parent']; } } - if (! empty($parents)) { + if (!empty($parents)) { foreach ($contents as $cart_key => $item) { if (isset($item['composite_children'])) { - $contents[ $cart_key ]['composite_children'] = array_keys($parents, $item['key']); + $contents[$cart_key]['composite_children'] = array_keys($parents, $item['key']); } } } @@ -339,8 +344,8 @@ class PLLWC_Composite_Products public function cart_loaded_from_session() { foreach (WC()->cart->cart_contents as $cart_key => $item) { - if (! empty($item['data'])) { - WC()->cart->cart_contents[ $cart_key ] = WC_CP_Cart::instance()->add_cart_item_filter($item, $cart_key); + if (!empty($item['data'])) { + WC()->cart->cart_contents[$cart_key] = WC_CP_Cart::instance()->add_cart_item_filter($item, $cart_key); } } } diff --git a/__plugins/polylang-wc/src/plugins/dynamic-pricing.php b/__plugins/polylang-wc/src/plugins/dynamic-pricing.php index f91de577a80bfbb39f75a1a17cf75be13f25e154..c3412713c3aa24696550e094a484297a2800fc17 100644 --- a/__plugins/polylang-wc/src/plugins/dynamic-pricing.php +++ b/__plugins/polylang-wc/src/plugins/dynamic-pricing.php @@ -1,9 +1,5 @@ $rule) { if (isset($rule['collector']['args']['cats'])) { - $cats = array(); + $cats = []; foreach ($rule['collector']['args']['cats'] as $term_id) { $cats[] = pll_get_term($term_id, $lang); } - $pricing_rules[ $k ]['collector']['args']['cats'] = $cats; + $pricing_rules[$k]['collector']['args']['cats'] = $cats; } if (isset($rule['variation_rules']['args']['variations'])) { - $ids = array(); + $ids = []; foreach ($rule['variation_rules']['args']['variations'] as $id) { $ids[] = $data_store->get($id, $lang); } - $pricing_rules[ $k ]['variation_rules']['args']['variations'] = $ids; + $pricing_rules[$k]['variation_rules']['args']['variations'] = $ids; } } } @@ -100,6 +98,7 @@ class PLLWC_Dynamic_Pricing * * @param array $args WP_Term_Query arguments. * @param array $taxonomies Taxonomies used for the terms query. + * * @return array modified arguments */ public function get_terms_args($args, $taxonomies) @@ -107,6 +106,7 @@ class PLLWC_Dynamic_Pricing if (in_array('product_cat', $taxonomies) && empty(PLL()->curlang)) { $args['lang'] = PLL()->options['default_lang']; } + return $args; } @@ -117,6 +117,7 @@ class PLLWC_Dynamic_Pricing * @since 0.5 * * @param array $rules Pricing rules set. + * * @return array */ public function category_pricing_rules($rules) @@ -128,10 +129,11 @@ class PLLWC_Dynamic_Pricing if (isset($rule['collector']['args']['cats'][0])) { $rule['collector']['args']['cats'][0] = pll_get_term($rule['collector']['args']['cats'][0], $lang); } - $rules[ 'set_' . $tr_id ] = $rule; + $rules['set_'.$tr_id] = $rule; } } } + return $rules; } @@ -142,27 +144,29 @@ class PLLWC_Dynamic_Pricing * @since 0.5 * * @param array $rules Pricing rules set. + * * @return array */ public function advanced_category_pricing_rules($rules) { foreach ($rules as $set_id => $rule) { if (isset($rule['collector']['args']['cats'])) { - $cats = array(); + $cats = []; foreach ($rule['collector']['args']['cats'] as $term_id) { $cats = array_merge($cats, array_values(pll_get_term_translations($term_id))); } - $rules[ $set_id ]['collector']['args']['cats'] = $cats; + $rules[$set_id]['collector']['args']['cats'] = $cats; } if (isset($rule['targets'])) { - $cats = array(); + $cats = []; foreach ($rule['targets'] as $term_id) { $cats = array_merge($cats, array_values(pll_get_term_translations($term_id))); } - $rules[ $set_id ]['targets'] = $cats; + $rules[$set_id]['targets'] = $cats; } } + return $rules; } } diff --git a/__plugins/polylang-wc/src/plugins/follow-up-emails.php b/__plugins/polylang-wc/src/plugins/follow-up-emails.php index 9f03691a7d4606d0569d6535817a7c6cc3523f68..bb6f408e570aad83f82f052ed13a501b641ed546 100644 --- a/__plugins/polylang-wc/src/plugins/follow-up-emails.php +++ b/__plugins/polylang-wc/src/plugins/follow-up-emails.php @@ -1,9 +1,5 @@ options['force_lang']) { - add_filter('fue_email_preview_url', array( $this, 'preview_url' )); + add_filter('fue_email_preview_url', [$this, 'preview_url']); } // Email language. - add_action('fue_before_email_send', array( $this, 'before_email_send' ), 10, 4); - add_action('fue_after_email_sent', array( PLLWC()->emails, 'after_email' )); + add_action('fue_before_email_send', [$this, 'before_email_send'], 10, 4); + add_action('fue_after_email_sent', [PLLWC()->emails, 'after_email']); } /** @@ -50,11 +46,13 @@ class PLLWC_Follow_Up_Emails * * @param string[] $types List of post type names for which Polylang manages language and translations. * @param bool $hide True when displaying the list in Polylang settings. + * * @return string[] List of post type names for which Polylang manages language and translations. */ public function translate_types($types, $hide) { - $fue_types = array( 'follow_up_email' ); + $fue_types = ['follow_up_email']; + return $hide ? array_diff($types, $fue_types) : array_merge($types, $fue_types); } @@ -65,11 +63,12 @@ class PLLWC_Follow_Up_Emails * @since 0.9 * * @param string[] $taxonomies List of taxonomies to Synchronize. + * * @return string[] Modified list of taxonomies. */ public function copy_taxonomies($taxonomies) { - return array_merge($taxonomies, array( 'follow_up_email_type', 'follow_up_email_campaign' )); + return array_merge($taxonomies, ['follow_up_email_type', 'follow_up_email_campaign']); } /** @@ -81,12 +80,13 @@ class PLLWC_Follow_Up_Emails * @param string[] $keys List of custom fields names. * @param bool $sync True if it is synchronization, false if it is a copy. * @param int $from Id of the post from which we copy information. + * * @return string[] */ public function copy_post_metas($keys, $sync, $from) { if ('follow_up_email' === get_post_type($from)) { - $to_sync = array( + $to_sync = [ '_template', '_interval_type', '_interval_num', @@ -101,13 +101,13 @@ class PLLWC_Follow_Up_Emails '_category_id', '_product_id', '_meta', - ); + ]; - $to_copy = array( + $to_copy = [ '_tracking_on', '_tracking', '_tracking_code', - ); + ]; if ($sync) { $keys = array_merge($keys, $to_sync); @@ -115,6 +115,7 @@ class PLLWC_Follow_Up_Emails $keys = array_merge($keys, $to_copy, $to_sync); } } + return $keys; } @@ -123,15 +124,17 @@ class PLLWC_Follow_Up_Emails * Hooked to the filter 'pll_translate_post_meta'. * * @since 1.0 + * * @param mixed $value Meta value. * @param string $key Meta key. * @param string $lang Language of target. * @param int $from Id of the follow-up email from which we copy information. + * * @return mixed */ public function translate_post_meta($value, $key, $lang, $from) { - if ('follow_up_email' === get_post_type($from) && ! empty($value)) { + if ('follow_up_email' === get_post_type($from) && !empty($value)) { switch ($key) { case '_category_id': // Translate a product category id. @@ -149,12 +152,12 @@ class PLLWC_Follow_Up_Emails switch ($k) { case 'excluded_customers_products': // Translate an array of product ids. - if (! empty($v)) { - $value[ $k ] = array(); + if (!empty($v)) { + $value[$k] = []; $data_store = PLLWC_Data_Store::load('product_language'); foreach ($v as $product_id) { if ($tr_id = $data_store->get($product_id, $lang)) { - $value[ $k ][] = $tr_id; + $value[$k][] = $tr_id; } } } @@ -162,11 +165,11 @@ class PLLWC_Follow_Up_Emails case 'excluded_categories': case 'excluded_customers_categories': // Translate an array of product category ids. - if (! empty($v)) { - $value[ $k ] = array(); + if (!empty($v)) { + $value[$k] = []; foreach ($v as $term_id) { if ($tr_id = pll_get_term($term_id, $lang)) { - $value[ $k ][] = $tr_id; + $value[$k][] = $tr_id; } } } @@ -179,11 +182,11 @@ class PLLWC_Follow_Up_Emails switch ($v['condition']) { case 'bought_categories': // Translate an array of product category ids. - if (! empty($v['categories'])) { - $value[ $k ]['categories'] = array(); + if (!empty($v['categories'])) { + $value[$k]['categories'] = []; foreach ($v['categories'] as $term_id) { if ($tr_id = pll_get_term($term_id, $lang)) { - $value[ $k ]['categories'][] = $tr_id; + $value[$k]['categories'][] = $tr_id; } } } @@ -205,6 +208,7 @@ class PLLWC_Follow_Up_Emails * @since 0.9 * * @param WP_Query $query WP_Query object. + * * @return void */ public function parse_query($query) @@ -227,16 +231,19 @@ class PLLWC_Follow_Up_Emails * @since 0.9 * * @param array $data Email order data. + * * @return string|bool */ protected function get_email_order_language($data) { - if (! empty($data['order_id'])) { + if (!empty($data['order_id'])) { $data_store = PLLWC_Data_Store::load('order_language'); + return $data_store->get_language($data['order_id']); - } elseif (! empty($data['user_id'])) { + } elseif (!empty($data['user_id'])) { return get_user_meta($data['user_id'], 'locale', true); } + return false; } @@ -247,20 +254,21 @@ class PLLWC_Follow_Up_Emails * @since 0.9 * * @param array $data Email order data. + * * @return array */ public function insert_email_order($data) { $lang = $this->get_email_order_language($data); - if (! empty($lang) && ! empty($data['email_id'])) { + if (!empty($lang) && !empty($data['email_id'])) { if (doing_action('user_register')) { // In this case Follow-Up Emails sends each email only once. if ($tr_id = pll_get_post($data['email_id'], $lang)) { - $args = array( + $args = [ 'email_id' => $tr_id, 'user_id' => $data['user_id'], - ); + ]; if (count(Follow_Up_Emails::instance()->scheduler->get_items($args)) === 0) { $data['email_id'] = $tr_id; @@ -278,6 +286,7 @@ class PLLWC_Follow_Up_Emails $data['email_id'] = 0; } } + return $data; } @@ -288,6 +297,7 @@ class PLLWC_Follow_Up_Emails * @since 0.9 * * @param string $url Preview url. + * * @return string Modified url. */ public function preview_url($url) @@ -295,12 +305,13 @@ class PLLWC_Follow_Up_Emails $query = wp_parse_url($url, PHP_URL_QUERY); parse_str($query, $args); - if (! empty($args['email']) && $lang = pll_get_post_language((int) $args['email'])) { - if (! PLL()->options['hide_default'] || PLL()->options['default_lang'] !== $lang) { + if (!empty($args['email']) && $lang = pll_get_post_language((int) $args['email'])) { + if (!PLL()->options['hide_default'] || PLL()->options['default_lang'] !== $lang) { // Can't use switch_language_in_link() due to the lack of slash before the query. $url = str_replace('?', "/{$lang}?", $url); } } + return $url; } @@ -314,11 +325,12 @@ class PLLWC_Follow_Up_Emails * @param string $message Email message. * @param string $headers Email headers. * @param object $queue_item Email queue item. + * * @return void */ public function before_email_send($subject, $message, $headers, $queue_item) { - if (! empty($queue_item->email_id)) { + if (!empty($queue_item->email_id)) { $language = PLL()->model->post->get_language($queue_item->email_id); PLLWC()->emails->set_email_language($language); } diff --git a/__plugins/polylang-wc/src/plugins/free-gift-coupons.php b/__plugins/polylang-wc/src/plugins/free-gift-coupons.php index 91d96edf86d430786aa6b21d4ac65ac2f5a405cb..9ba0e5b60720d5d25b14c23f9583f674700245d9 100644 --- a/__plugins/polylang-wc/src/plugins/free-gift-coupons.php +++ b/__plugins/polylang-wc/src/plugins/free-gift-coupons.php @@ -1,9 +1,5 @@ $item['free_gift'], 'fgc_quantity' => $item['fgc_quantity'], - ) + ] ); } + return $cart_item_data; } @@ -58,6 +56,7 @@ class PLLWC_Free_Gift_Coupons * @since 1.4 * * @param array $item Cart item. + * * @return array */ public function translate_cart_item($item) diff --git a/__plugins/polylang-wc/src/plugins/germanized.php b/__plugins/polylang-wc/src/plugins/germanized.php index 37847fa085d73b17f567900f8b8eef81f2d342a8..260025375c7b36ca1bf0079479023b1393fed856 100644 --- a/__plugins/polylang-wc/src/plugins/germanized.php +++ b/__plugins/polylang-wc/src/plugins/germanized.php @@ -1,9 +1,5 @@ has_custom_db = class_exists('WC_MNM_Compatibility') && WC_MNM_Compatibility::is_db_version_gte('2.0'); // Product synchronization. - add_filter('pllwc_copy_post_metas', array( $this, 'copy_product_metas' )); - add_filter('pllwc_translate_product_meta', array( $this, 'translate_product_meta' ), 10, 3); + add_filter('pllwc_copy_post_metas', [$this, 'copy_product_metas']); + add_filter('pllwc_translate_product_meta', [$this, 'translate_product_meta'], 10, 3); if ($this->has_custom_db) { - add_action('pllwc_copy_product', array( $this, 'copy_product' ), 10, 3); + add_action('pllwc_copy_product', [$this, 'copy_product'], 10, 3); } // Cart. - add_filter('pllwc_translate_cart_item', array( $this, 'translate_cart_item' ), 10, 2); - add_filter('pllwc_add_cart_item_data', array( $this, 'add_cart_item_data' ), 10, 2); - add_action('pllwc_translated_cart_item', array( $this, 'translated_cart_item' ), 10, 2); - add_filter('pllwc_translate_cart_contents', array( $this, 'translate_cart_contents' )); - add_action('woocommerce_cart_loaded_from_session', array( $this, 'cart_loaded_from_session' ), 20); // After PLLWC_Frontend_Cart. + add_filter('pllwc_translate_cart_item', [$this, 'translate_cart_item'], 10, 2); + add_filter('pllwc_add_cart_item_data', [$this, 'add_cart_item_data'], 10, 2); + add_action('pllwc_translated_cart_item', [$this, 'translated_cart_item'], 10, 2); + add_filter('pllwc_translate_cart_contents', [$this, 'translate_cart_contents']); + add_action('woocommerce_cart_loaded_from_session', [$this, 'cart_loaded_from_session'], 20); // After PLLWC_Frontend_Cart. } /** @@ -67,6 +63,7 @@ class PLLWC_Mix_Match * @since 1.1 * * @param string[] $metas List of custom fields names. + * * @return string[] */ public function copy_product_metas($metas) @@ -74,7 +71,7 @@ class PLLWC_Mix_Match if ($this->has_custom_db) { return array_merge( $metas, - array( + [ '_mnm_base_price' => '_mnm_base_price', '_mnm_base_regular_price' => '_mnm_base_regular_price', '_mnm_base_sale_price' => '_mnm_base_sale_price', @@ -90,12 +87,12 @@ class PLLWC_Mix_Match '_mnm_packing_mode' => '_mnm_packing_mode', '_mnm_per_product_discount' => '_mnm_per_product_discount', '_mnm_weight_cumulative' => '_mnm_weight_cumulative', - ) + ] ); } else { return array_merge( $metas, - array( + [ '_mnm_base_price' => '_mnm_base_price', '_mnm_base_regular_price' => '_mnm_base_regular_price', '_mnm_base_sale_price' => '_mnm_base_sale_price', @@ -105,7 +102,7 @@ class PLLWC_Mix_Match // Only M&M < 2.0. '_mnm_data' => '_mnm_data', '_mnm_per_product_shipping' => '_mnm_per_product_shipping', - ) + ] ); } } @@ -116,9 +113,10 @@ class PLLWC_Mix_Match * * @since 1.1 * - * @param mixed $value Meta value. - * @param string $key Meta key. - * @param string $lang Language of target. + * @param mixed $value Meta value. + * @param string $key Meta key. + * @param string $lang Language of target. + * * @return mixed */ public function translate_product_meta($value, $key, $lang) @@ -126,15 +124,15 @@ class PLLWC_Mix_Match switch ($key) { case '_mnm_child_category_ids': // For MNM 2.x category contents. - if (empty($value) || ! is_array($value)) { + if (empty($value) || !is_array($value)) { // An array of IDs is expected. - return array(); + return []; } - $out = array(); + $out = []; foreach ($value as $category_id) { - if (! is_numeric($category_id) || $category_id <= 0) { + if (!is_numeric($category_id) || $category_id <= 0) { continue; } @@ -150,40 +148,40 @@ class PLLWC_Mix_Match * * @see: PLLWC_Mix_Match::copy_product() */ - if (empty($value) || ! is_array($value)) { + if (empty($value) || !is_array($value)) { // An array of IDs is expected. - return array(); + return []; } - $out = array(); + $out = []; $data_store = PLLWC_Data_Store::load('product_language'); foreach ($value as $post_id => $data) { - if (! is_numeric($post_id) || $post_id <= 0) { + if (!is_numeric($post_id) || $post_id <= 0) { continue; } $tr_id = $data_store->get($post_id, $lang); if (empty($tr_id)) { - $out[ $post_id ] = $data; + $out[$post_id] = $data; continue; } - $tr_product_id = $tr_id; + $tr_product_id = $tr_id; $tr_variation_id = 0; // If a variation, need to also translate the parent ID. - if (! empty($data['product_id']) && ! empty($data['variation_id'])) { - $tr_product_id = $data_store->get($data['product_id'], $lang); + if (!empty($data['product_id']) && !empty($data['variation_id'])) { + $tr_product_id = $data_store->get($data['product_id'], $lang); $tr_variation_id = $tr_id; } - $out[ $tr_id ] = array( + $out[$tr_id] = [ 'child_id' => $tr_id, 'product_id' => $tr_product_id, 'variation_id' => $tr_variation_id, - ); + ]; } $value = $out; @@ -202,6 +200,7 @@ class PLLWC_Mix_Match * @param int $from Id of the post from which we copy information. * @param int $to Id of the post to which we paste information. * @param string $lang language slug. + * * @return void */ public function copy_product($from, $to, $lang) @@ -211,9 +210,9 @@ class PLLWC_Mix_Match * * @var array Post IDs as array keys. 1 as values */ - static $copying_products = array(); + static $copying_products = []; - if (isset($copying_products[ $from ])) { + if (isset($copying_products[$from])) { // Prevent an infinite loop. return; } @@ -221,7 +220,7 @@ class PLLWC_Mix_Match /** @var WC_Product_Mix_and_Match|null|false $from_product */ $from_product = wc_get_product($from); - if (empty($from_product) || ! $from_product->is_type('mix-and-match')) { + if (empty($from_product) || !$from_product->is_type('mix-and-match')) { return; } @@ -231,10 +230,10 @@ class PLLWC_Mix_Match return; } - $copying_products[ $from ] = 1; + $copying_products[$from] = 1; $data_store = PLLWC_Data_Store::load('product_language'); - $tr_items = array(); + $tr_items = []; foreach ($from_product->get_child_items() as $item) { $tr_product_id = $data_store->get($item->get_product_id(), $lang); @@ -243,25 +242,25 @@ class PLLWC_Mix_Match $tr_variation_id = $data_store->get($item->get_variation_id(), $lang); if ($tr_product_id && $tr_variation_id) { - $tr_items[] = array( + $tr_items[] = [ 'product_id' => $tr_product_id, 'variation_id' => $tr_variation_id, - ); + ]; } } elseif ($tr_product_id) { - $tr_items[] = array( + $tr_items[] = [ 'product_id' => $tr_product_id, 'variation_id' => 0, - ); + ]; } } - if (! empty($tr_items)) { + if (!empty($tr_items)) { $to_product->set_child_items($tr_items); $to_product->save(); } - unset($copying_products[ $from ]); + unset($copying_products[$from]); } /** @@ -272,20 +271,22 @@ class PLLWC_Mix_Match * * @param array $item Cart item. * @param string $lang Language code. + * * @return array + * * @phpstan-param CartItem $item * @phpstan-param string $lang */ public function translate_cart_item($item, $lang = '') { // `wc_mnm_is_container_cart_item()` and `wc_mnm_maybe_is_child_cart_item()` were introoduced in M&M 1.7. - if (! function_exists('wc_mnm_is_container_cart_item')) { + if (!function_exists('wc_mnm_is_container_cart_item')) { return $item; } if (wc_mnm_is_container_cart_item($item)) { $lang = PLL()->model->get_language($lang); - if (! $lang) { + if (!$lang) { return $item; } @@ -294,11 +295,11 @@ class PLLWC_Mix_Match if (isset($item['mnm_contents'])) { // Stash the content keys for later. Cannot translate now as the child products have not yet been translated. $item['mnm_contents_tr'] = $item['mnm_contents']; - $item['mnm_contents'] = array(); + $item['mnm_contents'] = []; } } elseif (wc_mnm_maybe_is_child_cart_item($item)) { - if (isset($item['mnm_container'], $this->translated_cart_keys[ $item['mnm_container'] ])) { - $item['mnm_container'] = $this->translated_cart_keys[ $item['mnm_container'] ]; + if (isset($item['mnm_container'], $this->translated_cart_keys[$item['mnm_container']])) { + $item['mnm_container'] = $this->translated_cart_keys[$item['mnm_container']]; } } @@ -310,8 +311,9 @@ class PLLWC_Mix_Match * * @since 1.7 * - * @param array $config Config. - * @param PLL_Language $lang Language. + * @param array $config Config. + * @param PLL_Language $lang Language. + * * @return array,array{ * product_id: int<0,max>, * variation_id: int<0,max>, @@ -320,11 +322,11 @@ class PLLWC_Mix_Match */ protected function translate_config($config, PLL_Language $lang) { - $tr_config = array(); + $tr_config = []; foreach ($config as $row) { - $row = (new Item($row))->translate($lang); - $tr_config[ $row['product_id'] ] = $row; + $row = (new Item($row))->translate($lang); + $tr_config[$row['product_id']] = $row; } return $tr_config; @@ -338,15 +340,17 @@ class PLLWC_Mix_Match * * @param array $cart_item_data Cart item data. * @param array $item Cart item. + * * @return array */ public function add_cart_item_data($cart_item_data, $item) { - $keys = array( + $keys = [ 'mnm_config', 'mnm_contents', 'mnm_container', - ); + ]; + return array_merge($cart_item_data, array_intersect_key($item, array_flip($keys))); } @@ -359,11 +363,12 @@ class PLLWC_Mix_Match * * @param array $item Cart item. * @param string $key Previous cart item key. The new key can be found in $item['key']. + * * @return void */ public function translated_cart_item($item, $key) { - $this->translated_cart_keys[ $key ] = $item['key']; + $this->translated_cart_keys[$key] = $item['key']; } /** @@ -374,6 +379,7 @@ class PLLWC_Mix_Match * @since 1.1 * * @param array $contents Cart contents. + * * @return array */ public function translate_cart_contents($contents) @@ -383,11 +389,11 @@ class PLLWC_Mix_Match } foreach ($contents as $key => $cart_item) { - if (! wc_mnm_is_container_cart_item($cart_item) || empty($cart_item['mnm_contents_tr'])) { + if (!wc_mnm_is_container_cart_item($cart_item) || empty($cart_item['mnm_contents_tr'])) { continue; } - $contents[ $key ]['mnm_contents'] = array_unique( + $contents[$key]['mnm_contents'] = array_unique( array_keys( array_intersect( array_flip($this->translated_cart_keys), @@ -395,7 +401,7 @@ class PLLWC_Mix_Match ) ) ); - unset($contents[ $key ]['mnm_contents_tr']); + unset($contents[$key]['mnm_contents_tr']); } return $contents; @@ -419,7 +425,7 @@ class PLLWC_Mix_Match continue; } - WC()->cart->cart_contents[ $cart_key ] = $mnm_cart->add_cart_item_filter($item, $cart_key); + WC()->cart->cart_contents[$cart_key] = $mnm_cart->add_cart_item_filter($item, $cart_key); } } } diff --git a/__plugins/polylang-wc/src/plugins/plugins-compat.php b/__plugins/polylang-wc/src/plugins/plugins-compat.php index 4b2c0fa459de6ea4b307c321b56a59878af915e2..e53497451f4dba62fdd892e7bab1ab02a68210d4 100644 --- a/__plugins/polylang-wc/src/plugins/plugins-compat.php +++ b/__plugins/polylang-wc/src/plugins/plugins-compat.php @@ -1,9 +1,5 @@ stock_manager = new PLLWC_Stock_Manager(); } @@ -190,16 +186,16 @@ class PLLWC_Plugins_Compat } // special case for WC brands. - add_action('plugins_loaded', array( $this, 'init_wc_brand' ), 20); + add_action('plugins_loaded', [$this, 'init_wc_brand'], 20); // Special case for Checkout Field Editor which defines constant in a function hooked to 'init'. - add_action('init', array( $this, 'maybe_init_wcfd' ), 20); + add_action('init', [$this, 'maybe_init_wcfd'], 20); // WC Free Gift Coupons initializes itself after us. - add_action('init', array( $this, 'maybe_init_fgc' )); + add_action('init', [$this, 'maybe_init_fgc']); // WC Mix and Match Products initializes itself after us. - add_action('init', array( $this, 'maybe_init_mnm' )); + add_action('init', [$this, 'maybe_init_mnm']); } /** @@ -214,10 +210,11 @@ class PLLWC_Plugins_Compat if (defined('WC_BRANDS_VERSION')) { // Backward compatibility with WC < 9.4, before it is merged into WC's core. $this->brands = new PLLWC_Brands(); + return; } - if (! method_exists(Packages::class, 'is_package_enabled') || ! Packages::is_package_enabled('woocommerce-brands')) { + if (!method_exists(Packages::class, 'is_package_enabled') || !Packages::is_package_enabled('woocommerce-brands')) { // The method `Packages::is_package_enabled()` was introduced in WC 9.4. return; } diff --git a/__plugins/polylang-wc/src/plugins/product-bundles.php b/__plugins/polylang-wc/src/plugins/product-bundles.php index c09d9a44ac06d3140a0210f8750a32c9149df8db..519f66cf0776f0b7fcccc25e5759f3e62c4cfa05 100644 --- a/__plugins/polylang-wc/src/plugins/product-bundles.php +++ b/__plugins/polylang-wc/src/plugins/product-bundles.php @@ -1,9 +1,5 @@ get_type()) { + if (!$from || 'bundle' !== $from->get_type()) { return; } @@ -77,15 +74,15 @@ class PLLWC_Product_Bundles // Remember the current items in translated bundle to synchronize the deleted items. $to = new WC_Product_Bundle($to); - $_translated_bundle_item_ids = array(); + $_translated_bundle_item_ids = []; foreach ($to->get_bundled_data_items() as $item) { - $_translated_bundle_item_ids[ $item->get_product_id() ] = $item->get_bundled_item_id(); + $_translated_bundle_item_ids[$item->get_product_id()] = $item->get_bundled_item_id(); } - $tr_ids = array(); + $tr_ids = []; // Invalidate the bundled data items in case a bundled item has been deleted. - $cache_key = WC_Cache_Helper::get_cache_prefix('bundled_data_items') . $from->get_id(); + $cache_key = WC_Cache_Helper::get_cache_prefix('bundled_data_items').$from->get_id(); wp_cache_delete($cache_key, 'bundled_data_items'); foreach ($from->get_bundled_data_items() as $item) { @@ -100,57 +97,57 @@ class PLLWC_Product_Bundles $meta_data = $item->get_meta_data(); $meta_data['bundled_id'] = $to->get_id(); - if (! empty($meta_data['allowed_variations'])) { + if (!empty($meta_data['allowed_variations'])) { foreach ($meta_data['allowed_variations'] as $k => $variation_id) { - $meta_data['allowed_variations'][ $k ] = $data_store->get($variation_id, $lang); + $meta_data['allowed_variations'][$k] = $data_store->get($variation_id, $lang); } } - if (! empty($meta_data['default_variation_attributes'])) { + if (!empty($meta_data['default_variation_attributes'])) { // FIXME Copy paste of PLLWC_Admin_Products::copy_default_attributes(). foreach ($meta_data['default_variation_attributes'] as $k => $v) { - if (! taxonomy_exists($k)) { + if (!taxonomy_exists($k)) { continue; } - $terms = get_terms(array( 'taxonomy' => $k, 'slug' => $v, 'lang' => '' )); // Don't use get_term_by filtered by language since WP 4.7. - if (! is_array($terms)) { + $terms = get_terms(['taxonomy' => $k, 'slug' => $v, 'lang' => '']); // Don't use get_term_by filtered by language since WP 4.7. + if (!is_array($terms)) { continue; } $term = reset($terms); - if (! $term) { + if (!$term) { continue; } $tr_term_id = pll_get_term($term->term_id, $lang); - if (! empty($tr_term_id)) { + if (!empty($tr_term_id)) { $term = get_term($tr_term_id, $k); - $meta_data['default_variation_attributes'][ $k ] = $term->slug; + $meta_data['default_variation_attributes'][$k] = $term->slug; } } } if ($sync) { - $meta_data = array_diff_key($meta_data, array_flip(array( 'title', 'description' ))); // Copy, don't sync. + $meta_data = array_diff_key($meta_data, array_flip(['title', 'description'])); // Copy, don't sync. } // Copy or update. - if (isset($_translated_bundle_item_ids[ $tr_id ])) { + if (isset($_translated_bundle_item_ids[$tr_id])) { WC_PB_DB::update_bundled_item( - $_translated_bundle_item_ids[ $tr_id ], - array( + $_translated_bundle_item_ids[$tr_id], + [ 'menu_order' => $item->get_menu_order(), 'meta_data' => $meta_data, - ) + ] ); } else { WC_PB_DB::add_bundled_item( - array( + [ 'bundle_id' => $to->get_id(), 'product_id' => $tr_id, 'menu_order' => $item->get_menu_order(), 'meta_data' => $meta_data, - ) + ] ); } } @@ -158,7 +155,7 @@ class PLLWC_Product_Bundles // Synchronize deleted items. if ($sync) { foreach ($_translated_bundle_item_ids as $tr_id => $item) { - if (! in_array($tr_id, $tr_ids)) { + if (!in_array($tr_id, $tr_ids)) { WC_PB_DB::delete_bundled_item($item); } } @@ -172,11 +169,12 @@ class PLLWC_Product_Bundles * @since 1.1 * * @param string[] $metas List of custom fields names. + * * @return string[] */ public function copy_product_metas($metas) { - $to_sync = array( + $to_sync = [ '_wc_pb_edit_in_cart', '_wc_pb_base_regular_price', '_wc_pb_base_sale_price', @@ -187,7 +185,7 @@ class PLLWC_Product_Bundles '_wc_pb_add_to_cart_form_location', '_wc_pb_bundle_sells_discount', '_wc_pb_bundle_sell_ids', - ); + ]; return array_merge($metas, array_combine($to_sync, $to_sync)); } @@ -198,11 +196,12 @@ class PLLWC_Product_Bundles * @since 2.2 * * @param array $metas An array of product metas to translate. + * * @return array */ public function get_metas_to_translate($metas) { - return array_merge($metas, array( '_wc_pb_bundle_sells_title' => 1 )); + return array_merge($metas, ['_wc_pb_bundle_sells_title' => 1]); } /** @@ -214,6 +213,7 @@ class PLLWC_Product_Bundles * @param mixed $value Meta value. * @param string $key Meta key. * @param string $lang Target language. + * * @return mixed */ public function translate_post_meta($value, $key, $lang) @@ -222,8 +222,8 @@ class PLLWC_Product_Bundles return $value; } - $data_store = PLLWC_Data_Store::load('product_language'); - $bundle_sells_tr_ids = array(); + $data_store = PLLWC_Data_Store::load('product_language'); + $bundle_sells_tr_ids = []; foreach ($value as $product_id) { $tr_id = $data_store->get($product_id, $lang); if (empty($tr_id)) { @@ -243,57 +243,58 @@ class PLLWC_Product_Bundles * * @param array $item Cart item. * @param string $lang Language code. + * * @return array */ protected function translate_stamp($item, $lang) { $lang = PLL()->model->get_language($lang); - if (! $lang) { + if (!$lang) { return $item['stamp']; } - $product_ids = array(); - $tr_stamp = array(); - $data_store = PLLWC_Data_Store::load('product_language'); + $product_ids = []; + $tr_stamp = []; + $data_store = PLLWC_Data_Store::load('product_language'); - if (isset($item['bundled_by'], $this->stamps[ $item['bundled_by'] ])) { - return $this->stamps[ $item['bundled_by'] ]; + if (isset($item['bundled_by'], $this->stamps[$item['bundled_by']])) { + return $this->stamps[$item['bundled_by']]; } foreach (wp_list_pluck($item['stamp'], 'product_id') as $product_id) { $product_ids[] = $data_store->get($product_id, $lang); } - $args = array( + $args = [ 'product_id' => $product_ids, 'bundle_id' => $data_store->get($item['product_id'], $lang), 'return' => 'id=>product_id', - ); + ]; $bundled_items = WC_PB_DB::query_bundled_items($args); $bundled_items = array_flip($bundled_items); foreach ($item['stamp'] as $s) { $orig_lang = PLL()->model->get_language((string) $data_store->get_language($s['product_id'])); - if (! $orig_lang) { + if (!$orig_lang) { continue; } $tr_id = $data_store->get($s['product_id'], $lang); - if ($tr_id && ! empty($bundled_items[ $tr_id ])) { - $bundled_item = $bundled_items[ $tr_id ]; + if ($tr_id && !empty($bundled_items[$tr_id])) { + $bundled_item = $bundled_items[$tr_id]; $s['product_id'] = $tr_id; // Variations. - if (! empty($s['variation_id'])) { + if (!empty($s['variation_id'])) { $tr_var_id = $data_store->get($s['variation_id'], $lang); $s['variation_id'] = $tr_var_id; } // Variations attributes. - if (! empty($s['attributes'])) { + if (!empty($s['attributes'])) { $s['attributes'] = (new Item($s))->translate_attributes($s['attributes'], $lang, $orig_lang); } @@ -302,12 +303,12 @@ class PLLWC_Product_Bundles $s['title'] = $title; } - $tr_stamp[ $bundled_item ] = $s; + $tr_stamp[$bundled_item] = $s; } } $tr_stamp = empty($tr_stamp) ? $item['stamp'] : $tr_stamp; - $this->stamps[ $item['key'] ] = $tr_stamp; + $this->stamps[$item['key']] = $tr_stamp; return $tr_stamp; } @@ -320,21 +321,21 @@ class PLLWC_Product_Bundles * * @param array $item Cart item. * @param string $lang Language code. + * * @return array */ public function translate_cart_item($item, $lang) { - if (isset($item['stamp'])) { $item['stamp'] = $this->translate_stamp($item, $lang); } if (isset($item['bundled_items'])) { - $item['bundled_items'] = array(); + $item['bundled_items'] = []; } - if (isset($item['bundled_by'], $this->translated_cart_keys[ $item['bundled_by'] ])) { - $item['bundled_by'] = $this->translated_cart_keys[ $item['bundled_by'] ]; + if (isset($item['bundled_by'], $this->translated_cart_keys[$item['bundled_by']])) { + $item['bundled_by'] = $this->translated_cart_keys[$item['bundled_by']]; } if (isset($item['bundled_item_id'])) { @@ -353,16 +354,18 @@ class PLLWC_Product_Bundles * * @param array $cart_item_data Cart item data. * @param array $item Cart item. + * * @return array */ public function add_cart_item_data($cart_item_data, $item) { - $keys = array( + $keys = [ 'bundled_by', 'bundled_items', 'bundled_item_id', 'stamp', - ); + ]; + return array_merge($cart_item_data, array_intersect_key($item, array_flip($keys))); } @@ -375,11 +378,12 @@ class PLLWC_Product_Bundles * * @param array $item Cart item. * @param string $key Previous cart item key. The new key can be found in $item['key']. + * * @return void */ public function translated_cart_item($item, $key) { - $this->translated_cart_keys[ $key ] = $item['key']; + $this->translated_cart_keys[$key] = $item['key']; } /** @@ -390,22 +394,23 @@ class PLLWC_Product_Bundles * @since 1.1 * * @param array $contents Cart contents. + * * @return array */ public function translate_cart_contents($contents) { - $bundled_by = array(); + $bundled_by = []; foreach ($contents as $cart_key => $item) { if (isset($item['bundled_by'])) { - $bundled_by[ $cart_key ] = $item['bundled_by']; + $bundled_by[$cart_key] = $item['bundled_by']; } } - if (! empty($bundled_by)) { + if (!empty($bundled_by)) { foreach ($contents as $cart_key => $item) { if (isset($item['bundled_items'])) { - $contents[ $cart_key ]['bundled_items'] = array_keys($bundled_by, $item['key']); + $contents[$cart_key]['bundled_items'] = array_keys($bundled_by, $item['key']); } } } @@ -427,8 +432,8 @@ class PLLWC_Product_Bundles public function cart_loaded_from_session() { foreach (WC()->cart->cart_contents as $cart_key => $item) { - if (! empty($item['data'])) { - WC()->cart->cart_contents[ $cart_key ] = WC_PB_Cart::instance()->add_cart_item_filter($item, $cart_key); + if (!empty($item['data'])) { + WC()->cart->cart_contents[$cart_key] = WC_PB_Cart::instance()->add_cart_item_filter($item, $cart_key); } } } diff --git a/__plugins/polylang-wc/src/plugins/shipment-tracking.php b/__plugins/polylang-wc/src/plugins/shipment-tracking.php index 2a7a9b943d0f69cae64d9611d00ffb43a420d89f..8e92f2abad56429b7a8cd4a0b387b501c2ca9c77 100644 --- a/__plugins/polylang-wc/src/plugins/shipment-tracking.php +++ b/__plugins/polylang-wc/src/plugins/shipment-tracking.php @@ -1,9 +1,5 @@ query_vars; - if (! $this->is_language_in_query($qvars) && $this->is_product_in_query($qvars)) { + if (!$this->is_language_in_query($qvars) && $this->is_product_in_query($qvars)) { $query->query_vars['lang'] = PLLWC_Admin::get_preferred_language(); } } diff --git a/__plugins/polylang-wc/src/plugins/stripe.php b/__plugins/polylang-wc/src/plugins/stripe.php index abd783a9ce988f7868231e589e90b03ee8919824..08a30a0b1b457b6d907ee1cdd6aa5e33e7d4f1c4 100644 --- a/__plugins/polylang-wc/src/plugins/stripe.php +++ b/__plugins/polylang-wc/src/plugins/stripe.php @@ -1,9 +1,5 @@ testmode) { /* translators: %s is a link to the Stripe documentation */ - $description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "Testing Stripe" for more card numbers.', 'polylang-wc'), 'https://stripe.com/docs/testing'); - $description = trim($description); + $description .= ' '.sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "Testing Stripe" for more card numbers.', 'polylang-wc'), 'https://stripe.com/docs/testing'); + $description = trim($description); } } + return $description; } } diff --git a/__plugins/polylang-wc/src/plugins/subscriptions.php b/__plugins/polylang-wc/src/plugins/subscriptions.php index b87e358358f12525068ad605523e07f732587ad6..9e9701f3d13fab7d2fa39d1ab86abf099f8a8e24 100644 --- a/__plugins/polylang-wc/src/plugins/subscriptions.php +++ b/__plugins/polylang-wc/src/plugins/subscriptions.php @@ -1,9 +1,5 @@ admin_orders instanceof PLLWC_Admin_Orders_HPOS) { - add_action('woocommerce_after_subscription_object_save', array( PLLWC()->admin_orders, 'save_order_language' )); + add_action('woocommerce_after_subscription_object_save', [PLLWC()->admin_orders, 'save_order_language']); } if (version_compare($GLOBALS['wp_version'], '6.7-beta') < 0) { // Backward compatibility with WP < 6.7. - add_action('change_locale', array( $this, 'change_locale' )); + add_action('change_locale', [$this, 'change_locale']); } if (PLL() instanceof PLL_Frontend) { - add_action('parse_query', array( $this, 'parse_query' ), 3); // Before Polylang. + add_action('parse_query', [$this, 'parse_query'], 3); // Before Polylang. } // Strings translations. - add_filter('pll_sanitize_string_translation', array( $this, 'sanitize_strings' ), 10, 3); - add_action('init', array( $this, 'register_strings' )); + add_filter('pll_sanitize_string_translation', [$this, 'sanitize_strings'], 10, 3); + add_action('init', [$this, 'register_strings']); // Endpoints. - add_filter('pll_translation_url', array( $this, 'pll_translation_url' ), 10, 2); + add_filter('pll_translation_url', [$this, 'pll_translation_url'], 10, 2); // Check if a user has a subscription. - add_filter('wcs_user_has_subscription', array( $this, 'user_has_subscription' ), 10, 4); - add_filter('woocommerce_get_subscriptions_query_args', array( $this, 'get_subscriptions_query_args' ), 10, 2); + add_filter('wcs_user_has_subscription', [$this, 'user_has_subscription'], 10, 4); + add_filter('woocommerce_get_subscriptions_query_args', [$this, 'get_subscriptions_query_args'], 10, 2); // Variable subscription products. - add_action('wp_trash_post', array( $this, 'delete_variation' )); - add_action('before_delete_post', array( $this, 'delete_variation' )); + add_action('wp_trash_post', [$this, 'delete_variation']); + add_action('before_delete_post', [$this, 'delete_variation']); // Work around endpoints options added in wpml-config.xml :/. - remove_filter('option_woocommerce_myaccount_subscriptions_endpoint', array( PLL_WPML_Config::instance(), 'translate_strings' )); - remove_filter('option_woocommerce_myaccount_view_subscription_endpoint', array( PLL_WPML_Config::instance(), 'translate_strings' )); + remove_filter('option_woocommerce_myaccount_subscriptions_endpoint', [PLL_WPML_Config::instance(), 'translate_strings']); + remove_filter('option_woocommerce_myaccount_view_subscription_endpoint', [PLL_WPML_Config::instance(), 'translate_strings']); // Add e-mails for translation. - add_filter('pllwc_order_email_actions', array( $this, 'filter_order_email_actions' )); + add_filter('pllwc_order_email_actions', [$this, 'filter_order_email_actions']); // Translate slugs for endpoints. - add_action('plugins_loaded', array( $this, 'add_query_vars' ), 20); // After `WC_Subscriptions_Core_Plugin::init_version_dependant_classes()` (prio 10). + add_action('plugins_loaded', [$this, 'add_query_vars'], 20); // After `WC_Subscriptions_Core_Plugin::init_version_dependant_classes()` (prio 10). } /** @@ -73,13 +69,14 @@ class PLLWC_Subscriptions * @since 1.6 * * @param string[] $actions Array of actions used to send emails. + * * @return string[] */ public function filter_order_email_actions($actions) { return array_merge( $actions, - array( + [ // Cancelled subscription. 'cancelled_subscription_notification', // Customer completed order. @@ -111,7 +108,7 @@ class PLLWC_Subscriptions 'woocommerce_subscriptions_switch_completed_switch_notification', // Suspended Subscription. 'on-hold_subscription_notification', // Since WCS 2.1. - ) + ] ); } @@ -122,11 +119,12 @@ class PLLWC_Subscriptions * @since 0.4 * * @param array $keys List of custom fields names. + * * @return array */ public function copy_post_metas($keys) { - $wcs_keys = array( + $wcs_keys = [ '_subscription_payment_sync_date', '_subscription_length', '_subscription_limit', @@ -136,7 +134,8 @@ class PLLWC_Subscriptions '_subscription_sign_up_fee', '_subscription_trial_length', '_subscription_trial_period', - ); + ]; + return array_merge($keys, $wcs_keys); } @@ -147,11 +146,12 @@ class PLLWC_Subscriptions * @since 0.4 * * @param array $types List of post type names for which Polylang manages language and translations. + * * @return array List of post type names for which Polylang manages language and translations. */ public function translate_types($types) { - return array_merge($types, array( 'shop_subscription' )); + return array_merge($types, ['shop_subscription']); } /** @@ -162,6 +162,7 @@ class PLLWC_Subscriptions * * @param object $new_order New order. * @param object $subscription Parent subscription. + * * @return object Unmodified order */ public function new_order_created($new_order, $subscription) @@ -170,6 +171,7 @@ class PLLWC_Subscriptions $data_store = PLLWC_Data_Store::load('order_language'); $data_store->set_language($new_order->get_id(), $lang); } + return $new_order; } @@ -197,23 +199,23 @@ class PLLWC_Subscriptions */ public function register_strings(): void { - $options = array( + $options = [ 'add_to_cart_button_text' => __('Add to Cart Button Text', 'polylang-wc'), 'order_button_text' => __('Place Order Button Text', 'polylang-wc'), 'switch_button_text' => __('Switch Button Text', 'polylang-wc'), - ); + ]; foreach ($options as $option => $name) { if (PLL() instanceof PLL_Frontend) { - add_filter('option_woocommerce_subscriptions_' . $option, 'pll__'); + add_filter('option_woocommerce_subscriptions_'.$option, 'pll__'); continue; } - if (! PLL() instanceof PLL_Admin_Base) { + if (!PLL() instanceof PLL_Admin_Base) { continue; } - $string = get_option('woocommerce_subscriptions_' . $option); + $string = get_option('woocommerce_subscriptions_'.$option); if (empty($string)) { continue; @@ -232,6 +234,7 @@ class PLLWC_Subscriptions * @param string $translation A string translation. * @param string $name The string name. * @param string $context The group the string belongs to. + * * @return string Sanitized translation */ public function sanitize_strings($translation, $name, $context) @@ -239,6 +242,7 @@ class PLLWC_Subscriptions if ('WooCommerce Subscriptions' === $context) { $translation = wp_kses_post(trim($translation)); } + return $translation; } @@ -249,6 +253,7 @@ class PLLWC_Subscriptions * @since 0.4 * * @param WP_Query $query WP_Query object. + * * @return void */ public function parse_query($query) @@ -270,19 +275,20 @@ class PLLWC_Subscriptions * * @param string $url URL of the translation, to modify. * @param string $lang Language slug. + * * @return string */ public function pll_translation_url($url, $lang) { if ($url && defined('POLYLANG_PRO') && POLYLANG_PRO && get_option('permalink_structure')) { - $wcs_query = pll_get_anonymous_object_from_filter('init', array( 'WCS_Query', 'add_endpoints' )); + $wcs_query = pll_get_anonymous_object_from_filter('init', ['WCS_Query', 'add_endpoints']); if (is_object($wcs_query)) { $endpoint = $wcs_query->get_current_endpoint(); - if ($endpoint && isset($wcs_query->query_vars[ $endpoint ])) { + if ($endpoint && isset($wcs_query->query_vars[$endpoint])) { $language = PLL()->model->get_language($lang); - $url = PLL()->translate_slugs->slugs_model->switch_translated_slug($url, $language, 'wc_' . $wcs_query->query_vars[ $endpoint ]); + $url = PLL()->translate_slugs->slugs_model->switch_translated_slug($url, $language, 'wc_'.$wcs_query->query_vars[$endpoint]); } } } @@ -300,11 +306,12 @@ class PLLWC_Subscriptions * @param int $user_id The ID of a user in the store. * @param int $product_id The ID of a product in the store. * @param mixed $status Subscription status. + * * @return bool */ public function user_has_subscription($has_subscription, $user_id, $product_id, $status) { - if (false === $has_subscription && ! empty($product_id)) { + if (false === $has_subscription && !empty($product_id)) { $data_store = PLLWC_Data_Store::load('product_language'); foreach (wcs_get_users_subscriptions($user_id) as $subscription) { if (empty($status) || 'any' === $status || $subscription->has_status($status)) { @@ -317,6 +324,7 @@ class PLLWC_Subscriptions } } } + return $has_subscription; } @@ -329,11 +337,12 @@ class PLLWC_Subscriptions * * @param array $query_args WP_Query() arguments. * @param array $args Arguments of wcs_get_subscriptions(). + * * @return array */ public function get_subscriptions_query_args($query_args, $args) { - if (isset($query_args['post__in']) && array( 0 ) === $query_args['post__in']) { // Where `array( 0 ) correspond to `WCS_Admin_Post_Types::$post__in_none`, telling no result should be returned. + if (isset($query_args['post__in']) && [0] === $query_args['post__in']) { // Where `array( 0 ) correspond to `WCS_Admin_Post_Types::$post__in_none`, telling no result should be returned. $data_store = PLLWC_Data_Store::load('product_language'); $found_subs_from_translations = wcs_get_subscriptions_for_product( array_merge( @@ -342,10 +351,11 @@ class PLLWC_Subscriptions ) ); - if (! empty($found_subs_from_translations)) { + if (!empty($found_subs_from_translations)) { $query_args['post__in'] = $found_subs_from_translations; } } + return $query_args; } @@ -358,15 +368,16 @@ class PLLWC_Subscriptions * @since 1.3.3 * * @param int $variation_id Subscription variation id. + * * @return void */ public function delete_variation($variation_id) { - static $avoid_delete = array(); + static $avoid_delete = []; $post_type = get_post_type($variation_id); - if ('product_variation' === $post_type && ! in_array($variation_id, $avoid_delete)) { + if ('product_variation' === $post_type && !in_array($variation_id, $avoid_delete)) { $variation_product = wc_get_product($variation_id); if ($variation_product && $variation_product->is_type('subscription_variation')) { @@ -389,12 +400,12 @@ class PLLWC_Subscriptions */ public function add_query_vars(): void { - $wcs_query = pll_get_anonymous_object_from_filter('init', array( 'WCS_Query', 'add_endpoints' )); + $wcs_query = pll_get_anonymous_object_from_filter('init', ['WCS_Query', 'add_endpoints']); - if (! $wcs_query instanceof WCS_Query) { + if (!$wcs_query instanceof WCS_Query) { return; } - add_filter('woocommerce_get_query_vars', array( $wcs_query, 'add_wcs_query_vars' )); + add_filter('woocommerce_get_query_vars', [$wcs_query, 'add_wcs_query_vars']); } } diff --git a/__plugins/polylang-wc/src/plugins/swatches.php b/__plugins/polylang-wc/src/plugins/swatches.php index 3221bcd15a11c77495b6bcd19bbd551b90e598bb..061a054790037f2021b1d5b88206e34fcdda4f5d 100644 --- a/__plugins/polylang-wc/src/plugins/swatches.php +++ b/__plugins/polylang-wc/src/plugins/swatches.php @@ -1,12 +1,8 @@ options['media_support']) { - add_filter('pll_translate_term_meta', array( $this, 'translate_swatches_photo' ), 10, 3); + add_filter('pll_translate_term_meta', [$this, 'translate_swatches_photo'], 10, 3); } // Product metas. - add_filter('pllwc_copy_post_metas', array( $this, 'copy_product_metas' )); - add_filter('pllwc_translate_product_meta', array( $this, 'translate_product_meta' ), 10, 4); + add_filter('pllwc_copy_post_metas', [$this, 'copy_product_metas']); + add_filter('pllwc_translate_product_meta', [$this, 'translate_product_meta'], 10, 4); } /** @@ -40,12 +36,13 @@ class PLLWC_Swatches * @param array $metas List of custom fields names. * @param bool $sync True if it is synchronization, false if it is a copy. * @param int $from Id of the product from which we copy information. + * * @return array */ public function copy_term_metas($metas, $sync, $from) { - $key_names = array( '_swatches_id_type', '_swatches_id_color', '_swatches_id_photo' ); - $to_copy = array(); + $key_names = ['_swatches_id_type', '_swatches_id_color', '_swatches_id_photo']; + $to_copy = []; foreach (array_keys(get_term_meta($from)) as $key) { foreach ($key_names as $name) { @@ -68,6 +65,7 @@ class PLLWC_Swatches * @param int $value Photo id. * @param string $key Meta key. * @param string $lang Language code. + * * @return int */ public function translate_swatches_photo($value, $key, $lang) @@ -76,6 +74,7 @@ class PLLWC_Swatches $to_value = pll_get_post($value, $lang); $value = $to_value ? $to_value : $value; } + return $value; } @@ -86,14 +85,16 @@ class PLLWC_Swatches * @since 1.1 * * @param array $metas List of custom fields names. + * * @return array */ public function copy_product_metas($metas) { - $to_sync = array( + $to_sync = [ '_swatch_type_options', '_swatch_type', - ); + ]; + return array_merge($metas, array_combine($to_sync, $to_sync)); } @@ -107,6 +108,7 @@ class PLLWC_Swatches * @param string $key Meta key. * @param string $lang Language of target. * @param int $from Id of the source. + * * @return mixed */ public function translate_product_meta($value, $key, $lang, $from) @@ -115,21 +117,21 @@ class PLLWC_Swatches return $value; } $product = wc_get_product($from); - if (! $product instanceof WC_Product_Variable) { + if (!$product instanceof WC_Product_Variable) { return $value; } - $attr_terms = array(); + $attr_terms = []; $data_store = PLLWC_Data_Store::load('product_language'); - $orig_lang = $data_store->get_language($from); + $orig_lang = $data_store->get_language($from); $attributes = $product->get_variation_attributes(); foreach ($attributes as $tax => $terms) { foreach ($terms as $slug) { - $attr_terms[ md5($slug) ] = array( + $attr_terms[md5($slug)] = [ 'taxonomy' => $tax, 'slug' => $slug, - ); + ]; } } @@ -139,12 +141,12 @@ class PLLWC_Swatches $attr['image'] = $tr_id; } - $terms = get_terms(array( 'taxonomy' => $attr_terms[ $k ]['taxonomy'], 'slug' => $attr_terms[ $k ]['slug'], 'lang' => $orig_lang )); + $terms = get_terms(['taxonomy' => $attr_terms[$k]['taxonomy'], 'slug' => $attr_terms[$k]['slug'], 'lang' => $orig_lang]); $term = reset($terms); $tr_term = get_term(pll_get_term($term->term_id, $lang)); $tr_k = md5($tr_term->slug); - unset($value[ $i ]['attributes'][ $k ]); - $value[ $i ]['attributes'][ $tr_k ] = $attr; + unset($value[$i]['attributes'][$k]); + $value[$i]['attributes'][$tr_k] = $attr; } } diff --git a/__plugins/polylang-wc/src/plugins/table-rate-shipping.php b/__plugins/polylang-wc/src/plugins/table-rate-shipping.php index 18a6ae8a8dcab652f34fd2a06b98ff346489ee34..38007e5714ce1b6c8b55287411559cd13b0cba4c 100644 --- a/__plugins/polylang-wc/src/plugins/table-rate-shipping.php +++ b/__plugins/polylang-wc/src/plugins/table-rate-shipping.php @@ -1,9 +1,5 @@ $rate) { - $rates[ $k ]->rate_label = pll__($rate->rate_label); + $rates[$k]->rate_label = pll__($rate->rate_label); } + return $rates; } } diff --git a/__plugins/polylang-wc/src/plugins/wc-brands.php b/__plugins/polylang-wc/src/plugins/wc-brands.php index 2262b811b7fddc6effc66bd4503d6fac3e8ac76d..0d8962855dd709375211ba428c647253f0059901 100644 --- a/__plugins/polylang-wc/src/plugins/wc-brands.php +++ b/__plugins/polylang-wc/src/plugins/wc-brands.php @@ -1,9 +1,5 @@ options['media_support']) { - add_action('admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' )); + add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); // WooCommerce ( verified in 2.5.5 ) inconsistently uses created_term and edit_term so we can't use pll_save_term. - add_action('created_product_brand', array( PLLWC()->admin_taxonomies, 'fix_term_thumbnail' ), 999); - add_action('edited_product_brand', array( PLLWC()->admin_taxonomies, 'fix_term_thumbnail' ), 999); + add_action('created_product_brand', [PLLWC()->admin_taxonomies, 'fix_term_thumbnail'], 999); + add_action('edited_product_brand', [PLLWC()->admin_taxonomies, 'fix_term_thumbnail'], 999); } // Sync brands taxonomy. - add_filter('pll_copy_taxonomies', array( $this, 'copy_taxonomies' ), 10, 3); + add_filter('pll_copy_taxonomies', [$this, 'copy_taxonomies'], 10, 3); } /** @@ -51,14 +46,16 @@ class PLLWC_Brands * @param array $metas List of custom fields names. * @param bool $sync True if it is synchronization, false if it is a copy. * @param int $from ID of the product from which we copy information. + * * @return array */ public function copy_term_metas($metas, $sync, $from) { $term = get_term($from); if ($term instanceof WP_Term && 'product_brand' === $term->taxonomy) { - return array_merge($metas, array( 'thumbnail_id' )); + return array_merge($metas, ['thumbnail_id']); } + return $metas; } @@ -67,8 +64,9 @@ class PLLWC_Brands * * @since 1.6 * - * @param string[] $taxonomies List of taxonomy names. + * @param string[] $taxonomies List of taxonomy names. * @param bool $is_settings True when displaying the list of custom taxonomies in Polylang settings. + * * @return string[] List of taxonomy names. */ public function add_taxonomy($taxonomies, $is_settings) @@ -96,7 +94,7 @@ class PLLWC_Brands $term = get_term((int) $_GET['from_tag'], 'product_brand'); // phpcs:ignore WordPress.Security.NonceVerification } - if (! empty($term)) { + if (!empty($term)) { // Add the edit "thumbnail field" with pre-filled with the source language term id. $GLOBALS['WC_Brands_Admin']->edit_thumbnail_field($term, 'product_brand'); } else { @@ -115,7 +113,7 @@ class PLLWC_Brands public function admin_enqueue_scripts() { $screen = get_current_screen(); - if (! empty($screen) && in_array($screen->base, array( 'edit-tags', 'term' )) && 'product_brand' === $screen->taxonomy) { + if (!empty($screen) && in_array($screen->base, ['edit-tags', 'term']) && 'product_brand' === $screen->taxonomy) { PLLWC()->admin_taxonomies->load_scripts(); } } @@ -127,11 +125,13 @@ class PLLWC_Brands * @since 2.2 * * @param string[] $taxonomies List of taxonomy names to sync. + * * @return string[] Modified list of taxonomies. */ public function copy_taxonomies($taxonomies) { $taxonomies[] = 'product_brand'; + return $taxonomies; } } diff --git a/__plugins/polylang-wc/src/plugins/wcfd.php b/__plugins/polylang-wc/src/plugins/wcfd.php index 37ef1c38a67ffddf57d5ab34c386d7c27bd10a7c..a83eba98aeb72b1e9d286116fb4fc9e1944e0563 100644 --- a/__plugins/polylang-wc/src/plugins/wcfd.php +++ b/__plugins/polylang-wc/src/plugins/wcfd.php @@ -1,9 +1,5 @@ $field) { - if (! empty($field['label'])) { - $fields[ $name ]['label'] = pll__($field['label']); + if (!empty($field['label'])) { + $fields[$name]['label'] = pll__($field['label']); } - if (! empty($field['placeholder'])) { - $fields[ $name ]['placeholder'] = pll__($field['placeholder']); + if (!empty($field['placeholder'])) { + $fields[$name]['placeholder'] = pll__($field['placeholder']); } } } @@ -81,11 +78,11 @@ class PLLWC_WCFD if (is_array($fields)) { foreach ($fields as $name => $field) { - if (! empty($field['label'])) { + if (!empty($field['label'])) { pll_register_string(sprintf(__('Label', 'polylang-wc'), $name), $field['label'], 'Checkout Field Editor'); } - if (! empty($field['placeholder'])) { + if (!empty($field['placeholder'])) { pll_register_string(sprintf(__('Placeholder', 'polylang-wc'), $name), $field['placeholder'], 'Checkout Field Editor'); } } @@ -94,13 +91,14 @@ class PLLWC_WCFD } /** - * Translated strings must be sanitized the same way Checkout Field Editor for WooCommerce does before they are saved + * Translated strings must be sanitized the same way Checkout Field Editor for WooCommerce does before they are saved. * * @since 1.3 * * @param string $translation The string translation. * @param string $name The name as defined in pll_register_string. * @param string $context The context as defined in pll_register_string. + * * @return string Sanitized translation. */ public function sanitize_strings($translation, $name, $context) diff --git a/__plugins/polylang-wc/src/plugins/yith-wcas.php b/__plugins/polylang-wc/src/plugins/yith-wcas.php index 15300e093ff2d0a32aec8c4721d466e2c163bab4..ecd857debbd5347fe3126c3ee571d6dee616e97f 100644 --- a/__plugins/polylang-wc/src/plugins/yith-wcas.php +++ b/__plugins/polylang-wc/src/plugins/yith-wcas.php @@ -1,9 +1,5 @@ = 2.0.0 are supported. - add_filter('ywcas_block_common_localize', array( $this, 'filter_block_localize' ), 99); - add_action('parse_request', array( $this, 'fix_lang_query_var' ), 5); // Early, so hooks that use the default priority will get the right `lang` query var. + add_filter('ywcas_block_common_localize', [$this, 'filter_block_localize'], 99); + add_action('parse_request', [$this, 'fix_lang_query_var'], 5); // Early, so hooks that use the default priority will get the right `lang` query var. } /** @@ -30,11 +26,13 @@ class PLLWC_Yith_WCAS * @since 1.9.5 * * @param array $script_localize An array of information about localization. + * * @return array */ public function filter_block_localize($script_localize) { $script_localize['siteURL'] = pll_home_url(); + return $script_localize; } @@ -45,6 +43,7 @@ class PLLWC_Yith_WCAS * @since 2.1.2 * * @param WP $wp Current WordPress environment instance (passed by reference). + * * @return void */ public function fix_lang_query_var(WP $wp): void @@ -54,28 +53,31 @@ class PLLWC_Yith_WCAS return; } - if (! empty(PLL()->curlang)) { + if (!empty(PLL()->curlang)) { $wp->query_vars['lang'] = PLL()->curlang->slug; + return; } - if (! empty($wp->matched_query)) { + if (!empty($wp->matched_query)) { // Pretty permalinks, the language is in the URL. parse_str($wp->matched_query, $matched_query); - if (! empty($matched_query['lang'])) { + if (!empty($matched_query['lang'])) { $wp->query_vars['lang'] = $matched_query['lang']; } + return; } - if (! empty(PLL()->options['hide_default']) && PLL()->options['force_lang'] < 3) { + if (!empty(PLL()->options['hide_default']) && PLL()->options['force_lang'] < 3) { // The language is not displayed in the URL (`hide_default` is `true`). $language_slug = pll_default_language(); - if (! empty($language_slug)) { + if (!empty($language_slug)) { $wp->query_vars['lang'] = $language_slug; } + return; } } diff --git a/__plugins/polylang-wc/src/post-types.php b/__plugins/polylang-wc/src/post-types.php index 92c3e4a90e9c770890ab5b434ffc164f70b0b937..0145eabf551dd1a73c94d55c2119b4fb24b9d37f 100644 --- a/__plugins/polylang-wc/src/post-types.php +++ b/__plugins/polylang-wc/src/post-types.php @@ -1,9 +1,5 @@ permalinks = get_option('woocommerce_permalinks'); - add_filter('woocommerce_taxonomy_args_product_cat', array( $this, 'woocommerce_taxonomy_args_product_cat' )); - add_filter('woocommerce_taxonomy_args_product_tag', array( $this, 'woocommerce_taxonomy_args_product_tag' )); - add_filter('pll_get_taxonomies', array( $this, 'translate_taxonomies' ), 10, 2); - add_filter('pll_copy_taxonomies', array( $this, 'copy_taxonomies' )); + add_filter('woocommerce_taxonomy_args_product_cat', [$this, 'woocommerce_taxonomy_args_product_cat']); + add_filter('woocommerce_taxonomy_args_product_tag', [$this, 'woocommerce_taxonomy_args_product_tag']); + add_filter('pll_get_taxonomies', [$this, 'translate_taxonomies'], 10, 2); + add_filter('pll_copy_taxonomies', [$this, 'copy_taxonomies']); // Add filters from the data stores. $product_data_store = PLLWC_Data_Store::load('product_language'); @@ -48,11 +44,13 @@ class PLLWC_Post_Types * @since 0.1 * * @param array $args Arguments used to register the taxonomy. + * * @return array */ public function woocommerce_taxonomy_args_product_cat($args) { $args['rewrite']['slug'] = empty($this->permalinks['category_base']) ? 'product-category' : $this->permalinks['category_base']; + return $args; } @@ -62,11 +60,13 @@ class PLLWC_Post_Types * @since 0.1 * * @param array $args Arguments used to register the taxonomy. + * * @return array */ public function woocommerce_taxonomy_args_product_tag($args) { $args['rewrite']['slug'] = empty($this->permalinks['tag_base']) ? 'product-tag' : $this->permalinks['tag_base']; + return $args; } @@ -82,11 +82,11 @@ class PLLWC_Post_Types // Attribute taxonomies. $woo_taxonomies = wp_list_pluck(wc_get_attribute_taxonomies(), 'attribute_name'); foreach ($woo_taxonomies as $key => $tax) { - $woo_taxonomies[ $key ] = 'pa_' . $tax; + $woo_taxonomies[$key] = 'pa_'.$tax; } // Add WooCommerce core taxonomies to translate. - return array_merge(array( 'product_cat', 'product_tag' ), $woo_taxonomies); + return array_merge(['product_cat', 'product_tag'], $woo_taxonomies); } /** @@ -97,11 +97,13 @@ class PLLWC_Post_Types * * @param string[] $taxonomies List of taxonomy names for which Polylang manages language and translations. * @param bool $hide True when displaying the list in Polylang settings. + * * @return string[] List of taxonomy names for which Polylang manages language and translations. */ public function translate_taxonomies($taxonomies, $hide) { unset($taxonomies['product_shipping_class']); // Untranslated but hidden from Polylang Settings. + return $hide ? array_diff($taxonomies, self::get_translated_taxonomies()) : array_merge($taxonomies, self::get_translated_taxonomies()); } @@ -111,13 +113,14 @@ class PLLWC_Post_Types * @since 0.1 * * @param string[] $taxonomies The list of taxonomies to copy or synchronize. + * * @return string[] The list of taxonomies to copy or synchronize. */ public function copy_taxonomies($taxonomies) { return array_merge( $taxonomies, - array( 'product_type', 'product_shipping_class', 'product_visibility', 'product_cat', 'product_tag' ) + ['product_type', 'product_shipping_class', 'product_visibility', 'product_cat', 'product_tag'] ); } } diff --git a/__plugins/polylang-wc/src/product-data-store-cpt.php b/__plugins/polylang-wc/src/product-data-store-cpt.php index 4029dff3514c3764606edc64c616f07f4382eb59..f624a5c49dbba43c782c80cd84346d1e142c92e0 100644 --- a/__plugins/polylang-wc/src/product-data-store-cpt.php +++ b/__plugins/polylang-wc/src/product-data-store-cpt.php @@ -1,9 +1,5 @@ object = PLL()->model->post; + $this->object = PLL()->model->post; $this->data_store = new PLLWC_Product_Data_Store_CPT(); } @@ -61,22 +57,23 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language $this->permalinks = get_option('woocommerce_permalinks'); - add_filter('pll_get_post_types', array( $this, 'translated_post_types' ), 10, 2); - add_filter('woocommerce_register_post_type_product', array( $this, 'woocommerce_register_post_type_product' )); - add_filter('woocommerce_variable_children_args', array( $this, 'variable_children_args' )); + add_filter('pll_get_post_types', [$this, 'translated_post_types'], 10, 2); + add_filter('woocommerce_register_post_type_product', [$this, 'woocommerce_register_post_type_product']); + add_filter('woocommerce_variable_children_args', [$this, 'variable_children_args']); // Synchronization. - add_action('set_object_terms', array( $this, 'set_object_terms' ), 10, 4); - add_filter('pll_copy_post_metas', array( $this, 'copy_post_metas' ), 5, 5); - add_filter('pll_translate_post_meta', array( $this, 'translate_post_meta' ), 5, 5); - add_action('woocommerce_product_object_updated_props', array( $this, 'updated_props' ), 10, 2); - add_action('pll_post_synchronized', array( $this, 'post_synchronized' ), 10, 2); + add_action('set_object_terms', [$this, 'set_object_terms'], 10, 4); + add_filter('pll_copy_post_metas', [$this, 'copy_post_metas'], 5, 5); + add_filter('pll_translate_post_meta', [$this, 'translate_post_meta'], 5, 5); + add_action('woocommerce_product_object_updated_props', [$this, 'updated_props'], 10, 2); + add_action('pll_post_synchronized', [$this, 'post_synchronized'], 10, 2); // Attributes. - remove_action('edit_term', array( 'WC_Post_Data', 'edit_term' )); - remove_action('edited_term', array( 'WC_Post_Data', 'edited_term' )); - add_action('edit_term', array( $this, 'edit_term' ), 10, 3); - add_action('edited_term', array( $this, 'edited_term' ), 10, 3); + remove_action('edit_term', ['WC_Post_Data', 'edit_term']); + remove_action('edited_term', ['WC_Post_Data', 'edited_term']); + add_action('edit_term', [$this, 'edit_term'], 10, 3); + add_action('edited_term', [$this, 'edited_term'], 10, 3); + return $this; } @@ -87,11 +84,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @param string[] $types List of post type names for which Polylang manages language and translations. * @param bool $hide True when displaying the list in Polylang settings. + * * @return string[] List of post type names for which Polylang manages language and translations. */ public function translated_post_types($types, $hide) { - $woo_types = array( 'product', 'product_variation' ); + $woo_types = ['product', 'product_variation']; + return $hide ? array_diff($types, $woo_types) : array_merge($types, $woo_types); } @@ -101,12 +100,14 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @since 0.1 * * @param array $args arguments used to register the post type. + * * @return array */ public function woocommerce_register_post_type_product($args) { $product_permalink = empty($this->permalinks['product_base']) ? 'product' : $this->permalinks['product_base']; - $args['rewrite'] = array( 'slug' => untrailingslashit($product_permalink), 'with_front' => false, 'feeds' => true ); + $args['rewrite'] = ['slug' => untrailingslashit($product_permalink), 'with_front' => false, 'feeds' => true]; + return $args; } @@ -116,11 +117,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @since 0.7.3 * * @param array $args Query arguments. + * * @return array */ public function variable_children_args($args) { $args['lang'] = ''; + return $args; } @@ -133,12 +136,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @param WP_Term[] $terms An array of object terms. * @param int[] $tt_ids An array of term taxonomy IDs. * @param string $taxonomy Taxonomy slug. + * * @return void */ public function set_object_terms($object_id, $terms, $tt_ids, $taxonomy) { if ('product_type' === $taxonomy) { - $cache_key = WC_Cache_Helper::get_cache_prefix('product_' . $object_id) . '_type_' . $object_id; + $cache_key = WC_Cache_Helper::get_cache_prefix('product_'.$object_id).'_type_'.$object_id; wp_cache_delete($cache_key, 'products'); } } @@ -150,11 +154,12 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @since 1.9 Type-hinted. * * @param bool $sync True if it is synchronization, false if it is a copy. + * * @return string[] */ protected function get_legacy_metas($sync): array { - $metas_to_sync = array( + $metas_to_sync = [ '_backorders' => 'backorders', '_children' => 'children', '_crosssell_ids' => 'cross_sell_ids', @@ -192,10 +197,11 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language '_variation_description' => 'description', '_cogs_total_value' => 'cogs_total_value', '_cogs_value_is_additive' => 'cogs_value_is_additive', - ); + ]; + return $sync ? $metas_to_sync : array_merge( $metas_to_sync, - array( '_stock_status' => 'stock_status' ) + ['_stock_status' => 'stock_status'] ); } @@ -209,11 +215,12 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @param int $from Id of the product from which we copy information. * @param int $to Id of the product to which we copy information. * @param string $lang Language code. + * * @return string[] */ public function copy_post_metas($metas, $sync, $from, $to, $lang) { - if (! in_array(get_post_type($from), array( 'product', 'product_variation' ))) { + if (!in_array(get_post_type($from), ['product', 'product_variation'])) { return $metas; } @@ -228,18 +235,18 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language } $_to_copy = self::get_legacy_metas($sync); - $to_copy = array_keys($_to_copy); + $to_copy = array_keys($_to_copy); // Should we copy text? - if (! PLLWC_Products::should_copy_texts($from, $to, $sync)) { + if (!PLLWC_Products::should_copy_texts($from, $to, $sync)) { $to_copy = array_diff( $to_copy, - array( + [ '_button_text', '_product_url', '_purchase_note', '_variation_description', - ) + ] ); } @@ -267,6 +274,7 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @param int $id ID of object to update. * @param string $table Lookup table name. + * * @return void */ public function update_lookup_table($id, $table) @@ -281,13 +289,14 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @param WC_Product|false $product Product. * @param array $updated_props Product properties being updated. + * * @return void */ public function updated_props($product, $updated_props) { static $avoid_recursion = false; - if ($avoid_recursion || ! $product) { + if ($avoid_recursion || !$product) { return; } @@ -297,7 +306,6 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language foreach ($this->get_translations($id) as $tr_id) { if ($id && $id !== $tr_id && $tr_product = wc_get_product($tr_id)) { - if (in_array('stock_quantity', $updated_props, true)) { if ($tr_product->is_type('variation')) { do_action('woocommerce_variation_set_stock', $tr_product); @@ -325,11 +333,12 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @param int $from Id of the product from which we copy information. * @param int $to Id of the target. + * * @return void */ public function post_synchronized($from, $to) { - if (in_array(get_post_type($to), array( 'product', 'product_variation' ))) { + if (in_array(get_post_type($to), ['product', 'product_variation'])) { $this->update_lookup_table($to, 'wc_product_meta_lookup'); } } @@ -344,23 +353,24 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @param string $lang Language of target. * @param int $from Id of the object from which we copy information. * @param int $to Id of the target. + * * @return mixed */ public function translate_post_meta($value, $key, $lang, $from, $to) { - if (in_array(get_post_type($from), array( 'product', 'product_variation' ))) { + if (in_array(get_post_type($from), ['product', 'product_variation'])) { if (0 === strpos($key, 'attribute_')) { // Translate taxonomy attributes in variations. $tax = substr($key, 10); - if (! empty($tax) && ! empty($value) && is_string($value)) { - $attribute = array( $tax => $value ); + if (!empty($tax) && !empty($value) && is_string($value)) { + $attribute = [$tax => $value]; $tr_attribute = PLLWC_Products::maybe_translate_attributes($attribute, $lang); - $value = $tr_attribute[ $tax ]; + $value = $tr_attribute[$tax]; } } else { $props = self::get_legacy_metas(false); - if (isset($props[ $key ])) { - $value = PLLWC_Products::maybe_translate_property($value, $props[ $key ], $lang); + if (isset($props[$key])) { + $value = PLLWC_Products::maybe_translate_property($value, $props[$key], $lang); } } @@ -377,6 +387,7 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language */ $value = apply_filters('pllwc_translate_product_meta', $value, $key, $lang, $from, $to); } + return $value; } @@ -385,16 +396,17 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @since 1.0 * - * @param int $from Id of the product from which we copy information. - * @param int $to Id of the product to which we copy information. - * @param string $lang Language code. - * @param bool $sync Optional, defaults to false. True if it is synchronization, false if it is a copy. + * @param int $from Id of the product from which we copy information. + * @param int $to Id of the product to which we copy information. + * @param string $lang Language code. + * @param bool $sync Optional, defaults to false. True if it is synchronization, false if it is a copy. + * * @return void */ public function copy($from, $to, $lang, $sync = false) { if (isset(PLL()->sync)) { - if (! $sync) { + if (!$sync) { PLL()->sync->taxonomies->copy($from, $to, $lang); } @@ -412,12 +424,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @param int $id Product id. * @param int $order Product order. + * * @return void */ public function save_product_ordering($id, $order) { global $wpdb; - $wpdb->update($wpdb->posts, array( 'menu_order' => $order ), array( 'ID' => $id )); + $wpdb->update($wpdb->posts, ['menu_order' => $order], ['ID' => $id]); } /** @@ -427,11 +440,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @since 1.0 * * @param int $id Product id. + * * @return string */ public function get_translation_group_name($id) { $term = $this->object->get_object_term($id, 'post_translations'); + return empty($term) ? '' : $term->name; } @@ -445,17 +460,19 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * @param string $value The field value to search (slashed to work around https://core.trac.wordpress.org/ticket/27421). * @param int $product_id Product ID. * @param PLL_Language $language The product language. + * * @return bool */ public function lookup_table_has(string $column, string $value, int $product_id, PLL_Language $language): bool { $meta_lookup_props = $this->get_meta_lookup_props(); - if (! in_array($column, $meta_lookup_props, true)) { + if (!in_array($column, $meta_lookup_props, true)) { _doing_it_wrong( __METHOD__, esc_html(sprintf('The column name must be one of the columns in the `wc_product_meta_lookup` table: %s', implode(', ', $meta_lookup_props))), '2.1' ); + return false; } @@ -484,12 +501,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language /** * Returns a product id based on the sku and the language. * Modified version WC_Product_Data_Store_CPT::get_product_id_by_sku(). - * Code last checked: WC 4.0 + * Code last checked: WC 4.0. * * @since 1.0 * * @param string $sku SKU. * @param string $lang Language code. + * * @return int Product id. */ public function get_product_id_by_sku($sku, $lang) @@ -528,9 +546,10 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @since 1.2 * - * @param int $term_id Term ID. - * @param int $tt_id Term taxonomy ID. - * @param string $taxonomy Taxonomy slug. + * @param int $term_id Term ID. + * @param int $tt_id Term taxonomy ID. + * @param string $taxonomy Taxonomy slug. + * * @return void */ public static function edit_term($term_id, $tt_id, $taxonomy) @@ -553,16 +572,17 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language * * @since 1.2 * - * @param int $term_id Term ID. - * @param int $tt_id Term taxonomy ID. - * @param string $taxonomy Taxonomy slug. + * @param int $term_id Term ID. + * @param int $tt_id Term taxonomy ID. + * @param string $taxonomy Taxonomy slug. + * * @return void */ public function edited_term($term_id, $tt_id, $taxonomy) { global $wpdb; - if (! is_null(self::$editing_term) && strpos($taxonomy, 'pa_') === 0) { + if (!is_null(self::$editing_term) && strpos($taxonomy, 'pa_') === 0) { $edited_term = get_term_by('id', $term_id, $taxonomy); if ($edited_term instanceof WP_Term && $edited_term->slug !== self::$editing_term->slug) { @@ -578,7 +598,7 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language AND meta_value = %s AND pll_tr.term_taxonomy_id = %d", $edited_term->slug, - 'attribute_' . sanitize_title($taxonomy), + 'attribute_'.sanitize_title($taxonomy), self::$editing_term->slug, $language ) @@ -591,8 +611,8 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language SET meta_value = REPLACE( meta_value, %s, %s ) WHERE meta_key = '_default_attributes' AND pll_tr.term_taxonomy_id = %d", - serialize(self::$editing_term->taxonomy) . serialize(self::$editing_term->slug), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize - serialize($edited_term->taxonomy) . serialize($edited_term->slug), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize + serialize(self::$editing_term->taxonomy).serialize(self::$editing_term->slug), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize + serialize($edited_term->taxonomy).serialize($edited_term->slug), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize $language ) ); @@ -612,12 +632,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language private function is_cogs_enabled(): bool { // Backward compatibility with WC < 9.5. - if (! class_exists(CostOfGoodsSoldController::class)) { + if (!class_exists(CostOfGoodsSoldController::class)) { return false; } /** @var CostOfGoodsSoldController */ $cogs_controller = wc_get_container()->get(CostOfGoodsSoldController::class); + return $cogs_controller->feature_is_enabled(); } @@ -631,12 +652,13 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language */ private function use_cogs_lookup_column(): bool { - if (! $this->is_cogs_enabled()) { + if (!$this->is_cogs_enabled()) { return false; } /** @var CostOfGoodsSoldController */ $cogs_controller = wc_get_container()->get(CostOfGoodsSoldController::class); + // Backward compatibility with WC < 9.8. return method_exists($cogs_controller, 'product_meta_lookup_table_cogs_value_columns_exist') && $cogs_controller->product_meta_lookup_table_cogs_value_columns_exist(); } @@ -650,7 +672,7 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language */ private function get_meta_lookup_props(): array { - $meta_lookup_props = array( + $meta_lookup_props = [ 'sku', 'global_unique_id', 'regular_price', @@ -666,11 +688,12 @@ class PLLWC_Product_Language_CPT extends PLLWC_Translated_Object_Language 'virtual', 'tax_status', 'tax_class', - ); + ]; if ($this->use_cogs_lookup_column()) { $meta_lookup_props[] = 'cogs_value'; } + return $meta_lookup_props; } } diff --git a/__plugins/polylang-wc/src/products.php b/__plugins/polylang-wc/src/products.php index 1352affeeb9e62ce9f4b5594d82bc50074d2906e..af183b5810a3db6f0391f6fa58ef588f1dc4194e 100644 --- a/__plugins/polylang-wc/src/products.php +++ b/__plugins/polylang-wc/src/products.php @@ -1,9 +1,5 @@ false, - 'taxonomies' => array(), - ); + 'taxonomies' => [], + ]; /** * Constructor. @@ -44,33 +40,32 @@ class PLLWC_Products $this->data_store = PLLWC_Data_Store::load('product_language'); // Variations synchronization. - add_action('add_meta_boxes', array( $this, 'add_meta_boxes' ), 5, 2); - add_action('woocommerce_update_product', array( $this, 'save_product' )); - add_action('woocommerce_new_product_variation', array( $this, 'save_variation' )); - add_action('woocommerce_update_product_variation', array( $this, 'save_variation' )); - add_action('woocommerce_after_product_object_save', array( $this, 'copy_product' )); + add_action('add_meta_boxes', [$this, 'add_meta_boxes'], 5, 2); + add_action('woocommerce_update_product', [$this, 'save_product']); + add_action('woocommerce_new_product_variation', [$this, 'save_variation']); + add_action('woocommerce_update_product_variation', [$this, 'save_variation']); + add_action('woocommerce_after_product_object_save', [$this, 'copy_product']); // Filters `get_terms()` in `LookupDataStore::get_term_ids_by_slug_cache()`. - add_action('woocommerce_before_product_object_save', array( $this, 'store_product_data' )); - add_filter('get_terms_args', array( $this, 'get_terms_args' ), 20); // After Polylang and Polylang Pro. - add_action('woocommerce_after_product_object_save', array( $this, 'reset_product_data' ), 5); // Before copy_product(), not mandatory though. - add_action('woocommerce_run_product_attribute_lookup_update_callback', array( $this, 'store_product_data' ), 1); // To set the language before WC processes the product. + add_action('woocommerce_before_product_object_save', [$this, 'store_product_data']); + add_filter('get_terms_args', [$this, 'get_terms_args'], 20); // After Polylang and Polylang Pro. + add_action('woocommerce_after_product_object_save', [$this, 'reset_product_data'], 5); // Before copy_product(), not mandatory though. + add_action('woocommerce_run_product_attribute_lookup_update_callback', [$this, 'store_product_data'], 1); // To set the language before WC processes the product. - add_action('pll_post_synchronized', array( $this, 'synchronize_product' ), 10, 4); - add_action('pll_created_sync_post', array( $this, 'copy_variations' ), 5, 3); + add_action('pll_post_synchronized', [$this, 'synchronize_product'], 10, 4); + add_action('pll_created_sync_post', [$this, 'copy_variations'], 5, 3); // Variations deletion. - add_action('woocommerce_before_delete_product_variation', array( $this, 'delete_variation' )); + add_action('woocommerce_before_delete_product_variation', [$this, 'delete_variation']); // Unique product ID. - add_filter('wc_product_has_global_unique_id', array( $this, 'unique_id' ), 10, 3); + add_filter('wc_product_has_global_unique_id', [$this, 'unique_id'], 10, 3); // Unique SKU. - add_filter('wc_product_has_unique_sku', array( $this, 'unique_id' ), 10, 3); - add_filter('wc_product_pre_lock_on_sku', array( $this, 'filter_lock_on_sku' ), 10, 2); - + add_filter('wc_product_has_unique_sku', [$this, 'unique_id'], 10, 3); + add_filter('wc_product_pre_lock_on_sku', [$this, 'filter_lock_on_sku'], 10, 2); // On sale products block. - add_filter('pll_filter_query_excluded_query_vars', array( $this, 'fix_on_sale_products_block_query' ), 10, 2); + add_filter('pll_filter_query_excluded_query_vars', [$this, 'fix_on_sale_products_block_query'], 10, 2); } /** @@ -81,6 +76,7 @@ class PLLWC_Products * @param int $id Source variation product id. * @param int $tr_parent Target variable product id. * @param string $lang Target language. + * * @return void * * @phpstan-param non-empty-string $lang @@ -88,14 +84,14 @@ class PLLWC_Products protected function copy_variation($id, $tr_parent, $lang) { static $avoid_recursion = false; - static $avoid_double = array(); - static $avoid_reverse = array(); + static $avoid_double = []; + static $avoid_reverse = []; - if ($avoid_recursion || ! empty($avoid_double[ "$id|$tr_parent" ]) || ! empty($avoid_reverse[ $id ])) { + if ($avoid_recursion || !empty($avoid_double["$id|$tr_parent"]) || !empty($avoid_reverse[$id])) { return; } - $avoid_double[ "$id|$tr_parent" ] = true; + $avoid_double["$id|$tr_parent"] = true; $tr_id = $this->data_store->get($id, $lang); @@ -109,28 +105,28 @@ class PLLWC_Products return; } - if (! $tr_id) { + if (!$tr_id) { // If the product variation is untranslated, attempt to find a translation based on the attribute. $tr_product = wc_get_product($tr_parent); if ($tr_product instanceof WC_Product_Variable) { $tr_attributes = $tr_product->get_variation_attributes(); - if (! empty($tr_attributes)) { + if (!empty($tr_attributes)) { // At least one translated variation was manually created. $attributes = $variation->get_attributes(); - if (! in_array('', $attributes)) { + if (!in_array('', $attributes)) { $attributes = $this->maybe_translate_attributes($attributes, $lang); foreach ($tr_product->get_children() as $_tr_id) { $tr_variation = wc_get_product($_tr_id); - if (! $tr_variation || $attributes !== $tr_variation->get_attributes()) { + if (!$tr_variation || $attributes !== $tr_variation->get_attributes()) { continue; } $source_lang = $this->data_store->get_language($id); - if (! $source_lang || ! empty($this->data_store->get($tr_variation->get_id(), $source_lang))) { + if (!$source_lang || !empty($this->data_store->get($tr_variation->get_id(), $source_lang))) { continue; } @@ -141,7 +137,7 @@ class PLLWC_Products } } - if (! $tr_id) { + if (!$tr_id) { // Creates the translated product variation if it does not exist yet. $avoid_recursion = true; @@ -157,11 +153,11 @@ class PLLWC_Products $this->data_store->copy($id, $tr_id, $lang); $this->data_store->set_language($tr_id, $lang); $translations = $this->data_store->get_translations($id); - $source_lang = $this->data_store->get_language($id); + $source_lang = $this->data_store->get_language($id); if ($source_lang) { - $translations[ $source_lang ] = $id; // In case this is the first translation created. + $translations[$source_lang] = $id; // In case this is the first translation created. } - $translations[ $lang ] = $tr_id; + $translations[$lang] = $tr_id; $this->data_store->save_translations($translations); } else { // Make sure the parent product is correct. Fixes edge case reported in #153. @@ -179,7 +175,7 @@ class PLLWC_Products $this->data_store->copy($id, $tr_id, $lang, true); } - $avoid_reverse[ $tr_id ] = true; + $avoid_reverse[$tr_id] = true; } /** @@ -190,6 +186,7 @@ class PLLWC_Products * @param int $from Product id from which we copy information. * @param int $to Product id to which we paste information. * @param string $lang Language code. + * * @return void * * @phpstan-param non-empty-string $lang @@ -203,12 +200,12 @@ class PLLWC_Products if ($language) { $variations = $product->get_children(); // Note: it does not return disabled variations in WC < 3.3. - remove_action('woocommerce_new_product_variation', array( $this, 'save_variation' )); // Avoid reverse sync. + remove_action('woocommerce_new_product_variation', [$this, 'save_variation']); // Avoid reverse sync. foreach ($variations as $id) { $this->data_store->set_language($id, $language); $this->copy_variation($id, $to, $lang); } - add_action('woocommerce_new_product_variation', array( $this, 'save_variation' )); + add_action('woocommerce_new_product_variation', [$this, 'save_variation']); } } } @@ -221,6 +218,7 @@ class PLLWC_Products * * @param string $post_type Post type. * @param WP_Post $post Current post object. + * * @return void */ public function add_meta_boxes($post_type, $post) @@ -256,6 +254,7 @@ class PLLWC_Products * @since 1.0 * * @param int $id Product ID. + * * @return void */ public function save_product($id) @@ -269,7 +268,7 @@ class PLLWC_Products foreach ($translations as $lang => $tr_id) { if ($id !== $tr_id) { // It's useless to copy variations if we already did it by saving variations before. - if (! did_action('woocommerce_update_product_variation') && ! did_action('woocommerce_new_product_variation')) { + if (!did_action('woocommerce_update_product_variation') && !did_action('woocommerce_new_product_variation')) { $this->copy_variations($id, $tr_id, $lang); } @@ -286,13 +285,14 @@ class PLLWC_Products * @since 1.0 * * @param int $id Variation product id. + * * @return void */ public function save_variation($id) { static $avoid_recursion = false; - if (! doing_action('woocommerce_product_duplicate') && ! doing_action('wp_ajax_woocommerce_do_ajax_product_import') && ! $avoid_recursion) { + if (!doing_action('woocommerce_product_duplicate') && !doing_action('wp_ajax_woocommerce_do_ajax_product_import') && !$avoid_recursion) { $avoid_recursion = true; if ($variation = wc_get_product($id)) { @@ -320,13 +320,14 @@ class PLLWC_Products * @since 1.0 * * @param int $id Variation product id. + * * @return void */ public function delete_variation($id) { - static $avoid_delete = array(); + static $avoid_delete = []; - if (! doing_action('delete_post') && ! in_array($id, $avoid_delete)) { + if (!doing_action('delete_post') && !in_array($id, $avoid_delete)) { $tr_ids = $this->data_store->get_translations($id); $avoid_delete = array_merge($avoid_delete, array_values($tr_ids)); // To avoid deleting a variation two times. foreach ($tr_ids as $tr_id) { @@ -344,6 +345,7 @@ class PLLWC_Products * * @param int $id ID of the first product to compare. * @param int $other_id ID of the second product to compare. + * * @return bool */ protected static function are_synchronized($id, $other_id) @@ -359,22 +361,23 @@ class PLLWC_Products * @param int $from Product id from which we copy information. * @param int $to Product id which we paste information. * @param bool $sync True if it is synchronization, false if it is a copy. + * * @return bool */ public static function should_copy_texts($from, $to, $sync) { - if (! $sync) { + if (!$sync) { $duplicate_options = get_user_meta(get_current_user_id(), 'pll_duplicate_content', true); - if (! empty($duplicate_options) && is_array($duplicate_options) && ! empty($duplicate_options['product'])) { + if (!empty($duplicate_options) && is_array($duplicate_options) && !empty($duplicate_options['product'])) { return true; } } if (isset(PLL()->sync_post)) { $from = wc_get_product($from); - $to = wc_get_product($to); + $to = wc_get_product($to); - if (! empty($from) && ! empty($to)) { + if (!empty($from) && !empty($to)) { if ('variation' === $from->get_type()) { return self::are_synchronized($from->get_parent_id(), $to->get_parent_id()); } else { @@ -395,16 +398,17 @@ class PLLWC_Products * @param mixed $value Property value. * @param string $prop Property name. * @param string $lang Language code. + * * @return mixed Property value, possibly translated. */ public static function maybe_translate_property($value, string $prop, string $lang) { $tr_value = $value; - if (! empty($value)) { + if (!empty($value)) { switch ($prop) { case 'image_id': - if (! PLL()->options['media_support'] || ! is_numeric($value)) { + if (!PLL()->options['media_support'] || !is_numeric($value)) { break; } @@ -416,11 +420,11 @@ class PLLWC_Products break; case 'gallery_image_ids': - if (! PLL()->options['media_support'] || ! is_string($value)) { + if (!PLL()->options['media_support'] || !is_string($value)) { break; } - $tr_value = array(); + $tr_value = []; foreach (array_map('absint', explode(',', $value)) as $post_id) { if (empty($post_id)) { @@ -442,15 +446,15 @@ class PLLWC_Products case 'children': case 'upsell_ids': case 'cross_sell_ids': - if (! is_array($value)) { + if (!is_array($value)) { break; } $data_store = PLLWC_Data_Store::load('product_language'); - $tr_value = array(); + $tr_value = []; foreach ($value as $id) { - if (! is_numeric($id)) { + if (!is_numeric($id)) { continue; } $tr_id = $data_store->get((int) $id, $lang); @@ -464,7 +468,7 @@ class PLLWC_Products case 'default_attributes': case 'attributes': - if (! is_array($value)) { + if (!is_array($value)) { break; } @@ -496,15 +500,17 @@ class PLLWC_Products * @param array $attributes Product attributes. Could be pairs of attribute taxonomies and term slugs (from `WC_Product_Variation`) * or a list of `WC_Product_Attribute` objects (from other kind of `WC_Product`). * @param string $lang Language code. + * * @return array Array of translated attributes with preserved keys. * * @phpstan-param array $attributes + * * @phpstan-return array */ public static function maybe_translate_attributes($attributes, $lang) { foreach ($attributes as $k => $v) { - if (! pll_is_translated_taxonomy($k)) { + if (!pll_is_translated_taxonomy($k)) { continue; } @@ -515,24 +521,24 @@ class PLLWC_Products */ case 'string': $attributes_taxonomies = wc_get_attribute_taxonomy_names(); - if (! in_array($k, $attributes_taxonomies)) { + if (!in_array($k, $attributes_taxonomies)) { break; } if ('' === $v) { // Correspond to attribute value "Any". - $attributes[ $k ] = ''; + $attributes[$k] = ''; break; } - $terms = get_terms(array( 'taxonomy' => $k, 'slug' => $v, 'hide_empty' => false, 'lang' => '' )); // Don't use get_term_by filtered by language since WP 4.7. + $terms = get_terms(['taxonomy' => $k, 'slug' => $v, 'hide_empty' => false, 'lang' => '']); // Don't use get_term_by filtered by language since WP 4.7. - if (! is_array($terms)) { + if (!is_array($terms)) { break; } $term = reset($terms); - if (! $term instanceof WP_Term) { + if (!$term instanceof WP_Term) { break; } @@ -544,11 +550,11 @@ class PLLWC_Products $tr_term = get_term($tr_id, $k); - if (! $tr_term instanceof WP_Term) { + if (!$tr_term instanceof WP_Term) { break; } - $attributes[ $k ] = $tr_term->slug; + $attributes[$k] = $tr_term->slug; break; /* @@ -556,7 +562,7 @@ class PLLWC_Products * See: {https://github.com/woocommerce/woocommerce/blob/7.3.0/plugins/woocommerce/includes/abstracts/abstract-wc-product.php#L1095-L1120} */ case 'object': - if (! $v instanceof WC_Product_Attribute || ! $v->is_taxonomy()) { + if (!$v instanceof WC_Product_Attribute || !$v->is_taxonomy()) { break; } @@ -566,7 +572,7 @@ class PLLWC_Products break; } - $tr_ids = array(); + $tr_ids = []; foreach ($terms as $term) { $tr_id = pll_get_term($term->term_id, $lang); @@ -580,7 +586,7 @@ class PLLWC_Products $v = clone $v; // Avoid original attribute to be modified. $v->set_options($tr_ids); - $attributes[ $k ] = $v; + $attributes[$k] = $v; break; } } @@ -599,21 +605,22 @@ class PLLWC_Products * @param bool $id_found True if the ID is already associated to an existing product, false otherwise. * @param int $product_id Product ID. * @param string $id_value Product SKU or global unique ID. + * * @return bool */ public function unique_id($id_found, $product_id, $id_value) { - if (! $id_found) { + if (!$id_found) { return $id_found; } $current_filter = current_filter(); - if (! $current_filter) { + if (!$current_filter) { return $id_found; } $current_filter = substr($current_filter, 15); // Can be unique_sku, lock_on_sku or global_unique_id. - $language = PLL()->model->get_language($this->data_store->get_language($product_id)); + $language = PLL()->model->get_language($this->data_store->get_language($product_id)); /** * Filters the language used to filter `wc_product_has_unique_sku` and `wc_product_has_global_unique_id`. @@ -626,9 +633,11 @@ class PLLWC_Products */ $language = apply_filters("pllwc_language_for_{$current_filter}", $language, $product_id); if ($language instanceof PLL_Language) { - $column = in_array($current_filter, array( 'unique_sku', 'lock_on_sku' )) ? 'sku' : $current_filter; + $column = in_array($current_filter, ['unique_sku', 'lock_on_sku']) ? 'sku' : $current_filter; + return $this->data_store->lookup_table_has($column, $id_value, $product_id, $language); } + return $id_found; } @@ -639,12 +648,13 @@ class PLLWC_Products * * @param bool|null $locked Whether the SKU is locked or not, `null` if not processed at all. * @param WC_Product $product Product of the SKU to lock. + * * @return bool|null Whether the SKU is locked or not, `null` if not bypassed. */ public function filter_lock_on_sku($locked, $product) { if (null === $locked && $product instanceof WC_Product) { - return ! $this->unique_id(true, $product->get_id(), $product->get_sku()); + return !$this->unique_id(true, $product->get_id(), $product->get_sku()); } return $locked; @@ -657,15 +667,17 @@ class PLLWC_Products * * @param string[] $excludes Query vars excluded from the language filter. * @param WP_Query $query WP Query object. + * * @return string[] */ public function fix_on_sale_products_block_query($excludes, $query) { $q = &$query->query; - if (isset($q['post_type'], $q['post__in']) && 'product' === $q['post_type'] && array_merge(array( 0 ), wc_get_product_ids_on_sale()) === $q['post__in']) { - $excludes = array_diff($excludes, array( 'post__in' )); + if (isset($q['post_type'], $q['post__in']) && 'product' === $q['post_type'] && array_merge([0], wc_get_product_ids_on_sale()) === $q['post__in']) { + $excludes = array_diff($excludes, ['post__in']); } + return $excludes; } @@ -680,15 +692,16 @@ class PLLWC_Products * @see PLLWC_Products::get_terms_args() * * @param WC_Product|int $product A product being saved. + * * @return void */ public function store_product_data($product) { - if (! $product instanceof WC_Product) { + if (!$product instanceof WC_Product) { $product = wc_get_product($product); } - if (! $product instanceof WC_Product) { + if (!$product instanceof WC_Product) { return; } @@ -699,6 +712,7 @@ class PLLWC_Products if (empty($lang)) { $this->reset_product_data(); + return; } } @@ -707,13 +721,14 @@ class PLLWC_Products if (empty($attributes)) { $this->reset_product_data(); + return; } - $this->product_data = array( + $this->product_data = [ 'lang' => $lang, 'taxonomies' => array_map('wc_sanitize_taxonomy_name', array_keys($attributes)), - ); + ]; } /** @@ -725,6 +740,7 @@ class PLLWC_Products * @see \Automattic\WooCommerce\Internal\ProductAttributesLookup\LookupDataStore::get_term_ids_by_slug_cache() * * @param array $args Arguments passed to WP_Term_Query. + * * @return array Modified arguments. */ public function get_terms_args($args) @@ -737,7 +753,7 @@ class PLLWC_Products // Not the arguments we're looking for. return $args; } - if (empty($args['taxonomy']) || ! is_array($args['taxonomy']) || 1 !== count($args['taxonomy'])) { + if (empty($args['taxonomy']) || !is_array($args['taxonomy']) || 1 !== count($args['taxonomy'])) { // Not the arguments we're looking for. return $args; } @@ -766,20 +782,21 @@ class PLLWC_Products */ public function reset_product_data() { - $this->product_data = array( + $this->product_data = [ 'lang' => false, - 'taxonomies' => array(), - ); + 'taxonomies' => [], + ]; } /** * Synchronizes product properties through all its translations. * The goal is also to trigger the product attributes lookup table update. - * See https://github.com/woocommerce/woocommerce/blob/7.4.1/plugins/woocommerce/includes/abstracts/abstract-wc-product.php#L1428-L1431 + * See https://github.com/woocommerce/woocommerce/blob/7.4.1/plugins/woocommerce/includes/abstracts/abstract-wc-product.php#L1428-L1431. * * @since 1.8 * * @param WC_Product $product The product that has been just saved. + * * @return void */ public function copy_product($product) @@ -819,6 +836,7 @@ class PLLWC_Products * @param WC_Product $from The product we copy information from. * @param WC_Product $to The target product. * @param string $lang Language of the target product. + * * @return int The id of the target product. */ public function copy_product_props($from, $to, $lang) @@ -831,7 +849,7 @@ class PLLWC_Products $to->set_status($from->get_status()); } - if (! empty($to->get_changes())) { + if (!empty($to->get_changes())) { $to->save(); } @@ -847,11 +865,12 @@ class PLLWC_Products * @param int $to ID of the target. * @param string $lang Language slug of the target post. * @param string $strategy `sync` if doing synchro, `copy` otherwise. + * * @return void */ public function synchronize_product($from, $to, $lang, $strategy) { - $product = wc_get_product($from); + $product = wc_get_product($from); $target_product = wc_get_product($to); if (empty($product) || empty($target_product)) { @@ -869,12 +888,13 @@ class PLLWC_Products * @since 2.2 * * @param WC_Product_Variable $product The variable product. + * * @return void */ protected function maybe_set_variations_language(WC_Product_Variable $product): void { $language = $this->data_store->get_language($product->get_id()); - if (! $language) { + if (!$language) { return; } diff --git a/__plugins/polylang-wc/src/stock.php b/__plugins/polylang-wc/src/stock.php index 73484224975badde1be105f2554eb399fd2537d4..7afec2bc494c2f0777af289e91fa07a1335538d1 100644 --- a/__plugins/polylang-wc/src/stock.php +++ b/__plugins/polylang-wc/src/stock.php @@ -1,9 +1,5 @@ data_store = PLLWC_Data_Store::load('product_language'); - add_filter('woocommerce_update_product_stock_query', array( $this, 'update_product_stock_query' ), 10, 2); // Since WC 3.6. - add_action('woocommerce_updated_product_stock', array( $this, 'updated_product_stock' )); // Since WC 3.6. + add_filter('woocommerce_update_product_stock_query', [$this, 'update_product_stock_query'], 10, 2); // Since WC 3.6. + add_action('woocommerce_updated_product_stock', [$this, 'updated_product_stock']); // Since WC 3.6. - add_filter('woocommerce_query_for_reserved_stock', array( $this, 'query_for_reserved_stock' ), 10, 2); + add_filter('woocommerce_query_for_reserved_stock', [$this, 'query_for_reserved_stock'], 10, 2); } /** @@ -42,6 +38,7 @@ class PLLWC_Stock * * @param string $sql SQL query used to update the product stock. * @param int $product_id Product id. + * * @return string Modified SQL query. */ public function update_product_stock_query($sql, $product_id) @@ -63,6 +60,7 @@ class PLLWC_Stock * @since 1.2 * * @param int $id Product id. + * * @return void */ public function updated_product_stock($id) @@ -78,13 +76,14 @@ class PLLWC_Stock } /** - * Synchronizes reserve_stock_for_product across translations + * Synchronizes reserve_stock_for_product across translations. * * @since 1.5 * @since 1.8 Removed the 3rd parameter. * * @param string $query The query to get the reserved stock of a product. * @param int $product_id Product ID. + * * @return string */ public function query_for_reserved_stock($query, $product_id) @@ -93,7 +92,7 @@ class PLLWC_Stock $product_ids = $this->data_store->get_translations($product_id); - if (empty(array_diff($product_ids, array( $product_id )))) { + if (empty(array_diff($product_ids, [$product_id]))) { // No other translations. return $query; } diff --git a/__plugins/polylang-wc/src/store-blocks.php b/__plugins/polylang-wc/src/store-blocks.php index 08a0a3aefb88f1eec96cef35533febd2f62251db..61ec09d69d2f94b80a7e9b85e7e637302f599a23 100644 --- a/__plugins/polylang-wc/src/store-blocks.php +++ b/__plugins/polylang-wc/src/store-blocks.php @@ -1,9 +1,5 @@ add_filters(); } else { - add_action('pll_language_defined', array( $this, 'add_filters' ), 1); + add_action('pll_language_defined', [$this, 'add_filters'], 1); } // The language is not defined yet in REST. if (Polylang::is_rest_request()) { - add_filter('locale', array( $this, 'get_locale' )); + add_filter('locale', [$this, 'get_locale']); } } @@ -44,21 +40,21 @@ class PLLWC_Store_Blocks */ public function add_filters() { - add_action('wp_footer', array( $this, 'filter_dynamic_blocks' ), 0); + add_action('wp_footer', [$this, 'filter_dynamic_blocks'], 0); - add_action('woocommerce_blocks_checkout_enqueue_data', array( $this, 'hydrate_store_routes' )); - add_action('woocommerce_blocks_cart_enqueue_data', array( $this, 'hydrate_store_routes' )); + add_action('woocommerce_blocks_checkout_enqueue_data', [$this, 'hydrate_store_routes']); + add_action('woocommerce_blocks_cart_enqueue_data', [$this, 'hydrate_store_routes']); // Use `render_block_data` to translate only attribute ids rather than content (which contains content such as post titles and links). - add_filter('render_block_data', array( $this, 'filter_reviews_by_product_block_id' )); + add_filter('render_block_data', [$this, 'filter_reviews_by_product_block_id']); // Fix assets URLs when using one domain per language. if (PLL()->options['force_lang'] > 1) { - add_filter('transient_woocommerce_blocks_asset_api_script_data', array( $this, 'blocks_assets_links' )); - add_filter('transient_woocommerce_blocks_asset_api_script_data_ssl', array( $this, 'blocks_assets_links' )); + add_filter('transient_woocommerce_blocks_asset_api_script_data', [$this, 'blocks_assets_links']); + add_filter('transient_woocommerce_blocks_asset_api_script_data_ssl', [$this, 'blocks_assets_links']); } - add_action('woocommerce_store_api_checkout_order_processed', array( $this, 'ensure_order_language' )); + add_action('woocommerce_store_api_checkout_order_processed', [$this, 'ensure_order_language']); } /** @@ -90,7 +86,7 @@ class PLLWC_Store_Blocks * is loaded before `wp-api-fetch` we're using to register our script to filter by language. * So we need to check `wc-cart-checkout-base` is enqueued to add our script after `wp-api-fetch` * only in this case. - */ + */ if (wp_script_is('wc-cart-checkout-base')) { wp_add_inline_script('wp-api-fetch', $script, 'after'); } @@ -108,12 +104,12 @@ class PLLWC_Store_Blocks */ public function hydrate_store_routes(): void { - if (! is_admin() && ! WC()->is_rest_api_request()) { + if (!is_admin() && !WC()->is_rest_api_request()) { $asset_data_registry = Package::container()->get(AssetDataRegistry::class); - $asset_data_registry->hydrate_api_request('/wc/store/v1/cart?lang=' . pll_current_language()); + $asset_data_registry->hydrate_api_request('/wc/store/v1/cart?lang='.pll_current_language()); if (current_action() === 'woocommerce_blocks_checkout_enqueue_data') { - $asset_data_registry->hydrate_data_from_api_request('checkoutData', '/wc/store/v1/checkout?lang=' . pll_current_language()); + $asset_data_registry->hydrate_data_from_api_request('checkoutData', '/wc/store/v1/checkout?lang='.pll_current_language()); } } } @@ -124,6 +120,7 @@ class PLLWC_Store_Blocks * @since 1.5.3 * * @param string $path The REST API path to filter. + * * @return string Inline js script to add. */ protected function get_filter_script($path) @@ -131,8 +128,8 @@ class PLLWC_Store_Blocks /** @var string $current_language This cannot be false because the language is defined at this point */ $current_language = pll_current_language(); - $path = esc_js($path); - $lang = esc_js($current_language); + $path = esc_js($path); + $lang = esc_js($current_language); return "wp.apiFetch.use( function( options, next ) { @@ -150,6 +147,7 @@ class PLLWC_Store_Blocks * @since 1.9 * * @param array $parsed_block The block being rendered. + * * @return array */ public function filter_reviews_by_product_block_id($parsed_block) @@ -170,7 +168,7 @@ class PLLWC_Store_Blocks } $translated_product_id = $data_store->get($parsed_block['attrs']['productId']); - if (! $translated_product_id) { + if (!$translated_product_id) { return $parsed_block; } @@ -184,13 +182,14 @@ class PLLWC_Store_Blocks * * @since 1.9.5 * - * @param string $locale The locale ID. + * @param string $locale The locale ID. + * * @return string */ public function get_locale($locale) { $requested_url = pll_get_requested_url(); - if (! is_string($requested_url) || ! strpos($requested_url, '/wc/store/v1')) { + if (!is_string($requested_url) || !strpos($requested_url, '/wc/store/v1')) { return $locale; } @@ -213,6 +212,7 @@ class PLLWC_Store_Blocks * @since 2.1 * * @param string|false $value Current value of the WooCommerce transient (JSON encoded). + * * @return string|false WooCommerce transient with blocks assets URLs modified with the current language. */ public function blocks_assets_links($value) @@ -222,7 +222,7 @@ class PLLWC_Store_Blocks if ( json_last_error() !== JSON_ERROR_NONE || empty($transient_value['script_data']) || - ! is_array($transient_value['script_data']) + !is_array($transient_value['script_data']) ) { return $value; } @@ -234,20 +234,19 @@ class PLLWC_Store_Blocks /** @var PLL_Language $language */ $language = PLL()->curlang; - $transient_value['script_data'][ $key ]['src'] = PLL()->links_model->switch_language_in_link($script_data['src'], $language); + $transient_value['script_data'][$key]['src'] = PLL()->links_model->switch_language_in_link($script_data['src'], $language); } return wp_json_encode($transient_value); } - - /** * Ensures the order language is set correctly. * * @since 2.2 * * @param WC_Order $order Order being processed. + * * @return void */ public function ensure_order_language($order) diff --git a/__plugins/polylang-wc/src/strings.php b/__plugins/polylang-wc/src/strings.php index ffc2ce243dfd986ef4d751f3de8e79c392f1104f..a9e94429ba5e2472f5c9bd294d14f4844195216a 100644 --- a/__plugins/polylang-wc/src/strings.php +++ b/__plugins/polylang-wc/src/strings.php @@ -1,9 +1,5 @@ array( 'name' => __('Footer text', 'polylang-wc'), 'multiline' => true ), - 'demo_store_notice' => array( 'name' => __('Store notice text', 'polylang-wc'), 'multiline' => true ), - 'price_display_suffix' => array( 'name' => 'price_display_suffix' ), - 'currency_pos' => array( 'name' => __('Currency position', 'polylang-wc') ), - 'price_thousand_sep' => array( 'name' => __('Thousand separator', 'polylang-wc') ), - 'price_decimal_sep' => array( 'name' => __('Decimal separator', 'polylang-wc') ), - 'registration_privacy_policy_text' => array( 'name' => __('Registration privacy policy', 'polylang-wc'), 'multiline' => true ), - 'checkout_privacy_policy_text' => array( 'name' => __('Checkout privacy policy', 'polylang-wc'), 'multiline' => true ), - 'checkout_terms_and_conditions_checkbox_text' => array( 'name' => __('Terms and conditions', 'polylang-wc') ), - 'email_from_name' => array( 'name' => 'email_from_name' ), - 'email_from_address' => array( 'name' => 'email_from_address' ), - 'email_header_image' => array( 'name' => __('Email header image', 'polylang-wc') ), - - ); + return [ + 'email_footer_text' => ['name' => __('Footer text', 'polylang-wc'), 'multiline' => true], + 'demo_store_notice' => ['name' => __('Store notice text', 'polylang-wc'), 'multiline' => true], + 'price_display_suffix' => ['name' => 'price_display_suffix'], + 'currency_pos' => ['name' => __('Currency position', 'polylang-wc')], + 'price_thousand_sep' => ['name' => __('Thousand separator', 'polylang-wc')], + 'price_decimal_sep' => ['name' => __('Decimal separator', 'polylang-wc')], + 'registration_privacy_policy_text' => ['name' => __('Registration privacy policy', 'polylang-wc'), 'multiline' => true], + 'checkout_privacy_policy_text' => ['name' => __('Checkout privacy policy', 'polylang-wc'), 'multiline' => true], + 'checkout_terms_and_conditions_checkbox_text' => ['name' => __('Terms and conditions', 'polylang-wc')], + 'email_from_name' => ['name' => 'email_from_name'], + 'email_from_address' => ['name' => 'email_from_address'], + 'email_header_image' => ['name' => __('Email header image', 'polylang-wc')], + + ]; } /** @@ -89,6 +85,7 @@ class PLLWC_Strings * @since 0.1 * * @param string $prop Property name. + * * @return bool */ protected function is_translated_email_property($prop) @@ -102,6 +99,7 @@ class PLLWC_Strings * @since 0.1 * * @param string $prop Property name. + * * @return bool */ protected function is_translated_shipping_property($prop) @@ -115,6 +113,7 @@ class PLLWC_Strings * @since 1.5.5 * * @param string $prop Property name. + * * @return bool */ protected function is_email_property_multiline($prop) @@ -130,18 +129,19 @@ class PLLWC_Strings * @param WC_Settings_API[] $objects Array of objects having properties to translate. * @param callable $is_translated_cb Function testing if a property should be translated. * @param callable $is_multiline_cb Function testing if the input field should be multiline (default to false). + * * @return void */ protected function register_sub_options($objects, $is_translated_cb, $is_multiline_cb = '__return_false') { foreach ($objects as $obj) { - if (! isset($obj->enabled) || 'no' !== $obj->enabled) { + if (!isset($obj->enabled) || 'no' !== $obj->enabled) { foreach (array_keys($obj->form_fields) as $prop) { if (call_user_func($is_translated_cb, $prop, $obj)) { - if (! empty($obj->settings[ $prop ])) { - pll_register_string($prop . '_' . $obj->id, $obj->settings[ $prop ], 'WooCommerce', call_user_func($is_multiline_cb, $prop)); - } elseif (! empty($obj->$prop)) { - pll_register_string($prop . '_' . $obj->id, $obj->$prop, 'WooCommerce', call_user_func($is_multiline_cb, $prop)); + if (!empty($obj->settings[$prop])) { + pll_register_string($prop.'_'.$obj->id, $obj->settings[$prop], 'WooCommerce', call_user_func($is_multiline_cb, $prop)); + } elseif (!empty($obj->$prop)) { + pll_register_string($prop.'_'.$obj->id, $obj->$prop, 'WooCommerce', call_user_func($is_multiline_cb, $prop)); } } } @@ -163,25 +163,25 @@ class PLLWC_Strings */ new PLL_Translate_Option( 'pickup_location_pickup_locations', - array( - '*' => array( + [ + '*' => [ 'name' => 1, 'details' => 1, - ), - ), - array( + ], + ], + [ 'context' => 'WooCommerce', - ) + ] ); new PLL_Translate_Option( 'woocommerce_pickup_location_settings', - array( + [ 'title' => 1, - ), - array( + ], + [ 'context' => 'WooCommerce', - ) + ] ); } @@ -191,22 +191,23 @@ class PLLWC_Strings * @since 2.2 * * @param WC_Shipping_Method[]|stdClass[] $methods Array of shipping method instances. + * * @return WC_Shipping_Method[]|stdClass[] */ public function translate_shipping_methods($methods) { foreach ($methods as $method) { - if (! $method instanceof WC_Shipping_Method) { + if (!$method instanceof WC_Shipping_Method) { continue; } new PLL_Translate_Option( $method->get_instance_option_key(), - array( 'title' => true ), - array( + ['title' => true], + [ 'context' => 'WooCommerce', - 'sanitize_callback' => Closure::fromCallable(array( $this, 'sanitize_text_field' )), - ) + 'sanitize_callback' => Closure::fromCallable([$this, 'sanitize_text_field']), + ] ); } @@ -219,13 +220,14 @@ class PLLWC_Strings * @since 2.0 * * @param Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry $integration_registry Woo integration registry. + * * @return void */ public function translate_payment_method_blocks($integration_registry): void { $gateways = $integration_registry->get_all_registered(); foreach ($gateways as $gateway) { - if (! $gateway instanceof PaymentMethodTypeInterface) { + if (!$gateway instanceof PaymentMethodTypeInterface) { continue; } $this->block_gateways[] = $gateway->get_name(); @@ -251,6 +253,7 @@ class PLLWC_Strings * @since 2.0 * * @param WC_Payment_Gateways $gateways Woo gateways registry. + * * @return void */ public function translate_payment_gateways($gateways) @@ -264,7 +267,7 @@ class PLLWC_Strings } /** - * Registers strings + * Registers strings. * * @since 0.1 * @@ -277,12 +280,12 @@ class PLLWC_Strings // Emails. $this->register_sub_options( WC_Emails::instance()->get_emails(), - array( $this, 'is_translated_email_property' ), - array( $this, 'is_email_property_multiline' ) + [$this, 'is_translated_email_property'], + [$this, 'is_email_property_multiline'] ); // BACS Account details. - $woocommerce_bacs_accounts = get_option('woocommerce_bacs_accounts', array()); + $woocommerce_bacs_accounts = get_option('woocommerce_bacs_accounts', []); if (is_array($woocommerce_bacs_accounts)) { foreach ($woocommerce_bacs_accounts as $account) { pll_register_string(__('Account name', 'polylang-wc'), $account['account_name'], 'WooCommerce'); @@ -300,13 +303,13 @@ class PLLWC_Strings // see `WC_Shipping::get_shipping_method_class_names()`. $this->register_sub_options( WC_Shipping::instance()->get_shipping_methods(), - array( $this, 'is_translated_shipping_property' ) + [$this, 'is_translated_shipping_property'] ); // Strings as single option. foreach (self::get_options() as $string => $arr) { - if ($option = get_option('woocommerce_' . $string)) { - pll_register_string($arr['name'], $option, 'WooCommerce', ! empty($arr['multiline'])); + if ($option = get_option('woocommerce_'.$string)) { + pll_register_string($arr['name'], $option, 'WooCommerce', !empty($arr['multiline'])); } } @@ -322,20 +325,20 @@ class PLLWC_Strings } // Local pickup. - $pickup_locations = get_option('pickup_location_pickup_locations', array()); + $pickup_locations = get_option('pickup_location_pickup_locations', []); if (is_array($pickup_locations)) { foreach ($pickup_locations as $pickup_location) { - if (! empty($pickup_location['name'])) { + if (!empty($pickup_location['name'])) { pll_register_string(__('Local pickup location name', 'polylang-wc'), $pickup_location['name'], 'WooCommerce'); } - if (! empty($pickup_location['details'])) { + if (!empty($pickup_location['details'])) { pll_register_string(__('Local pickup location details', 'polylang-wc'), $pickup_location['details'], 'WooCommerce'); } } } - $pickup_location_settings = get_option('woocommerce_pickup_location_settings', array()); - if (is_array($pickup_location_settings) && ! empty($pickup_location_settings['title'])) { + $pickup_location_settings = get_option('woocommerce_pickup_location_settings', []); + if (is_array($pickup_location_settings) && !empty($pickup_location_settings['title'])) { pll_register_string(__('Local pickup title', 'polylang-wc'), $pickup_location_settings['title'], 'WooCommerce'); } } @@ -349,6 +352,7 @@ class PLLWC_Strings * @param string $translation The string translation. * @param string $name The name as defined in pll_register_string. * @param string $context The context as defined in pll_register_string. + * * @return string sanitized translation */ public function sanitize_strings($translation, $name, $context) @@ -388,7 +392,7 @@ class PLLWC_Strings $translation = wc_clean($translation); break; case __('Currency position', 'polylang-wc'): - $translation = in_array($translation, array( 'left', 'right', 'left_space', 'right_space' )) ?: get_option('woocommerce_currency_pos', 'left'); + $translation = in_array($translation, ['left', 'right', 'left_space', 'right_space']) ?: get_option('woocommerce_currency_pos', 'left'); break; // Emails options. @@ -413,6 +417,7 @@ class PLLWC_Strings } break; } + return $translation; } @@ -426,37 +431,37 @@ class PLLWC_Strings public function translate_strings() { // Gateway instructions in emails. - add_action('woocommerce_email_before_order_table', array( $this, 'translate_instructions' ), 5); // Before WooCommerce. + add_action('woocommerce_email_before_order_table', [$this, 'translate_instructions'], 5); // Before WooCommerce. // Gateway instructions in thankyou page. - add_action('woocommerce_before_thankyou', array( $this, 'translate_instructions' )); // Since WooCommerce 3.7. + add_action('woocommerce_before_thankyou', [$this, 'translate_instructions']); // Since WooCommerce 3.7. - add_filter('woocommerce_bacs_accounts', array( $this, 'translate_bacs_accounts' )); + add_filter('woocommerce_bacs_accounts', [$this, 'translate_bacs_accounts']); - if (isset($_COOKIE[ PLL_COOKIE ]) && pll_current_language() !== $_COOKIE[ PLL_COOKIE ]) { - add_action('woocommerce_before_calculate_totals', array( $this, 'reset_shipping_language' )); + if (isset($_COOKIE[PLL_COOKIE]) && pll_current_language() !== $_COOKIE[PLL_COOKIE]) { + add_action('woocommerce_before_calculate_totals', [$this, 'reset_shipping_language']); } // Options. foreach (array_keys(self::get_options()) as $string) { - add_filter('option_woocommerce_' . $string, 'pll__'); + add_filter('option_woocommerce_'.$string, 'pll__'); } // Attributes. - add_filter('woocommerce_attribute_taxonomies', array( $this, 'attribute_taxonomies' )); + add_filter('woocommerce_attribute_taxonomies', [$this, 'attribute_taxonomies']); add_filter('woocommerce_attribute_label', 'pll__'); // Tax rate labels. add_filter('woocommerce_rate_label', 'pll__'); - add_filter('woocommerce_find_rates', array( $this, 'find_rates' )); - add_filter('woocommerce_order_get_tax_totals', array( $this, 'set_tax_label' )); + add_filter('woocommerce_find_rates', [$this, 'find_rates']); + add_filter('woocommerce_order_get_tax_totals', [$this, 'set_tax_label']); // Gateways. add_filter('woocommerce_gateway_title', 'pll__'); add_filter('woocommerce_gateway_description', 'pll__'); // Shipping methods. - add_filter('woocommerce_package_rates', array( $this, 'translate_shipping' )); + add_filter('woocommerce_package_rates', [$this, 'translate_shipping']); // Shipping methods since WooCommerce 2.6. add_filter('woocommerce_shipping_rate_label', 'pll__'); @@ -471,10 +476,10 @@ class PLLWC_Strings */ public function translate_emails() { - add_filter('woocommerce_email_get_option', array( $this, 'translate_email_option' ), 10, 4); + add_filter('woocommerce_email_get_option', [$this, 'translate_email_option'], 10, 4); // These filters are added by Polylang but not on admin. - foreach (array( 'option_blogname', 'option_blogdescription', 'option_date_format', 'option_time_format' ) as $filter) { + foreach (['option_blogname', 'option_blogdescription', 'option_date_format', 'option_time_format'] as $filter) { add_filter($filter, 'pll__', 1); } @@ -497,6 +502,7 @@ class PLLWC_Strings * @param WC_Email $email Instance of WC_Email, not used. * @param string $_value Same as $value, not used. * @param string $key Option name. + * * @return string */ public function translate_email_option($value, $email, $_value, $key) @@ -504,6 +510,7 @@ class PLLWC_Strings if ($this->is_translated_email_property($key)) { $value = pll__($value); } + return $value; } @@ -519,7 +526,7 @@ class PLLWC_Strings $gateways = WC_Payment_Gateways::instance()->get_available_payment_gateways(); foreach ($gateways as $key => $gateway) { if (isset($gateway->instructions)) { - $gateways[ $key ]->instructions = pll__($gateway->instructions); + $gateways[$key]->instructions = pll__($gateway->instructions); } } } @@ -530,18 +537,20 @@ class PLLWC_Strings * @since 1.2 * * @param array $accounts Array of account details. + * * @return array */ public function translate_bacs_accounts($accounts) { - if (! is_array($accounts)) { + if (!is_array($accounts)) { return $accounts; } foreach ($accounts as $k => $account) { - $accounts[ $k ]['account_name'] = pll__($account['account_name']); - $accounts[ $k ]['bank_name'] = pll__($account['bank_name']); + $accounts[$k]['account_name'] = pll__($account['account_name']); + $accounts[$k]['bank_name'] = pll__($account['bank_name']); } + return $accounts; } @@ -551,13 +560,15 @@ class PLLWC_Strings * @since 0.1 * * @param WC_Shipping_Rate[] $rates Array of WC_Shipping_Rate objects. + * * @return array */ public function translate_shipping($rates) { foreach ($rates as $key => $rate) { - $rates[ $key ]->set_label(pll__($rate->get_label())); + $rates[$key]->set_label(pll__($rate->get_label())); } + return $rates; } @@ -579,6 +590,7 @@ class PLLWC_Strings * @since 0.1 * * @param stdClass[] $attribute_taxonomies Attribute taxonomies. + * * @return stdClass[] */ public function attribute_taxonomies($attribute_taxonomies) @@ -586,6 +598,7 @@ class PLLWC_Strings foreach ($attribute_taxonomies as $attr) { $attr->attribute_label = pll__($attr->attribute_label); } + return $attribute_taxonomies; } @@ -595,13 +608,15 @@ class PLLWC_Strings * @since 1.2 * * @param array $rates An array of tax rates. + * * @return array */ public function find_rates($rates) { foreach ($rates as $k => $rate) { - $rates[ $k ]['label'] = pll__($rate['label']); + $rates[$k]['label'] = pll__($rate['label']); } + return $rates; } @@ -612,6 +627,7 @@ class PLLWC_Strings * @see WC_Abstract_Order::get_tax_totals() * * @param array $tax_totals Array of tax-data. + * * @return array * * @phpstan-param array< @@ -629,7 +645,7 @@ class PLLWC_Strings public function set_tax_label($tax_totals) { foreach ($tax_totals as $code => $tax) { - $tax_totals[ $code ]->label = \WC_Tax::get_rate_label($tax->rate_id); + $tax_totals[$code]->label = \WC_Tax::get_rate_label($tax->rate_id); } return $tax_totals; @@ -644,23 +660,26 @@ class PLLWC_Strings * @param string $label Attribute label. * @param string $name Taxonomy name, not used. * @param WC_Product|string $product Product data or empty string. + * * @return string */ public function attribute_label($label, $name, $product) { // Don't translate the attribute label when exporting a product, as it would create new attributes if the file is imported back. - if ($product instanceof WC_Product && ! doing_action('wp_ajax_woocommerce_do_ajax_product_export')) { + if ($product instanceof WC_Product && !doing_action('wp_ajax_woocommerce_do_ajax_product_export')) { $data_store = PLLWC_Data_Store::load('product_language'); - $lang = $data_store->get_language($product->get_id()); + $lang = $data_store->get_language($product->get_id()); $language = PLL()->model->get_language($lang); if ($language) { $mo = new PLL_MO(); $mo->import_from_db($language); + return $mo->translate($label); } } + return $label; } @@ -672,11 +691,12 @@ class PLLWC_Strings * @param string $string The string to sanitize. * @param string $name The option name as defined in `PLL_Translate_Option`. * @param string $context The context as defined in `PLL_Translate_Option`. + * * @return string The sanitized string. */ private function sanitize_text_field($string, $name, $context): string { - if ('WooCommerce' !== $context || ! in_array($name, array( 'title', 'description', 'instructions' ), true)) { + if ('WooCommerce' !== $context || !in_array($name, ['title', 'description', 'instructions'], true)) { return $string; } @@ -689,21 +709,22 @@ class PLLWC_Strings * @since 2.0 * * @param string $option_key The gateway option key. + * * @return void */ private function translate_payment_gateway_option($option_key) { new PLL_Translate_Option( $option_key, - array( + [ 'title' => true, 'description' => true, 'instructions' => true, - ), - array( + ], + [ 'context' => 'WooCommerce', - 'sanitize_callback' => Closure::fromCallable(array( $this, 'sanitize_text_field' )), - ) + 'sanitize_callback' => Closure::fromCallable([$this, 'sanitize_text_field']), + ] ); } } diff --git a/__plugins/polylang-wc/src/sync-content.php b/__plugins/polylang-wc/src/sync-content.php index 0fcfd588b5b32a14f5887ca441f8c200365dcf9a..41ec761c04c91d16005461ef2d036f3a0d307dd4 100644 --- a/__plugins/polylang-wc/src/sync-content.php +++ b/__plugins/polylang-wc/src/sync-content.php @@ -1,9 +1,5 @@ get($id, $lang); } - $blocks[ $k ]['attrs']['products'] = $products; - $blocks[ $k ]['innerHTML'] = preg_replace('#ids="\d+(,\d+)*"#', 'ids="' . implode(',', $products) . '"', $block['innerHTML']); - $blocks[ $k ]['innerContent'][0] = $blocks[ $k ]['innerHTML']; + $blocks[$k]['attrs']['products'] = $products; + $blocks[$k]['innerHTML'] = preg_replace('#ids="\d+(,\d+)*"#', 'ids="'.implode(',', $products).'"', $block['innerHTML']); + $blocks[$k]['innerContent'][0] = $blocks[$k]['innerHTML']; break; case 'woocommerce/product-category': @@ -54,30 +51,30 @@ class PLLWC_Sync_Content case 'woocommerce/product-new': case 'woocommerce/product-top-rated': case 'woocommerce/product-on-sale': - if (! empty($block['attrs']['categories'])) { - $categories = array(); + if (!empty($block['attrs']['categories'])) { + $categories = []; foreach ($block['attrs']['categories'] as $id) { $categories[] = pll_get_term($id, $lang); } - $blocks[ $k ]['attrs']['categories'] = $categories; - $blocks[ $k ]['innerHTML'] = preg_replace('#category="\d+(,\d+)*"#', 'category="' . implode(',', $categories) . '"', $block['innerHTML']); - $blocks[ $k ]['innerContent'][0] = $blocks[ $k ]['innerHTML']; + $blocks[$k]['attrs']['categories'] = $categories; + $blocks[$k]['innerHTML'] = preg_replace('#category="\d+(,\d+)*"#', 'category="'.implode(',', $categories).'"', $block['innerHTML']); + $blocks[$k]['innerContent'][0] = $blocks[$k]['innerHTML']; } break; case 'woocommerce/products-by-attribute': - $terms = array(); + $terms = []; foreach ($block['attrs']['attributes'] as $n => $attributes) { $tr_id = pll_get_term($attributes['id'], $lang); - $blocks[ $k ]['attrs']['attributes'][ $n ]['id'] = $tr_id; + $blocks[$k]['attrs']['attributes'][$n]['id'] = $tr_id; $terms[] = $tr_id; } - $blocks[ $k ]['innerHTML'] = preg_replace('#terms="\d+(,\d+)*"#', 'terms="' . implode(',', $terms) . '"', $block['innerHTML']); - $blocks[ $k ]['innerContent'][0] = $blocks[ $k ]['innerHTML']; + $blocks[$k]['innerHTML'] = preg_replace('#terms="\d+(,\d+)*"#', 'terms="'.implode(',', $terms).'"', $block['innerHTML']); + $blocks[$k]['innerContent'][0] = $blocks[$k]['innerHTML']; break; case 'woocommerce/featured-product': @@ -86,7 +83,7 @@ class PLLWC_Sync_Content } $data_store = PLLWC_Data_Store::load('product_language'); - $tr_id = $data_store->get($block['attrs']['productId'], $lang); + $tr_id = $data_store->get($block['attrs']['productId'], $lang); if (empty($tr_id)) { break; @@ -98,16 +95,16 @@ class PLLWC_Sync_Content break; } - $blocks[ $k ]['attrs']['productId'] = $tr_id; + $blocks[$k]['attrs']['productId'] = $tr_id; $tr_link = $product->get_permalink(); - if (empty($tr_link) || ! is_string($tr_link)) { + if (empty($tr_link) || !is_string($tr_link)) { break; } // Translates the URL in the button. - $this->translate_button_link($blocks[ $k ]['innerBlocks'][0], $tr_link); + $this->translate_button_link($blocks[$k]['innerBlocks'][0], $tr_link); break; case 'woocommerce/featured-category': @@ -121,16 +118,16 @@ class PLLWC_Sync_Content break; } - $blocks[ $k ]['attrs']['categoryId'] = $tr_id; + $blocks[$k]['attrs']['categoryId'] = $tr_id; $tr_link = get_term_link($tr_id); - if (empty($tr_link) || ! is_string($tr_link)) { + if (empty($tr_link) || !is_string($tr_link)) { break; } // Translates the URL in the button. - $this->translate_button_link($blocks[ $k ]['innerBlocks'][0], $tr_link); + $this->translate_button_link($blocks[$k]['innerBlocks'][0], $tr_link); break; case 'woocommerce/reviews-by-product': @@ -138,13 +135,13 @@ class PLLWC_Sync_Content $tr_id = $data_store->get($block['attrs']['productId'], $lang); - $blocks[ $k ]['attrs']['productId'] = $tr_id; - $blocks[ $k ]['innerHTML'] = preg_replace('#data-product-id="\d+"#', 'data-product-id="' . $tr_id . '"', $block['innerHTML']); - $blocks[ $k ]['innerContent'][0] = $blocks[ $k ]['innerHTML']; + $blocks[$k]['attrs']['productId'] = $tr_id; + $blocks[$k]['innerHTML'] = preg_replace('#data-product-id="\d+"#', 'data-product-id="'.$tr_id.'"', $block['innerHTML']); + $blocks[$k]['innerContent'][0] = $blocks[$k]['innerHTML']; break; case 'woocommerce/reviews-by-category': - $categories = array(); + $categories = []; foreach ($block['attrs']['categoryIds'] as $id) { $tr_id = pll_get_term($id, $lang); @@ -153,15 +150,15 @@ class PLLWC_Sync_Content } } - if (! empty($categories)) { - $blocks[ $k ]['attrs']['categoryIds'] = $categories; - $blocks[ $k ]['innerHTML'] = preg_replace('#data-category-ids="\d+(,\d+)*"#', 'data-category-ids="' . implode(',', $categories) . '"', $block['innerHTML']); - $blocks[ $k ]['innerContent'][0] = $blocks[ $k ]['innerHTML']; + if (!empty($categories)) { + $blocks[$k]['attrs']['categoryIds'] = $categories; + $blocks[$k]['innerHTML'] = preg_replace('#data-category-ids="\d+(,\d+)*"#', 'data-category-ids="'.implode(',', $categories).'"', $block['innerHTML']); + $blocks[$k]['innerContent'][0] = $blocks[$k]['innerHTML']; } break; case 'woocommerce/product-tag': - $tags = array(); + $tags = []; foreach ($block['attrs']['tags'] as $id) { $tr_id = pll_get_term($id, $lang); @@ -170,8 +167,8 @@ class PLLWC_Sync_Content } } - if (! empty($tags)) { - $blocks[ $k ]['attrs']['tags'] = $tags; + if (!empty($tags)) { + $blocks[$k]['attrs']['tags'] = $tags; } break; } @@ -187,11 +184,12 @@ class PLLWC_Sync_Content * * @param array $innerblock The block to search into and to modify. * @param string $link The translated link for replacing. + * * @return void */ private function translate_button_link(array &$innerblock, string $link) { - if (! empty($innerblock['innerBlocks'])) { + if (!empty($innerblock['innerBlocks'])) { $this->translate_link($innerblock['innerBlocks'][0], $link); // Since WC 6.4.0. } else { $this->translate_link($innerblock, $link); // If the block was created in WC < 6.4.0. @@ -205,6 +203,7 @@ class PLLWC_Sync_Content * * @param array $innerblock The block to search into and to modify. * @param string $link The translated link for replacing. + * * @return void */ private function translate_link(array &$innerblock, string $link) @@ -219,7 +218,7 @@ class PLLWC_Sync_Content $href = $tags[0]->getAttribute('href'); - $innerblock['innerHTML'] = str_replace($href, $link, $innerblock['innerHTML']); + $innerblock['innerHTML'] = str_replace($href, $link, $innerblock['innerHTML']); $innerblock['innerContent'][0] = $innerblock['innerHTML']; } } diff --git a/__plugins/polylang-wc/src/translated-object-language.php b/__plugins/polylang-wc/src/translated-object-language.php index 9eb76bbf528224eaedd2c67f3e18e107db6a978c..58922649e41daec390578d2d683ca416a132ad9e 100644 --- a/__plugins/polylang-wc/src/translated-object-language.php +++ b/__plugins/polylang-wc/src/translated-object-language.php @@ -1,9 +1,5 @@ @@ -60,6 +57,7 @@ abstract class PLLWC_Translated_Object_Language extends PLLWC_Object_Language * @since 1.9 Type-hinted. * * @param int $id Object ID. + * * @return int[] An associative array of translations with language code as key and translation ID as value. * * @phpstan-return array @@ -76,13 +74,14 @@ abstract class PLLWC_Translated_Object_Language extends PLLWC_Object_Language * * @param int $id Object ID. * @param PLL_Language|string|null $lang Optional language (object or slug), defaults to the current language. + * * @return int|null The translation object ID if exists, `0` otherwise. `null` if the language is not defined yet. * * @phpstan-return int<0, max>|null */ public function get($id, $lang = null) { - $lang = ! empty($lang) ? $lang : pll_current_language(\OBJECT); + $lang = !empty($lang) ? $lang : pll_current_language(\OBJECT); if (empty($lang)) { return null; diff --git a/__plugins/polylang-wc/src/variation-data-store-cpt.php b/__plugins/polylang-wc/src/variation-data-store-cpt.php index 73a861ea9efae86edbed85e295b5482405789cc2..7815be9af66d6070488e8129c1d42a228871f587 100644 --- a/__plugins/polylang-wc/src/variation-data-store-cpt.php +++ b/__plugins/polylang-wc/src/variation-data-store-cpt.php @@ -1,9 +1,5 @@ variation_data_store = $store; - $this->language_data_store = PLLWC_Data_Store::load('product_language'); + $this->language_data_store = PLLWC_Data_Store::load('product_language'); } - /** * Reads a product from the database and sets its data. * * @since 1.6 * * @param WC_Product_Variation $product Product object. + * * @return void */ public function read(&$product) { $this->attribute_filter_lang = $this->language_data_store->get_language($product->get_id()); - add_filter('get_terms_args', array( $this, 'get_terms_args' )); + add_filter('get_terms_args', [$this, 'get_terms_args']); $this->variation_data_store->read($product); - remove_filter('get_terms_args', array( $this, 'get_terms_args' )); + remove_filter('get_terms_args', [$this, 'get_terms_args']); } /** @@ -103,21 +100,22 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * @since 2.1.5 * * @param WC_Product $product Product object. + * * @return string The generated attribute summary. */ public function get_attribute_summary($product) { - if (! is_callable(array( $this->variation_data_store, 'get_attribute_summary' ))) { + if (!is_callable([$this->variation_data_store, 'get_attribute_summary'])) { // Ensure custom data store implements the method, since it's not in `WC_Object_Data_Store_Interface`. return ''; } $this->attribute_filter_lang = $this->language_data_store->get_language($product->get_id()); - add_filter('get_terms_args', array( $this, 'get_terms_args' )); + add_filter('get_terms_args', [$this, 'get_terms_args']); $attribute_summary = $this->variation_data_store->get_attribute_summary($product); - remove_filter('get_terms_args', array( $this, 'get_terms_args' )); + remove_filter('get_terms_args', [$this, 'get_terms_args']); return $attribute_summary; } @@ -128,6 +126,7 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * @since 1.6 * * @param WC_Product $product Product object. + * * @return void */ public function create(&$product) @@ -141,6 +140,7 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * @since 1.6 * * @param WC_Product $product Product object. + * * @return void */ public function update(&$product) @@ -155,9 +155,10 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * * @param WC_Product $product Product object. * @param array $args Array of args to pass to the delete method. + * * @return void */ - public function delete(&$product, $args = array()) + public function delete(&$product, $args = []) { $this->variation_data_store->delete($product, $args); } @@ -168,6 +169,7 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * @since 1.6 * * @param WC_Data $object WC_Data object. + * * @return array */ public function read_meta(&$object) @@ -179,8 +181,9 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * Deletes meta based on meta ID. * * @since 1.6 + * * @param WC_Data $object WC_Data object. - * @param stdClass $meta (containing at least ->id). + * @param stdClass $meta (containing at least ->id). */ public function delete_meta(&$object, $meta) { @@ -193,7 +196,8 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * @since 1.6 * * @param WC_Data $object WC_Data object. - * @param stdClass $meta (containing ->key and ->value). + * @param stdClass $meta (containing ->key and ->value). + * * @return int meta ID */ public function add_meta(&$object, $meta) @@ -207,7 +211,8 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * @since 1.6 * * @param WC_Data $object WC_Data object. - * @param stdClass $meta (containing ->id, ->key and ->value). + * @param stdClass $meta (containing ->id, ->key and ->value). + * * @return void */ public function update_meta(&$object, $meta) @@ -222,6 +227,7 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * * @param WC_Data $object WC_Data object. * @param array $raw_meta_data Array of std object of meta data to be filtered. + * * @return mixed|void */ public function filter_raw_meta_data(&$object, $raw_meta_data) @@ -236,13 +242,15 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * * @param string $method Method name. * @param array $args Method arguments. + * * @return mixed */ public function __call($method, $args) { - if (is_callable(array( $this->variation_data_store, $method ))) { + if (is_callable([$this->variation_data_store, $method])) { $object = array_shift($args); - $args = array_merge(array( &$object ), $args); + $args = array_merge([&$object], $args); + return $this->variation_data_store->$method(...$args); } } @@ -254,6 +262,7 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface * @since 1.6 * * @param array $args The terms query arguments. + * * @return array */ public function get_terms_args($args) @@ -262,17 +271,17 @@ class PLLWC_Variation_Data_Store_CPT implements WC_Object_Data_Store_Interface return $args; } - if (! isset($args['taxonomy']) || empty($args['slug']) || count($args['taxonomy']) !== 1 || 0 !== strpos(reset($args['taxonomy']), 'pa_')) { + if (!isset($args['taxonomy']) || empty($args['slug']) || count($args['taxonomy']) !== 1 || 0 !== strpos(reset($args['taxonomy']), 'pa_')) { return $args; } // These arguments are all added by `get_term_by()`. Having them all should help us detecting the usage of this function. - $get_terms_by_args = array( + $get_terms_by_args = [ 'get' => 'all', 'number' => 1, 'update_term_meta_cache' => false, 'orderby' => 'none', - ); + ]; if (array_diff_assoc($get_terms_by_args, $args)) { return $args; diff --git a/__plugins/polylang-wc/src/xdata-session-manager.php b/__plugins/polylang-wc/src/xdata-session-manager.php index 399e341a99c28fad4d3906d376e4cf8dabeed448..374d92b13b89479670f8416e21c00e9d9b0ce8a2 100644 --- a/__plugins/polylang-wc/src/xdata-session-manager.php +++ b/__plugins/polylang-wc/src/xdata-session-manager.php @@ -1,9 +1,5 @@ insert( - $wpdb->prefix . 'woocommerce_sessions', - array( + $wpdb->prefix.'woocommerce_sessions', + [ 'session_key' => $key, 'session_value' => maybe_serialize($data), 'session_expiry' => time() + 2 * MINUTE_IN_SECONDS, - ), - array( + ], + [ '%s', '%s', '%d', - ) + ] ); } @@ -55,6 +52,7 @@ class PLLWC_Xdata_Session_Manager * @since 0.3 * * @param string $key Session key. + * * @return array $data */ public function get($key) @@ -64,8 +62,9 @@ class PLLWC_Xdata_Session_Manager /** @var stdClass */ $value = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_sessions WHERE session_key = %s", $key)); - if (! empty($value->session_value) && time() < $value->session_expiry) { - $wpdb->delete($wpdb->prefix . 'woocommerce_sessions', array( 'session_key' => $key )); + if (!empty($value->session_value) && time() < $value->session_expiry) { + $wpdb->delete($wpdb->prefix.'woocommerce_sessions', ['session_key' => $key]); + return maybe_unserialize($value->session_value); } diff --git a/__plugins/polylang-wc/src/xdata.php b/__plugins/polylang-wc/src/xdata.php index ceeb1afd06bc5b136a8b33fe4ad9a7f941aa5ed9..bf43242831e213dc402f7357afccc7725651a3f1 100644 --- a/__plugins/polylang-wc/src/xdata.php +++ b/__plugins/polylang-wc/src/xdata.php @@ -1,9 +1,5 @@ options['force_lang']) { - add_filter('woocommerce_set_cookie_options', array( $this, 'set_cookie_options' ), 10, 2); // Since WC 6.7. + add_filter('woocommerce_set_cookie_options', [$this, 'set_cookie_options'], 10, 2); // Since WC 6.7. } } @@ -33,19 +29,20 @@ class PLLWC_Xdata * @since 0.3 * * @param array $data Data to transfer from one domain to the other. + * * @return array */ public function get_xdata($data) { if (isset($_COOKIE['woocommerce_cart_hash'], $_COOKIE['woocommerce_items_in_cart'])) { - $data['wc'] = array( + $data['wc'] = [ 'hash' => sanitize_key($_COOKIE['woocommerce_cart_hash']), 'items' => (int) $_COOKIE['woocommerce_items_in_cart'], - ); + ]; } - if (isset($_COOKIE[ 'wp_woocommerce_session_' . COOKIEHASH ])) { - $data['wc']['session'] = sanitize_text_field(wp_unslash($_COOKIE[ 'wp_woocommerce_session_' . COOKIEHASH ])); + if (isset($_COOKIE['wp_woocommerce_session_'.COOKIEHASH])) { + $data['wc']['session'] = sanitize_text_field(wp_unslash($_COOKIE['wp_woocommerce_session_'.COOKIEHASH])); } if (isset($_COOKIE['woocommerce_recently_viewed'])) { @@ -61,17 +58,18 @@ class PLLWC_Xdata * @since 0.3 * * @param array $data Transferred data. + * * @return void */ public function set_xdata($data) { - if (! empty($data['wc'])) { + if (!empty($data['wc'])) { $data = $data['wc']; if (isset($data['session'])) { - $session_expiration = time() + intval(apply_filters('wc_session_expiration', 60 * 60 * 48)); // 48 Hours + $session_expiration = time() + intval(apply_filters('wc_session_expiration', 60 * 60 * 48)); // 48 Hours $secure = apply_filters('wc_session_use_secure_cookie', false); - wc_setcookie('wp_woocommerce_session_' . COOKIEHASH, $data['session'], $session_expiration, $secure); + wc_setcookie('wp_woocommerce_session_'.COOKIEHASH, $data['session'], $session_expiration, $secure); } if (isset($data['hash'])) { @@ -109,16 +107,17 @@ class PLLWC_Xdata * * @param array $options Cookie options. * @param string $name Cookie name. + * * @return array */ public function set_cookie_options($options, $name) { - $cookies = array( - 'wp_woocommerce_session_' . COOKIEHASH, + $cookies = [ + 'wp_woocommerce_session_'.COOKIEHASH, 'woocommerce_cart_hash', 'woocommerce_items_in_cart', 'woocommerce_recently_viewed', - ); + ]; /** * Filters whether we allow crossdomain cookies. @@ -129,7 +128,7 @@ class PLLWC_Xdata * @param string $name Cookie name. */ if (is_ssl() && in_array($name, $cookies, true) && apply_filters('pllwc_allow_cookie_xdata', true, $name)) { - $options['secure'] = true; + $options['secure'] = true; $options['samesite'] = 'None'; } diff --git a/__plugins/polylang-wc/uninstall.php b/__plugins/polylang-wc/uninstall.php index 80d040aa0e9e11bf67374a95849f7fc88c19d78c..28c29a0a121ca89b61f5dc981b1df3ab04e5ea82 100644 --- a/__plugins/polylang-wc/uninstall.php +++ b/__plugins/polylang-wc/uninstall.php @@ -1,12 +1,8 @@ set('paged', $page); $query->set('page', 0); $query->set('pagename', ''); - $query->is_page = false; - $query->is_archive = true; + $query->is_page = false; + $query->is_archive = true; $query->is_post_type_archive = true; } diff --git a/app/Admin/SmtpConfig.php b/app/Admin/SmtpConfig.php index fb66ba2ea946232f998b768a7057dd37980b9b24..e335d2534e9ef8e4b831239df0e9ec35c39e3796 100644 --- a/app/Admin/SmtpConfig.php +++ b/app/Admin/SmtpConfig.php @@ -13,14 +13,14 @@ class SmtpConfig { $phpmailer->isSMTP(); - $phpmailer->Host = SMTP_HOST; - $phpmailer->Port = SMTP_PORT; - $phpmailer->SMTPAuth = true; - $phpmailer->Username = SMTP_USER; - $phpmailer->Password = SMTP_PASS; - $phpmailer->SMTPSecure = SMTP_SECURE; - $phpmailer->From = defined('SMTP_FROM') ? SMTP_FROM : SMTP_USER; - $phpmailer->FromName = defined('SMTP_FROM_NAME') ? SMTP_FROM_NAME : get_bloginfo('name'); + $phpmailer->Host = SMTP_HOST; + $phpmailer->Port = SMTP_PORT; + $phpmailer->SMTPAuth = true; + $phpmailer->Username = SMTP_USER; + $phpmailer->Password = SMTP_PASS; + $phpmailer->SMTPSecure = SMTP_SECURE; + $phpmailer->From = defined('SMTP_FROM') ? SMTP_FROM : SMTP_USER; + $phpmailer->FromName = defined('SMTP_FROM_NAME') ? SMTP_FROM_NAME : get_bloginfo('name'); $phpmailer->SMTPOptions = [ 'ssl' => [ 'verify_peer' => false, diff --git a/app/Admin/TimberContextProvider.php b/app/Admin/TimberContextProvider.php index a07993c487b59605d372f12969ba5b1da1113dd2..e7f7c1ed2fb8729bd9ce434c44c3eda1b342c607 100644 --- a/app/Admin/TimberContextProvider.php +++ b/app/Admin/TimberContextProvider.php @@ -14,20 +14,20 @@ class TimberContextProvider public function register(array $context): array { $context['main_menu'] = Timber::get_menu('main_menu'); - $context['site_url'] = home_url('/'); + $context['site_url'] = home_url('/'); $context['site_name'] = get_bloginfo('name'); - $context['logo'] = get_custom_logo(); + $context['logo'] = get_custom_logo(); if (function_exists('pll_the_languages')) { $context['languages'] = pll_the_languages(['raw' => 1, 'echo' => 0]); } if (function_exists('WC') && WC()->cart) { - $context['cart'] = WC()->cart; + $context['cart'] = WC()->cart; $context['currency_symbol'] = get_woocommerce_currency_symbol(); - $context['cart_link'] = wc_get_page_permalink('cart'); - $context['checkout_link'] = wc_get_page_permalink('checkout'); - $context['account_link'] = wc_get_page_permalink('myaccount'); + $context['cart_link'] = wc_get_page_permalink('cart'); + $context['checkout_link'] = wc_get_page_permalink('checkout'); + $context['account_link'] = wc_get_page_permalink('myaccount'); } return $context; diff --git a/app/Controllers/AccountController.php b/app/Controllers/AccountController.php index 1e9f34ed3763a672e7ea7c7cb3aef1b10d190252..d05e94d937e24d6b001b48dce46270ac11730555 100644 --- a/app/Controllers/AccountController.php +++ b/app/Controllers/AccountController.php @@ -8,11 +8,11 @@ class AccountController extends Controller { public function account(): array { - $this->data['post'] = Timber::get_post(); - $this->data['is_logged_in'] = is_user_logged_in(); - $this->data['is_wc_endpoint'] = (bool) WC()->query->get_current_endpoint(); + $this->data['post'] = Timber::get_post(); + $this->data['is_logged_in'] = is_user_logged_in(); + $this->data['is_wc_endpoint'] = (bool) WC()->query->get_current_endpoint(); $this->data['registration_enabled'] = 'yes'; - $this->data['lost_password_url'] = wc_get_account_endpoint_url('lost-password'); + $this->data['lost_password_url'] = wc_get_account_endpoint_url('lost-password'); return $this->data; } diff --git a/app/Controllers/CategoryController.php b/app/Controllers/CategoryController.php index 01baac8578daec10d1482ca07ee72e3635c524a7..8f097d2c53f1ade5dc578c90c9f9ae451e61d346 100644 --- a/app/Controllers/CategoryController.php +++ b/app/Controllers/CategoryController.php @@ -8,7 +8,7 @@ class CategoryController extends Controller { public function index(): array { - $this->data['term'] = Timber::get_term(); + $this->data['term'] = Timber::get_term(); $this->data['posts'] = Timber::get_posts(); return $this->data; diff --git a/app/Controllers/CheckoutController.php b/app/Controllers/CheckoutController.php index fd8ae4070eaae132f3cd758ba118b2b66f7eeb8d..4d2334443158702808eb38f15b013ac3be0f1132 100644 --- a/app/Controllers/CheckoutController.php +++ b/app/Controllers/CheckoutController.php @@ -15,17 +15,17 @@ class CheckoutController extends Controller public function checkout(): array { - $this->data['post'] = Timber::get_post(); + $this->data['post'] = Timber::get_post(); $this->data['is_order_received'] = is_wc_endpoint_url('order-received'); - $this->data['order_id'] = null; - $this->data['order'] = null; + $this->data['order_id'] = null; + $this->data['order'] = null; if ($this->data['is_order_received']) { $orderId = absint(get_query_var('order-received')); - $order = $orderId ? wc_get_order($orderId) : null; + $order = $orderId ? wc_get_order($orderId) : null; $this->data['order_id'] = $order ? $order->get_id() : null; - $this->data['order'] = $order; + $this->data['order'] = $order; if ($order) { do_action('woocommerce_before_thankyou', $order->get_id()); @@ -48,7 +48,7 @@ class CheckoutController extends Controller ? $order->get_billing_email() : '', 'order_total' => $order ? $order->get_formatted_order_total() : '', 'payment_method' => $order ? wp_kses_post($order->get_payment_method_title()) : '', - 'payment_content' => $order ? capture_action('woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id()) : '', + 'payment_content' => $order ? capture_action('woocommerce_thankyou_'.$order->get_payment_method(), $order->get_id()) : '', 'thankyou_content' => $order ? capture_action('woocommerce_thankyou', $order->get_id()) : '', ]; } @@ -63,11 +63,11 @@ class CheckoutController extends Controller WC()->cart->calculate_totals(); } - $this->data['checkout'] = $checkout; - $this->data['fields'] = $checkout->get_checkout_fields(); - $this->data['checkout_url'] = wc_get_checkout_url(); + $this->data['checkout'] = $checkout; + $this->data['fields'] = $checkout->get_checkout_fields(); + $this->data['checkout_url'] = wc_get_checkout_url(); $this->data['checkout_nonce'] = wp_create_nonce('woocommerce-process_checkout'); - $this->data['http_referer'] = esc_attr(wp_unslash($_SERVER['REQUEST_URI'] ?? '/')); + $this->data['http_referer'] = esc_attr(wp_unslash($_SERVER['REQUEST_URI'] ?? '/')); ob_start(); if (WC()->cart && WC()->cart->needs_shipping()) { @@ -88,8 +88,8 @@ class CheckoutController extends Controller ]; } $this->data['payment_gateways'] = $gateways; - $this->data['terms_enabled'] = wc_terms_and_conditions_checkbox_enabled(); - $this->data['terms_url'] = $this->data['terms_enabled'] ? wc_get_page_permalink('terms') : ''; + $this->data['terms_enabled'] = wc_terms_and_conditions_checkbox_enabled(); + $this->data['terms_url'] = $this->data['terms_enabled'] ? wc_get_page_permalink('terms') : ''; return $this->data; } diff --git a/app/Controllers/ProductController.php b/app/Controllers/ProductController.php index 4391563d3782d6e28121ec44e57492afbfe488df..e0f249409a5be4f14e84ac2a15ab87fbf6672a07 100644 --- a/app/Controllers/ProductController.php +++ b/app/Controllers/ProductController.php @@ -8,18 +8,18 @@ class ProductController extends Controller { public function index(): array { - $id = get_the_ID(); + $id = get_the_ID(); $product = wc_get_product($id); - $this->data['product'] = $product; - $this->data['post'] = Timber::get_post(); + $this->data['product'] = $product; + $this->data['post'] = Timber::get_post(); $this->data['categories'] = get_the_terms($id, 'product_cat'); - $related_limit = wc_get_loop_prop('columns'); - $related_ids = wc_get_related_products($id, $related_limit); + $related_limit = wc_get_loop_prop('columns'); + $related_ids = wc_get_related_products($id, $related_limit); $this->data['related_products'] = Timber::get_posts($related_ids); - $gallery_ids = array_filter(array_merge( + $gallery_ids = array_filter(array_merge( [$product->get_image_id()], $product->get_gallery_image_ids() )); @@ -43,14 +43,14 @@ class ProductController extends Controller } $taxonomy = str_replace('attribute_', '', $key); if (taxonomy_exists($taxonomy)) { - $term = get_term_by('slug', $value, $taxonomy); + $term = get_term_by('slug', $value, $taxonomy); $parts[] = $term ? $term->name : $value; } else { $parts[] = $value; } } - $variation['name'] = implode(' / ', $parts) ?: '#' . $variation['variation_id']; - $variations[] = $variation; + $variation['name'] = implode(' / ', $parts) ?: '#'.$variation['variation_id']; + $variations[] = $variation; } } $this->data['product_variations'] = $variations; @@ -61,7 +61,7 @@ class ProductController extends Controller continue; } if ($attribute->is_taxonomy()) { - $terms = wp_get_post_terms($id, $attribute->get_name()); + $terms = wp_get_post_terms($id, $attribute->get_name()); $values = is_wp_error($terms) ? [] : array_column($terms, 'name'); } else { $values = $attribute->get_options(); @@ -73,11 +73,11 @@ class ProductController extends Controller } $this->data['product_attributes'] = $product_attributes; - $this->data['reviews_open'] = comments_open($id); + $this->data['reviews_open'] = comments_open($id); $this->data['reviews_count'] = (int) $product->get_review_count(); $this->data['reviews_html'] = capture_output('comments_template'); - $upsell_ids = $product->get_upsell_ids(); + $upsell_ids = $product->get_upsell_ids(); $this->data['upsells'] = !empty($upsell_ids) ? Timber::get_posts(array_slice($upsell_ids, 0, 4)) : []; diff --git a/app/Controllers/ShopController.php b/app/Controllers/ShopController.php index 8ac3ed88aa2dc39d5ec256cca9afea97e5cf5416..c414b3328bd3cad9d6ad63d0f39d7863895f8fb7 100644 --- a/app/Controllers/ShopController.php +++ b/app/Controllers/ShopController.php @@ -11,9 +11,9 @@ class ShopController extends Controller { global $wp_query; - $posts = Timber::get_posts(); - $this->data['posts'] = $posts; - $filterArgs = array_filter( + $posts = Timber::get_posts(); + $this->data['posts'] = $posts; + $filterArgs = array_filter( $_GET, fn ($k) => !in_array($k, ['paged', 'page', 'product-page'], true), ARRAY_FILTER_USE_KEY @@ -22,19 +22,19 @@ class ShopController extends Controller 'total' => (int) ($wp_query->max_num_pages ?? 1), 'add_args' => $filterArgs, ]); - $cats = $this->getArchiveCategories(); - $this->data['categories'] = $cats['terms']; - $this->data['categories_reset_url'] = $cats['reset_url']; - $this->data['active_category'] = $cats['has_active']; + $cats = $this->getArchiveCategories(); + $this->data['categories'] = $cats['terms']; + $this->data['categories_reset_url'] = $cats['reset_url']; + $this->data['active_category'] = $cats['has_active']; $this->data['attributes'] = $this->getArchiveAttributes(); $requestedMin = get_requested_price('min_price'); $requestedMax = get_requested_price('max_price'); - $priceRange = $this->getPriceRange(); - $priceAbsMin = floor($priceRange['min']); - $priceAbsMax = ceil($priceRange['max']); - $priceMin = $requestedMin ?? $priceAbsMin; - $priceMax = $requestedMax ?? $priceAbsMax; + $priceRange = $this->getPriceRange(); + $priceAbsMin = floor($priceRange['min']); + $priceAbsMax = ceil($priceRange['max']); + $priceMin = $requestedMin ?? $priceAbsMin; + $priceMax = $requestedMax ?? $priceAbsMax; if ($priceMin > $priceMax) { [$priceMin, $priceMax] = [$priceMax, $priceMin]; @@ -50,7 +50,7 @@ class ShopController extends Controller fn ($k) => str_starts_with($k, 'filter_') || str_starts_with($k, 'query_type_') ); $this->data['has_active_filters'] = !empty($activeFilterKeys) || $requestedMin !== null || $requestedMax !== null; - $this->data['reset_url'] = $this->getCurrentArchiveUrl(); + $this->data['reset_url'] = $this->getCurrentArchiveUrl(); return $this->data; } @@ -62,8 +62,8 @@ class ShopController extends Controller } global $wp_query; - $filterQuery = new ProductFilterQuery($wp_query instanceof \WP_Query ? $wp_query : null); - $productIds = $filterQuery->getProductIds(['product_cat'], true); + $filterQuery = new ProductFilterQuery($wp_query instanceof \WP_Query ? $wp_query : null); + $productIds = $filterQuery->getProductIds(['product_cat'], true); $facetedTerms = array_values(array_filter( $this->getAttributeTermsForProducts('product_cat', $productIds), fn (\WP_Term $t) => $t->parent === 0 @@ -85,7 +85,7 @@ class ShopController extends Controller } $termData = array_map(function (\WP_Term $term) use ($activeSlug, $queryArgs, $currentUrl, $resetUrl) { - $isActive = $activeSlug === $term->slug; + $isActive = $activeSlug === $term->slug; $filterUrl = $isActive ? $resetUrl : add_query_arg(array_merge($queryArgs, ['filter_product_cat' => $term->slug]), $currentUrl); @@ -108,14 +108,14 @@ class ShopController extends Controller global $wp_query; $filterQuery = new ProductFilterQuery($wp_query instanceof \WP_Query ? $wp_query : null); - $productIds = $filterQuery->getProductIds([], true); + $productIds = $filterQuery->getProductIds([], true); if ($productIds === []) { return ['min' => 0.0, 'max' => 0.0]; } $placeholders = implode(', ', array_fill(0, count($productIds), '%d')); - $sql = " + $sql = " SELECT MIN(CAST(meta_value AS DECIMAL(10,2))) AS min_price, MAX(CAST(meta_value AS DECIMAL(10,2))) AS max_price FROM {$wpdb->postmeta} @@ -123,7 +123,7 @@ class ShopController extends Controller AND meta_value != '' AND post_id IN ($placeholders) "; - $row = $wpdb->get_row($wpdb->prepare($sql, $productIds)); + $row = $wpdb->get_row($wpdb->prepare($sql, $productIds)); return [ 'min' => (float) ($row->min_price ?? 0), @@ -135,13 +135,13 @@ class ShopController extends Controller { global $wp_query; $filterQuery = new ProductFilterQuery($wp_query instanceof \WP_Query ? $wp_query : null); - $attributes = []; + $attributes = []; foreach (wc_get_attribute_taxonomies() as $taxonomy) { - $attributeName = $taxonomy->attribute_name; + $attributeName = $taxonomy->attribute_name; $attributeTaxonomy = 'pa_'.$attributeName; - $productIds = $filterQuery->getProductIds([$attributeTaxonomy], true); - $terms = $this->getAttributeTermsForProducts($attributeTaxonomy, $productIds); + $productIds = $filterQuery->getProductIds([$attributeTaxonomy], true); + $terms = $this->getAttributeTermsForProducts($attributeTaxonomy, $productIds); if ($terms === []) { continue; @@ -180,7 +180,7 @@ class ShopController extends Controller private function buildTermData(\WP_Term $term, string $attributeName, array $queryArgs, string $currentFilter, string $resetUrl): array { - $isActive = $currentFilter !== '' && $currentFilter === $term->slug; + $isActive = $currentFilter !== '' && $currentFilter === $term->slug; $filterUrl = $isActive ? $resetUrl : add_query_arg( @@ -213,16 +213,16 @@ class ShopController extends Controller return []; } - $groupedTerms = []; + $groupedTerms = []; $termProductMap = []; foreach ($terms as $term) { - $termId = (int) $term->term_id; + $termId = (int) $term->term_id; $objectId = (int) $term->object_id; if (!isset($groupedTerms[$termId])) { - $term->count = 0; - $groupedTerms[$termId] = $term; + $term->count = 0; + $groupedTerms[$termId] = $term; $termProductMap[$termId] = []; } @@ -240,8 +240,8 @@ class ShopController extends Controller private function getCurrentArchiveUrl(): string { $requestUri = (string) wp_unslash($_SERVER['REQUEST_URI'] ?? '/'); - $path = strtok($requestUri, '?') ?: '/'; - $path = (string) preg_replace('#/page/\d+/?$#', '/', $path); + $path = strtok($requestUri, '?') ?: '/'; + $path = (string) preg_replace('#/page/\d+/?$#', '/', $path); return home_url($path); } diff --git a/app/Handlers/AjaxHandlers/register.php b/app/Handlers/AjaxHandlers/register.php index a02484282ad32085f5651047e6ce6005fd2693aa..43f094c4e873ac631a51f6627f4efaa76fd4a665 100644 --- a/app/Handlers/AjaxHandlers/register.php +++ b/app/Handlers/AjaxHandlers/register.php @@ -2,10 +2,10 @@ verify_ajax_nonce(); -$email = sanitize_email(wp_unslash($_POST['email'] ?? '')); -$password = wp_unslash($_POST['password'] ?? ''); +$email = sanitize_email(wp_unslash($_POST['email'] ?? '')); +$password = wp_unslash($_POST['password'] ?? ''); $firstName = sanitize_text_field(wp_unslash($_POST['first_name'] ?? '')); -$lastName = sanitize_text_field(wp_unslash($_POST['last_name'] ?? '')); +$lastName = sanitize_text_field(wp_unslash($_POST['last_name'] ?? '')); if (empty($email) || empty($password)) { wp_send_json(['type' => 'error', 'message' => __('Please fill in all required fields.', 'woocommerce')]); @@ -24,7 +24,7 @@ if (email_exists($email)) { } $username = wc_create_new_customer_username($email); -$userId = wc_create_new_customer($email, $username, $password, [ +$userId = wc_create_new_customer($email, $username, $password, [ 'first_name' => $firstName, 'last_name' => $lastName, ]); diff --git a/app/Services/ProductFilterQuery.php b/app/Services/ProductFilterQuery.php index a137fa0746d3cd27c9809493ab1a82bebb7a8929..c40e829fa90810d7edf9ec044d6fdea76e650f1a 100644 --- a/app/Services/ProductFilterQuery.php +++ b/app/Services/ProductFilterQuery.php @@ -14,12 +14,12 @@ class ProductFilterQuery return []; } - $queryArgs = $this->baseQuery->query_vars; - $queryArgs['fields'] = 'ids'; - $queryArgs['nopaging'] = true; - $queryArgs['no_found_rows'] = true; - $queryArgs['cache_results'] = false; - $queryArgs['suppress_filters'] = false; + $queryArgs = $this->baseQuery->query_vars; + $queryArgs['fields'] = 'ids'; + $queryArgs['nopaging'] = true; + $queryArgs['no_found_rows'] = true; + $queryArgs['cache_results'] = false; + $queryArgs['suppress_filters'] = false; $queryArgs['update_post_meta_cache'] = false; $queryArgs['update_post_term_cache'] = false; diff --git a/app/Traits/HandlesWcNotices.php b/app/Traits/HandlesWcNotices.php index 4f334243bc9bc1afc07bd5bc1618a3d31cec36de..23d21500ef322dd2bb7260bc7b4d8ff77f5c00ea 100644 --- a/app/Traits/HandlesWcNotices.php +++ b/app/Traits/HandlesWcNotices.php @@ -8,11 +8,12 @@ trait HandlesWcNotices protected function getNotice(string $type, string $fallback = ''): string { $notices = wc_get_notices($type); - $texts = array_filter(array_column($notices, 'notice')); + $texts = array_filter(array_column($notices, 'notice')); $message = !empty($texts) ? wp_strip_all_tags(implode(' ', $texts)) : $fallback; wc_clear_notices(); + return $message; } } diff --git a/routes/base.php b/routes/base.php index c1d6e86bcc2bb1de246dc398ead32bc02a8baeaa..32054d1f202a1cbc9f8202566af02f7a3fe046cc 100644 --- a/routes/base.php +++ b/routes/base.php @@ -2,9 +2,9 @@ use App\Controllers\AccountController; use App\Controllers\CategoryController; +use App\Controllers\CheckoutController; use App\Controllers\PageController; use App\Controllers\PostController; -use App\Controllers\CheckoutController; use App\Controllers\ShopController; use Core\Route; diff --git a/woocommerce/archive-product.php b/woocommerce/archive-product.php index 539647dc7fe0f3584a0fd44580bbb1fcd98d4b8c..cbff7f0757bf758f5188490b72b319c631c9e2c7 100644 --- a/woocommerce/archive-product.php +++ b/woocommerce/archive-product.php @@ -2,7 +2,7 @@ /** * @see https://woocommerce.com/document/template-structure/ - * @package WooCommerce\Templates + * * @version 8.6.0 */ diff --git a/woocommerce/brands/taxonomy-product_brand.php b/woocommerce/brands/taxonomy-product_brand.php index a9b6beee9e52c0cc29d5dfb527a2eed3492689fa..82843d8f62bd3478989ac9e3fdcf17a0936c1d4d 100644 --- a/woocommerce/brands/taxonomy-product_brand.php +++ b/woocommerce/brands/taxonomy-product_brand.php @@ -3,9 +3,8 @@ // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase for backwards compatibility. /** - * Use the WooCommerce archive template for brand taxonomy pages + * Use the WooCommerce archive template for brand taxonomy pages. * - * @package WooCommerce\Templates * @version 9.4.0 */ diff --git a/woocommerce/brands/widgets/brand-description.php b/woocommerce/brands/widgets/brand-description.php index c485fa839e624853a0248ab0b20bc54a7d6d5f6e..c7a19822a7702f5d628322f51ecd87bc211c45aa 100644 --- a/woocommerce/brands/widgets/brand-description.php +++ b/woocommerce/brands/widgets/brand-description.php @@ -1,7 +1,7 @@ is_user_logged_in(), ]); } else { - $order_received = capture_action('woocommerce_thankyou_order_received_text'); - $payment_content = capture_action('woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id()); - $thankyou_content = capture_action('woocommerce_thankyou', $order->get_id()); + $order_received = capture_action('woocommerce_thankyou_order_received_text'); + $payment_content = capture_action('woocommerce_thankyou_'.$order->get_payment_method(), $order->get_id()); + $thankyou_content = capture_action('woocommerce_thankyou', $order->get_id()); \Timber\Timber::render('views/woocommerce/checkout/thankyou.twig', [ 'failed' => false, diff --git a/woocommerce/emails/block/general-block-content-for-fulfillment-emails.php b/woocommerce/emails/block/general-block-content-for-fulfillment-emails.php index 63a45b84adbe85b5b9826113bda59fab3084dd28..80d00d44f7f19c3868d6ae849f9a51e3fefef13f 100644 --- a/woocommerce/emails/block/general-block-content-for-fulfillment-emails.php +++ b/woocommerce/emails/block/general-block-content-for-fulfillment-emails.php @@ -1,23 +1,22 @@ get_order_number()), esc_html($order->get_formatted_billing_full_name())) . "\n\n"; +echo sprintf(esc_html($text), esc_html($order->get_order_number()), esc_html($order->get_formatted_billing_full_name()))."\n\n"; /* * @hooked WC_Emails::order_details() Shows the order details table. diff --git a/woocommerce/emails/plain/admin-failed-order.php b/woocommerce/emails/plain/admin-failed-order.php index edca9557cd3c54806b189200bf3a0ada67a1edf7..3d8ea59a157ac82fed1d10c7bdd0bd8a0a6cc95a 100644 --- a/woocommerce/emails/plain/admin-failed-order.php +++ b/woocommerce/emails/plain/admin-failed-order.php @@ -1,7 +1,7 @@ get_order_number()), esc_html($order->get_formatted_billing_full_name())) . "\n\n"; +echo sprintf(esc_html($text), esc_html($order->get_order_number()), esc_html($order->get_formatted_billing_full_name()))."\n\n"; /* * @hooked WC_Emails::order_details() Shows the order details table. diff --git a/woocommerce/emails/plain/admin-new-order.php b/woocommerce/emails/plain/admin-new-order.php index fbae069c0620c9cbf41ef6eba99c241074d176c2..40901f10f9f7d7a031695ac514bbdeec4368e7c4 100644 --- a/woocommerce/emails/plain/admin-new-order.php +++ b/woocommerce/emails/plain/admin-new-order.php @@ -1,7 +1,7 @@ get_formatted_billing_full_name())) . "\n\n"; +echo sprintf(esc_html($text), esc_html($order->get_formatted_billing_full_name()))."\n\n"; /* * @hooked WC_Emails::order_details() Shows the order details table. diff --git a/woocommerce/emails/plain/admin-payment-gateway-enabled.php b/woocommerce/emails/plain/admin-payment-gateway-enabled.php index c42004eaa2b706c0e42ba0494818bb43415f34fc..55a452049b4213adf8e574e44b64e5f1fd828024 100644 --- a/woocommerce/emails/plain/admin-payment-gateway-enabled.php +++ b/woocommerce/emails/plain/admin-payment-gateway-enabled.php @@ -1,7 +1,7 @@ get_order_number())) . "\n\n"; +echo sprintf(esc_html($text), esc_html($order->get_order_number()))."\n\n"; /** * Hook: woocommerce_email_order_details. @@ -40,6 +40,7 @@ echo sprintf(esc_html($text), esc_html($order->get_order_number())) . "\n\n"; * @hooked WC_Emails::order_details() Shows the order details table. * @hooked WC_Structured_Data::generate_order_data() Generates structured data. * @hooked WC_Structured_Data::output_structured_data() Outputs structured data. + * * @since 2.5.0 */ do_action('woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email); @@ -50,6 +51,7 @@ echo "\n----------------------------------------\n\n"; * Hook: woocommerce_email_order_meta. * * @hooked WC_Emails::order_meta() Shows order meta data. + * * @since 2.5.0 */ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); @@ -59,6 +61,7 @@ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $ * * @hooked WC_Emails::customer_details() Shows customer details * @hooked WC_Emails::email_address() Shows email address + * * @since 2.5.0 */ do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); @@ -77,6 +80,7 @@ if ($additional_content) { * Hook: woocommerce_email_footer. * * @hooked WC_Emails::email_footer() Output the email footer + * * @since 2.5.0 */ do_action('woocommerce_email_footer', $email); diff --git a/woocommerce/emails/plain/customer-completed-order.php b/woocommerce/emails/plain/customer-completed-order.php index bbbfc1b1c35f01797b8f3a6d0e7a39afbb7da8a7..07d4e12360e310dbfefb59b93c06e4fd3e860a3f 100644 --- a/woocommerce/emails/plain/customer-completed-order.php +++ b/woocommerce/emails/plain/customer-completed-order.php @@ -1,7 +1,7 @@ get_billing_first_name())) . "\n\n"; -echo esc_html__('We have finished processing your order.', 'woocommerce') . "\n\n"; +echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; +echo esc_html__('We have finished processing your order.', 'woocommerce')."\n\n"; if ($email_improvements_enabled) { - echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce') . "\n\n"; + echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce')."\n\n"; } /* diff --git a/woocommerce/emails/plain/customer-failed-order.php b/woocommerce/emails/plain/customer-failed-order.php index 601d5d5402a87751f0b3cfbae63f912308ca1306..a4c790531e86799a72c0c3bec6302b1a48a3d4d3 100644 --- a/woocommerce/emails/plain/customer-failed-order.php +++ b/woocommerce/emails/plain/customer-failed-order.php @@ -1,7 +1,7 @@ get_billing_first_name())) . "\n\n"; -echo esc_html__("Unfortunately, we couldn't complete your order due to an issue with your payment method.", 'woocommerce') . "\n\n"; +echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; +echo esc_html__("Unfortunately, we couldn't complete your order due to an issue with your payment method.", 'woocommerce')."\n\n"; /* translators: %s: Site title */ -echo sprintf(esc_html__("If you'd like to continue with your purchase, please return to %s and try a different method of payment.", 'woocommerce'), esc_html($blogname)) . "\n\n"; -echo esc_html__('Your order details are as follows:', 'woocommerce') . "\n\n"; +echo sprintf(esc_html__("If you'd like to continue with your purchase, please return to %s and try a different method of payment.", 'woocommerce'), esc_html($blogname))."\n\n"; +echo esc_html__('Your order details are as follows:', 'woocommerce')."\n\n"; /** * Hook for the woocommerce_email_order_details. @@ -35,6 +34,7 @@ echo esc_html__('Your order details are as follows:', 'woocommerce') . "\n\n"; * @hooked WC_Emails::order_details() Shows the order details table. * @hooked WC_Structured_Data::generate_order_data() Generates structured data. * @hooked WC_Structured_Data::output_structured_data() Outputs structured data. + * * @since 2.5.0 */ do_action('woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email); @@ -45,6 +45,7 @@ echo "\n----------------------------------------\n\n"; * Hook for the woocommerce_email_order_meta. * * @hooked WC_Emails::order_meta() Shows order meta data. + * * @since 1.0.0 */ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); @@ -54,6 +55,7 @@ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $ * * @hooked WC_Emails::customer_details() Shows customer details * @hooked WC_Emails::email_address() Shows email address + * * @since 1.0.0 */ do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); diff --git a/woocommerce/emails/plain/customer-fulfillment-created.php b/woocommerce/emails/plain/customer-fulfillment-created.php index 6cd86b4975be9e2307e65932552766d0fd5075d0..d5e712d65f3adce043fb7696b72bad0b1ff0cf31 100644 --- a/woocommerce/emails/plain/customer-fulfillment-created.php +++ b/woocommerce/emails/plain/customer-fulfillment-created.php @@ -1,7 +1,7 @@ get_billing_first_name())) . "\n\n"; +echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; if ($order->needs_payment()) { if ($order->has_status(OrderStatus::FAILED)) { @@ -38,7 +38,7 @@ if ($order->needs_payment()) { esc_html(get_bloginfo('name', 'display')), esc_url($order->get_checkout_payment_url()) ) - ) . "\n\n"; + )."\n\n"; } else { echo wp_kses_post( sprintf( @@ -47,11 +47,11 @@ if ($order->needs_payment()) { esc_html(get_bloginfo('name', 'display')), esc_url($order->get_checkout_payment_url()) ) - ) . "\n\n"; + )."\n\n"; } } else { /* translators: %s: Order date */ - echo sprintf(esc_html__('Here are the details of your order placed on %s:', 'woocommerce'), esc_html(wc_format_datetime($order->get_date_created()))) . "\n\n"; + echo sprintf(esc_html__('Here are the details of your order placed on %s:', 'woocommerce'), esc_html(wc_format_datetime($order->get_date_created())))."\n\n"; } /** @@ -60,6 +60,7 @@ if ($order->needs_payment()) { * @hooked WC_Emails::order_details() Shows the order details table. * @hooked WC_Structured_Data::generate_order_data() Generates structured data. * @hooked WC_Structured_Data::output_structured_data() Outputs structured data. + * * @since 2.5.0 */ do_action('woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email); @@ -74,7 +75,7 @@ echo "\n----------------------------------------\n\n"; do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); /** - * Hook for woocommerce_email_customer_details + * Hook for woocommerce_email_customer_details. * * @hooked WC_Emails::customer_details() Shows customer details * @hooked WC_Emails::email_address() Shows email address diff --git a/woocommerce/emails/plain/customer-new-account.php b/woocommerce/emails/plain/customer-new-account.php index 58fc63010c8d2b50188d8df95832101e126a5858..b14b97f8e5e13b7c36949d095c22c928caa400bb 100644 --- a/woocommerce/emails/plain/customer-new-account.php +++ b/woocommerce/emails/plain/customer-new-account.php @@ -1,7 +1,7 @@ get_billing_first_name())) . "\n\n"; -echo esc_html__('The following note has been added to your order:', 'woocommerce') . "\n\n"; +echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; +echo esc_html__('The following note has been added to your order:', 'woocommerce')."\n\n"; echo "----------\n\n"; -echo wc_wptexturize_order_note($customer_note) . "\n\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped +echo wc_wptexturize_order_note($customer_note)."\n\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo "----------\n\n"; -echo esc_html__('As a reminder, here are your order details:', 'woocommerce') . "\n\n"; +echo esc_html__('As a reminder, here are your order details:', 'woocommerce')."\n\n"; /* * @hooked WC_Emails::order_details() Shows the order details table. diff --git a/woocommerce/emails/plain/customer-on-hold-order.php b/woocommerce/emails/plain/customer-on-hold-order.php index 8dc808033fa56a8d8fa60964975145e108451e06..3f9bea1160ff34d6cdacc34f62d233bddea82fba 100644 --- a/woocommerce/emails/plain/customer-on-hold-order.php +++ b/woocommerce/emails/plain/customer-on-hold-order.php @@ -1,7 +1,7 @@ get_billing_first_name())) . "\n\n"; +echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; if ($email_improvements_enabled) { - echo esc_html__('We’ve received your order and it’s currently on hold until we can confirm your payment has been processed.', 'woocommerce') . "\n\n"; - echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce') . "\n\n"; + echo esc_html__('We’ve received your order and it’s currently on hold until we can confirm your payment has been processed.', 'woocommerce')."\n\n"; + echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce')."\n\n"; } else { - echo esc_html__('Thanks for your order. It’s on-hold until we confirm that payment has been received.', 'woocommerce') . "\n\n"; + echo esc_html__('Thanks for your order. It’s on-hold until we confirm that payment has been received.', 'woocommerce')."\n\n"; } /* diff --git a/woocommerce/emails/plain/customer-pos-completed-order.php b/woocommerce/emails/plain/customer-pos-completed-order.php index 09c66af3a8db9316c33b75c9ab2741fca7b18ba9..14592338387cb4b3f0051a117bcccbfae66adae5 100644 --- a/woocommerce/emails/plain/customer-pos-completed-order.php +++ b/woocommerce/emails/plain/customer-pos-completed-order.php @@ -1,7 +1,7 @@ get_billing_first_name())) { +if (!empty($order->get_billing_first_name())) { /* translators: %s: Customer first name */ - echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name())) . "\n\n"; + echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; } else { - echo esc_html__('Hi there,', 'woocommerce') . "\n\n"; + echo esc_html__('Hi there,', 'woocommerce')."\n\n"; } -echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce') . "\n\n"; +echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce')."\n\n"; /** * Show the order details table, generate and output structured data. @@ -41,6 +41,7 @@ echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce') * @hooked WC_Emails::order_details() Shows the order details table. * @hooked WC_Structured_Data::generate_order_data() Generates structured data. * @hooked WC_Structured_Data::output_structured_data() Outputs structured data. + * * @since 2.5.0 */ do_action('woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email); @@ -51,6 +52,7 @@ echo "\n----------------------------------------\n\n"; * Show order meta data. * * @hooked WC_Emails::order_meta() Shows order meta data. + * * @since 1.0.0 */ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); @@ -60,6 +62,7 @@ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $ * * @hooked WC_Emails::customer_details() Shows customer details * @hooked WC_Emails::email_address() Shows email address + * * @since 1.0.0 */ do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); @@ -77,18 +80,18 @@ if ($additional_content) { /** * Show store information - store details are set in the Point of Sale settings. */ -if (! empty($pos_store_email) || ! empty($pos_store_phone_number) || ! empty($pos_store_address)) { - if (! empty($pos_store_name)) { - echo "\n" . esc_html($pos_store_name) . "\n\n"; +if (!empty($pos_store_email) || !empty($pos_store_phone_number) || !empty($pos_store_address)) { + if (!empty($pos_store_name)) { + echo "\n".esc_html($pos_store_name)."\n\n"; } - if (! empty($pos_store_email)) { - echo esc_html($pos_store_email) . "\n"; + if (!empty($pos_store_email)) { + echo esc_html($pos_store_email)."\n"; } - if (! empty($pos_store_phone_number)) { - echo esc_html($pos_store_phone_number) . "\n"; + if (!empty($pos_store_phone_number)) { + echo esc_html($pos_store_phone_number)."\n"; } - if (! empty($pos_store_address)) { - echo esc_html(wp_strip_all_tags(wptexturize($pos_store_address))) . "\n"; + if (!empty($pos_store_address)) { + echo esc_html(wp_strip_all_tags(wptexturize($pos_store_address)))."\n"; } echo "\n----------------------------------------\n\n"; } @@ -96,9 +99,9 @@ if (! empty($pos_store_email) || ! empty($pos_store_phone_number) || ! empty($po /** * Show refund & returns policy - this is set in the Point of Sale settings. */ -if (! empty($pos_refund_returns_policy)) { - echo "\n" . esc_html__('Refund & Returns Policy', 'woocommerce') . "\n\n"; - echo esc_html(wp_strip_all_tags(wptexturize($pos_refund_returns_policy))) . "\n"; +if (!empty($pos_refund_returns_policy)) { + echo "\n".esc_html__('Refund & Returns Policy', 'woocommerce')."\n\n"; + echo esc_html(wp_strip_all_tags(wptexturize($pos_refund_returns_policy)))."\n"; echo "\n----------------------------------------\n\n"; } diff --git a/woocommerce/emails/plain/customer-pos-refunded-order.php b/woocommerce/emails/plain/customer-pos-refunded-order.php index 1cd139d903c055a13f95f0f4b790e9aa98e1683d..41c570fd153a4d4ee3b08519cc05b88f27a60ad7 100644 --- a/woocommerce/emails/plain/customer-pos-refunded-order.php +++ b/woocommerce/emails/plain/customer-pos-refunded-order.php @@ -1,7 +1,7 @@ get_billing_first_name())) { +if (!empty($order->get_billing_first_name())) { /* translators: %s: Customer first name */ - echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name())) . "\n\n"; + echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; } else { - echo esc_html__('Hi there,', 'woocommerce') . "\n\n"; + echo esc_html__('Hi there,', 'woocommerce')."\n\n"; } if ($partial_refund) { /* translators: %s: Site title */ - echo sprintf(esc_html__('Your order from %s has been partially refunded.', 'woocommerce'), esc_html($pos_store_name)) . "\n\n"; + echo sprintf(esc_html__('Your order from %s has been partially refunded.', 'woocommerce'), esc_html($pos_store_name))."\n\n"; } else { /* translators: %s: Site title */ - echo sprintf(esc_html__('Your order from %s has been refunded.', 'woocommerce'), esc_html($pos_store_name)) . "\n\n"; + echo sprintf(esc_html__('Your order from %s has been refunded.', 'woocommerce'), esc_html($pos_store_name))."\n\n"; } -echo esc_html__('Here’s a reminder of what you’ve bought:', 'woocommerce') . "\n\n"; +echo esc_html__('Here’s a reminder of what you’ve bought:', 'woocommerce')."\n\n"; /** * Show order details. @@ -48,6 +48,7 @@ echo esc_html__('Here’s a reminder of what you’ve bought:', 'woocommerce') . * @hooked WC_Emails::order_details() Shows the order details table. * @hooked WC_Structured_Data::generate_order_data() Generates structured data. * @hooked WC_Structured_Data::output_structured_data() Outputs structured data. + * * @since 2.5.0 */ do_action('woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email); @@ -58,6 +59,7 @@ echo "\n----------------------------------------\n\n"; * Show order meta data. * * @hooked WC_Emails::order_meta() Shows order meta data. + * * @since 1.0.0 */ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); @@ -67,6 +69,7 @@ do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $ * * @hooked WC_Emails::customer_details() Shows customer details * @hooked WC_Emails::email_address() Shows email address + * * @since 1.0.0 */ do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); @@ -84,18 +87,18 @@ if ($additional_content) { /** * Show store information - store details are set in the Point of Sale settings. */ -if (! empty($pos_store_email) || ! empty($pos_store_phone_number) || ! empty($pos_store_address)) { - if (! empty($pos_store_name)) { - echo "\n" . esc_html($pos_store_name) . "\n\n"; +if (!empty($pos_store_email) || !empty($pos_store_phone_number) || !empty($pos_store_address)) { + if (!empty($pos_store_name)) { + echo "\n".esc_html($pos_store_name)."\n\n"; } - if (! empty($pos_store_email)) { - echo esc_html($pos_store_email) . "\n"; + if (!empty($pos_store_email)) { + echo esc_html($pos_store_email)."\n"; } - if (! empty($pos_store_phone_number)) { - echo esc_html($pos_store_phone_number) . "\n"; + if (!empty($pos_store_phone_number)) { + echo esc_html($pos_store_phone_number)."\n"; } - if (! empty($pos_store_address)) { - echo esc_html(wp_strip_all_tags(wptexturize($pos_store_address))) . "\n"; + if (!empty($pos_store_address)) { + echo esc_html(wp_strip_all_tags(wptexturize($pos_store_address)))."\n"; } echo "\n----------------------------------------\n\n"; } @@ -103,9 +106,9 @@ if (! empty($pos_store_email) || ! empty($pos_store_phone_number) || ! empty($po /** * Show refund & returns policy - this is set in the Point of Sale settings. */ -if (! empty($pos_refund_returns_policy)) { - echo "\n" . esc_html__('Refund & Returns Policy', 'woocommerce') . "\n\n"; - echo esc_html(wp_strip_all_tags(wptexturize($pos_refund_returns_policy))) . "\n"; +if (!empty($pos_refund_returns_policy)) { + echo "\n".esc_html__('Refund & Returns Policy', 'woocommerce')."\n\n"; + echo esc_html(wp_strip_all_tags(wptexturize($pos_refund_returns_policy)))."\n"; echo "\n----------------------------------------\n\n"; } diff --git a/woocommerce/emails/plain/customer-processing-order.php b/woocommerce/emails/plain/customer-processing-order.php index 005e506bb2be64daf5f077ccd3bcb44a9d8a6d40..540809f31a37577ea5be5c3b36ba14000f64605c 100644 --- a/woocommerce/emails/plain/customer-processing-order.php +++ b/woocommerce/emails/plain/customer-processing-order.php @@ -1,7 +1,7 @@ get_billing_first_name())) . "\n\n"; +echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; if ($email_improvements_enabled) { - echo esc_html__('Just to let you know — we’ve received your order, and it is now being processed.', 'woocommerce') . "\n\n"; - echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce') . "\n\n"; + echo esc_html__('Just to let you know — we’ve received your order, and it is now being processed.', 'woocommerce')."\n\n"; + echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce')."\n\n"; } else { /* translators: %s: Order number */ - echo sprintf(esc_html__('Just to let you know — we\'ve received your order #%s, and it is now being processed:', 'woocommerce'), esc_html($order->get_order_number())) . "\n\n"; + echo sprintf(esc_html__('Just to let you know — we\'ve received your order #%s, and it is now being processed:', 'woocommerce'), esc_html($order->get_order_number()))."\n\n"; } /* diff --git a/woocommerce/emails/plain/customer-refunded-order.php b/woocommerce/emails/plain/customer-refunded-order.php index 243cf94bcc4d0caba02924d4ce28ee45d18f8954..abc501e92dda2f9bd4ed299e627cae636c7f1ebd 100644 --- a/woocommerce/emails/plain/customer-refunded-order.php +++ b/woocommerce/emails/plain/customer-refunded-order.php @@ -1,7 +1,7 @@ get_billing_first_name())) . "\n\n"; +echo sprintf(esc_html__('Hi %s,', 'woocommerce'), esc_html($order->get_billing_first_name()))."\n\n"; if ($email_improvements_enabled) { if ($partial_refund) { /* translators: %s: Site title */ - echo sprintf(esc_html__('Your order from %s has been partially refunded.', 'woocommerce'), esc_html($blogname)) . "\n\n"; + echo sprintf(esc_html__('Your order from %s has been partially refunded.', 'woocommerce'), esc_html($blogname))."\n\n"; } else { /* translators: %s: Site title */ - echo sprintf(esc_html__('Your order from %s has been refunded.', 'woocommerce'), esc_html($blogname)) . "\n\n"; + echo sprintf(esc_html__('Your order from %s has been refunded.', 'woocommerce'), esc_html($blogname))."\n\n"; } - echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce') . "\n\n"; + echo esc_html__('Here’s a reminder of what you’ve ordered:', 'woocommerce')."\n\n"; } elseif ($partial_refund) { /* translators: %s: Site title */ - echo sprintf(esc_html__('Your order on %s has been partially refunded. There are more details below for your reference:', 'woocommerce'), esc_html($blogname)) . "\n\n"; + echo sprintf(esc_html__('Your order on %s has been partially refunded. There are more details below for your reference:', 'woocommerce'), esc_html($blogname))."\n\n"; } else { /* translators: %s: Site title */ - echo sprintf(esc_html__('Your order on %s has been refunded. There are more details below for your reference:', 'woocommerce'), esc_html($blogname)) . "\n\n"; + echo sprintf(esc_html__('Your order on %s has been refunded. There are more details below for your reference:', 'woocommerce'), esc_html($blogname))."\n\n"; } /* diff --git a/woocommerce/emails/plain/customer-reset-password.php b/woocommerce/emails/plain/customer-reset-password.php index ec6c16db398a0823e074d835c8ac6430c3911a6a..613739d1fa657925156f5e311c7ce34db753f72b 100644 --- a/woocommerce/emails/plain/customer-reset-password.php +++ b/woocommerce/emails/plain/customer-reset-password.php @@ -1,7 +1,7 @@ $reset_key, 'id' => $user_id, 'login' => rawurlencode($user_login) ), wc_get_endpoint_url('lost-password', '', wc_get_page_permalink('myaccount')))) . "\n\n"; // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound +echo esc_url(add_query_arg(['key' => $reset_key, 'id' => $user_id, 'login' => rawurlencode($user_login)], wc_get_endpoint_url('lost-password', '', wc_get_page_permalink('myaccount'))))."\n\n"; // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound echo "\n\n----------------------------------------\n\n"; diff --git a/woocommerce/emails/plain/customer-stock-notification-verified.php b/woocommerce/emails/plain/customer-stock-notification-verified.php index 8815828ce58837d067c99d0051a3c9b51a9801c0..b46302515243f370678b0698fe0a38e489d8a309 100644 --- a/woocommerce/emails/plain/customer-stock-notification-verified.php +++ b/woocommerce/emails/plain/customer-stock-notification-verified.php @@ -12,14 +12,13 @@ * the readme will list any important changes. * * @see https://woocommerce.com/document/template-structure/ - * @package WooCommerce\Templates\Emails\Plain + * * @version 10.2.0 */ // Exit if accessed directly. defined('ABSPATH') || exit; - echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"; echo esc_html(wp_strip_all_tags($email_heading)); echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; diff --git a/woocommerce/emails/plain/customer-stock-notification-verify.php b/woocommerce/emails/plain/customer-stock-notification-verify.php index 8fd2b41841358c8bc79fd76f853a7dc416a361f6..cdb5b46eb1b7270636c95b4fe34faf5bd64b8158 100644 --- a/woocommerce/emails/plain/customer-stock-notification-verify.php +++ b/woocommerce/emails/plain/customer-stock-notification-verify.php @@ -12,14 +12,13 @@ * the readme will list any important changes. * * @see https://woocommerce.com/document/template-structure/ - * @package WooCommerce\Templates\Emails\Plain + * * @version 10.2.0 */ // Exit if accessed directly. defined('ABSPATH') || exit; - echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"; echo esc_html(wp_strip_all_tags($email_heading)); echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; diff --git a/woocommerce/emails/plain/customer-stock-notification.php b/woocommerce/emails/plain/customer-stock-notification.php index 1030f9c03052a07e88d6ac339c834fa2cac9c397..25b3cf49c981e2e026fbe3531122b8d319f8c7c0 100644 --- a/woocommerce/emails/plain/customer-stock-notification.php +++ b/woocommerce/emails/plain/customer-stock-notification.php @@ -12,14 +12,13 @@ * the readme will list any important changes. * * @see https://woocommerce.com/document/template-structure/ - * @package WooCommerce\Templates\Emails\Plain + * * @version 10.2.0 */ // Exit if accessed directly. defined('ABSPATH') || exit; - echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"; echo esc_html(wp_strip_all_tags($email_heading)); echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; diff --git a/woocommerce/emails/plain/email-addresses.php b/woocommerce/emails/plain/email-addresses.php index 1ecbd9c4c80c053ede8e561b1ca09bf8d891b529..f25786310577f1c2763995998fd29b796ca1a696 100644 --- a/woocommerce/emails/plain/email-addresses.php +++ b/woocommerce/emails/plain/email-addresses.php @@ -1,7 +1,7 @@ #i', "\n", $order->get_formatted_billing_address()) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped +echo "\n".esc_html(wc_strtoupper(esc_html__('Billing address', 'woocommerce')))."\n\n"; +echo preg_replace('##i', "\n", $order->get_formatted_billing_address())."\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ($order->get_billing_phone()) { - echo $order->get_billing_phone() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo $order->get_billing_phone()."\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ($order->get_billing_email()) { - echo $order->get_billing_email() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo $order->get_billing_email()."\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** @@ -34,22 +33,22 @@ if ($order->get_billing_email()) { * * @since 8.6.0 * - * @param string $type Address type. Either 'billing' or 'shipping'. - * @param WC_Order $order Order instance. - * @param bool $sent_to_admin If this email is being sent to the admin or not. - * @param bool $plain_text If this email is plain text or not. + * @param string $type Address type. Either 'billing' or 'shipping'. + * @param WC_Order $order Order instance. + * @param bool $sent_to_admin If this email is being sent to the admin or not. + * @param bool $plain_text If this email is plain text or not. */ do_action('woocommerce_email_customer_address_section', 'billing', $order, $sent_to_admin, true); -if (! wc_ship_to_billing_address_only() && $order->needs_shipping_address()) { +if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address()) { $shipping = $order->get_formatted_shipping_address(); if ($shipping) { - echo "\n" . esc_html(wc_strtoupper(esc_html__('Shipping address', 'woocommerce'))) . "\n\n"; - echo preg_replace('##i', "\n", $shipping) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo "\n".esc_html(wc_strtoupper(esc_html__('Shipping address', 'woocommerce')))."\n\n"; + echo preg_replace('##i', "\n", $shipping)."\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ($order->get_shipping_phone()) { - echo $order->get_shipping_phone() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo $order->get_shipping_phone()."\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** @@ -57,10 +56,10 @@ if (! wc_ship_to_billing_address_only() && $order->needs_shipping_address()) { * * @since 8.6.0 * - * @param string $type Address type. Either 'billing' or 'shipping'. - * @param WC_Order $order Order instance. - * @param bool $sent_to_admin If this email is being sent to the admin or not. - * @param bool $plain_text If this email is plain text or not. + * @param string $type Address type. Either 'billing' or 'shipping'. + * @param WC_Order $order Order instance. + * @param bool $sent_to_admin If this email is being sent to the admin or not. + * @param bool $plain_text If this email is plain text or not. */ do_action('woocommerce_email_customer_address_section', 'shipping', $order, $sent_to_admin, true); } diff --git a/woocommerce/emails/plain/email-customer-details.php b/woocommerce/emails/plain/email-customer-details.php index f11d9bdea68be129e621b99a26e74c7c5dbc2f9d..e2618c7dfc83a1286f37d326c8914fb94c533be4 100644 --- a/woocommerce/emails/plain/email-customer-details.php +++ b/woocommerce/emails/plain/email-customer-details.php @@ -1,7 +1,7 @@ $column_name) { - echo wp_kses_post($column_name) . ': '; + echo wp_kses_post($column_name).': '; - if (has_action('woocommerce_email_downloads_column_' . $column_id)) { - do_action('woocommerce_email_downloads_column_' . $column_id, $download, $plain_text); + if (has_action('woocommerce_email_downloads_column_'.$column_id)) { + do_action('woocommerce_email_downloads_column_'.$column_id, $download, $plain_text); } else { switch ($column_id) { case 'download-product': echo esc_html($download['product_name']); break; case 'download-file': - echo esc_html($download['download_name']) . ' - ' . esc_url($download['download_url']); + echo esc_html($download['download_name']).' - '.esc_url($download['download_url']); break; case 'download-expires': - if (! empty($download['access_expires'])) { + if (!empty($download['access_expires'])) { echo esc_html(date_i18n(get_option('date_format'), strtotime($download['access_expires']))); } else { esc_html_e('Never', 'woocommerce'); diff --git a/woocommerce/emails/plain/email-fulfillment-details.php b/woocommerce/emails/plain/email-fulfillment-details.php index bfd1953970daec9a58c03021fc5191894f354828..c57ab767bd51829fc733ca5fe971d3df1bc38931 100644 --- a/woocommerce/emails/plain/email-fulfillment-details.php +++ b/woocommerce/emails/plain/email-fulfillment-details.php @@ -12,23 +12,23 @@ * the readme will list any important changes. * * @see https://woocommerce.com/document/template-structure/ - * @package WooCommerce\Templates\Emails\Plain + * * @version 10.1.0 */ - defined('ABSPATH') || exit; if (null === $fulfillment->get_date_deleted()) { - $tracking_number = $fulfillment->get_meta('_tracking_number', true); - $tracking_url = $fulfillment->get_meta('_tracking_url'); + $tracking_number = $fulfillment->get_meta('_tracking_number', true); + $tracking_url = $fulfillment->get_meta('_tracking_url'); $shipment_provider = $fulfillment->get_meta('_shipment_provider'); - if (! $tracking_number && ! $tracking_url && ! $shipment_provider) { + if (!$tracking_number && !$tracking_url && !$shipment_provider) { echo esc_html__('No tracking information available for this fulfillment at the moment.', 'woocommerce'); + return; } else { - echo esc_html__('Tracking Number', 'woocommerce') . ': ' . esc_attr($tracking_number) . "\n"; - echo esc_html__('Shipment Provider', 'woocommerce') . ': ' . esc_html($shipment_provider) . "\n"; - echo esc_html__('Tracking URL', 'woocommerce') . ': ' . esc_html($tracking_url) . "\n\n"; + echo esc_html__('Tracking Number', 'woocommerce').': '.esc_attr($tracking_number)."\n"; + echo esc_html__('Shipment Provider', 'woocommerce').': '.esc_html($shipment_provider)."\n"; + echo esc_html__('Tracking URL', 'woocommerce').': '.esc_html($tracking_url)."\n\n"; } echo esc_html__('You can access to more details of your order by visiting My Account > Orders and select the order you wish to see the latest status of the delivery.', 'woocommerce'); @@ -38,11 +38,12 @@ if (null === $fulfillment->get_date_deleted()) { /** * Action hook to add custom content before fulfillment details in email. * - * @param WC_Order $order Order object. - * @param Fulfillment $fulfillment Fulfillment object. - * @param bool $sent_to_admin Whether it's sent to admin or customer. - * @param bool $plain_text Whether it's a plain text email. - * @param WC_Email $email Email object. + * @param WC_Order $order Order object. + * @param Fulfillment $fulfillment Fulfillment object. + * @param bool $sent_to_admin Whether it's sent to admin or customer. + * @param bool $plain_text Whether it's a plain text email. + * @param WC_Email $email Email object. + * * @since 2.5.0 */ do_action('woocommerce_email_before_fulfillment_table', $order, $fulfillment, $sent_to_admin, $plain_text, $email); @@ -52,17 +53,17 @@ echo "\n\n==========\n\n"; if ($sent_to_admin) { $before = ''; - $after = '(' . esc_url($order->get_edit_order_url()) . ')'; + $after = '('.esc_url($order->get_edit_order_url()).')'; } else { $before = ''; - $after = ''; + $after = ''; } /* translators: %s: Order ID. */ $order_number_string = __('Order #%s', 'woocommerce'); echo wp_kses_post( - $before . sprintf( - $order_number_string . $after . ' (%s)', + $before.sprintf( + $order_number_string.$after.' (%s)', $order->get_order_number(), wc_format_datetime($order->get_date_created()) ) @@ -71,22 +72,23 @@ echo "\n\n\n"; echo wc_get_email_fulfillment_items( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $order, $fulfillment, - array( + [ 'show_sku' => $sent_to_admin, 'show_image' => true, - 'image_size' => array( 48, 48 ), + 'image_size' => [48, 48], 'plain_text' => $plain_text, 'sent_to_admin' => $sent_to_admin, - ) + ] ); /** * Action hook to add custom content after fulfillment details in email. * - * @param WC_Order $order Order object. + * @param WC_Order $order Order object. * @param bool $sent_to_admin Whether it's sent to admin or customer. - * @param bool $plain_text Whether it's a plain text email. - * @param WC_Email $email Email object. + * @param bool $plain_text Whether it's a plain text email. + * @param WC_Email $email Email object. + * * @since 2.5.0 */ do_action('woocommerce_email_after_fulfillment_table', $order, $fulfillment, $sent_to_admin, $plain_text, $email); diff --git a/woocommerce/emails/plain/email-fulfillment-items.php b/woocommerce/emails/plain/email-fulfillment-items.php index f40c35b812e46bd95c5fd5eb4d3e6c7dfca8f72d..f24ef049a7bd29e23fc5569fc3f39501d348178e 100644 --- a/woocommerce/emails/plain/email-fulfillment-items.php +++ b/woocommerce/emails/plain/email-fulfillment-items.php @@ -1,7 +1,7 @@ $item) : +foreach ($items as $item_id => $item) { /** * Email Order Item Visibility hook. * * @since 2.5.0 - * @param $visible Whether the item is visible in the email. - * @param WC_Order_Item_Product $item The order item object. + * + * @param $visible Whether the item is visible in the email. + * @param WC_Order_Item_Product $item The order item object. * * @return bool */ @@ -33,12 +33,12 @@ foreach ($items as $item_id => $item) : true, $item->item )) { - $product = $item->item->get_product(); - $sku = ''; + $product = $item->item->get_product(); + $sku = ''; $purchase_note = ''; if (is_object($product)) { - $sku = $product->get_sku(); + $sku = $product->get_sku(); $purchase_note = $product->get_purchase_note(); } @@ -47,30 +47,32 @@ foreach ($items as $item_id => $item) : * * @since 2.1.0 * @since 2.4.0 Added $is_visible parameter. + * * @param string $product_name Product name. - * @param WC_Order_Item $item Order item object. - * @param bool $is_visible Is item visible. + * @param WC_Order_Item $item Order item object. + * @param bool $is_visible Is item visible. */ $product_name = apply_filters('woocommerce_order_item_name', $item->item->get_name(), $item->item, false); /** * Email Order Item Quantity hook. * * @since 2.4.0 + * * @param int $quantity Item quantity. * @param WC_Order_Item $item Item object. */ - $product_name .= ' × ' . apply_filters('woocommerce_email_order_item_quantity', $item->qty, $item->item); + $product_name .= ' × '.apply_filters('woocommerce_email_order_item_quantity', $item->qty, $item->item); echo wp_kses_post(str_pad(wp_kses_post($product_name), 40)); echo ' '; - echo esc_html(str_pad(wp_kses($order->get_formatted_line_subtotal($item->item), array()), 20, ' ', STR_PAD_LEFT)) . "\n"; + echo esc_html(str_pad(wp_kses($order->get_formatted_line_subtotal($item->item), []), 20, ' ', STR_PAD_LEFT))."\n"; // SKU. if ($show_sku && $sku) { - echo esc_html('(#' . $sku . ")\n"); + echo esc_html('(#'.$sku.")\n"); } } // Note. if ($show_purchase_note && $purchase_note) { - echo "\n" . do_shortcode(wp_kses_post($purchase_note)); + echo "\n".do_shortcode(wp_kses_post($purchase_note)); } -endforeach; +} diff --git a/woocommerce/emails/plain/email-order-details.php b/woocommerce/emails/plain/email-order-details.php index e0fcb21eaa58e668d977c8687f7c70281b1edaea..a6a6735870f34ac928bfa9003e6fbd1e8aa2ec9a 100644 --- a/woocommerce/emails/plain/email-order-details.php +++ b/woocommerce/emails/plain/email-order-details.php @@ -12,7 +12,7 @@ * the readme will list any important changes. * * @see https://woocommerce.com/document/template-structure/ - * @package WooCommerce\Templates\Emails + * * @version 10.1.0 */ @@ -30,21 +30,21 @@ do_action('woocommerce_email_before_order_table', $order, $sent_to_admin, $plain if ($email_improvements_enabled) { /* translators: %1$s: Order ID. %2$s: Order date */ - echo wp_kses_post(sprintf(esc_html__('Order #%1$s (%2$s)', 'woocommerce'), $order->get_order_number(), wc_format_datetime($order->get_date_created()))) . "\n"; + echo wp_kses_post(sprintf(esc_html__('Order #%1$s (%2$s)', 'woocommerce'), $order->get_order_number(), wc_format_datetime($order->get_date_created())))."\n"; echo "\n==========\n"; } else { /* translators: %1$s: Order ID. %2$s: Order date */ - echo wp_kses_post(wc_strtoupper(sprintf(esc_html__('[Order #%1$s] (%2$s)', 'woocommerce'), $order->get_order_number(), wc_format_datetime($order->get_date_created())))) . "\n"; + echo wp_kses_post(wc_strtoupper(sprintf(esc_html__('[Order #%1$s] (%2$s)', 'woocommerce'), $order->get_order_number(), wc_format_datetime($order->get_date_created()))))."\n"; } -echo "\n" . wc_get_email_order_items( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped +echo "\n".wc_get_email_order_items( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $order, - array( + [ 'show_sku' => $sent_to_admin, 'show_image' => false, - 'image_size' => array( 32, 32 ), + 'image_size' => [32, 32], 'plain_text' => true, 'sent_to_admin' => $sent_to_admin, - ) + ] ); echo "==========\n\n"; @@ -56,28 +56,28 @@ if ($item_totals) { if ($email_improvements_enabled) { $label = $total['label']; if (isset($total['meta'])) { - $label .= ' ' . $total['meta']; + $label .= ' '.$total['meta']; } echo wp_kses_post(str_pad(wp_kses_post($label), 40)); echo ' '; - echo esc_html(str_pad(wp_kses($total['value'], array()), 20, ' ', STR_PAD_LEFT)) . "\n"; + echo esc_html(str_pad(wp_kses($total['value'], []), 20, ' ', STR_PAD_LEFT))."\n"; } else { - echo wp_kses_post($total['label'] . "\t " . $total['value']) . "\n"; + echo wp_kses_post($total['label']."\t ".$total['value'])."\n"; } } } if ($order->get_customer_note()) { if ($email_improvements_enabled) { - echo "\n" . esc_html__('Note:', 'woocommerce') . "\n" . wp_kses(wc_wptexturize_order_note($order->get_customer_note()), array()) . "\n"; + echo "\n".esc_html__('Note:', 'woocommerce')."\n".wp_kses(wc_wptexturize_order_note($order->get_customer_note()), [])."\n"; } else { - echo esc_html__('Note:', 'woocommerce') . "\t " . wp_kses(wc_wptexturize_order_note($order->get_customer_note()), array()) . "\n"; + echo esc_html__('Note:', 'woocommerce')."\t ".wp_kses(wc_wptexturize_order_note($order->get_customer_note()), [])."\n"; } } if ($sent_to_admin) { /* translators: %s: Order link. */ - echo "\n" . sprintf(esc_html__('View order: %s', 'woocommerce'), esc_url($order->get_edit_order_url())) . "\n"; + echo "\n".sprintf(esc_html__('View order: %s', 'woocommerce'), esc_url($order->get_edit_order_url()))."\n"; } do_action('woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email); diff --git a/woocommerce/emails/plain/email-order-items.php b/woocommerce/emails/plain/email-order-items.php index 3448ba42bf36994acea03a7072fa4aa4d59a7fb8..888c76d25202a20ce6a5991b9a3b3ecbe6389715 100644 --- a/woocommerce/emails/plain/email-order-items.php +++ b/woocommerce/emails/plain/email-order-items.php @@ -1,7 +1,7 @@ $item) : +foreach ($items as $item_id => $item) { if (apply_filters('woocommerce_order_item_visible', true, $item)) { - $product = $item->get_product(); - $sku = ''; + $product = $item->get_product(); + $sku = ''; $purchase_note = ''; if (is_object($product)) { - $sku = $product->get_sku(); + $sku = $product->get_sku(); $purchase_note = $product->get_purchase_note(); } @@ -39,24 +39,26 @@ foreach ($items as $item_id => $item) : * * @since 2.1.0 * @since 2.4.0 Added $is_visible parameter. + * * @param string $product_name Product name. - * @param WC_Order_Item $item Order item object. - * @param bool $is_visible Is item visible. + * @param WC_Order_Item $item Order item object. + * @param bool $is_visible Is item visible. */ $product_name = apply_filters('woocommerce_order_item_name', $item->get_name(), $item, false); /** * Email Order Item Quantity hook. * * @since 2.4.0 + * * @param int $quantity Item quantity. * @param WC_Order_Item $item Item object. */ - $product_name .= ' × ' . apply_filters('woocommerce_email_order_item_quantity', $item->get_quantity(), $item); + $product_name .= ' × '.apply_filters('woocommerce_email_order_item_quantity', $item->get_quantity(), $item); echo wp_kses_post(str_pad(wp_kses_post($product_name), 40)); echo ' '; - echo esc_html(str_pad(wp_kses($order->get_formatted_line_subtotal($item), array()), 20, ' ', STR_PAD_LEFT)) . "\n"; + echo esc_html(str_pad(wp_kses($order->get_formatted_line_subtotal($item), []), 20, ' ', STR_PAD_LEFT))."\n"; if ($show_sku && $sku) { - echo esc_html('(#' . $sku . ")\n"); + echo esc_html('(#'.$sku.")\n"); } } else { // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped @@ -65,23 +67,25 @@ foreach ($items as $item_id => $item) : * * @since 2.1.0 * @since 2.4.0 Added $is_visible parameter. + * * @param string $product_name Product name. - * @param WC_Order_Item $item Order item object. - * @param bool $is_visible Is item visible. + * @param WC_Order_Item $item Order item object. + * @param bool $is_visible Is item visible. */ echo wp_kses_post(apply_filters('woocommerce_order_item_name', $item->get_name(), $item, false)); if ($show_sku && $sku) { - echo ' (#' . $sku . ')'; + echo ' (#'.$sku.')'; } /** * Email Order Item Quantity hook. * * @since 2.4.0 + * * @param int $quantity Item quantity. * @param WC_Order_Item $item Item object. */ - echo ' X ' . apply_filters('woocommerce_email_order_item_quantity', $item->get_quantity(), $item); - echo ' = ' . $order->get_formatted_line_subtotal($item) . "\n"; + echo ' X '.apply_filters('woocommerce_email_order_item_quantity', $item->get_quantity(), $item); + echo ' = '.$order->get_formatted_line_subtotal($item)."\n"; // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped } @@ -91,13 +95,13 @@ foreach ($items as $item_id => $item) : echo strip_tags( wc_display_item_meta( $item, - array( + [ 'before' => "\n- ", 'separator' => "\n- ", 'after' => '', 'echo' => false, 'autop' => false, - ) + ] ) ); @@ -106,7 +110,7 @@ foreach ($items as $item_id => $item) : } // Note. if ($show_purchase_note && $purchase_note) { - echo "\n" . do_shortcode(wp_kses_post($purchase_note)); + echo "\n".do_shortcode(wp_kses_post($purchase_note)); } echo "\n\n"; -endforeach; +} diff --git a/woocommerce/global/breadcrumb.php b/woocommerce/global/breadcrumb.php index 6d30df67a3202de168b7e37f26b99e1ddc3b8cae..eb174b37b3186db111dbc0c2d8cb1cb2c3e7acc2 100644 --- a/woocommerce/global/breadcrumb.php +++ b/woocommerce/global/breadcrumb.php @@ -1,7 +1,7 @@ $crumb) { - echo $before; - if (! empty($crumb[1]) && sizeof($breadcrumb) !== $key + 1) { - echo '' . esc_html($crumb[0]) . ''; + if (!empty($crumb[1]) && sizeof($breadcrumb) !== $key + 1) { + echo ''.esc_html($crumb[0]).''; } else { echo esc_html($crumb[0]); } @@ -41,5 +39,4 @@ if (! empty($breadcrumb)) { } echo $wrap_after; - } diff --git a/woocommerce/global/sidebar.php b/woocommerce/global/sidebar.php index a57a5c6b1d62d98ded07b94fbb148349ef905dae..eecbd805996ccf4367dd4e8724097808eab0fbdc 100644 --- a/woocommerce/global/sidebar.php +++ b/woocommerce/global/sidebar.php @@ -1,7 +1,7 @@ ['href' => []]]); \Timber\Timber::render('views/woocommerce/myaccount/dashboard.twig', [ - 'user_name' => esc_html($current_user->display_name), - 'logout_url' => esc_url(wc_logout_url()), + 'user_name' => esc_html($current_user->display_name), + 'logout_url' => esc_url(wc_logout_url()), 'description_html' => $description_html, ]); diff --git a/woocommerce/myaccount/downloads.php b/woocommerce/myaccount/downloads.php index eb49b00a15fa432f1cc04f0680446f2cc9a61e14..b9bbc57b31f6dffea6c66ea79101bacb3adbc076 100644 --- a/woocommerce/myaccount/downloads.php +++ b/woocommerce/myaccount/downloads.php @@ -2,15 +2,15 @@ defined('ABSPATH') || exit; -$downloads = WC()->customer->get_downloadable_products(); +$downloads = WC()->customer->get_downloadable_products(); $has_downloads = (bool) $downloads; do_action('woocommerce_before_account_downloads', $has_downloads); if ($has_downloads) { - $before = capture_action('woocommerce_before_available_downloads'); + $before = capture_action('woocommerce_before_available_downloads'); $content = capture_action('woocommerce_available_downloads', $downloads); - $after = capture_action('woocommerce_after_available_downloads'); + $after = capture_action('woocommerce_after_available_downloads'); } else { $before = $content = $after = ''; } diff --git a/woocommerce/myaccount/form-add-payment-method.php b/woocommerce/myaccount/form-add-payment-method.php index 54b078fbfb4ed25dfc32f94992aff08f4924f2f2..bd9352c0108ed872637263da8eee29dbbd2d51dc 100644 --- a/woocommerce/myaccount/form-add-payment-method.php +++ b/woocommerce/myaccount/form-add-payment-method.php @@ -11,8 +11,8 @@ if ($available_gateways) { $gateways = []; foreach ($available_gateways as $gateway) { - $has_fields = $gateway->has_fields() || $gateway->get_description(); - $gateways[] = [ + $has_fields = $gateway->has_fields() || $gateway->get_description(); + $gateways[] = [ 'id' => $gateway->id, 'title' => $gateway->get_title(), 'icon' => $gateway->get_icon(), diff --git a/woocommerce/myaccount/form-edit-account.php b/woocommerce/myaccount/form-edit-account.php index a8c5362687ab3224e1cb58eaf008e5fa06b5b903..cb9c1a6ed9ca8886aeea7e9f68a0816547ba4c97 100644 --- a/woocommerce/myaccount/form-edit-account.php +++ b/woocommerce/myaccount/form-edit-account.php @@ -4,12 +4,12 @@ defined('ABSPATH') || exit; do_action('woocommerce_before_edit_account_form'); -$form_tag = capture_action('woocommerce_edit_account_form_tag'); -$form_start = capture_action('woocommerce_edit_account_form_start'); +$form_tag = capture_action('woocommerce_edit_account_form_tag'); +$form_start = capture_action('woocommerce_edit_account_form_start'); $form_fields = capture_action('woocommerce_edit_account_form_fields'); -$form_extra = capture_action('woocommerce_edit_account_form'); -$form_end = capture_action('woocommerce_edit_account_form_end'); -$nonce = wp_nonce_field('save_account_details', 'save-account-details-nonce', true, false); +$form_extra = capture_action('woocommerce_edit_account_form'); +$form_end = capture_action('woocommerce_edit_account_form_end'); +$nonce = wp_nonce_field('save_account_details', 'save-account-details-nonce', true, false); \Timber\Timber::render('views/woocommerce/myaccount/form-edit-account.twig', [ 'user' => $user, diff --git a/woocommerce/myaccount/form-edit-address.php b/woocommerce/myaccount/form-edit-address.php index 633c3d2cce94141c4a74ab57377819e565a6eacb..6c02a7ea021b63c6eaee19cd9cf7e1e6b760c206 100644 --- a/woocommerce/myaccount/form-edit-address.php +++ b/woocommerce/myaccount/form-edit-address.php @@ -6,6 +6,7 @@ do_action('woocommerce_before_edit_account_address_form'); if (!$load_address) { wc_get_template('myaccount/my-address.php'); + return; } @@ -18,7 +19,7 @@ $page_title = apply_filters( ); $before_form = capture_action("woocommerce_before_edit_address_form_{$load_address}"); -$after_form = capture_action("woocommerce_after_edit_address_form_{$load_address}"); +$after_form = capture_action("woocommerce_after_edit_address_form_{$load_address}"); ob_start(); foreach ($address as $key => $field) { diff --git a/woocommerce/myaccount/form-login.php b/woocommerce/myaccount/form-login.php index 32f402d437fbf5f9f0cc9168edad811a82771180..661c63e153d585ef89396a1813974cfe3cac5adf 100644 --- a/woocommerce/myaccount/form-login.php +++ b/woocommerce/myaccount/form-login.php @@ -6,22 +6,22 @@ do_action('woocommerce_before_customer_login_form'); $registration_enabled = 'yes' === get_option('woocommerce_enable_myaccount_registration'); -$login_form_start = capture_action('woocommerce_login_form_start'); +$login_form_start = capture_action('woocommerce_login_form_start'); $login_form_middle = capture_action('woocommerce_login_form'); -$login_form_end = capture_action('woocommerce_login_form_end'); +$login_form_end = capture_action('woocommerce_login_form_end'); $register_data = []; if ($registration_enabled) { - $register_data['form_start'] = capture_action('woocommerce_register_form_start'); + $register_data['form_start'] = capture_action('woocommerce_register_form_start'); $register_data['form_tag_attrs'] = capture_action('woocommerce_register_form_tag'); - $register_data['form_middle'] = capture_action('woocommerce_register_form'); - $register_data['form_end'] = capture_action('woocommerce_register_form_end'); + $register_data['form_middle'] = capture_action('woocommerce_register_form'); + $register_data['form_end'] = capture_action('woocommerce_register_form_end'); $register_data['generate_username'] = 'yes' === get_option('woocommerce_registration_generate_username'); $register_data['generate_password'] = 'yes' === get_option('woocommerce_registration_generate_password'); - $register_data['nonce'] = wp_nonce_field('woocommerce-register', 'woocommerce-register-nonce', true, false); - $register_data['username_value'] = !empty($_POST['username']) ? esc_attr(wp_unslash($_POST['username'])) : ''; - $register_data['email_value'] = !empty($_POST['email']) ? esc_attr(wp_unslash($_POST['email'])) : ''; + $register_data['nonce'] = wp_nonce_field('woocommerce-register', 'woocommerce-register-nonce', true, false); + $register_data['username_value'] = !empty($_POST['username']) ? esc_attr(wp_unslash($_POST['username'])) : ''; + $register_data['email_value'] = !empty($_POST['email']) ? esc_attr(wp_unslash($_POST['email'])) : ''; } \Timber\Timber::render('views/woocommerce/myaccount/form-login.twig', [ diff --git a/woocommerce/myaccount/form-lost-password.php b/woocommerce/myaccount/form-lost-password.php index 5e46eb98a78c50f3495a4a809bfdaea903eb76b2..ae2885dc9ffd304ea9a2d810b6692583e90edfb3 100644 --- a/woocommerce/myaccount/form-lost-password.php +++ b/woocommerce/myaccount/form-lost-password.php @@ -4,9 +4,9 @@ defined('ABSPATH') || exit; do_action('woocommerce_before_lost_password_form'); -$message = apply_filters('woocommerce_lost_password_message', esc_html__('Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.', 'woocommerce')); +$message = apply_filters('woocommerce_lost_password_message', esc_html__('Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.', 'woocommerce')); $form_extra = capture_action('woocommerce_lostpassword_form'); -$nonce = wp_nonce_field('lost_password', 'woocommerce-lost-password-nonce', true, false); +$nonce = wp_nonce_field('lost_password', 'woocommerce-lost-password-nonce', true, false); \Timber\Timber::render('views/woocommerce/myaccount/form-lost-password.twig', [ 'message' => $message, diff --git a/woocommerce/myaccount/form-reset-password.php b/woocommerce/myaccount/form-reset-password.php index 309d9266bc82326a901f15798483f689f54eacb5..c9ad1424e2d68751a1f9dc24fc88879a0c4c749c 100644 --- a/woocommerce/myaccount/form-reset-password.php +++ b/woocommerce/myaccount/form-reset-password.php @@ -4,9 +4,9 @@ defined('ABSPATH') || exit; do_action('woocommerce_before_reset_password_form'); -$message = apply_filters('woocommerce_reset_password_message', esc_html__('Enter a new password below.', 'woocommerce')); +$message = apply_filters('woocommerce_reset_password_message', esc_html__('Enter a new password below.', 'woocommerce')); $form_extra = capture_action('woocommerce_resetpassword_form'); -$nonce = wp_nonce_field('reset_password', 'woocommerce-reset-password-nonce', true, false); +$nonce = wp_nonce_field('reset_password', 'woocommerce-reset-password-nonce', true, false); \Timber\Timber::render('views/woocommerce/myaccount/form-reset-password.twig', [ 'message' => $message, diff --git a/woocommerce/myaccount/my-address.php b/woocommerce/myaccount/my-address.php index a265914901fdaee2c130523d285d1751d6bb8265..3a644ec9c01d65c4c07040b7e912a5ae1075a23e 100644 --- a/woocommerce/myaccount/my-address.php +++ b/woocommerce/myaccount/my-address.php @@ -2,7 +2,7 @@ defined('ABSPATH') || exit; -$customer_id = get_current_user_id(); +$customer_id = get_current_user_id(); $multi_address = !wc_ship_to_billing_address_only() && wc_shipping_enabled(); if ($multi_address) { diff --git a/woocommerce/myaccount/navigation.php b/woocommerce/myaccount/navigation.php index b8b62901f04351fc333838ac1e74510186ca0a51..d412acde76ef9aaf19caab0a39024403f1479552 100644 --- a/woocommerce/myaccount/navigation.php +++ b/woocommerce/myaccount/navigation.php @@ -5,7 +5,7 @@ defined('ABSPATH') || exit; do_action('woocommerce_before_account_navigation'); $menu_items = wc_get_account_menu_items(); -$nav_items = []; +$nav_items = []; foreach ($menu_items as $endpoint => $label) { $nav_items[] = [ diff --git a/woocommerce/myaccount/orders.php b/woocommerce/myaccount/orders.php index 06be69685347509ea618ecc9833c5c3e19f95b6d..89b03ad79cb1c7cbf98299747cff3031477b1b9a 100644 --- a/woocommerce/myaccount/orders.php +++ b/woocommerce/myaccount/orders.php @@ -4,24 +4,24 @@ defined('ABSPATH') || exit; do_action('woocommerce_before_account_orders', $has_orders); -$columns = wc_get_account_orders_columns(); -$order_rows = []; +$columns = wc_get_account_orders_columns(); +$order_rows = []; if ($has_orders) { foreach ($customer_orders->orders as $customer_order) { - $order = wc_get_order($customer_order); + $order = wc_get_order($customer_order); $item_count = $order->get_item_count() - $order->get_item_count_refunded(); - $cells = []; + $cells = []; foreach ($columns as $column_id => $column_name) { - if (has_action('woocommerce_my_account_my_orders_column_' . $column_id)) { - $content = capture_action('woocommerce_my_account_my_orders_column_' . $column_id, $order); + if (has_action('woocommerce_my_account_my_orders_column_'.$column_id)) { + $content = capture_action('woocommerce_my_account_my_orders_column_'.$column_id, $order); } elseif ('order-number' === $column_id) { $content = sprintf( '%s', esc_url($order->get_view_order_url()), esc_attr(sprintf(__('View order number %s', 'woocommerce'), $order->get_order_number())), - esc_html(_x('#', 'hash before order number', 'woocommerce') . $order->get_order_number()) + esc_html(_x('#', 'hash before order number', 'woocommerce').$order->get_order_number()) ); } elseif ('order-date' === $column_id) { $content = sprintf( diff --git a/woocommerce/myaccount/payment-methods.php b/woocommerce/myaccount/payment-methods.php index 2f1f773ba7d0fc03a960789f78c63d5e4edcd1b3..859405c0ca8b3ce52e72b880edbc9911742d3305 100644 --- a/woocommerce/myaccount/payment-methods.php +++ b/woocommerce/myaccount/payment-methods.php @@ -3,8 +3,8 @@ defined('ABSPATH') || exit; $saved_methods = wc_get_customer_saved_methods_list(get_current_user_id()); -$has_methods = (bool) $saved_methods; -$columns = wc_get_account_payment_methods_columns(); +$has_methods = (bool) $saved_methods; +$columns = wc_get_account_payment_methods_columns(); do_action('woocommerce_before_account_payment_methods', $has_methods); @@ -13,8 +13,8 @@ foreach ($saved_methods as $type => $methods) { foreach ($methods as $method) { $cells = []; foreach ($columns as $column_id => $column_name) { - if (has_action('woocommerce_account_payment_methods_column_' . $column_id)) { - $content = capture_action('woocommerce_account_payment_methods_column_' . $column_id, $method); + if (has_action('woocommerce_account_payment_methods_column_'.$column_id)) { + $content = capture_action('woocommerce_account_payment_methods_column_'.$column_id, $method); } elseif ('method' === $column_id) { if (!empty($method['method']['last4'])) { $content = sprintf( diff --git a/woocommerce/myaccount/view-order.php b/woocommerce/myaccount/view-order.php index 50eff355979f750a35001c3b489a36a58e44a15c..7da024345d6ce85d68409f555a0da73525f7bb92 100644 --- a/woocommerce/myaccount/view-order.php +++ b/woocommerce/myaccount/view-order.php @@ -8,9 +8,9 @@ $status_text = wp_kses_post(apply_filters( 'woocommerce_order_details_status', sprintf( esc_html__('Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce'), - '' . $order->get_order_number() . '', - '' . wc_format_datetime($order->get_date_created()) . '', - '' . wc_get_order_status_name($order->get_status()) . '' + ''.$order->get_order_number().'', + ''.wc_format_datetime($order->get_date_created()).'', + ''.wc_get_order_status_name($order->get_status()).'' ), $order )); diff --git a/woocommerce/single-product.php b/woocommerce/single-product.php index 6b622ab1c5a1067d465216020e4fcc58edf3c2ed..e72813cabd9d0240516d29e3d98debe11d7323ef 100644 --- a/woocommerce/single-product.php +++ b/woocommerce/single-product.php @@ -2,7 +2,7 @@ /** * @see https://woocommerce.com/document/template-structure/ - * @package WooCommerce\Templates + * * @version 1.6.4 */ diff --git a/woocommerce/single-product/product-thumbnails.php b/woocommerce/single-product/product-thumbnails.php index 04b5777b8d76e2ff3893f0e0e8c9c658ce337421..a2a50c6d387a25f394cede46b7408ae7be947ae6 100644 --- a/woocommerce/single-product/product-thumbnails.php +++ b/woocommerce/single-product/product-thumbnails.php @@ -1,7 +1,7 @@ ', ''); diff --git a/woocommerce/taxonomy-product-attribute.php b/woocommerce/taxonomy-product-attribute.php index c46ad71e26caa25e6411669af6fe31275c8ad6fa..57ef02ddef93d755b2ca20b14bfca6926ab2cca9 100644 --- a/woocommerce/taxonomy-product-attribute.php +++ b/woocommerce/taxonomy-product-attribute.php @@ -1,7 +1,7 @@