Title: pressaccept's Replies | WordPress.org

---

# pressaccept

  [  ](https://wordpress.org/support/users/pressaccept/)

 *   [Profile](https://wordpress.org/support/users/pressaccept/)
 *   [Topics Started](https://wordpress.org/support/users/pressaccept/topics/)
 *   [Replies Created](https://wordpress.org/support/users/pressaccept/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/pressaccept/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/pressaccept/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/pressaccept/engagements/)
 *   [Favorites](https://wordpress.org/support/users/pressaccept/favorites/)

 Search replies:

## Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Better Search Replace] Try decreasing the “Max Page Size” – error](https://wordpress.org/support/topic/try-decreasing-the-max-page-size-error/)
 *  [pressaccept](https://wordpress.org/support/users/pressaccept/)
 * (@pressaccept)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/try-decreasing-the-max-page-size-error/#post-18282634)
 * Just to note here, at a bit random, but `805306368` bytes is 768 MB, not 2 GB.
   A limit might be set at 2 GB, but that’s not where you’re running out of memory
   or what it’s running at. There are many factors. Still, a _lot_ of memory to 
   be sure.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[AnsPress - Question and answer] Database Creating Records That Are Never Deleted](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/)
 *  Thread Starter [pressaccept](https://wordpress.org/support/users/pressaccept/)
 * (@pressaccept)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/#post-17530270)
 * Also, after activating the plugin, links without permalink functionality don’t
   work (page=&question=…), permalink functionality has to be enabled or refreshed.
 * Also, when the answer subscriber is stored in the database the post id attached
   to ‘answer_’ is incorrect (it points to the parent post rather than the reference
   post id), so it’s not deleted when answers are deleted.
 * Here are fixes to the database issues, including the above, (the query hook requires
   the [phpmyadmin/sql-parser](https://github.com/phpmyadmin/sql-parser) package):
 *     ```wp-block-code
       use PhpMyAdmin\SqlParser\Parser;
       use PhpMyAdmin\SqlParser\Statements\DeleteStatement;
   
       function htpa_anspress_delete_subscriptions(): void {
       if ( defined( 'AP_DB_VERSION' ) ) {
       // https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/
   
       /*
       * You have a database leak: a record is created when deleting questions in the ap_qameta table after the same
       * ap_qameta record is deleted. Because of this, this qa_meta record is never actually deleted. This is because you
       * have AnsPress_Hooks::delete_subscriptions hooked into before_delete_post at a priority of 10. This causes the
       * hook to possibly fire AFTER the record is deleted, which performs an UPDATE/INSERT on the same record.
       *
       * To fix this, you need to edit line 129 in includes/hooks.php so that the hook for before_delete_post
       * (delete_subscriptions) is a lower priority, such as 5. This will cause all records to be deleted and no more
       * leaks.
       */
   
       remove_action( 'before_delete_post', [ 'AnsPress_Hooks', 'delete_subscriptions' ] );
       add_action( 'before_delete_post', [ 'AnsPress_Hooks', 'delete_subscriptions' ], 5 );
       }
       }
   
       add_action( 'init', 'htpa_anspress_delete_subscriptions' );
   
       function htpa_anspress_delete_subscribers( int $id, ?int $reassign, WP_User $user ): void {
       // https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/#post-17519488
   
       /*
       * Also, when deleting a user, it doesn’t appear that ap_subscribers with subs_user_id matching the deleted users
       * are consistently removed.
       */
   
       if ( is_plugin_active( 'anspress-question-answer/anspress-question-answer.php' ) ) {
       global $wpdb;
   
       if ( ! $reassign ) {
       $wpdb->delete( $wpdb->ap_subscribers, [ 'subs_user_id' => $id ], [ '%d' ] );
       } else {
       $wpdb->update( $wpdb->ap_subscribers,
       [ 'subs_user_id' => $reassign ],
       [ 'subs_user_id' => $id ],
       [ '%d' ],
       [ '%d' ] );
       }
       }
       }
   
       add_action( 'deleted_user', 'htpa_anspress_delete_subscribers', 10, 3 );
   
       function htpa_anspress_before_delete(): void {
       if ( defined( 'AP_DB_VERSION' ) ) {
       // https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/#post-17519536
   
       /*
       * Also, same deal, when deleting a post with comments, the system inserts comment metadata into ap_qameta AFTER
       * the post is deleted, which recreates the record.
       */
   
       remove_action( 'before_delete_post', [ 'AnsPress_Hooks', 'before_delete' ] );
       add_action( 'delete_post', [ 'AnsPress_Hooks', 'before_delete' ] );
       }
       }
   
       add_action( 'init', 'htpa_anspress_before_delete' );
   
       function htpa_anspress_query( string $query ): string {
       global $wpdb;
   
       // https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/#post-17519432
   
       /*
       * You also have a typo causing records not to be deleted in the ap_reputations table. In
       * addons/reputation/reputation.php on line 428 (function delete_user) you have a string: ‘repu_user_id’. This
       * needs to be ‘rep_user_id’, otherwise a database error is triggered and the record is not deleted.
       */
       $query = str_replace( 'repu_user_id', 'rep_user_id', $query );
   
       $parser = new Parser( $query );
       if ( $parser->statements ) {
       $statement = $parser->statements[0];
   
       switch ( get_class( $statement ) ) {
       case DeleteStatement::class:
       if ( $statement->where && isset( $statement->where[0]->identifiers[1] ) ) {
       if ( str_contains( $statement->where[0]->identifiers[1], 'answer_' ) ) {
       $expr =& $statement->where[0]->expr;
   
       // when deleting subscribers, answer_ is given parent_post instead of actual post id, fix it
       $expr = str_replace(
       $identifier = $statement->where[0]->identifiers[1],
       ( $subs_event = $wpdb->get_var(
       $wpdb->prepare(
       "SELECT subs_event FROM {$wpdb->ap_subscribers} WHERE subs_ref_id = %d",
       explode( '_', $identifier )[1]
       )
       ) )
       ? $subs_event
       : $identifier,
       $expr
       );
   
       $query = $statement->build();
       }
       }
   
       break;
       }
       }
   
       return $query;
       }
   
       add_action( 'query', 'htpa_anspress_query' );
       ```
   
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[AnsPress - Question and answer] Database Creating Records That Are Never Deleted](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/)
 *  Thread Starter [pressaccept](https://wordpress.org/support/users/pressaccept/)
 * (@pressaccept)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/#post-17519536)
 * Also, same deal, when deleting a post with comments, the system inserts comment
   metadata into ap_qameta AFTER the post is deleted, which recreates the record.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[AnsPress - Question and answer] Database Creating Records That Are Never Deleted](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/)
 *  Thread Starter [pressaccept](https://wordpress.org/support/users/pressaccept/)
 * (@pressaccept)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/#post-17519488)
 * Also, when deleting a user, it doesn’t appear that ap_subscribers with subs_user_id
   matching the deleted users are consistently removed.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[AnsPress - Question and answer] Database Creating Records That Are Never Deleted](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/)
 *  Thread Starter [pressaccept](https://wordpress.org/support/users/pressaccept/)
 * (@pressaccept)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/database-creating-records-that-are-never-deleted/#post-17519432)
 * You also have a typo causing records not to be deleted in the ap_reputations 
   table. In addons/reputation/reputation.php on line 428 (function delete_user)
   you have a string: ‘repu_user_id’. This needs to be ‘rep_user_id’, otherwise 
   a database error is triggered and the record is not deleted.

Viewing 5 replies - 1 through 5 (of 5 total)