status.php 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. <?php
  2. defined('ABSPATH') || exit;
  3. @include_once NEWSLETTER_INCLUDES_DIR . '/controls.php';
  4. $module = Newsletter::instance();
  5. $controls = new NewsletterControls();
  6. /* @var $wpdb wpdb */
  7. $wp_cron_calls = get_option('newsletter_diagnostic_cron_calls', array());
  8. $total = 0;
  9. $wp_cron_calls_max = 0;
  10. $wp_cron_calls_min = 0;
  11. $wp_cron_calls_avg = 0;
  12. if (count($wp_cron_calls) > 20) {
  13. for ($i = 1; $i < count($wp_cron_calls); $i++) {
  14. $diff = $wp_cron_calls[$i] - $wp_cron_calls[$i - 1];
  15. $total += $diff;
  16. if ($wp_cron_calls_min == 0 || $wp_cron_calls_min > $diff) {
  17. $wp_cron_calls_min = $diff;
  18. }
  19. if ($wp_cron_calls_max < $diff) {
  20. $wp_cron_calls_max = $diff;
  21. }
  22. }
  23. $wp_cron_calls_avg = (int) ($total / (count($wp_cron_calls) - 1));
  24. }
  25. if ($controls->is_action('delete_logs')) {
  26. $files = glob(WP_CONTENT_DIR . '/logs/newsletter/*.txt');
  27. foreach ($files as $file) {
  28. if (is_file($file))
  29. unlink($file);
  30. }
  31. $secret = NewsletterModule::get_token(8);
  32. update_option('newsletter_logger_secret', $secret);
  33. $controls->messages = 'Logs deleted';
  34. }
  35. if ($controls->is_action('reschedule')) {
  36. wp_clear_scheduled_hook('newsletter');
  37. wp_schedule_event(time() + 30, 'newsletter', 'newsletter');
  38. $controls->add_message_done();
  39. }
  40. if ($controls->is_action('trigger')) {
  41. Newsletter::instance()->hook_newsletter();
  42. $controls->messages = 'Triggered';
  43. }
  44. if ($controls->is_action('conversion')) {
  45. $this->logger->info('Maybe convert to utf8mb4');
  46. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  47. if (function_exists('maybe_convert_table_to_utf8mb4')) {
  48. maybe_convert_table_to_utf8mb4(NEWSLETTER_EMAILS_TABLE);
  49. maybe_convert_table_to_utf8mb4(NEWSLETTER_USERS_TABLE);
  50. $controls->messages = 'Done.';
  51. } else {
  52. $controls->errors = 'Table conversion function not available';
  53. }
  54. Newsletter::instance()->hook_newsletter();
  55. $controls->messages = 'Triggered';
  56. }
  57. if ($controls->is_action('test')) {
  58. if (!NewsletterModule::is_email($controls->data['test_email'])) {
  59. $controls->errors = 'The test email address is not set or is not correct.';
  60. }
  61. if (empty($controls->errors)) {
  62. $options = $controls->data;
  63. if ($controls->data['test_email'] == $module->options['sender_email']) {
  64. $controls->messages .= '<strong>Warning:</strong> you are using as test email the same address configured as sender in main configuration. Test can fail because of that.<br>';
  65. }
  66. $message = new TNP_Mailer_Message();
  67. $message->body = '<p>This is an <b>HTML</b> test email sent using the sender data set on Newsletter main setting. <a href="https://www.thenewsletterplugin.com">This is a link to an external site</a>.</p>';
  68. $message->body_text = 'This is a textual test email part sent using the sender data set on Newsletter main setting.';
  69. $message->to = $controls->data['test_email'];
  70. $message->subject = 'Newsletter test email at ' . date(DATE_ISO8601);
  71. $message->from = $module->options['sender_email'];
  72. $message->from_name = $module->options['sender_name'];
  73. $r = $module->deliver($message);
  74. if (!is_wp_error($r)) {
  75. $options['mail'] = 1;
  76. $controls->messages .= '<strong>SUCCESS</strong><br>';
  77. } else {
  78. $options['mail'] = 0;
  79. $options['mail_error'] = $r->get_error_message();
  80. $controls->errors .= '<strong>FAILED</strong> (' . $r->get_error_message() . ')<br>';
  81. if (!empty($module->options['return_path'])) {
  82. $controls->errors .= '- Try to remove the return path on main settings.<br>';
  83. }
  84. $controls->errors .= '<a href="https://www.thenewsletterplugin.com/documentation/email-sending-issues" target="_blank"><strong>' . __('Read more', 'newsletter') . '</strong></a>.';
  85. $parts = explode('@', $module->options['sender_email']);
  86. $sitename = strtolower($_SERVER['SERVER_NAME']);
  87. if (substr($sitename, 0, 4) == 'www.') {
  88. $sitename = substr($sitename, 4);
  89. }
  90. if (strtolower($sitename) != strtolower($parts[1])) {
  91. $controls->errors .= '- Try to set on main setting a sender address with the same domain of your blog: ' . $sitename . ' (you are using ' . $module->options['sender_email'] . ')<br>';
  92. }
  93. }
  94. $module->save_options($options, 'status');
  95. }
  96. }
  97. $options = $module->get_options('status');
  98. // Compute the number of newsletters ongoing and other stats
  99. $emails = $wpdb->get_results("select * from " . NEWSLETTER_EMAILS_TABLE . " where status='sending' and send_on<" . time() . " order by id asc");
  100. $total = 0;
  101. $queued = 0;
  102. foreach ($emails as $email) {
  103. $total += $email->total;
  104. $queued += $email->total - $email->sent;
  105. }
  106. $speed = Newsletter::$instance->options['scheduler_max'];
  107. ?>
  108. <div class="wrap tnp-main-status" id="tnp-wrap">
  109. <?php include NEWSLETTER_DIR . '/tnp-header.php'; ?>
  110. <div id="tnp-heading">
  111. <h2><?php _e('System Status', 'newsletter') ?></h2>
  112. </div>
  113. <div id="tnp-body">
  114. <form method="post" action="">
  115. <?php $controls->init(); ?>
  116. <h3>General checks</h3>
  117. <table class="widefat" id="tnp-status-table">
  118. <thead>
  119. <tr>
  120. <th>Parameter</th>
  121. <th><?php _e('Status', 'newsletter') ?></th>
  122. <th>Action</th>
  123. </tr>
  124. </thead>
  125. <tbody>
  126. <?php
  127. $method = '';
  128. if (function_exists('get_filesystem_method')) {
  129. $method = get_filesystem_method(array(), WP_PLUGIN_DIR);
  130. }
  131. ?>
  132. <tr>
  133. <td>Add-ons installable</td>
  134. <td>
  135. <?php if (empty($method)) { ?>
  136. <span class="tnp-maybe">MAYBE</span>
  137. <?php } else if ($method == 'direct') { ?>
  138. <span class="tnp-ok">OK</span>
  139. <?php } else { ?>
  140. <span class="tnp-ko">KO</span>
  141. <?php } ?>
  142. </td>
  143. <td>
  144. <?php if (empty($method)) { ?>
  145. No able to check, just try the add-ons manager one click install
  146. <?php } else if ($method == 'direct') { ?>
  147. The add-ons manager can install our add-ons
  148. <?php } else { ?>
  149. The plugins dir could be read-only, you can install add-ons uploading the package from the
  150. plugins panel (or uploading them directly via FTP). This is unusual you should ask te provider
  151. about file and folder permissions.
  152. <?php } ?>
  153. </td>
  154. </tr>
  155. <tr>
  156. <td>Delivering</td>
  157. <td>
  158. &nbsp;
  159. </td>
  160. <td>
  161. <?php if (count($emails)) { ?>
  162. Delivering <?php echo count($emails) ?> newsletters to about <?php echo $queued ?> recipients.
  163. At speed of <?php echo $speed ?> emails per hour it will take <?php printf('%.1f', $queued / $speed) ?> hours to finish.
  164. <?php } else { ?>
  165. Nothing delivering right now
  166. <?php } ?>
  167. </td>
  168. </tr>
  169. <tr>
  170. <td>Mailer</td>
  171. <td>
  172. &nbsp;
  173. </td>
  174. <td>
  175. <?php
  176. $mailer = Newsletter::instance()->get_mailer();
  177. $name = 'Unknown';
  178. if (is_object($mailer)) {
  179. if (method_exists($mailer, 'get_description')) {
  180. $name = $mailer->get_description();
  181. } else {
  182. $name = get_class($mailer);
  183. }
  184. }
  185. ?>
  186. <?php echo esc_html($name) ?>
  187. </td>
  188. </tr>
  189. <tr>
  190. <td>Mailing</td>
  191. <td>
  192. <?php if (empty($options['mail'])) { ?>
  193. <span class="tnp-ko">KO</span>
  194. <?php } else { ?>
  195. <span class="tnp-ok">OK</span>
  196. <?php } ?>
  197. </td>
  198. <td>
  199. <?php if (empty($options['mail'])) { ?>
  200. <?php if (empty($options['mail_error'])) { ?>
  201. A test has never run.
  202. <?php } else { ?>
  203. Last test failed with error "<?php echo esc_html($options['mail_error']) ?>".
  204. <?php } ?>
  205. <?php } else { ?>
  206. Last test was successful. If you didn't receive the test email:
  207. <ol>
  208. <li>If you set the Newsletter SMTP, do a test from that panel</li>
  209. <li>If you're using a integration extension do a test from its configuration panel</li>
  210. <li>If previous points do not apply to you, ask for support to your provider reporting the emails from your blog are not delivered</li>
  211. </ol>
  212. <?php } ?>
  213. <br>
  214. <a href="https://www.thenewsletterplugin.com/documentation/email-sending-issues" target="_blank">Read more to solve your issues, if any</a>.
  215. <br>
  216. Email: <?php $controls->text_email('test_email') ?> <?php $controls->button('test', __('Send a test message')) ?>
  217. </td>
  218. </tr>
  219. <?php if (ini_get('opcache.validate_timestamps') === '0') { ?>
  220. <tr>
  221. <td>
  222. Opcache
  223. </td>
  224. <td>
  225. <span class="tnp-ko">KO</span>
  226. </td>
  227. <td>
  228. You have the PHP opcache active with file validation disable so every blog plugins update needs a webserver restart!
  229. </td>
  230. </tr>
  231. <?php } ?>
  232. <?php
  233. $return_path = $module->options['return_path'];
  234. if (!empty($return_path)) {
  235. list($return_path_local, $return_path_domain) = explode('@', $return_path);
  236. }
  237. $sender = $module->options['sender_email'];
  238. if (!empty($sender)) {
  239. list($sender_local, $sender_domain) = explode('@', $sender);
  240. }
  241. ?>
  242. <tr>
  243. <td>Return path</td>
  244. <td>
  245. <?php if (empty($return_path)) { ?>
  246. <span class="tnp-ok">OK</span>
  247. <?php } else { ?>
  248. <?php if ($sender_domain != $return_path_domain) { ?>
  249. <span class="tnp-maybe">MAYBE</span>
  250. <?php } else { ?>
  251. <span class="tnp-ok">OK</span>
  252. <?php } ?>
  253. <?php } ?>
  254. </td>
  255. <td>
  256. <?php if (!empty($return_path)) { ?>
  257. Some providers require the return path domain <code><?php echo esc_html($return_path_domain) ?></code> to be identical
  258. to the sender domain <code><?php echo esc_html($sender_domain) ?></code>. See the main settings.
  259. <?php } else { ?>
  260. <?php } ?>
  261. </td>
  262. </tr>
  263. <tr>
  264. <td>Blog Charset</td>
  265. <td>
  266. <?php if (get_option('blog_charset') == 'UTF-8') { ?>
  267. <span class="tnp-ok">OK</span>
  268. <?php } else { ?>
  269. <span class="tnp-ko">KO</span>
  270. <?php } ?>
  271. </td>
  272. <td>
  273. Charset: <?php echo esc_html(get_option('blog_charset')) ?>
  274. <br>
  275. <?php if (get_option('blog_charset') == 'UTF-8') { ?>
  276. <?php } else { ?>
  277. Your blog charset is <?php echo esc_html(get_option('blog_charset')) ?> but it is recommended to use
  278. the <code>UTF-8</code> charset but the <a href="https://codex.wordpress.org/Converting_Database_Character_Sets" target="_blank">conversion</a>
  279. could be tricky. If you're not experiencing problem, leave things as is.
  280. <?php } ?>
  281. </td>
  282. </tr>
  283. <tr>
  284. <td>PHP version</td>
  285. <td>
  286. <?php if (version_compare(phpversion(), '5.3', '<')) { ?>
  287. <span class="tnp-ko">KO</span>
  288. <?php } else { ?>
  289. <span class="tnp-ok">OK</span>
  290. <?php } ?>
  291. </td>
  292. <td>
  293. Your PHP version is <?php echo phpversion() ?><br>
  294. <?php if (version_compare(phpversion(), '5.3', '<')) { ?>
  295. Newsletter plugin works correctly with PHP version 5.3 or greater. Ask your provider to upgrade your PHP. Your version is
  296. unsupported even by the PHP community.
  297. <?php } ?>
  298. </td>
  299. </tr>
  300. <tr>
  301. <td>Curl version</td>
  302. <td>
  303. <?php if (!function_exists('curl_version')) { ?>
  304. <span class="tnp-ko">KO</span>
  305. <?php } else { ?>
  306. <span class="tnp-ok">OK</span>
  307. <?php } ?>
  308. </td>
  309. <td>
  310. <?php if (!function_exists('curl_version')) { ?>
  311. cUrl is not available, ask the provider to install it and activate the PHP cUrl library
  312. <?php
  313. } else {
  314. $version = curl_version();
  315. echo 'Version: ' . $version['version'] . '<br>';
  316. echo 'SSL Version: ' . $version['ssl_version'] . '<br>';
  317. }
  318. ?>
  319. </td>
  320. </tr>
  321. <?php
  322. $value = (int) ini_get('max_execution_time');
  323. $res = true;
  324. if ($value != 0 && $value < NEWSLETTER_CRON_INTERVAL) {
  325. $res = set_time_limit(NEWSLETTER_CRON_INTERVAL);
  326. }
  327. ?>
  328. <tr>
  329. <td>Addons update</td>
  330. <td>
  331. <?php if (NEWSLETTER_EXTENSION_UPDATE) { ?>
  332. <span class="tnp-ok">OK</span>
  333. <?php } else { ?>
  334. <span class="tnp-maybe">MAYBE</span>
  335. <?php } ?>
  336. </td>
  337. <td>
  338. <?php if (!NEWSLETTER_EXTENSION_UPDATE) { ?>
  339. Newsletter Addons update is disabled (probably in your <code>wp-config.php</code> file)
  340. <?php } else { ?>
  341. Newsletter Addons can be updated
  342. <?php } ?>
  343. </td>
  344. </tr>
  345. <?php
  346. $value = (int) ini_get('max_execution_time');
  347. $res = true;
  348. if ($value != 0 && $value < NEWSLETTER_CRON_INTERVAL) {
  349. $res = set_time_limit(NEWSLETTER_CRON_INTERVAL);
  350. }
  351. ?>
  352. <tr>
  353. <td>PHP execution time limit</td>
  354. <td>
  355. <?php if ($res) { ?>
  356. <span class="tnp-ok">OK</span>
  357. <?php } else { ?>
  358. <span class="tnp-ko">KO</span>
  359. <?php } ?>
  360. </td>
  361. <td>
  362. <?php if (!$res) { ?>
  363. Your PHP execution time limit is <?php echo $value ?> seconds and cannot be changed or
  364. is too lower to grant the maximum delivery rate of Newsletter.
  365. <?php } else { ?>
  366. Your PHP execution time limit is <?php echo $value ?> seconds and can be eventually changed by Newsletter<br>
  367. <?php } ?>
  368. </td>
  369. </tr>
  370. <tr>
  371. <td>Home URL</td>
  372. <td>
  373. <?php if (strpos(home_url('/'), 'http') !== 0) { ?>
  374. <span class="tnp-ko">KO</span>
  375. <?php } else { ?>
  376. <span class="tnp-ok">OK</span>
  377. <?php } ?>
  378. </td>
  379. <td>
  380. Value: <?php echo home_url('/'); ?>
  381. <br>
  382. <?php if (strpos(home_url('/'), 'http') !== 0) { ?>
  383. Your home URL is not absolute, emails require absolute URLs.
  384. Probably you have a protocol agnostic plugin installed to manage both HTTPS and HTTP in your
  385. blog.
  386. <?php } else { ?>
  387. <?php } ?>
  388. </td>
  389. </tr>
  390. <tr>
  391. <td>WP_CONTENT_URL</td>
  392. <td>
  393. <?php if (strpos(WP_CONTENT_URL, 'http') !== 0) { ?>
  394. <span class="tnp-ko">KO</span>
  395. <?php } else { ?>
  396. <span class="tnp-ok">OK</span>
  397. <?php } ?>
  398. </td>
  399. <td>
  400. Value: <?php echo WP_CONTENT_URL; ?>
  401. <br>
  402. <?php if (strpos(WP_CONTENT_URL, 'http') !== 0) { ?>
  403. Your content URL is not absolute, emails require absolute URLs when they have images inside.
  404. Newsletter tries to deal with this problem but when a problem with images persists, you should try to remove
  405. from your wp-config.php the WP_CONTENT_URL define and check again.
  406. <?php } else { ?>
  407. <?php } ?>
  408. </td>
  409. </tr>
  410. <tr>
  411. <td>Database Charset</td>
  412. <td>
  413. <?php if ($wpdb->charset != 'utf8mb4') { ?>
  414. <span class="tnp-ko">KO</span>
  415. <?php } else { ?>
  416. <span class="tnp-ok">OK</span>
  417. <?php } ?>
  418. </td>
  419. <td>
  420. Charset: <?php echo $wpdb->charset; ?>
  421. <br>
  422. <?php if ($wpdb->charset != 'utf8mb4') { ?>
  423. The recommended charset for your database is <code>utf8mb4</code> to avoid possible saving errors when you use emoji.
  424. Read the WordPress Codex <a href="https://codex.wordpress.org/Converting_Database_Character_Sets" target="_blank">conversion
  425. instructions</a> (skilled technicia required).
  426. <?php } else { ?>
  427. If you experience newsletter saving database error
  428. <?php $controls->button('conversion', 'Try tables upgrade')?>
  429. <?php } ?>
  430. </td>
  431. </tr>
  432. <?php $wait_timeout = $wpdb->get_var("select @@wait_timeout"); ?>
  433. <tr>
  434. <td>Database wait timeout</td>
  435. <td>
  436. <?php if ($wait_timeout < 30) { ?>
  437. <span class="tnp-ko">KO</span>
  438. <?php } else { ?>
  439. <span class="tnp-ok">OK</span>
  440. <?php } ?>
  441. </td>
  442. <td>
  443. Your database wait timeout is <?php echo $wait_timeout; ?> seconds<br>
  444. <?php if ($wait_timeout < 30) { ?>
  445. That value is low and could produce database connection errors while sending emails or during long import
  446. sessions. Ask the provider to raise it at least to 60 seconds.
  447. <?php } ?>
  448. </td>
  449. </tr>
  450. <?php
  451. $res = $wpdb->query("drop table if exists {$wpdb->prefix}newsletter_test");
  452. $res = $wpdb->query("create table if not exists {$wpdb->prefix}newsletter_test (id int(20))");
  453. ?>
  454. <tr>
  455. <td>Database table creation</td>
  456. <td>
  457. <?php if ($res === false) { ?>
  458. <span class="tnp-ko">KO</span>
  459. <?php } else { ?>
  460. <span class="tnp-ok">OK</span>
  461. <?php } ?>
  462. </td>
  463. <td>
  464. <?php if ($res === false) { ?>
  465. Check the privileges of the user you use to connect to the database, it seems it cannot create tables.<br>
  466. (<?php echo esc_html($wpdb->last_error) ?>)
  467. <?php } else { ?>
  468. <?php } ?>
  469. </td>
  470. </tr>
  471. <?php
  472. $res = $wpdb->query("alter table {$wpdb->prefix}newsletter_test add column id1 int(20)");
  473. ?>
  474. <tr>
  475. <td>Database table change</td>
  476. <td>
  477. <?php if ($res === false) { ?>
  478. <span class="tnp-ko">KO</span>
  479. <?php } else { ?>
  480. <span class="tnp-ok">OK</span>
  481. <?php } ?>
  482. </td>
  483. <td>
  484. <?php if ($res === false) { ?>
  485. Check the privileges of the user you use to connect to the database, it seems it cannot change the tables. It's require to update the
  486. plugin.<br>
  487. (<?php echo esc_html($wpdb->last_error) ?>)
  488. <?php } else { ?>
  489. <?php } ?>
  490. </td>
  491. </tr>
  492. <?php
  493. // Clean up
  494. $res = $wpdb->query("drop table if exists {$wpdb->prefix}newsletter_test");
  495. ?>
  496. <?php
  497. set_transient('newsletter_transient_test', 1, 300);
  498. delete_transient('newsletter_transient_test');
  499. $res = get_transient('newsletter_transient_test');
  500. ?>
  501. <tr>
  502. <td>WordPress transients</td>
  503. <td>
  504. <?php if ($res !== false) { ?>
  505. <span class="tnp-ko">KO</span>
  506. <?php } else { ?>
  507. <span class="tnp-ok">OK</span>
  508. <?php } ?>
  509. </td>
  510. <td>
  511. <?php if ($res !== false) { ?>
  512. Transients cannot be delete. This can block the delivery engine. Usually it is due to a not well coded plugin installed.
  513. <?php } else { ?>
  514. <?php } ?>
  515. </td>
  516. </tr>
  517. <?php
  518. $time = wp_next_scheduled('newsletter');
  519. $res = true;
  520. if ($time === false) {
  521. $res = false;
  522. }
  523. $delta = $time - time();
  524. if ($delta <= -600) {
  525. $res = false;
  526. }
  527. ?>
  528. <tr>
  529. <td>Newsletter schedule timing</td>
  530. <td>
  531. <?php if ($res === false) { ?>
  532. <span class="tnp-ko">KO</span>
  533. <?php } else { ?>
  534. <span class="tnp-ok">OK</span>
  535. <?php } ?>
  536. </td>
  537. <td>
  538. <?php if ($time === false) { ?>
  539. No next execution is planned.
  540. <?php $controls->button('reschedule', 'Reset') ?>
  541. <?php } else if ($delta <= -600) { ?>
  542. The scheduler is very late: <?php echo $delta ?> seconds (<a href="https://www.thenewsletterplugin.com/plugins/newsletter/newsletter-delivery-engine" target="_blank">read more</a>)
  543. <?php $controls->button('trigger', 'Trigger') ?>
  544. <?php } else { ?>
  545. Next execution is planned in <?php echo $delta ?> seconds (negative values are ok).
  546. <?php } ?>
  547. </td>
  548. </tr>
  549. <?php
  550. $schedules = wp_get_schedules();
  551. $res = false;
  552. if (!empty($schedules)) {
  553. foreach ($schedules as $key => $data) {
  554. if ($key == 'newsletter') {
  555. $res = true;
  556. break;
  557. }
  558. }
  559. }
  560. ?>
  561. <tr>
  562. <td>
  563. Newsletter schedule
  564. </td>
  565. <td>
  566. <?php if ($res === false) { ?>
  567. <span class="tnp-ko">KO</span>
  568. <?php } else { ?>
  569. <span class="tnp-ok">OK</span>
  570. <?php } ?>
  571. </td>
  572. <td>
  573. <?php if ($res === false) { ?>
  574. The Newsletter schedule is not present probably another plugin is interfering with the starndard WordPress schuling system.<br>
  575. <?php } else { ?>
  576. <?php } ?>
  577. WordPress registered schedules:<br>
  578. <?php
  579. if (!empty($schedules)) {
  580. foreach ($schedules as $key => $data) {
  581. echo esc_html($key . ' - ' . $data['interval']) . ' seconds<br>';
  582. }
  583. }
  584. ?>
  585. </td>
  586. </tr>
  587. <tr>
  588. <td>
  589. WordPress scheduler auto trigger
  590. </td>
  591. <td>
  592. <?php if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) { ?>
  593. <span class="tnp-maybe">MAYBE</span>
  594. <?php } else { ?>
  595. <span class="tnp-ok">OK</span>
  596. <?php } ?>
  597. </td>
  598. <td>
  599. <?php if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) { ?>
  600. The constant DISABLE_WP_CRON is set to true (probably in wp-config.php). That disables the scheduler auto triggering and it's
  601. good ONLY if you setup an external trigger.
  602. <?php } else { ?>
  603. <?php } ?>
  604. </td>
  605. </tr>
  606. <tr>
  607. <td>
  608. Alternate cron
  609. </td>
  610. <td>
  611. &nbsp;
  612. </td>
  613. <td>
  614. <?php if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) { ?>
  615. Using the alternate cron trigger.
  616. <?php } else { ?>
  617. <?php } ?>
  618. </td>
  619. </tr>
  620. <tr>
  621. <td>
  622. Cron calls
  623. </td>
  624. <td>
  625. <?php if ($wp_cron_calls_avg > NEWSLETTER_CRON_INTERVAL * 1.1) { ?>
  626. <span class="tnp-ko">KO</span>
  627. <?php } else { ?>
  628. <span class="tnp-ok">OK</span>
  629. <?php } ?>
  630. </td>
  631. <td>
  632. <?php if ($wp_cron_calls_avg > NEWSLETTER_CRON_INTERVAL * 1.1) { ?>
  633. The blog cron system is NOT triggered enough often.
  634. <?php } else { ?>
  635. <?php } ?>
  636. <br>
  637. Trigger interval: average <?php echo $wp_cron_calls_avg ?>&nbsp;s, max <?php echo $wp_cron_calls_max ?>&nbsp;s, min <?php echo $wp_cron_calls_min ?>&nbsp;s
  638. </td>
  639. </tr>
  640. <?php
  641. $res = true;
  642. $response = wp_remote_post(home_url('/') . '?na=test');
  643. if (is_wp_error($response)) {
  644. $res = false;
  645. $message = $response->get_error_message();
  646. } else {
  647. if (wp_remote_retrieve_response_code($response) != 200) {
  648. $res = false;
  649. $message = wp_remote_retrieve_response_message($response);
  650. }
  651. }
  652. ?>
  653. <tr>
  654. <td>
  655. Action call
  656. </td>
  657. <td>
  658. <?php if (!$res) { ?>
  659. <span class="tnp-ko">KO</span>
  660. <?php } else { ?>
  661. <span class="tnp-ok">OK</span>
  662. <?php } ?>
  663. </td>
  664. <td>
  665. <?php if (!$res) { ?>
  666. The blog is not responding to Newsletter URLs: ask the provider or your IT consultant to check this problem. Report the URL and error below<br>
  667. Error: <?php echo esc_html($message) ?><br>
  668. <?php } else { ?>
  669. <?php } ?>
  670. Url: <?php echo esc_html(home_url('/') . '?na=test') ?><br>
  671. </td>
  672. </tr>
  673. <?php
  674. $res = true;
  675. $response = wp_remote_get(site_url('/wp-cron.php') . '?' . time());
  676. if (is_wp_error($response)) {
  677. $res = false;
  678. $message = $response->get_error_message();
  679. } else {
  680. if (wp_remote_retrieve_response_code($response) != 200) {
  681. $res = false;
  682. $message = wp_remote_retrieve_response_message($response);
  683. }
  684. }
  685. ?>
  686. <tr>
  687. <td>
  688. WordPress scheduler auto trigger call
  689. </td>
  690. <td>
  691. <?php if (!$res) { ?>
  692. <span class="tnp-ko">KO</span>
  693. <?php } else { ?>
  694. <span class="tnp-ok">OK</span>
  695. <?php } ?>
  696. </td>
  697. <td>
  698. <?php if (!$res) { ?>
  699. The blog cannot autotrigger the internal scheduler, if an external trigger is used this could not be a real problem.<br>
  700. Error: <?php echo esc_html($message) ?><br>
  701. <?php } else { ?>
  702. <?php } ?>
  703. Url: <?php echo esc_html(site_url('/wp-cron.php')) ?><br>
  704. </td>
  705. </tr>
  706. <?php
  707. $res = true;
  708. $response = wp_remote_get('http://www.thenewsletterplugin.com/wp-content/versions/all.txt');
  709. if (is_wp_error($response)) {
  710. $res = false;
  711. $message = $response->get_error_message();
  712. } else {
  713. if (wp_remote_retrieve_response_code($response) != 200) {
  714. $res = false;
  715. $message = wp_remote_retrieve_response_message($response);
  716. }
  717. }
  718. ?>
  719. <tr>
  720. <td>
  721. Extension version check
  722. </td>
  723. <td>
  724. <?php if (!$res) { ?>
  725. <span class="tnp-ko">KO</span>
  726. <?php } else { ?>
  727. <span class="tnp-ok">OK</span>
  728. <?php } ?>
  729. </td>
  730. <td>
  731. <?php if (!$res) { ?>
  732. The blog cannot contact www.thenewsletterplugin.com to check the license or the extension versions.<br>
  733. Error: <?php echo esc_html($message) ?><br>
  734. <?php } else { ?>
  735. <?php } ?>
  736. </td>
  737. </tr>
  738. <tr>
  739. <td>
  740. Addons update
  741. </td>
  742. <td>
  743. <?php if (NEWSLETTER_EXTENSION_UPDATE) { ?>
  744. <span class="tnp-ok">OK</span>
  745. <?php } else { ?>
  746. <span class="tnp-ko">KO</span>
  747. <?php } ?>
  748. </td>
  749. <td>
  750. <?php if (!NEWSLETTER_EXTENSION_UPDATE) { ?>
  751. Addons update has been disabled.
  752. <?php } else { ?>
  753. <?php } ?>
  754. </td>
  755. </tr>
  756. <?php
  757. // Send calls stats
  758. $send_calls = get_option('newsletter_diagnostic_send_calls', array());
  759. if (count($send_calls)) {
  760. $send_max = 0;
  761. $send_min = PHP_INT_MAX;
  762. $send_total_time = 0;
  763. $send_total_emails = 0;
  764. $send_completed = 0;
  765. for ($i = 0; $i < count($send_calls); $i++) {
  766. if (empty($send_calls[$i][2]))
  767. continue;
  768. $delta = $send_calls[$i][1] - $send_calls[$i][0];
  769. $send_total_time += $delta;
  770. $send_total_emails += $send_calls[$i][2];
  771. $send_mean = $delta / $send_calls[$i][2];
  772. if ($send_min > $send_mean) {
  773. $send_min = $send_mean;
  774. }
  775. if ($send_max < $send_mean) {
  776. $send_max = $send_mean;
  777. }
  778. if (isset($send_calls[$i][3])) {
  779. $send_completed++;
  780. }
  781. }
  782. $send_mean = $send_total_time / $send_total_emails;
  783. ?>
  784. <tr>
  785. <td>
  786. Send details
  787. </td>
  788. <td>
  789. <?php if ($send_mean > 1) { ?>
  790. <span class="tnp-ko">KO</span>
  791. <?php } else { ?>
  792. <span class="tnp-ok">OK</span>
  793. <?php } ?>
  794. </td>
  795. <td>
  796. <?php if ($send_mean > 1) { ?>
  797. <strong>Sending an email is taking more than 1 second, rather slow.</strong>
  798. <a href="https://www.thenewsletterplugin.com/documentation/status-panel#status-performance" target="_blank">Read more</a>.
  799. <?php } ?>
  800. Average time to send an email: <?php echo sprintf("%.2f", $send_mean) ?> seconds<br>
  801. <?php if ($send_mean > 0) { ?>
  802. Max speed: <?php echo sprintf("%.2f", 1.0 / $send_mean * 3600) ?> emails per hour<br>
  803. <?php } ?>
  804. Max mean time measured: <?php echo sprintf("%.2f", $send_max) ?> seconds<br>
  805. Min mean time measured: <?php echo sprintf("%.2f", $send_min) ?> seconds<br>
  806. Total email in the sample: <?php echo $send_total_emails ?><br>
  807. Runs in the sample: <?php echo count($send_calls); ?><br>
  808. Runs prematurely interrupted: <?php echo sprintf("%.2f", (count($send_calls) - $send_completed) * 100.0 / count($send_calls)) ?>%<br>
  809. </td>
  810. </tr>
  811. <?php
  812. }
  813. ?>
  814. <tr>
  815. <td>
  816. Cron warnings
  817. </td>
  818. <td>
  819. <?php if (defined('NEWSLETTER_CRON_WARNINGS') && !NEWSLETTER_CRON_WARNINGS) { ?>
  820. <span class="tnp-maybe">MAYBE</span>
  821. <?php } else { ?>
  822. <span class="tnp-ok">OK</span>
  823. <?php } ?>
  824. </td>
  825. <td>
  826. <?php if (defined('NEWSLETTER_CRON_WARNINGS') && !NEWSLETTER_CRON_WARNINGS) { ?>
  827. Scheduler warnings are disabled in your wp-config.php with the constant <code>NEWSLETTER_CRON_WARNINGS</code> set to true.
  828. <?php } else { ?>
  829. <?php } ?>
  830. </td>
  831. </tr>
  832. <tr>
  833. <td>
  834. WordPress debug mode
  835. </td>
  836. <td>
  837. <?php if (defined('WP_DEBUG') && WP_DEBUG) { ?>
  838. <span class="tnp-maybe">MAYBE</span>
  839. <?php } else { ?>
  840. <span class="tnp-ok">OK</span>
  841. <?php } ?>
  842. </td>
  843. <td>
  844. <?php if (defined('WP_DEBUG') && WP_DEBUG) { ?>
  845. WordPress is in debug mode it is not recommended on a production system. See the constant WP_DEBUG inside the wp-config.php.
  846. <?php } else { ?>
  847. <?php } ?>
  848. </td>
  849. </tr>
  850. <?php /*
  851. $memory = intval(WP_MEMORY_LIMIT);
  852. if (false !== strpos(WP_MEMORY_LIMIT, 'G'))
  853. $memory *= 1024;
  854. ?>
  855. <tr>
  856. <td>
  857. PHP memory limit
  858. </td>
  859. <td>
  860. <?php if ($memory < 64) { ?>
  861. <span class="tnp-ko">MAYBE</span>
  862. <?php } else if ($memory < 128) { ?>
  863. <span class="tnp-maybe">MAYBE</span>
  864. <?php } else { ?>
  865. <span class="tnp-ok">OK</span>
  866. <?php } ?>
  867. </td>
  868. <td>
  869. WordPress WP_MEMORY_LIMIT is set to <?php echo $memory ?> megabyte but your PHP setting could allow more than that.
  870. Anyway we suggest to set the value to at least 64M.
  871. <a href="https://www.thenewsletterplugin.com/documentation/status-panel#status-memory" target="_blank">Read more</a>.
  872. <?php if ($memory < 64) { ?>
  873. This value is too low you should increase it adding <code>define('WP_MEMORY_LIMIT', '64M');</code> to your <code>wp-config.php</code>.
  874. <a href="https://www.thenewsletterplugin.com/documentation/status-panel#status-memory" target="_blank">Read more</a>.
  875. <?php } else if ($memory < 128) { ?>
  876. The value should be fine, it depends on how many plugins you're running and how many resource are required by your theme.
  877. Blank pages may happen with low memory problems. Eventually increase it adding <code>define('WP_MEMORY_LIMIT', '128M');</code>
  878. to your <code>wp-config.php</code>.
  879. <a href="https://www.thenewsletterplugin.com/documentation/status-panel#status-memory" target="_blank">Read more</a>.
  880. <?php } else { ?>
  881. <?php } ?>
  882. </td>
  883. </tr>
  884. */ ?>
  885. <?php
  886. $ip = gethostbyname($_SERVER['HTTP_HOST']);
  887. $name = gethostbyaddr($ip);
  888. $res = true;
  889. if (strpos($name, '.secureserver.net') !== false) {
  890. //$smtp = get_option('newsletter_main_smtp');
  891. //if (!empty($smtp['enabled']))
  892. $res = false;
  893. $message = 'If you\'re hosted with GoDaddy, be sure to set their SMTP (relay-hosting.secureserver.net, without username and password) to send emails
  894. on Newsletter SMTP panel.
  895. Remember they limits you to 250 emails per day. Open them a ticket for more details.';
  896. }
  897. if (strpos($name, '.aruba.it') !== false) {
  898. $res = false;
  899. $message = 'If you\'re hosted with Aruba consider to use an external SMTP (Sendgrid, Mailjet, Mailgun, Amazon SES, Elasticemail, Sparkpost, ...)
  900. since their mail service is not good. If you have your personal email with them, you can try to use the SMTP of your
  901. pesonal account. Ask the support for the SMTP parameters and configure them on Newsletter SMTP panel.';
  902. }
  903. ?>
  904. <tr>
  905. <td>Your Server</td>
  906. <td>
  907. <?php if ($res === false) { ?>
  908. <span class="tnp-maybe">MAYBE</span>
  909. <?php } else { ?>
  910. <span class="tnp-ok">OK</span>
  911. <?php } ?>
  912. </td>
  913. <td>
  914. <?php if ($res === false) { ?>
  915. <?php echo $message ?>
  916. <?php } else { ?>
  917. <?php } ?>
  918. IP: <?php echo $ip ?><br>
  919. Name: <?php echo $name ?><br>
  920. </td>
  921. </tr>
  922. <?php
  923. wp_mkdir_p(NEWSLETTER_LOG_DIR);
  924. $res = is_dir(NEWSLETTER_LOG_DIR) && is_writable(NEWSLETTER_LOG_DIR);
  925. if ($res) {
  926. @file_put_contents(NEWSLETTER_LOG_DIR . '/test.txt', "");
  927. $res = is_file(NEWSLETTER_LOG_DIR . '/test.txt');
  928. if ($res) {
  929. @unlink(NEWSLETTER_LOG_DIR . '/test.txt');
  930. }
  931. }
  932. ?>
  933. <tr>
  934. <td>
  935. Log folder
  936. </td>
  937. <td>
  938. <?php if (!$res) { ?>
  939. <span class="tnp-ko">KO</span>
  940. <?php } else { ?>
  941. <span class="tnp-ok">OK</span>
  942. <?php } ?>
  943. </td>
  944. <td>
  945. The log folder is <?php echo esc_html(NEWSLETTER_LOG_DIR) ?><br>
  946. <?php if (!$res) { ?>
  947. Cannot create the folder or it is not writable.
  948. <?php } else { ?>
  949. <?php } ?>
  950. </td>
  951. </tr>
  952. </tbody>
  953. </table>
  954. <h3>General parameters</h3>
  955. <table class="widefat" id="tnp-parameters-table">
  956. <thead>
  957. <tr>
  958. <th>Parameter</th>
  959. <th>Value</th>
  960. </tr>
  961. </thead>
  962. <tbody>
  963. <tr>
  964. <td>Newsletter version</td>
  965. <td>
  966. <?php echo NEWSLETTER_VERSION ?>
  967. </td>
  968. </tr>
  969. <tr>
  970. <td>NEWSLETTER_MAX_EXECUTION_TIME</td>
  971. <td>
  972. <?php
  973. if (defined('NEWSLETTER_MAX_EXECUTION_TIME')) {
  974. echo NEWSLETTER_MAX_EXECUTION_TIME . ' (seconds)';
  975. } else {
  976. echo 'Not set';
  977. }
  978. ?>
  979. </td>
  980. </tr>
  981. <tr>
  982. <td>NEWSLETTER_CRON_INTERVAL</td>
  983. <td>
  984. <?php echo NEWSLETTER_CRON_INTERVAL . ' (seconds)'; ?>
  985. </td>
  986. </tr>
  987. <?php /*
  988. <tr>
  989. <td>WordPress plugin url</td>
  990. <td>
  991. <?php echo WP_PLUGIN_URL; ?>
  992. <br>
  993. Filters:
  994. <?php
  995. if (isset($wp_filter))
  996. $filters = $wp_filter['plugins_url'];
  997. if (!isset($filters) || !is_array($filters))
  998. echo 'no filters attached to "plugin_urls"';
  999. else {
  1000. echo '<ul>';
  1001. foreach ($filters as &$filter) {
  1002. foreach ($filter as &$entry) {
  1003. echo '<li>';
  1004. if (is_array($entry['function']))
  1005. echo esc_html(get_class($entry['function'][0]) . '->' . $entry['function'][1]);
  1006. else
  1007. echo esc_html($entry['function']);
  1008. echo '</li>';
  1009. }
  1010. }
  1011. echo '</ul>';
  1012. }
  1013. ?>
  1014. <p class="description">
  1015. This value should contains the full URL to your plugin folder. If there are filters
  1016. attached, the value can be different from the original generated by WordPress and sometime worng.
  1017. </p>
  1018. </td>
  1019. </tr>
  1020. */ ?>
  1021. <tr>
  1022. <td>Absolute path</td>
  1023. <td>
  1024. <?php echo esc_html(ABSPATH); ?>
  1025. </td>
  1026. </tr>
  1027. <tr>
  1028. <td>Tables Prefix</td>
  1029. <td>
  1030. <?php echo $wpdb->prefix; ?>
  1031. </td>
  1032. </tr>
  1033. </tbody>
  1034. </table>
  1035. <h3>Log files</h3>
  1036. <ul class="tnp-log-files">
  1037. <?php
  1038. $files = glob(WP_CONTENT_DIR . '/logs/newsletter/*.txt'); // get all file names
  1039. foreach ($files as $file) { // iterate files
  1040. echo '<li><a href="' . WP_CONTENT_URL . '/logs/newsletter/' . basename($file) . '" target="_blank">' . basename($file) . '</a>';
  1041. echo ' <span class="tnp-log-size">(' . size_format(filesize($file)) . ')</span>';
  1042. echo '</li>';
  1043. }
  1044. ?>
  1045. </ul>
  1046. <?php $controls->button('delete_logs', 'Delete all'); ?>
  1047. <?php if (isset($_GET['debug'])) { ?>
  1048. <h3>Database Tables</h3>
  1049. <h4><?php echo $wpdb->prefix ?>newsletter</h4>
  1050. <?php
  1051. $rs = $wpdb->get_results("describe {$wpdb->prefix}newsletter");
  1052. ?>
  1053. <table class="tnp-db-table">
  1054. <thead>
  1055. <tr>
  1056. <th>Field</th>
  1057. <th>Type</th>
  1058. <th>Null</th>
  1059. <th>Key</th>
  1060. <th>Default</th>
  1061. <th>Extra</th>
  1062. </tr>
  1063. </thead>
  1064. <tbody>
  1065. <?php foreach ($rs as $r) { ?>
  1066. <tr>
  1067. <td><?php echo esc_html($r->Field) ?></td>
  1068. <td><?php echo esc_html($r->Type) ?></td>
  1069. <td><?php echo esc_html($r->Null) ?></td>
  1070. <td><?php echo esc_html($r->Key) ?></td>
  1071. <td><?php echo esc_html($r->Default) ?></td>
  1072. <td><?php echo esc_html($r->Extra) ?></td>
  1073. </tr>
  1074. <?php } ?>
  1075. </tbody>
  1076. </table>
  1077. <h4><?php echo $wpdb->prefix ?>newsletter_emails</h4>
  1078. <?php
  1079. $rs = $wpdb->get_results("describe {$wpdb->prefix}newsletter_emails");
  1080. ?>
  1081. <table class="tnp-db-table">
  1082. <thead>
  1083. <tr>
  1084. <th>Field</th>
  1085. <th>Type</th>
  1086. <th>Null</th>
  1087. <th>Key</th>
  1088. <th>Default</th>
  1089. <th>Extra</th>
  1090. </tr>
  1091. </thead>
  1092. <tbody>
  1093. <?php foreach ($rs as $r) { ?>
  1094. <tr>
  1095. <td><?php echo esc_html($r->Field) ?></td>
  1096. <td><?php echo esc_html($r->Type) ?></td>
  1097. <td><?php echo esc_html($r->Null) ?></td>
  1098. <td><?php echo esc_html($r->Key) ?></td>
  1099. <td><?php echo esc_html($r->Default) ?></td>
  1100. <td><?php echo esc_html($r->Extra) ?></td>
  1101. </tr>
  1102. <?php } ?>
  1103. </tbody>
  1104. </table>
  1105. <h3>Extensions</h3>
  1106. <pre style="font-size: 11px; font-family: monospace; background-color: #efefef; color: #444"><?php echo esc_html(print_r(get_option('newsletter_extension_versions'), true)); ?></pre>
  1107. <h3>Update plugins data</h3>
  1108. <pre style="font-size: 11px; font-family: monospace; background-color: #efefef; color: #444"><?php echo esc_html(print_r(get_site_transient('update_plugins'), true)); ?></pre>
  1109. <?php } ?>
  1110. </div>
  1111. <?php include NEWSLETTER_DIR . '/tnp-footer.php'; ?>
  1112. </div>