• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Akismet::delete_orphaned_commentmeta() –

You appear to be a bot. Output may be restricted

Description

Usage

Akismet::delete_orphaned_commentmeta();

Parameters

Returns

void

Source

File name: akismet/class.akismet.php
Lines:

1 to 35 of 35
  public static function delete_orphaned_commentmeta() {
    global $wpdb;

    $last_meta_id = 0;
    $start_time = isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime( true );
    $max_exec_time = max( ini_get('max_execution_time') - 5, 3 );

    while ( $commentmeta_results = $wpdb->get_results( $wpdb->prepare( "SELECT m.meta_id, m.comment_id, m.meta_key FROM {$wpdb->commentmeta} as m LEFT JOIN {$wpdb->comments} as c USING(comment_id) WHERE c.comment_id IS NULL AND m.meta_id > %d ORDER BY m.meta_id LIMIT 1000", $last_meta_id ) ) ) {
      if ( empty( $commentmeta_results ) )
        return;

      $wpdb->queries = array();

      $commentmeta_deleted = 0;

      foreach ( $commentmeta_results as $commentmeta ) {
        if ( 'akismet_' == substr( $commentmeta->meta_key, 0, 8 ) ) {
          delete_comment_meta( $commentmeta->comment_id, $commentmeta->meta_key );
          do_action( 'akismet_batch_delete_count', __FUNCTION__ );
          $commentmeta_deleted++;
        }

        $last_meta_id = $commentmeta->meta_id;
      }

      do_action( 'akismet_delete_commentmeta_batch', $commentmeta_deleted );

      // If we're getting close to max_execution_time, quit for this round.
      if ( microtime(true) - $start_time > $max_exec_time )
        return;
    }

    if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->commentmeta ) ) // lucky number
      $wpdb->query("OPTIMIZE TABLE {$wpdb->commentmeta}");
  }
 

 View on GitHub View on Trac

Published: 19th December 2019 | Last updated: 19th December 2019

Primary Sidebar

Information

Function name: Akismet::delete_orphaned_commentmeta
Class ref: Akismet
Plugin ref: Akismet
Version: 5.0.1
Sourcefile: class.akismet.php
File ref: class.akismet.php
Deprecated?: No
API Letters: A,C,D,O

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites