RavanH / xml-sitemap-feed

XML Sitemap & Google News feeds
GNU General Public License v2.0
16 stars 21 forks source link

ClassicPress 1.7.2 cannot enable sitemap #46

Open aaro-n opened 6 months ago

aaro-n commented 6 months ago

Introduction to the running environment

ClassicPress version: 1.7.2 PHP version: 8.0, 8.1 Database: planetscale XML Sitemap Generator for Google: 4.1.19

Problem description

I switched from WordPress to ClassicPress (1.6.5) in October 2023 and installed the XML Sitemap Generator for Google plugin. It was working fine until yesterday, when I suddenly noticed that the sitemap had disappeared. I went to the ClassicPress Settings and under Reading, I found that XML Sitemap Index was not checked to enable it. I checked XML Sitemap Index and saved it, but the page automatically refreshed and I found that the XML Sitemap Index that I had just enabled had disappeared. I repeated this several times with the same result.

Summary

Option Can changes be saved? Description
XML Sitemap Index Changes cannot be saved Checkbox disappears after saving and refreshing
Google News Sitemap Changes cannot be saved Checkbox disappears after saving and refreshing
Additional robots.txt rules Changes can be saved Content can be saved
RavanH commented 6 months ago

Hi, this plugin (XML Sitemap & Google News feeds) is not compatible with XML Sitemap Generator for Google. But I'll test it on a ClassicPress installation...

RavanH commented 6 months ago

OK, I did find an incompatibility with ClassicPress (and WordPress pre-5.5 for that matter) ... I'll address it in the new 5.4.2 release coming up right now :)

RavanH commented 6 months ago

Could you test the latest version https://downloads.wordpress.org/plugin/xml-sitemap-feed.zip ?

aaro-n commented 6 months ago

I downloaded and tested the latest version, no improvement.

RavanH commented 6 months ago

Hi, I tested this version on ClassicPress 1.7.2 together with XML Sitemap Generator for Google: 4.1.19 running on PHP 8.2, 8.1 and 8.0 and not seeing the issues.

Is your hosting provider using an object cache maybe? These tend to interfere with admin settings sometimes...

aaro-n commented 6 months ago

@RavanH Yes, I am using the wp-redis plugin to enable redis cache, when I disable the redis configuration in the wp-config.php file, the xml-sitemap-feed can work normally, the sitemap and robots.txt can work normally (the wp-redis plugin is not disabled). When I enable the redis configuration in wp-config.php, the xml-sitemap-feed can work normally, in the ClassicPress settings->Reading->Enable XML Sitemap item, the XML Sitemap Index is automatically checked. Without making any changes to the table, click Save Changes below, at this time, the web page will automatically refresh, the XML Sitemap Index of the new page is unchecked, the sitemap cannot be accessed, and the robots.txt file can be accessed.

Disable cache in wp-config.php configuration file

root@e784779b644683:/home/www/html/classicpress# wp plugin list --allow-root
PHP Warning:  WP Redis: Connection refused in /home/www/html/classicpress/wp-content/plugins/wp-redis/object-cache.php on line 1485
Warning: WP Redis: Connection refused in /home/www/html/classicpress/wp-content/plugins/wp-redis/object-cache.php on line 1485
PHP Warning:  Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
Warning: Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
+--------------------------+----------+--------+---------+----------------+-------------+
| name                     | status   | update | version | update_version | auto_update |
+--------------------------+----------+--------+---------+----------------+-------------+
| opcache-scripts          | active   | none   | 1.1.6   |                | off         |
| oss-aliyun               | active   | none   | 1.4.9   |                | off         |
| peendev-markdown         | active   | none   | 1.0.3   |                | off         |
| wp-optimize              | inactive | none   | 3.3.0   |                | off         |
| wp-fastest-cache         | active   | none   | 1.2.3   |                | off         |
| wp-fastest-cache-premium | active   | none   | 1.7.0   |                | off         |
| wp-redis                 | active   | none   | 1.4.4   |                | off         |
| wp-smtp                  | active   | none   | 1.2.6   |                | off         |
| xml-sitemap-feed         | active   | none   | 5.4.4   |                | off         |
| object-cache.php         | dropin   | none   |         |                | off         |
+--------------------------+----------+--------+---------+----------------+-------------+
root@e784779b644683:/home/www/html/classicpress# wp plugin deactivate xml-sitemap-feed --allow-root
PHP Warning:  WP Redis: Connection refused in /home/www/html/classicpress/wp-content/plugins/wp-redis/object-cache.php on line 1485
Warning: WP Redis: Connection refused in /home/www/html/classicpress/wp-content/plugins/wp-redis/object-cache.php on line 1485
PHP Warning:  Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
Warning: Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
Plugin 'xml-sitemap-feed' deactivated.
Success: Deactivated 1 of 1 plugins.
root@e784779b644683:/home/www/html/classicpress# wp plugin delete xml-sitemap-feed --allow-root
PHP Warning:  WP Redis: Connection refused in /home/www/html/classicpress/wp-content/plugins/wp-redis/object-cache.php on line 1485
Warning: WP Redis: Connection refused in /home/www/html/classicpress/wp-content/plugins/wp-redis/object-cache.php on line 1485
PHP Warning:  Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
Warning: Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
Deleted 'xml-sitemap-feed' plugin.
Success: Deleted 1 of 1 plugins.
root@e784779b644683:/home/www/html/classicpress#

Enable redis cache in wp-config.php configuration file

root@e784779b644683:/home/www/html/classicpress# wp plugin deactivate xml-sitemap-feed --allow-root
PHP Warning:  Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
Warning: Undefined array key "SERVER_NAME" in /home/www/html/classicpress/wp-includes/rest-api.php on line 349
PHP Fatal error:  Uncaught Error: Call to undefined function xmlsf_clear_metacache() in /home/www/html/classicpress/wp-content/plugins/xml-sitemap-feed/xml-sitemap.php:160
Stack trace:
#0 /home/www/html/classicpress/wp-includes/class-wp-hook.php(287): xmlsf_deactivate()
#1 /home/www/html/classicpress/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters()
#2 /home/www/html/classicpress/wp-includes/plugin.php(458): WP_Hook->do_action()
#3 /home/www/html/classicpress/wp-admin/includes/plugin.php(753): do_action()
#4 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/Plugin_Command.php(453): deactivate_plugins()
#5 [internal function]: Plugin_Command->deactivate()
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func()
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}()
#8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(497): call_user_func()
#9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(441): WP_CLI\Dispatcher\Subcommand->invoke()
#10 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(464): WP_CLI\Runner->run_command()
#11 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1295): WP_CLI\Runner->run_command_and_exit()
#12 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#13 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process()
#14 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#15 phar:///usr/local/bin/wp/php/boot-phar.php(20): include('...')
#16 /usr/local/bin/wp(4): include('...')
#17 {main}
  thrown in /home/www/html/classicpress/wp-content/plugins/xml-sitemap-feed/xml-sitemap.php on line 160
Fatal error: Uncaught Error: Call to undefined function xmlsf_clear_metacache() in /home/www/html/classicpress/wp-content/plugins/xml-sitemap-feed/xml-sitemap.php:160
Stack trace:
#0 /home/www/html/classicpress/wp-includes/class-wp-hook.php(287): xmlsf_deactivate()
#1 /home/www/html/classicpress/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters()
#2 /home/www/html/classicpress/wp-includes/plugin.php(458): WP_Hook->do_action()
#3 /home/www/html/classicpress/wp-admin/includes/plugin.php(753): do_action()
#4 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/Plugin_Command.php(453): deactivate_plugins()
#5 [internal function]: Plugin_Command->deactivate()
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func()
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}()
#8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(497): call_user_func()
#9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(441): WP_CLI\Dispatcher\Subcommand->invoke()
#10 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(464): WP_CLI\Runner->run_command()
#11 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1295): WP_CLI\Runner->run_command_and_exit()
#12 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#13 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process()
#14 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#15 phar:///usr/local/bin/wp/php/boot-phar.php(20): include('...')
#16 /usr/local/bin/wp(4): include('...')
#17 {main}
  thrown in /home/www/html/classicpress/wp-content/plugins/xml-sitemap-feed/xml-sitemap.php on line 160
root@e784779b644683:/home/www/html/classicpress#

Notes

All of them have not disabled the wp-redis plugin, just enable or comment out the redis address in wp-config.php.

aaro-n commented 6 months ago

If I clear the cache through redis-cli, it can be used normally. When I click Save Changes under Reading, the page automatically refreshes and the site map is no longer available.

RavanH commented 6 months ago

I'll have to do further testing with Redis and see if there is a work-around... Thanks for your feedback so far!

Note that the "Call to undefined function" error on deactivation via wp-cli will be fixed in the upcoming release.

RavanH commented 6 months ago

OK, tested with both regular WP and CP running WP Redis but cannot reproduce the effect.

Can you make sure you have a WP_CACHE_KEY_SALT defined in your wp-config.php ? It must be unique for each site using a shared redis database to prevent cache conflicts. And/or try setting another database value in the $redis_server array...

Read more on https://wordpress.org/plugins/wp-redis/#installation

aaro-n commented 6 months ago

I did not deploy the Redis cache service myself, but used https://redis.com/try-free/ and https://upstash.com/. Both online cloud Redis were tested and both appeared. When clicking Save Changes in the Reading settings, the site map disappears after the web page is refreshed. Also the WP_CACHE_KEY_SALT parameter is set.

wp-config.php configuration

root@e784779b644683:/home/www/html/classicpress# cat wp-config.php
<?php
/**
 * The base configuration for ClassicPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://wordpress.org/support/article/editing-wp-config-php/
 *
 * @package ClassicPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for ClassicPress */
define('DB_NAME', 'database');

/** MySQL database username */
define('DB_USER', '456');

/** MySQL database password */
define('DB_PASSWORD', '123');

/** MySQL hostname */
define('DB_HOST', 'aws.connect.psdb.cloud:3306');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8mb4');

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

define( 'MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL );

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.classicpress.net/secret-key/1.0/salt/ ClassicPress.net secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since WP-2.6.0
 */
define('AUTH_KEY',         'UgFR<Fl{Ft%nBAh-#kcN-~arEsUI`bUzH`^(VxVKCQuV#H<EcZrYJJg+bNa1&i&a');
define('SECURE_AUTH_KEY',  'eq3IA4(Kkn7*hUO?k3Xm5fje09GyHH!U@!p,*|48XCP<mzXUF/CVRV(k[RL~STV|');
define('LOGGED_IN_KEY',    '?5X8Knbz}8Wl|>C7Vh?Ear3[Jj]uhuugEz@)z3jar,^`|&lT)sqmR65gv;]4E 4+');
define('NONCE_KEY',        'kKvXTTVHE)5~)>^ $+4hg/=0ha0t$ktvd#5buscE22w=-_m!C`Y/xP8j9.bQF_FD');
define('AUTH_SALT',        '|`9nM|/_-X$^KGVeNhMj8u-OU<rCKZ^Iz6>qvJ9i>Kp2[[8YZX?X//Gq6dQP>fhW');
define('SECURE_AUTH_SALT', 'ik40_=i4_o@n_9=GeE0UuL^:{(v833oL7eU^W#$R8+fsWhjRZb7+h7u!^AHdXbcN');
define('LOGGED_IN_SALT',   '7UlU)[@Pck&iis`#K*6vrRcj,igL%wWso{~1@RW!Hrp@M6FBV]xb!4(h6DY~5@u2');
define('NONCE_SALT',       ']z3I@p}AIWVsFd9LRiuO{ve6/-O3?|xo_(Q#[Y= s5x8N<[HannvV+E-a{G:65As');

/**#@-*/

/**
 * ClassicPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'cp_';

/**
 * For developers: ClassicPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the Codex.
 *
 * @link https://wordpress.org/support/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/* That's all, stop editing! Happy blogging. */

define('DISABLE_WP_CRON', true);

/** 强制使用HTTPS */
$_SERVER['HTTPS'] = 'ON';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);

/** 使用Redis换成 */
/* $redis_server = array(
/*     'host'     => 'r1112.cloud.redislabs.com',
/*     'port'     => 12550,
/*     'auth'     => '123',
/*     'database' => 0,
/* );
 */

$redis_server = array(
    'host'     => '123.upstash.io',
    'port'     => 6379,
    'auth'     => '123',
    'database' => 0,
  );

define('WP_CACHE_KEY_SALT', '5f5e10378b7f2c3f20015603b068f38f');

/** Absolute path to the ClassicPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}

/** Sets up ClassicPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
root@e784779b644683:/home/www/html/classicpress#
aaro-n commented 6 months ago

I use Docker to run ClassicPress. This is the Dockerfile repository for making images. https://github.com/aaro-n/script/tree/main/docker/classicpress

RavanH commented 6 months ago

Could you try https://wordpress.org/plugins/redis-cache/ ? It has a cache purge button in the admin...

And what happens if you hit the "Reset settings" button on Settings > XML Sitemap?

RavanH commented 6 months ago

Or maybe first try another WP_CACHE_KEY_SALT value... Pick a random value from https://api.wordpress.org/secret-key/1.1/salt/

aaro-n commented 6 months ago

I've tried all the suggestions you gave me, but they don't work. Here are the specific steps:

Use wp-redis plug-in

Reset is invalid

Clear the redis cache, "Reset settings" button on Settings > XML Sitemap, and then click "Save Settings" in the `Reading' configuration. After the web page is refreshed, the sitemap option is not checked, and the Settings > XML Sitemap configuration disappears.

WP_CACHE_KEY_SALT random variable is invalid

After following the link given and changing WP_CACHE_KEY_SALT, the same problem occurred.

Use redis-cache plug-in

Replacing the plug-in is invalid

Replace the redis-cache plug-in, delete the wp-redis plug-in, log out of the configuration, and click Save Settings in the Reading configuration again. The same problem occurs and the site map disappears.

When ClassicPress releases version 2.0, I can use it online like this. After version 2.0 is released, ClassicPress and the database will be reinstalled.

RavanH commented 6 months ago

When removing the wp-redis plugin, did you also remove the wp-content/object-cache.php file ?

aaro-n commented 6 months ago

Yes, the wp-content/object-cache.php file has been deleted. wp-redis uses wp-cli to enable redis cache. The object-cache.php file is a soft link. When wp-redis is deleted, manually delete wp-content/object. -cache.php. redis-cache also uses wp-cli to enable redis cache. When redis-cache is deleted, wp-content/object-cache.php will be automatically deleted.

RavanH commented 6 months ago

It feels to me like the Redis Cache on your setup is not being properly updated. This would make it a redis cache issue...

Could you verify the database entry with option_name "xmlsf_sitemaps" in your wp-options table? It should hold an array, reflecting activated sitemaps. For example, after activating both sitemaps on Settings > General and saving, the option_value should be updated to: a:2:{s:7:"sitemap";s:1:"1";s:12:"sitemap-news";s:1:"1";}

aaro-n commented 6 months ago

ClassicPress 2.0 has been released, and I'm ready to back up ClassicPress tomorrow, then purge the database and reinstall ClassicPress.

Just click "Save Changes"

With the sitemap working fine, on the Reading Settings page, when I click "Save Changes", the database doesn't change, but the XML Sitemap Index checkbox disappears, and the sitemap becomes unusable.

Screenshot: Click Save Changes, no change in the database.

未点保存

Check XML Sitemap Index, Google News Sitemap

When both are checked, the database changes, but Reading, XML Sitemap Index, and Google News Sitemap are all unchecked, and the sitemap is not enabled.

Screenshot:

I hope this translation is helpful!

截屏2024-02-24 19 43 30
aaro-n commented 6 months ago

I tested ClassicPress 2.0, but the problems reported before still occur. Below is the ClassicPress backup package, including program and database backup, how to use it, use the previous Dockerfile to prepare the running environment, and then modify wp-config.php, configure the database and Redis, run the data recovery command wp db import backup.sql through wp-cli to restore the database and test. classicpress.zip

RavanH commented 6 months ago

I'm afraid I do not have a docker environment to test with... Do any settings on Settings > XML Sitemap or Settings > Google News suffer from this issue?

RavanH commented 6 months ago

Just to make sure if I understand this correctly:

Your DB options table gets option_value a:2:{s:7:"sitemap";s:1:"1";s:12:"sitemap-news";s:1:"1";} for the xmlsf_sitemaps option after saving with both sitemaps checked, but the Settings > Reading page will still show the sitemaps unchecked and the sitemaps are not available...

What happens if you clear the full Redis Cache after that? Will the Settings > Reading page start reflecting the database state or will it still reflect an incorrect state?

aaro-n commented 6 months ago

When I clear the cache in redis, both the sitemap and google news work fine unless I click 'Save Settings' in the 'Reading' option again