最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Programmatically emulate viewing a post in wp-admin

programmeradmin3浏览0评论

A process is triggered when I view a post at /wp-admin . I don't know what is happening during that process. I want to trigger it for all posts in a list of post ids. How can I programmatically start all processes that start when a post is viewed in the wp-admin page?

Something like

view_post_in_wp_admin( 123 );

where 123 is the post id.

A process is triggered when I view a post at https://my.wordpress.page/wp-admin . I don't know what is happening during that process. I want to trigger it for all posts in a list of post ids. How can I programmatically start all processes that start when a post is viewed in the wp-admin page?

Something like

view_post_in_wp_admin( 123 );

where 123 is the post id.

Share Improve this question asked Jan 26, 2022 at 18:23 Osvald LauritsOsvald Laurits 1337 bronze badges 4
  • 1 can you explain this using different words? Do you mean when you edit a post? Or are you referring to specific dashboard screens? What processes are you referring to? What problem are you trying to solve by doing this? Viewing a post involves visiting the frontend, so I think something has been lost in translation – Tom J Nowell Commented Jan 26, 2022 at 18:39
  • Yes, the process triggers when I edit a post. I.E. when visiting my.wordpress.page/wp-admin/post.php?post=53728&action=edit . It is started when I view the edit page. The problem I am trying to solve is generating .png files that contain qr codes. The URL of the qr code is in get_post_meta( $post_id )['wpqr_url'][0]. E.G. my.wordpress.page/wp-content/uploads/wpqr-codes/…. But the file that the ['wpqr_url'] field points to does not exist for all posts. I'm looking for a way to generate the file other than visiting the edit page in browser. – Osvald Laurits Commented Jan 27, 2022 at 11:28
  • The plugin wpfavs.com/plugins/wp-qr-code-auto-generator is in use. But I don't find the function that actually creates the .png file. – Osvald Laurits Commented Jan 27, 2022 at 11:52
  • 1 I see, you will need to contact their support routes, 3rd party plugin dev/user support is off-topic here and not in this stacks scope. – Tom J Nowell Commented Jan 28, 2022 at 2:09
Add a comment  | 

1 Answer 1

Reset to default 0

I ended up using curl to login to the wp-admin page and sent a request to each post that misses the qr code.

<?php

$curl = curl_init();

//---------------- generic cURL settings start ----------------
$header     = array(
      "Referer: https://my.wordpress.com/wp-login.php",
"Origin: https://my.wordpress.com",
"Content-Type: application/x-www-form-urlencoded",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"
      );


curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookies.txt');
//---------------- generic cURL settings end ----------------



$url = 'https://my.wordpress.com/wp-admin';
curl_setopt($curl, CURLOPT_URL, $url);

$post = 'log=user&pwd=my-safe-password&wp-submit=Log+In&redirect_to=https%3A%2F%2Fmy.wordpress.com%2Fwp-admin';
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);

$output = curl_exec($curl);

$url = 'https://my.wordpress.com/wp-admin/post.php?post=123&action=edit';
curl_setopt($curl, CURLOPT_URL, $url);
$output = curl_exec($curl);


curl_close ($curl);

echo ($output);
发布评论

评论列表(0)

  1. 暂无评论