• Hello,
    add_filter( ‘site_transient_update_plugins’, array( $this, ‘update_check’ ) );

    This filter use in my custom plugin but using site_transient_update_plugins its call multiple times so my site make slow in admin side
    https://prnt.sc/Yg1y6XQhu76M

    Why this happened ?

    Here is my update_check()

    public function update_check( $transient ) {

    if ( empty( $transient->checked ) ) {

    return $transient;

    }

    $args = array(

    'request' => 'pluginupdatecheck',

    'slug' => $this->slug,

    'plugin_name' => $this->plugin_name,

    //'version' => $transient->checked[$this->plugin_name],

    'version' => $this->ame_software_version,

    'product_id' => $this->ame_product_id,

    'api_key' => $this->ame_options[ $this->ame_api_key ],

    'activation_email' => $this->ame_options[ $this->ame_activation_email ],

    'instance' => $this->ame_instance_id,

    'domain' => $this->ame_domain,

    'software_version' => $this->ame_software_version,

    'extra' => $this->extra,

    );

    // Check for a plugin update

    $response = $this->plugin_information( $args );

    // Displays an admin error message in the WordPress dashboard

    $this->check_response_for_errors( $response );

    // Set version variables

    if ( isset( $response ) && is_object( $response ) && $response !== false ) {

    // New plugin version from the API

    $new_ver = (string) $response->new_version;

    // Current installed plugin version

    $curr_ver = (string) $this->ame_software_version;

    //$curr_ver = (string)$transient->checked[$this->plugin_name];

    }

    // If there is a new version, modify the transient to reflect an update is available

    if ( isset( $new_ver ) && isset( $curr_ver ) ) {

    if ( $response !== false && version_compare( $new_ver, $curr_ver, '>' ) ) {

    if ( $this->plugin_or_theme == 'plugin' ) {

    if($response->package_url !== '') {

    $response->package = $response->package_url;

    }

    $transient->response[ $this->plugin_name ] = $response;

    } else if ( $this->plugin_or_theme == 'theme' ) {

    $transient->response[ $this->plugin_name ][ 'new_version' ] = $response->new_version;

    $transient->response[ $this->plugin_name ][ 'url' ] = $response->url;

    $transient->response[ $this->plugin_name ][ 'package' ] = $response->package;

    }

    }

    }

    return $transient;

    }

    Here is my plugin_information()

    public function plugin_information( $args ) {

    $target_url = esc_url_raw( $this->create_upgrade_api_url( $args ) );

    //echo $target_url;

    //$request = wp_safe_remote_get( $target_url );

    $request = wp_remote_post( $this->api_url . 'wc-api/upgrade-api/', array( 'body' => $args ) );

    if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) != 200 ) {

    return false;

    }

    $response = unserialize( wp_remote_retrieve_body( $request ) );

    /**

    * For debugging errors from the API

    * For errors like: unserialize(): Error at offset 0 of 170 bytes

    * Comment out $response above first

    */

    //$response = wp_remote_retrieve_body( $request );

    //print_r($response); exit;

    if ( is_object( $response ) ) {

    return $response;

    } else {

    return false;

    }

    }
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There are many WP filter and action hooks that fire multiple times. Often it’s of little consequence. When it is of consequence, you can have your callback remove itself from the filter call stack so it cannot re-execute on subsequent firings for the same request.

    The removal function should be called first thing since it takes time to process. If you waited until the end your callback will be called again before removal can be completed.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.