Popular New Releases in Wordpress
insomnia
Insomnia 2022.3.0-beta.4 📦
wp-calypso
WP-Desktop 6.15.0 [updater redirect to wp-desktop repository]
sage
v10.1.5
mailinabox
deployer
v7.0.0-rc.8
Popular Libraries in Wordpress
by Kong javascript
20669 MIT
The open-source, cross-platform API client for GraphQL, REST, and gRPC.
by benweet javascript
18405 Apache-2.0
In-browser Markdown editor
by WordPress php
16054 NOASSERTION
WordPress, Git-ified. This repository is just a mirror of the WordPress subversion repository. Please do not send pull requests. Submit pull requests to https://github.com/WordPress/wordpress-develop and patches to https://core.trac.wordpress.org/ instead.
by digitalocean javascript
15473 MIT
⚙️ NGINX config generator on steroids 💉
by Automattic javascript
12026 GPL-2.0
The JavaScript and API powered WordPress.com
by roots php
11698 MIT
WordPress starter theme with Laravel Blade components and templates, Tailwind CSS, and a modern development workflow
by mail-in-a-box python
10720 CC0-1.0
Mail-in-a-Box helps individuals take back control of their email by defining a one-click, easy-to-deploy SMTP+everything else server: a mail server in a box.
by Automattic css
10468 GPL-2.0
Hi. I'm a starter theme called _s, or underscores, if you like. I'm a theme meant for hacking so don't use me as a Parent Theme. Instead try turning me into the next, most awesome, WordPress theme out there. That's what I'm here for.
by deployphp php
9147 MIT
A deployment tool written in PHP with support for popular frameworks out of the box
Trending New libraries in Wordpress
by schenkd python
3880 MIT
Nginx UI allows you to access and modify the nginx configurations files without cli.
by alibaba typescript
1474 MIT
🧩 Make everything designable 🧩
by mirai-mamori php
1120 GPL-2.0
一个多彩,轻松上手,体验完善,具有强大自定义功能的WordPress主题(基于Sakura主题)A Colorful, Easy-to-use, Perfect Experience, and Powerful Customizable WordPress Theme (Based on Theme Sakura)
by is-a-dev javascript
960 GPL-3.0
Grab your own sweet-looking '.is-a.dev' subdomain
by wpengine typescript
845 NOASSERTION
Faust.js - The Headless WordPress Framework
by Licoy php
729 GPL-3.0
:art: 一款基于WordPress开发的高颜值的自适应主题,支持白天与黑夜模式、无刷新加载等 | A high-value adaptive theme based on WordPress, supports day and night modes, no refresh loading, etc.
by CERT-Polska python
653 NOASSERTION
DRAKVUF Sandbox - automated hypervisor-level malware analysis system
by google javascript
640 Apache-2.0
Web Stories for WordPress
by colbyfayock javascript
562 MIT
📝 Bring WordPress to the static world with Next.js
Top Authors in Wordpress
1
403 Libraries
1487
2
160 Libraries
36581
3
94 Libraries
6217
4
58 Libraries
3391
5
52 Libraries
606
6
51 Libraries
7754
7
50 Libraries
2595
8
49 Libraries
1833
9
44 Libraries
12173
10
44 Libraries
33327
1
403 Libraries
1487
2
160 Libraries
36581
3
94 Libraries
6217
4
58 Libraries
3391
5
52 Libraries
606
6
51 Libraries
7754
7
50 Libraries
2595
8
49 Libraries
1833
9
44 Libraries
12173
10
44 Libraries
33327
Trending Kits in Wordpress
No Trending Kits are available at this moment for Wordpress
Trending Discussions on Wordpress
Is it possible to add settings to "allow-plugins" in config section in composer.json through the CLI?
Failed to load next.config.js
EXPORTHOW and DECLARE - what are they?
clarity.js by Microsoft slowing overall page loads
vvv.test not loading (nor any of my sites) when running vagrant up
How to get the image links from Gutenberg block gallery and add them as html data attributes to a button in wordpress
Using EXPORTHOW to make declarator that acts like "sub"
jQuery: How to set max height of 3 'h3' element under a specific DIV to all h3 element?
Woocommerce admin_notices does not work when woocommerce_order_status_changed hook fires
Wordpress site hacked -- redirects to another site
QUESTION
Is it possible to add settings to "allow-plugins" in config section in composer.json through the CLI?
Asked 2022-Mar-29 at 08:31Since composer 2.2 the setting allow-plugins
will be compulsory I’ve tried to push this setting through the composer config
command in the CLI but with no luck.
I’ve tried a few commands like:
composer config --json '{"allow-plugins.composer/installers":true, "allow-plugins.dealerdirect/phpcodesniffer-composer-installer": true, "allow-plugins.roots/wordpress-core-installer": true }'
composer config config.allow-plugins '{"composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "wordpress-core-installer": true}'
composer config --append "allow-plugins" "composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "wordpress-core-installer": true
composer config --json "allow-plugins" '{"composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "roots/wordpress-core-installer": true }'
All I get is error messages like ".. is not defined" or that it is an invalid value.
What I have is this:
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5
And, I need to add the settings like this:
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5"config": {
6 "optimize-autoloader": true,
7 "preferred-install": "dist",
8 "allow-plugins": {
9 "composer/installers": true,
10 "dealerdirect/phpcodesniffer-composer-installer": true,
11 "roots/wordpress-core-installer": true
12 }
13},
14
Is this possible through the CLI?
ANSWER
Answered 2022-Mar-29 at 08:31You need to pass set them one by one.
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5"config": {
6 "optimize-autoloader": true,
7 "preferred-install": "dist",
8 "allow-plugins": {
9 "composer/installers": true,
10 "dealerdirect/phpcodesniffer-composer-installer": true,
11 "roots/wordpress-core-installer": true
12 }
13},
14composer config allow-plugins.composer/installers true
15composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
16composer config allow-plugins.roots/wordpress-core-installer true
17
Edit per conversation in comments:
OP was looking to also achieve not being prompted during the command. To do this, we must pass the --no-interaction
(or -n
) option. This can be useful when performing automation tasks.
Full Example of OP's Plugins:
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5"config": {
6 "optimize-autoloader": true,
7 "preferred-install": "dist",
8 "allow-plugins": {
9 "composer/installers": true,
10 "dealerdirect/phpcodesniffer-composer-installer": true,
11 "roots/wordpress-core-installer": true
12 }
13},
14composer config allow-plugins.composer/installers true
15composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
16composer config allow-plugins.roots/wordpress-core-installer true
17composer config --no-interaction allow-plugins.composer/installerstrue
18composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
19composer config --no-interaction allow-plugins.roots/wordpress-core-installer true
20
QUESTION
Failed to load next.config.js
Asked 2022-Mar-11 at 12:03After cloning the repository I created and set my .env.local
file, ran npm i
then ran npm run dev
. The server starts, env is loaded from .env.local
however it immediately fails prompting me with the following:
1error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
2Error: Not supported
3 at Object.loadConfig [as default] (C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\server\config.js:399:74)
4 at async NextServer.loadConfig (C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\server\next.js:110:22)
5 at async NextServer.prepare (C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\server\next.js:92:24)
6 at async C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\cli\next-dev.js:126:9
7npm ERR! code ELIFECYCLE
8npm ERR! errno 1
9npm ERR! rebuild@0.1.0 dev: `next dev`
10npm ERR! Exit status 1
11npm ERR!
12npm ERR! Failed at the rebuild@0.1.0 dev script.
13npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
14
15npm ERR! A complete log of this run can be found in:
16npm ERR! C:\Users\Nick\AppData\Roaming\npm-cache\_logs\2021-10-29T19_47_30_427Z-debug.log
17
The NextJS documentation says: See the error message in your terminal where you started next to see more context.
however all it is telling me is Not Supported.
I'm not familiar with the error and was looking for guidance.
ANSWER
Answered 2021-Oct-30 at 20:21I solved this by upgrading to the latest version of nodeJS
QUESTION
EXPORTHOW and DECLARE - what are they?
Asked 2022-Jan-30 at 01:25I have read an article by Jonathan Worthington about meta programming. There he writes:
Do do this, we stick it in the EXPORTHOW module, under the name “class”. The importer pays special attention to this module, if it exists.
At he same time here Jonathan uses DECLARE
.
Is there any documentation about that and other similar things? What and when should one use? What are other special things importer looks for?
I tried to search the official docs but failed to find anything there.
Thank you in advance!
ANSWER
Answered 2022-Jan-30 at 01:25where can we at least look at all possible things like that?
Aiui the source code of the Rakudo compiler is as good as you're gonna get.
It looks to me like EXPORTHOW
is processed here, with DECLARE
in particular here, as part of World.nqp
.
Afaik the World
class is:
An internal implementation specific detail of Rakudo. It is not part of the Raku language. It is not something you can rely on. It is not officially supported.
Written in nqp. nqp is not Raku. It's essentially a small subset of Raku focused on being a good programming language for writing compilers.
QUESTION
clarity.js by Microsoft slowing overall page loads
Asked 2022-Jan-17 at 16:40I have a customer using bing tracking via https://bat.bing.com/bat.js.
On December, 6th 2021 it started calling in clarity.js without the customer making any changes to their code.
This slowed the overall page load by 1 second on mobile and 500ms on desktop. I've been trying to figure out how to disable this JS but I'm not sure what to do as it's being fired from the bing tracking js.
The bing tracking code is being triggered via google tag manager.
Anyone else having this issue and know how to disable clarity.js from being called at all?
Customer is using Wordpress. Amazing Bing can implement code that slows down a site overall page speed without any notification to the customer.
ANSWER
Answered 2021-Dec-17 at 18:16We figured this out by going into our bing web tools and disabling the Clarity integration.
QUESTION
vvv.test not loading (nor any of my sites) when running vagrant up
Asked 2022-Jan-07 at 21:03Ever since I've upgraded my Mac
to Monteray
, I've been having issues with Vagrant
.
Initially, I use to see a vBoxManage
error on terminal
when running vagrant up
. I posted a question on this on SO previously, see here for details.
Today, I uninstalled VirtualBox
again (removed VirtualBox VMs
folder and moved application to trash) and reinstalled VirtualBox 6.1.3
for OS X hosts` (link here).
I then ran vagrant up
on terminal
and it successfully compiled:
After seeing the famous green teddy, I tried going to vvv.test
but, the page doesn't load. I've tried accessing URLs of sites that have been provisioned
before, but they too do not load.
I've also ran vagrant up --debug
, and nothing concerning was seen.
My Vagrant
version is 2.2.19
Unsure what steps to take next?
Edit:
Steps taken:
- Have ran
vagrant up --provision
to provision sites inconfig.yml
file (config.yml
file can be seen below) - Have tried to access
website-dev.test
, page doesn't load - Have tried to access
vvv.test
, page doesn't load - Have ran
vagrant reload --provision
and repeated steps 2 and 3, but same results - Have ran
vagrant halt
andvagrant up
and repeated steps 2 and 3, but same results
I don't believe there's an issue in my config.yml
file, as before Monteray
update, everything was working fine (and I've made no changes to my yml
file since). But, to cover all scenario's, here is my config.yml
file:
1sites:
2
3 website-dev:
4 skip_provisioning: false
5 description: ""
6 hosts:
7 - website-dev.test
8 custom:
9 wpconfig_constants:
10 WP_DEBUG: true
11 WP_DEBUG_LOG: true
12 WP_DISABLE_FATAL_ERROR_HANDLER: true
13
14
15 wordpress-trunk:
16 skip_provisioning: true
17 description: "An svn based WP Core trunk dev setup, useful for contributor days, Trac tickets, patches"
18 repo: https://github.com/Varying-Vagrant-Vagrants/custom-site-template-develop.git
19 hosts:
20 - trunk.wordpress.test
21
22 wordpress-meta-environment:
23 skip_provisioning: true
24 description: "An environment useful for contributions to the WordPress meta team."
25 repo: https://github.com/WordPress/meta-environment.git
26 hosts:
27 - wp-meta.test
28 custom:
29 provision_site:
30 "buddypressorg.test": true
31 "jobs.wordpressnet.test": true
32 "wordcamp.test": true
33 "wordpressorg.test": true
34 "wordpresstv.test": true
35
36utilities:
37 core:
38 - tls-ca
39 - phpmyadmin
40
41vm_config:
42 memory: 1600
43 cores: 2
44
45general:
46 db_backup: true
47 db_restore: true
48 db_share_type: false
49
50
51vagrant-plugins:
52 disksize: 10GB
In regards to vagrant ssh
, I'm unsure on what steps I would need to take to get vvv.test
to start working again here, can't see anything on the docs for this also?
ANSWER
Answered 2021-Dec-15 at 18:33Thanks to guidance from @Tinxuanna, I've managed to solve the issue (finally!).
For anyone else having similar issues, here's what I did:
- Access the
/etc/hosts
folder - Find file called
hosts
and open it in a text editor. - Remove the IP addresses related to
vagrant
(I kept a backup of the original file just in case) - After saving
hosts
file the IP addresses removed, I ranvagrant up --provision
- I then ran
vagrant up
- Then accessed
vvv.test
- You're done!
QUESTION
How to get the image links from Gutenberg block gallery and add them as html data attributes to a button in wordpress
Asked 2021-Dec-22 at 04:36I'm using gutenberg gallery block inside a post and I'm trying to create a button which contains all of the image ids in the gallery block as html data attributes such that later when I output the content to the page I can have access to those ids using javascript
. Basically I'm trying to create a lightbox feature for a custom post type.
The problem is that I can't get access to the gutenberg gallery block data.
Here's my code
1while ($custom_post_type->have_posts()) {
2 $custom_post_type->the_post();
3 $gallery = get_post_gallery(get_the_id(), false);
4 $ids = explode(",", $gallery['ids']);
5}
6
And here's that button with html data attributes
1while ($custom_post_type->have_posts()) {
2 $custom_post_type->the_post();
3 $gallery = get_post_gallery(get_the_id(), false);
4 $ids = explode(",", $gallery['ids']);
5}
6<button class="gallery"
7<?php
8for ($i = 0; $i < count($ids); $i++) {
9 $img_link = wp_get_attachment_image_url($ids[$i], 'full');
10 echo "data-img-" . $i . " = " . $img_link . " ";
11}?>
12>
13Light-box
14</button>
15
But it does not work, $ids
is empty. It prints out this
1while ($custom_post_type->have_posts()) {
2 $custom_post_type->the_post();
3 $gallery = get_post_gallery(get_the_id(), false);
4 $ids = explode(",", $gallery['ids']);
5}
6<button class="gallery"
7<?php
8for ($i = 0; $i < count($ids); $i++) {
9 $img_link = wp_get_attachment_image_url($ids[$i], 'full');
10 echo "data-img-" . $i . " = " . $img_link . " ";
11}?>
12>
13Light-box
14</button>
15<button class="gallery">Light-box</button>
16
Thanks for your help!
EditI'm using wordpress blocks on the post page, I'm not quite certain how they have been generated, but they work out of the box.
ANSWER
Answered 2021-Dec-22 at 04:34"it does not work,
$ids
is empty."
That block is one of the default wordpress blocks, aka "core blocks". In order to have access to its data you would need to use parse_blocks
function not get_post_gallery
. That's why your variable is empty.
So the overall workflow to get what you're looking for would be:
- Check whether your post has any blocks or not, using
has_block
function.has_block
Docs - If it does, then get all of the blocks (including gallery block) using
parse_blocks
function.parse_blocks
Docs parse_blocks
will return an array of all blocks used in your post, so loop through them and see which one is called"core/gallery"
."core/gallery"
block has"attributes"
and"ids"
for each image you've added in the admin panel.- Once you get the
"ids"
, you should be able to create your custom button and image links usingwp_get_attachment_image_url
function.wp_get_attachment_image_url
Docs
As a POC:
Please see the following code:
1while ($custom_post_type->have_posts()) {
2 $custom_post_type->the_post();
3 $gallery = get_post_gallery(get_the_id(), false);
4 $ids = explode(",", $gallery['ids']);
5}
6<button class="gallery"
7<?php
8for ($i = 0; $i < count($ids); $i++) {
9 $img_link = wp_get_attachment_image_url($ids[$i], 'full');
10 echo "data-img-" . $i . " = " . $img_link . " ";
11}?>
12>
13Light-box
14</button>
15<button class="gallery">Light-box</button>
16if (has_block("gallery", get_the_content()))
17{
18 $post_blocks = parse_blocks(get_the_content());
19 foreach ($post_blocks as $post_block)
20 {
21 if ("core/gallery" == $post_block["blockName"])
22 {
23 $ids = $post_block["attrs"]["ids"];
24 }
25 }
26}
27
And this is the button:
1while ($custom_post_type->have_posts()) {
2 $custom_post_type->the_post();
3 $gallery = get_post_gallery(get_the_id(), false);
4 $ids = explode(",", $gallery['ids']);
5}
6<button class="gallery"
7<?php
8for ($i = 0; $i < count($ids); $i++) {
9 $img_link = wp_get_attachment_image_url($ids[$i], 'full');
10 echo "data-img-" . $i . " = " . $img_link . " ";
11}?>
12>
13Light-box
14</button>
15<button class="gallery">Light-box</button>
16if (has_block("gallery", get_the_content()))
17{
18 $post_blocks = parse_blocks(get_the_content());
19 foreach ($post_blocks as $post_block)
20 {
21 if ("core/gallery" == $post_block["blockName"])
22 {
23 $ids = $post_block["attrs"]["ids"];
24 }
25 }
26}
27<button class="gallery"
28<?php
29for ($i = 0; $i < count($ids); $i++) {
30 $img_link = wp_get_attachment_image_url($ids[$i], "full");
31 echo "data-img-" . $i . " = " . $img_link . " ";
32}
33?>
34>
35Light Box
36</button>
37
Which will return:
Note:
- I've used
get_the_content
function, assuming that you're in the loop based on the code you provided in your question. If you're not in the loop or you would need to use the code outside of the loop you could useglobal $post; $post->post_content;
instead.
This answer has been tested on wordpress 5.8
and works.
QUESTION
Using EXPORTHOW to make declarator that acts like "sub"
Asked 2021-Dec-13 at 23:18The excellent 2011 Advent of Raku post Meta-programming: what, why and how provides a few clear examples of using EXPORTHOW
to create a declarator that acts like class
. Here's the first:
1my class SingleInheritanceClassHOW
2 is Metamodel::ClassHOW
3{
4 method add_parent(Mu $obj, Mu $parent) {
5 if +self.parents($obj, :local) > 0 {
6 die "Multiple inheritance is forbidden!";
7 }
8 callsame;
9 }
10}
11my module EXPORTHOW { }
12EXPORTHOW.WHO.<class> = SingleInheritanceClassHOW;
13
Is there a way to do something similar for a declarator that acts like sub
(that is, that allows the use to supply a signature and block, rather than allowing the user to supply attributes and methods)? The metaclass of a Sub
is ClassHOW
, so it seems that something similar should be possible, but I'm not seeing a way to do so.
ANSWER
Answered 2021-Dec-13 at 23:18The EXPORTHOW
mechanism is only for overriding the metaclass that will be used for package declarators, with the slight extension that EXPORTHOW::DECLARE
also performs a grammar tweak that introduces a new package declarator.
While one can call .HOW
on a Sub
, the result does not relate to the subroutine itself, but rather the metaclass of the Sub
type, of which a subroutine is an instance.
Really, EXPORTHOW
is an "easy things easy" mechanism (to the degree it's fair to call anything relating to meta-programming easy!) It was also a straightforward thing to provide: the parsing of package declarations was already extremely regular, and the compiler already maintained a mapping table from package keyword to metaclass, so providing a way for a module to replace entries in that table (or add new ones for DECLARE
) was barely a few hours of compiler hackery.
Routines are vastly less regular, even if that's only somewhat apparent syntactically. While packages pretty much parse the keyword (class
, role
, grammar
, etc.) and what follows is the very same syntax and semantics for all of them (modulo roles permitting a signature), there are separate parse rules and semantics behind each of sub
, method
, macro
, and rule
. Their interaction with the overall compilation process is also rather more involved. The ongoing RakuAST effort is bringing a bit more order to that chaos, and ultimately - when coupled with slangs - will offer a way to introduce new sub
-like constructs, as well as to give them semantics.
QUESTION
jQuery: How to set max height of 3 'h3' element under a specific DIV to all h3 element?
Asked 2021-Nov-18 at 15:16The code snippet below is a part of a WordPress
page being developed. I need to set heights of all the 4 h3
elements to the highest of them using jQuery
. Could anyone please help me fix the jQuery
function below to do this?
1<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
2 $(document).ready(function() {
3 var highestBox = 0;
4 $('.fast-easy-order .color-tan-bright').each(function() {
5 if ($(this).height() > highestBox) {
6 highestBox = $(this).height();
7 }
8 });
9 $('.fast-easy-order h3').height(highestBox);
10 });
11</script>
12
13<div class="fast-easy-order">
14 <div class="relative flex-content-row flex-id-icon_columns">
15 <div class="icon-column-repeater mt-row">
16 <div class="wrap-x">
17 <div class="inside">
18 <div class="row center-xs">
19
20
21
22 <div class="col col-xs-12 col-sm-8 col-md col-lg">
23 <div class="icon relative mb">
24 <div class="object-contain-wrap">
25 <img src="https://dev-packed-with-purpose.pantheonsite.io/wp-content/uploads/2021/11/Address_Collection.png" alt="">
26 </div>
27 </div>
28 <h3 class="mb0 h3 color-tan-bright">DEDICATED GIFT CONCIERGE</h3>
29 <article class="mt">
30 <p>We connect you with a personal assistant to find the perfect gift for any occasion</p>
31 </article>
32 </div>
33
34
35 <div class="col col-xs-12 col-sm-8 col-md col-lg">
36 <div class="icon relative mb">
37 <div class="object-contain-wrap">
38 <img src="https://dev-packed-with-purpose.pantheonsite.io/wp-content/uploads/2021/11/Custom_Branding.png" alt="">
39 </div>
40 </div>
41 <h3 class="mb0 h3 color-tan-bright">CORPORATE BRANDING</h3>
42 <article class="mt">
43 <p>We’ll take care of the details by collecting all your recipients’ addresses for effortless delivery</p>
44 </article>
45 </div>
46
47
48 <div class="col col-xs-12 col-sm-8 col-md col-lg">
49 <div class="icon relative mb">
50 <div class="object-contain-wrap">
51 <img src="https://dev-packed-with-purpose.pantheonsite.io/wp-content/uploads/2021/11/Gift_Concierge.png" alt="">
52 </div>
53 </div>
54 <h3 class="mb0 h3 color-tan-bright">ADDRESS COLLECTION SERVICE </h3>
55 <article class="mt">
56 <p>We’ll take care of the details by collecting all your recipients’ addresses for effortless delivery</p>
57 </article>
58 </div>
59
60
61 <div class="col col-xs-12 col-sm-8 col-md col-lg">
62 <div class="icon relative mb">
63 <div class="object-contain-wrap">
64 <img src="https://dev-packed-with-purpose.pantheonsite.io/wp-content/uploads/2021/11/Order_Fulfillment.png" alt="">
65 </div>
66 </div>
67 <h3 class="mb0 h3 color-tan-bright">SEAMLESS ORDER FULFILLMENT</h3>
68 <article class="mt">
69 <p>Send gifts to a conference location or drop-ship to 5,000 recipients — we’ll handle it all for you</p>
70 </article>
71 </div>
72
73
74 </div>
75 </div>
76 </div>
77 </div>
78 </div>
79</div>
ANSWER
Answered 2021-Nov-17 at 17:07This could be achieved using CSS and flexbox styling if they are contained within the same container.
If flexbox isn't possible due to the layout, for example h3 tags in different containers and unable to apply flexbox styles, Id take a look at using:
QUESTION
Woocommerce admin_notices does not work when woocommerce_order_status_changed hook fires
Asked 2021-Nov-06 at 15:39I'm new to WordPress development and I'm currently encountering a dead-end.
I want an admin notice to be displayed in a WooCommerce order after the order's status has been changed.
With the following code, the notice doesn't appear:
1<?php
2
3class TestNotice {
4 public function testTheNotice() {
5 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
6 }
7
8 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
9 {
10 add_action('admin_notices', [$this, 'notice']);
11 }
12
13 public function notice()
14 {
15 ?>
16 <div class="notice notice-error is-dismissible">
17 <p>This notice appears on the order page.</p>
18 </div>
19 <?php
20 }
21
22}
23
24$testNotice = new TestNotice();
25$testNotice->testTheNotice();
26
I have tried setting the "priority" parameter of the "admin_notices" action to 20
, without success (I think it would have been useful if the nested action was the same as the one first called).
However, when I call "admin_notices" action directly in testTheNotice()
method (and thus not calling "woocommerce_order_status_changed" action), it works (on every admin page, which is not what I want).
I thought it was because the notice()
was somehow not recognised, but it actually is: the code below displays "This notice appears on the order page." on a blank page (which is not what I want and only for test purpose).
1<?php
2
3class TestNotice {
4 public function testTheNotice() {
5 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
6 }
7
8 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
9 {
10 add_action('admin_notices', [$this, 'notice']);
11 }
12
13 public function notice()
14 {
15 ?>
16 <div class="notice notice-error is-dismissible">
17 <p>This notice appears on the order page.</p>
18 </div>
19 <?php
20 }
21
22}
23
24$testNotice = new TestNotice();
25$testNotice->testTheNotice();
26<?php
27
28class TestNotice {
29 public function testTheNotice() {
30 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
31 }
32
33 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
34 {
35 call_user_func([$this, 'notice']); die();
36 }
37
38 public function notice()
39 {
40 ?>
41 <div class="notice notice-error is-dismissible">
42 <p>This notice appears on the order page.</p>
43 </div>
44 <?php
45 }
46
47}
48
49$testNotice = new TestNotice();
50$testNotice->testTheNotice();
51
I'm aware there's a special class and method for WooCommerce admin notices, and writing below code in notice()
displays a notice, but with a purple border (because of the "update" css class, which I haven't found how to change) instead of a red border (which would be possible thanks to the "error" css class, which I don't know how to apply).
1<?php
2
3class TestNotice {
4 public function testTheNotice() {
5 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
6 }
7
8 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
9 {
10 add_action('admin_notices', [$this, 'notice']);
11 }
12
13 public function notice()
14 {
15 ?>
16 <div class="notice notice-error is-dismissible">
17 <p>This notice appears on the order page.</p>
18 </div>
19 <?php
20 }
21
22}
23
24$testNotice = new TestNotice();
25$testNotice->testTheNotice();
26<?php
27
28class TestNotice {
29 public function testTheNotice() {
30 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
31 }
32
33 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
34 {
35 call_user_func([$this, 'notice']); die();
36 }
37
38 public function notice()
39 {
40 ?>
41 <div class="notice notice-error is-dismissible">
42 <p>This notice appears on the order page.</p>
43 </div>
44 <?php
45 }
46
47}
48
49$testNotice = new TestNotice();
50$testNotice->testTheNotice();
51$adminNotice = new WC_Admin_Notices();
52$adminNotice->add_custom_notice("Test",'<p>This notice appears on the order page.</p>');
53$adminNotice->output_custom_notices();
54
ANSWER
Answered 2021-Nov-06 at 15:39Good question. It got me curious and made me dig into this WC_Admin_Notices
class. And here's what I found out!
Well, before I talk about WC_Admin_Notices
class, first let's talk about your first question!
"the notice doesn't appear"
Because when the woocommerce_order_status_changed
hook fires there is no screen associated with it and it's not just notices, for example if you try to do a print_r
and/or an echo
they won't show anything either because there is no screen associated with that hook. The only way you could find out that you hit that hook is by using die
function. In order to test this, you could do this:
1<?php
2
3class TestNotice {
4 public function testTheNotice() {
5 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
6 }
7
8 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
9 {
10 add_action('admin_notices', [$this, 'notice']);
11 }
12
13 public function notice()
14 {
15 ?>
16 <div class="notice notice-error is-dismissible">
17 <p>This notice appears on the order page.</p>
18 </div>
19 <?php
20 }
21
22}
23
24$testNotice = new TestNotice();
25$testNotice->testTheNotice();
26<?php
27
28class TestNotice {
29 public function testTheNotice() {
30 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
31 }
32
33 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
34 {
35 call_user_func([$this, 'notice']); die();
36 }
37
38 public function notice()
39 {
40 ?>
41 <div class="notice notice-error is-dismissible">
42 <p>This notice appears on the order page.</p>
43 </div>
44 <?php
45 }
46
47}
48
49$testNotice = new TestNotice();
50$testNotice->testTheNotice();
51$adminNotice = new WC_Admin_Notices();
52$adminNotice->add_custom_notice("Test",'<p>This notice appears on the order page.</p>');
53$adminNotice->output_custom_notices();
54add_action('woocommerce_order_status_changed', 'test', 99, 4);
55
56function test($order_id, $old_status, $new_status, $order_object)
57{
58 die('You hit the right hook!');
59}
60
But if you replace the die('You hit the right hook!')
function with echo
or print_r
, they won't show anything no matter how high you set the priority of the hook.
It gets interesting when you use WC_Admin_Notices
class. If there is no screen associated with the woocommerce_order_status_changed
hook, then how does this class work? Well, here's how:
- It has a property called
$notices
which is a simple empty array. - When you call
add_custom_notice
method, it'll store the values you gave it, into the database and into the "options" table. The key would be "woocommerce_admin_notice_{the name you gave for example test}", and the value would be the message/notice you defined. That's all it does! It stores your message/notice into the database. - When you call
output_custom_notices
method, it'll check the$notices
array, and check the database for any key value pairs stored in the options table with the format I just mentioned in number 2! Then, it uses a template calledhtml-notice-custom.php
in the following path:
yourwebsite.com > wp-content > plugins > woocommerce > includes > admin > views > html-notice-custom.php
html-notice-custom.php
Template
The html-notice-custom.php
file is responsible for outputting the html markup for custom notices and it'll give them a class called updated
which will trigger a css rule that has a light purple color.
So the overall workflow of the
WC_Admin_Notices
class is:
- Stores your custom message into either an array or in the database
- Retrieves the stored key and value pairs when the screen loads!
Technically, that's all it does, well, in the simplest terms!
Since we don't want that custom light purple template, we could use the workflow that WC_Admin_Notices
uses and write our own solution without using WC_Admin_Notices
class.
We could use one of the following approaches:
- Use the combination of
$_SESSION
+admin_notices
hook - Use the combination of
cookie
orlocal storage
+admin_notices
hook - Use the combination of
database
+admin_notices
hook
I think, if we use $_SESSION
+ admin_notices
hook approach, it'd be both safe and fast without even query the database for a simple string of text. Here's the solution I can think of at this moment:
Code goes into the functions.php
file of your active theme.
1<?php
2
3class TestNotice {
4 public function testTheNotice() {
5 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
6 }
7
8 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
9 {
10 add_action('admin_notices', [$this, 'notice']);
11 }
12
13 public function notice()
14 {
15 ?>
16 <div class="notice notice-error is-dismissible">
17 <p>This notice appears on the order page.</p>
18 </div>
19 <?php
20 }
21
22}
23
24$testNotice = new TestNotice();
25$testNotice->testTheNotice();
26<?php
27
28class TestNotice {
29 public function testTheNotice() {
30 add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
31 }
32
33 public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
34 {
35 call_user_func([$this, 'notice']); die();
36 }
37
38 public function notice()
39 {
40 ?>
41 <div class="notice notice-error is-dismissible">
42 <p>This notice appears on the order page.</p>
43 </div>
44 <?php
45 }
46
47}
48
49$testNotice = new TestNotice();
50$testNotice->testTheNotice();
51$adminNotice = new WC_Admin_Notices();
52$adminNotice->add_custom_notice("Test",'<p>This notice appears on the order page.</p>');
53$adminNotice->output_custom_notices();
54add_action('woocommerce_order_status_changed', 'test', 99, 4);
55
56function test($order_id, $old_status, $new_status, $order_object)
57{
58 die('You hit the right hook!');
59}
60add_action('woocommerce_order_status_changed', 'test', 99, 4);
61
62function test($order_id, $old_status, $new_status, $order_object)
63{
64
65 if ( $order_object && ($old_status != $new_status) )
66 {
67
68 $notice = 'This notice appears on the order page.';
69
70 session_start();
71
72 $_SESSION['your_custom_message_name'] = $notice;
73
74 }
75}
76
77add_action('admin_notices', 'your_them_displaying_custom_admin_notice');
78
79function your_them_displaying_custom_admin_notice()
80{
81 session_start();
82 if (isset($_SESSION['your_custom_message_name'])) {
83
84?>
85 <div class='notice notice-error is-dismissible'>
86 <p><?php echo $_SESSION['your_custom_message_name'] ?></p>
87 </div>
88<?php
89 unset($_SESSION['your_custom_message_name']);
90 }
91}
92
Note:
- This works only if there is an order AND the
$old_status
is not equal to the$new_status
. - In the
$notice
variable, I put raw text, not html, since we put ap
tag in the html section/template of theadmin_notices
hook. - I've used
notice-error
class for thediv
tag which shows thered color
for the notice. You could replace it withnotice-warning
, ornotice-info
ornotice-success
.
This answers has been fully tested on woocommerce 5.7
and works fine.
QUESTION
Wordpress site hacked -- redirects to another site
Asked 2021-Sep-26 at 22:34My Wordpress site has been hacked. Links on the site have been changed to take users to the hacker's site at storage.piterreceiver.ga. This site, in turn, redirects to other sites which my browser flags as dangerous.
Has anyone else had this happen? How can a restore my site and prevent a reoccurrence?
ANSWER
Answered 2021-Sep-23 at 16:14I recommend to rewrite affected files by the files from clean/original Wordpress (be sure you using the same version of the WP)
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Wordpress
Tutorials and Learning Resources are not available at this moment for Wordpress